widget: re-introduce <31 elevation

The pre-Android 12 padding option was removed previously, but I've
decided to re-add it for stylistic cohesion with the material design
of those versions.
This commit is contained in:
OxygenCobalt 2021-08-21 09:25:24 -06:00
parent 0c54fa05b9
commit 4b438daaf2
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 22 additions and 20 deletions

View file

@ -33,6 +33,8 @@ android {
} }
} }
// ExoPlayer needs Java 8 to compile.
kotlinOptions { kotlinOptions {
jvmTarget = "1.8" jvmTarget = "1.8"
} }

View file

@ -41,9 +41,19 @@ private fun createViews(
return views return views
} }
private fun RemoteViews.applyMeta(state: WidgetState) { private fun RemoteViews.applyMeta(context: Context, state: WidgetState) {
setTextViewText(R.id.widget_song, state.song.name) 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.name)
if (state.albumArt != null) {
setImageViewBitmap(R.id.widget_cover, state.albumArt)
setContentDescription(
R.id.widget_cover, context.getString(R.string.desc_album_cover, state.song.album.name)
)
} else {
setImageViewResource(R.id.widget_cover, R.drawable.ic_song)
setContentDescription(R.id.widget_cover, context.getString(R.string.desc_no_cover))
}
} }
fun RemoteViews.applyControls(context: Context, state: WidgetState) { fun RemoteViews.applyControls(context: Context, state: WidgetState) {
@ -78,34 +88,20 @@ fun RemoteViews.applyControls(context: Context, state: WidgetState) {
) )
} }
fun RemoteViews.applyCover(context: Context, state: WidgetState) {
if (state.albumArt != null) {
setImageViewBitmap(R.id.widget_cover, state.albumArt)
setContentDescription(
R.id.widget_cover, context.getString(R.string.desc_album_cover, state.song.album.name)
)
} else {
setImageViewResource(R.id.widget_cover, R.drawable.ic_song)
setContentDescription(R.id.widget_cover, context.getString(R.string.desc_no_cover))
}
}
fun createDefaultWidget(context: Context): RemoteViews { fun createDefaultWidget(context: Context): RemoteViews {
return createViews(context, R.layout.widget_default) return createViews(context, R.layout.widget_default)
} }
fun createSmallWidget(context: Context, state: WidgetState): RemoteViews { fun createSmallWidget(context: Context, state: WidgetState): RemoteViews {
val views = createViews(context, R.layout.widget_small) val views = createViews(context, R.layout.widget_small)
views.applyMeta(state) views.applyMeta(context, state)
views.applyCover(context, state)
views.applyControls(context, state) views.applyControls(context, state)
return views return views
} }
fun createFullWidget(context: Context, state: WidgetState): RemoteViews { fun createFullWidget(context: Context, state: WidgetState): RemoteViews {
val views = createViews(context, R.layout.widget_full) val views = createViews(context, R.layout.widget_full)
views.applyMeta(state) views.applyMeta(context, state)
views.applyCover(context, state)
views.applyControls(context, state) views.applyControls(context, state)
views.setOnClickPendingIntent( views.setOnClickPendingIntent(

View file

@ -38,8 +38,6 @@ import org.oxycblt.auxio.playback.state.PlaybackStateManager
* Auxio's one and only appwidget. This widget follows a more unorthodox approach, effectively * Auxio's one and only appwidget. This widget follows a more unorthodox approach, effectively
* packing what could be considered 3 or 4 widgets into a single responsive widget. More specifically: * packing what could be considered 3 or 4 widgets into a single responsive widget. More specifically:
* *
* - For widgets 2x1 or lower, show a text-only view with no controls
* - For widgets Wx1 or lower, show a compact view with no controls.
* - For widgets Wx2 or higher, show an expanded view with album art and basic controls * - For widgets Wx2 or higher, show an expanded view with album art and basic controls
* - For widgets 4x2 or higher, show a complete view with all playback controls * - For widgets 4x2 or higher, show a complete view with all playback controls
* *

View file

@ -3,4 +3,6 @@
<style name="Widget.Component.AppWidget.Button" parent="Widget.Component.AppWidget.Button.Base"> <style name="Widget.Component.AppWidget.Button" parent="Widget.Component.AppWidget.Button.Base">
<item name="android:background">@drawable/ui_unbounded_ripple</item> <item name="android:background">@drawable/ui_unbounded_ripple</item>
</style> </style>
<style name="Widget.Component.AppWidget.Panel" parent="Widget.Component.AppWidget.Panel.Base" />
</resources> </resources>

View file

@ -64,11 +64,15 @@
<item name="android:background">?android:attr/selectableItemBackgroundBorderless</item> <item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>
</style> </style>
<style name="Widget.Component.AppWidget.Panel" parent=""> <style name="Widget.Component.AppWidget.Panel.Base" parent="">
<item name="android:layout_height">wrap_content</item> <item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">match_parent</item> <item name="android:layout_width">match_parent</item>
<item name="android:padding">@dimen/spacing_medium</item> <item name="android:padding">@dimen/spacing_medium</item>
<item name="android:orientation">vertical</item> <item name="android:orientation">vertical</item>
<item name="android:background">?attr/colorSurface</item> <item name="android:background">?attr/colorSurface</item>
</style> </style>
<style name="Widget.Component.AppWidget.Panel" parent="Widget.Component.AppWidget.Panel.Base">
<item name="android:elevation">@dimen/elevation_normal</item>
</style>
</resources> </resources>