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,detector): restore ball drawing, suppress URL detection inside emails, fix Lens chip dismissal & union bounding boxes
Rishabh Bajpai6e9a67dd3bd0
diff --git a/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.kt b/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.ktindex 067bba5..678b5b4 100644--- a/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.kt+++ b/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.kt@@ -304,20 +304,23 @@ class GotchaAccessibilityService : AccessibilityService() {return performed}- /** Traverses active window nodes and extracts visible text along with screen bounds. */- fun extractScreenNodeTexts(): List<ScreenNodeText> {+ /**+ * Traverses active screen tree, builds full screen text with character offsets,+ * runs SmartActionDetector.detectAll, and constructs union bounding boxes for every entity.+ */+ fun extractScreenEntitiesWithBounds(): List<AnnotatedEntity> {val root = rootInActiveWindow ?: return emptyList()- val results = mutableListOf<ScreenNodeText>()+ val nodes = mutableListOf<Pair<String, android.graphics.Rect>>()fun walk(node: AccessibilityNodeInfo?) {if (node == null) returnif (node.isVisibleToUser) {val txt = (node.text?.toString() ?: node.contentDescription?.toString())?.trim()- if (!txt.isNullOrBlank() && txt.length >= 3) {+ if (!txt.isNullOrBlank()) {val rect = android.graphics.Rect()node.getBoundsInScreen(rect)- if (rect.width() > 10 && rect.height() > 10) {- results.add(ScreenNodeText(txt, rect))+ if (rect.width() > 5 && rect.height() > 5) {+ nodes.add(Pair(txt, rect))}}}@@ -328,7 +331,40 @@ class GotchaAccessibilityService : AccessibilityService() {walk(root)root.recycle()- return results++ if (nodes.isEmpty()) return emptyList()++ val fullTextBuilder = StringBuilder()+ val nodeRanges = mutableListOf<Pair<IntRange, android.graphics.Rect>>()+ for ((txt, rect) in nodes) {+ val startIdx = fullTextBuilder.length+ fullTextBuilder.append(txt).append("\n")+ val endIdx = fullTextBuilder.length+ nodeRanges.add(Pair(startIdx..endIdx, rect))+ }++ val fullText = fullTextBuilder.toString()+ val entities = SmartActionDetector.detectAll(fullText, allowChat = false)+ val annotated = mutableListOf<AnnotatedEntity>()++ for (entity in entities) {+ val unionRect = android.graphics.Rect()+ var count = 0+ for ((range, rect) in nodeRanges) {+ if (range.first <= entity.span.last && entity.span.first <= range.last) {+ if (count == 0) {+ unionRect.set(rect)+ } else {+ unionRect.union(rect)+ }+ count+++ }+ }+ if (count > 0 && unionRect.width() > 0 && unionRect.height() > 0) {+ annotated.add(AnnotatedEntity(entity, unionRect))+ }+ }+ return annotated}fun longPressByText(query: String): Boolean {diff --git a/app/src/main/java/com/gotcha/service/ScreenLensController.kt b/app/src/main/java/com/gotcha/service/ScreenLensController.ktindex e843983..8be3ac1 100644--- a/app/src/main/java/com/gotcha/service/ScreenLensController.kt+++ b/app/src/main/java/com/gotcha/service/ScreenLensController.kt@@ -46,17 +46,11 @@ class ScreenLensController(mainHandler.post {removeActionMenu()removeCropOverlay()+ removeTextChips()recyclePendingCrop()val service = GotchaAccessibilityService.instance- val nodeTexts = service?.extractScreenNodeTexts() ?: emptyList()- val annotatedEntities = mutableListOf<AnnotatedEntity>()- for (nodeText in nodeTexts) {- val entities = SmartActionDetector.detectAll(nodeText.text, allowChat = false)- for (entity in entities) {- annotatedEntities.add(AnnotatedEntity(entity, nodeText.bounds))- }- }+ val annotatedEntities = service?.extractScreenEntitiesWithBounds() ?: emptyList()val overlay = ScreenCropOverlayView(appContext,@@ -79,7 +73,8 @@ class ScreenLensController(WindowManager.LayoutParams.MATCH_PARENT,overlayType(),WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or- WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,+ WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or+ WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,PixelFormat.TRANSLUCENT).apply {gravity = Gravity.TOP or Gravity.START@@ -98,6 +93,7 @@ class ScreenLensController(mainHandler.post {removeCropOverlay()removeActionMenu()+ removeTextChips()recyclePendingCrop()}}diff --git a/app/src/main/java/com/gotcha/service/SmartActionDetector.kt b/app/src/main/java/com/gotcha/service/SmartActionDetector.ktindex 2e7e18f..454aab5 100644--- a/app/src/main/java/com/gotcha/service/SmartActionDetector.kt+++ b/app/src/main/java/com/gotcha/service/SmartActionDetector.kt@@ -564,12 +564,17 @@ object SmartActionDetector {}private fun deduplicateAndRank(entities: List<DetectedEntity>): List<DetectedEntity> {+ val emailSpans = entities.filter { it.type == EntityType.EMAIL }.map { it.span }val sorted = entities.sortedWith(compareByDescending<DetectedEntity> { calculateScore(it) }.thenByDescending { it.rawValue.length })val result = mutableListOf<DetectedEntity>()for (entity in sorted) {+ if (entity.type == EntityType.URL) {+ val insideEmail = emailSpans.any { emailSpan -> spansOverlap(entity.span, emailSpan) }+ if (insideEmail) continue+ }val overlaps = result.any { existing ->spansOverlap(entity.span, existing.span) && existing.normalizedValue == entity.normalizedValue}diff --git a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.ktindex 8ce929a..46ed538 100644--- a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt+++ b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt@@ -268,6 +268,7 @@ class AssistiveBallOverlay(context: Context) {fillColor = colors.surfacestrokeColor = Color.parseColor("#FF3E7BFF")strokeWidth = 2.5f * appContext.resources.displayMetrics.density+ ringRadius = size / 2f - 3f * appContext.resources.displayMetrics.density}alpha = PEEK_ALPHAsetOnTouchListener(ballTouchListener())diff --git a/app/src/main/java/com/gotcha/ui/RingDrawable.kt b/app/src/main/java/com/gotcha/ui/RingDrawable.ktindex 6921496..d1cb508 100644--- a/app/src/main/java/com/gotcha/ui/RingDrawable.kt+++ b/app/src/main/java/com/gotcha/ui/RingDrawable.kt@@ -103,15 +103,18 @@ class RingDrawable : Drawable() {canvas.drawCircle(cx, cy, auraRadius, auraPaint)}+ val defaultRadius = kotlin.math.min(bounds.width(), bounds.height()) / 2f - strokeWidth / 2f+ val effectiveRadius = if (ringRadius > 0f) ringRadius else defaultRadius+if (fillColor != Color.TRANSPARENT) {fillPaint.color = fillColor- canvas.drawCircle(cx, cy, ringRadius, fillPaint)+ canvas.drawCircle(cx, cy, effectiveRadius, fillPaint)}if (strokeColor != Color.TRANSPARENT && strokeWidth > 0f) {strokePaint.color = strokeColorstrokePaint.strokeWidth = strokeWidth- canvas.drawCircle(cx, cy, ringRadius, strokePaint)+ canvas.drawCircle(cx, cy, effectiveRadius, strokePaint)}}diff --git a/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.kt b/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.ktindex aee3f2c..f0706a7 100644--- a/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.kt+++ b/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.kt@@ -77,6 +77,16 @@ class SmartActionDetectorTest {assertTrue(email.actions.any { it.actionType == ActionType.NATIVE_COMPOSE_MAIL })}+ @Test+ fun `detectAll suppresses URL detection when domain is part of an email address`() {+ val entities = SmartActionDetector.detectAll("Reach out at [email protected]")+ val emails = entities.filter { it.type == EntityType.EMAIL }+ val urls = entities.filter { it.type == EntityType.URL }+ assertEquals(1, emails.size)+ assertEquals("[email protected]", emails.first().normalizedValue)+ assertTrue("URL list should be empty when domain is inside email", urls.isEmpty())+ }+@Testfun `detectAll finds tracking numbers`() {val entities = SmartActionDetector.detectAll("Your package 1Z9999999999999999 is out for delivery")