Merge branch 'master' of github.com:osmandapp/Osmand
This commit is contained in:
commit
ce7f102dce
7 changed files with 187 additions and 108 deletions
|
@ -495,7 +495,11 @@ public class TransportRoutePlanner {
|
||||||
public double getWalkTime() {
|
public double getWalkTime() {
|
||||||
return getWalkDist() / cfg.walkSpeed;
|
return getWalkDist() / cfg.walkSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getChangeTime() {
|
||||||
|
return cfg.getChangeTime();
|
||||||
|
}
|
||||||
|
|
||||||
public int getChanges() {
|
public int getChanges() {
|
||||||
return segments.size() - 1;
|
return segments.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
- 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="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 navigation is currently in beta testing, errors and inaccuracies may occur.</string>
|
<string name="public_transport_warning_title">Public transport navigation is currently in beta testing, errors and inaccuracies may occur.</string>
|
||||||
<string name="add_intermediate">Add intermediate point</string>
|
<string name="add_intermediate">Add intermediate point</string>
|
||||||
|
|
|
@ -60,6 +60,12 @@ public class OsmAndFormatter {
|
||||||
return hours + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (sec < 10 ? "0" + sec : sec);
|
return hours + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (sec < 10 ? "0" + sec : sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getFormattedDurationShortMinutes(int seconds) {
|
||||||
|
int hours = seconds / (60 * 60);
|
||||||
|
int minutes = (seconds / 60) % 60;
|
||||||
|
return hours + ":" + (minutes < 10 ? "0" + minutes : minutes);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getFormattedTime(long seconds, boolean useCurrentTime) {
|
public static String getFormattedTime(long seconds, boolean useCurrentTime) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
if (useCurrentTime) {
|
if (useCurrentTime) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -607,7 +607,8 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
!nightMode ? R.color.ctx_menu_collapse_icon_color_light : R.color.ctx_menu_collapse_icon_color_dark);
|
!nightMode ? R.color.ctx_menu_collapse_icon_color_light : R.color.ctx_menu_collapse_icon_color_dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildSegmentItem(View view, final TransportRouteResultSegment segment, long startTime) {
|
private void buildSegmentItem(View view, final TransportRouteResultSegment segment,
|
||||||
|
final TransportRouteResultSegment nextSegment, int[] startTime, double walkSpeed, double changeTime) {
|
||||||
TransportRoute transportRoute = segment.route;
|
TransportRoute transportRoute = segment.route;
|
||||||
List<TransportStop> stops = segment.getTravelStops();
|
List<TransportStop> stops = segment.getTravelStops();
|
||||||
final TransportStop startStop = stops.get(0);
|
final TransportStop startStop = stops.get(0);
|
||||||
|
@ -632,7 +633,7 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
Drawable icon = getContentIcon(drawableResId);
|
Drawable icon = getContentIcon(drawableResId);
|
||||||
|
|
||||||
Typeface typeface = FontCache.getRobotoMedium(app);
|
Typeface typeface = FontCache.getRobotoMedium(app);
|
||||||
String timeText = OsmAndFormatter.getFormattedTime(startTime, false);
|
String timeText = OsmAndFormatter.getFormattedDurationShortMinutes(startTime[0]);
|
||||||
|
|
||||||
SpannableString secondaryText = new SpannableString(getString(R.string.sit_on_the_stop));
|
SpannableString secondaryText = new SpannableString(getString(R.string.sit_on_the_stop));
|
||||||
secondaryText.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), 0, secondaryText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
secondaryText.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), 0, secondaryText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
@ -695,11 +696,13 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
buildCollapsableRow(stopsContainer, spannable, textType, true, collapsableView, null);
|
buildCollapsableRow(stopsContainer, spannable, textType, true, collapsableView, null);
|
||||||
|
|
||||||
final TransportStop endStop = stops.get(stops.size() - 1);
|
final TransportStop endStop = stops.get(stops.size() - 1);
|
||||||
long depTime = segment.depTime + arrivalTime;
|
int depTime = segment.depTime + arrivalTime;
|
||||||
if (depTime <= 0) {
|
if (depTime <= 0) {
|
||||||
depTime = startTime + arrivalTime;
|
depTime = startTime[0] + arrivalTime;
|
||||||
}
|
}
|
||||||
String textTime = OsmAndFormatter.getFormattedTime(depTime, false);
|
// TODO: fix later for schedule
|
||||||
|
startTime[0] += (int) segment.travelTime + (nextSegment != null ? changeTime / 2 : 0);
|
||||||
|
String textTime = OsmAndFormatter.getFormattedDurationShortMinutes(startTime[0]);
|
||||||
|
|
||||||
secondaryText = new SpannableString(getString(R.string.exit_at));
|
secondaryText = new SpannableString(getString(R.string.exit_at));
|
||||||
secondaryText.setSpan(new CustomTypefaceSpan(typeface), 0, secondaryText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
secondaryText.setSpan(new CustomTypefaceSpan(typeface), 0, secondaryText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
@ -719,6 +722,33 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
});
|
});
|
||||||
|
|
||||||
((ViewGroup) view).addView(baseContainer);
|
((ViewGroup) view).addView(baseContainer);
|
||||||
|
|
||||||
|
if (nextSegment != null) {
|
||||||
|
double walkDist = (long) getWalkDistance(segment, nextSegment, segment.walkDist);
|
||||||
|
if (walkDist > 0) {
|
||||||
|
int walkTime = (int) getWalkTime(segment, nextSegment, walkDist, walkSpeed);
|
||||||
|
if (walkTime < 60) {
|
||||||
|
walkTime = 60;
|
||||||
|
}
|
||||||
|
spannable = new SpannableStringBuilder("~");
|
||||||
|
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
startIndex = spannable.length();
|
||||||
|
spannable.append(OsmAndFormatter.getFormattedDuration(walkTime, app)).append(" ");
|
||||||
|
spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
startIndex = spannable.length();
|
||||||
|
spannable.append(getString(R.string.on_foot)).append(", ").append(OsmAndFormatter.getFormattedDistance((float) walkDist, app));
|
||||||
|
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
|
||||||
|
buildRowDivider(view, true);
|
||||||
|
buildWalkRow(view, spannable, null, new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
showWalkingRouteOnMap(segment, nextSegment);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
startTime[0] += walkTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private View createImagesContainer() {
|
private View createImagesContainer() {
|
||||||
|
@ -739,93 +769,29 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildTransportRouteRow(ViewGroup parent, TransportRouteResult routeResult, boolean showDivider) {
|
private void buildTransportRouteRow(ViewGroup parent, TransportRouteResult routeResult, boolean showDivider) {
|
||||||
Typeface typeface = FontCache.getRobotoMedium(app);
|
|
||||||
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
|
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
|
||||||
TargetPoint startPoint = targetPointsHelper.getPointToStart();
|
TargetPoint startPoint = targetPointsHelper.getPointToStart();
|
||||||
TargetPoint endPoint = targetPointsHelper.getPointToNavigate();
|
TargetPoint endPoint = targetPointsHelper.getPointToNavigate();
|
||||||
long startTime = System.currentTimeMillis() / 1000;
|
int[] startTime = { 0 };
|
||||||
|
|
||||||
List<TransportRouteResultSegment> segments = routeResult.getSegments();
|
List<TransportRouteResultSegment> segments = routeResult.getSegments();
|
||||||
boolean previousWalkItemUsed = false;
|
|
||||||
|
|
||||||
for (int i = 0; i < segments.size(); i++) {
|
for (int i = 0; i < segments.size(); i++) {
|
||||||
|
boolean first = i == 0;
|
||||||
|
boolean last = i == segments.size() - 1;
|
||||||
final TransportRouteResultSegment segment = segments.get(i);
|
final TransportRouteResultSegment segment = segments.get(i);
|
||||||
final TransportRouteResultSegment nextSegment = segments.size() > i + 1 ? segments.get(i + 1) : null;
|
if (first) {
|
||||||
long walkTime = (long) getWalkTime(segment.walkDist, routeResult.getWalkSpeed());
|
|
||||||
if (walkTime < 60) {
|
|
||||||
walkTime = 60;
|
|
||||||
}
|
|
||||||
if (i == 0) {
|
|
||||||
buildStartItem(parent, startPoint, startTime, segment, routeResult.getWalkSpeed());
|
buildStartItem(parent, startPoint, startTime, segment, routeResult.getWalkSpeed());
|
||||||
startTime += walkTime;
|
|
||||||
} else if (segment.walkDist > 0 && !previousWalkItemUsed) {
|
|
||||||
SpannableStringBuilder spannable = new SpannableStringBuilder("~");
|
|
||||||
int startIndex = spannable.length();
|
|
||||||
spannable.append(OsmAndFormatter.getFormattedDuration((int) walkTime, app)).append(" ");
|
|
||||||
spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
spannable.append(getString(R.string.on_foot)).append(" ").append(", ").append(OsmAndFormatter.getFormattedDistance((float) segment.walkDist, app));
|
|
||||||
|
|
||||||
buildWalkRow(parent, spannable, null, new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
showWalkingRouteOnMap(segment, nextSegment);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
buildRowDivider(parent, true);
|
|
||||||
startTime += walkTime;
|
|
||||||
}
|
}
|
||||||
|
buildSegmentItem(parent, segment, !last ? segments.get(i + 1) : null, startTime, routeResult.getWalkSpeed(), routeResult.getChangeTime());
|
||||||
buildSegmentItem(parent, segment, startTime);
|
if (last) {
|
||||||
|
|
||||||
double finishWalkDist = routeResult.getFinishWalkDist();
|
|
||||||
if (i == segments.size() - 1) {
|
|
||||||
buildDestinationItem(parent, endPoint, startTime, segment, routeResult.getWalkSpeed());
|
buildDestinationItem(parent, endPoint, startTime, segment, routeResult.getWalkSpeed());
|
||||||
} else if (finishWalkDist > 0) {
|
|
||||||
walkTime = (long) getWalkTime(finishWalkDist, routeResult.getWalkSpeed());
|
|
||||||
startTime += walkTime;
|
|
||||||
if (nextSegment != null) {
|
|
||||||
if (nextSegment.walkDist > 0) {
|
|
||||||
finishWalkDist += nextSegment.walkDist;
|
|
||||||
walkTime += getWalkTime(nextSegment.walkDist, routeResult.getWalkSpeed());
|
|
||||||
previousWalkItemUsed = true;
|
|
||||||
} else {
|
|
||||||
previousWalkItemUsed = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buildRowDivider(parent, true);
|
|
||||||
|
|
||||||
Spannable title = getWalkTitle(finishWalkDist, walkTime);
|
|
||||||
buildWalkRow(parent, title, null, new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
showWalkingRouteOnMap(segment, nextSegment);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (showDivider && i != segments.size() - 1) {
|
if (showDivider && !last) {
|
||||||
buildRowDivider(parent, true);
|
buildRowDivider(parent, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Spannable getWalkTitle(double finishWalkDist, double walkTime) {
|
private void buildStartItem(View view, final TargetPoint start, int[] startTime,
|
||||||
if (walkTime < 60) {
|
|
||||||
walkTime = 60;
|
|
||||||
}
|
|
||||||
Typeface typeface = FontCache.getRobotoMedium(app);
|
|
||||||
SpannableStringBuilder title = new SpannableStringBuilder("~");
|
|
||||||
int startIndex = title.length();
|
|
||||||
title.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
title.append(OsmAndFormatter.getFormattedDuration((int) walkTime, app)).append(" ");
|
|
||||||
title.setSpan(new CustomTypefaceSpan(typeface), startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
startIndex = title.length();
|
|
||||||
title.append(getString(R.string.on_foot)).append(", ").append(OsmAndFormatter.getFormattedDistance((float) finishWalkDist, app));
|
|
||||||
title.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buildStartItem(View view, final TargetPoint start, long startTime,
|
|
||||||
final TransportRouteResultSegment segment, double walkSpeed) {
|
final TransportRouteResultSegment segment, double walkSpeed) {
|
||||||
FrameLayout baseItemView = new FrameLayout(view.getContext());
|
FrameLayout baseItemView = new FrameLayout(view.getContext());
|
||||||
|
|
||||||
|
@ -843,7 +809,7 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
name = getString(R.string.shared_string_my_location);
|
name = getString(R.string.shared_string_my_location);
|
||||||
}
|
}
|
||||||
Spannable startTitle = new SpannableString(name);
|
Spannable startTitle = new SpannableString(name);
|
||||||
String text = OsmAndFormatter.getFormattedTime(startTime, false);
|
String text = OsmAndFormatter.getFormattedDurationShortMinutes(startTime[0]);
|
||||||
|
|
||||||
int drawableId = start == null ? R.drawable.ic_action_location_color : R.drawable.list_startpoint;
|
int drawableId = start == null ? R.drawable.ic_action_location_color : R.drawable.list_startpoint;
|
||||||
Drawable icon = app.getUIUtilities().getIcon(drawableId);
|
Drawable icon = app.getUIUtilities().getIcon(drawableId);
|
||||||
|
@ -857,17 +823,19 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
addWalkRouteIcon(imagesContainer);
|
addWalkRouteIcon(imagesContainer);
|
||||||
buildRowDivider(infoContainer, true);
|
buildRowDivider(infoContainer, true);
|
||||||
|
|
||||||
long walkTime = (long) getWalkTime(segment.walkDist, walkSpeed);
|
double walkDist = (long) getWalkDistance(null, segment, segment.walkDist);
|
||||||
|
int walkTime = (int) getWalkTime(null, segment, walkDist, walkSpeed);
|
||||||
if (walkTime < 60) {
|
if (walkTime < 60) {
|
||||||
walkTime = 60;
|
walkTime = 60;
|
||||||
}
|
}
|
||||||
|
startTime[0] += walkTime;
|
||||||
SpannableStringBuilder title = new SpannableStringBuilder(Algorithms.capitalizeFirstLetter(getString(R.string.on_foot)));
|
SpannableStringBuilder title = new SpannableStringBuilder(Algorithms.capitalizeFirstLetter(getString(R.string.on_foot)));
|
||||||
title.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
title.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
int startIndex = title.length();
|
int startIndex = title.length();
|
||||||
title.append(" ").append(OsmAndFormatter.getFormattedDuration((int) walkTime, app));
|
title.append(" ").append(OsmAndFormatter.getFormattedDuration(walkTime, app));
|
||||||
title.setSpan(new CustomTypefaceSpan(FontCache.getRobotoMedium(app)), startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
title.setSpan(new CustomTypefaceSpan(FontCache.getRobotoMedium(app)), startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
startIndex = title.length();
|
startIndex = title.length();
|
||||||
title.append(", ").append(OsmAndFormatter.getFormattedDistance((float) segment.walkDist, app));
|
title.append(", ").append(OsmAndFormatter.getFormattedDistance((float) walkDist, app));
|
||||||
title.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
title.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
|
||||||
buildWalkRow(infoContainer, title, imagesContainer, new OnClickListener() {
|
buildWalkRow(infoContainer, title, imagesContainer, new OnClickListener() {
|
||||||
|
@ -882,9 +850,9 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showLocationOnMap(LatLon latLon) {
|
public void showLocationOnMap(LatLon latLon) {
|
||||||
OsmandSettings settings = app.getSettings();
|
Location lastLocation = app.getLocationProvider().getLastKnownLocation();
|
||||||
if (latLon == null) {
|
if (latLon == null && lastLocation != null) {
|
||||||
latLon = settings.isLastKnownMapLocation() ? settings.getLastKnownMapLocation() : null;
|
latLon = new LatLon(lastLocation.getLatitude(), lastLocation.getLongitude());
|
||||||
}
|
}
|
||||||
if (latLon != null) {
|
if (latLon != null) {
|
||||||
openMenuHeaderOnly();
|
openMenuHeaderOnly();
|
||||||
|
@ -934,7 +902,8 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
container.addView(walkLineImage);
|
container.addView(walkLineImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildDestinationItem(View view, final TargetPoint destination, long startTime, final TransportRouteResultSegment segment, double walkSpeed) {
|
private void buildDestinationItem(View view, final TargetPoint destination, int[] startTime,
|
||||||
|
final TransportRouteResultSegment segment, double walkSpeed) {
|
||||||
Typeface typeface = FontCache.getRobotoMedium(app);
|
Typeface typeface = FontCache.getRobotoMedium(app);
|
||||||
FrameLayout baseItemView = new FrameLayout(view.getContext());
|
FrameLayout baseItemView = new FrameLayout(view.getContext());
|
||||||
|
|
||||||
|
@ -946,17 +915,18 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
|
|
||||||
buildRowDivider(infoContainer, true);
|
buildRowDivider(infoContainer, true);
|
||||||
|
|
||||||
long walkTime = (long) getWalkTime(segment.walkDist, walkSpeed);
|
double walkDist = (long) getWalkDistance(segment, null, segment.walkDist);
|
||||||
|
int walkTime = (int) getWalkTime(segment, null, walkDist, walkSpeed);
|
||||||
if (walkTime < 60) {
|
if (walkTime < 60) {
|
||||||
walkTime = 60;
|
walkTime = 60;
|
||||||
}
|
}
|
||||||
SpannableStringBuilder spannable = new SpannableStringBuilder("~");
|
SpannableStringBuilder spannable = new SpannableStringBuilder("~");
|
||||||
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
int startIndex = spannable.length();
|
int startIndex = spannable.length();
|
||||||
spannable.append(OsmAndFormatter.getFormattedDuration((int) walkTime, app)).append(" ");
|
spannable.append(OsmAndFormatter.getFormattedDuration(walkTime, app)).append(" ");
|
||||||
spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
startIndex = spannable.length();
|
startIndex = spannable.length();
|
||||||
spannable.append(getString(R.string.on_foot)).append(", ").append(OsmAndFormatter.getFormattedDistance((float) segment.walkDist, app));
|
spannable.append(getString(R.string.on_foot)).append(", ").append(OsmAndFormatter.getFormattedDistance((float) walkDist, app));
|
||||||
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light)), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
|
||||||
buildWalkRow(infoContainer, spannable, imagesContainer, new OnClickListener() {
|
buildWalkRow(infoContainer, spannable, imagesContainer, new OnClickListener() {
|
||||||
|
@ -968,7 +938,7 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
buildRowDivider(infoContainer, true);
|
buildRowDivider(infoContainer, true);
|
||||||
addWalkRouteIcon(imagesContainer);
|
addWalkRouteIcon(imagesContainer);
|
||||||
|
|
||||||
String timeStr = OsmAndFormatter.getFormattedTime(startTime + walkTime, false);
|
String timeStr = OsmAndFormatter.getFormattedDurationShortMinutes(startTime[0] + walkTime);
|
||||||
String name = getRoutePointDescription(destination.point, destination.getOnlyName());
|
String name = getRoutePointDescription(destination.point, destination.getOnlyName());
|
||||||
SpannableString title = new SpannableString(name);
|
SpannableString title = new SpannableString(name);
|
||||||
title.setSpan(new CustomTypefaceSpan(typeface), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
title.setSpan(new CustomTypefaceSpan(typeface), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
@ -1650,8 +1620,22 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getWalkTime(double walkDist, double walkSpeed) {
|
private double getWalkTime(@Nullable TransportRouteResultSegment segment,
|
||||||
return walkDist / walkSpeed;
|
@Nullable TransportRouteResultSegment nextSegment, double walkDistPT, double walkSpeedPT) {
|
||||||
|
RouteCalculationResult walkingRouteSegment = app.getTransportRoutingHelper().getWalkingRouteSegment(segment, nextSegment);
|
||||||
|
if (walkingRouteSegment != null) {
|
||||||
|
return walkingRouteSegment.getRoutingTime();
|
||||||
|
}
|
||||||
|
return walkDistPT / walkSpeedPT;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getWalkDistance(@Nullable TransportRouteResultSegment segment,
|
||||||
|
@Nullable TransportRouteResultSegment nextSegment, double walkDistPT) {
|
||||||
|
RouteCalculationResult walkingRouteSegment = app.getTransportRoutingHelper().getWalkingRouteSegment(segment, nextSegment);
|
||||||
|
if (walkingRouteSegment != null) {
|
||||||
|
return walkingRouteSegment.getWholeDistance();
|
||||||
|
}
|
||||||
|
return walkDistPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buildRowDivider(View view, boolean needMargin) {
|
public void buildRowDivider(View view, boolean needMargin) {
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class PublicTransportCard extends BaseCard {
|
||||||
TextView wayLine = (TextView) view.findViewById(R.id.way_line);
|
TextView wayLine = (TextView) view.findViewById(R.id.way_line);
|
||||||
|
|
||||||
fromLine.setText(getFirstLineDescrSpan());
|
fromLine.setText(getFirstLineDescrSpan());
|
||||||
wayLine.setText(getSecondLineDescrSpan());
|
wayLine.setText(getSecondLineDescrSpan(segments));
|
||||||
|
|
||||||
FrameLayout detailsButton = (FrameLayout) view.findViewById(R.id.details_button);
|
FrameLayout detailsButton = (FrameLayout) view.findViewById(R.id.details_button);
|
||||||
TextView detailsButtonDescr = (TextView) view.findViewById(R.id.details_button_descr);
|
TextView detailsButtonDescr = (TextView) view.findViewById(R.id.details_button_descr);
|
||||||
|
@ -171,27 +171,32 @@ public class PublicTransportCard extends BaseCard {
|
||||||
return firstLineDesc;
|
return firstLineDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SpannableString getSecondLineDescrSpan() {
|
private SpannableString getSecondLineDescrSpan(List<TransportRouteResultSegment> segments) {
|
||||||
|
TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
|
||||||
Typeface typeface = FontCache.getRobotoMedium(app);
|
Typeface typeface = FontCache.getRobotoMedium(app);
|
||||||
String travelTime = OsmAndFormatter.getFormattedDuration((int) routeResult.getTravelTime(), app);
|
String travelTimeStr = OsmAndFormatter.getFormattedDuration((int) routeResult.getTravelTime(), app);
|
||||||
String walkTime = OsmAndFormatter.getFormattedDuration((int) routeResult.getWalkTime(), app);
|
int walkTimeReal = transportRoutingHelper.getWalkingTime(segments);
|
||||||
String walkDistance = OsmAndFormatter.getFormattedDistance((int) routeResult.getWalkDist(), app);
|
int walkTimePT = (int) routeResult.getWalkTime();
|
||||||
|
String walkTimeStr = OsmAndFormatter.getFormattedDuration(walkTimeReal > 0 ? walkTimeReal : walkTimePT, app);
|
||||||
|
int walkDistanceReal = transportRoutingHelper.getWalkingDistance(segments);
|
||||||
|
int walkDistancePT = (int) routeResult.getWalkDist();
|
||||||
|
String walkDistanceStr = OsmAndFormatter.getFormattedDistance(walkDistanceReal > 0 ? walkDistanceReal : walkDistancePT, app);
|
||||||
|
|
||||||
String secondLine = travelTime + " • " + app.getString(R.string.on_foot) + " " + walkTime + ", " + walkDistance;
|
String secondLine = travelTimeStr + " • " + app.getString(R.string.on_foot) + " " + walkTimeStr + ", " + walkDistanceStr;
|
||||||
|
|
||||||
SpannableString secondLineDesc = new SpannableString(secondLine);
|
SpannableString secondLineDesc = new SpannableString(secondLine);
|
||||||
|
|
||||||
int startTravelTime = secondLine.indexOf(travelTime);
|
int startTravelTime = secondLine.indexOf(travelTimeStr);
|
||||||
secondLineDesc.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)),
|
secondLineDesc.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)),
|
||||||
startTravelTime, startTravelTime + travelTime.length(), 0);
|
startTravelTime, startTravelTime + travelTimeStr.length(), 0);
|
||||||
secondLineDesc.setSpan(new CustomTypefaceSpan(typeface),
|
secondLineDesc.setSpan(new CustomTypefaceSpan(typeface),
|
||||||
startTravelTime, startTravelTime + travelTime.length(), 0);
|
startTravelTime, startTravelTime + travelTimeStr.length(), 0);
|
||||||
|
|
||||||
int startWalkTime = secondLine.lastIndexOf(walkTime);
|
int startWalkTime = secondLine.lastIndexOf(walkTimeStr);
|
||||||
secondLineDesc.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)),
|
secondLineDesc.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)),
|
||||||
startWalkTime, startWalkTime + walkTime.length(), 0);
|
startWalkTime, startWalkTime + walkTimeStr.length(), 0);
|
||||||
secondLineDesc.setSpan(new CustomTypefaceSpan(typeface),
|
secondLineDesc.setSpan(new CustomTypefaceSpan(typeface),
|
||||||
startWalkTime, startWalkTime + walkTime.length(), 0);
|
startWalkTime, startWalkTime + walkTimeStr.length(), 0);
|
||||||
|
|
||||||
return secondLineDesc;
|
return secondLineDesc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,6 +111,50 @@ public class TransportRoutingHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getWalkingTime(@NonNull List<TransportRouteResultSegment> segments) {
|
||||||
|
int res = 0;
|
||||||
|
Map<Pair<TransportRouteResultSegment, TransportRouteResultSegment>, RouteCalculationResult> walkingRouteSegments = this.walkingRouteSegments;
|
||||||
|
if (walkingRouteSegments != null) {
|
||||||
|
TransportRouteResultSegment prevSegment = null;
|
||||||
|
for (TransportRouteResultSegment segment : segments) {
|
||||||
|
RouteCalculationResult walkingRouteSegment = getWalkingRouteSegment(prevSegment, segment);
|
||||||
|
if (walkingRouteSegment != null) {
|
||||||
|
res += walkingRouteSegment.getRoutingTime();
|
||||||
|
}
|
||||||
|
prevSegment = segment;
|
||||||
|
}
|
||||||
|
if (segments.size() > 0) {
|
||||||
|
RouteCalculationResult walkingRouteSegment = getWalkingRouteSegment(segments.get(segments.size() - 1), null);
|
||||||
|
if (walkingRouteSegment != null) {
|
||||||
|
res += walkingRouteSegment.getRoutingTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWalkingDistance(@NonNull List<TransportRouteResultSegment> segments) {
|
||||||
|
int res = 0;
|
||||||
|
Map<Pair<TransportRouteResultSegment, TransportRouteResultSegment>, RouteCalculationResult> walkingRouteSegments = this.walkingRouteSegments;
|
||||||
|
if (walkingRouteSegments != null) {
|
||||||
|
TransportRouteResultSegment prevSegment = null;
|
||||||
|
for (TransportRouteResultSegment segment : segments) {
|
||||||
|
RouteCalculationResult walkingRouteSegment = getWalkingRouteSegment(prevSegment, segment);
|
||||||
|
if (walkingRouteSegment != null) {
|
||||||
|
res += walkingRouteSegment.getWholeDistance();
|
||||||
|
}
|
||||||
|
prevSegment = segment;
|
||||||
|
}
|
||||||
|
if (segments.size() > 0) {
|
||||||
|
RouteCalculationResult walkingRouteSegment = getWalkingRouteSegment(segments.get(segments.size() - 1), null);
|
||||||
|
if (walkingRouteSegment != null) {
|
||||||
|
res += walkingRouteSegment.getWholeDistance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
public void setCurrentRoute(int currentRoute) {
|
public void setCurrentRoute(int currentRoute) {
|
||||||
this.currentRoute = currentRoute;
|
this.currentRoute = currentRoute;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue