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;
}
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;
}
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);
}
}
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);
}
}
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);
}
Aggregations