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: Status Pill with four buttons

Clauded29bb831622b
diff --git a/android/app/src/main/kotlin/com/coucou/android/MainActivity.kt b/android/app/src/main/kotlin/com/coucou/android/MainActivity.kt
index 0b76ded4..1996f6e8 100644
--- a/android/app/src/main/kotlin/com/coucou/android/MainActivity.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/MainActivity.kt
@@ -263,6 +263,8 @@ class MainActivity : ComponentActivity() {
// A tap on a widget row. The session screen says so itself if it has ended, and fills in when the link is back.
if (model.isPaired || model.mode != Mode.NONE) { detailPill = pill; screen = Screen.SESSION }
}
+ // A tap on a widget button: a screen of the closed list ([LaunchScreen]), even when the app is locked, not connected or not paired.
+ model.launch.takeScreen()?.let { screen = it.screen }
val launch = model.launch.take() ?: return
val fp = launch.fingerprint
if (launch.allow) {
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/LaunchActivity.kt b/android/app/src/main/kotlin/com/coucou/android/app/LaunchActivity.kt
index 43c81990..a7100291 100644
--- a/android/app/src/main/kotlin/com/coucou/android/app/LaunchActivity.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/app/LaunchActivity.kt
@@ -4,9 +4,10 @@ import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.coucou.android.MainActivity
+import com.coucou.android.core.LaunchScreen
/**
- * Where our own notification actions, the island's Allow and the widget rows land. It is not exported, so no other app can start it;
+ * Where our own notification actions, the island's Allow and the widget rows and buttons land. It is not exported, so no other app can start it;
* it passes the request to the app inside the process ([PendingLaunch]) and opens MainActivity with a plain intent.
*/
class LaunchActivity : Activity() {
@@ -14,10 +15,14 @@ class LaunchActivity : Activity() {
super.onCreate(savedInstanceState)
val model = (application as CoucouApp).model
val session = intent.getStringExtra(EXTRA_SESSION)
- // A widget row asks for a session to open; a notification asks for an Allow. Each has its own slot, and one
- // never clears the other.
- if (session != null) model.launch.requestSession(session)
- else model.launch.request(intent.getStringExtra(Notifications.EXTRA_FP), intent.getBooleanExtra(Notifications.EXTRA_ALLOW, false))
+ // A widget row asks for a session to open, a widget button for a screen of the closed list, a notification for an
+ // Allow. Each has its own slot, and one never clears the other. A screen that is not in the list is ignored: the
+ // app just opens.
+ when {
+ session != null -> model.launch.requestSession(session)
+ intent.hasExtra(EXTRA_SCREEN) -> LaunchScreen.parse(intent.getStringExtra(EXTRA_SCREEN))?.let { model.launch.requestScreen(it) }
+ else -> model.launch.request(intent.getStringExtra(Notifications.EXTRA_FP), intent.getBooleanExtra(Notifications.EXTRA_ALLOW, false))
+ }
startActivity(
Intent(this, MainActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP),
@@ -28,5 +33,8 @@ class LaunchActivity : Activity() {
companion object {
/** The pill id of the session a widget row opens. */
const val EXTRA_SESSION = "session"
+
+ /** The key of the [LaunchScreen] a widget button opens. */
+ const val EXTRA_SCREEN = "screen"
}
}
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
index 1186ad2f..c7bd8ad1 100644
--- a/android/app/src/main/kotlin/com/coucou/android/app/StatusPillWidget.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/app/StatusPillWidget.kt
@@ -3,21 +3,42 @@ package com.coucou.android.app
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
+import android.util.SizeF
+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
/**
- * 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.
+ * The Status Pill widget: one slim line. On the left a dot in the state's tone, the name of the most urgent agent and its state
+ * word; on the right four round buttons (Home, Chat, Settings, Recent) that open that screen of the app. Narrower, the state
+ * word goes first, then the name; the buttons never move and the text never runs under them. Drawn by [WidgetHub] when
+ * something changes (updatePeriodMillis = 0). A tap on the text opens the top agent, or the app. It only opens things: no
+ * button approves, denies or sends anything.
*/
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 {
+ // Width in dp: under 260 only the dot is left of the buttons, from 260 the name, from 330 the state word too.
+ private val MEDIUM_AT = SizeF(260f, 0f)
+ private val LARGE_AT = SizeF(330f, 0f)
+
+ private class Button(val view: Int, val screen: LaunchScreen)
+
+ private val BUTTONS = listOf(
+ Button(R.id.pill_btn_home, LaunchScreen.HOME),
+ Button(R.id.pill_btn_chat, LaunchScreen.CHAT),
+ Button(R.id.pill_btn_settings, LaunchScreen.SETTINGS),
+ Button(R.id.pill_btn_recent, LaunchScreen.RECENT),
+ )
+
+ 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_pill)
WidgetHub.paint(v, R.id.pill_root, R.id.pill_tint, c.look)
val top = c.top
@@ -25,6 +46,8 @@ class StatusPillWidget : AppWidgetProvider() {
val state = top?.stateWord ?: c.emptyLine.orEmpty()
v.setTextViewText(R.id.pill_name, name)
v.setTextViewText(R.id.pill_state, state)
+ v.setViewVisibility(R.id.pill_name, if (size == WidgetHub.Size.SMALL) View.GONE else View.VISIBLE)
+ v.setViewVisibility(R.id.pill_state, if (size == WidgetHub.Size.LARGE) View.VISIBLE else View.GONE)
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))
@@ -32,6 +55,9 @@ class StatusPillWidget : AppWidgetProvider() {
R.id.pill_root,
if (top != null) WidgetHub.openSession(context, WidgetHub.CODE_PILL, top.pillId) else WidgetHub.openApp(context, WidgetHub.CODE_PILL),
)
+ BUTTONS.forEachIndexed { i, b ->
+ v.setOnClickPendingIntent(b.view, WidgetHub.openScreen(context, WidgetHub.CODE_PILL_BUTTON + i, b.screen))
+ }
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 19e1df4b..49fb3b58 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
@@ -11,6 +11,7 @@ import android.util.SizeF
import android.widget.RemoteViews
import com.coucou.android.MainActivity
import com.coucou.android.R
+import com.coucou.android.core.LaunchScreen
import com.coucou.android.core.WidgetContent
import com.coucou.android.core.WidgetTone
import kotlin.math.roundToInt
@@ -136,6 +137,17 @@ object WidgetHub {
return PendingIntent.getActivity(context, code, open, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
}
+ /**
+ * Opens one screen of the closed [LaunchScreen] list, for a button. Through LaunchActivity like [openSession]: explicit
+ * component, immutable, one [code] of its own per button, and only the key of the screen travels. Nothing is approved.
+ */
+ fun openScreen(context: Context, code: Int, screen: LaunchScreen): PendingIntent {
+ val open = Intent(context, LaunchActivity::class.java)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ .putExtra(LaunchActivity.EXTRA_SCREEN, screen.key)
+ return PendingIntent.getActivity(context, code, open, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
+ }
+
/** Request codes: one range per widget, one code per row, so no two PendingIntents are the same. */
const val CODE_SOLO = 0x5100
const val CODE_LIST_HEADER = 0x5200
@@ -146,4 +158,9 @@ object WidgetHub {
const val CODE_RING = 0x5700
const val CODE_TODAY = 0x5800
const val CODE_MOOD = 0x5900
+
+ /** The buttons: one code each, from these bases (the Status Pill has 4, Mochi Big 6, the summary none). */
+ const val CODE_PILL_BUTTON = 0x5A00
+ const val CODE_BIG_BUTTON = 0x5B00
+ const val CODE_GLANCE = 0x5C00
}
diff --git a/android/app/src/main/kotlin/com/coucou/android/core/LaunchScreen.kt b/android/app/src/main/kotlin/com/coucou/android/core/LaunchScreen.kt
new file mode 100644
index 00000000..210556bb
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/core/LaunchScreen.kt
@@ -0,0 +1,25 @@
+package com.coucou.android.core
+
+/**
+ * The screens a Widget button may open: a closed list, never a free string. A button carries the [key] of one of these to
+ * LaunchActivity (ours, not exported), which turns it into a [LaunchScreen] with [parse] and hands it to the app inside
+ * the process ([PendingLaunch]). Anything that is not in the list is rejected, so a button can only ever open a screen; none
+ * approves, denies or sends anything.
+ */
+enum class LaunchScreen(val key: String, val screen: Screen) {
+ HOME("home", Screen.HOME),
+ CHAT("chat", Screen.CHAT),
+ SETTINGS("settings", Screen.SETTINGS),
+
+ /** "Recent": the full list of your own decisions (the same one as Home's Recent, in full). */
+ RECENT("recent", Screen.HISTORY),
+
+ /** "Pair again": the pairing scan. It always asks to confirm before anything is paired. */
+ PAIR("pair", Screen.SCAN),
+ ;
+
+ companion object {
+ /** The screen called exactly [key]; null for anything else (another case, spaces, an unknown name, null). */
+ fun parse(key: String?): LaunchScreen? = values().firstOrNull { it.key == key }
+ }
+}
diff --git a/android/app/src/main/kotlin/com/coucou/android/core/PendingLaunch.kt b/android/app/src/main/kotlin/com/coucou/android/core/PendingLaunch.kt
index 7c7ec5eb..f441ec6b 100644
--- a/android/app/src/main/kotlin/com/coucou/android/core/PendingLaunch.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/core/PendingLaunch.kt
@@ -16,6 +16,9 @@ class PendingLaunch(private val clock: () -> Long = System::currentTimeMillis) {
private var session: String? = null
private var sessionAt = 0L
+ private var screen: LaunchScreen? = null
+ private var screenAt = 0L
+
@Synchronized
fun request(fp: String?, allow: Boolean) {
val clean = fp?.takeIf { it.isNotBlank() && it.length <= MAX_FP }
@@ -54,6 +57,26 @@ class PendingLaunch(private val clock: () -> Long = System::currentTimeMillis) {
return if (fresh) id else null
}
+ /**
+ * "Open this screen", from a Widget button. A slot of its own, holding a value of the closed [LaunchScreen] list and
+ * nothing else: it never carries an Allow or a session, and they never carry a screen. Only the non-exported
+ * LaunchActivity calls it.
+ */
+ @Synchronized
+ fun requestScreen(which: LaunchScreen?) {
+ screen = which
+ screenAt = clock()
+ }
+
+ /** The screen to open, once, if the tap is fresh; null for everything else (nothing asked, already taken, too old). */
+ @Synchronized
+ fun takeScreen(): LaunchScreen? {
+ val s = screen ?: return null
+ val fresh = clock() - screenAt <= TTL_MS
+ screen = null
+ return if (fresh) s else null
+ }
+
companion object {
const val MAX_PILL = 64
/** The tap and the screen are in the same second; a longer wait means something else is going on. */
diff --git a/android/app/src/main/res/layout/widget_pill.xml b/android/app/src/main/res/layout/widget_pill.xml
index ce9b895c..1f70083a 100644
--- a/android/app/src/main/res/layout/widget_pill.xml
+++ b/android/app/src/main/res/layout/widget_pill.xml
@@ -1,5 +1,7 @@
<?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. -->
+<!-- The Status Pill widget: one slim line. On the left a dot in the state's tone, the agent's name and its state word (one line,
+ ellipsized: the state word gives way first, then the name); on the right four round buttons (Home, Chat, Settings, Recent)
+ that only open a screen of the app. The buttons are measured first, so the text can never run under them. Plain RemoteViews. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pill_root"
android:layout_width="match_parent"
@@ -18,40 +20,91 @@
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal"
- android:paddingStart="18dp"
- android:paddingEnd="18dp">
+ android:paddingStart="16dp"
+ android:paddingEnd="8dp">
- <ImageView
- android:id="@+id/pill_dot"
- android:tint="@color/widget_tone_muted"
- 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:text="@string/widget_initial_title"
- 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:text="@string/widget_initial_line"
+ <LinearLayout
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" />
+ android:gravity="center_vertical"
+ android:orientation="horizontal">
+
+ <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"
+ android:tint="@color/widget_tone_muted" />
+
+ <TextView
+ android:id="@+id/pill_name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="8dp"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:text="@string/widget_initial_title"
+ 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="8dp"
+ android:layout_weight="1"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:text="@string/widget_initial_line"
+ android:textColor="@color/widget_text_secondary"
+ android:textSize="@dimen/widget_text_state" />
+ </LinearLayout>
+
+ <ImageView
+ android:id="@+id/pill_btn_home"
+ android:layout_width="@dimen/widget_button"
+ android:layout_height="@dimen/widget_button"
+ android:layout_marginStart="6dp"
+ android:background="@drawable/widget_button_bg"
+ android:contentDescription="@string/widget_btn_home_cd"
+ android:padding="@dimen/widget_button_pad"
+ android:scaleType="fitCenter"
+ android:src="@drawable/ic_widget_home" />
+
+ <ImageView
+ android:id="@+id/pill_btn_chat"
+ android:layout_width="@dimen/widget_button"
+ android:layout_height="@dimen/widget_button"
+ android:layout_marginStart="6dp"
+ android:background="@drawable/widget_button_bg"
+ android:contentDescription="@string/widget_btn_chat_cd"
+ android:padding="@dimen/widget_button_pad"
+ android:scaleType="fitCenter"
+ android:src="@drawable/ic_widget_chat" />
+
+ <ImageView
+ android:id="@+id/pill_btn_settings"
+ android:layout_width="@dimen/widget_button"
+ android:layout_height="@dimen/widget_button"
+ android:layout_marginStart="6dp"
+ android:background="@drawable/widget_button_bg"
+ android:contentDescription="@string/widget_btn_settings_cd"
+ android:padding="@dimen/widget_button_pad"
+ android:scaleType="fitCenter"
+ android:src="@drawable/ic_widget_settings" />
+
+ <ImageView
+ android:id="@+id/pill_btn_recent"
+ android:layout_width="@dimen/widget_button"
+ android:layout_height="@dimen/widget_button"
+ android:layout_marginStart="6dp"
+ android:background="@drawable/widget_button_bg"
+ android:contentDescription="@string/widget_btn_recent_cd"
+ android:padding="@dimen/widget_button_pad"
+ android:scaleType="fitCenter"
+ android:src="@drawable/ic_widget_recent" />
</LinearLayout>
</FrameLayout>
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
index 57da77e1..1af8893d 100644
--- a/android/app/src/main/res/xml/coucou_pill_widget_info.xml
+++ b/android/app/src/main/res/xml/coucou_pill_widget_info.xml
@@ -6,7 +6,7 @@
android:minHeight="40dp"
android:targetCellWidth="4"
android:targetCellHeight="1"
- android:minResizeWidth="180dp"
+ android:minResizeWidth="220dp"
android:minResizeHeight="40dp"
android:resizeMode="horizontal"
android:updatePeriodMillis="0"