use of android.graphics.drawable.LayerDrawable in project httpclient by pixmob.
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 xabber-android by redsolution.
the class AvatarManager method getDefaultAvatarDrawable.
private Drawable getDefaultAvatarDrawable(BaseAvatarSet.DefaultAvatar defaultAvatar) {
Drawable[] layers = new Drawable[2];
layers[0] = new ColorDrawable(defaultAvatar.getBackgroundColor());
layers[1] = application.getResources().getDrawable(defaultAvatar.getIconResource());
return new LayerDrawable(layers);
}
use of android.graphics.drawable.LayerDrawable in project xabber-android by redsolution.
the class AvatarManager method getDefaultAccountAvatar.
@NonNull
public Drawable getDefaultAccountAvatar(String account) {
Drawable[] layers = new Drawable[2];
layers[0] = new ColorDrawable(ColorManager.getInstance().getAccountPainter().getAccountMainColor(account));
layers[1] = application.getResources().getDrawable(R.drawable.ic_avatar_1);
return new LayerDrawable(layers);
}
use of android.graphics.drawable.LayerDrawable in project robolectric by robolectric.
the class ShadowLayerDrawableTest method setDrawableByLayerId_shouldReturnFalseIfIdNotFound.
@Test
public void setDrawableByLayerId_shouldReturnFalseIfIdNotFound() throws Exception {
LayerDrawable layerDrawable = new LayerDrawable(drawables);
boolean ret = layerDrawable.setDrawableByLayerId(123, drawable4000);
assertFalse(ret);
}
use of android.graphics.drawable.LayerDrawable in project TextDrawable by amulyakhare.
the class DrawableProvider method getRectWithCustomSize.
public Drawable getRectWithCustomSize() {
String leftText = "I";
String rightText = "J";
TextDrawable.IBuilder builder = TextDrawable.builder().beginConfig().width(toPx(29)).withBorder(toPx(2)).endConfig().rect();
TextDrawable left = builder.build(leftText, mGenerator.getColor(leftText));
TextDrawable right = builder.build(rightText, mGenerator.getColor(rightText));
Drawable[] layerList = { new InsetDrawable(left, 0, 0, toPx(31), 0), new InsetDrawable(right, toPx(31), 0, 0, 0) };
return new LayerDrawable(layerList);
}
Aggregations