Merge "InsetsController: Add missing onWindowInsetsAnimationEnd when cancelling" into rvc-dev

This commit is contained in:
Adrian Roos
2020-05-27 18:08:19 +00:00
committed by Android (Google) Code Review

View File

@@ -70,6 +70,8 @@ import java.util.function.BiFunction;
*/ */
public class InsetsController implements WindowInsetsController, InsetsAnimationControlCallbacks { public class InsetsController implements WindowInsetsController, InsetsAnimationControlCallbacks {
private int mTypesBeingCancelled;
public interface Host { public interface Host {
Handler getHandler(); Handler getHandler();
@@ -809,6 +811,12 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
@AnimationType int animationType, @AnimationType int animationType,
@LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation, @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation,
boolean useInsetsAnimationThread) { boolean useInsetsAnimationThread) {
if ((types & mTypesBeingCancelled) != 0) {
throw new IllegalStateException("Cannot start a new insets animation of "
+ Type.toString(types)
+ " while an existing " + Type.toString(mTypesBeingCancelled)
+ " is being cancelled.");
}
if (types == 0) { if (types == 0) {
// nothing to animate. // nothing to animate.
listener.onCancelled(null); listener.onCancelled(null);
@@ -868,7 +876,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
if (DEBUG) Log.d(TAG, "Animation added to runner. useInsetsAnimationThread: " if (DEBUG) Log.d(TAG, "Animation added to runner. useInsetsAnimationThread: "
+ useInsetsAnimationThread); + useInsetsAnimationThread);
if (cancellationSignal != null) { if (cancellationSignal != null) {
cancellationSignal.setOnCancelListener(runner::cancel); cancellationSignal.setOnCancelListener(() -> {
cancelAnimation(runner, true /* invokeCallback */);
});
} }
if (layoutInsetsDuringAnimation == LAYOUT_INSETS_DURING_ANIMATION_SHOWN) { if (layoutInsetsDuringAnimation == LAYOUT_INSETS_DURING_ANIMATION_SHOWN) {
showDirectly(types); showDirectly(types);
@@ -963,14 +973,20 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
} }
private void cancelExistingControllers(@InsetsType int types) { private void cancelExistingControllers(@InsetsType int types) {
for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { final int originalmTypesBeingCancelled = mTypesBeingCancelled;
InsetsAnimationControlRunner control = mRunningAnimations.get(i).runner; mTypesBeingCancelled |= types;
if ((control.getTypes() & types) != 0) { try {
cancelAnimation(control, true /* invokeCallback */); for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
InsetsAnimationControlRunner control = mRunningAnimations.get(i).runner;
if ((control.getTypes() & types) != 0) {
cancelAnimation(control, true /* invokeCallback */);
}
} }
} if ((types & ime()) != 0) {
if ((types & ime()) != 0) { abortPendingImeControlRequest();
abortPendingImeControlRequest(); }
} finally {
mTypesBeingCancelled = originalmTypesBeingCancelled;
} }
} }
@@ -1029,6 +1045,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
mHost.notifyInsetsChanged(); mHost.notifyInsetsChanged();
} }
} }
if (invokeCallback && runningAnimation.startDispatched) {
dispatchAnimationEnd(runningAnimation.runner.getAnimation());
}
break; break;
} }
} }