ColorExtractor available through Dependency
Having only one instance of ColorExtractor instead of
multiple. Also registering listeners since 1 won't be
enough anymore.
Test: set wallpaper, check scrim color
Change-Id: Ic7f08f98e0671f5b9b5d25d7f0263ad3a1443fa7
diff --git a/packages/SystemUI/colorextraction/src/com/google/android/colorextraction/ColorExtractor.java b/packages/SystemUI/colorextraction/src/com/google/android/colorextraction/ColorExtractor.java
index a91aa61..c07b7ae 100644
--- a/packages/SystemUI/colorextraction/src/com/google/android/colorextraction/ColorExtractor.java
+++ b/packages/SystemUI/colorextraction/src/com/google/android/colorextraction/ColorExtractor.java
@@ -20,17 +20,21 @@
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Color;
+import android.support.v4.graphics.ColorUtils;
import android.util.Log;
import com.google.android.colorextraction.types.ExtractionType;
import com.google.android.colorextraction.types.Tonal;
+import java.util.ArrayList;
+
/**
* Class to process wallpaper colors and generate a tonal palette based on them.
*/
public class ColorExtractor implements WallpaperManager.OnColorsChangedListener {
private static final String TAG = "ColorExtractor";
private static final int FALLBACK_COLOR = Color.BLACK;
+ private static final float DARK_TEXT_LUMINOSITY = 0.7f;
private int mMainFallbackColor = FALLBACK_COLOR;
private int mSecondaryFallbackColor = FALLBACK_COLOR;
@@ -38,13 +42,14 @@
private final GradientColors mLockColors;
private final Context mContext;
private final ExtractionType mExtractionType;
- private OnColorsChangedListener mListener;
+ private final ArrayList<OnColorsChangedListener> mOnColorsChangedListeners;
public ColorExtractor(Context context) {
mContext = context;
mSystemColors = new GradientColors();
mLockColors = new GradientColors();
mExtractionType = new Tonal();
+ mOnColorsChangedListeners = new ArrayList<>();
WallpaperManager wallpaperManager = mContext.getSystemService(WallpaperManager.class);
@@ -69,22 +74,18 @@
}
}
- public void setListener(OnColorsChangedListener listener) {
- mListener = listener;
- }
-
@Override
public void onColorsChanged(WallpaperColors colors, int which) {
if ((which & WallpaperManager.FLAG_LOCK) != 0) {
extractInto(colors, mLockColors);
- if (mListener != null) {
- mListener.onColorsChanged(mLockColors, WallpaperManager.FLAG_LOCK);
+ for (OnColorsChangedListener listener : mOnColorsChangedListeners) {
+ listener.onColorsChanged(mLockColors, WallpaperManager.FLAG_LOCK);
}
}
if ((which & WallpaperManager.FLAG_SYSTEM) != 0) {
extractInto(colors, mSystemColors);
- if (mListener != null) {
- mListener.onColorsChanged(mSystemColors, WallpaperManager.FLAG_SYSTEM);
+ for (OnColorsChangedListener listener : mOnColorsChangedListeners) {
+ listener.onColorsChanged(mSystemColors, WallpaperManager.FLAG_SYSTEM);
}
}
}
@@ -109,6 +110,14 @@
}
}
+ public void addOnColorsChangedListener(OnColorsChangedListener listener) {
+ mOnColorsChangedListeners.add(listener);
+ }
+
+ public void removeOnColorsChangedListener(OnColorsChangedListener listener) {
+ mOnColorsChangedListeners.remove(listener);
+ }
+
public static class GradientColors {
private int mMainColor = FALLBACK_COLOR;
private int mSecondaryColor = FALLBACK_COLOR;
diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java
index cfac2b7..bddae02 100644
--- a/packages/SystemUI/src/com/android/systemui/Dependency.java
+++ b/packages/SystemUI/src/com/android/systemui/Dependency.java
@@ -84,6 +84,8 @@
import com.android.systemui.util.leak.LeakReporter;
import com.android.systemui.volume.VolumeDialogControllerImpl;
+import com.google.android.colorextraction.ColorExtractor;
+
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.HashMap;
@@ -264,6 +266,8 @@
mProviders.put(AccessibilityManagerWrapper.class,
() -> new AccessibilityManagerWrapper(mContext));
+ mProviders.put(ColorExtractor.class, () -> new ColorExtractor(mContext));
+
// Put all dependencies above here so the factory can override them if it wants.
SystemUIFactory.getInstance().injectDependencies(mProviders, mContext);
}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
index 7bc591f..4e17bc9 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
@@ -374,6 +374,8 @@
EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, true));
MetricsLogger.visible(this, MetricsEvent.OVERVIEW_ACTIVITY);
+ // Make sure we have the right gradient and we're listening for update events
+ mRecentsView.onStart();
// Notify of the next draw
mRecentsView.getViewTreeObserver().addOnPreDrawListener(mRecentsDrawnEventListener);
@@ -534,6 +536,9 @@
MetricsLogger.hidden(this, MetricsEvent.OVERVIEW_ACTIVITY);
Recents.getTaskLoader().getHighResThumbnailLoader().setVisible(false);
+ // We don't need to update the gradient when we're not visible
+ mRecentsView.onStop();
+
if (!isChangingConfigurations()) {
// Workaround for b/22542869, if the RecentsActivity is started again, but without going
// through SystemUI, we need to reset the config launch flags to ensure that we do not
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
index 2401e67..6879436 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
@@ -45,6 +45,7 @@
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.systemui.Dependency;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.recents.Recents;
@@ -145,11 +146,7 @@
mBackgroundScrim = new GradientDrawable(context);
mBackgroundScrim.setCallback(this);
mBackgroundScrim.setAlpha((int) (mScrimAlpha * 255));
- mColorExtractor = new ColorExtractor(context);
- mColorExtractor.setListener(this);
- // We don't want to interpolate colors because we're defining the initial state.
- // Gradient should be set/ready when you open "Recents".
- mBackgroundScrim.setColors(mColorExtractor.getColors(WallpaperManager.FLAG_SYSTEM), false);
+ mColorExtractor = Dependency.get(ColorExtractor.class);
LayoutInflater inflater = LayoutInflater.from(context);
if (RecentsDebugFlags.Static.EnableStackActionButton) {
@@ -828,4 +825,15 @@
mBackgroundScrim.setColors(colors);
}
}
+
+ public void onStart() {
+ mColorExtractor.addOnColorsChangedListener(this);
+ // We don't want to interpolate colors because we're defining the initial state.
+ // Gradient should be set/ready when you open "Recents".
+ mBackgroundScrim.setColors(mColorExtractor.getColors(WallpaperManager.FLAG_SYSTEM), false);
+ }
+
+ public void onStop() {
+ mColorExtractor.removeOnColorsChangedListener(this);
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
index d29b356..1799bc9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
@@ -35,6 +35,7 @@
import android.view.animation.PathInterpolator;
import com.android.keyguard.KeyguardUpdateMonitor;
+import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationData;
@@ -123,8 +124,8 @@
mLightBarController = lightBarController;
mScrimBehindAlpha = context.getResources().getFloat(R.dimen.scrim_behind_alpha);
- mColorExtractor = new ColorExtractor(context);
- mColorExtractor.setListener(this);
+ mColorExtractor = Dependency.get(ColorExtractor.class);
+ mColorExtractor.addOnColorsChangedListener(this);
mLockColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK);
mSystemColors = mColorExtractor.getColors(WallpaperManager.FLAG_SYSTEM);
mNeedsDrawableColorUpdate = true;