hide speed cameras from ui
This commit is contained in:
parent
678306870b
commit
66413f856e
6 changed files with 104 additions and 47 deletions
|
@ -37,6 +37,7 @@ import net.osmand.data.PointDescription;
|
||||||
import net.osmand.data.QuadRect;
|
import net.osmand.data.QuadRect;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
|
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
|
import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
|
||||||
|
@ -569,6 +570,9 @@ public class MapActivityActions implements DialogProvider {
|
||||||
if (targets.hasTooLongDistanceToNavigate()) {
|
if (targets.hasTooLongDistanceToNavigate()) {
|
||||||
app.showToastMessage(R.string.route_is_too_long_v2);
|
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) {
|
public void recalculateRoute(boolean showDialog) {
|
||||||
|
|
|
@ -7,6 +7,9 @@ import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -20,9 +23,10 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
public static final String TAG = SpeedCamerasBottomSheet.class.getName();
|
public static final String TAG = SpeedCamerasBottomSheet.class.getName();
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
|
||||||
public static void showInstance(@NonNull FragmentManager fm) {
|
public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment) {
|
||||||
if (!fm.isStateSaved()) {
|
if (!fm.isStateSaved()) {
|
||||||
SpeedCamerasBottomSheet bottomSheet = new SpeedCamerasBottomSheet();
|
SpeedCamerasBottomSheet bottomSheet = new SpeedCamerasBottomSheet();
|
||||||
|
bottomSheet.setTargetFragment(targetFragment, 0);
|
||||||
bottomSheet.show(fm, TAG);
|
bottomSheet.show(fm, TAG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,19 +40,34 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
View root = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_speed_cameras, null);
|
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());
|
((TextView) root.findViewById(R.id.description)).setText(getDescriptionText());
|
||||||
items.add(new BaseBottomSheetItem.Builder().setCustomView(root).create());
|
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
|
@Override
|
||||||
protected void onRightBottomButtonClick() {
|
protected void onRightBottomButtonClick() {
|
||||||
super.onRightBottomButtonClick();
|
setDialogShowed();
|
||||||
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDismissButtonClickAction() {
|
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
|
@Override
|
||||||
|
@ -67,4 +86,12 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
String text = getString(R.string.speed_cameras_legal_descr, keepActive, uninstall);
|
String text = getString(R.string.speed_cameras_legal_descr, keepActive, uninstall);
|
||||||
return UiUtilities.setWordsMediumFont(app, text, 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2108,6 +2108,9 @@ public class OsmandSettings {
|
||||||
public final OsmandPreference<Boolean> SPEAK_SPEED_CAMERA = new BooleanPreference("speak_cameras", false).makeProfile().cache();
|
public final OsmandPreference<Boolean> SPEAK_SPEED_CAMERA = new BooleanPreference("speak_cameras", false).makeProfile().cache();
|
||||||
public final OsmandPreference<Boolean> SPEAK_TUNNELS = new BooleanPreference("speak_tunnels", false).makeProfile().cache();
|
public final OsmandPreference<Boolean> SPEAK_TUNNELS = new BooleanPreference("speak_tunnels", false).makeProfile().cache();
|
||||||
|
|
||||||
|
public final OsmandPreference<Boolean> SPEED_CAMERAS_UNINSTALLED = new BooleanPreference("speed_cameras_uninstalled", false).makeGlobal().cache();
|
||||||
|
public final OsmandPreference<Boolean> SPEED_CAMERAS_ALERT_SHOWED = new BooleanPreference("speed_cameras_alert_showed", false).makeGlobal().cache();
|
||||||
|
|
||||||
public final OsmandPreference<Boolean> ANNOUNCE_WPT = new BooleanPreference("announce_wpt", true) {
|
public final OsmandPreference<Boolean> ANNOUNCE_WPT = new BooleanPreference("announce_wpt", true) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean setValue(Object prefs, Boolean val) {
|
protected boolean setValue(Object prefs, Boolean val) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.widget.ImageView;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
import androidx.preference.SwitchPreferenceCompat;
|
import androidx.preference.SwitchPreferenceCompat;
|
||||||
|
|
||||||
|
@ -14,20 +15,28 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.SettingsGeneralActivity;
|
import net.osmand.plus.activities.SettingsGeneralActivity;
|
||||||
import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment;
|
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;
|
||||||
|
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
||||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
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();
|
public static final String TAG = GlobalSettingsFragment.class.getSimpleName();
|
||||||
|
|
||||||
private static final String SEND_ANONYMOUS_DATA_PREF_ID = "send_anonymous_data";
|
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 DIALOGS_AND_NOTIFICATIONS_PREF_ID = "dialogs_and_notifications";
|
||||||
private static final String UNINSTALL_SPEED_CAMERAS_PREF_ID = "uninstall_speed_cameras";
|
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
|
@Override
|
||||||
protected void setupPreferences() {
|
protected void setupPreferences() {
|
||||||
|
@ -38,7 +47,12 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send
|
||||||
setupSendAnonymousDataPref();
|
setupSendAnonymousDataPref();
|
||||||
setupDialogsAndNotificationsPref();
|
setupDialogsAndNotificationsPref();
|
||||||
setupEnableProxyPref();
|
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
|
@Override
|
||||||
|
@ -117,7 +131,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send
|
||||||
if (UNINSTALL_SPEED_CAMERAS_PREF_ID.equals(prefId)) {
|
if (UNINSTALL_SPEED_CAMERAS_PREF_ID.equals(prefId)) {
|
||||||
FragmentManager fm = getFragmentManager();
|
FragmentManager fm = getFragmentManager();
|
||||||
if (fm != null) {
|
if (fm != null) {
|
||||||
SpeedCamerasBottomSheet.showInstance(fm);
|
SpeedCamerasBottomSheet.showInstance(fm, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.onPreferenceClick(preference);
|
return super.onPreferenceClick(preference);
|
||||||
|
@ -207,8 +221,11 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send
|
||||||
enableProxy.setIcon(getPersistentPrefIcon(R.drawable.ic_action_proxy));
|
enableProxy.setIcon(getPersistentPrefIcon(R.drawable.ic_action_proxy));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupUninstallSpeedCamerasPref() {
|
@Override
|
||||||
Preference uninstallSpeedCameras = (Preference) findPreference(UNINSTALL_SPEED_CAMERAS_PREF_ID);
|
public void onSpeedCamerasUninstalled() {
|
||||||
uninstallSpeedCameras.setIcon(getPersistentPrefIcon(R.drawable.ic_speed_camera_disabled));
|
if (uninstallSpeedCameras != null && legalCategory != null) {
|
||||||
|
uninstallSpeedCameras.setVisible(false);
|
||||||
|
legalCategory.setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,8 +9,11 @@ import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.SwitchCompat;
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
@ -19,6 +22,7 @@ import androidx.preference.SwitchPreferenceCompat;
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet;
|
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet;
|
||||||
|
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener;
|
||||||
import net.osmand.plus.helpers.FontCache;
|
import net.osmand.plus.helpers.FontCache;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -28,30 +32,34 @@ import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR;
|
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();
|
public static final String TAG = ScreenAlertsFragment.class.getSimpleName();
|
||||||
|
|
||||||
private static final String SHOW_ROUTING_ALARMS_INFO = "show_routing_alarms_info";
|
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 SCREEN_ALERTS_IMAGE = "screen_alerts_image";
|
||||||
private static final String SHOW_CAMERAS = "show_cameras";
|
private static final String SHOW_CAMERAS = "show_cameras";
|
||||||
|
private SwitchPreferenceCompat showCameras;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupPreferences() {
|
protected void setupPreferences() {
|
||||||
Preference showRoutingAlarmsInfo = findPreference(SHOW_ROUTING_ALARMS_INFO);
|
Preference showRoutingAlarmsInfo = findPreference(SHOW_ROUTING_ALARMS_INFO);
|
||||||
SwitchPreferenceCompat showTrafficWarnings = (SwitchPreferenceCompat) findPreference(settings.SHOW_TRAFFIC_WARNINGS.getId());
|
SwitchPreferenceCompat showTrafficWarnings = (SwitchPreferenceCompat) findPreference(settings.SHOW_TRAFFIC_WARNINGS.getId());
|
||||||
SwitchPreferenceCompat showPedestrian = (SwitchPreferenceCompat) findPreference(settings.SHOW_PEDESTRIAN.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());
|
SwitchPreferenceCompat showTunnels = (SwitchPreferenceCompat) findPreference(settings.SHOW_TUNNELS.getId());
|
||||||
|
showCameras = (SwitchPreferenceCompat) findPreference(settings.SHOW_CAMERAS.getId());
|
||||||
|
|
||||||
showRoutingAlarmsInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
|
showRoutingAlarmsInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
|
||||||
showTrafficWarnings.setIcon(getIcon(R.drawable.list_warnings_traffic_calming));
|
showTrafficWarnings.setIcon(getIcon(R.drawable.list_warnings_traffic_calming));
|
||||||
showPedestrian.setIcon(getIcon(R.drawable.list_warnings_pedestrian));
|
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));
|
showTunnels.setIcon(getIcon(R.drawable.list_warnings_tunnel));
|
||||||
|
showCameras.setIcon(getIcon(R.drawable.list_warnings_speed_camera));
|
||||||
|
|
||||||
setupScreenAlertsImage();
|
setupScreenAlertsImage();
|
||||||
enableDisablePreferences(settings.SHOW_ROUTING_ALARMS.getModeValue(getSelectedAppMode()));
|
enableDisablePreferences(settings.SHOW_ROUTING_ALARMS.getModeValue(getSelectedAppMode()));
|
||||||
|
if (settings.SPEED_CAMERAS_UNINSTALLED.get()) {
|
||||||
|
onSpeedCamerasUninstalled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -112,7 +120,7 @@ public class ScreenAlertsFragment extends BaseSettingsFragment {
|
||||||
deviceImage.setImageDrawable(getDeviceImage());
|
deviceImage.setImageDrawable(getDeviceImage());
|
||||||
warningIcon.setImageDrawable(getWarningIcon());
|
warningIcon.setImageDrawable(getWarningIcon());
|
||||||
} else if (SHOW_CAMERAS.equals(key)) {
|
} 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;
|
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);
|
ImageView alertIcon = (ImageView) holder.itemView.findViewById(R.id.alert_icon);
|
||||||
TextView alertTitle = (TextView) holder.itemView.findViewById(R.id.alert_title);
|
TextView alertTitle = (TextView) holder.itemView.findViewById(R.id.alert_title);
|
||||||
TextView alertSubTitle = (TextView) holder.itemView.findViewById(R.id.alert_subtitle);
|
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_dark)
|
||||||
: app.getResources().getColor(R.color.active_color_primary_light));
|
: app.getResources().getColor(R.color.active_color_primary_light));
|
||||||
final WeakReference<FragmentActivity> weakActivity = new WeakReference<>(activity);
|
final WeakReference<FragmentActivity> weakActivity = new WeakReference<>(activity);
|
||||||
|
final WeakReference<Fragment> weakFragment = new WeakReference<>(targetFragment);
|
||||||
alertSubTitle.setOnClickListener(new View.OnClickListener() {
|
alertSubTitle.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
FragmentActivity a = weakActivity.get();
|
FragmentActivity a = weakActivity.get();
|
||||||
if (a != null) {
|
if (a != null) {
|
||||||
SpeedCamerasBottomSheet.showInstance(a.getSupportFragmentManager());
|
SpeedCamerasBottomSheet.showInstance(a.getSupportFragmentManager(), weakFragment.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSpeedCamerasUninstalled() {
|
||||||
|
if (showCameras != null) {
|
||||||
|
showCameras.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,6 @@
|
||||||
package net.osmand.plus.settings.fragments;
|
package net.osmand.plus.settings.fragments;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
@ -12,14 +10,13 @@ import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.appcompat.widget.SwitchCompat;
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
import androidx.preference.SwitchPreferenceCompat;
|
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
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.UiUtilities.CompoundButtonType.TOOLBAR;
|
||||||
import static net.osmand.plus.activities.SettingsNavigationActivity.MORE_VALUE;
|
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();
|
public static final String TAG = VoiceAnnouncesFragment.class.getSimpleName();
|
||||||
|
private Preference speakCamera;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createToolbar(LayoutInflater inflater, View view) {
|
protected void createToolbar(LayoutInflater inflater, View view) {
|
||||||
|
@ -100,6 +98,10 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
||||||
setupInterruptMusicPref();
|
setupInterruptMusicPref();
|
||||||
}
|
}
|
||||||
enableDisablePreferences(!settings.VOICE_MUTE.getModeValue(getSelectedAppMode()));
|
enableDisablePreferences(!settings.VOICE_MUTE.getModeValue(getSelectedAppMode()));
|
||||||
|
speakCamera = findPreference(settings.SPEAK_SPEED_CAMERA.getId());
|
||||||
|
if (settings.SPEED_CAMERAS_UNINSTALLED.get()) {
|
||||||
|
onSpeedCamerasUninstalled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSpeedLimitExceedPref() {
|
private void setupSpeedLimitExceedPref() {
|
||||||
|
@ -209,29 +211,6 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
||||||
getPreferenceScreen().addPreference(interruptMusicPref);
|
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() {
|
private void updateMenu() {
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null) {
|
||||||
|
@ -253,7 +232,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
||||||
imageView.setEnabled(preference.isEnabled() && !OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(currentValue));
|
imageView.setEnabled(preference.isEnabled() && !OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(currentValue));
|
||||||
}
|
}
|
||||||
} else if (settings.SPEAK_SPEED_CAMERA.getId().equals(preference.getKey())) {
|
} 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 (prefId.equals(settings.SPEAK_SPEED_CAMERA.getId())) {
|
||||||
if (!settings.SPEAK_SPEED_CAMERA.getModeValue(selectedMode)) {
|
if (!settings.SPEAK_SPEED_CAMERA.getModeValue(selectedMode)) {
|
||||||
confirmSpeedCamerasDlg();
|
return onConfirmPreferenceChange(
|
||||||
return false;
|
settings.SPEAK_SPEED_CAMERA.getId(), true, ApplyQueryType.SNACK_BAR);
|
||||||
} else {
|
} else {
|
||||||
return onConfirmPreferenceChange(
|
return onConfirmPreferenceChange(
|
||||||
settings.SPEAK_SPEED_CAMERA.getId(), false, ApplyQueryType.SNACK_BAR);
|
settings.SPEAK_SPEED_CAMERA.getId(), false, ApplyQueryType.SNACK_BAR);
|
||||||
|
@ -315,4 +294,11 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
||||||
super.onApplyPreferenceChange(prefId, applyToAllProfiles, newValue);
|
super.onApplyPreferenceChange(prefId, applyToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSpeedCamerasUninstalled() {
|
||||||
|
if (speakCamera != null) {
|
||||||
|
speakCamera.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue