use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class GpxBlockStatisticsBuilder method initItems.
public void initItems(@Nullable GPXTrackAnalysis initAnalysis) {
GPXFile gpxFile = getGPXFile();
if (app == null || gpxFile == null) {
return;
}
boolean withoutGaps = false;
if (initAnalysis == null) {
withoutGaps = true;
if (gpxFile.equals(app.getSavingTrackHelper().getCurrentGpx())) {
GPXFile currentGpx = app.getSavingTrackHelper().getCurrentTrack().getGpxFile();
analysis = currentGpx.getAnalysis(0);
withoutGaps = !selectedGpxFile.isJoinSegments() && (Algorithms.isEmpty(currentGpx.tracks) || currentGpx.tracks.get(0).generalTrack);
} else {
GpxDisplayItem gpxDisplayItem = getDisplayItem(gpxFile);
if (gpxDisplayItem != null) {
analysis = gpxDisplayItem.analysis;
withoutGaps = !selectedGpxFile.isJoinSegments() && gpxDisplayItem.isGeneralTrack();
}
}
} else {
analysis = initAnalysis;
}
items.clear();
if (analysis != null) {
if (tabItem == null) {
float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
String minElevation = OsmAndFormatter.getFormattedAlt(analysis.minElevation, app);
String maxElevation = OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app);
String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app);
String maxSpeed = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app);
float timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
long timeMoving = withoutGaps ? analysis.timeMovingWithoutGaps : analysis.timeMoving;
prepareDataDistance(totalDistance);
prepareDataAscent(asc);
prepareDataDescent(desc);
prepareDataAltitudeRange(minElevation, maxElevation);
prepareDataAverageSpeed(avg);
prepareDataMaximumSpeed(maxSpeed);
prepareDataTimeSpan(timeSpan);
prepareDataTimeMoving(timeMoving);
} else {
switch(tabItem) {
case GPX_TAB_ITEM_GENERAL:
{
float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
float timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
Date start = new Date(analysis.startTime);
Date end = new Date(analysis.endTime);
prepareDataDistance(totalDistance);
prepareDataTimeSpan(timeSpan);
prepareDataStartTime(start);
prepareDataEndTime(end);
break;
}
case GPX_TAB_ITEM_ALTITUDE:
{
String min = OsmAndFormatter.getFormattedAlt(analysis.minElevation, app);
String max = OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app);
String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
prepareDataAverageAltitude();
prepareDataAltitudeRange(min, max);
prepareDataAscent(asc);
prepareDataDescent(desc);
break;
}
case GPX_TAB_ITEM_SPEED:
{
String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app);
String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app);
long timeMoving = withoutGaps ? analysis.timeMovingWithoutGaps : analysis.timeMoving;
float totalDistanceMoving = withoutGaps ? analysis.totalDistanceMovingWithoutGaps : analysis.totalDistanceMoving;
prepareDataAverageSpeed(avg);
prepareDataMaximumSpeed(max);
prepareDataTimeMoving(timeMoving);
prepareDataDistanceCorrected(totalDistanceMoving);
break;
}
}
}
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class TrackDetailsMenu method getLocationAtPos.
@Nullable
private LatLon getLocationAtPos(LineChart chart, float pos) {
WptPt point = null;
LineData lineData = chart.getLineData();
List<ILineDataSet> ds = lineData != null ? lineData.getDataSets() : null;
GpxDisplayItem gpxItem = getGpxItem();
if (!Algorithms.isEmpty(ds) && gpxItem != null) {
TrkSegment segment = getTrackSegment(chart);
if (segment == null) {
return null;
}
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
GPXFile gpxFile = gpxItem.group.getGpx();
boolean joinSegments = selectedGpxFile != null && selectedGpxFile.isJoinSegments();
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME || gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
float time = pos * 1000;
point = GpxUiHelper.getSegmentPointByTime(segment, gpxFile, time, true, joinSegments);
} else {
float distance = pos * dataSet.getDivX();
point = GpxUiHelper.getSegmentPointByDistance(segment, gpxFile, distance, true, joinSegments);
}
}
return point == null ? null : new LatLon(point.lat, point.lon);
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class TrackDetailsMenu method updateChart.
private void updateChart(LineChart chart) {
GpxDisplayItem gpxItem = getGpxItem();
chart.notifyDataSetChanged();
chart.invalidate();
if (gpxItem != null) {
if (gpxItem.chartMatrix != null) {
chart.getViewPortHandler().refresh(new Matrix(gpxItem.chartMatrix), chart, true);
}
if (gpxItem.chartHighlightPos != -1) {
chart.highlightValue(gpxItem.chartHighlightPos, 0);
} else if (gpxItem.locationOnMap != null) {
LineData lineData = chart.getLineData();
List<ILineDataSet> ds = lineData != null ? lineData.getDataSets() : null;
if (ds != null && ds.size() > 0) {
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
gpxItem.chartHighlightPos = (float) (gpxItem.locationOnMap.distance / dataSet.getDivX());
chart.highlightValue(gpxItem.chartHighlightPos, 0);
}
} else {
chart.highlightValue(null);
}
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class TrackDetailsMenu method refreshChart.
public void refreshChart(LineChart chart, boolean fitTrackOnMap, boolean forceFit) {
MapActivity mapActivity = getMapActivity();
GpxDisplayItem gpxItem = getGpxItem();
if (mapActivity == null || gpxItem == null) {
return;
}
Highlight[] highlights = chart.getHighlighted();
LatLon location = null;
TrackChartPoints trackChartPoints = this.trackChartPoints;
if (trackChartPoints == null) {
trackChartPoints = new TrackChartPoints();
TrkSegment segment = getTrackSegment(chart);
int segmentColor = segment != null ? segment.getColor(0) : 0;
trackChartPoints.setSegmentColor(segmentColor);
trackChartPoints.setGpx(gpxItem.group.getGpx());
this.trackChartPoints = trackChartPoints;
}
float minimumVisibleXValue = chart.getLowestVisibleX();
float maximumVisibleXValue = chart.getHighestVisibleX();
if (highlights != null && highlights.length > 0) {
if (minimumVisibleXValue != 0 && maximumVisibleXValue != 0) {
if (highlights[0].getX() < minimumVisibleXValue) {
float difference = (maximumVisibleXValue - minimumVisibleXValue) * 0.1f;
gpxItem.chartHighlightPos = minimumVisibleXValue + difference;
chart.highlightValue(minimumVisibleXValue + difference, 0);
} else if (highlights[0].getX() > maximumVisibleXValue) {
float difference = (maximumVisibleXValue - minimumVisibleXValue) * 0.1f;
gpxItem.chartHighlightPos = maximumVisibleXValue - difference;
chart.highlightValue(maximumVisibleXValue - difference, 0);
} else {
gpxItem.chartHighlightPos = highlights[0].getX();
}
} else {
gpxItem.chartHighlightPos = highlights[0].getX();
}
location = getLocationAtPos(chart, gpxItem.chartHighlightPos);
if (location != null) {
trackChartPoints.setHighlightedPoint(location);
}
} else {
gpxItem.chartHighlightPos = -1;
}
if (shouldShowXAxisPoints()) {
trackChartPoints.setXAxisPoints(getXAxisPoints(chart));
}
if (gpxItem.chartPointLayer == ChartPointLayer.ROUTE) {
mapActivity.getMapLayers().getRouteLayer().setTrackChartPoints(trackChartPoints);
} else if (gpxItem.chartPointLayer == ChartPointLayer.GPX) {
mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(trackChartPoints);
} else if (gpxItem.chartPointLayer == ChartPointLayer.MEASUREMENT_TOOL) {
mapActivity.getMapLayers().getMeasurementToolLayer().setTrackChartPoints(trackChartPoints);
}
if (location != null) {
mapActivity.refreshMap();
}
if (!fitTrackOnMapForbidden && fitTrackOnMap) {
fitTrackOnMap(chart, location, forceFit);
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class TrackDetailsMenu method updateView.
private void updateView(final View parentView, boolean forceFitTrackOnMap) {
MapActivity mapActivity = getMapActivity();
GpxDisplayItem gpxItem = getGpxItem();
if (mapActivity == null || gpxItem == null) {
return;
}
final OsmandApplication app = mapActivity.getMyApplication();
final UiUtilities ic = app.getUIUtilities();
final boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
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() {
}
});
// final float minDragTriggerDist = AndroidUtils.dpToPx(app, 3);
// chart.setOnTouchListener(new BarLineChartTouchListener(chart, chart.getViewPortHandler().getMatrixTouch(), 3f) {
// private PointF touchStartPoint = new PointF();
//
// @SuppressLint("ClickableViewAccessibility")
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// switch (event.getAction() & MotionEvent.ACTION_MASK) {
// case MotionEvent.ACTION_DOWN:
// saveTouchStart(event);
// break;
// case MotionEvent.ACTION_POINTER_DOWN:
// if (event.getPointerCount() >= 2) {
// saveTouchStart(event);
// }
// break;
// case MotionEvent.ACTION_MOVE:
// if (mTouchMode == NONE && mChart.hasNoDragOffset()) {
// float touchDistance = distance(event.getX(), touchStartPoint.x, event.getY(), touchStartPoint.y);
// if (Math.abs(touchDistance) > minDragTriggerDist) {
// mTouchMode = DRAG;
// }
// }
// break;
// }
// return super.onTouch(v, event);
// }
//
// private void saveTouchStart(MotionEvent event) {
// touchStartPoint.x = event.getX();
// touchStartPoint.y = event.getY();
// }
// });
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;
}
MapActivity mapActivity = getMapActivity();
if (lastPerformedGesture != ChartGesture.NONE && mapActivity != null && mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation()) {
mapActivity.getMapViewTrackingUtilities().setMapLinkedToLocation(false);
}
}
@Override
public void onChartGestureEnd(MotionEvent me, ChartGesture lastPerformedGesture) {
GpxDisplayItem gpxItem = getGpxItem();
if (gpxItem != null) {
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, false);
}
}
}
@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);
}
}
}
});
boolean useHours = analysis.timeSpan != 0 && analysis.timeSpan / HOUR_IN_MILLIS > 0;
GpxMarkerView markerView = new GpxMarkerView(mapActivity, analysis.startTime, useHours);
GpxUiHelper.setupGPXChart(chart, markerView, 24, 16, true);
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;
boolean withoutGaps = selectedGpxFile != null && (!selectedGpxFile.isJoinSegments() && gpxItem.isGeneralTrack());
switch(gpxItem.chartTypes[i]) {
case ALTITUDE:
dataSet = GpxUiHelper.createGPXElevationDataSet(app, chart, analysis, gpxItem.chartAxisType, false, true, withoutGaps);
break;
case SPEED:
dataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart, analysis, gpxItem.chartAxisType, gpxItem.chartTypes.length > 1, true, withoutGaps);
break;
case SLOPE:
dataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart, analysis, gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true, withoutGaps);
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 && gpxItem.chartAxisType != GPXDataSetAxisType.TIMEOFDAY) {
availableTypes.add(new GPXDataSetType[] { GPXDataSetType.SLOPE });
}
}
if (analysis.hasSpeedData) {
availableTypes.add(new GPXDataSetType[] { GPXDataSetType.SPEED });
}
if (analysis.hasElevationData && gpxItem.chartAxisType != GPXDataSetAxisType.TIME && gpxItem.chartAxisType != GPXDataSetAxisType.TIMEOFDAY) {
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) {
List<PopUpMenuItem> items = new ArrayList<>();
for (GPXDataSetType[] types : availableTypes) {
String title = GPXDataSetType.getName(app, types);
Drawable icon = GPXDataSetType.getImageDrawable(app, types);
items.add(new PopUpMenuItem.Builder(app).setTitle(title).setIcon(icon).create());
}
AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
fitTrackOnMapForbidden = true;
GpxDisplayItem gpxItem = getGpxItem();
gpxItem.chartTypes = availableTypes.get(position);
update();
fitTrackOnMapForbidden = false;
}
};
new PopUpMenuHelper.Builder(v, items, nightMode).setListener(listener).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 if (gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_time_span));
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));
}
if (analysis.isTimeSpecified() && !hasSlopeChart) {
xAxis.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<PopUpMenuItem> items = new ArrayList<>();
for (GPXDataSetAxisType type : GPXDataSetAxisType.values()) {
items.add(new PopUpMenuItem.Builder(app).setTitleId(type.getStringId()).setIcon(type.getImageDrawable(app)).create());
}
new PopUpMenuHelper.Builder(v, items, nightMode).setListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
fitTrackOnMapForbidden = true;
GpxDisplayItem gpxItem = getGpxItem();
if (gpxItem != null) {
gpxItem.chartAxisType = GPXDataSetAxisType.values()[position];
gpxItem.chartHighlightPos = -1;
gpxItem.chartMatrix = null;
update();
}
fitTrackOnMapForbidden = false;
}
}).show();
}
});
xAxisArrow.setVisibility(View.VISIBLE);
} else {
xAxis.setOnClickListener(null);
xAxis.setBackgroundResource(0);
xAxisArrow.setVisibility(View.GONE);
}
refreshChart(chart, forceFitTrackOnMap);
}
Aggregations