Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.
Kotlin alternativeandroidandroid-applicationclientglassmorphisminnertubelibrespotliquid-glassspotifyspotify-connectspotifyapiyoutube-musicyoutube-playerytdlnis
Add a home-screen widget in glass, from two by two to full size
Lelonioc927686cf2e5
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xmlindex ec7ad33..9814b56 100644--- a/app/src/main/AndroidManifest.xml+++ b/app/src/main/AndroidManifest.xml@@ -145,6 +145,32 @@</intent-filter></receiver>+ <!-- The two-by-two square, the same widget offered at that size. -->+ <receiver+ android:name=".widget.SquareWidget$Tile"+ android:exported="true"+ android:label="@string/app_name">+ <intent-filter>+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />+ </intent-filter>+ <meta-data+ android:name="android.appwidget.provider"+ android:resource="@xml/square_widget_tile_info" />+ </receiver>++ <!-- The home-screen widget; see widget/SquareWidget. -->+ <receiver+ android:name=".widget.SquareWidget"+ android:exported="true"+ android:label="@string/app_name">+ <intent-filter>+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />+ </intent-filter>+ <meta-data+ android:name="android.appwidget.provider"+ android:resource="@xml/square_widget_info" />+ </receiver>+<serviceandroid:name=".auth.LoginKeepAlive"android:exported="false"diff --git a/app/src/main/java/dev/lelonio/square/SquareApplication.kt b/app/src/main/java/dev/lelonio/square/SquareApplication.ktindex dd07d33..3f5eb96 100644--- a/app/src/main/java/dev/lelonio/square/SquareApplication.kt+++ b/app/src/main/java/dev/lelonio/square/SquareApplication.kt@@ -156,6 +156,11 @@ class SquareApplication : Application(), ImageLoaderFactory {/** Which playlists were opened most recently, for ordering the home page. */val playlistOrder: PlaylistOrderStore by lazy { PlaylistOrderStore(this) }+ /** The playlists the home-screen widget offers; see SquareWidget. */+ val widgetPlaylists: dev.lelonio.square.widget.WidgetPlaylists by lazy {+ dev.lelonio.square.widget.WidgetPlaylists(this)+ }+/** Tracks the listener has liked ("Tus me gusta"). */val likedStore: dev.lelonio.square.data.LikedStore by lazy {dev.lelonio.square.data.LikedStore(this)diff --git a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.ktindex 0e449fe..3cf5ba6 100644--- a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt+++ b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt@@ -286,6 +286,7 @@ class PlaybackService : MediaLibraryService() {player = buildPlayer(container.preferences.backend.value)startListeningRecorder()+ startWidgetUpdates()browseTree = MediaBrowseTree(this, scope, ::ensurePlayerFor, ::resumption)session = MediaLibrarySession.Builder(this, player, browseTree)// Without this the notification is inert to a tap: Media3 has no way@@ -1552,6 +1553,35 @@ class PlaybackService : MediaLibraryService() {)}+ /**+ * Keeps the home-screen widget on the song and the state playing.+ *+ * Read once a second rather than from listener events: the player is+ * swapped whole when the source changes, and the widget only redraws when+ * what it shows has actually changed; see SquareWidget.publish.+ */+ private fun startWidgetUpdates() {+ scope.launch {+ while (true) {+ val item = player.currentMediaItem+ val metadata = item?.mediaMetadata+ val title = metadata?.title?.toString()+ if (!title.isNullOrBlank()) {+ dev.lelonio.square.widget.SquareWidget.publish(+ this@PlaybackService,+ dev.lelonio.square.widget.SquareWidget.NowPlaying(+ title = title,+ artist = metadata.artist?.toString().orEmpty(),+ artworkUri = metadata.artworkUri?.toString(),+ playing = player.isPlaying,+ ),+ )+ }+ delay(1_000)+ }+ }+ }+/** Measures only playback on this device, independently of the activity. */private fun startListeningRecorder() {val sampler = dev.lelonio.square.data.ListeningSampler()@@ -1878,6 +1908,20 @@ class PlaybackService : MediaLibraryService() {override fun onDestroy() {// Before cancelling the scope: the last position is the one worth having.runCatching { savePlayback() }+ // Nothing plays once the service is gone, whatever the widget last heard.+ runCatching {+ player.currentMediaItem?.mediaMetadata?.let { metadata ->+ dev.lelonio.square.widget.SquareWidget.publish(+ this,+ dev.lelonio.square.widget.SquareWidget.NowPlaying(+ title = metadata.title?.toString().orEmpty(),+ artist = metadata.artist?.toString().orEmpty(),+ artworkUri = metadata.artworkUri?.toString(),+ playing = false,+ ),+ )+ }+ }scope.cancel()session?.run {player.release()diff --git a/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt b/app/src/main/java/dev/lelonio/square/ui/MainActivity.ktindex c36a375..1865102 100644--- a/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt+++ b/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt@@ -253,6 +253,19 @@ class MainActivity : ComponentActivity() {* than a new instance, so both ways in lead here.*/private fun takeLink(intent: android.content.Intent) {+ // A playlist tapped on the home-screen widget, with what is needed to+ // show it before it has loaded.+ if (intent.action == dev.lelonio.square.widget.SquareWidget.ACTION_OPEN_PLAYLIST) {+ val uri = intent.getStringExtra(dev.lelonio.square.widget.SquareWidget.EXTRA_URI) ?: return+ link = LinkRequest(+ uri = uri,+ n = (link?.n ?: 0) + 1,+ name = intent.getStringExtra(dev.lelonio.square.widget.SquareWidget.EXTRA_NAME).orEmpty(),+ artworkUrl = intent.getStringExtra(dev.lelonio.square.widget.SquareWidget.EXTRA_ARTWORK),+ fromWidget = true,+ )+ return+ }if (intent.action != android.content.Intent.ACTION_VIEW) returnval uri = dev.lelonio.square.data.SpotifyLink.parse(intent.data) ?: returnlink = LinkRequest(uri, (link?.n ?: 0) + 1)@@ -489,7 +502,14 @@ class MainActivity : ComponentActivity() {}/** A `spotify:` URI the app was opened with, and which opening it was. */-data class LinkRequest(val uri: String, val n: Int)+data class LinkRequest(+ val uri: String,+ val n: Int,+ val name: String = "",+ val artworkUrl: String? = null,+ /** A playlist of the current source, from the widget, rather than a Spotify link. */+ val fromWidget: Boolean = false,+)/** Key for the context URI carried in a media item's metadata extras. */const val EXTRA_CONTEXT_URI = "dev.lelonio.square.CONTEXT_URI"diff --git a/app/src/main/java/dev/lelonio/square/ui/MainViewModel.kt b/app/src/main/java/dev/lelonio/square/ui/MainViewModel.ktindex d11c42f..87f5951 100644--- a/app/src/main/java/dev/lelonio/square/ui/MainViewModel.kt+++ b/app/src/main/java/dev/lelonio/square/ui/MainViewModel.kt@@ -3786,6 +3786,8 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {// Reopening one counts as opening it, and that is exactly the playlist// the home page should keep at the front.container.playlistOrder.record(playlist.uri)+ container.widgetPlaylists.record(playlist.uri, playlist.name, playlist.artworkUrl, container.activeBackend.id)+ dev.lelonio.square.widget.SquareWidget.refresh(getApplication())if (playlist.uri == LocalLibrary.CONTEXT_URI) {openLocalFiles(playlist)@@ -5800,6 +5802,22 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {private val _savedAlbums = MutableStateFlow<List<CatalogPlaylist>>(emptyList())+ init {+ // The widget's playlists, from the library's own recency and the+ // library's names and covers; see WidgetPlaylists.fill.+ viewModelScope.launch {+ kotlinx.coroutines.flow.combine(_state, container.playlistOrder.order, _savedAlbums) { state, order, albums ->+ Triple(state, order, albums)+ }.collect { (state, order, albums) ->+ val ready = state as? UiState.Ready ?: return@collect+ val changed = kotlinx.coroutines.withContext(Dispatchers.IO) {+ container.widgetPlaylists.fill(order, ready.playlists + albums, container.activeBackend.id)+ }+ if (changed) dev.lelonio.square.widget.SquareWidget.refresh(getApplication())+ }+ }+ }+/*** The albums the account has saved, for the library's own shelf of them.*diff --git a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt b/app/src/main/java/dev/lelonio/square/ui/SquareApp.ktindex a651d0f..a4c2b1f 100644--- a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt+++ b/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt@@ -1376,7 +1376,14 @@ fun SquareApp(// whatever was on screen.LaunchedEffect(link) {val uri = link?.uri ?: return@LaunchedEffect- if (uri.startsWith("spotify:track:")) {+ if (link?.fromWidget == true) {+ viewModel.openPlaylist(+ dev.lelonio.square.data.CatalogPlaylist(uri = uri, name = link?.name.orEmpty(), artworkUrl = link?.artworkUrl),+ )+ if (navController.currentDestination?.route != Routes.PLAYLIST) {+ navController.navigate(Routes.PLAYLIST) { launchSingleTop = true }+ }+ } else if (uri.startsWith("spotify:track:")) {sharedTrack = viewModel.resolveTrack(uri)} else {viewModel.openLink(uri)diff --git a/app/src/main/java/dev/lelonio/square/widget/SquareWidget.kt b/app/src/main/java/dev/lelonio/square/widget/SquareWidget.ktnew file mode 100644index 0000000..c420e81--- /dev/null+++ b/app/src/main/java/dev/lelonio/square/widget/SquareWidget.kt@@ -0,0 +1,336 @@+package dev.lelonio.square.widget++import android.app.PendingIntent+import android.appwidget.AppWidgetManager+import android.appwidget.AppWidgetProvider+import android.content.ComponentName+import android.content.Context+import android.content.Intent+import android.graphics.Bitmap+import android.os.Build+import android.os.Bundle+import android.view.View+import android.widget.RemoteViews+import androidx.core.graphics.drawable.toBitmap+import androidx.media3.session.MediaController+import androidx.media3.session.SessionToken+import coil.imageLoader+import coil.request.ImageRequest+import coil.request.SuccessResult+import com.google.common.util.concurrent.MoreExecutors+import dev.lelonio.square.R+import dev.lelonio.square.SquareApplication+import dev.lelonio.square.playback.ACTION_OPEN_PLAYER+import dev.lelonio.square.playback.PlaybackService+import dev.lelonio.square.ui.MainActivity+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.Job+import kotlinx.coroutines.SupervisorJob+import kotlinx.coroutines.launch++/**+ * Square on the home screen: what is playing, its controls, the playlists last+ * opened, and the mark that opens the app.+ *+ * Drawn by the launcher from RemoteViews, so it is redrawn by being told:+ * [publish] from the playback service as the song or the state changes, and+ * [refresh] when the playlists change. What it shows is kept on disk, so a+ * widget added, resized or brought back after a restart draws the last song+ * without waiting for the music to start.+ */+open class SquareWidget : AppWidgetProvider() {++ /**+ * The same widget, listed again at two by two: the square the small+ * widgets of other phones are, which a launcher otherwise only reaches by+ * resizing the wide one down.+ */+ class Tile : SquareWidget()++ override fun onUpdate(context: Context, manager: AppWidgetManager, ids: IntArray) = refresh(context)++ override fun onAppWidgetOptionsChanged(context: Context, manager: AppWidgetManager, id: Int, options: Bundle) =+ refresh(context)++ override fun onReceive(context: Context, intent: Intent) {+ when (intent.action) {+ ACTION_PREVIOUS, ACTION_TOGGLE, ACTION_NEXT -> press(context, intent.action!!)+ else -> super.onReceive(context, intent)+ }+ }++ /**+ * A button pressed: handed to the player through a controller, as the app's+ * own screens do.+ *+ * Not as a media key sent to the service: started that way with nothing+ * loaded, the service has to come to the foreground with nothing to show,+ * and Android ends the app for it. Connecting starts the service as an+ * ordinary bound one, which may then put itself in the foreground once the+ * music actually plays.+ */+ private fun press(context: Context, action: String) {+ val pending = goAsync()+ val app = context.applicationContext+ val token = SessionToken(app, ComponentName(app, PlaybackService::class.java))+ val future = MediaController.Builder(app, token).buildAsync()+ future.addListener({+ val controller = runCatching { future.get() }.getOrNull()+ try {+ when (action) {+ ACTION_PREVIOUS -> controller?.seekToPrevious()+ ACTION_NEXT -> controller?.seekToNext()+ ACTION_TOGGLE -> controller?.let { if (it.isPlaying) it.pause() else it.play() }+ }+ } finally {+ controller?.release()+ pending.finish()+ }+ }, MoreExecutors.directExecutor())+ }++ /** What the widget shows of the song. */+ data class NowPlaying(+ val title: String,+ val artist: String,+ val artworkUri: String?,+ val playing: Boolean,+ )++ companion object {+ private const val ACTION_PREVIOUS = "dev.lelonio.square.widget.PREVIOUS"+ private const val ACTION_TOGGLE = "dev.lelonio.square.widget.TOGGLE"+ private const val ACTION_NEXT = "dev.lelonio.square.widget.NEXT"+ const val ACTION_OPEN_PLAYLIST = "dev.lelonio.square.widget.OPEN_PLAYLIST"+ const val EXTRA_URI = "dev.lelonio.square.widget.URI"+ const val EXTRA_NAME = "dev.lelonio.square.widget.NAME"+ const val EXTRA_ARTWORK = "dev.lelonio.square.widget.ARTWORK"++ private const val PREFS = "square_widget"+ private const val PLAYLIST_SLOTS = 4++ private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)+ private var drawing: Job? = null+ private var last: NowPlaying? = null++ /** A new song or state from the playback service; ignored when nothing changed. */+ fun publish(context: Context, now: NowPlaying) {+ if (now == last) return+ last = now+ context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()+ .putString("title", now.title)+ .putString("artist", now.artist)+ .putString("artwork", now.artworkUri)+ .putBoolean("playing", now.playing)+ .apply()+ refresh(context)+ }++ /** Draws every Square widget again from what is kept. */+ fun refresh(context: Context) {+ val app = context.applicationContext+ val manager = AppWidgetManager.getInstance(app)+ val ids = manager.getAppWidgetIds(ComponentName(app, SquareWidget::class.java)) ++ manager.getAppWidgetIds(ComponentName(app, Tile::class.java))+ if (ids.isEmpty()) return+ drawing?.cancel()+ drawing = scope.launch {+ val now = stored(app)+ val backend = (app as SquareApplication).preferences.backend.value+ val playlists = app.widgetPlaylists.recent(backend).take(PLAYLIST_SLOTS)+ val density = app.resources.displayMetrics.density+ val cover = now?.artworkUri?.let { load(app, it, 512) }+ val covers = playlists.map { entry -> entry.artworkUrl?.let { load(app, it, 192) } }+ ids.forEach { id ->+ val options = manager.getAppWidgetOptions(id)+ val views = build(app, options, now, cover, playlists, covers, density)+ runCatching { manager.updateAppWidget(id, views) }+ }+ }+ }++ private fun stored(context: Context): NowPlaying? {+ val prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)+ val title = prefs.getString("title", null)?.takeIf { it.isNotBlank() } ?: return null+ return NowPlaying(title, prefs.getString("artist", "").orEmpty(), prefs.getString("artwork", null), prefs.getBoolean("playing", false))+ }++ private suspend fun load(context: Context, data: String, size: Int): Bitmap? = runCatching {+ val result = context.imageLoader.execute(+ ImageRequest.Builder(context).data(data).size(size).allowHardware(false).build(),+ )+ (result as? SuccessResult)?.drawable?.toBitmap()+ }.getOrNull()++ /** The arrangements, by what fits; see [shapeFor]. */+ private enum class Shape(val layout: Int) {+ /** Wide and tall: song and controls on one line, playlists below. */+ LARGE(R.layout.widget_square),+ /** Wide, one row: the mark, the song, all three controls. */+ ROW(R.layout.widget_square_small),+ /** Narrow, one row: the song, play and next. */+ COMPACT(R.layout.widget_square_compact),+ /** Narrow and tall: the song above its controls, playlists if they fit. */+ COLUMN(R.layout.widget_square_column),+ /** Narrow and not so tall: the same, smaller, and no playlists. */+ COLUMN_TIGHT(R.layout.widget_square_column_tight),+ /** Two by two: the cover large, the song under it, the controls stacked beside. */+ TILE(R.layout.widget_square_tile),+ }++ /**+ * Chosen from the widget's own size, in the portrait it is mostly seen+ * in, and chosen again whenever it is resized (onAppWidgetOptionsChanged).+ *+ * Two fixed arrangements were not enough: between them a three-by-three+ * widget got the wide one, and the title was squeezed to an ellipsis+ * between the cover and the buttons. A title next to three buttons+ * needs [INLINE_WIDTH]; below that the buttons go under the song.+ */+ private fun shapeFor(widthDp: Int, heightDp: Int): Shape = when {+ // Too narrow for three buttons side by side, and tall enough to be+ // a square rather than a strip.+ widthDp < TILE_WIDTH && heightDp >= TILE_MIN_HEIGHT -> Shape.TILE+ heightDp < TALL_HEIGHT -> if (widthDp >= INLINE_WIDTH) Shape.ROW else Shape.COMPACT+ widthDp >= INLINE_WIDTH -> Shape.LARGE+ heightDp < COLUMN_HEIGHT -> Shape.COLUMN_TIGHT+ else -> Shape.COLUMN+ }++ private fun build(+ context: Context,+ options: Bundle,+ now: NowPlaying?,+ cover: Bitmap?,+ playlists: List<WidgetPlaylists.Entry>,+ covers: List<Bitmap?>,+ density: Float,+ ): RemoteViews {+ val width = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, 300).coerceAtLeast(60)+ val height = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, 180).coerceAtLeast(40)+ return views(context, shapeFor(width, height), now, cover, playlists, covers, width, height, density)+ }++ private fun views(+ context: Context,+ shape: Shape,+ now: NowPlaying?,+ cover: Bitmap?,+ playlists: List<WidgetPlaylists.Entry>,+ covers: List<Bitmap?>,+ widthDp: Int,+ heightDp: Int,+ density: Float,+ ): RemoteViews {+ val views = RemoteViews(context.packageName, shape.layout)+ // Drawn at a size the launcher can hold: widgets share a bitmap+ // budget, and the blur loses nothing to the scaling.+ val scale = minOf(density, MAX_PANEL_PX / maxOf(widthDp, heightDp).toFloat())+ val panel = WidgetGlass.panel(+ cover, (widthDp * scale).toInt(), (heightDp * scale).toInt(), CORNER_DP * scale, scale,+ )+ views.setImageViewBitmap(R.id.widget_glass, panel)++ views.setTextViewText(R.id.widget_title, now?.title ?: context.getString(R.string.widget_nothing_playing))+ views.setTextViewText(R.id.widget_artist, now?.artist.orEmpty())+ views.setViewVisibility(R.id.widget_artist, if (now?.artist.isNullOrBlank()) View.GONE else View.VISIBLE)+ if (cover != null) {+ views.setImageViewBitmap(R.id.widget_cover, WidgetGlass.rounded(cover, (64 * density).toInt(), 11 * density))+ } else {+ views.setImageViewResource(R.id.widget_cover, R.drawable.widget_cover_placeholder)+ }+ val playing = now?.playing == true+ views.setImageViewResource(R.id.widget_toggle, if (playing) R.drawable.ic_pip_pause else R.drawable.ic_pip_play)+ views.setContentDescription(R.id.widget_toggle, context.getString(if (playing) R.string.pause else R.string.play))++ views.setOnClickPendingIntent(R.id.widget_logo, openApp(context, player = false))+ views.setOnClickPendingIntent(R.id.widget_now, openApp(context, player = true))+ views.setOnClickPendingIntent(R.id.widget_toggle, control(context, ACTION_TOGGLE))+ views.setOnClickPendingIntent(R.id.widget_next, control(context, ACTION_NEXT))+ if (shape != Shape.COMPACT) {+ views.setOnClickPendingIntent(R.id.widget_previous, control(context, ACTION_PREVIOUS))+ } else {+ // The mark only where it leaves the title room to be read.+ views.setViewVisibility(R.id.widget_logo, if (widthDp >= COMPACT_LOGO_WIDTH) View.VISIBLE else View.GONE)+ }++ if (shape == Shape.LARGE || shape == Shape.COLUMN) {+ // As many as fit side by side at a readable size, and none+ // where the song and its controls have taken the height.+ val room = shape == Shape.LARGE || heightDp >= COLUMN_PLAYLISTS_HEIGHT+ val slots = ((widthDp - 28) / PLAYLIST_TILE_DP).coerceIn(2, PLAYLIST_SLOTS)+ val shown = if (room) playlists.take(slots) else emptyList()+ views.setViewVisibility(R.id.widget_playlists, if (shown.isEmpty()) View.GONE else View.VISIBLE)+ SLOTS.forEachIndexed { index, slot ->+ val entry = shown.getOrNull(index)+ if (entry == null) {+ views.setViewVisibility(slot, if (index < slots) View.INVISIBLE else View.GONE)+ return@forEachIndexed+ }+ views.setViewVisibility(slot, View.VISIBLE)+ val size = (64 * density).toInt()+ val art = covers.getOrNull(index)+ views.setImageViewBitmap(+ slot,+ if (art != null) WidgetGlass.rounded(art, size, 12 * density)+ else WidgetGlass.nameTile(entry.name, size, 12 * density, density),+ )+ views.setContentDescription(slot, entry.name)+ views.setOnClickPendingIntent(slot, openPlaylist(context, index, entry))+ }+ }+ return views+ }++ private fun openApp(context: Context, player: Boolean): PendingIntent {+ val intent = Intent(context, MainActivity::class.java)+ .setAction(if (player) ACTION_OPEN_PLAYER else Intent.ACTION_MAIN)+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)+ return PendingIntent.getActivity(+ context, if (player) 1 else 0, intent,+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,+ )+ }++ private fun openPlaylist(context: Context, index: Int, entry: WidgetPlaylists.Entry): PendingIntent {+ val intent = Intent(context, MainActivity::class.java)+ .setAction(ACTION_OPEN_PLAYLIST)+ .putExtra(EXTRA_URI, entry.uri)+ .putExtra(EXTRA_NAME, entry.name)+ .putExtra(EXTRA_ARTWORK, entry.artworkUrl)+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)+ return PendingIntent.getActivity(+ context, 10 + index, intent,+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,+ )+ }++ private fun control(context: Context, action: String): PendingIntent =+ PendingIntent.getBroadcast(+ context, action.hashCode(),+ Intent(context, SquareWidget::class.java).setAction(action),+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,+ )++ private val SLOTS = intArrayOf(R.id.widget_playlist_0, R.id.widget_playlist_1, R.id.widget_playlist_2, R.id.widget_playlist_3)++ /** Narrower than this, a widget tall enough for it is the square. */+ private const val TILE_WIDTH = 220+ private const val TILE_MIN_HEIGHT = 110++ /** Below this height the widget is one row. */+ private const val TALL_HEIGHT = 150+ /** What a title beside all three controls needs to be read. */+ private const val INLINE_WIDTH = 320+ /** A narrow column has room for the full-size song and controls from here. */+ private const val COLUMN_HEIGHT = 200+ /** A narrow column has room for playlists under its controls from here. */+ private const val COLUMN_PLAYLISTS_HEIGHT = 250+ private const val COMPACT_LOGO_WIDTH = 230+ /** A playlist tile and the gap after it. */+ private const val PLAYLIST_TILE_DP = 62+ private const val CORNER_DP = 26f+ private const val MAX_PANEL_PX = 600f+ }+}diff --git a/app/src/main/java/dev/lelonio/square/widget/WidgetGlass.kt b/app/src/main/java/dev/lelonio/square/widget/WidgetGlass.ktnew file mode 100644index 0000000..f7d43bb--- /dev/null+++ b/app/src/main/java/dev/lelonio/square/widget/WidgetGlass.kt@@ -0,0 +1,218 @@+package dev.lelonio.square.widget++import android.graphics.Bitmap+import android.graphics.Canvas+import android.graphics.Color+import android.graphics.LinearGradient+import android.graphics.Paint+import android.graphics.Path+import android.graphics.PorterDuff+import android.graphics.PorterDuffXfermode+import android.graphics.RectF+import android.graphics.Shader+import androidx.core.graphics.createBitmap+import androidx.core.graphics.scale++/**+ * The widget's glass, drawn as a picture.+ *+ * A widget is drawn by the launcher from a description, and nothing in that+ * description can blur or bend what lies behind it: the app's own glass cannot+ * be had on a home screen. What can is the look of it over the record playing:+ * the cover, blurred and dimmed, under a sheen and a rim of light, which is+ * what the player's glass looks like when it sits on the artwork.+ */+internal object WidgetGlass {+ /** The panel, [width] by [height] pixels, with [radius] corners. */+ fun panel(cover: Bitmap?, width: Int, height: Int, radius: Float, density: Float): Bitmap {+ val out = createBitmap(width, height)+ val canvas = Canvas(out)+ val bounds = RectF(0f, 0f, width.toFloat(), height.toFloat())+ val shape = Path().apply { addRoundRect(bounds, radius, radius, Path.Direction.CW) }+ canvas.clipPath(shape)++ if (cover != null) {+ canvas.drawBitmap(blurred(cover, width, height), 0f, 0f, Paint(Paint.FILTER_BITMAP_FLAG))+ canvas.drawColor(Color.argb(105, 0, 0, 0))+ } else {+ canvas.drawPaint(Paint().apply {+ shader = LinearGradient(0f, 0f, width.toFloat(), height.toFloat(),+ Color.rgb(0x34, 0x34, 0x3A), Color.rgb(0x16, 0x16, 0x1A), Shader.TileMode.CLAMP)+ })+ }++ // The sheen across the top, where light would catch the glass.+ canvas.drawRect(bounds, Paint().apply {+ shader = LinearGradient(0f, 0f, 0f, height * 0.55f,+ Color.argb(46, 255, 255, 255), Color.argb(0, 255, 255, 255), Shader.TileMode.CLAMP)+ })++ // The rim: bright at the top left, fading round to the bottom right.+ val stroke = 1.4f * density+ val inset = stroke / 2+ canvas.drawRoundRect(+ RectF(inset, inset, width - inset, height - inset), radius - inset, radius - inset,+ Paint(Paint.ANTI_ALIAS_FLAG).apply {+ style = Paint.Style.STROKE+ strokeWidth = stroke+ shader = LinearGradient(0f, 0f, width.toFloat(), height.toFloat(),+ Color.argb(120, 255, 255, 255), Color.argb(18, 255, 255, 255), Shader.TileMode.CLAMP)+ },+ )+ return out+ }++ /** A cover with rounded corners, for the views that cannot clip. */+ fun rounded(source: Bitmap, size: Int, radius: Float): Bitmap {+ val out = createBitmap(size, size)+ val canvas = Canvas(out)+ val paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)+ canvas.drawRoundRect(RectF(0f, 0f, size.toFloat(), size.toFloat()), radius, radius, paint)+ paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)+ canvas.drawBitmap(centreCrop(source, size, size), 0f, 0f, paint)+ return out+ }++ /**+ * A playlist with no cover of its own: a pane of the same glass with its+ * name on it, rather than an empty square nobody could tell apart.+ */+ fun nameTile(name: String, size: Int, radius: Float, density: Float): Bitmap {+ val out = createBitmap(size, size)+ val canvas = Canvas(out)+ val bounds = RectF(0f, 0f, size.toFloat(), size.toFloat())+ canvas.drawRoundRect(bounds, radius, radius, Paint(Paint.ANTI_ALIAS_FLAG).apply {+ shader = LinearGradient(0f, 0f, size.toFloat(), size.toFloat(),+ Color.argb(70, 255, 255, 255), Color.argb(30, 255, 255, 255), Shader.TileMode.CLAMP)+ })+ val text = android.text.TextPaint(Paint.ANTI_ALIAS_FLAG).apply {+ color = Color.WHITE+ textSize = 11f * density+ typeface = android.graphics.Typeface.DEFAULT_BOLD+ }+ val pad = (6 * density).toInt()+ val layout = android.text.StaticLayout.Builder.obtain(name, 0, name.length, text, size - pad * 2)+ .setAlignment(android.text.Layout.Alignment.ALIGN_CENTER)+ .setMaxLines(3)+ .setEllipsize(android.text.TextUtils.TruncateAt.END)+ .build()+ canvas.save()+ canvas.translate(pad.toFloat(), (size - layout.height) / 2f)+ layout.draw(canvas)+ canvas.restore()+ return out+ }++ /**+ * A real blur, on a small copy, grown back smoothly.+ *+ * Shrinking and growing alone was tried first, and from that few pixels+ * the growing shows them: the glass came out in blocks and steps. Here the+ * small copy is blurred properly first (a stack blur, which is a close and+ * quick stand-in for a Gaussian), so what is grown back has no edges left+ * to show.+ */+ private fun blurred(source: Bitmap, width: Int, height: Int): Bitmap {+ val small = (BLUR_WIDTH.toFloat() / width).coerceAtMost(1f)+ val w = (width * small).toInt().coerceAtLeast(8)+ val h = (height * small).toInt().coerceAtLeast(8)+ val copy = centreCrop(source, w, h).copy(Bitmap.Config.ARGB_8888, true)+ stackBlur(copy, BLUR_RADIUS)+ return copy.scale(width, height, filter = true)+ }++ /** Mario Klingemann's stack blur, in place, on the colour channels. */+ private fun stackBlur(bitmap: Bitmap, radius: Int) {+ val w = bitmap.width+ val h = bitmap.height+ val pixels = IntArray(w * h)+ bitmap.getPixels(pixels, 0, w, 0, 0, w, h)+ val div = radius * 2 + 1+ val r = IntArray(w * h)+ val g = IntArray(w * h)+ val b = IntArray(w * h)+ val dv = IntArray(256 * ((div + 1) / 2) * ((div + 1) / 2)) { it / (((div + 1) / 2) * ((div + 1) / 2)) }+ val stack = Array(div) { IntArray(3) }+ val r1 = radius + 1+ val vmin = IntArray(maxOf(w, h))++ var yi = 0+ var yw = 0+ for (y in 0 until h) {+ var rin = 0; var gin = 0; var bin = 0; var rout = 0; var gout = 0; var bout = 0+ var rsum = 0; var gsum = 0; var bsum = 0+ for (i in -radius..radius) {+ val p = pixels[yi + minOf(w - 1, maxOf(i, 0))]+ val sir = stack[i + radius]+ sir[0] = p shr 16 and 0xff; sir[1] = p shr 8 and 0xff; sir[2] = p and 0xff+ val rbs = r1 - kotlin.math.abs(i)+ rsum += sir[0] * rbs; gsum += sir[1] * rbs; bsum += sir[2] * rbs+ if (i > 0) { rin += sir[0]; gin += sir[1]; bin += sir[2] } else { rout += sir[0]; gout += sir[1]; bout += sir[2] }+ }+ var stackpointer = radius+ for (x in 0 until w) {+ r[yi] = dv[rsum]; g[yi] = dv[gsum]; b[yi] = dv[bsum]+ rsum -= rout; gsum -= gout; bsum -= bout+ var sir = stack[(stackpointer - radius + div) % div]+ rout -= sir[0]; gout -= sir[1]; bout -= sir[2]+ if (y == 0) vmin[x] = minOf(x + radius + 1, w - 1)+ val p = pixels[yw + vmin[x]]+ sir[0] = p shr 16 and 0xff; sir[1] = p shr 8 and 0xff; sir[2] = p and 0xff+ rin += sir[0]; gin += sir[1]; bin += sir[2]+ rsum += rin; gsum += gin; bsum += bin+ stackpointer = (stackpointer + 1) % div+ sir = stack[stackpointer % div]+ rout += sir[0]; gout += sir[1]; bout += sir[2]+ rin -= sir[0]; gin -= sir[1]; bin -= sir[2]+ yi+++ }+ yw += w+ }+ for (x in 0 until w) {+ var rin = 0; var gin = 0; var bin = 0; var rout = 0; var gout = 0; var bout = 0+ var rsum = 0; var gsum = 0; var bsum = 0+ var yp = -radius * w+ for (i in -radius..radius) {+ yi = maxOf(0, yp) + x+ val sir = stack[i + radius]+ sir[0] = r[yi]; sir[1] = g[yi]; sir[2] = b[yi]+ val rbs = r1 - kotlin.math.abs(i)+ rsum += r[yi] * rbs; gsum += g[yi] * rbs; bsum += b[yi] * rbs+ if (i > 0) { rin += sir[0]; gin += sir[1]; bin += sir[2] } else { rout += sir[0]; gout += sir[1]; bout += sir[2] }+ if (i < h - 1) yp += w+ }+ yi = x+ var stackpointer = radius+ for (y in 0 until h) {+ pixels[yi] = (0xff000000).toInt() or (dv[rsum] shl 16) or (dv[gsum] shl 8) or dv[bsum]+ rsum -= rout; gsum -= gout; bsum -= bout+ var sir = stack[(stackpointer - radius + div) % div]+ rout -= sir[0]; gout -= sir[1]; bout -= sir[2]+ if (x == 0) vmin[y] = minOf(y + r1, h - 1) * w+ val p = x + vmin[y]+ sir[0] = r[p]; sir[1] = g[p]; sir[2] = b[p]+ rin += sir[0]; gin += sir[1]; bin += sir[2]+ rsum += rin; gsum += gin; bsum += bin+ stackpointer = (stackpointer + 1) % div+ sir = stack[stackpointer]+ rout += sir[0]; gout += sir[1]; bout += sir[2]+ rin -= sir[0]; gin -= sir[1]; bin -= sir[2]+ yi += w+ }+ }+ bitmap.setPixels(pixels, 0, w, 0, 0, w, h)+ }++ /** How wide the copy that is blurred is, and how far it is blurred. */+ private const val BLUR_WIDTH = 160+ private const val BLUR_RADIUS = 14++ private fun centreCrop(source: Bitmap, width: Int, height: Int): Bitmap {+ val scale = maxOf(width.toFloat() / source.width, height.toFloat() / source.height)+ val w = (width / scale).toInt().coerceIn(1, source.width)+ val h = (height / scale).toInt().coerceIn(1, source.height)+ val x = (source.width - w) / 2+ val y = (source.height - h) / 2+ return Bitmap.createBitmap(source, x, y, w, h).scale(width, height, filter = true)+ }+}diff --git a/app/src/main/java/dev/lelonio/square/widget/WidgetPlaylists.kt b/app/src/main/java/dev/lelonio/square/widget/WidgetPlaylists.ktnew file mode 100644index 0000000..7d4a8aa--- /dev/null+++ b/app/src/main/java/dev/lelonio/square/widget/WidgetPlaylists.kt@@ -0,0 +1,70 @@+package dev.lelonio.square.widget++import android.content.Context+import dev.lelonio.square.backend.BackendId+import kotlinx.serialization.Serializable+import kotlinx.serialization.builtins.ListSerializer+import kotlinx.serialization.json.Json++/**+ * The playlists last opened, with what the widget needs to draw them.+ *+ * The library's own recency list keeps addresses only, and the widget is drawn+ * by the launcher with the app possibly not running: the name and the cover+ * have to be on disk already. Kept per source, so the widget never offers a+ * YouTube Music playlist to a Spotify session or the other way round.+ */+class WidgetPlaylists(context: Context) {+ @Serializable+ data class Entry(val uri: String, val name: String, val artworkUrl: String?, val backend: String)++ private val prefs = context.applicationContext.getSharedPreferences("square_widget_playlists", Context.MODE_PRIVATE)+ private val json = Json { ignoreUnknownKeys = true }+ private val serializer = ListSerializer(Entry.serializer())++ fun record(uri: String, name: String, artworkUrl: String?, backend: BackendId) {+ // A page opened by address alone has no name yet; it is not one to show.+ if (name.isBlank()) return+ val entry = Entry(uri, name, artworkUrl, backend.name)+ save(backend, listOf(entry) + recent(backend).filterNot { it.uri == uri })+ }++ /**+ * Fills in from what the app already knew before the widget existed: the+ * library's own order of recently opened, with names and covers from the+ * library. Without it the widget started empty and only learned a playlist+ * when one was opened again. True when anything changed.+ */+ fun fill(order: List<String>, known: List<dev.lelonio.square.data.CatalogPlaylist>, backend: BackendId): Boolean {+ val byUri = known.associateBy { it.uri }+ val mine = recent(backend)+ val stored = mine.associateBy { it.uri }+ val fromOrder = order.mapNotNull { uri ->+ byUri[uri]?.takeIf { it.name.isNotBlank() }+ ?.let { Entry(uri, it.name, it.artworkUrl ?: stored[uri]?.artworkUrl, backend.name) }+ ?: stored[uri]+ }+ val updated = (fromOrder + mine.filter { it.uri !in order }).take(LIMIT)+ if (updated == mine) return false+ save(backend, updated)+ return true+ }++ fun recent(backend: BackendId): List<Entry> = all().filter { it.backend == backend.name }++ fun clear() = prefs.edit().remove(KEY).apply()++ /** This source's entries replaced, the other source's kept. */+ private fun save(backend: BackendId, entries: List<Entry>) {+ val updated = all().filter { it.backend != backend.name } + entries.take(LIMIT)+ prefs.edit().putString(KEY, json.encodeToString(serializer, updated)).apply()+ }++ private fun all(): List<Entry> =+ runCatching { json.decodeFromString(serializer, prefs.getString(KEY, null) ?: "[]") }.getOrDefault(emptyList())++ private companion object {+ const val KEY = "entries"+ const val LIMIT = 12+ }+}diff --git a/app/src/main/res/drawable/ic_widget_next.xml b/app/src/main/res/drawable/ic_widget_next.xmlnew file mode 100644index 0000000..a8c71fe--- /dev/null+++ b/app/src/main/res/drawable/ic_widget_next.xml@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?><!-- Phosphor's skip-forward, filled, for the widget. -->+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp" android:height="24dp"+ android:viewportWidth="256" android:viewportHeight="256">+ <path android:fillColor="#FFFFFFFF"+ android:pathData="M208,40V216a8,8,0,0,1-16,0V146.77L72.43,221.55A15.95,15.95,0,0,1,48,208.12V47.88A15.95,15.95,0,0,1,72.43,34.45L192,109.23V40a8,8,0,0,1,16,0Z" />+</vector>diff --git a/app/src/main/res/drawable/ic_widget_previous.xml b/app/src/main/res/drawable/ic_widget_previous.xmlnew file mode 100644index 0000000..1cc5e41--- /dev/null+++ b/app/src/main/res/drawable/ic_widget_previous.xml@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?><!-- Phosphor's skip-back, filled, for the widget. -->+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp" android:height="24dp"+ android:viewportWidth="256" android:viewportHeight="256">+ <path android:fillColor="#FFFFFFFF"+ android:pathData="M208,47.88V208.12a16,16,0,0,1-24.43,13.43L64,146.77V216a8,8,0,0,1-16,0V40a8,8,0,0,1,16,0v69.23L183.57,34.45A15.95,15.95,0,0,1,208,47.88Z" />+</vector>diff --git a/app/src/main/res/drawable/widget_button.xml b/app/src/main/res/drawable/widget_button.xmlnew file mode 100644index 0000000..7b886d4--- /dev/null+++ b/app/src/main/res/drawable/widget_button.xml@@ -0,0 +1,6 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- A small disc of glass for the widget's secondary controls. -->+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">+ <solid android:color="#29FFFFFF" />+ <stroke android:width="1dp" android:color="#38FFFFFF" />+</shape>diff --git a/app/src/main/res/drawable/widget_button_primary.xml b/app/src/main/res/drawable/widget_button_primary.xmlnew file mode 100644index 0000000..170356f--- /dev/null+++ b/app/src/main/res/drawable/widget_button_primary.xml@@ -0,0 +1,5 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- Play and pause, lit like the player's own button. -->+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">+ <solid android:color="#EBFFFFFF" />+</shape>diff --git a/app/src/main/res/drawable/widget_cover_placeholder.xml b/app/src/main/res/drawable/widget_cover_placeholder.xmlnew file mode 100644index 0000000..2a06c1f--- /dev/null+++ b/app/src/main/res/drawable/widget_cover_placeholder.xml@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- Where a cover goes before there is one: a pane of the same glass. -->+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">+ <solid android:color="#26FFFFFF" />+ <corners android:radius="10dp" />+ <size android:width="56dp" android:height="56dp" />+</shape>diff --git a/app/src/main/res/layout/widget_header.xml b/app/src/main/res/layout/widget_header.xmlnew file mode 100644index 0000000..f34c32c--- /dev/null+++ b/app/src/main/res/layout/widget_header.xml@@ -0,0 +1,29 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- The mark and the name, which open the app. -->+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:id="@+id/widget_logo"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:contentDescription="@string/widget_open_app"+ android:gravity="center_vertical"+ android:orientation="horizontal"+ android:paddingTop="2dp"+ android:paddingEnd="8dp"+ android:paddingBottom="2dp">++ <ImageView+ android:layout_width="20dp"+ android:layout_height="20dp"+ android:importantForAccessibility="no"+ android:src="@drawable/ic_app_mark" />++ <TextView+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_marginStart="7dp"+ android:importantForAccessibility="no"+ android:text="@string/app_name"+ android:textColor="#FFFFFFFF"+ android:textSize="14sp"+ android:textStyle="bold" />+</LinearLayout>diff --git a/app/src/main/res/layout/widget_now_playing.xml b/app/src/main/res/layout/widget_now_playing.xmlnew file mode 100644index 0000000..7445599--- /dev/null+++ b/app/src/main/res/layout/widget_now_playing.xml@@ -0,0 +1,82 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- The song and its controls, shared by both sizes of the widget. -->+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:layout_marginTop="8dp"+ android:gravity="center_vertical"+ android:orientation="horizontal">++ <LinearLayout+ android:id="@+id/widget_now"+ android:layout_width="0dp"+ android:layout_height="wrap_content"+ android:layout_weight="1"+ android:gravity="center_vertical"+ android:orientation="horizontal">++ <ImageView+ android:id="@+id/widget_cover"+ android:layout_width="52dp"+ android:layout_height="52dp"+ android:importantForAccessibility="no"+ android:scaleType="centerCrop" />++ <LinearLayout+ android:layout_width="0dp"+ android:layout_height="wrap_content"+ android:layout_marginStart="12dp"+ android:layout_weight="1"+ android:orientation="vertical">++ <TextView+ android:id="@+id/widget_title"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:ellipsize="end"+ android:maxLines="1"+ android:textColor="#FFFFFFFF"+ android:textSize="15sp"+ android:textStyle="bold" />++ <TextView+ android:id="@+id/widget_artist"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:ellipsize="end"+ android:maxLines="1"+ android:textColor="#B3FFFFFF"+ android:textSize="13sp" />+ </LinearLayout>+ </LinearLayout>++ <ImageView+ android:id="@+id/widget_previous"+ android:layout_width="40dp"+ android:layout_height="40dp"+ android:layout_marginStart="4dp"+ android:background="@drawable/widget_button"+ android:contentDescription="@string/previous"+ android:padding="11dp"+ android:src="@drawable/ic_widget_previous" />++ <ImageView+ android:id="@+id/widget_toggle"+ android:layout_width="46dp"+ android:layout_height="46dp"+ android:layout_marginStart="6dp"+ android:background="@drawable/widget_button_primary"+ android:padding="13dp"+ android:src="@drawable/ic_pip_play"+ android:tint="#FF111114" />++ <ImageView+ android:id="@+id/widget_next"+ android:layout_width="40dp"+ android:layout_height="40dp"+ android:layout_marginStart="6dp"+ android:background="@drawable/widget_button"+ android:contentDescription="@string/next"+ android:padding="11dp"+ android:src="@drawable/ic_widget_next" />+</LinearLayout>diff --git a/app/src/main/res/layout/widget_now_stacked.xml b/app/src/main/res/layout/widget_now_stacked.xmlnew file mode 100644index 0000000..5049808--- /dev/null+++ b/app/src/main/res/layout/widget_now_stacked.xml@@ -0,0 +1,90 @@+<?xml version="1.0" encoding="utf-8"?>+<!--+ The song above its controls, for a widget too narrow to have both on one+ line: there the title was squeezed down to an ellipsis.+-->+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:orientation="vertical">++ <LinearLayout+ android:id="@+id/widget_now"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:layout_marginTop="8dp"+ android:gravity="center_vertical"+ android:orientation="horizontal">++ <ImageView+ android:id="@+id/widget_cover"+ android:layout_width="48dp"+ android:layout_height="48dp"+ android:importantForAccessibility="no"+ android:scaleType="centerCrop" />++ <LinearLayout+ android:layout_width="0dp"+ android:layout_height="wrap_content"+ android:layout_marginStart="10dp"+ android:layout_weight="1"+ android:orientation="vertical">++ <TextView+ android:id="@+id/widget_title"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:ellipsize="end"+ android:maxLines="2"+ android:textColor="#FFFFFFFF"+ android:textSize="15sp"+ android:textStyle="bold" />++ <TextView+ android:id="@+id/widget_artist"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:ellipsize="end"+ android:maxLines="1"+ android:textColor="#B3FFFFFF"+ android:textSize="13sp" />+ </LinearLayout>+ </LinearLayout>++ <LinearLayout+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:layout_marginTop="10dp"+ android:gravity="center"+ android:orientation="horizontal">++ <ImageView+ android:id="@+id/widget_previous"+ android:layout_width="42dp"+ android:layout_height="42dp"+ android:background="@drawable/widget_button"+ android:contentDescription="@string/previous"+ android:padding="12dp"+ android:src="@drawable/ic_widget_previous" />++ <ImageView+ android:id="@+id/widget_toggle"+ android:layout_width="50dp"+ android:layout_height="50dp"+ android:layout_marginStart="14dp"+ android:layout_marginEnd="14dp"+ android:background="@drawable/widget_button_primary"+ android:padding="14dp"+ android:src="@drawable/ic_pip_play"+ android:tint="#FF111114" />++ <ImageView+ android:id="@+id/widget_next"+ android:layout_width="42dp"+ android:layout_height="42dp"+ android:background="@drawable/widget_button"+ android:contentDescription="@string/next"+ android:padding="12dp"+ android:src="@drawable/ic_widget_next" />+ </LinearLayout>+</LinearLayout>diff --git a/app/src/main/res/layout/widget_now_stacked_tight.xml b/app/src/main/res/layout/widget_now_stacked_tight.xmlnew file mode 100644index 0000000..c6a0d9e--- /dev/null+++ b/app/src/main/res/layout/widget_now_stacked_tight.xml@@ -0,0 +1,91 @@+<?xml version="1.0" encoding="utf-8"?>+<!--+ The song above its controls, made to fit a narrow widget that is not tall+ either: one line of title, a smaller cover and lower buttons, which at the+ full sizes ran out of the bottom of the widget.+-->+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:orientation="vertical">++ <LinearLayout+ android:id="@+id/widget_now"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:layout_marginTop="6dp"+ android:gravity="center_vertical"+ android:orientation="horizontal">++ <ImageView+ android:id="@+id/widget_cover"+ android:layout_width="42dp"+ android:layout_height="42dp"+ android:importantForAccessibility="no"+ android:scaleType="centerCrop" />++ <LinearLayout+ android:layout_width="0dp"+ android:layout_height="wrap_content"+ android:layout_marginStart="10dp"+ android:layout_weight="1"+ android:orientation="vertical">++ <TextView+ android:id="@+id/widget_title"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:ellipsize="end"+ android:maxLines="1"+ android:textColor="#FFFFFFFF"+ android:textSize="15sp"+ android:textStyle="bold" />++ <TextView+ android:id="@+id/widget_artist"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:ellipsize="end"+ android:maxLines="1"+ android:textColor="#B3FFFFFF"+ android:textSize="13sp" />+ </LinearLayout>+ </LinearLayout>++ <LinearLayout+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:layout_marginTop="6dp"+ android:gravity="center"+ android:orientation="horizontal">++ <ImageView+ android:id="@+id/widget_previous"+ android:layout_width="36dp"+ android:layout_height="36dp"+ android:background="@drawable/widget_button"+ android:contentDescription="@string/previous"+ android:padding="10dp"+ android:src="@drawable/ic_widget_previous" />++ <ImageView+ android:id="@+id/widget_toggle"+ android:layout_width="42dp"+ android:layout_height="42dp"+ android:layout_marginStart="12dp"+ android:layout_marginEnd="12dp"+ android:background="@drawable/widget_button_primary"+ android:padding="12dp"+ android:src="@drawable/ic_pip_play"+ android:tint="#FF111114" />++ <ImageView+ android:id="@+id/widget_next"+ android:layout_width="36dp"+ android:layout_height="36dp"+ android:background="@drawable/widget_button"+ android:contentDescription="@string/next"+ android:padding="10dp"+ android:src="@drawable/ic_widget_next" />+ </LinearLayout>+</LinearLayout>diff --git a/app/src/main/res/layout/widget_playlist_row.xml b/app/src/main/res/layout/widget_playlist_row.xmlnew file mode 100644index 0000000..08bd2c3--- /dev/null+++ b/app/src/main/res/layout/widget_playlist_row.xml@@ -0,0 +1,27 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- The playlists last opened, in whatever room is left at the bottom. -->+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:id="@+id/widget_playlists"+ android:layout_width="match_parent"+ android:layout_height="0dp"+ android:layout_marginTop="12dp"+ android:layout_weight="1"+ android:gravity="bottom"+ android:orientation="horizontal">++ <ImageView+ android:id="@+id/widget_playlist_0"+ style="@style/WidgetPlaylist" />++ <ImageView+ android:id="@+id/widget_playlist_1"+ style="@style/WidgetPlaylist" />++ <ImageView+ android:id="@+id/widget_playlist_2"+ style="@style/WidgetPlaylist" />++ <ImageView+ android:id="@+id/widget_playlist_3"+ style="@style/WidgetPlaylist" />+</LinearLayout>diff --git a/app/src/main/res/layout/widget_square.xml b/app/src/main/res/layout/widget_square.xmlnew file mode 100644index 0000000..597e853--- /dev/null+++ b/app/src/main/res/layout/widget_square.xml@@ -0,0 +1,35 @@+<?xml version="1.0" encoding="utf-8"?>+<!--+ The widget at its full size: the mark, the song with its controls, and the+ playlists last opened. The glass under it all is a picture the app draws;+ see WidgetGlass.+-->+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:id="@android:id/background"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:clipToOutline="true">++ <ImageView+ android:id="@+id/widget_glass"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:importantForAccessibility="no"+ android:scaleType="fitXY" />++ <LinearLayout+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:orientation="vertical"+ android:paddingStart="16dp"+ android:paddingTop="12dp"+ android:paddingEnd="12dp"+ android:paddingBottom="14dp">++ <include layout="@layout/widget_header" />++ <include layout="@layout/widget_now_playing" />++ <include layout="@layout/widget_playlist_row" />+ </LinearLayout>+</FrameLayout>diff --git a/app/src/main/res/layout/widget_square_column.xml b/app/src/main/res/layout/widget_square_column.xmlnew file mode 100644index 0000000..e2c9d8b--- /dev/null+++ b/app/src/main/res/layout/widget_square_column.xml@@ -0,0 +1,34 @@+<?xml version="1.0" encoding="utf-8"?>+<!--+ A narrow, tall widget: the mark, the song above its controls, and, when there+ is room below, the playlists last opened.+-->+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:id="@android:id/background"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:clipToOutline="true">++ <ImageView+ android:id="@+id/widget_glass"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:importantForAccessibility="no"+ android:scaleType="fitXY" />++ <LinearLayout+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:orientation="vertical"+ android:paddingStart="14dp"+ android:paddingTop="12dp"+ android:paddingEnd="14dp"+ android:paddingBottom="14dp">++ <include layout="@layout/widget_header" />++ <include layout="@layout/widget_now_stacked" />++ <include layout="@layout/widget_playlist_row" />+ </LinearLayout>+</FrameLayout>diff --git a/app/src/main/res/layout/widget_square_column_tight.xml b/app/src/main/res/layout/widget_square_column_tight.xmlnew file mode 100644index 0000000..8ebf902--- /dev/null+++ b/app/src/main/res/layout/widget_square_column_tight.xml@@ -0,0 +1,29 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- A narrow widget of middling height: the mark, then the song above its controls, all made smaller. -->+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:id="@android:id/background"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:clipToOutline="true">++ <ImageView+ android:id="@+id/widget_glass"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:importantForAccessibility="no"+ android:scaleType="fitXY" />++ <LinearLayout+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:orientation="vertical"+ android:paddingStart="14dp"+ android:paddingTop="10dp"+ android:paddingEnd="14dp"+ android:paddingBottom="10dp">++ <include layout="@layout/widget_header" />++ <include layout="@layout/widget_now_stacked_tight" />+ </LinearLayout>+</FrameLayout>diff --git a/app/src/main/res/layout/widget_square_compact.xml b/app/src/main/res/layout/widget_square_compact.xmlnew file mode 100644index 0000000..46567eb--- /dev/null+++ b/app/src/main/res/layout/widget_square_compact.xml@@ -0,0 +1,98 @@+<?xml version="1.0" encoding="utf-8"?>+<!--+ A narrow widget one row high: the song and the two controls that matter+ most. The mark is there when the row is wide enough to keep the title.+-->+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:id="@android:id/background"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:clipToOutline="true">++ <ImageView+ android:id="@+id/widget_glass"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:importantForAccessibility="no"+ android:scaleType="fitXY" />++ <LinearLayout+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:gravity="center_vertical"+ android:orientation="horizontal"+ android:paddingStart="10dp"+ android:paddingEnd="8dp">++ <ImageView+ android:id="@+id/widget_logo"+ android:layout_width="32dp"+ android:layout_height="32dp"+ android:contentDescription="@string/widget_open_app"+ android:padding="7dp"+ android:src="@drawable/ic_app_mark" />++ <LinearLayout+ android:id="@+id/widget_now"+ android:layout_width="0dp"+ android:layout_height="wrap_content"+ android:layout_weight="1"+ android:gravity="center_vertical"+ android:orientation="horizontal">++ <ImageView+ android:id="@+id/widget_cover"+ android:layout_width="44dp"+ android:layout_height="44dp"+ android:importantForAccessibility="no"+ android:scaleType="centerCrop" />++ <LinearLayout+ android:layout_width="0dp"+ android:layout_height="wrap_content"+ android:layout_marginStart="10dp"+ android:layout_weight="1"+ android:orientation="vertical">++ <TextView+ android:id="@+id/widget_title"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:ellipsize="end"+ android:maxLines="1"+ android:textColor="#FFFFFFFF"+ android:textSize="14sp"+ android:textStyle="bold" />++ <TextView+ android:id="@+id/widget_artist"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:ellipsize="end"+ android:maxLines="1"+ android:textColor="#B3FFFFFF"+ android:textSize="12sp" />+ </LinearLayout>+ </LinearLayout>++ <ImageView+ android:id="@+id/widget_toggle"+ android:layout_width="42dp"+ android:layout_height="42dp"+ android:layout_marginStart="6dp"+ android:background="@drawable/widget_button_primary"+ android:padding="12dp"+ android:src="@drawable/ic_pip_play"+ android:tint="#FF111114" />++ <ImageView+ android:id="@+id/widget_next"+ android:layout_width="38dp"+ android:layout_height="38dp"+ android:layout_marginStart="6dp"+ android:background="@drawable/widget_button"+ android:contentDescription="@string/next"+ android:padding="11dp"+ android:src="@drawable/ic_widget_next" />+ </LinearLayout>+</FrameLayout>diff --git a/app/src/main/res/layout/widget_square_small.xml b/app/src/main/res/layout/widget_square_small.xmlnew file mode 100644index 0000000..cb812cc--- /dev/null+++ b/app/src/main/res/layout/widget_square_small.xml@@ -0,0 +1,40 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- The widget one row high: the mark, the song and its controls. -->+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:id="@android:id/background"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:clipToOutline="true">++ <ImageView+ android:id="@+id/widget_glass"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:importantForAccessibility="no"+ android:scaleType="fitXY" />++ <LinearLayout+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:gravity="center_vertical"+ android:orientation="horizontal"+ android:paddingStart="12dp"+ android:paddingEnd="10dp">++ <ImageView+ android:id="@+id/widget_logo"+ android:layout_width="36dp"+ android:layout_height="36dp"+ android:layout_marginEnd="4dp"+ android:contentDescription="@string/widget_open_app"+ android:padding="8dp"+ android:src="@drawable/ic_app_mark" />++ <include+ layout="@layout/widget_now_playing"+ android:layout_marginTop="0dp"+ android:layout_width="0dp"+ android:layout_height="wrap_content"+ android:layout_weight="1" />+ </LinearLayout>+</FrameLayout>diff --git a/app/src/main/res/layout/widget_square_tile.xml b/app/src/main/res/layout/widget_square_tile.xmlnew file mode 100644index 0000000..f208eda--- /dev/null+++ b/app/src/main/res/layout/widget_square_tile.xml@@ -0,0 +1,119 @@+<?xml version="1.0" encoding="utf-8"?>+<!--+ The widget as a square of two by two, the way the small widgets of other+ phones are drawn. Two columns, each as tall as the widget, so neither can push+ the other out of it: the cover at the top of the first and the song at its+ foot; the mark at the top of the second and, at its foot, previous and next+ as bare icons one above the other, over play.+-->+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:id="@android:id/background"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:clipToOutline="true">++ <ImageView+ android:id="@+id/widget_glass"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:importantForAccessibility="no"+ android:scaleType="fitXY" />++ <LinearLayout+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:orientation="horizontal"+ android:paddingStart="12dp"+ android:paddingTop="12dp"+ android:paddingEnd="8dp"+ android:paddingBottom="10dp">++ <LinearLayout+ android:id="@+id/widget_now"+ android:layout_width="0dp"+ android:layout_height="match_parent"+ android:layout_weight="1"+ android:orientation="vertical">++ <ImageView+ android:id="@+id/widget_cover"+ android:layout_width="64dp"+ android:layout_height="64dp"+ android:importantForAccessibility="no"+ android:scaleType="centerCrop" />++ <!-- A FrameLayout, not a View: a widget may not inflate a plain View. -->+ <FrameLayout+ android:layout_width="0dp"+ android:layout_height="0dp"+ android:layout_weight="1" />++ <TextView+ android:id="@+id/widget_title"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:ellipsize="end"+ android:maxLines="2"+ android:textColor="#FFFFFFFF"+ android:textSize="14sp"+ android:textStyle="bold" />++ <TextView+ android:id="@+id/widget_artist"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:ellipsize="end"+ android:maxLines="1"+ android:textColor="#B3FFFFFF"+ android:textSize="12sp" />+ </LinearLayout>++ <LinearLayout+ android:layout_width="wrap_content"+ android:layout_height="match_parent"+ android:layout_marginStart="4dp"+ android:gravity="center_horizontal"+ android:orientation="vertical">++ <ImageView+ android:id="@+id/widget_logo"+ android:layout_width="28dp"+ android:layout_height="28dp"+ android:contentDescription="@string/widget_open_app"+ android:padding="5dp"+ android:src="@drawable/ic_app_mark" />++ <FrameLayout+ android:layout_width="0dp"+ android:layout_height="0dp"+ android:layout_weight="1" />++ <ImageView+ android:id="@+id/widget_previous"+ android:layout_width="28dp"+ android:layout_height="24dp"+ android:contentDescription="@string/previous"+ android:padding="4dp"+ android:src="@drawable/ic_widget_previous" />++ <ImageView+ android:id="@+id/widget_next"+ android:layout_width="28dp"+ android:layout_height="24dp"+ android:layout_marginTop="2dp"+ android:contentDescription="@string/next"+ android:padding="4dp"+ android:src="@drawable/ic_widget_next" />++ <ImageView+ android:id="@+id/widget_toggle"+ android:layout_width="38dp"+ android:layout_height="38dp"+ android:layout_marginTop="4dp"+ android:background="@drawable/widget_button_primary"+ android:padding="11dp"+ android:src="@drawable/ic_pip_play"+ android:tint="#FF111114" />+ </LinearLayout>+ </LinearLayout>+</FrameLayout>diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xmlindex deb50ca..94dc24b 100644--- a/app/src/main/res/values-de/strings.xml+++ b/app/src/main/res/values-de/strings.xml@@ -539,4 +539,7 @@<string name="recap_stat_minutes">Minuten in Square</string><string name="recap_empty">Diesen Monat noch nichts gehört.</string><string name="recap_partial_youtube">Enthält, was du in Square hörst, und, solange Square geöffnet ist, deinen YouTube-Music-Verlauf. Wiedergaben aus anderen Apps und auf anderen Geräten sind ungefähr: YouTube nennt nur den Tag, nicht die Uhrzeit.</string>+ <string name="widget_description">Aktuelle Wiedergabe, Steuerung und deine letzten Playlists</string>+ <string name="widget_nothing_playing">Es läuft nichts</string>+ <string name="widget_open_app">Square öffnen</string></resources>diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xmlindex 4e4d5bd..14e297a 100644--- a/app/src/main/res/values-es/strings.xml+++ b/app/src/main/res/values-es/strings.xml@@ -545,4 +545,7 @@<string name="recap_stat_minutes">minutos en Square</string><string name="recap_empty">Aún no hay escuchas este mes.</string><string name="recap_partial_youtube">Incluye lo que escuchas en Square y, mientras Square está abierta, tu historial de YouTube Music. Las escuchas en otras apps y dispositivos son aproximadas: YouTube no da la hora, solo el día.</string>+ <string name="widget_description">Lo que suena, sus controles y tus playlists recientes</string>+ <string name="widget_nothing_playing">No suena nada</string>+ <string name="widget_open_app">Abrir Square</string></resources>diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xmlindex c8690ea..449c117 100644--- a/app/src/main/res/values-fr/strings.xml+++ b/app/src/main/res/values-fr/strings.xml@@ -539,4 +539,7 @@<string name="recap_stat_minutes">minutes dans Square</string><string name="recap_empty">Aucune écoute ce mois-ci pour l’instant.</string><string name="recap_partial_youtube">Comprend ce que tu écoutes dans Square et, tant que Square est ouverte, ton historique YouTube Music. Les écoutes depuis d’autres apps et appareils sont approximatives : YouTube ne donne pas l’heure, seulement le jour.</string>+ <string name="widget_description">En cours de lecture, les commandes et tes playlists récentes</string>+ <string name="widget_nothing_playing">Rien en cours de lecture</string>+ <string name="widget_open_app">Ouvrir Square</string></resources>diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xmlindex 48f7979..9148926 100644--- a/app/src/main/res/values-hi/strings.xml+++ b/app/src/main/res/values-hi/strings.xml@@ -554,4 +554,7 @@<string name="recap_stat_minutes">Square में मिनट</string><string name="recap_empty">इस महीने अभी तक कुछ नहीं सुना।</string><string name="recap_partial_youtube">इसमें Square में सुने गए गाने और, जब तक Square खुला है, आपका YouTube Music इतिहास शामिल है। दूसरे ऐप और डिवाइस पर सुने गए गाने अनुमानित हैं: YouTube समय नहीं, सिर्फ़ दिन बताता है।</string>+ <string name="widget_description">अभी चल रहा गाना, उसके कंट्रोल और आपकी हाल की प्लेलिस्ट</string>+ <string name="widget_nothing_playing">कुछ नहीं चल रहा</string>+ <string name="widget_open_app">Square खोलें</string></resources>diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xmlindex dfe3461..3f7e3ff 100644--- a/app/src/main/res/values-it/strings.xml+++ b/app/src/main/res/values-it/strings.xml@@ -576,4 +576,7 @@<string name="recap_stat_minutes">minuti in Square</string><string name="recap_empty">Ancora nessun ascolto questo mese.</string><string name="recap_partial_youtube">Include quello che ascolti in Square e, mentre Square è aperta, la cronologia di YouTube Music. Gli ascolti da altre app e dispositivi sono approssimativi: YouTube non dice l’ora, solo il giorno.</string>+ <string name="widget_description">In riproduzione, i controlli e le tue playlist recenti</string>+ <string name="widget_nothing_playing">Niente in riproduzione</string>+ <string name="widget_open_app">Apri Square</string></resources>diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xmlindex 75d8979..1a3e5d5 100644--- a/app/src/main/res/values-pt/strings.xml+++ b/app/src/main/res/values-pt/strings.xml@@ -539,4 +539,7 @@<string name="recap_stat_minutes">minutos no Square</string><string name="recap_empty">Nenhuma reprodução neste mês ainda.</string><string name="recap_partial_youtube">Inclui o que você ouve no Square e, enquanto o Square está aberto, seu histórico do YouTube Music. Reproduções em outros apps e dispositivos são aproximadas: o YouTube não informa a hora, só o dia.</string>+ <string name="widget_description">O que está tocando, os controles e suas playlists recentes</string>+ <string name="widget_nothing_playing">Nada tocando</string>+ <string name="widget_open_app">Abrir o Square</string></resources>diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xmlindex 7865a64..f5eee59 100644--- a/app/src/main/res/values-ru/strings.xml+++ b/app/src/main/res/values-ru/strings.xml@@ -568,4 +568,7 @@<string name="recap_stat_minutes">минут в Square</string><string name="recap_empty">В этом месяце пока ничего не прослушано.</string><string name="recap_partial_youtube">Учитывается то, что вы слушаете в Square, и, пока Square открыт, история YouTube Music. Прослушивания в других приложениях и на других устройствах приблизительны: YouTube сообщает только день, а не время.</string>+ <string name="widget_description">Что играет, управление и ваши недавние плейлисты</string>+ <string name="widget_nothing_playing">Ничего не играет</string>+ <string name="widget_open_app">Открыть Square</string></resources>diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xmlindex 05d227e..f62df71 100644--- a/app/src/main/res/values-tr/strings.xml+++ b/app/src/main/res/values-tr/strings.xml@@ -552,4 +552,7 @@<string name="recap_stat_minutes">Square’de dakika</string><string name="recap_empty">Bu ay henüz dinleme yok.</string><string name="recap_partial_youtube">Square’de dinlediklerini ve Square açıkken YouTube Music geçmişini içerir. Diğer uygulama ve cihazlardaki dinlemeler yaklaşıktır: YouTube saati değil, yalnızca günü verir.</string>+ <string name="widget_description">Çalan şarkı, kontrolleri ve son çalma listelerin</string>+ <string name="widget_nothing_playing">Hiçbir şey çalmıyor</string>+ <string name="widget_open_app">Square’i aç</string></resources>diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xmlindex 1507e2a..5e6b171 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -603,4 +603,7 @@<string name="recap_stat_minutes">minutes in Square</string><string name="recap_empty">No listens this month yet.</string><string name="recap_partial_youtube">Includes what you play in Square and, while Square is open, your YouTube Music history. Plays from other apps and devices are approximate: YouTube does not say when, only the day.</string>+ <string name="widget_description">Now playing, its controls and your recent playlists</string>+ <string name="widget_nothing_playing">Nothing playing</string>+ <string name="widget_open_app">Open Square</string></resources>diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xmlindex 97b96b5..3d577ed 100644--- a/app/src/main/res/values/themes.xml+++ b/app/src/main/res/values/themes.xml@@ -7,4 +7,12 @@<item name="android:navigationBarColor">@android:color/transparent</item><item name="android:windowBackground">@android:color/black</item></style>+ <!-- A playlist cover in the widget's bottom row; see widget_square. -->+ <style name="WidgetPlaylist">+ <item name="android:layout_width">0dp</item>+ <item name="android:layout_height">match_parent</item>+ <item name="android:layout_weight">1</item>+ <item name="android:layout_marginEnd">6dp</item>+ <item name="android:scaleType">fitCenter</item>+ </style></resources>diff --git a/app/src/main/res/xml/square_widget_info.xml b/app/src/main/res/xml/square_widget_info.xmlnew file mode 100644index 0000000..7818025--- /dev/null+++ b/app/src/main/res/xml/square_widget_info.xml@@ -0,0 +1,14 @@+<?xml version="1.0" encoding="utf-8"?>+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"+ android:description="@string/widget_description"+ android:initialLayout="@layout/widget_square"+ android:minWidth="250dp"+ android:minHeight="40dp"+ android:minResizeWidth="100dp"+ android:minResizeHeight="40dp"+ android:previewLayout="@layout/widget_square"+ android:resizeMode="horizontal|vertical"+ android:targetCellWidth="4"+ android:targetCellHeight="2"+ android:updatePeriodMillis="0"+ android:widgetCategory="home_screen" />diff --git a/app/src/main/res/xml/square_widget_tile_info.xml b/app/src/main/res/xml/square_widget_tile_info.xmlnew file mode 100644index 0000000..92c79cd--- /dev/null+++ b/app/src/main/res/xml/square_widget_tile_info.xml@@ -0,0 +1,15 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- The same widget, offered at two by two; see SquareWidget.Tile. -->+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"+ android:description="@string/widget_description"+ android:initialLayout="@layout/widget_square_tile"+ android:minWidth="110dp"+ android:minHeight="110dp"+ android:minResizeWidth="100dp"+ android:minResizeHeight="40dp"+ android:previewLayout="@layout/widget_square_tile"+ android:resizeMode="horizontal|vertical"+ android:targetCellWidth="2"+ android:targetCellHeight="2"+ android:updatePeriodMillis="0"+ android:widgetCategory="home_screen" />