CircleToSearch with multi search engine support for all android
Kotlin
fix: custom overlay screen
AKS Labs277a09288962
diff --git a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.ktindex 9de5789..b57b7ef 100644--- a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt+++ b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt@@ -111,6 +111,7 @@ class CircleToSearchAccessibilityService : AccessibilityService() {private var windowManager: WindowManager? = nullprivate val overlayViews = mutableListOf<View>() // Track all added segment views+ private var statusBarView: View? = null // Dedicated status-bar double-tap strip (independent of segments)private val bottomEdgeViews = mutableListOf<BottomEdgeOverlayView>() // Track bottom-edge corner/mid overlaysprivate val executor: Executor = Executors.newSingleThreadExecutor()private lateinit var configManager: OverlayConfigurationManager@@ -135,6 +136,7 @@ class CircleToSearchAccessibilityService : AccessibilityService() {// On any overlay config change, rebuild the overlayupdateOverlay()updateBottomEdgeOverlays()+ updateStatusBarOverlay()}override fun onServiceConnected() {@@ -172,12 +174,14 @@ class CircleToSearchAccessibilityService : AccessibilityService() {updateBubbleState()updateOverlay()updateBottomEdgeOverlays()+ updateStatusBarOverlay()}override fun onConfigurationChanged(newConfig: Configuration) {super.onConfigurationChanged(newConfig)updateOverlay()updateBottomEdgeOverlays()+ updateStatusBarOverlay()}private fun updateBubbleState() {@@ -328,6 +332,124 @@ class CircleToSearchAccessibilityService : AccessibilityService() {if (!::configManager.isInitialized) returnupdateOverlay()updateBottomEdgeOverlays()+ updateStatusBarOverlay()+ }++ private fun statusBarPrimaryColor(): Int =+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {+ getColor(android.R.color.system_accent1_500)+ } else {+ Color.parseColor("#FF6200EE") // Default Material Primary+ }++ private fun themeOverlayPalette(): List<Int> =+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {+ listOf(+ android.R.color.system_accent1_200,+ android.R.color.system_accent2_200,+ android.R.color.system_accent3_200,+ android.R.color.system_neutral1_200,+ android.R.color.system_neutral2_200+ ).map {+ val color = getColor(it)+ // Solid fill so the visible overlay is clearly distinguishable+ Color.argb(255, Color.red(color), Color.green(color), Color.blue(color))+ }+ } else {+ // Legacy fallbacks (solid)+ listOf(+ Color.parseColor("#FFFF0000"), // Red+ Color.parseColor("#FF00FF00"), // Green+ Color.parseColor("#FF0000FF"), // Blue+ Color.parseColor("#FFFFFF00"), // Yellow+ Color.parseColor("#FFFF00FF") // Magenta+ )+ }++ /**+ * Dedicated, always-on status-bar double-tap strip (Circle to Search),+ * configured from the home screen's status-bar section. Fully independent+ * from the user-defined Custom overlay segments: neither its existence nor+ * its visibility is affected by OverlayConfig.segments or the "Show overlay"+ * switch, and vice versa. Transparent while running; tinted only while the+ * home dropdown preview is open.+ */+ private fun updateStatusBarOverlay() {+ val wm = windowManager ?: return+ if (!::configManager.isInitialized) return+ val cfg = configManager.getStatusBarConfig()+ val density = resources.displayMetrics.density+ val screenWidth = resources.displayMetrics.widthPixels+ val width = if (cfg.widthPx > 0) cfg.widthPx else screenWidth+ val height = if (cfg.heightPx > 0) cfg.heightPx else (24 * density).toInt()+ val yOffset = (3 * density).toInt() + cfg.yOffsetPx+ fun buildSegment() = OverlaySegment(+ width = width,+ height = height,+ xOffset = 0,+ yOffset = cfg.yOffsetPx,+ gestures = mutableMapOf(GestureType.DOUBLE_TAP to ActionType.CTS_AUTO)+ )++ if (!cfg.isEnabled && !cfg.previewVisible) {+ statusBarView?.let { view ->+ try { wm.removeView(view) } catch (_: Exception) {}+ }+ statusBarView = null+ return+ }++ val existing = statusBarView+ if (existing != null) {+ val params = existing.layoutParams as WindowManager.LayoutParams+ var changed = false+ if (params.width != width) { params.width = width; changed = true }+ if (params.height != height) { params.height = height; changed = true }+ if (params.y != yOffset) { params.y = yOffset; changed = true }+ if (changed) {+ try { wm.updateViewLayout(existing, params) } catch (_: Exception) {}+ // Re-attach so the full-width smart-swipe check uses the new width.+ attachTouchListener(existing, buildSegment(), 0)+ }+ applyStatusBarTint(existing, cfg.previewVisible)+ return+ }+ val view = View(this)+ val params = WindowManager.LayoutParams(+ width,+ height,+ WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY,+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or+ WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or+ WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or+ WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,+ PixelFormat.TRANSLUCENT+ )+ params.gravity = Gravity.TOP or Gravity.START+ params.x = 0+ params.y = yOffset+ attachTouchListener(view, buildSegment(), 0)+ applyStatusBarTint(view, cfg.previewVisible)+ try {+ wm.addView(view, params)+ statusBarView = view+ } catch (e: Exception) {+ e.printStackTrace()+ }+ }++ private fun applyStatusBarTint(view: View, tinted: Boolean) {+ if (tinted) {+ val drawable = GradientDrawable().apply {+ setColor(themeOverlayPalette()[0])+ cornerRadius = 3 * resources.displayMetrics.density+ setStroke(2, statusBarPrimaryColor())+ }+ view.background = drawable+ } else {+ view.background = null+ view.setBackgroundColor(Color.TRANSPARENT)+ }}private fun updateOverlay() {@@ -349,34 +471,8 @@ class CircleToSearchAccessibilityService : AccessibilityService() {}// --- Resolution of Colors ---- val primaryColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {- getColor(android.R.color.system_accent1_500)- } else {- Color.parseColor("#FF6200EE") // Default Material Primary- }-- val themePalette = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {- listOf(- android.R.color.system_accent1_200,- android.R.color.system_accent2_200,- android.R.color.system_accent3_200,- android.R.color.system_neutral1_200,- android.R.color.system_neutral2_200- ).map {- val color = getColor(it)- // Set alpha to 40% (approx 102/255) for subtle blending- Color.argb(102, Color.red(color), Color.green(color), Color.blue(color))- }- } else {- // Legacy fallbacks with 40% opacity- listOf(- Color.parseColor("#66FF0000"), // Red- Color.parseColor("#6600FF00"), // Green- Color.parseColor("#660000FF"), // Blue- Color.parseColor("#66FFFF00"), // Yellow- Color.parseColor("#66FF00FF") // Magenta- )- }+ val primaryColor = statusBarPrimaryColor()+ val themePalette = themeOverlayPalette()// Landscape checkval currentOrientation = resources.configuration.orientation@@ -421,6 +517,7 @@ class CircleToSearchAccessibilityService : AccessibilityService() {val color = themePalette[index % themePalette.size]val drawable = GradientDrawable().apply {setColor(color)+ cornerRadius = 3 * resources.displayMetrics.density// Outline every visible strip so its position is obvious while// adjusting; the strip being edited gets a thicker border.setStroke(@@ -474,6 +571,7 @@ class CircleToSearchAccessibilityService : AccessibilityService() {val color = themePalette[index % themePalette.size]val drawable = GradientDrawable().apply {setColor(color)+ cornerRadius = 3 * resources.displayMetrics.density// Outline every visible strip so its position is obvious while// adjusting; the strip being edited gets a thicker border.setStroke(@@ -1895,6 +1993,10 @@ class CircleToSearchAccessibilityService : AccessibilityService() {e.printStackTrace()}}+ statusBarView?.let { view ->+ try { windowManager?.removeView(view) } catch (_: Exception) {}+ }+ statusBarView = nullbottomEdgeViews.forEach { view ->try { windowManager?.removeView(view) } catch (_: Exception) {}}diff --git a/app/src/main/java/com/akslabs/circletosearch/data/OverlayConfig.kt b/app/src/main/java/com/akslabs/circletosearch/data/OverlayConfig.ktindex 7f14935..bee6855 100644--- a/app/src/main/java/com/akslabs/circletosearch/data/OverlayConfig.kt+++ b/app/src/main/java/com/akslabs/circletosearch/data/OverlayConfig.kt@@ -17,7 +17,7 @@ data class OverlayConfig(@SerializedName("isVisible") val isVisible: Boolean = false, // Debug visibility (colored)@SerializedName("previewVisible") val previewVisible: Boolean = false, // true only while the settings dropdown is open@SerializedName("activeSegmentIndex") val activeSegmentIndex: Int = -1, // Currently being edited in settings- @SerializedName("segments") val segments: List<OverlaySegment> = listOf(OverlaySegment(width = 1080)) // Default to a common large width+ @SerializedName("segments") val segments: List<OverlaySegment> = emptyList() // No default overlay — users add their own in Custom overlay)data class OverlaySegment(@@ -43,6 +43,20 @@ data class BottomEdgeConfig(@SerializedName("previewVisible") val previewVisible: Boolean = false, // true only while settings dropdown open)+/**+ * Dedicated config for the always-on status-bar double-tap strip configured from+ * the home screen. Fully separate from the user-defined Custom overlay segments:+ * neither its visibility nor its master switch affects OverlayConfig.segments,+ * and vice versa.+ */+data class StatusBarConfig(+ @SerializedName("isEnabled") val isEnabled: Boolean = true,+ @SerializedName("widthPx") val widthPx: Int = 0, // 0 = full screen width+ @SerializedName("heightPx") val heightPx: Int = 0, // 0 = default 24dp+ @SerializedName("yOffsetPx") val yOffsetPx: Int = 0, // below the 3dp system inset+ @SerializedName("previewVisible") val previewVisible: Boolean = false, // true while home dropdown is open+)+enum class GestureType {DOUBLE_TAP,LONG_PRESS,@@ -144,7 +158,9 @@ class OverlayConfigurationManager(context: Context) {companion object {private const val KEY_CONFIG = "overlay_config"private const val KEY_BOTTOM_EDGE = "bottom_edge_config"+private const val KEY_STATUS_BAR = "status_bar_config"private const val KEY_BOTTOM_EDGE_MID_MIGRATED = "bottom_edge_mid_migrated_v1"+private const val KEY_STATUS_BAR_DEDICATED_MIGRATED = "status_bar_dedicated_migrated_v1"}fun getConfig(): OverlayConfig {@@ -156,6 +172,20 @@ private const val KEY_BOTTOM_EDGE_MID_MIGRATED = "bottom_edge_mid_migrated_v1"val sanitizedSegments = config.segments.map { segment ->val cleanGestures = segment.gestures.filterKeys { it != null }.toMutableMap()segment.copy(gestures = cleanGestures)+ }.toMutableList()+ // One-time migration: the legacy default segment (full-width status-bar+ // strip, double-tap -> CTS) is now provided by a dedicated always-on+ // overlay in the accessibility service. Remove it from saved user+ // segments so the two aren't duplicated.+ if (!prefs.getBoolean(KEY_STATUS_BAR_DEDICATED_MIGRATED, false)) {+ sanitizedSegments.removeAll { seg ->+ seg.width == 1080 && seg.height == 60 && seg.xOffset == 0 && seg.yOffset == 0 &&+ seg.gestures == mapOf(GestureType.DOUBLE_TAP to ActionType.CTS_AUTO)+ }+ prefs.edit()+ .putBoolean(KEY_STATUS_BAR_DEDICATED_MIGRATED, true)+ .putString(KEY_CONFIG, gson.toJson(config.copy(segments = sanitizedSegments)))+ .apply()}return config.copy(segments = sanitizedSegments)} catch (e: Exception) {@@ -201,4 +231,18 @@ private const val KEY_BOTTOM_EDGE_MID_MIGRATED = "bottom_edge_mid_migrated_v1"fun saveBottomEdgeConfig(config: BottomEdgeConfig) {prefs.edit().putString(KEY_BOTTOM_EDGE, gson.toJson(config)).apply()}++ fun getStatusBarConfig(): StatusBarConfig {+ val json = prefs.getString(KEY_STATUS_BAR, null)+ ?: return StatusBarConfig()+ return try {+ gson.fromJson(json, StatusBarConfig::class.java) ?: StatusBarConfig()+ } catch (e: Exception) {+ StatusBarConfig()+ }+ }++ fun saveStatusBarConfig(config: StatusBarConfig) {+ prefs.edit().putString(KEY_STATUS_BAR, gson.toJson(config)).apply()+ }}diff --git a/app/src/main/java/com/akslabs/circletosearch/ui/wobblepulldown/WobbleAppInfoScreen.kt b/app/src/main/java/com/akslabs/circletosearch/ui/wobblepulldown/WobbleAppInfoScreen.ktindex c5f1b2a..0b26a20 100644--- a/app/src/main/java/com/akslabs/circletosearch/ui/wobblepulldown/WobbleAppInfoScreen.kt+++ b/app/src/main/java/com/akslabs/circletosearch/ui/wobblepulldown/WobbleAppInfoScreen.kt@@ -144,7 +144,7 @@ private fun loadAppInfo(context: Context): AppInfoData {private fun loadLaunchMethods(context: Context): List<LaunchMethod> {val a11y = isA11yGranted(context)- val overlayOn = OverlayConfigurationManager(context).getConfig().isEnabled+ val overlayOn = OverlayConfigurationManager(context).getStatusBarConfig().isEnabledval appPrefs = context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE)val bubbleOn = appPrefs.getBoolean("bubble_enabled", false)val hwCount = HW_TRIGGER_KEYS.count { appPrefs.getBoolean(it, false) }diff --git a/app/src/main/java/com/akslabs/circletosearch/ui/wobblepulldown/WobbleHomeScreen.kt b/app/src/main/java/com/akslabs/circletosearch/ui/wobblepulldown/WobbleHomeScreen.ktindex 4043c30..b0177c7 100644--- a/app/src/main/java/com/akslabs/circletosearch/ui/wobblepulldown/WobbleHomeScreen.kt+++ b/app/src/main/java/com/akslabs/circletosearch/ui/wobblepulldown/WobbleHomeScreen.kt@@ -117,9 +117,8 @@ import com.akslabs.circletosearch.SupportDialogHostimport com.akslabs.circletosearch.data.ActionTypeimport com.akslabs.circletosearch.data.BottomEdgeConfigimport com.akslabs.circletosearch.data.GestureType-import com.akslabs.circletosearch.data.OverlayConfigimport com.akslabs.circletosearch.data.OverlayConfigurationManager-import com.akslabs.circletosearch.data.OverlaySegment+import com.akslabs.circletosearch.data.StatusBarConfigimport com.akslabs.circletosearch.ui.SettingsSectionHeaderimport com.akslabs.circletosearch.ui.components.UnifiedSearchMethodSelectorimport com.akslabs.circletosearch.utils.UIPreferences@@ -209,8 +208,7 @@ fun WobbleHomeScreen(val uiPreferences = remember { UIPreferences(context) }var a11yGranted by remember { mutableStateOf(isA11yGranted(context)) }var assistantGranted by remember { mutableStateOf(isAssistantGranted(context)) }- var overlayEnabled by remember { mutableStateOf(configManager.getConfig().isEnabled) }- var overlayConfig by remember { mutableStateOf(configManager.getConfig()) }+ var statusBarCfg by remember { mutableStateOf(configManager.getStatusBarConfig()) }var bubbleEnabled by remember { mutableStateOf(appPrefs.getBoolean("bubble_enabled", false)) }var hwTriggers by remember {mutableStateOf(HW_TRIGGER_KEYS.associateWith { appPrefs.getBoolean(it, false) })@@ -222,13 +220,12 @@ fun WobbleHomeScreen(val bottomEdgeActive = bottomEdge.leftEnabled || bottomEdge.rightEnabled || bottomEdge.midEnabledval hwEnabledCount = hwTriggers.values.count { it }val running = assistantGranted ||- (a11yGranted && (overlayEnabled || bubbleEnabled || bottomEdgeActive || hwEnabledCount > 0))+ (a11yGranted && (statusBarCfg.isEnabled || bubbleEnabled || bottomEdgeActive || hwEnabledCount > 0))val refreshHomeState = {a11yGranted = isA11yGranted(context)assistantGranted = isAssistantGranted(context)- overlayEnabled = configManager.getConfig().isEnabled- overlayConfig = configManager.getConfig()+ statusBarCfg = configManager.getStatusBarConfig()bubbleEnabled = appPrefs.getBoolean("bubble_enabled", false)hwTriggers = HW_TRIGGER_KEYS.associateWith { appPrefs.getBoolean(it, false) }bottomEdge = configManager.getBottomEdgeConfig()@@ -267,10 +264,9 @@ fun WobbleHomeScreen(context.startActivity(intent, options.toBundle())}- val saveOverlayConfig: (OverlayConfig) -> Unit = { cfg ->- configManager.saveConfig(cfg)- overlayConfig = cfg- overlayEnabled = cfg.isEnabled+ val saveStatusBar: (StatusBarConfig) -> Unit = { cfg ->+ configManager.saveStatusBarConfig(cfg)+ statusBarCfg = cfg}val setBubbleEnabled: (Boolean) -> Unit = { on ->@@ -305,6 +301,8 @@ fun WobbleHomeScreen(onDispose {val cur = configManager.getBottomEdgeConfig()if (cur.previewVisible) configManager.saveBottomEdgeConfig(cur.copy(previewVisible = false))+ val status = configManager.getStatusBarConfig()+ if (status.previewVisible) configManager.saveStatusBarConfig(status.copy(previewVisible = false))}}@@ -560,11 +558,11 @@ fun WobbleHomeScreen() {Column {HomeStatusBarSection(- config = overlayConfig,+ config = statusBarCfg,a11yGranted = a11yGranted,expanded = statusBarExpanded,onExpandedChange = { statusBarExpanded = it },- onChange = saveOverlayConfig,+ onChange = saveStatusBar,)HomeRowDivider()HomeToggleItem(@@ -880,14 +878,15 @@ private fun HomeHwSheet(* Expandable block for the status-bar overlay, mirroring [HomeBottomEdgeSection]:* a header row with a master switch, and a dropdown with an animated strip preview* plus width / height / vertical-position sliders for the top trigger strip.+ * Driven by [StatusBarConfig] — fully independent from Custom overlay segments.*/@Composableprivate fun HomeStatusBarSection(- config: OverlayConfig,+ config: StatusBarConfig,a11yGranted: Boolean,expanded: Boolean,onExpandedChange: (Boolean) -> Unit,- onChange: (OverlayConfig) -> Unit,+ onChange: (StatusBarConfig) -> Unit,) {val masterOn = config.isEnabledval density = LocalDensity.current@@ -905,18 +904,10 @@ private fun HomeStatusBarSection(}}- val segment = config.segments.firstOrNull() ?: OverlaySegment()- fun saveSegment(newSegment: OverlaySegment) {- val segments = config.segments.toMutableList()- if (segments.isEmpty()) segments.add(newSegment) else segments[0] = newSegment- onChange(config.copy(segments = segments))- }-val screenWidthDp = LocalConfiguration.current.screenWidthDp.toFloat()- val screenWidthPx = screenWidthDp * density.density- val widthDp = segment.width / density.density- val heightDp = segment.height / density.density- val yDp = segment.yOffset / density.density+ val widthDp = if (config.widthPx > 0) config.widthPx / density.density else screenWidthDp+ val heightDp = if (config.heightPx > 0) config.heightPx / density.density else 24f+ val yDp = config.yOffsetPx / density.densityColumn(modifier = Modifier.fillMaxWidth()) {Row(@@ -992,7 +983,7 @@ private fun HomeStatusBarSection(contentAlignment = Alignment.TopCenter,) {val stripWidthFraction =- (segment.width / screenWidthPx).coerceIn(0.08f, 1f)+ (widthDp / screenWidthDp).coerceIn(0.08f, 1f)Box(modifier = Modifier.padding(top = yDp.dp)@@ -1013,7 +1004,7 @@ private fun HomeStatusBarSection(valueRange = 60f..maxOf(screenWidthDp, widthDp),valueText = "${widthDp.toInt()}dp",onValueChange = {- saveSegment(segment.copy(width = (it * density.density).toInt()))+ onChange(config.copy(widthPx = (it * density.density).toInt()))},)LabelledSlider(@@ -1022,7 +1013,7 @@ private fun HomeStatusBarSection(valueRange = 24f..140f,valueText = "${heightDp.toInt()}dp",onValueChange = {- saveSegment(segment.copy(height = (it * density.density).toInt()))+ onChange(config.copy(heightPx = (it * density.density).toInt()))},)LabelledSlider(@@ -1031,7 +1022,7 @@ private fun HomeStatusBarSection(valueRange = 0f..160f,valueText = "${yDp.toInt()}dp",onValueChange = {- saveSegment(segment.copy(yOffset = (it * density.density).toInt()))+ onChange(config.copy(yOffsetPx = (it * density.density).toInt()))},)}