Search in sources :

Example 31 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project BoomMenu by Nightonke.

the class Util method getRectangleStateListBitmapDrawable.

// Bitmap drawable in state-list drawable is able to perform a click-effect.
public static StateListDrawable getRectangleStateListBitmapDrawable(View view, int width, int height, int cornerRadius, int normalColor, int highlightedColor, int unableColor) {
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, getRectangleBitmapDrawable(view, width, height, cornerRadius, highlightedColor));
    stateListDrawable.addState(new int[] { -android.R.attr.state_enabled }, getRectangleBitmapDrawable(view, width, height, cornerRadius, unableColor));
    stateListDrawable.addState(StateSet.WILD_CARD, getRectangleBitmapDrawable(view, width, height, cornerRadius, normalColor));
    return stateListDrawable;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 32 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project BoomMenu by Nightonke.

the class Util method getRectangleStateListGradientDrawable.

// Gradient drawable in state-list drawable is not able to perform a click-effect.
public static StateListDrawable getRectangleStateListGradientDrawable(View view, int cornerRadius, int normalColor, int highlightedColor, int unableColor) {
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, getRectangleDrawable(view, cornerRadius, highlightedColor));
    stateListDrawable.addState(new int[] { -android.R.attr.state_enabled }, getRectangleDrawable(view, cornerRadius, unableColor));
    stateListDrawable.addState(StateSet.WILD_CARD, getRectangleDrawable(view, cornerRadius, normalColor));
    return stateListDrawable;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 33 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project HoloEverywhere by Prototik.

the class ProgressBar method tileify.

private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];
        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i), id == android.R.id.progress || id == android.R.id.secondaryProgress);
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);
        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }
        return newBg;
    } else if (drawable instanceof StateListDrawable) {
        StateListDrawable in = (StateListDrawable) drawable;
        StateListDrawable out = new StateListDrawable();
        int numStates = ReflectHelper.invoke(in, "getStateCount", int.class);
        for (int i = 0; i < numStates; i++) {
            out.addState(ReflectHelper.invoke(in, "getStateSet", int[].class, i), tileify(ReflectHelper.invoke(in, "getStateDrawable", Drawable.class, i), clip));
        }
        return out;
    } else if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }
        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        return clip ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }
    return drawable;
}
Also used : Bitmap(android.graphics.Bitmap) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) BitmapShader(android.graphics.BitmapShader) SuppressLint(android.annotation.SuppressLint) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 34 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 35 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project UltimateRecyclerView by cymcsg.

the class JellyBeanFloatingActionButton method createFillDrawable.

/**
     * more advanced usage for fillable in alpha
     *
     * @param circleRect the defined rectangle
     * @return StateListDrawable item
     */
protected StateListDrawable createFillDrawable(RectF circleRect) {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { android.R.attr.state_pressed }, createAlphaDrawble(circleRect, mColorPressed, mAlpha_press));
    drawable.addState(new int[] {}, createAlphaDrawble(circleRect, mColorNormal, mAlpha_normal));
    return drawable;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Aggregations

StateListDrawable (android.graphics.drawable.StateListDrawable)166 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)17 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 ColorStateList (android.content.res.ColorStateList)8 Paint (android.graphics.Paint)8 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