Clean up refactoring
This commit is contained in:
parent
c82f85bb92
commit
20d95707fe
12 changed files with 55 additions and 71 deletions
|
@ -23,6 +23,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.plus.profiles.EditProfileFragment;
|
||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
|
@ -51,7 +52,6 @@ public class ApplicationMode {
|
|||
private final int keyName;
|
||||
// TODO custom profile
|
||||
private ApplicationMode parentAppMode;
|
||||
private int mapIconId = R.drawable.map_world_globe_dark;
|
||||
// TODO custom profile
|
||||
private int smallIconDark = R.drawable.ic_world_globe_dark;
|
||||
private float defaultSpeed = 10f;
|
||||
|
@ -77,31 +77,41 @@ public class ApplicationMode {
|
|||
* DEFAULT("Browse map"), CAR("Car"), BICYCLE("Bicycle"), PEDESTRIAN("Pedestrian"); NAUTICAL("boat"); PUBLIC_TRANSPORT("Public transport"); AIRCRAFT("Aircraft")
|
||||
*/
|
||||
public static final ApplicationMode DEFAULT = create(null, R.string.app_mode_default, "default").speed(1.5f, 5).arrivalDistance(90).defLocation().
|
||||
icon(R.drawable.map_world_globe_dark, R.drawable.ic_world_globe_dark, "map_world_globe_dark").reg();
|
||||
icon(R.drawable.ic_world_globe_dark, "map_world_globe_dark").reg();
|
||||
|
||||
public static final ApplicationMode CAR = create(null, R.string.app_mode_car, "car").speed(15.3f, 35).carLocation().
|
||||
icon(R.drawable.map_action_car_dark, R.drawable.ic_action_car_dark, "ic_action_car_dark").setRoutingProfile("car").reg();
|
||||
icon(R.drawable.ic_action_car_dark, "ic_action_car_dark").setRoutingProfile("car").reg();
|
||||
|
||||
public static final ApplicationMode BICYCLE = create(null, R.string.app_mode_bicycle, "bicycle").speed(5.5f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation().
|
||||
icon(R.drawable.map_action_bicycle_dark, R.drawable.ic_action_bicycle_dark, "ic_action_bicycle_dark").setRoutingProfile("bicycle").reg();
|
||||
icon(R.drawable.ic_action_bicycle_dark, "ic_action_bicycle_dark").setRoutingProfile("bicycle").reg();
|
||||
|
||||
public static final ApplicationMode PEDESTRIAN = create(null, R.string.app_mode_pedestrian, "pedestrian").speed(1.5f, 5).arrivalDistance(45).offRouteDistance(20).
|
||||
icon(R.drawable.map_action_pedestrian_dark, R.drawable.ic_action_pedestrian_dark, "ic_action_pedestrian_dark").setRoutingProfile("pedestrian").reg();
|
||||
icon(R.drawable.ic_action_pedestrian_dark, "ic_action_pedestrian_dark").setRoutingProfile("pedestrian").reg();
|
||||
|
||||
public static final ApplicationMode PUBLIC_TRANSPORT = create(null, R.string.app_mode_public_transport, "public_transport").
|
||||
icon(R.drawable.map_action_bus_dark, R.drawable.ic_action_bus_dark, "ic_action_bus_dark").setRoutingProfile("public_transport").reg();
|
||||
icon(R.drawable.ic_action_bus_dark, "ic_action_bus_dark").setRoutingProfile("public_transport").reg();
|
||||
|
||||
public static final ApplicationMode BOAT = create(null, R.string.app_mode_boat, "boat").speed(5.5f, 20).nauticalLocation().
|
||||
icon(R.drawable.map_action_sail_boat_dark, R.drawable.ic_action_sail_boat_dark, "ic_action_sail_boat_dark").setRoutingProfile("boat").reg();
|
||||
icon(R.drawable.ic_action_sail_boat_dark, "ic_action_sail_boat_dark").setRoutingProfile("boat").reg();
|
||||
|
||||
public static final ApplicationMode AIRCRAFT = create(null, R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation().
|
||||
icon(R.drawable.map_action_aircraft, R.drawable.ic_action_aircraft, "ic_action_aircraft").setRouteService(RouteService.STRAIGHT).setRoutingProfile("STRAIGHT_LINE_MODE").reg();
|
||||
icon(R.drawable.ic_action_aircraft, "ic_action_aircraft").setRouteService(RouteService.STRAIGHT).setRoutingProfile("STRAIGHT_LINE_MODE").reg();
|
||||
|
||||
public static final ApplicationMode SKI = create(null, R.string.app_mode_skiing, "ski").speed(5.5f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation().
|
||||
icon(R.drawable.ic_plugin_skimaps, R.drawable.ic_plugin_skimaps, "ic_plugin_skimaps").setRoutingProfile("ski").reg();
|
||||
icon(R.drawable.ic_plugin_skimaps, "ic_plugin_skimaps").setRoutingProfile("ski").reg();
|
||||
|
||||
|
||||
public static void initRegVisibility() {
|
||||
private static class ApplicationModeBean {
|
||||
@Expose String stringKey;
|
||||
@Expose String userProfileName;
|
||||
@Expose String parent;
|
||||
@Expose String iconName = "map_world_globe_dark";
|
||||
@Expose ProfileIconColors iconColor = ProfileIconColors.DEFAULT;
|
||||
@Expose String routingProfile = null;
|
||||
@Expose RouteService routeService = RouteService.OSMAND;
|
||||
}
|
||||
|
||||
private static void initRegVisibility() {
|
||||
// DEFAULT, CAR, BICYCLE, PEDESTRIAN, PUBLIC_TRANSPORT, BOAT, AIRCRAFT, SKI
|
||||
ApplicationMode[] exceptDefault = new ApplicationMode[]{CAR, BICYCLE, PEDESTRIAN, PUBLIC_TRANSPORT, BOAT, AIRCRAFT, SKI};
|
||||
ApplicationMode[] all = null;
|
||||
|
@ -166,8 +176,7 @@ public class ApplicationMode {
|
|||
return applicationMode;
|
||||
}
|
||||
|
||||
public ApplicationModeBuilder icon(int mapIcon, int smallIconDark, String iconName) {
|
||||
applicationMode.mapIconId = mapIcon;
|
||||
public ApplicationModeBuilder icon(int smallIconDark, String iconName) {
|
||||
applicationMode.smallIconDark = smallIconDark;
|
||||
applicationMode.iconName = iconName;
|
||||
return this;
|
||||
|
@ -445,8 +454,13 @@ public class ApplicationMode {
|
|||
return stringKey;
|
||||
}
|
||||
|
||||
public int getMapIconId() {
|
||||
return mapIconId;
|
||||
|
||||
public String getUserProfileName(OsmandApplication app) {
|
||||
// TODO toHumanStringCTX
|
||||
if(keyName > 0) {
|
||||
return app.getString(keyName);
|
||||
}
|
||||
return userProfileName;
|
||||
}
|
||||
|
||||
public String toHumanString(Context ctx) {
|
||||
|
@ -458,14 +472,6 @@ public class ApplicationMode {
|
|||
|
||||
}
|
||||
|
||||
public String toHumanStringCtx(Context ctx) {
|
||||
if (Algorithms.isEmpty(userProfileName)) {
|
||||
return ctx.getString(keyName);
|
||||
} else {
|
||||
return userProfileName;
|
||||
}
|
||||
}
|
||||
|
||||
public RouteService getRouteService() {
|
||||
return routeService;
|
||||
}
|
||||
|
@ -507,13 +513,6 @@ public class ApplicationMode {
|
|||
return routingProfile;
|
||||
}
|
||||
|
||||
public String getUserProfileName(OsmandApplication app) {
|
||||
if(keyName > 0) {
|
||||
return app.getString(keyName);
|
||||
}
|
||||
return userProfileName;
|
||||
}
|
||||
|
||||
public static void onApplicationStart(OsmandSettings settings) {
|
||||
initCustomModes(settings);
|
||||
initRegVisibility();
|
||||
|
@ -562,6 +561,7 @@ public class ApplicationMode {
|
|||
public static ApplicationMode saveNewCustomProfile(ApplicationModeBuilder builder, OsmandApplication app) {
|
||||
ApplicationMode mode = builder.customReg();
|
||||
ApplicationMode.saveCustomModeToSettings(app.getSettings());
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
|
|
|
@ -1151,11 +1151,6 @@ public class OsmandSettings {
|
|||
DAYNIGHT_MODE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, DayNightMode.DAY);
|
||||
}
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final OsmandPreference<RouteService> ROUTER_SERVICE =
|
||||
new EnumIntPreference<RouteService>("router_service", RouteService.OSMAND,
|
||||
RouteService.values()).makeProfile();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final CommonPreference<Boolean> AUTO_ZOOM_MAP = new BooleanPreference("auto_zoom_map_on_off", false).makeProfile().cache();
|
||||
{
|
||||
|
|
|
@ -405,9 +405,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
|
|||
|
||||
void updateModeButton(ApplicationMode mode) {
|
||||
boolean nightMode = !getMyApplication().getSettings().isLightContent();
|
||||
String title = Algorithms.isEmpty(mode.getUserProfileName())
|
||||
? mode.toHumanString(SettingsBaseActivity.this)
|
||||
: mode.getUserProfileName();
|
||||
String title = mode.toHumanString(SettingsBaseActivity.this);
|
||||
|
||||
getModeTitleTV().setText(title);
|
||||
getModeSubTitleTV().setText(getAppModeDescription(mode));
|
||||
|
|
|
@ -238,7 +238,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
PreferenceCategory cat = (PreferenceCategory) screen.findPreference("routing_preferences");
|
||||
cat.removeAll();
|
||||
CheckBoxPreference fastRoute = createCheckBoxPreference(settings.FAST_ROUTE_MODE, R.string.fast_route_mode, R.string.fast_route_mode_descr);
|
||||
if(settings.ROUTER_SERVICE.get() != RouteService.OSMAND) {
|
||||
if(settings.getApplicationMode().getRouteService() != RouteService.OSMAND) {
|
||||
cat.addPreference(fastRoute);
|
||||
} else {
|
||||
ApplicationMode am = settings.getApplicationMode();
|
||||
|
|
|
@ -75,7 +75,7 @@ public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFrag
|
|||
public void onProfilePressed(ApplicationMode item) {
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
|
||||
if (!Algorithms.isEmpty(item.getUserProfileName())) {
|
||||
if (item.getParent() != null) {
|
||||
intent.putExtra(IS_USER_PROFILE, true);
|
||||
}
|
||||
startActivity(intent);
|
||||
|
|
|
@ -633,32 +633,26 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
|
||||
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode
|
||||
.createCustomMode(profile.parent, profile.userProfileTitle.trim(), customStringKey)
|
||||
.icon(profile.iconId, profile.iconId, profile.iconStringName);
|
||||
.icon(profile.iconId, profile.iconStringName);
|
||||
|
||||
if (profile.routingProfileDataObject != null) {
|
||||
if(profile.routingProfileDataObject.getStringKey().equals(
|
||||
RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
|
||||
builder.setRouteService(RouteService.STRAIGHT);
|
||||
} else if(profile.routingProfileDataObject.getStringKey().equals(
|
||||
RoutingProfilesResources.BROUTER_MODE.name())) {
|
||||
builder.setRouteService(RouteService.BROUTER);
|
||||
} else if (profile.routingProfileDataObject != null) {
|
||||
builder.setRoutingProfile(profile.routingProfileDataObject.getStringKey());
|
||||
}
|
||||
|
||||
if(EditProfileFragment.RoutingProfilesResources.STRAIGHT_LINE_MODE.toString()
|
||||
builder.setColor(profile.iconColor);
|
||||
|
||||
ApplicationMode newMode = ApplicationMode.saveNewCustomProfile(builder, getMyApplication());
|
||||
|
||||
|
||||
// TODO ?????
|
||||
if (!ApplicationMode.values(app).contains(mode)) {
|
||||
boolean save = ApplicationMode.changeProfileStatus(mode, true, getMyApplication());
|
||||
|
||||
if (save && getSettings() != null) {
|
||||
if (profile.routingProfileDataObject.getStringKey()
|
||||
.equals(RoutingProfilesResources.STRAIGHT_LINE_MODE.toString())) {
|
||||
getSettings().ROUTER_SERVICE.setModeValue(mode, RouteService.STRAIGHT);
|
||||
} else if (profile.routingProfileDataObject.getStringKey()
|
||||
.equals(RoutingProfilesResources.BROUTER_MODE.toString())) {
|
||||
getSettings().ROUTER_SERVICE.setModeValue(mode, RouteService.BROUTER);
|
||||
} else {
|
||||
getSettings().ROUTER_SERVICE.setModeValue(mode, RouteService.OSMAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
isDataChanged = false;
|
||||
isCancelAllowed = true;
|
||||
|
@ -731,14 +725,14 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
static List<RoutingProfileDataObject> getRoutingProfiles(OsmandApplication context) {
|
||||
List<RoutingProfileDataObject> profilesObjects = new ArrayList<>();
|
||||
profilesObjects.add(new RoutingProfileDataObject(
|
||||
RoutingProfilesResources.STRAIGHT_LINE_MODE.toString(),
|
||||
RoutingProfilesResources.STRAIGHT_LINE_MODE.name(),
|
||||
context.getString(RoutingProfilesResources.STRAIGHT_LINE_MODE.getStringRes()),
|
||||
context.getString(R.string.special_routing_type),
|
||||
RoutingProfilesResources.STRAIGHT_LINE_MODE.getIconRes(),
|
||||
false, null));
|
||||
if (context.getBRouterService() != null) {
|
||||
profilesObjects.add(new RoutingProfileDataObject(
|
||||
RoutingProfilesResources.BROUTER_MODE.toString(),
|
||||
RoutingProfilesResources.BROUTER_MODE.name(),
|
||||
context.getString(RoutingProfilesResources.BROUTER_MODE.getStringRes()),
|
||||
context.getString(R.string.third_party_routing_type),
|
||||
RoutingProfilesResources.BROUTER_MODE.getIconRes(),
|
||||
|
@ -766,7 +760,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
public enum RoutingProfilesResources {
|
||||
STRAIGHT_LINE_MODE(R.string.routing_profile_straightline,R.drawable.ic_action_split_interval),
|
||||
STRAIGHT_LINE_MODE(R.string.routing_profile_straightline, R.drawable.ic_action_split_interval),
|
||||
BROUTER_MODE(R.string.routing_profile_broutrer, R.drawable.ic_action_split_interval),
|
||||
CAR(R.string.rendering_value_car_name, R.drawable.ic_action_car_dark),
|
||||
PEDESTRIAN(R.string.rendering_value_pedestrian_name, R.drawable.map_action_pedestrian_dark),
|
||||
|
|
|
@ -110,7 +110,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
public void onProfilePressed(ApplicationMode item) {
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
|
||||
if (!Algorithms.isEmpty(item.getUserProfileName())) {
|
||||
if (item.getParent() != null) {
|
||||
intent.putExtra(IS_USER_PROFILE, true);
|
||||
}
|
||||
startActivity(intent);
|
||||
|
|
|
@ -422,7 +422,7 @@ public class RoutingOptionsHelper {
|
|||
final OsmandSettings settings = app.getSettings();
|
||||
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
|
||||
RouteProvider.GPXRouteParamsBuilder rparams = app.getRoutingHelper().getCurrentGPXRoute();
|
||||
boolean osmandRouter = settings.ROUTER_SERVICE.getModeValue(am) == RouteProvider.RouteService.OSMAND;
|
||||
boolean osmandRouter = am.getRouteService() == RouteProvider.RouteService.OSMAND;
|
||||
if (!osmandRouter) {
|
||||
list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet,
|
||||
app.getString(R.string.calculate_osmand_route_without_internet), settings.GPX_ROUTE_CALC_OSMAND_PARTS
|
||||
|
|
|
@ -22,7 +22,6 @@ public class RouteCalculationParams {
|
|||
public OsmandApplication ctx;
|
||||
public RoutingContext cachedRoutingContext;
|
||||
public ApplicationMode mode;
|
||||
public RouteService type;
|
||||
public GPXRouteParams gpxRoute;
|
||||
public RouteCalculationResult previousToRecalculate;
|
||||
public boolean onlyStartPointChanged;
|
||||
|
|
|
@ -296,22 +296,22 @@ public class RouteProvider {
|
|||
if (params.start != null && params.end != null) {
|
||||
if(log.isInfoEnabled()){
|
||||
log.info("Start finding route from " + params.start + " to " + params.end +" using " +
|
||||
params.type.getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
params.mode.getRouteService().getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
try {
|
||||
RouteCalculationResult res;
|
||||
boolean calcGPXRoute = params.gpxRoute != null && !params.gpxRoute.points.isEmpty();
|
||||
if(calcGPXRoute && !params.gpxRoute.calculateOsmAndRoute){
|
||||
res = calculateGpxRoute(params);
|
||||
} else if (params.type == RouteService.OSMAND) {
|
||||
} else if (params.mode.getRouteService() == RouteService.OSMAND) {
|
||||
res = findVectorMapsRoute(params, calcGPXRoute);
|
||||
} else if (params.type == RouteService.BROUTER) {
|
||||
} else if (params.mode.getRouteService() == RouteService.BROUTER) {
|
||||
res = findBROUTERRoute(params);
|
||||
// } else if (params.type == RouteService.ORS) {
|
||||
// res = findORSRoute(params);
|
||||
// } else if (params.type == RouteService.OSRM) {
|
||||
// res = findOSRMRoute(params);
|
||||
} else if (params.type == RouteService.STRAIGHT){
|
||||
} else if (params.mode.getRouteService() == RouteService.STRAIGHT){
|
||||
res = findStraightRoute(params);
|
||||
}
|
||||
else {
|
||||
|
@ -410,7 +410,6 @@ public class RouteProvider {
|
|||
rp.start = routeParams.start;
|
||||
rp.end = routeParams.end;
|
||||
rp.leftSide = routeParams.leftSide;
|
||||
rp.type = routeParams.type;
|
||||
rp.fast = routeParams.fast;
|
||||
rp.onlyStartPointChanged = routeParams.onlyStartPointChanged;
|
||||
rp.previousToRecalculate = routeParams.previousToRecalculate;
|
||||
|
@ -776,7 +775,7 @@ public class RouteProvider {
|
|||
}
|
||||
|
||||
private RouteCalculationResult applicationModeNotSupported(RouteCalculationParams params) {
|
||||
return new RouteCalculationResult("Application mode '"+ params.mode.toHumanStringCtx(params.ctx)+ "' is not supported.");
|
||||
return new RouteCalculationResult("Application mode '"+ params.mode.toHumanString(params.ctx)+ "' is not supported.");
|
||||
}
|
||||
|
||||
private RouteCalculationResult interrupted() {
|
||||
|
|
|
@ -942,7 +942,8 @@ public class RoutingHelper {
|
|||
}
|
||||
return;
|
||||
}
|
||||
final boolean onlineSourceWithoutInternet = !res.isCalculated() && params.type.isOnline() && !settings.isInternetConnectionAvailable();
|
||||
final boolean onlineSourceWithoutInternet = !res.isCalculated() &&
|
||||
params.mode.getRouteService().isOnline() && !settings.isInternetConnectionAvailable();
|
||||
if (onlineSourceWithoutInternet && settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
|
||||
if (params.previousToRecalculate != null && params.previousToRecalculate.isCalculated()) {
|
||||
res = provider.recalculatePartOfflineRoute(res, params);
|
||||
|
@ -1034,11 +1035,10 @@ public class RoutingHelper {
|
|||
}
|
||||
params.leftSide = settings.DRIVING_REGION.get().leftHandDriving;
|
||||
params.fast = settings.FAST_ROUTE_MODE.getModeValue(mode);
|
||||
params.type = settings.ROUTER_SERVICE.getModeValue(mode);
|
||||
params.mode = mode;
|
||||
params.ctx = app;
|
||||
boolean updateProgress = false;
|
||||
if (params.type == RouteService.OSMAND) {
|
||||
if (params.mode.getRouteService() == RouteService.OSMAND) {
|
||||
params.calculationProgress = new RouteCalculationProgress();
|
||||
updateProgress = true;
|
||||
}
|
||||
|
@ -1112,7 +1112,6 @@ public class RoutingHelper {
|
|||
public static void applyApplicationSettings(RouteCalculationParams params, OsmandSettings settings, ApplicationMode mode) {
|
||||
params.leftSide = settings.DRIVING_REGION.get().leftHandDriving;
|
||||
params.fast = settings.FAST_ROUTE_MODE.getModeValue(mode);
|
||||
params.type = settings.ROUTER_SERVICE.getModeValue(mode);
|
||||
}
|
||||
|
||||
public void setProgressBar(RouteCalculationProgressCallback progressRoute) {
|
||||
|
|
|
@ -166,7 +166,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(map, app, false);
|
||||
registerSideWidget(bigInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn, WIDGET_NEXT_TURN, true, 5);
|
||||
NextTurnInfoWidget smallInfoControl = ric.createNextInfoControl(map, app, true);
|
||||
registerSideWidget(smallInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn_small, ApplicationMode.WIDGET_NEXT_TURN_SMALL, true, 6);
|
||||
registerSideWidget(smallInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn_small, WIDGET_NEXT_TURN_SMALL, true, 6);
|
||||
NextTurnInfoWidget nextNextInfoControl = ric.createNextNextInfoControl(map, app, true);
|
||||
registerSideWidget(nextNextInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_next_turn, WIDGET_NEXT_NEXT_TURN,true, 7);
|
||||
|
||||
|
|
Loading…
Reference in a new issue