Search in sources :

Example 21 with ShapeDrawable

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

the class CircleProgressBar method onLayout.

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final float density = getContext().getResources().getDisplayMetrics().density;
    mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
    if (mDiameter <= 0) {
        mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
    }
    if (getBackground() == null && mCircleBackgroundEnabled) {
        final int shadowYOffset = (int) (density * Y_OFFSET);
        final int shadowXOffset = (int) (density * X_OFFSET);
        mShadowRadius = (int) (density * SHADOW_RADIUS);
        if (elevationSupported()) {
            mBgCircle = new ShapeDrawable(new OvalShape());
            ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
        } else {
            OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
            mBgCircle = new ShapeDrawable(oval);
            ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
            mBgCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
            final int padding = (int) mShadowRadius;
            // set padding so the inner image sits correctly within the shadow.
            setPadding(padding, padding, padding, padding);
        }
        mBgCircle.getPaint().setColor(mBackGroundColor);
        setBackgroundDrawable(mBgCircle);
    }
    mProgressDrawable.setBackgroundColor(mBackGroundColor);
    mProgressDrawable.setColorSchemeColors(mColors);
    if (isShowArrow()) {
        mProgressDrawable.setArrowScale(1f);
        mProgressDrawable.showArrow(true);
    }
    super.setImageDrawable(null);
    super.setImageDrawable(mProgressDrawable);
    mProgressDrawable.setAlpha(255);
    if (getVisibility() == VISIBLE) {
        mProgressDrawable.setStartEndTrim(0, (float) 0.8);
    }
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape) Paint(android.graphics.Paint)

Example 22 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project J2ME-Loader by nikita36078.

the class Item method createBackground.

public static Drawable createBackground(Context context, int color) {
    float radius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, BORDER_RADIUS, context.getResources().getDisplayMetrics());
    float[] radii = new float[8];
    for (int i = 0; i < 8; i++) {
        radii[i] = radius;
    }
    ShapeDrawable drawable = new ShapeDrawable(new RoundRectShape(radii, null, null));
    Paint paint = drawable.getPaint();
    paint.setColor(color);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(2);
    int padding = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, BORDER_PADDING, context.getResources().getDisplayMetrics()));
    drawable.setPadding(padding, padding, padding, padding);
    return drawable;
}
Also used : RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 23 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project httpclient by pixmob.

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

use of android.graphics.drawable.ShapeDrawable in project SwipeToLoadLayout by Aspsine.

the class GoogleCircleProgressView method setBackgroundColor.

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

use of android.graphics.drawable.ShapeDrawable in project instructure-android by instructure.

the class BaseBinder method createIndicatorBackground.

public static ShapeDrawable createIndicatorBackground(int color) {
    ShapeDrawable circle = new ShapeDrawable(new OvalShape());
    circle.getPaint().setColor(color);
    return circle;
}
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