widgets: re-add 2x2 widgets

Re-add 2x2 widgets. They were originally removed due to strange layouts
in landscape mode, but that has now been fixed with a new "tiny" layout
meant for that specific edge case. Also rename the widget forms to more
sensible names and make the small (previously minimal) widget be
text-only again.
This commit is contained in:
OxygenCobalt
2021-10-28 19:46:00 -06:00
parent df49e2765f
commit 4f4f6654c0
10 changed files with 150 additions and 101 deletions
@@ -43,7 +43,7 @@ private fun createViews(
private fun RemoteViews.applyMeta(context: Context, state: WidgetState) {
setTextViewText(R.id.widget_song, state.song.name)
setTextViewText(R.id.widget_artist, state.song.album.artist.name)
setTextViewText(R.id.widget_artist, state.song.album.artist.resolvedName)
if (state.albumArt != null) {
setImageViewBitmap(R.id.widget_cover, state.albumArt)
@@ -92,15 +92,15 @@ fun createDefaultWidget(context: Context): RemoteViews {
return createViews(context, R.layout.widget_default)
}
fun createCompactWidget(context: Context, state: WidgetState): RemoteViews {
val views = createViews(context, R.layout.widget_compact)
fun createTinyWidget(context: Context, state: WidgetState): RemoteViews {
val views = createViews(context, R.layout.widget_tiny)
views.applyMeta(context, state)
views.applyControls(context, state)
return views
}
fun createMinimalWidget(context: Context, state: WidgetState): RemoteViews {
val views = createViews(context, R.layout.widget_minimal)
fun createWideWidget(context: Context, state: WidgetState): RemoteViews {
val views = createViews(context, R.layout.widget_wide)
views.applyMeta(context, state)
views.applyControls(context, state)
return views
@@ -113,8 +113,15 @@ fun createSmallWidget(context: Context, state: WidgetState): RemoteViews {
return views
}
fun createFullWidget(context: Context, state: WidgetState): RemoteViews {
val views = createViews(context, R.layout.widget_full)
fun createMediumWidget(context: Context, state: WidgetState): RemoteViews {
val views = createViews(context, R.layout.widget_medium)
views.applyMeta(context, state)
views.applyControls(context, state)
return views
}
fun createLargeWidget(context: Context, state: WidgetState): RemoteViews {
val views = createViews(context, R.layout.widget_large)
views.applyMeta(context, state)
views.applyControls(context, state)
@@ -46,10 +46,11 @@ import org.oxycblt.auxio.util.logD
* packing what could be considered multiple widgets into a single responsive widget. All types
* are listed below:
*
* - Full: Large widgets will show cover art and all controls
* - Small: Tall and thin widgets will show cover art and three controls
* - Compact: Wide and short widgets will show cover art and all controls in a compact manner
* - Minimal: Small widgets will only show cover art and three controls
* - Large widgets will show cover art and all controls
* - Tall and thin widgets will show cover art and three controls
* - Wide and short widgets will show cover art and all controls in a compact manner
* - Small widgets will only show text and three controls
* - Tiny widgets [e.g landscape mode] will show cover art, text, and a play/pause control.
*
* There are some minor problems with this implementation [notably UI jittering when the widget
* picks a new layout below Android 12], but this is tolerable. It may be improved in the future.
@@ -80,10 +81,11 @@ class WidgetProvider : AppWidgetProvider() {
// Map each widget form to the cells where it would look at least okay.
val views = mapOf(
SizeF(180f, 152f) to createMinimalWidget(context, state),
SizeF(272f, 152f) to createCompactWidget(context, state),
SizeF(180f, 270f) to createSmallWidget(context, state),
SizeF(272f, 270f) to createFullWidget(context, state)
SizeF(180f, 100f) to createTinyWidget(context, state),
SizeF(180f, 152f) to createSmallWidget(context, state),
SizeF(272f, 152f) to createWideWidget(context, state),
SizeF(180f, 270f) to createMediumWidget(context, state),
SizeF(272f, 270f) to createLargeWidget(context, state)
)
appWidgetManager.applyViewsCompat(context, views)