Skip to content

CircleToSearch with multi search engine support for all android

Kotlin

added proper roundness and physics to pinned sticker

AKS Labs73ab67064138
diff --git a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt
index e1101d6..0c37c6b 100644
--- a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt
+++ b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt
@@ -34,6 +34,14 @@ import android.graphics.Rect
import android.graphics.Typeface
import android.graphics.drawable.GradientDrawable
import android.hardware.camera2.CameraManager
+import android.graphics.Path
+import android.graphics.RectF
+import android.graphics.Canvas
+import android.graphics.Paint
+import android.graphics.BitmapShader
+import android.graphics.Shader
+import android.graphics.Matrix
+import androidx.core.graphics.drawable.toBitmap
import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator
@@ -631,12 +639,10 @@ class CircleToSearchAccessibilityService : AccessibilityService() {
handler.postDelayed({
dispatchGesture(gesture, object : android.accessibilityservice.AccessibilityService.GestureResultCallback() {
override fun onCompleted(gestureDescription: android.accessibilityservice.GestureDescription?) {
- super.onCompleted(gestureDescription)
restoreFlags()
}
override fun onCancelled(gestureDescription: android.accessibilityservice.GestureDescription?) {
- super.onCancelled(gestureDescription)
restoreFlags()
}
@@ -736,6 +742,37 @@ class CircleToSearchAccessibilityService : AccessibilityService() {
startActivity(intent)
}
+ // Custom ImageView that clips to rounded corners on the Canvas level
+ // This is much more robust than OutlineProvider for rapid movements and scaling.
+ private class RoundedImageView(context: android.content.Context) : android.widget.ImageView(context) {
+ private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
+ private val rect = RectF()
+ private val matrix = Matrix()
+ private val radius = 12f * context.resources.displayMetrics.density
+
+ override fun onDraw(canvas: android.graphics.Canvas) {
+ val drawable = drawable ?: return
+ val bitmap = try {
+ drawable.toBitmap()
+ } catch (e: Exception) {
+ return
+ }
+
+ val shader = BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
+
+ // Adjust shader to current view bounds
+ matrix.reset()
+ matrix.setScale(width.toFloat() / bitmap.width, height.toFloat() / bitmap.height)
+ shader.setLocalMatrix(matrix)
+
+ paint.shader = shader
+ rect.set(0f, 0f, width.toFloat(), height.toFloat())
+
+ // This never "looses roundness" because it's rendering at the pixel level on each frame
+ canvas.drawRoundRect(rect, radius, radius, paint)
+ }
+ }
+
private fun showPinnedArea(bitmap: Bitmap, rect: android.graphics.Rect) {
android.util.Log.d("CircleToSearch", "showPinnedArea called for rect: $rect")
@@ -764,16 +801,10 @@ class CircleToSearchAccessibilityService : AccessibilityService() {
params.x = centerX - width / 2
params.y = centerY - height / 2
- val pinnedView = android.widget.ImageView(this).apply {
+ val pinnedView = RoundedImageView(this).apply {
setImageBitmap(bitmap)
scaleType = android.widget.ImageView.ScaleType.FIT_CENTER
- elevation = 0f // Phase 35: Remove shadows
- outlineProvider = object : ViewOutlineProvider() {
- override fun getOutline(view: View, outline: android.graphics.Outline) {
- // Phase 35: Fixed corner radius to be consistent with lens
- outline.setRoundRect(0, 0, view.width, view.height, 12f * resources.displayMetrics.density)
- }
- }
+ elevation = 0f
clipToOutline = true
var initialX = 0
@@ -793,11 +824,6 @@ class CircleToSearchAccessibilityService : AccessibilityService() {
flingAnimator = null
}
- // Function to ensure consistent roundness during any size/scale change
- val updateOutline = {
- }
-
// --- Phase 33: ScaleGestureDetector for pinch zoom ---
val scaleDetector = ScaleGestureDetector(context, object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
override fun onScale(detector: ScaleGestureDetector): Boolean {
@@ -822,7 +848,6 @@ class CircleToSearchAccessibilityService : AccessibilityService() {
params.width = newWidth
params.height = newHeight
windowManager?.updateViewLayout(this@apply, params)
- updateOutline()
}
return true
}
@@ -919,15 +944,32 @@ class CircleToSearchAccessibilityService : AccessibilityService() {
params.y = params.y.coerceIn(0, display.heightPixels - params.height)
}
- try { windowManager?.updateViewLayout(v, params) } catch(e: Exception) { anim.cancel() }
+ try {
+ windowManager?.updateViewLayout(v, params)
+ // v.invalidateOutline() // No longer needed with canvas clipping
+ } catch(e: Exception) {
+ anim.cancel()
+ flingAnimator = null
+ }
// Lower friction for fun play
currVx *= 0.992f
currVy *= 0.992f
- // Stop if too slow
- if (Math.abs(currVx) < 40 && Math.abs(currVy) < 40) anim.cancel()
+ // Safety check: if velocity is zero or view is gone, stop
+ if (Math.abs(currVx) < 10 && Math.abs(currVy) < 10) {
+ anim.cancel()
+ flingAnimator = null
+ }
}
+ addListener(object : android.animation.AnimatorListenerAdapter() {
+ override fun onAnimationEnd(animation: android.animation.Animator) {
+ flingAnimator = null
+ }
+ override fun onAnimationCancel(animation: android.animation.Animator) {
+ flingAnimator = null
+ }
+ })
start()
}
}
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 8de253d..ee5b48c 100644
--- a/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt
+++ b/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt
@@ -23,6 +23,7 @@ import android.graphics.Bitmap
import android.graphics.Rect
import com.akslabs.circletosearch.CircleToSearchAccessibilityService
import android.util.Base64
+import android.view.Display
import android.view.ViewGroup
import android.webkit.WebSettings
import android.webkit.WebView
@@ -65,6 +66,8 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
@@ -1485,23 +1488,31 @@ fun CircleToSearchScreen(
Row(
modifier = Modifier
.fillMaxWidth()
- .padding(horizontal = 8.dp)
- .horizontalScroll(rememberScrollState()),
- horizontalArrangement = Arrangement.spacedBy(8.dp),
- verticalAlignment = Alignment.CenterVertically
+ .padding(horizontal = 4.dp),
+ horizontalArrangement = Arrangement.Center,
+ verticalAlignment = Alignment.Bottom
) {
@Composable
fun BottomBarButton(label: String, icon: @Composable () -> Unit, onClick: () -> Unit) {
- Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(4.dp)) {
- FilledTonalIconButton(
- onClick = { haptic.performHapticFeedback(androidx.compose.ui.hapticfeedback.HapticFeedbackType.LongPress); onClick() },
- modifier = Modifier.size(52.dp),
- colors = IconButtonDefaults.filledTonalIconButtonColors(
- containerColor = MaterialTheme.colorScheme.surfaceContainer,
- contentColor = MaterialTheme.colorScheme.onSurface
+ Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.BottomCenter) {
+ Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(1.dp)) {
+ FilledTonalIconButton(
+ onClick = { haptic.performHapticFeedback(androidx.compose.ui.hapticfeedback.HapticFeedbackType.LongPress); onClick() },
+ modifier = Modifier.size(46.dp),
+ colors = IconButtonDefaults.filledTonalIconButtonColors(
+ containerColor = MaterialTheme.colorScheme.surfaceContainer,
+ contentColor = MaterialTheme.colorScheme.onSurface
+ )
+ ) { icon() }
+ Text(
+ text = label,
+ style = MaterialTheme.typography.labelSmall.copy(fontSize = 8.sp),
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ textAlign = TextAlign.Center,
+ maxLines = 1,
+ softWrap = false
)
- ) { icon() }
- Text(text = label, style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.Center, maxLines = 1, softWrap = false)
+ }
}
}
@@ -1512,43 +1523,44 @@ fun CircleToSearchScreen(
// Pin
val isPinEnabled = selectedBitmap != null
- Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(4.dp)) {
- FilledTonalIconButton(
- onClick = {
- if (isPinEnabled) {
- haptic.performHapticFeedback(androidx.compose.ui.hapticfeedback.HapticFeedbackType.LongPress)
- selectedBitmap?.let { bmp ->
- CircleToSearchAccessibilityService.pinArea(bmp, selectionRect ?: android.graphics.Rect())
- // Close CTS UI after pinning
- (context as? android.app.Activity)?.finish()
+ Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.BottomCenter) {
+ Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(1.dp)) {
+ FilledTonalIconButton(
+ onClick = {
+ if (isPinEnabled) {
+ haptic.performHapticFeedback(androidx.compose.ui.hapticfeedback.HapticFeedbackType.LongPress)
+ selectedBitmap?.let { bmp ->
+ CircleToSearchAccessibilityService.pinArea(bmp, selectionRect ?: android.graphics.Rect())
+ (context as? android.app.Activity)?.finish()
+ }
}
- }
- },
- modifier = Modifier.size(52.dp),
- colors = IconButtonDefaults.filledTonalIconButtonColors(
- containerColor = MaterialTheme.colorScheme.surfaceContainer,
- contentColor = if (isPinEnabled) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f),
- disabledContainerColor = MaterialTheme.colorScheme.surfaceContainer,
- disabledContentColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
+ },
+ modifier = Modifier.size(46.dp),
+ colors = IconButtonDefaults.filledTonalIconButtonColors(
+ containerColor = MaterialTheme.colorScheme.surfaceContainer,
+ contentColor = if (isPinEnabled) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f),
+ disabledContainerColor = MaterialTheme.colorScheme.surfaceContainer,
+ disabledContentColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
+ )
+ ) {
+ Icon(
+ Icons.Default.PushPin,
+ contentDescription = "Pin Selection",
+ modifier = Modifier.size(20.dp)
+ )
+ }
+ Text(
+ text = "Pin",
+ style = MaterialTheme.typography.labelSmall.copy(fontSize = 8.sp),
+ color = if (isPinEnabled) MaterialTheme.colorScheme.onSurfaceVariant else MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.38f),
+ textAlign = TextAlign.Center,
+ maxLines = 1,
+ softWrap = false
)
- ) {
- Icon(
- Icons.Default.PushPin,
- contentDescription = "Pin Selection",
- modifier = Modifier.size(22.dp)
- )
}
- Text(
- text = "Pin",
- style = MaterialTheme.typography.labelSmall,
- color = if (isPinEnabled) MaterialTheme.colorScheme.onSurfaceVariant else MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.38f),
- textAlign = TextAlign.Center,
- maxLines = 1,
- softWrap = false
- )
}
- // Phase 44: Smart Entity Extractor
+ // Smart Entity Extractor
BottomBarButton("Smart Extract", { Icon(Icons.Default.Search, null, modifier = Modifier.size(22.dp)) }) {
isEntityExtractMode = true
if (detectedEntities.isEmpty() && !isExtractingEntities) {