use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method setMaskDrawableRad.
public static void setMaskDrawableRad(Drawable rippleDrawable, int top, int bottom) {
if (Build.VERSION.SDK_INT < 21) {
return;
}
if (rippleDrawable instanceof RippleDrawable) {
RippleDrawable drawable = (RippleDrawable) rippleDrawable;
int count = drawable.getNumberOfLayers();
for (int a = 0; a < count; a++) {
Drawable layer = drawable.getDrawable(a);
if (layer instanceof RippleRadMaskDrawable) {
drawable.setDrawableByLayerId(android.R.id.mask, new RippleRadMaskDrawable(top, bottom));
break;
}
}
}
}
use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method setSelectorDrawableColor.
public static void setSelectorDrawableColor(Drawable drawable, int color, boolean selected) {
if (drawable instanceof StateListDrawable) {
try {
Drawable state;
if (selected) {
state = getStateDrawable(drawable, 0);
if (state instanceof ShapeDrawable) {
((ShapeDrawable) state).getPaint().setColor(color);
} else {
state.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
}
state = getStateDrawable(drawable, 1);
} else {
state = getStateDrawable(drawable, 2);
}
if (state instanceof ShapeDrawable) {
((ShapeDrawable) state).getPaint().setColor(color);
} else {
state.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
}
} catch (Throwable ignore) {
}
} else if (Build.VERSION.SDK_INT >= 21 && drawable instanceof RippleDrawable) {
RippleDrawable rippleDrawable = (RippleDrawable) drawable;
if (selected) {
rippleDrawable.setColor(new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { color }));
} else {
if (rippleDrawable.getNumberOfLayers() > 0) {
Drawable drawable1 = rippleDrawable.getDrawable(0);
if (drawable1 instanceof ShapeDrawable) {
((ShapeDrawable) drawable1).getPaint().setColor(color);
} else {
drawable1.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
}
}
}
}
}
use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method createSimpleSelectorCircleDrawable.
public static Drawable createSimpleSelectorCircleDrawable(int size, int defaultColor, int pressedColor) {
OvalShape ovalShape = new OvalShape();
ovalShape.resize(size, size);
ShapeDrawable defaultDrawable = new ShapeDrawable(ovalShape);
defaultDrawable.getPaint().setColor(defaultColor);
ShapeDrawable pressedDrawable = new ShapeDrawable(ovalShape);
if (Build.VERSION.SDK_INT >= 21) {
pressedDrawable.getPaint().setColor(0xffffffff);
ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { pressedColor });
return new RippleDrawable(colorStateList, defaultDrawable, pressedDrawable);
} else {
pressedDrawable.getPaint().setColor(pressedColor);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressedDrawable);
stateListDrawable.addState(new int[] { android.R.attr.state_focused }, pressedDrawable);
stateListDrawable.addState(StateSet.WILD_CARD, defaultDrawable);
return stateListDrawable;
}
}
use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method getSelectorDrawable.
public static Drawable getSelectorDrawable(int color, String backgroundColor) {
if (backgroundColor != null) {
if (Build.VERSION.SDK_INT >= 21) {
Drawable maskDrawable = new ColorDrawable(0xffffffff);
ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { color });
return new RippleDrawable(colorStateList, new ColorDrawable(getColor(backgroundColor)), maskDrawable);
} else {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(color));
stateListDrawable.addState(new int[] { android.R.attr.state_selected }, new ColorDrawable(color));
stateListDrawable.addState(StateSet.WILD_CARD, new ColorDrawable(getColor(backgroundColor)));
return stateListDrawable;
}
} else {
return createSelectorDrawable(color, 2);
}
}
use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method createSelectorDrawable.
public static Drawable createSelectorDrawable(int color, int maskType, int radius) {
Drawable drawable;
if (Build.VERSION.SDK_INT >= 21) {
Drawable maskDrawable = null;
if ((maskType == 1 || maskType == 5) && Build.VERSION.SDK_INT >= 23) {
maskDrawable = null;
} else if (maskType == 1 || maskType == 3 || maskType == 4 || maskType == 5 || maskType == 6 || maskType == 7) {
maskPaint.setColor(0xffffffff);
maskDrawable = new Drawable() {
RectF rect;
@Override
public void draw(Canvas canvas) {
android.graphics.Rect bounds = getBounds();
if (maskType == 7) {
if (rect == null) {
rect = new RectF();
}
rect.set(bounds);
canvas.drawRoundRect(rect, AndroidUtilities.dp(6), AndroidUtilities.dp(6), maskPaint);
} else {
int rad;
if (maskType == 1 || maskType == 6) {
rad = AndroidUtilities.dp(20);
} else if (maskType == 3) {
rad = (Math.max(bounds.width(), bounds.height()) / 2);
} else {
rad = (int) Math.ceil(Math.sqrt((bounds.left - bounds.centerX()) * (bounds.left - bounds.centerX()) + (bounds.top - bounds.centerY()) * (bounds.top - bounds.centerY())));
}
canvas.drawCircle(bounds.centerX(), bounds.centerY(), rad, maskPaint);
}
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
}
@Override
public int getOpacity() {
return PixelFormat.UNKNOWN;
}
};
} else if (maskType == 2) {
maskDrawable = new ColorDrawable(0xffffffff);
}
ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { color });
RippleDrawable rippleDrawable = new RippleDrawable(colorStateList, null, maskDrawable);
if (Build.VERSION.SDK_INT >= 23) {
if (maskType == 1) {
rippleDrawable.setRadius(radius <= 0 ? AndroidUtilities.dp(20) : radius);
} else if (maskType == 5) {
rippleDrawable.setRadius(RippleDrawable.RADIUS_AUTO);
}
}
return rippleDrawable;
} else {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(color));
stateListDrawable.addState(new int[] { android.R.attr.state_selected }, new ColorDrawable(color));
stateListDrawable.addState(StateSet.WILD_CARD, new ColorDrawable(0x00000000));
return stateListDrawable;
}
}
Aggregations