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: implement chrome hiding mechanism during screenshots to prevent UI capture interference
Rishabh Bajpai08a01441d450
diff --git a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt b/app/src/main/java/com/gotcha/service/AssistiveBallService.ktindex 5cc593a..a8654bd 100644--- a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt+++ b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt@@ -284,7 +284,18 @@ class AssistiveBallService : Service() {onOcrToClipboard = { bitmap ->ocrCropToClipboard(bitmap)},- onError = { overlay.showError(it) }+ onError = { overlay.showError(it) },+ onCaptureChrome = { hide ->+ if (hide) {+ overlay.hideChromeForCapture()+ chatWindow.setVisibleForCapture(false)+ screenCompanionPanel.setVisibleForCapture(false)+ } else {+ overlay.showChromeAfterCapture()+ chatWindow.setVisibleForCapture(true)+ screenCompanionPanel.setVisibleForCapture(true)+ }+ })}@@ -714,22 +725,33 @@ class AssistiveBallService : Service() {private fun takeScreenshot() {scope.launch(Dispatchers.IO) {if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {- overlay.showError("Screenshot requires Android 11+")+ withContext(Dispatchers.Main) { overlay.showError("Screenshot requires Android 11+") }return@launch}try {val service = GotchaAccessibilityService.instanceif (service == null) {- overlay.showError("Accessibility service not available")+ withContext(Dispatchers.Main) { overlay.showError("Accessibility service not available") }return@launch}+ withContext(Dispatchers.Main) {+ overlay.hideChromeForCapture()+ chatWindow.setVisibleForCapture(false)+ screenCompanionPanel.setVisibleForCapture(false)+ }+ delay(250L)var bitmap = service.takeScreenshotBitmap()if (bitmap == null) {- delay(1200L)+ delay(800L)bitmap = service.takeScreenshotBitmap()}+ withContext(Dispatchers.Main) {+ overlay.showChromeAfterCapture()+ chatWindow.setVisibleForCapture(true)+ screenCompanionPanel.setVisibleForCapture(true)+ }if (bitmap == null) {- overlay.showError("Screenshot failed — try again")+ withContext(Dispatchers.Main) { overlay.showError("Screenshot failed — try again") }return@launch}val timestamp = java.text.SimpleDateFormat(@@ -755,13 +777,18 @@ class AssistiveBallService : Service() {contentResolver.openOutputStream(uri)?.use { out ->bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, out)}- overlay.showError("Screenshot saved: $fileName")+ withContext(Dispatchers.Main) { overlay.showError("Screenshot saved: $fileName") }} else {- overlay.showError("Screenshot save failed")+ withContext(Dispatchers.Main) { overlay.showError("Screenshot save failed") }}bitmap.recycle()} catch (e: Throwable) {- overlay.showError("Screenshot error: ${e.message}")+ withContext(Dispatchers.Main) {+ overlay.showChromeAfterCapture()+ chatWindow.setVisibleForCapture(true)+ screenCompanionPanel.setVisibleForCapture(true)+ overlay.showError("Screenshot error: ${e.message}")+ }}}}diff --git a/app/src/main/java/com/gotcha/service/ScreenLensController.kt b/app/src/main/java/com/gotcha/service/ScreenLensController.ktindex 6027e30..8059d02 100644--- a/app/src/main/java/com/gotcha/service/ScreenLensController.kt+++ b/app/src/main/java/com/gotcha/service/ScreenLensController.kt@@ -26,7 +26,8 @@ class ScreenLensController(private val onContextualAction: (prompt: String) -> Unit,private val onImagePrompt: (base64Jpeg: String, prompt: String) -> Unit,private val onOcrToClipboard: (crop: Bitmap) -> Unit,- private val onError: (String) -> Unit+ private val onError: (String) -> Unit,+ private val onCaptureChrome: (hide: Boolean) -> Unit = {}) {private val appContext = context.applicationContextprivate val windowManager = appContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager@@ -123,14 +124,20 @@ class ScreenLensController(val regionText = service.dumpTextInRegion(finalRect)val contextualActions = regionText?.let { SmartActionDetector.detectContextual(it) } ?: emptyList()- withContext(Dispatchers.Main) { overlay?.setCaptureMode(true) }- kotlinx.coroutines.delay(80)+ withContext(Dispatchers.Main) {+ overlay?.setCaptureMode(true)+ onCaptureChrome(true)+ }+ kotlinx.coroutines.delay(250L)var full = service.takeScreenshotBitmap()if (full == null) {- kotlinx.coroutines.delay(400)+ kotlinx.coroutines.delay(600L)full = service.takeScreenshotBitmap()}- withContext(Dispatchers.Main) { overlay?.setCaptureMode(false) }+ withContext(Dispatchers.Main) {+ onCaptureChrome(false)+ overlay?.setCaptureMode(false)+ }if (full == null) {withContext(Dispatchers.Main) {removeCropOverlay()diff --git a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.ktindex cf06971..fa9601d 100644--- a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt+++ b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt@@ -123,6 +123,10 @@ class AssistiveBallOverlay(context: Context) {fun hideChromeForCapture() {mainHandler.post {ballView?.visibility = View.INVISIBLE+ ringView?.visibility = View.INVISIBLE+ menuView?.visibility = View.INVISIBLE+ cardView?.visibility = View.INVISIBLE+ dismissTargetView?.visibility = View.INVISIBLE}}@@ -130,6 +134,10 @@ class AssistiveBallOverlay(context: Context) {mainHandler.post {ballView?.visibility = View.VISIBLEballView?.alpha = PEEK_ALPHA+ ringView?.visibility = View.VISIBLE+ menuView?.visibility = View.VISIBLE+ cardView?.visibility = View.VISIBLE+ dismissTargetView?.visibility = View.VISIBLE}}diff --git a/app/src/main/java/com/gotcha/ui/ScreenCompanionPanelOverlay.kt b/app/src/main/java/com/gotcha/ui/ScreenCompanionPanelOverlay.ktindex f247db5..d3e13e5 100644--- a/app/src/main/java/com/gotcha/ui/ScreenCompanionPanelOverlay.kt+++ b/app/src/main/java/com/gotcha/ui/ScreenCompanionPanelOverlay.kt@@ -50,6 +50,12 @@ class ScreenCompanionPanelOverlay(private val context: Context) {private fun dp(value: Int): Int = (value * appContext.resources.displayMetrics.density).toInt()+ fun setVisibleForCapture(visible: Boolean) {+ mainHandler.post {+ panelView?.visibility = if (visible) View.VISIBLE else View.GONE+ }+ }+@Suppress("LongMethod", "CyclomaticComplexMethod")@SuppressLint("ClickableViewAccessibility")fun show(initialPrompt: String, resultText: String? = null) {