CircleToSearch with multi search engine support for all android
Kotlin
added loading indicator for copy text mode
AKS Labs3c551fddbfad
diff --git a/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt b/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.ktindex f4b0612..41f444e 100644--- a/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt+++ b/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt@@ -1052,56 +1052,63 @@ fun CircleToSearchScreen(val bottomDp = with(density) { bottomPx.toDp() }val widthDp = rightDp - leftDp+ // SHARE BUTTON: Positioned in a separate Box for perfect centeringBox(modifier = Modifier.fillMaxSize()- .zIndex(300f)+ .zIndex(1000f) // Keep it well above all overlays) {- androidx.compose.material3.FilledTonalButton(- onClick = {- if (selectedBitmap != null) {- scope.launch {- try { val fileName = "selection_${java.util.UUID.randomUUID()}.png"- val path = ImageUtils.saveBitmap(context, selectedBitmap!!, fileName)- val file = java.io.File(path)- val uri = androidx.core.content.FileProvider.getUriForFile(context, "com.akslabs.circletosearch.fileprovider", file)- val shareIntent = android.content.Intent(android.content.Intent.ACTION_SEND).apply {- type = "image/png"- putExtra(android.content.Intent.EXTRA_STREAM, uri)- clipData = android.content.ClipData.newRawUri("Selection", uri)- addFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION)- addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)- }- context.startActivity(android.content.Intent.createChooser(shareIntent, "Share Selection").apply {- addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)- })-- } catch (e: Exception) {- android.util.Log.e("CircleToSearch", "Failed to share selection", e)- }- }- }- },+ Box(modifier = Modifier- .align(Alignment.TopStart).offset(- x = leftDp + (widthDp / 2) - 80.dp, // Approximate center+ x = leftDp,y = if (topPx > 200f) topDp - 64.dp else bottomDp + 16.dp)- .height(48.dp),- shape = CircleShape,- colors = androidx.compose.material3.ButtonDefaults.filledTonalButtonColors(- containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,- contentColor = MaterialTheme.colorScheme.onSurface- ),- elevation = androidx.compose.material3.ButtonDefaults.buttonElevation(defaultElevation = 6.dp), contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 20.dp)+ .width(widthDp),+ contentAlignment = Alignment.Center) {- Text(- "Share",- style = MaterialTheme.typography.labelLarge.copy(- fontWeight = androidx.compose.ui.text.font.FontWeight.Normal+ androidx.compose.material3.FilledTonalButton(+ onClick = {+ if (selectedBitmap != null) {+ scope.launch {+ try {+ val fileName = "selection_${java.util.UUID.randomUUID()}.png"+ val path = ImageUtils.saveBitmap(context, selectedBitmap!!, fileName)+ val file = java.io.File(path)+ val uri = androidx.core.content.FileProvider.getUriForFile(context, "com.akslabs.circletosearch.fileprovider", file)+ val shareIntent = android.content.Intent(android.content.Intent.ACTION_SEND).apply {+ type = "image/png"+ putExtra(android.content.Intent.EXTRA_STREAM, uri)+ clipData = android.content.ClipData.newRawUri("Selection", uri)+ addFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION)+ addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)+ }+ context.startActivity(android.content.Intent.createChooser(shareIntent, "Share Selection").apply {+ addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)+ })++ } catch (e: Exception) {+ android.util.Log.e("CircleToSearch", "Failed to share selection", e)+ }+ }+ }+ },+ modifier = Modifier.height(48.dp),+ shape = CircleShape,+ colors = androidx.compose.material3.ButtonDefaults.filledTonalButtonColors(+ containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,+ contentColor = MaterialTheme.colorScheme.onSurface+ ),+ elevation = androidx.compose.material3.ButtonDefaults.buttonElevation(defaultElevation = 6.dp),+ contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 20.dp)+ ) {+ Text(+ "Share",+ style = MaterialTheme.typography.labelLarge.copy(+ fontWeight = androidx.compose.ui.text.font.FontWeight.Normal+ ))- )+ }}}}diff --git a/app/src/main/java/com/akslabs/circletosearch/ui/components/CopyTextOverlayManager.kt b/app/src/main/java/com/akslabs/circletosearch/ui/components/CopyTextOverlayManager.ktindex ed82541..b588790 100644--- a/app/src/main/java/com/akslabs/circletosearch/ui/components/CopyTextOverlayManager.kt+++ b/app/src/main/java/com/akslabs/circletosearch/ui/components/CopyTextOverlayManager.kt@@ -1,21 +1,6 @@/** Copyright (C) 2025 AKS-Labs* SPDX-License-Identifier: GPL-3.0-or-later- *- * CopyTextOverlayManager — fully offline, zero network, zero logging.- *- * FIXES applied vs original:- * 1. isPotentialTextNode — strict text-only filter, no contentDescription/button leakage- * 2. collectTextNodes — nodes are NOT recycled until AFTER leaf-filter completes (fixes- * non-deterministic parent-pointer traversal on recycled nodes)- * 3. findNearestWord — converts word.bounds (screen coords) to local view coords before- * comparing against touch x/y (which are already in local coords)- * 4. estimateWordBounds — clamps output to node bounds so multi-line text never maps- * words outside the visible region; documented limitation noted- * 5. getRootNode selection — prefers the window with the MOST text content, not just- * windows.first(), so systemui chrome windows rank below real app windows- * 6. snapshot timing — snapshot nodes are now re-collected on demand (when Copy Text- * button is tapped) not only at launch time*/package com.akslabs.circletosearch.ui.components@@ -25,10 +10,9 @@ import android.content.ClipDataimport android.content.ClipboardManagerimport android.content.Contextimport android.graphics.*+import android.util.Logimport android.view.*-import android.view.accessibility.*import android.widget.FrameLayout-import android.widget.PopupMenuimport android.widget.Toastimport androidx.compose.ui.platform.ComposeViewimport androidx.compose.runtime.*@@ -43,6 +27,9 @@ import androidx.compose.material.icons.filled.MoreVertimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.shape.CircleShapeimport androidx.compose.ui.Alignment+import com.akslabs.circletosearch.data.BitmapRepository+import com.akslabs.circletosearch.ocr.TesseractEngine+import com.akslabs.circletosearch.utils.ImageUtilsimport kotlinx.coroutines.*import java.util.UUID@@ -50,13 +37,7 @@ import java.util.UUIDprivate class ToolbarButton(val label: String, val rect: Rect)/**- * Manages the dim+punch-out Copy Text overlay.- *- * Usage:- * val mgr = CopyTextOverlayManager(context) { getRootNode() }- * mgr.getOverlayView(onDismiss = { ... }) // embed in AndroidView- * mgr.rescanNodes() // call on scroll events- * mgr.dismiss()+ * Manages the dim+punch-out Copy Text overlay with OCR capabilities.*/class CopyTextOverlayManager(private val context: Context,@@ -67,25 +48,22 @@ class CopyTextOverlayManager(private var scanJob: Job? = nullprivate var onDismissCallback: (() -> Unit)? = null- // Detected text nodes and flattened words (sorted by reading order)- private val detectedNodes = mutableListOf<TextNode>()+ // State for Compose and Drawing+ private val isScanning = mutableStateOf(false)+ private val textNodes = mutableStateListOf<TextNode>()private var allWords: List<Word> = emptyList()- private var startSelectionIdx = -1 // For dragging-- // Global selection state (indices into 'allWords')++ // Selection stateprivate var globalSelectionStart: Int = -1private var globalSelectionEnd: Int = -1- // ── Public API ───────────────────────────────────────────────────────────-fun getOverlayView(onDismiss: () -> Unit): View {onDismissCallback = onDismiss- // Full Reset state for "fresh start"+ // Reset stateglobalSelectionStart = -1globalSelectionEnd = -1- startSelectionIdx = -1- detectedNodes.clear()+ textNodes.clear()allWords = emptyList()val container = FrameLayout(context)@@ -98,16 +76,13 @@ class CopyTextOverlayManager(setContent {MaterialTheme {Box(modifier = Modifier.fillMaxSize()) {- TopBarUI(- onClose = { dismiss() }- )+ TopBarUI(onClose = { dismiss() })}}}}container.addView(topBar)- android.util.Log.d("CopyText", "Starting accessibility node scan…")scanNodes(view)return container}@@ -122,17 +97,32 @@ class CopyTextOverlayManager(horizontalArrangement = Arrangement.SpaceBetween,verticalAlignment = Alignment.CenterVertically) {- // Close Button (Exact match from main UI)IconButton(onClick = onClose,modifier = Modifier.background(android.graphics.Color.GRAY.toComposeColor().copy(alpha = 0.5f), CircleShape).size(40.dp)) {- Icon(Icons.Default.Close, contentDescription = "Close", tint = ComposeColor.White)+ Icon(Icons.Default.Close, contentDescription = "Exit Copy Mode", tint = ComposeColor.White)}++ if (isScanning.value) {+ Spacer(Modifier.width(16.dp))+ CircularProgressIndicator(+ modifier = Modifier.size(24.dp),+ color = ComposeColor.White,+ strokeWidth = 2.dp+ )+ Spacer(Modifier.width(8.dp))+ Text(+ "Scanning text...",+ style = MaterialTheme.typography.labelMedium,+ color = ComposeColor.White+ )+ }++ Spacer(modifier = Modifier.weight(1f))- // Menu Button (Exact match from main UI)Box {var showMenu by remember { mutableStateOf(false) }IconButton(@@ -170,7 +160,7 @@ class CopyTextOverlayManager(private fun Int.toComposeColor(): ComposeColor = ComposeColor(this)private fun showLanguageModelSelector() {- val models = com.akslabs.circletosearch.ocr.TesseractEngine.getAvailableModels(context)+ val models = TesseractEngine.getAvailableModels(context)val prefs = context.getSharedPreferences("OcrSettings", Context.MODE_PRIVATE)val current = prefs.getString("selected_lang", "eng") ?: "eng"@@ -198,504 +188,266 @@ class CopyTextOverlayManager(onDismissCallback = null}- /** Call on TYPE_VIEW_SCROLLED events to refresh punched-out regions live. */fun rescanNodes() {dimView?.let { scanNodes(it) }}- // ── Node scanning ────────────────────────────────────────────────────────-- private fun scanNodes(view: DimPunchOutView) {+ private fun scanNodes(view: View) {scanJob?.cancel()- scanJob = scope.launch {- android.util.Log.d("CopyText", "scanNodes triggered")-- if (screenshotBitmap == null) {- android.util.Log.e("CopyText", "scanNodes: screenshotBitmap is null")- detectedNodes.clear()+ scanJob = scope.launch(Dispatchers.Main) {+ isScanning.value = true+ val bitmap = screenshotBitmap ?: BitmapRepository.getScreenshot()+ if (bitmap == null) {+ textNodes.clear()+ isScanning.value = falseview.invalidate()return@launch}- android.util.Log.d("CopyText", "Live scan with OCR on bitmap")-- val nodes = com.akslabs.circletosearch.ocr.TesseractEngine.extractText(context, screenshotBitmap)-- // Sort nodes by top coordinate, then left to ensure logical reading order- val sortedNodes = nodes.sortedWith(compareBy({ it.bounds.top }, { it.bounds.left }))-- android.util.Log.d("CopyText", "Live OCR scan complete: ${sortedNodes.size} text nodes")-- detectedNodes.clear()- val tempAllWords = mutableListOf<Word>()- detectedNodes.addAll(sortedNodes)-- // Flatten words and update their global index- sortedNodes.forEach { node ->- node.words.forEach { word ->- // We reuse the Word object but treat it globally- tempAllWords.add(word)+ try {+ val nodes = TesseractEngine.extractText(context, bitmap)+ val sortedNodes = nodes.sortedWith(compareBy({ it.bounds.top }, { it.bounds.left }))++ textNodes.clear()+ textNodes.addAll(sortedNodes)++ val tempAllWords = mutableListOf<Word>()+ sortedNodes.forEach { node ->+ node.words.forEach { word ->+ tempAllWords.add(word)+ }}+ allWords = tempAllWords+ Log.d("CopyTextOverlay", "OCR complete: ${textNodes.size} nodes, ${allWords.size} words")+ } catch (e: Exception) {+ Log.e("CopyTextOverlay", "OCR failed: ${e.message}")+ } finally {+ isScanning.value = false+ view.invalidate()}- allWords = tempAllWords-- view.invalidate()}}--- // ── Dim + punch-out View ─────────────────────────────────────────────────-@SuppressLint("ClickableViewAccessibility")- inner class DimPunchOutView(- context: Context- ) : View(context) {-+ inner class DimPunchOutView(context: Context) : View(context) {private val density = resources.displayMetrics.density-- // ── Coordinate helpers ────────────────────────────────────────────────-private val viewLocation = IntArray(2)- /** Convert a screen-coordinate Rect to this view's local coordinates. */- private fun toLocal(screenRect: Rect): RectF {- getLocationOnScreen(viewLocation)- return RectF(- (screenRect.left - viewLocation[0]).toFloat(),- (screenRect.top - viewLocation[1]).toFloat(),- (screenRect.right - viewLocation[0]).toFloat(),- (screenRect.bottom - viewLocation[1]).toFloat()- )- }-- /** Convert a screen-coordinate RectF to this view's local coordinates. */- private fun toLocal(screenRectF: RectF): RectF {- getLocationOnScreen(viewLocation)- return RectF(- screenRectF.left - viewLocation[0],- screenRectF.top - viewLocation[1],- screenRectF.right - viewLocation[0],- screenRectF.bottom - viewLocation[1]- )- }-- /**- * Convert a local-coordinate point to screen coordinates.- * Used so we can compare touch x/y against word.bounds (screen coords).- *- * FIX #3: word.bounds are in SCREEN coordinates (set from getBoundsInScreen).- * Touch events arrive in LOCAL view coordinates. We must translate before- * comparing — the original code compared local touch coords directly to- * screen-space word bounds, causing selection to be offset by the view origin.- */- private fun toScreenX(localX: Float): Float {- getLocationOnScreen(viewLocation)- return localX + viewLocation[0]- }-- private fun toScreenY(localY: Float): Float {- getLocationOnScreen(viewLocation)- return localY + viewLocation[1]- }-- // ── Paint objects ─────────────────────────────────────────────────────-- private val dimPaint = Paint().apply {- color = Color.BLACK- alpha = 38 // ~15% dim- isAntiAlias = false- }-- private val textPaint = Paint().apply {- color = Color.WHITE- textSize = 32f- isAntiAlias = true- textAlign = Paint.Align.CENTER- }--+ private val dimPaint = Paint().apply { color = Color.BLACK; alpha = 38; isAntiAlias = false }private val selectedWordPaint = Paint().apply {- // Priority: M3 dynamic color if possible, fallback to a nice purple/blue accent- val colorRes = android.R.color.system_accent1_200- color = try { context.getColor(colorRes) } catch(e: Exception) { Color.parseColor("#D0BCFF") }- alpha = 150- isAntiAlias = true+ color = try { context.getColor(android.R.color.system_accent1_200) } catch(e: Exception) { Color.parseColor("#D0BCFF") }+ alpha = 150; isAntiAlias = true}-- private val handlePaint = Paint().apply {- color = Color.parseColor("#6750A4") // M3 Primary+ private val handlePaint = Paint().apply { color = Color.parseColor("#6750A4"); isAntiAlias = true }+ private val toolbarBgPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = Color.parseColor("#F3EDF7") }+ private val toolbarActionPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = Color.parseColor("#6750A4") }+ private val clearPaint = Paint().apply {+ xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR)isAntiAlias = true}- private val toolbarBgPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {- color = Color.parseColor("#F3EDF7") // M3 Surface Container- }-- private val toolbarActionPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {- color = Color.parseColor("#6750A4") // M3 Primary- }-- private val toolbarTextPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {- color = Color.parseColor("#1D1B20") // M3 On Surface- textSize = 38f- textAlign = Paint.Align.CENTER- typeface = android.graphics.Typeface.create("sans-serif-medium", android.graphics.Typeface.NORMAL)- }-- private val toolbarIconPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {- color = Color.parseColor("#6750A4")- style = Paint.Style.STROKE- strokeWidth = 3f- }-- // ── Pulse animation ───────────────────────────────────────────────────-- init {- background = null- setWillNotDraw(false)- setLayerType(LAYER_TYPE_SOFTWARE, null)- }-- // ── Selection / drag state ────────────────────────────────────────────-- private var dragHandleType = 0 // 0=none, 1=start, 2=end+ private var dragHandleType = 0private var toolbarButtons: List<ToolbarButton> = emptyList()private var toolbarRect = RectF()private var dragHandleRect = RectF()private var toolbarOffsetX = 0fprivate var toolbarOffsetY = 0fprivate var isDraggingToolbar = false+ private var toolbarInitialized = falseprivate var lastTouchX = 0fprivate var lastTouchY = 0f- private var toolbarInitialized = false-- // ── Node entry / exit ─────────────────────────────────────────────────-- private fun enterNode(node: TextNode) {- // Find global range for this node's words- val firstWord = node.words.firstOrNull() ?: return- val lastWord = node.words.lastOrNull() ?: return-- val startIdx = allWords.indexOfFirst { it === firstWord }- val endIdx = allWords.indexOfLast { it === lastWord }-- if (startIdx != -1 && endIdx != -1) {- globalSelectionStart = startIdx- globalSelectionEnd = endIdx- }- invalidate()+ init {+ setLayerType(LAYER_TYPE_SOFTWARE, null)}- private fun exitNode() {- globalSelectionStart = -1- globalSelectionEnd = -1- invalidate()+ private fun toLocal(screenRect: Rect): RectF {+ getLocationOnScreen(viewLocation)+ return RectF(+ (screenRect.left - viewLocation[0]).toFloat(),+ (screenRect.top - viewLocation[1]).toFloat(),+ (screenRect.right - viewLocation[0]).toFloat(),+ (screenRect.bottom - viewLocation[1]).toFloat()+ )}- // ── Drawing ───────────────────────────────────────────────────────────-- private val clearPaint = Paint().apply {- xfermode = android.graphics.PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR)- isAntiAlias = true+ private fun toLocal(screenRectF: RectF): RectF {+ getLocationOnScreen(viewLocation)+ return RectF(+ screenRectF.left - viewLocation[0],+ screenRectF.top - viewLocation[1],+ screenRectF.right - viewLocation[0],+ screenRectF.bottom - viewLocation[1]+ )}+ private fun toScreenX(localX: Float): Float { getLocationOnScreen(viewLocation); return localX + viewLocation[0] }+ private fun toScreenY(localY: Float): Float { getLocationOnScreen(viewLocation); return localY + viewLocation[1] }+override fun onDraw(canvas: Canvas) {val saveCount = canvas.saveLayer(0f, 0f, width.toFloat(), height.toFloat(), null)-- // 1. Dim layercanvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), dimPaint)- // 2. Punch out holes for all text blocks- detectedNodes.forEach { node ->+ textNodes.forEach { node ->val localBounds = toLocal(node.bounds)- localBounds.inset(-16f, -12f) // More padding for professional look- canvas.drawRoundRect(localBounds, 16f, 16f, clearPaint)+ localBounds.inset(-12f, -8f)+ canvas.drawRoundRect(localBounds, 12f, 12f, clearPaint)}- // 3. Draw Highlights (Merged into unified bars)if (globalSelectionStart != -1 && globalSelectionEnd != -1) {val start = globalSelectionStart.coerceAtMost(globalSelectionEnd)- val end = globalSelectionStart.coerceAtLeast(globalSelectionEnd)-- // Group words by line (simplified: words in the same node that are close horizontally)- // Actually, Tesseract's TextNode usually represents a line or block.- // We'll group selected words by their Word.bounds.centerY() (rounded)+ val end = globalSelectionStart.coerceAtLeast(globalSelectionEnd)val selectedWords = (start..end).mapNotNull { allWords.getOrNull(it) }- // Group words by line segmentsval highlightPath = Path()selectedWords.groupBy { (it.bounds.centerY() / 20).toInt() }.forEach { (_, wordsInLine) ->if (wordsInLine.isEmpty()) return@forEach-val first = wordsInLine.minBy { it.bounds.left }- val last = wordsInLine.maxBy { it.bounds.right }-- val lineRect = RectF(- first.bounds.left,- wordsInLine.minOf { it.bounds.top },- last.bounds.right,- wordsInLine.maxOf { it.bounds.bottom }- )-- val localLineHighlight = toLocal(lineRect)- localLineHighlight.inset(-16f, -12f)- highlightPath.addRoundRect(localLineHighlight, 12f, 12f, Path.Direction.CW)+ val last = wordsInLine.maxBy { it.bounds.right }+ val lineRect = RectF(first.bounds.left, wordsInLine.minOf { it.bounds.top }, last.bounds.right, wordsInLine.maxOf { it.bounds.bottom })+ val localHighlight = toLocal(lineRect)+ localHighlight.inset(-12f, -8f)+ highlightPath.addRoundRect(localHighlight, 8f, 8f, Path.Direction.CW)}- // Draw all highlights IN ONE CALL to prevent alpha stacking (darker overlaps)canvas.drawPath(highlightPath, selectedWordPaint)- // 4. Handles & Toolbar- val firstWord = allWords[start]- val lastWord = allWords[end]- val startLocal = toLocal(firstWord.bounds)- val endLocal = toLocal(lastWord.bounds)-- drawHandle(canvas, startLocal.left, startLocal.top, isStart = true)- drawHandle(canvas, endLocal.right, endLocal.bottom, isStart = false)+ val startLocal = toLocal(allWords[start].bounds)+ val endLocal = toLocal(allWords[end].bounds)+ drawHandle(canvas, startLocal.left, startLocal.top, true)+ drawHandle(canvas, endLocal.right, endLocal.bottom, false)- val encompassing = RectF(firstWord.bounds)+ val encompassing = RectF(allWords[start].bounds)selectedWords.forEach { encompassing.union(it.bounds) }drawFloatingToolbar(canvas, toLocal(encompassing))}-- // 5. Top Bar is now handled by ComposeView in the FrameLayout- // so we don't draw it manually here anymore.-canvas.restoreToCount(saveCount)}--private fun drawHandle(canvas: Canvas, x: Float, y: Float, isStart: Boolean) {canvas.drawCircle(x, y, 18f, handlePaint)if (isStart) canvas.drawRect(x - 2f, y, x + 2f, y + 40f, handlePaint)- else canvas.drawRect(x - 2f, y - 40f, x + 2f, y, handlePaint)+ else canvas.drawRect(x - 2f, y - 40f, x + 2f, y, handlePaint)}private fun drawFloatingToolbar(canvas: Canvas, anchor: RectF) {val buttonLabels = listOf("Copy", "Share", "All", "Cancel")- val btnPadding = 16f * density // More compact- val btnHeight = 36f * density // Match native pill height+ val btnPadding = 16f * density+ val btnHeight = 36f * densityval btnSpacing = 6f * densityval m = 10f * density- toolbarActionPaint.textSize = 30f // Slightly smaller+ toolbarActionPaint.textSize = 30fval labelWidths = buttonLabels.map { toolbarActionPaint.measureText(it) + btnPadding * 2 }val dragHandleWidth = 24f * densityval totalWidth = labelWidths.sum() + (buttonLabels.size - 1) * btnSpacing + m * 2 + dragHandleWidth + btnSpacingval tx = ((width - totalWidth) / 2) + toolbarOffsetX-if (!toolbarInitialized) {- // Dock to bottom initially- toolbarOffsetY = height - (btnHeight + m * 2) - 100f * density+ toolbarOffsetY = anchor.top - (btnHeight + m * 2) - 32f+ if (toolbarOffsetY < 150f) toolbarOffsetY = anchor.bottom + 32ftoolbarInitialized = true}val ty = toolbarOffsetY-toolbarRect.set(tx, ty, tx + totalWidth, ty + btnHeight + m * 2)- // Dynamic Background with shadow- val dynamicSurface = try {- context.getColor(android.R.color.system_surface_container_light)- } catch(e: Exception) { Color.parseColor("#F3EDF7") }-- val shadowPaint = Paint(toolbarBgPaint).apply {- setShadowLayer(12f * density, 0f, 4f * density, Color.BLACK and 0x2F000000)- }+ val dynamicSurface = try { context.getColor(android.R.color.system_surface_container_light) } catch(e: Exception) { Color.parseColor("#F3EDF7") }+ val shadowPaint = Paint(toolbarBgPaint).apply { setShadowLayer(12f * density, 0f, 4f * density, Color.BLACK and 0x2F000000) }canvas.drawRoundRect(toolbarRect, 22f * density, 22f * density, shadowPaint)canvas.drawRoundRect(toolbarRect, 22f * density, 22f * density, toolbarBgPaint.apply { color = dynamicSurface })- // Draw dedicated drag handle (M3 style bar)val dx = tx + mdragHandleRect.set(dx, ty + m, dx + dragHandleWidth, ty + m + btnHeight)-- val handleBarColor = try {- context.getColor(android.R.color.system_outline_variant_light)- } catch(e: Exception) { Color.LTGRAY }-- val hPaint = Paint(toolbarActionPaint).apply {- color = handleBarColor- style = Paint.Style.FILL- }- // Draw a vertical pill for dragging- canvas.drawRoundRect(- dx + 8f * density,- ty + m + 8f * density,- dx + 16f * density,- ty + m + btnHeight - 8f * density,- 4f * density, 4f * density, hPaint- )+ val hPaint = Paint(toolbarActionPaint).apply { color = Color.LTGRAY; style = Paint.Style.FILL }+ canvas.drawRoundRect(dx + 8f * density, ty + m + 8f * density, dx + 16f * density, ty + m + btnHeight - 8f * density, 4f * density, 4f * density, hPaint)var currentX = tx + m + dragHandleWidth + btnSpacingval newButtons = mutableListOf<ToolbarButton>()-buttonLabels.forEachIndexed { i, label ->val bWidth = labelWidths[i]val bRect = RectF(currentX, ty + m, currentX + bWidth, ty + m + btnHeight)-- // M3 Pill for EVERY button with Dynamic Primary- val dynamicPrimary = try {- context.getColor(android.R.color.system_accent1_600)- } catch(e: Exception) { Color.parseColor("#6750A4") }-+ val dynamicPrimary = try { context.getColor(android.R.color.system_accent1_600) } catch(e: Exception) { Color.parseColor("#6750A4") }canvas.drawRoundRect(bRect, btnHeight / 2, btnHeight / 2, handlePaint.apply { color = dynamicPrimary })- // Fix: Ensure perfect vertical centering by using font metricsval fontMetrics = toolbarActionPaint.fontMetrics- val textHeight = fontMetrics.descent - fontMetrics.ascent- val textOffset = (textHeight / 2) - fontMetrics.descent-+ val textOffset = ((fontMetrics.descent - fontMetrics.ascent) / 2) - fontMetrics.descentcanvas.drawText(label, bRect.centerX(), bRect.centerY() + textOffset, toolbarActionPaint.apply {- color = Color.WHITE- style = Paint.Style.FILL- textSize = 30f- typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)- textAlign = Paint.Align.CENTER+ color = Color.WHITE; style = Paint.Style.FILL; textSize = 30f; typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD); textAlign = Paint.Align.CENTER})-newButtons.add(ToolbarButton(label, Rect(bRect.left.toInt(), bRect.top.toInt(), bRect.right.toInt(), bRect.bottom.toInt())))currentX += bWidth + btnSpacing}toolbarButtons = newButtons}- // ── Touch handling ────────────────────────────────────────────────────-override fun onTouchEvent(event: MotionEvent): Boolean {- val lx = event.x- val ly = event.y-+ val lx = event.x; val ly = event.ywhen (event.action) {MotionEvent.ACTION_DOWN -> {- lastTouchX = lx- lastTouchY = ly-- // Clicks for Top Bar are now handled by ComposeView,- // so we only check the floating toolbar and selection logic.-- // 1. Check toolbar buttons FIRST+ lastTouchX = lx; lastTouchY = lyfor (btn in toolbarButtons) {- val touchRect = Rect(btn.rect).apply { inset(-24, -24) }- if (touchRect.contains(lx.toInt(), ly.toInt())) {- handleToolbarAction(btn.label)- return true+ if (Rect(btn.rect).apply { inset(-24, -24) }.contains(lx.toInt(), ly.toInt())) {+ handleToolbarAction(btn.label); return true}}-- // 2. Check dedicated drag handle ONLY- if (dragHandleRect.contains(lx, ly)) {- isDraggingToolbar = true- return true- }-- // 2. Check for handle drag+ if (dragHandleRect.contains(lx, ly)) { isDraggingToolbar = true; return true }if (globalSelectionStart != -1) {val start = globalSelectionStart.coerceAtMost(globalSelectionEnd)- val end = globalSelectionStart.coerceAtLeast(globalSelectionEnd)+ val end = globalSelectionStart.coerceAtLeast(globalSelectionEnd)val startLocal = toLocal(allWords[start].bounds)- val endLocal = toLocal(allWords[end].bounds)-- if (isPointNear(lx, ly, startLocal.left, startLocal.top)) {- dragHandleType = 1; return true- }- if (isPointNear(lx, ly, endLocal.right, endLocal.bottom)) {- dragHandleType = 2; return true- }+ val endLocal = toLocal(allWords[end].bounds)+ if (isPointNear(lx, ly, startLocal.left, startLocal.top)) { dragHandleType = 1; return true }+ if (isPointNear(lx, ly, endLocal.right, endLocal.bottom)) { dragHandleType = 2; return true }}-- // 3. Glide Select across ALL nodes- val sx = toScreenX(lx)- val sy = toScreenY(ly)+ val sx = toScreenX(lx); val sy = toScreenY(ly)val nearest = findNearestWordGlobal(sx, sy)if (nearest != -1) {- globalSelectionStart = nearest- globalSelectionEnd = nearest- performHapticFeedback(android.view.HapticFeedbackConstants.LONG_PRESS)- invalidate()- return true- } else {- exitNode()- }+ globalSelectionStart = nearest; globalSelectionEnd = nearest+ performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); invalidate(); return true+ } else { globalSelectionStart = -1; globalSelectionEnd = -1; invalidate() }}-MotionEvent.ACTION_MOVE -> {- val dx = lx - lastTouchX- val dy = ly - lastTouchY- lastTouchX = lx- lastTouchY = ly-- if (isDraggingToolbar) {- toolbarOffsetX += dx- toolbarOffsetY += dy- invalidate()- return true- }-- val sx = toScreenX(lx)- val sy = toScreenY(ly)-+ val dx = lx - lastTouchX; val dy = ly - lastTouchY+ lastTouchX = lx; lastTouchY = ly+ if (isDraggingToolbar) { toolbarOffsetX += dx; toolbarOffsetY += dy; invalidate(); return true }+ val sx = toScreenX(lx); val sy = toScreenY(ly)if (dragHandleType != 0) {val nearest = findNearestWordGlobal(sx, sy)if (nearest != -1) {- if (dragHandleType == 1) globalSelectionStart = nearest- else globalSelectionEnd = nearest+ if (dragHandleType == 1) globalSelectionStart = nearest else globalSelectionEnd = nearestinvalidate()}return true- } else if (globalSelectionStart != -1 && globalSelectionEnd != -1) { // Continue selection if already active+ } else if (globalSelectionStart != -1) {val nearest = findNearestWordGlobal(sx, sy)- if (nearest != -1) {- globalSelectionEnd = nearest- invalidate()- return true- }+ if (nearest != -1) { globalSelectionEnd = nearest; invalidate(); return true }}}-MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {- isDraggingToolbar = false- dragHandleType = 0- startSelectionIdx = -1- invalidate()+ isDraggingToolbar = false; dragHandleType = 0; invalidate()}}- return super.onTouchEvent(event)+ return true}private fun findNearestWordGlobal(sx: Float, sy: Float): Int {- var minDist = Float.MAX_VALUE- var nearest = -1+ var minDist = Float.MAX_VALUE; var nearest = -1allWords.forEachIndexed { idx, word ->- val dx = sx - word.bounds.centerX()- val dy = sy - word.bounds.centerY()- val d = dx * dx + dy * dy- // Only consider it a "hit" if it's within a reasonable distance of the block- if (d < minDist) {- minDist = d- nearest = idx- }+ val dx = sx - word.bounds.centerX(); val dy = sy - word.bounds.centerY()+ val d = dx * dx + dy * dy+ if (d < minDist) { minDist = d; nearest = idx }}- // If the nearest word is too far (e.g. empty space), return -1return if (minDist < 600 * 600) nearest else -1}private fun isPointNear(px: Float, py: Float, x: Float, y: Float): Boolean {- val dx = px - x- val dy = py - y+ val dx = px - x; val dy = py - yreturn dx * dx + dy * dy < 80 * 80}---private fun handleToolbarAction(label: String) {val start = globalSelectionStart.coerceAtMost(globalSelectionEnd)- val end = globalSelectionStart.coerceAtLeast(globalSelectionEnd)+ val end = globalSelectionStart.coerceAtLeast(globalSelectionEnd)if (start == -1) return-val selectedText = (start..end).mapNotNull { allWords.getOrNull(it) }.joinToString(" ") { it.text }when (label) {@@ -707,42 +459,14 @@ class CopyTextOverlayManager(}"Share" -> {val intent = android.content.Intent(android.content.Intent.ACTION_SEND).apply {- type = "text/plain"- putExtra(android.content.Intent.EXTRA_TEXT, selectedText)- addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)+ type = "text/plain"; putExtra(android.content.Intent.EXTRA_TEXT, selectedText); addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)}- context.startActivity(android.content.Intent.createChooser(intent, "Share text via").apply {- addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)- })+ context.startActivity(android.content.Intent.createChooser(intent, "Share text via").apply { addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK) })dismiss()}- "All", "Select All" -> {- globalSelectionStart = 0- globalSelectionEnd = allWords.lastIndex- invalidate()- }- "Cancel" -> {- exitNode()- }- }- }--- private fun statusBarsHeight(): Int {- val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")- return if (resourceId > 0) resources.getDimensionPixelSize(resourceId) else 0- }-- // ── Misc ──────────────────────────────────────────────────────────────-- override fun isInEditMode(): Boolean = false-- override fun onKeyDown(keyCode: Int, event: android.view.KeyEvent): Boolean {- if (keyCode == android.view.KeyEvent.KEYCODE_BACK) {- dismiss()- return true+ "All" -> { globalSelectionStart = 0; globalSelectionEnd = allWords.lastIndex; invalidate() }+ "Cancel" -> { globalSelectionStart = -1; globalSelectionEnd = -1; invalidate() }}- return super.onKeyDown(keyCode, event)}}}diff --git a/build_errors_27.txt b/build_errors_27.txtnew file mode 100644index 0000000..51d96c7Binary files /dev/null and b/build_errors_27.txt differdiff --git a/build_errors_28.txt b/build_errors_28.txtnew file mode 100644index 0000000..15cdee0Binary files /dev/null and b/build_errors_28.txt differdiff --git a/build_errors_29.txt b/build_errors_29.txtnew file mode 100644index 0000000..8532902Binary files /dev/null and b/build_errors_29.txt differdiff --git a/builderors.md b/builderors.mdindex 0ee4169..36f5b32 100644--- a/builderors.md+++ b/builderors.md@@ -1,18 +1,18 @@-e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt:257:13 Unresolved reference 'selectionRect'.+e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/components/CopyTextOverlayManager.kt:247:42 Unresolved reference 'ToolbarButton'.Fix with AI-e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt:258:13 Unresolved reference 'selectedBitmap'.+e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/components/CopyTextOverlayManager.kt:247:59 Cannot infer type for this parameter. Please specify it explicitly.Fix with AI-e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt:259:13 Unresolved reference 'isSearching'.+e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/components/CopyTextOverlayManager.kt:361:44 Unresolved reference 'ToolbarButton'.Fix with AI-e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt:260:13 Unresolved reference 'currentPathPoints'.+e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/components/CopyTextOverlayManager.kt:373:32 Unresolved reference 'ToolbarButton'.Fix with AI-e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt:261:13 Unresolved reference 'selectionAnim'.+e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/components/CopyTextOverlayManager.kt:385:38 Unresolved reference 'rect'.Fix with AI-e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt:1048:21 Syntax error: Expecting an expression.+e: file:///C:/Users/ashin/AndroidStudioProjects/CircleToSearch/app/src/main/java/com/akslabs/circletosearch/ui/components/CopyTextOverlayManager.kt:386:53 Unresolved reference 'label'.Fix with AI