CircleToSearch with multi search engine support for all android
Kotlin
added floating button
AKS Labs4e4e6dff109c
diff --git a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchService.kt b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchService.ktindex 53af164..bc0d820 100644--- a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchService.kt+++ b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchService.kt@@ -22,10 +22,72 @@ class CircleToSearchService : AccessibilityService() {private var windowManager: WindowManager? = nullprivate var triggerView: View? = nullprivate val executor: Executor = Executors.newSingleThreadExecutor()++ private var bubbleView: View? = null+ private val prefs by lazy { getSharedPreferences("app_prefs", Context.MODE_PRIVATE) }+ private val prefsListener = android.content.SharedPreferences.OnSharedPreferenceChangeListener { _, key ->+ if (key == "bubble_enabled") {+ updateBubbleState()+ }+ }override fun onServiceConnected() {super.onServiceConnected()setupTriggerOverlay()+ prefs.registerOnSharedPreferenceChangeListener(prefsListener)+ updateBubbleState()+ }++ private fun updateBubbleState() {+ if (prefs.getBoolean("bubble_enabled", false)) {+ showBubble()+ } else {+ hideBubble()+ }+ }++ private fun showBubble() {+ if (bubbleView != null) return // Already shown++ bubbleView = View(this).apply {+ background = android.graphics.drawable.GradientDrawable().apply {+ shape = android.graphics.drawable.GradientDrawable.OVAL+ setColor(android.graphics.Color.parseColor("#4285F4")) // Google Blue+ setStroke(4, android.graphics.Color.WHITE)+ }+ elevation = 10f+ setOnClickListener {+ performCapture()+ }+ }++ val params = WindowManager.LayoutParams(+ 150, 150,+ WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY,+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or+ WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,+ PixelFormat.TRANSLUCENT+ )+ params.gravity = Gravity.CENTER_VERTICAL or Gravity.END+ params.x = 0+ params.y = 200 // Offset slightly++ try {+ windowManager?.addView(bubbleView, params)+ } catch (e: Exception) {+ e.printStackTrace()+ }+ }++ private fun hideBubble() {+ if (bubbleView != null) {+ try {+ windowManager?.removeView(bubbleView)+ } catch (e: Exception) {+ e.printStackTrace()+ }+ bubbleView = null+ }}private fun setupTriggerOverlay() {@@ -53,14 +115,16 @@ class CircleToSearchService : AccessibilityService() {triggerView?.setOnTouchListener { _, event ->gestureDetector.onTouchEvent(event)- false // Pass touch through so we don't block status bar interactions completely?- // Actually, if we want to intercept double tap, we might consume it.- // But for status bar, we usually want clicks to pass through if it's not a double tap.- // However, returning false here means the gesture detector might not get the full stream.- // Let's try returning true if we want to consume, but for now we want to be "smart".- // A simple overlay that consumes touches might block the status bar.- // To avoid blocking, we might need a more complex setup or just accept that we block that thin strip.- // For this demo, blocking the top 100px for double tap is acceptable as per requirements "smart invisible overlay".+ // Pass touch through so we don't block status bar interactions completely+ // But we need to return true to consume events for gesture detector to work?+ // Actually, if we return false, the gesture detector might not see the full sequence.+ // But if we return true, we block clicks.+ // For a transparent overlay, usually we want to pass through.+ // However, GestureDetector needs the stream.+ // A common trick is to use FLAG_NOT_TOUCH_MODAL and let touches pass through *if* we don't consume them?+ // But we are just an overlay.+ // Let's stick to the previous logic which was 'true' but maybe refine it if user complains about blocked status bar.+ // For now, keep it simple.true}@@ -115,8 +179,10 @@ class CircleToSearchService : AccessibilityService() {override fun onDestroy() {super.onDestroy()+ prefs.unregisterOnSharedPreferenceChangeListener(prefsListener)if (triggerView != null && windowManager != null) {windowManager?.removeView(triggerView)}+ hideBubble()}}diff --git a/app/src/main/java/com/akslabs/circletosearch/MainActivity.kt b/app/src/main/java/com/akslabs/circletosearch/MainActivity.ktindex 2bb8fd4..0d6b61f 100644--- a/app/src/main/java/com/akslabs/circletosearch/MainActivity.kt+++ b/app/src/main/java/com/akslabs/circletosearch/MainActivity.kt@@ -12,11 +12,16 @@ import androidx.compose.foundation.layout.Spacerimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.material3.Buttonimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Surface+import androidx.compose.material3.Switchimport androidx.compose.material3.Textimport androidx.compose.runtime.Composable+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.rememberimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.LocalContext@@ -73,5 +78,34 @@ fun SetupScreen() {}) {Text("Enable Overlay Permission")}++ Spacer(modifier = Modifier.height(32.dp))++ BubbleSwitch(context)+ }+}++@Composable+fun BubbleSwitch(context: android.content.Context) {+ val prefs = context.getSharedPreferences("app_prefs", android.content.Context.MODE_PRIVATE)+ val isBubbleEnabled = remember { mutableStateOf(prefs.getBoolean("bubble_enabled", false)) }++ Row(+ verticalAlignment = Alignment.CenterVertically,+ horizontalArrangement = Arrangement.SpaceBetween,+ modifier = Modifier+ .fillMaxWidth()+ .padding(horizontal = 32.dp)+ ) {+ Text("Enable Floating Bubble")+ Switch(+ checked = isBubbleEnabled.value,+ onCheckedChange = { enabled ->+ isBubbleEnabled.value = enabled+ prefs.edit().putBoolean("bubble_enabled", enabled).apply()+ // Notify service if running?+ // The service will listen to preference changes.+ }+ )}}\ No newline at end of filediff --git a/app/src/main/res/xml/accessibility_service_config.xml b/app/src/main/res/xml/accessibility_service_config.xmlindex 21c1e14..c3eee45 100644--- a/app/src/main/res/xml/accessibility_service_config.xml+++ b/app/src/main/res/xml/accessibility_service_config.xml@@ -6,5 +6,6 @@android:canRetrieveWindowContent="true"android:canRequestFilterKeyEvents="true"android:canPerformGestures="true"+ android:canTakeScreenshot="true"android:description="@string/app_name"android:notificationTimeout="100" />