Enabling swipe up from overview to all-apps
> Fixing wrong alpha interpolator when swiping down from all-apps
Change-Id: I7d4200c89797e5609fd7c4aa8681dea2ffd00bf7
diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java
index dfb935f..0a0bb85 100644
--- a/src/com/android/launcher3/LauncherState.java
+++ b/src/com/android/launcher3/LauncherState.java
@@ -19,7 +19,10 @@
import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
+import static com.android.launcher3.anim.Interpolators.ACCEL_2;
+
import android.view.View;
+import android.view.animation.Interpolator;
import com.android.launcher3.uioverrides.AllAppsState;
import com.android.launcher3.states.SpringLoadedState;
@@ -41,7 +44,13 @@
protected static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = 1 << 4;
protected static final int FLAG_DISABLE_PAGE_CLIPPING = 1 << 5;
- protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER = (i) -> 1f;
+ protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER =
+ new PageAlphaProvider(ACCEL_2) {
+ @Override
+ public float getPageAlpha(int pageIndex) {
+ return 1;
+ }
+ };
private static final LauncherState[] sAllStates = new LauncherState[4];
@@ -149,16 +158,27 @@
if (this != NORMAL || !launcher.getDeviceProfile().shouldFadeAdjacentWorkspaceScreens()) {
return DEFAULT_ALPHA_PROVIDER;
}
- int centerPage = launcher.getWorkspace().getPageNearestToCenterOfScreen();
- return (childIndex) -> childIndex != centerPage ? 0 : 1f;
+ final int centerPage = launcher.getWorkspace().getPageNearestToCenterOfScreen();
+ return new PageAlphaProvider(ACCEL_2) {
+ @Override
+ public float getPageAlpha(int pageIndex) {
+ return pageIndex != centerPage ? 0 : 1f;
+ }
+ };
}
protected static void dispatchWindowStateChanged(Launcher launcher) {
launcher.getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED);
}
- public interface PageAlphaProvider {
+ public static abstract class PageAlphaProvider {
- float getPageAlpha(int pageIndex);
+ public final Interpolator interpolator;
+
+ public PageAlphaProvider(Interpolator interpolator) {
+ this.interpolator = interpolator;
+ }
+
+ public abstract float getPageAlpha(int pageIndex);
}
}
diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
index 9f76b6f..a8a2b38 100644
--- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
+++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
@@ -153,7 +153,7 @@
propertySetter.setInt(cl.getScrimBackground(),
DRAWABLE_ALPHA, state.hasScrim ? 255 : 0, Interpolators.ZOOM_IN);
propertySetter.setFloat(cl.getShortcutsAndWidgets(), View.ALPHA,
- pageAlphaProvider.getPageAlpha(childIndex), Interpolators.DEACCEL_2);
+ pageAlphaProvider.getPageAlpha(childIndex), pageAlphaProvider.interpolator);
}
public static class PropertySetter {
diff --git a/src/com/android/launcher3/VerticalSwipeController.java b/src/com/android/launcher3/util/VerticalSwipeController.java
similarity index 76%
rename from src/com/android/launcher3/VerticalSwipeController.java
rename to src/com/android/launcher3/util/VerticalSwipeController.java
index b3dc176..7b1632c 100644
--- a/src/com/android/launcher3/VerticalSwipeController.java
+++ b/src/com/android/launcher3/util/VerticalSwipeController.java
@@ -14,10 +14,9 @@
* limitations under the License.
*/
-package com.android.launcher3;
+package com.android.launcher3.util;
import static com.android.launcher3.LauncherState.ALL_APPS;
-import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
import static com.android.launcher3.anim.SpringAnimationHandler.Y_DIRECTION;
@@ -28,21 +27,22 @@
import android.util.Log;
import android.view.MotionEvent;
+import com.android.launcher3.AbstractFloatingView;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherState;
+import com.android.launcher3.Utilities;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.SpringAnimationHandler;
import com.android.launcher3.touch.SwipeDetector;
-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.TouchController;
import java.util.ArrayList;
/**
- * Handles vertical touch gesture on the DragLayer
+ * Handles vertical touch gesture on the DragLayer allowing transitioning from
+ * {@link #mBaseState} to {@link LauncherState#ALL_APPS} and vice-versa.
*/
-public class VerticalSwipeController extends AnimatorListenerAdapter
+public abstract class VerticalSwipeController extends AnimatorListenerAdapter
implements TouchController, SwipeDetector.Listener {
private static final String TAG = "VerticalSwipeController";
@@ -53,11 +53,11 @@
// Progress after which the transition is assumed to be a success in case user does not fling
private static final float SUCCESS_TRANSITION_PROGRESS = 0.5f;
- private final Launcher mLauncher;
+ protected final Launcher mLauncher;
private final SwipeDetector mDetector;
+ private final LauncherState mBaseState;
private boolean mNoIntercept;
- private int mStartContainerType;
private AnimatorPlaybackController mCurrentAnimation;
private LauncherState mToState;
@@ -68,30 +68,25 @@
private SpringAnimationHandler[] mSpringHandlers;
- public VerticalSwipeController(Launcher l) {
+ public VerticalSwipeController(Launcher l, LauncherState baseState) {
mLauncher = l;
mDetector = new SwipeDetector(l, this, SwipeDetector.VERTICAL);
+ mBaseState = baseState;
}
private boolean canInterceptTouch(MotionEvent ev) {
- if (!mLauncher.isInState(NORMAL) && !mLauncher.isInState(ALL_APPS)) {
- // Don't listen for the swipe gesture if we are already in some other state.
- return false;
- }
if (mCurrentAnimation != null) {
// If we are already animating from a previous state, we can intercept.
return true;
}
- if (mLauncher.isInState(ALL_APPS) && !mLauncher.getAppsView().shouldContainerScroll(ev)) {
- return false;
- }
if (AbstractFloatingView.getTopOpenView(mLauncher) != null) {
return false;
}
-
- return true;
+ return shouldInterceptTouch(ev);
}
+ protected abstract boolean shouldInterceptTouch(MotionEvent ev);
+
@Override
public void onAnimationCancel(Animator animation) {
if (mCurrentAnimation != null && animation == mCurrentAnimation.getTarget()) {
@@ -147,14 +142,7 @@
ignoreSlopWhenSettling = true;
}
} else {
- if (mLauncher.isInState(ALL_APPS)) {
- directionsToDetectScroll = SwipeDetector.DIRECTION_NEGATIVE;
- mStartContainerType = ContainerType.ALLAPPS;
- } else {
- directionsToDetectScroll = SwipeDetector.DIRECTION_POSITIVE;
- mStartContainerType = mLauncher.getDragLayer().isEventOverHotseat(ev) ?
- ContainerType.HOTSEAT : ContainerType.WORKSPACE;
- }
+ directionsToDetectScroll = getSwipeDirection(ev);
}
mDetector.setDetectableScrollConditions(
@@ -173,6 +161,8 @@
return mDetector.isDraggingOrSettling();
}
+ protected abstract int getSwipeDirection(MotionEvent ev);
+
@Override
public boolean onControllerTouchEvent(MotionEvent ev) {
for (SpringAnimationHandler h : mSpringHandlers) {
@@ -188,7 +178,7 @@
long maxAccuracy = (long) (2 * range);
// Build current animation
- mToState = mLauncher.isInState(ALL_APPS) ? NORMAL : ALL_APPS;
+ mToState = mLauncher.isInState(ALL_APPS) ? mBaseState : ALL_APPS;
mCurrentAnimation = mLauncher.getStateManager()
.createAnimationToNewWorkspace(mToState, maxAccuracy);
mCurrentAnimation.getTarget().addListener(this);
@@ -206,7 +196,7 @@
}
private float getShiftRange() {
- return mLauncher.mAllAppsController.getShiftRange();
+ return mLauncher.getAllAppsController().getShiftRange();
}
@Override
@@ -219,29 +209,26 @@
@Override
public void onDragEnd(float velocity, boolean fling) {
final long animationDuration;
- final int logAction;
final LauncherState targetState;
final float progress = mCurrentAnimation.getProgressFraction();
if (fling) {
- logAction = Touch.FLING;
if (velocity < 0) {
targetState = ALL_APPS;
animationDuration = SwipeDetector.calculateDuration(velocity,
mToState == ALL_APPS ? (1 - progress) : progress);
} else {
- targetState = NORMAL;
+ targetState = mBaseState;
animationDuration = SwipeDetector.calculateDuration(velocity,
mToState == ALL_APPS ? progress : (1 - progress));
}
// snap to top or bottom using the release velocity
} else {
- logAction = Touch.SWIPE;
if (progress > SUCCESS_TRANSITION_PROGRESS) {
targetState = mToState;
animationDuration = SwipeDetector.calculateDuration(velocity, 1 - progress);
} else {
- targetState = mToState == ALL_APPS ? NORMAL : ALL_APPS;
+ targetState = mToState == ALL_APPS ? mBaseState : ALL_APPS;
animationDuration = SwipeDetector.calculateDuration(velocity, progress);
}
}
@@ -253,21 +240,11 @@
}
}
- mCurrentAnimation.setEndAction(new Runnable() {
- @Override
- public void run() {
- if (targetState == mToState) {
- // Transition complete. log the action
- mLauncher.getUserEventDispatcher().logActionOnContainer(logAction,
- mToState == ALL_APPS ? Direction.UP : Direction.DOWN,
- mStartContainerType, mLauncher.getWorkspace().getCurrentPage());
- } else {
- mLauncher.getStateManager().goToState(
- mToState == ALL_APPS ? NORMAL : ALL_APPS, false);
- }
- mDetector.finishedScrolling();
- mCurrentAnimation = null;
- }
+ mCurrentAnimation.setEndAction(() -> {
+ mLauncher.getStateManager().goToState(targetState, false);
+ onTransitionComplete(fling, targetState == mToState);
+ mDetector.finishedScrolling();
+ mCurrentAnimation = null;
});
float nextFrameProgress = Utilities.boundToRange(
@@ -279,4 +256,6 @@
anim.setInterpolator(scrollInterpolatorForVelocity(velocity));
anim.start();
}
+
+ protected abstract void onTransitionComplete(boolean wasFling, boolean stateChanged);
}