[android] Added settings for Speed cameras

This commit is contained in:
Dmitry Donskoy 2018-11-21 15:36:22 +03:00 committed by Aleksandr Zatsepin
parent 5d5af46d48
commit 0d0f5796fd
4 changed files with 102 additions and 22 deletions

View file

@ -50,6 +50,7 @@
<string name="pref_tts_language" translatable="false">TtsLanguage</string>
<string name="pref_tts_info" translatable="false">TtsInfo</string>
<string name="pref_tts_info_link" translatable="false">TtsInfoLink</string>
<string name="pref_speed_cameras" translatable="false">SpeedCameras</string>
<string name="tts_info_link" translatable="false">https://support.maps.me/hc/en-us/articles/208628985-How-can-I-check-TTS-settings-on-my-Android-device-</string>
<string name="pref_autodownload" translatable="false">AutoDownloadMap</string>
<string name="pref_backupbookmarks" translatable="false">BackupBookmarks</string>
@ -91,4 +92,7 @@
<string name="pref_opt_out_fabric_activated" translatable="false">pref_opt_out_fabric_activated</string>
<string name="pref_opt_out_mopub" translatable="false">pref_opt_out_mopub</string>
<string name="pref_opt_out_flurry" translatable="false">pref_opt_out_flurry</string>
<string name="never_enum_value" translatable="false">NEVER</string>
<string name="always_enum_value" translatable="false">ALWAYS</string>
<string name="auto_enum_value" translatable="false">AUTO</string>
</resources>

View file

@ -24,6 +24,18 @@
<item>@string/theme_auto</item>
</string-array>
<string-array name="speed_cameras">
<item>@string/pref_map_style_auto</item>
<item>@string/always</item>
<item>@string/never</item>
</string-array>
<string-array name="speed_cameras_values" translatable="false">
<item>@string/auto_enum_value</item>
<item>@string/always_enum_value</item>
<item>@string/never_enum_value</item>
</string-array>
<string-array name="track_length">
<item>@string/duration_disabled</item>
<item>@string/duration_1_hour</item>

View file

@ -152,6 +152,13 @@
android:summary="@string/prefs_languages_information_off_link"
android:order="4"/>
</android.support.v7.preference.PreferenceScreen>
<ListPreference
android:key="@string/pref_speed_cameras"
android:title="@string/pref_speed_cameras_title"
android:entries="@array/speed_cameras"
android:entryValues="@array/speed_cameras_values"
android:defaultValue="@string/auto_enum_value"
android:order="5"/>
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory
android:key="@string/pref_information"

View file

@ -322,6 +322,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
initMeasureUnitsPrefsCallbacks();
initZoomPrefsCallbacks();
initMapStylePrefsCallbacks();
initSpeedCamerasPrefs();
initAutoDownloadPrefsCallbacks();
initBackupBookmarksPrefsCallbacks();
initLargeFontSizePrefsCallbacks();
@ -340,6 +341,37 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
updateTts();
}
private void initSpeedCamerasPrefs()
{
String key = getString(R.string.pref_speed_cameras);
final ListPreference pref = (ListPreference) findPreference(key);
if (pref == null)
return;
pref.setSummary(pref.getEntry());
pref.setOnPreferenceChangeListener(this::onSpeedCamerasPrefSelected);
}
private boolean onSpeedCamerasPrefSelected(Preference preference, Object newValue)
{
String speedCamModeValue = (String) newValue;
ListPreference speedCamModeList = (ListPreference) preference;
SpeedCameraMode newCamMode = SpeedCameraMode.valueOf(speedCamModeValue);
CharSequence summary = speedCamModeList.getEntries()[newCamMode.ordinal()];
speedCamModeList.setSummary(summary);
if (speedCamModeList.getValue().equals(newValue))
return true;
SpeedCameraMode oldCamMode = SpeedCameraMode.valueOf(speedCamModeList.getValue());
onSpeedCamerasPrefChanged(oldCamMode, newCamMode);
return true;
}
private void onSpeedCamerasPrefChanged(@NonNull SpeedCameraMode oldCamMode,
@NonNull SpeedCameraMode newCamMode)
{
}
@Override
public void onResume()
{
@ -779,31 +811,24 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
String curTheme = Config.getUiThemeSettings();
pref.setValue(curTheme);
pref.setSummary(pref.getEntry());
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
{
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
String themeName = (String)newValue;
if (!Config.setUiThemeSettings(themeName))
return true;
pref.setOnPreferenceChangeListener(this::onMapStylePrefChanged);
}
ThemeSwitcher.restart(false);
Statistics.INSTANCE.trackEvent(Statistics.EventName.Settings.MAP_STYLE,
Statistics.params().add(Statistics.EventParam.NAME, themeName));
private boolean onMapStylePrefChanged(@NonNull Preference pref, @NonNull Object newValue)
{
String themeName = (String) newValue;
if (!Config.setUiThemeSettings(themeName))
return true;
UiThread.runLater(new Runnable()
{
@Override
public void run()
{
pref.setSummary(pref.getEntry());
}
});
ThemeSwitcher.restart(false);
Statistics.INSTANCE.trackEvent(Statistics.EventName.Settings.MAP_STYLE,
Statistics.params().add(Statistics.EventParam.NAME, themeName));
ListPreference mapStyleModeList = (ListPreference) pref;
return true;
}
});
ThemeMode mode = ThemeMode.getInstance(getContext().getApplicationContext(), themeName);
CharSequence summary = mapStyleModeList.getEntries()[mode.ordinal()];
mapStyleModeList.setSummary(summary);
return true;
}
private void initZoomPrefsCallbacks()
@ -926,4 +951,36 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
{
return mAdsRemovalPurchaseController;
}
enum ThemeMode
{
DEFAULT(R.string.theme_default),
NIGHT(R.string.theme_night),
AUTO(R.string.theme_auto);
private final int mModeStringId;
ThemeMode(int modeStringId)
{
mModeStringId = modeStringId;
}
@NonNull
public static ThemeMode getInstance(@NonNull Context context, @NonNull String src)
{
for (ThemeMode each : values())
{
if (context.getResources().getString(each.mModeStringId).equals(src))
return each;
}
return AUTO;
}
}
enum SpeedCameraMode
{
AUTO,
ALWAYS,
NEVER
}
}