Add accessibility preferences screen

This commit is contained in:
Vitaliy 2020-01-14 18:53:14 +02:00
parent 3e47c60c87
commit 3444eaeda8
16 changed files with 308 additions and 25 deletions

View file

@ -48,7 +48,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="?colorAccent"
android:textSize="@dimen/default_list_text_size"

View file

@ -41,7 +41,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"

View file

@ -38,7 +38,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"

View file

@ -48,7 +48,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"

View file

@ -38,7 +38,7 @@
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:maxLines="2"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />

View file

@ -53,7 +53,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"

View file

@ -11,6 +11,8 @@
Thx - Hardy
-->
<string name="route_recalculation">Route recalculation</string>
<string name="accessibility_announce">Announce</string>
<string name="login_and_pass">Username and password</string>
<string name="plugin_global_prefs_info">This plugin settings are global, and apply to all profiles.</string>
<string name="osm_editing">OpenStreetMap Editing</string>

View file

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:title="@string/shared_string_accessibility">
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:icon="@drawable/ic_action_android"
android:key="accessibility_mode"
android:layout="@layout/preference_with_descr"
android:title="@string/accessibility_mode"
tools:summary="@string/accessibility_default" />
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="speech_rate"
android:layout="@layout/preference_with_descr"
android:title="@string/speech_rate"
tools:icon="@drawable/ic_world_globe_dark"
tools:summary="50 %" />
<PreferenceCategory
android:key="announce"
android:layout="@layout/preference_category_with_descr"
android:title="@string/accessibility_announce" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="accessibility_smart_autoannounce"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/access_smart_autoannounce" />
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="accessibility_autoannounce_period"
android:layout="@layout/preference_with_descr"
android:title="@string/access_autoannounce_period"
tools:summary="10 seconds" />
<Preference
android:layout="@layout/simple_divider_item"
android:selectable="false" />
<PreferenceCategory
android:key="route_recalculation"
android:layout="@layout/preference_category_with_descr"
android:title="@string/route_recalculation" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="disable_offroute_recalc"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/access_disable_offroute_recalc" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="disable_wrong_direction_recalc"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/access_disable_wrong_direction_recalc" />
<Preference
android:layout="@layout/simple_divider_item"
android:selectable="false" />
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="direction_style"
android:layout="@layout/preference_with_descr"
android:title="@string/settings_direction_style"
tools:summary="@string/direction_style_sidewise" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="direction_audio_feedback"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/access_direction_audio_feedback" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="direction_haptic_feedback"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/access_direction_haptic_feedback" />
<Preference
android:layout="@layout/simple_divider_item"
android:selectable="false" />
<Preference
android:key="copy_plugin_settings"
android:layout="@layout/preference_button"
android:persistent="false"
android:title="@string/copy_from_other_profile"
tools:icon="@drawable/ic_action_copy" />
<Preference
android:key="reset_to_default"
android:layout="@layout/preference_button"
android:persistent="false"
android:title="@string/reset_to_default"
tools:icon="@drawable/ic_action_reset_to_default_dark" />
</PreferenceScreen>

View file

@ -24,8 +24,8 @@
android:icon="@drawable/ic_action_offline"
android:key="offline_osm_editing"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_off"
android:summaryOn="@string/shared_string_on"
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/offline_edition" />
<Preference

View file

@ -13,6 +13,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.settings.AccessibilitySettingsFragment;
import net.osmand.plus.settings.BaseSettingsFragment;
public class AccessibilityPlugin extends OsmandPlugin {
@ -68,7 +69,7 @@ public class AccessibilityPlugin extends OsmandPlugin {
@Override
public Class<? extends BaseSettingsFragment> getSettingsFragment() {
return null;
return AccessibilitySettingsFragment.class;
}
@Override

View file

@ -871,10 +871,14 @@ public class OsmandApplication extends MultiDexApplication {
public OsmandRegions getRegions() {
return regions;
}
public boolean accessibilityEnabled() {
final AccessibilityMode mode = getSettings().ACCESSIBILITY_MODE.get();
if(OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) == null) {
return accessibilityEnabledForMode(getSettings().APPLICATION_MODE.get());
}
public boolean accessibilityEnabledForMode(ApplicationMode appMode) {
final AccessibilityMode mode = getSettings().ACCESSIBILITY_MODE.getModeValue(appMode);
if (OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) == null) {
return false;
}
if (mode == AccessibilityMode.ON) {

View file

@ -1374,16 +1374,16 @@ public class OsmandSettings {
// 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()).makeGlobal().cache();
"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()).makeGlobal().cache();
"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).makeGlobal();
new FloatPreference("speech_rate", 1f).makeProfile();
public final OsmandPreference<Float> ARRIVAL_DISTANCE_FACTOR =
new FloatPreference("arrival_distance_factor", 1f).makeProfile();
@ -1409,27 +1409,27 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> ACCESSIBILITY_SMART_AUTOANNOUNCE =
new BooleanAccessibilityPreference("accessibility_smart_autoannounce", true).makeGlobal();
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).makeGlobal().cache();
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).makeGlobal();
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).makeGlobal();
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).makeGlobal();
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).makeGlobal();
new BooleanAccessibilityPreference("direction_haptic_feedback", false).makeProfile();
// 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();

View file

@ -0,0 +1,163 @@
package net.osmand.plus.settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import net.osmand.plus.R;
import net.osmand.plus.access.AccessibilityMode;
import net.osmand.plus.access.RelativeDirectionStyle;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
public class AccessibilitySettingsFragment extends BaseSettingsFragment implements OnPreferenceChanged {
private static final String COPY_PLUGIN_SETTINGS = "copy_plugin_settings";
private static final String RESET_TO_DEFAULT = "reset_to_default";
@Override
protected void setupPreferences() {
setupAccessibilityModePref();
setupSpeechRatePref();
setupSmartAutoAnnouncePref();
setupAutoAnnouncePeriodPref();
setupDisableOffRouteRecalculationPref();
setupDisableWrongDirectionRecalculationPref();
setupDirectionStylePref();
setupDirectionAudioFeedbackPref();
setupDirectionHapticFeedbackPref();
setupCopyProfileSettingsPref();
setupResetToDefaultPref();
updateAccessibilityOptions();
}
private void setupAccessibilityModePref() {
AccessibilityMode[] accessibilityModes = AccessibilityMode.values();
String[] entries = new String[accessibilityModes.length];
Integer[] entryValues = new Integer[accessibilityModes.length];
for (int i = 0; i < entries.length; i++) {
entries[i] = accessibilityModes[i].toHumanString(app);
entryValues[i] = accessibilityModes[i].ordinal();
}
ListPreferenceEx accessibilityMode = (ListPreferenceEx) findPreference(settings.ACCESSIBILITY_MODE.getId());
accessibilityMode.setEntries(entries);
accessibilityMode.setEntryValues(entryValues);
accessibilityMode.setDescription(R.string.accessibility_mode_descr);
}
private void setupSpeechRatePref() {
Float[] entryValues = new Float[] {0.5f, 0.75f, 1f, 1.25f, 1.5f, 2f};
String[] entries = new String[entryValues.length];
for (int i = 0; i < entries.length; i++) {
entries[i] = (int) (entryValues[i] * 100) + " %";
}
ListPreferenceEx speechRate = (ListPreferenceEx) findPreference(settings.SPEECH_RATE.getId());
speechRate.setEntries(entries);
speechRate.setEntryValues(entryValues);
speechRate.setIcon(getContentIcon(R.drawable.ic_world_globe_dark));
speechRate.setDescription(R.string.speech_rate_descr);
}
private void setupSmartAutoAnnouncePref() {
SwitchPreferenceEx smartAutoAnnounce = (SwitchPreferenceEx) findPreference(settings.ACCESSIBILITY_SMART_AUTOANNOUNCE.getId());
smartAutoAnnounce.setDescription(getString(R.string.access_smart_autoannounce_descr));
}
private void setupAutoAnnouncePeriodPref() {
int[] seconds = new int[] {5, 10, 15, 20, 30, 45, 60, 90};
int[] minutes = new int[] {2, 3, 5};
Integer[] entryValues = new Integer[seconds.length + minutes.length];
String[] entries = new String[entryValues.length];
int k = 0;
for (int second : seconds) {
entryValues[k] = second * 1000;
entries[k] = second + " " + getString(R.string.int_seconds);
k++;
}
for (int minute : minutes) {
entryValues[k] = (minute * 60) * 1000;
entries[k] = minute + " " + getString(R.string.int_min);
k++;
}
ListPreferenceEx autoAnnouncePeriod = (ListPreferenceEx) findPreference(settings.ACCESSIBILITY_AUTOANNOUNCE_PERIOD.getId());
autoAnnouncePeriod.setEntries(entries);
autoAnnouncePeriod.setEntryValues(entryValues);
autoAnnouncePeriod.setDescription(R.string.access_autoannounce_period_descr);
}
private void setupDisableOffRouteRecalculationPref() {
SwitchPreferenceEx disableOffRouteRecalculation = (SwitchPreferenceEx) findPreference(settings.DISABLE_OFFROUTE_RECALC.getId());
disableOffRouteRecalculation.setDescription(getString(R.string.access_disable_offroute_recalc_descr));
}
private void setupDisableWrongDirectionRecalculationPref() {
SwitchPreferenceEx disableWrongDirectionRecalculation = (SwitchPreferenceEx) findPreference(settings.DISABLE_WRONG_DIRECTION_RECALC.getId());
disableWrongDirectionRecalculation.setDescription(getString(R.string.access_disable_wrong_direction_recalc_descr));
}
private void setupDirectionStylePref() {
RelativeDirectionStyle[] relativeDirectionStyles = RelativeDirectionStyle.values();
String[] entries = new String[relativeDirectionStyles.length];
Integer[] entryValues = new Integer[relativeDirectionStyles.length];
for (int i = 0; i < entries.length; i++) {
entries[i] = relativeDirectionStyles[i].toHumanString(app);
entryValues[i] = relativeDirectionStyles[i].ordinal();
}
ListPreferenceEx directionStyle = (ListPreferenceEx) findPreference(settings.DIRECTION_STYLE.getId());
directionStyle.setEntries(entries);
directionStyle.setEntryValues(entryValues);
directionStyle.setDescription(R.string.settings_direction_style_descr);
}
private void setupDirectionAudioFeedbackPref() {
SwitchPreferenceEx directionAudioFeedback = (SwitchPreferenceEx) findPreference(settings.DIRECTION_AUDIO_FEEDBACK.getId());
directionAudioFeedback.setDescription(getString(R.string.access_direction_audio_feedback_descr));
}
private void setupDirectionHapticFeedbackPref() {
SwitchPreferenceEx directionHapticFeedback = (SwitchPreferenceEx) findPreference(settings.DIRECTION_HAPTIC_FEEDBACK.getId());
directionHapticFeedback.setDescription(getString(R.string.access_direction_haptic_feedback_descr));
}
private void setupCopyProfileSettingsPref() {
Preference copyProfilePrefs = findPreference(COPY_PLUGIN_SETTINGS);
copyProfilePrefs.setIcon(getActiveIcon(R.drawable.ic_action_copy));
}
private void setupResetToDefaultPref() {
Preference resetToDefault = findPreference(RESET_TO_DEFAULT);
resetToDefault.setIcon(getActiveIcon(R.drawable.ic_action_reset_to_default_dark));
}
@Override
public void onPreferenceChanged(String prefId) {
if (settings.ACCESSIBILITY_MODE.getId().equals(prefId)) {
updateAccessibilityOptions();
}
}
private void updateAccessibilityOptions() {
boolean accessibilityEnabled = app.accessibilityEnabledForMode(getSelectedAppMode());
PreferenceScreen screen = getPreferenceScreen();
if (screen != null) {
for (int i = 0; i < screen.getPreferenceCount(); i++) {
Preference preference = screen.getPreference(i);
String prefId = preference.getKey();
if (!settings.ACCESSIBILITY_MODE.getId().equals(prefId) && !settings.SPEECH_RATE.getId().equals(prefId))
preference.setEnabled(accessibilityEnabled);
}
}
}
}

View file

@ -95,6 +95,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
ROUTE_PARAMETERS(RouteParametersFragment.class.getName(), true, R.xml.route_parameters, R.layout.profile_preference_toolbar),
SCREEN_ALERTS(ScreenAlertsFragment.class.getName(), true, R.xml.screen_alerts, R.layout.profile_preference_toolbar_with_switch),
VOICE_ANNOUNCES(VoiceAnnouncesFragment.class.getName(), true, R.xml.voice_announces, R.layout.profile_preference_toolbar_with_switch),
ACCESSIBILITY_SETTINGS(AccessibilitySettingsFragment.class.getName(), true, R.xml.accessibility_settings, R.layout.profile_preference_toolbar_big),
VEHICLE_PARAMETERS(VehicleParametersFragment.class.getName(), true, R.xml.vehicle_parameters, R.layout.profile_preference_toolbar),
MAP_DURING_NAVIGATION(MapDuringNavigationFragment.class.getName(), true, R.xml.map_during_navigation, R.layout.profile_preference_toolbar),
TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, R.xml.turn_screen_on, R.layout.profile_preference_toolbar_with_switch),

View file

@ -13,7 +13,7 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
public class OsmEditingFragment extends BaseSettingsFragment {
public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged {
private static final String OPEN_OSM_EDITS = "open_osm_edits";
private static final String OSM_LOGIN_DATA = "osm_login_data";
@ -77,4 +77,12 @@ public class OsmEditingFragment extends BaseSettingsFragment {
}
return super.onPreferenceClick(preference);
}
@Override
public void onPreferenceChanged(String prefId) {
if (OSM_LOGIN_DATA.equals(prefId)) {
Preference nameAndPasswordPref = findPreference(OSM_LOGIN_DATA);
nameAndPasswordPref.setSummary(settings.USER_NAME.get());
}
}
}

View file

@ -18,6 +18,7 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.osmedit.SettingsOsmEditingActivity;
import net.osmand.plus.settings.OnPreferenceChanged;
public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
@ -32,8 +33,7 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
@Override
public void createMenuItems(Bundle savedInstanceState) {
Context context = getContext();
Preference editTextPreference = getPreference();
if (context == null || editTextPreference == null) {
if (context == null) {
return;
}
OsmandApplication app = requiredMyApplication();
@ -83,7 +83,13 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
app.getSettings().USER_NAME.set(userNameEditText.getText().toString());
app.getSettings().USER_PASSWORD.set(passwordEditText.getText().toString());
new SettingsOsmEditingActivity.ValidateOsmLoginDetailsTask(getActivity()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new SettingsOsmEditingActivity.ValidateOsmLoginDetailsTask(app).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
Fragment target = getTargetFragment();
Preference preference = getPreference();
if (target instanceof OnPreferenceChanged && preference != null) {
((OnPreferenceChanged) target).onPreferenceChanged(preference.getKey());
}
dismiss();
}