use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.
the class AvailableGPXFragment method getGpxTrackAnalysis.
@Nullable
private static GPXTrackAnalysis getGpxTrackAnalysis(GpxInfo gpxInfo, OsmandApplication app) {
SelectedGpxFile sgpx = getSelectedGpxFile(gpxInfo, app);
GPXTrackAnalysis analysis = null;
if (sgpx != null) {
analysis = sgpx.getTrackAnalysis();
} else if (gpxInfo.currentlyRecordingTrack) {
analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis();
} else {
GpxDataItem dataItem = gpxInfo.file == null ? null : app.getGpxDatabase().getItem(gpxInfo.file);
if (dataItem != null) {
analysis = dataItem.getAnalysis();
}
}
return analysis;
}
use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.
the class AvailableGPXFragment method updateGpxInfoView.
public static void updateGpxInfoView(View v, GpxInfo child, OsmandApplication app, boolean isDashItem) {
TextView viewName = ((TextView) v.findViewById(R.id.name));
if (!isDashItem) {
v.findViewById(R.id.divider_list).setVisibility(View.VISIBLE);
v.findViewById(R.id.divider_dash).setVisibility(View.GONE);
} else {
v.findViewById(R.id.divider_dash).setVisibility(View.VISIBLE);
v.findViewById(R.id.divider_list).setVisibility(View.GONE);
}
viewName.setText(child.getName());
// ImageView icon = (ImageView) v.findViewById(!isDashItem? R.id.icon : R.id.show_on_map);
ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setVisibility(View.VISIBLE);
icon.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_polygom_dark));
if (child.isCorrupted()) {
viewName.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
} else {
viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
}
if (getSelectedGpxFile(child, app) != null) {
icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_polygom_dark, R.color.color_distance));
}
GPXTrackAnalysis analysis = getGpxTrackAnalysis(child, app);
boolean sectionRead = analysis == null;
if (sectionRead) {
v.findViewById(R.id.read_section).setVisibility(View.GONE);
v.findViewById(R.id.unknown_section).setVisibility(View.VISIBLE);
String date = "";
String size = "";
if (child.getSize() >= 0) {
if (child.getSize() > 100) {
size = formatMb.format(new Object[] { (float) child.getSize() / (1 << 10) });
} else {
size = child.getSize() + " kB";
}
}
DateFormat df = app.getResourceManager().getDateFormat();
long fd = child.getFileDate();
if (fd > 0) {
date = (df.format(new Date(fd)));
}
TextView sizeText = (TextView) v.findViewById(R.id.date_and_size_details);
sizeText.setText(date + " \u2022 " + size);
} else {
v.findViewById(R.id.read_section).setVisibility(View.VISIBLE);
v.findViewById(R.id.unknown_section).setVisibility(View.GONE);
ImageView distanceI = (ImageView) v.findViewById(R.id.distance_icon);
distanceI.setVisibility(View.VISIBLE);
distanceI.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_small_distance));
ImageView pointsI = (ImageView) v.findViewById(R.id.points_icon);
pointsI.setVisibility(View.VISIBLE);
pointsI.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_small_point));
ImageView timeI = (ImageView) v.findViewById(R.id.time_icon);
timeI.setVisibility(View.VISIBLE);
timeI.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_small_time));
TextView time = (TextView) v.findViewById(R.id.time);
TextView distance = (TextView) v.findViewById(R.id.distance);
TextView pointsCount = (TextView) v.findViewById(R.id.points_count);
pointsCount.setText(analysis.wptPoints + "");
// if (analysis.totalDistanceMoving != 0) {
// distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistanceMoving, app));
// } else {
distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app));
if (analysis.isTimeSpecified()) {
// if (analysis.isTimeMoving()) {
// time.setText(Algorithms.formatDuration((int) (analysis.timeMoving / 1000)) + "");
// } else {
time.setText(Algorithms.formatDuration((int) (analysis.timeSpan / 1000), app.accessibilityEnabled()) + "");
// }
} else {
time.setText("");
}
}
TextView descr = ((TextView) v.findViewById(R.id.description));
descr.setVisibility(View.GONE);
v.findViewById(R.id.check_item).setVisibility(View.GONE);
}
use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.
the class ShowRouteInfoDialogFragment method buildHeader.
private void buildHeader(View headerView) {
OsmandApplication app = getMyApplication();
final LineChart mChart = (LineChart) headerView.findViewById(R.id.chart);
GpxUiHelper.setupGPXChart(app, mChart, 4);
mChart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
listView.requestDisallowInterceptTouchEvent(true);
return false;
}
});
GPXTrackAnalysis analysis = gpx.getAnalysis(0);
if (analysis.hasElevationData) {
List<ILineDataSet> dataSets = new ArrayList<>();
elevationDataSet = GpxUiHelper.createGPXElevationDataSet(app, mChart, analysis, GPXDataSetAxisType.DISTANCE, false, true);
if (elevationDataSet != null) {
dataSets.add(elevationDataSet);
}
slopeDataSet = GpxUiHelper.createGPXSlopeDataSet(app, mChart, analysis, GPXDataSetAxisType.DISTANCE, elevationDataSet.getValues(), true, true);
if (slopeDataSet != null) {
dataSets.add(slopeDataSet);
}
LineData data = new LineData(dataSets);
mChart.setData(data);
mChart.setOnChartGestureListener(new OnChartGestureListener() {
float highlightDrawX = -1;
@Override
public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
if (mChart.getHighlighted() != null && mChart.getHighlighted().length > 0) {
highlightDrawX = mChart.getHighlighted()[0].getDrawX();
} else {
highlightDrawX = -1;
}
}
@Override
public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
gpxItem.chartMatrix = new Matrix(mChart.getViewPortHandler().getMatrixTouch());
Highlight[] highlights = mChart.getHighlighted();
if (highlights != null && highlights.length > 0) {
gpxItem.chartHighlightPos = highlights[0].getX();
} else {
gpxItem.chartHighlightPos = -1;
}
}
@Override
public void onChartLongPressed(MotionEvent me) {
}
@Override
public void onChartDoubleTapped(MotionEvent me) {
}
@Override
public void onChartSingleTapped(MotionEvent me) {
}
@Override
public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
}
@Override
public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
}
@Override
public void onChartTranslate(MotionEvent me, float dX, float dY) {
if (highlightDrawX != -1) {
Highlight h = mChart.getHighlightByTouchPoint(highlightDrawX, 0f);
if (h != null) {
mChart.highlightValue(h);
}
}
}
});
mChart.setVisibility(View.VISIBLE);
} else {
elevationDataSet = null;
slopeDataSet = null;
mChart.setVisibility(View.GONE);
}
((TextView) headerView.findViewById(R.id.average_text)).setText(OsmAndFormatter.getFormattedAlt(analysis.avgElevation, app));
String min = OsmAndFormatter.getFormattedAlt(analysis.minElevation, app);
String max = OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app);
((TextView) headerView.findViewById(R.id.range_text)).setText(min + " - " + max);
String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
((TextView) headerView.findViewById(R.id.descent_text)).setText(desc);
((TextView) headerView.findViewById(R.id.ascent_text)).setText(asc);
((ImageView) headerView.findViewById(R.id.average_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_average));
((ImageView) headerView.findViewById(R.id.range_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_average));
((ImageView) headerView.findViewById(R.id.descent_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_descent));
((ImageView) headerView.findViewById(R.id.ascent_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_ascent));
headerView.findViewById(R.id.details_view).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openDetails();
}
});
}
use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.
the class SavingTrackHelper method saveDataToGpx.
/**
* @return warnings
*/
public synchronized List<String> saveDataToGpx(File dir) {
List<String> warnings = new ArrayList<String>();
dir.mkdirs();
if (dir.getParentFile().canWrite()) {
if (dir.exists()) {
Map<String, GPXFile> data = collectRecordedData();
// save file
for (final String f : data.keySet()) {
// $NON-NLS-1$
File fout = new File(dir, f + ".gpx");
if (!data.get(f).isEmpty()) {
WptPt pt = data.get(f).findPointToShow();
File targetDir = dir;
if (ctx.getSettings().STORE_TRACKS_IN_MONTHLY_DIRECTORIES.get()) {
SimpleDateFormat dateDirFormat = new SimpleDateFormat("yyyy-MM");
String dateDirName = dateDirFormat.format(new Date(pt.time));
File dateDir = new File(dir, dateDirName);
dateDir.mkdirs();
if (dateDir.exists()) {
targetDir = dateDir;
}
}
// $NON-NLS-1$
String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time));
// $NON-NLS-1$
fout = new File(targetDir, fileName + ".gpx");
int ind = 1;
while (fout.exists()) {
// $NON-NLS-1$ //$NON-NLS-2$
fout = new File(targetDir, fileName + "_" + (++ind) + ".gpx");
}
}
String warn = GPXUtilities.writeGpxFile(fout, data.get(f), ctx);
if (warn != null) {
warnings.add(warn);
return warnings;
}
GPXFile gpx = data.get(f);
GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified());
GpxDataItem item = new GpxDataItem(fout, analysis);
ctx.getGpxDatabase().add(item);
}
}
}
SQLiteDatabase db = getWritableDatabase();
if (db != null && warnings.isEmpty() && db.isOpen()) {
try {
// remove all from db
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE " + TRACK_COL_DATE + " <= ?", new Object[] { System.currentTimeMillis() });
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
db.execSQL("DELETE FROM " + POINT_NAME + " WHERE " + POINT_COL_DATE + " <= ?", new Object[] { System.currentTimeMillis() });
// delete all
// db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$
// db.execSQL("DELETE FROM " + POINT_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$
} finally {
db.close();
}
}
distance = 0;
points = 0;
duration = 0;
ctx.getSelectedGpxHelper().clearPoints(currentTrack.getModifiableGpxFile());
currentTrack.getModifiableGpxFile().tracks.clear();
currentTrack.getModifiablePointsToDisplay().clear();
currentTrack.getModifiableGpxFile().modifiedTime = System.currentTimeMillis();
prepareCurrentTrackForRecording();
return warnings;
}
use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.
the class GpxSelectionHelper method processGroupTrack.
private static void processGroupTrack(OsmandApplication app, GpxDisplayGroup group) {
List<GpxDisplayItem> list = group.getModifiableList();
String timeSpanClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_time_span_color));
String speedClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_speed));
String ascClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_altitude_asc));
String descClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_altitude_desc));
String distanceClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_distance_color));
final float eleThreshold = 3;
// int t = 1;
for (TrkSegment r : group.track.segments) {
if (r.points.size() == 0) {
continue;
}
GPXTrackAnalysis[] as;
boolean split = true;
if (group.splitDistance > 0) {
List<GPXTrackAnalysis> trackSegments = r.splitByDistance(group.splitDistance);
as = trackSegments.toArray(new GPXTrackAnalysis[trackSegments.size()]);
} else if (group.splitTime > 0) {
List<GPXTrackAnalysis> trackSegments = r.splitByTime(group.splitTime);
as = trackSegments.toArray(new GPXTrackAnalysis[trackSegments.size()]);
} else {
split = false;
as = new GPXTrackAnalysis[] { GPXTrackAnalysis.segment(0, r) };
}
for (GPXTrackAnalysis analysis : as) {
GpxDisplayItem item = new GpxDisplayItem();
item.group = group;
if (split) {
item.splitMetric = analysis.metricEnd;
item.secondarySplitMetric = analysis.secondaryMetricEnd;
item.splitName = formatSplitName(analysis.metricEnd, group, app);
item.splitName += " (" + formatSecondarySplitName(analysis.secondaryMetricEnd, group, app) + ") ";
}
item.description = GpxUiHelper.getDescription(app, analysis, true);
item.analysis = analysis;
String name = "";
// }
if (!group.isSplitDistance()) {
name += GpxUiHelper.getColorValue(distanceClr, OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app));
}
if ((analysis.timeSpan > 0 || analysis.timeMoving > 0) && !group.isSplitTime()) {
long tm = analysis.timeMoving;
if (tm == 0) {
tm = analysis.timeSpan;
}
if (name.length() != 0)
name += ", ";
name += GpxUiHelper.getColorValue(timeSpanClr, Algorithms.formatDuration((int) (tm / 1000), app.accessibilityEnabled()));
}
if (analysis.isSpeedSpecified()) {
if (name.length() != 0)
name += ", ";
name += GpxUiHelper.getColorValue(speedClr, OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app));
}
// add min/max elevation data to split track analysis to facilitate easier track/segment identification
if (analysis.isElevationSpecified()) {
if (name.length() != 0)
name += ", ";
name += GpxUiHelper.getColorValue(descClr, OsmAndFormatter.getFormattedAlt(analysis.minElevation, app));
name += " - ";
name += GpxUiHelper.getColorValue(ascClr, OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app));
}
if (analysis.isElevationSpecified() && (analysis.diffElevationUp > eleThreshold || analysis.diffElevationDown > eleThreshold)) {
if (name.length() != 0)
name += ", ";
if (analysis.diffElevationDown > eleThreshold) {
name += GpxUiHelper.getColorValue(descClr, " \u2193 " + OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app));
}
if (analysis.diffElevationUp > eleThreshold) {
name += GpxUiHelper.getColorValue(ascClr, " \u2191 " + OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app));
}
}
item.name = name;
item.locationStart = analysis.locationStart;
item.locationEnd = analysis.locationEnd;
list.add(item);
}
}
}
Aggregations