Ensure that animated key button drawable has callbacks

- The animated drawable never has callbacks set, so if nothing
  else invalidates while the AVD is drawing, we may not end
  up invalidating.  Haven't actually been able to repro the
  original issue but, this is a potential cause.

Bug: 158680912
Test: Haven't been able to repro the original issue, but
      we ensure that the rotation button still works

ehange-Id: Iba00785cf85df2e85a19e1b44a17953877514b68
Change-Id: I4dc673824e1cf068ee0eb9953c7e3264c22fa7f5
This commit is contained in:
Winson Chung
2020-07-13 21:32:08 -07:00
parent 0811c47412
commit 2cd3b901f9

View File

@@ -80,6 +80,22 @@ public class KeyButtonDrawable extends Drawable {
private final Paint mShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
private final ShadowDrawableState mState;
private AnimatedVectorDrawable mAnimatedDrawable;
private final Callback mAnimatedDrawableCallback = new Callback() {
@Override
public void invalidateDrawable(@NonNull Drawable who) {
invalidateSelf();
}
@Override
public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {
scheduleSelf(what, when);
}
@Override
public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) {
unscheduleSelf(what);
}
};
public KeyButtonDrawable(Drawable d, @ColorInt int lightColor, @ColorInt int darkColor,
boolean horizontalFlip, Color ovalBackgroundColor) {
@@ -97,6 +113,7 @@ public class KeyButtonDrawable extends Drawable {
}
if (canAnimate()) {
mAnimatedDrawable = (AnimatedVectorDrawable) mState.mChildState.newDrawable().mutate();
mAnimatedDrawable.setCallback(mAnimatedDrawableCallback);
setDrawableBounds(mAnimatedDrawable);
}
}