Merge "Resumption player colorized from the album art" into rvc-dev am: e93d99c647 am: dea05a61f1
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11912008 Change-Id: I3ad438f138b9cfb453eafc75bf048b80a62d3479
This commit is contained in:
@@ -293,10 +293,11 @@ class MediaDataManager @Inject constructor(
|
|||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
val bgColor = artworkBitmap?.let { computeBackgroundColor(it) } ?: Color.DKGRAY
|
||||||
|
|
||||||
val mediaAction = getResumeMediaAction(resumeAction)
|
val mediaAction = getResumeMediaAction(resumeAction)
|
||||||
foregroundExecutor.execute {
|
foregroundExecutor.execute {
|
||||||
onMediaDataLoaded(packageName, null, MediaData(true, Color.DKGRAY, appName,
|
onMediaDataLoaded(packageName, null, MediaData(true, bgColor, appName,
|
||||||
null, desc.subtitle, desc.title, artworkIcon, listOf(mediaAction), listOf(0),
|
null, desc.subtitle, desc.title, artworkIcon, listOf(mediaAction), listOf(0),
|
||||||
packageName, token, appIntent, device = null, active = false,
|
packageName, token, appIntent, device = null, active = false,
|
||||||
resumeAction = resumeAction))
|
resumeAction = resumeAction))
|
||||||
@@ -319,7 +320,6 @@ class MediaDataManager @Inject constructor(
|
|||||||
|
|
||||||
// Foreground and Background colors computed from album art
|
// Foreground and Background colors computed from album art
|
||||||
val notif: Notification = sbn.notification
|
val notif: Notification = sbn.notification
|
||||||
var bgColor = Color.WHITE
|
|
||||||
var artworkBitmap = metadata.getBitmap(MediaMetadata.METADATA_KEY_ART)
|
var artworkBitmap = metadata.getBitmap(MediaMetadata.METADATA_KEY_ART)
|
||||||
if (artworkBitmap == null) {
|
if (artworkBitmap == null) {
|
||||||
artworkBitmap = metadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART)
|
artworkBitmap = metadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART)
|
||||||
@@ -349,26 +349,8 @@ class MediaDataManager @Inject constructor(
|
|||||||
drawable.draw(canvas)
|
drawable.draw(canvas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val p = MediaNotificationProcessor.generateArtworkPaletteBuilder(artworkBitmap)
|
|
||||||
.generate()
|
|
||||||
val swatch = MediaNotificationProcessor.findBackgroundSwatch(p)
|
|
||||||
bgColor = swatch.rgb
|
|
||||||
}
|
}
|
||||||
// Adapt background color, so it's always subdued and text is legible
|
val bgColor = computeBackgroundColor(artworkBitmap)
|
||||||
val tmpHsl = floatArrayOf(0f, 0f, 0f)
|
|
||||||
ColorUtils.colorToHSL(bgColor, tmpHsl)
|
|
||||||
|
|
||||||
val l = tmpHsl[2]
|
|
||||||
// Colors with very low luminosity can have any saturation. This means that changing the
|
|
||||||
// luminosity can make a black become red. Let's remove the saturation of very light or
|
|
||||||
// very dark colors to avoid this issue.
|
|
||||||
if (l < LUMINOSITY_THRESHOLD || l > 1f - LUMINOSITY_THRESHOLD) {
|
|
||||||
tmpHsl[1] = 0f
|
|
||||||
}
|
|
||||||
tmpHsl[1] *= SATURATION_MULTIPLIER
|
|
||||||
tmpHsl[2] = DEFAULT_LUMINOSITY
|
|
||||||
|
|
||||||
bgColor = ColorUtils.HSLToColor(tmpHsl)
|
|
||||||
|
|
||||||
// App name
|
// App name
|
||||||
val builder = Notification.Builder.recoverBuilder(context, notif)
|
val builder = Notification.Builder.recoverBuilder(context, notif)
|
||||||
@@ -480,6 +462,33 @@ class MediaDataManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun computeBackgroundColor(artworkBitmap: Bitmap?): Int {
|
||||||
|
var color = Color.WHITE
|
||||||
|
if (artworkBitmap != null) {
|
||||||
|
// If we have art, get colors from that
|
||||||
|
val p = MediaNotificationProcessor.generateArtworkPaletteBuilder(artworkBitmap)
|
||||||
|
.generate()
|
||||||
|
val swatch = MediaNotificationProcessor.findBackgroundSwatch(p)
|
||||||
|
color = swatch.rgb
|
||||||
|
}
|
||||||
|
// Adapt background color, so it's always subdued and text is legible
|
||||||
|
val tmpHsl = floatArrayOf(0f, 0f, 0f)
|
||||||
|
ColorUtils.colorToHSL(color, tmpHsl)
|
||||||
|
|
||||||
|
val l = tmpHsl[2]
|
||||||
|
// Colors with very low luminosity can have any saturation. This means that changing the
|
||||||
|
// luminosity can make a black become red. Let's remove the saturation of very light or
|
||||||
|
// very dark colors to avoid this issue.
|
||||||
|
if (l < LUMINOSITY_THRESHOLD || l > 1f - LUMINOSITY_THRESHOLD) {
|
||||||
|
tmpHsl[1] = 0f
|
||||||
|
}
|
||||||
|
tmpHsl[1] *= SATURATION_MULTIPLIER
|
||||||
|
tmpHsl[2] = DEFAULT_LUMINOSITY
|
||||||
|
|
||||||
|
color = ColorUtils.HSLToColor(tmpHsl)
|
||||||
|
return color
|
||||||
|
}
|
||||||
|
|
||||||
private fun getResumeMediaAction(action: Runnable): MediaAction {
|
private fun getResumeMediaAction(action: Runnable): MediaAction {
|
||||||
return MediaAction(
|
return MediaAction(
|
||||||
context.getDrawable(R.drawable.lb_ic_play),
|
context.getDrawable(R.drawable.lb_ic_play),
|
||||||
|
|||||||
Reference in New Issue
Block a user