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(clipboard): surface translate action for non-preferred language clipboard text in Assistive Ball

Rishabh Bajpai2ef26b25ed9d
diff --git a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
index 17456ae..e572ef8 100644
--- a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
+++ b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
@@ -323,18 +323,38 @@ class AssistiveBallService : Service() {
overlay.setSmartActionAvailable(fetch.label, fetch.prompt)
return@readClipboardWithFocus
}
- // Prefer a structured action (dial / navigate / convert / schedule / reply)
- // when the copied text carries recognisable data; otherwise fall back to
- // the generic translate/summarize offer.
- val smart = SmartActionDetector.detect(clipText, allowChat = true)
- if (smart != null) {
- android.util.Log.d("AssistiveBallService", "Setting smart action: ${smart.label}")
+ val settings = runCatching { com.gotcha.data.SettingsRepository(applicationContext).load() }.getOrNull()
+ val preferredLang = settings?.preferredLanguage ?: "English"
+ val preferredCurr = settings?.preferredCurrency ?: "USD"
+ val isAlreadyTargetLang = SmartActionDetector.isTextInLanguage(clipText, preferredLang)
+
+ val smart = SmartActionDetector.detect(
+ clipText,
+ allowChat = true,
+ targetCurrency = preferredCurr,
+ targetLanguage = preferredLang
+ )
+
+ if (!isAlreadyTargetLang) {
+ val translateLabel = "🌐 Translate: ${SmartActionDetector.snippet(clipText, 20)}"
+ val translatePrompt = "Translate the copied text to $preferredLang:\n\n$clipText"
+
+ if (smart != null && !smart.label.contains("Translate", ignoreCase = true)) {
+ overlay.setSmartActionPairAvailable(
+ translateLabel,
+ translatePrompt,
+ smart.label,
+ smart.prompt
+ )
+ } else {
+ overlay.setSmartActionAvailable(translateLabel, translatePrompt)
+ }
+ } else if (smart != null) {
overlay.setSmartActionAvailable(smart.label, smart.prompt)
} else {
- android.util.Log.d("AssistiveBallService", "Setting smart action: Text copied. Translate?")
overlay.setSmartActionAvailable(
- "📋 Translate: ${SmartActionDetector.snippet(clipText, 24)}",
- "Translate the copied text to English if it is not, otherwise summarize it:\n\n$clipText"
+ "📋 Summarize: ${SmartActionDetector.snippet(clipText, 24)}",
+ "Summarize the copied text:\n\n$clipText"
)
}
}
diff --git a/app/src/main/java/com/gotcha/service/SmartActionDetector.kt b/app/src/main/java/com/gotcha/service/SmartActionDetector.kt
index e862d61..e90bb6e 100644
--- a/app/src/main/java/com/gotcha/service/SmartActionDetector.kt
+++ b/app/src/main/java/com/gotcha/service/SmartActionDetector.kt
@@ -175,7 +175,8 @@ object SmartActionDetector {
fun detectAll(
text: String,
allowChat: Boolean = false,
- targetCurrency: String = "USD"
+ targetCurrency: String = "USD",
+ targetLanguage: String = "English"
): List<DetectedEntity> {
if (text.isBlank()) return emptyList()
@@ -208,24 +209,35 @@ object SmartActionDetector {
// 9. Chat reply fallback (if allowChat set)
if (allowChat && looksLikeChatMessage(text)) {
val normalized = text.trim()
- val actions = listOf(
+ val isAlreadyTargetLang = isTextInLanguage(normalized, targetLanguage)
+ val actions = mutableListOf<SmartAction>()
+
+ if (!isAlreadyTargetLang) {
+ actions.add(
+ SmartAction(
+ label = "🌐 Translate to $targetLanguage",
+ prompt = "Translate the following text to $targetLanguage:\n\n$text",
+ actionType = ActionType.LLM_TRANSLATE,
+ isPrimary = true
+ )
+ )
+ }
+ actions.add(
SmartAction(
label = "💬 Draft reply: ${snippet(normalized, 24)}",
prompt = "Draft a short, friendly reply to this message. Return only the reply text:\n\n$text",
actionType = ActionType.LLM_CHAT_REPLY,
- isPrimary = true
- ),
+ isPrimary = isAlreadyTargetLang
+ )
+ )
+ actions.add(
SmartAction(
label = "📋 Copy text",
prompt = encode(TYPE_COPY, normalized),
actionType = ActionType.NATIVE_COPY
- ),
- SmartAction(
- label = "🌐 Translate",
- prompt = "Translate the following text to English:\n\n$text",
- actionType = ActionType.LLM_TRANSLATE
)
)
+
rawEntities.add(
DetectedEntity(
type = EntityType.CHAT_REPLY,
@@ -246,8 +258,13 @@ object SmartActionDetector {
* Proactive detection wrapper for backward compatibility.
* Returns the primary action of the highest-ranked entity, or null.
*/
- fun detect(text: String, allowChat: Boolean = false): SmartAction? {
- val entities = detectAll(text, allowChat)
+ fun detect(
+ text: String,
+ allowChat: Boolean = false,
+ targetCurrency: String = "USD",
+ targetLanguage: String = "English"
+ ): SmartAction? {
+ val entities = detectAll(text, allowChat, targetCurrency, targetLanguage)
// Proactive detect historically excluded currency & calendar unless in Lens mode
val filtered = entities.filter { it.type != EntityType.CURRENCY && it.type != EntityType.CALENDAR }
return filtered.firstOrNull()?.primaryAction
diff --git a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
index 420c9ba..7fbfbb9 100644
--- a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
+++ b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt
@@ -425,6 +425,14 @@ class AssistiveBallOverlay(context: Context) {
}
)
}
+ pendingSmartActionAlt?.let { (altLabel, altPrompt) ->
+ menuCard.addView(
+ tapButton(altLabel, colors) {
+ removeMenu()
+ onSmartActionSelected(altPrompt)
+ }
+ )
+ }
}
}