use of android.graphics.drawable.StateListDrawable in project android_frameworks_base by AOSPA.
the class ProgressBar method tileify.
/**
* Converts a drawable to a tiled version of itself. It will recursively
* traverse layer and state list drawables.
*/
private Drawable tileify(Drawable drawable, boolean clip) {
if (drawable instanceof LayerDrawable) {
final LayerDrawable orig = (LayerDrawable) drawable;
final int N = orig.getNumberOfLayers();
final Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
final int id = orig.getId(i);
outDrawables[i] = tileify(orig.getDrawable(i), (id == R.id.progress || id == R.id.secondaryProgress));
}
final LayerDrawable clone = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
clone.setId(i, orig.getId(i));
clone.setLayerGravity(i, orig.getLayerGravity(i));
clone.setLayerWidth(i, orig.getLayerWidth(i));
clone.setLayerHeight(i, orig.getLayerHeight(i));
clone.setLayerInsetLeft(i, orig.getLayerInsetLeft(i));
clone.setLayerInsetRight(i, orig.getLayerInsetRight(i));
clone.setLayerInsetTop(i, orig.getLayerInsetTop(i));
clone.setLayerInsetBottom(i, orig.getLayerInsetBottom(i));
clone.setLayerInsetStart(i, orig.getLayerInsetStart(i));
clone.setLayerInsetEnd(i, orig.getLayerInsetEnd(i));
}
return clone;
}
if (drawable instanceof StateListDrawable) {
final StateListDrawable in = (StateListDrawable) drawable;
final StateListDrawable out = new StateListDrawable();
final int N = in.getStateCount();
for (int i = 0; i < N; i++) {
out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
}
return out;
}
if (drawable instanceof BitmapDrawable) {
final Drawable.ConstantState cs = drawable.getConstantState();
final BitmapDrawable clone = (BitmapDrawable) cs.newDrawable(getResources());
clone.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
if (mSampleWidth <= 0) {
mSampleWidth = clone.getIntrinsicWidth();
}
if (clip) {
return new ClipDrawable(clone, Gravity.LEFT, ClipDrawable.HORIZONTAL);
} else {
return clone;
}
}
return drawable;
}
use of android.graphics.drawable.StateListDrawable in project SublimePicker by vikramkakkar.
the class SUtils method createButtonNormalBg.
// Button bg for API version < Lollipop
private static Drawable createButtonNormalBg(Context context, int colorControlHighlight) {
StateListDrawable sld = new StateListDrawable();
sld.addState(new int[] { android.R.attr.state_pressed }, createButtonShape(context, colorControlHighlight));
sld.addState(new int[] {}, new ColorDrawable(Color.TRANSPARENT));
return sld;
}
use of android.graphics.drawable.StateListDrawable in project SublimePicker by vikramkakkar.
the class SublimeRecurrencePicker method createStateListDrawableForOption.
private Drawable createStateListDrawableForOption(int pressedBgColor) {
StateListDrawable sld = new StateListDrawable();
sld.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(pressedBgColor));
sld.addState(new int[] {}, new ColorDrawable(Color.TRANSPARENT));
return sld;
}
use of android.graphics.drawable.StateListDrawable in project wire-android by wireapp.
the class ConfirmationMenu method getButtonBackground.
private Drawable getButtonBackground(int borderColor, int fillColor, int strokeWidth, int cornerRadius) {
int fillColorPressed = getPressColor(PRESSED_ALPHA, fillColor);
int borderColorPressed = getPressColor(PRESSED_ALPHA, borderColor);
GradientDrawable gradientDrawablePressed = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { fillColorPressed, fillColorPressed });
gradientDrawablePressed.setStroke(strokeWidth, borderColorPressed);
gradientDrawablePressed.setCornerRadius(cornerRadius);
GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { fillColor, fillColor });
gradientDrawable.setStroke(strokeWidth, borderColor);
gradientDrawable.setCornerRadius(cornerRadius);
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { android.R.attr.state_pressed }, gradientDrawablePressed);
states.addState(new int[] { android.R.attr.state_focused }, gradientDrawablePressed);
states.addState(new int[] {}, gradientDrawable);
return states;
}
use of android.graphics.drawable.StateListDrawable in project android_frameworks_base by crdroidandroid.
the class ProgressBar method tileify.
/**
* Converts a drawable to a tiled version of itself. It will recursively
* traverse layer and state list drawables.
*/
private Drawable tileify(Drawable drawable, boolean clip) {
if (drawable instanceof LayerDrawable) {
final LayerDrawable orig = (LayerDrawable) drawable;
final int N = orig.getNumberOfLayers();
final Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
final int id = orig.getId(i);
outDrawables[i] = tileify(orig.getDrawable(i), (id == R.id.progress || id == R.id.secondaryProgress));
}
final LayerDrawable clone = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
clone.setId(i, orig.getId(i));
clone.setLayerGravity(i, orig.getLayerGravity(i));
clone.setLayerWidth(i, orig.getLayerWidth(i));
clone.setLayerHeight(i, orig.getLayerHeight(i));
clone.setLayerInsetLeft(i, orig.getLayerInsetLeft(i));
clone.setLayerInsetRight(i, orig.getLayerInsetRight(i));
clone.setLayerInsetTop(i, orig.getLayerInsetTop(i));
clone.setLayerInsetBottom(i, orig.getLayerInsetBottom(i));
clone.setLayerInsetStart(i, orig.getLayerInsetStart(i));
clone.setLayerInsetEnd(i, orig.getLayerInsetEnd(i));
}
return clone;
}
if (drawable instanceof StateListDrawable) {
final StateListDrawable in = (StateListDrawable) drawable;
final StateListDrawable out = new StateListDrawable();
final int N = in.getStateCount();
for (int i = 0; i < N; i++) {
out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
}
return out;
}
if (drawable instanceof BitmapDrawable) {
final Drawable.ConstantState cs = drawable.getConstantState();
final BitmapDrawable clone = (BitmapDrawable) cs.newDrawable(getResources());
clone.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
if (mSampleWidth <= 0) {
mSampleWidth = clone.getIntrinsicWidth();
}
if (clip) {
return new ClipDrawable(clone, Gravity.LEFT, ClipDrawable.HORIZONTAL);
} else {
return clone;
}
}
return drawable;
}
Aggregations