use of android.graphics.drawable.LayerDrawable in project FloatingActionButton by Clans.
the class FloatingActionButton method updateBackground.
void updateBackground() {
LayerDrawable layerDrawable;
if (hasShadow()) {
layerDrawable = new LayerDrawable(new Drawable[] { new Shadow(), createFillDrawable(), getIconDrawable() });
} else {
layerDrawable = new LayerDrawable(new Drawable[] { createFillDrawable(), getIconDrawable() });
}
int iconSize = -1;
if (getIconDrawable() != null) {
iconSize = Math.max(getIconDrawable().getIntrinsicWidth(), getIconDrawable().getIntrinsicHeight());
}
int iconOffset = (getCircleSize() - (iconSize > 0 ? iconSize : mIconSize)) / 2;
int circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0;
int circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0;
if (mProgressBarEnabled) {
circleInsetHorizontal += mProgressWidth;
circleInsetVertical += mProgressWidth;
}
/*layerDrawable.setLayerInset(
mShowShadow ? 1 : 0,
circleInsetHorizontal,
circleInsetVertical,
circleInsetHorizontal,
circleInsetVertical
);*/
layerDrawable.setLayerInset(hasShadow() ? 2 : 1, circleInsetHorizontal + iconOffset, circleInsetVertical + iconOffset, circleInsetHorizontal + iconOffset, circleInsetVertical + iconOffset);
setBackgroundCompat(layerDrawable);
}
use of android.graphics.drawable.LayerDrawable in project FloatingActionButton by Clans.
the class Label method updateBackground.
void updateBackground() {
LayerDrawable layerDrawable;
if (mShowShadow) {
layerDrawable = new LayerDrawable(new Drawable[] { new Shadow(), createFillDrawable() });
int leftInset = mShadowRadius + Math.abs(mShadowXOffset);
int topInset = mShadowRadius + Math.abs(mShadowYOffset);
int rightInset = (mShadowRadius + Math.abs(mShadowXOffset));
int bottomInset = (mShadowRadius + Math.abs(mShadowYOffset));
layerDrawable.setLayerInset(1, leftInset, topInset, rightInset, bottomInset);
} else {
layerDrawable = new LayerDrawable(new Drawable[] { createFillDrawable() });
}
setBackgroundCompat(layerDrawable);
}
use of android.graphics.drawable.LayerDrawable in project ActionBarSherlock by JakeWharton.
the class IcsProgressBar 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) {
LayerDrawable background = (LayerDrawable) drawable;
final int N = background.getNumberOfLayers();
Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
int id = background.getId(i);
outDrawables[i] = tileify(background.getDrawable(i), (id == android.R.id.progress || id == android.R.id.secondaryProgress));
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else /* else if (drawable instanceof StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = in.getStateCount();
for (int i = 0; i < numStates; i++) {
out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
}
return out;
}*/
if (drawable instanceof BitmapDrawable) {
final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
if (mSampleTile == null) {
mSampleTile = tileBitmap;
}
final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
shapeDrawable.getPaint().setShader(bitmapShader);
return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
}
return drawable;
}
use of android.graphics.drawable.LayerDrawable in project UltimateAndroid by cymcsg.
the class ViewpagerSlidingTabsActivity 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.view_sliding_tab_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;
}
use of android.graphics.drawable.LayerDrawable in project android_frameworks_base by DirtyUnicorns.
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);
}
Aggregations