use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class TrackDetailsMenu method updateMyLocation.
public void updateMyLocation(View mainView, Location location) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
LineChart chart = mainView.findViewById(R.id.chart);
GpxDisplayItem gpxItem = getGpxItem();
TrkSegment segment = getTrackSegment(chart);
LineData lineData = chart.getLineData();
List<ILineDataSet> ds = lineData != null ? lineData.getDataSets() : null;
if (ds != null && ds.size() > 0 && gpxItem != null && segment != null) {
RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox();
int mx = (int) tb.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
int my = (int) tb.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
int r = (int) (MAX_DISTANCE_LOCATION_PROJECTION * tb.getPixDensity());
Pair<WptPt, WptPt> points = GPXLayer.findPointsNearSegment(tb, segment.points, r, mx, my);
if (points != null) {
LatLon latLon = tb.getLatLonFromPixel(mx, my);
gpxItem.locationOnMap = GPXLayer.createProjectionPoint(points.first, points.second, latLon);
float pos;
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME || gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
pos = gpxItem.locationOnMap.time / 1000f;
} else {
double totalDistance = 0;
int index = segment.points.indexOf(points.first);
if (index != -1) {
WptPt previousPoint = null;
for (int i = 0; i < index; i++) {
WptPt currentPoint = segment.points.get(i);
if (previousPoint != null) {
totalDistance += MapUtils.getDistance(previousPoint.lat, previousPoint.lon, currentPoint.lat, currentPoint.lon);
}
previousPoint = currentPoint;
}
totalDistance += MapUtils.getDistance(gpxItem.locationOnMap.lat, gpxItem.locationOnMap.lon, points.first.lat, points.first.lon);
}
pos = (float) (totalDistance / ((OrderedLineDataSet) ds.get(0)).getDivX());
}
float lowestVisibleX = chart.getLowestVisibleX();
float highestVisibleX = chart.getHighestVisibleX();
float nextVisibleX = lowestVisibleX + (pos - gpxItem.chartHighlightPos);
float oneFourthDiff = (highestVisibleX - lowestVisibleX) / 4f;
if (pos > oneFourthDiff) {
nextVisibleX = pos - oneFourthDiff;
}
gpxItem.chartHighlightPos = pos;
chart.moveViewToX(nextVisibleX);
chart.highlightValue(gpxItem.chartHighlightPos, 0);
}
myLocation = location;
}
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class TrackDetailsMenu method onDismiss.
public void onDismiss() {
GpxDisplayItem gpxItem = getGpxItem();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (gpxItem != null && gpxItem.chartPointLayer == ChartPointLayer.GPX && gpxItem.wasHidden && gpxItem.group != null && gpxItem.group.getGpx() != null) {
mapActivity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpxItem.group.getGpx(), false, false);
}
TrackDetailsBarController toolbarController = this.toolbarController;
if (toolbarController != null) {
mapActivity.hideTopToolbar(toolbarController);
}
mapActivity.getMapLayers().getContextMenuLayer().exitGpxDetailsMode();
mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(null);
mapActivity.getMapLayers().getMapInfoLayer().setTrackChartPoints(null);
mapActivity.getMapView().setMapPositionX(0);
mapActivity.refreshMap();
}
if (hidding) {
hidding = false;
visible = false;
reset();
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class TrackDetailsMenu method getRect.
private QuadRect getRect(LineChart chart, float startPos, float endPos) {
double left = 0, right = 0;
double top = 0, bottom = 0;
LineData lineData = chart.getLineData();
List<ILineDataSet> ds = lineData != null ? lineData.getDataSets() : null;
GpxDisplayItem gpxItem = getGpxItem();
if (ds != null && ds.size() > 0 && gpxItem != null) {
TrkSegment segment = getTrackSegment(chart);
if (segment != null) {
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME || 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();
double previousSplitDistance = 0;
for (int i = 0; i < segment.points.size(); i++) {
WptPt currentPoint = segment.points.get(i);
if (i != 0) {
WptPt previousPoint = segment.points.get(i - 1);
if (currentPoint.distance < previousPoint.distance) {
previousSplitDistance += previousPoint.distance;
}
}
if (previousSplitDistance + currentPoint.distance >= startDistance && previousSplitDistance + currentPoint.distance <= endDistance) {
if (left == 0 && right == 0) {
left = currentPoint.getLongitude();
right = currentPoint.getLongitude();
top = currentPoint.getLatitude();
bottom = currentPoint.getLatitude();
} else {
left = Math.min(left, currentPoint.getLongitude());
right = Math.max(right, currentPoint.getLongitude());
top = Math.max(top, currentPoint.getLatitude());
bottom = Math.min(bottom, currentPoint.getLatitude());
}
}
}
}
}
}
return new QuadRect(left, top, right, bottom);
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class TrackDetailsMenu method onShow.
public void onShow() {
MapActivity mapActivity = getMapActivity();
GpxDisplayItem gpxItem = getGpxItem();
if (mapActivity != null && gpxItem != null) {
OsmandApplication app = mapActivity.getMyApplication();
GPXFile groupGpx = gpxItem.group.getGpx();
if (groupGpx != null && gpxItem.chartPointLayer == ChartPointLayer.GPX) {
gpxItem.wasHidden = app.getSelectedGpxHelper().getSelectedFileByPath(groupGpx.path) == null;
app.getSelectedGpxHelper().setGpxFileToDisplay(groupGpx);
}
boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
if (!portrait) {
mapActivity.getMapView().setMapPositionX(1);
} else {
TrackDetailsBarController toolbarController = new TrackDetailsBarController();
this.toolbarController = toolbarController;
if (gpxItem.group != null) {
toolbarController.setTitle(gpxItem.group.getGpxName());
} else {
toolbarController.setTitle(mapActivity.getString(R.string.rendering_category_details));
}
toolbarController.setOnBackButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.onBackPressed();
}
}
});
int navigationIconResId = AndroidUtils.getNavigationIconResId(mapActivity);
toolbarController.setBackBtnIconIds(navigationIconResId, navigationIconResId);
toolbarController.setOnCloseButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hide(false);
}
});
mapActivity.showTopToolbar(toolbarController);
}
mapActivity.refreshMap();
mapActivity.getMapLayers().getContextMenuLayer().enterGpxDetailsMode();
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class RouteDetailsFragment method createRouteStatisticCards.
private void createRouteStatisticCards(LinearLayout cardsContainer) {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return;
}
OsmandApplication app = mapActivity.getMyApplication();
statisticCard = new RouteStatisticCard(mapActivity, gpx, new OnClickListener() {
@Override
public void onClick(View v) {
openDetails();
}
});
statisticCard.setTransparentBackground(true);
statisticCard.setListener(this);
menuCards.add(statisticCard);
cardsContainer.addView(statisticCard.build(mapActivity));
buildRowDivider(cardsContainer, false);
slopeDataSet = statisticCard.getSlopeDataSet();
elevationDataSet = statisticCard.getElevationDataSet();
List<RouteSegmentResult> route = app.getRoutingHelper().getRoute().getOriginalRoute();
if (route != null) {
List<RouteStatistics> routeStatistics = calculateRouteStatistics(app, route, isNightMode());
GPXTrackAnalysis analysis = gpx.getAnalysis(0);
for (RouteStatistics statistic : routeStatistics) {
RouteInfoCard routeClassCard = new RouteInfoCard(mapActivity, statistic, analysis);
addRouteCard(cardsContainer, routeClassCard);
}
}
routeDetailsMenu = new RouteDetailsMenu();
GpxDisplayItem gpxItem = statisticCard.getGpxItem();
if (gpxItem != null) {
routeDetailsMenu.setGpxItem(gpxItem);
}
routeDetailsMenu.setMapActivity(mapActivity);
CommonChartAdapter mainGraphAdapter = statisticCard.getGraphAdapter();
if (mainGraphAdapter != null) {
ChartAdapterHelper.bindGraphAdapters(mainGraphAdapter, getRouteInfoCardsGraphAdapters(), getMainView());
refreshMapCallback = ChartAdapterHelper.bindToMap(mainGraphAdapter, mapActivity, routeDetailsMenu);
}
}
Aggregations