CircleToSearch with multi search engine support for all android
Kotlin
docked copy text toolbar in bottom
AKS Labs19395bb42d01
diff --git a/app/src/main/java/com/akslabs/circletosearch/ocr/TesseractEngine.kt b/app/src/main/java/com/akslabs/circletosearch/ocr/TesseractEngine.ktindex dc72ee1..ec1e905 100644--- a/app/src/main/java/com/akslabs/circletosearch/ocr/TesseractEngine.kt+++ b/app/src/main/java/com/akslabs/circletosearch/ocr/TesseractEngine.kt@@ -60,7 +60,14 @@ object TesseractEngine {return@withContext emptyList()}- tess.setImage(bitmap)+ val scale = 2f+ val scaledBitmap = Bitmap.createScaledBitmap(+ bitmap,+ (bitmap.width * scale).toInt(),+ (bitmap.height * scale).toInt(),+ true+ )+ tess.setImage(scaledBitmap)// CRITICAL: We MUST call getUTF8Text() (or other recognition trigger) before accessing the iterator.// Otherwise, resultIterator will be null or empty.@@ -69,6 +76,7 @@ object TesseractEngine {val iterator = tess.resultIterator ?: run {Log.e(TAG, "ResultIterator is null after recognition!")+ scaledBitmap.recycle()tess.recycle()return@withContext emptyList()}@@ -92,15 +100,14 @@ object TesseractEngine {if (wRect.isEmpty || wRect.width() < 2) continue- // We'll wrap each word in a Word object and put it in a single TextNode for now,- // or group them by line if we want to maintain the "TextNode" structure.- // For simplified global selection, a single TextNode per line or even per word is fine.- // Let's group by line to keep the visual "block" grouping if needed.- // Actually, the new global selection treats all words linearly, so we can just- // create one TextNode per word or one per line.- // Let's try to group them by the same line to keep the UI clean.+ // Scale bounds back to original size+ val wordBounds = android.graphics.RectF(+ wRect.left / scale,+ wRect.top / scale,+ wRect.right / scale,+ wRect.bottom / scale+ )- val wordBounds = android.graphics.RectF(wRect)val wordObj = Word(text = wordText,index = allDetectedWords.size,@@ -114,6 +121,8 @@ object TesseractEngine {} while (iterator.next(TessBaseAPI.PageIteratorLevel.RIL_WORD))+ scaledBitmap.recycle()+// Group words into lines based on Y-overlap for better UI groupingval sortedWords = allDetectedWords.sortedBy { it.bounds.top }val lines = mutableListOf<MutableList<Word>>()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 5cfa6ba..13cfd59 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@@ -356,6 +356,13 @@ class CopyTextOverlayManager(private var dragHandleType = 0 // 0=none, 1=start, 2=endprivate var toolbarButtons: List<ToolbarButton> = emptyList()+ private var toolbarRect = RectF()+ private var toolbarOffsetX = 0f+ private var toolbarOffsetY = 0f+ private var isDraggingToolbar = false+ private var lastTouchX = 0f+ private var lastTouchY = 0f+ private var toolbarInitialized = false// ── Node entry / exit ─────────────────────────────────────────────────@@ -472,11 +479,16 @@ class CopyTextOverlayManager(val labelWidths = buttonLabels.map { toolbarActionPaint.measureText(it) + btnPadding * 2 }val totalWidth = labelWidths.sum() + (buttonLabels.size - 1) * btnSpacing + m * 2- val tx = (width - totalWidth) / 2- var ty = anchor.bottom + 30f * density- if (ty + btnHeight + m * 2 > height - 100f) ty = anchor.top - (btnHeight + m * 2) - 30f * density+ val tx = ((width - totalWidth) / 2) + toolbarOffsetX- val toolbarRect = RectF(tx, ty, tx + totalWidth, ty + btnHeight + m * 2)+ if (!toolbarInitialized) {+ // Dock to bottom initially+ toolbarOffsetY = height - (btnHeight + m * 2) - 100f * density+ toolbarInitialized = true+ }+ val ty = toolbarOffsetY++ toolbarRect.set(tx, ty, tx + totalWidth, ty + btnHeight + m * 2)// Dynamic Background with shadowval dynamicSurface = try {@@ -503,11 +515,17 @@ class CopyTextOverlayManager(canvas.drawRoundRect(bRect, btnHeight / 2, btnHeight / 2, handlePaint.apply { color = dynamicPrimary })- canvas.drawText(label, bRect.centerX(), bRect.centerY() + 10f, toolbarActionPaint.apply {+ // Fix: Ensure perfect vertical centering by using font metrics+ val fontMetrics = toolbarActionPaint.fontMetrics+ val textHeight = fontMetrics.descent - fontMetrics.ascent+ val textOffset = (textHeight / 2) - fontMetrics.descent++ canvas.drawText(label, bRect.centerX(), bRect.centerY() + textOffset, toolbarActionPaint.apply {color = Color.WHITEstyle = Paint.Style.FILLtextSize = 30ftypeface = 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())))@@ -524,10 +542,13 @@ class CopyTextOverlayManager(when (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 FIRST with 24px extra hit-padding for reliability+ // 1. Check toolbar buttons FIRSTfor (btn in toolbarButtons) {val touchRect = Rect(btn.rect).apply { inset(-24, -24) }if (touchRect.contains(lx.toInt(), ly.toInt())) {@@ -536,6 +557,12 @@ class CopyTextOverlayManager(}}+ // 2. Check toolbar background dragging+ if (toolbarRect.contains(lx, ly)) {+ isDraggingToolbar = true+ return true+ }+// 2. Check for handle dragif (globalSelectionStart != -1) {val start = globalSelectionStart.coerceAtMost(globalSelectionEnd)@@ -567,6 +594,18 @@ class CopyTextOverlayManager(}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)@@ -589,6 +628,7 @@ class CopyTextOverlayManager(}MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {+ isDraggingToolbar = falsedragHandleType = 0startSelectionIdx = -1invalidate()diff --git a/build_errors_19.txt b/build_errors_19.txtnew file mode 100644index 0000000..f60d987Binary files /dev/null and b/build_errors_19.txt differ