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.

fix(ball,lens,browser): open menu upwards near bottom edge, fix Lens bounding box Y-offset with view getLocationOnScreen, add selectable text card feature, and fix WebView node traversal for browsers

Rishabh Bajpai0d548d7986ec
diff --git a/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.kt b/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.kt
index 678b5b4..ba7f5cc 100644
--- a/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.kt
+++ b/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.kt
@@ -312,16 +312,26 @@ class GotchaAccessibilityService : AccessibilityService() {
val root = rootInActiveWindow ?: return emptyList()
val nodes = mutableListOf<Pair<String, android.graphics.Rect>>()
+ fun findValidBounds(node: AccessibilityNodeInfo): android.graphics.Rect? {
+ var curr: AccessibilityNodeInfo? = node
+ while (curr != null) {
+ val r = android.graphics.Rect()
+ curr.getBoundsInScreen(r)
+ if (r.width() > 10 && r.height() > 10) {
+ return r
+ }
+ curr = curr.parent
+ }
+ return null
+ }
+
fun walk(node: AccessibilityNodeInfo?) {
if (node == null) return
- if (node.isVisibleToUser) {
- val txt = (node.text?.toString() ?: node.contentDescription?.toString())?.trim()
- if (!txt.isNullOrBlank()) {
- val rect = android.graphics.Rect()
- node.getBoundsInScreen(rect)
- if (rect.width() > 5 && rect.height() > 5) {
- nodes.add(Pair(txt, rect))
- }
+ val txt = (node.text?.toString() ?: node.contentDescription?.toString())?.trim()
+ if (!txt.isNullOrBlank()) {
+ val rect = findValidBounds(node)
+ if (rect != null) {
+ nodes.add(Pair(txt, rect))
}
}
for (i in 0 until node.childCount) {
diff --git a/app/src/main/java/com/gotcha/service/ScreenLensController.kt b/app/src/main/java/com/gotcha/service/ScreenLensController.kt
index 8be3ac1..8acbf0c 100644
--- a/app/src/main/java/com/gotcha/service/ScreenLensController.kt
+++ b/app/src/main/java/com/gotcha/service/ScreenLensController.kt
@@ -200,7 +200,12 @@ class ScreenLensController(
}
val hasText = !cleanText.isNullOrBlank()
- if (hasText) {
+ if (hasText && cleanText != null) {
+ chipsLayout.addView(
+ chipButton("📝 Select text") {
+ showSelectableTextCard(cleanText)
+ }
+ )
chipsLayout.addView(
chipButton("📋 Copy text") {
val crop = pendingCrop
@@ -264,6 +269,89 @@ class ScreenLensController(
}
}
+ private fun showSelectableTextCard(text: String) {
+ removeActionMenu()
+ val density = appContext.resources.displayMetrics.density
+
+ val cardLayout = android.widget.LinearLayout(appContext).apply {
+ orientation = android.widget.LinearLayout.VERTICAL
+ setPadding((16 * density).toInt(), (14 * density).toInt(), (16 * density).toInt(), (14 * density).toInt())
+ background = android.graphics.drawable.GradientDrawable().apply {
+ cornerRadius = 18f * density
+ setColor(android.graphics.Color.parseColor("#F51E293B"))
+ setStroke((1 * density).toInt(), android.graphics.Color.parseColor("#334155"))
+ }
+ }
+
+ val titleView = TextView(appContext).apply {
+ this.text = "📝 Extracted Text"
+ textSize = 14f
+ setTypeface(null, android.graphics.Typeface.BOLD)
+ setTextColor(android.graphics.Color.WHITE)
+ setPadding(0, 0, 0, (8 * density).toInt())
+ }
+ cardLayout.addView(titleView)
+
+ val textView = TextView(appContext).apply {
+ this.text = text
+ textSize = 13f
+ setTextColor(android.graphics.Color.parseColor("#E2E8F0"))
+ setTextIsSelectable(true)
+ }
+
+ val scroll = android.widget.ScrollView(appContext).apply {
+ addView(textView)
+ layoutParams = android.widget.LinearLayout.LayoutParams(
+ android.widget.LinearLayout.LayoutParams.MATCH_PARENT,
+ (180 * density).toInt()
+ )
+ }
+ cardLayout.addView(scroll)
+
+ val btnRow = android.widget.LinearLayout(appContext).apply {
+ orientation = android.widget.LinearLayout.HORIZONTAL
+ setPadding(0, (10 * density).toInt(), 0, 0)
+ }
+
+ btnRow.addView(
+ chipButton("📋 Copy All") {
+ val clipService = Context.CLIPBOARD_SERVICE
+ val clipManager = appContext.getSystemService(clipService) as? android.content.ClipboardManager
+ clipManager?.setPrimaryClip(android.content.ClipData.newPlainText("Extracted Text", text))
+ android.widget.Toast.makeText(
+ appContext,
+ "Copied to clipboard",
+ android.widget.Toast.LENGTH_SHORT
+ ).show()
+ cancel()
+ }
+ )
+
+ btnRow.addView(
+ chipButton("✕ Close") {
+ cancel()
+ }
+ )
+ cardLayout.addView(btnRow)
+
+ val params = WindowManager.LayoutParams(
+ (300 * density).toInt(),
+ WindowManager.LayoutParams.WRAP_CONTENT,
+ overlayType(),
+ WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
+ PixelFormat.TRANSLUCENT
+ ).apply {
+ gravity = Gravity.CENTER
+ }
+
+ try {
+ windowManager.addView(cardLayout, params)
+ actionMenu = cardLayout
+ } catch (_: Exception) {
+ actionMenu = null
+ }
+ }
+
private fun showActionMenu(actions: List<SmartAction>) {
removeActionMenu()
if (actions.isEmpty()) return
diff --git a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
index 46ed538..44470aa 100644
--- a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
+++ b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
@@ -333,8 +333,14 @@ class AssistiveBallOverlay(context: Context) {
FrameLayout.LayoutParams.WRAP_CONTENT
).apply {
val metrics = appContext.resources.displayMetrics
- leftMargin = (ballParams.x).coerceIn(0, (metrics.widthPixels - dp(MENU_WIDTH_DP)).coerceAtLeast(0))
- topMargin = (ballParams.y + dp(64)).coerceIn(0, (metrics.heightPixels - dp(280)).coerceAtLeast(0))
+ val estimatedMenuHeight = dp(280)
+ val spaceBelow = metrics.heightPixels - (ballParams.y + dp(64))
+ leftMargin = (ballParams.x).coerceIn(dp(8), (metrics.widthPixels - dp(MENU_WIDTH_DP) - dp(8)).coerceAtLeast(0))
+ topMargin = if (spaceBelow >= estimatedMenuHeight) {
+ (ballParams.y + dp(64)).coerceIn(dp(16), (metrics.heightPixels - estimatedMenuHeight).coerceAtLeast(0))
+ } else {
+ (ballParams.y - estimatedMenuHeight - dp(8)).coerceIn(dp(16), (metrics.heightPixels - estimatedMenuHeight).coerceAtLeast(0))
+ }
}
rootLayout.addView(menuCard, cardParams)
diff --git a/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt b/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt
index 48dc8c8..1424b38 100644
--- a/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt
+++ b/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt
@@ -209,9 +209,19 @@ class ScreenCropOverlayView(
}
private fun drawAnnotatedEntities(canvas: Canvas) {
+ val location = IntArray(2)
+ getLocationOnScreen(location)
+ val viewOffsetX = location[0].toFloat()
+ val viewOffsetY = location[1].toFloat()
+
for (item in annotatedEntities) {
val bounds = item.boundsOnScreen
- val rectF = RectF(bounds)
+ val rectF = RectF(
+ bounds.left.toFloat() - viewOffsetX,
+ bounds.top.toFloat() - viewOffsetY,
+ bounds.right.toFloat() - viewOffsetX,
+ bounds.bottom.toFloat() - viewOffsetY
+ )
// Draw bounding box
val radius = 8f * density
@@ -295,16 +305,27 @@ class ScreenCropOverlayView(
// Check if touch hits an annotated entity box/chip
if (event.action == MotionEvent.ACTION_UP && !moved) {
+ val location = IntArray(2)
+ getLocationOnScreen(location)
+ val viewOffsetX = location[0].toFloat()
+ val viewOffsetY = location[1].toFloat()
+
val touchX = event.x
val touchY = event.y
for (item in annotatedEntities) {
- val bounds = RectF(item.boundsOnScreen)
+ val bounds = item.boundsOnScreen
+ val rectF = RectF(
+ bounds.left.toFloat() - viewOffsetX,
+ bounds.top.toFloat() - viewOffsetY,
+ bounds.right.toFloat() - viewOffsetX,
+ bounds.bottom.toFloat() - viewOffsetY
+ )
val chipH = 24f * density
val expandedBounds = RectF(
- bounds.left - 16f,
- bounds.top - chipH - 16f,
- bounds.right + 16f,
- bounds.bottom + 16f
+ rectF.left - 16f,
+ rectF.top - chipH - 16f,
+ rectF.right + 16f,
+ rectF.bottom + 16f
)
if (expandedBounds.contains(touchX, touchY)) {
val prompt = item.entity.primaryAction?.prompt