Skip to content

CircleToSearch with multi search engine support for all android

Kotlin

made support dialog scrollable

AKS Labsb96a99ecadb1
diff --git a/app/src/main/java/com/akslabs/circletosearch/MainActivity.kt b/app/src/main/java/com/akslabs/circletosearch/MainActivity.kt
index 20d8877..135d3df 100644
--- a/app/src/main/java/com/akslabs/circletosearch/MainActivity.kt
+++ b/app/src/main/java/com/akslabs/circletosearch/MainActivity.kt
@@ -567,149 +567,161 @@ fun SupportDialog(
color = MaterialTheme.colorScheme.surface,
tonalElevation = 6.dp
) {
- Column(
- modifier = Modifier.padding(24.dp),
- horizontalAlignment = Alignment.CenterHorizontally
+ // Outer column: wraps content naturally but caps height at 85% screen height
+ // using BoxWithConstraints so the scroll only kicks in when needed
+ androidx.compose.foundation.layout.BoxWithConstraints(
+ modifier = Modifier.fillMaxWidth()
) {
- Icon(
- painter = painterResource(id = com.akslabs.circletosearch.R.drawable.donation),
- contentDescription = null,
- tint = MaterialTheme.colorScheme.primary,
- modifier = Modifier.size(48.dp)
- )
-
- Spacer(modifier = Modifier.height(16.dp))
-
- Text(
- text = "Help Keep this Project \n Alive! ❤️",
- style = MaterialTheme.typography.titleLarge,
- fontWeight = FontWeight.ExtraBold,
- textAlign = TextAlign.Center
- )
-
- Spacer(modifier = Modifier.height(16.dp))
-
- var isExpanded by remember { mutableStateOf(false) }
-
- Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
- Text(
- text = "Please consider donating to this project Your\n support helps keep this project alive and \n enable us to add amazing \nnew features.",
- style = MaterialTheme.typography.bodyLarge,
- lineHeight = 22.sp,
- textAlign = TextAlign.Center,
- fontWeight = FontWeight.Medium
- )
-
+ val maxDialogHeight = maxHeight * 0.85f
+ Column(
+ modifier = Modifier
+ .fillMaxWidth()
+ .heightIn(max = maxDialogHeight),
+ horizontalAlignment = Alignment.CenterHorizontally
+ ) {
+ // ── Fixed header (always visible) ──────────────────────────
+ Column(
+ modifier = Modifier.padding(start = 24.dp, end = 24.dp, top = 24.dp),
+ horizontalAlignment = Alignment.CenterHorizontally
+ ) {
+ Icon(
+ painter = painterResource(id = com.akslabs.circletosearch.R.drawable.donation),
+ contentDescription = null,
+ tint = MaterialTheme.colorScheme.primary,
+ modifier = Modifier.size(48.dp)
+ )
+ Spacer(modifier = Modifier.height(16.dp))
+ Text(
+ text = "Help Keep this Project \n Alive! ❤️",
+ style = MaterialTheme.typography.titleLarge,
+ fontWeight = FontWeight.ExtraBold,
+ textAlign = TextAlign.Center
+ )
+ Spacer(modifier = Modifier.height(16.dp))
+ }
+
+ // ── Scrollable body ────────────────────────────────────────
+ var isExpanded by remember { mutableStateOf(false) }
Column(
modifier = Modifier
- .fillMaxWidth()
- .clip(androidx.compose.foundation.shape.RoundedCornerShape(16.dp))
- .background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f))
- .padding(16.dp)
- .animateContentSize()
+ .weight(1f, fill = false)
+ .verticalScroll(rememberScrollState())
+ .padding(horizontal = 24.dp),
+ verticalArrangement = Arrangement.spacedBy(10.dp)
) {
- Row(
- modifier = Modifier.fillMaxWidth().clickable { isExpanded = !isExpanded },
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.SpaceBetween
+ Text(
+ text = "Please consider donating to this project Your\n support helps keep this project alive and \n enable us to add amazing \nnew features.",
+ style = MaterialTheme.typography.bodyLarge,
+ lineHeight = 22.sp,
+ textAlign = TextAlign.Center,
+ fontWeight = FontWeight.Medium
+ )
+
+ Column(
+ modifier = Modifier
+ .fillMaxWidth()
+ .clip(androidx.compose.foundation.shape.RoundedCornerShape(16.dp))
+ .background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f))
+ .padding(16.dp)
+ .animateContentSize()
) {
- Text(
- text = "Planned Features:",
- style = MaterialTheme.typography.titleSmall,
- fontWeight = FontWeight.Bold,
- color = MaterialTheme.colorScheme.primary
- )
-
- TextButton(onClick = { isExpanded = !isExpanded }, contentPadding = PaddingValues(0.dp)) {
- Icon(
- imageVector = if (isExpanded) Icons.Default.KeyboardArrowUp else Icons.Default.KeyboardArrowDown,
- contentDescription = if (isExpanded) "Collapse" else "Expand",
- tint = MaterialTheme.colorScheme.primary
+ Row(
+ modifier = Modifier.fillMaxWidth().clickable { isExpanded = !isExpanded },
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.SpaceBetween
+ ) {
+ Text(
+ text = "Planned Features:",
+ style = MaterialTheme.typography.titleSmall,
+ fontWeight = FontWeight.Bold,
+ color = MaterialTheme.colorScheme.primary
)
+ TextButton(onClick = { isExpanded = !isExpanded }, contentPadding = PaddingValues(0.dp)) {
+ Icon(
+ imageVector = if (isExpanded) Icons.Default.KeyboardArrowUp else Icons.Default.KeyboardArrowDown,
+ contentDescription = if (isExpanded) "Collapse" else "Expand",
+ tint = MaterialTheme.colorScheme.primary
+ )
+ }
+ }
+
+ val allFeatures = listOf(
+ "Self-hosted image upload (remove catbox/litterbox dependency)",
+ "More triggers: volume button, power button, shake gesture etc.",
+ "Add more actions to trigger with overlay",
+ "Offline on-device translation",
+ "Improved text detection accuracy",
+ "More Search engines support SearXNG, DuckDuckGo, Brave Search",
+ "Add more QS tiles to directly launch copy text, QR code, SmartScan etc.",
+ "Multi-language support",
+ "More Overlay actions",
+ "Long-press image to download or share",
+ "Image result context menu (reverse search, save, open etc.)",
+ "Material You dynamic theming improvements",
+ "Floating bubble customization (size, opacity, position)",
+ )
+
+ val features = if (isExpanded) allFeatures else allFeatures.take(5)
+
+ Spacer(modifier = Modifier.height(12.dp))
+ features.forEach { feature ->
+ Row(
+ verticalAlignment = Alignment.CenterVertically,
+ modifier = Modifier.padding(vertical = 4.dp)
+ ) {
+ Icon(
+ Icons.Default.Check, null,
+ modifier = Modifier.size(16.dp),
+ tint = MaterialTheme.colorScheme.primary
+ )
+ Spacer(modifier = Modifier.width(12.dp))
+ Text(text = feature, style = MaterialTheme.typography.bodyMedium)
+ }
}
}
-
- val allFeatures = listOf(
- "Self-hosted image upload (remove catbox/litterbox dependency)",
- "More triggers: volume button, power button, shake gesture etc.",
- "Add more actions to trigger with overlay",
- "Offline on-device translation",
- "Improved text detection accuracy",
- "More Search engines support SearXNG, DuckDuckGo, Brave Search",
- "Add more QS tiles to directly launch copy text, QR code,SmartScan etc ",
- "Multi-language support",
- "More Overlay actions",
- "Long-press image to download or share",
- "Image result context menu (reverse search, save, open etc.)",
- "Material You dynamic theming improvements",
- "Floating bubble customization (size, opacity, position)",
- )
-
- val features = if (isExpanded) allFeatures else allFeatures.take(5)
-
- Spacer(modifier = Modifier.height(12.dp))
-
- features.forEach { feature ->
+
+ if (showCount >= 7) {
Row(
verticalAlignment = Alignment.CenterVertically,
- modifier = Modifier.padding(vertical = 4.dp)
+ modifier = Modifier
+ .fillMaxWidth()
+ .clip(androidx.compose.foundation.shape.RoundedCornerShape(8.dp))
+ .clickable { dontShowAgain.value = !dontShowAgain.value }
+ .padding(vertical = 4.dp)
) {
- Icon(
- Icons.Default.Check,
- null,
- modifier = Modifier.size(16.dp),
- tint = MaterialTheme.colorScheme.primary
+ Checkbox(
+ checked = dontShowAgain.value,
+ onCheckedChange = { dontShowAgain.value = it }
)
- Spacer(modifier = Modifier.width(12.dp))
Text(
- text = feature,
- style = MaterialTheme.typography.bodyMedium
+ text = "Don't show this again",
+ style = MaterialTheme.typography.bodySmall,
+ modifier = Modifier.padding(start = 8.dp)
)
}
}
+ Spacer(modifier = Modifier.height(4.dp))
}
- }
-
- if (showCount >= 7) {
- Spacer(modifier = Modifier.height(24.dp))
-
+
+ // ── Fixed bottom buttons (always visible) ──────────────────
Row(
- verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
- .clip(androidx.compose.foundation.shape.RoundedCornerShape(8.dp))
- .clickable { dontShowAgain.value = !dontShowAgain.value }
- .padding(vertical = 4.dp)
- ) {
- Checkbox(
- checked = dontShowAgain.value,
- onCheckedChange = { dontShowAgain.value = it }
- )
- Text(
- text = "Don't show this again",
- style = MaterialTheme.typography.bodySmall,
- modifier = Modifier.padding(start = 8.dp)
- )
- }
- }
-
- Spacer(modifier = Modifier.height(24.dp))
-
- Row(
- modifier = Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.End,
- verticalAlignment = Alignment.CenterVertically
- ) {
- TextButton(onClick = onDismiss) {
- Text("Close")
- }
- Spacer(modifier = Modifier.width(8.dp))
- Button(
- onClick = onDonate,
- shape = androidx.compose.foundation.shape.RoundedCornerShape(14.dp),
- contentPadding = PaddingValues(horizontal = 24.dp, vertical = 12.dp)
+ .padding(horizontal = 24.dp, vertical = 16.dp),
+ horizontalArrangement = Arrangement.End,
+ verticalAlignment = Alignment.CenterVertically
) {
- Text("Donate", fontWeight = FontWeight.Bold)
+ TextButton(onClick = onDismiss) {
+ Text("Close")
+ }
+ Spacer(modifier = Modifier.width(8.dp))
+ Button(
+ onClick = onDonate,
+ shape = androidx.compose.foundation.shape.RoundedCornerShape(14.dp),
+ contentPadding = PaddingValues(horizontal = 24.dp, vertical = 12.dp)
+ ) {
+ Text("Donate", fontWeight = FontWeight.Bold)
+ }
}
}
}
diff --git a/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt b/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt
index 5fac35e..2760010 100644
--- a/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt
+++ b/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt
@@ -641,16 +641,22 @@ fun CircleToSearchScreen(
val path = ImageUtils.saveBitmap(context, selectedBitmap!!)
val uri = android.net.Uri.fromFile(java.io.File(path))
- // Prepare content URI for Lens (using existing FileProvider logic in helper)
- val success = searchWithGoogleLens(uri, context)
-
- if (success) {
- // Close the overlay since Lens is taking over
- onClose()
- return@LaunchedEffect
- } else {
- // Fallback to multi-search if Lens failed
- android.util.Log.e("CircleToSearch", "Google Lens launch failed, falling back to multi-search")
+ val result = searchWithGoogleLens(uri, context)
+ when (result) {
+ com.akslabs.circletosearch.ui.components.LensLaunchResult.LAUNCHED_DIRECTLY -> {
+ // Lens launched directly — safe to dismiss the overlay
+ onClose()
+ return@LaunchedEffect
+ }
+ com.akslabs.circletosearch.ui.components.LensLaunchResult.LAUNCHED_VIA_CHOOSER -> {
+ // Chooser shown — overlay must stay open, user picks the app
+ isLoading = false
+ return@LaunchedEffect
+ }
+ com.akslabs.circletosearch.ui.components.LensLaunchResult.FAILED -> {
+ // Fallback to multi-search
+ android.util.Log.e("CircleToSearch", "Google Lens launch failed, falling back to multi-search")
+ }
}
}
diff --git a/app/src/main/java/com/akslabs/circletosearch/ui/components/GoogleLensHelper.kt b/app/src/main/java/com/akslabs/circletosearch/ui/components/GoogleLensHelper.kt
index 0f8d89e..ad1fab5 100644
--- a/app/src/main/java/com/akslabs/circletosearch/ui/components/GoogleLensHelper.kt
+++ b/app/src/main/java/com/akslabs/circletosearch/ui/components/GoogleLensHelper.kt
@@ -19,14 +19,24 @@ import java.io.File
*/
private const val TAG = "GoogleLensHelper"
+/** Result of attempting to launch Google Lens */
+enum class LensLaunchResult {
+ /** Launched directly into Google app / Gallery — overlay can be safely dismissed */
+ LAUNCHED_DIRECTLY,
+ /** Showed system app chooser — overlay must stay open so user can pick */
+ LAUNCHED_VIA_CHOOSER,
+ /** All approaches failed */
+ FAILED
+}
+
/**
* Launch Google Lens with the given image URI
*
* @param uri The URI of the image to search with Google Lens
* @param context The context to use for launching the intent
- * @return True if Google Lens was launched successfully, false otherwise
+ * @return [LensLaunchResult] indicating how Lens was launched
*/
-fun searchWithGoogleLens(uri: Uri, context: Context): Boolean {
+fun searchWithGoogleLens(uri: Uri, context: Context): LensLaunchResult {
Log.d(TAG, "Launching Google Lens with URI: $uri")
try {
@@ -35,11 +45,11 @@ fun searchWithGoogleLens(uri: Uri, context: Context): Boolean {
uri
} else {
try {
- val file = File(uri.path ?: return false)
+ val file = File(uri.path ?: return LensLaunchResult.FAILED)
if (!file.exists()) {
Log.e(TAG, "Image file does not exist: ${file.absolutePath}")
Toast.makeText(context, "Image file not found", Toast.LENGTH_SHORT).show()
- return false
+ return LensLaunchResult.FAILED
}
FileProvider.getUriForFile(
@@ -50,15 +60,12 @@ fun searchWithGoogleLens(uri: Uri, context: Context): Boolean {
} catch (e: Exception) {
Log.e(TAG, "Error creating content URI: ${e.message}")
Toast.makeText(context, "Error preparing image for Google Lens", Toast.LENGTH_SHORT).show()
- return false
+ return LensLaunchResult.FAILED
}
}
Log.d(TAG, "Content URI: $contentUri")
- // Try different approaches to launch Google Lens
- var success = false
-
// Approach 1: Use Google Lens directly with ACTION_SEND
try {
val lensIntent = Intent(Intent.ACTION_SEND).apply {
@@ -68,111 +75,72 @@ fun searchWithGoogleLens(uri: Uri, context: Context): Boolean {
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
-
context.startActivity(lensIntent)
- vibrateDevice(context) // Provide haptic feedback
+ vibrateDevice(context)
Log.d(TAG, "Google Lens launched with ACTION_SEND")
- success = true
+ return LensLaunchResult.LAUNCHED_DIRECTLY
} catch (e: Exception) {
Log.e(TAG, "Failed to launch Google Lens with ACTION_SEND: ${e.message}")
}
// Approach 2: Use Google Gallery with ACTION_SEND
- if (!success) {
- try {
- val GalleryIntent = Intent(Intent.ACTION_SEND).apply {
- type = "image/*"
- putExtra(Intent.EXTRA_STREAM, contentUri)
- setPackage("com.google.android.apps.Gallery")
- putExtra("lens", true) // Hint to open in Lens mode
- addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- }
-
- context.startActivity(GalleryIntent)
- vibrateDevice(context) // Provide haptic feedback
- Log.d(TAG, "Google Gallery launched with ACTION_SEND")
- success = true
- } catch (e: Exception) {
- Log.e(TAG, "Failed to launch Google Gallery: ${e.message}")
- }
- }
-
- // Approach 3: Use a chooser with ACTION_SEND
- if (!success) {
- try {
- val sendIntent = Intent(Intent.ACTION_SEND).apply {
- type = "image/*"
- putExtra(Intent.EXTRA_STREAM, contentUri)
- addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
- }
-
- val chooser = Intent.createChooser(sendIntent, "Search with Google Lens")
- chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
-
- context.startActivity(chooser)
- vibrateDevice(context) // Provide haptic feedback
- Log.d(TAG, "Chooser launched with ACTION_SEND")
- success = true
- } catch (e: Exception) {
- Log.e(TAG, "Failed to launch chooser: ${e.message}")
+ try {
+ val galleryIntent = Intent(Intent.ACTION_SEND).apply {
+ type = "image/*"
+ putExtra(Intent.EXTRA_STREAM, contentUri)
+ setPackage("com.google.android.apps.Gallery")
+ putExtra("lens", true)
+ addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
+ context.startActivity(galleryIntent)
+ vibrateDevice(context)
+ Log.d(TAG, "Google Gallery launched with ACTION_SEND")
+ return LensLaunchResult.LAUNCHED_DIRECTLY
+ } catch (e: Exception) {
+ Log.e(TAG, "Failed to launch Google Gallery: ${e.message}")
}
- // Approach 4: Use Google app with ACTION_VIEW
- if (!success) {
- try {
- val googleIntent = Intent(Intent.ACTION_VIEW).apply {
- setPackage("com.google.android.googlequicksearchbox")
- data = contentUri
- addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- }
-
- context.startActivity(googleIntent)
- vibrateDevice(context) // Provide haptic feedback
- Log.d(TAG, "Google app launched with ACTION_VIEW")
- success = true
- } catch (e: Exception) {
- Log.e(TAG, "Failed to launch Google app with ACTION_VIEW: ${e.message}")
+ // Approach 3: Use Google app with ACTION_VIEW
+ try {
+ val googleIntent = Intent(Intent.ACTION_VIEW).apply {
+ setPackage("com.google.android.googlequicksearchbox")
+ data = contentUri
+ addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
+ context.startActivity(googleIntent)
+ vibrateDevice(context)
+ Log.d(TAG, "Google app launched with ACTION_VIEW")
+ return LensLaunchResult.LAUNCHED_DIRECTLY
+ } catch (e: Exception) {
+ Log.e(TAG, "Failed to launch Google app with ACTION_VIEW: ${e.message}")
}
- // Approach 5: Use web browser with lens.google.com
- if (!success) {
- try {
- val webIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://lens.google.com")).apply {
- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- }
-
- context.startActivity(webIntent)
- vibrateDevice(context) // Provide haptic feedback
-
- Toast.makeText(
- context,
- "Opening Google Lens website as fallback",
- Toast.LENGTH_SHORT
- ).show()
-
- Log.d(TAG, "Web Google Lens launched")
- success = true
- } catch (e: Exception) {
- Log.e(TAG, "Failed to launch web Google Lens: ${e.message}")
+ // Approach 4 (Fallback): System chooser — overlay must stay open
+ try {
+ val sendIntent = Intent(Intent.ACTION_SEND).apply {
+ type = "image/*"
+ putExtra(Intent.EXTRA_STREAM, contentUri)
+ addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
+ val chooser = Intent.createChooser(sendIntent, "Search with Google Lens")
+ chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ context.startActivity(chooser)
+ vibrateDevice(context)
+ Log.d(TAG, "Chooser launched — overlay stays open")
+ return LensLaunchResult.LAUNCHED_VIA_CHOOSER
+ } catch (e: Exception) {
+ Log.e(TAG, "Failed to launch chooser: ${e.message}")
}
- // If all approaches failed
- if (!success) {
- Toast.makeText(context, "Google Lens is not available on this device", Toast.LENGTH_SHORT).show()
- Log.e(TAG, "Google Lens not available - all approaches failed")
- return false
- }
-
- return true
+ Toast.makeText(context, "Google Lens is not available on this device", Toast.LENGTH_SHORT).show()
+ Log.e(TAG, "Google Lens not available - all approaches failed")
+ return LensLaunchResult.FAILED
} catch (e: Exception) {
Log.e(TAG, "Error launching Google Lens", e)
Toast.makeText(context, "Error launching Google Lens", Toast.LENGTH_SHORT).show()
- return false
+ return LensLaunchResult.FAILED
}
}