Setting navigation profile to application profile. Work in progress. Need testing.
This commit is contained in:
parent
195112ac63
commit
08d28d65ed
7 changed files with 105 additions and 63 deletions
|
@ -91,7 +91,8 @@ public class GeneralRouter implements VehicleRouter {
|
|||
PEDESTRIAN,
|
||||
BICYCLE,
|
||||
BOAT,
|
||||
PUBLIC_TRANSPORT
|
||||
PUBLIC_TRANSPORT,
|
||||
CUSTOM
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import net.osmand.router.GeneralRouter.RouteAttributeContext;
|
|||
import net.osmand.router.GeneralRouter.RouteDataObjectAttribute;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -19,6 +20,8 @@ import java.util.Map;
|
|||
import java.util.Stack;
|
||||
|
||||
public class RoutingConfiguration {
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(RoutingConfiguration.class);
|
||||
|
||||
public static final int DEFAULT_MEMORY_LIMIT = 30;
|
||||
public final float DEVIATION_RADIUS = 3000;
|
||||
|
@ -131,6 +134,10 @@ public class RoutingConfiguration {
|
|||
|
||||
}
|
||||
|
||||
public Map<String, GeneralRouter> getAllRoutes() {
|
||||
return routers;
|
||||
}
|
||||
|
||||
public void removeImpassableRoad(RouteDataObject obj) {
|
||||
impassableRoadLocations.remove(obj.id);
|
||||
}
|
||||
|
|
|
@ -7,9 +7,7 @@ import com.google.gson.GsonBuilder;
|
|||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.StateChangedListener;
|
||||
|
||||
|
@ -21,10 +19,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.plus.profiles.RoutingProfile;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.sf.junidecode.App;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
|
||||
|
@ -233,8 +228,8 @@ public class ApplicationMode {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ApplicationModeBuilder assignRoutingProfile(GeneralRouter.GeneralRouterProfile profile) {
|
||||
applicationMode.assignedRoutingProfile = profile;
|
||||
public ApplicationModeBuilder setRoutingProfile(String routingProfileName) {
|
||||
applicationMode.routingProfile = routingProfileName;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -471,8 +466,8 @@ public class ApplicationMode {
|
|||
return this == mode || getParent() == mode;
|
||||
}
|
||||
|
||||
public GeneralRouter.GeneralRouterProfile getAssignedRouteingProfile() {
|
||||
return assignedRoutingProfile;
|
||||
public String getRoutingProfile() {
|
||||
return routingProfile;
|
||||
}
|
||||
|
||||
public int getMapIconsSetId() {
|
||||
|
@ -502,7 +497,7 @@ public class ApplicationMode {
|
|||
@Expose private int locationIconNight = R.drawable.map_pedestrian_location_night;
|
||||
@Expose private int locationIconDayLost = R.drawable.map_pedestrian_location_lost;
|
||||
@Expose private int locationIconNightLost = R.drawable.map_pedestrian_location_lost_night;
|
||||
@Expose private GeneralRouter.GeneralRouterProfile assignedRoutingProfile = null;
|
||||
@Expose private String routingProfile = null;
|
||||
private static StateChangedListener<String> listener;
|
||||
private static OsmAndAppCustomization.OsmAndAppCustomizationListener customizationListener;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.content.Intent;
|
||||
|
@ -23,14 +22,13 @@ import android.widget.FrameLayout;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
|
@ -39,8 +37,8 @@ import net.osmand.plus.base.BaseOsmAndFragment;
|
|||
import net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.ProfileTypeDialogListener;
|
||||
import net.osmand.plus.profiles.SelectIconBottomSheetDialogFragment.IconIdListener;
|
||||
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
|
||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
||||
import net.sf.junidecode.App;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
import net.osmand.util.Algorithms;
|
||||
import org.apache.commons.logging.Log;
|
||||
import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
|
||||
|
||||
|
@ -55,6 +53,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
public static final String SELECTED_PROFILE = "editedProfile";
|
||||
|
||||
TempApplicationProfile profile = null;
|
||||
ApplicationMode mode = null;
|
||||
ArrayList<RoutingProfile> routingProfiles;
|
||||
OsmandApplication app;
|
||||
RoutingProfile selectedRoutingProfile = null;
|
||||
|
@ -75,11 +74,8 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
String modeName = getArguments().getString("stringKey", "car");
|
||||
isNew = getArguments().getBoolean("isNew", false);
|
||||
isUserProfile = getArguments().getBoolean("isUserProfile", false);
|
||||
|
||||
profile = new TempApplicationProfile(
|
||||
ApplicationMode.valueOfStringKey(modeName, ApplicationMode.DEFAULT), isNew, isUserProfile);
|
||||
|
||||
LOG.debug("Name: " + modeName + ", ");
|
||||
mode = ApplicationMode.valueOfStringKey(modeName, ApplicationMode.DEFAULT);
|
||||
profile = new TempApplicationProfile(mode, isNew, isUserProfile);
|
||||
}
|
||||
routingProfiles = getRoutingProfiles();
|
||||
}
|
||||
|
@ -109,8 +105,6 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
GradientDrawable selectIconBtnBackground = (GradientDrawable) profileIconBtn
|
||||
.getBackground();
|
||||
|
||||
|
||||
|
||||
if (isNightMode) {
|
||||
profileNameTextBox.setPrimaryColor(ContextCompat.getColor(app, R.color.color_dialog_buttons_dark));
|
||||
navTypeTextBox.setPrimaryColor(ContextCompat.getColor(app, R.color.color_dialog_buttons_dark));
|
||||
|
@ -121,22 +115,61 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
|
||||
String title = "New Profile";
|
||||
int startIconId = R.drawable.map_world_globe_dark;
|
||||
LOG.debug("isUserProfile = " + isUserProfile);
|
||||
LOG.debug("isNew = " + isNew);
|
||||
|
||||
if (isUserProfile && !isNew) {
|
||||
title = profile.getUserProfileTitle();
|
||||
profileNameEt.setText(title);
|
||||
startIconId = profile.iconId;
|
||||
} else if (isNew) {
|
||||
title = String.format("%s (new)", getResources().getString(profile.parent.getStringResource()));
|
||||
title = String.format("Custom %s", getResources().getString(profile.parent.getStringResource()));
|
||||
profileNameEt.setText(title);
|
||||
profileNameEt.selectAll();
|
||||
startIconId = profile.getParent().getSmallIconDark();
|
||||
profile.setIconId(startIconId);
|
||||
} else if (profile.getKey() != -1){
|
||||
title = getResources().getString(profile.getKey());
|
||||
profileNameEt.setText(profile.getKey());
|
||||
startIconId = profile.getIconId();
|
||||
}
|
||||
|
||||
profile.setUserProfileTitle(title);
|
||||
|
||||
if (!Algorithms.isEmpty(mode.getRoutingProfile())) {
|
||||
for (RoutingProfile r : routingProfiles) {
|
||||
if (mode.getRoutingProfile().equals(r.getStringKey())) {
|
||||
profile.setRoutingProfile(r);
|
||||
r.setSelected(true);
|
||||
navTypeEt.setText(r.getName());
|
||||
navTypeEt.clearFocus();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (RoutingProfile rp : routingProfiles) {
|
||||
if (profile.getStringKey().equals(rp.getStringKey())) {
|
||||
switch (rp.getStringKey()) {
|
||||
case "car":
|
||||
navTypeEt.setText(R.string.rendering_value_car_name);
|
||||
break;
|
||||
case "pedestrian":
|
||||
navTypeEt.setText(R.string.rendering_value_pedestrian_name);
|
||||
break;
|
||||
case "bicycle":
|
||||
navTypeEt.setText(R.string.rendering_value_bicycle_name);
|
||||
break;
|
||||
case "public_transport":
|
||||
navTypeEt.setText(R.string.app_mode_public_transport);
|
||||
break;
|
||||
case "boat":
|
||||
navTypeEt.setText(R.string.app_mode_boat);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
navTypeEt.clearFocus();
|
||||
}
|
||||
|
||||
|
||||
|
||||
profileNameEt.clearFocus();
|
||||
|
||||
if (getActivity() != null && ((EditProfileActivity) getActivity()).getSupportActionBar() != null) {
|
||||
|
@ -292,6 +325,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -356,6 +390,10 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
break;
|
||||
}
|
||||
|
||||
if (profile.getRoutingProfile() != null) {
|
||||
builder.setRoutingProfile(profile.getRoutingProfile().getStringKey());
|
||||
}
|
||||
|
||||
ApplicationMode mode = builder.customReg();
|
||||
ApplicationMode.saveCustomModeToSettings(getSettings());
|
||||
|
||||
|
@ -395,39 +433,43 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For now there are only default nav profiles placeholders todo: add profiles from custom routing xml-s
|
||||
*/
|
||||
private ArrayList<RoutingProfile> getRoutingProfiles() {
|
||||
ArrayList<RoutingProfile> routingProfiles = new ArrayList<>();
|
||||
for (GeneralRouterProfile navProfileName : GeneralRouterProfile.values()) {
|
||||
String name = "";
|
||||
int iconRes = -1;
|
||||
switch (navProfileName) {
|
||||
case CAR:
|
||||
Map<String, GeneralRouter> routingProfilesNames = getMyApplication().getDefaultRoutingConfig().getAllRoutes();
|
||||
for (Entry<String, GeneralRouter> e: routingProfilesNames.entrySet()) {
|
||||
String name;
|
||||
String description = getResources().getString(R.string.osmand_default_routing);
|
||||
int iconRes;
|
||||
switch (e.getKey()) {
|
||||
case "car":
|
||||
iconRes = R.drawable.ic_action_car_dark;
|
||||
name = getString(R.string.rendering_value_car_name);
|
||||
break;
|
||||
case PEDESTRIAN:
|
||||
case "pedestrian":
|
||||
iconRes = R.drawable.map_action_pedestrian_dark;
|
||||
name = getString(R.string.rendering_value_pedestrian_name);
|
||||
break;
|
||||
case BICYCLE:
|
||||
case "bicycle":
|
||||
iconRes = R.drawable.map_action_bicycle_dark;
|
||||
name = getString(R.string.rendering_value_bicycle_name);
|
||||
break;
|
||||
case PUBLIC_TRANSPORT:
|
||||
case "public_transport":
|
||||
iconRes = R.drawable.map_action_bus_dark;
|
||||
name = getString(R.string.app_mode_public_transport);
|
||||
break;
|
||||
case BOAT:
|
||||
case "boat":
|
||||
iconRes = R.drawable.map_action_sail_boat_dark;
|
||||
name = getString(R.string.app_mode_boat);
|
||||
break;
|
||||
default:
|
||||
iconRes = R.drawable.ic_action_world_globe;
|
||||
name = Algorithms.capitalizeFirstLetterAndLowercase(e.getKey().replace("_", " "));
|
||||
description = "Custom profile from profile.xml";
|
||||
break;
|
||||
}
|
||||
routingProfiles
|
||||
.add(new RoutingProfile(name, getResources().getString(R.string.osmand_default_routing), iconRes, false));
|
||||
routingProfiles.add(new RoutingProfile(e.getKey(), name, description, iconRes, false));
|
||||
}
|
||||
|
||||
return routingProfiles;
|
||||
}
|
||||
|
||||
|
@ -438,8 +480,6 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
String userProfileTitle = "";
|
||||
ApplicationMode parent = null;
|
||||
int iconId = R.drawable.map_world_globe_dark;
|
||||
float defaultSpeed = 10f; //todo use default or what?
|
||||
int minDistanceForTurn = 50; //todo use default or what?
|
||||
RoutingProfile routingProfile = null;
|
||||
|
||||
TempApplicationProfile(ApplicationMode mode, boolean isNew, boolean isUserProfile) {
|
||||
|
@ -456,7 +496,6 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
stringKey = mode.getStringKey();
|
||||
iconId = mode.getSmallIconDark();
|
||||
}
|
||||
LOG.debug("Parent: " + getParent());
|
||||
}
|
||||
|
||||
public RoutingProfile getRoutingProfile() {
|
||||
|
|
|
@ -159,7 +159,7 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
});
|
||||
if (item instanceof RoutingProfile) {
|
||||
holder.descr.setText(Algorithms
|
||||
.capitalizeFirstLetterAndLowercase(((RoutingProfile) item).getParent()));
|
||||
.capitalizeFirstLetterAndLowercase(((RoutingProfile) item).getDescription()));
|
||||
if (((RoutingProfile) item).isSelected()) {
|
||||
holder.radioButton.setChecked(true);
|
||||
previousSelection = position;
|
||||
|
|
|
@ -2,24 +2,18 @@ package net.osmand.plus.profiles;
|
|||
|
||||
import android.os.Parcel;
|
||||
|
||||
import net.osmand.router.GeneralRouter;
|
||||
|
||||
public class RoutingProfile extends ProfileDataObject {
|
||||
|
||||
private String parent;
|
||||
private String stringKey;
|
||||
private boolean isSelected;
|
||||
private String routerProfile;
|
||||
|
||||
public RoutingProfile(String name, String parent, int iconRes, boolean isSelected) {
|
||||
super(name, parent, iconRes);
|
||||
this.parent = parent;
|
||||
public RoutingProfile(String stringKey, String name, String descr, int iconRes, boolean isSelected) {
|
||||
super(name, descr, iconRes);
|
||||
this.stringKey = stringKey;
|
||||
this.isSelected = isSelected;
|
||||
}
|
||||
|
||||
public String getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return isSelected;
|
||||
}
|
||||
|
@ -28,9 +22,13 @@ public class RoutingProfile extends ProfileDataObject {
|
|||
isSelected = selected;
|
||||
}
|
||||
|
||||
public String getStringKey() {
|
||||
return stringKey;
|
||||
}
|
||||
|
||||
protected RoutingProfile(Parcel in) {
|
||||
super(in);
|
||||
parent = in.readString();
|
||||
stringKey = in.readString();
|
||||
isSelected = in.readByte() != 0;
|
||||
}
|
||||
|
||||
|
@ -54,7 +52,7 @@ public class RoutingProfile extends ProfileDataObject {
|
|||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeString(parent);
|
||||
dest.writeString(stringKey);
|
||||
dest.writeByte((byte) (isSelected ? 1 : 0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -685,9 +685,10 @@ public class RouteProvider {
|
|||
private RoutingConfiguration initOsmAndRoutingConfig(Builder config, final RouteCalculationParams params, OsmandSettings settings,
|
||||
GeneralRouter generalRouter) throws IOException, FileNotFoundException {
|
||||
GeneralRouterProfile p ;
|
||||
if (params.mode.getAssignedRouteingProfile() != null ) {
|
||||
//todo get assigned routing profile from ApplicationMode. Maybe assign routing profiles to default modes?
|
||||
p = params.mode.getAssignedRouteingProfile();
|
||||
|
||||
if (params.mode.getRoutingProfile() != null ) {
|
||||
//todo get assigned routing profile from ApplicationMode
|
||||
p = GeneralRouterProfile.CUSTOM;
|
||||
} else if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
|
||||
p = GeneralRouterProfile.BICYCLE;
|
||||
} else if (params.mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
|
||||
|
@ -699,7 +700,8 @@ public class RouteProvider {
|
|||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
log.debug("General Router Profile:" + p.name());
|
||||
|
||||
Map<String, String> paramsR = new LinkedHashMap<String, String>();
|
||||
for(Map.Entry<String, RoutingParameter> e : generalRouter.getParameters().entrySet()){
|
||||
String key = e.getKey();
|
||||
|
@ -727,8 +729,8 @@ public class RouteProvider {
|
|||
// make visible
|
||||
int memoryLimit = (int) (0.95 * ((rt.maxMemory() - rt.totalMemory()) + rt.freeMemory()) / mb);
|
||||
log.warn("Use " + memoryLimit + " MB Free " + rt.freeMemory() / mb + " of " + rt.totalMemory() / mb + " max " + rt.maxMemory() / mb);
|
||||
|
||||
RoutingConfiguration cf = config.build(p.name().toLowerCase(), params.start.hasBearing() ?
|
||||
String name = p == GeneralRouterProfile.CUSTOM ? params.mode.getRoutingProfile() : p.name().toLowerCase();
|
||||
RoutingConfiguration cf = config.build(name, params.start.hasBearing() ?
|
||||
params.start.getBearing() / 180d * Math.PI : null,
|
||||
memoryLimit, paramsR);
|
||||
return cf;
|
||||
|
|
Loading…
Reference in a new issue