-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from enaboapps/iss234
Implement edit menu
- Loading branch information
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/enaboapps/switchify/service/menu/menus/edit/EditMenu.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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 | ||
|
||
class EditMenu(accessibilityService: SwitchifyAccessibilityService) : | ||
BaseMenu(accessibilityService, buildEditMenuItems(accessibilityService)) { | ||
companion object { | ||
private fun buildEditMenuItems(accessibilityService: SwitchifyAccessibilityService): List<MenuItem> { | ||
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 | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters