use of android.graphics.drawable.StateListDrawable in project BoomMenu by Nightonke.
the class Util method getRectangleStateListBitmapDrawable.
// Bitmap drawable in state-list drawable is able to perform a click-effect.
public static StateListDrawable getRectangleStateListBitmapDrawable(View view, int width, int height, int cornerRadius, int normalColor, int highlightedColor, int unableColor) {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, getRectangleBitmapDrawable(view, width, height, cornerRadius, highlightedColor));
stateListDrawable.addState(new int[] { -android.R.attr.state_enabled }, getRectangleBitmapDrawable(view, width, height, cornerRadius, unableColor));
stateListDrawable.addState(StateSet.WILD_CARD, getRectangleBitmapDrawable(view, width, height, cornerRadius, normalColor));
return stateListDrawable;
}
use of android.graphics.drawable.StateListDrawable in project BoomMenu by Nightonke.
the class Util method getRectangleStateListGradientDrawable.
// Gradient drawable in state-list drawable is not able to perform a click-effect.
public static StateListDrawable getRectangleStateListGradientDrawable(View view, int cornerRadius, int normalColor, int highlightedColor, int unableColor) {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, getRectangleDrawable(view, cornerRadius, highlightedColor));
stateListDrawable.addState(new int[] { -android.R.attr.state_enabled }, getRectangleDrawable(view, cornerRadius, unableColor));
stateListDrawable.addState(StateSet.WILD_CARD, getRectangleDrawable(view, cornerRadius, normalColor));
return stateListDrawable;
}
use of android.graphics.drawable.StateListDrawable in project HoloEverywhere by Prototik.
the class ProgressBar method tileify.
private Drawable tileify(Drawable drawable, boolean clip) {
if (drawable instanceof LayerDrawable) {
LayerDrawable background = (LayerDrawable) drawable;
final int N = background.getNumberOfLayers();
Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
int id = background.getId(i);
outDrawables[i] = tileify(background.getDrawable(i), id == android.R.id.progress || id == android.R.id.secondaryProgress);
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else if (drawable instanceof StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = ReflectHelper.invoke(in, "getStateCount", int.class);
for (int i = 0; i < numStates; i++) {
out.addState(ReflectHelper.invoke(in, "getStateSet", int[].class, i), tileify(ReflectHelper.invoke(in, "getStateDrawable", Drawable.class, i), clip));
}
return out;
} else if (drawable instanceof BitmapDrawable) {
final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
if (mSampleTile == null) {
mSampleTile = tileBitmap;
}
final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
shapeDrawable.getPaint().setShader(bitmapShader);
return clip ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
}
return drawable;
}
use of android.graphics.drawable.StateListDrawable 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.StateListDrawable in project UltimateRecyclerView by cymcsg.
the class JellyBeanFloatingActionButton method createFillDrawable.
/**
* more advanced usage for fillable in alpha
*
* @param circleRect the defined rectangle
* @return StateListDrawable item
*/
protected StateListDrawable createFillDrawable(RectF circleRect) {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[] { android.R.attr.state_pressed }, createAlphaDrawble(circleRect, mColorPressed, mAlpha_press));
drawable.addState(new int[] {}, createAlphaDrawble(circleRect, mColorNormal, mAlpha_normal));
return drawable;
}
Aggregations