Example usage for android.graphics.drawable GradientDrawable setSize

List of usage examples for android.graphics.drawable GradientDrawable setSize

Introduction

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

Prototype

public void setSize(int width, int height) 

Source Link

Document

Sets the size of the shape drawn by this drawable.

Note: changing this property will affect all instances of a drawable loaded from a resource.

Usage

From source file:com.example.android.materialme.DetailActivity.java

/**
 * Initializes the activity, filling in the data from the Intent.
 * @param savedInstanceState Contains information about the saved state of the activity
 *//*from w w  w  .  j a  v a2s. co  m*/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);

    //Initialize the views
    TextView sportsTitle = (TextView) findViewById(R.id.titleDetail);
    ImageView sportsImage = (ImageView) findViewById(R.id.sportsImageDetail);

    //Get the drawable
    Drawable drawable = ContextCompat.getDrawable(this, getIntent().getIntExtra(Sport.IMAGE_KEY, 0));

    //Create a placeholder gray scrim while the image loads
    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setColor(Color.GRAY);

    //Make it the same size as the image
    if (drawable != null) {
        gradientDrawable.setSize(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    }

    //Set the text from the Intent extra
    sportsTitle.setText(getIntent().getStringExtra(Sport.TITLE_KEY));

    //Load the image using the glide library and the Intent extra
    Glide.with(this).load(getIntent().getIntExtra(Sport.IMAGE_KEY, 0)).placeholder(gradientDrawable)
            .into(sportsImage);
}

From source file:rus.cpuinfo.Ui.Fragments.Base.CpuInfoBaseTabFragment.java

@Nullable
@Override/*  w  w w.  ja v  a 2s .  com*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_tab, container, false);
    ButterKnife.bind(this, v);

    mViewPager.setAdapter(createAdapter());
    mTabLayout.setupWithViewPager(mViewPager);

    View root = mTabLayout.getChildAt(0);

    if (root instanceof LinearLayout) {

        LinearLayout linearLayout = ((LinearLayout) root);
        linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);

        GradientDrawable drawable = new GradientDrawable();
        drawable.setSize(2, 0);

        linearLayout.setDividerDrawable(drawable);
    }

    if (savedInstanceState != null) {
        mCurrentItem = savedInstanceState.getInt(SELECTED_TAB);
    }

    return v;
}

From source file:com.saulmm.cui.recycler.ProductViewHolder.java

void bind(Product product) {
    binding.setProduct(product);/*ww w  .  jav  a  2  s.  com*/

    final GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat
            .getDrawable(itemView.getContext(), R.drawable.bg_product);

    gradientDrawable.setColor(ContextCompat.getColor(itemView.getContext(), product.color));

    gradientDrawable.setSize(itemView.getWidth(), getDrawableHeight());

    gradientDrawable.mutate();

    binding.imgProduct.setBackground(gradientDrawable);
    binding.imgProduct.setImageResource(product.image);
}

From source file:com.fuzz.emptyhusk.prefab.ProportionalImageCellGenerator.java

@Override
public void onBindChild(@NonNull View child, @NonNull CutoutViewLayoutParams lp, @Nullable View originator) {
    child.setBackgroundResource(lp.cellBackgroundId);
    if (originator != null) {
        rvChildLength = originator.getHeight();
        if (originator.getParent() instanceof ViewGroup) {
            rvLength = ((ViewGroup) originator.getParent()).getHeight();
        }/*from w w w  .ja v a2  s .c o m*/
    }
    if (child instanceof ImageView) {
        GradientDrawable elongated = new GradientDrawable();
        elongated.setShape(GradientDrawable.RECTANGLE);

        int accent = ContextCompat.getColor(child.getContext(), R.color.transparentColorAccent);

        float fractionOfParent = rvLength * 1.0f / rvChildLength;

        elongated.setColor(accent);
        float proposedLength = fractionOfParent * lp.perpendicularLength;
        elongated.setSize(lp.perpendicularLength, (int) proposedLength);

        ((ImageView) child).setImageDrawable(elongated);
    }
}

From source file:com.arsy.maps_library.MapRadar.java

private void setDrawableAndBitmap() {
    mOuterDrawable.setColor(mFillColor);
    mOuterDrawable.setStroke(UiUtil.dpToPx(mStrokeWidth), mStrokeColor);
    mBackgroundImageDescriptor = UiUtil.drawableToBitmapDescriptor(mOuterDrawable);
    GradientDrawable radarDrawable = new GradientDrawable(GradientDrawable.Orientation.TL_BR, mColors);
    radarDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
    radarDrawable.setShape(GradientDrawable.OVAL);
    radarDrawable.setSize(1200, 1200);
    mBackgroundImageSweepDescriptor = UiUtil.drawableToBitmapDescriptor(radarDrawable);
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.RecyclerViewFastIndexer.java

protected void init(Context context) {
    if (isInitialized)
        return;//  ww  w  . ja va2s  .  com
    isInitialized = true;
    setOrientation(HORIZONTAL);
    setClipChildren(false);
    setWillNotDraw(false);

    bubble = new TextView(context);
    bubble.setTextColor(Color.WHITE);
    bubble.setTextSize(48);

    GradientDrawable bubbleDrawable = new GradientDrawable();
    bubbleDrawable.setColor(0xFFce891e);
    bubbleDrawable.setSize(getCustomSize(88), getCustomSize(88));
    bubbleDrawable.setCornerRadii(new float[] { getCustomSize(44), getCustomSize(44), getCustomSize(44),
            getCustomSize(44), 0, 0, getCustomSize(44), getCustomSize(44) });

    bubble.setBackgroundDrawable(bubbleDrawable);

    //bubble.setBackgroundResource(R.drawable.recycler_view_fast_scroller__bubble);
    bubble.setGravity(Gravity.CENTER);

    LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.RIGHT | Gravity.END;

    addView(bubble, params);

    if (bubble != null)
        bubble.setVisibility(INVISIBLE);

    handle = new ImageView(context);
    //handle.setBackgroundResource(R.drawable.recycler_view_fast_scroller__handle);

    GradientDrawable drawable = new GradientDrawable();
    drawable.setShape(GradientDrawable.RECTANGLE);
    drawable.setSize(getCustomSize(4), getCustomSize(35));
    drawable.setColor(0xFFce891e);
    drawable.setCornerRadius(getCustomSize(5));

    GradientDrawable drawable2 = new GradientDrawable();
    drawable2.setShape(GradientDrawable.RECTANGLE);
    drawable2.setSize(getCustomSize(4), getCustomSize(35));
    drawable2.setColor(0xFFf3a124);
    drawable2.setCornerRadius(getCustomSize(5));

    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { android.R.attr.state_selected }, drawable);
    states.addState(new int[] {}, drawable2);

    handle.setBackgroundDrawable(states);

    LayoutParams params2 = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    int dimension = getCustomSize(3);

    int doubleDimension = dimension * 2;
    params2.leftMargin = doubleDimension;
    params2.rightMargin = doubleDimension;

    handle.setPadding(dimension, 0, dimension, 0);
    handle.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                v.setBackgroundColor(Color.parseColor("#00891e"));
            } else {
                v.setBackgroundColor(Color.parseColor("#44891e"));
            }
        }
    });

    addView(handle, params2);

}

From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java

private void setLegends() {
    if (mChart.getData().getDataSets().size() > 1) {
        final Resources resources = ApplicationData.getAppContext().getResources();
        final float density = getResources().getDisplayMetrics().density;
        final float legendWidth = resources.getDimension(R.dimen.chart_legend_width) / density;
        final float legendHeight = resources.getDimension(R.dimen.chart_legend_height) / density;
        final float legendMargin = resources.getDimension(R.dimen.chart_legend_margin) / density;
        final float legendCorner = resources.getDimension(R.dimen.chart_legend_corner) / density;

        for (ILineDataSet lineDataSet : mChart.getData().getDataSets()) {
            final CheckBox checkBox = new CheckBox(mLegendLayout.getContext());
            checkBox.setChecked(true);//from   w w  w.java2 s. c o  m
            checkBox.setText(lineDataSet.getLabel());
            checkBox.setTag(lineDataSet);
            checkBox.setOnCheckedChangeListener(mLegendCheckedChangeListener);

            GradientDrawable drawable = new GradientDrawable();
            drawable.setShape(GradientDrawable.RECTANGLE);
            drawable.setColor(lineDataSet.getColor());
            drawable.setSize((int) legendWidth, (int) legendHeight);
            drawable.setCornerRadius(legendCorner);

            checkBox.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
            checkBox.setCompoundDrawablePadding((int) legendMargin);

            final GridLayout.Spec titleTxtSpecColumn = GridLayout.spec(GridLayout.UNDEFINED);
            final GridLayout.Spec titleRowSpec = GridLayout.spec(GridLayout.UNDEFINED);
            final GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(titleRowSpec,
                    titleTxtSpecColumn);
            layoutParams.setMargins((int) legendWidth, 0, (int) legendWidth, 0);
            mLegendLayout.addView(checkBox, layoutParams);
        }
    }
}

From source file:am.widget.basetabstrip.BaseTabStrip.java

/**
 * ?Tag/*from w  w w. ja va  2s.  c  om*/
 *
 * @return Tag
 */
@SuppressWarnings("unused")
protected Drawable getDefaultTagBackground() {
    final float density = getResources().getDisplayMetrics().density;
    final GradientDrawable mBackground = new GradientDrawable();
    mBackground.setShape(GradientDrawable.RECTANGLE);
    mBackground.setColor(0xffff4444);
    mBackground.setCornerRadius(100000 * density);
    mBackground.setSize((int) (10 * density), (int) (10 * density));
    return mBackground;
}

From source file:com.bilibili.magicasakura.utils.GradientDrawableUtils.java

@Override
protected Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs)
        throws XmlPullParserException, IOException {
    GradientDrawable gradientDrawable = new GradientDrawable();
    inflateGradientRootElement(context, attrs, gradientDrawable);

    int type;//from   w w  w .j a  v  a  2 s.  c  o  m
    final int innerDepth = parser.getDepth() + 1;
    int depth;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        if (depth > innerDepth) {
            continue;
        }

        String name = parser.getName();

        if (name.equals("size")) {
            final int width = getAttrDimensionPixelSize(context, attrs, android.R.attr.width);
            final int height = getAttrDimensionPixelSize(context, attrs, android.R.attr.height);
            gradientDrawable.setSize(width, height);
        } else if (name.equals("gradient")
                && Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            final float centerX = getAttrFloatOrFraction(context, attrs, android.R.attr.centerX, 0.5f, 1.0f,
                    1.0f);
            final float centerY = getAttrFloatOrFraction(context, attrs, android.R.attr.centerY, 0.5f, 1.0f,
                    1.0f);
            gradientDrawable.setGradientCenter(centerX, centerY);
            final boolean useLevel = getAttrBoolean(context, attrs, android.R.attr.useLevel, false);
            gradientDrawable.setUseLevel(useLevel);
            final int gradientType = getAttrInt(context, attrs, android.R.attr.type, 0);
            gradientDrawable.setGradientType(gradientType);
            final int startColor = getAttrColor(context, attrs, android.R.attr.startColor, Color.TRANSPARENT);
            final int centerColor = getAttrColor(context, attrs, android.R.attr.centerColor, Color.TRANSPARENT);
            final int endColor = getAttrColor(context, attrs, android.R.attr.endColor, Color.TRANSPARENT);
            if (!getAttrHasValue(context, attrs, android.R.attr.centerColor)) {
                gradientDrawable.setColors(new int[] { startColor, endColor });
            } else {
                gradientDrawable.setColors(new int[] { startColor, centerColor, endColor });
                setStGradientPositions(gradientDrawable.getConstantState(), 0.0f,
                        centerX != 0.5f ? centerX : centerY, 1f);
            }

            if (gradientType == GradientDrawable.LINEAR_GRADIENT) {
                int angle = (int) getAttrFloat(context, attrs, android.R.attr.angle, 0.0f);
                angle %= 360;

                if (angle % 45 != 0) {
                    throw new XmlPullParserException(
                            "<gradient> tag requires" + "'angle' attribute to " + "be a multiple of 45");
                }

                setStGradientAngle(gradientDrawable.getConstantState(), angle);

                switch (angle) {
                case 0:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT);
                    break;
                case 45:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.BL_TR);
                    break;
                case 90:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.BOTTOM_TOP);
                    break;
                case 135:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.BR_TL);
                    break;
                case 180:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.RIGHT_LEFT);
                    break;
                case 225:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.TR_BL);
                    break;
                case 270:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM);
                    break;
                case 315:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.TL_BR);
                    break;
                }
            } else {
                setGradientRadius(context, attrs, gradientDrawable, gradientType);
            }
        } else if (name.equals("solid")) {
            int color = getAttrColor(context, attrs, android.R.attr.color, Color.TRANSPARENT);
            gradientDrawable
                    .setColor(getAlphaColor(color, getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f)));
        } else if (name.equals("stroke")) {
            final float alphaMod = getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f);
            final int strokeColor = getAttrColor(context, attrs, android.R.attr.color, Color.TRANSPARENT);
            final int strokeWidth = getAttrDimensionPixelSize(context, attrs, android.R.attr.width);
            final float dashWidth = getAttrDimension(context, attrs, android.R.attr.dashWidth);
            if (dashWidth != 0.0f) {
                final float dashGap = getAttrDimension(context, attrs, android.R.attr.dashGap);
                gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod), dashWidth,
                        dashGap);
            } else {
                gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod));
            }
        } else if (name.equals("corners")) {
            final int radius = getAttrDimensionPixelSize(context, attrs, android.R.attr.radius);
            gradientDrawable.setCornerRadius(radius);

            final int topLeftRadius = getAttrDimensionPixelSize(context, attrs, android.R.attr.topLeftRadius,
                    radius);
            final int topRightRadius = getAttrDimensionPixelSize(context, attrs, android.R.attr.topRightRadius,
                    radius);
            final int bottomLeftRadius = getAttrDimensionPixelSize(context, attrs,
                    android.R.attr.bottomLeftRadius, radius);
            final int bottomRightRadius = getAttrDimensionPixelSize(context, attrs,
                    android.R.attr.bottomRightRadius, radius);
            if (topLeftRadius != radius || topRightRadius != radius || bottomLeftRadius != radius
                    || bottomRightRadius != radius) {
                // The corner radii are specified in clockwise order (see Path.addRoundRect())
                gradientDrawable.setCornerRadii(
                        new float[] { topLeftRadius, topLeftRadius, topRightRadius, topRightRadius,
                                bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius });
            }
        } else if (name.equals("padding")) {
            final int paddingLeft = getAttrDimensionPixelOffset(context, attrs, android.R.attr.left);
            final int paddingTop = getAttrDimensionPixelOffset(context, attrs, android.R.attr.top);
            final int paddingRight = getAttrDimensionPixelOffset(context, attrs, android.R.attr.right);
            final int paddingBottom = getAttrDimensionPixelOffset(context, attrs, android.R.attr.bottom);
            if (paddingLeft != 0 || paddingTop != 0 || paddingRight != 0 || paddingBottom != 0) {
                final Rect pad = new Rect();
                pad.set(paddingLeft, paddingTop, paddingRight, paddingBottom);
                try {
                    if (sPaddingField == null) {
                        sPaddingField = GradientDrawable.class.getDeclaredField("mPadding");
                        sPaddingField.setAccessible(true);
                    }
                    sPaddingField.set(gradientDrawable, pad);
                    if (sStPaddingField == null) {
                        sStPaddingField = Class
                                .forName("android.graphics.drawable.GradientDrawable$GradientState")
                                .getDeclaredField("mPadding");
                        sStPaddingField.setAccessible(true);
                    }
                    sStPaddingField.set(gradientDrawable.getConstantState(), pad);
                } catch (NoSuchFieldException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        } else {
            Log.w("drawable", "Bad element under <shape>: " + name);
        }
    }
    return gradientDrawable;
}

From source file:com.bilibili.magicasakura.utils.GradientDrawableInflateImpl.java

@Override
public Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs)
        throws XmlPullParserException, IOException {
    GradientDrawable gradientDrawable = new GradientDrawable();
    inflateGradientRootElement(context, attrs, gradientDrawable);

    int type;/*from  w  w w  .  ja v  a  2s.c o  m*/
    final int innerDepth = parser.getDepth() + 1;
    int depth;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        if (depth > innerDepth) {
            continue;
        }

        String name = parser.getName();

        if (name.equals("size")) {
            final int width = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.width);
            final int height = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.height);
            gradientDrawable.setSize(width, height);
        } else if (name.equals("gradient")
                && Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            final float centerX = getAttrFloatOrFraction(context, attrs, android.R.attr.centerX, 0.5f, 1.0f,
                    1.0f);
            final float centerY = getAttrFloatOrFraction(context, attrs, android.R.attr.centerY, 0.5f, 1.0f,
                    1.0f);
            gradientDrawable.setGradientCenter(centerX, centerY);
            final boolean useLevel = DrawableUtils.getAttrBoolean(context, attrs, android.R.attr.useLevel,
                    false);
            gradientDrawable.setUseLevel(useLevel);
            final int gradientType = DrawableUtils.getAttrInt(context, attrs, android.R.attr.type, 0);
            gradientDrawable.setGradientType(gradientType);
            final int startColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.startColor,
                    Color.TRANSPARENT);
            final int centerColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.centerColor,
                    Color.TRANSPARENT);
            final int endColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.endColor,
                    Color.TRANSPARENT);
            if (!DrawableUtils.getAttrHasValue(context, attrs, android.R.attr.centerColor)) {
                gradientDrawable.setColors(new int[] { startColor, endColor });
            } else {
                gradientDrawable.setColors(new int[] { startColor, centerColor, endColor });
                setStGradientPositions(gradientDrawable.getConstantState(), 0.0f,
                        centerX != 0.5f ? centerX : centerY, 1f);
            }

            if (gradientType == GradientDrawable.LINEAR_GRADIENT) {
                int angle = (int) DrawableUtils.getAttrFloat(context, attrs, android.R.attr.angle, 0.0f);
                angle %= 360;

                if (angle % 45 != 0) {
                    throw new XmlPullParserException(
                            "<gradient> tag requires" + "'angle' attribute to " + "be a multiple of 45");
                }

                setStGradientAngle(gradientDrawable.getConstantState(), angle);

                switch (angle) {
                case 0:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT);
                    break;
                case 45:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.BL_TR);
                    break;
                case 90:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.BOTTOM_TOP);
                    break;
                case 135:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.BR_TL);
                    break;
                case 180:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.RIGHT_LEFT);
                    break;
                case 225:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.TR_BL);
                    break;
                case 270:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM);
                    break;
                case 315:
                    gradientDrawable.setOrientation(GradientDrawable.Orientation.TL_BR);
                    break;
                }
            } else {
                setGradientRadius(context, attrs, gradientDrawable, gradientType);
            }
        } else if (name.equals("solid")) {
            int color = DrawableUtils.getAttrColor(context, attrs, android.R.attr.color, Color.TRANSPARENT);
            gradientDrawable.setColor(getAlphaColor(color,
                    DrawableUtils.getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f)));
        } else if (name.equals("stroke")) {
            final float alphaMod = DrawableUtils.getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f);
            final int strokeColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.color,
                    Color.TRANSPARENT);
            final int strokeWidth = DrawableUtils.getAttrDimensionPixelSize(context, attrs,
                    android.R.attr.width);
            final float dashWidth = DrawableUtils.getAttrDimension(context, attrs, android.R.attr.dashWidth);
            if (dashWidth != 0.0f) {
                final float dashGap = DrawableUtils.getAttrDimension(context, attrs, android.R.attr.dashGap);
                gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod), dashWidth,
                        dashGap);
            } else {
                gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod));
            }
        } else if (name.equals("corners")) {
            final int radius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.radius);
            gradientDrawable.setCornerRadius(radius);

            final int topLeftRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs,
                    android.R.attr.topLeftRadius, radius);
            final int topRightRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs,
                    android.R.attr.topRightRadius, radius);
            final int bottomLeftRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs,
                    android.R.attr.bottomLeftRadius, radius);
            final int bottomRightRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs,
                    android.R.attr.bottomRightRadius, radius);
            if (topLeftRadius != radius || topRightRadius != radius || bottomLeftRadius != radius
                    || bottomRightRadius != radius) {
                // The corner radii are specified in clockwise order (see Path.addRoundRect())
                gradientDrawable.setCornerRadii(
                        new float[] { topLeftRadius, topLeftRadius, topRightRadius, topRightRadius,
                                bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius });
            }
        } else if (name.equals("padding")) {
            final int paddingLeft = DrawableUtils.getAttrDimensionPixelOffset(context, attrs,
                    android.R.attr.left);
            final int paddingTop = DrawableUtils.getAttrDimensionPixelOffset(context, attrs,
                    android.R.attr.top);
            final int paddingRight = DrawableUtils.getAttrDimensionPixelOffset(context, attrs,
                    android.R.attr.right);
            final int paddingBottom = DrawableUtils.getAttrDimensionPixelOffset(context, attrs,
                    android.R.attr.bottom);
            if (paddingLeft != 0 || paddingTop != 0 || paddingRight != 0 || paddingBottom != 0) {
                final Rect pad = new Rect();
                pad.set(paddingLeft, paddingTop, paddingRight, paddingBottom);
                try {
                    if (sPaddingField == null) {
                        sPaddingField = GradientDrawable.class.getDeclaredField("mPadding");
                        sPaddingField.setAccessible(true);
                    }
                    sPaddingField.set(gradientDrawable, pad);
                    if (sStPaddingField == null) {
                        sStPaddingField = Class
                                .forName("android.graphics.drawable.GradientDrawable$GradientState")
                                .getDeclaredField("mPadding");
                        sStPaddingField.setAccessible(true);
                    }
                    sStPaddingField.set(gradientDrawable.getConstantState(), pad);
                } catch (NoSuchFieldException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        } else {
            Log.w("drawable", "Bad element under <shape>: " + name);
        }
    }
    return gradientDrawable;
}