Code example for StateListDrawable

Methods: addState

0
 
public class IconHighlights { 
	public static final int TYPE_DESKTOP=1;
	public static final int TYPE_DOCKBAR=2;
	public static final int TYPE_DRAWER=3;
	public IconHighlights(Context context) {
		// TODO Auto-generated constructor stub 
	} 
	private static Drawable newSelector(Context context){
		GradientDrawable mDrawPressed;
		GradientDrawable mDrawSelected;
		StateListDrawable drawable=new StateListDrawable();
		int selectedColor=AlmostNexusSettingsHelper.getHighlightsColorFocus(context);
		int pressedColor=AlmostNexusSettingsHelper.getHighlightsColor(context);
		int stateFocused = android.R.attr.state_focused;
		int statePressed = android.R.attr.state_pressed;
		int stateWindowFocused = android.R.attr.state_window_focused;
		  
		mDrawSelected = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
		        new int[] { 0x77FFFFFF, selectedColor,selectedColor,selectedColor,selectedColor, 0x77000000 });
		mDrawSelected.setShape(GradientDrawable.RECTANGLE);
		mDrawSelected.setGradientRadius((float)(Math.sqrt(2) * 60));
		mDrawSelected.setCornerRadius(8);
		mDrawPressed = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
				new int[] { 0x77FFFFFF, pressedColor,pressedColor,pressedColor,pressedColor, 0x77000000 });
		mDrawPressed.setShape(GradientDrawable.RECTANGLE);
		mDrawPressed.setGradientRadius((float)(Math.sqrt(2) * 60));
		mDrawPressed.setCornerRadius(8);
 
		drawable.addState(new int[]{ statePressed}, mDrawPressed);
		drawable.addState(new int[]{ stateFocused, stateWindowFocused}, mDrawSelected);
		drawable.addState(new int[]{stateFocused, -stateWindowFocused}, null);
		drawable.addState(new int[]{-stateFocused, stateWindowFocused}, null);