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: Mochi Big with buttons

Claude441eb8881e94
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
index d59bfbf0..6812fb50 100644
--- a/android/app/src/main/kotlin/com/coucou/android/app/MochiBigWidget.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/app/MochiBigWidget.kt
@@ -8,20 +8,35 @@ import android.util.TypedValue
import android.view.View
import android.widget.RemoteViews
import com.coucou.android.R
+import com.coucou.android.core.LaunchScreen
import com.coucou.android.core.WidgetContent
+import com.coucou.android.core.WidgetTone
/**
* 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.
+ * (updatePeriodMillis = 0). A tap on the card opens the top agent, or the app. Below the status line are buttons (Home, Chat, Settings, Recent, the top agent, Pair again): none when the card is small, one row of four, then two rows; they only open 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)
+ // Height in dp, so that Mochi keeps at least 40% of the card: under 270 no buttons, from 270 one row of four, from 380 two rows.
+ private val MEDIUM_AT = SizeF(0f, 270f)
+ private val LARGE_AT = SizeF(0f, 380f)
+
+ private class Tile(val view: Int, val screen: LaunchScreen?)
+
+ // Home, Chat, Settings, Recent; then the top agent (a session, not a screen) and Pair again.
+ private val TILES = listOf(
+ Tile(R.id.big_tile_home, LaunchScreen.HOME),
+ Tile(R.id.big_tile_chat, LaunchScreen.CHAT),
+ Tile(R.id.big_tile_settings, LaunchScreen.SETTINGS),
+ Tile(R.id.big_tile_recent, LaunchScreen.RECENT),
+ Tile(R.id.big_tile_session, null),
+ Tile(R.id.big_tile_pair, LaunchScreen.PAIR),
+ )
fun views(context: Context, c: WidgetContent): RemoteViews =
WidgetHub.responsive(MEDIUM_AT, LARGE_AT) { size -> render(context, c, size) }
@@ -38,7 +53,7 @@ class MochiBigWidget : AppWidgetProvider() {
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) {
+ if (top != null) {
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)
@@ -46,6 +61,21 @@ class MochiBigWidget : AppWidgetProvider() {
} else {
v.setViewVisibility(R.id.big_row, View.GONE)
}
+
+ // The buttons: none when small, one row of four by default, two rows when tall. They only open things.
+ v.setViewVisibility(R.id.big_buttons, if (small) View.GONE else View.VISIBLE)
+ v.setViewVisibility(R.id.big_buttons_b, if (large) View.VISIBLE else View.GONE)
+ val tile = if (c.look == WidgetTone.ATTENTION) R.drawable.widget_tile_bg_attention else R.drawable.widget_tile_bg
+ TILES.forEachIndexed { i, t ->
+ v.setInt(t.view, "setBackgroundResource", tile)
+ val open = when {
+ t.screen != null -> WidgetHub.openScreen(context, WidgetHub.CODE_BIG_BUTTON + i, t.screen)
+ top != null -> WidgetHub.openSession(context, WidgetHub.CODE_BIG_BUTTON + i, top.pillId)
+ else -> WidgetHub.openScreen(context, WidgetHub.CODE_BIG_BUTTON + i, LaunchScreen.HOME) // no agent yet: the app
+ }
+ v.setOnClickPendingIntent(t.view, open)
+ }
+
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))
diff --git a/android/app/src/main/res/layout/widget_big.xml b/android/app/src/main/res/layout/widget_big.xml
index 779829e7..5533d871 100644
--- a/android/app/src/main/res/layout/widget_big.xml
+++ b/android/app/src/main/res/layout/widget_big.xml
@@ -18,7 +18,7 @@
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
- android:padding="14dp">
+ android:padding="12dp">
<TextView
android:id="@+id/big_bubble"
@@ -30,9 +30,9 @@
android:gravity="center"
android:maxLines="2"
android:paddingStart="16dp"
- android:paddingTop="10dp"
+ android:paddingTop="8dp"
android:paddingEnd="16dp"
- android:paddingBottom="10dp"
+ android:paddingBottom="8dp"
android:textColor="@color/widget_bubble_text"
android:textSize="@dimen/widget_text_name"
android:textStyle="bold" />
@@ -89,6 +89,193 @@
android:textColor="@color/widget_text_secondary"
android:textSize="@dimen/widget_text_state" />
</LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/big_buttons"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"
+ android:orientation="vertical"
+ android:visibility="gone">
+
+ <LinearLayout
+ android:id="@+id/big_buttons_a"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/widget_tile_height"
+ android:orientation="horizontal">
+
+ <LinearLayout
+ android:id="@+id/big_tile_home"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_marginStart="3dp"
+ android:layout_marginEnd="3dp"
+ android:layout_weight="1"
+ android:background="@drawable/widget_tile_bg"
+ android:gravity="center"
+ android:orientation="vertical">
+
+ <ImageView
+ android:layout_width="22dp"
+ android:layout_height="22dp"
+ android:importantForAccessibility="no"
+ android:src="@drawable/ic_widget_home" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:text="@string/widget_btn_home"
+ android:textColor="@color/widget_text"
+ android:textSize="@dimen/widget_text_secondary" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/big_tile_chat"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_marginStart="3dp"
+ android:layout_marginEnd="3dp"
+ android:layout_weight="1"
+ android:background="@drawable/widget_tile_bg"
+ android:gravity="center"
+ android:orientation="vertical">
+
+ <ImageView
+ android:layout_width="22dp"
+ android:layout_height="22dp"
+ android:importantForAccessibility="no"
+ android:src="@drawable/ic_widget_chat" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:text="@string/widget_btn_chat"
+ android:textColor="@color/widget_text"
+ android:textSize="@dimen/widget_text_secondary" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/big_tile_settings"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_marginStart="3dp"
+ android:layout_marginEnd="3dp"
+ android:layout_weight="1"
+ android:background="@drawable/widget_tile_bg"
+ android:gravity="center"
+ android:orientation="vertical">
+
+ <ImageView
+ android:layout_width="22dp"
+ android:layout_height="22dp"
+ android:importantForAccessibility="no"
+ android:src="@drawable/ic_widget_settings" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:text="@string/widget_btn_settings"
+ android:textColor="@color/widget_text"
+ android:textSize="@dimen/widget_text_secondary" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/big_tile_recent"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_marginStart="3dp"
+ android:layout_marginEnd="3dp"
+ android:layout_weight="1"
+ android:background="@drawable/widget_tile_bg"
+ android:gravity="center"
+ android:orientation="vertical">
+
+ <ImageView
+ android:layout_width="22dp"
+ android:layout_height="22dp"
+ android:importantForAccessibility="no"
+ android:src="@drawable/ic_widget_recent" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:text="@string/widget_btn_recent"
+ android:textColor="@color/widget_text"
+ android:textSize="@dimen/widget_text_secondary" />
+ </LinearLayout>
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/big_buttons_b"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/widget_tile_height"
+ android:layout_marginTop="6dp"
+ android:orientation="horizontal"
+ android:visibility="gone">
+
+ <LinearLayout
+ android:id="@+id/big_tile_session"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_marginStart="3dp"
+ android:layout_marginEnd="3dp"
+ android:layout_weight="1"
+ android:background="@drawable/widget_tile_bg"
+ android:gravity="center"
+ android:orientation="vertical">
+
+ <ImageView
+ android:layout_width="22dp"
+ android:layout_height="22dp"
+ android:importantForAccessibility="no"
+ android:src="@drawable/ic_widget_session" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:text="@string/widget_btn_session"
+ android:textColor="@color/widget_text"
+ android:textSize="@dimen/widget_text_secondary" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/big_tile_pair"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_marginStart="3dp"
+ android:layout_marginEnd="3dp"
+ android:layout_weight="1"
+ android:background="@drawable/widget_tile_bg"
+ android:gravity="center"
+ android:orientation="vertical">
+
+ <ImageView
+ android:layout_width="22dp"
+ android:layout_height="22dp"
+ android:importantForAccessibility="no"
+ android:src="@drawable/ic_widget_pair" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:text="@string/widget_btn_pair"
+ android:textColor="@color/widget_text"
+ android:textSize="@dimen/widget_text_secondary" />
+ </LinearLayout>
+ </LinearLayout>
+ </LinearLayout>
</LinearLayout>
<TextView