diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ff56fc5a..8d7cd806 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -22,7 +22,7 @@ android { minSdk = 31 targetSdk = 34 versionCode = gitVersionCode() - versionName = "1.23.1" + versionName = "1.24.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/MenuItem.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/MenuItem.kt index af09cc62..5fadc4c3 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/MenuItem.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/MenuItem.kt @@ -12,6 +12,7 @@ import com.enaboapps.switchify.service.utils.ScreenUtils /** * This class represents a menu item + * @property id The id of the menu item * @property text The text of the menu item * @property drawableId The drawable resource id of the menu item * @property drawableDescription The description of the drawable @@ -22,13 +23,14 @@ import com.enaboapps.switchify.service.utils.ScreenUtils * @property action The action to perform when the item is selected */ class MenuItem( + val id: String, private val text: String = "", private val drawableId: Int = 0, private val drawableDescription: String = "", val closeOnSelect: Boolean = true, var isLinkToMenu: Boolean = false, var isMenuHierarchyManipulator: Boolean = false, - var page: Int = 0, + private var page: Int = 0, private val action: () -> Unit ) { /** diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/MenuPage.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/MenuPage.kt index e32f76d3..f4fb44c1 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/MenuPage.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/MenuPage.kt @@ -93,6 +93,7 @@ class MenuPage( if (maxPageIndex > 0) { menuChangeBtn = MenuItem( + id = "change_page", drawableId = R.drawable.ic_change_menu_page, drawableDescription = "Change page", closeOnSelect = false, diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/BaseMenu.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/BaseMenu.kt index 7d859ecf..3ace6ac2 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/BaseMenu.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/BaseMenu.kt @@ -1,11 +1,9 @@ package com.enaboapps.switchify.service.menu.menus -import android.accessibilityservice.AccessibilityService -import com.enaboapps.switchify.R import com.enaboapps.switchify.service.SwitchifyAccessibilityService import com.enaboapps.switchify.service.menu.MenuItem -import com.enaboapps.switchify.service.menu.MenuManager import com.enaboapps.switchify.service.menu.MenuView +import com.enaboapps.switchify.service.menu.store.MenuItemStore /** * This class represents a base menu @@ -29,18 +27,7 @@ open class BaseMenu( * @return The system navigation items */ fun buildSystemNavItems(): List { - return listOfNotNull( - MenuItem( - drawableId = R.drawable.ic_sys_back, - drawableDescription = "Back", - action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK) } - ), - MenuItem( - drawableId = R.drawable.ic_sys_home, - drawableDescription = "Home", - action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME) } - ) - ) + return MenuItemStore(accessibilityService).systemNavItems } /** @@ -48,26 +35,7 @@ open class BaseMenu( * @return The navigation menu items */ fun buildNavMenuItems(): List { - val navMenuItems = mutableListOf() - if (MenuManager.getInstance().menuHierarchy?.getTopMenu() != null) { - navMenuItems.add( - MenuItem( - drawableId = R.drawable.ic_previous_menu, - drawableDescription = "Previous menu", - isMenuHierarchyManipulator = true, - action = { MenuManager.getInstance().menuHierarchy?.popMenu() } - ) - ) - } - navMenuItems.add( - MenuItem( - drawableId = R.drawable.ic_close_menu, - drawableDescription = "Close menu", - isMenuHierarchyManipulator = true, - action = { MenuManager.getInstance().menuHierarchy?.removeAllMenus() } - ) - ) - return navMenuItems + return MenuItemStore(accessibilityService).menuManipulatorItems } /** diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/edit/EditMenu.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/edit/EditMenu.kt index b78e5315..dd493bec 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/edit/EditMenu.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/edit/EditMenu.kt @@ -1,38 +1,15 @@ package com.enaboapps.switchify.service.menu.menus.edit -import android.view.accessibility.AccessibilityNodeInfo import com.enaboapps.switchify.service.SwitchifyAccessibilityService -import com.enaboapps.switchify.service.gestures.GesturePoint import com.enaboapps.switchify.service.menu.MenuItem import com.enaboapps.switchify.service.menu.menus.BaseMenu -import com.enaboapps.switchify.service.nodes.Node -import com.enaboapps.switchify.service.nodes.NodeExaminer +import com.enaboapps.switchify.service.menu.store.MenuItemStore class EditMenu(accessibilityService: SwitchifyAccessibilityService) : BaseMenu(accessibilityService, buildEditMenuItems(accessibilityService)) { companion object { private fun buildEditMenuItems(accessibilityService: SwitchifyAccessibilityService): List { - val currentPoint = GesturePoint.getPoint() - val cutNode = NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.CUT) - val copyNode = NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.COPY) - val pasteNode = NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.PASTE) - return listOfNotNull( - if (cutNode != null) { - MenuItem("Cut") { - cutNode.performAction(AccessibilityNodeInfo.ACTION_CUT) - } - } else null, - if (copyNode != null) { - MenuItem("Copy") { - copyNode.performAction(AccessibilityNodeInfo.ACTION_COPY) - } - } else null, - if (pasteNode != null) { - MenuItem("Paste") { - pasteNode.performAction(AccessibilityNodeInfo.ACTION_PASTE) - } - } else null - ) + return MenuItemStore(accessibilityService).buildEditMenuObject().getMenuItems() } } } \ No newline at end of file diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/GesturesMenu.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/GesturesMenu.kt index 3fc3c35d..a5a36d3d 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/GesturesMenu.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/GesturesMenu.kt @@ -1,33 +1,16 @@ package com.enaboapps.switchify.service.menu.menus.gestures import com.enaboapps.switchify.service.SwitchifyAccessibilityService -import com.enaboapps.switchify.service.gestures.GestureManager import com.enaboapps.switchify.service.menu.MenuItem -import com.enaboapps.switchify.service.menu.MenuManager import com.enaboapps.switchify.service.menu.menus.BaseMenu +import com.enaboapps.switchify.service.menu.store.MenuItemStore class GesturesMenu(accessibilityService: SwitchifyAccessibilityService) : BaseMenu(accessibilityService, buildGesturesMenuItems(accessibilityService)) { companion object { private fun buildGesturesMenuItems(accessibilityService: SwitchifyAccessibilityService): List { - return listOf( - MenuItem("Tap Gestures", isLinkToMenu = true) { - MenuManager.getInstance().openTapMenu() - }, - MenuItem("Swipe Gestures", isLinkToMenu = true) { - MenuManager.getInstance().openSwipeMenu() - }, - MenuItem("Drag") { - GestureManager.getInstance().startDragGesture() - }, - MenuItem("Zoom Gestures", isLinkToMenu = true) { - MenuManager.getInstance().openZoomGesturesMenu() - }, - MenuItem("Toggle Gesture Lock", closeOnSelect = false) { - GestureManager.getInstance().toggleGestureLock() - } - ) + return MenuItemStore(accessibilityService).gesturesMenuObject.getMenuItems() } } } \ No newline at end of file diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/SwipeGesturesMenu.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/SwipeGesturesMenu.kt index a33ff5bb..5593e8ef 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/SwipeGesturesMenu.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/SwipeGesturesMenu.kt @@ -1,30 +1,16 @@ package com.enaboapps.switchify.service.menu.menus.gestures import com.enaboapps.switchify.service.SwitchifyAccessibilityService -import com.enaboapps.switchify.service.gestures.GestureManager -import com.enaboapps.switchify.service.gestures.SwipeDirection import com.enaboapps.switchify.service.menu.MenuItem import com.enaboapps.switchify.service.menu.menus.BaseMenu +import com.enaboapps.switchify.service.menu.store.MenuItemStore class SwipeGesturesMenu(accessibilityService: SwitchifyAccessibilityService) : BaseMenu(accessibilityService, buildSwipeGesturesMenuItems(accessibilityService)) { companion object { private fun buildSwipeGesturesMenuItems(accessibilityService: SwitchifyAccessibilityService): List { - return listOf( - MenuItem("Swipe Up") { - GestureManager.getInstance().performSwipe(SwipeDirection.UP) - }, - MenuItem("Swipe Down") { - GestureManager.getInstance().performSwipe(SwipeDirection.DOWN) - }, - MenuItem("Swipe Left") { - GestureManager.getInstance().performSwipe(SwipeDirection.LEFT) - }, - MenuItem("Swipe Right") { - GestureManager.getInstance().performSwipe(SwipeDirection.RIGHT) - } - ) + return MenuItemStore(accessibilityService).swipeGesturesMenuObject.getMenuItems() } } } \ No newline at end of file diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/TapGesturesMenu.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/TapGesturesMenu.kt index 6871bf5e..a3cf1408 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/TapGesturesMenu.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/TapGesturesMenu.kt @@ -1,26 +1,16 @@ package com.enaboapps.switchify.service.menu.menus.gestures import com.enaboapps.switchify.service.SwitchifyAccessibilityService -import com.enaboapps.switchify.service.gestures.GestureManager import com.enaboapps.switchify.service.menu.MenuItem import com.enaboapps.switchify.service.menu.menus.BaseMenu +import com.enaboapps.switchify.service.menu.store.MenuItemStore class TapGesturesMenu(accessibilityService: SwitchifyAccessibilityService) : BaseMenu(accessibilityService, buildTapGesturesMenuItems(accessibilityService)) { companion object { private fun buildTapGesturesMenuItems(accessibilityService: SwitchifyAccessibilityService): List { - return listOf( - MenuItem("Tap") { - GestureManager.getInstance().performTap() - }, - MenuItem("Double Tap") { - GestureManager.getInstance().performDoubleTap() - }, - MenuItem("Tap and Hold") { - GestureManager.getInstance().performTapAndHold() - } - ) + return MenuItemStore(accessibilityService).tapGesturesMenuObject.getMenuItems() } } } \ No newline at end of file diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/ZoomGesturesMenu.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/ZoomGesturesMenu.kt index d23cb4b1..e84ee665 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/ZoomGesturesMenu.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/gestures/ZoomGesturesMenu.kt @@ -1,25 +1,15 @@ package com.enaboapps.switchify.service.menu.menus.gestures import com.enaboapps.switchify.service.SwitchifyAccessibilityService -import com.enaboapps.switchify.service.gestures.GestureManager -import com.enaboapps.switchify.service.gestures.ZoomGesturePerformer import com.enaboapps.switchify.service.menu.MenuItem import com.enaboapps.switchify.service.menu.menus.BaseMenu +import com.enaboapps.switchify.service.menu.store.MenuItemStore class ZoomGesturesMenu(accessibilityService: SwitchifyAccessibilityService) : BaseMenu(accessibilityService, buildZoomGesturesMenuItems(accessibilityService)) { companion object { private fun buildZoomGesturesMenuItems(accessibilityService: SwitchifyAccessibilityService): List { - return listOf( - MenuItem("Zoom In") { - GestureManager.getInstance() - .performZoomAction(ZoomGesturePerformer.ZoomAction.ZOOM_IN) - }, - MenuItem("Zoom Out") { - GestureManager.getInstance() - .performZoomAction(ZoomGesturePerformer.ZoomAction.ZOOM_OUT) - } - ) + return MenuItemStore(accessibilityService).zoomGesturesMenuObject.getMenuItems() } } } \ No newline at end of file diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/main/MainMenu.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/main/MainMenu.kt index e1fd9891..ea68821e 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/main/MainMenu.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/main/MainMenu.kt @@ -1,64 +1,16 @@ package com.enaboapps.switchify.service.menu.menus.main import com.enaboapps.switchify.service.SwitchifyAccessibilityService -import com.enaboapps.switchify.service.gestures.GestureManager -import com.enaboapps.switchify.service.gestures.GesturePoint import com.enaboapps.switchify.service.menu.MenuItem -import com.enaboapps.switchify.service.menu.MenuManager import com.enaboapps.switchify.service.menu.menus.BaseMenu -import com.enaboapps.switchify.service.nodes.NodeExaminer -import com.enaboapps.switchify.service.scanning.ScanMethod +import com.enaboapps.switchify.service.menu.store.MenuItemStore class MainMenu(accessibilityService: SwitchifyAccessibilityService) : BaseMenu(accessibilityService, buildMainMenuItems(accessibilityService)) { companion object { private fun buildMainMenuItems(accessibilityService: SwitchifyAccessibilityService): List { - val point = GesturePoint.getPoint() - - val menuItems = mutableListOf() - - menuItems.add(MenuItem("Tap") { - GestureManager.getInstance().performTap() - }) - - menuItems.add(MenuItem("Gestures", isLinkToMenu = true) { - MenuManager.getInstance().openGesturesMenu() - }) - - if (NodeExaminer.canPerformScrollActions(point)) { - menuItems.add(MenuItem("Scroll", isLinkToMenu = true) { - MenuManager.getInstance().openScrollMenu() - }) - } - - // Only add "Refine Selection" if the current scan method is not item scan - if (ScanMethod.getType() != ScanMethod.MethodType.ITEM_SCAN) { - menuItems.add(MenuItem("Refine Selection") { - GesturePoint.setReselect(true) - }) - } - - menuItems.add(MenuItem("Device", isLinkToMenu = true) { - MenuManager.getInstance().openDeviceMenu() - }) - - menuItems.add(MenuItem("Media Control", isLinkToMenu = true) { - MenuManager.getInstance().openMediaControlMenu() - }) - - val canEdit = NodeExaminer.canPerformEditActions(GesturePoint.getPoint()) - if (canEdit) { - menuItems.add(MenuItem("Edit", isLinkToMenu = true) { - MenuManager.getInstance().openEditMenu() - }) - } - - menuItems.add(MenuItem(MenuManager.getInstance().getTypeToSwitchTo()) { - MenuManager.getInstance().changeBetweenCursorAndItemScan() - }) - - return menuItems + return MenuItemStore(accessibilityService).mainMenuObject.getMenuItems() } } } \ No newline at end of file diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/media/MediaControlMenu.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/media/MediaControlMenu.kt index 14bb09eb..1274c65e 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/media/MediaControlMenu.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/media/MediaControlMenu.kt @@ -1,21 +1,16 @@ package com.enaboapps.switchify.service.menu.menus.media -import android.accessibilityservice.AccessibilityService import com.enaboapps.switchify.service.SwitchifyAccessibilityService import com.enaboapps.switchify.service.menu.MenuItem import com.enaboapps.switchify.service.menu.menus.BaseMenu +import com.enaboapps.switchify.service.menu.store.MenuItemStore class MediaControlMenu(accessibilityService: SwitchifyAccessibilityService) : BaseMenu(accessibilityService, buildMediaControlMenuItems(accessibilityService)) { companion object { private fun buildMediaControlMenuItems(accessibilityService: SwitchifyAccessibilityService): List { - return listOf( - // Play/Pause using headset - MenuItem("Play/Pause") { - accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_KEYCODE_HEADSETHOOK) - } - ) + return MenuItemStore(accessibilityService).mediaControlMenuObject.getMenuItems() } } } \ No newline at end of file diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/scroll/ScrollMenu.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/scroll/ScrollMenu.kt index 881a75e6..103a43c3 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/scroll/ScrollMenu.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/scroll/ScrollMenu.kt @@ -1,48 +1,15 @@ package com.enaboapps.switchify.service.menu.menus.scroll -import android.view.accessibility.AccessibilityNodeInfo import com.enaboapps.switchify.service.SwitchifyAccessibilityService -import com.enaboapps.switchify.service.gestures.GesturePoint import com.enaboapps.switchify.service.menu.MenuItem import com.enaboapps.switchify.service.menu.menus.BaseMenu -import com.enaboapps.switchify.service.nodes.Node -import com.enaboapps.switchify.service.nodes.NodeExaminer +import com.enaboapps.switchify.service.menu.store.MenuItemStore class ScrollMenu(accessibilityService: SwitchifyAccessibilityService) : BaseMenu(accessibilityService, buildScrollMenuItems(accessibilityService)) { companion object { private fun buildScrollMenuItems(accessibilityService: SwitchifyAccessibilityService): List { - val currentPoint = GesturePoint.getPoint() - val scrollUpNode = - NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.SCROLL_UP) - val scrollDownNode = - NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.SCROLL_DOWN) - val scrollLeftNode = - NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.SCROLL_LEFT) - val scrollRightNode = - NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.SCROLL_RIGHT) - return listOfNotNull( - if (scrollUpNode != null) { - MenuItem("Scroll Up", closeOnSelect = false) { - scrollUpNode.performAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP.id) - } - } else null, - if (scrollDownNode != null) { - MenuItem("Scroll Down", closeOnSelect = false) { - scrollDownNode.performAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN.id) - } - } else null, - if (scrollLeftNode != null) { - MenuItem("Scroll Left", closeOnSelect = false) { - scrollLeftNode.performAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_LEFT.id) - } - } else null, - if (scrollRightNode != null) { - MenuItem("Scroll Right", closeOnSelect = false) { - scrollRightNode.performAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_RIGHT.id) - } - } else null - ) + return MenuItemStore(accessibilityService).buildScrollMenuObject().getMenuItems() } } } \ No newline at end of file diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/system/DeviceMenu.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/system/DeviceMenu.kt index 8bbafc86..816a5b06 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/system/DeviceMenu.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/system/DeviceMenu.kt @@ -1,51 +1,17 @@ package com.enaboapps.switchify.service.menu.menus.system -import android.accessibilityservice.AccessibilityService -import android.content.pm.PackageManager import com.enaboapps.switchify.service.SwitchifyAccessibilityService import com.enaboapps.switchify.service.menu.MenuItem -import com.enaboapps.switchify.service.menu.MenuManager import com.enaboapps.switchify.service.menu.menus.BaseMenu -import com.enaboapps.switchify.service.utils.ScreenUtils +import com.enaboapps.switchify.service.menu.store.MenuItemStore class DeviceMenu( accessibilityService: SwitchifyAccessibilityService ) : BaseMenu(accessibilityService, buildDeviceItems(accessibilityService)) { companion object { - private fun buildDeviceItems(accessibilityService: AccessibilityService): List { - val packageManager = accessibilityService.packageManager - return listOfNotNull( - MenuItem("Recents") { - accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS) - }, - MenuItem("Notifications") { - accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS) - }, - MenuItem("All Apps") { - accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_ACCESSIBILITY_ALL_APPS) - }, - if (packageManager.hasSystemFeature(PackageManager.FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS) && ScreenUtils.isTablet( - accessibilityService - ) - ) { - MenuItem("Toggle Split Screen") { - accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN) - } - } else null, - MenuItem("Quick Settings") { - accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS) - }, - MenuItem("Lock Screen") { - accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_LOCK_SCREEN) - }, - MenuItem("Power Dialog") { - accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_POWER_DIALOG) - }, - MenuItem("Volume Control", isLinkToMenu = true) { - MenuManager.getInstance().openVolumeControlMenu() - } - ) + private fun buildDeviceItems(accessibilityService: SwitchifyAccessibilityService): List { + return MenuItemStore(accessibilityService).buildDeviceMenuObject().getMenuItems() } } } \ No newline at end of file diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/system/VolumeControlMenu.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/system/VolumeControlMenu.kt index 79da87c7..153e59a6 100644 --- a/app/src/main/java/com/enaboapps/switchify/service/menu/menus/system/VolumeControlMenu.kt +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/menus/system/VolumeControlMenu.kt @@ -1,34 +1,16 @@ package com.enaboapps.switchify.service.menu.menus.system -import android.content.Context -import android.media.AudioManager import com.enaboapps.switchify.service.SwitchifyAccessibilityService import com.enaboapps.switchify.service.menu.MenuItem import com.enaboapps.switchify.service.menu.menus.BaseMenu +import com.enaboapps.switchify.service.menu.store.MenuItemStore class VolumeControlMenu(private val accessibilityService: SwitchifyAccessibilityService) : BaseMenu(accessibilityService, buildVolumeControlMenuItems(accessibilityService)) { companion object { private fun buildVolumeControlMenuItems(accessibilityService: SwitchifyAccessibilityService): List { - val audioManager = - accessibilityService.getSystemService(Context.AUDIO_SERVICE) as AudioManager - return listOf( - MenuItem("Volume Up", closeOnSelect = false) { - audioManager.adjustStreamVolume( - AudioManager.STREAM_ACCESSIBILITY, - AudioManager.ADJUST_RAISE, - AudioManager.FLAG_SHOW_UI - ) - }, - MenuItem("Volume Down", closeOnSelect = false) { - audioManager.adjustStreamVolume( - AudioManager.STREAM_ACCESSIBILITY, - AudioManager.ADJUST_LOWER, - AudioManager.FLAG_SHOW_UI - ) - } - ) + return MenuItemStore(accessibilityService).buildVolumeControlMenuObject().getMenuItems() } } } \ No newline at end of file diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/store/MenuItemStore.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/store/MenuItemStore.kt new file mode 100644 index 00000000..c0d76f0f --- /dev/null +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/store/MenuItemStore.kt @@ -0,0 +1,452 @@ +package com.enaboapps.switchify.service.menu.store + +import android.accessibilityservice.AccessibilityService +import android.content.Context +import android.content.pm.PackageManager +import android.media.AudioManager +import android.view.accessibility.AccessibilityNodeInfo +import com.enaboapps.switchify.R +import com.enaboapps.switchify.service.SwitchifyAccessibilityService +import com.enaboapps.switchify.service.gestures.GestureManager +import com.enaboapps.switchify.service.gestures.GesturePoint +import com.enaboapps.switchify.service.gestures.SwipeDirection +import com.enaboapps.switchify.service.gestures.ZoomGesturePerformer +import com.enaboapps.switchify.service.menu.MenuItem +import com.enaboapps.switchify.service.menu.MenuManager +import com.enaboapps.switchify.service.nodes.Node +import com.enaboapps.switchify.service.nodes.NodeExaminer +import com.enaboapps.switchify.service.scanning.ScanMethod +import com.enaboapps.switchify.service.utils.ScreenUtils + +class MenuItemStore(private val accessibilityService: SwitchifyAccessibilityService) { + private val tapMenuItem = MenuItem( + id = "tap", + text = "Tap", + action = { + GestureManager.getInstance().performTap() + } + ) + + private val toggleGestureLockMenuItem = MenuItem( + id = "toggle_gesture_lock", + text = "Toggle Gesture Lock", + action = { GestureManager.getInstance().toggleGestureLock() } + ) + + /** + * The system navigation items + */ + val systemNavItems = listOf( + MenuItem( + id = "sys_back", + drawableId = R.drawable.ic_sys_back, + drawableDescription = "Back", + action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK) } + ), + MenuItem( + id = "sys_home", + drawableId = R.drawable.ic_sys_home, + drawableDescription = "Home", + action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME) } + ) + ) + + /** + * The navigation menu items + */ + val menuManipulatorItems = listOfNotNull( + if (MenuManager.getInstance().menuHierarchy?.getTopMenu() != null) { + MenuItem( + id = "previous_menu", + drawableId = R.drawable.ic_previous_menu, + drawableDescription = "Previous menu", + isMenuHierarchyManipulator = true, + action = { MenuManager.getInstance().menuHierarchy?.popMenu() } + ) + } else null, + MenuItem( + id = "close_menu", + drawableId = R.drawable.ic_close_menu, + drawableDescription = "Close menu", + isMenuHierarchyManipulator = true, + action = { MenuManager.getInstance().menuHierarchy?.removeAllMenus() } + ) + ) + + /** + * The main menu item store object + */ + val mainMenuObject = MenuItemStoreObject( + id = "main_menu", + items = listOfNotNull( + tapMenuItem, + MenuItem( + id = "gestures", + text = "Gestures", + isLinkToMenu = true, + action = { MenuManager.getInstance().openGesturesMenu() } + ), + if (NodeExaminer.canPerformScrollActions(GesturePoint.getPoint())) { + MenuItem( + id = "scroll", + text = "Scroll", + isLinkToMenu = true, + action = { MenuManager.getInstance().openScrollMenu() } + ) + } else null, + if (ScanMethod.getType() != ScanMethod.MethodType.ITEM_SCAN) { + MenuItem( + id = "refine_selection", + text = "Refine Selection", + action = { GesturePoint.setReselect(true) } + ) + } else null, + MenuItem( + id = "device", + text = "Device", + isLinkToMenu = true, + action = { MenuManager.getInstance().openDeviceMenu() } + ), + MenuItem( + id = "media_control", + text = "Media Control", + isLinkToMenu = true, + action = { MenuManager.getInstance().openMediaControlMenu() } + ), + if (NodeExaminer.canPerformEditActions(GesturePoint.getPoint())) { + MenuItem( + id = "edit", + text = "Edit", + isLinkToMenu = true, + action = { MenuManager.getInstance().openEditMenu() } + ) + } else null, + MenuItem( + id = "switch_cursor_item_scan", + text = MenuManager.getInstance().getTypeToSwitchTo(), + action = { MenuManager.getInstance().changeBetweenCursorAndItemScan() } + ) + ) + ) + + /** + * The gestures menu item store object + */ + val gesturesMenuObject = MenuItemStoreObject( + id = "gestures_menu", + items = listOf( + MenuItem( + id = "tap_gestures", + text = "Tap Gestures", + isLinkToMenu = true, + action = { MenuManager.getInstance().openTapMenu() } + ), + MenuItem( + id = "swipe_gestures", + text = "Swipe Gestures", + isLinkToMenu = true, + action = { MenuManager.getInstance().openSwipeMenu() } + ), + MenuItem( + id = "drag", + text = "Drag", + action = { GestureManager.getInstance().startDragGesture() } + ), + MenuItem( + id = "zoom_gestures", + text = "Zoom Gestures", + isLinkToMenu = true, + action = { MenuManager.getInstance().openZoomGesturesMenu() } + ), + toggleGestureLockMenuItem + ) + ) + + /** + * The swipe gestures menu item store object + */ + val swipeGesturesMenuObject = MenuItemStoreObject( + id = "swipe_gestures_menu", + items = listOf( + MenuItem( + id = "swipe_up", + text = "Swipe Up", + action = { GestureManager.getInstance().performSwipe(SwipeDirection.UP) } + ), + MenuItem( + id = "swipe_down", + text = "Swipe Down", + action = { GestureManager.getInstance().performSwipe(SwipeDirection.DOWN) } + ), + MenuItem( + id = "swipe_left", + text = "Swipe Left", + action = { GestureManager.getInstance().performSwipe(SwipeDirection.LEFT) } + ), + MenuItem( + id = "swipe_right", + text = "Swipe Right", + action = { GestureManager.getInstance().performSwipe(SwipeDirection.RIGHT) } + ), + toggleGestureLockMenuItem + ) + ) + + /** + * The tap gestures menu item store object + */ + val tapGesturesMenuObject = MenuItemStoreObject( + id = "tap_gestures_menu", + items = listOf( + tapMenuItem, + MenuItem( + id = "double_tap", + text = "Double Tap", + action = { GestureManager.getInstance().performDoubleTap() } + ), + MenuItem( + id = "tap_and_hold", + text = "Tap and Hold", + action = { GestureManager.getInstance().performTapAndHold() } + ), + toggleGestureLockMenuItem + ) + ) + + /** + * The zoom gestures menu item store object + */ + val zoomGesturesMenuObject = MenuItemStoreObject( + id = "zoom_gestures_menu", + items = listOf( + MenuItem( + id = "zoom_in", + text = "Zoom In", + action = { + GestureManager.getInstance() + .performZoomAction(ZoomGesturePerformer.ZoomAction.ZOOM_IN) + } + ), + MenuItem( + id = "zoom_out", + text = "Zoom Out", + action = { + GestureManager.getInstance() + .performZoomAction(ZoomGesturePerformer.ZoomAction.ZOOM_OUT) + } + ), + toggleGestureLockMenuItem + ) + ) + + /** + * The device menu item store object + */ + fun buildDeviceMenuObject(): MenuItemStoreObject { + val packageManager = accessibilityService.packageManager + return MenuItemStoreObject( + id = "device_menu", + items = listOfNotNull( + MenuItem( + id = "recent_apps", + text = "Recent Apps", + action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS) } + ), + MenuItem( + id = "notifications", + text = "Notifications", + action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS) } + ), + MenuItem( + id = "all_apps", + text = "All Apps", + action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_ACCESSIBILITY_ALL_APPS) } + ), + if (packageManager.hasSystemFeature(PackageManager.FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS) && ScreenUtils.isTablet( + accessibilityService + ) + ) { + MenuItem( + id = "toggle_split_screen", + text = "Toggle Split Screen", + action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN) } + ) + } else null, + MenuItem( + id = "quick_settings", + text = "Quick Settings", + action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS) } + ), + MenuItem( + id = "lock_screen", + text = "Lock Screen", + action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_LOCK_SCREEN) } + ), + MenuItem( + id = "power_dialog", + text = "Power Dialog", + action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_POWER_DIALOG) } + ), + MenuItem( + id = "volume_control", + text = "Volume Control", + isLinkToMenu = true, + action = { MenuManager.getInstance().openVolumeControlMenu() } + ) + ) + ) + } + + /** + * The volume control menu item store object + */ + fun buildVolumeControlMenuObject(): MenuItemStoreObject { + return MenuItemStoreObject( + id = "volume_control_menu", + items = listOf( + MenuItem( + id = "volume_up", + text = "Volume Up", + action = { + val audioManager = + accessibilityService.getSystemService(Context.AUDIO_SERVICE) as AudioManager + audioManager.adjustStreamVolume( + AudioManager.STREAM_ACCESSIBILITY, + AudioManager.ADJUST_RAISE, + AudioManager.FLAG_SHOW_UI + ) + } + ), + MenuItem( + id = "volume_down", + text = "Volume Down", + action = { + val audioManager = + accessibilityService.getSystemService(Context.AUDIO_SERVICE) as AudioManager + audioManager.adjustStreamVolume( + AudioManager.STREAM_ACCESSIBILITY, + AudioManager.ADJUST_LOWER, + AudioManager.FLAG_SHOW_UI + ) + } + ) + ) + ) + } + + /** + * The media control menu item store object + */ + val mediaControlMenuObject = MenuItemStoreObject( + id = "media_control_menu", + items = listOf( + MenuItem( + id = "play_pause", + text = "Play/Pause", + action = { accessibilityService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_KEYCODE_HEADSETHOOK) } + ) + ) + ) + + /** + * The scroll menu item store object + */ + fun buildScrollMenuObject(): MenuItemStoreObject { + val currentPoint = GesturePoint.getPoint() + val scrollUpNode = + NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.SCROLL_UP) + val scrollDownNode = + NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.SCROLL_DOWN) + val scrollLeftNode = + NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.SCROLL_LEFT) + val scrollRightNode = + NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.SCROLL_RIGHT) + return MenuItemStoreObject( + id = "scroll_menu", + items = listOfNotNull( + if (scrollUpNode != null) { + MenuItem( + id = "scroll_up", + text = "Scroll Up", + closeOnSelect = false, + action = { + scrollUpNode.performAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP.id) + } + ) + } else null, + if (scrollDownNode != null) { + MenuItem( + id = "scroll_down", + text = "Scroll Down", + closeOnSelect = false, + action = { + scrollDownNode.performAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN.id) + } + ) + } else null, + if (scrollLeftNode != null) { + MenuItem( + id = "scroll_left", + text = "Scroll Left", + closeOnSelect = false, + action = { + scrollLeftNode.performAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_LEFT.id) + } + ) + } else null, + if (scrollRightNode != null) { + MenuItem( + id = "scroll_right", + text = "Scroll Right", + closeOnSelect = false, + action = { + scrollRightNode.performAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_RIGHT.id) + } + ) + } else null + ) + ) + } + + /** + * The edit menu item store object + */ + fun buildEditMenuObject(): MenuItemStoreObject { + val currentPoint = GesturePoint.getPoint() + val cutNode = NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.CUT) + val copyNode = NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.COPY) + val pasteNode = NodeExaminer.findNodeForAction(currentPoint, Node.ActionType.PASTE) + return MenuItemStoreObject( + id = "edit_menu", + items = listOfNotNull( + if (cutNode != null) { + MenuItem( + id = "cut", + text = "Cut", + action = { + cutNode.performAction(AccessibilityNodeInfo.ACTION_CUT) + } + ) + } else null, + if (copyNode != null) { + MenuItem( + id = "copy", + text = "Copy", + action = { + copyNode.performAction(AccessibilityNodeInfo.ACTION_COPY) + } + ) + } else null, + if (pasteNode != null) { + MenuItem( + id = "paste", + text = "Paste", + action = { + pasteNode.performAction(AccessibilityNodeInfo.ACTION_PASTE) + } + ) + } else null + ) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/enaboapps/switchify/service/menu/store/MenuItemStoreObject.kt b/app/src/main/java/com/enaboapps/switchify/service/menu/store/MenuItemStoreObject.kt new file mode 100644 index 00000000..ad9aa705 --- /dev/null +++ b/app/src/main/java/com/enaboapps/switchify/service/menu/store/MenuItemStoreObject.kt @@ -0,0 +1,16 @@ +package com.enaboapps.switchify.service.menu.store + +import com.enaboapps.switchify.service.menu.MenuItem + +class MenuItemStoreObject( + val id: String, + private val items: List +) { + fun getMenuItems(): List { + return items + } + + fun getMenuItemIdList(): List { + return items.map { it.id } + } +} \ No newline at end of file