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: six more Widgets

Claude9937eca0826a
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index b57d633c..1f7ff0f7 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -88,6 +88,48 @@
<meta-data android:name="android.appwidget.provider" android:resource="@xml/coucou_list_widget_info" />
</receiver>
+ <!-- More Widgets: Mochi Big, Status Pill, Waiting Alert, Usage Ring, Today and Mochi Mood. Pushed by the app when something changes (no timer). -->
+ <receiver android:name=".app.MochiBigWidget" android:exported="true" android:label="@string/widget_big_label">
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider" android:resource="@xml/coucou_big_widget_info" />
+ </receiver>
+ <receiver android:name=".app.StatusPillWidget" android:exported="true" android:label="@string/widget_pill_label">
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider" android:resource="@xml/coucou_pill_widget_info" />
+ </receiver>
+ <receiver android:name=".app.WaitingAlertWidget" android:exported="true" android:label="@string/widget_alert_label">
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider" android:resource="@xml/coucou_alert_widget_info" />
+ </receiver>
+ <receiver android:name=".app.UsageRingWidget" android:exported="true" android:label="@string/widget_ring_label">
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider" android:resource="@xml/coucou_ring_widget_info" />
+ </receiver>
+ <receiver android:name=".app.TodayWidget" android:exported="true" android:label="@string/widget_today_label">
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ <!-- The day changed: the count starts again at zero. System broadcasts, no timer. -->
+ <action android:name="android.intent.action.DATE_CHANGED" />
+ <action android:name="android.intent.action.TIME_SET" />
+ <action android:name="android.intent.action.TIMEZONE_CHANGED" />
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider" android:resource="@xml/coucou_today_widget_info" />
+ </receiver>
+ <receiver android:name=".app.MoodWidget" android:exported="true" android:label="@string/widget_mood_label">
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider" android:resource="@xml/coucou_mood_widget_info" />
+ </receiver>
+
<!-- The quick-settings tile: on while the computer is connected; a tap opens Coucou. -->
<service
android:name=".app.GlanceTile"
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt b/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt
index ede089e2..63ecf799 100644
--- a/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt
@@ -72,6 +72,9 @@ class AppModel(private val context: Context) : LinkListener {
/** Set only by LaunchActivity (not exported), read by MainActivity: see [com.coucou.android.core.PendingLaunch]. */
val launch = com.coucou.android.core.PendingLaunch()
+ /** Agent tasks finished today, for the Today widget. Kept on this phone only (see [TodayStore]). */
+ private val todayCounter = com.coucou.android.core.TodayCounter(TodayStore(context))
+
var mode by mutableStateOf(Mode.NONE); private set
var linkState by mutableStateOf(LinkState.DISCONNECTED); private set
var desktopName by mutableStateOf<String?>(null); private set
@@ -330,12 +333,16 @@ class AppModel(private val context: Context) : LinkListener {
mode != Mode.NONE || isPaired, linkState, desktopName, sessions, approvals.size, this::agentName,
)
+ /** What the Widgets draw now: the glance, the sessions, the plan usage the computer sent and today's finished tasks. */
+ fun widgetContent(g: com.coucou.android.core.Glance = glance()): com.coucou.android.core.WidgetContent =
+ com.coucou.android.core.WidgetData.build(g, sessions, this::agentName, usage, todayCounter.count(), System.currentTimeMillis())
+
/** The small surfaces follow every change of sessions, requests and link; none of them runs a timer. */
private fun pushGlance() {
val g = glance()
notifier.updateOngoing(this, g)
GlanceWidget.update(context, g)
- WidgetHub.update(context, com.coucou.android.core.WidgetData.build(g, sessions, this::agentName))
+ WidgetHub.update(context, widgetContent(g))
GlanceTile.requestUpdate(context)
}
@@ -663,13 +670,16 @@ class AppModel(private val context: Context) : LinkListener {
chatOffered = Protocol.CAP_CHAT in caps
detailsOffered = Protocol.CAP_DETAILS in caps
diffsOffered = Protocol.CAP_DIFFS in caps
- if (Protocol.CAP_USAGE !in caps) usage = null
+ if (Protocol.CAP_USAGE !in caps) { usage = null; pushGlance() } // the Usage Ring says to turn it on
if (Protocol.CAP_SERVICES !in caps) services = emptyList()
}
}
override fun onUsage(usage: com.coucou.android.link.UsageSnapshot) {
- main.post { this.usage = usage.takeIf { it.claude != null || it.codex != null } }
+ main.post {
+ this.usage = usage.takeIf { it.claude != null || it.codex != null }
+ pushGlance() // the Usage Ring follows it
+ }
}
override fun onServices(cards: List<com.coucou.android.link.ServiceCard>) {
@@ -711,6 +721,8 @@ class AppModel(private val context: Context) : LinkListener {
val minute = java.time.LocalTime.now().let { it.hour * 60 + it.minute }
for (s in sessions) {
val prev = lastState.put(s.pillId, s.state)
+ // A task just finished (not one already finished when the link came back).
+ if (prev != null && prev != BotState.FINISHED && s.state == BotState.FINISHED) todayCounter.increment()
val name = agentName(s.pillId)
val sound = com.coucou.android.mochi.MochiConst.STATE_SOUND[s.state]
if (sound != null && StatusPolicy.stateSoundWanted(prev, s.state, settings)) sounds.play(sound)
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/MochiBigWidget.kt b/android/app/src/main/kotlin/com/coucou/android/app/MochiBigWidget.kt
new file mode 100644
index 00000000..d59bfbf0
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/app/MochiBigWidget.kt
@@ -0,0 +1,63 @@
+package com.coucou.android.app
+
+import android.appwidget.AppWidgetManager
+import android.appwidget.AppWidgetProvider
+import android.content.Context
+import android.util.SizeF
+import android.util.TypedValue
+import android.view.View
+import android.widget.RemoteViews
+import com.coucou.android.R
+import com.coucou.android.core.WidgetContent
+
+/**
+ * The Mochi Big widget: a large Mochi with a glow and a speech bubble that says who is doing what in plain words
+ * ([WidgetContent.bubble]: a name and a state, never a command or a file). Drawn by [WidgetHub] when something changes
+ * (updatePeriodMillis = 0). A tap opens the top agent, or the app. It only opens things.
+ */
+class MochiBigWidget : AppWidgetProvider() {
+ override fun onUpdate(context: Context, manager: AppWidgetManager, ids: IntArray) =
+ WidgetHub.refresh(context, manager, ids) { c, w -> views(c, w) }
+
+ companion object {
+ private val MEDIUM_AT = SizeF(240f, 240f)
+ private val LARGE_AT = SizeF(320f, 320f)
+
+ fun views(context: Context, c: WidgetContent): RemoteViews =
+ WidgetHub.responsive(MEDIUM_AT, LARGE_AT) { size -> render(context, c, size) }
+
+ private fun render(context: Context, c: WidgetContent, size: WidgetHub.Size): RemoteViews {
+ val v = RemoteViews(context.packageName, R.layout.widget_big)
+ WidgetHub.paint(v, R.id.big_root, R.id.big_tint, c.look)
+ val top = c.top
+ val large = size == WidgetHub.Size.LARGE
+ val small = size == WidgetHub.Size.SMALL
+
+ v.setTextViewText(R.id.big_bubble, c.bubble)
+ v.setTextViewTextSize(R.id.big_bubble, TypedValue.COMPLEX_UNIT_SP, if (large) 19f else if (small) 14f else 16f)
+ v.setImageViewBitmap(R.id.big_mochi, MochiBitmap.of(c.mood, WidgetHub.px(context, if (large) 240 else if (small) 110 else 180), glow = true))
+ v.setContentDescription(R.id.big_mochi, context.getString(R.string.widget_mochi_description, (top?.stateWord ?: c.headline).lowercase()))
+
+ if (top != null && !small) {
+ v.setViewVisibility(R.id.big_row, View.VISIBLE)
+ v.setInt(R.id.big_dot, "setColorFilter", top.tone.argb)
+ v.setTextViewText(R.id.big_name, top.name)
+ v.setTextViewText(R.id.big_state, top.stateWord)
+ } else {
+ v.setViewVisibility(R.id.big_row, View.GONE)
+ }
+ if (c.waiting > 0) {
+ v.setTextViewText(R.id.big_badge, c.waiting.toString())
+ v.setContentDescription(R.id.big_badge, context.getString(R.string.widget_badge_description, c.waiting))
+ v.setViewVisibility(R.id.big_badge, View.VISIBLE)
+ } else {
+ v.setViewVisibility(R.id.big_badge, View.GONE)
+ }
+ v.setOnClickPendingIntent(
+ R.id.big_root,
+ if (top != null) WidgetHub.openSession(context, WidgetHub.CODE_BIG, top.pillId) else WidgetHub.openApp(context, WidgetHub.CODE_BIG),
+ )
+ return v
+ }
+ }
+}
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/MoodWidget.kt b/android/app/src/main/kotlin/com/coucou/android/app/MoodWidget.kt
new file mode 100644
index 00000000..6a7146a8
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/app/MoodWidget.kt
@@ -0,0 +1,32 @@
+package com.coucou.android.app
+
+import android.appwidget.AppWidgetManager
+import android.appwidget.AppWidgetProvider
+import android.content.Context
+import android.widget.RemoteViews
+import com.coucou.android.R
+import com.coucou.android.core.WidgetContent
+
+/**
+ * The Mochi Mood widget: only Mochi's face in the current state, with his glow. Drawn by [WidgetHub] when something changes
+ * (updatePeriodMillis = 0). A tap opens the top agent, or the app. It only opens things.
+ */
+class MoodWidget : AppWidgetProvider() {
+ override fun onUpdate(context: Context, manager: AppWidgetManager, ids: IntArray) =
+ WidgetHub.refresh(context, manager, ids) { c, w -> views(c, w) }
+
+ companion object {
+ fun views(context: Context, c: WidgetContent): RemoteViews {
+ val v = RemoteViews(context.packageName, R.layout.widget_mood)
+ WidgetHub.paint(v, R.id.mood_root, R.id.mood_tint, c.look)
+ v.setImageViewBitmap(R.id.mood_face, MochiBitmap.of(c.mood, WidgetHub.px(context, 64), glow = true))
+ v.setContentDescription(R.id.mood_face, context.getString(R.string.widget_mochi_description, (c.top?.stateWord ?: c.headline).lowercase()))
+ val top = c.top
+ v.setOnClickPendingIntent(
+ R.id.mood_root,
+ if (top != null) WidgetHub.openSession(context, WidgetHub.CODE_MOOD, top.pillId) else WidgetHub.openApp(context, WidgetHub.CODE_MOOD),
+ )
+ return v
+ }
+ }
+}
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/RingBitmap.kt b/android/app/src/main/kotlin/com/coucou/android/app/RingBitmap.kt
new file mode 100644
index 00000000..90a81b47
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/app/RingBitmap.kt
@@ -0,0 +1,52 @@
+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.Canvas
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.ImageBitmap
+import androidx.compose.ui.graphics.StrokeCap
+import androidx.compose.ui.graphics.asAndroidBitmap
+import androidx.compose.ui.graphics.drawscope.CanvasDrawScope
+import androidx.compose.ui.graphics.drawscope.Stroke
+import androidx.compose.ui.unit.Density
+import androidx.compose.ui.unit.LayoutDirection
+import com.coucou.android.core.UsageRing
+
+/**
+ * The ring of the Usage Ring widget, drawn once into a bitmap: a faint track and an arc in the tone of the usage, starting at
+ * the top. A few are kept so a push that changes nothing about the ring draws nothing. No timer, no frame loop.
+ */
+object RingBitmap {
+ private const val KEEP = 6
+ private const val TRACK = 0x40808080
+ private const val STROKE = 0.12f
+
+ private data class Key(val pct: Int, val tone: Int, val size: Int)
+
+ private val cache = object : LinkedHashMap<Key, Bitmap>(8, 0.75f, true) {
+ override fun removeEldestEntry(eldest: MutableMap.MutableEntry<Key, Bitmap>) = size > KEEP
+ }
+
+ /** The ring for [ring], [sizePx] pixels square. */
+ @Synchronized
+ fun of(ring: UsageRing, sizePx: Int): Bitmap {
+ val key = Key(ring.pct.coerceIn(0, 100), ring.tone.argb, sizePx)
+ return cache.getOrPut(key) { draw(ring, sizePx) }
+ }
+
+ private fun draw(ring: UsageRing, sizePx: Int): Bitmap {
+ val image = ImageBitmap(sizePx, sizePx)
+ val stroke = sizePx * STROKE
+ val box = Size(sizePx - stroke, sizePx - stroke)
+ val corner = Offset(stroke / 2, stroke / 2)
+ CanvasDrawScope().draw(Density(1f), LayoutDirection.Ltr, Canvas(image), Size(sizePx.toFloat(), sizePx.toFloat())) {
+ drawArc(Color(TRACK), 0f, 360f, false, corner, box, style = Stroke(stroke))
+ if (ring.fraction > 0f) {
+ drawArc(Color(ring.tone.argb), -90f, 360f * ring.fraction, false, corner, box, style = Stroke(stroke, cap = StrokeCap.Round))
+ }
+ }
+ return image.asAndroidBitmap()
+ }
+}
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/StatusPillWidget.kt b/android/app/src/main/kotlin/com/coucou/android/app/StatusPillWidget.kt
new file mode 100644
index 00000000..1186ad2f
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/app/StatusPillWidget.kt
@@ -0,0 +1,38 @@
+package com.coucou.android.app
+
+import android.appwidget.AppWidgetManager
+import android.appwidget.AppWidgetProvider
+import android.content.Context
+import android.widget.RemoteViews
+import com.coucou.android.R
+import com.coucou.android.core.WidgetContent
+
+/**
+ * The Status Pill widget: one slim line, a dot in the state's tone, the name of the most urgent agent and its state word.
+ * With no agent, the headline and the one clear line. Drawn by [WidgetHub] when something changes (updatePeriodMillis = 0).
+ * A tap opens that agent, or the app. It only opens things.
+ */
+class StatusPillWidget : AppWidgetProvider() {
+ override fun onUpdate(context: Context, manager: AppWidgetManager, ids: IntArray) =
+ WidgetHub.refresh(context, manager, ids) { c, w -> views(c, w) }
+
+ companion object {
+ fun views(context: Context, c: WidgetContent): RemoteViews {
+ val v = RemoteViews(context.packageName, R.layout.widget_pill)
+ WidgetHub.paint(v, R.id.pill_root, R.id.pill_tint, c.look)
+ val top = c.top
+ val name = top?.name ?: c.headline
+ val state = top?.stateWord ?: c.emptyLine.orEmpty()
+ v.setTextViewText(R.id.pill_name, name)
+ v.setTextViewText(R.id.pill_state, state)
+ v.setImageViewResource(R.id.pill_dot, if (top == null && !c.connected) R.drawable.ic_widget_offline else R.drawable.widget_dot)
+ v.setInt(R.id.pill_dot, "setColorFilter", (top?.tone ?: c.look).argb)
+ v.setContentDescription(R.id.pill_root, context.getString(R.string.widget_pill_cd, name, state))
+ v.setOnClickPendingIntent(
+ R.id.pill_root,
+ if (top != null) WidgetHub.openSession(context, WidgetHub.CODE_PILL, top.pillId) else WidgetHub.openApp(context, WidgetHub.CODE_PILL),
+ )
+ return v
+ }
+ }
+}
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/TodayStore.kt b/android/app/src/main/kotlin/com/coucou/android/app/TodayStore.kt
new file mode 100644
index 00000000..dd8ed49a
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/app/TodayStore.kt
@@ -0,0 +1,23 @@
+package com.coucou.android.app
+
+import android.content.Context
+import com.coucou.android.core.TodayStorage
+
+/** The day's count of finished tasks, in this app's private preferences. It stays on the phone: nothing sends it anywhere. */
+class TodayStore(context: Context) : TodayStorage {
+ private val prefs = context.getSharedPreferences("widget_today", Context.MODE_PRIVATE)
+
+ override fun load(): Pair<String, Int>? {
+ val day = prefs.getString(DAY, null) ?: return null
+ return day to prefs.getInt(COUNT, 0)
+ }
+
+ override fun save(day: String, count: Int) {
+ prefs.edit().putString(DAY, day).putInt(COUNT, count).apply()
+ }
+
+ private companion object {
+ const val DAY = "day"
+ const val COUNT = "count"
+ }
+}
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/TodayWidget.kt b/android/app/src/main/kotlin/com/coucou/android/app/TodayWidget.kt
new file mode 100644
index 00000000..90af1c91
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/app/TodayWidget.kt
@@ -0,0 +1,38 @@
+package com.coucou.android.app
+
+import android.appwidget.AppWidgetManager
+import android.appwidget.AppWidgetProvider
+import android.content.Context
+import android.content.Intent
+import android.widget.RemoteViews
+import com.coucou.android.R
+import com.coucou.android.core.WidgetContent
+
+/**
+ * The Today widget: how many agent tasks finished today. The count is kept on this phone only ([TodayStore]) and starts
+ * again at local midnight: the system's "the date changed" broadcast redraws it, so nothing runs on a timer. A tap opens the app.
+ */
+class TodayWidget : AppWidgetProvider() {
+ override fun onUpdate(context: Context, manager: AppWidgetManager, ids: IntArray) =
+ WidgetHub.refresh(context, manager, ids) { c, w -> views(c, w) }
+
+ override fun onReceive(context: Context, intent: Intent) {
+ super.onReceive(context, intent)
+ if (intent.action in DAY_CHANGED) WidgetHub.refreshAll(context)
+ }
+
+ companion object {
+ private val DAY_CHANGED = setOf(Intent.ACTION_DATE_CHANGED, Intent.ACTION_TIME_CHANGED, Intent.ACTION_TIMEZONE_CHANGED)
+
+ fun views(context: Context, c: WidgetContent): RemoteViews {
+ val v = RemoteViews(context.packageName, R.layout.widget_today)
+ WidgetHub.paint(v, R.id.today_root, R.id.today_tint, c.todayLook)
+ v.setImageViewBitmap(R.id.today_face, MochiBitmap.of(c.todayMood, WidgetHub.px(context, 72), glow = true))
+ v.setContentDescription(R.id.today_face, context.getString(R.string.widget_mochi_description, c.todayMood.key))
+ v.setTextViewText(R.id.today_count, c.today.toString())
+ v.setContentDescription(R.id.today_root, context.getString(R.string.widget_today_cd, c.today))
+ v.setOnClickPendingIntent(R.id.today_root, WidgetHub.openApp(context, WidgetHub.CODE_TODAY))
+ return v
+ }
+ }
+}
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/UsageRingWidget.kt b/android/app/src/main/kotlin/com/coucou/android/app/UsageRingWidget.kt
new file mode 100644
index 00000000..0947e692
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/app/UsageRingWidget.kt
@@ -0,0 +1,44 @@
+package com.coucou.android.app
+
+import android.appwidget.AppWidgetManager
+import android.appwidget.AppWidgetProvider
+import android.content.Context
+import android.view.View
+import android.widget.RemoteViews
+import com.coucou.android.R
+import com.coucou.android.core.WidgetContent
+
+/**
+ * The Usage Ring widget: a ring drawn to a bitmap for the plan usage the computer sent (its switch is on), with the
+ * percentage in the middle. If plan usage is off it says "Turn on plan usage in the app"; if the computer is not there, that
+ * it is waiting for it. A tap opens the app. It only shows what the computer already sent to this phone.
+ */
+class UsageRingWidget : AppWidgetProvider() {
+ override fun onUpdate(context: Context, manager: AppWidgetManager, ids: IntArray) =
+ WidgetHub.refresh(context, manager, ids) { c, w -> views(c, w) }
+
+ companion object {
+ fun views(context: Context, c: WidgetContent): RemoteViews {
+ val v = RemoteViews(context.packageName, R.layout.widget_ring)
+ val ring = c.ring
+ WidgetHub.paint(v, R.id.ring_root, R.id.ring_tint, ring?.tone ?: com.coucou.android.core.WidgetTone.MUTED)
+ if (ring != null) {
+ v.setViewVisibility(R.id.ring_area, View.VISIBLE)
+ v.setViewVisibility(R.id.ring_label, View.VISIBLE)
+ v.setViewVisibility(R.id.ring_off, View.GONE)
+ v.setImageViewBitmap(R.id.ring_image, RingBitmap.of(ring, WidgetHub.px(context, 96)))
+ v.setTextViewText(R.id.ring_pct, "${ring.pct}%")
+ v.setTextViewText(R.id.ring_label, ring.label)
+ v.setContentDescription(R.id.ring_root, context.getString(R.string.widget_ring_cd, ring.plan, ring.pct))
+ } else {
+ v.setViewVisibility(R.id.ring_area, View.GONE)
+ v.setViewVisibility(R.id.ring_label, View.GONE)
+ v.setViewVisibility(R.id.ring_off, View.VISIBLE)
+ v.setTextViewText(R.id.ring_off_text, if (c.connected) context.getString(R.string.widget_usage_off) else c.emptyLine.orEmpty())
+ v.setContentDescription(R.id.ring_root, context.getString(R.string.widget_ring_label))
+ }
+ v.setOnClickPendingIntent(R.id.ring_root, WidgetHub.openApp(context, WidgetHub.CODE_RING))
+ return v
+ }
+ }
+}
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/WaitingAlertWidget.kt b/android/app/src/main/kotlin/com/coucou/android/app/WaitingAlertWidget.kt
new file mode 100644
index 00000000..f4d8cef7
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/app/WaitingAlertWidget.kt
@@ -0,0 +1,36 @@
+package com.coucou.android.app
+
+import android.appwidget.AppWidgetManager
+import android.appwidget.AppWidgetProvider
+import android.content.Context
+import android.view.View
+import android.widget.RemoteViews
+import com.coucou.android.R
+import com.coucou.android.core.WidgetContent
+
+/**
+ * The Waiting Alert widget: calm when nothing waits for you; a bright orange "N waiting", an orange border and an anxious
+ * Mochi when something does. A tap opens the app and the sheet for the request rises by itself over whatever is on screen,
+ * so there is no deep link here. It only opens things: a request waits for you in the app, behind the fingerprint.
+ */
+class WaitingAlertWidget : AppWidgetProvider() {
+ override fun onUpdate(context: Context, manager: AppWidgetManager, ids: IntArray) =
+ WidgetHub.refresh(context, manager, ids) { c, w -> views(c, w) }
+
+ companion object {
+ fun views(context: Context, c: WidgetContent): RemoteViews {
+ val v = RemoteViews(context.packageName, R.layout.widget_alert)
+ WidgetHub.paint(v, R.id.alert_root, R.id.alert_tint, c.look)
+ v.setImageViewBitmap(R.id.alert_face, MochiBitmap.of(c.mood, WidgetHub.px(context, 84), glow = true))
+ v.setContentDescription(R.id.alert_face, context.getString(R.string.widget_mochi_description, c.mood.key))
+ val waiting = c.waiting > 0
+ v.setViewVisibility(R.id.alert_count, if (waiting) View.VISIBLE else View.GONE)
+ v.setViewVisibility(R.id.alert_calm, if (waiting) View.GONE else View.VISIBLE)
+ v.setTextViewText(if (waiting) R.id.alert_count else R.id.alert_calm, c.alertLine)
+ v.setTextViewText(R.id.alert_sub, c.alertSub)
+ if (waiting) v.setContentDescription(R.id.alert_count, context.getString(R.string.widget_badge_description, c.waiting))
+ v.setOnClickPendingIntent(R.id.alert_root, WidgetHub.openApp(context, WidgetHub.CODE_ALERT))
+ return v
+ }
+ }
+}
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 9c2a0a3f..77449422 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
@@ -12,12 +12,11 @@ import android.widget.RemoteViews
import com.coucou.android.MainActivity
import com.coucou.android.R
import com.coucou.android.core.WidgetContent
-import com.coucou.android.core.WidgetData
import com.coucou.android.core.WidgetTone
import kotlin.math.roundToInt
/**
- * The one place that pushes the Solo and List widgets. The app calls [update] on every change of sessions, requests and
+ * The one place that pushes the Widgets (Solo, List, Mochi Big, Status Pill, Waiting Alert, Usage Ring, Today and Mochi Mood). The app calls [update] on every change of sessions, requests and
* link (from AppModel.pushGlance); a push whose content is the same as the last one is dropped, so a change that does not
* show on a widget costs nothing. There is no timer: a widget is drawn when something changes or when it is added.
*/
@@ -27,11 +26,17 @@ object WidgetHub {
private val widgets = listOf(
Kind(SoloWidget::class.java) { c, w -> SoloWidget.views(c, w) },
Kind(ListWidget::class.java) { c, w -> ListWidget.views(c, w) },
+ Kind(MochiBigWidget::class.java) { c, w -> MochiBigWidget.views(c, w) },
+ Kind(StatusPillWidget::class.java) { c, w -> StatusPillWidget.views(c, w) },
+ Kind(WaitingAlertWidget::class.java) { c, w -> WaitingAlertWidget.views(c, w) },
+ Kind(UsageRingWidget::class.java) { c, w -> UsageRingWidget.views(c, w) },
+ Kind(TodayWidget::class.java) { c, w -> TodayWidget.views(c, w) },
+ Kind(MoodWidget::class.java) { c, w -> MoodWidget.views(c, w) },
)
private var last: WidgetContent? = null
- /** Pushes [content] to every Solo and List widget on the home screen (none: nothing happens). */
+ /** Pushes [content] to every Widget of the family on the home screen (none: nothing happens). */
@Synchronized
fun update(context: Context, content: WidgetContent) {
if (content == last) return
@@ -52,9 +57,7 @@ object WidgetHub {
/** Draws the widgets the system just created or resized, from what the app says now. */
fun refresh(context: Context, manager: AppWidgetManager, ids: IntArray, views: (Context, WidgetContent) -> RemoteViews) {
- val model = (context.applicationContext as CoucouApp).model
- val content = WidgetData.build(model.glance(), model.sessions, model::agentName)
- val rendered = views(context, content)
+ val rendered = views(context, current(context))
for (id in ids) runCatching { manager.updateAppWidget(id, rendered) }
}
@@ -90,6 +93,16 @@ object WidgetHub {
WidgetTone.TROUBLE -> R.drawable.widget_tint_trouble
}
+ /** What the app says now. */
+ private fun current(context: Context): WidgetContent = (context.applicationContext as CoucouApp).model.widgetContent()
+
+ /** Draws every Widget again from what the app says now, even if nothing looks different (a new day, a new time zone). */
+ @Synchronized
+ fun refreshAll(context: Context) {
+ last = null
+ update(context, current(context))
+ }
+
/** Opens the app on Home. */
fun openApp(context: Context, code: Int): PendingIntent {
val open = Intent(context, MainActivity::class.java)
@@ -112,4 +125,10 @@ object WidgetHub {
const val CODE_SOLO = 0x5100
const val CODE_LIST_HEADER = 0x5200
const val CODE_LIST_ROW = 0x5300
+ const val CODE_BIG = 0x5400
+ const val CODE_PILL = 0x5500
+ const val CODE_ALERT = 0x5600
+ const val CODE_RING = 0x5700
+ const val CODE_TODAY = 0x5800
+ const val CODE_MOOD = 0x5900
}
diff --git a/android/app/src/main/kotlin/com/coucou/android/core/TodayCounter.kt b/android/app/src/main/kotlin/com/coucou/android/core/TodayCounter.kt
new file mode 100644
index 00000000..371b9a25
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/core/TodayCounter.kt
@@ -0,0 +1,29 @@
+package com.coucou.android.core
+
+import java.time.LocalDate
+
+/** Where the count of the day is kept: one day and one number. */
+interface TodayStorage {
+ fun load(): Pair<String, Int>?
+ fun save(day: String, count: Int)
+}
+
+/**
+ * How many agent tasks finished today, counted on this phone only. A new local day starts at zero without any timer: the
+ * day is compared when the count is read or raised, so after midnight the first read says 0. [day] is injectable for tests.
+ */
+class TodayCounter(private val storage: TodayStorage, private val day: () -> String = { LocalDate.now().toString() }) {
+ @Synchronized
+ fun count(): Int {
+ val (saved, n) = storage.load() ?: return 0
+ return if (saved == day()) n else 0
+ }
+
+ /** One more task finished; returns the new count. */
+ @Synchronized
+ fun increment(): Int {
+ val n = count() + 1
+ storage.save(day(), n)
+ return n
+ }
+}
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 b2d68986..8a6a5ec1 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
@@ -1,6 +1,7 @@
package com.coucou.android.core
import com.coucou.android.link.SessionInfo
+import com.coucou.android.link.UsageSnapshot
import com.coucou.android.mochi.BotState
import com.coucou.android.mochi.MochiConst
import com.coucou.android.mochi.Rgb
@@ -41,8 +42,24 @@ data class WidgetTile(val pillId: String, val name: String, val state: BotState,
val tone: WidgetTone get() = WidgetTone.of(state)
}
+/** The plan usage a ring shows: which plan and window, and how much of it is used. */
+data class UsageRing(val plan: String, val window: String, val pct: Int) {
+ /** 0 to 1, for the arc. */
+ val fraction: Float get() = pct.coerceIn(0, 100) / 100f
+
+ /** "Claude · 5 h". */
+ val label: String get() = "$plan · $window"
+
+ /** Green while there is room, orange from half, red from four fifths: the same rule as Home ([PlanText]). */
+ val tone: WidgetTone get() = when (PlanText.level(pct)) {
+ PlanText.Level.LOW -> WidgetTone.DONE
+ PlanText.Level.MEDIUM -> WidgetTone.ATTENTION
+ PlanText.Level.HIGH -> WidgetTone.TROUBLE
+ }
+}
+
/**
- * Everything the Solo and List widgets draw, as plain data so two pushes can be compared and the identical one skipped.
+ * Everything the Widgets draw, as plain data so two pushes can be compared and the identical one skipped.
* Built from the same sessions, order and wording as [GlanceBuilder], so the widgets never say anything the notification,
* the tile and the first widget do not.
*/
@@ -54,6 +71,10 @@ data class WidgetContent(
val waiting: Int,
/** Most urgent first. Empty while the computer is not connected. */
val tiles: List<WidgetTile>,
+ /** The plan usage for the ring; null when the computer does not send it (its switch is off) or is not connected. */
+ val ring: UsageRing? = null,
+ /** Agent tasks finished today, counted on this phone only. */
+ val today: Int = 0,
) {
/** The agent Solo shows. */
val top: WidgetTile? get() = tiles.firstOrNull()
@@ -65,6 +86,44 @@ data class WidgetContent(
else -> "No agents running"
}
+ /** What Mochi says in his speech bubble: the agent's name and its state, nothing about what it is doing. */
+ val bubble: String get() {
+ val t = top ?: return emptyLine.orEmpty()
+ if (waiting > 1) return "$waiting things are waiting for you"
+ return when (t.state) {
+ BotState.APPROVAL -> "${t.name} is waiting for you"
+ BotState.QUESTION -> "${t.name} has a question"
+ BotState.WORKING -> "${t.name} is working"
+ BotState.THINKING -> "${t.name} is thinking"
+ BotState.SEARCHING -> "${t.name} is searching"
+ BotState.FINISHED -> "${t.name} is done"
+ BotState.ERROR -> "${t.name} stopped on an error"
+ BotState.RATELIMIT -> "${t.name} hit a limit"
+ BotState.DIZZY -> "${t.name} needs a look"
+ BotState.IDLE, BotState.SLEEPING -> "${t.name} is idle"
+ }
+ }
+
+ /** The Waiting Alert's line: "2 waiting" in orange, or a calm word. */
+ val alertLine: String get() = when {
+ !connected -> "Not connected"
+ waiting > 0 -> "$waiting waiting"
+ else -> "All calm"
+ }
+
+ /** The line under the alert: who is waiting, or why there is nothing to say. */
+ val alertSub: String get() = when {
+ !connected -> "Waiting for your computer"
+ waiting > 0 -> top?.name.orEmpty()
+ else -> "Nothing needs you"
+ }
+
+ /** Mochi's face on the Today widget: pleased once something finished today, calm before. */
+ val todayMood: BotState get() = if (today > 0) BotState.FINISHED else BotState.IDLE
+
+ /** The Today widget glows green once something finished today. */
+ val todayLook: WidgetTone get() = if (today > 0) WidgetTone.DONE else WidgetTone.MUTED
+
/** 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
@@ -81,12 +140,31 @@ object WidgetData {
const val MAX_ROWS = 5
private val FALLBACK = GlanceTone.CALM.argb
- fun build(glance: Glance, sessions: List<SessionInfo>, nameOf: (String) -> String): WidgetContent {
+ fun build(
+ glance: Glance,
+ sessions: List<SessionInfo>,
+ nameOf: (String) -> String,
+ usage: UsageSnapshot? = null,
+ today: Int = 0,
+ nowMs: Long = 0L,
+ ): WidgetContent {
val tiles = if (!glance.connected) emptyList() else sessions
.sortedBy { GlanceBuilder.rank(it.state) }
.take(MAX_ROWS)
.map { WidgetTile(it.pillId, nameOf(it.pillId), it.state, GlanceBuilder.lineOf(it), colourOf(it)) }
- return WidgetContent(glance.headline, glance.tone, glance.connected, glance.waiting, tiles)
+ val ring = if (glance.connected) ring(usage, nowMs) else null
+ return WidgetContent(glance.headline, glance.tone, glance.connected, glance.waiting, tiles, ring, today.coerceAtLeast(0))
+ }
+
+ /** Claude's five-hour window first, then its week, then Codex; null when the computer sent none of them. */
+ fun ring(usage: UsageSnapshot?, nowMs: Long): UsageRing? {
+ usage ?: return null
+ for ((name, plan) in listOf("Claude" to usage.claude, "Codex" to usage.codex)) {
+ plan ?: continue
+ plan.fiveHour?.let { return UsageRing(name, "5 h", PlanText.effectivePct(it, nowMs)) }
+ plan.sevenDay?.let { return UsageRing(name, "week", PlanText.effectivePct(it, nowMs)) }
+ }
+ return null
}
/** The session's own colour, else its pill's, else grey. */
diff --git a/android/app/src/main/res/layout/widget_alert.xml b/android/app/src/main/res/layout/widget_alert.xml
new file mode 100644
index 00000000..b9f922c6
--- /dev/null
+++ b/android/app/src/main/res/layout/widget_alert.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The Waiting Alert widget: calm when nothing waits, a bright orange count (and an orange border) when something does. Plain RemoteViews. -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/alert_root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@drawable/widget_card">
+
+ <FrameLayout
+ android:id="@+id/alert_tint"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="1dp"
+ android:background="@drawable/widget_tint_muted" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical"
+ android:padding="10dp">
+
+ <ImageView
+ android:id="@+id/alert_face"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:contentDescription="@string/widget_alert_label"
+ android:scaleType="fitCenter" />
+
+ <TextView
+ android:id="@+id/alert_count"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:gravity="center"
+ android:maxLines="1"
+ android:textColor="@color/widget_tone_attention"
+ android:textSize="24sp"
+ android:textStyle="bold"
+ android:visibility="gone" />
+
+ <TextView
+ android:id="@+id/alert_calm"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:gravity="center"
+ android:maxLines="1"
+ android:textColor="@color/widget_text"
+ android:textSize="@dimen/widget_text_name"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/alert_sub"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:gravity="center"
+ android:maxLines="1"
+ android:textColor="@color/widget_text_secondary"
+ android:textSize="@dimen/widget_text_state" />
+ </LinearLayout>
+</FrameLayout>
diff --git a/android/app/src/main/res/layout/widget_big.xml b/android/app/src/main/res/layout/widget_big.xml
new file mode 100644
index 00000000..57abc203
--- /dev/null
+++ b/android/app/src/main/res/layout/widget_big.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The Mochi Big widget: a large Mochi with a glow, a speech bubble that says who is doing what in plain words (never a command or a file), and the agent's name and state. Plain RemoteViews. -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/big_root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@drawable/widget_card">
+
+ <FrameLayout
+ android:id="@+id/big_tint"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="1dp"
+ android:background="@drawable/widget_tint_muted" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center_horizontal"
+ android:orientation="vertical"
+ android:padding="14dp">
+
+ <TextView
+ android:id="@+id/big_bubble"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/widget_bubble"
+ android:ellipsize="end"
+ android:gravity="center"
+ android:maxLines="2"
+ android:paddingStart="16dp"
+ android:paddingTop="10dp"
+ android:paddingEnd="16dp"
+ android:paddingBottom="10dp"
+ android:textColor="@color/widget_bubble_text"
+ android:textSize="@dimen/widget_text_name"
+ android:textStyle="bold" />
+
+ <ImageView
+ android:layout_width="20dp"
+ android:layout_height="10dp"
+ android:importantForAccessibility="no"
+ android:src="@drawable/widget_bubble_tail" />
+
+ <ImageView
+ android:id="@+id/big_mochi"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:contentDescription="@string/widget_big_label"
+ android:scaleType="fitCenter" />
+
+ <LinearLayout
+ android:id="@+id/big_row"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical"
+ android:orientation="horizontal">
+
+ <ImageView
+ android:id="@+id/big_dot"
+ android:layout_width="@dimen/widget_dot"
+ android:layout_height="@dimen/widget_dot"
+ android:importantForAccessibility="no"
+ android:src="@drawable/widget_dot" />
+
+ <TextView
+ android:id="@+id/big_name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="8dp"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:textColor="@color/widget_text"
+ android:textSize="@dimen/widget_text_name"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/big_state"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="8dp"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:textColor="@color/widget_text_secondary"
+ android:textSize="@dimen/widget_text_state" />
+ </LinearLayout>
+ </LinearLayout>
+
+ <TextView
+ android:id="@+id/big_badge"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top|end"
+ android:layout_margin="12dp"
+ android:background="@drawable/widget_badge_bg"
+ android:gravity="center"
+ android:minWidth="22dp"
+ android:paddingStart="6dp"
+ android:paddingEnd="6dp"
+ android:textColor="#FF1C1C1E"
+ android:textSize="@dimen/widget_text_secondary"
+ android:textStyle="bold"
+ android:visibility="gone" />
+</FrameLayout>
diff --git a/android/app/src/main/res/layout/widget_list.xml b/android/app/src/main/res/layout/widget_list.xml
index 46c5d5f3..66f8433a 100644
--- a/android/app/src/main/res/layout/widget_list.xml
+++ b/android/app/src/main/res/layout/widget_list.xml
@@ -87,6 +87,7 @@
<ImageView
android:id="@+id/list_face0"
+ android:contentDescription="@string/widget_list_label"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="8dp"
@@ -144,6 +145,7 @@
<ImageView
android:id="@+id/list_face1"
+ android:contentDescription="@string/widget_list_label"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="8dp"
@@ -201,6 +203,7 @@
<ImageView
android:id="@+id/list_face2"
+ android:contentDescription="@string/widget_list_label"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="8dp"
@@ -258,6 +261,7 @@
<ImageView
android:id="@+id/list_face3"
+ android:contentDescription="@string/widget_list_label"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="8dp"
@@ -315,6 +319,7 @@
<ImageView
android:id="@+id/list_face4"
+ android:contentDescription="@string/widget_list_label"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="8dp"
@@ -367,6 +372,7 @@
<ImageView
android:id="@+id/list_empty_face"
+ android:contentDescription="@string/widget_list_label"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
diff --git a/android/app/src/main/res/layout/widget_mood.xml b/android/app/src/main/res/layout/widget_mood.xml
new file mode 100644
index 00000000..85359e64
--- /dev/null
+++ b/android/app/src/main/res/layout/widget_mood.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The Mochi Mood widget: only Mochi's face in the current state, with his glow. Plain RemoteViews. -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/mood_root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@drawable/widget_card">
+
+ <FrameLayout
+ android:id="@+id/mood_tint"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="1dp"
+ android:background="@drawable/widget_tint_muted" />
+
+ <ImageView
+ android:id="@+id/mood_face"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:contentDescription="@string/widget_mood_label"
+ android:padding="4dp"
+ android:scaleType="fitCenter" />
+</FrameLayout>
diff --git a/android/app/src/main/res/layout/widget_pill.xml b/android/app/src/main/res/layout/widget_pill.xml
new file mode 100644
index 00000000..6f45aebb
--- /dev/null
+++ b/android/app/src/main/res/layout/widget_pill.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The Status Pill widget: one slim line with a dot in the state's tone, the agent's name and its state word. Plain RemoteViews. -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/pill_root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@drawable/widget_card">
+
+ <FrameLayout
+ android:id="@+id/pill_tint"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="1dp"
+ android:background="@drawable/widget_tint_muted" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center_vertical"
+ android:orientation="horizontal"
+ android:paddingStart="18dp"
+ android:paddingEnd="18dp">
+
+ <ImageView
+ android:id="@+id/pill_dot"
+ android:layout_width="@dimen/widget_dot"
+ android:layout_height="@dimen/widget_dot"
+ android:importantForAccessibility="no"
+ android:src="@drawable/widget_dot" />
+
+ <TextView
+ android:id="@+id/pill_name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="10dp"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:textColor="@color/widget_text"
+ android:textSize="@dimen/widget_text_name"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/pill_state"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="10dp"
+ android:layout_weight="1"
+ android:ellipsize="end"
+ android:gravity="end"
+ android:maxLines="1"
+ android:textColor="@color/widget_text_secondary"
+ android:textSize="@dimen/widget_text_state" />
+ </LinearLayout>
+</FrameLayout>
diff --git a/android/app/src/main/res/layout/widget_ring.xml b/android/app/src/main/res/layout/widget_ring.xml
new file mode 100644
index 00000000..45d2cede
--- /dev/null
+++ b/android/app/src/main/res/layout/widget_ring.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The Usage Ring widget: a ring bitmap for the plan usage with the percentage in its middle; or one clear line when plan usage is off. Plain RemoteViews. -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/ring_root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@drawable/widget_card">
+
+ <FrameLayout
+ android:id="@+id/ring_tint"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="1dp"
+ android:background="@drawable/widget_tint_muted" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical"
+ android:padding="10dp">
+
+ <FrameLayout
+ android:id="@+id/ring_area"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1">
+
+ <ImageView
+ android:id="@+id/ring_image"
+ android:contentDescription="@string/widget_ring_label"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:scaleType="fitCenter" />
+
+ <TextView
+ android:id="@+id/ring_pct"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:maxLines="1"
+ android:textColor="@color/widget_text"
+ android:textSize="24sp"
+ android:textStyle="bold" />
+ </FrameLayout>
+
+ <TextView
+ android:id="@+id/ring_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:gravity="center"
+ android:maxLines="1"
+ android:textColor="@color/widget_text_secondary"
+ android:textSize="@dimen/widget_text_state" />
+
+ <LinearLayout
+ android:id="@+id/ring_off"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical"
+ android:visibility="gone">
+
+ <ImageView
+ android:id="@+id/ring_off_icon"
+ android:layout_width="28dp"
+ android:layout_height="28dp"
+ android:importantForAccessibility="no"
+ android:src="@drawable/ic_widget_offline" />
+
+ <TextView
+ android:id="@+id/ring_off_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="6dp"
+ android:ellipsize="end"
+ android:gravity="center"
+ android:maxLines="3"
+ android:textColor="@color/widget_text_soft"
+ android:textSize="@dimen/widget_text_note"
+ android:textStyle="bold" />
+ </LinearLayout>
+ </LinearLayout>
+</FrameLayout>
diff --git a/android/app/src/main/res/layout/widget_today.xml b/android/app/src/main/res/layout/widget_today.xml
new file mode 100644
index 00000000..de3d0c2d
--- /dev/null
+++ b/android/app/src/main/res/layout/widget_today.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The Today widget: how many agent tasks finished today, counted on this phone only. Plain RemoteViews. -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/today_root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@drawable/widget_card">
+
+ <FrameLayout
+ android:id="@+id/today_tint"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="1dp"
+ android:background="@drawable/widget_tint_muted" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical"
+ android:padding="10dp">
+
+ <ImageView
+ android:id="@+id/today_face"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:contentDescription="@string/widget_today_label"
+ android:scaleType="fitCenter" />
+
+ <TextView
+ android:id="@+id/today_count"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:maxLines="1"
+ android:textColor="@color/widget_text"
+ android:textSize="34sp"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/today_unit"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:maxLines="1"
+ android:text="@string/widget_today_unit"
+ android:textColor="@color/widget_text_secondary"
+ android:textSize="@dimen/widget_text_state" />
+ </LinearLayout>
+</FrameLayout>
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index 6b117617..8e9fb273 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -17,6 +17,23 @@
<string name="widget_list_description">Your agents and what each one is doing, without opening Coucou.</string>
<string name="widget_mochi_description">Mochi, %1$s</string>
<string name="widget_badge_description">%1$d waiting for you</string>
+ <string name="widget_big_label">Coucou Mochi Big</string>
+ <string name="widget_big_description">A large Mochi with a speech bubble that says what your agent is doing, in plain words.</string>
+ <string name="widget_pill_label">Coucou Status Pill</string>
+ <string name="widget_pill_description">One slim line: your most urgent agent and how it is doing.</string>
+ <string name="widget_alert_label">Coucou Waiting Alert</string>
+ <string name="widget_alert_description">Calm when nothing waits for you, bright orange when an agent does.</string>
+ <string name="widget_ring_label">Coucou Usage Ring</string>
+ <string name="widget_ring_description">How much of your Claude or Codex plan is used.</string>
+ <string name="widget_today_label">Coucou Today</string>
+ <string name="widget_today_description">How many agent tasks finished today, counted on this phone only.</string>
+ <string name="widget_mood_label">Coucou Mochi Mood</string>
+ <string name="widget_mood_description">Just Mochi\'s face, in the mood of your agents.</string>
+ <string name="widget_today_unit">done today</string>
+ <string name="widget_usage_off">Turn on plan usage in the app</string>
+ <string name="widget_ring_cd">%1$s plan usage, %2$d percent used</string>
+ <string name="widget_today_cd">%1$d agent tasks finished today</string>
+ <string name="widget_pill_cd">%1$s, %2$s</string>
<string name="status_connected">Connected</string>
<string name="status_connecting">Connecting…</string>
<string name="status_not_connected">Not connected</string>
diff --git a/android/app/src/main/res/xml/coucou_alert_widget_info.xml b/android/app/src/main/res/xml/coucou_alert_widget_info.xml
new file mode 100644
index 00000000..9e8477f8
--- /dev/null
+++ b/android/app/src/main/res/xml/coucou_alert_widget_info.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="110dp"
+ android:minHeight="110dp"
+ android:targetCellWidth="2"
+ android:targetCellHeight="2"
+ android:minResizeWidth="110dp"
+ android:minResizeHeight="110dp"
+ android:resizeMode="horizontal|vertical"
+ android:updatePeriodMillis="0"
+ android:widgetCategory="home_screen"
+ android:initialLayout="@layout/widget_alert"
+ android:description="@string/widget_alert_description" />
diff --git a/android/app/src/main/res/xml/coucou_big_widget_info.xml b/android/app/src/main/res/xml/coucou_big_widget_info.xml
new file mode 100644
index 00000000..9959baff
--- /dev/null
+++ b/android/app/src/main/res/xml/coucou_big_widget_info.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="250dp"
+ android:minHeight="250dp"
+ android:targetCellWidth="4"
+ android:targetCellHeight="4"
+ android:minResizeWidth="180dp"
+ android:minResizeHeight="180dp"
+ android:resizeMode="horizontal|vertical"
+ android:updatePeriodMillis="0"
+ android:widgetCategory="home_screen"
+ android:initialLayout="@layout/widget_big"
+ android:description="@string/widget_big_description" />
diff --git a/android/app/src/main/res/xml/coucou_mood_widget_info.xml b/android/app/src/main/res/xml/coucou_mood_widget_info.xml
new file mode 100644
index 00000000..eee44c41
--- /dev/null
+++ b/android/app/src/main/res/xml/coucou_mood_widget_info.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="40dp"
+ android:minHeight="40dp"
+ android:targetCellWidth="1"
+ android:targetCellHeight="1"
+ android:resizeMode="none"
+ android:updatePeriodMillis="0"
+ android:widgetCategory="home_screen"
+ android:initialLayout="@layout/widget_mood"
+ android:description="@string/widget_mood_description" />
diff --git a/android/app/src/main/res/xml/coucou_pill_widget_info.xml b/android/app/src/main/res/xml/coucou_pill_widget_info.xml
new file mode 100644
index 00000000..697fdd1a
--- /dev/null
+++ b/android/app/src/main/res/xml/coucou_pill_widget_info.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="250dp"
+ android:minHeight="40dp"
+ android:targetCellWidth="4"
+ android:targetCellHeight="1"
+ android:minResizeWidth="180dp"
+ android:minResizeHeight="40dp"
+ android:resizeMode="horizontal"
+ android:updatePeriodMillis="0"
+ android:widgetCategory="home_screen"
+ android:initialLayout="@layout/widget_pill"
+ android:description="@string/widget_pill_description" />
diff --git a/android/app/src/main/res/xml/coucou_ring_widget_info.xml b/android/app/src/main/res/xml/coucou_ring_widget_info.xml
new file mode 100644
index 00000000..80be9fd5
--- /dev/null
+++ b/android/app/src/main/res/xml/coucou_ring_widget_info.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="110dp"
+ android:minHeight="110dp"
+ android:targetCellWidth="2"
+ android:targetCellHeight="2"
+ android:minResizeWidth="110dp"
+ android:minResizeHeight="110dp"
+ android:resizeMode="horizontal|vertical"
+ android:updatePeriodMillis="0"
+ android:widgetCategory="home_screen"
+ android:initialLayout="@layout/widget_ring"
+ android:description="@string/widget_ring_description" />
diff --git a/android/app/src/main/res/xml/coucou_today_widget_info.xml b/android/app/src/main/res/xml/coucou_today_widget_info.xml
new file mode 100644
index 00000000..44595e02
--- /dev/null
+++ b/android/app/src/main/res/xml/coucou_today_widget_info.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="110dp"
+ android:minHeight="110dp"
+ android:targetCellWidth="2"
+ android:targetCellHeight="2"
+ android:minResizeWidth="110dp"
+ android:minResizeHeight="110dp"
+ android:resizeMode="horizontal|vertical"
+ android:updatePeriodMillis="0"
+ android:widgetCategory="home_screen"
+ android:initialLayout="@layout/widget_today"
+ android:description="@string/widget_today_description" />
diff --git a/android/app/src/test/kotlin/com/coucou/android/PendingLaunchTest.kt b/android/app/src/test/kotlin/com/coucou/android/PendingLaunchTest.kt
index 1e8718b3..ae007ff7 100644
--- a/android/app/src/test/kotlin/com/coucou/android/PendingLaunchTest.kt
+++ b/android/app/src/test/kotlin/com/coucou/android/PendingLaunchTest.kt
@@ -79,7 +79,10 @@ class PendingLaunchTest {
@Test fun everyOtherComponentWithAnIntentFilterIsTheLauncher() {
val m = manifest()
val exported = Regex("""android:name="([^"]+)"[^>]*android:exported="true"""").findAll(m).map { it.groupValues[1] }.toSet()
- assertEquals(setOf(".MainActivity", ".app.GlanceWidget", ".app.GlanceTile", ".app.SoloWidget", ".app.ListWidget"), exported)
+ assertEquals(setOf(
+ ".MainActivity", ".app.GlanceWidget", ".app.GlanceTile", ".app.SoloWidget", ".app.ListWidget", ".app.MochiBigWidget",
+ ".app.StatusPillWidget", ".app.WaitingAlertWidget", ".app.UsageRingWidget", ".app.TodayWidget", ".app.MoodWidget",
+ ), exported)
}
@Test fun aWidgetRowAsksForASessionOnce() {
diff --git a/android/app/src/test/kotlin/com/coucou/android/TodayCounterTest.kt b/android/app/src/test/kotlin/com/coucou/android/TodayCounterTest.kt
new file mode 100644
index 00000000..b20591b0
--- /dev/null
+++ b/android/app/src/test/kotlin/com/coucou/android/TodayCounterTest.kt
@@ -0,0 +1,57 @@
+package com.coucou.android
+
+import com.coucou.android.core.TodayCounter
+import com.coucou.android.core.TodayStorage
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import java.io.File
+
+class TodayCounterTest {
+ private class Memory : TodayStorage {
+ var saved: Pair<String, Int>? = null
+ override fun load() = saved
+ override fun save(day: String, count: Int) { saved = day to count }
+ }
+
+ private var day = "2026-10-13"
+ private val storage = Memory()
+ private val counter = TodayCounter(storage) { day }
+
+ @Test fun startsAtZero() = assertEquals(0, counter.count())
+
+ @Test fun countsUpDuringTheDay() {
+ assertEquals(1, counter.increment())
+ assertEquals(2, counter.increment())
+ assertEquals(2, counter.count())
+ assertEquals("2026-10-13" to 2, storage.saved)
+ }
+
+ @Test fun readsZeroAfterMidnightWithoutAnythingRunning() {
+ counter.increment(); counter.increment()
+ day = "2026-10-14"
+ assertEquals(0, counter.count())
+ }
+
+ @Test fun theFirstTaskOfTheNewDayStartsAtOne() {
+ repeat(3) { counter.increment() }
+ day = "2026-10-14"
+ assertEquals(1, counter.increment())
+ assertEquals("2026-10-14" to 1, storage.saved)
+ }
+
+ @Test fun anOldDayNeverComesBack() {
+ counter.increment()
+ day = "2026-10-12"
+ assertEquals("a day that is not today is not today", 0, counter.count())
+ }
+
+ @Test fun itIsKeptOnThePhoneOnly() {
+ val store = File("src/main/kotlin/com/coucou/android/app/TodayStore.kt")
+ if (store.exists()) {
+ val src = store.readText()
+ assertTrue(src.contains("getSharedPreferences(\"widget_today\""))
+ for (net in listOf("http", "Socket", "link.", "Protocol")) assertTrue(net, !src.contains(net))
+ }
+ }
+}
diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.kt
index 6747d0c5..fce6f32b 100644
--- a/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.kt
+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.kt
@@ -5,7 +5,12 @@ import com.coucou.android.core.GlanceBuilder
import com.coucou.android.core.GlanceTone
import com.coucou.android.core.WidgetData
import com.coucou.android.link.LinkState
+import com.coucou.android.link.PlanUsage
+import com.coucou.android.link.PlanWindow
import com.coucou.android.link.SessionInfo
+import com.coucou.android.link.UsageSnapshot
+import com.coucou.android.core.UsageRing
+import com.coucou.android.core.WidgetTone
import com.coucou.android.mochi.BotState
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@@ -22,7 +27,7 @@ class WidgetDataTest {
GlanceBuilder.build(true, link, "PC", sessions, approvals) { names[it] ?: "An agent" }
private fun build(sessions: List<SessionInfo>, approvals: Int = 0, link: LinkState = LinkState.CONNECTED) =
- WidgetData.build(glance(sessions, approvals, link), sessions) { names[it] ?: "An agent" }
+ WidgetData.build(glance(sessions, approvals, link), sessions, nameOf = { names[it] ?: "An agent" })
@Test fun theMostUrgentAgentComesFirstLikeOnTheOtherSurfaces() {
val sessions = listOf(s("agent_amp", BotState.IDLE), s("agent_codex", BotState.WORKING), s("agent_gemini", BotState.APPROVAL))
@@ -109,4 +114,76 @@ class WidgetDataTest {
assertEquals(com.coucou.android.core.WidgetTone.ATTENTION, t[0].tone)
assertEquals(com.coucou.android.core.WidgetTone.DONE, t[1].tone)
}
+
+ // ── The speech bubble, the alert, the ring and the day's count ──────────────────────────────────
+
+ @Test fun theBubbleSaysWhoAndHowNeverWhat() {
+ fun bubble(state: BotState, approvals: Int = 0) = build(listOf(s("agent_codex", state, status = "editing secret.txt")), approvals).bubble
+ assertEquals("Codex is working", bubble(BotState.WORKING))
+ assertEquals("Codex is thinking", bubble(BotState.THINKING))
+ assertEquals("Codex is searching", bubble(BotState.SEARCHING))
+ assertEquals("Codex is waiting for you", bubble(BotState.APPROVAL, approvals = 1))
+ assertEquals("Codex has a question", bubble(BotState.QUESTION))
+ assertEquals("Codex is done", bubble(BotState.FINISHED))
+ assertEquals("Codex stopped on an error", bubble(BotState.ERROR))
+ assertEquals("Codex hit a limit", bubble(BotState.RATELIMIT))
+ assertEquals("Codex needs a look", bubble(BotState.DIZZY))
+ assertEquals("Codex is idle", bubble(BotState.IDLE))
+ for (st in BotState.values()) assertFalse(bubble(st).contains("secret"))
+ }
+
+ @Test fun theBubbleCountsWhatWaitsAndSpeaksWhenThereIsNoAgent() {
+ assertEquals("3 things are waiting for you", build(listOf(s("agent_codex", BotState.APPROVAL)), approvals = 3).bubble)
+ assertEquals("No agents running", build(emptyList()).bubble)
+ assertEquals("Waiting for your computer", build(emptyList(), link = LinkState.DISCONNECTED).bubble)
+ }
+
+ @Test fun theAlertIsCalmUntilSomethingWaits() {
+ assertEquals("All calm", build(emptyList()).alertLine)
+ assertEquals("1 waiting", build(listOf(s("agent_codex", BotState.APPROVAL)), approvals = 1).alertLine)
+ assertEquals("3 waiting", build(listOf(s("agent_codex", BotState.QUESTION)), approvals = 2).alertLine)
+ assertEquals("Not connected", build(emptyList(), link = LinkState.DISCONNECTED).alertLine)
+ assertEquals(WidgetTone.ATTENTION, build(listOf(s("agent_codex", BotState.APPROVAL)), approvals = 1).look)
+ assertEquals(WidgetTone.MUTED, build(emptyList()).look)
+ }
+
+ private val now = 1_000_000L
+ private fun usage(claude5: Int? = null, claudeWeek: Int? = null, codex5: Int? = null, resets: Long = now + 3_600_000) = UsageSnapshot(
+ if (claude5 != null || claudeWeek != null) PlanUsage(claude5?.let { PlanWindow(it, resets) }, claudeWeek?.let { PlanWindow(it, resets) }) else null,
+ codex5?.let { PlanUsage(PlanWindow(it, resets), null) },
+ )
+
+ private fun built(u: UsageSnapshot?, link: LinkState = LinkState.CONNECTED) =
+ WidgetData.build(glance(emptyList(), 0, link), emptyList(), { "x" }, u, today = 0, nowMs = now)
+
+ @Test fun theRingPrefersClaudesFiveHoursThenItsWeekThenCodex() {
+ assertEquals(UsageRing("Claude", "5 h", 42), built(usage(claude5 = 42, claudeWeek = 10, codex5 = 90)).ring)
+ assertEquals(UsageRing("Claude", "week", 10), built(usage(claudeWeek = 10, codex5 = 90)).ring)
+ assertEquals(UsageRing("Codex", "5 h", 90), built(usage(codex5 = 90)).ring)
+ assertNull(built(usage()).ring)
+ assertNull("the switch is off", built(null).ring)
+ }
+
+ @Test fun aWindowThatHasResetCountsAsZeroAndNothingShowsWhenNotConnected() {
+ assertEquals(0, built(usage(claude5 = 80, resets = now - 1)).ring!!.pct)
+ assertNull(built(usage(claude5 = 42), LinkState.DISCONNECTED).ring)
+ }
+
+ @Test fun theRingIsGreenThenOrangeThenRedLikeHome() {
+ assertEquals(WidgetTone.DONE, UsageRing("Claude", "5 h", 49).tone)
+ assertEquals(WidgetTone.ATTENTION, UsageRing("Claude", "5 h", 50).tone)
+ assertEquals(WidgetTone.ATTENTION, UsageRing("Claude", "5 h", 79).tone)
+ assertEquals(WidgetTone.TROUBLE, UsageRing("Claude", "5 h", 80).tone)
+ assertEquals(0.42f, UsageRing("Claude", "5 h", 42).fraction, 0.0001f)
+ assertEquals(1f, UsageRing("Claude", "5 h", 140).fraction, 0f)
+ assertEquals(0f, UsageRing("Claude", "5 h", -3).fraction, 0f)
+ assertEquals("Claude · 5 h", UsageRing("Claude", "5 h", 1).label)
+ }
+
+ @Test fun todayRidesAlongAndIsNeverNegative() {
+ val g = glance(emptyList())
+ assertEquals(4, WidgetData.build(g, emptyList(), { "x" }, today = 4).today)
+ assertEquals(0, WidgetData.build(g, emptyList(), { "x" }, today = -2).today)
+ assertFalse(WidgetData.build(g, emptyList(), { "x" }, today = 4) == WidgetData.build(g, emptyList(), { "x" }, today = 5))
+ }
}
diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt
index 4a76919d..24ba427e 100644
--- a/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt
+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt
@@ -12,11 +12,19 @@ class WidgetSurfacesTest {
private fun read(path: String) = File(path).readText()
private val manifest get() = read("src/main/AndroidManifest.xml")
- private val sources = listOf("app/SoloWidget.kt", "app/ListWidget.kt", "app/WidgetHub.kt", "app/MochiBitmap.kt", "core/WidgetData.kt")
- .associateWith { read(main + it) }
+ /** Every widget source: the providers, the hub, the pictures, the pure logic and the day's count. */
+ private val widgets = listOf(
+ "SoloWidget" to "coucou_solo_widget_info", "ListWidget" to "coucou_list_widget_info", "MochiBigWidget" to "coucou_big_widget_info",
+ "StatusPillWidget" to "coucou_pill_widget_info", "WaitingAlertWidget" to "coucou_alert_widget_info",
+ "UsageRingWidget" to "coucou_ring_widget_info", "TodayWidget" to "coucou_today_widget_info", "MoodWidget" to "coucou_mood_widget_info",
+ )
+ private val sources = (
+ widgets.map { "app/${it.first}.kt" } +
+ listOf("app/WidgetHub.kt", "app/MochiBitmap.kt", "app/RingBitmap.kt", "app/TodayStore.kt", "core/WidgetData.kt", "core/TodayCounter.kt")
+ ).associateWith { read(main + it) }
@Test fun theWidgetsAreRegisteredAndNeverWakeOnATimer() {
- for ((cls, info) in listOf("SoloWidget" to "coucou_solo_widget_info", "ListWidget" to "coucou_list_widget_info")) {
+ for ((cls, info) in widgets) {
assertTrue(manifest.contains("""android:name=".app.$cls""""))
assertTrue(manifest.contains("@xml/$info"))
val xml = read("src/main/res/xml/$info.xml")
@@ -52,27 +60,42 @@ class WidgetSurfacesTest {
assertEquals(2, Regex("FLAG_IMMUTABLE").findAll(hub).count())
assertTrue(hub.contains("Intent(context, LaunchActivity::class.java)"))
assertTrue(hub.contains("Intent(context, MainActivity::class.java)"))
- for (src in listOf(sources.getValue("app/SoloWidget.kt"), sources.getValue("app/ListWidget.kt"))) {
- assertFalse(src.contains("PendingIntent.get"))
- assertFalse(src.contains("Intent(\""))
+ for ((name, src) in sources) {
+ if (name == "app/WidgetHub.kt") continue
+ assertFalse("$name builds its own PendingIntent", src.contains("PendingIntent.get"))
+ assertFalse("$name builds its own Intent", src.contains("Intent(\""))
}
}
@Test fun everyRowAndEveryWidgetHasItsOwnRequestCode() {
val hub = sources.getValue("app/WidgetHub.kt")
val codes = Regex("""const val CODE_\w+ = (0x[0-9A-Fa-f]+)""").findAll(hub).map { it.groupValues[1] }.toList()
- assertEquals(3, codes.size)
+ assertEquals(9, codes.size)
assertEquals(codes.size, codes.toSet().size)
// The rows use CODE_LIST_ROW + index: the ranges must not run into the next code.
val values = codes.map { it.removePrefix("0x").toInt(16) }.sorted()
assertTrue(values.zipWithNext().all { (a, b) -> b - a >= 16 })
assertTrue(sources.getValue("app/ListWidget.kt").contains("WidgetHub.CODE_LIST_ROW + i"))
+ // Every provider uses its own code, and the family uses each code once.
+ val used = widgets.map { (cls, _) -> Regex("""WidgetHub\.(CODE_\w+)""").findAll(sources.getValue("app/$cls.kt")).map { it.groupValues[1] }.toSet() }
+ for (u in used) assertTrue(u.isNotEmpty())
+ val flat = used.flatten()
+ assertEquals("a code is shared by two Widgets: $flat", flat.size, flat.toSet().size)
}
@Test fun theImageAndTheBadgeAreDescribed() {
- for (cls in listOf("app/SoloWidget.kt")) assertTrue(sources.getValue(cls).contains("setContentDescription(R.id.solo_mochi"))
+ assertTrue(sources.getValue("app/SoloWidget.kt").contains("setContentDescription(R.id.solo_mochi"))
assertTrue(sources.getValue("app/SoloWidget.kt").contains("setContentDescription(R.id.solo_badge"))
assertTrue(sources.getValue("app/ListWidget.kt").contains("setContentDescription(R.id.list_badge"))
+ // Every Widget with a picture describes it; every layout image that is not decoration has a description or is hidden from it.
+ for ((cls, _) in widgets) assertTrue("$cls has no content description", sources.getValue("app/$cls.kt").contains("setContentDescription("))
+ for (layout in File("src/main/res/layout").listFiles()!!.filter { it.name.startsWith("widget_") && it.name != "widget_glance.xml" }) {
+ for (img in Regex("""<ImageView[^>]*>""").findAll(layout.readText())) {
+ val tag = img.value
+ assertTrue("${layout.name}: an image with neither a description nor importantForAccessibility=no: $tag",
+ tag.contains("android:contentDescription") || tag.contains("""android:importantForAccessibility="no""""))
+ }
+ }
}
@Test fun everyChangeOfThePictureReachesTheHub() {
diff --git a/android/i18n/app-strings.json b/android/i18n/app-strings.json
index 68abd230..24ea2b41 100644
--- a/android/i18n/app-strings.json
+++ b/android/i18n/app-strings.json
@@ -17,6 +17,23 @@
"widget_list_description": "Your agents and what each one is doing, without opening Coucou.",
"widget_mochi_description": "Mochi, %1$s",
"widget_badge_description": "%1$d waiting for you",
+ "widget_big_label": "Coucou Mochi Big",
+ "widget_big_description": "A large Mochi with a speech bubble that says what your agent is doing, in plain words.",
+ "widget_pill_label": "Coucou Status Pill",
+ "widget_pill_description": "One slim line: your most urgent agent and how it is doing.",
+ "widget_alert_label": "Coucou Waiting Alert",
+ "widget_alert_description": "Calm when nothing waits for you, bright orange when an agent does.",
+ "widget_ring_label": "Coucou Usage Ring",
+ "widget_ring_description": "How much of your Claude or Codex plan is used.",
+ "widget_today_label": "Coucou Today",
+ "widget_today_description": "How many agent tasks finished today, counted on this phone only.",
+ "widget_mood_label": "Coucou Mochi Mood",
+ "widget_mood_description": "Just Mochi's face, in the mood of your agents.",
+ "widget_today_unit": "done today",
+ "widget_usage_off": "Turn on plan usage in the app",
+ "widget_ring_cd": "%1$s plan usage, %2$d percent used",
+ "widget_today_cd": "%1$d agent tasks finished today",
+ "widget_pill_cd": "%1$s, %2$s",
"status_connected": "Connected",
"status_connecting": "Connecting…",
"status_not_connected": "Not connected",