Dedupe updates to the home handle tint

- The dark intensity & home handle was updating but due to the
  interpolator used and the long duration of the animation, the
  rounded rgb/alpha values didn't actually change between every
  animation frame.

Bug: 143565744
Test: Trigger nav bar handle tint change, ensure no unnecessary updates
Change-Id: I44a403f381b4216d07cecb74097e52c4abc85465
This commit is contained in:
Winson Chung
2019-10-29 20:32:21 -07:00
parent a96a062a56
commit a217afdc69
5 changed files with 57 additions and 18 deletions

View File

@@ -47,6 +47,7 @@ public class CornerHandleView extends View {
private int mLightColor;
private int mDarkColor;
private Path mPath;
private boolean mRequiresInvalidate;
public CornerHandleView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -67,6 +68,15 @@ public class CornerHandleView extends View {
updatePath();
}
@Override
public void setAlpha(float alpha) {
super.setAlpha(alpha);
if (alpha > 0f && mRequiresInvalidate) {
mRequiresInvalidate = false;
invalidate();
}
}
private void updatePath() {
mPath = new Path();
@@ -104,11 +114,16 @@ public class CornerHandleView extends View {
* appropriately. Intention is to match the home handle color.
*/
public void updateDarkness(float darkIntensity) {
mPaint.setColor((int) ArgbEvaluator.getInstance().evaluate(darkIntensity,
mLightColor,
mDarkColor));
if (getVisibility() == VISIBLE) {
invalidate();
int color = (int) ArgbEvaluator.getInstance().evaluate(darkIntensity,
mLightColor, mDarkColor);
if (mPaint.getColor() != color) {
mPaint.setColor(color);
if (getVisibility() == VISIBLE && getAlpha() > 0) {
invalidate();
} else {
// If we are currently invisible, then invalidate when we are next made visible
mRequiresInvalidate = true;
}
}
}

View File

@@ -67,8 +67,10 @@ public final class EdgeLight {
}
/** Sets the edge light color. */
public void setColor(@ColorInt int color) {
public boolean setColor(@ColorInt int color) {
boolean changed = mColor != color;
mColor = color;
return changed;
}
/** Returns the edge light length, in units of the total device perimeter. */

View File

@@ -259,10 +259,13 @@ public class InvocationLightsView extends View
if (mUseNavBarColor) {
@ColorInt int invocationColor = (int) ArgbEvaluator.getInstance().evaluate(
darkIntensity, mLightColor, mDarkColor);
boolean changed = true;
for (EdgeLight light : mAssistInvocationLights) {
light.setColor(invocationColor);
changed &= light.setColor(invocationColor);
}
if (changed) {
invalidate();
}
invalidate();
}
}

View File

@@ -203,10 +203,16 @@ public class ButtonDispatcher {
mFadeAnimator.addUpdateListener(mAlphaListener);
mFadeAnimator.start();
} else {
mAlpha = alpha;
final int N = mViews.size();
for (int i = 0; i < N; i++) {
mViews.get(i).setAlpha(alpha);
// Discretize the alpha updates to prevent too frequent updates when there is a long
// alpha animation
int prevAlpha = (int) (getAlpha() * 255);
int nextAlpha = (int) (alpha * 255);
if (prevAlpha != nextAlpha) {
mAlpha = nextAlpha / 255f;
final int N = mViews.size();
for (int i = 0; i < N; i++) {
mViews.get(i).setAlpha(mAlpha);
}
}
}
}

View File

@@ -31,13 +31,13 @@ import com.android.settingslib.Utils;
import com.android.systemui.R;
public class NavigationHandle extends View implements ButtonInterface {
private float mDarkIntensity = -1;
private final Paint mPaint = new Paint();
private @ColorInt final int mLightColor;
private @ColorInt final int mDarkColor;
private final int mRadius;
private final int mBottom;
private boolean mRequiresInvalidate;
public NavigationHandle(Context context) {
this(context, null);
@@ -59,6 +59,15 @@ public class NavigationHandle extends View implements ButtonInterface {
setFocusable(false);
}
@Override
public void setAlpha(float alpha) {
super.setAlpha(alpha);
if (alpha > 0f && mRequiresInvalidate) {
mRequiresInvalidate = false;
invalidate();
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
@@ -85,11 +94,15 @@ public class NavigationHandle extends View implements ButtonInterface {
@Override
public void setDarkIntensity(float intensity) {
if (mDarkIntensity != intensity) {
mPaint.setColor((int) ArgbEvaluator.getInstance().evaluate(intensity, mLightColor,
mDarkColor));
mDarkIntensity = intensity;
invalidate();
int color = (int) ArgbEvaluator.getInstance().evaluate(intensity, mLightColor, mDarkColor);
if (mPaint.getColor() != color) {
mPaint.setColor(color);
if (getVisibility() == VISIBLE && getAlpha() > 0) {
invalidate();
} else {
// If we are currently invisible, then invalidate when we are next made visible
mRequiresInvalidate = true;
}
}
}