diff --git a/OsmAnd/res/layout/preference_cancel_save_button.xml b/OsmAnd/res/layout/preference_cancel_save_button.xml
new file mode 100644
index 0000000000..e1ba07d9d2
--- /dev/null
+++ b/OsmAnd/res/layout/preference_cancel_save_button.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/preference_dropdown_list.xml b/OsmAnd/res/layout/preference_dropdown_list.xml
new file mode 100644
index 0000000000..bb72778082
--- /dev/null
+++ b/OsmAnd/res/layout/preference_dropdown_list.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/preference_text_field.xml b/OsmAnd/res/layout/preference_text_field.xml
new file mode 100644
index 0000000000..5c11125cf1
--- /dev/null
+++ b/OsmAnd/res/layout/preference_text_field.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/preferences_screen.xml b/OsmAnd/res/layout/preferences_screen.xml
index 9899fbebd9..4549d388a0 100644
--- a/OsmAnd/res/layout/preferences_screen.xml
+++ b/OsmAnd/res/layout/preferences_screen.xml
@@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
-
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index d3fbbe47fb..3b30fa4984 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -11,7 +11,9 @@
Thx - Hardy
-->
- After you tap Apply, deleted profiles will be lost completely.
+ After you tap Apply, deleted profiles will be lost completely.
+ Master profile
+ Select color
Downloading %s
You can’t delete default OsmAnd profiles, but you can disable them in previous screen, or move them to the bottom.
Edit profiles
diff --git a/OsmAnd/res/xml/profile_appeariance.xml b/OsmAnd/res/xml/profile_appeariance.xml
new file mode 100644
index 0000000000..1426609223
--- /dev/null
+++ b/OsmAnd/res/xml/profile_appeariance.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java b/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java
index e06e43a749..8f043bde1f 100644
--- a/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java
+++ b/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java
@@ -852,7 +852,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
}
}
- private class ApplicationProfileObject {
+ class ApplicationProfileObject {
int stringKeyName = -1;
String stringKey;
diff --git a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java
index 9017ca3229..399cb53ef3 100644
--- a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java
@@ -18,6 +18,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.NavigationFragment;
+import net.osmand.plus.settings.ProfileAppearanceFragment;
import org.apache.commons.logging.Log;
@@ -225,6 +226,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
EditProfileFragment editProfileFragment = (EditProfileFragment) fragmentManager.findFragmentByTag(EditProfileFragment.TAG);
SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.class.getName());
NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName());
+ ProfileAppearanceFragment profileAppearanceFragment = (ProfileAppearanceFragment) fragmentManager.findFragmentByTag(ProfileAppearanceFragment.class.getName());
if (editProfileFragment != null) {
switch (type) {
@@ -243,7 +245,9 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
listener = settingsProfileFragment.getBaseProfileListener();
} else if (navigationFragment != null) {
listener = navigationFragment.getNavProfileListener();
- }
+ } else if (profileAppearanceFragment != null) {
+ listener = profileAppearanceFragment.getParentProfileListener();
+ }
}
}
diff --git a/OsmAnd/src/net/osmand/plus/profiles/SettingsProfileFragment.java b/OsmAnd/src/net/osmand/plus/profiles/SettingsProfileFragment.java
index 36abb3ceaa..2ebe4582f6 100644
--- a/OsmAnd/src/net/osmand/plus/profiles/SettingsProfileFragment.java
+++ b/OsmAnd/src/net/osmand/plus/profiles/SettingsProfileFragment.java
@@ -170,7 +170,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
return typeListener;
}
- static List getBaseProfiles(Context ctx) {
+ public static List getBaseProfiles(Context ctx) {
List profiles = new ArrayList<>();
for (ApplicationMode mode : ApplicationMode.getDefaultValues()) {
if (mode != ApplicationMode.DEFAULT) {
diff --git a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java
index 39947cdfc0..3045a2ae8f 100644
--- a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java
@@ -97,7 +97,8 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
MAP_DURING_NAVIGATION(MapDuringNavigationFragment.class.getName(), true, R.xml.map_during_navigation, R.layout.profile_preference_toolbar),
TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, R.xml.turn_screen_on, R.layout.profile_preference_toolbar_with_switch),
DATA_STORAGE(DataStorageFragment.class.getName(), false, R.xml.data_storage, R.layout.global_preference_toolbar),
- DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class.getName(), false, R.xml.dialogs_and_notifications_preferences, R.layout.global_preferences_toolbar_with_switch);
+ DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class.getName(), false, R.xml.dialogs_and_notifications_preferences, R.layout.global_preferences_toolbar_with_switch),
+ PROFILE_APPEARANCE(ProfileAppearanceFragment.class.getName(), true, R.xml.profile_appeariance, R.layout.profile_preference_toolbar);
public final String fragmentName;
public final boolean profileDependent;
diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java
index 559218e572..446abb16bc 100644
--- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java
@@ -41,7 +41,6 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
-import net.osmand.plus.profiles.EditProfileFragment;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.plus.skimapsplugin.SkiMapsPlugin;
@@ -67,7 +66,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
private static final String CONFIGURE_MAP = "configure_map";
private static final String CONFIGURE_SCREEN = "configure_screen";
private static final String EXPORT_PROFILE = "export_profile";
- private static final String PROFILE_APPEARANCE = "profile_appearance";
+ private static final String PROFILE_APPEARANCE = "profile_appearance";
@ColorRes
protected int getBackgroundColorRes() {
@@ -99,25 +98,20 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
toolbarSubtitle.setText(R.string.configure_profile);
toolbarSubtitle.setVisibility(View.VISIBLE);
- if (!getSelectedAppMode().equals(ApplicationMode.DEFAULT)) {
- view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- ApplicationMode selectedMode = getSelectedAppMode();
- List availableAppModes = ApplicationMode.values(getMyApplication());
- boolean isChecked = availableAppModes.contains(selectedMode);
- if (!isChecked) {
- availableAppModes.add(selectedMode);
- } else {
- availableAppModes.remove(selectedMode);
- }
- ApplicationMode.changeProfileAvailability(selectedMode, !isChecked, getMyApplication());
- updateToolbarSwitch();
- }
- });
- } else {
- view.findViewById(R.id.switchWidget).setVisibility(View.GONE);
- }
+ if (!getSelectedAppMode().equals(ApplicationMode.DEFAULT)) {
+ view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ ApplicationMode selectedMode = getSelectedAppMode();
+ List availableAppModes = ApplicationMode.values(getMyApplication());
+ boolean isChecked = availableAppModes.contains(selectedMode);
+ ApplicationMode.changeProfileAvailability(selectedMode, !isChecked, getMyApplication());
+ updateToolbarSwitch();
+ }
+ });
+ } else {
+ view.findViewById(R.id.switchWidget).setVisibility(View.GONE);
+ }
}
private void updateToolbarSwitch() {
@@ -198,7 +192,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
setupNavigationSettingsPref();
setupConfigureMapPref();
setupConfigureScreenPref();
- setupProfileAppearancePref();
+ setupProfileAppearancePref();
PreferenceCategory pluginSettings = (PreferenceCategory) findPreference(PLUGIN_SETTINGS);
pluginSettings.setIconSpaceReserved(false);
@@ -246,15 +240,15 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
configureMap.setIntent(intent);
}
- private void setupProfileAppearancePref() {
- Context ctx = getContext();
- if (ctx == null) {
- return;
- }
- Preference configureMap = findPreference(PROFILE_APPEARANCE);
- configureMap.setIcon(getContentIcon(R.drawable.ic_action_offroad));
- configureMap.setFragment(EditProfileFragment.class.getName());
- }
+ private void setupProfileAppearancePref() {
+ Context ctx = getContext();
+ if (ctx == null) {
+ return;
+ }
+ Preference configureMap = findPreference(PROFILE_APPEARANCE);
+ configureMap.setIcon(getContentIcon(getSelectedAppMode().getIconRes()));
+ configureMap.setFragment(ProfileAppearanceFragment.class.getName());
+ }
private void setupExportProfilePref() {
Preference exportProfile = findPreference(EXPORT_PROFILE);
diff --git a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java
index a05584afb9..7b8be26915 100644
--- a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java
@@ -3,6 +3,8 @@ package net.osmand.plus.settings;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.SwitchPreferenceCompat;
+import android.view.LayoutInflater;
+import android.view.View;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R;
@@ -24,6 +26,7 @@ import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TY
public class NavigationFragment extends BaseSettingsFragment {
public static final String TAG = NavigationFragment.class.getSimpleName();
+ public static final String NAVIGATION_TYPE = "navigation_type";
private SelectProfileBottomSheetDialogFragment.SelectProfileListener navTypeListener;
List routingProfileDataObjects;
private Preference navigationType;
@@ -34,9 +37,15 @@ public class NavigationFragment extends BaseSettingsFragment {
routingProfileDataObjects = EditProfileFragment.getRoutingProfiles(app);
}
+ @Override
+ protected void createToolbar(LayoutInflater inflater, View view) {
+ super.createToolbar(inflater, view);
+ view.findViewById(R.id.profile_button).setVisibility(View.GONE);
+ }
+
@Override
protected void setupPreferences() {
- navigationType = findPreference("navigation_type");
+ navigationType = findPreference(NAVIGATION_TYPE);
Preference routeParameters = findPreference("route_parameters");
SwitchPreferenceCompat showRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.SHOW_ROUTING_ALARMS.getId());
SwitchPreferenceCompat speakRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.VOICE_MUTE.getId());
@@ -71,7 +80,7 @@ public class NavigationFragment extends BaseSettingsFragment {
@Override
public boolean onPreferenceClick(Preference preference) {
- if (preference.getKey().equals("navigation_type")) {
+ if (preference.getKey().equals(NAVIGATION_TYPE)) {
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
Bundle bundle = new Bundle();
if (getSelectedAppMode() != null) {
diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java
new file mode 100644
index 0000000000..9bae42bb0e
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java
@@ -0,0 +1,202 @@
+package net.osmand.plus.settings;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceCategory;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+
+import net.osmand.plus.ApplicationMode;
+import net.osmand.plus.R;
+import net.osmand.plus.UiUtilities;
+import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
+import net.osmand.plus.profiles.SettingsProfileFragment;
+import net.osmand.plus.widgets.OsmandTextFieldBoxes;
+import net.osmand.util.Algorithms;
+
+import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
+import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
+import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
+
+public class ProfileAppearanceFragment extends BaseSettingsFragment {
+
+ private static final String MASTER_PROFILE = "master_profile";
+ private static final String PROFILE_NAME = "profile_name";
+ private static final String SELECT_COLOR = "select_color";
+ private static final String SELECT_ICON = "select_icon";
+ private SelectProfileBottomSheetDialogFragment.SelectProfileListener parentProfileListener;
+ private EditText baseProfileName;
+ private ApplicationProfileObject profile;
+ private ApplicationProfileObject changedProfile;
+ private Button cancelButton;
+ private Button saveButton;
+ private EditText profileName;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (savedInstanceState != null) {
+ profile.parent = getSelectedAppMode().getParent();
+ } else {
+ profile = new ApplicationProfileObject();
+ profile.parent = getSelectedAppMode().getParent();
+ profile.name = "";
+ changedProfile = new ApplicationProfileObject();
+ changedProfile.parent = profile.parent;
+ changedProfile.name = profile.name;
+ }
+ }
+
+ @Override
+ protected void setupPreferences() {
+ PreferenceCategory selectColor = (PreferenceCategory) findPreference(SELECT_COLOR);
+ selectColor.setIconSpaceReserved(false);
+ PreferenceCategory selectIcon = (PreferenceCategory) findPreference(SELECT_ICON);
+ selectIcon.setIconSpaceReserved(false);
+
+
+ }
+
+ @SuppressLint("InlinedApi")
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View view = super.onCreateView(inflater, container, savedInstanceState);
+ if (view != null) {
+ FrameLayout frameLayout = view.findViewById(android.R.id.list_container);
+ View inflatedLayout = UiUtilities.getInflater(getContext(), isNightMode())
+ .inflate(R.layout.preference_cancel_save_button, frameLayout, false);
+ (frameLayout).addView(inflatedLayout);
+ cancelButton=inflatedLayout.findViewById(R.id.cancel_button);
+ saveButton=inflatedLayout.findViewById(R.id.save_profile_btn);
+ cancelButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (getActivity() != null) {
+ getActivity().onBackPressed();
+ }
+ }
+ });
+ saveButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (getActivity() != null) {
+ getActivity().onBackPressed();
+ }
+ }
+ });
+ }
+ return view;
+ }
+
+ @Override
+ protected void createToolbar(LayoutInflater inflater, View view) {
+ super.createToolbar(inflater, view);
+ View profileIcon = view.findViewById(R.id.profile_button);
+ profileIcon.setVisibility(View.VISIBLE);
+ }
+
+ @Override
+ protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {
+ super.onBindPreferenceViewHolder(preference, holder);
+ if (PROFILE_NAME.equals(preference.getKey())) {
+ profileName = (EditText) holder.findViewById(R.id.profile_name_et);
+ profileName.setText(getSelectedAppMode().toHumanString(getContext()));
+
+ profileName.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ profile.name = s.toString();
+ }
+ });
+ } else if (MASTER_PROFILE.equals(preference.getKey())) {
+ baseProfileName = (EditText) holder.findViewById(R.id.navigation_type_et);
+ baseProfileName.setText(getSelectedAppMode().getParent() != null ? getSelectedAppMode().getParent().toHumanString(getContext()) : getSelectedAppMode().toHumanString(getContext()));
+ OsmandTextFieldBoxes baseProfileNameHint = (OsmandTextFieldBoxes) holder.findViewById(R.id.navigation_type_otfb);
+ baseProfileNameHint.setLabelText(getString(R.string.master_profile));
+ FrameLayout selectNavTypeBtn = (FrameLayout) holder.findViewById(R.id.select_nav_type_btn);
+ selectNavTypeBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (getSelectedAppMode().isCustomProfile()) {
+ hideKeyboard();
+ final SelectProfileBottomSheetDialogFragment fragment = new SelectProfileBottomSheetDialogFragment();
+ Bundle bundle = new Bundle();
+ if (getSelectedAppMode() != null) {
+ bundle.putString(SELECTED_KEY, getSelectedAppMode().getRoutingProfile());
+ }
+ bundle.putString(DIALOG_TYPE, TYPE_BASE_APP_PROFILE);
+ fragment.setArguments(bundle);
+ if (getActivity() != null) {
+ getActivity().getSupportFragmentManager().beginTransaction()
+ .add(fragment, "select_nav_type").commitAllowingStateLoss();
+ }
+ }
+ }
+ });
+ }
+ }
+
+ private void hideKeyboard() {
+ Activity activity = getActivity();
+ if (activity != null) {
+ View cf = activity.getCurrentFocus();
+ if (cf != null) {
+ InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(cf.getWindowToken(), 0);
+ }
+ }
+ }
+ }
+
+ public SelectProfileBottomSheetDialogFragment.SelectProfileListener getParentProfileListener() {
+ if (parentProfileListener == null) {
+ parentProfileListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() {
+ @Override
+ public void onSelectedType(int pos, String stringRes) {
+ updateParentProfile(pos);
+ }
+ };
+ }
+ return parentProfileListener;
+ }
+
+ void updateParentProfile(int pos) {
+
+ String key = SettingsProfileFragment.getBaseProfiles(getMyApplication()).get(pos).getStringKey();
+ setupBaseProfileView(key);
+ profile.parent = ApplicationMode.valueOfStringKey(key, ApplicationMode.DEFAULT);
+ }
+
+ private void setupBaseProfileView(String stringKey) {
+ for (ApplicationMode am : ApplicationMode.getDefaultValues()) {
+ if (am.getStringKey().equals(stringKey)) {
+ baseProfileName.setText(Algorithms.capitalizeFirstLetter(am.toHumanString(app)));
+ }
+ }
+ }
+
+ class ApplicationProfileObject {
+ ApplicationMode parent = null;
+ String name;
+ }
+}