Search in sources :

Example 76 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project weex-example by KalicyZhou.

the class CircleProgressBar method setBackgroundColorResource.

/**
   * Update the background color of the mBgCircle image view.
   */
public void setBackgroundColorResource(int colorRes) {
    if (getBackground() instanceof ShapeDrawable) {
        final Resources res = getResources();
        ((ShapeDrawable) getBackground()).getPaint().setColor(res.getColor(colorRes));
    }
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) Resources(android.content.res.Resources)

Example 77 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project wire-android by wireapp.

the class ConversationQuickMenu method setAccentColor.

public void setAccentColor(int color) {
    conversationButton.setAccentColor(color);
    ShapeDrawable ovalBackground = new ShapeDrawable(new OvalShape());
    ovalBackground.getPaint().setColor(color);
    ovalBackground.getPaint().setStyle(Paint.Style.FILL);
    ovalBackground.getPaint().setAntiAlias(true);
    cameraButton.setBackground(ovalBackground);
    callButton.setBackground(ovalBackground);
    videoCallButton.setBackground(ovalBackground);
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 78 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project wire-android by wireapp.

the class AccentColorEditText method updateCursor.

protected void updateCursor() {
    ShapeDrawable cursorDrawable = new ShapeDrawable(new RectShape());
    cursorDrawable.setIntrinsicWidth(ViewUtils.toPx(getContext(), DEFAULT_CURSOR_WIDTH_DP));
    cursorDrawable.getPaint().setColor(accentColor);
    setHintCursorSize(cursorDrawable);
    try {
        // now attach the resource so it stops using the old one
        Field ef = ReflectionUtils.getInheritedPrivateField(this.getClass(), "mEditor");
        if (ef == null) {
            return;
        }
        ef.setAccessible(true);
        Object editorObject = ef.get(this);
        Field df = ReflectionUtils.getInheritedPrivateField(editorObject.getClass(), "mCursorDrawable");
        if (df == null) {
            return;
        }
        df.setAccessible(true);
        Object dfo = df.get(editorObject);
        if (dfo == null || !(dfo instanceof Drawable[])) {
            return;
        }
        Drawable[] darray = (Drawable[]) dfo;
        for (int i = 0; i < darray.length; i++) {
            darray[i] = cursorDrawable;
        }
    } catch (IllegalAccessException | IllegalArgumentException ex) {
        Timber.e(ex, "Error accessing private field");
    }
}
Also used : Field(java.lang.reflect.Field) RectShape(android.graphics.drawable.shapes.RectShape) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Drawable(android.graphics.drawable.Drawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable)

Example 79 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project XobotOS by xamarin.

the class ProgressBar 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 == R.id.progress || id == 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 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;
    } else 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) StateListDrawable(android.graphics.drawable.StateListDrawable) 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) StateListDrawable(android.graphics.drawable.StateListDrawable) BitmapShader(android.graphics.BitmapShader) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 80 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project PhotoNoter by yydcdut.

the class ColorChooserDialog method createSelector.

private Drawable createSelector(int color) {
    ShapeDrawable coloredCircle = new ShapeDrawable(new OvalShape());
    coloredCircle.getPaint().setColor(color);
    ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape());
    darkerCircle.getPaint().setColor(shiftColor(color));
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { -android.R.attr.state_pressed }, coloredCircle);
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, darkerCircle);
    return stateListDrawable;
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape) StateListDrawable(android.graphics.drawable.StateListDrawable)

Aggregations

ShapeDrawable (android.graphics.drawable.ShapeDrawable)89 OvalShape (android.graphics.drawable.shapes.OvalShape)40 Paint (android.graphics.Paint)27 Drawable (android.graphics.drawable.Drawable)23 LayerDrawable (android.graphics.drawable.LayerDrawable)23 ClipDrawable (android.graphics.drawable.ClipDrawable)16 StateListDrawable (android.graphics.drawable.StateListDrawable)16 Bitmap (android.graphics.Bitmap)15 BitmapDrawable (android.graphics.drawable.BitmapDrawable)15 SuppressLint (android.annotation.SuppressLint)14 BitmapShader (android.graphics.BitmapShader)14 AnimationDrawable (android.graphics.drawable.AnimationDrawable)13 RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)12 RectShape (android.graphics.drawable.shapes.RectShape)8 ColorDrawable (android.graphics.drawable.ColorDrawable)7 Shape (android.graphics.drawable.shapes.Shape)6 Resources (android.content.res.Resources)5 Canvas (android.graphics.Canvas)5 TypedArray (android.content.res.TypedArray)4 Shader (android.graphics.Shader)4