Set RecentView's translationX based on to/from state
Also make sure to reset it when setting the state without animation,
otherwise it's possible for recents to stay translated offscreen
when it's not being animated back (e.g. when swiping up after
launching an app from all apps).
Bug: 74602990
Change-Id: Ib0596c84cfb67242f436f9aba8af53556d5ca743
diff --git a/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java b/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java
index 31261d9..efa83e4 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java
@@ -90,6 +90,11 @@
}
@Override
+ public float getOverviewTranslationX(Launcher launcher) {
+ return 0;
+ }
+
+ @Override
public LauncherState getHistoryForState(LauncherState previousState) {
return previousState == OVERVIEW ? OVERVIEW : NORMAL;
}
diff --git a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
index abb4ecf..09acb1d 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
@@ -57,6 +57,11 @@
}
@Override
+ public float getOverviewTranslationX(Launcher launcher) {
+ return 0;
+ }
+
+ @Override
public void onStateEnabled(Launcher launcher) {
RecentsView rv = launcher.getOverviewPanel();
rv.setOverviewStateEnabled(true);
diff --git a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
index b7f79b3..b68a3d8 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
@@ -16,7 +16,6 @@
package com.android.launcher3.uioverrides;
import static com.android.launcher3.LauncherState.NORMAL;
-import static com.android.launcher3.anim.Interpolators.ACCEL;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -33,7 +32,6 @@
import com.android.launcher3.anim.Interpolators;
import com.android.quickstep.AnimatedFloat;
import com.android.quickstep.views.RecentsView;
-import com.android.quickstep.views.TaskView;
public class RecentsViewStateController implements StateHandler {
@@ -45,8 +43,6 @@
// overall transition while the RecentsView is being shown or hidden.
private final AnimatedFloat mVisibilityMultiplier = new AnimatedFloat(this::onVisibilityProgress);
- private boolean mIsRecentsSlidingInOrOut;
-
public RecentsViewStateController(Launcher launcher) {
mLauncher = launcher;
mRecentsView = launcher.getOverviewPanel();
@@ -59,16 +55,17 @@
if (state.overviewUi) {
mRecentsView.resetTaskVisuals();
}
+ float overviewTranslationX = state.getOverviewTranslationX(mLauncher);
+ int direction = mRecentsView.isRtl() ? -1 : 1;
+ mRecentsView.setTranslationX(overviewTranslationX * direction);
}
@Override
public void setStateWithAnimation(final LauncherState toState,
AnimatorSetBuilder builder, AnimationConfig config) {
- LauncherState fromState = mLauncher.getStateManager().getState();
- mIsRecentsSlidingInOrOut = fromState == NORMAL && toState.overviewUi
- || fromState.overviewUi && toState == NORMAL;
// Scroll to the workspace card before changing to the NORMAL state.
+ LauncherState fromState = mLauncher.getStateManager().getState();
int currPage = mRecentsView.getCurrentPage();
if (fromState.overviewUi && toState == NORMAL && currPage != 0 && !config.userControlled) {
int maxSnapDuration = PagedView.SLOW_PAGE_SNAP_ANIMATION_DURATION;
@@ -83,19 +80,27 @@
mTransitionProgress.animateToValue(toState.overviewUi ? 1 : 0);
progressAnim.setDuration(config.duration);
progressAnim.setInterpolator(Interpolators.LINEAR);
- progressAnim.addListener(new AnimationSuccessListener() {
-
- @Override
- public void onAnimationSuccess(Animator animator) {
- mRecentsView.setCurrentPage(mRecentsView.getPageNearestToCenterOfScreen());
- }
- });
builder.play(progressAnim);
ObjectAnimator visibilityAnim = animateVisibility(toState.overviewUi);
visibilityAnim.setDuration(config.duration);
visibilityAnim.setInterpolator(Interpolators.LINEAR);
builder.play(visibilityAnim);
+
+ int direction = mRecentsView.isRtl() ? -1 : 1;
+ float fromTranslationX = fromState.getOverviewTranslationX(mLauncher) * direction;
+ float toTranslationX = toState.getOverviewTranslationX(mLauncher) * direction;
+ ObjectAnimator translationXAnim = ObjectAnimator.ofFloat(mRecentsView, View.TRANSLATION_X,
+ fromTranslationX, toTranslationX);
+ translationXAnim.setDuration(config.duration);
+ translationXAnim.setInterpolator(Interpolators.ACCEL);
+ if (toState.overviewUi) {
+ translationXAnim.addUpdateListener(valueAnimator -> {
+ // While animating into recents, update the visible task data as needed
+ mRecentsView.loadVisibleTaskData();
+ });
+ }
+ builder.play(translationXAnim);
}
public void setVisibility(boolean isVisible) {
@@ -131,15 +136,6 @@
private void onTransitionProgress() {
applyProgress();
- if (mIsRecentsSlidingInOrOut) {
- float interpolatedProgress = ACCEL.getInterpolation(mTransitionProgress.value);
- // Slide in from the side as we swipe.
- int translation = mRecentsView.getWidth();
- if (mRecentsView.isRtl()) {
- translation = -translation;
- }
- mRecentsView.setTranslationX(translation * (1 - interpolatedProgress));
- }
}
private void onVisibilityProgress() {
@@ -148,9 +144,5 @@
private void applyProgress() {
mRecentsView.setAlpha(mTransitionProgress.value * mVisibilityMultiplier.value);
- if (mIsRecentsSlidingInOrOut) {
- // While animating into recents, update the visible task data as needed
- mRecentsView.loadVisibleTaskData();
- }
}
}
diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java
index 4e6bcdc..e5d8f47 100644
--- a/src/com/android/launcher3/LauncherState.java
+++ b/src/com/android/launcher3/LauncherState.java
@@ -165,6 +165,10 @@
return 1f;
}
+ public float getOverviewTranslationX(Launcher launcher) {
+ return launcher.getDragLayer().getMeasuredWidth();
+ }
+
public void onStateEnabled(Launcher launcher) {
dispatchWindowStateChanged(launcher);
}