public void setCornerRadius(int radius) { if (mCornerRadius == radius) { return; } mCornerRadius = radius; if (mDrawable instanceof RoundedDrawable) { ((RoundedDrawable) mDrawable).setCornerRadius(radius); } if (mRoundBackground && mBackgroundDrawable instanceof RoundedDrawable) { ((RoundedDrawable) mBackgroundDrawable).setCornerRadius(radius); } }
private void updateDrawableAttrs(RoundedDrawable drawable) { drawable.setScaleType(mScaleType); drawable.setCornerRadius(mCornerRadius); drawable.setBorderWidth(mBorderWidth); drawable.setBorderColors(mBorderColor); drawable.setOval(mOval); }
private void updateAttrs(Drawable drawable) { if (drawable == null) { return; } if (drawable instanceof RoundedDrawable) { ((RoundedDrawable) drawable).setScaleType(mScaleType); ((RoundedDrawable) drawable).setCornerRadius(mCornerRadius); mDrawable.setColorFilter(mColorFilter); } else if (drawable instanceof LayerDrawable) { // loop through layers to and set drawable attrs LayerDrawable ld = ((LayerDrawable) drawable); for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) { updateAttrs(ld.getDrawable(i)); } } }
public void setRoundBackground(boolean roundBackground) { if (mRoundBackground == roundBackground) { return; } mRoundBackground = roundBackground; if (roundBackground) { if (mBackgroundDrawable instanceof RoundedDrawable) { updateDrawableAttrs((RoundedDrawable) mBackgroundDrawable); } else { setBackgroundDrawable(mBackgroundDrawable); } } else if (mBackgroundDrawable instanceof RoundedDrawable) { ((RoundedDrawable) mBackgroundDrawable).setBorderWidth(0); ((RoundedDrawable) mBackgroundDrawable).setCornerRadius(0); } invalidate(); }