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(lens,service): remove Reading text dialog, shorten chip labels, and position chip bar away from selection rect

Rishabh Bajpai9414925581ff
diff --git a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
index b1a8063..17456ae 100644
--- a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
+++ b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
@@ -455,7 +455,6 @@ class AssistiveBallService : Service() {
/** OCR a Lens crop via ML Kit on-device text recognition and copy to clipboard. */
private fun ocrCropToClipboard(bitmap: android.graphics.Bitmap) {
- overlay.showError("Reading text…")
scope.launch {
try {
val recognizer = com.google.mlkit.vision.text.TextRecognition.getClient(
@@ -467,17 +466,26 @@ class AssistiveBallService : Service() {
}
val text = result.text.trim()
if (text.isBlank()) {
- overlay.showError("No text found in selection")
+ showToast("No text found in selection")
} else {
val clipboard = getSystemService(CLIPBOARD_SERVICE) as android.content.ClipboardManager
clipboard.setPrimaryClip(android.content.ClipData.newPlainText("Lens text", text))
+ showToast("Copied to clipboard")
}
} catch (e: Exception) {
- overlay.showError("Couldn't read text: ${e.message}")
+ showToast("Couldn't read text: ${e.message}")
+ } finally {
+ if (!bitmap.isRecycled) bitmap.recycle()
}
}
}
+ private fun showToast(msg: String) {
+ android.os.Handler(android.os.Looper.getMainLooper()).post {
+ android.widget.Toast.makeText(this, msg, android.widget.Toast.LENGTH_SHORT).show()
+ }
+ }
+
private fun setupScreenCompanionPanel() {
screenCompanionPanel = com.gotcha.ui.ScreenCompanionPanelOverlay(this).apply {
onDismiss = {
diff --git a/app/src/main/java/com/gotcha/service/ScreenLensController.kt b/app/src/main/java/com/gotcha/service/ScreenLensController.kt
index 284e4bb..2d436ac 100644
--- a/app/src/main/java/com/gotcha/service/ScreenLensController.kt
+++ b/app/src/main/java/com/gotcha/service/ScreenLensController.kt
@@ -201,14 +201,14 @@ class ScreenLensController(
if (!cleanText.isNullOrBlank()) {
chipsLayout.addView(
- chipButton("📝 Select text") {
+ chipButton("📝 Select") {
showSelectableTextCard(cleanText)
}
)
}
chipsLayout.addView(
- chipButton("📋 Copy text") {
+ chipButton("📋 Copy") {
val crop = pendingCrop
if (crop != null && !crop.isRecycled) {
val cropCopy = runCatching { crop.copy(crop.config, false) }.getOrNull()
@@ -232,7 +232,7 @@ class ScreenLensController(
)
chipsLayout.addView(
- chipButton("💾 Save image") {
+ chipButton("💾 Save") {
val crop = pendingCrop
if (crop != null && !crop.isRecycled) {
val cropCopy = runCatching { crop.copy(crop.config, false) }.getOrNull()
@@ -245,7 +245,7 @@ class ScreenLensController(
)
chipsLayout.addView(
- chipButton("❓ Ask about this") {
+ chipButton("❓ Ask") {
val crop = pendingCrop
if (crop != null && !crop.isRecycled) {
val base64 = bitmapToBase64(crop)
@@ -255,6 +255,24 @@ class ScreenLensController(
}
)
+ val chipBarHeight = (42 * density).toInt()
+ val chipBarWidth = (300 * density).toInt()
+ val screenHeight = overlay.height
+ val screenWidth = overlay.width
+
+ val targetY = if (finalRect.bottom + chipBarHeight + (12 * density).toInt() <= screenHeight) {
+ finalRect.bottom + (12 * density).toInt()
+ } else if (finalRect.top - chipBarHeight - (12 * density).toInt() >= 0) {
+ finalRect.top - chipBarHeight - (12 * density).toInt()
+ } else {
+ (16 * density).toInt()
+ }
+
+ val targetX = (finalRect.centerX() - chipBarWidth / 2).coerceIn(
+ (12 * density).toInt(),
+ (screenWidth - chipBarWidth - (12 * density).toInt()).coerceAtLeast(0)
+ )
+
val params = WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
@@ -263,8 +281,8 @@ class ScreenLensController(
PixelFormat.TRANSLUCENT
).apply {
gravity = Gravity.TOP or Gravity.START
- x = (finalRect.centerX() - (120 * density)).toInt().coerceIn(0, overlay.width - 240)
- y = (finalRect.top - (48 * density)).toInt().coerceAtLeast((16 * density).toInt())
+ x = targetX
+ y = targetY
}
try {