From 0ede0fa4059800c2b0295e648a9d2ff66550bea4 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Wed, 29 Sep 2021 16:16:43 -0700 Subject: [PATCH] Aniamte stashed handle color changes Test: Swipe from light background to dark background, ensure handle animates the color change Bug: 193938970 Change-Id: I815c3a364019935bdf3d69309e695ac34b119c5e --- .../launcher3/taskbar/StashedHandleView.java | 36 +++++++++++++++++-- .../taskbar/StashedHandleViewController.java | 5 +-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/StashedHandleView.java b/quickstep/src/com/android/launcher3/taskbar/StashedHandleView.java index 0224bc4a5b..f7d4a30739 100644 --- a/quickstep/src/com/android/launcher3/taskbar/StashedHandleView.java +++ b/quickstep/src/com/android/launcher3/taskbar/StashedHandleView.java @@ -15,6 +15,10 @@ */ package com.android.launcher3.taskbar; +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.ObjectAnimator; +import android.annotation.Nullable; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; @@ -23,15 +27,20 @@ import android.view.View; import androidx.annotation.ColorInt; import androidx.core.content.ContextCompat; +import com.android.launcher3.LauncherAnimUtils; import com.android.launcher3.R; public class StashedHandleView extends View { + private static final long COLOR_CHANGE_DURATION = 120; + private final @ColorInt int mStashedHandleLightColor; private final @ColorInt int mStashedHandleDarkColor; private final Rect mSampledRegion = new Rect(); private final int[] mTmpArr = new int[2]; + private @Nullable ObjectAnimator mColorChangeAnim; + public StashedHandleView(Context context) { this(context, null); } @@ -64,7 +73,30 @@ public class StashedHandleView extends View { return mSampledRegion; } - public void updateHandleColor(boolean isRegionDark) { - setBackgroundColor(isRegionDark ? mStashedHandleLightColor : mStashedHandleDarkColor); + /** + * Updates the handle color. + * @param isRegionDark Whether the background behind the handle is dark, and thus the handle + * should be light (and vice versa). + * @param animate Whether to animate the change, or apply it immediately. + */ + public void updateHandleColor(boolean isRegionDark, boolean animate) { + int newColor = isRegionDark ? mStashedHandleLightColor : mStashedHandleDarkColor; + if (mColorChangeAnim != null) { + mColorChangeAnim.cancel(); + } + if (animate) { + mColorChangeAnim = ObjectAnimator.ofArgb(this, + LauncherAnimUtils.VIEW_BACKGROUND_COLOR, newColor); + mColorChangeAnim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mColorChangeAnim = null; + } + }); + mColorChangeAnim.setDuration(COLOR_CHANGE_DURATION); + mColorChangeAnim.start(); + } else { + setBackgroundColor(newColor); + } } } diff --git a/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java b/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java index 2858d7c38e..b9730a5114 100644 --- a/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java @@ -70,7 +70,8 @@ public class StashedHandleViewController { mPrefs = Utilities.getPrefs(mActivity); mStashedHandleView = stashedHandleView; mStashedHandleView.updateHandleColor( - mPrefs.getBoolean(SHARED_PREFS_STASHED_HANDLE_REGION_DARK_KEY, false)); + mPrefs.getBoolean(SHARED_PREFS_STASHED_HANDLE_REGION_DARK_KEY, false), + false /* animate */); final Resources resources = mActivity.getResources(); mStashedHandleWidth = resources.getDimensionPixelSize(R.dimen.taskbar_stashed_handle_width); mStashedHandleHeight = resources.getDimensionPixelSize( @@ -79,7 +80,7 @@ public class StashedHandleViewController { new RegionSamplingHelper.SamplingCallback() { @Override public void onRegionDarknessChanged(boolean isRegionDark) { - mStashedHandleView.updateHandleColor(isRegionDark); + mStashedHandleView.updateHandleColor(isRegionDark, true /* animate */); mPrefs.edit().putBoolean(SHARED_PREFS_STASHED_HANDLE_REGION_DARK_KEY, isRegionDark).apply(); }