From 5d3f1fd6e377a5c895ba745dfea5bd198dbf1110 Mon Sep 17 00:00:00 2001 From: HeCodes2Much Date: Wed, 8 May 2024 17:52:08 +0100 Subject: [PATCH] Refactor: accessibility actions and helper methods This commit refactors the accessibility actions in MyAccessibilityService.kt and updates corresponding invocations in AppHelper.kt to use the new methods. Specifically, the following changes were made: - Introduced separate methods for various accessibility actions such as showing recent apps, opening notifications, opening quick settings, opening the power dialog, and taking a screenshot in MyAccessibilityService.kt. - Updated the calls in AppHelper.kt to use these new methods instead of directly calling performGlobalAction. - Removed commented-out code related to accessibility actions in AppHelper.kt. --- CHANGELOG.md | 4 +++ .../accessibility/MyAccessibilityService.kt | 28 ++++++++++++++++++- .../launcher/helper/AppHelper.kt | 20 ++++--------- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 523f92d..37e8987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,4 +12,8 @@ All notable changes to this project will be documented in this file. See [conven - Fixed Others Text/Links - ([e91771f](https://github.com/DroidWorksStudio/mLauncher/commit/e91771f4bbf92915e98f758cfb2d261a12cd9adc)) +### Refactoring: + +- Accessibility actions and helper methods - ([e4dab29](https://github.com/DroidWorksStudio/mLauncher/commit/e4dab299574a9bd26eb0b7f7d786464c0ef75a1f)) + diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/accessibility/MyAccessibilityService.kt b/app/src/main/java/com/github/droidworksstudio/launcher/accessibility/MyAccessibilityService.kt index b3e48c9..a9d7b42 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/accessibility/MyAccessibilityService.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/accessibility/MyAccessibilityService.kt @@ -37,7 +37,33 @@ class MyAccessibilityService : AccessibilityService() { override fun onAccessibilityEvent(event: AccessibilityEvent?) {} @RequiresApi(Build.VERSION_CODES.P) - fun lockScreen(): Boolean = performGlobalAction(GLOBAL_ACTION_LOCK_SCREEN) + fun lockScreen(): Boolean { + return performGlobalAction(GLOBAL_ACTION_LOCK_SCREEN) + } + + @RequiresApi(Build.VERSION_CODES.P) + fun showRecents(): Boolean { + return performGlobalAction(GLOBAL_ACTION_RECENTS) + } + + @RequiresApi(Build.VERSION_CODES.P) + fun openNotifications(): Boolean { + return performGlobalAction(GLOBAL_ACTION_NOTIFICATIONS) + } + + @RequiresApi(Build.VERSION_CODES.P) + fun openQuickSettings(): Boolean { + return performGlobalAction(GLOBAL_ACTION_QUICK_SETTINGS) + } + + fun openPowerDialog(): Boolean { + return performGlobalAction(GLOBAL_ACTION_POWER_DIALOG) + } + + @RequiresApi(Build.VERSION_CODES.P) + fun takeScreenShot(): Boolean { + return performGlobalAction(GLOBAL_ACTION_TAKE_SCREENSHOT) + } companion object { private var mInstance: WeakReference = WeakReference(null) diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt b/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt index fa32e18..7a5e148 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt @@ -66,9 +66,9 @@ class AppHelper @Inject constructor() { val method = statusBarManager.getMethod(Constants.NOTIFICATION_METHOD) method.invoke(statusBarService) } catch (exception: Exception) { -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { -// initActionService(context)?.openNotifications() -// } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + MyAccessibilityService.instance()?.openNotifications() + } exception.printStackTrace() } } @@ -81,9 +81,9 @@ class AppHelper @Inject constructor() { val method = statusBarManager.getMethod(Constants.QUICKSETTINGS_METHOD) method.invoke(statusBarService) } catch (exception: Exception) { -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { -// initActionService(context)?.openQuickSettings() -// } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + MyAccessibilityService.instance()?.openQuickSettings() + } exception.printStackTrace() } } @@ -94,14 +94,6 @@ class AppHelper @Inject constructor() { context.startActivity(intent) } - fun darkThemes(darkThemes: Boolean){ - if (darkThemes){ - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) - }else{ - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) - } - } - fun dayNightMod(context: Context, view: View) { when (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) { Configuration.UI_MODE_NIGHT_YES -> {