use of android.graphics.drawable.LayerDrawable in project MaterialDesignLibrary by navasmdc.
the class Card method setBackgroundColor.
// Set color of background
public void setBackgroundColor(int color) {
this.backgroundColor = color;
if (isEnabled())
beforeBackground = backgroundColor;
LayerDrawable layer = (LayerDrawable) getBackground();
GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
shape.setColor(backgroundColor);
}
use of android.graphics.drawable.LayerDrawable in project Android-Developers-Samples by johnjohndoe.
the class ThumbnailRadioButton method setThumbnail.
public void setThumbnail(Bitmap bitmap) {
//Bitmap drawable
BitmapDrawable bmp = new BitmapDrawable(getResources(), bitmap);
bmp.setGravity(Gravity.CENTER);
int strokeWidth = 24;
//Checked state
ShapeDrawable rectChecked = new ShapeDrawable(new RectShape());
rectChecked.getPaint().setColor(0xFFFFFFFF);
rectChecked.getPaint().setStyle(Paint.Style.STROKE);
rectChecked.getPaint().setStrokeWidth(strokeWidth);
rectChecked.setIntrinsicWidth(bitmap.getWidth() + strokeWidth);
rectChecked.setIntrinsicHeight(bitmap.getHeight() + strokeWidth);
Drawable[] drawableArray = new Drawable[] { bmp, rectChecked };
LayerDrawable layerChecked = new LayerDrawable(drawableArray);
//Unchecked state
ShapeDrawable rectUnchecked = new ShapeDrawable(new RectShape());
rectUnchecked.getPaint().setColor(0x0);
rectUnchecked.getPaint().setStyle(Paint.Style.STROKE);
rectUnchecked.getPaint().setStrokeWidth(strokeWidth);
rectUnchecked.setIntrinsicWidth(bitmap.getWidth() + strokeWidth);
rectUnchecked.setIntrinsicHeight(bitmap.getHeight() + strokeWidth);
Drawable[] drawableArray2 = new Drawable[] { bmp, rectUnchecked };
LayerDrawable layerUnchecked = new LayerDrawable(drawableArray2);
//Statelist drawable
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { android.R.attr.state_checked }, layerChecked);
states.addState(new int[] {}, layerUnchecked);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
setBackground(states);
else
setBackgroundDrawable(states);
//Offset text to center/bottom of the checkbox
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setTextSize(getTextSize());
paint.setTypeface(getTypeface());
float w = paint.measureText(getText(), 0, getText().length());
setPadding(getPaddingLeft() + (int) ((bitmap.getWidth() - w) / 2.f + .5f), getPaddingTop() + (int) (bitmap.getHeight() * 0.70), getPaddingRight(), getPaddingBottom());
setShadowLayer(5, 0, 0, Color.BLACK);
}
use of android.graphics.drawable.LayerDrawable in project GalleryFinal by pengjianbo.
the class FloatingActionButton method updateBackground.
void updateBackground() {
float circleLeft = mShadowRadius;
float circleTop = mShadowRadius - mShadowOffset;
final RectF circleRect = new RectF(circleLeft, circleTop, circleLeft + mCircleSize, circleTop + mCircleSize);
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);
}
use of android.graphics.drawable.LayerDrawable in project android_frameworks_base by ResurrectionRemix.
the class ToggleButton method updateReferenceToIndicatorDrawable.
private void updateReferenceToIndicatorDrawable(Drawable backgroundDrawable) {
if (backgroundDrawable instanceof LayerDrawable) {
LayerDrawable layerDrawable = (LayerDrawable) backgroundDrawable;
mIndicatorDrawable = layerDrawable.findDrawableByLayerId(com.android.internal.R.id.toggle);
} else {
mIndicatorDrawable = null;
}
}
use of android.graphics.drawable.LayerDrawable in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class FloatingActionButton method updateBackground.
void updateBackground() {
final float strokeWidth = getDimension(R.dimen.fab_stroke_width);
final float halfStrokeWidth = strokeWidth / 2f;
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini), createFillDrawable(strokeWidth), createOuterStrokeDrawable(strokeWidth), getIconDrawable() });
int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2;
int circleInsetHorizontal = (int) (mShadowRadius);
int circleInsetTop = (int) (mShadowRadius - mShadowOffset);
int circleInsetBottom = (int) (mShadowRadius + mShadowOffset);
layerDrawable.setLayerInset(1, circleInsetHorizontal, circleInsetTop, circleInsetHorizontal, circleInsetBottom);
layerDrawable.setLayerInset(2, (int) (circleInsetHorizontal - halfStrokeWidth), (int) (circleInsetTop - halfStrokeWidth), (int) (circleInsetHorizontal - halfStrokeWidth), (int) (circleInsetBottom - halfStrokeWidth));
layerDrawable.setLayerInset(3, circleInsetHorizontal + iconOffset, circleInsetTop + iconOffset, circleInsetHorizontal + iconOffset, circleInsetBottom + iconOffset);
setBackgroundCompat(layerDrawable);
}
Aggregations