summaryrefslogtreecommitdiff
path: root/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
diff options
context:
space:
mode:
Diffstat (limited to 'packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java')
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java44
1 files changed, 42 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
index 7218acf614d4..822920e63460 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
@@ -1,5 +1,6 @@
package com.android.keyguard;
+import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Paint;
import android.graphics.Paint.Style;
@@ -12,11 +13,13 @@ import android.widget.TextClock;
import androidx.annotation.VisibleForTesting;
+import com.android.internal.colorextraction.ColorExtractor;
import com.android.keyguard.clock.ClockManager;
import com.android.systemui.Dependency;
+import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.plugins.ClockPlugin;
+import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.StatusBarState;
-import com.android.systemui.statusbar.StatusBarStateController;
import java.util.TimeZone;
@@ -50,6 +53,8 @@ public class KeyguardClockSwitch extends RelativeLayout {
* Maintain state so that a newly connected plugin can be initialized.
*/
private float mDarkAmount;
+ private boolean mSupportsDarkText;
+ private int[] mColorPalette;
private final StatusBarStateController.StateListener mStateListener =
new StatusBarStateController.StateListener() {
@@ -72,6 +77,21 @@ public class KeyguardClockSwitch extends RelativeLayout {
private ClockManager.ClockChangedListener mClockChangedListener = this::setClockPlugin;
+ /**
+ * Listener for changes to the color palette.
+ *
+ * The color palette changes when the wallpaper is changed.
+ */
+ private SysuiColorExtractor.OnColorsChangedListener mColorsListener = (extractor, which) -> {
+ if ((which & WallpaperManager.FLAG_LOCK) != 0) {
+ if (extractor instanceof SysuiColorExtractor) {
+ updateColors((SysuiColorExtractor) extractor);
+ } else {
+ updateColors(Dependency.get(SysuiColorExtractor.class));
+ }
+ }
+ };
+
public KeyguardClockSwitch(Context context) {
this(context, null);
}
@@ -100,6 +120,9 @@ public class KeyguardClockSwitch extends RelativeLayout {
super.onAttachedToWindow();
Dependency.get(ClockManager.class).addOnClockChangedListener(mClockChangedListener);
Dependency.get(StatusBarStateController.class).addCallback(mStateListener);
+ SysuiColorExtractor colorExtractor = Dependency.get(SysuiColorExtractor.class);
+ colorExtractor.addOnColorsChangedListener(mColorsListener);
+ updateColors(colorExtractor);
}
@Override
@@ -107,6 +130,8 @@ public class KeyguardClockSwitch extends RelativeLayout {
super.onDetachedFromWindow();
Dependency.get(ClockManager.class).removeOnClockChangedListener(mClockChangedListener);
Dependency.get(StatusBarStateController.class).removeCallback(mStateListener);
+ Dependency.get(SysuiColorExtractor.class)
+ .removeOnColorsChangedListener(mColorsListener);
}
private void setClockPlugin(ClockPlugin plugin) {
@@ -149,6 +174,9 @@ public class KeyguardClockSwitch extends RelativeLayout {
mClockPlugin.setStyle(getPaint().getStyle());
mClockPlugin.setTextColor(getCurrentTextColor());
mClockPlugin.setDarkAmount(mDarkAmount);
+ if (mColorPalette != null) {
+ mClockPlugin.setColorPalette(mSupportsDarkText, mColorPalette);
+ }
}
/**
@@ -159,7 +187,9 @@ public class KeyguardClockSwitch extends RelativeLayout {
View bigClockView = mClockPlugin.getBigClockView();
if (bigClockView != null) {
container.addView(bigClockView);
- container.setVisibility(View.VISIBLE);
+ if (container.getVisibility() == View.GONE) {
+ container.setVisibility(View.VISIBLE);
+ }
}
}
mBigClockContainer = container;
@@ -246,6 +276,16 @@ public class KeyguardClockSwitch extends RelativeLayout {
}
}
+ private void updateColors(SysuiColorExtractor colorExtractor) {
+ ColorExtractor.GradientColors colors = colorExtractor.getColors(WallpaperManager.FLAG_LOCK,
+ true);
+ mSupportsDarkText = colors.supportsDarkText();
+ mColorPalette = colors.getColorPalette();
+ if (mClockPlugin != null) {
+ mClockPlugin.setColorPalette(mSupportsDarkText, mColorPalette);
+ }
+ }
+
@VisibleForTesting (otherwise = VisibleForTesting.NONE)
ClockManager.ClockChangedListener getClockChangedListener() {
return mClockChangedListener;