Skip to content

CircleToSearch with multi search engine support for all android

Kotlin

removed image extractor

AKS Labs7a3bba928232
diff --git a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt
index 3725cba..b8fca5a 100644
--- a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt
+++ b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt
@@ -54,9 +54,6 @@ import com.akslabs.circletosearch.data.OverlayConfigurationManager
import com.akslabs.circletosearch.data.OverlaySegment
import com.akslabs.circletosearch.ui.components.CopyTextOverlayManager
import com.akslabs.circletosearch.utils.ImageUtils
-import kotlinx.coroutines.flow.MutableStateFlow
-import kotlinx.coroutines.flow.StateFlow
-import kotlinx.coroutines.flow.asStateFlow
import java.util.concurrent.Executor
import java.util.concurrent.Executors
@@ -70,10 +67,6 @@ class CircleToSearchAccessibilityService : AccessibilityService() {
/** Kept by companion so scroll events can re-scan copy-text nodes. */
internal var copyTextManager: CopyTextOverlayManager? = null
- // Phase 42: Extraction Results
- private val _extractionResults = MutableStateFlow<List<Rect>>(emptyList())
- val extractionResults: StateFlow<List<Rect>> = _extractionResults.asStateFlow()
-
// Bubble related - Keeping existing logic but refactoring slightly if needed
// For now, keeping bubble separate as requested in prompt "statusbar overlay customization... but it should work normally like now"
// The prompt asks to disable statusbar overlay in landscape but keep it working normally.
@@ -1073,95 +1066,6 @@ class CircleToSearchAccessibilityService : AccessibilityService() {
}
}
- // --- Phase 42: Hybrid Image Extractor ---
- fun extractImages() {
- val bitmap = BitmapRepository.getScreenshot()
- if (bitmap == null) return
-
- val results = mutableListOf<Rect>()
-
- // 1. Accessibility Tree Scan (High-fidelity for Views/Compose)
- // Scan ALL windows instead of just rootInActiveWindow to ensure we get underlying app UI
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- for (window in windows) {
- window.root?.let { scanNodesForImages(it, results) }
- }
- } else {
- rootInActiveWindow?.let { scanNodesForImages(it, results) }
- }
-
- // 2. Visual Scan Fallback (For Canvas/Games)
- if (results.size < 3) {
- visualScanForImages(bitmap, results)
- }
-
- // Deduplicate and filter (ignore tiny or massive items)
- val filtered = results.distinctBy { "${it.left},${it.top},${it.right},${it.bottom}" }
- .filter { it.width() > 50 && it.height() > 50 && it.width() < bitmap.width * 0.9f }
-
- _extractionResults.value = filtered
-
- android.os.Handler(android.os.Looper.getMainLooper()).post {
- android.widget.Toast.makeText(this, "Found ${filtered.size} images", android.widget.Toast.LENGTH_SHORT).show()
- }
- }
-
- private fun scanNodesForImages(node: AccessibilityNodeInfo, results: MutableList<Rect>) {
- // Exclude our own app's UI elements (like the search tools) from extraction
- if (node.packageName?.toString() == "com.akslabs.circletosearch") return
-
- val className = node.className?.toString() ?: ""
- val contentDesc = node.contentDescription?.toString()?.lowercase() ?: ""
- val roleDesc = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) node.viewIdResourceName?.lowercase() ?: "" else ""
-
- // Look for ImageViews or Compose nodes with Image semantics
- val isImage = className.contains("ImageView", ignoreCase = true) ||
- className.contains("Image", ignoreCase = true) ||
- contentDesc.contains("photo", ignoreCase = true) ||
- contentDesc.contains("image", ignoreCase = true) ||
- roleDesc.contains("image", ignoreCase = true) ||
- roleDesc.contains("photo", ignoreCase = true)
-
- if (isImage) {
- val rect = Rect()
- node.getBoundsInScreen(rect)
- // Ensure bounds are valid
- if (rect.width() > 0 && rect.height() > 0) {
- results.add(rect)
- }
- }
-
- for (i in 0 until node.childCount) {
- node.getChild(i)?.let { scanNodesForImages(it, results) }
- }
- }
-
- private fun visualScanForImages(bitmap: Bitmap, results: MutableList<Rect>) {
- val w = bitmap.width
- val h = bitmap.height
- val step = 100
-
- for (y in 100 until h - 100 step step) {
- for (x in 100 until w - 100 step step) {
- if (results.any { it.contains(x, y) }) continue
-
- val p1 = bitmap.getPixel(x, y)
- val p2 = bitmap.getPixel(x + 5, y + 5)
- // Simple entropy heuristic: check color difference
- if (Math.abs(Color.red(p1) - Color.red(p2)) > 30) {
- // Create an estimated bounding box around the complex region
- val estimatedRect = Rect(
- (x - 50).coerceAtLeast(0),
- (y - 50).coerceAtLeast(0),
- (x + 150).coerceAtMost(w),
- (y + 150).coerceAtMost(h)
- )
- results.add(estimatedRect)
- }
- }
- }
- }
-
override fun onCreate() {
super.onCreate()
instance = this
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 2c9e11e..5929767 100644
--- a/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt
+++ b/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt
@@ -229,23 +229,6 @@ fun CircleToSearchScreen(
// Copy Mode internal state
var isCopyMode by remember { mutableStateOf(false) }
-
- // Image Extraction state (Phase 41-43)
- var isExtractMode by remember { mutableStateOf(false) }
- val extractedImages = remember { mutableStateListOf<android.graphics.Rect>() }
-
- // Listen for extraction results from service
- LaunchedEffect(isExtractMode) {
- if (isExtractMode) {
- CircleToSearchAccessibilityService.instance?.let { service ->
- service.extractionResults.collect { rects ->
- extractedImages.clear()
- extractedImages.addAll(rects)
- }
- }
- }
- }
-
// Support Settings Sheet
var showSettingsScreen by remember { mutableStateOf(false) }
@@ -1550,13 +1533,11 @@ fun CircleToSearchScreen(
)
}
- // Image Extractor (Phase 41)
- BottomBarButton("Extract", { Icon(Icons.Default.Image, null, modifier = Modifier.size(22.dp)) }) {
- isExtractMode = true
- scope.launch {
- // Trigger extraction logic in service
- CircleToSearchAccessibilityService.instance?.extractImages()
- }
+ // Telegram
+ BottomBarButton("Telegram", { Icon(painterResource(id = com.akslabs.circletosearch.R.drawable.telegram), null, modifier = Modifier.size(22.dp)) }) {
+ val intent = android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse("https://t.me/Aks_Labs"))
+ intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)
+ try { context.startActivity(intent) } catch(e:Exception){}
}
// Donate
@@ -1869,47 +1850,6 @@ fun CircleToSearchScreen(
onDismissRequest = { showSettingsScreen = false }
)
}
-
- // --- Phase 43: Image Extraction Highlights ---
- if (isExtractMode) {
- Canvas(modifier = Modifier.fillMaxSize().zIndex(4000f)) {
- extractedImages.forEach { rect ->
- val localRect = androidx.compose.ui.geometry.Rect(
- rect.left.toFloat(),
- rect.top.toFloat(),
- rect.right.toFloat(),
- rect.bottom.toFloat()
- )
- // Draw translucent highlight
- drawRect(
- color = Color.White.copy(alpha = 0.3f),
- topLeft = localRect.topLeft,
- size = localRect.size
- )
- // Draw subtle border
- drawRect(
- color = Color.White,
- topLeft = localRect.topLeft,
- size = localRect.size,
- style = androidx.compose.ui.graphics.drawscope.Stroke(width = 2.dp.toPx())
- )
- }
- }
-
- // Exit button for Extract Mode
- Box(modifier = Modifier.fillMaxSize().padding(16.dp).statusBarsPadding().zIndex(5000f)) {
- androidx.compose.material3.FilledTonalIconButton(
- onClick = { isExtractMode = false; extractedImages.clear() },
- modifier = Modifier.align(Alignment.TopStart).size(40.dp),
- colors = androidx.compose.material3.IconButtonDefaults.filledTonalIconButtonColors(
- containerColor = Color.Black.copy(alpha = 0.6f),
- contentColor = Color.White
- )
- ) {
- Icon(Icons.Default.Close, contentDescription = "Exit Extraction Mode")
- }
- }
- }
}
}
}