Search in sources :

Example 11 with GpxDisplayItem

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;
        }
    }
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) RotatedTileBox(net.osmand.data.RotatedTileBox) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) TrkSegment(net.osmand.GPXUtilities.TrkSegment) LatLon(net.osmand.data.LatLon) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) OrderedLineDataSet(net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet) LineChart(com.github.mikephil.charting.charts.LineChart) MapActivity(net.osmand.plus.activities.MapActivity)

Example 12 with GpxDisplayItem

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();
    }
}
Also used : GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) MapActivity(net.osmand.plus.activities.MapActivity)

Example 13 with GpxDisplayItem

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);
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) OrderedLineDataSet(net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet) TrkSegment(net.osmand.GPXUtilities.TrkSegment) QuadRect(net.osmand.data.QuadRect)

Example 14 with GpxDisplayItem

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();
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) GPXFile(net.osmand.GPXUtilities.GPXFile) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) TopToolbarView(net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView) GpxMarkerView(net.osmand.plus.track.GpxMarkerView) MapActivity(net.osmand.plus.activities.MapActivity)

Example 15 with GpxDisplayItem

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);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) CommonChartAdapter(net.osmand.plus.measurementtool.graph.CommonChartAdapter) ImageView(android.widget.ImageView) View(android.view.View) CollapsableView(net.osmand.plus.mapcontextmenu.CollapsableView) TextView(android.widget.TextView) RouteStatistics(net.osmand.router.RouteStatisticsHelper.RouteStatistics) OnClickListener(android.view.View.OnClickListener) RouteStatisticCard(net.osmand.plus.routepreparationmenu.cards.RouteStatisticCard) RouteSegmentResult(net.osmand.router.RouteSegmentResult) RouteInfoCard(net.osmand.plus.routepreparationmenu.cards.RouteInfoCard) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

GpxDisplayItem (net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem)35 ArrayList (java.util.ArrayList)8 GPXFile (net.osmand.GPXUtilities.GPXFile)7 TrkSegment (net.osmand.GPXUtilities.TrkSegment)7 WptPt (net.osmand.GPXUtilities.WptPt)7 LatLon (net.osmand.data.LatLon)7 MapActivity (net.osmand.plus.activities.MapActivity)7 GpxDisplayGroup (net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup)7 View (android.view.View)5 LineData (com.github.mikephil.charting.data.LineData)5 List (java.util.List)5 QuadRect (net.osmand.data.QuadRect)5 OrderedLineDataSet (net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet)5 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 Matrix (android.graphics.Matrix)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 NonNull (androidx.annotation.NonNull)3 LinkedHashMap (java.util.LinkedHashMap)3