Search in sources :

Example 1 with DrawableWrapper

use of android.support.v4.graphics.drawable.DrawableWrapper in project Android-skin-support by ximsfei.

the class SkinCompatProgressBarHelper 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 DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else 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 if (drawable instanceof BitmapDrawable) {
        final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        final Bitmap tileBitmap = bitmapDrawable.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);
        shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter());
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }
    return drawable;
}
Also used : Bitmap(android.graphics.Bitmap) DrawableWrapper(android.support.v4.graphics.drawable.DrawableWrapper) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) 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) BitmapShader(android.graphics.BitmapShader) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 2 with DrawableWrapper

use of android.support.v4.graphics.drawable.DrawableWrapper in project wire-android by wireapp.

the class AddPhoneNumberPreferenceDialogFragment method clearColorFilter.

// from TextInputLayout
@TargetApi(Build.VERSION_CODES.KITKAT)
private static void clearColorFilter(@NonNull Drawable drawable) {
    drawable.clearColorFilter();
    if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) {
        // children manually
        if (drawable instanceof InsetDrawable) {
            clearColorFilter(((InsetDrawable) drawable).getDrawable());
        } else if (drawable instanceof DrawableWrapper) {
            clearColorFilter(((DrawableWrapper) drawable).getWrappedDrawable());
        } else if (drawable instanceof DrawableContainer) {
            final DrawableContainer container = (DrawableContainer) drawable;
            final DrawableContainer.DrawableContainerState state = (DrawableContainer.DrawableContainerState) container.getConstantState();
            if (state != null) {
                for (int i = 0, count = state.getChildCount(); i < count; i++) {
                    clearColorFilter(state.getChild(i));
                }
            }
        }
    }
}
Also used : DrawableWrapper(android.support.v4.graphics.drawable.DrawableWrapper) InsetDrawable(android.graphics.drawable.InsetDrawable) DrawableContainer(android.graphics.drawable.DrawableContainer) SuppressLint(android.annotation.SuppressLint) TargetApi(android.annotation.TargetApi)

Aggregations

DrawableWrapper (android.support.v4.graphics.drawable.DrawableWrapper)2 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Bitmap (android.graphics.Bitmap)1 BitmapShader (android.graphics.BitmapShader)1 AnimationDrawable (android.graphics.drawable.AnimationDrawable)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ClipDrawable (android.graphics.drawable.ClipDrawable)1 Drawable (android.graphics.drawable.Drawable)1 DrawableContainer (android.graphics.drawable.DrawableContainer)1 InsetDrawable (android.graphics.drawable.InsetDrawable)1 LayerDrawable (android.graphics.drawable.LayerDrawable)1 ShapeDrawable (android.graphics.drawable.ShapeDrawable)1