mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-03 09:26:51 +00:00
Merge "Aniamte stashed handle color changes" into sc-v2-dev
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user