From 74fcdc7ce1080562630b502988f7798f3f39f2dc Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Tue, 6 Apr 2021 18:52:15 +0300 Subject: [PATCH] Fix #9567 --- .../activities/MapActivityKeyListener.java | 8 +++---- .../net/osmand/plus/helpers/ScrollHelper.java | 21 +++++++++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityKeyListener.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityKeyListener.java index 20c2459c69..e218272c13 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityKeyListener.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityKeyListener.java @@ -53,9 +53,7 @@ public class MapActivityKeyListener implements KeyEvent.Callback { uiHandler.sendMessageDelayed(msg, LONG_KEYPRESS_DELAY); } return true; - } else if (settings.EXTERNAL_INPUT_DEVICE.get() != NO_EXTERNAL_DEVICE) { - return true; - } else if (mapScrollHelper.isScrollingDirectionKeyCode(keyCode)) { + } else if (mapScrollHelper.isAvailableKeyCode(keyCode)) { return mapScrollHelper.onKeyDown(keyCode, event); } @@ -96,6 +94,8 @@ public class MapActivityKeyListener implements KeyEvent.Callback { mapActivity.getMapViewTrackingUtilities().backToLocationImpl(); } else if (keyCode == KeyEvent.KEYCODE_D) { mapActivity.getMapViewTrackingUtilities().switchRotateMapMode(); + } else if (mapScrollHelper.isAvailableKeyCode(keyCode)) { + return mapScrollHelper.onKeyUp(keyCode, event); } else if (settings.EXTERNAL_INPUT_DEVICE.get() == PARROT_EXTERNAL_DEVICE) { // Parrot device has only dpad left and right if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { @@ -120,8 +120,6 @@ public class MapActivityKeyListener implements KeyEvent.Callback { mapActivity.startActivity(intent); return true; } - } else if (mapScrollHelper.isScrollingDirectionKeyCode(keyCode)) { - return mapScrollHelper.onKeyUp(keyCode, event); } else if (settings.EXTERNAL_INPUT_DEVICE.get() == GENERIC_EXTERNAL_DEVICE) { if (keyCode == KeyEvent.KEYCODE_MINUS) { mapActivity.changeZoom(-1); diff --git a/OsmAnd/src/net/osmand/plus/helpers/ScrollHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ScrollHelper.java index 8fd43c49c2..37da378f6d 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ScrollHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ScrollHelper.java @@ -3,12 +3,16 @@ package net.osmand.plus.helpers; import android.view.KeyEvent; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.settings.backend.OsmandSettings; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import static net.osmand.plus.settings.backend.OsmandSettings.PARROT_EXTERNAL_DEVICE; +import static net.osmand.plus.settings.backend.OsmandSettings.WUNDERLINQ_EXTERNAL_DEVICE; + public class ScrollHelper { private final static int LONG_PRESS_TIME_MS = 250; @@ -135,8 +139,21 @@ public class ScrollHelper { this.onScrollEventListener = onScrollEventListener; } - public boolean isScrollingDirectionKeyCode(int keyCode) { - return availableDirections.containsKey(keyCode); + public boolean isAvailableKeyCode(int keyCode) { + return availableDirections.containsKey(keyCode) + && !isOverrideBySelectedExternalDevice(keyCode); + } + + public boolean isOverrideBySelectedExternalDevice(int keyCode) { + OsmandSettings settings = app.getSettings(); + + if (settings.EXTERNAL_INPUT_DEVICE.get() == PARROT_EXTERNAL_DEVICE) { + return keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT; + + } else if (settings.EXTERNAL_INPUT_DEVICE.get() == WUNDERLINQ_EXTERNAL_DEVICE) { + return keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN; + } + return false; } public List getLastDirections() {