From 1a4fe63e87478d02f8aefde266542e94b81fc743 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 2 Sep 2019 18:41:56 +0300 Subject: [PATCH] Coordinates fragment initial commit --- OsmAnd/res/layout/preference_radio_button.xml | 50 +++++++++++ OsmAnd/res/values/strings.xml | 3 + OsmAnd/res/xml/configure_profile.xml | 1 + OsmAnd/res/xml/coordinates_format.xml | 47 ++++++++++ OsmAnd/res/xml/general_profile_settings.xml | 8 +- .../settings/ConfigureProfileFragment.java | 46 ++++++++-- .../settings/CoordinatesFormatFragment.java | 89 +++++++++++++++++++ .../GeneralProfileSettingsFragment.java | 37 ++++---- .../plus/settings/SettingsMainFragment.java | 3 +- 9 files changed, 249 insertions(+), 35 deletions(-) create mode 100644 OsmAnd/res/layout/preference_radio_button.xml create mode 100644 OsmAnd/res/xml/coordinates_format.xml create mode 100644 OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java diff --git a/OsmAnd/res/layout/preference_radio_button.xml b/OsmAnd/res/layout/preference_radio_button.xml new file mode 100644 index 0000000000..393bacca0b --- /dev/null +++ b/OsmAnd/res/layout/preference_radio_button.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index bc80ae3aa6..085ad4831b 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,9 @@ Thx - Hardy --> + UTM + OLC + The selected format will be applied to all places in the application. This setting is selected by default for profiles: %s. Change default settings Discard changes diff --git a/OsmAnd/res/xml/configure_profile.xml b/OsmAnd/res/xml/configure_profile.xml index 94ed0b0fcd..fb17dbc432 100644 --- a/OsmAnd/res/xml/configure_profile.xml +++ b/OsmAnd/res/xml/configure_profile.xml @@ -31,6 +31,7 @@ diff --git a/OsmAnd/res/xml/coordinates_format.xml b/OsmAnd/res/xml/coordinates_format.xml new file mode 100644 index 0000000000..78bca2cf65 --- /dev/null +++ b/OsmAnd/res/xml/coordinates_format.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/xml/general_profile_settings.xml b/OsmAnd/res/xml/general_profile_settings.xml index ab83cb8459..a7f942289f 100644 --- a/OsmAnd/res/xml/general_profile_settings.xml +++ b/OsmAnd/res/xml/general_profile_settings.xml @@ -1,5 +1,6 @@ - + - + android:title="@string/coords_format" + app:fragment="net.osmand.plus.settings.CoordinatesFormatFragment" /> connectedApps = getMyApplication().getAidlApi().getConnectedApps(); - List plugins = OsmandPlugin.getVisiblePlugins(); - for (ConnectedApp connectedApp : connectedApps) { SwitchPreference preference = new SwitchPreference(getContext()); preference.setKey(connectedApp.getPack()); @@ -55,8 +59,12 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { preference.setChecked(connectedApp.isEnabled()); preference.setLayoutResource(R.layout.preference_dialog_and_switch); - screen.addPreference(preference); + getPreferenceScreen().addPreference(preference); } + } + + private void setupOsmandPluginsPref() { + List plugins = OsmandPlugin.getVisiblePlugins(); for (OsmandPlugin plugin : plugins) { SwitchPreferenceEx preference = new SwitchPreferenceEx(getContext()); preference.setKey(plugin.getId()); @@ -69,10 +77,30 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId()); preference.setIntent(intent); - screen.addPreference(preference); + getPreferenceScreen().addPreference(preference); } } + private void setupConfigureMapPref() { + Preference configureMap = findPreference("configure_map"); + configureMap.setIcon(getContentIcon(R.drawable.ic_action_layers_dark)); + + Intent intent = new Intent(getActivity(), MapActivity.class); + intent.putExtra(OPEN_CONFIG_ON_MAP, MAP_CONFIG); + intent.putExtra(SELECTED_ITEM, getSelectedAppMode().getStringKey()); + configureMap.setIntent(intent); + } + + @Override + public boolean onPreferenceClick(Preference preference) { + if (preference.getKey().equals("configure_map")) { + getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit(); + return false; + } + + return super.onPreferenceClick(preference); + } + @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String key = preference.getKey(); diff --git a/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java b/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java new file mode 100644 index 0000000000..04ffb61d1c --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java @@ -0,0 +1,89 @@ +package net.osmand.plus.settings; + +import android.content.Context; +import android.support.v7.preference.CheckBoxPreference; +import android.support.v7.preference.Preference; + +import net.osmand.plus.R; + +public class CoordinatesFormatFragment extends BaseSettingsFragment { + + public static final String TAG = "CoordinatesFormatFragment"; + + @Override + protected int getPreferencesResId() { + return R.xml.coordinates_format; + } + + @Override + protected int getToolbarResId() { + return R.layout.profile_preference_toolbar; + } + + protected String getToolbarTitle() { + return getString(R.string.coordinates_format); + } + + @Override + protected void setupPreferences() { + Context ctx = getContext(); + if (ctx == null) { + return; + } + Preference generalSettings = findPreference("coordinates_format_info"); + generalSettings.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); + + CheckBoxPreference degreesPref = (CheckBoxPreference) findPreference("format_degrees"); + CheckBoxPreference minutesPref = (CheckBoxPreference) findPreference("format_minutes"); + CheckBoxPreference secondsPref = (CheckBoxPreference) findPreference("format_seconds"); + CheckBoxPreference utmPref = (CheckBoxPreference) findPreference("format_utm"); + CheckBoxPreference olcPref = (CheckBoxPreference) findPreference("format_olc"); + + degreesPref.setSummary(R.string.exit_at); + minutesPref.setSummary(R.string.exit_at); + secondsPref.setSummary(R.string.exit_at); + utmPref.setSummary(R.string.exit_at); + olcPref.setSummary(R.string.exit_at); + + // settings.COORDINATES_FORMAT.get() + +// coordinatesFormat.setEntries(new String[] { +// PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_DEGREES), +// PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_MINUTES), +// PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_SECONDS), +// PointDescription.formatToHumanString(ctx, PointDescription.UTM_FORMAT), +// PointDescription.formatToHumanString(ctx, PointDescription.OLC_FORMAT) +// }); +// coordinatesFormat.setEntryValues(new Integer[] { +// PointDescription.FORMAT_DEGREES, +// PointDescription.FORMAT_MINUTES, +// PointDescription.FORMAT_SECONDS, +// PointDescription.UTM_FORMAT, +// PointDescription.OLC_FORMAT +// }); + } + + @Override + public boolean onPreferenceClick(Preference preference) { + String key = preference.getKey(); + + for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) { + Preference pref = getPreferenceScreen().getPreference(i); + if (pref instanceof CheckBoxPreference) { + CheckBoxPreference checkBoxPreference = ((CheckBoxPreference) pref); + if (!checkBoxPreference.getKey().equals(key)) { + checkBoxPreference.setChecked(false); + } + } + } + + return super.onPreferenceClick(preference); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + String key = preference.getKey(); + + return super.onPreferenceChange(preference, newValue); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java index f6b898fa86..27c6ee1e31 100644 --- a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java @@ -1,6 +1,5 @@ package net.osmand.plus.settings; -import android.content.Context; import android.content.DialogInterface; import android.content.pm.ActivityInfo; import android.graphics.drawable.Drawable; @@ -155,28 +154,24 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { } private void setupCoordinatesFormatPref() { - Context ctx = getContext(); - if (ctx == null) { - return; - } - - ListPreferenceEx coordinatesFormat = (ListPreferenceEx) findPreference(settings.COORDINATES_FORMAT.getId()); + Preference coordinatesFormat = findPreference(settings.COORDINATES_FORMAT.getId()); coordinatesFormat.setIcon(getContentIcon(R.drawable.ic_action_coordinates_widget)); + coordinatesFormat.setSummary(PointDescription.formatToHumanString(app, settings.COORDINATES_FORMAT.get())); - coordinatesFormat.setEntries(new String[] { - PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_DEGREES), - PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_MINUTES), - PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_SECONDS), - PointDescription.formatToHumanString(ctx, PointDescription.UTM_FORMAT), - PointDescription.formatToHumanString(ctx, PointDescription.OLC_FORMAT) - }); - coordinatesFormat.setEntryValues(new Integer[] { - PointDescription.FORMAT_DEGREES, - PointDescription.FORMAT_MINUTES, - PointDescription.FORMAT_SECONDS, - PointDescription.UTM_FORMAT, - PointDescription.OLC_FORMAT - }); +// coordinatesFormat.setEntries(new String[] { +// PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_DEGREES), +// PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_MINUTES), +// PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_SECONDS), +// PointDescription.formatToHumanString(ctx, PointDescription.UTM_FORMAT), +// PointDescription.formatToHumanString(ctx, PointDescription.OLC_FORMAT) +// }); +// coordinatesFormat.setEntryValues(new Integer[] { +// PointDescription.FORMAT_DEGREES, +// PointDescription.FORMAT_MINUTES, +// PointDescription.FORMAT_SECONDS, +// PointDescription.UTM_FORMAT, +// PointDescription.OLC_FORMAT +// }); } private void setupAngularUnitsPref() { diff --git a/OsmAnd/src/net/osmand/plus/settings/SettingsMainFragment.java b/OsmAnd/src/net/osmand/plus/settings/SettingsMainFragment.java index af51ec8e43..5313631306 100644 --- a/OsmAnd/src/net/osmand/plus/settings/SettingsMainFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/SettingsMainFragment.java @@ -63,7 +63,6 @@ public class SettingsMainFragment extends BaseSettingsFragment { Intent intent = new Intent(getActivity(), MapActivity.class); intent.putExtra(OPEN_CONFIG_ON_MAP, MAP_CONFIG); intent.putExtra(SELECTED_ITEM, getSelectedAppMode().getStringKey()); - startActivity(intent); browseMap.setIntent(intent); } @@ -91,7 +90,7 @@ public class SettingsMainFragment extends BaseSettingsFragment { public boolean onPreferenceClick(Preference preference) { if (preference.getKey().equals("browse_map")) { getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit(); - return true; + return false; } return super.onPreferenceClick(preference);