CircleToSearch with multi search engine support for all android
Kotlin
added advance settings
AKS Labsf1066028647b
diff --git a/app/build.gradle.kts b/app/build.gradle.ktsindex 1d4c657..1ed58bf 100644--- a/app/build.gradle.kts+++ b/app/build.gradle.kts@@ -34,8 +34,8 @@ android {applicationId = "com.akslabs.circletosearch"minSdk = 29targetSdk = 36- versionCode = 2- versionName = "0.2"+ versionCode = 3+ versionName = "0.3"testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"}@@ -88,4 +88,5 @@ dependencies {implementation("androidx.compose.material:material-icons-extended")implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")implementation("androidx.webkit:webkit:1.9.0")+ implementation("com.google.code.gson:gson:2.10.1")}\ No newline at end of filediff --git a/app/release/app-release.aab b/app/release/app-release.aabindex 89be73f..6b7d7c7 100644Binary files a/app/release/app-release.aab and b/app/release/app-release.aab differdiff --git a/app/release/app-release.apk b/app/release/app-release.apkindex 5462d58..e6a1cf0 100644Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differdiff --git a/app/release/baselineProfiles/0/app-release.dm b/app/release/baselineProfiles/0/app-release.dmindex 7fc2dcd..222e6b4 100644Binary files a/app/release/baselineProfiles/0/app-release.dm and b/app/release/baselineProfiles/0/app-release.dm differdiff --git a/app/release/baselineProfiles/1/app-release.dm b/app/release/baselineProfiles/1/app-release.dmindex 577b27e..f1906e2 100644Binary files a/app/release/baselineProfiles/1/app-release.dm and b/app/release/baselineProfiles/1/app-release.dm differdiff --git a/app/release/output-metadata.json b/app/release/output-metadata.jsonindex 79702a0..4bd1c83 100644--- a/app/release/output-metadata.json+++ b/app/release/output-metadata.json@@ -11,8 +11,8 @@"type": "SINGLE","filters": [],"attributes": [],- "versionCode": 2,- "versionName": "0.2",+ "versionCode": 3,+ "versionName": "0.","outputFile": "app-release.apk"}],diff --git a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.ktindex 0f8753f..e01ed6c 100644--- a/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt+++ b/app/src/main/java/com/akslabs/circletosearch/CircleToSearchAccessibilityService.kt@@ -20,10 +20,16 @@package com.akslabs.circletosearchimport android.accessibilityservice.AccessibilityService+import android.annotation.SuppressLintimport android.content.Contextimport android.content.Intent+import android.content.SharedPreferences+import android.content.pm.ActivityInfo+import android.content.res.Configurationimport android.graphics.Bitmap+import android.graphics.Colorimport android.graphics.PixelFormat+import android.hardware.camera2.CameraManagerimport android.os.Buildimport android.os.VibrationEffectimport android.os.Vibrator@@ -34,29 +40,54 @@ import android.view.MotionEventimport android.view.Viewimport android.view.WindowManagerimport android.view.accessibility.AccessibilityEvent+import com.akslabs.circletosearch.data.ActionTypeimport com.akslabs.circletosearch.data.BitmapRepository+import com.akslabs.circletosearch.data.GestureType+import com.akslabs.circletosearch.data.OverlayConfigurationManagerimport java.util.concurrent.Executorimport java.util.concurrent.Executorsclass CircleToSearchAccessibilityService : AccessibilityService() {private var windowManager: WindowManager? = null- private var triggerView: View? = null+ private val overlayViews = mutableListOf<View>() // Track all added segment viewsprivate val executor: Executor = Executors.newSingleThreadExecutor()+ private lateinit var configManager: OverlayConfigurationManager++ // Bubble related - Keeping existing logic but refactoring slightly if needed+ // For now, keeping bubble separate as requested in prompt "statusbar overlay customization... but it should work normally like now"+ // The prompt asks to disable statusbar overlay in landscape but keep it working normally.private var bubbleView: View? = nullprivate val prefs by lazy { getSharedPreferences("app_prefs", Context.MODE_PRIVATE) }- private val prefsListener = android.content.SharedPreferences.OnSharedPreferenceChangeListener { _, key ->+ private val overlayPrefs by lazy { getSharedPreferences("overlay_prefs", Context.MODE_PRIVATE) } // Watch overlay prefs too++ private val prefsListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->if (key == "bubble_enabled") {updateBubbleState()}}++ private val overlayPrefsListener = SharedPreferences.OnSharedPreferenceChangeListener { _, _ ->+ // On any overlay config change, rebuild the overlay+ updateOverlay()+ }override fun onServiceConnected() {super.onServiceConnected()- setupTriggerOverlay()+ windowManager = getSystemService(WINDOW_SERVICE) as WindowManager+ configManager = OverlayConfigurationManager(this)+prefs.registerOnSharedPreferenceChangeListener(prefsListener)+ overlayPrefs.registerOnSharedPreferenceChangeListener(overlayPrefsListener)+updateBubbleState()+ updateOverlay()+ }++ override fun onConfigurationChanged(newConfig: Configuration) {+ super.onConfigurationChanged(newConfig)+ updateOverlay()}private fun updateBubbleState() {@@ -90,7 +121,8 @@ class CircleToSearchAccessibilityService : AccessibilityService() {var initialTouchX = 0fvar initialTouchY = 0f- setOnTouchListener { v, event ->+ @SuppressLint("ClickableViewAccessibility")+ setOnTouchListener { _, event ->when (event.action) {MotionEvent.ACTION_DOWN -> {initialX = params.x@@ -134,50 +166,185 @@ class CircleToSearchAccessibilityService : AccessibilityService() {}}- private fun setupTriggerOverlay() {- windowManager = getSystemService(WINDOW_SERVICE) as WindowManager- triggerView = View(this)-- val params = WindowManager.LayoutParams(- WindowManager.LayoutParams.MATCH_PARENT,- 100, // Height of the status bar trigger area (approx)- 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+ private fun updateOverlay() {+ // Remove existing views+ overlayViews.forEach { view ->+ try {+ windowManager?.removeView(view)+ } catch (e: Exception) {+ e.printStackTrace()+ }+ }+ overlayViews.clear()++ val config = configManager.getConfig()++ if (!config.isEnabled) return++ // Check Landscape Mode+ val currentOrientation = resources.configuration.orientation+ if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE && !config.isEnabledInLandscape) {+ return+ }- val gestureDetector = GestureDetector(this, object : GestureDetector.SimpleOnGestureListener() {- override fun onDoubleTap(e: MotionEvent): Boolean {- performCapture()- return true+ val screenWidth = resources.displayMetrics.widthPixels++ // Create views for each segment+ config.segments.forEach { segment ->+ val segmentWidth = (screenWidth * segment.widthFraction).toInt()+ val segmentX = (screenWidth * segment.startFraction).toInt()++ val view = View(this)++ // Visual debug or transparent+ if (config.isVisible) {+ view.setBackgroundColor(Color.argb(100, 255, 0, 0)) // Semi-transparent red for debug+ } else {+ view.setBackgroundColor(Color.TRANSPARENT)}- override fun onFling(- e1: MotionEvent?,- e2: MotionEvent,- velocityX: Float,- velocityY: Float- ): Boolean {- // Detect downward swipe to open notifications- if (e1 != null && velocityY > 1000) { // Swipe down with sufficient velocity- performGlobalAction(GLOBAL_ACTION_NOTIFICATIONS)+ val params = WindowManager.LayoutParams(+ segmentWidth,+ config.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 = segmentX+ params.y = config.verticalOffset++ // GestureDetector for this segment+ val gestureDetector = GestureDetector(this, object : GestureDetector.SimpleOnGestureListener() {+ override fun onDoubleTap(e: MotionEvent): Boolean {+ val action = segment.gestures[GestureType.DOUBLE_TAP] ?: ActionType.NONE+ performAction(action)return true}- return false- }- })++ override fun onLongPress(e: MotionEvent) {+ val action = segment.gestures[GestureType.LONG_PRESS] ?: ActionType.NONE+ performAction(action)+ }++ override fun onSingleTapConfirmed(e: MotionEvent): Boolean {+ // Possible triple tap logic here if needed, but Triple Tap usually handled by onDoubleTapEvent or custom logic.+ // For simplicity, we stick to Double and Long for now, or Tripple via custom counter if GestureDetector doesn't support it directly easily.+ // Standard GestureDetector doesn't have explicit onTripleTap.+ // We can check previous tap times if we want triple tap.+ // For now, let's just stick to what GestureDetector offers cleanly.+ return false+ }+ }).apply {+ // Triple tap workaround could be added here+ setOnDoubleTapListener(object : GestureDetector.OnDoubleTapListener {+ override fun onSingleTapConfirmed(e: MotionEvent): Boolean = false++ override fun onDoubleTap(e: MotionEvent): Boolean {+ // Check for Triple Tap (very crude implementation concept, but standard is double)+ // Implementing strict double tap mapped action+ val action = segment.gestures[GestureType.DOUBLE_TAP] ?: ActionType.NONE+ if (action != ActionType.NONE) {+ performAction(action)+ return true+ }+ return false+ }- triggerView?.setOnTouchListener { _, event ->- gestureDetector.onTouchEvent(event)- true+ override fun onDoubleTapEvent(e: MotionEvent): Boolean = false+ })+ }++ // Triple tap helper+ var lastTapTime: Long = 0+ var tapCount = 0++ @SuppressLint("ClickableViewAccessibility")+ view.setOnTouchListener { _, event ->+ if (event.action == MotionEvent.ACTION_DOWN) {+ val currentTime = System.currentTimeMillis()+ if (currentTime - lastTapTime < 400) {+ tapCount+++ } else {+ tapCount = 1+ }+ lastTapTime = currentTime++ if (tapCount == 3) {+ val action = segment.gestures[GestureType.TRIPLE_TAP] ?: ActionType.NONE+ if (action != ActionType.NONE) {+ performAction(action)+ tapCount = 0 // Reset+ return@setOnTouchListener true+ }+ }+ }++ gestureDetector.onTouchEvent(event)+ true+ }++ try {+ windowManager?.addView(view, params)+ overlayViews.add(view)+ } catch (e: Exception) {+ e.printStackTrace()+ }+ }+ }++ private fun performAction(action: ActionType) {+ if (action == ActionType.NONE) return++ // Haptic feedback for action trigger+ val vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {+ vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK))+ } else {+ @Suppress("DEPRECATION")+ vibrator.vibrate(10)}- try {- windowManager?.addView(triggerView, params)+ when(action) {+ ActionType.SCREENSHOT -> performCapture()+ ActionType.FLASHLIGHT -> toggleFlashlight()+ ActionType.HOME -> performGlobalAction(GLOBAL_ACTION_HOME)+ ActionType.BACK -> performGlobalAction(GLOBAL_ACTION_BACK)+ ActionType.RECENTS -> performGlobalAction(GLOBAL_ACTION_RECENTS)+ ActionType.LOCK_SCREEN -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {+ performGlobalAction(GLOBAL_ACTION_LOCK_SCREEN)+ }+ ActionType.OPEN_NOTIFICATIONS -> performGlobalAction(GLOBAL_ACTION_NOTIFICATIONS)+ ActionType.OPEN_QUICK_SETTINGS -> performGlobalAction(GLOBAL_ACTION_QUICK_SETTINGS)+ ActionType.OPEN_APP -> {+ // TODO: Implement open app logic if package name provided+ }+ else -> {}+ }+ }++ private fun toggleFlashlight() {+ try {+ val cameraManager = getSystemService(Context.CAMERA_SERVICE) as CameraManager+ val cameraId = cameraManager.cameraIdList[0]+ // This is tricky because we don't know current state easily without callback.+ // For now, let's assume valid flash.+ // A robust implementation needs a callback to track state.+ // We'll just try to turn it on for a second for testing or we need a tracked state.+ // Let's implement a simple tracking using static var or prefs?+ // Or just ignore toggle for now and just turn ON? No, user expects toggle.+ // Let's use a static state?+ if (isFlashlightOn) {+ cameraManager.setTorchMode(cameraId, false)+ isFlashlightOn = false+ } else {+ cameraManager.setTorchMode(cameraId, true)+ isFlashlightOn = true+ }} catch (e: Exception) {e.printStackTrace()}@@ -185,15 +352,9 @@ class CircleToSearchAccessibilityService : AccessibilityService() {private fun performCapture() {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {- // Haptic Feedback (Crisp Click)- val vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {- vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK))- } else {- @Suppress("DEPRECATION")- vibrator.vibrate(10) // Very short pulse for crisp feel- }-+ // Haptic Feedback (Crisp Click) - Moved to performAction, but keeping here specifically for direct calls if any+ // (performAction handles its own vibration)+// Execute immediately for instant triggertakeScreenshot(Display.DEFAULT_DISPLAY,@@ -250,8 +411,9 @@ class CircleToSearchAccessibilityService : AccessibilityService() {override fun onInterrupt() {}-companion object {+ companion object {private var instance: CircleToSearchAccessibilityService? = null+ private var isFlashlightOn = false // Simple static state trackingfun triggerCapture() {instance?.performCapture()@@ -261,15 +423,24 @@ companion object {override fun onCreate() {super.onCreate()instance = this+ // configManager init moved to onServiceConnected or safe lazy?+ // WindowManager is needed for views which happens in onServiceConnected mostly.}override fun onDestroy() {super.onDestroy()instance = nullprefs.unregisterOnSharedPreferenceChangeListener(prefsListener)- if (triggerView != null && windowManager != null) {- windowManager?.removeView(triggerView)+ overlayPrefs.unregisterOnSharedPreferenceChangeListener(overlayPrefsListener)++ overlayViews.forEach { view ->+ try {+ windowManager?.removeView(view)+ } catch (e: Exception) {+ e.printStackTrace()+ }}hideBubble()}}+diff --git a/app/src/main/java/com/akslabs/circletosearch/MainActivity.kt b/app/src/main/java/com/akslabs/circletosearch/MainActivity.ktindex c976ad5..2dbc618 100644--- a/app/src/main/java/com/akslabs/circletosearch/MainActivity.kt+++ b/app/src/main/java/com/akslabs/circletosearch/MainActivity.kt@@ -61,7 +61,13 @@ class MainActivity : ComponentActivity() {modifier = Modifier.fillMaxSize(),color = MaterialTheme.colorScheme.background) {- SetupScreen()+ var currentScreen by remember { mutableStateOf("home") }++ if (currentScreen == "settings") {+ com.akslabs.circletosearch.ui.OverlaySettingsScreen(onBack = { currentScreen = "home" })+ } else {+ SetupScreen(onSettingsClick = { currentScreen = "settings" })+ }}}}@@ -70,7 +76,7 @@ class MainActivity : ComponentActivity() {@OptIn(ExperimentalMaterial3Api::class)@Composable-fun SetupScreen() {+fun SetupScreen(onSettingsClick: () -> Unit) {val context = LocalContext.currentval lifecycleOwner = androidx.lifecycle.compose.LocalLifecycleOwner.currentval prefs = context.getSharedPreferences("app_prefs", android.content.Context.MODE_PRIVATE)@@ -312,6 +318,43 @@ fun SetupScreen() {)BubbleSwitch(context)LensOnlySwitch(context)++ Spacer(modifier = Modifier.height(12.dp))++ // Advanced Overlay Settings Button+ Card(+ onClick = onSettingsClick,+ colors = CardDefaults.cardColors(+ containerColor = MaterialTheme.colorScheme.tertiaryContainer+ ),+ shape = androidx.compose.foundation.shape.RoundedCornerShape(24.dp),+ modifier = Modifier.fillMaxWidth()+ ) {+ Row(+ modifier = Modifier.padding(16.dp),+ verticalAlignment = Alignment.CenterVertically+ ) {+ Icon(+ imageVector = Icons.Default.Settings,+ contentDescription = null,+ modifier = Modifier.size(24.dp),+ tint = MaterialTheme.colorScheme.onTertiaryContainer+ )+ Spacer(modifier = Modifier.width(16.dp))+ Column {+ Text(+ text = "Advanced Status Bar Settings",+ style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold),+ color = MaterialTheme.colorScheme.onTertiaryContainer+ )+ Text(+ text = "Customize overlay size, gestures & segments",+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onTertiaryContainer.copy(alpha = 0.8f)+ )+ }+ }+ }Spacer(modifier = Modifier.height(25.dp))diff --git a/app/src/main/java/com/akslabs/circletosearch/data/OverlayConfig.kt b/app/src/main/java/com/akslabs/circletosearch/data/OverlayConfig.ktnew file mode 100644index 0000000..245b895--- /dev/null+++ b/app/src/main/java/com/akslabs/circletosearch/data/OverlayConfig.kt@@ -0,0 +1,75 @@+/*+ * Copyright (C) 2025 AKS-Labs+ */++package com.akslabs.circletosearch.data++import android.content.Context+import android.content.SharedPreferences+import com.google.gson.Gson+import com.google.gson.reflect.TypeToken++data class OverlayConfig(+ val isEnabled: Boolean = true,+ val isEnabledInLandscape: Boolean = false,+ val height: Int = 100, // Pixels+ val verticalOffset: Int = 0, // Pixels from top+ val isVisible: Boolean = false, // Debug visibility (colored)+ val segments: List<OverlaySegment> = listOf(OverlaySegment(0f, 1f)) // Default single full-width segment+)++data class OverlaySegment(+ val startFraction: Float, // 0.0 to 1.0+ val widthFraction: Float, // 0.0 to 1.0+ val gestures: MutableMap<GestureType, ActionType> = mutableMapOf(GestureType.DOUBLE_TAP to ActionType.SCREENSHOT)+)++enum class GestureType {+ DOUBLE_TAP,+ LONG_PRESS,+ TRIPLE_TAP+}++enum class ActionType {+ NONE,+ SCREENSHOT,+ FLASHLIGHT,+ HOME,+ BACK,+ RECENTS,+ LOCK_SCREEN,+ OPEN_APP, // Requires extra data, maybe simple string for package name later+ OPEN_NOTIFICATIONS,+ OPEN_QUICK_SETTINGS+}++class OverlayConfigurationManager(context: Context) {+ private val prefs: SharedPreferences = context.getSharedPreferences("overlay_prefs", Context.MODE_PRIVATE)+ private val gson = Gson()++ companion object {+ private const val KEY_CONFIG = "overlay_config"+ }++ fun getConfig(): OverlayConfig {+ val json = prefs.getString(KEY_CONFIG, null)+ return if (json != null) {+ try {+ gson.fromJson(json, OverlayConfig::class.java)+ } catch (e: Exception) {+ OverlayConfig()+ }+ } else {+ OverlayConfig()+ }+ }++ fun saveConfig(config: OverlayConfig) {+ val json = gson.toJson(config)+ prefs.edit().putString(KEY_CONFIG, json).apply()+ }++ fun resetConfig() {+ prefs.edit().remove(KEY_CONFIG).apply()+ }+}diff --git a/app/src/main/java/com/akslabs/circletosearch/ui/OverlaySettingsScreen.kt b/app/src/main/java/com/akslabs/circletosearch/ui/OverlaySettingsScreen.ktnew file mode 100644index 0000000..da28e9a--- /dev/null+++ b/app/src/main/java/com/akslabs/circletosearch/ui/OverlaySettingsScreen.kt@@ -0,0 +1,365 @@+/*+ * Copyright (C) 2025 AKS-Labs+ */++package com.akslabs.circletosearch.ui++import android.content.Context+import androidx.compose.foundation.Canvas+import androidx.compose.foundation.background+import androidx.compose.foundation.border+import androidx.compose.foundation.clickable+import androidx.compose.foundation.gestures.detectTapGestures+import androidx.compose.foundation.layout.*+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.foundation.verticalScroll+import androidx.compose.material.icons.Icons+import androidx.compose.material.icons.filled.*+import androidx.compose.material3.*+import androidx.compose.runtime.*+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.vector.ImageVector+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import androidx.compose.ui.window.Dialog+import com.akslabs.circletosearch.data.*++@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun OverlaySettingsScreen(+ onBack: () -> Unit+) {+ val context = LocalContext.current+ val configManager = remember { OverlayConfigurationManager(context) }+ var config by remember { mutableStateOf(configManager.getConfig()) }++ // Save on changes+ fun updateConfig(newConfig: OverlayConfig) {+ config = newConfig+ configManager.saveConfig(newConfig)+ }++ Scaffold(+ topBar = {+ TopAppBar(+ title = { Text("Overlay Settings", fontWeight = FontWeight.Bold) },+ navigationIcon = {+ IconButton(onClick = onBack) {+ Icon(Icons.Default.ArrowBack, contentDescription = "Back")+ }+ },+ actions = {+ IconButton(onClick = {+ updateConfig(OverlayConfig()) // Reset+ }) {+ Icon(Icons.Default.Refresh, contentDescription = "Reset")+ }+ }+ )+ }+ ) { padding ->+ Column(+ modifier = Modifier+ .fillMaxSize()+ .padding(padding)+ .verticalScroll(rememberScrollState())+ .padding(16.dp)+ ) {+ // 1. Visualizer+ Text("PREVIEW", style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.primary)+ Spacer(modifier = Modifier.height(8.dp))+ OverlayVisualizer(config = config)+ Spacer(modifier = Modifier.height(24.dp))++ // 2. Main Toggles+ SettingsSectionHeader(title = "General")+ SettingsToggleItem(+ title = "Enable Overlay",+ subtitle = "Show trigger zone over status bar",+ icon = Icons.Default.Layers,+ checked = config.isEnabled,+ onCheckedChange = { updateConfig(config.copy(isEnabled = it)) }+ )+ Spacer(modifier = Modifier.height(12.dp))+ SettingsToggleItem(+ title = "Landscape Mode",+ subtitle = "Keep overlay active in landscape",+ icon = Icons.Default.ScreenRotation,+ checked = config.isEnabledInLandscape,+ onCheckedChange = { updateConfig(config.copy(isEnabledInLandscape = it)) }+ )+ Spacer(modifier = Modifier.height(12.dp))+ SettingsToggleItem(+ title = "Debug Visibility",+ subtitle = "Show colored overlay for testing",+ icon = Icons.Default.Visibility,+ checked = config.isVisible,+ onCheckedChange = { updateConfig(config.copy(isVisible = it)) }+ )++ Spacer(modifier = Modifier.height(24.dp))++ // 3. Dimensions+ SettingsSectionHeader(title = "Dimensions")+ Text("Height: ${config.height}px", style = MaterialTheme.typography.bodySmall)+ Slider(+ value = config.height.toFloat(),+ onValueChange = { updateConfig(config.copy(height = it.toInt())) },+ valueRange = 20f..300f+ )++ Text("Vertical Offset: ${config.verticalOffset}px", style = MaterialTheme.typography.bodySmall)+ Slider(+ value = config.verticalOffset.toFloat(),+ onValueChange = { updateConfig(config.copy(verticalOffset = it.toInt())) },+ valueRange = 0f..200f+ )++ Spacer(modifier = Modifier.height(24.dp))++ // 4. Segments+ Row(+ modifier = Modifier.fillMaxWidth(),+ horizontalArrangement = Arrangement.SpaceBetween,+ verticalAlignment = Alignment.CenterVertically+ ) {+ SettingsSectionHeader(title = "Segments & Gestures")+ TextButton(onClick = {+ // Add split logic: Split the last segment in half or add new one+ val currentSegments = config.segments.toMutableList()+ if (currentSegments.isNotEmpty()) {+ // Redistribution logic: reset to equal parts for simplicity when adding+ val newCount = currentSegments.size + 1+ val newWidth = 1f / newCount+ val newSegments = mutableListOf<OverlaySegment>()+ for (i in 0 until newCount) {+ newSegments.add(OverlaySegment(startFraction = i * newWidth, widthFraction = newWidth))+ }+ updateConfig(config.copy(segments = newSegments))+ } else {+ updateConfig(config.copy(segments = listOf(OverlaySegment(0f, 1f))))+ }+ }) {+ Text("+ Add Split")+ }+ }++ // Re-distribute/Clear+ if (config.segments.size > 1) {+ TextButton(+ onClick = { updateConfig(config.copy(segments = listOf(OverlaySegment(0f, 1f)))) },+ modifier = Modifier.align(Alignment.End)+ ) {+ Text("Reset to Single", color = MaterialTheme.colorScheme.error)+ }+ }++ config.segments.forEachIndexed { index, segment ->+ SegmentEditorItem(+ index = index,+ segment = segment,+ onUpdate = { updatedSegment ->+ val newSegments = config.segments.toMutableList()+ newSegments[index] = updatedSegment+ updateConfig(config.copy(segments = newSegments))+ }+ )+ Spacer(modifier = Modifier.height(8.dp))+ }+ }+ }+}++@Composable+fun OverlayVisualizer(config: OverlayConfig) {+ Box(+ modifier = Modifier+ .fillMaxWidth()+ .height(60.dp) // Scaled down verification+ .clip(RoundedCornerShape(8.dp))+ .background(Color.Black)+ .border(1.dp, Color.DarkGray, RoundedCornerShape(8.dp))+ ) {+ // Draw Status Bar hints+ Row(+ modifier = Modifier+ .fillMaxWidth()+ .padding(horizontal = 12.dp),+ horizontalArrangement = Arrangement.SpaceBetween,+ verticalAlignment = Alignment.CenterVertically+ ) {+ Text("9:41", color = Color.White, fontSize = 10.sp)+ Row {+ Icon(Icons.Default.Wifi, contentDescription = null, tint = Color.White, modifier = Modifier.size(10.dp))+ Spacer(modifier = Modifier.width(4.dp))+ Icon(Icons.Default.BatteryFull, contentDescription = null, tint = Color.White, modifier = Modifier.size(10.dp))+ }+ }++ // Draw Overlay Segments+ Box(modifier = Modifier.fillMaxSize()) {+ config.segments.forEachIndexed { index, segment ->+ Box(+ modifier = Modifier+ .fillMaxHeight()+ .fillMaxWidth(fraction = segment.widthFraction)+ // Align based on start fraction.+ // Note: fillMaxWidth(fraction) takes fraction of PARENT.+ // To allow arbitrary positioning we might need offsets or a Row with weights.+ // Or easier: Custom Layout or simple Offset.+ // Since segments are usually sequential, Row is best visually. But we support config.+ // Let's use alignment bias or Offset.+ )+ }++ // Better Visualizer: Canvas+ Canvas(modifier = Modifier.fillMaxSize()) {+ val totalWidth = size.width+ val height = if (config.height > size.height) size.height else config.height.toFloat() // Clamp for visual+ val yOffset = 0f // In visualizer, always top++ config.segments.forEachIndexed { index, segment ->+ val x = totalWidth * segment.startFraction+ val w = totalWidth * segment.widthFraction++ // Colors+ val colors = listOf(Color.Red, Color.Blue, Color.Green, Color.Yellow, Color.Magenta)+ val color = colors[index % colors.size].copy(alpha = 0.5f)++ drawRect(+ color = color,+ topLeft = Offset(x, yOffset),+ size = androidx.compose.ui.geometry.Size(w, 20f) // Fixed visual height+ )++ // Draw Borders+ }+ }+ }+ }+}++@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun SegmentEditorItem(+ index: Int,+ segment: OverlaySegment,+ onUpdate: (OverlaySegment) -> Unit+) {+ var showGestureDialog by remember { mutableStateOf(false) }++ Card(+ modifier = Modifier.fillMaxWidth().clickable { showGestureDialog = true },+ colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha=0.5f))+ ) {+ Column(modifier = Modifier.padding(12.dp)) {+ Row(verticalAlignment = Alignment.CenterVertically) {+ Box(+ modifier = Modifier.size(16.dp).background(+ listOf(Color.Red, Color.Blue, Color.Green, Color.Yellow, Color.Magenta)[index % 5],+ shape = androidx.compose.foundation.shape.CircleShape+ )+ )+ Spacer(modifier = Modifier.width(8.dp))+ Text("Segment ${index + 1}", fontWeight = FontWeight.Bold)+ Spacer(modifier = Modifier.weight(1f))+ Icon(Icons.Default.Edit, contentDescription = "Edit", modifier = Modifier.size(16.dp))+ }++ Spacer(modifier = Modifier.height(8.dp))++ // Readout of gestures+ segment.gestures.forEach { (type, action) ->+ Text(+ "${type.name}: ${action.name}",+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant+ )+ }+ }+ }++ if (showGestureDialog) {+ GestureConfigDialog(+ segment = segment,+ onDismiss = { showGestureDialog = false },+ onUpdate = onUpdate+ )+ }+}++@Composable+fun GestureConfigDialog(+ segment: OverlaySegment,+ onDismiss: () -> Unit,+ onUpdate: (OverlaySegment) -> Unit+) {+ // We only support configuring specific gestures.+ // Let's just list them.++ Dialog(onDismissRequest = onDismiss) {+ Card(+ shape = RoundedCornerShape(24.dp),+ colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface)+ ) {+ Column(+ modifier = Modifier.padding(24.dp).verticalScroll(rememberScrollState())+ ) {+ Text("Configure Gestures", style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold)+ Spacer(modifier = Modifier.height(16.dp))++ GestureType.values().forEach { gesture ->+ val currentAction = segment.gestures[gesture] ?: ActionType.NONE+ var expanded by remember { mutableStateOf(false) }++ Text(gesture.name.replace("_", " "), fontWeight = FontWeight.Medium)++ Box(modifier = Modifier.fillMaxWidth()) {+ OutlinedButton(+ onClick = { expanded = true },+ modifier = Modifier.fillMaxWidth()+ ) {+ Text(currentAction.name)+ Spacer(modifier = Modifier.weight(1f))+ Icon(Icons.Default.ArrowDropDown, contentDescription = null)+ }++ DropdownMenu(+ expanded = expanded,+ onDismissRequest = { expanded = false }+ ) {+ ActionType.values().forEach { action ->+ DropdownMenuItem(+ text = { Text(action.name) },+ onClick = {+ val newGestures = segment.gestures.toMutableMap()+ newGestures[gesture] = action+ onUpdate(segment.copy(gestures = newGestures))+ expanded = false+ }+ )+ }+ }+ }+ Spacer(modifier = Modifier.height(12.dp))+ }++ Spacer(modifier = Modifier.height(16.dp))+ Button(+ onClick = onDismiss,+ modifier = Modifier.fillMaxWidth()+ ) {+ Text("Done")+ }+ }+ }+ }+}