diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-06-21 22:05:28 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-06-21 22:05:28 +0000 |
commit | 37dc5b193673f7b8b4e381f87730b219eb143c95 (patch) | |
tree | 0441bcbcfa97e6d32fd3a6dc24ca6982778af439 /src | |
parent | 58fd654e573a02d14470e8bc627611d35733fbf3 (diff) | |
parent | c4bb3739b1ff3b3e34daa1fc53550b2ef2e8398a (diff) | |
download | packages_apps_Trebuchet-37dc5b193673f7b8b4e381f87730b219eb143c95.tar.gz packages_apps_Trebuchet-37dc5b193673f7b8b4e381f87730b219eb143c95.tar.bz2 packages_apps_Trebuchet-37dc5b193673f7b8b4e381f87730b219eb143c95.zip |
Merge "Cleaning up some animation states:" into ub-launcher3-qt-dev
Diffstat (limited to 'src')
6 files changed, 84 insertions, 7 deletions
diff --git a/src/com/android/launcher3/LauncherAppTransitionManager.java b/src/com/android/launcher3/LauncherAppTransitionManager.java index 4bddc6a4e..c55c120a6 100644 --- a/src/com/android/launcher3/LauncherAppTransitionManager.java +++ b/src/com/android/launcher3/LauncherAppTransitionManager.java @@ -17,6 +17,7 @@ package com.android.launcher3; +import android.animation.Animator; import android.app.ActivityOptions; import android.content.Context; import android.graphics.Rect; @@ -55,4 +56,15 @@ public class LauncherAppTransitionManager implements ResourceBasedOverride { public boolean supportsAdaptiveIconAnimation() { return false; } + + /** + * Number of animations which run on state properties. + */ + public int getStateElementAnimationsCount() { + return 0; + } + + public Animator createStateElementAnimation(int index, float... values) { + throw new RuntimeException("Unknown gesture animation " + index); + } } diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java index 505918e09..2c8c20845 100644 --- a/src/com/android/launcher3/LauncherStateManager.java +++ b/src/com/android/launcher3/LauncherStateManager.java @@ -111,6 +111,9 @@ public class LauncherStateManager { private final Launcher mLauncher; private final ArrayList<StateListener> mListeners = new ArrayList<>(); + // Animators which are run on properties also controlled by state animations. + private Animator[] mStateElementAnimators; + private StateHandler[] mStateHandlers; private LauncherState mState = NORMAL; @@ -209,6 +212,7 @@ public class LauncherStateManager { public void reapplyState(boolean cancelCurrentAnimation) { boolean wasInAnimation = mConfig.mCurrentAnimation != null; if (cancelCurrentAnimation) { + cancelAllStateElementAnimation(); cancelAnimation(); } if (mConfig.mCurrentAnimation == null) { @@ -250,6 +254,7 @@ public class LauncherStateManager { mConfig.reset(); if (!animated) { + cancelAllStateElementAnimation(); onStateTransitionStart(state); for (StateHandler handler : getStateHandlers()) { handler.setState(state); @@ -521,6 +526,47 @@ public class LauncherStateManager { mConfig.setAnimation(anim, null); } + private void cancelAllStateElementAnimation() { + if (mStateElementAnimators == null) { + return; + } + + for (Animator animator : mStateElementAnimators) { + if (animator != null) { + animator.cancel(); + } + } + } + + /** + * Cancels a currently running gesture animation + */ + public void cancelStateElementAnimation(int index) { + if (mStateElementAnimators == null) { + return; + } + if (mStateElementAnimators[index] != null) { + mStateElementAnimators[index].cancel(); + } + } + + public Animator createStateElementAnimation(int index, float... values) { + cancelStateElementAnimation(index); + LauncherAppTransitionManager latm = mLauncher.getAppTransitionManager(); + if (mStateElementAnimators == null) { + mStateElementAnimators = new Animator[latm.getStateElementAnimationsCount()]; + } + Animator anim = latm.createStateElementAnimation(index, values); + mStateElementAnimators[index] = anim; + anim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mStateElementAnimators[index] = null; + } + }); + return anim; + } + private void clearCurrentAnimation() { if (mConfig.mCurrentAnimation != null) { mConfig.mCurrentAnimation.removeListener(mConfig); diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index dfa3e1bee..2eeb132bb 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -16,6 +16,7 @@ package com.android.launcher3; +import static com.android.launcher3.Utilities.shouldDisableGestures; import static com.android.launcher3.compat.AccessibilityManagerCompat.isAccessibilityEnabled; import static com.android.launcher3.compat.AccessibilityManagerCompat.isObservedEventType; import static com.android.launcher3.config.FeatureFlags.QUICKSTEP_SPRINGS; @@ -844,10 +845,11 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou * If we return true, onTouchEvent will be called and we do the actual * scrolling there. */ - acquireVelocityTrackerAndAddMovement(ev); // Skip touch handling if there are no pages to swipe - if (getChildCount() <= 0) return super.onInterceptTouchEvent(ev); + if (getChildCount() <= 0 || shouldDisableGestures(ev)) return false; + + acquireVelocityTrackerAndAddMovement(ev); /* * Shortcut the most recurring case: the user is in the dragging @@ -1093,7 +1095,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou @Override public boolean onTouchEvent(MotionEvent ev) { // Skip touch handling if there are no pages to swipe - if (getChildCount() <= 0) return false; + if (getChildCount() <= 0 || shouldDisableGestures(ev)) return false; acquireVelocityTrackerAndAddMovement(ev); diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 7bdbb95f7..65aa3a775 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -128,6 +128,16 @@ public final class Utilities { public static final int EDGE_NAV_BAR = 1 << 8; /** + * Set on a motion event do disallow any gestures and only handle touch. + * See {@link MotionEvent#setEdgeFlags(int)}. + */ + public static final int FLAG_NO_GESTURES = 1 << 9; + + public static boolean shouldDisableGestures(MotionEvent ev) { + return (ev.getEdgeFlags() & FLAG_NO_GESTURES) == FLAG_NO_GESTURES; + } + + /** * Indicates if the device has a debug build. Should only be used to store additional info or * add extra logging and not for changing the app behavior. */ diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java index 3289d7d1d..4683893ea 100644 --- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java +++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java @@ -47,8 +47,8 @@ import com.android.launcher3.views.ScrimView; */ public class AllAppsTransitionController implements StateHandler, OnDeviceProfileChangeListener { - public static final float SPRING_DAMPING_RATIO = 0.9f; - public static final float SPRING_STIFFNESS = 600f; + private static final float SPRING_DAMPING_RATIO = 0.9f; + private static final float SPRING_STIFFNESS = 600f; public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PROGRESS = new FloatProperty<AllAppsTransitionController>("allAppsProgress") { @@ -188,8 +188,7 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil Interpolator interpolator = config.userControlled ? LINEAR : toState == OVERVIEW ? builder.getInterpolator(ANIM_OVERVIEW_SCALE, FAST_OUT_SLOW_IN) : FAST_OUT_SLOW_IN; - Animator anim = new SpringObjectAnimator<>(this, ALL_APPS_PROGRESS, 1f / mShiftRange, - SPRING_DAMPING_RATIO, SPRING_STIFFNESS, mProgress, targetProgress); + Animator anim = createSpringAnimation(mProgress, targetProgress); anim.setDuration(config.duration); anim.setInterpolator(builder.getInterpolator(ANIM_VERTICAL_PROGRESS, interpolator)); anim.addListener(getProgressAnimatorListener()); @@ -199,6 +198,11 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil setAlphas(toState, config, builder); } + public Animator createSpringAnimation(float... progressValues) { + return new SpringObjectAnimator<>(this, ALL_APPS_PROGRESS, 1f / mShiftRange, + SPRING_DAMPING_RATIO, SPRING_STIFFNESS, progressValues); + } + private void setAlphas(LauncherState toState, AnimationConfig config, AnimatorSetBuilder builder) { setAlphas(toState.getVisibleElements(mLauncher), config, builder); diff --git a/src/com/android/launcher3/views/BaseDragLayer.java b/src/com/android/launcher3/views/BaseDragLayer.java index 51c7022bd..c1ba78050 100644 --- a/src/com/android/launcher3/views/BaseDragLayer.java +++ b/src/com/android/launcher3/views/BaseDragLayer.java @@ -21,6 +21,7 @@ import static android.view.MotionEvent.ACTION_DOWN; import static android.view.MotionEvent.ACTION_UP; import static com.android.launcher3.Utilities.SINGLE_FRAME_MS; +import static com.android.launcher3.Utilities.shouldDisableGestures; import android.annotation.TargetApi; import android.content.Context; @@ -151,6 +152,8 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext> } private TouchController findControllerToHandleTouch(MotionEvent ev) { + if (shouldDisableGestures(ev)) return null; + AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(mActivity); if (topView != null && topView.onControllerInterceptTouchEvent(ev)) { return topView; |