Merge "Aniamte stashed handle color changes" into sc-v2-dev

This commit is contained in:
Tony Wickham
2021-09-30 02:17:18 +00:00
committed by Android (Google) Code Review
2 changed files with 37 additions and 4 deletions

View File

@@ -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);
}
@@ -68,7 +77,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);
}
}
}

View File

@@ -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();
}