Merge "Aniamte stashed handle color changes" into sc-v2-dev
diff --git a/quickstep/src/com/android/launcher3/taskbar/StashedHandleView.java b/quickstep/src/com/android/launcher3/taskbar/StashedHandleView.java
index 670035a..6db5839 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 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);
}
@@ -68,7 +77,30 @@
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 d6e0ba7..10da826 100644
--- a/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java
@@ -70,7 +70,8 @@
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 @@
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();
}