Search in sources :

Example 51 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project Android-Bootstrap by Bearded-Hen.

the class BootstrapDrawableFactory method setupStateDrawable.

private static StateListDrawable setupStateDrawable(ViewGroupPosition position, int strokeWidth, GradientDrawable defaultGd, GradientDrawable activeGd, GradientDrawable disabledGd) {
    StateListDrawable stateListDrawable = new StateListDrawable();
    LayerDrawable defaultLayer = new LayerDrawable(new Drawable[] { defaultGd });
    LayerDrawable activeLayer = new LayerDrawable(new Drawable[] { activeGd });
    LayerDrawable disabledLayer = new LayerDrawable(new Drawable[] { disabledGd });
    LayerDrawable[] ldAry = new LayerDrawable[] { defaultLayer, activeLayer, disabledLayer };
    int n = strokeWidth * -1;
    // use LayerDrawable to hide strokes on one side of the drawable (if needed), using negative insets
    if (position != null) {
        switch(position) {
            case MIDDLE_HORI:
                setInsetOnLayers(ldAry, n, 0, 0, 0);
                break;
            case END:
                setInsetOnLayers(ldAry, n, 0, 0, 0);
                break;
            case MIDDLE_VERT:
                setInsetOnLayers(ldAry, 0, n, 0, 0);
                break;
            case BOTTOM:
                setInsetOnLayers(ldAry, 0, n, 0, 0);
        }
    }
    if (Build.VERSION.SDK_INT >= 14) {
        stateListDrawable.addState(new int[] { android.R.attr.state_hovered }, activeLayer);
    }
    stateListDrawable.addState(new int[] { android.R.attr.state_activated }, activeLayer);
    stateListDrawable.addState(new int[] { android.R.attr.state_focused }, activeLayer);
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, activeLayer);
    stateListDrawable.addState(new int[] { android.R.attr.state_selected }, activeLayer);
    stateListDrawable.addState(new int[] { -android.R.attr.state_enabled }, disabledLayer);
    stateListDrawable.addState(new int[] {}, defaultLayer);
    return stateListDrawable;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 52 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project Android-Bootstrap by Bearded-Hen.

the class BootstrapDrawableFactory method bootstrapAlertCloseIcon.

static StateListDrawable bootstrapAlertCloseIcon(Context context, int width, int height, int inset) {
    StateListDrawable stateListDrawable = new StateListDrawable();
    int defaultColor = ColorUtils.resolveColor(R.color.bootstrap_alert_cross_default, context);
    int activeColor = ColorUtils.resolveColor(R.color.bootstrap_gray, context);
    int disabledColor = ColorUtils.resolveColor(R.color.bootstrap_alert_cross_default, context);
    if (Build.VERSION.SDK_INT >= 14) {
        stateListDrawable.addState(new int[] { android.R.attr.state_hovered }, createCloseCrossIcon(context, width, height, activeColor, inset));
    }
    stateListDrawable.addState(new int[] { android.R.attr.state_activated }, createCloseCrossIcon(context, width, height, activeColor, inset));
    stateListDrawable.addState(new int[] { android.R.attr.state_focused }, createCloseCrossIcon(context, width, height, activeColor, inset));
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, createCloseCrossIcon(context, width, height, activeColor, inset));
    stateListDrawable.addState(new int[] { android.R.attr.state_selected }, createCloseCrossIcon(context, width, height, activeColor, inset));
    stateListDrawable.addState(new int[] { -android.R.attr.state_enabled }, createCloseCrossIcon(context, width, height, disabledColor, inset));
    stateListDrawable.addState(new int[] {}, createCloseCrossIcon(context, width, height, defaultColor, inset));
    return stateListDrawable;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 53 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project FloatingActionButton by Clans.

the class FloatingActionButton method onActionDown.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed });
    } else if (Util.hasLollipop()) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed });
        ripple.setHotspot(calculateCenterX(), calculateCenterY());
        ripple.setVisible(true, true);
    }
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

Example 54 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project FloatingActionButton by Clans.

the class FloatingActionButton method onActionUp.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[] { android.R.attr.state_enabled });
    } else if (Util.hasLollipop()) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[] { android.R.attr.state_enabled });
        ripple.setHotspot(calculateCenterX(), calculateCenterY());
        ripple.setVisible(true, true);
    }
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

Example 55 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project FloatingActionButton by Clans.

the class Label method onActionUp.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
    if (mUsingStyle) {
        mBackgroundDrawable = getBackground();
    }
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[] {});
    } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[] {});
        ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        ripple.setVisible(true, true);
    }
//        setPressed(false);
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

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