From 701b0f528e78ef4fcc9bf0f585a82e36021a8cd8 Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Tue, 23 Jan 2018 11:13:05 -0800 Subject: [PATCH] Use AllAppsTransitionController to animate the hotseat & scrim. Bug: 70220260 Change-Id: I69bff4234c2fd0c76cb43cdd89342dcc04f2db40 --- quickstep/res/values/dimens.xml | 2 - .../LauncherAppTransitionManager.java | 49 +++++++++---------- .../allapps/AllAppsTransitionController.java | 7 +-- .../android/launcher3/views/AllAppsScrim.java | 34 ++----------- 4 files changed, 33 insertions(+), 59 deletions(-) diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index 9cc79738c7..bdc7c36d7f 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -37,6 +37,4 @@ 25dp 80dp - - -2.857dp diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java index 256e9265df..47179c5a02 100644 --- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java +++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java @@ -16,7 +16,7 @@ package com.android.launcher3; -import static com.android.launcher3.views.AllAppsScrim.SCRIM_PROGRESS; +import static com.android.launcher3.allapps.AllAppsTransitionController.ALL_APPS_PROGRESS; import static com.android.systemui.shared.recents.utilities.Utilities.getNextFrameNumber; import static com.android.systemui.shared.recents.utilities.Utilities.getSurface; import static com.android.systemui.shared.recents.utilities.Utilities.postAtFrontOfQueueAsynchronously; @@ -40,9 +40,9 @@ import android.view.animation.Interpolator; import android.widget.ImageView; import com.android.launcher3.InsettableFrameLayout.LayoutParams; +import com.android.launcher3.allapps.AllAppsTransitionController; import com.android.launcher3.anim.Interpolators; import com.android.launcher3.dragndrop.DragLayer; -import com.android.launcher3.views.AllAppsScrim; import com.android.systemui.shared.system.ActivityCompat; import com.android.systemui.shared.system.ActivityOptionsCompat; import com.android.systemui.shared.system.RemoteAnimationAdapterCompat; @@ -62,14 +62,16 @@ public class LauncherAppTransitionManager { private static final int CLOSING_TRANSITION_DURATION_MS = 350; + // Progress = 0: All apps is fully pulled up, Progress = 1: All apps is fully pulled down. + private static final float ALL_APPS_PROGRESS_START = 1.3059858f; + private static final float ALL_APPS_PROGRESS_SLIDE_END = 0.99581414f; + private final DragLayer mDragLayer; private final Launcher mLauncher; private final DeviceProfile mDeviceProfile; private final float mContentTransY; private final float mWorkspaceTransY; - // The smallest y-value the shelf will reach on screen, before overshooting back down to 0. - private final float mShelfMinValue; private ImageView mFloatingView; private boolean mIsRtl; @@ -84,7 +86,6 @@ public class LauncherAppTransitionManager { Resources res = launcher.getResources(); mContentTransY = res.getDimensionPixelSize(R.dimen.content_trans_y); mWorkspaceTransY = res.getDimensionPixelSize(R.dimen.workspace_trans_y); - mShelfMinValue = res.getDimensionPixelSize(R.dimen.shelf_min_value); } /** @@ -477,31 +478,29 @@ public class LauncherAppTransitionManager { workspaceAnimator.setDuration(333); workspaceAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); - // Animate the shelf - AllAppsScrim allAppsScrim = mLauncher.findViewById(R.id.all_apps_scrim); - View hotseat = mLauncher.getHotseat(); - final float endY = mShelfMinValue; - int startY = hotseat.getMeasuredHeight() - + (allAppsScrim.getShadowBitmap().getHeight() / 2); - hotseat.setTranslationY(startY); - allAppsScrim.setTranslationY(startY); + // Animate the shelf in two parts: slide in, and overeshoot. + AllAppsTransitionController allAppsController = mLauncher.getAllAppsController(); + // The shelf will start offscreen + final float startY = ALL_APPS_PROGRESS_START; + // And will end slightly pulled up, so that there is something to overshoot back to 1f. + final float slideEnd = ALL_APPS_PROGRESS_SLIDE_END; - AnimatorSet hotseatSlideIn = new AnimatorSet(); - hotseatSlideIn.play(ObjectAnimator.ofFloat(hotseat, View.TRANSLATION_Y, startY, endY)); - hotseatSlideIn.play(ObjectAnimator.ofFloat(allAppsScrim, SCRIM_PROGRESS, startY, endY)); - hotseatSlideIn.setStartDelay(150); - hotseatSlideIn.setDuration(317); - hotseatSlideIn.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); + allAppsController.setProgress(startY); - AnimatorSet hotseatOvershoot = new AnimatorSet(); - hotseatOvershoot.play(ObjectAnimator.ofFloat(hotseat, View.TRANSLATION_Y, endY, 0)); - hotseatOvershoot.play(ObjectAnimator.ofFloat(allAppsScrim, SCRIM_PROGRESS, endY, 0)); - hotseatOvershoot.setDuration(153); - hotseatOvershoot.setInterpolator(Interpolators.OVERSHOOT_0); + Animator allAppsSlideIn = + ObjectAnimator.ofFloat(allAppsController, ALL_APPS_PROGRESS, startY, slideEnd); + allAppsSlideIn.setStartDelay(150); + allAppsSlideIn.setDuration(317); + allAppsSlideIn.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); + + Animator allAppsOvershoot = + ObjectAnimator.ofFloat(allAppsController, ALL_APPS_PROGRESS, slideEnd, 1f); + allAppsOvershoot.setDuration(153); + allAppsOvershoot.setInterpolator(Interpolators.OVERSHOOT_0); AnimatorSet resumeLauncherAnimation = new AnimatorSet(); resumeLauncherAnimation.play(workspaceAnimator); - resumeLauncherAnimation.playSequentially(hotseatSlideIn, hotseatOvershoot); + resumeLauncherAnimation.playSequentially(allAppsSlideIn, allAppsOvershoot); return resumeLauncherAnimation; } } diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java index c02f2dfd8d..dadc6cd0be 100644 --- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java +++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java @@ -37,8 +37,8 @@ import com.android.launcher3.views.AllAppsScrim; public class AllAppsTransitionController implements SearchUiManager.OnScrollRangeChangeListener, LauncherStateManager.StateHandler { - private static final Property PROGRESS = - new Property(Float.class, "progress") { + public static final Property ALL_APPS_PROGRESS = + new Property(Float.class, "allAppsProgress") { @Override public Float get(AllAppsTransitionController controller) { @@ -164,7 +164,8 @@ public class AllAppsTransitionController } Interpolator interpolator = config.userControlled ? LINEAR : FAST_OUT_SLOW_IN; - ObjectAnimator anim = ObjectAnimator.ofFloat(this, PROGRESS, mProgress, targetProgress); + ObjectAnimator anim = + ObjectAnimator.ofFloat(this, ALL_APPS_PROGRESS, mProgress, targetProgress); anim.setDuration(config.duration); anim.setInterpolator(interpolator); anim.addListener(getProgressAnimatorListener()); diff --git a/src/com/android/launcher3/views/AllAppsScrim.java b/src/com/android/launcher3/views/AllAppsScrim.java index 6cd40fd5ab..662f99c05f 100644 --- a/src/com/android/launcher3/views/AllAppsScrim.java +++ b/src/com/android/launcher3/views/AllAppsScrim.java @@ -61,25 +61,11 @@ public class AllAppsScrim extends View implements OnChangeListener, Insettable { private final NinePatchDrawHelper mShadowHelper = new NinePatchDrawHelper(); - private float mProgress; private int mFillAlpha; private float mDrawHeight; private float mDrawOffsetY; - public static final Property SCRIM_PROGRESS = - new Property(Float.class, "allAppsScrimProgress") { - @Override - public Float get(AllAppsScrim allAppsScrim) { - return allAppsScrim.getProgress(); - } - - @Override - public void set(AllAppsScrim allAppsScrim, Float progress) { - allAppsScrim.setProgress(progress); - } - }; - public AllAppsScrim(Context context) { this(context, null); } @@ -174,23 +160,17 @@ public class AllAppsScrim extends View implements OnChangeListener, Insettable { public void setProgress(float translateY, float alpha) { int newAlpha = Math.round(alpha * mAlphaRange + mMinAlpha); - if (newAlpha != mFillAlpha) { - mFillAlpha = newAlpha; - mFillPaint.setAlpha(mFillAlpha); - invalidateDrawRect(); - } - - setProgress(translateY); - } - - public void setProgress(float translateY) { // Negative translation means the scrim is moving up. For negative translation, we change // draw offset as it requires redraw (since more area of the scrim needs to be shown). For // position translation, we simply translate the scrim down as it avoids invalidate and // hence could be optimized by the platform. float drawOffsetY = Math.min(translateY, 0); - if (drawOffsetY != mDrawOffsetY) { + if (newAlpha != mFillAlpha || drawOffsetY != mDrawOffsetY) { + invalidateDrawRect(); + + mFillAlpha = newAlpha; + mFillPaint.setAlpha(mFillAlpha); mDrawOffsetY = drawOffsetY; invalidateDrawRect(); } @@ -198,10 +178,6 @@ public class AllAppsScrim extends View implements OnChangeListener, Insettable { setTranslationY(Math.max(translateY, 0)); } - public float getProgress() { - return mProgress; - } - private void invalidateDrawRect() { mDrawRect.top = (int) (getHeight() + mDrawOffsetY - mDrawHeight + mPadding.top - mShadowBlur - 0.5f);