Clamp ink color alpha

On the old version of the ripple, the alpha is limited to 50%, we should
also do the same on the latest designs.

Bug: 184165556
Test: manual
Change-Id: Iec14394e0a0bca00283a713a409dd0794eb6fb9a
This commit is contained in:
Lucas Dupin
2021-04-20 21:36:37 -07:00
parent 469e1b4942
commit fe06390a3c

View File

@@ -23,6 +23,7 @@ import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.animation.ValueAnimator;
import android.annotation.ColorInt;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -960,9 +961,11 @@ public class RippleDrawable extends LayerDrawable {
float radius = getComputedRadius();
RippleAnimationSession.AnimationProperties<Float, Paint> properties;
RippleShader shader = new RippleShader();
final int color = mMaskColorFilter == null
// Grab the color for the current state and cut the alpha channel in
// half so that the ripple and background together yield full alpha.
final int color = clampAlpha(mMaskColorFilter == null
? mState.mColor.getColorForState(getState(), Color.BLACK)
: mMaskColorFilter.getColor();
: mMaskColorFilter.getColor());
final int effectColor = mState.mEffectColor.getColorForState(getState(), Color.MAGENTA);
shader.setColor(color, effectColor);
shader.setOrigin(cx, cy);
@@ -984,6 +987,13 @@ public class RippleDrawable extends LayerDrawable {
return properties;
}
private int clampAlpha(@ColorInt int color) {
if (Color.alpha(color) > 128) {
return (color & 0x00FFFFFF) | 0x80000000;
}
return color;
}
private boolean shouldUseCanvasProps(Canvas c) {
return !mForceSoftware && c.isHardwareAccelerated();
}
@@ -1194,10 +1204,7 @@ public class RippleDrawable extends LayerDrawable {
// Grab the color for the current state and cut the alpha channel in
// half so that the ripple and background together yield full alpha.
int color = mState.mColor.getColorForState(getState(), Color.BLACK);
if (Color.alpha(color) > 128) {
color = (color & 0x00FFFFFF) | 0x80000000;
}
final int color = clampAlpha(mState.mColor.getColorForState(getState(), Color.BLACK));
final Paint p = mRipplePaint;
if (mMaskColorFilter != null) {