use of android.graphics.drawable.StateListDrawable in project Launcher3 by chislon.
the class HolographicLinearLayout method drawableStateChanged.
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
if (mImageView != null) {
mHolographicHelper.generatePressedFocusedStates(mImageView);
Drawable d = mImageView.getDrawable();
if (d instanceof StateListDrawable) {
StateListDrawable sld = (StateListDrawable) d;
sld.setState(getDrawableState());
sld.invalidateSelf();
}
}
}
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;
}
use of android.graphics.drawable.StateListDrawable in project circular-progress-button by dmytrodanylyk.
the class CircularProgressButton method initErrorStateDrawable.
private void initErrorStateDrawable() {
int colorPressed = getPressedColor(mErrorColorState);
StrokeGradientDrawable drawablePressed = createDrawable(colorPressed);
mErrorStateDrawable = new StateListDrawable();
mErrorStateDrawable.addState(new int[] { android.R.attr.state_pressed }, drawablePressed.getGradientDrawable());
mErrorStateDrawable.addState(StateSet.WILD_CARD, background.getGradientDrawable());
}
use of android.graphics.drawable.StateListDrawable in project FlexibleAdapter by davideas.
the class FastScroller method setBubbleAndHandleColor.
private void setBubbleAndHandleColor(int accentColor) {
//TODO: Programmatically generate the Drawables instead of using resources
//BubbleDrawable accentColor
GradientDrawable bubbleDrawable;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
bubbleDrawable = (GradientDrawable) getResources().getDrawable(R.drawable.fast_scroller_bubble, null);
} else {
//noinspection deprecation
bubbleDrawable = (GradientDrawable) getResources().getDrawable(R.drawable.fast_scroller_bubble);
}
assert bubbleDrawable != null;
bubbleDrawable.setColor(accentColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
bubble.setBackground(bubbleDrawable);
} else {
//noinspection deprecation
bubble.setBackgroundDrawable(bubbleDrawable);
}
//HandleDrawable accentColor
try {
StateListDrawable stateListDrawable;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
stateListDrawable = (StateListDrawable) getResources().getDrawable(R.drawable.fast_scroller_handle, null);
} else {
//noinspection deprecation
stateListDrawable = (StateListDrawable) getResources().getDrawable(R.drawable.fast_scroller_handle);
}
//Method is still hidden, invoke Java reflection
Method getStateDrawable = StateListDrawable.class.getMethod("getStateDrawable", int.class);
GradientDrawable handleDrawable = (GradientDrawable) getStateDrawable.invoke(stateListDrawable, 0);
handleDrawable.setColor(accentColor);
handle.setImageDrawable(stateListDrawable);
} catch (Exception e) {
e.printStackTrace();
}
}
use of android.graphics.drawable.StateListDrawable in project FlatUI by eluleci.
the class FlatCheckBox method init.
private void init(AttributeSet attrs) {
if (attributes == null)
attributes = new Attributes(this, getResources());
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatCheckBox);
// getting common attributes
int customTheme = a.getResourceId(R.styleable.fl_FlatCheckBox_fl_theme, Attributes.DEFAULT_THEME);
attributes.setThemeSilent(customTheme, getResources());
attributes.setFontFamily(a.getString(R.styleable.fl_FlatCheckBox_fl_fontFamily));
attributes.setFontWeight(a.getString(R.styleable.fl_FlatCheckBox_fl_fontWeight));
attributes.setFontExtension(a.getString(R.styleable.fl_FlatCheckBox_fl_fontExtension));
attributes.setSize(a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_size, Attributes.DEFAULT_SIZE_PX));
attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
attributes.setBorderWidth(attributes.getSize() / 10);
// getting view specific attributes
dotMargin = a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_dotMargin, dotMargin);
a.recycle();
}
// creating unchecked-enabled state drawable
GradientDrawable uncheckedEnabled = new GradientDrawable();
uncheckedEnabled.setCornerRadius(attributes.getRadius());
uncheckedEnabled.setSize(attributes.getSize(), attributes.getSize());
uncheckedEnabled.setColor(Color.TRANSPARENT);
uncheckedEnabled.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
// creating checked-enabled state drawable
GradientDrawable checkedOutside = new GradientDrawable();
checkedOutside.setCornerRadius(attributes.getRadius());
checkedOutside.setSize(attributes.getSize(), attributes.getSize());
checkedOutside.setColor(Color.TRANSPARENT);
checkedOutside.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
PaintDrawable checkedCore = new PaintDrawable(attributes.getColor(2));
checkedCore.setCornerRadius(attributes.getRadius());
checkedCore.setIntrinsicHeight(attributes.getSize());
checkedCore.setIntrinsicWidth(attributes.getSize());
InsetDrawable checkedInside = new InsetDrawable(checkedCore, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
Drawable[] checkedEnabledDrawable = { checkedOutside, checkedInside };
LayerDrawable checkedEnabled = new LayerDrawable(checkedEnabledDrawable);
// creating unchecked-enabled state drawable
GradientDrawable uncheckedDisabled = new GradientDrawable();
uncheckedDisabled.setCornerRadius(attributes.getRadius());
uncheckedDisabled.setSize(attributes.getSize(), attributes.getSize());
uncheckedDisabled.setColor(Color.TRANSPARENT);
uncheckedDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
// creating checked-disabled state drawable
GradientDrawable checkedOutsideDisabled = new GradientDrawable();
checkedOutsideDisabled.setCornerRadius(attributes.getRadius());
checkedOutsideDisabled.setSize(attributes.getSize(), attributes.getSize());
checkedOutsideDisabled.setColor(Color.TRANSPARENT);
checkedOutsideDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
PaintDrawable checkedCoreDisabled = new PaintDrawable(attributes.getColor(3));
checkedCoreDisabled.setCornerRadius(attributes.getRadius());
checkedCoreDisabled.setIntrinsicHeight(attributes.getSize());
checkedCoreDisabled.setIntrinsicWidth(attributes.getSize());
InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
Drawable[] checkedDisabledDrawable = { checkedOutsideDisabled, checkedInsideDisabled };
LayerDrawable checkedDisabled = new LayerDrawable(checkedDisabledDrawable);
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_enabled }, uncheckedEnabled);
states.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, checkedEnabled);
states.addState(new int[] { -android.R.attr.state_checked, -android.R.attr.state_enabled }, uncheckedDisabled);
states.addState(new int[] { android.R.attr.state_checked, -android.R.attr.state_enabled }, checkedDisabled);
setButtonDrawable(states);
// setting padding for avoiding text to appear on icon
setPadding(attributes.getSize() / 4 * 5, 0, 0, 0);
setTextColor(attributes.getColor(2));
// check for IDE preview render
if (!this.isInEditMode()) {
Typeface typeface = FlatUI.getFont(getContext(), attributes);
if (typeface != null)
setTypeface(typeface);
}
}
Aggregations