Search in sources :

Example 1 with ClipDrawable

use of android.graphics.drawable.ClipDrawable in project cw-omnibus by commonsguy.

the class IcsProgressBar method tileifyIndeterminate.

/**
     * Convert a AnimationDrawable for use as a barberpole animation.
     * Each frame of the animation is wrapped in a ClipDrawable and
     * given a tiling BitmapShader.
     */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());
        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) 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)

Example 2 with ClipDrawable

use of android.graphics.drawable.ClipDrawable in project FlatUI by eluleci.

the class FlatSeekBar method init.

private void init(AttributeSet attrs) {
    if (attributes == null)
        attributes = new Attributes(this, getResources());
    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, com.cengalabs.flatui.R.styleable.fl_FlatSeekBar);
        // getting common attributes
        int customTheme = a.getResourceId(com.cengalabs.flatui.R.styleable.fl_FlatSeekBar_fl_theme, Attributes.DEFAULT_THEME);
        attributes.setThemeSilent(customTheme, getResources());
        attributes.setSize(a.getDimensionPixelSize(com.cengalabs.flatui.R.styleable.fl_FlatSeekBar_fl_size, Attributes.DEFAULT_SIZE_PX));
        a.recycle();
    }
    // setting thumb
    PaintDrawable thumb = new PaintDrawable(attributes.getColor(0));
    thumb.setCornerRadius(attributes.getSize() * 9 / 8);
    thumb.setIntrinsicWidth(attributes.getSize() * 9 / 4);
    thumb.setIntrinsicHeight(attributes.getSize() * 9 / 4);
    setThumb(thumb);
    // progress
    PaintDrawable progress = new PaintDrawable(attributes.getColor(1));
    progress.setCornerRadius(attributes.getSize());
    progress.setIntrinsicHeight(attributes.getSize());
    progress.setIntrinsicWidth(attributes.getSize());
    progress.setDither(true);
    ClipDrawable progressClip = new ClipDrawable(progress, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    // secondary progress
    PaintDrawable secondary = new PaintDrawable(attributes.getColor(2));
    secondary.setCornerRadius(attributes.getSize());
    secondary.setIntrinsicHeight(attributes.getSize());
    ClipDrawable secondaryProgressClip = new ClipDrawable(secondary, Gravity.LEFT, ClipDrawable.HORIZONTAL);
    // background
    PaintDrawable background = new PaintDrawable(attributes.getColor(3));
    background.setCornerRadius(attributes.getSize());
    background.setIntrinsicHeight(attributes.getSize());
    // applying drawable
    LayerDrawable ld = (LayerDrawable) getProgressDrawable();
    ld.setDrawableByLayerId(R.id.background, background);
    ld.setDrawableByLayerId(R.id.progress, progressClip);
    ld.setDrawableByLayerId(R.id.secondaryProgress, secondaryProgressClip);
}
Also used : TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) Attributes(com.cengalabs.flatui.Attributes) PaintDrawable(android.graphics.drawable.PaintDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 3 with ClipDrawable

use of android.graphics.drawable.ClipDrawable in project Libraries-for-Android-Developers by eoecn.

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 4 with ClipDrawable

use of android.graphics.drawable.ClipDrawable in project Libraries-for-Android-Developers by eoecn.

the class IcsProgressBar method tileifyIndeterminate.

/**
     * Convert a AnimationDrawable for use as a barberpole animation.
     * Each frame of the animation is wrapped in a ClipDrawable and
     * given a tiling BitmapShader.
     */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());
        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) 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)

Example 5 with ClipDrawable

use of android.graphics.drawable.ClipDrawable in project android_frameworks_base by ParanoidAndroid.

the class ProgressBar method tileifyIndeterminate.

/**
     * Convert a AnimationDrawable for use as a barberpole animation.
     * Each frame of the animation is wrapped in a ClipDrawable and
     * given a tiling BitmapShader.
     */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());
        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Aggregations

ClipDrawable (android.graphics.drawable.ClipDrawable)40 BitmapDrawable (android.graphics.drawable.BitmapDrawable)35 Drawable (android.graphics.drawable.Drawable)35 LayerDrawable (android.graphics.drawable.LayerDrawable)35 AnimationDrawable (android.graphics.drawable.AnimationDrawable)34 ShapeDrawable (android.graphics.drawable.ShapeDrawable)27 StateListDrawable (android.graphics.drawable.StateListDrawable)16 Bitmap (android.graphics.Bitmap)13 BitmapShader (android.graphics.BitmapShader)13 RectShape (android.graphics.drawable.shapes.RectShape)3 SuppressLint (android.annotation.SuppressLint)2 TypedArray (android.content.res.TypedArray)1 RectF (android.graphics.RectF)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 PaintDrawable (android.graphics.drawable.PaintDrawable)1 RotateDrawable (android.graphics.drawable.RotateDrawable)1 ScaleDrawable (android.graphics.drawable.ScaleDrawable)1 TransitionDrawable (android.graphics.drawable.TransitionDrawable)1 Handler (android.os.Handler)1 DrawableWrapper (android.support.v4.graphics.drawable.DrawableWrapper)1