Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Android Widgets: one shared look

Claudefa25b59535b0
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/MochiBitmap.kt b/android/app/src/main/kotlin/com/coucou/android/app/MochiBitmap.kt
index 8f0b3953..6e79ef86 100644
--- a/android/app/src/main/kotlin/com/coucou/android/app/MochiBitmap.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/app/MochiBitmap.kt
@@ -1,13 +1,17 @@
package com.coucou.android.app
import android.graphics.Bitmap
+import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Canvas
+import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.graphics.drawscope.CanvasDrawScope
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.LayoutDirection
+import com.coucou.android.core.WidgetTone
import com.coucou.android.mochi.BotState
import com.coucou.android.mochi.MochiEngine
import com.coucou.android.mochi.MochiPainter.drawMochi
@@ -16,28 +20,33 @@ import kotlin.random.Random
/**
* One still picture of Mochi for a widget (a widget cannot animate): the engine is settled for a second of fake time
* with a fixed seed, so the same state always gives the same picture, then drawn once with the app's own painter into an
- * [ImageBitmap]. No timer and no frame loop; a few pictures are kept so a push that changes only the text redraws nothing.
+ * [ImageBitmap]. With [glow] a soft radial light in the state's colour sits behind him. No timer and no frame loop; a few
+ * pictures are kept so a push that changes only the text redraws nothing.
*/
object MochiBitmap {
private const val SEED = 7
private const val SETTLE_FRAMES = 60
private const val FRAME_SEC = 1.0 / 60
- private const val KEEP = 6
+ private const val KEEP = 12
- private data class Key(val state: BotState, val size: Int)
+ /** How strong the glow is at its centre; a muted state glows less. */
+ private const val GLOW_ALPHA = 0.55f
+ private const val GLOW_ALPHA_MUTED = 0.32f
- private val cache = object : LinkedHashMap<Key, Bitmap>(8, 0.75f, true) {
+ private data class Key(val state: BotState, val size: Int, val glow: Boolean)
+
+ private val cache = object : LinkedHashMap<Key, Bitmap>(16, 0.75f, true) {
override fun removeEldestEntry(eldest: MutableMap.MutableEntry<Key, Bitmap>) = size > KEEP
}
/** Mochi in [state], [sizePx] pixels square. The same instance comes back while it is kept. */
@Synchronized
- fun of(state: BotState, sizePx: Int): Bitmap {
- val key = Key(state, sizePx)
- return cache.getOrPut(key) { draw(state, sizePx) }
+ fun of(state: BotState, sizePx: Int, glow: Boolean = false): Bitmap {
+ val key = Key(state, sizePx, glow)
+ return cache.getOrPut(key) { draw(state, sizePx, glow) }
}
- private fun draw(state: BotState, sizePx: Int): Bitmap {
+ private fun draw(state: BotState, sizePx: Int, glow: Boolean): Bitmap {
var ms = 0.0
val engine = MochiEngine({ ms }, Random(SEED)).apply { setState(state, force = true) }
repeat(SETTLE_FRAMES) {
@@ -46,6 +55,12 @@ object MochiBitmap {
}
val image = ImageBitmap(sizePx, sizePx)
CanvasDrawScope().draw(Density(1f), LayoutDirection.Ltr, Canvas(image), Size(sizePx.toFloat(), sizePx.toFloat())) {
+ if (glow) {
+ val tone = WidgetTone.of(state)
+ val centre = Offset(sizePx / 2f, sizePx / 2f)
+ val light = Color(tone.argb).copy(alpha = if (tone == WidgetTone.MUTED) GLOW_ALPHA_MUTED else GLOW_ALPHA)
+ drawCircle(Brush.radialGradient(listOf(light, Color.Transparent), centre, sizePx / 2f), sizePx / 2f, centre)
+ }
drawMochi(engine, ms / 1000)
}
return image.asAndroidBitmap()
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/WidgetHub.kt b/android/app/src/main/kotlin/com/coucou/android/app/WidgetHub.kt
index e2e12b79..fd85245d 100644
--- a/android/app/src/main/kotlin/com/coucou/android/app/WidgetHub.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/app/WidgetHub.kt
@@ -6,6 +6,8 @@ import android.appwidget.AppWidgetProvider
import android.content.ComponentName
import android.content.Context
import android.content.Intent
+import android.os.Build
+import android.util.SizeF
import android.widget.RemoteViews
import com.coucou.android.MainActivity
import com.coucou.android.core.WidgetContent
@@ -53,6 +55,25 @@ object WidgetHub {
for (id in ids) runCatching { manager.updateAppWidget(id, rendered) }
}
+ /** The three sizes a responsive Widget is drawn for (Android 12 and later picks one by the room it has). */
+ enum class Size { SMALL, MEDIUM, LARGE }
+
+ // Where each size starts, in dp. The system picks the largest entry that fits, so SMALL starts at zero.
+ private val SMALL_AT = SizeF(0f, 0f)
+ private val MEDIUM_AT = SizeF(180f, 110f)
+ private val LARGE_AT = SizeF(250f, 180f)
+
+ /**
+ * One picture per size on Android 12 and later; on Android 11 (API 30) there is no size map, so the plain MEDIUM
+ * picture is the only one. [draw] builds the picture for a size from the same layout.
+ */
+ fun responsive(draw: (Size) -> RemoteViews): RemoteViews =
+ if (Build.VERSION.SDK_INT >= 31) {
+ RemoteViews(mapOf(SMALL_AT to draw(Size.SMALL), MEDIUM_AT to draw(Size.MEDIUM), LARGE_AT to draw(Size.LARGE)))
+ } else {
+ draw(Size.MEDIUM)
+ }
+
/** Opens the app on Home. */
fun openApp(context: Context, code: Int): PendingIntent {
val open = Intent(context, MainActivity::class.java)
diff --git a/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.kt b/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.kt
index 93fed543..eedf9a35 100644
--- a/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.kt
@@ -2,6 +2,38 @@ package com.coucou.android.core
import com.coucou.android.link.SessionInfo
import com.coucou.android.mochi.BotState
+import com.coucou.android.mochi.MochiConst
+import com.coucou.android.mochi.Rgb
+import kotlin.math.roundToInt
+
+/**
+ * How loud a widget looks: the colour of its dot, badge, glow and gradient. Taken from the app's own state colours
+ * ([MochiConst]), so a Widget and Mochi on Home always agree. Waiting is orange, working blue, done green.
+ */
+enum class WidgetTone(val rgb: Rgb) {
+ MUTED(MochiConst.C_SLEEPING),
+ WORKING(MochiConst.C_WORKING),
+ ATTENTION(MochiConst.C_APPROVAL),
+ DONE(MochiConst.C_FINISHED),
+ TROUBLE(MochiConst.C_ERROR),
+ ;
+
+ /** Opaque ARGB. */
+ val argb: Int get() = 0xFF000000.toInt() or (c(rgb.r) shl 16) or (c(rgb.g) shl 8) or c(rgb.b)
+
+ companion object {
+ private fun c(v: Double) = (v.coerceIn(0.0, 1.0) * 255).roundToInt()
+
+ /** The tone of one agent's state; a computer that is not connected is always muted. */
+ fun of(state: BotState, connected: Boolean = true): WidgetTone = if (!connected) MUTED else when (state) {
+ BotState.APPROVAL, BotState.QUESTION -> ATTENTION
+ BotState.WORKING, BotState.THINKING, BotState.SEARCHING -> WORKING
+ BotState.FINISHED -> DONE
+ BotState.ERROR, BotState.RATELIMIT, BotState.DIZZY -> TROUBLE
+ BotState.IDLE, BotState.SLEEPING -> MUTED
+ }
+ }
+}
/** One agent on a widget: who it is, a plain state word and its colour. Only names, state words and colours. */
data class WidgetTile(val pillId: String, val name: String, val state: BotState, val stateWord: String, val argb: Int)
@@ -23,6 +55,13 @@ data class WidgetContent(
/** The agent Solo shows. */
val top: WidgetTile? get() = tiles.firstOrNull()
+ /** The look of the whole widget: orange while something waits for you, else the top agent's tone, muted when nothing runs. */
+ val look: WidgetTone get() = when {
+ !connected -> WidgetTone.MUTED
+ waiting > 0 -> WidgetTone.ATTENTION
+ else -> top?.let { WidgetTone.of(it.state) } ?: WidgetTone.MUTED
+ }
+
/** The state Mochi is drawn in: the top agent's, else calm when connected and asleep when not. */
val mood: BotState get() = top?.state ?: if (connected) BotState.IDLE else BotState.SLEEPING
}
diff --git a/android/app/src/main/res/drawable/ic_widget_offline.xml b/android/app/src/main/res/drawable/ic_widget_offline.xml
new file mode 100644
index 00000000..9bf5d69b
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_widget_offline.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- A circle with a bar through it: "not connected". -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="@color/widget_tone_muted"
+ android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM4,12c0,-4.42 3.58,-8 8,-8 1.85,0 3.55,0.63 4.9,1.69L5.69,16.9C4.63,15.55 4,13.85 4,12zM12,20c-1.85,0 -3.55,-0.63 -4.9,-1.69L18.31,7.1C19.37,8.45 20,10.15 20,12c0,4.42 -3.58,8 -8,8z" />
+</vector>
diff --git a/android/app/src/main/res/drawable/widget_bubble.xml b/android/app/src/main/res/drawable/widget_bubble.xml
new file mode 100644
index 00000000..32e7d695
--- /dev/null
+++ b/android/app/src/main/res/drawable/widget_bubble.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <solid android:color="@color/widget_bubble" />
+ <corners android:radius="18dp" />
+</shape>
diff --git a/android/app/src/main/res/drawable/widget_bubble_tail.xml b/android/app/src/main/res/drawable/widget_bubble_tail.xml
new file mode 100644
index 00000000..7f8de2ab
--- /dev/null
+++ b/android/app/src/main/res/drawable/widget_bubble_tail.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The little point under Mochi's speech bubble. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="20dp"
+ android:height="10dp"
+ android:viewportWidth="20"
+ android:viewportHeight="10">
+ <path android:fillColor="@color/widget_bubble" android:pathData="M0,0 L20,0 L10,10 Z" />
+</vector>
diff --git a/android/app/src/main/res/drawable/widget_card.xml b/android/app/src/main/res/drawable/widget_card.xml
new file mode 100644
index 00000000..d8e6c9dc
--- /dev/null
+++ b/android/app/src/main/res/drawable/widget_card.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The card of every Widget: 24dp corners and a thin lighter border so it stands out on a dark wallpaper. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <solid android:color="@color/widget_card" />
+ <stroke android:width="@dimen/widget_border_width" android:color="@color/widget_border" />
+ <corners android:radius="@dimen/widget_radius" />
+</shape>
diff --git a/android/app/src/main/res/drawable/widget_card_attention.xml b/android/app/src/main/res/drawable/widget_card_attention.xml
new file mode 100644
index 00000000..81e4f87c
--- /dev/null
+++ b/android/app/src/main/res/drawable/widget_card_attention.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The card while something waits for you: the same shape with an orange border. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <solid android:color="@color/widget_card" />
+ <stroke android:width="2dp" android:color="@color/widget_tone_attention" />
+ <corners android:radius="@dimen/widget_radius" />
+</shape>
diff --git a/android/app/src/main/res/drawable/widget_dot.xml b/android/app/src/main/res/drawable/widget_dot.xml
new file mode 100644
index 00000000..71853617
--- /dev/null
+++ b/android/app/src/main/res/drawable/widget_dot.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- A round dot; its colour is set in code from the tone. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
+ <solid android:color="#FFFFFFFF" />
+ <size android:width="@dimen/widget_dot" android:height="@dimen/widget_dot" />
+</shape>
diff --git a/android/app/src/main/res/drawable/widget_stripe.xml b/android/app/src/main/res/drawable/widget_stripe.xml
new file mode 100644
index 00000000..40a5443d
--- /dev/null
+++ b/android/app/src/main/res/drawable/widget_stripe.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The thin bar before a row; its colour is the agent's own, set in code. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <solid android:color="#FFFFFFFF" />
+ <corners android:radius="2dp" />
+</shape>
diff --git a/android/app/src/main/res/drawable/widget_tint_attention.xml b/android/app/src/main/res/drawable/widget_tint_attention.xml
new file mode 100644
index 00000000..1c85a481
--- /dev/null
+++ b/android/app/src/main/res/drawable/widget_tint_attention.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The gradient over a card in the "attention" tone: the tone colour fading into the card. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <gradient
+ android:angle="315"
+ android:startColor="@color/widget_tint_attention"
+ android:endColor="#00000000" />
+ <corners android:radius="@dimen/widget_radius" />
+</shape>
diff --git a/android/app/src/main/res/drawable/widget_tint_done.xml b/android/app/src/main/res/drawable/widget_tint_done.xml
new file mode 100644
index 00000000..c3ba1b0a
--- /dev/null
+++ b/android/app/src/main/res/drawable/widget_tint_done.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The gradient over a card in the "done" tone: the tone colour fading into the card. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <gradient
+ android:angle="315"
+ android:startColor="@color/widget_tint_done"
+ android:endColor="#00000000" />
+ <corners android:radius="@dimen/widget_radius" />
+</shape>
diff --git a/android/app/src/main/res/drawable/widget_tint_muted.xml b/android/app/src/main/res/drawable/widget_tint_muted.xml
new file mode 100644
index 00000000..20c78391
--- /dev/null
+++ b/android/app/src/main/res/drawable/widget_tint_muted.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The gradient over a card in the "muted" tone: the tone colour fading into the card. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <gradient
+ android:angle="315"
+ android:startColor="@color/widget_tint_muted"
+ android:endColor="#00000000" />
+ <corners android:radius="@dimen/widget_radius" />
+</shape>
diff --git a/android/app/src/main/res/drawable/widget_tint_trouble.xml b/android/app/src/main/res/drawable/widget_tint_trouble.xml
new file mode 100644
index 00000000..e6caeb86
--- /dev/null
+++ b/android/app/src/main/res/drawable/widget_tint_trouble.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The gradient over a card in the "trouble" tone: the tone colour fading into the card. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <gradient
+ android:angle="315"
+ android:startColor="@color/widget_tint_trouble"
+ android:endColor="#00000000" />
+ <corners android:radius="@dimen/widget_radius" />
+</shape>
diff --git a/android/app/src/main/res/drawable/widget_tint_working.xml b/android/app/src/main/res/drawable/widget_tint_working.xml
new file mode 100644
index 00000000..77b0d673
--- /dev/null
+++ b/android/app/src/main/res/drawable/widget_tint_working.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The gradient over a card in the "working" tone: the tone colour fading into the card. -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+ <gradient
+ android:angle="315"
+ android:startColor="@color/widget_tint_working"
+ android:endColor="#00000000" />
+ <corners android:radius="@dimen/widget_radius" />
+</shape>
diff --git a/android/app/src/main/res/values-notnight/colors.xml b/android/app/src/main/res/values-notnight/colors.xml
new file mode 100644
index 00000000..d839d2cd
--- /dev/null
+++ b/android/app/src/main/res/values-notnight/colors.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The light variant of the Widgets (the system is in day mode). The tone and tint colours do not change. -->
+<resources>
+ <color name="widget_card">#FFF7F7FA</color>
+ <color name="widget_border">#FFD2D4DC</color>
+ <color name="widget_text">#FF1C1C1E</color>
+ <color name="widget_text_soft">#D91C1C1E</color>
+ <color name="widget_text_secondary">#B31C1C1E</color>
+ <color name="widget_bubble">#FFFFFFFF</color>
+ <color name="widget_bubble_text">#FF1C1C1E</color>
+</resources>
diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml
new file mode 100644
index 00000000..d27a84b9
--- /dev/null
+++ b/android/app/src/main/res/values/colors.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Widgets: dark by default; values-notnight/colors.xml is the light variant that follows the system day/night mode. -->
+<resources>
+ <color name="widget_card">#FF17181C</color>
+ <color name="widget_border">#FF3A3C44</color>
+ <color name="widget_text">#FFFFFFFF</color>
+ <color name="widget_text_soft">#D9FFFFFF</color>
+ <color name="widget_text_secondary">#B3FFFFFF</color>
+ <color name="widget_bubble">#FFFFFFFF</color>
+ <color name="widget_bubble_text">#FF1C1C1E</color>
+
+ <!-- The state palette: the same colours as Mochi's states (MochiConst) and WidgetTone. -->
+ <color name="widget_tone_muted">#FF94A2B8</color>
+ <color name="widget_tone_working">#FF3B9EFF</color>
+ <color name="widget_tone_attention">#FFF5A524</color>
+ <color name="widget_tone_done">#FF34D499</color>
+ <color name="widget_tone_trouble">#FFF4505E</color>
+
+ <!-- The gradient of a card: the tone at 15 to 25 % alpha, fading into the card. -->
+ <color name="widget_tint_muted">#2694A2B8</color>
+ <color name="widget_tint_working">#333B9EFF</color>
+ <color name="widget_tint_attention">#40F5A524</color>
+ <color name="widget_tint_done">#3334D499</color>
+ <color name="widget_tint_trouble">#33F4505E</color>
+</resources>
diff --git a/android/app/src/main/res/values/dimens.xml b/android/app/src/main/res/values/dimens.xml
new file mode 100644
index 00000000..fca3ab8d
--- /dev/null
+++ b/android/app/src/main/res/values/dimens.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Widgets: one scale for every card. -->
+<resources>
+ <dimen name="widget_radius">24dp</dimen>
+ <dimen name="widget_border_width">1dp</dimen>
+ <dimen name="widget_pad">12dp</dimen>
+ <dimen name="widget_row_min">48dp</dimen>
+ <dimen name="widget_dot">10dp</dimen>
+ <dimen name="widget_icon">18dp</dimen>
+ <dimen name="widget_text_name">16sp</dimen>
+ <dimen name="widget_text_state">13sp</dimen>
+ <dimen name="widget_text_secondary">12sp</dimen>
+ <dimen name="widget_text_note">14sp</dimen>
+</resources>
diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetToneTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetToneTest.kt
new file mode 100644
index 00000000..b3303b4b
--- /dev/null
+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetToneTest.kt
@@ -0,0 +1,100 @@
+package com.coucou.android
+
+import com.coucou.android.core.GlanceTone
+import com.coucou.android.core.WidgetContent
+import com.coucou.android.core.WidgetTile
+import com.coucou.android.core.WidgetTone
+import com.coucou.android.mochi.BotState
+import java.io.File
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+/** The Widgets' state palette: the pure mapping, and that the colour resources say the same thing. */
+class WidgetToneTest {
+ private fun colours(path: String): Map<String, String> =
+ Regex("""<color name="(\w+)">(#[0-9A-Fa-f]{6,8})</color>""").findAll(File(path).readText()).associate { it.groupValues[1] to it.groupValues[2] }
+
+ private val dark get() = colours("src/main/res/values/colors.xml")
+ private val light get() = colours("src/main/res/values-notnight/colors.xml")
+
+ private fun content(connected: Boolean = true, waiting: Int = 0, vararg states: BotState) = WidgetContent(
+ "x", GlanceTone.CALM, connected, waiting, states.mapIndexed { i, s -> WidgetTile("p$i", "n$i", s, "w", 0xFF000000.toInt()) },
+ )
+
+ @Test fun everyStateHasATone() {
+ for (s in BotState.values()) WidgetTone.of(s)
+ assertEquals(WidgetTone.ATTENTION, WidgetTone.of(BotState.APPROVAL))
+ assertEquals(WidgetTone.ATTENTION, WidgetTone.of(BotState.QUESTION))
+ for (s in listOf(BotState.WORKING, BotState.THINKING, BotState.SEARCHING)) assertEquals(WidgetTone.WORKING, WidgetTone.of(s))
+ assertEquals(WidgetTone.DONE, WidgetTone.of(BotState.FINISHED))
+ for (s in listOf(BotState.ERROR, BotState.RATELIMIT, BotState.DIZZY)) assertEquals(WidgetTone.TROUBLE, WidgetTone.of(s))
+ for (s in listOf(BotState.IDLE, BotState.SLEEPING)) assertEquals(WidgetTone.MUTED, WidgetTone.of(s))
+ }
+
+ @Test fun aComputerThatIsNotConnectedIsAlwaysMuted() {
+ for (s in BotState.values()) assertEquals(WidgetTone.MUTED, WidgetTone.of(s, connected = false))
+ }
+
+ @Test fun theColoursAreOpaqueAndTheOnesOfMochi() {
+ assertEquals(0xFFF5A524.toInt(), WidgetTone.ATTENTION.argb)
+ assertEquals(0xFF3B9EFF.toInt(), WidgetTone.WORKING.argb)
+ assertEquals(0xFF34D499.toInt(), WidgetTone.DONE.argb)
+ assertEquals(0xFFF4505E.toInt(), WidgetTone.TROUBLE.argb)
+ assertEquals(0xFF94A2B8.toInt(), WidgetTone.MUTED.argb)
+ }
+
+ @Test fun theResourcesCarryTheSamePalette() {
+ for (t in WidgetTone.values()) {
+ val hex = dark.getValue("widget_tone_${t.name.lowercase()}").removePrefix("#")
+ assertEquals(t.name, t.argb.toUInt().toString(16).uppercase().padStart(8, '0'), hex.uppercase())
+ assertFalse("the tone colours are the same in day mode", light.containsKey("widget_tone_${t.name.lowercase()}"))
+ }
+ }
+
+ @Test fun theGradientIsTheToneAtFifteenToTwentyFivePercent() {
+ for (t in WidgetTone.values()) {
+ val tint = dark.getValue("widget_tint_${t.name.lowercase()}").removePrefix("#")
+ assertEquals(8, tint.length)
+ val alpha = tint.substring(0, 2).toInt(16) / 255.0
+ assertTrue("${t.name} alpha $alpha", alpha in 0.145..0.255)
+ assertEquals(dark.getValue("widget_tone_${t.name.lowercase()}").removePrefix("#FF").uppercase(), tint.substring(2).uppercase())
+ }
+ }
+
+ @Test fun theLightVariantRestylesTheCardAndTheText() {
+ for (k in listOf("widget_card", "widget_border", "widget_text", "widget_text_soft", "widget_text_secondary")) {
+ assertTrue(k, light.containsKey(k))
+ assertTrue("$k differs in day mode", light[k] != dark[k])
+ }
+ // White at 85 % on the dark card, and 70 % for the secondary text.
+ assertEquals("#D9FFFFFF", dark["widget_text_soft"])
+ assertEquals("#B3FFFFFF", dark["widget_text_secondary"])
+ }
+
+ @Test fun theCardHasTwentyFourDpCornersAndABorder() {
+ assertTrue(File("src/main/res/values/dimens.xml").readText().contains("""<dimen name="widget_radius">24dp</dimen>"""))
+ assertTrue(File("src/main/res/values/dimens.xml").readText().contains("""<dimen name="widget_border_width">1dp</dimen>"""))
+ val card = File("src/main/res/drawable/widget_card.xml").readText()
+ assertTrue(card.contains("@dimen/widget_radius"))
+ assertTrue(card.contains("<stroke"))
+ }
+
+ @Test fun theTypographyScale() {
+ val d = File("src/main/res/values/dimens.xml").readText()
+ assertTrue(d.contains("""<dimen name="widget_text_name">16sp</dimen>"""))
+ assertTrue(d.contains("""<dimen name="widget_text_state">13sp</dimen>"""))
+ assertTrue(d.contains("""<dimen name="widget_text_secondary">12sp</dimen>"""))
+ assertTrue(d.contains("""<dimen name="widget_text_note">14sp</dimen>"""))
+ assertTrue(d.contains("""<dimen name="widget_row_min">48dp</dimen>"""))
+ }
+
+ @Test fun theLookFollowsWhatWaitsThenTheTopAgent() {
+ assertEquals(WidgetTone.MUTED, content(connected = false, waiting = 2, states = arrayOf(BotState.WORKING)).look)
+ assertEquals(WidgetTone.ATTENTION, content(waiting = 1, states = arrayOf(BotState.WORKING)).look)
+ assertEquals(WidgetTone.WORKING, content(states = arrayOf(BotState.WORKING, BotState.IDLE)).look)
+ assertEquals(WidgetTone.DONE, content(states = arrayOf(BotState.FINISHED)).look)
+ assertEquals(WidgetTone.MUTED, content().look)
+ }
+}