use of android.graphics.drawable.LayerDrawable in project SmartAndroidSource by jaychou2012.
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 nmid-headline by miao1007.
the class EditPage method genBackground.
private void genBackground() {
background = new ColorDrawable(DIM_COLOR);
if (backgroundView != null) {
try {
Bitmap bgBm = captureView(backgroundView, backgroundView.getWidth(), backgroundView.getHeight());
bgBm = blur(bgBm, 20, 8);
BitmapDrawable blurBm = new BitmapDrawable(activity.getResources(), bgBm);
background = new LayerDrawable(new Drawable[] { blurBm, background });
} catch (Throwable e) {
e.printStackTrace();
}
}
}
use of android.graphics.drawable.LayerDrawable in project MaterialDesignLibrary by navasmdc.
the class Card method setBackgroundColor.
// Set color of background
public void setBackgroundColor(int color) {
this.backgroundColor = color;
if (isEnabled())
beforeBackground = backgroundColor;
LayerDrawable layer = (LayerDrawable) getBackground();
GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
shape.setColor(backgroundColor);
}
use of android.graphics.drawable.LayerDrawable in project MaterialDesignLibrary by navasmdc.
the class Button method setBackgroundColor.
// Set color of background
public void setBackgroundColor(int color) {
this.backgroundColor = color;
if (isEnabled())
beforeBackground = backgroundColor;
try {
LayerDrawable layer = (LayerDrawable) getBackground();
GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
shape.setColor(backgroundColor);
rippleColor = makePressColor();
} catch (Exception ex) {
// Without bacground
}
}
use of android.graphics.drawable.LayerDrawable in project GalleryFinal by pengjianbo.
the class FloatingActionButton method updateBackground.
void updateBackground() {
float circleLeft = mShadowRadius;
float circleTop = mShadowRadius - mShadowOffset;
final RectF circleRect = new RectF(circleLeft, circleTop, circleLeft + mCircleSize, circleTop + mCircleSize);
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { new BitmapDrawable(getResources()), createFillDrawable(circleRect), new BitmapDrawable(getResources()), getIconDrawable() });
float iconOffset = (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2f;
int iconInsetHorizontal = (int) (mShadowRadius + iconOffset);
int iconInsetTop = (int) (circleTop + iconOffset);
int iconInsetBottom = (int) (mShadowRadius + mShadowOffset + iconOffset);
layerDrawable.setLayerInset(3, iconInsetHorizontal, iconInsetTop, iconInsetHorizontal, iconInsetBottom);
setBackgroundCompat(layerDrawable);
}
Aggregations