Support swiping between states

- Swiping down on hotseat from overview goes to workspace
- Can swipe up through overview to get to all apps

Bug: 76449024
Change-Id: I7f76d92da976e268cc2a97e55746cca4603e6620
This commit is contained in:
Tony Wickham
2018-03-28 11:21:49 -07:00
committed by Tony
parent 86d7b2d81d
commit 274b9529ff
5 changed files with 65 additions and 30 deletions

View File

@@ -19,7 +19,6 @@ import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelo
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.util.Log;
import android.view.MotionEvent;
@@ -58,6 +57,7 @@ public abstract class AbstractStateChangeTouchController extends AnimatorListene
private float mStartProgress;
// Ratio of transition process [0, 1] to drag displacement (px)
private float mProgressMultiplier;
private float mDisplacementShift;
public AbstractStateChangeTouchController(Launcher l, SwipeDetector.Direction dir) {
mLauncher = l;
@@ -68,7 +68,7 @@ public abstract class AbstractStateChangeTouchController extends AnimatorListene
/**
* Initializes the {@code mFromState} and {@code mToState} and swipe direction to use for
* the detector. In can of disabling swipe, return 0.
* the detector. In case of disabling swipe, return 0.
*/
protected abstract int getSwipeDirection(MotionEvent ev);
@@ -122,16 +122,36 @@ public abstract class AbstractStateChangeTouchController extends AnimatorListene
return mLauncher.getAllAppsController().getShiftRange();
}
protected abstract LauncherState getTargetState(LauncherState fromState,
boolean isDragTowardPositive);
protected abstract float initCurrentAnimation();
private boolean reinitCurrentAnimation(boolean reachedToState, boolean isDragTowardPositive) {
LauncherState newFromState = mFromState == null ? mLauncher.getStateManager().getState()
: reachedToState ? mToState : mFromState;
LauncherState newToState = getTargetState(newFromState, isDragTowardPositive);
if (newFromState == mFromState && newToState == mToState || (newFromState == newToState)) {
return false;
}
mFromState = newFromState;
mToState = newToState;
mStartProgress = 0;
mProgressMultiplier = initCurrentAnimation();
mCurrentAnimation.getTarget().addListener(this);
mCurrentAnimation.dispatchOnStart();
return true;
}
@Override
public void onDragStart(boolean start) {
if (mCurrentAnimation == null) {
mStartProgress = 0;
mProgressMultiplier = initCurrentAnimation();
mCurrentAnimation.getTarget().addListener(this);
mCurrentAnimation.dispatchOnStart();
mFromState = mToState = null;
reinitCurrentAnimation(false, mDetector.wasInitialTouchPositive());
mDisplacementShift = 0;
} else {
mCurrentAnimation.pause();
mStartProgress = mCurrentAnimation.getProgressFraction();
@@ -140,8 +160,19 @@ public abstract class AbstractStateChangeTouchController extends AnimatorListene
@Override
public boolean onDrag(float displacement, float velocity) {
float deltaProgress = mProgressMultiplier * displacement;
updateProgress(deltaProgress + mStartProgress);
float deltaProgress = mProgressMultiplier * (displacement - mDisplacementShift);
float progress = deltaProgress + mStartProgress;
updateProgress(progress);
boolean isDragTowardPositive = (displacement - mDisplacementShift) < 0;
if (progress <= 0) {
if (reinitCurrentAnimation(false, isDragTowardPositive)) {
mDisplacementShift = displacement;
}
} else if (progress >= 1) {
if (reinitCurrentAnimation(true, isDragTowardPositive)) {
mDisplacementShift = displacement;
}
}
return true;
}