Work in progress
This commit is contained in:
parent
45d8204121
commit
5174acb5d1
6 changed files with 103 additions and 23 deletions
|
@ -158,12 +158,14 @@ public class GPXUtilities {
|
|||
public static class Elevation {
|
||||
public float distance;
|
||||
public int time;
|
||||
public int timeOfDay;
|
||||
public float elevation;
|
||||
}
|
||||
|
||||
public static class Speed {
|
||||
public float distance;
|
||||
public int time;
|
||||
public int timeOfDay;
|
||||
public float speed;
|
||||
}
|
||||
|
||||
|
@ -610,6 +612,7 @@ public class GPXUtilities {
|
|||
}
|
||||
|
||||
elevation1.time = timeDiff;
|
||||
elevation1.timeOfDay = Algorithms.getDayTimeInSeconds(point.time, false);
|
||||
elevation1.distance = (j > 0) ? calculations[0] : 0;
|
||||
elevationData.add(elevation1);
|
||||
if (!hasElevationData && !Float.isNaN(elevation1.elevation) && totalDistance > 0) {
|
||||
|
@ -626,6 +629,7 @@ public class GPXUtilities {
|
|||
Speed speed1 = new Speed();
|
||||
speed1.speed = speed;
|
||||
speed1.time = timeDiff;
|
||||
speed1.timeOfDay = Algorithms.getDayTimeInSeconds(point.time, false);
|
||||
speed1.distance = elevation1.distance;
|
||||
speedData.add(speed1);
|
||||
if (!hasSpeedData && speed1.speed > 0 && totalDistance > 0) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.osmand.util;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
|
@ -746,4 +748,11 @@ public class Algorithms {
|
|||
is.close();
|
||||
return map;
|
||||
}
|
||||
|
||||
public static int getDayTimeInSeconds(long seconds, boolean defaultTimeZone) {
|
||||
Calendar calendar = defaultTimeZone ? Calendar.getInstance(TimeZone.getDefault()) : Calendar.getInstance();
|
||||
calendar.setTimeInMillis(seconds * 1000);
|
||||
int daytime = calendar.get(Calendar.HOUR)*3600 + calendar.get(Calendar.MINUTE)*60 + calendar.get(Calendar.SECOND);
|
||||
return daytime;
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
3. If you modify the English strings file, please add new strings at the top of the file, this makes periodic reviews before releases easier.
|
||||
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
||||
Thx - Hardy
|
||||
-->
|
||||
--> <string name="time_of_day">Time of day</string>
|
||||
<string name="tracks_on_map">Tracks on the map</string>
|
||||
<string name="add_destination_query">Please add Destination first</string>
|
||||
<string name="previous_route">Previous route</string>
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus;
|
|||
import android.content.Context;
|
||||
import android.text.format.DateUtils;
|
||||
|
||||
import java.util.TimeZone;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.City.CityType;
|
||||
import net.osmand.osm.AbstractPoiType;
|
||||
|
@ -74,6 +75,12 @@ public class OsmAndFormatter {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getFormattedTimeShort(long seconds) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(seconds * 1000);
|
||||
return SIMPLE_TIME_OF_DAY_FORMAT.format(calendar.getTime());
|
||||
}
|
||||
|
||||
public static String getFormattedDate(Context context, long milliseconds) {
|
||||
return DateUtils.formatDateTime(context, milliseconds, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ import net.osmand.AndroidUtils;
|
|||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||
|
@ -100,6 +101,7 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import static com.github.mikephil.charting.components.XAxis.XAxisPosition.BOTTOM;
|
||||
import static net.osmand.binary.RouteDataObject.HEIGHT_UNDEFINED;
|
||||
|
@ -116,6 +118,7 @@ import static net.osmand.plus.download.DownloadActivity.formatMb;
|
|||
public class GpxUiHelper {
|
||||
|
||||
private static final int OPEN_GPX_DOCUMENT_REQUEST = 1005;
|
||||
private static final Log LOG = PlatformUtil.getLog(GpxUiHelper.class);
|
||||
|
||||
public static String getDescription(OsmandApplication app, GPXFile result, File f, boolean html) {
|
||||
GPXTrackAnalysis analysis = result.getAnalysis(f == null ? 0 : f.lastModified());
|
||||
|
@ -1120,7 +1123,6 @@ public class GpxUiHelper {
|
|||
final boolean useHours = timeSpan / 3600000 > 0;
|
||||
xAxis.setGranularity(1f);
|
||||
xAxis.setValueFormatter(new IAxisValueFormatter() {
|
||||
|
||||
@Override
|
||||
public String getFormattedValue(float value, AxisBase axis) {
|
||||
int seconds = (int)value;
|
||||
|
@ -1140,6 +1142,21 @@ public class GpxUiHelper {
|
|||
return 1f;
|
||||
}
|
||||
|
||||
private static float setupXAxisTimeOfDay(XAxis xAxis) {
|
||||
xAxis.setGranularity(1f);
|
||||
xAxis.setValueFormatter(new IAxisValueFormatter() {
|
||||
@Override
|
||||
public String getFormattedValue(float value, AxisBase axis) {
|
||||
|
||||
|
||||
int seconds = (int)value/1000;
|
||||
LOG.debug(OsmAndFormatter.getFormattedTimeShort(seconds));
|
||||
return OsmAndFormatter.getFormattedTimeShort(seconds);
|
||||
}
|
||||
});
|
||||
return 1f;
|
||||
}
|
||||
|
||||
private static List<Entry> calculateElevationArray(GPXTrackAnalysis analysis, GPXDataSetAxisType axisType,
|
||||
float divX, float convEle) {
|
||||
List<Entry> values = new ArrayList<>();
|
||||
|
@ -1207,6 +1224,8 @@ public class GpxUiHelper {
|
|||
XAxis xAxis = mChart.getXAxis();
|
||||
if (axisType == GPXDataSetAxisType.TIME && analysis.isTimeSpecified()) {
|
||||
divX = setupXAxisTime(xAxis, analysis.timeSpan);
|
||||
} else if (axisType == GPXDataSetAxisType.TIMEOFDAY && analysis.isTimeSpecified()) {
|
||||
divX = setupXAxisTimeOfDay(xAxis);
|
||||
} else {
|
||||
divX = setupXAxisDistance(ctx, xAxis, analysis.totalDistance);
|
||||
}
|
||||
|
@ -1291,6 +1310,9 @@ public class GpxUiHelper {
|
|||
XAxis xAxis = mChart.getXAxis();
|
||||
if (axisType == GPXDataSetAxisType.TIME && analysis.isTimeSpecified()) {
|
||||
divX = setupXAxisTime(xAxis, analysis.timeSpan);
|
||||
} else if (axisType == GPXDataSetAxisType.TIMEOFDAY && analysis.isTimeSpecified()) {
|
||||
divX = setupXAxisTimeOfDay(xAxis);
|
||||
|
||||
} else {
|
||||
divX = setupXAxisDistance(ctx, xAxis, analysis.totalDistance);
|
||||
}
|
||||
|
@ -1336,13 +1358,29 @@ public class GpxUiHelper {
|
|||
float nextY;
|
||||
float x;
|
||||
for (Speed s : speedData) {
|
||||
x = axisType == GPXDataSetAxisType.TIME ? s.time : s.distance;
|
||||
switch(axisType) {
|
||||
case TIME:
|
||||
x = s.time;
|
||||
break;
|
||||
case TIMEOFDAY:
|
||||
x = s.timeOfDay;
|
||||
break;
|
||||
default:
|
||||
x = s.distance;
|
||||
break;
|
||||
}
|
||||
|
||||
if (x > 0) {
|
||||
if (axisType == GPXDataSetAxisType.TIME && x > 60) {
|
||||
values.add(new Entry(nextX + 1, 0));
|
||||
values.add(new Entry(nextX + x - 1, 0));
|
||||
}
|
||||
// if (axisType == GPXDataSetAxisType.TIMEOFDAY) {
|
||||
// values.add(new Entry(nextX + 1, 0));
|
||||
// values.add(new Entry(nextX + x - 1, 0));
|
||||
// }
|
||||
nextX += x / divX;
|
||||
LOG.debug("X = " + x + ", divX = " + divX + ", nextX = " + nextX);
|
||||
if (Float.isNaN(divSpeed)) {
|
||||
nextY = s.speed * mulSpeed;
|
||||
} else {
|
||||
|
@ -1651,7 +1689,8 @@ public class GpxUiHelper {
|
|||
|
||||
public enum GPXDataSetAxisType {
|
||||
DISTANCE(R.string.distance, R.drawable.ic_action_marker_dark),
|
||||
TIME(R.string.shared_string_time, R.drawable.ic_action_time);
|
||||
TIME(R.string.shared_string_time, R.drawable.ic_action_time),
|
||||
TIMEOFDAY(R.string.time_of_day, R.drawable.ic_action_time);
|
||||
|
||||
private int stringId;
|
||||
private int imageId;
|
||||
|
|
|
@ -186,7 +186,8 @@ public class TrackDetailsMenu {
|
|||
if (ds != null && ds.size() > 0) {
|
||||
TrkSegment segment = getTrackSegment(chart);
|
||||
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
|
||||
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) {
|
||||
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME ||
|
||||
gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
|
||||
float time = pos * 1000;
|
||||
for (WptPt p : segment.points) {
|
||||
if (p.time - gpxItem.analysis.startTime >= time) {
|
||||
|
@ -227,7 +228,7 @@ public class TrackDetailsMenu {
|
|||
float endTime = endPos * 1000;
|
||||
for (WptPt p : segment.points) {
|
||||
if (p.time - gpxItem.analysis.startTime >= startTime &&
|
||||
p.time - gpxItem.analysis.startTime <= endTime) {
|
||||
p.time - gpxItem.analysis.startTime <= endTime) {
|
||||
if (left == 0 && right == 0) {
|
||||
left = p.getLongitude();
|
||||
right = p.getLongitude();
|
||||
|
@ -241,6 +242,26 @@ public class TrackDetailsMenu {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
|
||||
float startTime = startPos * 1000;
|
||||
float endTime = endPos * 1000;
|
||||
for (WptPt p : segment.points) {
|
||||
if (p.time - gpxItem.analysis.startTime >= startTime &&
|
||||
p.time - gpxItem.analysis.startTime <= endTime) {
|
||||
if (left == 0 && right == 0) {
|
||||
left = p.getLongitude();
|
||||
right = p.getLongitude();
|
||||
top = p.getLatitude();
|
||||
bottom = p.getLatitude();
|
||||
} else {
|
||||
left = Math.min(left, p.getLongitude());
|
||||
right = Math.max(right, p.getLongitude());
|
||||
top = Math.max(top, p.getLatitude());
|
||||
bottom = Math.min(bottom, p.getLatitude());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
float startDistance = startPos * dataSet.getDivX();
|
||||
float endDistance = endPos * dataSet.getDivX();
|
||||
|
@ -541,7 +562,6 @@ public class TrackDetailsMenu {
|
|||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
optionsMenu.show();
|
||||
}
|
||||
|
@ -560,6 +580,9 @@ public class TrackDetailsMenu {
|
|||
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) {
|
||||
xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_time));
|
||||
xAxisTitle.setText(app.getString(R.string.shared_string_time));
|
||||
} else if (gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
|
||||
xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_time));
|
||||
xAxisTitle.setText(app.getString(R.string.time_of_day));
|
||||
} else {
|
||||
xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_marker_dark));
|
||||
xAxisTitle.setText(app.getString(R.string.distance));
|
||||
|
@ -570,23 +593,21 @@ public class TrackDetailsMenu {
|
|||
public void onClick(View v) {
|
||||
final PopupMenu optionsMenu = new PopupMenu(mapActivity, v);
|
||||
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
|
||||
final GPXDataSetAxisType type;
|
||||
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) {
|
||||
type = GPXDataSetAxisType.DISTANCE;
|
||||
} else {
|
||||
type = GPXDataSetAxisType.TIME;
|
||||
for (final GPXDataSetAxisType type : GPXDataSetAxisType.values()) {
|
||||
MenuItem menuItem = optionsMenu.getMenu()
|
||||
.add(type.getStringId()).setIcon(type.getImageDrawable(app));
|
||||
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem mItem) {
|
||||
|
||||
gpxItem.chartAxisType = type;
|
||||
gpxItem.chartHighlightPos = -1;
|
||||
gpxItem.chartMatrix = null;
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
MenuItem menuItem = optionsMenu.getMenu().add(type.getStringId()).setIcon(type.getImageDrawable(app));
|
||||
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem mItem) {
|
||||
gpxItem.chartAxisType = type;
|
||||
gpxItem.chartHighlightPos = -1;
|
||||
gpxItem.chartMatrix = null;
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
optionsMenu.show();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue