Only detect swipe directions that lead to new states

This cleans up the code and ensures that the current state animation
is always initialized when we get drag events.

Also log when we pass through states.

Bug: 78017680
Change-Id: I54ab42923ed539940ea708973ad65f5793669c11
This commit is contained in:
Tony Wickham
2018-04-24 13:42:59 -07:00
parent f325b19de3
commit 52240a3aa0
5 changed files with 72 additions and 52 deletions

View File

@@ -15,6 +15,9 @@
*/
package com.android.launcher3.touch;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
@@ -27,6 +30,7 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.util.PendingAnimation;
import com.android.launcher3.util.TouchController;
@@ -65,12 +69,6 @@ public abstract class AbstractStateChangeTouchController
protected abstract boolean canInterceptTouch(MotionEvent ev);
/**
* Initializes the {@code mFromState} and {@code mToState} and swipe direction to use for
* the detector. In case of disabling swipe, return 0.
*/
protected abstract int getSwipeDirection(MotionEvent ev);
@Override
public final boolean onControllerInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
@@ -94,7 +92,7 @@ public abstract class AbstractStateChangeTouchController
ignoreSlopWhenSettling = true;
}
} else {
directionsToDetectScroll = getSwipeDirection(ev);
directionsToDetectScroll = getSwipeDirection();
if (directionsToDetectScroll == 0) {
mNoIntercept = true;
return false;
@@ -112,6 +110,18 @@ public abstract class AbstractStateChangeTouchController
return mDetector.isDraggingOrSettling();
}
private int getSwipeDirection() {
LauncherState fromState = mLauncher.getStateManager().getState();
int swipeDirection = 0;
if (getTargetState(fromState, true /* isDragTowardPositive */) != fromState) {
swipeDirection |= SwipeDetector.DIRECTION_POSITIVE;
}
if (getTargetState(fromState, false /* isDragTowardPositive */) != fromState) {
swipeDirection |= SwipeDetector.DIRECTION_NEGATIVE;
}
return swipeDirection;
}
@Override
public final boolean onControllerTouchEvent(MotionEvent ev) {
return mDetector.onTouchEvent(ev);
@@ -130,6 +140,11 @@ public abstract class AbstractStateChangeTouchController
protected abstract float initCurrentAnimation();
/**
* Returns the container that the touch started from when leaving NORMAL state.
*/
protected abstract int getLogContainerTypeForNormalState();
private boolean reinitCurrentAnimation(boolean reachedToState, boolean isDragTowardPositive) {
LauncherState newFromState = mFromState == null ? mLauncher.getStateManager().getState()
: reachedToState ? mToState : mFromState;
@@ -139,6 +154,17 @@ public abstract class AbstractStateChangeTouchController
return false;
}
if (reachedToState) {
logReachedState(Touch.SWIPE);
}
if (newFromState == ALL_APPS) {
mStartContainerType = ContainerType.ALLAPPS;
} else if (newFromState == NORMAL) {
mStartContainerType = getLogContainerTypeForNormalState();
} else if (newFromState == OVERVIEW){
mStartContainerType = ContainerType.TASKSWITCHER;
}
mFromState = newFromState;
mToState = newToState;
@@ -261,18 +287,22 @@ public abstract class AbstractStateChangeTouchController
}
if (shouldGoToTargetState) {
if (targetState != mFromState) {
// Transition complete. log the action
mLauncher.getUserEventDispatcher().logStateChangeAction(logAction,
getDirectionForLog(),
mStartContainerType,
mFromState.containerType,
mToState.containerType,
mLauncher.getWorkspace().getCurrentPage());
logReachedState(logAction);
}
mLauncher.getStateManager().goToState(targetState, false /* animated */);
}
}
private void logReachedState(int logAction) {
// Transition complete. log the action
mLauncher.getUserEventDispatcher().logStateChangeAction(logAction,
getDirectionForLog(),
mStartContainerType,
mFromState.containerType,
mToState.containerType,
mLauncher.getWorkspace().getCurrentPage());
}
protected void clearState() {
mCurrentAnimation = null;
mDetector.finishedScrolling();