Skip to content

Commit ede490f

Browse files
authored
Merge branch 'develop' into develop
2 parents 1c13ed7 + 294adbe commit ede490f

File tree

23 files changed

+221
-106
lines changed

23 files changed

+221
-106
lines changed

.run/instrumentation-tests.run.xml

Lines changed: 0 additions & 51 deletions
This file was deleted.

.run/unit-tests.run.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
- #1466 show onboarding when creating a key map for the first time
88
- #1729 target Android 16.
9+
- #1725 action to move cursor to previous/next character, word, line, paragraph, or page.
910

1011
## Changed
1112

1213
- #1711 major refactoring of the entire codebase into separate Gradle modules.
1314
- #1701 improve the order of the actions and categories
15+
- Key Mapper keyboard or Shizuku are no longer required for the action to move the cursor to the end
1416

1517
## Bug fixes
1618

app/version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
VERSION_NAME=3.2.0
2-
VERSION_CODE=123
2+
VERSION_CODE=125
33
VERSION_NUM=0

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionData.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,21 @@ sealed class ActionData : Comparable<ActionData> {
764764
}
765765

766766
@Serializable
767-
data object MoveCursorToEnd : ActionData() {
768-
override val id = ActionId.MOVE_CURSOR_TO_END
767+
data class MoveCursor(val moveType: Type, val direction: Direction) : ActionData() {
768+
override val id = ActionId.MOVE_CURSOR
769+
770+
enum class Type {
771+
CHAR,
772+
WORD,
773+
LINE,
774+
PARAGRAPH,
775+
PAGE,
776+
}
777+
778+
enum class Direction {
779+
START,
780+
END,
781+
}
769782
}
770783

771784
@Serializable

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionDataEntityMapper.kt

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ object ActionDataEntityMapper {
498498
ActionId.DISABLE_NFC -> ActionData.Nfc.Disable
499499
ActionId.TOGGLE_NFC -> ActionData.Nfc.Toggle
500500

501-
ActionId.MOVE_CURSOR_TO_END -> ActionData.MoveCursorToEnd
502501
ActionId.TOGGLE_KEYBOARD -> ActionData.ToggleKeyboard
503502
ActionId.SHOW_KEYBOARD -> ActionData.ShowKeyboard
504503
ActionId.HIDE_KEYBOARD -> ActionData.HideKeyboard
@@ -606,6 +605,39 @@ object ActionDataEntityMapper {
606605
nodeActions = actions,
607606
)
608607
}
608+
609+
ActionId.MOVE_CURSOR -> {
610+
// For compatibility with the old "Move cursor to the end" action.
611+
if (entity.extras.isEmpty()) {
612+
return ActionData.MoveCursor(
613+
moveType = ActionData.MoveCursor.Type.PAGE,
614+
ActionData.MoveCursor.Direction.END,
615+
)
616+
}
617+
618+
val type =
619+
entity.extras.getData(ActionEntity.EXTRA_MOVE_CURSOR_TYPE).then { value ->
620+
when (value) {
621+
ActionEntity.CURSOR_TYPE_CHAR -> Success(ActionData.MoveCursor.Type.CHAR)
622+
ActionEntity.CURSOR_TYPE_WORD -> Success(ActionData.MoveCursor.Type.WORD)
623+
ActionEntity.CURSOR_TYPE_LINE -> Success(ActionData.MoveCursor.Type.LINE)
624+
ActionEntity.CURSOR_TYPE_PARAGRAPH -> Success(ActionData.MoveCursor.Type.PARAGRAPH)
625+
ActionEntity.CURSOR_TYPE_PAGE -> Success(ActionData.MoveCursor.Type.PAGE)
626+
else -> KMError.Exception(IllegalArgumentException("Unknown move cursor type: $value"))
627+
}
628+
}.valueOrNull() ?: return null
629+
630+
val direction =
631+
entity.extras.getData(ActionEntity.EXTRA_MOVE_CURSOR_DIRECTION).then { value ->
632+
when (value) {
633+
ActionEntity.CURSOR_DIRECTION_START -> Success(ActionData.MoveCursor.Direction.START)
634+
ActionEntity.CURSOR_DIRECTION_END -> Success(ActionData.MoveCursor.Direction.END)
635+
else -> KMError.Exception(IllegalArgumentException("Unknown move cursor direction: $value"))
636+
}
637+
}.valueOrNull() ?: return null
638+
639+
ActionData.MoveCursor(moveType = type, direction = direction)
640+
}
609641
}
610642
}
611643

@@ -918,6 +950,23 @@ object ActionDataEntityMapper {
918950
}
919951
}
920952

953+
is ActionData.MoveCursor -> buildList {
954+
val typeString = when (data.moveType) {
955+
ActionData.MoveCursor.Type.CHAR -> ActionEntity.CURSOR_TYPE_CHAR
956+
ActionData.MoveCursor.Type.WORD -> ActionEntity.CURSOR_TYPE_WORD
957+
ActionData.MoveCursor.Type.LINE -> ActionEntity.CURSOR_TYPE_LINE
958+
ActionData.MoveCursor.Type.PARAGRAPH -> ActionEntity.CURSOR_TYPE_PARAGRAPH
959+
ActionData.MoveCursor.Type.PAGE -> ActionEntity.CURSOR_TYPE_PAGE
960+
}
961+
add(EntityExtra(ActionEntity.EXTRA_MOVE_CURSOR_TYPE, typeString))
962+
963+
val directionString = when (data.direction) {
964+
ActionData.MoveCursor.Direction.START -> ActionEntity.CURSOR_DIRECTION_START
965+
ActionData.MoveCursor.Direction.END -> ActionEntity.CURSOR_DIRECTION_END
966+
}
967+
add(EntityExtra(ActionEntity.EXTRA_MOVE_CURSOR_DIRECTION, directionString))
968+
}
969+
921970
else -> emptyList()
922971
}
923972

@@ -1051,7 +1100,9 @@ object ActionDataEntityMapper {
10511100
ActionId.DISABLE_NFC to "nfc_disable",
10521101
ActionId.TOGGLE_NFC to "nfc_toggle",
10531102

1054-
ActionId.MOVE_CURSOR_TO_END to "move_cursor_to_end",
1103+
// This action used to just move the cursor to the end. Do not change the
1104+
// id for compatibility reasons.
1105+
ActionId.MOVE_CURSOR to "move_cursor_to_end",
10551106
ActionId.TOGGLE_KEYBOARD to "toggle_keyboard",
10561107
ActionId.SHOW_KEYBOARD to "show_keyboard",
10571108
ActionId.HIDE_KEYBOARD to "hide_keyboard",

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionErrorSnapshot.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class LazyActionErrorSnapshot(
7575
val isCurrentImeCompatible =
7676
KeyMapperImeHelper.isKeyMapperInputMethod(
7777
currentImeFromActions.packageName,
78-
buildConfigProvider.packageName
78+
buildConfigProvider.packageName,
7979
)
8080

8181
if (isCurrentImeCompatible) {
@@ -200,7 +200,6 @@ class LazyActionErrorSnapshot(
200200
return isGranted
201201
}
202202
}
203-
204203
}
205204

206205
interface ActionErrorSnapshot {

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionId.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ enum class ActionId {
103103
TEXT_CUT,
104104
TEXT_COPY,
105105
TEXT_PASTE,
106-
MOVE_CURSOR_TO_END,
106+
MOVE_CURSOR,
107107
SELECT_WORD_AT_CURSOR,
108108
TOGGLE_KEYBOARD,
109109
SHOW_KEYBOARD,

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUiHelper.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,29 @@ class ActionUiHelper(
492492
ActionData.MobileData.Enable -> getString(R.string.action_enable_mobile_data)
493493
ActionData.MobileData.Toggle -> getString(R.string.action_toggle_mobile_data)
494494

495-
ActionData.MoveCursorToEnd -> getString(R.string.action_move_to_end_of_text)
495+
is ActionData.MoveCursor -> {
496+
when (action.direction) {
497+
ActionData.MoveCursor.Direction.START -> {
498+
when (action.moveType) {
499+
ActionData.MoveCursor.Type.CHAR -> getString(R.string.action_move_cursor_prev_character)
500+
ActionData.MoveCursor.Type.WORD -> getString(R.string.action_move_cursor_start_word)
501+
ActionData.MoveCursor.Type.LINE -> getString(R.string.action_move_cursor_start_line)
502+
ActionData.MoveCursor.Type.PARAGRAPH -> getString(R.string.action_move_cursor_start_paragraph)
503+
ActionData.MoveCursor.Type.PAGE -> getString(R.string.action_move_cursor_start_page)
504+
}
505+
}
506+
507+
ActionData.MoveCursor.Direction.END -> {
508+
when (action.moveType) {
509+
ActionData.MoveCursor.Type.CHAR -> getString(R.string.action_move_cursor_next_character)
510+
ActionData.MoveCursor.Type.WORD -> getString(R.string.action_move_cursor_end_word)
511+
ActionData.MoveCursor.Type.LINE -> getString(R.string.action_move_cursor_end_line)
512+
ActionData.MoveCursor.Type.PARAGRAPH -> getString(R.string.action_move_cursor_end_paragraph)
513+
ActionData.MoveCursor.Type.PAGE -> getString(R.string.action_move_cursor_end_page)
514+
}
515+
}
516+
}
517+
}
496518

497519
ActionData.Nfc.Disable -> getString(R.string.action_nfc_disable)
498520
ActionData.Nfc.Enable -> getString(R.string.action_nfc_enable)

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUtils.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ object ActionUtils {
209209
ActionId.ENABLE_AIRPLANE_MODE -> ActionCategory.CONNECTIVITY
210210
ActionId.DISABLE_AIRPLANE_MODE -> ActionCategory.CONNECTIVITY
211211

212-
ActionId.MOVE_CURSOR_TO_END -> ActionCategory.KEYBOARD
212+
ActionId.MOVE_CURSOR -> ActionCategory.KEYBOARD
213213
ActionId.TOGGLE_KEYBOARD -> ActionCategory.KEYBOARD
214214
ActionId.SHOW_KEYBOARD -> ActionCategory.KEYBOARD
215215
ActionId.HIDE_KEYBOARD -> ActionCategory.KEYBOARD
@@ -317,7 +317,7 @@ object ActionUtils {
317317
ActionId.ENABLE_NFC -> R.string.action_nfc_enable
318318
ActionId.DISABLE_NFC -> R.string.action_nfc_disable
319319
ActionId.TOGGLE_NFC -> R.string.action_nfc_toggle
320-
ActionId.MOVE_CURSOR_TO_END -> R.string.action_move_to_end_of_text
320+
ActionId.MOVE_CURSOR -> R.string.action_move_cursor
321321
ActionId.TOGGLE_KEYBOARD -> R.string.action_toggle_keyboard
322322
ActionId.SHOW_KEYBOARD -> R.string.action_show_keyboard
323323
ActionId.HIDE_KEYBOARD -> R.string.action_hide_keyboard
@@ -436,7 +436,7 @@ object ActionUtils {
436436
ActionId.ENABLE_NFC -> R.drawable.ic_outline_nfc_24
437437
ActionId.DISABLE_NFC -> R.drawable.ic_nfc_off
438438
ActionId.TOGGLE_NFC -> R.drawable.ic_outline_nfc_24
439-
ActionId.MOVE_CURSOR_TO_END -> R.drawable.ic_cursor
439+
ActionId.MOVE_CURSOR -> R.drawable.ic_cursor
440440
ActionId.TOGGLE_KEYBOARD -> R.drawable.ic_outline_keyboard_24
441441
ActionId.SHOW_KEYBOARD -> R.drawable.ic_outline_keyboard_24
442442
ActionId.HIDE_KEYBOARD -> R.drawable.ic_outline_keyboard_hide_24
@@ -759,7 +759,7 @@ object ActionUtils {
759759
ActionId.ENABLE_NFC -> Icons.Outlined.Nfc
760760
ActionId.DISABLE_NFC -> KeyMapperIcons.NfcOff
761761
ActionId.TOGGLE_NFC -> Icons.Outlined.Nfc
762-
ActionId.MOVE_CURSOR_TO_END -> KeyMapperIcons.TextSelectEnd
762+
ActionId.MOVE_CURSOR -> KeyMapperIcons.TextSelectEnd
763763
ActionId.TOGGLE_KEYBOARD -> Icons.Outlined.Keyboard
764764
ActionId.SHOW_KEYBOARD -> Icons.Outlined.Keyboard
765765
ActionId.HIDE_KEYBOARD -> Icons.Outlined.KeyboardHide
@@ -813,13 +813,11 @@ fun ActionData.canBeHeldDown(): Boolean = when (this) {
813813
fun ActionData.canUseImeToPerform(): Boolean = when (this) {
814814
is ActionData.InputKeyEvent -> !useShell
815815
is ActionData.Text -> true
816-
is ActionData.MoveCursorToEnd -> true
817816
else -> false
818817
}
819818

820819
fun ActionData.canUseShizukuToPerform(): Boolean = when (this) {
821820
is ActionData.InputKeyEvent -> true
822-
is ActionData.MoveCursorToEnd -> true
823821
else -> false
824822
}
825823

@@ -853,6 +851,7 @@ fun ActionData.isEditable(): Boolean = when (this) {
853851
is ActionData.PhoneCall,
854852
is ActionData.HttpRequest,
855853
is ActionData.InteractUiElement,
854+
is ActionData.MoveCursor,
856855
-> true
857856

858857
else -> false

0 commit comments

Comments
 (0)