Example usage for android.graphics.drawable LayerDrawable setLayerInset

List of usage examples for android.graphics.drawable LayerDrawable setLayerInset

Introduction

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

Prototype

public void setLayerInset(int index, int l, int t, int r, int b) 

Source Link

Document

Specifies the insets in pixels for the drawable at the specified index.

Usage

From source file:Main.java

public static LayerDrawable getBorderLayerDrawable(int color, int backgroundColor, int padding, int radius) {
    Drawable[] layers = new Drawable[2];
    layers[0] = getShapeDrawable(color, radius);
    layers[0].setState(new int[] { android.R.attr.state_enabled });
    layers[1] = getShapeDrawable(backgroundColor, radius);
    layers[1].setState(new int[] { android.R.attr.state_enabled });
    LayerDrawable layerDrawable = new LayerDrawable(layers);
    layerDrawable.setLayerInset(1, padding, padding, padding, padding);
    return layerDrawable;
}

From source file:br.ufrgs.ufrgsmapas.views.BuildingClusterRenderer.java

private LayerDrawable makeClusterBackground() {
    this.mColoredCircleBackground = new ShapeDrawable(new OvalShape());
    ShapeDrawable outline = new ShapeDrawable(new OvalShape());
    outline.getPaint().setColor(-2130706433);
    LayerDrawable background = new LayerDrawable(new Drawable[] { outline, this.mColoredCircleBackground });
    int strokeWidth = (int) (this.mDensity * 3.0F);
    background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
    return background;
}

From source file:com.saulmm.cui.OrderDialogFragment.java

private Drawable createProductImageDrawable(Product product) {
    final ShapeDrawable background = new ShapeDrawable();
    background.setShape(new OvalShape());
    background.getPaint().setColor(ContextCompat.getColor(getContext(), product.color));

    final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),
            BitmapFactory.decodeResource(getResources(), product.image));

    final LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, bitmapDrawable });

    final int padding = (int) getResources().getDimension(R.dimen.spacing_huge);
    layerDrawable.setLayerInset(1, padding, padding, padding, padding);

    return layerDrawable;
}

From source file:io.imoji.sdk.editor.fragment.TagImojiFragment.java

public Drawable createTagDrawable() {

    GradientDrawable d = new GradientDrawable();
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(new int[] { R.attr.colorAccent });
    final int accentColor = a.getColor(0, Color.WHITE);
    a.recycle();/*from ww  w . ja  v a2 s . co  m*/
    d.setColor(0xB3FFFFFF & accentColor);
    d.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d.setShape(GradientDrawable.RECTANGLE);

    GradientDrawable d1 = new GradientDrawable();
    d1.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d1.setStroke((int) getResources().getDimension(R.dimen.dim_0_5dp), 0x66FFFFFF & Color.BLACK);

    GradientDrawable d2 = new GradientDrawable();
    d2.setStroke((int) getResources().getDimension(R.dimen.dim_1dp), accentColor);
    d2.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));

    LayerDrawable layer = new LayerDrawable(new Drawable[] { d, d2, d1 });

    int halfDp = (int) getResources().getDimension(R.dimen.dim_0_5dp);
    int oneDp = (int) getResources().getDimension(R.dimen.dim_1dp);
    int oneAndHalf = halfDp + oneDp;

    layer.setLayerInset(2, 0, 0, 0, 0);
    layer.setLayerInset(1, halfDp, halfDp, halfDp, halfDp);
    layer.setLayerInset(0, oneAndHalf, oneAndHalf, oneAndHalf, oneAndHalf);

    return layer;
}

From source file:cn.finalteam.galleryfinal.widget.FloatingActionButton.java

void updateBackground() {
    float circleLeft = mShadowRadius;
    float circleTop = mShadowRadius - mShadowOffset;

    final RectF circleRect = new RectF(circleLeft, circleTop, circleLeft + mCircleSize,
            circleTop + mCircleSize);/* w w  w  .j  a v  a  2s. c  om*/

    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { new BitmapDrawable(getResources()),
            createFillDrawable(circleRect), new BitmapDrawable(getResources()), getIconDrawable() });

    float iconOffset = (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2f;

    int iconInsetHorizontal = (int) (mShadowRadius + iconOffset);
    int iconInsetTop = (int) (circleTop + iconOffset);
    int iconInsetBottom = (int) (mShadowRadius + mShadowOffset + iconOffset);

    layerDrawable.setLayerInset(3, iconInsetHorizontal, iconInsetTop, iconInsetHorizontal, iconInsetBottom);

    setBackgroundCompat(layerDrawable);
}

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.winneredge.stockly.wcommons.floatingactionwidget.FloatingActionButton.java

void updateBackground() {
    LayerDrawable layerDrawable;
    if (hasShadow()) {
        layerDrawable = new LayerDrawable(
                new Drawable[] { new Shadow(), createFillDrawable(), getIconDrawable() });
    } else {/*from  w w w  .  ja  v a 2 s .c om*/
        layerDrawable = new LayerDrawable(new Drawable[] { createFillDrawable(), getIconDrawable() });
    }

    int iconSize = -1;
    if (getIconDrawable() != null) {
        iconSize = Math.max(getIconDrawable().getIntrinsicWidth(), getIconDrawable().getIntrinsicHeight());
    }
    int iconOffset = (getCircleSize() - (iconSize > 0 ? iconSize : mIconSize)) / 2;
    int circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0;
    int circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0;

    if (mProgressBarEnabled) {
        circleInsetHorizontal += mProgressWidth;
        circleInsetVertical += mProgressWidth;
    }

    /*layerDrawable.setLayerInset(
        mShowShadow ? 1 : 0,
        circleInsetHorizontal,
        circleInsetVertical,
        circleInsetHorizontal,
        circleInsetVertical
    );*/
    layerDrawable.setLayerInset(hasShadow() ? 2 : 1, circleInsetHorizontal + iconOffset,
            circleInsetVertical + iconOffset, circleInsetHorizontal + iconOffset,
            circleInsetVertical + iconOffset);

    setBackgroundCompat(layerDrawable);
}