From ec4a56a311437a46415e0cba04d666989fbd59af Mon Sep 17 00:00:00 2001 From: Brian Isganitis Date: Tue, 29 Jun 2021 01:33:25 -0400 Subject: [PATCH] Support overriding All Apps EDU animation on drag Test: Dragging during All Apps EDU animation overrides the animation. Bug: 160218103 Change-Id: I1c0a2d047bcb43ea7ce30cf87182b392dac313e4 --- .../quickstep/views/AllAppsEduView.java | 92 ++++++++++++------- .../AbstractStateChangeTouchController.java | 4 +- 2 files changed, 63 insertions(+), 33 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/AllAppsEduView.java b/quickstep/src/com/android/quickstep/views/AllAppsEduView.java index f67940ab56..04a7baaa2b 100644 --- a/quickstep/src/com/android/quickstep/views/AllAppsEduView.java +++ b/quickstep/src/com/android/quickstep/views/AllAppsEduView.java @@ -17,13 +17,10 @@ package com.android.quickstep.views; import static com.android.launcher3.LauncherState.ALL_APPS; import static com.android.launcher3.LauncherState.NORMAL; -import static com.android.launcher3.anim.Interpolators.ACCEL; import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN; import static com.android.launcher3.anim.Interpolators.LINEAR; import static com.android.launcher3.anim.Interpolators.OVERSHOOT_1_7; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALL_APPS_EDU_SHOWN; -import static com.android.launcher3.states.StateAnimationConfig.ANIM_ALL_APPS_FADE; -import static com.android.launcher3.states.StateAnimationConfig.ANIM_SCRIM_FADE; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -35,7 +32,7 @@ import android.graphics.Rect; import android.graphics.drawable.GradientDrawable; import android.util.AttributeSet; import android.view.MotionEvent; -import android.view.ViewGroup; +import android.view.View; import androidx.core.graphics.ColorUtils; @@ -44,25 +41,21 @@ import com.android.launcher3.DeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.Utilities; -import com.android.launcher3.allapps.AllAppsTransitionController; import com.android.launcher3.anim.AnimatorPlaybackController; -import com.android.launcher3.anim.Interpolators; -import com.android.launcher3.anim.PendingAnimation; import com.android.launcher3.dragndrop.DragLayer; -import com.android.launcher3.states.StateAnimationConfig; +import com.android.launcher3.uioverrides.touchcontrollers.PortraitStatesTouchController; import com.android.launcher3.util.Themes; import com.android.quickstep.util.MultiValueUpdateListener; /** * View used to educate the user on how to access All Apps when in No Nav Button navigation mode. - * Consumes all touches until after the animation is completed and the view is removed. + * If the user drags on the view, the animation is overridden so the user can swipe to All Apps or + * Home. */ public class AllAppsEduView extends AbstractFloatingView { - private static final float HINT_PROG_SCRIM_THRESHOLD = 0.06f; - private static final float HINT_PROG_CONTENT_THRESHOLD = 0.08f; - private Launcher mLauncher; + private AllAppsEduTouchController mTouchController; private AnimatorSet mAnimation; @@ -123,8 +116,35 @@ public class AllAppsEduView extends AbstractFloatingView { return true; } + @Override + public boolean onControllerTouchEvent(MotionEvent ev) { + mTouchController.onControllerTouchEvent(ev); + if (mAnimation != null) { + updateAnimationOnTouchEvent(ev); + } + return super.onControllerTouchEvent(ev); + } + + private void updateAnimationOnTouchEvent(MotionEvent ev) { + switch (ev.getActionMasked()) { + case MotionEvent.ACTION_DOWN: + mAnimation.pause(); + return; + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: + mAnimation.resume(); + return; + } + + if (mTouchController.isDraggingOrSettling()) { + mAnimation = null; + handleClose(false); + } + } + @Override public boolean onControllerInterceptTouchEvent(MotionEvent ev) { + mTouchController.onControllerInterceptTouchEvent(ev); return true; } @@ -145,23 +165,9 @@ public class AllAppsEduView extends AbstractFloatingView { int secondPart = 1200; int introDuration = firstPart + secondPart; - StateAnimationConfig config = new StateAnimationConfig(); - config.setInterpolator(ANIM_ALL_APPS_FADE, Interpolators.clampToProgress(ACCEL, - HINT_PROG_SCRIM_THRESHOLD, HINT_PROG_CONTENT_THRESHOLD)); - config.setInterpolator(ANIM_SCRIM_FADE, - Interpolators.clampToProgress(ACCEL, 0, HINT_PROG_CONTENT_THRESHOLD)); - config.duration = secondPart; - config.userControlled = false; AnimatorPlaybackController stateAnimationController = - mLauncher.getStateManager().createAnimationToNewWorkspace(ALL_APPS, config); - float maxAllAppsProgress = mLauncher.getDeviceProfile().isLandscape ? 0.35f : 0.15f; - - AllAppsTransitionController allAppsController = mLauncher.getAllAppsController(); - PendingAnimation allAppsAlpha = new PendingAnimation(config.duration); - allAppsController.setAlphas(ALL_APPS, config, allAppsAlpha); - mLauncher.getWorkspace().getStateTransitionAnimation().setScrim(allAppsAlpha, ALL_APPS, - config); - mAnimation.play(allAppsAlpha.buildAnim()); + mTouchController.initAllAppsAnimation(); + float maxAllAppsProgress = 0.75f; ValueAnimator intro = ValueAnimator.ofFloat(0, 1f); intro.setInterpolator(LINEAR); @@ -198,6 +204,7 @@ public class AllAppsEduView extends AbstractFloatingView { mGradient.setAlpha(0); } }); + mLauncher.getAppsView().setVisibility(View.VISIBLE); mAnimation.play(intro); ValueAnimator closeAllApps = ValueAnimator.ofFloat(maxAllAppsProgress, 0f); @@ -223,6 +230,7 @@ public class AllAppsEduView extends AbstractFloatingView { private void init(Launcher launcher) { mLauncher = launcher; + mTouchController = new AllAppsEduTouchController(mLauncher); int accentColor = Themes.getColorAccent(launcher); mGradient = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, @@ -250,9 +258,8 @@ public class AllAppsEduView extends AbstractFloatingView { */ public static void show(Launcher launcher) { final DragLayer dragLayer = launcher.getDragLayer(); - ViewGroup parent = (ViewGroup) dragLayer.getParent(); - AllAppsEduView view = launcher.getViewCache().getView(R.layout.all_apps_edu_view, - launcher, parent); + AllAppsEduView view = (AllAppsEduView) launcher.getLayoutInflater().inflate( + R.layout.all_apps_edu_view, dragLayer, false); view.init(launcher); launcher.getDragLayer().addView(view); launcher.getStatsLogManager().logger().log(LAUNCHER_ALL_APPS_EDU_SHOWN); @@ -260,4 +267,27 @@ public class AllAppsEduView extends AbstractFloatingView { view.requestLayout(); view.playAnimation(); } + + private static class AllAppsEduTouchController extends PortraitStatesTouchController { + + private AllAppsEduTouchController(Launcher l) { + super(l); + } + + @Override + protected boolean canInterceptTouch(MotionEvent ev) { + return true; + } + + private AnimatorPlaybackController initAllAppsAnimation() { + mFromState = NORMAL; + mToState = ALL_APPS; + mProgressMultiplier = initCurrentAnimation(); + return mCurrentAnimation; + } + + private boolean isDraggingOrSettling() { + return mDetector.isDraggingOrSettling(); + } + } } diff --git a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java index 90f37f3404..5f8a4d4f3c 100644 --- a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java +++ b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java @@ -65,12 +65,12 @@ public abstract class AbstractStateChangeTouchController protected LauncherState mToState; protected AnimatorPlaybackController mCurrentAnimation; protected boolean mGoingBetweenStates = true; + // Ratio of transition process [0, 1] to drag displacement (px) + protected float mProgressMultiplier; private boolean mNoIntercept; private boolean mIsLogContainerSet; private float mStartProgress; - // Ratio of transition process [0, 1] to drag displacement (px) - private float mProgressMultiplier; private float mDisplacementShift; private boolean mCanBlockFling; private boolean mAllAppsOvershootStarted;