improve sensor and VoiceRouter settings setup

This commit is contained in:
Nazar 2019-07-04 14:17:30 +03:00
parent 2dd1f801ae
commit fd5d0c5697
7 changed files with 52 additions and 45 deletions

View file

@ -11,9 +11,10 @@
Thx - Hardy
-->
<string name="wake_on_voice_time_descr">Set the time for which the screen will turn on.</string>
<string name="wake_on_voice_sensor">Use proximity sensor</string>
<string name="wake_on_voice_sensor_descr">Wave your hand over the top of the screen to turn on the screen while navigating.</string>
<string name="turn_screen_on_router">Wake on turn</string>
<string name="turn_screen_on_time_descr">Set the time for which the screen will turn on.</string>
<string name="turn_screen_on_sensor">Use proximity sensor</string>
<string name="turn_screen_on_sensor_descr">Wave your hand over the top of the screen to turn on the screen while navigating.</string>
<string name="app_profile_custom_nav_subtitle"></string>
<string name="rate_dialog_descr">Please give us 30 seconds, share feedback and rate our work on Google Play.</string>
<string name="button_rate">Rate</string>

View file

@ -74,18 +74,20 @@
<PreferenceCategory
android:key="turn_screen_on"
android:layout="@layout/preference_category_summary"
android:title="@string/wake_on_voice"
android:summary="@string/wake_on_voice_descr">
android:title="@string/wake_on_voice">
<ListPreference
android:key="wake_on_voice_time_int"
android:summary="@string/wake_on_voice_time_descr"
android:key="turn_screen_on_time_int"
android:summary="@string/turn_screen_on_time_descr"
android:title="@string/shared_string_time"/>
<CheckBoxPreference
android:key="wake_on_voice_sensor"
android:summary="@string/wake_on_voice_sensor_descr"
android:title="@string/wake_on_voice_sensor"/>
android:key="turn_screen_on_router"
android:summary="@string/wake_on_voice_descr"
android:title="@string/turn_screen_on_router"/>
<CheckBoxPreference
android:key="turn_screen_on_sensor"
android:summary="@string/turn_screen_on_sensor_descr"
android:title="@string/turn_screen_on_sensor"/>
</PreferenceCategory>
<PreferenceCategory

View file

@ -1387,21 +1387,17 @@ public class OsmandSettings {
KEEP_INFORMING.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 0);
}
public final CommonPreference<Integer> WAKE_ON_VOICE_TIME_INT = new IntPreference("wake_on_voice_time_int", 0).makeProfile();
public final CommonPreference<Integer> TURN_SCREEN_ON_TIME_INT = new IntPreference("turn_screen_on_time_int", 0).makeGlobal();
public final CommonPreference<Boolean> TURN_SCREEN_ON_ROUTER = new BooleanPreference("turn_screen_on_router", false).makeProfile();
{
WAKE_ON_VOICE_TIME_INT.setModeDefaultValue(ApplicationMode.CAR, 0);
WAKE_ON_VOICE_TIME_INT.setModeDefaultValue(ApplicationMode.BICYCLE, 0);
WAKE_ON_VOICE_TIME_INT.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 0);
TURN_SCREEN_ON_ROUTER.setModeDefaultValue(ApplicationMode.CAR, false);
TURN_SCREEN_ON_ROUTER.setModeDefaultValue(ApplicationMode.BICYCLE, false);
TURN_SCREEN_ON_ROUTER.setModeDefaultValue(ApplicationMode.PEDESTRIAN, false);
}
public final CommonPreference<Boolean> WAKE_ON_VOICE_SENSOR = new BooleanPreference("wake_on_voice_sensor", false).makeProfile();
{
WAKE_ON_VOICE_SENSOR.setModeDefaultValue(ApplicationMode.CAR, false);
WAKE_ON_VOICE_SENSOR.setModeDefaultValue(ApplicationMode.BICYCLE, false);
WAKE_ON_VOICE_SENSOR.setModeDefaultValue(ApplicationMode.PEDESTRIAN, false);
}
public final CommonPreference<Boolean> TURN_SCREEN_ON_SENSOR = new BooleanPreference("turn_screen_on_sensor", false).makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
// try without AUTO_FOLLOW_ROUTE_NAV (see forum discussion 'Simplify our navigation preference menu')

View file

@ -1415,6 +1415,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
getMapView().refreshMap(true);
}
});
lockHelper.refreshProfilesSettings();
getMapView().refreshMap(true);
}

View file

@ -3,7 +3,6 @@ package net.osmand.plus.activities;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent;
import android.media.AudioManager;
@ -17,19 +16,14 @@ import android.preference.PreferenceScreen;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.AutoZoomMap;
@ -44,7 +38,6 @@ import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.voice.CommandPlayer;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.router.GeneralRouter.RoutingParameterType;
import net.osmand.util.Algorithms;
@ -186,12 +179,12 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
selectAppModeDialog().show();
}
addWakeOnVoice((PreferenceGroup) screen.findPreference("turn_screen_on"));
addTurnScreenOn((PreferenceGroup) screen.findPreference("turn_screen_on"));
addVoicePrefs((PreferenceGroup) screen.findPreference("voice"));
}
private void addWakeOnVoice(PreferenceGroup screen) {
private void addTurnScreenOn(PreferenceGroup screen) {
Integer[] screenPowerSaveValues = new Integer[] { 0, 5, 10, 15, 20, 30, 45, 60 };
String[] screenPowerSaveNames = new String[screenPowerSaveValues.length];
screenPowerSaveNames[0] = getString(R.string.shared_string_never);
@ -199,8 +192,9 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
screenPowerSaveNames[i] = screenPowerSaveValues[i] + " "
+ getString(R.string.int_seconds);
}
registerListPreference(settings.WAKE_ON_VOICE_TIME_INT, screen, screenPowerSaveNames, screenPowerSaveValues);
registerBooleanPreference(settings.WAKE_ON_VOICE_SENSOR, screen);
registerListPreference(settings.TURN_SCREEN_ON_TIME_INT, screen, screenPowerSaveNames, screenPowerSaveValues);
registerBooleanPreference(settings.TURN_SCREEN_ON_ROUTER, screen);
registerBooleanPreference(settings.TURN_SCREEN_ON_SENSOR, screen);
}
private void reloadVoiceListPreference(PreferenceScreen screen) {
@ -402,6 +396,13 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
return true;
}
super.onPreferenceChange(preference, newValue);
if (id.equals(settings.TURN_SCREEN_ON_ROUTER.getId())) {
boolean isRoutingListnerEnabled = Boolean.valueOf(newValue.toString());
getMyApplication().getLockHelper().setVoiceRouterListener(isRoutingListnerEnabled);
} else if (id.equals(settings.TURN_SCREEN_ON_SENSOR.getId())) {
boolean isSensorEnabled = Boolean.valueOf(newValue.toString());
getMyApplication().getLockHelper().setSensor(isSensorEnabled);
}
return true;
}

View file

@ -204,7 +204,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
}
registerUnregisterSensor(location, smallSpeedForDirectionOfMovement);
if (settings.ANIMATE_MY_LOCATION.get() && !smallSpeedForAnimation && !movingToMyLocation &&
settings.WAKE_ON_VOICE_TIME_INT.get() == 0) {
settings.TURN_SCREEN_ON_TIME_INT.get() == 0) {
mapView.getAnimatedDraggingThread().startMoving(
location.getLatitude(), location.getLongitude(), zoom, rotation, false);
} else {

View file

@ -11,6 +11,7 @@ import android.os.PowerManager;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.routing.VoiceRouter;
public class LockHelper implements SensorEventListener {
@ -25,6 +26,7 @@ public class LockHelper implements SensorEventListener {
private OsmandApplication app;
private LockRunnable lockRunnable;
private LockUIAdapter lockUIAdapter;
private OsmandSettings settings;
private VoiceRouter.VoiceMessageListener voiceMessageListener;
@ -46,6 +48,7 @@ public class LockHelper implements SensorEventListener {
this.app = app;
uiHandler = new Handler();
lockRunnable = new LockRunnable();
settings = app.getSettings();
mSensorManager = (SensorManager) app.getSystemService(Context.SENSOR_SERVICE);
mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
@ -56,9 +59,8 @@ public class LockHelper implements SensorEventListener {
unlockEvent();
}
};
setVoiceRouterListener(true);
setSensor(true);
refreshGlobalSettings();
}
private void releaseWakeLocks() {
@ -99,7 +101,7 @@ public class LockHelper implements SensorEventListener {
boolean isScreenOn = AndroidUtils.isScreenOn(app);
boolean isScreenLocked = AndroidUtils.isScreenLocked(app);
Integer screenPowerSave = app.getSettings().WAKE_ON_VOICE_TIME_INT.get();
Integer screenPowerSave = app.getSettings().TURN_SCREEN_ON_TIME_INT.get();
if ((isScreenOn || isScreenLocked) && screenPowerSave > 0) {
timedUnlock(screenPowerSave * 1000L);
@ -113,11 +115,9 @@ public class LockHelper implements SensorEventListener {
@Override
public void onSensorChanged(SensorEvent event) {
if (isSensorEnabled()) {
if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
if (event.values[0] >= -SENSOR_SENSITIVITY && event.values[0] <= SENSOR_SENSITIVITY) {
unlockEvent();
}
if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
if (event.values[0] >= -SENSOR_SENSITIVITY && event.values[0] <= SENSOR_SENSITIVITY) {
unlockEvent();
}
}
}
@ -139,8 +139,14 @@ public class LockHelper implements SensorEventListener {
}
}
private boolean isSensorEnabled() {
return app.getSettings().WAKE_ON_VOICE_SENSOR.get();
public void refreshProfilesSettings() {
boolean isVRListenerEnabled = settings.TURN_SCREEN_ON_ROUTER.get();
setVoiceRouterListener(isVRListenerEnabled);
}
public void refreshGlobalSettings() {
boolean isSensorEnabled = settings.TURN_SCREEN_ON_SENSOR.get();
setSensor(isSensorEnabled);
}
public void setLockUIAdapter(LockUIAdapter adapter) {