Fix crashes
This commit is contained in:
parent
33948c4e25
commit
5f8b542664
4 changed files with 39 additions and 50 deletions
|
@ -561,14 +561,16 @@ public class AppInitializer implements IProgress {
|
|||
protected Builder doInBackground(Void... voids) {
|
||||
File routingFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
|
||||
RoutingConfiguration.Builder builder = RoutingConfiguration.getDefault();
|
||||
if (routingFolder.isDirectory() && routingFolder.listFiles().length > 0) {
|
||||
if (routingFolder.isDirectory()) {
|
||||
File[] fl = routingFolder.listFiles();
|
||||
for (File f : fl) {
|
||||
if (f.isFile() && f.getName().endsWith(".xml") && f.canRead()) {
|
||||
try {
|
||||
RoutingConfiguration.parseFromInputStream(new FileInputStream(f), f.getName(), builder);
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
if (fl != null && fl.length > 0) {
|
||||
for (File f : fl) {
|
||||
if (f.isFile() && f.getName().endsWith(".xml") && f.canRead()) {
|
||||
try {
|
||||
RoutingConfiguration.parseFromInputStream(new FileInputStream(f), f.getName(), builder);
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,10 @@ import com.google.gson.GsonBuilder;
|
|||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -49,8 +46,6 @@ import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_TIME;
|
|||
|
||||
public class ApplicationMode {
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(ApplicationMode.class);
|
||||
|
||||
private static Map<String, Set<ApplicationMode>> widgetsVisibilityMap = new LinkedHashMap<>();
|
||||
private static Map<String, Set<ApplicationMode>> widgetsAvailabilityMap = new LinkedHashMap<>();
|
||||
|
||||
|
@ -64,6 +59,7 @@ public class ApplicationMode {
|
|||
private final int keyName;
|
||||
private final String stringKey;
|
||||
private String userProfileName;
|
||||
private int descriptionId;
|
||||
|
||||
private ApplicationMode parentAppMode;
|
||||
private String iconResName = "ic_world_globe_dark";
|
||||
|
@ -97,29 +93,29 @@ 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 = createBase( R.string.app_mode_default, "default").speed(1.5f, 5).arrivalDistance(90).defLocation().
|
||||
public static final ApplicationMode DEFAULT = createBase(R.string.app_mode_default, "default").speed(1.5f, 5).arrivalDistance(90).defLocation().
|
||||
icon(R.drawable.ic_world_globe_dark, R.drawable.map_world_globe_dark, "ic_world_globe_dark").reg();
|
||||
|
||||
public static final ApplicationMode CAR = createBase( R.string.app_mode_car, "car").speed(12.5f, 35).carLocation().
|
||||
icon(R.drawable.ic_action_car_dark, R.drawable.map_action_car_dark, "ic_action_car_dark").setRoutingProfile("car").reg();
|
||||
public static final ApplicationMode CAR = createBase(R.string.app_mode_car, "car").speed(12.5f, 35).carLocation().
|
||||
icon(R.drawable.ic_action_car_dark, R.drawable.map_action_car_dark, "ic_action_car_dark").setRoutingProfile("car").description(R.string.base_profile_descr_car).reg();
|
||||
|
||||
public static final ApplicationMode BICYCLE = createBase( R.string.app_mode_bicycle, "bicycle").speed(2.77f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation().
|
||||
icon(R.drawable.ic_action_bicycle_dark, R.drawable.map_action_bicycle_dark,"ic_action_bicycle_dark").setRoutingProfile("bicycle").reg();
|
||||
public static final ApplicationMode BICYCLE = createBase(R.string.app_mode_bicycle, "bicycle").speed(2.77f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation().
|
||||
icon(R.drawable.ic_action_bicycle_dark, R.drawable.map_action_bicycle_dark,"ic_action_bicycle_dark").setRoutingProfile("bicycle").description(R.string.base_profile_descr_bicycle).reg();
|
||||
|
||||
public static final ApplicationMode PEDESTRIAN = createBase( R.string.app_mode_pedestrian, "pedestrian").speed(1.11f, 5).arrivalDistance(45).offRouteDistance(20).
|
||||
icon(R.drawable.ic_action_pedestrian_dark, R.drawable.map_action_pedestrian_dark, "ic_action_pedestrian_dark").setRoutingProfile("pedestrian").reg();
|
||||
public static final ApplicationMode PEDESTRIAN = createBase(R.string.app_mode_pedestrian, "pedestrian").speed(1.11f, 5).arrivalDistance(45).offRouteDistance(20).
|
||||
icon(R.drawable.ic_action_pedestrian_dark, R.drawable.map_action_pedestrian_dark, "ic_action_pedestrian_dark").setRoutingProfile("pedestrian").description(R.string.base_profile_descr_pedestrian).reg();
|
||||
|
||||
public static final ApplicationMode PUBLIC_TRANSPORT = createBase( R.string.app_mode_public_transport, "public_transport").
|
||||
icon(R.drawable.ic_action_bus_dark, R.drawable.map_action_bus_dark,"ic_action_bus_dark").setRoutingProfile("public_transport").reg();
|
||||
public static final ApplicationMode PUBLIC_TRANSPORT = createBase(R.string.app_mode_public_transport, "public_transport").
|
||||
icon(R.drawable.ic_action_bus_dark, R.drawable.map_action_bus_dark,"ic_action_bus_dark").setRoutingProfile("public_transport").description(R.string.base_profile_descr_public_transport).reg();
|
||||
|
||||
public static final ApplicationMode BOAT = createBase( R.string.app_mode_boat, "boat").speed(1.38f, 20).nauticalLocation().
|
||||
icon(R.drawable.ic_action_sail_boat_dark, R.drawable.map_action_sail_boat_dark, "ic_action_sail_boat_dark").setRoutingProfile("boat").reg();
|
||||
public static final ApplicationMode BOAT = createBase(R.string.app_mode_boat, "boat").speed(1.38f, 20).nauticalLocation().
|
||||
icon(R.drawable.ic_action_sail_boat_dark, R.drawable.map_action_sail_boat_dark, "ic_action_sail_boat_dark").setRoutingProfile("boat").description(R.string.base_profile_descr_boat).reg();
|
||||
|
||||
public static final ApplicationMode AIRCRAFT = createBase( R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation().
|
||||
icon(R.drawable.ic_action_aircraft, R.drawable.map_action_aircraft,"ic_action_aircraft").setRouteService(RouteService.STRAIGHT).setRoutingProfile("STRAIGHT_LINE_MODE").reg();
|
||||
public static final ApplicationMode AIRCRAFT = createBase(R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation().
|
||||
icon(R.drawable.ic_action_aircraft, R.drawable.map_action_aircraft,"ic_action_aircraft").setRouteService(RouteService.STRAIGHT).setRoutingProfile("STRAIGHT_LINE_MODE").description(R.string.base_profile_descr_aircraft).reg();
|
||||
|
||||
public static final ApplicationMode SKI = createBase( R.string.app_mode_skiing, "ski").speed(1.38f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation().
|
||||
icon(R.drawable.ic_action_skiing, R.drawable.ic_action_skiing,"ic_action_skiing").setRoutingProfile("ski").reg();
|
||||
public static final ApplicationMode SKI = createBase(R.string.app_mode_skiing, "ski").speed(1.38f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation().
|
||||
icon(R.drawable.ic_action_skiing, R.drawable.ic_action_skiing,"ic_action_skiing").setRoutingProfile("ski").description(R.string.base_profile_descr_ski).reg();
|
||||
|
||||
|
||||
private static class ApplicationModeBean {
|
||||
|
@ -223,6 +219,11 @@ public class ApplicationMode {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ApplicationModeBuilder description(int strId) {
|
||||
applicationMode.descriptionId = strId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApplicationModeBuilder icon(Context app, String iconResName) {
|
||||
try {
|
||||
applicationMode.iconResName = iconResName;
|
||||
|
@ -527,6 +528,13 @@ public class ApplicationMode {
|
|||
}
|
||||
}
|
||||
|
||||
public String getDescription(Context ctx) {
|
||||
if (descriptionId != 0) {
|
||||
return ctx.getString(descriptionId);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public RouteService getRouteService() {
|
||||
return routeService;
|
||||
}
|
||||
|
|
|
@ -963,7 +963,7 @@ public class GpxUiHelper {
|
|||
for (String fname : filename) {
|
||||
final File f = new File(dir, fname);
|
||||
GPXFile res = GPXUtilities.loadGPXFile(f);
|
||||
if (res.error != null && res.error.getMessage().length() > 0) {
|
||||
if (res.error != null && !Algorithms.isEmpty(res.error.getMessage())) {
|
||||
w += res.error.getMessage() + "\n";
|
||||
}
|
||||
result[k++] = res;
|
||||
|
|
|
@ -150,31 +150,10 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
List<ProfileDataObject> profiles = new ArrayList<>();
|
||||
for (ApplicationMode mode : ApplicationMode.getDefaultValues()) {
|
||||
if (mode != ApplicationMode.DEFAULT) {
|
||||
profiles.add(new ProfileDataObject( mode.toHumanString(ctx),
|
||||
ctx.getString(BaseProfilesDescr.valueOf(mode.getStringKey().toUpperCase()).getDescrRes()),
|
||||
profiles.add(new ProfileDataObject(mode.toHumanString(ctx), mode.getDescription(ctx),
|
||||
mode.getStringKey(), mode.getIconRes(), false, mode.getIconColorInfo()));
|
||||
}
|
||||
}
|
||||
return profiles;
|
||||
}
|
||||
|
||||
public enum BaseProfilesDescr {
|
||||
CAR(R.string.base_profile_descr_car),
|
||||
BICYCLE(R.string.base_profile_descr_bicycle),
|
||||
PEDESTRIAN(R.string.base_profile_descr_pedestrian),
|
||||
PUBLIC_TRANSPORT(R.string.base_profile_descr_public_transport),
|
||||
BOAT(R.string.base_profile_descr_boat),
|
||||
AIRCRAFT(R.string.base_profile_descr_aircraft),
|
||||
SKI(R.string.base_profile_descr_ski);
|
||||
|
||||
private int descrRes;
|
||||
|
||||
BaseProfilesDescr(int descrRes) {
|
||||
this.descrRes = descrRes;
|
||||
}
|
||||
|
||||
public int getDescrRes() {
|
||||
return descrRes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue