Search in sources :

Example 21 with LayerDrawable

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;
}
Also used : Bitmap(android.graphics.Bitmap) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapShader(android.graphics.BitmapShader) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 22 with LayerDrawable

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);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 23 with LayerDrawable

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);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) NonNull(android.support.annotation.NonNull)

Example 24 with LayerDrawable

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);
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) Test(org.junit.Test)

Example 25 with LayerDrawable

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);
}
Also used : TextDrawable(com.amulyakhare.textdrawable.TextDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) TextDrawable(com.amulyakhare.textdrawable.TextDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) InsetDrawable(android.graphics.drawable.InsetDrawable)

Aggregations

LayerDrawable (android.graphics.drawable.LayerDrawable)127 Drawable (android.graphics.drawable.Drawable)87 BitmapDrawable (android.graphics.drawable.BitmapDrawable)60 StateListDrawable (android.graphics.drawable.StateListDrawable)44 AnimationDrawable (android.graphics.drawable.AnimationDrawable)42 ClipDrawable (android.graphics.drawable.ClipDrawable)42 ShapeDrawable (android.graphics.drawable.ShapeDrawable)38 Paint (android.graphics.Paint)23 SuppressLint (android.annotation.SuppressLint)19 GradientDrawable (android.graphics.drawable.GradientDrawable)16 Bitmap (android.graphics.Bitmap)14 BitmapShader (android.graphics.BitmapShader)13 ColorDrawable (android.graphics.drawable.ColorDrawable)12 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)8 OvalShape (android.graphics.drawable.shapes.OvalShape)7 Nullable (android.annotation.Nullable)5 Resources (android.content.res.Resources)5 TypedArray (android.content.res.TypedArray)5 InsetDrawable (android.graphics.drawable.InsetDrawable)5 TransitionDrawable (android.graphics.drawable.TransitionDrawable)5