Skip to content
Snippets Groups Projects
Commit 1c4879f6 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Duncan McNamara
Browse files

Widgets: add a secondary background color for the micro layout

parent 256a3b9d
No related branches found
No related tags found
1 merge request!1363New widgets
......@@ -248,7 +248,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
views.setImageViewBitmap(R.id.seek_rewind, context.getColoredBitmapFromColor(R.drawable.ic_widget_rewind_10, foregroundColor))
views.setImageViewBitmap(R.id.seek_forward, context.getColoredBitmapFromColor(R.drawable.ic_widget_forward_10, foregroundColor))
}
views.setImageViewBitmap(R.id.play_pause_background, context.getColoredBitmapFromColor(R.drawable.widget_rectangle_background, backgroundColor, 52.dp, 52.dp))
views.setImageViewBitmap(R.id.play_pause_background, context.getColoredBitmapFromColor(R.drawable.widget_rectangle_background, widgetCacheEntry.widget.getBackgroundSecondaryColor(context, palette = palette), 52.dp, 52.dp))
views.setImageViewBitmap(R.id.widget_configure, if (widgetCacheEntry.widget.showConfigure) context.getColoredBitmapFromColor(R.drawable.ic_widget_configure, foregroundColor, 24.dp, 24.dp) else null)
if (widgetType == WidgetType.PILL) views.setImageViewBitmap(R.id.cover_background, context.getColoredBitmapFromColor(R.drawable.widget_circle, widgetCacheEntry.widget.getSeparatorColor(context, palette), 48.dp, 48.dp))
}
......
......@@ -71,6 +71,22 @@ fun Widget.getBackgroundColor(context: Context, palette: Palette?): Int {
return if (opacity.coerceAtLeast(0).coerceAtMost(100) != 100) ColorUtils.setAlphaComponent(untreatedColor, (opacity * 2.55F).toInt()) else untreatedColor
}
/**
* Get the background secondary color of the widget depending on its theme. Mostly used for the micro widget 'FAB' color
* @param context the context to use
* @param palette the palette to be used if needed
* @return a color
*/
@RequiresApi(Build.VERSION_CODES.S)
fun Widget.getBackgroundSecondaryColor(context: Context, palette: Palette?): Int {
val untreatedColor = when {
theme == 0 -> ContextCompat.getColor(context, if (lightTheme) android.R.color.system_accent1_100 else android.R.color.system_accent1_700)
theme == 1 -> (if (lightTheme) palette?.lightMutedSwatch?.rgb ?: ContextCompat.getColor(context, R.color.grey300) else palette?.darkMutedSwatch?.rgb ?: ContextCompat.getColor(context, R.color.grey800))
else -> backgroundColor.lightenOrDarkenColor(0.1F)
}
return if (opacity.coerceAtLeast(0).coerceAtMost(100) != 100) ColorUtils.setAlphaComponent(untreatedColor, (opacity * 2.55F).toInt()) else untreatedColor
}
/**
* Get the Artist text color of the widget depending on its theme
* @param context the context to use
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment