Merge branch 'r3.3' into quickaction_fix_3.3

This commit is contained in:
Denis Kolomiets 2019-03-15 18:04:10 +02:00 committed by GitHub
commit 718c5d263f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 126 additions and 68 deletions

View file

@ -43,7 +43,10 @@ public class TransportRoute extends MapObject {
} }
public List<Way> getForwardWays() { public List<Way> getForwardWays() {
return forwardWays == null ? Collections.emptyList() : forwardWays; if(forwardWays == null) {
return Collections.emptyList();
}
return forwardWays;
} }

View file

@ -1,16 +1,9 @@
package net.osmand.router; package net.osmand.router;
import net.osmand.Location; import gnu.trove.iterator.TIntIterator;
import net.osmand.binary.BinaryMapIndexReader; import gnu.trove.list.array.TIntArrayList;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import gnu.trove.map.hash.TIntObjectHashMap;
import net.osmand.data.LatLon; import gnu.trove.map.hash.TLongObjectHashMap;
import net.osmand.data.QuadRect;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportSchedule;
import net.osmand.data.TransportStop;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.util.MapUtils;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,10 +14,16 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.PriorityQueue; import java.util.PriorityQueue;
import gnu.trove.iterator.TIntIterator; import net.osmand.binary.BinaryMapIndexReader;
import gnu.trove.list.array.TIntArrayList; import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import gnu.trove.map.hash.TIntObjectHashMap; import net.osmand.data.LatLon;
import gnu.trove.map.hash.TLongObjectHashMap; import net.osmand.data.QuadRect;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportSchedule;
import net.osmand.data.TransportStop;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.util.MapUtils;
public class TransportRoutePlanner { public class TransportRoutePlanner {
@ -39,6 +38,9 @@ public class TransportRoutePlanner {
for(TransportRouteSegment s : endStops) { for(TransportRouteSegment s : endStops) {
endSegments.put(s.getId(), s); endSegments.put(s.getId(), s);
} }
if(startStops.size() == 0) {
return Collections.emptyList();
}
PriorityQueue<TransportRouteSegment> queue = new PriorityQueue<TransportRouteSegment>(startStops.size(), new SegmentsComparator(ctx)); PriorityQueue<TransportRouteSegment> queue = new PriorityQueue<TransportRouteSegment>(startStops.size(), new SegmentsComparator(ctx));
for(TransportRouteSegment r : startStops){ for(TransportRouteSegment r : startStops){
r.walkDist = (float) MapUtils.getDistance(r.getLocation(), start); r.walkDist = (float) MapUtils.getDistance(r.getLocation(), start);
@ -96,11 +98,12 @@ public class TransportRoutePlanner {
} else { } else {
travelTime += ctx.cfg.stopTime + segmentDist / ctx.cfg.travelSpeed; travelTime += ctx.cfg.stopTime + segmentDist / ctx.cfg.travelSpeed;
} }
if(travelDist > finishTime + ctx.cfg.finishTimeSeconds) { if(segment.distFromStart + travelTime > finishTime + ctx.cfg.finishTimeSeconds) {
break; break;
} }
sgms.clear(); sgms.clear();
sgms = ctx.getTransportStops(stop.x31, stop.y31, true, sgms); sgms = ctx.getTransportStops(stop.x31, stop.y31, true, sgms);
ctx.visitedStops++;
for (TransportRouteSegment sgm : sgms) { for (TransportRouteSegment sgm : sgms) {
if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) { if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) {
return null; return null;
@ -108,31 +111,31 @@ public class TransportRoutePlanner {
if (segment.wasVisited(sgm)) { if (segment.wasVisited(sgm)) {
continue; continue;
} }
TransportRouteSegment rrs = new TransportRouteSegment(sgm); TransportRouteSegment nextSegment = new TransportRouteSegment(sgm);
rrs.parentRoute = segment; nextSegment.parentRoute = segment;
rrs.parentStop = ind; nextSegment.parentStop = ind;
rrs.walkDist = MapUtils.getDistance(rrs.getLocation(), stop.getLocation()); nextSegment.walkDist = MapUtils.getDistance(nextSegment.getLocation(), stop.getLocation());
rrs.parentTravelTime = travelTime; nextSegment.parentTravelTime = travelTime;
rrs.parentTravelDist = travelDist; nextSegment.parentTravelDist = travelDist;
double walkTime = rrs.walkDist / ctx.cfg.walkSpeed double walkTime = nextSegment.walkDist / ctx.cfg.walkSpeed
+ (ctx.cfg.getChangeTime()); + (ctx.cfg.getChangeTime());
rrs.distFromStart = segment.distFromStart + travelTime + walkTime; nextSegment.distFromStart = segment.distFromStart + travelTime + walkTime;
if(ctx.cfg.useSchedule) { if(ctx.cfg.useSchedule) {
int tm = (sgm.departureTime - ctx.cfg.scheduleTimeOfDay) * 10; int tm = (sgm.departureTime - ctx.cfg.scheduleTimeOfDay) * 10;
if(tm >= rrs.distFromStart) { if(tm >= nextSegment.distFromStart) {
rrs.distFromStart = tm; nextSegment.distFromStart = tm;
queue.add(rrs); queue.add(nextSegment);
} }
} else { } else {
queue.add(rrs); queue.add(nextSegment);
} }
} }
TransportRouteSegment f = endSegments.get(segmentId); TransportRouteSegment finalSegment = endSegments.get(segmentId);
double distToEnd = MapUtils.getDistance(stop.getLocation(), end); double distToEnd = MapUtils.getDistance(stop.getLocation(), end);
if (f != null && distToEnd < ctx.cfg.walkRadius) { if (finalSegment != null && distToEnd < ctx.cfg.walkRadius) {
if (finish == null || minDist > distToEnd) { if (finish == null || minDist > distToEnd) {
minDist = distToEnd; minDist = distToEnd;
finish = new TransportRouteSegment(f); finish = new TransportRouteSegment(finalSegment);
finish.parentRoute = segment; finish.parentRoute = segment;
finish.parentStop = ind; finish.parentStop = ind;
finish.walkDist = distToEnd; finish.walkDist = distToEnd;
@ -198,9 +201,11 @@ public class TransportRoutePlanner {
private List<TransportRouteResult> prepareResults(TransportRoutingContext ctx, List<TransportRouteSegment> results) { private List<TransportRouteResult> prepareResults(TransportRoutingContext ctx, List<TransportRouteSegment> results) {
Collections.sort(results, new SegmentsComparator(ctx)); Collections.sort(results, new SegmentsComparator(ctx));
List<TransportRouteResult> lst = new ArrayList<TransportRouteResult>(); List<TransportRouteResult> lst = new ArrayList<TransportRouteResult>();
System.out.println(String.format("Calculated %.1f seconds, found %d results, visited %d routes, loaded %d tiles (%d ms read, %d ms total),", System.out.println(String.format("Calculated %.1f seconds, found %d results, visited %d routes / %d stops, loaded %d tiles (%d ms read, %d ms total), loaded ways %d (%d wrong)",
(System.currentTimeMillis() - ctx.startCalcTime) / 1000.0, results.size(), ctx.visitedRoutesCount, (System.currentTimeMillis() - ctx.startCalcTime) / 1000.0, results.size(),
ctx.quadTree.size(), ctx.readTime / (1000 * 1000), ctx.loadTime / (1000 * 1000))); ctx.visitedRoutesCount, ctx.visitedStops,
ctx.quadTree.size(), ctx.readTime / (1000 * 1000), ctx.loadTime / (1000 * 1000),
ctx.loadedWays, ctx.wrongLoadedWays));
for(TransportRouteSegment res : results) { for(TransportRouteSegment res : results) {
if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) { if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) {
return null; return null;
@ -214,9 +219,15 @@ public class TransportRoutePlanner {
return null; return null;
} }
if (p.parentRoute != null) { if (p.parentRoute != null) {
TransportRouteResultSegment sg = new TransportRouteResultSegment(p.parentRoute.road, TransportRouteResultSegment sg = new TransportRouteResultSegment();
p.parentRoute.segStart, p.parentStop, p.parentRoute.walkDist, sg.route = p.parentRoute.road;
p.departureTime); sg.start = p.parentRoute.segStart;
sg.end = p.parentStop;
sg.walkDist = p.parentRoute.walkDist;
sg.walkTime = sg.walkDist / ctx.cfg.walkSpeed;
sg.depTime = p.departureTime;
sg.travelInaccurateDist = p.parentTravelDist;
sg.travelTime = p.parentTravelTime;
route.segments.add(0, sg); route.segments.add(0, sg);
} }
p = p.parentRoute; p = p.parentRoute;
@ -278,20 +289,19 @@ public class TransportRoutePlanner {
public static class TransportRouteResultSegment { public static class TransportRouteResultSegment {
private static final boolean DISPLAY_FULL_SEGMENT_ROUTE = false; private static final boolean DISPLAY_FULL_SEGMENT_ROUTE = false;
private static final int DISPLAY_SEGMENT_IND = 0; private static final int DISPLAY_SEGMENT_IND = 0;
public final TransportRoute route; public TransportRoute route;
public final int start; public double walkTime;
public final int end; public double travelInaccurateDist;
public final double walkDist ; public double travelTime;
public final int depTime; public int start;
public int end;
public double walkDist ;
public int depTime;
public TransportRouteResultSegment(TransportRoute route, int start, int end, double walkDist, int depTime) { public TransportRouteResultSegment() {
this.route = route;
this.start = start;
this.end = end;
this.walkDist = walkDist;
this.depTime = depTime;
} }
public int getArrivalTime() { public int getArrivalTime() {
@ -534,9 +544,9 @@ public class TransportRoutePlanner {
private static final int SHIFT_DEPTIME = 14; // assume less than 1024 stops private static final int SHIFT_DEPTIME = 14; // assume less than 1024 stops
TransportRouteSegment parentRoute = null; TransportRouteSegment parentRoute = null;
int parentStop; int parentStop; // last stop to exit for parent route
double parentTravelTime; // travel time double parentTravelTime; // travel time for parent route
double parentTravelDist; // inaccurate double parentTravelDist; // travel distance for parent route (inaccurate)
// walk distance to start route location (or finish in case last segment) // walk distance to start route location (or finish in case last segment)
double walkDist = 0; double walkDist = 0;
@ -643,6 +653,7 @@ public class TransportRoutePlanner {
// stats // stats
public long startCalcTime; public long startCalcTime;
public int visitedRoutesCount; public int visitedRoutesCount;
public int visitedStops;
public int wrongLoadedWays; public int wrongLoadedWays;
public int loadedWays; public int loadedWays;
public long loadTime; public long loadTime;

View file

@ -4,7 +4,7 @@ public class TransportRoutingConfiguration {
public static final String KEY = "public_transport"; public static final String KEY = "public_transport";
public int ZOOM_TO_LOAD_TILES = 14; public int ZOOM_TO_LOAD_TILES = 15;
public int walkRadius = 1500; // ? 3000 public int walkRadius = 1500; // ? 3000

View file

@ -858,8 +858,8 @@ public class SearchUICore {
return cmp; return cmp;
} }
} }
int st1 = Algorithms.extractFirstIntegerNumber(o1.localeName); int st1 = o1.localeName == null ? -10000 : Algorithms.extractFirstIntegerNumber(o1.localeName);
int st2 = Algorithms.extractFirstIntegerNumber(o2.localeName); int st2 = o2.localeName == null ? -10000 : Algorithms.extractFirstIntegerNumber(o2.localeName);
if (st1 != st2) { if (st1 != st2) {
return Algorithms.compare(st1, st2); return Algorithms.compare(st1, st2);
} }

View file

@ -112,6 +112,7 @@ public class MapUtils {
} }
/** /**
* Gets distance in meters * Gets distance in meters
*/ */

View file

@ -66,6 +66,16 @@ android {
warningsAsErrors false warningsAsErrors false
} }
bundle {
language {
// Specifies that the app bundle should not support
// configuration APKs for language resources. These
// resources are instead packaged with each base and
// dynamic feature APK.
enableSplit = false
}
}
// related to kuromoji // related to kuromoji
//packagingOptions { //packagingOptions {
// exclude '/META-INF/CONTRIBUTORS.md' // exclude '/META-INF/CONTRIBUTORS.md'

View file

@ -10,7 +10,9 @@
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience - For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
Thx - Hardy Thx - Hardy
--> <string name="quick_action_day_night_mode">%s mode</string> <string name="quick_action_day_night_mode">%s mode</string>
<string name="save_poi_value_exceed_length">Value of tag \"%s\" cannot exceed 255 chars. \nPlease edit it before continue.</string>
<string name="save_poi_value_exceed_length_title">Length of \"%s\" value</string>
<string name="public_transport_warning_descr_blog">Learn more about how OsmAnd calculates routes in our blog.</string> <string name="public_transport_warning_descr_blog">Learn more about how OsmAnd calculates routes in our blog.</string>
<string name="public_transport_warning_title">Public transport routes are now in the beta testing phase, so errors and inaccuracies may occur.</string> <string name="public_transport_warning_title">Public transport routes are now in the beta testing phase, so errors and inaccuracies may occur.</string>
<string name="add_intermediate">Add intermediate point</string> <string name="add_intermediate">Add intermediate point</string>

View file

@ -3,6 +3,7 @@ package net.osmand.plus.osmedit;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
@ -108,7 +109,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
private View view; private View view;
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Context activity) {
super.onAttach(activity); super.onAttach(activity);
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (getSettings().OFFLINE_EDITION.get() if (getSettings().OFFLINE_EDITION.get()
@ -400,7 +401,14 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
} }
private void trySave() { private void trySave() {
if (TextUtils.isEmpty(poiTypeEditText.getText())) { String tagWithExceedingValue = isTextLengthInRange();
if (!Algorithms.isEmpty(tagWithExceedingValue)){
ValueExceedLimitDialogFragment f = new ValueExceedLimitDialogFragment();
Bundle args = new Bundle();
args.putString("tag", tagWithExceedingValue);
f.setArguments(args);
f.show(getChildFragmentManager(), "exceedDialog");
} else if (TextUtils.isEmpty(poiTypeEditText.getText())) {
HashSet<String> tagsCopy = new HashSet<>(); HashSet<String> tagsCopy = new HashSet<>();
tagsCopy.addAll(editPoiData.getTagValues().keySet()); tagsCopy.addAll(editPoiData.getTagValues().keySet());
if (Algorithms.isEmpty(editPoiData.getTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue()))) { if (Algorithms.isEmpty(editPoiData.getTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue()))) {
@ -422,12 +430,22 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
} else if (editPoiData.getPoiCategory() == getMyApplication().getPoiTypes().getOtherPoiCategory()) { } else if (editPoiData.getPoiCategory() == getMyApplication().getPoiTypes().getOtherPoiCategory()) {
poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type)); poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type));
} else if (editPoiData.getPoiTypeDefined() == null) { } else if (editPoiData.getPoiTypeDefined() == null) {
poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type_only_from_list)); poiTypeEditText.setError(
getResources().getString(R.string.please_specify_poi_type_only_from_list));
} else { } else {
save(); save();
} }
} }
private String isTextLengthInRange() {
for (String s: editPoiData.getChangedTags()) {
if (editPoiData.getTag(s).length() > 255) {
return s;
}
}
return "";
}
private boolean testTooManyCapitalLetters(String name) { private boolean testTooManyCapitalLetters(String name) {
if(name == null) { if(name == null) {
return false; return false;
@ -889,6 +907,23 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
} }
} }
public static class ValueExceedLimitDialogFragment extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
String msg = getString(R.string.save_poi_value_exceed_length);
String fieldTag = getArguments().getString("tag", "");
if(!Algorithms.isEmpty(fieldTag)) {
msg = String.format(msg, fieldTag);
}
builder.setTitle(String.format(getResources().getString(R.string.save_poi_value_exceed_length_title), fieldTag))
.setMessage(msg)
.setNegativeButton(R.string.shared_string_ok, null);
return builder.create();
}
}
private TextView.OnEditorActionListener mOnEditorActionListener = private TextView.OnEditorActionListener mOnEditorActionListener =
new TextView.OnEditorActionListener() { new TextView.OnEditorActionListener() {
@Override @Override

View file

@ -714,19 +714,15 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
OnClickListener listener = new OnClickListener() { OnClickListener listener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
//MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
//if (mapActivity != null) { if (mapActivity != null) {
if (selected.size() > 0) { if (selected.size() > 0) {
// OsmandApplication app = mapActivity.getMyApplication();
ApplicationMode next = selected.iterator().next(); ApplicationMode next = selected.iterator().next();
// if (app.getRoutingHelper().isRouteCalculated()) {
// app.getSettings().LAST_ROUTE_APPLICATION_MODE.set(next);
// }
updateApplicationMode(am, next); updateApplicationMode(am, next);
} }
updateFinishPointView(); updateFinishPointView();
updateOptionsButtons(); updateOptionsButtons();
//} }
} }
}; };
final List<ApplicationMode> values = new ArrayList<ApplicationMode>(ApplicationMode.values(mapActivity.getMyApplication())); final List<ApplicationMode> values = new ArrayList<ApplicationMode>(ApplicationMode.values(mapActivity.getMyApplication()));

View file

@ -23,7 +23,7 @@ import net.osmand.plus.wikipedia.WikipediaDialogFragment;
public class WarningCard extends BaseCard { public class WarningCard extends BaseCard {
public static final String OSMAND_BLOG_LINK = "https://osmand.net/blog"; public static final String OSMAND_BLOG_LINK = "https://osmand.net/blog/guideline-pt";
public WarningCard(MapActivity mapActivity) { public WarningCard(MapActivity mapActivity) {
super(mapActivity); super(mapActivity);

View file

@ -943,7 +943,6 @@ public class RoutingHelper {
public void recalculateRouteDueToSettingsChange() { public void recalculateRouteDueToSettingsChange() {
clearCurrentRoute(finalLocation, intermediatePoints); clearCurrentRoute(finalLocation, intermediatePoints);
getSettings().LAST_ROUTE_APPLICATION_MODE.set(getAppMode());
if (isPublicTransportMode()) { if (isPublicTransportMode()) {
Location start = lastFixedLocation; Location start = lastFixedLocation;
LatLon finish = finalLocation; LatLon finish = finalLocation;

View file

@ -158,6 +158,7 @@ public class TransportRoutingHelper {
private void startRouteCalculationThread(TransportRouteCalculationParams params) { private void startRouteCalculationThread(TransportRouteCalculationParams params) {
synchronized (this) { synchronized (this) {
final Thread prevRunningJob = currentRunningJob; final Thread prevRunningJob = currentRunningJob;
app.getSettings().LAST_ROUTE_APPLICATION_MODE.set(routingHelper.getAppMode());
RouteRecalculationThread newThread = RouteRecalculationThread newThread =
new RouteRecalculationThread("Calculating public transport route", params); new RouteRecalculationThread("Calculating public transport route", params);
currentRunningJob = newThread; currentRunningJob = newThread;