From 2b9c871e7dbdd0ef6f399bb653a19183f2e5cb07 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 3 Feb 2020 15:07:47 +0200 Subject: [PATCH 1/6] Fix profile switch visibility and update osm editing icon --- OsmAnd/res/xml/osm_editing.xml | 4 ++-- .../osmand/plus/osmedit/OsmEditingFragment.java | 14 ++++++++++++++ .../osmand/plus/settings/MainSettingsFragment.java | 6 +++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/OsmAnd/res/xml/osm_editing.xml b/OsmAnd/res/xml/osm_editing.xml index b4e892cb6d..2fe5a777c9 100644 --- a/OsmAnd/res/xml/osm_editing.xml +++ b/OsmAnd/res/xml/osm_editing.xml @@ -21,12 +21,12 @@ tools:summary="@string/open_street_map_login_descr" /> + android:title="@string/offline_edition" + tools:icon="@drawable/ic_action_offline" /> Date: Mon, 3 Feb 2020 15:13:33 +0200 Subject: [PATCH 2/6] Hide daily folders option and fix pref info padding --- OsmAnd/res/layout/global_preference_toolbar.xml | 2 ++ OsmAnd/res/layout/preference_info.xml | 1 - OsmAnd/res/layout/preference_with_descr.xml | 1 + .../preference_with_descr_dialog_and_switch.xml | 1 + OsmAnd/res/xml/osm_editing.xml | 2 +- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 2 +- .../osmand/plus/activities/SavingTrackHelper.java | 6 +++--- .../plus/monitoring/MonitoringSettingsFragment.java | 5 ++--- .../plus/monitoring/SettingsMonitoringActivity.java | 5 ++--- .../net/osmand/plus/osmedit/OsmEditingFragment.java | 13 ++++++++++++- 10 files changed, 25 insertions(+), 13 deletions(-) diff --git a/OsmAnd/res/layout/global_preference_toolbar.xml b/OsmAnd/res/layout/global_preference_toolbar.xml index 6a5d37f661..a32e3d1192 100644 --- a/OsmAnd/res/layout/global_preference_toolbar.xml +++ b/OsmAnd/res/layout/global_preference_toolbar.xml @@ -35,6 +35,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" + android:letterSpacing="@dimen/text_button_letter_spacing" android:maxLines="2" android:textColor="?attr/app_bar_primary_item_color" android:textSize="@dimen/dialog_header_text_size" @@ -46,6 +47,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" + android:letterSpacing="@dimen/description_letter_spacing" android:maxLines="2" android:textColor="?attr/pstsInactiveTextColor" android:textSize="@dimen/default_desc_text_size" diff --git a/OsmAnd/res/layout/preference_info.xml b/OsmAnd/res/layout/preference_info.xml index 69717fdf48..0a2270b18a 100644 --- a/OsmAnd/res/layout/preference_info.xml +++ b/OsmAnd/res/layout/preference_info.xml @@ -21,7 +21,6 @@ android:id="@android:id/title" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_gravity="center_vertical" android:letterSpacing="@dimen/description_letter_spacing" android:paddingLeft="@dimen/content_padding" android:paddingTop="@dimen/content_padding_small" diff --git a/OsmAnd/res/layout/preference_with_descr.xml b/OsmAnd/res/layout/preference_with_descr.xml index 3ed18db7ae..a4eb1124fb 100644 --- a/OsmAnd/res/layout/preference_with_descr.xml +++ b/OsmAnd/res/layout/preference_with_descr.xml @@ -41,6 +41,7 @@ android:layout_height="wrap_content" android:ellipsize="marquee" android:singleLine="true" + android:letterSpacing="@dimen/text_button_letter_spacing" android:textColor="?android:textColorPrimary" android:textSize="@dimen/default_list_text_size" osmand:typeface="@string/font_roboto_regular" /> diff --git a/OsmAnd/res/layout/preference_with_descr_dialog_and_switch.xml b/OsmAnd/res/layout/preference_with_descr_dialog_and_switch.xml index 0d8eff15f5..59f4022e7e 100644 --- a/OsmAnd/res/layout/preference_with_descr_dialog_and_switch.xml +++ b/OsmAnd/res/layout/preference_with_descr_dialog_and_switch.xml @@ -39,6 +39,7 @@ android:layout_height="wrap_content" android:ellipsize="marquee" android:fadingEdge="horizontal" + android:letterSpacing="@dimen/text_button_letter_spacing" android:maxLines="2" android:textColor="?android:textColorPrimary" android:textSize="@dimen/default_list_text_size" diff --git a/OsmAnd/res/xml/osm_editing.xml b/OsmAnd/res/xml/osm_editing.xml index 2fe5a777c9..990a15349c 100644 --- a/OsmAnd/res/xml/osm_editing.xml +++ b/OsmAnd/res/xml/osm_editing.xml @@ -6,7 +6,7 @@ DISABLE_RECORDING_ONCE_APP_KILLED = new BooleanPreference("disable_recording_once_app_killed", false).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index 4e8f2dadc0..c00fa94337 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -216,9 +216,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper { Integer track_storage_directory = ctx.getSettings().TRACK_STORAGE_DIRECTORY.get(); if (track_storage_directory != OsmandSettings.REC_DIRECTORY) { SimpleDateFormat dateDirFormat = new SimpleDateFormat("yyyy-MM"); - if (track_storage_directory == OsmandSettings.DAILY_DIRECTORY) { - dateDirFormat = new SimpleDateFormat("yyyy-MM-dd"); - } +// if (track_storage_directory == OsmandSettings.DAILY_DIRECTORY) { +// dateDirFormat = new SimpleDateFormat("yyyy-MM-dd"); +// } String dateDirName = dateDirFormat.format(new Date(pt.time)); File dateDir = new File(dir, dateDirName); dateDir.mkdirs(); diff --git a/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java index 654faeab8d..08528fe019 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java @@ -29,7 +29,6 @@ import java.io.Serializable; import java.util.HashMap; import java.util.LinkedHashMap; -import static net.osmand.plus.OsmandSettings.DAILY_DIRECTORY; import static net.osmand.plus.OsmandSettings.MONTHLY_DIRECTORY; import static net.osmand.plus.OsmandSettings.REC_DIRECTORY; import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.MINUTES; @@ -195,11 +194,11 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment implements } private void setupTrackStorageDirectoryPref() { - Integer[] entryValues = new Integer[] {REC_DIRECTORY, MONTHLY_DIRECTORY, DAILY_DIRECTORY}; + Integer[] entryValues = new Integer[] {REC_DIRECTORY, MONTHLY_DIRECTORY}; String[] entries = new String[entryValues.length]; entries[0] = getString(R.string.store_tracks_in_rec_directory); entries[1] = getString(R.string.store_tracks_in_monthly_directories); - entries[2] = getString(R.string.store_tracks_in_daily_directories); +// entries[2] = getString(R.string.store_tracks_in_daily_directories); ListPreferenceEx trackStorageDirectory = (ListPreferenceEx) findPreference(settings.TRACK_STORAGE_DIRECTORY.getId()); trackStorageDirectory.setEntries(entries); diff --git a/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java b/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java index a8a12a9b2b..135e409ce9 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/SettingsMonitoringActivity.java @@ -37,7 +37,6 @@ import net.osmand.plus.activities.SettingsBaseActivity; import java.util.Map; -import static net.osmand.plus.OsmandSettings.DAILY_DIRECTORY; import static net.osmand.plus.OsmandSettings.MONTHLY_DIRECTORY; import static net.osmand.plus.OsmandSettings.REC_DIRECTORY; @@ -156,11 +155,11 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity { cat.addPreference(createCheckBoxPreference(settings.SAVE_HEADING_TO_GPX, R.string.save_heading, R.string.save_heading_descr)); - Integer[] intValues = new Integer[]{REC_DIRECTORY, MONTHLY_DIRECTORY, DAILY_DIRECTORY}; + Integer[] intValues = new Integer[]{REC_DIRECTORY, MONTHLY_DIRECTORY}; names = new String[intValues.length]; names[0] = getString(R.string.store_tracks_in_rec_directory); names[1] = getString(R.string.store_tracks_in_monthly_directories); - names[2] = getString(R.string.store_tracks_in_daily_directories); +// names[2] = getString(R.string.store_tracks_in_daily_directories); cat.addPreference(createListPreference(settings.TRACK_STORAGE_DIRECTORY, names, intValues, R.string.track_storage_directory, R.string.track_storage_directory_descrp)); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java index bb491abcca..cd92fa4592 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java @@ -5,6 +5,7 @@ import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.support.v4.app.FragmentManager; import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceViewHolder; import android.text.SpannableString; import android.view.LayoutInflater; import android.view.View; @@ -22,12 +23,13 @@ import net.osmand.plus.widgets.style.CustomTypefaceSpan; public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged { + private static final String OSM_EDITING_INFO = "osm_editing_info"; private static final String OPEN_OSM_EDITS = "open_osm_edits"; private static final String OSM_LOGIN_DATA = "osm_login_data"; @Override protected void setupPreferences() { - Preference osmEditingInfo = findPreference("osm_editing_info"); + Preference osmEditingInfo = findPreference(OSM_EDITING_INFO); osmEditingInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); setupNameAndPasswordPref(); @@ -45,6 +47,15 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer AndroidUiHelper.updateVisibility(toolbarSubtitle, true); } + @Override + protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) { + super.onBindPreferenceViewHolder(preference, holder); + if (OSM_EDITING_INFO.equals(preference.getKey())) { + TextView titleView = (TextView) holder.findViewById(android.R.id.title); + titleView.setTextSize(16); + } + } + private void setupNameAndPasswordPref() { Preference nameAndPasswordPref = findPreference(OSM_LOGIN_DATA); nameAndPasswordPref.setSummary(settings.USER_NAME.get()); From a6f26f8dcd53d463e733938aec0552d729dc7340 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 3 Feb 2020 16:11:53 +0200 Subject: [PATCH 3/6] Fix editText margin inside textFieldBox --- .../bottomsheets/EditTextPreferenceBottomSheet.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/EditTextPreferenceBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/EditTextPreferenceBottomSheet.java index 81f6675afb..447b34dd24 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/EditTextPreferenceBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/EditTextPreferenceBottomSheet.java @@ -8,7 +8,9 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.view.View; import android.widget.EditText; +import android.widget.RelativeLayout; +import net.osmand.AndroidUtils; import net.osmand.plus.ApplicationMode; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; @@ -47,6 +49,13 @@ public class EditTextPreferenceBottomSheet extends BasePreferenceBottomSheet { View view = UiUtilities.getInflater(ctx, nightMode).inflate(R.layout.preference_edit_text_box, null); editText = view.findViewById(R.id.edit_text); editText.setText(text); + + RelativeLayout editTextLayout = view.findViewById(R.id.text_field_boxes_editTextLayout); + if (editTextLayout != null && editTextLayout.getLayoutParams() instanceof RelativeLayout.LayoutParams) { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) editTextLayout.getLayoutParams(); + params.setMargins(params.leftMargin, AndroidUtils.dpToPx(ctx, 19), params.rightMargin, params.bottomMargin); + } + items.add(new SimpleBottomSheetItem.Builder().setCustomView(view).create()); String description = editTextPreference.getDescription(); From 871717daac6471eb590be5ae989c1dfb3c5f1b04 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 3 Feb 2020 17:36:50 +0200 Subject: [PATCH 4/6] Add pref warning for system accessibility pref --- OsmAnd/res/layout/preference_permission.xml | 4 +- OsmAnd/res/values/strings.xml | 1 + OsmAnd/res/xml/accessibility_settings.xml | 8 +++ .../access/AccessibilitySettingsFragment.java | 61 ++++++++++++++++++- 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/layout/preference_permission.xml b/OsmAnd/res/layout/preference_permission.xml index d793433529..7df4bece52 100644 --- a/OsmAnd/res/layout/preference_permission.xml +++ b/OsmAnd/res/layout/preference_permission.xml @@ -4,14 +4,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginLeft="@dimen/content_padding_half" - android:layout_marginRight="@dimen/content_padding_half" android:background="?attr/list_background_color"> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 4a0e4e852f..b9196f0aec 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Accessibility mode disabled in your system. Show only at night All plugin settings restored to default state. All profile settings restored to default state. diff --git a/OsmAnd/res/xml/accessibility_settings.xml b/OsmAnd/res/xml/accessibility_settings.xml index f69a4fcabf..69e92ecc50 100644 --- a/OsmAnd/res/xml/accessibility_settings.xml +++ b/OsmAnd/res/xml/accessibility_settings.xml @@ -3,6 +3,14 @@ xmlns:tools="http://schemas.android.com/tools" android:title="@string/shared_string_accessibility"> + + Build.VERSION_CODES.LOLLIPOP) { + Drawable bgDrawable = getPaintedIcon(R.drawable.rectangle_rounded, color); + Drawable selectable = getPaintedIcon(R.drawable.ripple_rectangle_rounded, selectedColor); + Drawable[] layers = {bgDrawable, selectable}; + AndroidUtils.setBackground(selectableView, new LayerDrawable(layers)); + } else { + Drawable bgDrawable = getPaintedIcon(R.drawable.rectangle_rounded, color); + AndroidUtils.setBackground(selectableView, bgDrawable); + } + LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) selectableView.getLayoutParams(); + params.setMargins(params.leftMargin, AndroidUtils.dpToPx(app, 6), params.rightMargin, params.bottomMargin); + } + } + } + @Override public void onPreferenceChanged(String prefId) { if (settings.ACCESSIBILITY_MODE.getId().equals(prefId)) { @@ -202,8 +256,11 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen 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) - && !RESET_TO_DEFAULT.equals(prefId) && !COPY_PLUGIN_SETTINGS.equals(prefId)) + if (!settings.ACCESSIBILITY_MODE.getId().equals(prefId) + && !settings.SPEECH_RATE.getId().equals(prefId) + && !RESET_TO_DEFAULT.equals(prefId) + && !COPY_PLUGIN_SETTINGS.equals(prefId) + && !ACCESSIBILITY_OPTIONS.equals(prefId)) preference.setEnabled(accessibilityEnabled); } } From 83ac4163046474383432f97521d6c793aadde0a6 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 3 Feb 2020 19:03:55 +0200 Subject: [PATCH 5/6] Fix ui update bug --- .../settings/ConfigureProfileFragment.java | 28 +++++++++---------- .../BasePreferenceBottomSheet.java | 3 ++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java index 2dd0a010d5..fafa908a45 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java @@ -38,6 +38,7 @@ import net.osmand.plus.SettingsHelper; import net.osmand.plus.SettingsHelper.ProfileSettingsItem; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet; @@ -100,20 +101,16 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co toolbarSubtitle.setText(R.string.configure_profile); toolbarSubtitle.setVisibility(View.VISIBLE); - if (!getSelectedAppMode().equals(ApplicationMode.DEFAULT)) { - view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - ApplicationMode selectedMode = getSelectedAppMode(); - List availableAppModes = ApplicationMode.values(getMyApplication()); - boolean isChecked = availableAppModes.contains(selectedMode); - ApplicationMode.changeProfileAvailability(selectedMode, !isChecked, getMyApplication()); - updateToolbarSwitch(); - } - }); - } else { - view.findViewById(R.id.switchWidget).setVisibility(View.GONE); - } + view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + ApplicationMode selectedMode = getSelectedAppMode(); + List availableAppModes = ApplicationMode.values(getMyApplication()); + boolean isChecked = availableAppModes.contains(selectedMode); + ApplicationMode.changeProfileAvailability(selectedMode, !isChecked, getMyApplication()); + updateToolbarSwitch(); + } + }); } @Override @@ -148,6 +145,9 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co updateToolbarSwitch(); TextView toolbarTitle = view.findViewById(R.id.toolbar_title); toolbarTitle.setText(getSelectedAppMode().toHumanString()); + + boolean visible = !getSelectedAppMode().equals(ApplicationMode.DEFAULT); + AndroidUiHelper.updateVisibility(view.findViewById(R.id.switchWidget), visible); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BasePreferenceBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BasePreferenceBottomSheet.java index 37de56fb93..f6ae08a36c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BasePreferenceBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BasePreferenceBottomSheet.java @@ -17,6 +17,7 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra public static final String PREFERENCE_ID = "preference_id"; private static final String APP_MODE_KEY = "app_mode_key"; + private static final String PROFILE_DEPENDENT = "profile_dependent"; private String prefId; private Preference preference; @@ -36,12 +37,14 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra super.onCreate(savedInstanceState); if (savedInstanceState != null) { appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null); + profileDependent = savedInstanceState.getBoolean(PROFILE_DEPENDENT, false); } } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); + outState.putBoolean(PROFILE_DEPENDENT, profileDependent); if (appMode != null) { outState.putString(APP_MODE_KEY, appMode.getStringKey()); } From d7bd9d89e6dabd6617d60052c7505c6e1035a4c6 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 4 Feb 2020 18:32:04 +0200 Subject: [PATCH 6/6] Update accessibility screen after system pref changed --- .../access/AccessibilitySettingsFragment.java | 52 ++++++++++++++++--- .../net/osmand/plus/OsmandApplication.java | 4 ++ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/access/AccessibilitySettingsFragment.java b/OsmAnd/src/net/osmand/access/AccessibilitySettingsFragment.java index 69212ea286..9ff2d322c5 100644 --- a/OsmAnd/src/net/osmand/access/AccessibilitySettingsFragment.java +++ b/OsmAnd/src/net/osmand/access/AccessibilitySettingsFragment.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.os.Build; +import android.os.Bundle; import android.provider.Settings; import android.support.v4.app.FragmentManager; import android.support.v7.preference.Preference; @@ -12,6 +13,7 @@ import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceViewHolder; import android.view.View; import android.view.accessibility.AccessibilityManager; +import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener; import android.widget.LinearLayout; import net.osmand.AndroidUtils; @@ -37,6 +39,21 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen private static final String COPY_PLUGIN_SETTINGS = "copy_plugin_settings"; private static final String RESET_TO_DEFAULT = "reset_to_default"; + private AccessibilityStateChangeListener accessibilityListener; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + accessibilityListener = new AccessibilityStateChangeListener() { + @Override + public void onAccessibilityStateChanged(boolean b) { + if (isResumed() && useSystemAccessibility()) { + updateAllSettings(); + } + } + }; + } + @Override protected void setupPreferences() { setupAccessibilityPermissionPref(); @@ -59,22 +76,43 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen updateAccessibilityOptions(); } + @Override + public void onResume() { + super.onResume(); + Preference accessibilityPrefs = findPreference(ACCESSIBILITY_OPTIONS); + if (useSystemAccessibility() && accessibilityPrefs.isVisible() == app.systemAccessibilityEnabled()) { + updateAllSettings(); + } + AccessibilityManager accessibilityManager = (AccessibilityManager) app.getSystemService(Context.ACCESSIBILITY_SERVICE); + accessibilityManager.addAccessibilityStateChangeListener(accessibilityListener); + } + + @Override + public void onPause() { + super.onPause(); + AccessibilityManager accessibilityManager = (AccessibilityManager) app.getSystemService(Context.ACCESSIBILITY_SERVICE); + accessibilityManager.removeAccessibilityStateChangeListener(accessibilityListener); + } + private void setupAccessibilityPermissionPref() { Preference accessibilityPrefs = findPreference(ACCESSIBILITY_OPTIONS); - AccessibilityMode currentAccessibilityMode = settings.ACCESSIBILITY_MODE.getModeValue(getSelectedAppMode()); - boolean systemAccessibilityEnabled = ((AccessibilityManager) app.getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled(); - if (!currentAccessibilityMode.equals(AccessibilityMode.DEFAULT) || systemAccessibilityEnabled) { + if (!useSystemAccessibility() || app.systemAccessibilityEnabled()) { accessibilityPrefs.setVisible(false); } else { Intent accessibilitySettings = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); - boolean resolved = accessibilitySettings.resolveActivity(app.getPackageManager()) != null; - accessibilityPrefs.setVisible(resolved); - if (resolved) { + accessibilityPrefs.setVisible(true); + if (accessibilitySettings.resolveActivity(app.getPackageManager()) != null) { accessibilityPrefs.setIntent(accessibilitySettings); + } else { + accessibilityPrefs.setSummary(null); } } } + private boolean useSystemAccessibility() { + return AccessibilityMode.DEFAULT == settings.ACCESSIBILITY_MODE.getModeValue(getSelectedAppMode()); + } + private void setupAccessibilityModePref() { AccessibilityMode[] accessibilityModes = AccessibilityMode.values(); String[] entries = new String[accessibilityModes.length]; @@ -208,7 +246,7 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen @Override public void onPreferenceChanged(String prefId) { if (settings.ACCESSIBILITY_MODE.getId().equals(prefId)) { - updateAccessibilityOptions(); + updateAllSettings(); } } diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 68b232df3d..ba6804721f 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -886,6 +886,10 @@ public class OsmandApplication extends MultiDexApplication { } else if (mode == AccessibilityMode.OFF) { return false; } + return systemAccessibilityEnabled(); + } + + public boolean systemAccessibilityEnabled() { return ((AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled(); }