Example usage for android.graphics.drawable ShapeDrawable ShapeDrawable

List of usage examples for android.graphics.drawable ShapeDrawable ShapeDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable ShapeDrawable ShapeDrawable.

Prototype

public ShapeDrawable(Shape s) 

Source Link

Document

Creates a ShapeDrawable with a specified Shape.

Usage

From source file:com.shizhefei.view.coolrefreshview.header.MaterialProgressDrawable.java

private void setUp(final double diameter) {
    if (mBackgroundColor != Color.TRANSPARENT) {
        final int shadowYOffset = Utils.dipToPix(mContext, Y_OFFSET);
        final int shadowXOffset = Utils.dipToPix(mContext, X_OFFSET);
        int mShadowRadius = Utils.dipToPix(mContext, 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());
        }//www .j  av  a 2 s  .c o m
        mShadow.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
    }

}

From source file:com.tr4android.support.extension.internal.AccountAdapter.java

private static void setupCheckBox(CheckBox checkBox) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        checkBox.setButtonDrawable(R.drawable.btn_checkbox_circle);
        checkBox.setBackgroundResource(R.drawable.btn_checkbox_circle_background);
    } else {//from w  ww  .ja v a 2  s.com
        Context context = checkBox.getContext();
        AppCompatDrawableManager dm = AppCompatDrawableManager.get();

        StateListDrawable button = new StateListDrawable();
        button.addState(new int[] { android.R.attr.state_checked },
                dm.getDrawable(context, R.drawable.ic_checkbox_circle_checked));
        button.addState(new int[] {}, dm.getDrawable(context, R.drawable.ic_checkbox_circle_unchecked));
        ColorStateList buttonTint = new ColorStateList(new int[][] { // states
                new int[] { android.R.attr.state_checked }, new int[] {} // state_default
        }, new int[] { // colors
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated),
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlNormal) });
        Drawable buttonCompat = DrawableCompat.wrap(button);
        DrawableCompat.setTintList(buttonCompat, buttonTint);
        checkBox.setButtonDrawable(buttonCompat);

        ShapeDrawable background = new ShapeDrawable(new OvalShape());
        int backgroundTint = ThemeUtils.getThemeAttrColor(context, android.R.attr.colorBackground);
        Drawable backgroundCompat = DrawableCompat.wrap(background);
        DrawableCompat.setTint(backgroundCompat, backgroundTint);
        ViewCompatUtils.setBackground(checkBox, backgroundCompat);
    }
}

From source file:org.zarroboogs.msrl.widget.CircleProgressBar.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    //        if (!elevationSupported()) {
    //            setMeasuredDimension(getMeasuredWidth() + mShadowRadius * 2, getMeasuredHeight()
    //                    + mShadowRadius * 2);
    //        }//ww w  .ja  v a2  s  .c o  m
    if (mDiameter <= 0 && getMeasuredHeight() > 0 && getMeasuredWidth() > 0) {

        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);

            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);
        mProgressDrawable.setSizeParameters(mDiameter, mDiameter,
                mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius,
                mProgressStokeWidth, mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth,
                mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
        if (isShowArrow()) {
            mProgressDrawable.setArrowScale(1f);
            mProgressDrawable.showArrow(true);
        }
        super.setImageDrawable(null);
        super.setImageDrawable(mProgressDrawable);
        mProgressDrawable.setAlpha(255);
        if (getVisibility() == VISIBLE) {
            mProgressDrawable.start();
        }
    }
}

From source file:com.google.maps.android.clustering.view.DefaultClusterRenderer.java

private LayerDrawable makeClusterBackground() {
    mColoredCircleBackground = new ShapeDrawable(new OvalShape());
    ShapeDrawable outline = new ShapeDrawable(new OvalShape());
    outline.getPaint().setColor(0x80ffffff); // Transparent white.
    LayerDrawable background = new LayerDrawable(new Drawable[] { outline, mColoredCircleBackground });
    int strokeWidth = (int) (mDensity * 3);
    background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
    return background;
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

private static Drawable createImageViewShape(int color) {
    OvalShape ovalShape = new OvalShape();

    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(color);

    return shapeDrawable;
}

From source file:com.waz.zclient.utils.ViewUtils.java

public static Drawable getRoundedRect(int cornerRadius, int backgroundColor) {
    RoundRectShape rect = new RoundRectShape(new float[] { cornerRadius, cornerRadius, cornerRadius,
            cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius }, null, null);

    ShapeDrawable background = new ShapeDrawable(rect);
    background.getPaint().setColor(backgroundColor);

    return background;
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

public static Drawable createBgDrawable(int color, int rTopLeft, int rTopRight, int rBottomRight,
        int rBottomLeft) {
    float[] outerRadii = new float[8];
    outerRadii[0] = rTopLeft;/*from  w w w.  j ava 2  s  . co m*/
    outerRadii[1] = rTopLeft;
    outerRadii[2] = rTopRight;
    outerRadii[3] = rTopRight;
    outerRadii[4] = rBottomRight;
    outerRadii[5] = rBottomRight;
    outerRadii[6] = rBottomLeft;
    outerRadii[7] = rBottomLeft;

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);

    return shapeDrawable;
}

From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java

private Drawable createDrawable(RenderOptions renderOptions) {

    PathShape pathShape = new PathShape(getPath(renderOptions.getWidth(), renderOptions.getHeight()),
            renderOptions.getWidth(), renderOptions.getHeight());

    if (renderOptions.getRenderStyle() == RenderStyles.BlackWhite) {

        ShapeDrawable strokeDrawable = new ShapeDrawable(pathShape);
        strokeDrawable.setBounds(0, 0, renderOptions.getWidth(), renderOptions.getHeight());
        strokeDrawable.getPaint().setColor(Color.BLACK);
        strokeDrawable.getPaint().setStyle(Paint.Style.STROKE);
        strokeDrawable.getPaint().setStrokeWidth(renderOptions.getStrokeWidth());

        ShapeDrawable fillDrawable = new ShapeDrawable(pathShape);
        fillDrawable.setBounds(0, 0, renderOptions.getWidth(), renderOptions.getHeight());
        fillDrawable.getPaint().setColor(Color.WHITE);
        fillDrawable.getPaint().setStyle(Paint.Style.FILL);

        Drawable[] layers = new Drawable[2];
        layers[0] = fillDrawable;/*from ww w .j a va  2 s .  c  o  m*/
        layers[1] = strokeDrawable;
        LayerDrawable drawable = new LayerDrawable(layers);

        return drawable;

    } else {

        ShapeDrawable drawable = new ShapeDrawable(pathShape);
        drawable.getPaint().setColor(getColor());
        drawable.getPaint().setStyle(Paint.Style.FILL);

        return drawable;
    }
}

From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java

public static Drawable createRectGradient(final int direction, final int[] colors) {

    final ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape());
    final ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {

        @Override//  ww  w .j  a v a  2s  .c  om
        public Shader resize(int width, int height) {
            int x0, y0, x1, y1;
            x0 = y0 = x1 = y1 = 0;
            if (direction == GRADIENT_DOWN) {
                y1 = height;
            } else if (direction == GRADIENT_UP) {
                y0 = height;
            } else if (direction == GRADIENT_RIGHT) {
                x1 = width;
            } else if (direction == GRADIENT_LEFT) {
                x0 = width;
            }
            LinearGradient lg = new LinearGradient(x0, y0, x1, y1, colors, new float[] { 0, 0.05f, 0.1f, 1 },
                    Shader.TileMode.REPEAT);
            return lg;
        }
    };
    shapeDrawable.setShaderFactory(shaderFactory);

    return shapeDrawable;
}

From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java

private ArrayList<ImageButton> generateFollowCircles() {

    int diameter = mFAB.getType() == FloatingActionButton.TYPE_NORMAL
            ? Utils.getDimension(mContext, R.dimen.fab_size_normal) - 2
            : Utils.getDimension(mContext, R.dimen.fab_size_mini);

    ArrayList<ImageButton> circles = new ArrayList<>(mMenuItems.size());
    for (MenuItem item : mMenuItems) {
        ImageButton circle = new ImageButton(mContext);
        circle.setScaleType(ImageView.ScaleType.FIT_CENTER);
        OvalShape ovalShape = new OvalShape();
        ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
        shapeDrawable.getPaint().setColor(getResources().getColor(item.getBgColor()));
        circle.setBackgroundDrawable(shapeDrawable);

        if (TextUtils.isEmpty(item.getIconFilePath())) {
            circle.setImageResource(item.getIcon());
        } else {/*ww  w .  j  a va  2s  .co m*/
            circle.setImageURI(Uri.fromFile(new File(item.getIconFilePath())));
        }

        LayoutParams lp = new LayoutParams(diameter, diameter);
        circle.setLayoutParams(lp);
        circles.add(circle);
    }

    return circles;
}