Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

feat: add Assistive Ball settings screen and toggle functionality

Durganshu Mishrab6f797d52b8c
diff --git a/.maestro/flows/04-assistive-ball.yaml b/.maestro/flows/04-assistive-ball.yaml
index 25ce7bb..8d49c82 100644
--- a/.maestro/flows/04-assistive-ball.yaml
+++ b/.maestro/flows/04-assistive-ball.yaml
@@ -3,6 +3,13 @@ appId: com.gotcha
# Requires scripts/maestro_run.sh to have granted the SYSTEM_ALERT_WINDOW appop first
# (Maestro cannot send shell/appops commands itself).
- launchApp
+# The toggle lives in Settings ▸ Assistive Ball.
+- tapOn: "Open menu"
+- tapOn: "Settings"
+- scrollUntilVisible:
+ element: "Assistive Ball"
+ direction: DOWN
+- tapOn: "Assistive Ball"
- tapOn: "Turn on assistive ball"
- pressKey: Home
- assertVisible: "Gotcha assistive ball"
diff --git a/app/src/androidTest/java/com/gotcha/AssistiveBallTest.kt b/app/src/androidTest/java/com/gotcha/AssistiveBallTest.kt
index 047414b..339a468 100644
--- a/app/src/androidTest/java/com/gotcha/AssistiveBallTest.kt
+++ b/app/src/androidTest/java/com/gotcha/AssistiveBallTest.kt
@@ -3,7 +3,9 @@ package com.gotcha
import androidx.compose.ui.test.hasContentDescription
import androidx.compose.ui.test.junit4.createEmptyComposeRule
import androidx.compose.ui.test.onNodeWithTag
+import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
+import androidx.compose.ui.test.performScrollTo
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -75,7 +77,15 @@ class AssistiveBallTest {
composeRule.waitForIdle()
composeRule.onNodeWithTag("chat_input").assertExists()
- composeRule.onNode(hasContentDescription("Turn on assistive ball")).performClick()
+
+ // The toggle lives in Settings ▸ Assistive Ball: drawer, category, switch.
+ composeRule.onNode(hasContentDescription("Open menu")).performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithText("Settings").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("settings_assistive_ball_row").performScrollTo().performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("settings_assistive_ball").performClick()
composeRule.waitForIdle()
assertTrue(
diff --git a/app/src/main/java/com/gotcha/MainActivity.kt b/app/src/main/java/com/gotcha/MainActivity.kt
index c66310d..9c75452 100644
--- a/app/src/main/java/com/gotcha/MainActivity.kt
+++ b/app/src/main/java/com/gotcha/MainActivity.kt
@@ -533,6 +533,10 @@ class MainActivity : ComponentActivity() {
},
onTestVoice = { language -> chatViewModel.testAndroidTts(language) },
packageName = packageName,
+ assistiveBallEnabled = assistiveBallOn,
+ onToggleAssistiveBall = { enabled ->
+ assistiveBallOn = setAssistiveBall(enabled)
+ },
initialPage = if (unconfigured) SettingsPage.AI_CONFIG else null
)
}
@@ -562,10 +566,6 @@ class MainActivity : ComponentActivity() {
onOpenDrawer = { scope.launch { drawerState.open() } },
onOpenSettings = { currentRoute = Route.SETTINGS },
sessionTitle = sessions.firstOrNull { it.id == state.activeSessionId }?.title,
- assistiveBallEnabled = assistiveBallOn,
- onToggleAssistiveBall = { enabled ->
- assistiveBallOn = setAssistiveBall(enabled)
- },
onPickImage = { uri -> chatViewModel.loadImageBase64(uri) },
onSwitchAgent = chatViewModel::switchAgent,
onSetAgent = chatViewModel::setAgent,
diff --git a/app/src/main/java/com/gotcha/ui/AssistiveBallScreen.kt b/app/src/main/java/com/gotcha/ui/AssistiveBallScreen.kt
new file mode 100644
index 0000000..1252083
--- /dev/null
+++ b/app/src/main/java/com/gotcha/ui/AssistiveBallScreen.kt
@@ -0,0 +1,53 @@
+package com.gotcha.ui
+
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+
+/**
+ * The Assistive Ball page: one switch that starts or stops the floating overlay,
+ * plus the short version of what the ball does once it is on.
+ *
+ * The switch is not a stored preference the page owns — it drives the
+ * [com.gotcha.service.AssistiveBallService] through the host, which persists
+ * `assistiveBallEnabled` itself and may refuse (no overlay permission yet, in
+ * which case the host deep-links the user to grant it and the switch stays off).
+ * So state is hoisted: [enabled] is the service's real state, and toggling only
+ * asks for a change.
+ */
+@Composable
+fun AssistiveBallScreen(
+ enabled: Boolean,
+ onToggle: (Boolean) -> Unit,
+ onBack: () -> Unit
+) {
+ val overlay = rememberSettingsOverlayState()
+
+ SettingsScaffold(title = SettingsPage.ASSISTIVE_BALL.title, onBack = onBack, overlay = overlay) {
+ SettingsToggleRow(
+ label = "Show Assistive Ball",
+ checked = enabled,
+ onCheckedChange = onToggle,
+ isLarge = true,
+ switchTestTag = "settings_assistive_ball",
+ switchContentDescription = if (enabled) {
+ "Turn off assistive ball"
+ } else {
+ "Turn on assistive ball"
+ }
+ )
+ Text(
+ "A draggable ball floating over other apps. Long-press it to start a " +
+ "hands-free voice call with the assistant; tap it for Start / Pause / " +
+ "End and to open the app. Drag it onto the ✕ to hide it again.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant
+ )
+ Text(
+ "Needs the \"Display over other apps\" permission — turning this on the " +
+ "first time takes you there to grant it.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant
+ )
+ }
+}
diff --git a/app/src/main/java/com/gotcha/ui/ChatScreen.kt b/app/src/main/java/com/gotcha/ui/ChatScreen.kt
index 3df9283..9dabbda 100644
--- a/app/src/main/java/com/gotcha/ui/ChatScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/ChatScreen.kt
@@ -32,7 +32,6 @@ import androidx.compose.material.icons.filled.Send
import androidx.compose.material.icons.filled.Share
import androidx.compose.material.icons.filled.Stop
import androidx.compose.material.icons.filled.TouchApp
-import androidx.compose.material.icons.outlined.Adjust
import androidx.compose.material.icons.outlined.Visibility
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
@@ -89,8 +88,6 @@ fun ChatScreen(
onOpenDrawer: () -> Unit,
onOpenSettings: () -> Unit,
sessionTitle: String? = null,
- assistiveBallEnabled: Boolean = false,
- onToggleAssistiveBall: (Boolean) -> Unit = {},
onPickImage: (Uri) -> String?,
onSwitchAgent: () -> Unit,
onSetAgent: (AgentMode) -> Unit = {},
@@ -162,23 +159,9 @@ fun ChatScreen(
}
},
actions = {
- if (isHome) {
- IconButton(onClick = { onToggleAssistiveBall(!assistiveBallEnabled) }) {
- Icon(
- Icons.Outlined.Adjust,
- contentDescription = if (assistiveBallEnabled) {
- "Turn off assistive ball"
- } else {
- "Turn on assistive ball"
- },
- tint = if (assistiveBallEnabled) {
- MaterialTheme.colorScheme.primary
- } else {
- MaterialTheme.colorScheme.onSurfaceVariant
- }
- )
- }
- } else {
+ // The home screen carries no actions: its top bar is the menu
+ // and the title only. Everything here belongs to an open chat.
+ if (!isHome) {
// Operator can change the device, Monitor cannot. An icon
// that only changes shape is not enough signal for that, so
// the riskier of the two says its own name.
diff --git a/app/src/main/java/com/gotcha/ui/SettingsCommon.kt b/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
index 90c265a..c46c9d9 100644
--- a/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
+++ b/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
@@ -36,6 +36,8 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
@@ -92,6 +94,11 @@ enum class SettingsPage(val title: String, val summary: String, val testTag: Str
"Offers, OTP detection, what may be scanned",
"settings_proactive_row"
),
+ ASSISTIVE_BALL(
+ "Assistive Ball",
+ "Floating ball over other apps, hands-free calls",
+ "settings_assistive_ball_row"
+ ),
APPEARANCE(
"Appearance",
"How the app looks",
@@ -312,7 +319,9 @@ fun SamosaAuthSection(
*
* [switchTestTag] tags the `Switch` rather than the row, so a test that clicks
* it actually toggles something; a tag on the row would find a node that isn't
- * toggleable and no-op silently.
+ * toggleable and no-op silently. [switchContentDescription] names the `Switch`
+ * for the same reason — it is what a UiAutomator/Maestro flow, which cannot see
+ * test tags, has to aim at.
*/
@Composable
fun SettingsToggleRow(
@@ -321,6 +330,7 @@ fun SettingsToggleRow(
onCheckedChange: (Boolean) -> Unit,
isLarge: Boolean = false,
switchTestTag: String? = null,
+ switchContentDescription: String? = null,
modifier: Modifier = Modifier
) {
Row(
@@ -335,7 +345,15 @@ fun SettingsToggleRow(
Switch(
checked = checked,
onCheckedChange = onCheckedChange,
- modifier = if (switchTestTag != null) Modifier.testTag(switchTestTag) else Modifier
+ modifier = Modifier
+ .then(if (switchTestTag != null) Modifier.testTag(switchTestTag) else Modifier)
+ .then(
+ if (switchContentDescription != null) {
+ Modifier.semantics { contentDescription = switchContentDescription }
+ } else {
+ Modifier
+ }
+ )
)
}
}
diff --git a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
index a356d69..a91504e 100644
--- a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
@@ -61,6 +61,15 @@ fun SettingsScreen(
*/
onTestVoice: suspend (Language) -> Boolean? = { null },
packageName: String = "",
+ /**
+ * Whether the assistive-ball service is currently running. Not read from
+ * [load]: the ball can also be dismissed from its own overlay, which stops
+ * the service directly, and the switch has to follow that.
+ */
+ assistiveBallEnabled: Boolean = false,
+ /** Asks the host to start or stop the assistive ball. May be refused (no
+ * overlay permission), in which case [assistiveBallEnabled] stays false. */
+ onToggleAssistiveBall: (Boolean) -> Unit = {},
/**
* Page to open on, instead of the home list. For the unconfigured first run,
* where the one thing the user must do is enter an API key and a model, and
@@ -122,6 +131,11 @@ fun SettingsScreen(
onSave = onSave,
onBack = backToHome
)
+ SettingsPage.ASSISTIVE_BALL -> AssistiveBallScreen(
+ enabled = assistiveBallEnabled,
+ onToggle = onToggleAssistiveBall,
+ onBack = backToHome
+ )
SettingsPage.NOTIFICATIONS -> NotificationsScreen(
load = load,
onSave = onSave,