Remove unnecessary changes

This commit is contained in:
Vitaliy 2020-01-20 17:45:34 +02:00
parent cb426eae75
commit 1f9a94cea4
8 changed files with 114 additions and 89 deletions

View file

@ -8,13 +8,14 @@ import android.support.annotation.NonNull;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.access.AccessibilityMode;
import net.osmand.plus.access.RelativeDirectionStyle;
import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class AccessibilityPlugin extends OsmandPlugin { public class AccessibilityPlugin extends OsmandPlugin {
@ -28,27 +29,19 @@ public class AccessibilityPlugin extends OsmandPlugin {
private SoundPool sounds; private SoundPool sounds;
private Map<Integer, Integer> soundIcons = new HashMap<Integer, Integer>(); private Map<Integer, Integer> soundIcons = new HashMap<Integer, Integer>();
public final OsmandSettings.OsmandPreference<AccessibilityMode> ACCESSIBILITY_MODE; private List<OsmandPreference> pluginPreferences = new ArrayList<>();
public final OsmandSettings.OsmandPreference<Float> SPEECH_RATE;
public final OsmandSettings.OsmandPreference<Boolean> ACCESSIBILITY_SMART_AUTOANNOUNCE;
public final OsmandSettings.OsmandPreference<Integer> ACCESSIBILITY_AUTOANNOUNCE_PERIOD;
public final OsmandSettings.OsmandPreference<Boolean> DISABLE_OFFROUTE_RECALC;
public final OsmandSettings.OsmandPreference<Boolean> DISABLE_WRONG_DIRECTION_RECALC;
public final OsmandSettings.OsmandPreference<RelativeDirectionStyle> DIRECTION_STYLE;
public final OsmandSettings.OsmandPreference<Boolean> DIRECTION_AUDIO_FEEDBACK;
public final OsmandSettings.OsmandPreference<Boolean> DIRECTION_HAPTIC_FEEDBACK;
public AccessibilityPlugin(OsmandApplication app) { public AccessibilityPlugin(OsmandApplication app) {
this.app = app; this.app = app;
ACCESSIBILITY_MODE = registerEnumIntPreference(app, "accessibility_mode", AccessibilityMode.DEFAULT, AccessibilityMode.values(), AccessibilityMode.class).makeProfile().cache(); pluginPreferences.add(app.getSettings().ACCESSIBILITY_MODE);
SPEECH_RATE = registerFloatPreference(app, "speech_rate", 1f).makeProfile(); pluginPreferences.add(app.getSettings().SPEECH_RATE);
ACCESSIBILITY_SMART_AUTOANNOUNCE = registerBooleanAccessibilityPreference(app, "accessibility_smart_autoannounce", true).makeProfile(); pluginPreferences.add(app.getSettings().ACCESSIBILITY_SMART_AUTOANNOUNCE);
ACCESSIBILITY_AUTOANNOUNCE_PERIOD = registerIntPreference(app, "accessibility_autoannounce_period", 10000).makeProfile().cache(); pluginPreferences.add(app.getSettings().ACCESSIBILITY_AUTOANNOUNCE_PERIOD);
DISABLE_OFFROUTE_RECALC = registerBooleanAccessibilityPreference(app, "disable_offroute_recalc", false).makeProfile(); pluginPreferences.add(app.getSettings().DISABLE_OFFROUTE_RECALC);
DISABLE_WRONG_DIRECTION_RECALC = registerBooleanAccessibilityPreference(app, "disable_wrong_direction_recalc", false).makeProfile(); pluginPreferences.add(app.getSettings().DISABLE_WRONG_DIRECTION_RECALC);
DIRECTION_STYLE = registerEnumIntPreference(app, "direction_style", RelativeDirectionStyle.SIDEWISE, RelativeDirectionStyle.values(), RelativeDirectionStyle.class).makeProfile().cache(); pluginPreferences.add(app.getSettings().DIRECTION_STYLE);
DIRECTION_AUDIO_FEEDBACK = registerBooleanAccessibilityPreference(app, "direction_audio_feedback", false).makeProfile(); pluginPreferences.add(app.getSettings().DIRECTION_AUDIO_FEEDBACK);
DIRECTION_HAPTIC_FEEDBACK = registerBooleanAccessibilityPreference(app, "direction_haptic_feedback", false).makeProfile(); pluginPreferences.add(app.getSettings().DIRECTION_HAPTIC_FEEDBACK);
} }
@Override @Override
@ -87,6 +80,11 @@ public class AccessibilityPlugin extends OsmandPlugin {
return AccessibilitySettingsFragment.class; return AccessibilitySettingsFragment.class;
} }
@Override
public List<OsmandPreference> getPreferences() {
return pluginPreferences;
}
@Override @Override
public String getPrefsDescription() { public String getPrefsDescription() {
return app.getString(R.string.accessibility_prefs_descr); return app.getString(R.string.accessibility_prefs_descr);

View file

@ -24,29 +24,25 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen
private static final String COPY_PLUGIN_SETTINGS = "copy_plugin_settings"; private static final String COPY_PLUGIN_SETTINGS = "copy_plugin_settings";
private static final String RESET_TO_DEFAULT = "reset_to_default"; private static final String RESET_TO_DEFAULT = "reset_to_default";
private AccessibilityPlugin plugin = OsmandPlugin.getPlugin(AccessibilityPlugin.class);
@Override @Override
protected void setupPreferences() { protected void setupPreferences() {
if (plugin != null) { setupAccessibilityModePref();
setupAccessibilityModePref(); setupSpeechRatePref();
setupSpeechRatePref();
setupSmartAutoAnnouncePref(); setupSmartAutoAnnouncePref();
setupAutoAnnouncePeriodPref(); setupAutoAnnouncePeriodPref();
setupDisableOffRouteRecalculationPref(); setupDisableOffRouteRecalculationPref();
setupDisableWrongDirectionRecalculationPref(); setupDisableWrongDirectionRecalculationPref();
setupDirectionStylePref(); setupDirectionStylePref();
setupDirectionAudioFeedbackPref(); setupDirectionAudioFeedbackPref();
setupDirectionHapticFeedbackPref(); setupDirectionHapticFeedbackPref();
setupCopyProfileSettingsPref(); setupCopyProfileSettingsPref();
setupResetToDefaultPref(); setupResetToDefaultPref();
updateAccessibilityOptions(); updateAccessibilityOptions();
}
} }
private void setupAccessibilityModePref() { private void setupAccessibilityModePref() {
@ -59,7 +55,7 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen
entryValues[i] = accessibilityModes[i].ordinal(); entryValues[i] = accessibilityModes[i].ordinal();
} }
ListPreferenceEx accessibilityMode = (ListPreferenceEx) findPreference(plugin.ACCESSIBILITY_MODE.getId()); ListPreferenceEx accessibilityMode = (ListPreferenceEx) findPreference(settings.ACCESSIBILITY_MODE.getId());
accessibilityMode.setEntries(entries); accessibilityMode.setEntries(entries);
accessibilityMode.setEntryValues(entryValues); accessibilityMode.setEntryValues(entryValues);
accessibilityMode.setDescription(R.string.accessibility_mode_descr); accessibilityMode.setDescription(R.string.accessibility_mode_descr);
@ -73,7 +69,7 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen
entries[i] = (int) (entryValues[i] * 100) + " %"; entries[i] = (int) (entryValues[i] * 100) + " %";
} }
ListPreferenceEx speechRate = (ListPreferenceEx) findPreference(plugin.SPEECH_RATE.getId()); ListPreferenceEx speechRate = (ListPreferenceEx) findPreference(settings.SPEECH_RATE.getId());
speechRate.setEntries(entries); speechRate.setEntries(entries);
speechRate.setEntryValues(entryValues); speechRate.setEntryValues(entryValues);
speechRate.setIcon(getContentIcon(R.drawable.ic_world_globe_dark)); speechRate.setIcon(getContentIcon(R.drawable.ic_world_globe_dark));
@ -81,7 +77,7 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen
} }
private void setupSmartAutoAnnouncePref() { private void setupSmartAutoAnnouncePref() {
SwitchPreferenceEx smartAutoAnnounce = (SwitchPreferenceEx) findPreference(plugin.ACCESSIBILITY_SMART_AUTOANNOUNCE.getId()); SwitchPreferenceEx smartAutoAnnounce = (SwitchPreferenceEx) findPreference(settings.ACCESSIBILITY_SMART_AUTOANNOUNCE.getId());
smartAutoAnnounce.setDescription(getString(R.string.access_smart_autoannounce_descr)); smartAutoAnnounce.setDescription(getString(R.string.access_smart_autoannounce_descr));
} }
@ -103,19 +99,19 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen
k++; k++;
} }
ListPreferenceEx autoAnnouncePeriod = (ListPreferenceEx) findPreference(plugin.ACCESSIBILITY_AUTOANNOUNCE_PERIOD.getId()); ListPreferenceEx autoAnnouncePeriod = (ListPreferenceEx) findPreference(settings.ACCESSIBILITY_AUTOANNOUNCE_PERIOD.getId());
autoAnnouncePeriod.setEntries(entries); autoAnnouncePeriod.setEntries(entries);
autoAnnouncePeriod.setEntryValues(entryValues); autoAnnouncePeriod.setEntryValues(entryValues);
autoAnnouncePeriod.setDescription(R.string.access_autoannounce_period_descr); autoAnnouncePeriod.setDescription(R.string.access_autoannounce_period_descr);
} }
private void setupDisableOffRouteRecalculationPref() { private void setupDisableOffRouteRecalculationPref() {
SwitchPreferenceEx disableOffRouteRecalculation = (SwitchPreferenceEx) findPreference(plugin.DISABLE_OFFROUTE_RECALC.getId()); SwitchPreferenceEx disableOffRouteRecalculation = (SwitchPreferenceEx) findPreference(settings.DISABLE_OFFROUTE_RECALC.getId());
disableOffRouteRecalculation.setDescription(getString(R.string.access_disable_offroute_recalc_descr)); disableOffRouteRecalculation.setDescription(getString(R.string.access_disable_offroute_recalc_descr));
} }
private void setupDisableWrongDirectionRecalculationPref() { private void setupDisableWrongDirectionRecalculationPref() {
SwitchPreferenceEx disableWrongDirectionRecalculation = (SwitchPreferenceEx) findPreference(plugin.DISABLE_WRONG_DIRECTION_RECALC.getId()); SwitchPreferenceEx disableWrongDirectionRecalculation = (SwitchPreferenceEx) findPreference(settings.DISABLE_WRONG_DIRECTION_RECALC.getId());
disableWrongDirectionRecalculation.setDescription(getString(R.string.access_disable_wrong_direction_recalc_descr)); disableWrongDirectionRecalculation.setDescription(getString(R.string.access_disable_wrong_direction_recalc_descr));
} }
@ -129,19 +125,19 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen
entryValues[i] = relativeDirectionStyles[i].ordinal(); entryValues[i] = relativeDirectionStyles[i].ordinal();
} }
ListPreferenceEx directionStyle = (ListPreferenceEx) findPreference(plugin.DIRECTION_STYLE.getId()); ListPreferenceEx directionStyle = (ListPreferenceEx) findPreference(settings.DIRECTION_STYLE.getId());
directionStyle.setEntries(entries); directionStyle.setEntries(entries);
directionStyle.setEntryValues(entryValues); directionStyle.setEntryValues(entryValues);
directionStyle.setDescription(R.string.settings_direction_style_descr); directionStyle.setDescription(R.string.settings_direction_style_descr);
} }
private void setupDirectionAudioFeedbackPref() { private void setupDirectionAudioFeedbackPref() {
SwitchPreferenceEx directionAudioFeedback = (SwitchPreferenceEx) findPreference(plugin.DIRECTION_AUDIO_FEEDBACK.getId()); SwitchPreferenceEx directionAudioFeedback = (SwitchPreferenceEx) findPreference(settings.DIRECTION_AUDIO_FEEDBACK.getId());
directionAudioFeedback.setDescription(getString(R.string.access_direction_audio_feedback_descr)); directionAudioFeedback.setDescription(getString(R.string.access_direction_audio_feedback_descr));
} }
private void setupDirectionHapticFeedbackPref() { private void setupDirectionHapticFeedbackPref() {
SwitchPreferenceEx directionHapticFeedback = (SwitchPreferenceEx) findPreference(plugin.DIRECTION_HAPTIC_FEEDBACK.getId()); SwitchPreferenceEx directionHapticFeedback = (SwitchPreferenceEx) findPreference(settings.DIRECTION_HAPTIC_FEEDBACK.getId());
directionHapticFeedback.setDescription(getString(R.string.access_direction_haptic_feedback_descr)); directionHapticFeedback.setDescription(getString(R.string.access_direction_haptic_feedback_descr));
} }
@ -157,7 +153,7 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen
@Override @Override
public void onPreferenceChanged(String prefId) { public void onPreferenceChanged(String prefId) {
if (plugin.ACCESSIBILITY_MODE.getId().equals(prefId)) { if (settings.ACCESSIBILITY_MODE.getId().equals(prefId)) {
updateAccessibilityOptions(); updateAccessibilityOptions();
} }
} }
@ -198,11 +194,12 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen
private void updateAccessibilityOptions() { private void updateAccessibilityOptions() {
boolean accessibilityEnabled = app.accessibilityEnabledForMode(getSelectedAppMode()); boolean accessibilityEnabled = app.accessibilityEnabledForMode(getSelectedAppMode());
PreferenceScreen screen = getPreferenceScreen(); PreferenceScreen screen = getPreferenceScreen();
if (screen != null) { OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class);
if (screen != null && plugin != null) {
for (int i = 0; i < screen.getPreferenceCount(); i++) { for (int i = 0; i < screen.getPreferenceCount(); i++) {
Preference preference = screen.getPreference(i); Preference preference = screen.getPreference(i);
String prefId = preference.getKey(); String prefId = preference.getKey();
if (!plugin.ACCESSIBILITY_MODE.getId().equals(prefId) && !plugin.SPEECH_RATE.getId().equals(prefId)) if (!settings.ACCESSIBILITY_MODE.getId().equals(prefId) && !settings.SPEECH_RATE.getId().equals(prefId))
preference.setEnabled(accessibilityEnabled); preference.setEnabled(accessibilityEnabled);
} }
} }

View file

@ -46,20 +46,20 @@ public class NavigationInfo implements OsmAndCompassListener, OsmAndLocationList
private int value; private int value;
public RelativeDirection() { public RelativeDirection() {
style = plugin.DIRECTION_STYLE.get(); style = settings.DIRECTION_STYLE.get();
clear(); clear();
} }
// The argument must be not null as well as the currentLocation // The argument must be not null as well as the currentLocation
// and currentLocation must have bearing. // and currentLocation must have bearing.
public RelativeDirection(final Location point) { public RelativeDirection(final Location point) {
style = plugin.DIRECTION_STYLE.get(); style = settings.DIRECTION_STYLE.get();
value = directionTo(point, currentLocation.getBearing()); value = directionTo(point, currentLocation.getBearing());
} }
// The first argument must be not null as well as the currentLocation. // The first argument must be not null as well as the currentLocation.
public RelativeDirection(final Location point, float heading) { public RelativeDirection(final Location point, float heading) {
style = plugin.DIRECTION_STYLE.get(); style = settings.DIRECTION_STYLE.get();
value = directionTo(point, heading); value = directionTo(point, heading);
} }
@ -70,7 +70,7 @@ public class NavigationInfo implements OsmAndCompassListener, OsmAndLocationList
// The first argument must be not null as well as the currentLocation. // The first argument must be not null as well as the currentLocation.
public boolean update(final Location point, float heading) { public boolean update(final Location point, float heading) {
boolean result = false; boolean result = false;
final RelativeDirectionStyle newStyle = plugin.DIRECTION_STYLE.get(); final RelativeDirectionStyle newStyle = settings.DIRECTION_STYLE.get();
if (style != newStyle) { if (style != newStyle) {
style = newStyle; style = newStyle;
result = true; result = true;
@ -151,7 +151,7 @@ public class NavigationInfo implements OsmAndCompassListener, OsmAndLocationList
private final long HAPTIC_INCLINATION_RIGHT[] = { 0, 20, 80, 20 }; private final long HAPTIC_INCLINATION_RIGHT[] = { 0, 20, 80, 20 };
private final OsmandApplication app; private final OsmandApplication app;
private final AccessibilityPlugin plugin; private final OsmandSettings settings;
private Location currentLocation; private Location currentLocation;
private RelativeDirection lastDirection; private RelativeDirection lastDirection;
private long lastNotificationTime; private long lastNotificationTime;
@ -160,7 +160,7 @@ public class NavigationInfo implements OsmAndCompassListener, OsmAndLocationList
public NavigationInfo(OsmandApplication app) { public NavigationInfo(OsmandApplication app) {
this.app = app; this.app = app;
plugin = OsmandPlugin.getPlugin(AccessibilityPlugin.class); settings = app.getSettings();
currentLocation = null; currentLocation = null;
lastDirection = new RelativeDirection(); lastDirection = new RelativeDirection();
lastNotificationTime = SystemClock.uptimeMillis(); lastNotificationTime = SystemClock.uptimeMillis();
@ -253,11 +253,11 @@ public class NavigationInfo implements OsmAndCompassListener, OsmAndLocationList
if (point != null) { if (point != null) {
if ((currentLocation != null) && currentLocation.hasBearing() && !MapViewTrackingUtilities.isSmallSpeedForCompass(currentLocation)) { if ((currentLocation != null) && currentLocation.hasBearing() && !MapViewTrackingUtilities.isSmallSpeedForCompass(currentLocation)) {
final long now = SystemClock.uptimeMillis(); final long now = SystemClock.uptimeMillis();
if ((now - lastNotificationTime) >= plugin.ACCESSIBILITY_AUTOANNOUNCE_PERIOD.get()) { if ((now - lastNotificationTime) >= settings.ACCESSIBILITY_AUTOANNOUNCE_PERIOD.get()) {
Location destination = new Location("map"); //$NON-NLS-1$ Location destination = new Location("map"); //$NON-NLS-1$
destination.setLatitude(point.getLatitude()); destination.setLatitude(point.getLatitude());
destination.setLongitude(point.getLongitude()); destination.setLongitude(point.getLongitude());
if (lastDirection.update(destination) || !plugin.ACCESSIBILITY_SMART_AUTOANNOUNCE.get()) { if (lastDirection.update(destination) || !settings.ACCESSIBILITY_SMART_AUTOANNOUNCE.get()) {
final String notification = distanceString(destination) + " " + lastDirection.getString(); //$NON-NLS-1$ final String notification = distanceString(destination) + " " + lastDirection.getString(); //$NON-NLS-1$
lastNotificationTime = now; lastNotificationTime = now;
app.runInUIThread(new Runnable() { app.runInUIThread(new Runnable() {
@ -281,7 +281,7 @@ public class NavigationInfo implements OsmAndCompassListener, OsmAndLocationList
Integer inclination = direction.getInclination(); Integer inclination = direction.getInclination();
if (targetDirectionFlag && ((inclination == null) || (inclination != 0))) { if (targetDirectionFlag && ((inclination == null) || (inclination != 0))) {
targetDirectionFlag = false; targetDirectionFlag = false;
if (plugin.DIRECTION_AUDIO_FEEDBACK.get()) { if (settings.DIRECTION_AUDIO_FEEDBACK.get()) {
AccessibilityPlugin accessibilityPlugin = OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class); AccessibilityPlugin accessibilityPlugin = OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class);
if (accessibilityPlugin != null) { if (accessibilityPlugin != null) {
if (inclination == null) { if (inclination == null) {
@ -293,7 +293,7 @@ public class NavigationInfo implements OsmAndCompassListener, OsmAndLocationList
} }
} }
} }
if (plugin.DIRECTION_HAPTIC_FEEDBACK.get()) { if (settings.DIRECTION_HAPTIC_FEEDBACK.get()) {
Vibrator haptic = (Vibrator)app.getSystemService(Context.VIBRATOR_SERVICE); Vibrator haptic = (Vibrator)app.getSystemService(Context.VIBRATOR_SERVICE);
if ((haptic != null) && haptic.hasVibrator()) { if ((haptic != null) && haptic.hasVibrator()) {
if (inclination == null) { if (inclination == null) {

View file

@ -10,7 +10,6 @@ import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.access.AccessibilityMode; import net.osmand.plus.access.AccessibilityMode;
import net.osmand.plus.access.RelativeDirectionStyle; import net.osmand.plus.access.RelativeDirectionStyle;
@ -18,8 +17,6 @@ import net.osmand.plus.activities.SettingsBaseActivity;
public class SettingsAccessibilityActivity extends SettingsBaseActivity { public class SettingsAccessibilityActivity extends SettingsBaseActivity {
private AccessibilityPlugin plugin;
private ListPreference accessibilityModePreference; private ListPreference accessibilityModePreference;
private ListPreference directionStylePreference; private ListPreference directionStylePreference;
private ListPreference autoannouncePeriodPreference; private ListPreference autoannouncePeriodPreference;
@ -32,13 +29,11 @@ public class SettingsAccessibilityActivity extends SettingsBaseActivity {
getToolbar().setTitle(R.string.shared_string_accessibility); getToolbar().setTitle(R.string.shared_string_accessibility);
PreferenceScreen grp = getPreferenceScreen(); PreferenceScreen grp = getPreferenceScreen();
plugin = OsmandPlugin.getPlugin(AccessibilityPlugin.class);
String[] entries = new String[AccessibilityMode.values().length]; String[] entries = new String[AccessibilityMode.values().length];
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
entries[i] = AccessibilityMode.values()[i].toHumanString(getMyApplication()); entries[i] = AccessibilityMode.values()[i].toHumanString(getMyApplication());
} }
accessibilityModePreference = createListPreference(plugin.ACCESSIBILITY_MODE, entries, AccessibilityMode.values(), accessibilityModePreference = createListPreference(settings.ACCESSIBILITY_MODE, entries, AccessibilityMode.values(),
R.string.accessibility_mode, R.string.accessibility_mode_descr); R.string.accessibility_mode, R.string.accessibility_mode_descr);
accessibilityModePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { accessibilityModePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
private final OnPreferenceChangeListener committer = accessibilityModePreference.getOnPreferenceChangeListener(); private final OnPreferenceChangeListener committer = accessibilityModePreference.getOnPreferenceChangeListener();
@ -63,7 +58,7 @@ public class SettingsAccessibilityActivity extends SettingsBaseActivity {
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
entries[i] = RelativeDirectionStyle.values()[i].toHumanString(getMyApplication()); entries[i] = RelativeDirectionStyle.values()[i].toHumanString(getMyApplication());
} }
directionStylePreference = createListPreference(plugin.DIRECTION_STYLE, entries, RelativeDirectionStyle.values(), directionStylePreference = createListPreference(settings.DIRECTION_STYLE, entries, RelativeDirectionStyle.values(),
R.string.settings_direction_style, R.string.settings_direction_style_descr); R.string.settings_direction_style, R.string.settings_direction_style_descr);
directionStylePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { directionStylePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
private final OnPreferenceChangeListener committer = directionStylePreference.getOnPreferenceChangeListener(); private final OnPreferenceChangeListener committer = directionStylePreference.getOnPreferenceChangeListener();
@ -77,12 +72,12 @@ public class SettingsAccessibilityActivity extends SettingsBaseActivity {
}); });
cat.addPreference(directionStylePreference); cat.addPreference(directionStylePreference);
cat.addPreference(createCheckBoxPreference(plugin.ACCESSIBILITY_SMART_AUTOANNOUNCE, R.string.access_smart_autoannounce, cat.addPreference(createCheckBoxPreference(settings.ACCESSIBILITY_SMART_AUTOANNOUNCE, R.string.access_smart_autoannounce,
R.string.access_smart_autoannounce_descr)); R.string.access_smart_autoannounce_descr));
final int[] seconds = new int[] {5, 10, 15, 20, 30, 45, 60, 90}; final int[] seconds = new int[] {5, 10, 15, 20, 30, 45, 60, 90};
final int[] minutes = new int[] {2, 3, 5}; final int[] minutes = new int[] {2, 3, 5};
autoannouncePeriodPreference = createTimeListPreference(plugin.ACCESSIBILITY_AUTOANNOUNCE_PERIOD, seconds, minutes, 1000, autoannouncePeriodPreference = createTimeListPreference(settings.ACCESSIBILITY_AUTOANNOUNCE_PERIOD, seconds, minutes, 1000,
R.string.access_autoannounce_period, R.string.access_autoannounce_period_descr); R.string.access_autoannounce_period, R.string.access_autoannounce_period_descr);
autoannouncePeriodPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { autoannouncePeriodPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
private final OnPreferenceChangeListener committer = autoannouncePeriodPreference.getOnPreferenceChangeListener(); private final OnPreferenceChangeListener committer = autoannouncePeriodPreference.getOnPreferenceChangeListener();
@ -96,14 +91,14 @@ public class SettingsAccessibilityActivity extends SettingsBaseActivity {
}); });
cat.addPreference(autoannouncePeriodPreference); cat.addPreference(autoannouncePeriodPreference);
cat.addPreference(createCheckBoxPreference(plugin.DISABLE_OFFROUTE_RECALC, R.string.access_disable_offroute_recalc, cat.addPreference(createCheckBoxPreference(settings.DISABLE_OFFROUTE_RECALC, R.string.access_disable_offroute_recalc,
R.string.access_disable_offroute_recalc_descr)); R.string.access_disable_offroute_recalc_descr));
cat.addPreference(createCheckBoxPreference(plugin.DISABLE_WRONG_DIRECTION_RECALC, R.string.access_disable_wrong_direction_recalc, cat.addPreference(createCheckBoxPreference(settings.DISABLE_WRONG_DIRECTION_RECALC, R.string.access_disable_wrong_direction_recalc,
R.string.access_disable_wrong_direction_recalc_descr)); R.string.access_disable_wrong_direction_recalc_descr));
cat.addPreference(createCheckBoxPreference(plugin.DIRECTION_AUDIO_FEEDBACK, R.string.access_direction_audio_feedback, cat.addPreference(createCheckBoxPreference(settings.DIRECTION_AUDIO_FEEDBACK, R.string.access_direction_audio_feedback,
R.string.access_direction_audio_feedback_descr)); R.string.access_direction_audio_feedback_descr));
cat.addPreference(createCheckBoxPreference(plugin.DIRECTION_HAPTIC_FEEDBACK, R.string.access_direction_haptic_feedback, cat.addPreference(createCheckBoxPreference(settings.DIRECTION_HAPTIC_FEEDBACK, R.string.access_direction_haptic_feedback,
R.string.access_direction_haptic_feedback_descr)); R.string.access_direction_haptic_feedback_descr));
} }
@ -115,7 +110,7 @@ public class SettingsAccessibilityActivity extends SettingsBaseActivity {
for(int i = 0; i < sprNames.length; i++) { for(int i = 0; i < sprNames.length; i++) {
sprNames[i] = (int)(sprValues[i] * 100) + " %"; sprNames[i] = (int)(sprValues[i] * 100) + " %";
} }
grp.addPreference(createListPreference(plugin.SPEECH_RATE, sprNames, sprValues, R.string.speech_rate, R.string.speech_rate_descr)); grp.addPreference(createListPreference(settings.SPEECH_RATE, sprNames, sprValues, R.string.speech_rate, R.string.speech_rate_descr));
} }
@ -126,13 +121,14 @@ public class SettingsAccessibilityActivity extends SettingsBaseActivity {
if (accessibilityOptions != null) if (accessibilityOptions != null)
accessibilityOptions.setEnabled(getMyApplication().accessibilityEnabled()); accessibilityOptions.setEnabled(getMyApplication().accessibilityEnabled());
if(accessibilityModePreference != null) { if(accessibilityModePreference != null) {
accessibilityModePreference.setSummary(getString(R.string.accessibility_mode_descr) + " [" + plugin.ACCESSIBILITY_MODE.get().toHumanString(getMyApplication()) + "]"); accessibilityModePreference.setSummary(getString(R.string.accessibility_mode_descr) + " [" + settings.ACCESSIBILITY_MODE.get().toHumanString(getMyApplication()) + "]");
} }
if(directionStylePreference != null) { if(directionStylePreference != null) {
directionStylePreference.setSummary(getString(R.string.settings_direction_style_descr) + " [" + plugin.DIRECTION_STYLE.get().toHumanString(getMyApplication()) + "]"); directionStylePreference.setSummary(getString(R.string.settings_direction_style_descr) + " [" + settings.DIRECTION_STYLE.get().toHumanString(getMyApplication()) + "]");
} }
if(autoannouncePeriodPreference != null) { if(autoannouncePeriodPreference != null) {
autoannouncePeriodPreference.setSummary(getString(R.string.access_autoannounce_period_descr) + " [" + autoannouncePeriodPreference.getEntry() + "]"); autoannouncePeriodPreference.setSummary(getString(R.string.access_autoannounce_period_descr) + " [" + autoannouncePeriodPreference.getEntry() + "]");
} }
} }
} }

View file

@ -877,11 +877,10 @@ public class OsmandApplication extends MultiDexApplication {
} }
public boolean accessibilityEnabledForMode(ApplicationMode appMode) { public boolean accessibilityEnabledForMode(ApplicationMode appMode) {
AccessibilityPlugin accessibilityPlugin = OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class); final AccessibilityMode mode = getSettings().ACCESSIBILITY_MODE.getModeValue(appMode);
if (accessibilityPlugin == null) { if (OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) == null) {
return false; return false;
} }
AccessibilityMode mode = accessibilityPlugin.ACCESSIBILITY_MODE.getModeValue(appMode);
if (mode == AccessibilityMode.ON) { if (mode == AccessibilityMode.ON) {
return true; return true;
} else if (mode == AccessibilityMode.OFF) { } else if (mode == AccessibilityMode.OFF) {

View file

@ -30,6 +30,8 @@ import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager;
import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.osm.io.NetworkUtils; import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.access.AccessibilityMode;
import net.osmand.plus.access.RelativeDirectionStyle;
import net.osmand.plus.api.SettingsAPI; import net.osmand.plus.api.SettingsAPI;
import net.osmand.plus.api.SettingsAPI.SettingsEditor; import net.osmand.plus.api.SettingsAPI.SettingsEditor;
import net.osmand.plus.api.SettingsAPIImpl; import net.osmand.plus.api.SettingsAPIImpl;
@ -1407,6 +1409,21 @@ public class OsmandSettings {
}.makeProfile(); }.makeProfile();
// this value string is synchronized with settings_pref.xml preference name
// cache of metrics constants as they are used very often
public final OsmandPreference<RelativeDirectionStyle> DIRECTION_STYLE = new EnumIntPreference<RelativeDirectionStyle>(
"direction_style", RelativeDirectionStyle.SIDEWISE, RelativeDirectionStyle.values()).makeProfile().cache();
// this value string is synchronized with settings_pref.xml preference name
// cache of metrics constants as they are used very often
public final OsmandPreference<AccessibilityMode> ACCESSIBILITY_MODE = new EnumIntPreference<AccessibilityMode>(
"accessibility_mode", AccessibilityMode.DEFAULT, AccessibilityMode.values()).makeProfile().cache();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Float> SPEECH_RATE =
new FloatPreference("speech_rate", 1f).makeProfile();
public final OsmandPreference<Float> ARRIVAL_DISTANCE_FACTOR = public final OsmandPreference<Float> ARRIVAL_DISTANCE_FACTOR =
new FloatPreference("arrival_distance_factor", 1f).makeProfile(); new FloatPreference("arrival_distance_factor", 1f).makeProfile();
@ -1429,6 +1446,30 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> USE_TRACKBALL_FOR_MOVEMENTS = public final OsmandPreference<Boolean> USE_TRACKBALL_FOR_MOVEMENTS =
new BooleanPreference("use_trackball_for_movements", true).makeProfile(); new BooleanPreference("use_trackball_for_movements", true).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> ACCESSIBILITY_SMART_AUTOANNOUNCE =
new BooleanAccessibilityPreference("accessibility_smart_autoannounce", true).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
// cache of metrics constants as they are used very often
public final OsmandPreference<Integer> ACCESSIBILITY_AUTOANNOUNCE_PERIOD = new IntPreference("accessibility_autoannounce_period", 10000).makeProfile().cache();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> DISABLE_OFFROUTE_RECALC =
new BooleanAccessibilityPreference("disable_offroute_recalc", false).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> DISABLE_WRONG_DIRECTION_RECALC =
new BooleanAccessibilityPreference("disable_wrong_direction_recalc", false).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> DIRECTION_AUDIO_FEEDBACK =
new BooleanAccessibilityPreference("direction_audio_feedback", false).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> DIRECTION_HAPTIC_FEEDBACK =
new BooleanAccessibilityPreference("direction_haptic_feedback", false).makeProfile();
// magnetic field doesn'torkmost of the time on some phones // 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_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_KALMAN_FILTER_FOR_COMPASS = new BooleanPreference("use_kalman_filter_compass", true).makeProfile().cache();

View file

@ -1,13 +1,12 @@
package net.osmand.plus.routing; package net.osmand.plus.routing;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.ValueHolder; import net.osmand.ValueHolder;
import net.osmand.access.AccessibilityPlugin;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.plus.NavigationService; import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmAndAppCustomization.OsmAndAppCustomizationListener; import net.osmand.plus.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
@ -72,7 +71,6 @@ public class RoutingHelper {
private ApplicationMode mode; private ApplicationMode mode;
private OsmandSettings settings; private OsmandSettings settings;
private AccessibilityPlugin accessibilityPlugin;
private RouteProvider provider; private RouteProvider provider;
private VoiceRouter voiceRouter; private VoiceRouter voiceRouter;
@ -103,7 +101,6 @@ public class RoutingHelper {
transportRoutingHelper = context.getTransportRoutingHelper(); transportRoutingHelper = context.getTransportRoutingHelper();
transportRoutingHelper.setRoutingHelper(this); transportRoutingHelper.setRoutingHelper(this);
setAppMode(settings.APPLICATION_MODE.get()); setAppMode(settings.APPLICATION_MODE.get());
accessibilityPlugin = OsmandPlugin.getPlugin(AccessibilityPlugin.class);
OsmAndAppCustomizationListener customizationListener = new OsmAndAppCustomizationListener() { OsmAndAppCustomizationListener customizationListener = new OsmAndAppCustomizationListener() {
@Override @Override
@ -398,7 +395,7 @@ public class RoutingHelper {
// >100m off current route (sideways) // >100m off current route (sideways)
if (currentRoute > 0) { if (currentRoute > 0) {
distOrth = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute)); distOrth = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
if ((!accessibilityPlugin.DISABLE_OFFROUTE_RECALC.get()) && (distOrth > (1.7 * posTolerance))) { if ((!settings.DISABLE_OFFROUTE_RECALC.get()) && (distOrth > (1.7 * posTolerance))) {
log.info("Recalculate route, because correlation : " + distOrth); //$NON-NLS-1$ log.info("Recalculate route, because correlation : " + distOrth); //$NON-NLS-1$
isDeviatedFromRoute = true; isDeviatedFromRoute = true;
calculateRoute = true; calculateRoute = true;
@ -407,7 +404,7 @@ public class RoutingHelper {
// 3. Identify wrong movement direction // 3. Identify wrong movement direction
Location next = route.getNextRouteLocation(); Location next = route.getNextRouteLocation();
boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next); boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next);
if ((!accessibilityPlugin.DISABLE_WRONG_DIRECTION_RECALC.get()) && wrongMovementDirection && (currentLocation.distanceTo(routeNodes.get(currentRoute)) > (2 * posTolerance))) { if ((!settings.DISABLE_WRONG_DIRECTION_RECALC.get()) && wrongMovementDirection && (currentLocation.distanceTo(routeNodes.get(currentRoute)) > (2 * posTolerance))) {
log.info("Recalculate route, because wrong movement direction: " + currentLocation.distanceTo(routeNodes.get(currentRoute))); //$NON-NLS-1$ log.info("Recalculate route, because wrong movement direction: " + currentLocation.distanceTo(routeNodes.get(currentRoute))); //$NON-NLS-1$
isDeviatedFromRoute = true; isDeviatedFromRoute = true;
calculateRoute = true; calculateRoute = true;

View file

@ -14,10 +14,8 @@ import android.support.v7.app.AlertDialog;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityPlugin;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.routing.VoiceRouter; import net.osmand.plus.routing.VoiceRouter;
@ -85,9 +83,8 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
ctx.getString(R.string.voice_data_corrupted)); ctx.getString(R.string.voice_data_corrupted));
} }
OsmandApplication app = (OsmandApplication) ctx.getApplicationContext(); OsmandApplication app = (OsmandApplication) ctx.getApplicationContext();
AccessibilityPlugin accessibilityPlugin = OsmandPlugin.getPlugin(AccessibilityPlugin.class); if(app.accessibilityEnabled()) {
if (app.accessibilityEnabled() && accessibilityPlugin != null) { cSpeechRate = app.getSettings().SPEECH_RATE.get();
cSpeechRate = accessibilityPlugin.SPEECH_RATE.get();
} }
initializeEngine(app, ctx); initializeEngine(app, ctx);
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, app.getSettings().AUDIO_STREAM_GUIDANCE params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, app.getSettings().AUDIO_STREAM_GUIDANCE