diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml
index f108fc7dd5..54442ccbf2 100644
--- a/OsmAnd/AndroidManifest.xml
+++ b/OsmAnd/AndroidManifest.xml
@@ -484,10 +484,6 @@
-
-
-
-
diff --git a/OsmAnd/res/layout/help_to_improve_item.xml b/OsmAnd/res/layout/help_to_improve_item.xml
index 795053dbbe..71f94da43d 100644
--- a/OsmAnd/res/layout/help_to_improve_item.xml
+++ b/OsmAnd/res/layout/help_to_improve_item.xml
@@ -1,51 +1,54 @@
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp">
+ android:textColor="?android:textColorSecondary"
+ tools:drawableTop="@drawable/ic_action_message" />
+ android:background="?attr/divider_color" />
+ android:textColor="?android:textColorSecondary"
+ tools:drawableTop="@drawable/ic_action_message" />
+ android:background="?attr/divider_color" />
+ android:textColor="?android:textColorSecondary"
+ tools:drawableTop="@drawable/ic_crashlog" />
\ No newline at end of file
diff --git a/OsmAnd/res/xml/general_settings.xml b/OsmAnd/res/xml/general_settings.xml
deleted file mode 100644
index 6060bcc19c..0000000000
--- a/OsmAnd/res/xml/general_settings.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/OsmAnd/res/xml/navigation_settings.xml b/OsmAnd/res/xml/navigation_settings.xml
deleted file mode 100644
index 9931f48368..0000000000
--- a/OsmAnd/res/xml/navigation_settings.xml
+++ /dev/null
@@ -1,106 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/OsmAnd/res/xml/settings_main_screen.xml b/OsmAnd/res/xml/settings_main_screen.xml
index e2a2a5be80..ba31622bf4 100644
--- a/OsmAnd/res/xml/settings_main_screen.xml
+++ b/OsmAnd/res/xml/settings_main_screen.xml
@@ -53,6 +53,13 @@
android:title="@string/import_profile"
tools:icon="@drawable/ic_action_import" />
+
+
-
-
-
-
-
-
-
diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java
index 0efdd133f3..40ea9cfb98 100644
--- a/OsmAnd/src/net/osmand/AndroidUtils.java
+++ b/OsmAnd/src/net/osmand/AndroidUtils.java
@@ -67,6 +67,7 @@ import net.osmand.plus.R;
import net.osmand.util.Algorithms;
import java.io.File;
+import java.lang.reflect.Field;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
@@ -884,4 +885,65 @@ public class AndroidUtils {
}
return builder;
}
+
+ public static String getRoutingStringPropertyName(Context ctx, String propertyName, String defValue) {
+ String value = getStringByProperty(ctx, "routing_attr_" + propertyName + "_name");
+ return value != null ? value : defValue;
+ }
+
+ public static String getRoutingStringPropertyDescription(Context ctx, String propertyName, String defValue) {
+ String value = getStringByProperty(ctx, "routing_attr_" + propertyName + "_description");
+ return value != null ? value : defValue;
+ }
+
+ public static String getRenderingStringPropertyName(Context ctx, String propertyName, String defValue) {
+ String value = getStringByProperty(ctx, "rendering_attr_" + propertyName + "_name");
+ return value != null ? value : defValue;
+ }
+
+ public static String getRenderingStringPropertyDescription(Context ctx, String propertyName, String defValue) {
+ String value = getStringByProperty(ctx, "rendering_attr_" + propertyName + "_description");
+ return value != null ? value : defValue;
+ }
+
+ public static String getIconStringPropertyName(Context ctx, String propertyName) {
+ String value = getStringByProperty(ctx, "icon_group_" + propertyName);
+ return value != null ? value : propertyName;
+ }
+
+ public static String getRenderingStringPropertyValue(Context ctx, String propertyValue) {
+ if (propertyValue == null) {
+ return "";
+ }
+ String propertyValueReplaced = propertyValue.replaceAll("\\s+", "_");
+ String value = getStringByProperty(ctx, "rendering_value_" + propertyValueReplaced + "_name");
+ return value != null ? value : propertyValue;
+ }
+
+ public static String getStringRouteInfoPropertyValue(Context ctx, String propertyValue) {
+ if (propertyValue == null) {
+ return "";
+ }
+ String propertyValueReplaced = propertyValue.replaceAll("\\s+", "_");
+ String value = getStringByProperty(ctx, "routeInfo_" + propertyValueReplaced + "_name");
+ return value != null ? value : propertyValue;
+ }
+
+ private static String getStringByProperty(@NonNull Context ctx, @NonNull String property) {
+ try {
+ Field field = R.string.class.getField(property);
+ return getStringForField(ctx, field);
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+ return null;
+ }
+
+ private static String getStringForField(@NonNull Context ctx, @Nullable Field field) throws IllegalAccessException {
+ if (field != null) {
+ Integer in = (Integer) field.get(null);
+ return ctx.getString(in);
+ }
+ return null;
+ }
}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java
index 21ed74a437..ec3a9c1e10 100644
--- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java
+++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java
@@ -2312,7 +2312,7 @@ public class OsmandAidlApi {
File exportDir = app.getSettings().getExternalStorageDirectory();
String fileName = appMode.toHumanString();
SettingsHelper settingsHelper = app.getSettingsHelper();
- settingsItems.addAll(settingsHelper.getFilteredSettingsItems(settingsHelper.getAdditionalData(), settingsTypes));
+ settingsItems.addAll(settingsHelper.getFilteredSettingsItems(settingsHelper.getAdditionalData(false), settingsTypes));
settingsHelper.exportSettings(exportDir, fileName, null, settingsItems, true);
return true;
}
diff --git a/OsmAnd/src/net/osmand/plus/activities/ActionBarPreferenceActivity.java b/OsmAnd/src/net/osmand/plus/activities/ActionBarPreferenceActivity.java
deleted file mode 100644
index 02ed96daba..0000000000
--- a/OsmAnd/src/net/osmand/plus/activities/ActionBarPreferenceActivity.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package net.osmand.plus.activities;
-
-import android.app.Activity;
-import android.graphics.drawable.Drawable;
-import android.os.Build.VERSION;
-import android.os.Build.VERSION_CODES;
-import android.os.Bundle;
-import android.util.TypedValue;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.Spinner;
-import android.widget.TextView;
-
-import androidx.appcompat.widget.Toolbar;
-import androidx.core.view.ViewCompat;
-
-import net.osmand.AndroidUtils;
-import net.osmand.plus.OsmandApplication;
-import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.R;
-
-public abstract class ActionBarPreferenceActivity extends AppCompatPreferenceActivity {
- private Toolbar tb;
- private View shadowView;
-
- public Toolbar getToolbar() {
- return tb;
- }
-
- @Override
- protected void onCreate(final Bundle savedInstanceState) {
- //settings needed it's own theme because of check boxes not styled properly
- OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings();
- int t = settings.isLightContent()
- ? R.style.OsmandLightTheme_NoActionbar_Preferences
- : R.style.OsmandDarkTheme_NoActionbar_Preferences;
- setTheme(t);
- super.onCreate(savedInstanceState);
- boolean lightTheme = settings.isLightContent();
- setContentView(R.layout.preference_activity);
- tb = (Toolbar) findViewById(R.id.toolbar);
- if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- shadowView = findViewById(R.id.shadowView);
- final ViewGroup parent = (ViewGroup) shadowView.getParent();
- parent.removeView(shadowView);
- shadowView = null;
- }
- tb.setClickable(true);
- int activeButtonsAndLinksTextColorResId = lightTheme ? R.color.active_buttons_and_links_text_light : R.color.active_buttons_and_links_text_dark;
- int navigationIconResId = AndroidUtils.getNavigationIconResId(getApplication());
- Drawable icBack = ((OsmandApplication) getApplication()).getUIUtilities().getIcon(navigationIconResId, activeButtonsAndLinksTextColorResId);
- tb.setNavigationIcon(icBack);
- tb.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
- tb.setBackgroundColor(getResources().getColor(getResIdFromAttribute(this, R.attr.pstsTabBackground)));
- tb.setTitleTextColor(getResources().getColor(getResIdFromAttribute(this, R.attr.pstsTextColor)));
- tb.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(final View v) {
- finish();
- }
- });
-
- getSpinner().setVisibility(View.GONE);
- getTypeButton().setVisibility(View.GONE);
- setProgressVisibility(false);
- }
-
- static int getResIdFromAttribute(final Activity activity, final int attr) {
- if (attr == 0)
- return 0;
- final TypedValue typedvalueattr = new TypedValue();
- activity.getTheme().resolveAttribute(attr, typedvalueattr, true);
- return typedvalueattr.resourceId;
- }
-
- protected void setEnabledActionBarShadow(final boolean enable) {
- if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- ViewCompat.setElevation(tb, enable ? 4 : 0);
- } else {
- if (shadowView == null)
- shadowView = findViewById(R.id.shadowView);
- shadowView.setVisibility(enable ? View.VISIBLE : View.GONE);
- }
- }
-
- protected Spinner getSpinner() {
- return (Spinner) findViewById(R.id.spinner_nav);
- }
-
- protected LinearLayout getTypeButton() {
- return (LinearLayout) findViewById(R.id.type_selection_button);
- }
-
- protected TextView getModeTitleTV() {
- return (TextView) findViewById(R.id.mode_title);
- }
-
- protected TextView getModeSubTitleTV() {
- return (TextView) findViewById(R.id.mode_subtitle);
- }
-
- protected ImageView getModeIconIV() {
- return (ImageView) findViewById(R.id.mode_icon);
- }
- protected ImageView getDropDownArrow() {
- return (ImageView) findViewById(R.id.type_down_arrow);
- }
-
- protected void setProgressVisibility(boolean visibility) {
- if (visibility) {
- findViewById(R.id.ProgressBar).setVisibility(View.VISIBLE);
- } else {
- findViewById(R.id.ProgressBar).setVisibility(View.GONE);
- }
-
- }
-}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/activities/AppCompatPreferenceActivity.java b/OsmAnd/src/net/osmand/plus/activities/AppCompatPreferenceActivity.java
deleted file mode 100644
index 84b60b56e8..0000000000
--- a/OsmAnd/src/net/osmand/plus/activities/AppCompatPreferenceActivity.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.osmand.plus.activities;
-
-import android.content.res.Configuration;
-import android.os.Bundle;
-import android.preference.PreferenceActivity;
-import android.view.MenuInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.annotation.LayoutRes;
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.AppCompatDelegate;
-import androidx.appcompat.widget.Toolbar;
-/**
- * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
- * to be used with AppCompat.
- *
- * This technique can be used with an {@link android.app.Activity} class, not just
- * {@link android.preference.PreferenceActivity}.
- */
-public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
- private AppCompatDelegate mDelegate;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- getDelegate().installViewFactory();
- getDelegate().onCreate(savedInstanceState);
- super.onCreate(savedInstanceState);
- }
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
- getDelegate().onPostCreate(savedInstanceState);
- }
- public ActionBar getSupportActionBar() {
- return getDelegate().getSupportActionBar();
- }
- public void setSupportActionBar(@Nullable Toolbar toolbar) {
- getDelegate().setSupportActionBar(toolbar);
- }
- @Override
- public MenuInflater getMenuInflater() {
- return getDelegate().getMenuInflater();
- }
- @Override
- public void setContentView(@LayoutRes int layoutResID) {
- getDelegate().setContentView(layoutResID);
- }
- @Override
- public void setContentView(View view) {
- getDelegate().setContentView(view);
- }
- @Override
- public void setContentView(View view, ViewGroup.LayoutParams params) {
- getDelegate().setContentView(view, params);
- }
- @Override
- public void addContentView(View view, ViewGroup.LayoutParams params) {
- getDelegate().addContentView(view, params);
- }
- @Override
- protected void onPostResume() {
- super.onPostResume();
- getDelegate().onPostResume();
- }
- @Override
- protected void onTitleChanged(CharSequence title, int color) {
- super.onTitleChanged(title, color);
- getDelegate().setTitle(title);
- }
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- getDelegate().onConfigurationChanged(newConfig);
- }
- @Override
- protected void onStop() {
- super.onStop();
- getDelegate().onStop();
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- getDelegate().onDestroy();
- }
- public void invalidateOptionsMenu() {
- getDelegate().invalidateOptionsMenu();
- }
- private AppCompatDelegate getDelegate() {
- if (mDelegate == null) {
- mDelegate = AppCompatDelegate.create(this, null);
- }
- return mDelegate;
- }
-}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java
deleted file mode 100644
index 3509f99d65..0000000000
--- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package net.osmand.plus.activities;
-
-
-import android.content.Intent;
-import android.os.Bundle;
-import android.preference.Preference;
-import android.preference.PreferenceCategory;
-import android.preference.PreferenceScreen;
-
-import net.osmand.plus.OsmandApplication;
-import net.osmand.plus.OsmandPlugin;
-import net.osmand.plus.R;
-import net.osmand.plus.Version;
-import net.osmand.plus.liveupdates.OsmLiveActivity;
-
-public class SettingsActivity extends SettingsBaseActivity {
-
- public static final String INTENT_KEY_SETTINGS_SCREEN = "INTENT_KEY_SETTINGS_SCREEN";
- public static final int SCREEN_GENERAL_SETTINGS = 1;
- public static final int SCREEN_NAVIGATION_SETTINGS = 2;
-
- private static final int PLUGINS_SELECTION_REQUEST = 1;
- private static final String CONTRIBUTION_VERSION_FLAG = "CONTRIBUTION_VERSION_FLAG";
-
-
- private Preference general;
- private Preference routing;
- private Preference subscription;
- private Preference privacy;
-
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- ((OsmandApplication) getApplication()).applyTheme(this);
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.settings_pref);
- PreferenceScreen screen = getPreferenceScreen();
- general = (Preference) screen.findPreference("general_settings");
- general.setOnPreferenceClickListener(this);
- routing = (Preference) screen.findPreference("routing_settings");
- routing.setOnPreferenceClickListener(this);
- subscription = (Preference) screen.findPreference("subscription_settings");
- subscription.setOnPreferenceClickListener(this);
- privacy = (Preference) screen.findPreference("privacy_and_security");
- privacy.setOnPreferenceClickListener(this);
-
- getToolbar().setTitle(Version.getFullVersion(getMyApplication()));
-
- Intent intent = getIntent();
- if(intent != null && intent.getIntExtra(INTENT_KEY_SETTINGS_SCREEN, 0) != 0){
- int s = intent.getIntExtra(INTENT_KEY_SETTINGS_SCREEN, 0);
- if(s == SCREEN_GENERAL_SETTINGS){
- startActivity(new Intent(this, SettingsGeneralActivity.class));
- } else if(s == SCREEN_NAVIGATION_SETTINGS){
- startActivity(new Intent(this, SettingsNavigationActivity.class));
- }
- }
- PreferenceCategory plugins = (PreferenceCategory) screen.findPreference("plugin_settings");
- for(OsmandPlugin op : OsmandPlugin.getEnabledPlugins()) {
-// final Class extends Activity> sa = op.getSettingsActivity();
-// if(sa != null) {
-// Preference preference = new Preference(this);
-// preference.setTitle(op.getName());
-// preference.setKey(op.getId());
-// preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
-//
-// @Override
-// public boolean onPreferenceClick(Preference preference) {
-// startActivity(new Intent(SettingsActivity.this, sa));
-// return false;
-// }
-// });
-// plugins.addPreference(preference);
-// }
- }
- }
-
- @Override
- public boolean onPreferenceClick(Preference preference) {
- if (preference == general) {
- startActivity(new Intent(this, SettingsGeneralActivity.class));
- return true;
- } else if (preference == routing) {
- startActivity(new Intent(this, SettingsNavigationActivity.class));
- return true;
- } else if (preference == subscription) {
- Intent intent = new Intent(this, OsmLiveActivity.class);
- intent.putExtra(OsmLiveActivity.SHOW_SETTINGS_ONLY_INTENT_PARAM, true);
- startActivity(intent);
- return true;
- } else if (preference == privacy) {
- Intent intent = new Intent(this, PrivacyAndSecurityActivity.class);
- startActivity(intent);
- return true;
- } else {
- super.onPreferenceClick(preference);
- }
- return false;
- }
-
-}
diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java
index 1821c88474..e69de29bb2 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java
@@ -1,623 +0,0 @@
-package net.osmand.plus.activities;
-
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
-import android.content.DialogInterface.OnDismissListener;
-import android.content.DialogInterface.OnMultiChoiceClickListener;
-import android.os.Bundle;
-import android.preference.CheckBoxPreference;
-import android.preference.EditTextPreference;
-import android.preference.ListPreference;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
-import android.preference.Preference.OnPreferenceClickListener;
-import android.preference.PreferenceGroup;
-import android.preference.PreferenceScreen;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.Toast;
-
-import androidx.appcompat.app.AlertDialog;
-import androidx.appcompat.app.AlertDialog.Builder;
-
-import net.osmand.AndroidUtils;
-import net.osmand.PlatformUtil;
-import net.osmand.plus.OsmAndFormatter;
-import net.osmand.plus.OsmandApplication;
-import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.CommonPreference;
-import net.osmand.plus.settings.backend.OsmandPreference;
-import net.osmand.plus.R;
-import net.osmand.plus.profiles.AppProfileArrayAdapter;
-import net.osmand.plus.profiles.ProfileDataObject;
-import net.osmand.plus.settings.backend.ApplicationMode;
-
-import org.apache.commons.logging.Log;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-
-public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
- implements OnPreferenceChangeListener, OnPreferenceClickListener {
-
- private static final Log LOG = PlatformUtil.getLog(SettingsBaseActivity.class);
- public static final String INTENT_APP_MODE = "INTENT_APP_MODE";
- private static final String PREV_MODE_KEY = "previous_mode";
- private static final String SELECTED_MODE_KEY = "selected_mode";
-
- protected OsmandSettings settings;
- protected final boolean profileSettings;
- protected List modes = new ArrayList();
- private ApplicationMode previousAppMode;
- protected ApplicationMode selectedAppMode;
-
- private Map screenPreferences = new LinkedHashMap();
- private Map> booleanPreferences = new LinkedHashMap>();
- private Map> listPreferences = new LinkedHashMap>();
- private Map> editTextPreferences = new LinkedHashMap>();
-
- private Map> listPrefValues = new LinkedHashMap>();
-
- public SettingsBaseActivity() {
- this(false);
- }
-
- private boolean isModeSelected = false;
-
- public SettingsBaseActivity(boolean profile) {
- profileSettings = profile;
- }
-
- public CheckBoxPreference registerBooleanPreference(OsmandPreference b, PreferenceGroup screen) {
- CheckBoxPreference p = (CheckBoxPreference) screen.findPreference(b.getId());
- p.setOnPreferenceChangeListener(this);
- screenPreferences.put(b.getId(), p);
- booleanPreferences.put(b.getId(), b);
- return p;
- }
-
-
- public CheckBoxPreference createCheckBoxPreference(OsmandPreference b, int title, int summary) {
- CheckBoxPreference p = new CheckBoxPreference(this);
- p.setTitle(title);
- p.setKey(b.getId());
- p.setSummary(summary);
- p.setOnPreferenceChangeListener(this);
- screenPreferences.put(b.getId(), p);
- booleanPreferences.put(b.getId(), b);
- return p;
- }
-
- public CheckBoxPreference createCheckBoxPreference(OsmandPreference b, String title, String summary) {
- CheckBoxPreference p = new CheckBoxPreference(this);
- p.setTitle(title);
- p.setKey(b.getId());
- p.setSummary(summary);
- p.setOnPreferenceChangeListener(this);
- screenPreferences.put(b.getId(), p);
- booleanPreferences.put(b.getId(), b);
- return p;
- }
-
- public CheckBoxPreference createCheckBoxPreference(OsmandPreference b) {
- CheckBoxPreference p = new CheckBoxPreference(this);
- p.setKey(b.getId());
- p.setOnPreferenceChangeListener(this);
- screenPreferences.put(b.getId(), p);
- booleanPreferences.put(b.getId(), b);
- return p;
- }
-
- public static String getIconStringPropertyName(Context ctx, String propertyName, String defValue) {
- try {
- Field f = R.string.class.getField("icon_group_" + propertyName);
- if (f != null) {
- Integer in = (Integer) f.get(null);
- return ctx.getString(in);
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- return defValue;
- }
-
- public static String getRoutingStringPropertyName(Context ctx, String propertyName, String defValue) {
- try {
- Field f = R.string.class.getField("routing_attr_" + propertyName + "_name");
- if (f != null) {
- Integer in = (Integer) f.get(null);
- return ctx.getString(in);
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- return defValue;
- }
-
- public static String getRoutingStringPropertyDescription(Context ctx, String propertyName, String defValue) {
- try {
- Field f = R.string.class.getField("routing_attr_" + propertyName + "_description");
- if (f != null) {
- Integer in = (Integer) f.get(null);
- return ctx.getString(in);
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- return defValue;
- }
-
- public static String getStringPropertyName(Context ctx, String propertyName, String defValue) {
- try {
- Field f = R.string.class.getField("rendering_attr_" + propertyName + "_name");
- if (f != null) {
- Integer in = (Integer) f.get(null);
- return ctx.getString(in);
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- return defValue;
- }
-
- public static String getStringPropertyDescription(Context ctx, String propertyName, String defValue) {
- try {
- Field f = R.string.class.getField("rendering_attr_" + propertyName + "_description");
- if (f != null) {
- Integer in = (Integer) f.get(null);
- return ctx.getString(in);
- }
- } catch (Exception e) {
- //e.printStackTrace();
- System.err.println(e.getMessage());
- }
- return defValue;
- }
-
- public static String getStringPropertyValue(Context ctx, String propertyValue) {
- try {
- if(propertyValue == null) {
- return "";
- }
- final String propertyValueReplaced = propertyValue.replaceAll("\\s+","_");
- Field f = R.string.class.getField("rendering_value_" + propertyValueReplaced + "_name");
- if (f != null) {
- Integer in = (Integer) f.get(null);
- return ctx.getString(in);
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- return propertyValue;
- }
-
- public static String getStringRouteInfoPropertyValue(Context ctx, String propertyValue) {
- try {
- if(propertyValue == null) {
- return "";
- }
- final String propertyValueReplaced = propertyValue.replaceAll("\\s+","_");
- Field f = R.string.class.getField("routeInfo_" + propertyValueReplaced + "_name");
- if (f != null) {
- Integer in = (Integer) f.get(null);
- return ctx.getString(in);
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- return propertyValue;
- }
-
- public void registerListPreference(OsmandPreference b, PreferenceGroup screen, String[] names, T[] values) {
- ListPreference p = (ListPreference) screen.findPreference(b.getId());
- prepareListPreference(b, names, values, p);
- }
-
- public ListPreference createListPreference(OsmandPreference b, String[] names, T[] values, int title, int summary) {
- ListPreference p = new ListPreference(this);
- p.setTitle(title);
- p.setKey(b.getId());
- p.setDialogTitle(title);
- p.setSummary(summary);
- prepareListPreference(b, names, values, p);
- return p;
- }
-
- public ListPreference createListPreference(OsmandPreference b, String[] names, T[] values, String title, String summary) {
- ListPreference p = new ListPreference(this);
- p.setTitle(title);
- p.setKey(b.getId());
- p.setDialogTitle(title);
- p.setSummary(summary);
- prepareListPreference(b, names, values, p);
- return p;
- }
-
- public ListPreference createListPreference(OsmandPreference b, String[] names, T[] values) {
- ListPreference p = new ListPreference(this);
- p.setKey(b.getId());
- prepareListPreference(b, names, values, p);
- return p;
- }
-
- private void prepareListPreference(OsmandPreference b, String[] names, T[] values, ListPreference p) {
- p.setOnPreferenceChangeListener(this);
- LinkedHashMap vals = new LinkedHashMap();
- screenPreferences.put(b.getId(), p);
- listPreferences.put(b.getId(), b);
- listPrefValues.put(b.getId(), vals);
- assert names.length == values.length;
- for (int i = 0; i < names.length; i++) {
- vals.put(names[i], values[i]);
- }
- }
-
- private void registerDisablePreference(OsmandPreference p, String value, OsmandPreference disable) {
- LinkedHashMap vals = (LinkedHashMap) listPrefValues.get(p.getId());
- vals.put(value, disable);
- }
-
- public void registerEditTextPreference(OsmandPreference b, PreferenceScreen screen) {
- EditTextPreference p = (EditTextPreference) screen.findPreference(b.getId());
- p.setOnPreferenceChangeListener(this);
- screenPreferences.put(b.getId(), p);
- editTextPreferences.put(b.getId(), b);
- }
-
- public EditTextPreference createEditTextPreference(OsmandPreference b, int title, int summary) {
- EditTextPreference p = new EditTextPreference(this);
- p.setTitle(title);
- p.setKey(b.getId());
- p.setDialogTitle(title);
- p.setSummary(summary);
- p.setOnPreferenceChangeListener(this);
- screenPreferences.put(b.getId(), p);
- editTextPreferences.put(b.getId(), b);
- return p;
- }
-
- public void registerTimeListPreference(OsmandPreference b, PreferenceScreen screen, int[] seconds, int[] minutes, int coeff) {
- int minutesLength = minutes == null ? 0 : minutes.length;
- int secondsLength = seconds == null ? 0 : seconds.length;
- Integer[] ints = new Integer[secondsLength + minutesLength];
- String[] intDescriptions = new String[ints.length];
- for (int i = 0; i < secondsLength; i++) {
- ints[i] = seconds[i] * coeff;
- intDescriptions[i] = seconds[i] + " " + getString(R.string.int_seconds); //$NON-NLS-1$
- }
- for (int i = 0; i < minutesLength; i++) {
- ints[secondsLength + i] = (minutes[i] * 60) * coeff;
- intDescriptions[secondsLength + i] = minutes[i] + " " + getString(R.string.int_min); //$NON-NLS-1$
- }
- registerListPreference(b, screen, intDescriptions, ints);
- }
-
- public ListPreference createTimeListPreference(OsmandPreference b, int[] seconds, int[] minutes, int coeff, int title, int summary) {
- return createTimeListPreference(b, seconds, minutes, coeff, null, title, summary);
- }
-
- public ListPreference createTimeListPreference(OsmandPreference b, int[] seconds, int[] minutes,
- int coeff, CommonPreference disable, int title, int summary) {
- int minutesLength = minutes == null ? 0 : minutes.length;
- int secondsLength = seconds == null ? 0 : seconds.length;
- Integer[] ints = new Integer[secondsLength + minutesLength];
- String[] intDescriptions = new String[ints.length];
- int k = 0;
- for (int i = 0; i < secondsLength; i++) {
- ints[k] = seconds[i] * coeff;
- intDescriptions[k] = seconds[i] + " " + getString(R.string.int_seconds); //$NON-NLS-1$
- k++;
- }
- OsmandApplication app = getMyApplication();
- for (int i = 0; i < minutesLength; i++) {
- ints[k] = (minutes[i] * 60) * coeff;
- intDescriptions[k] = OsmAndFormatter.getFormattedDuration(minutes[i] * 60, app);
- k++;
- }
- ListPreference lp = createListPreference(b, intDescriptions, ints, title, summary);
- if (disable != null) {
- registerDisablePreference(b, getString(R.string.confirm_every_run), disable);
- }
- return lp;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int itemId = item.getItemId();
- switch (itemId) {
- case android.R.id.home:
- finish();
- return true;
-
- }
- return false;
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- OsmandApplication app = getMyApplication();
- settings = app.getSettings();
- getToolbar().setTitle(R.string.shared_string_settings);
-
- if (profileSettings) {
- modes.clear();
- findViewById(R.id.selector_shadow).setVisibility(View.VISIBLE);
- if (this instanceof SettingsNavigationActivity) {
- for (ApplicationMode a : ApplicationMode.values(app)) {
- if (a != ApplicationMode.DEFAULT) {
- modes.add(a);
- }
- }
- } else {
- modes.addAll(ApplicationMode.values(app));
- }
-
- getTypeButton().setVisibility(View.VISIBLE);
- getTypeButton().setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- selectAppModeDialog().show();
- }
- });
-
- }
- setPreferenceScreen(getPreferenceManager().createPreferenceScreen(this));
- }
-
- protected AlertDialog.Builder selectAppModeDialog() {
- AlertDialog.Builder singleSelectDialogBuilder = new Builder(SettingsBaseActivity.this);
- singleSelectDialogBuilder.setTitle(R.string.profile_settings);
-
- final List activeModes = new ArrayList<>();
- for (ApplicationMode am : ApplicationMode.values(getMyApplication())) {
- boolean isSelected = am == selectedAppMode;
-
- if (am != ApplicationMode.DEFAULT || !(this instanceof SettingsNavigationActivity)) {
- activeModes.add(new ProfileDataObject(
- am.toHumanString(),
- getAppModeDescription(am),
- am.getStringKey(),
- am.getIconRes(),
- isSelected,
- am.getIconColorInfo()
- ));
- }
- }
-
- final AppProfileArrayAdapter modeNames = new AppProfileArrayAdapter(
- SettingsBaseActivity.this, R.layout.bottom_sheet_item_with_descr_and_radio_btn, activeModes, isModeSelected);
-
- singleSelectDialogBuilder.setNegativeButton(R.string.shared_string_cancel,
- new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
- singleSelectDialogBuilder.setOnDismissListener(new OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- if (!isModeSelected) {
- List m = ApplicationMode.values(getMyApplication());
- setSelectedAppMode(m.get(m.size() > 1 ? 1 : 0));
- }
- }
- });
- singleSelectDialogBuilder.setAdapter(modeNames, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- settings.APPLICATION_MODE.set(modes.get(which));
- updateModeButton(modes.get(which));
- updateAllSettings();
- }
- });
- return singleSelectDialogBuilder;
- }
-
- void updateModeButton(ApplicationMode mode) {
- OsmandApplication app = getMyApplication();
- boolean nightMode = !app.getSettings().isLightContent();
- String title = mode.toHumanString();
-
- getModeTitleTV().setText(title);
- getModeSubTitleTV().setText(getAppModeDescription(mode));
- settings.APPLICATION_MODE.set(mode);
- selectedAppMode = mode;
- getModeIconIV().setImageDrawable(getMyApplication().getUIUtilities().getIcon(mode.getIconRes(),
- mode.getIconColorInfo().getColor(nightMode)));
- getDropDownArrow().setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, !nightMode));
- isModeSelected = true;
- updateAllSettings();
- }
-
- private String getAppModeDescription(ApplicationMode mode) {
- String descr;
- if (!mode.isCustomProfile()) {
- descr = getString(R.string.profile_type_base_string);
- } else {
- descr = String.format(getString(R.string.profile_type_descr_string),
- mode.getParent().toHumanString());
- if (mode.getRoutingProfile() != null && mode.getRoutingProfile().contains("/")) {
- descr = descr.concat(", " + mode.getRoutingProfile()
- .substring(0, mode.getRoutingProfile().indexOf("/")));
- }
- }
- return descr;
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- if (profileSettings) {
- if (previousAppMode == null) {
- previousAppMode = settings.getApplicationMode();
- }
- if (getIntent() != null && getIntent().hasExtra(INTENT_APP_MODE)) {
- String modeStr = getIntent().getStringExtra(INTENT_APP_MODE);
- ApplicationMode mode = ApplicationMode.valueOfStringKey(modeStr, previousAppMode);
- setSelectedAppMode(mode);
- } else {
- setSelectedAppMode(selectedAppMode);
- }
- } else {
- updateAllSettings();
- }
- }
-
- protected void setSelectedAppMode(ApplicationMode am) {
- for (ApplicationMode a : modes) {
- if (am != null && am == a) {
- updateModeButton(a);
- break;
- }
- }
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- if(profileSettings) {
- settings.APPLICATION_MODE.set(previousAppMode);
- }
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- if (profileSettings) {
- if (previousAppMode != null) {
- outState.putString(PREV_MODE_KEY, previousAppMode.getStringKey());
- }
- if (selectedAppMode != null) {
- outState.putString(SELECTED_MODE_KEY, selectedAppMode.getStringKey());
- }
- }
- }
-
- @Override
- protected void onRestoreInstanceState(Bundle state) {
- super.onRestoreInstanceState(state);
- if (state != null) {
- if (profileSettings && state.containsKey(SELECTED_MODE_KEY) && state.containsKey(PREV_MODE_KEY)) {
- for (ApplicationMode am : ApplicationMode.values(getMyApplication())) {
- if (am.getStringKey() == state.get(SELECTED_MODE_KEY)) {
- setSelectedAppMode(am);
- }
- if (am.getStringKey() == state.get(PREV_MODE_KEY)) {
- previousAppMode = am;
- }
- }
- }
- }
- }
-
- public void updateAllSettings() {
- for (OsmandPreference b : booleanPreferences.values()) {
- CheckBoxPreference pref = (CheckBoxPreference) screenPreferences.get(b.getId());
- pref.setChecked(b.get());
- }
-
- for (OsmandPreference> p : listPreferences.values()) {
- ListPreference listPref = (ListPreference) screenPreferences.get(p.getId());
- Map prefValues = listPrefValues.get(p.getId());
- String[] entryValues = new String[prefValues.size()];
- String[] entries = new String[prefValues.size()];
- int i = 0;
- for (Entry e : prefValues.entrySet()) {
- entries[i] = e.getKey();
- entryValues[i] = e.getValue() + ""; // case of null
- i++;
- }
- listPref.setEntries(entries);
- listPref.setEntryValues(entryValues);
- listPref.setValue(p.get() + "");
- }
-
- for (OsmandPreference s : editTextPreferences.values()) {
- EditTextPreference pref = (EditTextPreference) screenPreferences.get(s.getId());
- pref.setText(s.get());
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- // handle boolean preferences
- OsmandPreference boolPref = booleanPreferences.get(preference.getKey());
- OsmandPreference