@@ -4,6 +4,7 @@ import android.content.Context
44import android.graphics.Color
55import androidx.annotation.OptIn
66import androidx.core.content.ContextCompat
7+ import androidx.core.graphics.drawable.toBitmapOrNull
78import androidx.wear.protolayout.ActionBuilders
89import androidx.wear.protolayout.ColorBuilders
910import androidx.wear.protolayout.ColorBuilders.ColorProp
@@ -43,10 +44,16 @@ import androidx.wear.protolayout.material.Text
4344import androidx.wear.protolayout.material.Typography
4445import androidx.wear.protolayout.material.layouts.MultiSlotLayout
4546import androidx.wear.protolayout.material.layouts.PrimaryLayout
47+ import androidx.wear.tiles.tooling.preview.TilePreviewData
48+ import com.thewizrd.shared_resources.actions.AudioStreamState
49+ import com.thewizrd.shared_resources.actions.AudioStreamType
4650import com.thewizrd.shared_resources.helpers.WearConnectionStatus
4751import com.thewizrd.shared_resources.media.PlaybackState
52+ import com.thewizrd.shared_resources.utils.ImageUtils.toByteArray
4853import com.thewizrd.simplewear.R
54+ import com.thewizrd.simplewear.ui.tools.WearTilePreviewDevices
4955import com.thewizrd.simplewear.wearable.tiles.MediaPlayerTileMessenger.PlayerAction
56+ import com.thewizrd.simplewear.wearable.tiles.MediaPlayerTileRenderer
5057import com.thewizrd.simplewear.wearable.tiles.MediaPlayerTileRenderer.Companion.ID_APPICON
5158import com.thewizrd.simplewear.wearable.tiles.MediaPlayerTileRenderer.Companion.ID_ARTWORK
5259import com.thewizrd.simplewear.wearable.tiles.MediaPlayerTileRenderer.Companion.ID_OPENONPHONE
@@ -58,6 +65,7 @@ import com.thewizrd.simplewear.wearable.tiles.MediaPlayerTileRenderer.Companion.
5865import com.thewizrd.simplewear.wearable.tiles.MediaPlayerTileRenderer.Companion.ID_VOL_DOWN
5966import com.thewizrd.simplewear.wearable.tiles.MediaPlayerTileRenderer.Companion.ID_VOL_UP
6067import com.thewizrd.simplewear.wearable.tiles.MediaPlayerTileState
68+ import kotlinx.coroutines.runBlocking
6169import java.time.Instant
6270
6371private val CIRCLE_SIZE = dp(48f )
@@ -435,7 +443,7 @@ private fun PlayerButton(
435443 action : PlayerAction
436444): LayoutElement {
437445 val isPlayPause = action == PlayerAction .PAUSE || action == PlayerAction .PLAY
438- val size = if (isPlayPause) dp(50f ) else dp( 52f )
446+ val size = dp(50f )
439447 return Box .Builder ()
440448 .setHeight(size)
441449 .setWidth(size)
@@ -552,4 +560,30 @@ private fun getResourceIdForPlayerAction(action: PlayerAction): String {
552560 PlayerAction .VOL_UP -> ID_VOL_UP
553561 PlayerAction .VOL_DOWN -> ID_VOL_DOWN
554562 }
563+ }
564+
565+ @WearTilePreviewDevices
566+ private fun MediaPlayerTilePreview (context : Context ): TilePreviewData {
567+ val state = MediaPlayerTileState (
568+ connectionStatus = WearConnectionStatus .CONNECTED ,
569+ title = " Title" ,
570+ artist = " Artist" ,
571+ playbackState = PlaybackState .PAUSED ,
572+ audioStreamState = AudioStreamState (3 , 0 , 5 , AudioStreamType .MUSIC ),
573+ artwork = runBlocking {
574+ ContextCompat .getDrawable(context, R .drawable.ws_full_sad)?.toBitmapOrNull()
575+ ?.toByteArray()
576+ },
577+ appIcon = runBlocking {
578+ ContextCompat .getDrawable(context, R .drawable.ic_play_circle_simpleblue)
579+ ?.toBitmapOrNull()
580+ ?.toByteArray()
581+ }
582+ )
583+ val renderer = MediaPlayerTileRenderer (context, debugResourceMode = true )
584+
585+ return TilePreviewData (
586+ onTileRequest = { renderer.renderTimeline(state, it) },
587+ onTileResourceRequest = { renderer.produceRequestedResources(state, it) }
588+ )
555589}
0 commit comments