Search in sources :

Example 41 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project AndroidPicker by gzu-liyujiang.

the class BaseDialog method setBackgroundColor.

public final void setBackgroundColor(@CornerRound int cornerRound, @Dimension(unit = Dimension.DP) int radius, @ColorInt int color) {
    if (contentView == null) {
        return;
    }
    float radiusInPX = contentView.getResources().getDisplayMetrics().density * radius;
    contentView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    Drawable drawable;
    switch(cornerRound) {
        case CornerRound.Top:
            float[] outerRadii = new float[] { radiusInPX, radiusInPX, radiusInPX, radiusInPX, 0, 0, 0, 0 };
            ShapeDrawable shapeDrawable = new ShapeDrawable(new RoundRectShape(outerRadii, null, null));
            shapeDrawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
            drawable = shapeDrawable;
            break;
        case CornerRound.All:
            GradientDrawable gradientDrawable = new GradientDrawable();
            gradientDrawable.setCornerRadius(radiusInPX);
            gradientDrawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
            drawable = gradientDrawable;
            break;
        default:
            drawable = new ColorDrawable(color);
            break;
    }
    contentView.setBackground(drawable);
}
Also used : RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 42 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class MaterialProgressDrawable method setUp.

private void setUp(final double diameter) {
    PtrLocalDisplay.init(mParent.getContext());
    final int shadowYOffset = PtrLocalDisplay.dp2px(Y_OFFSET);
    final int shadowXOffset = PtrLocalDisplay.dp2px(X_OFFSET);
    int mShadowRadius = PtrLocalDisplay.dp2px(SHADOW_RADIUS);
    OvalShape oval = new OvalShadow(mShadowRadius, (int) diameter);
    mShadow = new ShapeDrawable(oval);
    if (Build.VERSION.SDK_INT >= 11) {
        mParent.setLayerType(View.LAYER_TYPE_SOFTWARE, mShadow.getPaint());
    }
    mShadow.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 43 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project Android-MaterialRefreshLayout by android-cjj.

the class CircleProgressBar method setBackgroundColor.

/**
 * Update the background color of the mBgCircle image view.
 */
public void setBackgroundColor(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 44 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable 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 45 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project BottomBar by roughike.

the class BottomBarBadge method setColoredCircleBackground.

void setColoredCircleBackground(int circleColor) {
    int innerPadding = MiscUtils.dpToPixel(getContext(), 1);
    ShapeDrawable backgroundCircle = BadgeCircle.make(innerPadding * 3, circleColor);
    setPadding(innerPadding, innerPadding, innerPadding, innerPadding);
    setBackgroundCompat(backgroundCircle);
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable)

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