From 3c14562baf87f09ec0192c7c579585414e0304c6 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 5 Jun 2020 18:22:15 +0300 Subject: [PATCH 1/9] speed cameras alert ui --- .../res/layout/bottom_sheet_speed_cameras.xml | 36 ++++++++++ .../layout/preference_switch_with_alert.xml | 61 ++++++++++++++++ OsmAnd/res/values/strings.xml | 10 +++ OsmAnd/res/xml/global_settings.xml | 11 +++ OsmAnd/res/xml/screen_alerts.xml | 2 +- OsmAnd/res/xml/voice_announces.xml | 2 +- OsmAnd/src/net/osmand/plus/UiUtilities.java | 34 +++++++++ .../plus/dialogs/SpeedCamerasBottomSheet.java | 70 +++++++++++++++++++ .../fragments/GlobalSettingsFragment.java | 20 ++++++ .../fragments/ScreenAlertsFragment.java | 42 +++++++++++ .../fragments/VoiceAnnouncesFragment.java | 2 + 11 files changed, 288 insertions(+), 2 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_speed_cameras.xml create mode 100644 OsmAnd/res/layout/preference_switch_with_alert.xml create mode 100644 OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java diff --git a/OsmAnd/res/layout/bottom_sheet_speed_cameras.xml b/OsmAnd/res/layout/bottom_sheet_speed_cameras.xml new file mode 100644 index 0000000000..6fc553118f --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_speed_cameras.xml @@ -0,0 +1,36 @@ + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/preference_switch_with_alert.xml b/OsmAnd/res/layout/preference_switch_with_alert.xml new file mode 100644 index 0000000000..cdf10c32a6 --- /dev/null +++ b/OsmAnd/res/layout/preference_switch_with_alert.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index c7eb036115..384333fa4c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,16 @@ Thx - Hardy --> + Speed cameras alerts in some countries is prohibited by the law. + Uninstall + Keep active + In some countries or regions, the use of speed camera warning applications is prohibited by law. + \n\nYou need to make a choice depending on the law of your country. + \n\nSelect %1$s and you will receive alerts and warnings about speed cameras. + \n\nSelect %2$s. All data related to speed cameras: alerts, notifications, POIs will be deleted until OsmAnd is completely reinstalled. + Speed camera POI’s + Legal + Uninstall speed cameras Screen timeout Are you sure you want to irrevocably delete %d quick actions? Delete all? diff --git a/OsmAnd/res/xml/global_settings.xml b/OsmAnd/res/xml/global_settings.xml index de67e9fb54..b323527a39 100644 --- a/OsmAnd/res/xml/global_settings.xml +++ b/OsmAnd/res/xml/global_settings.xml @@ -60,4 +60,15 @@ app:fragment="net.osmand.plus.settings.fragments.ProxySettingsFragment" tools:icon="@drawable/ic_action_proxy" /> + + + + \ No newline at end of file diff --git a/OsmAnd/res/xml/screen_alerts.xml b/OsmAnd/res/xml/screen_alerts.xml index 58002ea240..c0c0219ab8 100644 --- a/OsmAnd/res/xml/screen_alerts.xml +++ b/OsmAnd/res/xml/screen_alerts.xml @@ -28,7 +28,7 @@ weakActivity = new WeakReference<>(activity); + alertSubTitle.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + FragmentActivity a = weakActivity.get(); + if (a != null) { + SpeedCamerasBottomSheet.showInstance(a.getSupportFragmentManager()); + } + } + }); + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java index 2d3ff2eb5e..084a55ce64 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java @@ -252,6 +252,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { Object currentValue = ((ListPreferenceEx) preference).getValue(); imageView.setEnabled(preference.isEnabled() && !OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(currentValue)); } + } else if (settings.SPEAK_SPEED_CAMERA.getId().equals(preference.getKey())) { + ScreenAlertsFragment.setupSpeedCamerasAlert(app, requireMyActivity(), holder, isNightMode()); } } From 66413f856ecb1f81d584f98eb397cf9079e1e930 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 10 Jun 2020 16:36:30 +0300 Subject: [PATCH 2/9] hide speed cameras from ui --- .../plus/activities/MapActivityActions.java | 4 ++ .../plus/dialogs/SpeedCamerasBottomSheet.java | 35 ++++++++++++-- .../plus/settings/backend/OsmandSettings.java | 3 ++ .../fragments/GlobalSettingsFragment.java | 29 ++++++++--- .../fragments/ScreenAlertsFragment.java | 32 ++++++++++--- .../fragments/VoiceAnnouncesFragment.java | 48 +++++++------------ 6 files changed, 104 insertions(+), 47 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 2fddc98cc6..6e80c3a83d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -37,6 +37,7 @@ import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; import net.osmand.map.ITileSource; +import net.osmand.plus.dialogs.SpeedCamerasBottomSheet; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.ItemClickListener; @@ -569,6 +570,9 @@ public class MapActivityActions implements DialogProvider { if (targets.hasTooLongDistanceToNavigate()) { app.showToastMessage(R.string.route_is_too_long_v2); } + if (!settings.SPEED_CAMERAS_ALERT_SHOWED.get()) { + SpeedCamerasBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), null); + } } public void recalculateRoute(boolean showDialog) { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java index ceb267385d..997bc98d8b 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java @@ -7,6 +7,9 @@ import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import net.osmand.plus.OsmandApplication; @@ -20,9 +23,10 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { public static final String TAG = SpeedCamerasBottomSheet.class.getName(); private OsmandApplication app; - public static void showInstance(@NonNull FragmentManager fm) { + public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment) { if (!fm.isStateSaved()) { SpeedCamerasBottomSheet bottomSheet = new SpeedCamerasBottomSheet(); + bottomSheet.setTargetFragment(targetFragment, 0); bottomSheet.show(fm, TAG); } } @@ -36,19 +40,34 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { @Override public void createMenuItems(Bundle savedInstanceState) { View root = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_speed_cameras, null); - ((ImageView) root.findViewById(R.id.icon)).setImageResource(R.drawable.img_speed_camera_warning); + ((ImageView) root.findViewById(R.id.icon)).setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.img_speed_camera_warning)); ((TextView) root.findViewById(R.id.description)).setText(getDescriptionText()); items.add(new BaseBottomSheetItem.Builder().setCustomView(root).create()); } + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + UiUtilities.setupDialogButton(nightMode, rightButton, getDismissButtonType(), R.string.keep_active); + } + @Override protected void onRightBottomButtonClick() { - super.onRightBottomButtonClick(); + setDialogShowed(); + dismiss(); } @Override protected void onDismissButtonClickAction() { - super.onDismissButtonClickAction(); + app.getSettings().SPEED_CAMERAS_UNINSTALLED.set(true); + app.getSettings().SPEAK_SPEED_CAMERA.set(false); + app.getSettings().SHOW_CAMERAS.set(false); + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof OnSpeedCamerasUninstallListener) { + ((OnSpeedCamerasUninstallListener) targetFragment).onSpeedCamerasUninstalled(); + } + setDialogShowed(); + dismiss(); } @Override @@ -67,4 +86,12 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { String text = getString(R.string.speed_cameras_legal_descr, keepActive, uninstall); return UiUtilities.setWordsMediumFont(app, text, keepActive, uninstall); } + + private void setDialogShowed() { + app.getSettings().SPEED_CAMERAS_ALERT_SHOWED.set(true); + } + + public interface OnSpeedCamerasUninstallListener { + void onSpeedCamerasUninstalled(); + } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index 10037b6d0f..55d211417a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -2108,6 +2108,9 @@ public class OsmandSettings { public final OsmandPreference SPEAK_SPEED_CAMERA = new BooleanPreference("speak_cameras", false).makeProfile().cache(); public final OsmandPreference SPEAK_TUNNELS = new BooleanPreference("speak_tunnels", false).makeProfile().cache(); + public final OsmandPreference SPEED_CAMERAS_UNINSTALLED = new BooleanPreference("speed_cameras_uninstalled", false).makeGlobal().cache(); + public final OsmandPreference SPEED_CAMERAS_ALERT_SHOWED = new BooleanPreference("speed_cameras_alert_showed", false).makeGlobal().cache(); + public final OsmandPreference ANNOUNCE_WPT = new BooleanPreference("announce_wpt", true) { @Override protected boolean setValue(Object prefs, Boolean val) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java index 0763b302a4..8896c159b9 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java @@ -7,6 +7,7 @@ import android.widget.ImageView; import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; +import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceViewHolder; import androidx.preference.SwitchPreferenceCompat; @@ -14,20 +15,28 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.SettingsGeneralActivity; import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment; +import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment.OnSendAnalyticsPrefsUpdate; import net.osmand.plus.dialogs.SpeedCamerasBottomSheet; +import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; -public class GlobalSettingsFragment extends BaseSettingsFragment implements SendAnalyticsBottomSheetDialogFragment.OnSendAnalyticsPrefsUpdate, OnPreferenceChanged { +public class GlobalSettingsFragment extends BaseSettingsFragment + implements OnSendAnalyticsPrefsUpdate, OnPreferenceChanged, + OnSpeedCamerasUninstallListener { public static final String TAG = GlobalSettingsFragment.class.getSimpleName(); private static final String SEND_ANONYMOUS_DATA_PREF_ID = "send_anonymous_data"; private static final String DIALOGS_AND_NOTIFICATIONS_PREF_ID = "dialogs_and_notifications"; private static final String UNINSTALL_SPEED_CAMERAS_PREF_ID = "uninstall_speed_cameras"; + private static final String LEGAL_CATEGORY_ID = "legal"; + + private Preference uninstallSpeedCameras; + private PreferenceCategory legalCategory; @Override protected void setupPreferences() { @@ -38,7 +47,12 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send setupSendAnonymousDataPref(); setupDialogsAndNotificationsPref(); setupEnableProxyPref(); - setupUninstallSpeedCamerasPref(); + legalCategory = (PreferenceCategory) findPreference(LEGAL_CATEGORY_ID); + uninstallSpeedCameras = (Preference) findPreference(UNINSTALL_SPEED_CAMERAS_PREF_ID); + uninstallSpeedCameras.setIcon(getPersistentPrefIcon(R.drawable.ic_speed_camera_disabled)); + if (settings.SPEED_CAMERAS_UNINSTALLED.get()) { + onSpeedCamerasUninstalled(); + } } @Override @@ -117,7 +131,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send if (UNINSTALL_SPEED_CAMERAS_PREF_ID.equals(prefId)) { FragmentManager fm = getFragmentManager(); if (fm != null) { - SpeedCamerasBottomSheet.showInstance(fm); + SpeedCamerasBottomSheet.showInstance(fm, this); } } return super.onPreferenceClick(preference); @@ -207,8 +221,11 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send enableProxy.setIcon(getPersistentPrefIcon(R.drawable.ic_action_proxy)); } - private void setupUninstallSpeedCamerasPref() { - Preference uninstallSpeedCameras = (Preference) findPreference(UNINSTALL_SPEED_CAMERAS_PREF_ID); - uninstallSpeedCameras.setIcon(getPersistentPrefIcon(R.drawable.ic_speed_camera_disabled)); + @Override + public void onSpeedCamerasUninstalled() { + if (uninstallSpeedCameras != null && legalCategory != null) { + uninstallSpeedCameras.setVisible(false); + legalCategory.setVisible(false); + } } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ScreenAlertsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ScreenAlertsFragment.java index 683aa15a49..4752a11590 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ScreenAlertsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ScreenAlertsFragment.java @@ -9,8 +9,11 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; @@ -19,6 +22,7 @@ import androidx.preference.SwitchPreferenceCompat; import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.dialogs.SpeedCamerasBottomSheet; +import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.R; @@ -28,30 +32,34 @@ import java.lang.ref.WeakReference; import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; -public class ScreenAlertsFragment extends BaseSettingsFragment { +public class ScreenAlertsFragment extends BaseSettingsFragment implements OnSpeedCamerasUninstallListener { public static final String TAG = ScreenAlertsFragment.class.getSimpleName(); private static final String SHOW_ROUTING_ALARMS_INFO = "show_routing_alarms_info"; private static final String SCREEN_ALERTS_IMAGE = "screen_alerts_image"; private static final String SHOW_CAMERAS = "show_cameras"; + private SwitchPreferenceCompat showCameras; @Override protected void setupPreferences() { Preference showRoutingAlarmsInfo = findPreference(SHOW_ROUTING_ALARMS_INFO); SwitchPreferenceCompat showTrafficWarnings = (SwitchPreferenceCompat) findPreference(settings.SHOW_TRAFFIC_WARNINGS.getId()); SwitchPreferenceCompat showPedestrian = (SwitchPreferenceCompat) findPreference(settings.SHOW_PEDESTRIAN.getId()); - SwitchPreferenceCompat showCameras = (SwitchPreferenceCompat) findPreference(settings.SHOW_CAMERAS.getId()); SwitchPreferenceCompat showTunnels = (SwitchPreferenceCompat) findPreference(settings.SHOW_TUNNELS.getId()); + showCameras = (SwitchPreferenceCompat) findPreference(settings.SHOW_CAMERAS.getId()); showRoutingAlarmsInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); showTrafficWarnings.setIcon(getIcon(R.drawable.list_warnings_traffic_calming)); showPedestrian.setIcon(getIcon(R.drawable.list_warnings_pedestrian)); - showCameras.setIcon(getIcon(R.drawable.list_warnings_speed_camera)); showTunnels.setIcon(getIcon(R.drawable.list_warnings_tunnel)); + showCameras.setIcon(getIcon(R.drawable.list_warnings_speed_camera)); setupScreenAlertsImage(); enableDisablePreferences(settings.SHOW_ROUTING_ALARMS.getModeValue(getSelectedAppMode())); + if (settings.SPEED_CAMERAS_UNINSTALLED.get()) { + onSpeedCamerasUninstalled(); + } } @Override @@ -112,7 +120,7 @@ public class ScreenAlertsFragment extends BaseSettingsFragment { deviceImage.setImageDrawable(getDeviceImage()); warningIcon.setImageDrawable(getWarningIcon()); } else if (SHOW_CAMERAS.equals(key)) { - setupSpeedCamerasAlert(app, requireMyActivity(), holder, isNightMode()); + setupSpeedCamerasAlert(app, requireMyActivity(), holder, this, isNightMode()); } } } @@ -155,7 +163,11 @@ public class ScreenAlertsFragment extends BaseSettingsFragment { return null; } - public static void setupSpeedCamerasAlert(OsmandApplication app, FragmentActivity activity, PreferenceViewHolder holder, boolean nightMode) { + public static void setupSpeedCamerasAlert(@NonNull OsmandApplication app, + @NonNull FragmentActivity activity, + @NonNull PreferenceViewHolder holder, + @Nullable Fragment targetFragment, + boolean nightMode) { ImageView alertIcon = (ImageView) holder.itemView.findViewById(R.id.alert_icon); TextView alertTitle = (TextView) holder.itemView.findViewById(R.id.alert_title); TextView alertSubTitle = (TextView) holder.itemView.findViewById(R.id.alert_subtitle); @@ -176,14 +188,22 @@ public class ScreenAlertsFragment extends BaseSettingsFragment { ? app.getResources().getColor(R.color.active_color_primary_dark) : app.getResources().getColor(R.color.active_color_primary_light)); final WeakReference weakActivity = new WeakReference<>(activity); + final WeakReference weakFragment = new WeakReference<>(targetFragment); alertSubTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FragmentActivity a = weakActivity.get(); if (a != null) { - SpeedCamerasBottomSheet.showInstance(a.getSupportFragmentManager()); + SpeedCamerasBottomSheet.showInstance(a.getSupportFragmentManager(), weakFragment.get()); } } }); } + + @Override + public void onSpeedCamerasUninstalled() { + if (showCameras != null) { + showCameras.setVisible(false); + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java index 084a55ce64..11c1f6b72b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java @@ -1,8 +1,6 @@ package net.osmand.plus.settings.fragments; import android.app.Activity; -import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; @@ -12,14 +10,13 @@ import android.view.View; import android.widget.ImageView; import android.widget.TextView; -import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; -import androidx.preference.SwitchPreferenceCompat; import net.osmand.AndroidUtils; +import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; @@ -37,9 +34,10 @@ import static net.osmand.plus.settings.backend.OsmandSettings.VOICE_PROVIDER_NOT import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; import static net.osmand.plus.activities.SettingsNavigationActivity.MORE_VALUE; -public class VoiceAnnouncesFragment extends BaseSettingsFragment { +public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnSpeedCamerasUninstallListener { public static final String TAG = VoiceAnnouncesFragment.class.getSimpleName(); + private Preference speakCamera; @Override protected void createToolbar(LayoutInflater inflater, View view) { @@ -100,6 +98,10 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { setupInterruptMusicPref(); } enableDisablePreferences(!settings.VOICE_MUTE.getModeValue(getSelectedAppMode())); + speakCamera = findPreference(settings.SPEAK_SPEED_CAMERA.getId()); + if (settings.SPEED_CAMERAS_UNINSTALLED.get()) { + onSpeedCamerasUninstalled(); + } } private void setupSpeedLimitExceedPref() { @@ -209,29 +211,6 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { getPreferenceScreen().addPreference(interruptMusicPref); } - public void confirmSpeedCamerasDlg() { - Context ctx = getContext(); - if (ctx == null) { - return; - } - AlertDialog.Builder bld = new AlertDialog.Builder(UiUtilities.getThemedContext(ctx, isNightMode())); - bld.setMessage(R.string.confirm_usage_speed_cameras); - bld.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - onConfirmPreferenceChange( - settings.SPEAK_SPEED_CAMERA.getId(), true, ApplyQueryType.SNACK_BAR); - SwitchPreferenceCompat speakSpeedCamera = (SwitchPreferenceCompat) findPreference(settings.SPEAK_SPEED_CAMERA.getId()); - if (speakSpeedCamera != null) { - speakSpeedCamera.setChecked(true); - } - } - }); - bld.setNegativeButton(R.string.shared_string_cancel, null); - bld.show(); - } - private void updateMenu() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { @@ -253,7 +232,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { imageView.setEnabled(preference.isEnabled() && !OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(currentValue)); } } else if (settings.SPEAK_SPEED_CAMERA.getId().equals(preference.getKey())) { - ScreenAlertsFragment.setupSpeedCamerasAlert(app, requireMyActivity(), holder, isNightMode()); + ScreenAlertsFragment.setupSpeedCamerasAlert(app, requireMyActivity(), holder, this, isNightMode()); } } @@ -277,8 +256,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { } if (prefId.equals(settings.SPEAK_SPEED_CAMERA.getId())) { if (!settings.SPEAK_SPEED_CAMERA.getModeValue(selectedMode)) { - confirmSpeedCamerasDlg(); - return false; + return onConfirmPreferenceChange( + settings.SPEAK_SPEED_CAMERA.getId(), true, ApplyQueryType.SNACK_BAR); } else { return onConfirmPreferenceChange( settings.SPEAK_SPEED_CAMERA.getId(), false, ApplyQueryType.SNACK_BAR); @@ -315,4 +294,11 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { super.onApplyPreferenceChange(prefId, applyToAllProfiles, newValue); } } + + @Override + public void onSpeedCamerasUninstalled() { + if (speakCamera != null) { + speakCamera.setVisible(false); + } + } } \ No newline at end of file From f2b1836e539ee12be28689634eb1ffc3f3fb732d Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 10 Jun 2020 17:08:44 +0300 Subject: [PATCH 3/9] hide speed cameras from search --- .../java/net/osmand/search/SearchUICore.java | 20 +++++++++++++++++++ .../plus/dialogs/SpeedCamerasBottomSheet.java | 2 ++ .../osmand/plus/search/QuickSearchHelper.java | 1 + 3 files changed, 23 insertions(+) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index 46b0ee4e82..8aab2a9103 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -11,6 +11,7 @@ import net.osmand.data.MapObject; import net.osmand.data.Street; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiType; import net.osmand.search.core.CustomSearchPoiFilter; import net.osmand.search.core.ObjectType; import net.osmand.search.core.SearchCoreAPI; @@ -656,6 +657,8 @@ public class SearchUICore { private List exportedObjects; private List exportedCities; + private static boolean speedCamerasUninstalled = false; + public SearchResultMatcher(ResultMatcher matcher, SearchPhrase phrase, int request, AtomicInteger requestNumber, int totalLimit) { this.matcher = matcher; @@ -733,6 +736,9 @@ public class SearchUICore { @Override public boolean publish(SearchResult object) { + if (speedCamerasUninstalled && isSpeedCameraObject(object.object)) { + return false; + } if (phrase != null && object.otherNames != null && !phrase.getFirstUnknownNameStringMatcher().matches(object.localeName)) { for (String s : object.otherNames) { if (phrase.getFirstUnknownNameStringMatcher().matches(s)) { @@ -886,6 +892,20 @@ public class SearchUICore { } return json; } + + private boolean isSpeedCameraObject(Object object) { + String key = ""; + if (object instanceof PoiType) { + key = ((PoiType) object).getKeyName(); + } else if (object instanceof Amenity) { + key = ((Amenity) object).getSubType(); + } + return "speed_camera".equals(key); + } + + public static void setSpeedCamerasUninstalled(boolean speedCamerasUninstalled) { + SearchResultMatcher.speedCamerasUninstalled = speedCamerasUninstalled; + } } private enum ResultCompareStep { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java index 997bc98d8b..a6ea85e238 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java @@ -17,6 +17,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.search.SearchUICore.SearchResultMatcher; public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { @@ -62,6 +63,7 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { app.getSettings().SPEED_CAMERAS_UNINSTALLED.set(true); app.getSettings().SPEAK_SPEED_CAMERA.set(false); app.getSettings().SHOW_CAMERAS.set(false); + SearchResultMatcher.setSpeedCamerasUninstalled(true); Fragment targetFragment = getTargetFragment(); if (targetFragment instanceof OnSpeedCamerasUninstallListener) { ((OnSpeedCamerasUninstallListener) targetFragment).onSpeedCamerasUninstalled(); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index f504c9c22f..ad87af9077 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -68,6 +68,7 @@ public class QuickSearchHelper implements ResourceListener { core = new SearchUICore(app.getPoiTypes(), app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get()); app.getResourceManager().addResourceListener(this); + SearchResultMatcher.setSpeedCamerasUninstalled(app.getSettings().SPEED_CAMERAS_UNINSTALLED.get()); } public SearchUICore getCore() { From 6cb52d9130df9829e7c5752d653ec4a38f91c99e Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 10 Jun 2020 18:25:34 +0300 Subject: [PATCH 4/9] hide speed cameras poiTypes --- .../src/main/java/net/osmand/osm/MapPoiTypes.java | 13 +++++++++++++ .../src/net/osmand/plus/activities/MapActivity.java | 3 +++ .../plus/dialogs/SpeedCamerasBottomSheet.java | 1 + 3 files changed, 17 insertions(+) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 60d835dbec..7b719ab158 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -945,4 +945,17 @@ public class MapPoiTypes { return pat.isText(); } } + + public void excludeSpeedCameraPoiType() { + Iterator categoryIter = categories.iterator(); + while (categoryIter.hasNext()) { + Iterator poiIter = categoryIter.next().getPoiTypes().iterator(); + while (poiIter.hasNext()) { + PoiType poiType = poiIter.next(); + if ("speed_camera".equals(poiType.getKeyName())) { + poiIter.remove(); + } + } + } + } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 9bc9d3e24b..476768dc6e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -389,6 +389,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven lockHelper.setLockUIAdapter(this); mIsDestroyed = false; + if (settings.SPEED_CAMERAS_UNINSTALLED.get()) { + app.getPoiTypes().excludeSpeedCameraPoiType(); + } } public void exitFromFullScreen(View view) { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java index a6ea85e238..27b59e97a2 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java @@ -63,6 +63,7 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { app.getSettings().SPEED_CAMERAS_UNINSTALLED.set(true); app.getSettings().SPEAK_SPEED_CAMERA.set(false); app.getSettings().SHOW_CAMERAS.set(false); + app.getPoiTypes().excludeSpeedCameraPoiType(); SearchResultMatcher.setSpeedCamerasUninstalled(true); Fragment targetFragment = getTargetFragment(); if (targetFragment instanceof OnSpeedCamerasUninstallListener) { From 1dd909b115972032b906cc698125970639f13a76 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Tue, 16 Jun 2020 18:28:35 +0300 Subject: [PATCH 5/9] refactoring pr --- .../main/java/net/osmand/osm/MapPoiTypes.java | 5 +- .../java/net/osmand/search/SearchUICore.java | 6 +- .../layout/preference_switch_with_alert.xml | 61 -------------- OsmAnd/res/xml/global_settings.xml | 3 +- OsmAnd/res/xml/screen_alerts.xml | 10 ++- OsmAnd/res/xml/voice_announces.xml | 10 ++- .../access/AccessibilitySettingsFragment.java | 25 +----- .../src/net/osmand/plus/AppInitializer.java | 3 + OsmAnd/src/net/osmand/plus/UiUtilities.java | 55 +++++-------- .../osmand/plus/activities/MapActivity.java | 3 - .../audionotes/MultimediaNotesFragment.java | 19 +---- .../plus/dialogs/SpeedCamerasBottomSheet.java | 40 ++++----- .../mapsource/InputZoomLevelsBottomSheet.java | 20 +---- .../quickaction/QuickActionListFragment.java | 2 +- .../search/QuickSearchDialogFragment.java | 2 +- .../osmand/plus/search/QuickSearchHelper.java | 8 +- .../plus/settings/backend/OsmandSettings.java | 4 +- .../fragments/BaseSettingsFragment.java | 31 ++++++- .../fragments/GlobalSettingsFragment.java | 36 ++++---- .../fragments/ImportCompleteFragment.java | 3 +- .../fragments/ImportDuplicatesFragment.java | 3 +- .../fragments/ImportSettingsFragment.java | 3 +- .../fragments/ScreenAlertsFragment.java | 82 +++++-------------- .../fragments/VoiceAnnouncesFragment.java | 36 +++++--- 24 files changed, 174 insertions(+), 296 deletions(-) delete mode 100644 OsmAnd/res/layout/preference_switch_with_alert.xml diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 7b719ab158..d0c941a898 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -947,9 +947,8 @@ public class MapPoiTypes { } public void excludeSpeedCameraPoiType() { - Iterator categoryIter = categories.iterator(); - while (categoryIter.hasNext()) { - Iterator poiIter = categoryIter.next().getPoiTypes().iterator(); + for (PoiCategory category : categories) { + Iterator poiIter = category.getPoiTypes().iterator(); while (poiIter.hasNext()) { PoiType poiType = poiIter.next(); if ("speed_camera".equals(poiType.getKeyName())) { diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index 8aab2a9103..1143a2965b 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -657,7 +657,7 @@ public class SearchUICore { private List exportedObjects; private List exportedCities; - private static boolean speedCamerasUninstalled = false; + public static boolean speedCamerasUninstalled = false; public SearchResultMatcher(ResultMatcher matcher, SearchPhrase phrase, int request, AtomicInteger requestNumber, int totalLimit) { @@ -902,10 +902,6 @@ public class SearchUICore { } return "speed_camera".equals(key); } - - public static void setSpeedCamerasUninstalled(boolean speedCamerasUninstalled) { - SearchResultMatcher.speedCamerasUninstalled = speedCamerasUninstalled; - } } private enum ResultCompareStep { diff --git a/OsmAnd/res/layout/preference_switch_with_alert.xml b/OsmAnd/res/layout/preference_switch_with_alert.xml deleted file mode 100644 index cdf10c32a6..0000000000 --- a/OsmAnd/res/layout/preference_switch_with_alert.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/res/xml/global_settings.xml b/OsmAnd/res/xml/global_settings.xml index b323527a39..4cbc10ef0d 100644 --- a/OsmAnd/res/xml/global_settings.xml +++ b/OsmAnd/res/xml/global_settings.xml @@ -66,7 +66,8 @@ android:title="@string/shared_string_legal" /> diff --git a/OsmAnd/res/xml/screen_alerts.xml b/OsmAnd/res/xml/screen_alerts.xml index c0c0219ab8..ca963a5927 100644 --- a/OsmAnd/res/xml/screen_alerts.xml +++ b/OsmAnd/res/xml/screen_alerts.xml @@ -28,9 +28,17 @@ + + + + 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); - } + setupPrefRoundedBg(holder); } else if (settings.ACCESSIBILITY_MODE.getId().equals(prefId)) { ImageView imageView = (ImageView) holder.findViewById(android.R.id.icon); if (imageView != null) { diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index c39fe3a9d5..e07399832c 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -406,6 +406,9 @@ public class AppInitializer implements IProgress { return null; } }); + if (app.getSettings().SPEED_CAMERAS_UNINSTALLED.get()) { + app.getPoiTypes().excludeSpeedCameraPoiType(); + } } public void onCreateApplication() { diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 0f817aac35..3c24dff20a 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.res.ColorStateList; import android.graphics.Color; +import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; @@ -639,44 +640,32 @@ public class UiUtilities { } } - public static SpannableString createSpannableString(@NonNull String text, @NonNull String textToStyle, @NonNull StyleSpan styleSpan) { - SpannableString spannable = new SpannableString(text); - try { - int startIndex = text.indexOf(textToStyle); - spannable.setSpan( - styleSpan, - startIndex, - startIndex + textToStyle.length(), - Spanned.SPAN_INCLUSIVE_INCLUSIVE); - return spannable; - } catch (RuntimeException e) { - LOG.error("Error trying to find index of " + textToStyle + " " + e); - return spannable; - } - } - - public static SpannableString setWordsMediumFont(@NonNull Context ctx, @NonNull String text, @NonNull String... textToStyle) { + public static SpannableString createSpannableString(@NonNull String text, @NonNull StyleSpan styleSpan, @NonNull String... textToStyle) { SpannableString spannable = new SpannableString(text); for (String t : textToStyle) { - try { - int startIndex = text.indexOf(t); - spannable.setSpan( - new CustomTypefaceSpan(FontCache.getRobotoMedium(ctx)), - startIndex, - startIndex + t.length(), - Spanned.SPAN_INCLUSIVE_INCLUSIVE); - } catch (RuntimeException e) { - LOG.error("Error trying to find index of " + t + " " + e); - } + setSpan(spannable, styleSpan, text, t); } return spannable; } - public static GradientDrawable getRoundedBackgroundDrawable(@NonNull Context context, @ColorRes int colorRes, int radius) { - int r = AndroidUtils.dpToPx(context, radius); - GradientDrawable background = new GradientDrawable(); - background.setColor(ContextCompat.getColor(context, colorRes)); - background.setCornerRadius(r); - return background; + private static void setSpan(@NonNull SpannableString spannable, @NonNull Object styleSpan, @NonNull String text, @NonNull String t) { + try { + int startIndex = text.indexOf(t); + spannable.setSpan( + styleSpan, + startIndex, + startIndex + t.length(), + Spanned.SPAN_INCLUSIVE_INCLUSIVE); + } catch (RuntimeException e) { + LOG.error("Error trying to find index of " + t + " " + e); + } + } + + public static SpannableString createCustomFontSpannable(@NonNull Typeface typeface, @NonNull String text, @NonNull String... textToStyle) { + SpannableString spannable = new SpannableString(text); + for (String s : textToStyle) { + setSpan(spannable, new CustomTypefaceSpan(typeface), text, s); + } + return spannable; } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 476768dc6e..9bc9d3e24b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -389,9 +389,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven lockHelper.setLockUIAdapter(this); mIsDestroyed = false; - if (settings.SPEED_CAMERAS_UNINSTALLED.get()) { - app.getPoiTypes().excludeSpeedCameraPoiType(); - } } public void exitFromFullScreen(View view) { diff --git a/OsmAnd/src/net/osmand/plus/audionotes/MultimediaNotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/MultimediaNotesFragment.java index 1741f768b3..6996f7ee5b 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/MultimediaNotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/MultimediaNotesFragment.java @@ -6,7 +6,6 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Typeface; import android.graphics.drawable.Drawable; -import android.graphics.drawable.LayerDrawable; import android.hardware.Camera; import android.media.CamcorderProfile; import android.media.MediaRecorder; @@ -14,7 +13,6 @@ import android.os.Build; import android.os.Bundle; import android.os.StatFs; import android.text.SpannableString; -import android.view.View; import androidx.annotation.NonNull; import androidx.core.app.ActivityCompat; @@ -28,7 +26,6 @@ import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; -import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet; @@ -466,21 +463,7 @@ public class MultimediaNotesFragment extends BaseSettingsFragment implements Cop super.onBindPreferenceViewHolder(preference, holder); String prefId = preference.getKey(); if (CAMERA_PERMISSION.equals(prefId)) { - View selectableView = holder.itemView.findViewById(R.id.selectable_list_item); - if (selectableView != null) { - int color = AndroidUtils.getColorFromAttr(app, R.attr.activity_background_color); - int selectedColor = UiUtilities.getColorWithAlpha(getActiveProfileColor(), 0.3f); - - if (Build.VERSION.SDK_INT > 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); - } - } + setupPrefRoundedBg(holder); } else if (OPEN_NOTES_DESCRIPTION.equals(prefId)) { int minHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_list_item_height); holder.itemView.setMinimumHeight(minHeight); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java index 27b59e97a2..fbf64a8d29 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java @@ -17,12 +17,18 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.helpers.FontCache; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; +import net.osmand.plus.settings.fragments.OnPreferenceChanged; +import net.osmand.plus.widgets.style.CustomTypefaceSpan; import net.osmand.search.SearchUICore.SearchResultMatcher; public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { public static final String TAG = SpeedCamerasBottomSheet.class.getName(); private OsmandApplication app; + private OsmandSettings settings; public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment) { if (!fm.isStateSaved()) { @@ -36,22 +42,17 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); app = requiredMyApplication(); + settings = app.getSettings(); } @Override public void createMenuItems(Bundle savedInstanceState) { View root = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_speed_cameras, null); - ((ImageView) root.findViewById(R.id.icon)).setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.img_speed_camera_warning)); + ((ImageView) root.findViewById(R.id.icon)).setImageDrawable(ContextCompat.getDrawable(app, R.drawable.img_speed_camera_warning)); ((TextView) root.findViewById(R.id.description)).setText(getDescriptionText()); items.add(new BaseBottomSheetItem.Builder().setCustomView(root).create()); } - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - UiUtilities.setupDialogButton(nightMode, rightButton, getDismissButtonType(), R.string.keep_active); - } - @Override protected void onRightBottomButtonClick() { setDialogShowed(); @@ -60,17 +61,17 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { @Override protected void onDismissButtonClickAction() { - app.getSettings().SPEED_CAMERAS_UNINSTALLED.set(true); - app.getSettings().SPEAK_SPEED_CAMERA.set(false); - app.getSettings().SHOW_CAMERAS.set(false); + OsmandPreference speedCamUninstalled = settings.SPEED_CAMERAS_UNINSTALLED; + speedCamUninstalled.set(true); + settings.SPEAK_SPEED_CAMERA.set(false); + settings.SHOW_CAMERAS.set(false); app.getPoiTypes().excludeSpeedCameraPoiType(); - SearchResultMatcher.setSpeedCamerasUninstalled(true); + SearchResultMatcher.speedCamerasUninstalled = true; Fragment targetFragment = getTargetFragment(); - if (targetFragment instanceof OnSpeedCamerasUninstallListener) { - ((OnSpeedCamerasUninstallListener) targetFragment).onSpeedCamerasUninstalled(); + if (targetFragment instanceof OnPreferenceChanged) { + ((OnPreferenceChanged) targetFragment).onPreferenceChanged(speedCamUninstalled.getId()); } setDialogShowed(); - dismiss(); } @Override @@ -83,18 +84,19 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { return R.string.keep_active; } + @Override + protected UiUtilities.DialogButtonType getRightBottomButtonType() { + return getDismissButtonType(); + } + private SpannableString getDescriptionText() { String keepActive = getString(R.string.keep_active); String uninstall = getString(R.string.shared_string_uninstall); String text = getString(R.string.speed_cameras_legal_descr, keepActive, uninstall); - return UiUtilities.setWordsMediumFont(app, text, keepActive, uninstall); + return UiUtilities.createCustomFontSpannable(FontCache.getRobotoMedium(app), text, keepActive, uninstall); } private void setDialogShowed() { app.getSettings().SPEED_CAMERAS_ALERT_SHOWED.set(true); } - - public interface OnSpeedCamerasUninstallListener { - void onSpeedCamerasUninstalled(); - } } diff --git a/OsmAnd/src/net/osmand/plus/mapsource/InputZoomLevelsBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapsource/InputZoomLevelsBottomSheet.java index 3f44454f22..8cf8f99444 100644 --- a/OsmAnd/src/net/osmand/plus/mapsource/InputZoomLevelsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/mapsource/InputZoomLevelsBottomSheet.java @@ -3,6 +3,7 @@ package net.osmand.plus.mapsource; import android.os.Bundle; import android.text.SpannableString; import android.text.Spanned; +import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; @@ -81,7 +82,7 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment { String mapSource = getString(R.string.map_source); String overlayUnderlay = getString(R.string.pref_overlay); String dialogDesr = getString(dialogDescrRes, mapSource, overlayUnderlay); - dialogDescrTv.setText(createSpannableString(dialogDesr, mapSource, overlayUnderlay)); + dialogDescrTv.setText(UiUtilities.createCustomFontSpannable(FontCache.getRobotoMedium(app), dialogDesr, mapSource, overlayUnderlay)); } else { dialogDescrTv.setText(getString(dialogDescrRes)); } @@ -155,23 +156,6 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment { return R.string.shared_string_apply; } - private SpannableString createSpannableString(@NonNull String text, @NonNull String... textToStyle) { - SpannableString spannable = new SpannableString(text); - for (String t : textToStyle) { - try { - int startIndex = text.indexOf(t); - spannable.setSpan( - new CustomTypefaceSpan(FontCache.getRobotoMedium(requireContext())), - startIndex, - startIndex + t.length(), - Spanned.SPAN_INCLUSIVE_INCLUSIVE); - } catch (RuntimeException e) { - LOG.error("Error trying to find index of " + t + " " + e); - } - } - return spannable; - } - private void setSliderDescrRes(int sliderDescrRes) { this.sliderDescrRes = sliderDescrRes; } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index 8bb543ef16..b32addf136 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -890,7 +890,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment String message = String.format(ctx.getString( R.string.quick_actions_delete_text), actionName); SpannableString styledMessage = UiUtilities.createSpannableString( - message, actionName, new StyleSpan(Typeface.BOLD)); + message, new StyleSpan(Typeface.BOLD), actionName); ConfirmationBottomSheet.showInstance(ctx.getSupportFragmentManager(), target, ctx.getString(R.string.quick_actions_delete), styledMessage, diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 673af0c9e1..022cbb8468 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -1256,7 +1256,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC //show "Apply to all profiles" SnackBar String modeName = appMode.toHumanString(); String text = app.getString(R.string.changes_applied_to_profile, modeName); - SpannableString message = UiUtilities.createSpannableString(text, modeName, new StyleSpan(Typeface.BOLD)); + SpannableString message = UiUtilities.createSpannableString(text, new StyleSpan(Typeface.BOLD), modeName); Snackbar snackbar = Snackbar.make(containerView, message, Snackbar.LENGTH_LONG) .setAction(R.string.apply_to_all_profiles, new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index ad87af9077..0878f0a37c 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -29,6 +29,7 @@ import net.osmand.plus.poi.NominatimPoiFilter; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.resources.ResourceManager.ResourceListener; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.search.SearchUICore; @@ -65,10 +66,11 @@ public class QuickSearchHelper implements ResourceListener { public QuickSearchHelper(OsmandApplication app) { this.app = app; - core = new SearchUICore(app.getPoiTypes(), app.getSettings().MAP_PREFERRED_LOCALE.get(), - app.getSettings().MAP_TRANSLITERATE_NAMES.get()); + OsmandSettings settings = app.getSettings(); + core = new SearchUICore(app.getPoiTypes(), settings.MAP_PREFERRED_LOCALE.get(), + settings.MAP_TRANSLITERATE_NAMES.get()); app.getResourceManager().addResourceListener(this); - SearchResultMatcher.setSpeedCamerasUninstalled(app.getSettings().SPEED_CAMERAS_UNINSTALLED.get()); + SearchResultMatcher.speedCamerasUninstalled = settings.SPEED_CAMERAS_UNINSTALLED.get(); } public SearchUICore getCore() { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index 532dd0a245..ab296c4a3f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -2108,8 +2108,8 @@ public class OsmandSettings { public final OsmandPreference SPEAK_SPEED_CAMERA = new BooleanPreference("speak_cameras", false).makeProfile().cache(); public final OsmandPreference SPEAK_TUNNELS = new BooleanPreference("speak_tunnels", false).makeProfile().cache(); - public final OsmandPreference SPEED_CAMERAS_UNINSTALLED = new BooleanPreference("speed_cameras_uninstalled", false).makeGlobal().cache(); - public final OsmandPreference SPEED_CAMERAS_ALERT_SHOWED = new BooleanPreference("speed_cameras_alert_showed", false).makeGlobal().cache(); + public final OsmandPreference SPEED_CAMERAS_UNINSTALLED = new BooleanPreference("speed_cameras_uninstalled", false).makeGlobal(); + public final OsmandPreference SPEED_CAMERAS_ALERT_SHOWED = new BooleanPreference("speed_cameras_alert_showed", false).makeGlobal(); public final OsmandPreference ANNOUNCE_WPT = new BooleanPreference("announce_wpt", true) { @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java index d0ed8f7515..f0da066fbe 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java @@ -16,6 +16,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.ColorInt; @@ -923,14 +924,40 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } } - protected void applyPreferenceWithSnackBar(final String prefId, final Serializable newValue) { + public void setupSpeedCamerasAlert() { + Preference speedCamerasAlert = findPreference(settings.SPEED_CAMERAS_UNINSTALLED.getId()); + speedCamerasAlert.setIcon(getContentIcon(R.drawable.ic_action_alert)); + speedCamerasAlert.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get()); + } + + public void setupPrefRoundedBg(PreferenceViewHolder holder) { + View selectableView = holder.itemView.findViewById(R.id.selectable_list_item); + if (selectableView != null) { + int color = AndroidUtils.getColorFromAttr(app, R.attr.activity_background_color); + int selectedColor = UiUtilities.getColorWithAlpha(getActiveProfileColor(), 0.3f); + + Drawable bgDrawable = getPaintedIcon(R.drawable.rectangle_rounded, color); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + Drawable selectable = getPaintedIcon(R.drawable.ripple_rectangle_rounded, selectedColor); + Drawable[] layers = {bgDrawable, selectable}; + AndroidUtils.setBackground(selectableView, new LayerDrawable(layers)); + } else { + AndroidUtils.setBackground(selectableView, bgDrawable); + } + LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) selectableView.getLayoutParams(); + params.setMargins(params.leftMargin, AndroidUtils.dpToPx(app, 6), params.rightMargin, params.bottomMargin); + } + } + + protected void applyPreferenceWithSnackBar(final String prefId, + final Serializable newValue) { onApplyPreferenceChange(prefId, false, newValue); updateSetting(prefId); View containerView = getView(); if (containerView != null) { String modeName = appMode.toHumanString(); String text = app.getString(R.string.changes_applied_to_profile, modeName); - SpannableString message = UiUtilities.createSpannableString(text, modeName, new StyleSpan(Typeface.BOLD)); + SpannableString message = UiUtilities.createSpannableString(text, new StyleSpan(Typeface.BOLD), modeName); Snackbar snackbar = Snackbar.make(containerView, message, Snackbar.LENGTH_LONG) .setAction(R.string.apply_to_all_profiles, new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java index 8896c159b9..9f3a6439aa 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java @@ -17,7 +17,6 @@ import net.osmand.plus.activities.SettingsGeneralActivity; import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment; import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment.OnSendAnalyticsPrefsUpdate; import net.osmand.plus.dialogs.SpeedCamerasBottomSheet; -import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.preferences.ListPreferenceEx; @@ -25,19 +24,14 @@ import net.osmand.plus.settings.preferences.SwitchPreferenceEx; public class GlobalSettingsFragment extends BaseSettingsFragment - implements OnSendAnalyticsPrefsUpdate, OnPreferenceChanged, - OnSpeedCamerasUninstallListener { + implements OnSendAnalyticsPrefsUpdate, OnPreferenceChanged { public static final String TAG = GlobalSettingsFragment.class.getSimpleName(); private static final String SEND_ANONYMOUS_DATA_PREF_ID = "send_anonymous_data"; private static final String DIALOGS_AND_NOTIFICATIONS_PREF_ID = "dialogs_and_notifications"; - private static final String UNINSTALL_SPEED_CAMERAS_PREF_ID = "uninstall_speed_cameras"; private static final String LEGAL_CATEGORY_ID = "legal"; - private Preference uninstallSpeedCameras; - private PreferenceCategory legalCategory; - @Override protected void setupPreferences() { setupDefaultAppModePref(); @@ -47,12 +41,8 @@ public class GlobalSettingsFragment extends BaseSettingsFragment setupSendAnonymousDataPref(); setupDialogsAndNotificationsPref(); setupEnableProxyPref(); - legalCategory = (PreferenceCategory) findPreference(LEGAL_CATEGORY_ID); - uninstallSpeedCameras = (Preference) findPreference(UNINSTALL_SPEED_CAMERAS_PREF_ID); - uninstallSpeedCameras.setIcon(getPersistentPrefIcon(R.drawable.ic_speed_camera_disabled)); - if (settings.SPEED_CAMERAS_UNINSTALLED.get()) { - onSpeedCamerasUninstalled(); - } + setupLegalCategory(); + setupUninstallSpeedCamerasPref(); } @Override @@ -117,6 +107,9 @@ public class GlobalSettingsFragment extends BaseSettingsFragment app.checkPreferredLocale(); app.restartApp(activity); } + } else if (prefId.equals(settings.SPEED_CAMERAS_UNINSTALLED.getId())) { + setupLegalCategory(); + setupUninstallSpeedCamerasPref(); } } @@ -128,7 +121,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment @Override public boolean onPreferenceClick(Preference preference) { String prefId = preference.getKey(); - if (UNINSTALL_SPEED_CAMERAS_PREF_ID.equals(prefId)) { + if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(prefId)) { FragmentManager fm = getFragmentManager(); if (fm != null) { SpeedCamerasBottomSheet.showInstance(fm, this); @@ -221,11 +214,14 @@ public class GlobalSettingsFragment extends BaseSettingsFragment enableProxy.setIcon(getPersistentPrefIcon(R.drawable.ic_action_proxy)); } - @Override - public void onSpeedCamerasUninstalled() { - if (uninstallSpeedCameras != null && legalCategory != null) { - uninstallSpeedCameras.setVisible(false); - legalCategory.setVisible(false); - } + private void setupLegalCategory() { + PreferenceCategory legalCategory = (PreferenceCategory) findPreference(LEGAL_CATEGORY_ID); + legalCategory.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get()); + } + + private void setupUninstallSpeedCamerasPref() { + Preference uninstallSpeedCameras = (Preference) findPreference(settings.SPEED_CAMERAS_UNINSTALLED.getId()); + uninstallSpeedCameras.setIcon(getActiveIcon(R.drawable.ic_speed_camera_disabled)); + uninstallSpeedCameras.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get()); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java index 273e0f3de2..b7ab4e13ea 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java @@ -77,8 +77,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { recyclerView = root.findViewById(R.id.list); description.setText(UiUtilities.createSpannableString( String.format(getString(R.string.import_complete_description), fileName), - fileName, - new StyleSpan(Typeface.BOLD) + new StyleSpan(Typeface.BOLD), fileName )); btnClose.setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportDuplicatesFragment.java index 6224105fa9..7ea985e19a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportDuplicatesFragment.java @@ -257,8 +257,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View toolbarLayout.setTitle(getString(R.string.shared_string_importing)); description.setText(UiUtilities.createSpannableString( String.format(getString(R.string.importing_from), file.getName()), - file.getName(), - new StyleSpan(Typeface.BOLD) + new StyleSpan(Typeface.BOLD), file.getName() )); progressBar.setVisibility(View.VISIBLE); list.setVisibility(View.GONE); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index 99f1af5f37..bf3df71f48 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -234,8 +234,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment toolbarLayout.setTitle(getString(toolbarTitleRes)); description.setText(UiUtilities.createSpannableString( String.format(getString(descriptionRes), fileName), - fileName, - new StyleSpan(Typeface.BOLD) + new StyleSpan(Typeface.BOLD), fileName )); buttonsContainer.setVisibility(View.GONE); progressBar.setVisibility(View.VISIBLE); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ScreenAlertsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ScreenAlertsFragment.java index 901d0cfdc9..c07f8fca2d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ScreenAlertsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ScreenAlertsFragment.java @@ -6,40 +6,29 @@ import android.os.Build; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; import androidx.preference.SwitchPreferenceCompat; import net.osmand.AndroidUtils; -import net.osmand.plus.OsmandApplication; import net.osmand.plus.dialogs.SpeedCamerasBottomSheet; -import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener; -import net.osmand.plus.helpers.FontCache; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; -import java.lang.ref.WeakReference; import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; -public class ScreenAlertsFragment extends BaseSettingsFragment implements OnSpeedCamerasUninstallListener { +public class ScreenAlertsFragment extends BaseSettingsFragment implements OnPreferenceChanged { public static final String TAG = ScreenAlertsFragment.class.getSimpleName(); private static final String SHOW_ROUTING_ALARMS_INFO = "show_routing_alarms_info"; private static final String SCREEN_ALERTS_IMAGE = "screen_alerts_image"; - private static final String SHOW_CAMERAS = "show_cameras"; - private SwitchPreferenceCompat showCameras; @Override protected void setupPreferences() { @@ -47,19 +36,16 @@ public class ScreenAlertsFragment extends BaseSettingsFragment implements OnSpee SwitchPreferenceCompat showTrafficWarnings = (SwitchPreferenceCompat) findPreference(settings.SHOW_TRAFFIC_WARNINGS.getId()); SwitchPreferenceCompat showPedestrian = (SwitchPreferenceCompat) findPreference(settings.SHOW_PEDESTRIAN.getId()); SwitchPreferenceCompat showTunnels = (SwitchPreferenceCompat) findPreference(settings.SHOW_TUNNELS.getId()); - showCameras = (SwitchPreferenceCompat) findPreference(settings.SHOW_CAMERAS.getId()); showRoutingAlarmsInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); showTrafficWarnings.setIcon(getIcon(R.drawable.list_warnings_traffic_calming)); showPedestrian.setIcon(getIcon(R.drawable.list_warnings_pedestrian)); showTunnels.setIcon(getIcon(R.drawable.list_warnings_tunnel)); - showCameras.setIcon(getIcon(R.drawable.list_warnings_speed_camera)); setupScreenAlertsImage(); + setupShowCamerasPref(); + setupSpeedCamerasAlert(); enableDisablePreferences(settings.SHOW_ROUTING_ALARMS.getModeValue(getSelectedAppMode())); - if (settings.SPEED_CAMERAS_UNINSTALLED.get()) { - onSpeedCamerasUninstalled(); - } } @Override @@ -119,8 +105,8 @@ public class ScreenAlertsFragment extends BaseSettingsFragment implements OnSpee deviceImage.setImageDrawable(getDeviceImage()); warningIcon.setImageDrawable(getWarningIcon()); - } else if (SHOW_CAMERAS.equals(key)) { - setupSpeedCamerasAlert(app, requireMyActivity(), holder, this, isNightMode()); + } else if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(key)) { + setupPrefRoundedBg(holder); } } } @@ -131,10 +117,20 @@ public class ScreenAlertsFragment extends BaseSettingsFragment implements OnSpee Preference routeParametersImage = findPreference(SCREEN_ALERTS_IMAGE); updatePreference(routeParametersImage); } - + if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(preference.getKey())) { + SpeedCamerasBottomSheet.showInstance(requireActivity().getSupportFragmentManager(), this); + } return super.onPreferenceClick(preference); } + @Override + public void onPreferenceChanged(String prefId) { + if (prefId.equals(settings.SPEED_CAMERAS_UNINSTALLED.getId())) { + setupShowCamerasPref(); + setupSpeedCamerasAlert(); + } + } + private void setupScreenAlertsImage() { Preference routeParametersImage = findPreference(SCREEN_ALERTS_IMAGE); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { @@ -163,47 +159,9 @@ public class ScreenAlertsFragment extends BaseSettingsFragment implements OnSpee return null; } - public static void setupSpeedCamerasAlert(@NonNull OsmandApplication app, - @NonNull FragmentActivity activity, - @NonNull PreferenceViewHolder holder, - @Nullable Fragment targetFragment, - boolean nightMode) { - ImageView alertIcon = (ImageView) holder.itemView.findViewById(R.id.alert_icon); - TextView alertTitle = (TextView) holder.itemView.findViewById(R.id.alert_title); - TextView alertSubTitle = (TextView) holder.itemView.findViewById(R.id.alert_subtitle); - LinearLayout alertBg = (LinearLayout) holder.itemView.findViewById(R.id.alert_bg); - - alertBg.setBackgroundDrawable(UiUtilities.getRoundedBackgroundDrawable( - app, - nightMode ? R.color.activity_background_color_dark : R.color.activity_background_color_light, - 6)); - alertIcon.setImageDrawable(app.getUIUtilities().getIcon( - R.drawable.ic_action_alert, - nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light)); - alertTitle.setText(R.string.speed_cameras_alert); - alertTitle.setTypeface(FontCache.getRobotoMedium(app)); - alertSubTitle.setText(R.string.read_more); - alertSubTitle.setTypeface(FontCache.getRobotoMedium(app)); - alertSubTitle.setTextColor(nightMode - ? app.getResources().getColor(R.color.active_color_primary_dark) - : app.getResources().getColor(R.color.active_color_primary_light)); - final WeakReference weakActivity = new WeakReference<>(activity); - final WeakReference weakFragment = new WeakReference<>(targetFragment); - alertSubTitle.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - FragmentActivity a = weakActivity.get(); - if (a != null) { - SpeedCamerasBottomSheet.showInstance(a.getSupportFragmentManager(), weakFragment.get()); - } - } - }); - } - - @Override - public void onSpeedCamerasUninstalled() { - if (showCameras != null) { - showCameras.setVisible(false); - } + private void setupShowCamerasPref() { + SwitchPreferenceCompat showCameras = (SwitchPreferenceCompat) findPreference(settings.SHOW_CAMERAS.getId()); + showCameras.setIcon(getIcon(R.drawable.list_warnings_speed_camera)); + showCameras.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get()); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java index 11c1f6b72b..24a1b817d4 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VoiceAnnouncesFragment.java @@ -14,9 +14,10 @@ import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; +import androidx.preference.SwitchPreferenceCompat; import net.osmand.AndroidUtils; -import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener; +import net.osmand.plus.dialogs.SpeedCamerasBottomSheet; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; @@ -34,10 +35,9 @@ import static net.osmand.plus.settings.backend.OsmandSettings.VOICE_PROVIDER_NOT import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; import static net.osmand.plus.activities.SettingsNavigationActivity.MORE_VALUE; -public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnSpeedCamerasUninstallListener { +public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPreferenceChanged { public static final String TAG = VoiceAnnouncesFragment.class.getSimpleName(); - private Preference speakCamera; @Override protected void createToolbar(LayoutInflater inflater, View view) { @@ -98,10 +98,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnSp setupInterruptMusicPref(); } enableDisablePreferences(!settings.VOICE_MUTE.getModeValue(getSelectedAppMode())); - speakCamera = findPreference(settings.SPEAK_SPEED_CAMERA.getId()); - if (settings.SPEED_CAMERAS_UNINSTALLED.get()) { - onSpeedCamerasUninstalled(); - } + setupSpeakCamerasPref(); + setupSpeedCamerasAlert(); } private void setupSpeedLimitExceedPref() { @@ -231,8 +229,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnSp Object currentValue = ((ListPreferenceEx) preference).getValue(); imageView.setEnabled(preference.isEnabled() && !OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(currentValue)); } - } else if (settings.SPEAK_SPEED_CAMERA.getId().equals(preference.getKey())) { - ScreenAlertsFragment.setupSpeedCamerasAlert(app, requireMyActivity(), holder, this, isNightMode()); + } else if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(preference.getKey())) { + setupPrefRoundedBg(holder); } } @@ -296,9 +294,23 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnSp } @Override - public void onSpeedCamerasUninstalled() { - if (speakCamera != null) { - speakCamera.setVisible(false); + public boolean onPreferenceClick(Preference preference) { + if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(preference.getKey())) { + SpeedCamerasBottomSheet.showInstance(requireActivity().getSupportFragmentManager(), this); + } + return super.onPreferenceClick(preference); + } + + @Override + public void onPreferenceChanged(String prefId) { + if (prefId.equals(settings.SPEED_CAMERAS_UNINSTALLED.getId())) { + setupSpeakCamerasPref(); + setupSpeedCamerasAlert(); } } + + private void setupSpeakCamerasPref() { + SwitchPreferenceCompat showCameras = (SwitchPreferenceCompat) findPreference(settings.SPEAK_SPEED_CAMERA.getId()); + showCameras.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get()); + } } \ No newline at end of file From 4009946a32ccd8500e0e535875d5a4baf2d0d0df Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 17 Jun 2020 12:40:31 +0300 Subject: [PATCH 6/9] small refactor --- OsmAnd/res/layout/bottom_sheet_speed_cameras.xml | 2 +- OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/layout/bottom_sheet_speed_cameras.xml b/OsmAnd/res/layout/bottom_sheet_speed_cameras.xml index 6fc553118f..c00d4a72a5 100644 --- a/OsmAnd/res/layout/bottom_sheet_speed_cameras.xml +++ b/OsmAnd/res/layout/bottom_sheet_speed_cameras.xml @@ -8,7 +8,7 @@ android:orientation="vertical" android:padding="@dimen/content_padding"> - Date: Thu, 18 Jun 2020 12:29:59 +0300 Subject: [PATCH 7/9] refactor speed camera restriction --- .../osmand/binary/BinaryMapPoiReaderAdapter.java | 4 ++++ .../main/java/net/osmand/osm/AbstractPoiType.java | 8 ++++++++ .../src/main/java/net/osmand/osm/MapPoiTypes.java | 10 ++++------ .../main/java/net/osmand/search/SearchUICore.java | 13 ++++--------- OsmAnd/src/net/osmand/plus/AppInitializer.java | 3 ++- .../plus/dialogs/SpeedCamerasBottomSheet.java | 7 ++----- .../net/osmand/plus/search/QuickSearchHelper.java | 1 - .../search/QuickSearchSubCategoriesFragment.java | 7 +++++++ 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java index aa51de0c4b..a080b25851 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java @@ -715,6 +715,10 @@ public class BinaryMapPoiReaderAdapter { am.setRoutePoint(arp); } } + PoiType poiType = poiTypes.getPoiTypeByKeyInCategory(am.getType(), am.getSubType()); + if (poiType != null && poiType.isForbidden()) { + return null; + } return am; case OsmandOdb.OsmAndPoiBoxDataAtom.DX_FIELD_NUMBER: x = (codedIS.readSInt32() + (px << (24 - zoom))) << 7; diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java b/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java index 5a8d801d25..3d9ae43b66 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java @@ -21,6 +21,7 @@ public abstract class AbstractPoiType { private String synonyms; private String enTranslation; private String translation; + private boolean isForbidden; public AbstractPoiType(String keyName, MapPoiTypes registry) { this.keyName = keyName; @@ -67,6 +68,13 @@ public abstract class AbstractPoiType { return this instanceof PoiType && this.isAdditional(); } + public void setForbidden(boolean forbidden) { + isForbidden = forbidden; + } + + public boolean isForbidden() { + return isForbidden; + } public String getTranslation() { if(translation == null) { diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index d0c941a898..9f6b42933e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -946,13 +946,11 @@ public class MapPoiTypes { } } - public void excludeSpeedCameraPoiType() { + public void forbidPoiType(String keyName) { for (PoiCategory category : categories) { - Iterator poiIter = category.getPoiTypes().iterator(); - while (poiIter.hasNext()) { - PoiType poiType = poiIter.next(); - if ("speed_camera".equals(poiType.getKeyName())) { - poiIter.remove(); + for (PoiType poiType : category.getPoiTypes()) { + if (keyName.equals(poiType.getKeyName())) { + poiType.setForbidden(true); } } } diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index 1143a2965b..53c035fdaa 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -657,8 +657,6 @@ public class SearchUICore { private List exportedObjects; private List exportedCities; - public static boolean speedCamerasUninstalled = false; - public SearchResultMatcher(ResultMatcher matcher, SearchPhrase phrase, int request, AtomicInteger requestNumber, int totalLimit) { this.matcher = matcher; @@ -736,7 +734,7 @@ public class SearchUICore { @Override public boolean publish(SearchResult object) { - if (speedCamerasUninstalled && isSpeedCameraObject(object.object)) { + if (isPoiTypeForbidden(object.object)) { return false; } if (phrase != null && object.otherNames != null && !phrase.getFirstUnknownNameStringMatcher().matches(object.localeName)) { @@ -893,14 +891,11 @@ public class SearchUICore { return json; } - private boolean isSpeedCameraObject(Object object) { - String key = ""; + private boolean isPoiTypeForbidden(Object object) { if (object instanceof PoiType) { - key = ((PoiType) object).getKeyName(); - } else if (object instanceof Amenity) { - key = ((Amenity) object).getSubType(); + return ((PoiType) object).isForbidden(); } - return "speed_camera".equals(key); + return false; } } diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index e07399832c..f7c1d89aba 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -86,6 +86,7 @@ import java.util.Random; import btools.routingapp.BRouterServiceConnection; import static net.osmand.plus.AppVersionUpgradeOnInit.LAST_APP_VERSION; +import static net.osmand.plus.dialogs.SpeedCamerasBottomSheet.SPEED_CAMERA_KEY_NAME; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn; @@ -407,7 +408,7 @@ public class AppInitializer implements IProgress { } }); if (app.getSettings().SPEED_CAMERAS_UNINSTALLED.get()) { - app.getPoiTypes().excludeSpeedCameraPoiType(); + app.getPoiTypes().forbidPoiType(SPEED_CAMERA_KEY_NAME); } } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java index dc2b01fcb8..cd6b8f487a 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java @@ -8,7 +8,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -21,12 +20,11 @@ import net.osmand.plus.helpers.FontCache; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; import net.osmand.plus.settings.fragments.OnPreferenceChanged; -import net.osmand.plus.widgets.style.CustomTypefaceSpan; -import net.osmand.search.SearchUICore.SearchResultMatcher; public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { public static final String TAG = SpeedCamerasBottomSheet.class.getName(); + public static final String SPEED_CAMERA_KEY_NAME = "speed_camera"; private OsmandApplication app; private OsmandSettings settings; @@ -65,8 +63,7 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { speedCamUninstalled.set(true); settings.SPEAK_SPEED_CAMERA.set(false); settings.SHOW_CAMERAS.set(false); - app.getPoiTypes().excludeSpeedCameraPoiType(); - SearchResultMatcher.speedCamerasUninstalled = true; + app.getPoiTypes().forbidPoiType(SPEED_CAMERA_KEY_NAME); Fragment targetFragment = getTargetFragment(); if (targetFragment instanceof OnPreferenceChanged) { ((OnPreferenceChanged) targetFragment).onPreferenceChanged(speedCamUninstalled.getId()); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index 0878f0a37c..55da1967d0 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -70,7 +70,6 @@ public class QuickSearchHelper implements ResourceListener { core = new SearchUICore(app.getPoiTypes(), settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()); app.getResourceManager().addResourceListener(this); - SearchResultMatcher.speedCamerasUninstalled = settings.SPEED_CAMERAS_UNINSTALLED.get(); } public SearchUICore getCore() { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java index 09777e794d..f7b58f6ab6 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -86,6 +87,12 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment { acceptedCategories = new HashSet<>(savedInstanceState.getStringArrayList(ACCEPTED_CATEGORIES_KEY)); } poiTypeList = new ArrayList<>(poiCategory.getPoiTypes()); + Iterator iter = poiTypeList.iterator(); + while (iter.hasNext()) { + if (iter.next().isForbidden()) { + iter.remove(); + } + } Collections.sort(poiTypeList, new Comparator() { @Override public int compare(PoiType poiType, PoiType t1) { From 18074b0dfcd2f680c0ca0c3a8c8796f41399ee49 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Thu, 18 Jun 2020 13:38:24 +0300 Subject: [PATCH 8/9] small refactor --- .../java/net/osmand/binary/BinaryMapPoiReaderAdapter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java index a080b25851..5c196ebd89 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java @@ -715,10 +715,6 @@ public class BinaryMapPoiReaderAdapter { am.setRoutePoint(arp); } } - PoiType poiType = poiTypes.getPoiTypeByKeyInCategory(am.getType(), am.getSubType()); - if (poiType != null && poiType.isForbidden()) { - return null; - } return am; case OsmandOdb.OsmAndPoiBoxDataAtom.DX_FIELD_NUMBER: x = (codedIS.readSInt32() + (px << (24 - zoom))) << 7; @@ -774,6 +770,10 @@ public class BinaryMapPoiReaderAdapter { } } subtype = poiTypes.replaceDeprecatedSubtype(type, subtype); + PoiType poiType = poiTypes.getPoiTypeByKeyInCategory(type, subtype); + if (poiType != null && poiType.isForbidden()) { + return null; + } if (req.poiTypeFilter == null || req.poiTypeFilter.accept(type, subtype)) { if (amenityType == null) { amenityType = type; From c20e096cdade8332c11e2c1114e68e999f196b57 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 19 Jun 2020 10:07:46 +0300 Subject: [PATCH 9/9] refactor speed cameras hiding --- .../binary/BinaryMapPoiReaderAdapter.java | 8 +-- .../java/net/osmand/osm/AbstractPoiType.java | 9 --- .../main/java/net/osmand/osm/MapPoiTypes.java | 16 ++--- .../main/java/net/osmand/osm/PoiFilter.java | 8 ++- .../java/net/osmand/search/SearchUICore.java | 11 ---- OsmAnd/res/values/strings.xml | 2 + .../src/net/osmand/plus/AppInitializer.java | 5 +- OsmAnd/src/net/osmand/plus/UiUtilities.java | 15 +++-- .../plus/dialogs/SpeedCamerasBottomSheet.java | 13 +--- ...eedCamerasUninstallRestartBottomSheet.java | 64 +++++++++++++++++++ .../plus/helpers/SearchHistoryHelper.java | 3 + .../QuickSearchSubCategoriesFragment.java | 6 -- .../plus/settings/backend/OsmandSettings.java | 10 +++ 13 files changed, 108 insertions(+), 62 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasUninstallRestartBottomSheet.java diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java index 5c196ebd89..4e8441a1bb 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java @@ -692,10 +692,11 @@ public class BinaryMapPoiReaderAdapter { StringBuilder retValue = new StringBuilder(); PoiCategory amenityType = null; LinkedList textTags = null; + boolean isForbidden = false; while (true) { int t = codedIS.readTag(); int tag = WireFormat.getTagFieldNumber(t); - if (amenityType == null && (tag > OsmandOdb.OsmAndPoiBoxDataAtom.CATEGORIES_FIELD_NUMBER || tag == 0)) { + if (amenityType == null && (tag > OsmandOdb.OsmAndPoiBoxDataAtom.CATEGORIES_FIELD_NUMBER || tag == 0) || isForbidden) { codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); return null; } @@ -770,10 +771,7 @@ public class BinaryMapPoiReaderAdapter { } } subtype = poiTypes.replaceDeprecatedSubtype(type, subtype); - PoiType poiType = poiTypes.getPoiTypeByKeyInCategory(type, subtype); - if (poiType != null && poiType.isForbidden()) { - return null; - } + isForbidden = poiTypes.isKeyNameForbidden(subtype); if (req.poiTypeFilter == null || req.poiTypeFilter.accept(type, subtype)) { if (amenityType == null) { amenityType = type; diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java b/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java index 3d9ae43b66..19cb42f350 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java @@ -21,7 +21,6 @@ public abstract class AbstractPoiType { private String synonyms; private String enTranslation; private String translation; - private boolean isForbidden; public AbstractPoiType(String keyName, MapPoiTypes registry) { this.keyName = keyName; @@ -68,14 +67,6 @@ public abstract class AbstractPoiType { return this instanceof PoiType && this.isAdditional(); } - public void setForbidden(boolean forbidden) { - isForbidden = forbidden; - } - - public boolean isForbidden() { - return isForbidden; - } - public String getTranslation() { if(translation == null) { translation = registry.getTranslation(this); diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 9f6b42933e..be3644ab90 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -34,6 +35,7 @@ public class MapPoiTypes { private static final Log log = PlatformUtil.getLog(MapRenderingTypes.class); private String resourceName; private List categories = new ArrayList(); + private Set forbiddenKeyNames = new HashSet<>(); private PoiCategory otherCategory; private PoiCategory otherMapCategory; @@ -946,13 +948,11 @@ public class MapPoiTypes { } } - public void forbidPoiType(String keyName) { - for (PoiCategory category : categories) { - for (PoiType poiType : category.getPoiTypes()) { - if (keyName.equals(poiType.getKeyName())) { - poiType.setForbidden(true); - } - } - } + public void setForbiddenKeyNames(Set forbiddenKeyNames) { + this.forbiddenKeyNames = forbiddenKeyNames; + } + + public boolean isKeyNameForbidden(String key) { + return forbiddenKeyNames.contains(key); } } diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java b/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java index fbb5fddca7..12bbaa13f0 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java @@ -30,13 +30,14 @@ public class PoiFilter extends AbstractPoiType { List npoiTypes = null; Map nmap = null; for (PoiType poiType : poiTypesToAdd.values()) { - if (!map.containsKey(poiType.getKeyName())) { + String keyName = poiType.getKeyName(); + if (!map.containsKey(keyName) && !registry.isKeyNameForbidden(keyName)) { if (npoiTypes == null) { npoiTypes = new ArrayList(this.poiTypes); nmap = new LinkedHashMap<>(map); } npoiTypes.add(poiType); - nmap.put(poiType.getKeyName(), poiType); + nmap.put(keyName, poiType); } } if (npoiTypes != null) { @@ -46,6 +47,9 @@ public class PoiFilter extends AbstractPoiType { } public void addPoiType(PoiType type) { + if (registry.isKeyNameForbidden(type.keyName)) { + return; + } if (!map.containsKey(type.getKeyName())) { poiTypes.add(type); map.put(type.getKeyName(), type); diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index 53c035fdaa..46b0ee4e82 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -11,7 +11,6 @@ import net.osmand.data.MapObject; import net.osmand.data.Street; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; -import net.osmand.osm.PoiType; import net.osmand.search.core.CustomSearchPoiFilter; import net.osmand.search.core.ObjectType; import net.osmand.search.core.SearchCoreAPI; @@ -734,9 +733,6 @@ public class SearchUICore { @Override public boolean publish(SearchResult object) { - if (isPoiTypeForbidden(object.object)) { - return false; - } if (phrase != null && object.otherNames != null && !phrase.getFirstUnknownNameStringMatcher().matches(object.localeName)) { for (String s : object.otherNames) { if (phrase.getFirstUnknownNameStringMatcher().matches(s)) { @@ -890,13 +886,6 @@ public class SearchUICore { } return json; } - - private boolean isPoiTypeForbidden(Object object) { - if (object instanceof PoiType) { - return ((PoiType) object).isForbidden(); - } - return false; - } } private enum ResultCompareStep { diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 6c1fdd47f7..05f81e943d 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,8 @@ Thx - Hardy --> + Uninstall and Restart + Restart is needed to completely delete speed camera data. A toggle to show or hide the Mapillary layer on the map. Show Mapillary Hide Mapillary diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index f7c1d89aba..9e06a56d20 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -86,7 +86,6 @@ import java.util.Random; import btools.routingapp.BRouterServiceConnection; import static net.osmand.plus.AppVersionUpgradeOnInit.LAST_APP_VERSION; -import static net.osmand.plus.dialogs.SpeedCamerasBottomSheet.SPEED_CAMERA_KEY_NAME; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn; @@ -303,6 +302,7 @@ public class AppInitializer implements IProgress { } private void initPoiTypes() { + app.poiTypes.setForbiddenKeyNames(app.osmandSettings.getForbiddenPoiKeyNames()); if (app.getAppPath(IndexConstants.SETTINGS_DIR + "poi_types.xml").exists()) { app.poiTypes.init(app.getAppPath(IndexConstants.SETTINGS_DIR + "poi_types.xml").getAbsolutePath()); } else { @@ -407,9 +407,6 @@ public class AppInitializer implements IProgress { return null; } }); - if (app.getSettings().SPEED_CAMERAS_UNINSTALLED.get()) { - app.getPoiTypes().forbidPoiType(SPEED_CAMERA_KEY_NAME); - } } public void onCreateApplication() { diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 0063d9aeea..c60117f58c 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -1,13 +1,11 @@ package net.osmand.plus; import android.content.Context; -import android.content.Intent; import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; -import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.RippleDrawable; import android.hardware.Sensor; @@ -15,8 +13,6 @@ import android.hardware.SensorManager; import android.os.Build; import android.text.SpannableString; import android.text.Spanned; -import android.text.method.LinkMovementMethod; -import android.text.style.ClickableSpan; import android.text.style.StyleSpan; import android.view.Gravity; import android.view.LayoutInflater; @@ -38,7 +34,6 @@ import androidx.annotation.StringRes; import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.view.ContextThemeWrapper; import androidx.appcompat.widget.ListPopupWindow; -import androidx.appcompat.widget.AppCompatButton; import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; @@ -55,7 +50,6 @@ import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.data.LatLon; -import net.osmand.plus.helpers.FontCache; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.views.DirectionDrawable; import net.osmand.plus.widgets.TextViewEx; @@ -66,7 +60,6 @@ import org.apache.commons.logging.Log; import java.util.ArrayList; import java.util.List; -import java.lang.ref.WeakReference; import gnu.trove.map.hash.TLongObjectHashMap; @@ -87,6 +80,7 @@ public class UiUtilities { public enum DialogButtonType { PRIMARY, SECONDARY, + SECONDARY_HARMFUL, STROKED } @@ -633,6 +627,13 @@ public class UiUtilities { AndroidUtils.setBackground(ctx, buttonView, nightMode, R.drawable.dlg_btn_secondary_light, R.drawable.dlg_btn_secondary_dark); textAndIconColorResId = nightMode ? R.color.dlg_btn_secondary_text_dark : R.color.dlg_btn_secondary_text_light; break; + case SECONDARY_HARMFUL: + if (v21) { + AndroidUtils.setBackground(ctx, buttonContainer, nightMode, R.drawable.ripple_solid_light, R.drawable.ripple_solid_dark); + } + AndroidUtils.setBackground(ctx, buttonView, nightMode, R.drawable.dlg_btn_secondary_light, R.drawable.dlg_btn_secondary_dark); + textAndIconColorResId = R.color.color_osm_edit_delete; + break; case STROKED: if (v21) { AndroidUtils.setBackground(ctx, buttonContainer, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java index cd6b8f487a..fac4230c77 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java @@ -18,8 +18,6 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; -import net.osmand.plus.settings.fragments.OnPreferenceChanged; public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { @@ -59,14 +57,9 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { @Override protected void onDismissButtonClickAction() { - OsmandPreference speedCamUninstalled = settings.SPEED_CAMERAS_UNINSTALLED; - speedCamUninstalled.set(true); - settings.SPEAK_SPEED_CAMERA.set(false); - settings.SHOW_CAMERAS.set(false); - app.getPoiTypes().forbidPoiType(SPEED_CAMERA_KEY_NAME); - Fragment targetFragment = getTargetFragment(); - if (targetFragment instanceof OnPreferenceChanged) { - ((OnPreferenceChanged) targetFragment).onPreferenceChanged(speedCamUninstalled.getId()); + FragmentManager fm = getFragmentManager(); + if (fm != null) { + SpeedCamerasUninstallRestartBottomSheet.showInstance(fm); } setDialogShowed(); } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasUninstallRestartBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasUninstallRestartBottomSheet.java new file mode 100644 index 0000000000..8a5271cec9 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasUninstallRestartBottomSheet.java @@ -0,0 +1,64 @@ +package net.osmand.plus.dialogs; + +import android.app.Activity; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.fragment.app.FragmentManager; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities.DialogButtonType; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.settings.backend.OsmandSettings; + +public class SpeedCamerasUninstallRestartBottomSheet extends MenuBottomSheetDialogFragment { + + public static final String TAG = SpeedCamerasUninstallRestartBottomSheet.class.getSimpleName(); + + public static void showInstance(@NonNull FragmentManager fm) { + if (!fm.isStateSaved()) { + SpeedCamerasUninstallRestartBottomSheet bottomSheet = new SpeedCamerasUninstallRestartBottomSheet(); + bottomSheet.show(fm, TAG); + } + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + items.add(new TitleItem(getString(R.string.uninstall_speed_cameras))); + items.add(new LongDescriptionItem(getString(R.string.speed_cameras_restart_descr))); + } + + @Override + protected int getDismissButtonTextId() { + return R.string.shared_string_cancel; + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_uninstall_and_restart; + } + + @Override + protected DialogButtonType getRightBottomButtonType() { + return DialogButtonType.SECONDARY_HARMFUL; + } + + @Override + protected void onRightBottomButtonClick() { + OsmandApplication app = requiredMyApplication(); + OsmandSettings settings = app.getSettings(); + settings.SPEED_CAMERAS_UNINSTALLED.set(true); + settings.SPEAK_SPEED_CAMERA.set(false); + settings.SHOW_CAMERAS.set(false); + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + MapActivity.doRestart(activity); + } else { + android.os.Process.killProcess(android.os.Process.myPid()); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java index fb708bf8fd..828d79dbf0 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java @@ -428,6 +428,9 @@ public class SearchHistoryHelper { do { String name = query.getString(0); PointDescription p = PointDescription.deserializeFromString(name, new LatLon(query.getDouble(1), query.getDouble(2))); + if (context.getPoiTypes().isKeyNameForbidden(p.getName())){ + query.moveToNext(); + } HistoryEntry e = new HistoryEntry(query.getDouble(1), query.getDouble(2), p); long time = query.getLong(3); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java index f7b58f6ab6..e61b4631c2 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java @@ -87,12 +87,6 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment { acceptedCategories = new HashSet<>(savedInstanceState.getStringArrayList(ACCEPTED_CATEGORIES_KEY)); } poiTypeList = new ArrayList<>(poiCategory.getPoiTypes()); - Iterator iter = poiTypeList.iterator(); - while (iter.hasNext()) { - if (iter.next().isForbidden()) { - iter.remove(); - } - } Collections.sort(poiTypeList, new Comparator() { @Override public int compare(PoiType poiType, PoiType t1) { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index ab296c4a3f..9bc2bf0c88 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -74,6 +74,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -87,6 +88,7 @@ import java.util.StringTokenizer; import static net.osmand.aidlapi.OsmAndCustomizationConstants.CONFIGURE_MAP_ITEM_ID_SCHEME; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_ITEM_ID_SCHEME; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ACTIONS; +import static net.osmand.plus.dialogs.SpeedCamerasBottomSheet.SPEED_CAMERA_KEY_NAME; public class OsmandSettings { @@ -2111,6 +2113,14 @@ public class OsmandSettings { public final OsmandPreference SPEED_CAMERAS_UNINSTALLED = new BooleanPreference("speed_cameras_uninstalled", false).makeGlobal(); public final OsmandPreference SPEED_CAMERAS_ALERT_SHOWED = new BooleanPreference("speed_cameras_alert_showed", false).makeGlobal(); + public Set getForbiddenPoiKeyNames() { + Set keyNames = new HashSet<>(); + if (SPEED_CAMERAS_UNINSTALLED.get()) { + keyNames.add(SPEED_CAMERA_KEY_NAME); + } + return keyNames; + } + public final OsmandPreference ANNOUNCE_WPT = new BooleanPreference("announce_wpt", true) { @Override protected boolean setValue(Object prefs, Boolean val) {