use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method createCircleSelectorDrawable.
public static Drawable createCircleSelectorDrawable(int color, int leftInset, int rightInset) {
if (Build.VERSION.SDK_INT >= 21) {
maskPaint.setColor(0xffffffff);
Drawable maskDrawable = new Drawable() {
@Override
public void draw(Canvas canvas) {
android.graphics.Rect bounds = getBounds();
final int rad = (Math.max(bounds.width(), bounds.height()) / 2) + leftInset + rightInset;
canvas.drawCircle(bounds.centerX() - leftInset + rightInset, bounds.centerY(), rad, maskPaint);
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
}
@Override
public int getOpacity() {
return PixelFormat.UNKNOWN;
}
};
ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { color });
return new RippleDrawable(colorStateList, null, 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(0x00000000));
return stateListDrawable;
}
}
use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method getRoundRectSelectorDrawable.
public static Drawable getRoundRectSelectorDrawable(int color) {
if (Build.VERSION.SDK_INT >= 21) {
Drawable maskDrawable = createRoundRectDrawable(AndroidUtilities.dp(3), 0xffffffff);
ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { (color & 0x00ffffff) | 0x19000000 });
return new RippleDrawable(colorStateList, null, maskDrawable);
} else {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, createRoundRectDrawable(AndroidUtilities.dp(3), (color & 0x00ffffff) | 0x19000000));
stateListDrawable.addState(new int[] { android.R.attr.state_selected }, createRoundRectDrawable(AndroidUtilities.dp(3), (color & 0x00ffffff) | 0x19000000));
stateListDrawable.addState(StateSet.WILD_CARD, new ColorDrawable(0x00000000));
return stateListDrawable;
}
}
use of android.graphics.drawable.RippleDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method createSimpleSelectorRoundRectDrawable.
public static Drawable createSimpleSelectorRoundRectDrawable(int rad, int defaultColor, int pressedColor, int maskColor) {
ShapeDrawable defaultDrawable = new ShapeDrawable(new RoundRectShape(new float[] { rad, rad, rad, rad, rad, rad, rad, rad }, null, null));
defaultDrawable.getPaint().setColor(defaultColor);
ShapeDrawable pressedDrawable = new ShapeDrawable(new RoundRectShape(new float[] { rad, rad, rad, rad, rad, rad, rad, rad }, null, null));
pressedDrawable.getPaint().setColor(maskColor);
if (Build.VERSION.SDK_INT >= 21) {
ColorStateList colorStateList = new ColorStateList(new int[][] { StateSet.WILD_CARD }, new int[] { pressedColor });
return new RippleDrawable(colorStateList, defaultDrawable, pressedDrawable);
} else {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressedDrawable);
stateListDrawable.addState(new int[] { android.R.attr.state_selected }, 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 PagerSlidingTabStrip method addIconTab.
private void addIconTab(final int position, Drawable drawable, CharSequence contentDescription) {
ImageView tab = new ImageView(getContext()) {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (pager.getAdapter() instanceof IconTabProvider) {
((IconTabProvider) pager.getAdapter()).customOnDraw(canvas, position);
}
}
@Override
public void setSelected(boolean selected) {
super.setSelected(selected);
Drawable background = getBackground();
if (Build.VERSION.SDK_INT >= 21 && background != null) {
int color = Theme.getColor(selected ? Theme.key_chat_emojiPanelIconSelected : Theme.key_chat_emojiBottomPanelIcon);
Theme.setSelectorDrawableColor(background, Color.argb(30, Color.red(color), Color.green(color), Color.blue(color)), true);
}
}
};
tab.setFocusable(true);
if (Build.VERSION.SDK_INT >= 21) {
RippleDrawable rippleDrawable = (RippleDrawable) Theme.createSelectorDrawable(Theme.getColor(Theme.key_chat_emojiBottomPanelIcon));
Theme.setRippleDrawableForceSoftware(rippleDrawable);
tab.setBackground(rippleDrawable);
}
tab.setImageDrawable(drawable);
tab.setScaleType(ImageView.ScaleType.CENTER);
tab.setOnClickListener(v -> {
if (pager.getAdapter() instanceof IconTabProvider) {
if (!((IconTabProvider) pager.getAdapter()).canScrollToTab(position)) {
return;
}
}
pager.setCurrentItem(position, false);
});
tabsContainer.addView(tab);
tab.setSelected(position == currentPosition);
tab.setContentDescription(contentDescription);
}
use of android.graphics.drawable.RippleDrawable in project GreenHouse by utsanjan.
the class MaterialCardViewHelper method updateRippleColor.
private void updateRippleColor() {
Drawable drawable;
if (!RippleUtils.USE_FRAMEWORK_RIPPLE || (drawable = this.rippleDrawable) == null) {
MaterialShapeDrawable materialShapeDrawable = this.compatRippleDrawable;
if (materialShapeDrawable != null) {
materialShapeDrawable.setFillColor(this.rippleColor);
return;
}
return;
}
((RippleDrawable) drawable).setColor(this.rippleColor);
}
Aggregations