diff options
author | Jon <jonmiranda@google.com> | 2018-07-13 14:40:08 -0400 |
---|---|---|
committer | Jon <jonmiranda@google.com> | 2018-07-13 14:41:28 -0400 |
commit | 0fd1472b940efc7f92c5a441935206afc9db7470 (patch) | |
tree | 6ce6af2fc210eb180d7a2630af37b842e44b69a9 | |
parent | 1748c4ad619b18546b249e03579dd26f02344a0c (diff) | |
parent | 35a6848fa813b6b3d5c41b2b6792f7b7effa195b (diff) | |
download | Launcher3-pie-qpr1-s3-release.tar.gz |
Merge branch 'ub-launcher3-edmonton-polish' into pi-devandroid-9.0.0_r30android-9.0.0_r22android-9.0.0_r21android-9.0.0_r20android-9.0.0_r19android-9.0.0_r16pie-qpr1-s3-releasepie-qpr1-s2-releasepie-qpr1-s1-releasepie-qpr1-releasepie-dr1-dev
Bug: 111438498
Bug: 80134723
Test: manual
Change-Id: If50f0cfd7ce02978eb0d2ab3a8d5e2c1550548c6
13 files changed, 257 insertions, 166 deletions
diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index 0af2b28250..49c4492b60 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -21,6 +21,7 @@ <dimen name="task_thumbnail_icon_size">48dp</dimen> <dimen name="task_corner_radius">2dp</dimen> <dimen name="recents_page_spacing">10dp</dimen> + <dimen name="recents_clear_all_deadzone_vertical_margin">70dp</dimen> <dimen name="quickscrub_adjacent_visible_width">20dp</dimen> <!-- The speed in dp/s at which the user needs to be scrolling in recents such that we start @@ -32,7 +33,7 @@ <!-- Launcher app transition --> <dimen name="content_trans_y">50dp</dimen> - <dimen name="springs_trans_y">-70dp</dimen> + <dimen name="workspace_trans_y">50dp</dimen> <dimen name="closing_window_trans_y">115dp</dimen> <dimen name="recents_empty_message_text_size">16sp</dimen> diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java index 252e3eaeee..14633afa52 100644 --- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java +++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java @@ -16,7 +16,6 @@ package com.android.launcher3; -import static android.view.View.TRANSLATION_Y; import static com.android.launcher3.BaseActivity.INVISIBLE_ALL; import static com.android.launcher3.BaseActivity.INVISIBLE_BY_APP_TRANSITIONS; import static com.android.launcher3.BaseActivity.INVISIBLE_BY_PENDING_FLAGS; @@ -28,10 +27,8 @@ import static com.android.launcher3.LauncherState.OVERVIEW; import static com.android.launcher3.Utilities.postAsyncCallback; import static com.android.launcher3.allapps.AllAppsTransitionController.ALL_APPS_PROGRESS; import static com.android.launcher3.anim.Interpolators.AGGRESSIVE_EASE; -import static com.android.launcher3.anim.Interpolators.DEACCEL; import static com.android.launcher3.anim.Interpolators.DEACCEL_1_7; import static com.android.launcher3.anim.Interpolators.LINEAR; -import static com.android.launcher3.anim.Interpolators.OSCILLATE; import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_TRANSITIONS; import static com.android.quickstep.TaskUtils.findTaskViewToLaunch; import static com.android.quickstep.TaskUtils.getRecentsWindowAnimator; @@ -57,7 +54,6 @@ import android.os.CancellationSignal; import android.os.Handler; import android.os.Looper; import android.util.Pair; -import android.util.Property; import android.view.View; import android.view.ViewGroup; @@ -119,20 +115,12 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag public static final int RECENTS_LAUNCH_DURATION = 336; public static final int RECENTS_QUICKSCRUB_LAUNCH_DURATION = 300; - private static final int LAUNCHER_RESUME_START_DELAY = 40; + private static final int LAUNCHER_RESUME_START_DELAY = 100; private static final int CLOSING_TRANSITION_DURATION_MS = 250; // Progress = 0: All apps is fully pulled up, Progress = 1: All apps is fully pulled down. public static final float ALL_APPS_PROGRESS_OFF_SCREEN = 1.3059858f; - private static final int APP_CLOSE_ROW_START_DELAY_MS = 8; - - // The sum of [slide, oscillate, and settle] should be <= LAUNCHER_RESUME_TOTAL_DURATION. - private static final int LAUNCHER_RESUME_TOTAL_DURATION = 346; - private static final int SPRING_SLIDE_DURATION = 166; - private static final int SPRING_OSCILLATE_DURATION = 130; - private static final int SPRING_SETTLE_DURATION = 50; - private final Launcher mLauncher; private final DragLayer mDragLayer; private final AlphaProperty mDragLayerAlpha; @@ -141,8 +129,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag private final boolean mIsRtl; private final float mContentTransY; - private final float mStartSlideTransY; - private final float mEndSlideTransY; + private final float mWorkspaceTransY; private final float mClosingWindowTransY; private DeviceProfile mDeviceProfile; @@ -172,9 +159,8 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag Resources res = mLauncher.getResources(); mContentTransY = res.getDimensionPixelSize(R.dimen.content_trans_y); + mWorkspaceTransY = res.getDimensionPixelSize(R.dimen.workspace_trans_y); mClosingWindowTransY = res.getDimensionPixelSize(R.dimen.closing_window_trans_y); - mStartSlideTransY = res.getDimensionPixelSize(R.dimen.springs_trans_y); - mEndSlideTransY = -mStartSlideTransY * 0.1f; mLauncher.addOnDeviceProfileChangeListener(this); registerRemoteAnimations(); @@ -786,33 +772,25 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag }); } else { AnimatorSet workspaceAnimator = new AnimatorSet(); - workspaceAnimator.setStartDelay(LAUNCHER_RESUME_START_DELAY); - ShortcutAndWidgetContainer currentPage = ((CellLayout) mLauncher.getWorkspace() - .getChildAt(mLauncher.getWorkspace().getCurrentPage())) - .getShortcutsAndWidgets(); + mDragLayer.setTranslationY(-mWorkspaceTransY);; + workspaceAnimator.play(ObjectAnimator.ofFloat(mDragLayer, View.TRANSLATION_Y, + -mWorkspaceTransY, 0)); - // Set up springs on workspace items. - for (int i = currentPage.getChildCount() - 1; i >= 0; i--) { - View child = currentPage.getChildAt(i); - CellLayout.LayoutParams lp = ((CellLayout.LayoutParams) child.getLayoutParams()); - addStaggeredAnimationForView(child, workspaceAnimator, lp.cellY + lp.cellVSpan); - } + mDragLayerAlpha.setValue(0); + workspaceAnimator.play(ObjectAnimator.ofFloat( + mDragLayerAlpha, MultiValueAlpha.VALUE, 0, 1f)); - // Set up a spring for the shelf. - if (!mLauncher.getDeviceProfile().isVerticalBarLayout()) { - AllAppsTransitionController allAppsController = mLauncher.getAllAppsController(); - float shiftRange = allAppsController.getShiftRange(); - float slideStart = shiftRange / (shiftRange - mStartSlideTransY); - float oscillateStart = shiftRange / (shiftRange - mEndSlideTransY); - - buildSpringAnimation(workspaceAnimator, allAppsController, ALL_APPS_PROGRESS, - 0 /* startDelay */, slideStart, oscillateStart, 1f /* finalPosition */); - } + workspaceAnimator.setStartDelay(LAUNCHER_RESUME_START_DELAY); + workspaceAnimator.setDuration(333); + workspaceAnimator.setInterpolator(Interpolators.DEACCEL_1_7); mDragLayer.getScrim().hideSysUiScrim(true); + // Pause page indicator animations as they lead to layer trashing. mLauncher.getWorkspace().getPageIndicator().pauseAnimations(); + mDragLayer.setLayerType(View.LAYER_TYPE_HARDWARE, null); + workspaceAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { @@ -823,66 +801,6 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag } } - /** - * Adds an alpha/trans animator for {@param v}, with a start delay based on the view's row. - * - * @param v View in a ShortcutAndWidgetContainer. - * @param row The bottom-most row that contains the view. - */ - private void addStaggeredAnimationForView(View v, AnimatorSet outAnimator, int row) { - // Invert the rows, because we stagger starting from the bottom of the screen. - int invertedRow = LauncherAppState.getIDP(mLauncher).numRows - row + 1; - long startDelay = (long) (invertedRow * APP_CLOSE_ROW_START_DELAY_MS); - - v.setAlpha(0); - ObjectAnimator alpha = ObjectAnimator.ofFloat(v, View.ALPHA, 1f); - alpha.setInterpolator(LINEAR); - alpha.setDuration(SPRING_SLIDE_DURATION + SPRING_OSCILLATE_DURATION); - alpha.setStartDelay(startDelay); - outAnimator.play(alpha); - - buildSpringAnimation(outAnimator, v, TRANSLATION_Y, startDelay, mStartSlideTransY, - mEndSlideTransY, 0f /* finalPosition */); - - outAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - v.setAlpha(1f); - v.setTranslationY(0); - } - }); - } - - /** - * Spring animations consists of three sequential animators: a slide, an oscillation, and - * a settle. - */ - private <T> void buildSpringAnimation(AnimatorSet outAnimator, T objectToSpring, - Property<T, Float> property, long startDelay, float slideStart, float oscillateStart, - float finalPosition) { - // Ensures a clean hand-off between slide and oscillate. - float slideEnd = Utilities.mapToRange(0, 0, 1f, oscillateStart, finalPosition, OSCILLATE); - - property.set(objectToSpring, slideStart); - - ObjectAnimator slideIn = ObjectAnimator.ofFloat(objectToSpring, property, slideStart, - slideEnd); - slideIn.setInterpolator(DEACCEL); - slideIn.setStartDelay(startDelay); - slideIn.setDuration(SPRING_SLIDE_DURATION); - - ObjectAnimator oscillate = ObjectAnimator.ofFloat(objectToSpring, property, oscillateStart, - finalPosition); - oscillate.setInterpolator(OSCILLATE); - oscillate.setDuration(SPRING_OSCILLATE_DURATION); - - ObjectAnimator settle = ObjectAnimator.ofFloat(objectToSpring, property, finalPosition); - settle.setInterpolator(LINEAR); - settle.setDuration(SPRING_SETTLE_DURATION); - - outAnimator.playSequentially(slideIn, oscillate, settle); - } - private void resetContentView() { mLauncher.getWorkspace().getPageIndicator().skipAnimationsToEnd(); mDragLayerAlpha.setValue(1f); diff --git a/quickstep/src/com/android/quickstep/LongSwipeHelper.java b/quickstep/src/com/android/quickstep/LongSwipeHelper.java index 0785093302..6b66ec8db5 100644 --- a/quickstep/src/com/android/quickstep/LongSwipeHelper.java +++ b/quickstep/src/com/android/quickstep/LongSwipeHelper.java @@ -20,17 +20,22 @@ import static com.android.launcher3.LauncherState.ALL_APPS; import static com.android.launcher3.LauncherState.OVERVIEW; import static com.android.launcher3.anim.Interpolators.DEACCEL; import static com.android.quickstep.WindowTransformSwipeHandler.MAX_SWIPE_DURATION; +import static com.android.quickstep.WindowTransformSwipeHandler.MIN_OVERSHOOT_DURATION; import android.animation.ValueAnimator; +import android.view.animation.Interpolator; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAnimUtils; import com.android.launcher3.LauncherStateManager; import com.android.launcher3.R; +import com.android.launcher3.Utilities; import com.android.launcher3.allapps.AllAppsTransitionController; import com.android.launcher3.allapps.DiscoveryBounce; import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.anim.AnimatorSetBuilder; +import com.android.launcher3.anim.Interpolators; +import com.android.launcher3.anim.Interpolators.OvershootParams; import com.android.launcher3.uioverrides.PortraitStatesTouchController; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch; @@ -89,7 +94,9 @@ public class LongSwipeHelper { } public void end(float velocity, boolean isFling, Runnable callback) { + float velocityPxPerMs = velocity / 1000; long duration = MAX_SWIPE_DURATION; + Interpolator interpolator = DEACCEL; final float currentFraction = mAnimator.getProgressFraction(); final boolean toAllApps; @@ -107,6 +114,16 @@ public class LongSwipeHelper { long expectedDuration = Math.abs(Math.round((endProgress - currentFraction) * MAX_SWIPE_DURATION * SWIPE_DURATION_MULTIPLIER)); duration = Math.min(MAX_SWIPE_DURATION, expectedDuration); + + if (blockedFling && !toAllApps) { + Interpolators.OvershootParams overshoot = new OvershootParams(currentFraction, + currentFraction, endProgress, velocityPxPerMs, (int) mMaxSwipeDistance); + duration = (overshoot.duration + duration); + duration = Utilities.boundToRange(duration, MIN_OVERSHOOT_DURATION, + MAX_SWIPE_DURATION); + interpolator = overshoot.interpolator; + endProgress = overshoot.end; + } } else { toAllApps = velocity < 0; endProgress = toAllApps ? 1 : 0; @@ -119,18 +136,16 @@ public class LongSwipeHelper { // we want the page's snap velocity to approximately match the velocity at // which the user flings, so we scale the duration by a value near to the // derivative of the scroll interpolator at zero, ie. 2. - long baseDuration = Math.round(1000 * Math.abs(distanceToTravel / velocity)); + long baseDuration = Math.round(Math.abs(distanceToTravel / velocityPxPerMs)); duration = Math.min(MAX_SWIPE_DURATION, 2 * baseDuration); } } - if (blockedFling && !toAllApps) { - duration *= LauncherAnimUtils.blockedFlingDurationFactor(0); - } final boolean finalIsFling = isFling; mAnimator.setEndAction(() -> onSwipeAnimationComplete(toAllApps, finalIsFling, callback)); + ValueAnimator animator = mAnimator.getAnimationPlayer(); - animator.setDuration(duration).setInterpolator(DEACCEL); + animator.setDuration(duration).setInterpolator(interpolator); animator.setFloatValues(currentFraction, endProgress); animator.start(); } diff --git a/quickstep/src/com/android/quickstep/TaskSystemShortcut.java b/quickstep/src/com/android/quickstep/TaskSystemShortcut.java index c77d0c7d79..5a6312d4e1 100644 --- a/quickstep/src/com/android/quickstep/TaskSystemShortcut.java +++ b/quickstep/src/com/android/quickstep/TaskSystemShortcut.java @@ -189,9 +189,14 @@ public class TaskSystemShortcut<T extends SystemShortcut> extends SystemShortcut final Rect taskBounds = new Rect(position[0], position[1], position[0] + width, position[1] + height); + // Take the thumbnail of the task without a scrim and apply it back after + float alpha = thumbnailView.getDimAlpha(); + thumbnailView.setDimAlpha(0); Bitmap thumbnail = RecentsTransition.drawViewIntoHardwareBitmap( taskBounds.width(), taskBounds.height(), thumbnailView, 1f, Color.BLACK); + thumbnailView.setDimAlpha(alpha); + AppTransitionAnimationSpecsFuture future = new AppTransitionAnimationSpecsFuture(mHandler) { @Override diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java index ff3137d441..902eb950de 100644 --- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java @@ -21,6 +21,7 @@ import static com.android.launcher3.Utilities.SINGLE_FRAME_MS; import static com.android.launcher3.Utilities.postAsyncCallback; import static com.android.launcher3.anim.Interpolators.DEACCEL; import static com.android.launcher3.anim.Interpolators.LINEAR; +import static com.android.launcher3.anim.Interpolators.OVERSHOOT_1_2; import static com.android.quickstep.QuickScrubController.QUICK_SCRUB_FROM_APP_START_DURATION; import static com.android.quickstep.TouchConsumer.INTERACTION_NORMAL; import static com.android.quickstep.TouchConsumer.INTERACTION_QUICK_SCRUB; @@ -163,6 +164,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> { public static final long MAX_SWIPE_DURATION = 350; public static final long MIN_SWIPE_DURATION = 80; + public static final long MIN_OVERSHOOT_DURATION = 120; public static final float MIN_PROGRESS_FOR_OVERVIEW = 0.5f; private static final float SWIPE_DURATION_MULTIPLIER = @@ -498,7 +500,8 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> { setStateOnUiThread(STATE_QUICK_SCRUB_START | STATE_GESTURE_COMPLETED); // Start the window animation without waiting for launcher. - animateToProgress(mCurrentShift.value, 1f, QUICK_SCRUB_FROM_APP_START_DURATION, LINEAR); + animateToProgress(mCurrentShift.value, 1f, QUICK_SCRUB_FROM_APP_START_DURATION, LINEAR, + true /* goingToHome */); } private void shiftAnimationDestinationForQuickscrub() { @@ -699,36 +702,46 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> { private void handleNormalGestureEnd(float endVelocity, boolean isFling) { float velocityPxPerMs = endVelocity / 1000; long duration = MAX_SWIPE_DURATION; - final float endShift; + float currentShift = mCurrentShift.value; + final boolean goingToHome; + float endShift; final float startShift; - final Interpolator interpolator; + Interpolator interpolator = DEACCEL; if (!isFling) { - endShift = mCurrentShift.value >= MIN_PROGRESS_FOR_OVERVIEW && mGestureStarted ? 1 : 0; - long expectedDuration = Math.abs(Math.round((endShift - mCurrentShift.value) + goingToHome = currentShift >= MIN_PROGRESS_FOR_OVERVIEW && mGestureStarted; + endShift = goingToHome ? 1 : 0; + long expectedDuration = Math.abs(Math.round((endShift - currentShift) * MAX_SWIPE_DURATION * SWIPE_DURATION_MULTIPLIER)); duration = Math.min(MAX_SWIPE_DURATION, expectedDuration); - startShift = mCurrentShift.value; - interpolator = DEACCEL; + startShift = currentShift; + interpolator = goingToHome ? OVERSHOOT_1_2 : DEACCEL; } else { - endShift = endVelocity < 0 ? 1 : 0; - interpolator = endVelocity < 0 - ? Interpolators.overshootInterpolatorForVelocity(velocityPxPerMs, 2f) - : DEACCEL; + goingToHome = endVelocity < 0; + endShift = goingToHome ? 1 : 0; + startShift = Utilities.boundToRange(currentShift - velocityPxPerMs + * SINGLE_FRAME_MS / mTransitionDragLength, 0, 1); float minFlingVelocity = mContext.getResources() .getDimension(R.dimen.quickstep_fling_min_velocity); if (Math.abs(endVelocity) > minFlingVelocity && mTransitionDragLength > 0) { - float distanceToTravel = (endShift - mCurrentShift.value) * mTransitionDragLength; - - // we want the page's snap velocity to approximately match the velocity at - // which the user flings, so we scale the duration by a value near to the - // derivative of the scroll interpolator at zero, ie. 2. - long baseDuration = Math.round(Math.abs(distanceToTravel / velocityPxPerMs)); - duration = Math.min(MAX_SWIPE_DURATION, 2 * baseDuration); + if (goingToHome) { + Interpolators.OvershootParams overshoot = new Interpolators.OvershootParams( + startShift, endShift, endShift, velocityPxPerMs, mTransitionDragLength); + endShift = overshoot.end; + interpolator = overshoot.interpolator; + duration = Utilities.boundToRange(overshoot.duration, MIN_OVERSHOOT_DURATION, + MAX_SWIPE_DURATION); + } else { + float distanceToTravel = (endShift - currentShift) * mTransitionDragLength; + + // we want the page's snap velocity to approximately match the velocity at + // which the user flings, so we scale the duration by a value near to the + // derivative of the scroll interpolator at zero, ie. 2. + long baseDuration = Math.round(Math.abs(distanceToTravel / velocityPxPerMs)); + duration = Math.min(MAX_SWIPE_DURATION, 2 * baseDuration); + } } - startShift = Utilities.boundToRange(mCurrentShift.value - velocityPxPerMs - * SINGLE_FRAME_MS / (mTransitionDragLength), 0, 1); } - animateToProgress(startShift, endShift, duration, interpolator); + animateToProgress(startShift, endShift, duration, interpolator, goingToHome); } private void doLogGesture(boolean toLauncher) { @@ -754,14 +767,14 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> { /** Animates to the given progress, where 0 is the current app and 1 is overview. */ private void animateToProgress(float start, float end, long duration, - Interpolator interpolator) { + Interpolator interpolator, boolean goingToHome) { mRecentsAnimationWrapper.runOnInit(() -> animateToProgressInternal(start, end, duration, - interpolator)); + interpolator, goingToHome)); } private void animateToProgressInternal(float start, float end, long duration, - Interpolator interpolator) { - mIsGoingToHome = Float.compare(end, 1) == 0; + Interpolator interpolator, boolean goingToHome) { + mIsGoingToHome = goingToHome; ObjectAnimator anim = mCurrentShift.animateToValue(start, end).setDuration(duration); anim.setInterpolator(interpolator); anim.addListener(new AnimationSuccessListener() { @@ -869,8 +882,21 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> { // new thumbnail finishTransitionPosted = new WindowCallbacksCompat(taskView) { + // The number of frames to defer until we actually finish the animation + private int mDeferFrameCount = 2; + @Override public void onPostDraw(Canvas canvas) { + if (mDeferFrameCount > 0) { + mDeferFrameCount--; + // Workaround, detach and reattach to invalidate the root node for + // another draw + detach(); + attach(); + taskView.invalidate(); + return; + } + setStateOnUiThread(STATE_SCREENSHOT_CAPTURED); detach(); } diff --git a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java index 9e2de33954..261f45dc24 100644 --- a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java +++ b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java @@ -39,7 +39,7 @@ public class FallbackRecentsView extends RecentsView<RecentsActivity> { } @Override - protected void onAllTasksRemoved() { + protected void startHome() { mActivity.startHome(); } diff --git a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java index 5aca4f3263..7c5828b440 100644 --- a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java +++ b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java @@ -79,7 +79,7 @@ public class LauncherRecentsView extends RecentsView<Launcher> { } @Override - protected void onAllTasksRemoved() { + protected void startHome() { mActivity.getStateManager().goToState(NORMAL); } diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 92852d2cbf..e18708b193 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -55,6 +55,7 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import android.view.ViewDebug; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; @@ -127,6 +128,8 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl private final RecentsModel mModel; private final int mTaskTopMargin; private final ClearAllButton mClearAllButton; + private final Rect mClearAllButtonDeadZoneRect = new Rect(); + private final Rect mTaskViewDeadZoneRect = new Rect(); private final ScrollState mScrollState = new ScrollState(); // Keeps track of the previously known visible tasks for purposes of loading/unloading task data @@ -230,6 +233,10 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl private boolean mHandleTaskStackChanges; private Runnable mNextPageSwitchRunnable; private boolean mSwipeDownShouldLaunchApp; + private boolean mTouchDownToStartHome; + private final int mTouchSlop; + private int mDownX; + private int mDownY; private PendingAnimation mPendingAnimation; @@ -275,6 +282,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl setLayoutDirection(mIsRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR); mTaskTopMargin = getResources() .getDimensionPixelSize(R.dimen.task_thumbnail_top_margin); + mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mEmptyIcon = context.getDrawable(R.drawable.ic_empty_recents); mEmptyIcon.setCallback(this); @@ -378,9 +386,45 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl @Override public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); - if (ev.getAction() == MotionEvent.ACTION_UP && mShowEmptyMessage) { - onAllTasksRemoved(); + final int x = (int) ev.getX(); + final int y = (int) ev.getY(); + switch (ev.getAction()) { + case MotionEvent.ACTION_UP: + if (mShowEmptyMessage) { + onAllTasksRemoved(); + } + if (mTouchDownToStartHome) { + startHome(); + } + mTouchDownToStartHome = false; + break; + case MotionEvent.ACTION_CANCEL: + mTouchDownToStartHome = false; + break; + case MotionEvent.ACTION_MOVE: + // Passing the touch slop will not allow dismiss to home + if (mTouchDownToStartHome && Math.hypot(mDownX - x, mDownY - y) > mTouchSlop) { + mTouchDownToStartHome = false; + } + break; + case MotionEvent.ACTION_DOWN: + // Touch down anywhere but the deadzone around the visible clear all button and + // between the task views will start home on touch up + if (mTouchState == TOUCH_STATE_REST) { + updateDeadZoneRects(); + final boolean clearAllButtonDeadZoneConsumed = mClearAllButton.getAlpha() == 1 + && mClearAllButtonDeadZoneRect.contains(x, y); + if (!clearAllButtonDeadZoneConsumed + && !mTaskViewDeadZoneRect.contains(x + getScrollX(), y)) { + mTouchDownToStartHome = true; + } + } + mDownX = x; + mDownY = y; + break; } + + // Do not let touch escape to siblings below this view. return true; } @@ -599,7 +643,11 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl mHasVisibleTaskData.clear(); } - protected abstract void onAllTasksRemoved(); + protected void onAllTasksRemoved() { + startHome(); + } + + protected abstract void startHome(); public void reset() { mRunningTaskId = -1; @@ -1058,6 +1106,27 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl + (getWidth() - mInsets.right - getPaddingRight())) / 2); } + private void updateDeadZoneRects() { + // Get the deadzone rect surrounding the clear all button to not dismiss overview to home + mClearAllButtonDeadZoneRect.setEmpty(); + if (mClearAllButton.getWidth() > 0) { + int verticalMargin = getResources() + .getDimensionPixelSize(R.dimen.recents_clear_all_deadzone_vertical_margin); + mClearAllButton.getHitRect(mClearAllButtonDeadZoneRect); + mClearAllButtonDeadZoneRect.inset(-getPaddingRight() / 2, -verticalMargin); + } + + // Get the deadzone rect between the task views + mTaskViewDeadZoneRect.setEmpty(); + int count = getTaskViewCount(); + if (count > 0) { + final View taskView = getTaskViewAt(0); + getTaskViewAt(count - 1).getHitRect(mTaskViewDeadZoneRect); + mTaskViewDeadZoneRect.union(taskView.getLeft(), taskView.getTop(), taskView.getRight(), + taskView.getBottom()); + } + } + private void updateEmptyStateUi(boolean sizeChanged) { boolean hasValidSize = getWidth() > 0 && getHeight() > 0; if (sizeChanged && hasValidSize) { diff --git a/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java b/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java index 07f22aada4..fb653cfacd 100644 --- a/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java +++ b/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java @@ -161,6 +161,10 @@ public class TaskThumbnailView extends View { updateThumbnailPaintFilter(); } + public float getDimAlpha() { + return mDimAlpha; + } + public Rect getInsets() { if (mThumbnailData != null) { return mThumbnailData.insets; diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index 9dc3129fd8..c5ca183f7d 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -801,7 +801,7 @@ public class IconCache { } private static final class IconDB extends SQLiteCacheHelper { - private final static int RELEASE_VERSION = 23; + private final static int RELEASE_VERSION = 24; private final static String TABLE_NAME = "icons"; private final static String COLUMN_ROWID = "rowid"; diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 3a8679e21b..c3c4f5e5ed 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -741,6 +741,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, NotificationListener.removeNotificationsChangedListener(); getStateManager().moveToRestState(); + UiFactory.onLauncherStateOrResumeChanged(this); + // Workaround for b/78520668, explicitly trim memory once UI is hidden onTrimMemory(TRIM_MEMORY_UI_HIDDEN); } diff --git a/src/com/android/launcher3/anim/Interpolators.java b/src/com/android/launcher3/anim/Interpolators.java index 8a1abf412d..675e26de05 100644 --- a/src/com/android/launcher3/anim/Interpolators.java +++ b/src/com/android/launcher3/anim/Interpolators.java @@ -16,7 +16,10 @@ package com.android.launcher3.anim; +import static com.android.launcher3.Utilities.SINGLE_FRAME_MS; + import android.graphics.Path; +import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; @@ -45,6 +48,8 @@ public class Interpolators { public static final Interpolator DEACCEL_2_5 = new DecelerateInterpolator(2.5f); public static final Interpolator DEACCEL_3 = new DecelerateInterpolator(3f); + public static final Interpolator ACCEL_DEACCEL = new AccelerateDecelerateInterpolator(); + public static final Interpolator FAST_OUT_SLOW_IN = new PathInterpolator(0.4f, 0f, 0.2f, 1f); public static final Interpolator AGGRESSIVE_EASE = new PathInterpolator(0.2f, 0f, 0f, 1f); @@ -52,6 +57,9 @@ public class Interpolators { public static final Interpolator EXAGGERATED_EASE; + private static final int MIN_SETTLE_DURATION = 200; + private static final float OVERSHOOT_FACTOR = 0.9f; + static { Path exaggeratedEase = new Path(); exaggeratedEase.moveTo(0, 0); @@ -112,46 +120,18 @@ public class Interpolators { } }; - /** - * Interpolates using a particular section of the damped oscillation function. - * The section is selected by scaling and shifting the function. - */ - public static final Interpolator OSCILLATE = new Interpolator() { - - // Used to scale the oscillations horizontally - private final float horizontalScale = 1f; - // Used to shift the oscillations horizontally - private final float horizontalShift = 0.5f; - // Used to scale the oscillations vertically - private final float verticalScale = 1f; - // Used to shift the oscillations vertically - private final float verticalShift = 1f; - - @Override - public float getInterpolation(float t) { - t = horizontalScale * (t + horizontalShift); - return (float) ((verticalScale * (Math.exp(-t) * Math.cos(2 * Math.PI * t))) - + verticalShift); - } - }; - private static final float FAST_FLING_PX_MS = 10; public static Interpolator scrollInterpolatorForVelocity(float velocity) { return Math.abs(velocity) > FAST_FLING_PX_MS ? SCROLL : SCROLL_CUBIC; } - public static Interpolator overshootInterpolatorForVelocity(float velocity) { - return overshootInterpolatorForVelocity(velocity, 1f); - } - /** * Create an OvershootInterpolator with tension directly related to the velocity (in px/ms). * @param velocity The start velocity of the animation we want to overshoot. - * @param dampFactor An optional factor to reduce the amount of tension (how far we overshoot). */ - public static Interpolator overshootInterpolatorForVelocity(float velocity, float dampFactor) { - return new OvershootInterpolator(Math.min(Math.abs(velocity), 3f) / dampFactor); + public static Interpolator overshootInterpolatorForVelocity(float velocity) { + return new OvershootInterpolator(Math.min(Math.abs(velocity), 3f)); } /** @@ -183,4 +163,75 @@ public class Interpolators { float upperBound) { return t -> Utilities.mapRange(interpolator.getInterpolation(t), lowerBound, upperBound); } -}
\ No newline at end of file + + /** + * Computes parameters necessary for an overshoot effect. + */ + public static class OvershootParams { + public Interpolator interpolator; + public float start; + public float end; + public long duration; + + /** + * Given the input params, sets OvershootParams variables to be used by the caller. + * @param startProgress The progress from 0 to 1 that the overshoot starts from. + * @param overshootPastProgress The progress from 0 to 1 where we overshoot past (should + * either be equal to startProgress or endProgress, depending on if we want to + * overshoot immediately or only once we reach the end). + * @param endProgress The final progress from 0 to 1 that we will settle to. + * @param velocityPxPerMs The initial velocity that causes this overshoot. + * @param totalDistancePx The distance against which progress is calculated. + */ + public OvershootParams(float startProgress, float overshootPastProgress, + float endProgress, float velocityPxPerMs, int totalDistancePx) { + velocityPxPerMs = Math.abs(velocityPxPerMs); + start = startProgress; + int startPx = (int) (start * totalDistancePx); + // Overshoot by about half a frame. + float overshootBy = OVERSHOOT_FACTOR * velocityPxPerMs * + SINGLE_FRAME_MS / totalDistancePx / 2; + overshootBy = Utilities.boundToRange(overshootBy, 0.02f, 0.15f); + end = overshootPastProgress + overshootBy; + int endPx = (int) (end * totalDistancePx); + int overshootDistance = endPx - startPx; + // Calculate deceleration necessary to reach overshoot distance. + // Formula: velocityFinal^2 = velocityInitial^2 + 2 * acceleration * distance + // 0 = v^2 + 2ad (velocityFinal == 0) + // a = v^2 / -2d + float decelerationPxPerMs = velocityPxPerMs * velocityPxPerMs / (2 * overshootDistance); + // Calculate time necessary to reach peak of overshoot. + // Formula: acceleration = velocity / time + // time = velocity / acceleration + duration = (long) (velocityPxPerMs / decelerationPxPerMs); + + // Now that we're at the top of the overshoot, need to settle back to endProgress. + float settleDistance = end - endProgress; + int settleDistancePx = (int) (settleDistance * totalDistancePx); + // Calculate time necessary for the settle. + // Formula: distance = velocityInitial * time + 1/2 * acceleration * time^2 + // d = 1/2at^2 (velocityInitial = 0, since we just stopped at the top) + // t = sqrt(2d/a) + // Above formula assumes constant acceleration. Since we use ACCEL_DEACCEL, we actually + // have acceleration to halfway then deceleration the rest. So the formula becomes: + // t = sqrt(d/a) * 2 (half the distance for accel, half for deaccel) + long settleDuration = (long) Math.sqrt(settleDistancePx / decelerationPxPerMs) * 4; + + settleDuration = Math.max(MIN_SETTLE_DURATION, settleDuration); + // How much of the animation to devote to playing the overshoot (the rest is for settle). + float overshootFraction = (float) duration / (duration + settleDuration); + duration += settleDuration; + // Finally, create the interpolator, composed of two interpolators: an overshoot, which + // reaches end > 1, and then a settle to endProgress. + Interpolator overshoot = Interpolators.clampToProgress(DEACCEL, 0, overshootFraction); + // The settle starts at 1, where 1 is the top of the overshoot, and maps to a fraction + // such that final progress is endProgress. For example, if we overshot to 1.1 but want + // to end at 1, we need to map to 1/1.1. + Interpolator settle = Interpolators.clampToProgress(Interpolators.mapToProgress( + ACCEL_DEACCEL, 1, (endProgress - start) / (end - start)), overshootFraction, 1); + interpolator = t -> t <= overshootFraction + ? overshoot.getInterpolation(t) + : settle.getInterpolation(t); + } + } +} diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java index 09ea1ad41a..333fe5907c 100644 --- a/src/com/android/launcher3/graphics/LauncherIcons.java +++ b/src/com/android/launcher3/graphics/LauncherIcons.java @@ -340,7 +340,7 @@ public class LauncherIcons implements AutoCloseable { if (Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) { int offset = Math.max((int) Math.ceil(BLUR_FACTOR * textureWidth), Math.max(left, top)); int size = Math.max(width, height); - icon.setBounds(offset, offset, offset + size, offset + size); + icon.setBounds(offset, offset, size - offset, size - offset); } else { icon.setBounds(left, top, left+width, top+height); } |