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
This commit is contained in:
Tony 2018-03-14 12:05:00 +00:00
parent 9da6c526cb
commit 3bb5e8e56c
4 changed files with 33 additions and 27 deletions

View File

@ -89,6 +89,11 @@ public class AllAppsState extends LauncherState {
return 0;
}
@Override
public float getOverviewTranslationX(Launcher launcher) {
return 0;
}
@Override
public LauncherState getHistoryForState(LauncherState previousState) {
return previousState == OVERVIEW ? OVERVIEW : NORMAL;

View File

@ -56,6 +56,11 @@ public class OverviewState extends LauncherState {
return getScaleAndTranslationForPageRect(launcher, pageRect);
}
@Override
public float getOverviewTranslationX(Launcher launcher) {
return 0;
}
@Override
public void onStateEnabled(Launcher launcher) {
RecentsView rv = launcher.getOverviewPanel();

View File

@ -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.AnimatorSetBuilder;
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 @@ public class RecentsViewStateController implements StateHandler {
// 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 @@ public class RecentsViewStateController implements StateHandler {
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 @@ public class RecentsViewStateController implements StateHandler {
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 @@ public class RecentsViewStateController implements StateHandler {
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 @@ public class RecentsViewStateController implements StateHandler {
private void applyProgress() {
mRecentsView.setAlpha(mTransitionProgress.value * mVisibilityMultiplier.value);
if (mIsRecentsSlidingInOrOut) {
// While animating into recents, update the visible task data as needed
mRecentsView.loadVisibleTaskData();
}
}
}

View File

@ -165,6 +165,10 @@ public class LauncherState {
return 1f;
}
public float getOverviewTranslationX(Launcher launcher) {
return launcher.getDragLayer().getMeasuredWidth();
}
public void onStateEnabled(Launcher launcher) {
dispatchWindowStateChanged(launcher);
}