From 03b541eee527ca76f4180284c9c926a98776a5d6 Mon Sep 17 00:00:00 2001 From: sds100 Date: Thu, 4 Apr 2019 18:37:16 +0100 Subject: [PATCH] MyAccessibilityService: don't perform a short press action more than once after a long press action has been performed --- .../sds100/keymapper/service/MyAccessibilityService.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/github/sds100/keymapper/service/MyAccessibilityService.kt b/app/src/main/java/io/github/sds100/keymapper/service/MyAccessibilityService.kt index 7f13ffefd1..3b19a98039 100644 --- a/app/src/main/java/io/github/sds100/keymapper/service/MyAccessibilityService.kt +++ b/app/src/main/java/io/github/sds100/keymapper/service/MyAccessibilityService.kt @@ -353,6 +353,13 @@ class MyAccessibilityService : AccessibilityService(), IContext, IPerformGlobalA mLongPressPendingActions.any { it.trigger.keys.contains(event.keyCode) }) { imitateButtonPress(event.keyCode) } + } else { + /* must remove all short press pending actions created during the down press. But don't run them + * since only the long press should be ran. */ + mShortPressPendingActions.filter { it.trigger.keys.contains(event.keyCode) }.forEach { + mHandler.removeCallbacks(it) + mShortPressPendingActions.remove(it) + } } //remove all pending long press actions since their trigger has been released @@ -381,7 +388,7 @@ class MyAccessibilityService : AccessibilityService(), IContext, IPerformGlobalA mKeyMapListCache.forEach { keymap -> /* only add a trigger to the list if it hasn't already been registered as a long press trigger */ - if (keymap.isLongPress) { + if (keymap.isLongPress && keymap.isEnabled) { val newLongPressTriggers = keymap.triggerList.filter { !mTriggersAwaitingLongPress.contains(it) } mTriggersAwaitingLongPress.addAll(newLongPressTriggers)