use of android.graphics.drawable.StateListDrawable in project actor-platform by actorapp.
the class SelectorFactory method get.
public static StateListDrawable get(int color, Context context) {
GradientDrawable bg = (GradientDrawable) context.getResources().getDrawable(R.drawable.btn_bg);
bg.setColor(color);
GradientDrawable bgPressed = (GradientDrawable) context.getResources().getDrawable(R.drawable.btn_bg_pressed);
bgPressed.setColor(ActorStyle.getDarkenArgb(color, 0.95));
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { android.R.attr.state_pressed }, bgPressed);
states.addState(StateSet.WILD_CARD, bg);
return states;
}
use of android.graphics.drawable.StateListDrawable in project Android-Developers-Samples by johnjohndoe.
the class ThumbnailRadioButton method setThumbnail.
public void setThumbnail(Bitmap bitmap) {
//Bitmap drawable
BitmapDrawable bmp = new BitmapDrawable(getResources(), bitmap);
bmp.setGravity(Gravity.CENTER);
int strokeWidth = 24;
//Checked state
ShapeDrawable rectChecked = new ShapeDrawable(new RectShape());
rectChecked.getPaint().setColor(0xFFFFFFFF);
rectChecked.getPaint().setStyle(Paint.Style.STROKE);
rectChecked.getPaint().setStrokeWidth(strokeWidth);
rectChecked.setIntrinsicWidth(bitmap.getWidth() + strokeWidth);
rectChecked.setIntrinsicHeight(bitmap.getHeight() + strokeWidth);
Drawable[] drawableArray = new Drawable[] { bmp, rectChecked };
LayerDrawable layerChecked = new LayerDrawable(drawableArray);
//Unchecked state
ShapeDrawable rectUnchecked = new ShapeDrawable(new RectShape());
rectUnchecked.getPaint().setColor(0x0);
rectUnchecked.getPaint().setStyle(Paint.Style.STROKE);
rectUnchecked.getPaint().setStrokeWidth(strokeWidth);
rectUnchecked.setIntrinsicWidth(bitmap.getWidth() + strokeWidth);
rectUnchecked.setIntrinsicHeight(bitmap.getHeight() + strokeWidth);
Drawable[] drawableArray2 = new Drawable[] { bmp, rectUnchecked };
LayerDrawable layerUnchecked = new LayerDrawable(drawableArray2);
//Statelist drawable
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { android.R.attr.state_checked }, layerChecked);
states.addState(new int[] {}, layerUnchecked);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
setBackground(states);
else
setBackgroundDrawable(states);
//Offset text to center/bottom of the checkbox
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setTextSize(getTextSize());
paint.setTypeface(getTypeface());
float w = paint.measureText(getText(), 0, getText().length());
setPadding(getPaddingLeft() + (int) ((bitmap.getWidth() - w) / 2.f + .5f), getPaddingTop() + (int) (bitmap.getHeight() * 0.70), getPaddingRight(), getPaddingBottom());
setShadowLayer(5, 0, 0, Color.BLACK);
}
use of android.graphics.drawable.StateListDrawable in project ImageWindow by kanytu.
the class ImageWindow method init.
private void init() {
ImageView closeButton = new ImageView(getContext());
closeButton.setLayoutParams(new RelativeLayout.LayoutParams((int) (mCloseButtonSize), (int) (mCloseButtonSize)));
StateListDrawable drawable = new StateListDrawable();
ShapeDrawable shape = new ShapeDrawable(new OvalShape());
ShapeDrawable shapePressed = new ShapeDrawable(new OvalShape());
shape.setColorFilter(mCloseColor, PorterDuff.Mode.SRC_ATOP);
//a little bit darker
shapePressed.setColorFilter(mCloseColor - 0x444444, PorterDuff.Mode.SRC_ATOP);
drawable.addState(new int[] { android.R.attr.state_pressed }, shapePressed);
drawable.addState(new int[] {}, shape);
closeButton.setImageResource(mCloseIcon);
//todo change this to support lower api
closeButton.setBackground(drawable);
closeButton.setClickable(true);
closeButton.setId(R.id.closeId);
mImageView = new CustomImageView(getContext(), mCloseButtonSize, mCloseButtonMargin, mCornerRadius);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(Math.round(mTopLeftMargin), Math.round(mTopLeftMargin), 0, 0);
mImageView.setLayoutParams(params);
mImageView.setAdjustViewBounds(true);
addView(mImageView);
addView(closeButton);
}
use of android.graphics.drawable.StateListDrawable in project ScrollableTabHost-for-Android by honcheng.
the class TabBarButton method setStateImageDrawables.
private void setStateImageDrawables(Drawable onDrawable, Drawable offDrawable) {
StateListDrawable drawables = new StateListDrawable();
int stateChecked = android.R.attr.state_checked;
int stateFocused = android.R.attr.state_focused;
int statePressed = android.R.attr.state_pressed;
int stateWindowFocused = android.R.attr.state_window_focused;
Resources resource = this.getResources();
Drawable xDrawable = resource.getDrawable(R.drawable.bottom_bar_highlight);
drawables.addState(new int[] { stateChecked, -stateWindowFocused }, offDrawable);
drawables.addState(new int[] { -stateChecked, -stateWindowFocused }, offDrawable);
drawables.addState(new int[] { stateChecked, statePressed }, onDrawable);
drawables.addState(new int[] { -stateChecked, statePressed }, onDrawable);
drawables.addState(new int[] { stateChecked, stateFocused }, onDrawable);
drawables.addState(new int[] { -stateChecked, stateFocused }, offDrawable);
drawables.addState(new int[] { stateChecked }, onDrawable);
drawables.addState(new int[] { -stateChecked }, offDrawable);
drawables.addState(new int[] {}, xDrawable);
this.setButtonDrawable(drawables);
}
use of android.graphics.drawable.StateListDrawable in project FastAdapter by mikepenz.
the class FastAdapterUIUtils method getSelectablePressedBackground.
/**
* helper to get the system default selectable background inclusive an active and pressed state
*
* @param ctx the context
* @param selected_color the selected color
* @param pressed_alpha 0-255
* @param animate true if you want to fade over the states (only animates if API newer than Build.VERSION_CODES.HONEYCOMB)
* @return the StateListDrawable
*/
public static StateListDrawable getSelectablePressedBackground(Context ctx, @ColorInt int selected_color, int pressed_alpha, boolean animate) {
StateListDrawable states = getSelectableBackground(ctx, selected_color, animate);
ColorDrawable clrPressed = new ColorDrawable(adjustAlpha(selected_color, pressed_alpha));
states.addState(new int[] { android.R.attr.state_pressed }, clrPressed);
return states;
}
Aggregations