use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.
the class SavingTrackHelper method loadGpxFromDatabase.
public void loadGpxFromDatabase() {
Map<String, GPXFile> files = collectRecordedData();
currentTrack.getModifiableGpxFile().tracks.clear();
for (Map.Entry<String, GPXFile> entry : files.entrySet()) {
ctx.getSelectedGpxHelper().addPoints(entry.getValue().getPoints(), currentTrack.getModifiableGpxFile());
currentTrack.getModifiableGpxFile().tracks.addAll(entry.getValue().tracks);
}
currentTrack.processPoints();
prepareCurrentTrackForRecording();
GPXTrackAnalysis analysis = currentTrack.getModifiableGpxFile().getAnalysis(System.currentTimeMillis());
distance = analysis.totalDistance;
points = analysis.wptPoints;
duration = analysis.timeSpan;
}
use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.
the class GpxUiHelper method updateGpxInfoView.
public static void updateGpxInfoView(View v, ContextMenuItem item, GPXInfo info, GpxDataItem dataItem, boolean currentlyRecordingTrack, OsmandApplication app) {
TextView viewName = ((TextView) v.findViewById(R.id.name));
viewName.setText(item.getTitle().replace("/", " • ").trim());
ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setVisibility(View.GONE);
// icon.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_polygom_dark));
viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
GPXTrackAnalysis analysis = null;
if (currentlyRecordingTrack) {
analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis();
} else if (dataItem != null) {
analysis = dataItem.getAnalysis();
}
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 (info.getFileSize() >= 0) {
if (info.getFileSize() > (100 * (1 << 10))) {
size = formatMb.format(new Object[] { (float) info.getFileSize() / (1 << 20) });
} else {
size = formatKb.format(new Object[] { (float) info.getFileSize() / (1 << 10) });
}
}
DateFormat df = app.getResourceManager().getDateFormat();
long fd = info.getLastModified();
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 + "");
distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app));
if (analysis.isTimeSpecified()) {
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 TrackDetailsMenu method updateView.
private void updateView(final View parentView) {
GPXTrackAnalysis analysis = gpxItem.analysis;
if (analysis == null || gpxItem.chartTypes == null) {
parentView.setVisibility(View.GONE);
if (analysis != null && analysis.isBoundsCalculated()) {
mapActivity.getMapView().fitRectToMap(analysis.left, analysis.right, analysis.top, analysis.bottom, 0, 0, 0);
}
return;
}
final LineChart chart = (LineChart) parentView.findViewById(R.id.chart);
chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
refreshChart(chart, false);
}
@Override
public void onNothingSelected() {
}
});
chart.setOnChartGestureListener(new OnChartGestureListener() {
boolean hasTranslated = false;
float highlightDrawX = -1;
@Override
public void onChartGestureStart(MotionEvent me, ChartGesture lastPerformedGesture) {
hasTranslated = false;
if (chart.getHighlighted() != null && chart.getHighlighted().length > 0) {
highlightDrawX = chart.getHighlighted()[0].getDrawX();
} else {
highlightDrawX = -1;
}
}
@Override
public void onChartGestureEnd(MotionEvent me, ChartGesture lastPerformedGesture) {
if ((lastPerformedGesture == ChartGesture.DRAG && hasTranslated) || lastPerformedGesture == ChartGesture.X_ZOOM || lastPerformedGesture == ChartGesture.Y_ZOOM || lastPerformedGesture == ChartGesture.PINCH_ZOOM || lastPerformedGesture == ChartGesture.DOUBLE_TAP || lastPerformedGesture == ChartGesture.ROTATE) {
gpxItem.chartMatrix = new Matrix(chart.getViewPortHandler().getMatrixTouch());
refreshChart(chart, true);
}
}
@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) {
hasTranslated = true;
if (highlightDrawX != -1) {
Highlight h = chart.getHighlightByTouchPoint(highlightDrawX, 0f);
if (h != null) {
chart.highlightValue(h);
refreshChart(chart, false);
}
}
}
});
final OsmandApplication app = mapActivity.getMyApplication();
final IconsCache ic = app.getIconsCache();
GpxUiHelper.setupGPXChart(app, chart, 4);
List<ILineDataSet> dataSets = new ArrayList<>();
if (gpxItem.chartTypes != null && gpxItem.chartTypes.length > 0) {
for (int i = 0; i < gpxItem.chartTypes.length; i++) {
OrderedLineDataSet dataSet = null;
switch(gpxItem.chartTypes[i]) {
case ALTITUDE:
dataSet = GpxUiHelper.createGPXElevationDataSet(app, chart, analysis, gpxItem.chartAxisType, false, true);
break;
case SPEED:
dataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart, analysis, gpxItem.chartAxisType, gpxItem.chartTypes.length > 1, true);
break;
case SLOPE:
dataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart, analysis, gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true);
break;
}
if (dataSet != null) {
dataSets.add(dataSet);
}
}
}
Collections.sort(dataSets, new Comparator<ILineDataSet>() {
@Override
public int compare(ILineDataSet ds1, ILineDataSet ds2) {
OrderedLineDataSet dataSet1 = (OrderedLineDataSet) ds1;
OrderedLineDataSet dataSet2 = (OrderedLineDataSet) ds2;
return dataSet1.getPriority() > dataSet2.getPriority() ? -1 : (dataSet1.getPriority() == dataSet2.getPriority() ? 0 : 1);
}
});
chart.setData(new LineData(dataSets));
updateChart(chart);
View yAxis = parentView.findViewById(R.id.y_axis);
ImageView yAxisIcon = (ImageView) parentView.findViewById(R.id.y_axis_icon);
TextView yAxisTitle = (TextView) parentView.findViewById(R.id.y_axis_title);
View yAxisArrow = parentView.findViewById(R.id.y_axis_arrow);
final List<GPXDataSetType[]> availableTypes = new ArrayList<>();
boolean hasSlopeChart = false;
if (analysis.hasElevationData) {
availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE });
if (gpxItem.chartAxisType != GPXDataSetAxisType.TIME) {
availableTypes.add(new GPXDataSetType[] { GPXDataSetType.SLOPE });
}
}
if (analysis.hasSpeedData) {
availableTypes.add(new GPXDataSetType[] { GPXDataSetType.SPEED });
}
if (analysis.hasElevationData && gpxItem.chartAxisType != GPXDataSetAxisType.TIME) {
availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE });
}
if (analysis.hasElevationData && analysis.hasSpeedData) {
availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED });
}
for (GPXDataSetType t : gpxItem.chartTypes) {
if (t == GPXDataSetType.SLOPE) {
hasSlopeChart = true;
break;
}
}
yAxisIcon.setImageDrawable(GPXDataSetType.getImageDrawable(app, gpxItem.chartTypes));
yAxisTitle.setText(GPXDataSetType.getName(app, gpxItem.chartTypes));
if (availableTypes.size() > 0) {
yAxis.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu optionsMenu = new PopupMenu(mapActivity, v);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
for (final GPXDataSetType[] types : availableTypes) {
MenuItem menuItem = optionsMenu.getMenu().add(GPXDataSetType.getName(app, types)).setIcon(GPXDataSetType.getImageDrawable(app, types));
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem mItem) {
gpxItem.chartTypes = types;
update();
return true;
}
});
}
optionsMenu.show();
}
});
yAxisArrow.setVisibility(View.VISIBLE);
} else {
yAxis.setOnClickListener(null);
yAxis.setBackgroundResource(0);
yAxisArrow.setVisibility(View.GONE);
}
View xAxis = parentView.findViewById(R.id.x_axis);
ImageView xAxisIcon = (ImageView) parentView.findViewById(R.id.x_axis_icon);
TextView xAxisTitle = (TextView) parentView.findViewById(R.id.x_axis_title);
View xAxisArrow = parentView.findViewById(R.id.x_axis_arrow);
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) {
xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_time));
xAxisTitle.setText(app.getString(R.string.shared_string_time));
} else {
xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_marker_dark));
xAxisTitle.setText(app.getString(R.string.distance));
}
if (analysis.isTimeSpecified() && !hasSlopeChart) {
xAxis.setOnClickListener(new View.OnClickListener() {
@Override
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;
}
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();
}
});
xAxisArrow.setVisibility(View.VISIBLE);
} else {
xAxis.setOnClickListener(null);
xAxis.setBackgroundResource(0);
xAxisArrow.setVisibility(View.GONE);
}
refreshChart(chart, true);
}
use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.
the class GPXDatabase method insert.
private void insert(GpxDataItem item, SQLiteConnection db) {
String fileName = getFileName(item.file);
String fileDir = getFileDir(item.file);
GPXTrackAnalysis a = item.getAnalysis();
String color;
if (item.color == 0) {
color = "";
} else {
color = Algorithms.colorToString(item.color);
}
if (a != null) {
db.execSQL("INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] { fileName, fileDir, a.totalDistance, a.totalTracks, a.startTime, a.endTime, a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown, a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints, color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0, Algorithms.encodeStringSet(item.analysis.wptCategoryNames) });
} else {
db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" + GPX_COL_NAME + ", " + GPX_COL_DIR + ", " + GPX_COL_COLOR + ", " + GPX_COL_FILE_LAST_MODIFIED_TIME + ", " + GPX_COL_SPLIT_TYPE + ", " + GPX_COL_SPLIT_INTERVAL + ", " + GPX_COL_API_IMPORTED + ") VALUES (?, ?, ?, ?, ?, ?, ?)", new Object[] { fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0 });
}
}
use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.
the class AvailableGPXFragment method openPopUpMenu.
private void openPopUpMenu(View v, final GpxInfo gpxInfo) {
IconsCache iconsCache = getMyApplication().getIconsCache();
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_show_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_show_on_map));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
showGpxOnMap(gpxInfo);
return true;
}
});
GPXTrackAnalysis analysis;
if ((analysis = getGpxTrackAnalysis(gpxInfo, app)) != null) {
if (analysis.totalDistance != 0 && !gpxInfo.currentlyRecordingTrack) {
item = optionsMenu.getMenu().add(R.string.analyze_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_info_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
new OpenGpxDetailsTask(gpxInfo).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return true;
}
});
}
}
item = optionsMenu.getMenu().add(R.string.shared_string_move).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_folder_stroke));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
moveGpx(gpxInfo);
return true;
}
});
item = optionsMenu.getMenu().add(R.string.shared_string_rename).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
LocalIndexesFragment.renameFile(getActivity(), gpxInfo.file, new RenameCallback() {
@Override
public void renamedTo(File file) {
app.getGpxDatabase().rename(gpxInfo.file, file);
asyncLoader = new LoadGpxTask();
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
}
});
return true;
}
});
item = optionsMenu.getMenu().add(R.string.shared_string_share).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_gshare_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
final Uri fileUri = Uri.fromFile(gpxInfo.file);
final Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
sendIntent.setType("application/gpx+xml");
startActivity(sendIntent);
return true;
}
});
final OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
if (osmEditingPlugin != null && osmEditingPlugin.isActive()) {
item = optionsMenu.getMenu().add(R.string.shared_string_export).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_export));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
osmEditingPlugin.sendGPXFiles(getActivity(), AvailableGPXFragment.this, gpxInfo);
return true;
}
});
}
item = optionsMenu.getMenu().add(R.string.shared_string_delete).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.recording_delete_confirm);
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
operationTask = new DeleteGpxTask();
operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxInfo);
}
});
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.show();
return true;
}
});
optionsMenu.show();
}
Aggregations