Merge "Disable color extraction for media" into pi-dev

This commit is contained in:
Lucas Dupin
2018-03-07 17:36:26 +00:00
committed by Android (Google) Code Review
3 changed files with 43 additions and 8 deletions

View File

@@ -46,6 +46,7 @@ import java.util.Arrays;
public class SysuiColorExtractor extends ColorExtractor implements Dumpable {
private static final String TAG = "SysuiColorExtractor";
private boolean mWallpaperVisible;
private boolean mMediaBackdropVisible;
// Colors to return when the wallpaper isn't visible
private final GradientColors mWpHiddenColors;
@@ -157,13 +158,18 @@ public class SysuiColorExtractor extends ColorExtractor implements Dumpable {
public GradientColors getColors(int which, int type, boolean ignoreWallpaperVisibility) {
// mWallpaperVisible only handles the "system wallpaper" and will be always set to false
// if we have different lock and system wallpapers.
if (which == WallpaperManager.FLAG_LOCK) {
ignoreWallpaperVisibility = true;
}
if (mWallpaperVisible || ignoreWallpaperVisibility) {
return super.getColors(which, type);
if (which == WallpaperManager.FLAG_SYSTEM) {
if (mWallpaperVisible || ignoreWallpaperVisibility) {
return super.getColors(which, type);
} else {
return mWpHiddenColors;
}
} else {
return mWpHiddenColors;
if (mMediaBackdropVisible) {
return mWpHiddenColors;
} else {
return super.getColors(which, type);
}
}
}
@@ -175,6 +181,13 @@ public class SysuiColorExtractor extends ColorExtractor implements Dumpable {
}
}
public void setMediaBackdropVisible(boolean visible) {
if (mMediaBackdropVisible != visible) {
mMediaBackdropVisible = visible;
triggerColorsChanged(WallpaperManager.FLAG_LOCK);
}
}
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("SysuiColorExtractor:");

View File

@@ -1589,8 +1589,7 @@ public class StatusBar extends SystemUI implements DemoMode,
Drawable artworkDrawable = null;
if (mediaMetadata != null) {
Bitmap artworkBitmap = null;
artworkBitmap = mediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ART);
Bitmap artworkBitmap = mediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ART);
if (artworkBitmap == null) {
artworkBitmap = mediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
// might still be null
@@ -1633,6 +1632,7 @@ public class StatusBar extends SystemUI implements DemoMode,
mBackdrop.setAlpha(1f);
}
mStatusBarWindowManager.setBackdropShowing(true);
mColorExtractor.setMediaBackdropVisible(true);
metaDataChanged = true;
if (DEBUG_MEDIA) {
Log.v(TAG, "DEBUG_MEDIA: Fading in album artwork");
@@ -1684,6 +1684,7 @@ public class StatusBar extends SystemUI implements DemoMode,
if (DEBUG_MEDIA) {
Log.v(TAG, "DEBUG_MEDIA: Fading out album artwork");
}
mColorExtractor.setMediaBackdropVisible(false);
boolean cannotAnimateDoze = mDozing && !ScrimState.AOD.getAnimateChange();
if (mFingerprintUnlockController.getMode()
== FingerprintUnlockController.MODE_WAKE_AND_UNLOCK_PULSING

View File

@@ -84,6 +84,27 @@ public class SysuiColorExtractorTests extends SysuiTestCase {
}
}
@Test
public void getColors_fallbackWhenMediaIsVisible() {
ColorExtractor.GradientColors colors = new ColorExtractor.GradientColors();
colors.setMainColor(Color.RED);
colors.setSecondaryColor(Color.RED);
SysuiColorExtractor extractor = getTestableExtractor(colors);
simulateEvent(extractor);
extractor.setWallpaperVisible(true);
extractor.setMediaBackdropVisible(true);
ColorExtractor.GradientColors fallbackColors = extractor.getFallbackColors();
for (int type : sTypes) {
assertEquals("Not using fallback!",
extractor.getColors(WallpaperManager.FLAG_LOCK, type), fallbackColors);
assertNotEquals("Media visibility should not affect system wallpaper.",
extractor.getColors(WallpaperManager.FLAG_SYSTEM, type), fallbackColors);
}
}
private SysuiColorExtractor getTestableExtractor(ColorExtractor.GradientColors colors) {
return new SysuiColorExtractor(getContext(),
(inWallpaperColors, outGradientColorsNormal, outGradientColorsDark,