This commit is contained in:
nazar-kutz 2021-04-06 18:52:15 +03:00
parent 64e2bc56e1
commit 74fcdc7ce1
2 changed files with 22 additions and 7 deletions

View file

@ -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);

View file

@ -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<Direction> getLastDirections() {