From 1d02aa8d78903b84eba994604d40fcd51cd73321 Mon Sep 17 00:00:00 2001 From: He4eT Date: Sat, 28 Dec 2024 13:43:20 +0100 Subject: [PATCH 1/2] Show recent apps with swipe --- .../java/eu/ottop/yamlauncher/MainActivity.kt | 15 ++++++++++++++- .../ottop/yamlauncher/tasks/ScreenLockService.kt | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 55b02dd..eb67c0e 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -1196,7 +1196,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } - // Swipe right + // Swipe right else if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled("right")) { if (rightSwipeActivity.first != null && rightSwipeActivity.second != null) { canLaunchShortcut = false @@ -1205,6 +1205,19 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh Toast.makeText(this@MainActivity, getString(R.string.launch_error), Toast.LENGTH_SHORT).show() } } + else if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && !sharedPreferenceManager.isGestureEnabled("right")) { + if (gestureUtils.isAccessibilityServiceEnabled( + ScreenLockService::class.java + ) + ) { + val intent = Intent(this@MainActivity, ScreenLockService::class.java) + intent.action = "RECENTS" + startService(intent) + finishAndRemoveTask() + } else { + gestureUtils.promptEnableAccessibility() + } + } } return true } diff --git a/app/src/main/java/eu/ottop/yamlauncher/tasks/ScreenLockService.kt b/app/src/main/java/eu/ottop/yamlauncher/tasks/ScreenLockService.kt index 403ccec..afcf884 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/tasks/ScreenLockService.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/tasks/ScreenLockService.kt @@ -16,6 +16,9 @@ class ScreenLockService : AccessibilityService() { if (intent != null && intent.action == "LOCK_SCREEN") { performLockScreen() } + if (intent != null && intent.action == "RECENTS") { + performShowRecents() + } stopSelf() return super.onStartCommand(intent, flags, startId) } @@ -23,4 +26,8 @@ class ScreenLockService : AccessibilityService() { private fun performLockScreen() { performGlobalAction(GLOBAL_ACTION_LOCK_SCREEN) } + + private fun performShowRecents() { + performGlobalAction(GLOBAL_ACTION_RECENTS) + } } \ No newline at end of file From a1bcc6e389fda96f18c6e7aac90407fd71fc2062 Mon Sep 17 00:00:00 2001 From: He4eT Date: Sat, 28 Dec 2024 13:46:19 +0100 Subject: [PATCH 2/2] Swipes: change priorities --- .../java/eu/ottop/yamlauncher/MainActivity.kt | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index eb67c0e..3b70360 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -1170,8 +1170,31 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh val deltaY = e2.y - e1.y val deltaX = e2.x - e1.x + // Swipe right + if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled("right")) { + if (rightSwipeActivity.first != null && rightSwipeActivity.second != null) { + canLaunchShortcut = false + appUtils.launchApp(rightSwipeActivity.first!!.componentName, launcherApps.profiles[rightSwipeActivity.second!!]) + } else { + Toast.makeText(this@MainActivity, getString(R.string.launch_error), Toast.LENGTH_SHORT).show() + } + } + else if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && !sharedPreferenceManager.isGestureEnabled("right")) { + if (gestureUtils.isAccessibilityServiceEnabled( + ScreenLockService::class.java + ) + ) { + val intent = Intent(this@MainActivity, ScreenLockService::class.java) + intent.action = "RECENTS" + startService(intent) + finishAndRemoveTask() + } else { + gestureUtils.promptEnableAccessibility() + } + } + // Swipe up - if (deltaY < -swipeThreshold && abs(velocityY) > swipeVelocityThreshold) { + else if (deltaY < -swipeThreshold && abs(velocityY) > swipeVelocityThreshold) { canLaunchShortcut = false openAppMenu() } @@ -1194,30 +1217,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh Toast.makeText(this@MainActivity, getString(R.string.launch_error), Toast.LENGTH_SHORT).show() } } - - - // Swipe right - else if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled("right")) { - if (rightSwipeActivity.first != null && rightSwipeActivity.second != null) { - canLaunchShortcut = false - appUtils.launchApp(rightSwipeActivity.first!!.componentName, launcherApps.profiles[rightSwipeActivity.second!!]) - } else { - Toast.makeText(this@MainActivity, getString(R.string.launch_error), Toast.LENGTH_SHORT).show() - } - } - else if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && !sharedPreferenceManager.isGestureEnabled("right")) { - if (gestureUtils.isAccessibilityServiceEnabled( - ScreenLockService::class.java - ) - ) { - val intent = Intent(this@MainActivity, ScreenLockService::class.java) - intent.action = "RECENTS" - startService(intent) - finishAndRemoveTask() - } else { - gestureUtils.promptEnableAccessibility() - } - } } return true }