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:
@@ -41,9 +41,19 @@ private fun createViews(
|
||||
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_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) {
|
||||
@@ -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 {
|
||||
return createViews(context, R.layout.widget_default)
|
||||
}
|
||||
|
||||
fun createSmallWidget(context: Context, state: WidgetState): RemoteViews {
|
||||
val views = createViews(context, R.layout.widget_small)
|
||||
views.applyMeta(state)
|
||||
views.applyCover(context, state)
|
||||
views.applyMeta(context, state)
|
||||
views.applyControls(context, state)
|
||||
return views
|
||||
}
|
||||
|
||||
fun createFullWidget(context: Context, state: WidgetState): RemoteViews {
|
||||
val views = createViews(context, R.layout.widget_full)
|
||||
views.applyMeta(state)
|
||||
views.applyCover(context, state)
|
||||
views.applyMeta(context, state)
|
||||
views.applyControls(context, state)
|
||||
|
||||
views.setOnClickPendingIntent(
|
||||
|
||||
@@ -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
|
||||
* 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 4x2 or higher, show a complete view with all playback controls
|
||||
*
|
||||
|
||||
@@ -3,4 +3,6 @@
|
||||
<style name="Widget.Component.AppWidget.Button" parent="Widget.Component.AppWidget.Button.Base">
|
||||
<item name="android:background">@drawable/ui_unbounded_ripple</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.Component.AppWidget.Panel" parent="Widget.Component.AppWidget.Panel.Base" />
|
||||
</resources>
|
||||
@@ -64,11 +64,15 @@
|
||||
<item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>
|
||||
</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_width">match_parent</item>
|
||||
<item name="android:padding">@dimen/spacing_medium</item>
|
||||
<item name="android:orientation">vertical</item>
|
||||
<item name="android:background">?attr/colorSurface</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.Component.AppWidget.Panel" parent="Widget.Component.AppWidget.Panel.Base">
|
||||
<item name="android:elevation">@dimen/elevation_normal</item>
|
||||
</style>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user