Merge pull request #9321 from osmandapp/Volume_buttons_as_zoom

Option to use volume buttons as zoom
This commit is contained in:
vshcherb 2020-06-25 21:04:14 +02:00 committed by GitHub
commit bdc3d67dd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 168 additions and 71 deletions

View file

@ -11,6 +11,8 @@
Thx - Hardy
-->
<string name="use_volume_buttons_as_zoom">Volume buttons as zoom</string>
<string name="use_volume_buttons_as_zoom_descr">Enable to control the map zoom level with device volume buttons.</string>
<string name="app_mode_inline_skates">Inline skates</string>
<string name="speed_cameras_removed_descr">This device doesn\'t have speed cameras.</string>
<string name="shared_string_uninstall_and_restart">Uninstall and Restart</string>

View file

@ -82,6 +82,14 @@
android:layout="@layout/preference_category_with_descr"
android:title="@string/shared_string_other" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="use_volume_buttons_as_zoom"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/use_volume_buttons_as_zoom"
tools:icon="@drawable/ic_action_zoom_volume_buttons" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="use_kalman_filter_compass"
android:layout="@layout/preference_with_descr_dialog_and_switch"

View file

@ -17,8 +17,6 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.KeyEvent;
@ -173,9 +171,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
import static net.osmand.plus.settings.backend.OsmandSettings.GENERIC_EXTERNAL_DEVICE;
import static net.osmand.plus.settings.backend.OsmandSettings.PARROT_EXTERNAL_DEVICE;
import static net.osmand.plus.settings.backend.OsmandSettings.WUNDERLINQ_EXTERNAL_DEVICE;
public class MapActivity extends OsmandActionBarActivity implements DownloadEvents,
OnRequestPermissionsResultCallback, IRouteInformationListener, AMapPointUpdateListener,
@ -187,8 +182,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
public static final String INTENT_PARAMS = "intent_prarams";
private static final int SHOW_POSITION_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 1;
private static final int LONG_KEYPRESS_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 2;
private static final int LONG_KEYPRESS_DELAY = 500;
private static final int ZOOM_LABEL_DISPLAY = 16;
private static final int MIN_ZOOM_LABEL_DISPLAY = 12;
private static final int SECOND_SPLASH_TIME_OUT = 8000;
@ -217,8 +210,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private MapActivityActions mapActions;
private MapActivityLayers mapLayers;
// handler to show/hide trackball position and to link map with delay
private Handler uiHandler = new Handler();
// App variables
private OsmandApplication app;
private OsmandSettings settings;
@ -265,6 +256,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
changeKeyguardFlags();
}
};
private MapActivityKeyListener mapActivityKeyListener;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -387,7 +379,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
app.getAidlApi().onCreateMapActivity(this);
lockHelper.setLockUIAdapter(this);
mapActivityKeyListener = new MapActivityKeyListener(this);
mIsDestroyed = false;
}
@ -1532,78 +1524,26 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
public ScrollHelper getMapScrollHelper() {
return mapScrollHelper;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER && app.accessibilityEnabled()) {
if (!uiHandler.hasMessages(LONG_KEYPRESS_MSG_ID)) {
Message msg = Message.obtain(uiHandler, new Runnable() {
@Override
public void run() {
app.getLocationProvider().emitNavigationHint();
}
});
msg.what = LONG_KEYPRESS_MSG_ID;
uiHandler.sendMessageDelayed(msg, LONG_KEYPRESS_DELAY);
}
if (mapActivityKeyListener != null) {
if (mapActivityKeyListener.onKeyDown(keyCode, event)) {
return true;
} else if (mapScrollHelper.isScrollingDirectionKeyCode(keyCode)) {
return mapScrollHelper.onKeyDown(keyCode, event);
}
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
if (!app.accessibilityEnabled()) {
mapActions.contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
} else if (uiHandler.hasMessages(LONG_KEYPRESS_MSG_ID)) {
uiHandler.removeMessages(LONG_KEYPRESS_MSG_ID);
mapActions.contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_MENU /*&& event.getRepeatCount() == 0*/) {
// repeat count 0 doesn't work for samsung, 1 doesn't work for lg
toggleDrawer();
return true;
} else if (keyCode == KeyEvent.KEYCODE_C) {
mapViewTrackingUtilities.backToLocationImpl();
} else if (settings.EXTERNAL_INPUT_DEVICE.get() == PARROT_EXTERNAL_DEVICE) {
// Parrot device has only dpad left and right
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
changeZoom(-1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
changeZoom(1);
if (mapActivityKeyListener != null) {
if (mapActivityKeyListener.onKeyUp(keyCode, event)) {
return true;
}
} else if (settings.EXTERNAL_INPUT_DEVICE.get() == WUNDERLINQ_EXTERNAL_DEVICE) {
// WunderLINQ device, motorcycle smart phone control
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
changeZoom(-1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
changeZoom(1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_ESCAPE) {
String callingApp = "wunderlinq://datagrid";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(callingApp));
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) {
changeZoom(-1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_PLUS) {
changeZoom(1);
return true;
}
} else if (OsmandPlugin.onMapActivityKeyUp(this, keyCode)) {
return true;
}
return super.onKeyUp(keyCode, event);
}

View file

@ -0,0 +1,137 @@
package net.osmand.plus.activities;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.helpers.ScrollHelper;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.OsmandMapTileView;
import static net.osmand.plus.settings.backend.OsmandSettings.GENERIC_EXTERNAL_DEVICE;
import static net.osmand.plus.settings.backend.OsmandSettings.PARROT_EXTERNAL_DEVICE;
import static net.osmand.plus.settings.backend.OsmandSettings.WUNDERLINQ_EXTERNAL_DEVICE;
public class MapActivityKeyListener implements KeyEvent.Callback {
public static final int LONG_KEYPRESS_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 2;
public static final int LONG_KEYPRESS_DELAY = 500;
private MapActivity mapActivity;
private OsmandApplication app;
private MapActivityActions mapActions;
private OsmandSettings settings;
// handler to show/hide trackball position and to link map with delay
private Handler uiHandler = new Handler();
private ScrollHelper mapScrollHelper;
public MapActivityKeyListener(MapActivity mapActivity) {
this.mapActivity = mapActivity;
app = mapActivity.getMyApplication();
mapActions = mapActivity.getMapActions();
settings = app.getSettings();
mapScrollHelper = mapActivity.getMapScrollHelper();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER && app.accessibilityEnabled()) {
if (!uiHandler.hasMessages(LONG_KEYPRESS_MSG_ID)) {
Message msg = Message.obtain(uiHandler, new Runnable() {
@Override
public void run() {
app.getLocationProvider().emitNavigationHint();
}
});
msg.what = LONG_KEYPRESS_MSG_ID;
uiHandler.sendMessageDelayed(msg, LONG_KEYPRESS_DELAY);
}
return true;
} else if (settings.USE_VOLUME_BUTTONS_AS_ZOOM.get()) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
mapActivity.changeZoom(-1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
mapActivity.changeZoom(1);
return true;
}
} else if (mapScrollHelper.isScrollingDirectionKeyCode(keyCode)) {
return mapScrollHelper.onKeyDown(keyCode, event);
}
return false;
}
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
return false;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
OsmandMapTileView mapView = mapActivity.getMapView();
if (!app.accessibilityEnabled()) {
mapActions.contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
} else if (uiHandler.hasMessages(LONG_KEYPRESS_MSG_ID)) {
uiHandler.removeMessages(LONG_KEYPRESS_MSG_ID);
mapActions.contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_MENU /*&& event.getRepeatCount() == 0*/) {
// repeat count 0 doesn't work for samsung, 1 doesn't work for lg
mapActivity.toggleDrawer();
return true;
} else if (keyCode == KeyEvent.KEYCODE_C) {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
} else if (settings.EXTERNAL_INPUT_DEVICE.get() == PARROT_EXTERNAL_DEVICE) {
// Parrot device has only dpad left and right
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
mapActivity.changeZoom(-1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
mapActivity.changeZoom(1);
return true;
}
} else if (settings.EXTERNAL_INPUT_DEVICE.get() == WUNDERLINQ_EXTERNAL_DEVICE) {
// WunderLINQ device, motorcycle smart phone control
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
mapActivity.changeZoom(-1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
mapActivity.changeZoom(1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_ESCAPE) {
String callingApp = "wunderlinq://datagrid";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(callingApp));
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);
return true;
} else if (keyCode == KeyEvent.KEYCODE_PLUS) {
mapActivity.changeZoom(1);
return true;
}
} else {
return OsmandPlugin.onMapActivityKeyUp(mapActivity, keyCode);
}
return false;
}
@Override
public boolean onKeyMultiple(int keyCode, int count, KeyEvent event) {
return false;
}
}

View file

@ -1884,6 +1884,7 @@ public class OsmandSettings {
// magnetic field doesn'torkmost of the time on some phones
public final OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS = new BooleanPreference("use_magnetic_field_sensor_compass", false).makeProfile().cache();
public final OsmandPreference<Boolean> USE_KALMAN_FILTER_FOR_COMPASS = new BooleanPreference("use_kalman_filter_compass", true).makeProfile().cache();
public final OsmandPreference<Boolean> USE_VOLUME_BUTTONS_AS_ZOOM = new BooleanPreference("use_volume_buttons_as_zoom", false).makeProfile().cache();
public final OsmandPreference<Boolean> DO_NOT_SHOW_STARTUP_MESSAGES = new BooleanPreference("do_not_show_startup_messages", false).makeGlobal().cache();
public final OsmandPreference<Boolean> SHOW_DOWNLOAD_MAP_DIALOG = new BooleanPreference("show_download_map_dialog", true).makeGlobal().cache();

View file

@ -54,6 +54,7 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
setupAngularUnitsPref();
setupSpeedSystemPref();
setupVolumeButtonsAsZoom();
setupKalmanFilterPref();
setupMagneticFieldSensorPref();
setupMapEmptyStateAllowedPref();
@ -224,6 +225,14 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
speedSystem.setIcon(getActiveIcon(R.drawable.ic_action_speed));
}
private void setupVolumeButtonsAsZoom() {
SwitchPreferenceEx volumeButtonsPref = (SwitchPreferenceEx) findPreference(settings.USE_VOLUME_BUTTONS_AS_ZOOM.getId());
volumeButtonsPref.setTitle(getString(R.string.use_volume_buttons_as_zoom));
volumeButtonsPref.setDescription(getString(R.string.use_volume_buttons_as_zoom_descr));
Drawable icon = getPersistentPrefIcon(R.drawable.ic_action_zoom_volume_buttons);
volumeButtonsPref.setIcon(icon);
}
private void setupKalmanFilterPref() {
SwitchPreferenceEx kalmanFilterPref = (SwitchPreferenceEx) findPreference(settings.USE_KALMAN_FILTER_FOR_COMPASS.getId());
kalmanFilterPref.setTitle(getString(R.string.use_kalman_filter_compass));