From b33471a21f41931791f556104cda01ddcde3d302 Mon Sep 17 00:00:00 2001 From: Jeremy Sim Date: Wed, 17 Aug 2022 14:19:03 -0400 Subject: [PATCH] Fix bug with Launcher animation canceling, esp. around OverviewSplitSelect This commit fixes a bug where the user could cancel animations when transitioning between Launcher states, potentially resulting in a state where Overview elements (task thumbnails etc.) were wrongly hidden or invisible. The bug occurred because functions such as createInitialSplitSelectAnimation() and createAtomicAnimation() did not carry out any cleanup upon animation failure. This resulted in RecentsView potentially being in a polluted state for the next launch. Bug was fixed by adding cleanup routines to two onAnimationEnd listeners. Fixes: 242715097 Test: Manual Change-Id: I05415ecf515e247aa535e3ca8371e540c3189b01 --- .../BaseRecentsViewStateController.java | 18 +++---- .../fallback/FallbackRecentsView.java | 5 ++ .../quickstep/views/FloatingTaskView.java | 24 +++++++++ .../quickstep/views/GroupedTaskView.java | 6 +++ .../quickstep/views/LauncherRecentsView.java | 5 ++ .../android/quickstep/views/RecentsView.java | 50 ++++++------------- .../com/android/quickstep/views/TaskView.java | 17 +++++++ .../launcher3/statemanager/StateManager.java | 16 ++++++ 8 files changed, 97 insertions(+), 44 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java b/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java index 8782ee65a5..2e4e7397aa 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java @@ -28,11 +28,10 @@ import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SP import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_X; import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_Y; import static com.android.launcher3.states.StateAnimationConfig.SKIP_OVERVIEW; +import static com.android.quickstep.views.FloatingTaskView.PRIMARY_TRANSLATE_OFFSCREEN; import static com.android.quickstep.views.RecentsView.ADJACENT_PAGE_HORIZONTAL_OFFSET; -import static com.android.quickstep.views.RecentsView.FIRST_FLOATING_TASK_TRANSLATE_OFFSCREEN; import static com.android.quickstep.views.RecentsView.RECENTS_GRID_PROGRESS; import static com.android.quickstep.views.RecentsView.RECENTS_SCALE_PROPERTY; -import static com.android.quickstep.views.RecentsView.SPLIT_INSTRUCTIONS_FADE; import static com.android.quickstep.views.RecentsView.TASK_SECONDARY_TRANSLATION; import static com.android.quickstep.views.RecentsView.TASK_THUMBNAIL_SPLASH_ALPHA; @@ -112,6 +111,7 @@ public abstract class BaseRecentsViewStateController // TODO (b/238651489): Refactor state management to avoid need for double check FloatingTaskView floatingTask = mRecentsView.getFirstFloatingTaskView(); if (floatingTask != null) { + // We are in split selection state currently, transitioning to another state DragLayer dragLayer = mLauncher.getDragLayer(); RectF onScreenRectF = new RectF(); Utilities.getBoundsForViewInDragLayer(mLauncher.getDragLayer(), floatingTask, @@ -127,8 +127,8 @@ public abstract class BaseRecentsViewStateController ); setter.setFloat( - mRecentsView, - FIRST_FLOATING_TASK_TRANSLATE_OFFSCREEN, + mRecentsView.getFirstFloatingTaskView(), + PRIMARY_TRANSLATE_OFFSCREEN, mRecentsView.getPagedOrientationHandler() .getFloatingTaskOffscreenTranslationTarget( floatingTask, @@ -140,14 +140,14 @@ public abstract class BaseRecentsViewStateController ANIM_OVERVIEW_SPLIT_SELECT_FLOATING_TASK_TRANSLATE_OFFSCREEN, LINEAR )); - setter.setFloat( - mRecentsView, - SPLIT_INSTRUCTIONS_FADE, - 1, + setter.setViewAlpha( + mRecentsView.getSplitInstructionsView(), + 0, config.getInterpolator( ANIM_OVERVIEW_SPLIT_SELECT_INSTRUCTIONS_FADE, LINEAR - )); + ) + ); } } diff --git a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java index eb739a6972..7c96bf8a78 100644 --- a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java +++ b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java @@ -226,6 +226,11 @@ public class FallbackRecentsView extends RecentsView PRIMARY_TRANSLATE_OFFSCREEN = + new FloatProperty("floatingTaskPrimaryTranslateOffscreen") { + @Override + public void setValue(FloatingTaskView view, float translation) { + ((RecentsView) view.mActivity.getOverviewPanel()).getPagedOrientationHandler() + .setFloatingTaskPrimaryTranslation( + view, + translation, + view.mActivity.getDeviceProfile() + ); + } + + @Override + public Float get(FloatingTaskView view) { + return ((RecentsView) view.mActivity.getOverviewPanel()) + .getPagedOrientationHandler() + .getFloatingTaskPrimaryTranslation( + view, + view.mActivity.getDeviceProfile() + ); + } + }; + private FloatingTaskThumbnailView mThumbnailView; private SplitPlaceholderView mSplitPlaceholderView; private RectF mStartingPosition; diff --git a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java index a870f9cc8f..2539ed6d26 100644 --- a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java +++ b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java @@ -319,4 +319,10 @@ public class GroupedTaskView extends TaskView { super.applyThumbnailSplashAlpha(); mSnapshotView2.setSplashAlpha(mTaskThumbnailSplashAlpha); } + + @Override + void setThumbnailVisibility(int visibility) { + super.setThumbnailVisibility(visibility); + mSnapshotView2.setVisibility(visibility); + } } diff --git a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java index 6a33d36ab4..de7ccad7a3 100644 --- a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java +++ b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java @@ -119,6 +119,11 @@ public class LauncherRecentsView extends RecentsView FIRST_FLOATING_TASK_TRANSLATE_OFFSCREEN = - new FloatProperty("firstFloatingTaskTranslateOffscreen") { - @Override - public void setValue(RecentsView view, float translation) { - view.getPagedOrientationHandler().setFloatingTaskPrimaryTranslation( - view.mFirstFloatingTaskView, - translation, - view.mActivity.getDeviceProfile() - ); - } - - @Override - public Float get(RecentsView view) { - return view.getPagedOrientationHandler().getFloatingTaskPrimaryTranslation( - view.mFirstFloatingTaskView, - view.mActivity.getDeviceProfile() - ); - } - }; - - public static final FloatProperty SPLIT_INSTRUCTIONS_FADE = - new FloatProperty("splitInstructionsFade") { - @Override - public void setValue(RecentsView view, float fade) { - view.mSplitInstructionsView.setAlpha(1 - fade); - } - - @Override - public Float get(RecentsView view) { - return 1 - view.mSplitInstructionsView.getAlpha(); - } - }; - // OverScroll constants private static final int OVERSCROLL_PAGE_SNAP_ANIMATION_DURATION = 270; @@ -2827,7 +2794,11 @@ public abstract class RecentsView ICON_ALPHA = + new FloatProperty("iconAlpha") { + @Override + public void setValue(TaskView taskView, float v) { + taskView.mIconView.setAlpha(v); + } + + @Override + public Float get(TaskView taskView) { + return taskView.mIconView.getAlpha(); + } + }; + @Nullable protected Task mTask; protected TaskThumbnailView mSnapshotView; @@ -1488,6 +1501,10 @@ public class TaskView extends FrameLayout implements Reusable { return display != null ? display.getDisplayId() : DEFAULT_DISPLAY; } + void setThumbnailVisibility(int visibility) { + mSnapshotView.setVisibility(visibility); + } + /** * We update and subsequently draw these in {@link #setFullscreenProgress(float)}. */ diff --git a/src/com/android/launcher3/statemanager/StateManager.java b/src/com/android/launcher3/statemanager/StateManager.java index 2aa9ddeb50..c44e1e1784 100644 --- a/src/com/android/launcher3/statemanager/StateManager.java +++ b/src/com/android/launcher3/statemanager/StateManager.java @@ -342,6 +342,11 @@ public class StateManager> { public void onAnimationSuccess(Animator animator) { onStateTransitionEnd(state); } + + @Override + public void onAnimationCancel(Animator animation) { + onStateTransitionFailed(state); + } }; } @@ -354,6 +359,12 @@ public class StateManager> { } } + private void onStateTransitionFailed(STATE_TYPE state) { + for (int i = mListeners.size() - 1; i >= 0; i--) { + mListeners.get(i).onStateTransitionFailed(state); + } + } + private void onStateTransitionEnd(STATE_TYPE state) { // Only change the stable states after the transitions have finished if (state != mCurrentStableState) { @@ -588,6 +599,11 @@ public class StateManager> { default void onStateTransitionStart(STATE_TYPE toState) { } + /** + * If the state transition animation fails (e.g. is canceled by the user), this fires. + */ + default void onStateTransitionFailed(STATE_TYPE toState) { } + default void onStateTransitionComplete(STATE_TYPE finalState) { } }