Search in sources :

Example 21 with StateListDrawable

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;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 22 with StateListDrawable

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);
}
Also used : RectShape(android.graphics.drawable.shapes.RectShape) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint) StateListDrawable(android.graphics.drawable.StateListDrawable) Paint(android.graphics.Paint)

Example 23 with StateListDrawable

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);
}
Also used : RelativeLayout(android.widget.RelativeLayout) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ImageView(android.widget.ImageView) StateListDrawable(android.graphics.drawable.StateListDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 24 with StateListDrawable

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);
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) Drawable(android.graphics.drawable.Drawable) Resources(android.content.res.Resources) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 25 with StateListDrawable

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;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Aggregations

StateListDrawable (android.graphics.drawable.StateListDrawable)163 Drawable (android.graphics.drawable.Drawable)43 LayerDrawable (android.graphics.drawable.LayerDrawable)24 BitmapDrawable (android.graphics.drawable.BitmapDrawable)21 GradientDrawable (android.graphics.drawable.GradientDrawable)21 ColorDrawable (android.graphics.drawable.ColorDrawable)15 Bitmap (android.graphics.Bitmap)13 TextView (android.widget.TextView)12 ShapeDrawable (android.graphics.drawable.ShapeDrawable)11 View (android.view.View)11 AnimationDrawable (android.graphics.drawable.AnimationDrawable)9 ClipDrawable (android.graphics.drawable.ClipDrawable)9 SuppressLint (android.annotation.SuppressLint)8 Paint (android.graphics.Paint)8 ColorStateList (android.content.res.ColorStateList)7 RippleDrawable (android.graphics.drawable.RippleDrawable)7 TargetApi (android.annotation.TargetApi)6 TypedArray (android.content.res.TypedArray)6 TextPaint (android.text.TextPaint)5 Button (android.widget.Button)5