Search in sources :

Example 31 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project android_packages_apps_OmniClock by omnirom.

the class ColorPickerPreference method createRectShape.

private static ShapeDrawable createRectShape(int width, int height, int color) {
    ShapeDrawable shape = new ShapeDrawable(new RectShape());
    shape.setIntrinsicHeight(height);
    shape.setIntrinsicWidth(width);
    shape.getPaint().setColor(color);
    return shape;
}
Also used : RectShape(android.graphics.drawable.shapes.RectShape) ShapeDrawable(android.graphics.drawable.ShapeDrawable)

Example 32 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project Genius-Android by qiujuer.

the class TextView method setBorder.

/**
 * Set the border, You can init border size, color and decision that direction contains border
 *
 * @param flag  use {@link #BORDER_ALL } if you need All border,
 *              or {@link #BORDER_LEFT} the view will have Left border
 *              of case you can use eg: {@link #BORDER_LEFT}|{@link #BORDER_BOTTOM}
 *              the view will left and bottom border
 *              <p>
 *              if you not use border you need set the flag to 0
 * @param size  set all border size, unit is px, if you use dp, plx see {@link Ui#dipToPx(Resources, float)} )}
 * @param color set all border color
 */
public void setBorder(int flag, int size, int color) {
    if (mBorder != flag || mBorderSize != size || mBorderColor != color) {
        mBorder = flag;
        mBorderSize = size;
        mBorderColor = color;
        if (flag <= 0) {
            mBorderDrawable = null;
        } else {
            RectF borderRect;
            if ((flag & BORDER_ALL) == BORDER_ALL)
                borderRect = new RectF(size, size, size, size);
            else {
                int l = 0, t = 0, r = 0, b = 0;
                if ((flag & BORDER_LEFT) == BORDER_LEFT)
                    l = size;
                if ((flag & BORDER_RIGHT) == BORDER_RIGHT)
                    r = size;
                if ((flag & BORDER_TOP) == BORDER_TOP)
                    t = size;
                if ((flag & BORDER_BOTTOM) == BORDER_BOTTOM)
                    b = size;
                borderRect = new RectF(l, t, r, b);
            }
            if (mBorderDrawable == null) {
                ShapeDrawable drawable = new ShapeDrawable(new BorderShape(borderRect));
                Paint paint = drawable.getPaint();
                paint.setColor(color);
                drawable.setCallback(this);
                mBorderDrawable = drawable;
            } else {
                ShapeDrawable drawable = (ShapeDrawable) mBorderDrawable;
                Paint paint = drawable.getPaint();
                paint.setColor(color);
                BorderShape shape = (BorderShape) drawable.getShape();
                shape.setBorder(borderRect);
            }
        }
        invalidate();
    }
}
Also used : RectF(android.graphics.RectF) BorderShape(net.qiujuer.genius.ui.drawable.shape.BorderShape) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 33 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project MDM-Android-Agent by wso2-attic.

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 34 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project android_packages_apps_DU-Tweaks by DirtyUnicorns.

the class NotificationLightPreference method createOvalShape.

private static ShapeDrawable createOvalShape(int size, int color) {
    ShapeDrawable shape = new ShapeDrawable(new OvalShape());
    shape.setIntrinsicHeight(size);
    shape.setIntrinsicWidth(size);
    shape.getPaint().setColor(color);
    return shape;
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 35 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project android_packages_apps_DU-Tweaks by DirtyUnicorns.

the class ColorPickerPreference method createOvalShape.

private static ShapeDrawable createOvalShape(int size, int color) {
    ShapeDrawable shape = new ShapeDrawable(new OvalShape());
    shape.setIntrinsicHeight(size);
    shape.setIntrinsicWidth(size);
    shape.getPaint().setColor(color);
    return shape;
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape)

Aggregations

ShapeDrawable (android.graphics.drawable.ShapeDrawable)131 OvalShape (android.graphics.drawable.shapes.OvalShape)64 Paint (android.graphics.Paint)38 Drawable (android.graphics.drawable.Drawable)30 LayerDrawable (android.graphics.drawable.LayerDrawable)28 SuppressLint (android.annotation.SuppressLint)20 RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)20 StateListDrawable (android.graphics.drawable.StateListDrawable)18 ClipDrawable (android.graphics.drawable.ClipDrawable)17 Bitmap (android.graphics.Bitmap)16 BitmapDrawable (android.graphics.drawable.BitmapDrawable)16 BitmapShader (android.graphics.BitmapShader)15 AnimationDrawable (android.graphics.drawable.AnimationDrawable)14 ColorDrawable (android.graphics.drawable.ColorDrawable)11 RectShape (android.graphics.drawable.shapes.RectShape)10 Resources (android.content.res.Resources)8 Shape (android.graphics.drawable.shapes.Shape)8 Canvas (android.graphics.Canvas)6 Shader (android.graphics.Shader)6 ImageView (android.widget.ImageView)6