diff --git a/OsmAnd/res/layout/profile_preference_toolbar.xml b/OsmAnd/res/layout/profile_preference_toolbar.xml
index 125581fdb7..a86b981894 100644
--- a/OsmAnd/res/layout/profile_preference_toolbar.xml
+++ b/OsmAnd/res/layout/profile_preference_toolbar.xml
@@ -37,14 +37,6 @@
android:textSize="@dimen/dialog_header_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/routing_settings_2" />
-
-
-
\ No newline at end of file
diff --git a/OsmAnd/res/xml/navigation_settings_new.xml b/OsmAnd/res/xml/navigation_settings_new.xml
index c2eca13dcf..27fe337ccc 100644
--- a/OsmAnd/res/xml/navigation_settings_new.xml
+++ b/OsmAnd/res/xml/navigation_settings_new.xml
@@ -9,7 +9,6 @@
android:layout="@layout/preference_with_descr"
android:summary="@string/rendering_value_car_name"
android:title="@string/nav_type_hint"
- app:fragment="net.osmand.plus.settings.SelectProfileBottomSheetDialogFragment"
tools:icon="@drawable/ic_action_car_dark" />
getRoutingProfiles(OsmandApplication context) {
+ public static List getRoutingProfiles(OsmandApplication context) {
List profilesObjects = new ArrayList<>();
profilesObjects.add(new RoutingProfileDataObject(
RoutingProfilesResources.STRAIGHT_LINE_MODE.name(),
diff --git a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java
index c5d0609bfd..9017ca3229 100644
--- a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java
@@ -17,6 +17,7 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment;
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 org.apache.commons.logging.Log;
@@ -223,6 +224,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
FragmentManager fragmentManager = activity.getSupportFragmentManager();
EditProfileFragment editProfileFragment = (EditProfileFragment) fragmentManager.findFragmentByTag(EditProfileFragment.TAG);
SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.class.getName());
+ NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName());
if (editProfileFragment != null) {
switch (type) {
@@ -231,6 +233,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
break;
case TYPE_NAV_PROFILE:
listener = editProfileFragment.getNavProfileListener();
+
break;
case TYPE_ICON:
listener = editProfileFragment.getIconListener();
@@ -238,6 +241,8 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
}
} else if (settingsProfileFragment != null) {
listener = settingsProfileFragment.getBaseProfileListener();
+ } else if (navigationFragment != null) {
+ listener = navigationFragment.getNavProfileListener();
}
}
}
@@ -272,7 +277,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
return icons;
}
- interface SelectProfileListener {
+ public interface SelectProfileListener {
void onSelectedType(int pos, String stringRes);
}
diff --git a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java
index 74a20d1264..39947cdfc0 100644
--- a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java
@@ -88,7 +88,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
CONFIGURE_PROFILE(ConfigureProfileFragment.class.getName(), true, R.xml.configure_profile, R.layout.profile_preference_toolbar_with_switch),
PROXY_SETTINGS(ProxySettingsFragment.class.getName(), false, R.xml.proxy_preferences, R.layout.global_preferences_toolbar_with_switch),
GENERAL_PROFILE(GeneralProfileSettingsFragment.class.getName(), true, R.xml.general_profile_settings, R.layout.profile_preference_toolbar_big),
- NAVIGATION(NavigationFragment.class.getName(), true, R.xml.navigation_settings_new, R.layout.profile_preference_toolbar_big),
+ NAVIGATION(NavigationFragment.class.getName(), true, R.xml.navigation_settings_new, R.layout.profile_preference_toolbar),
COORDINATES_FORMAT(CoordinatesFormatFragment.class.getName(), true, R.xml.coordinates_format, R.layout.profile_preference_toolbar),
ROUTE_PARAMETERS(RouteParametersFragment.class.getName(), true, R.xml.route_parameters, R.layout.profile_preference_toolbar),
SCREEN_ALERTS(ScreenAlertsFragment.class.getName(), true, R.xml.screen_alerts, R.layout.profile_preference_toolbar_with_switch),
diff --git a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java
index 809d4e4b4d..b5bbb5da9d 100644
--- a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java
@@ -90,6 +90,16 @@ public class MainSettingsFragment extends BaseSettingsFragment {
return super.onPreferenceChange(preference, newValue);
}
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ String prefId = preference.getKey();
+ if (APP_PROFILES.equals(preference.getParent().getKey())) {
+ BaseSettingsFragment.showInstance(getActivity(), SettingsScreenType.CONFIGURE_PROFILE, ApplicationMode.valueOfStringKey(prefId, null));
+ return true;
+ }
+ return super.onPreferenceClick(preference);
+ }
+
private void setupConfigureProfilePref() {
ApplicationMode selectedMode = app.getSettings().APPLICATION_MODE.get();
String title = selectedMode.toHumanString(getContext());
diff --git a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java
index abb6aecd49..a05584afb9 100644
--- a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java
@@ -4,13 +4,19 @@ import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.SwitchPreferenceCompat;
+import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.profiles.EditProfileFragment;
import net.osmand.plus.profiles.EditProfileFragment.RoutingProfilesResources;
+import net.osmand.plus.profiles.RoutingProfileDataObject;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
+import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.router.GeneralRouter;
+import java.util.List;
+
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_NAV_PROFILE;
@@ -18,20 +24,30 @@ import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TY
public class NavigationFragment extends BaseSettingsFragment {
public static final String TAG = NavigationFragment.class.getSimpleName();
+ private SelectProfileBottomSheetDialogFragment.SelectProfileListener navTypeListener;
+ List routingProfileDataObjects;
+ private Preference navigationType;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ routingProfileDataObjects = EditProfileFragment.getRoutingProfiles(app);
+ }
@Override
protected void setupPreferences() {
- Preference 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());
SwitchPreferenceCompat turnScreenOn = (SwitchPreferenceCompat) findPreference(settings.TURN_SCREEN_ON_ENABLED.getId());
SwitchPreferenceEx animateMyLocation = (SwitchPreferenceEx) findPreference(settings.ANIMATE_MY_LOCATION.getId());
-
- GeneralRouter gr = app.getRoutingConfig().getRouter(getSelectedAppMode().getRoutingProfile());
- RoutingProfilesResources routingProfilesResources = RoutingProfilesResources.valueOf(gr.getProfileName().toUpperCase());
- navigationType.setSummary(routingProfilesResources.getStringRes());
- navigationType.setIcon(getContentIcon(routingProfilesResources.getIconRes()));
+ if (getSelectedAppMode().getRoutingProfile() != null) {
+ GeneralRouter gr = app.getRoutingConfig().getRouter(getSelectedAppMode().getRoutingProfile());
+ RoutingProfilesResources routingProfilesResources = RoutingProfilesResources.valueOf(gr.getProfileName().toUpperCase());
+ navigationType.setSummary(routingProfilesResources.getStringRes());
+ navigationType.setIcon(getContentIcon(routingProfilesResources.getIconRes()));
+ }
routeParameters.setIcon(getContentIcon(R.drawable.ic_action_route_distance));
showRoutingAlarms.setIcon(getContentIcon(R.drawable.ic_action_alert));
speakRoutingAlarms.setIcon(getContentIcon(R.drawable.ic_action_volume_up));
@@ -56,21 +72,59 @@ public class NavigationFragment extends BaseSettingsFragment {
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals("navigation_type")) {
- if (getSelectedAppMode().isCustomProfile()) {
- final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
- Bundle bundle = new Bundle();
- if (getSelectedAppMode() != null) {
- bundle.putString(SELECTED_KEY, getSelectedAppMode().getRoutingProfile());
- }
- bundle.putString(DIALOG_TYPE, TYPE_NAV_PROFILE);
- dialog.setArguments(bundle);
- if (getActivity() != null) {
- getActivity().getSupportFragmentManager().beginTransaction()
- .add(dialog, "select_nav_type").commitAllowingStateLoss();
- }
+ final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
+ Bundle bundle = new Bundle();
+ if (getSelectedAppMode() != null) {
+ bundle.putString(SELECTED_KEY, getSelectedAppMode().getRoutingProfile());
+ }
+ bundle.putString(DIALOG_TYPE, TYPE_NAV_PROFILE);
+ dialog.setArguments(bundle);
+ if (getActivity() != null) {
+ getActivity().getSupportFragmentManager().beginTransaction()
+ .add(dialog, "select_nav_type").commitAllowingStateLoss();
}
}
- return true;
+ return false;
+ }
+
+ public SelectProfileBottomSheetDialogFragment.SelectProfileListener getNavProfileListener() {
+ if (navTypeListener == null) {
+ navTypeListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() {
+ @Override
+ public void onSelectedType(int pos, String stringRes) {
+ updateRoutingProfile(pos);
+ }
+ };
+ }
+ return navTypeListener;
+ }
+
+ void updateRoutingProfile(int pos) {
+ for (int i = 0; i < routingProfileDataObjects.size(); i++) {
+ if (i == pos) {
+ routingProfileDataObjects.get(i).setSelected(true);
+ } else {
+ routingProfileDataObjects.get(i).setSelected(false);
+ }
+ }
+ RoutingProfileDataObject selectedRoutingProfileDataObject = routingProfileDataObjects.get(pos);
+ navigationType.setSummary(selectedRoutingProfileDataObject.getName());
+ navigationType.setIcon(getContentIcon(selectedRoutingProfileDataObject.getIconRes()));
+ ApplicationMode.ApplicationModeBuilder builder = ApplicationMode.changeBaseMode(getSelectedAppMode());
+ if (selectedRoutingProfileDataObject.getStringKey().equals(
+ RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
+ builder.setRouteService(RouteProvider.RouteService.STRAIGHT);
+ } else if (selectedRoutingProfileDataObject.getStringKey().equals(
+ RoutingProfilesResources.BROUTER_MODE.name())) {
+ builder.setRouteService(RouteProvider.RouteService.BROUTER);
+ } else {
+ builder.setRoutingProfile(selectedRoutingProfileDataObject.getStringKey());
+ }
+
+ ApplicationMode mode = ApplicationMode.saveProfile(builder, app);
+ if (!ApplicationMode.values(app).contains(mode)) {
+ ApplicationMode.changeProfileAvailability(mode, true, app);
+ }
}
private void setupVehicleParametersPref() {