use of android.graphics.drawable.LayerDrawable in project platform_frameworks_base by android.
the class ProgressBar method setVisualProgress.
/**
* Sets the visual state of a progress indicator.
*
* @param id the identifier of the progress indicator
* @param progress the visual progress in the range [0...1]
*/
private void setVisualProgress(int id, float progress) {
mVisualProgress = progress;
Drawable d = mCurrentDrawable;
if (d instanceof LayerDrawable) {
d = ((LayerDrawable) d).findDrawableByLayerId(id);
if (d == null) {
// If we can't find the requested layer, fall back to setting
// the level of the entire drawable. This will break if
// progress is set on multiple elements, but the theme-default
// drawable will always have all layer IDs present.
d = mCurrentDrawable;
}
}
if (d != null) {
final int level = (int) (progress * MAX_LEVEL);
d.setLevel(level);
} else {
invalidate();
}
onVisualProgressChanged(id, progress);
}
use of android.graphics.drawable.LayerDrawable in project platform_frameworks_base by android.
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.LayerDrawable in project Shuttle by timusus.
the class ThemeUtils method themeContextualActionBar.
public static void themeContextualActionBar(Activity activity) {
if (activity != null) {
View v = activity.findViewById(R.id.action_mode_bar);
if (v != null) {
Drawable bottom = CompatUtils.getDrawableCompat(activity, R.drawable.abc_cab_background_top_mtrl_alpha);
if (bottom != null) {
bottom.setColorFilter(ColorUtils.getAccentColor(), PorterDuff.Mode.SRC_ATOP);
}
Drawable background = new ColorDrawable(ColorUtils.getPrimaryColorDark(activity));
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, bottom });
v.setBackgroundDrawable(layerDrawable);
}
}
}
use of android.graphics.drawable.LayerDrawable in project Shuttle by timusus.
the class ThemeUtils method themeSeekBar.
public static void themeSeekBar(Context context, SizableSeekBar seekBar, boolean noBackground) {
int accentColor = ColorUtils.getAccentColor();
if (noBackground) {
if (accentColor == ColorUtils.getPrimaryColor()) {
accentColor = android.graphics.Color.WHITE;
}
}
seekBar.setThumb(DrawableUtils.getColoredDrawable(seekBar.getThumb(), accentColor));
LayerDrawable progressDrawable = (LayerDrawable) seekBar.getProgressDrawable();
progressDrawable.setDrawableByLayerId(android.R.id.progress, DrawableUtils.getColoredDrawable(progressDrawable.findDrawableByLayerId(android.R.id.progress), accentColor));
if (!noBackground) {
int color;
int themeType = getThemeType(context);
if (themeType == ThemeType.TYPE_DARK || themeType == ThemeType.TYPE_SOLID_DARK || themeType == ThemeType.TYPE_BLACK || themeType == ThemeType.TYPE_SOLID_BLACK) {
color = android.graphics.Color.parseColor("#5a5a5a");
} else {
color = android.graphics.Color.parseColor("#bfbfbf");
}
progressDrawable.setDrawableByLayerId(android.R.id.background, DrawableUtils.getColoredDrawable(progressDrawable.findDrawableByLayerId(android.R.id.background), color));
} else {
progressDrawable.setDrawableByLayerId(android.R.id.background, new ColorDrawable(context.getResources().getColor(android.R.color.transparent)));
}
}
use of android.graphics.drawable.LayerDrawable in project PagerSlidingTabStrip by astuetz.
the class MainActivity method changeColor.
private void changeColor(int newColor) {
tabs.setIndicatorColor(newColor);
// change ActionBar color just if an ActionBar is available
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Drawable colorDrawable = new ColorDrawable(newColor);
Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom);
LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });
if (oldBackground == null) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
ld.setCallback(drawableCallback);
} else {
getActionBar().setBackgroundDrawable(ld);
}
} else {
TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
// https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
td.setCallback(drawableCallback);
} else {
getActionBar().setBackgroundDrawable(td);
}
td.startTransition(200);
}
oldBackground = ld;
// http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setDisplayShowTitleEnabled(true);
}
currentColor = newColor;
}
Aggregations