Search in sources :

Example 26 with GpxDisplayItem

use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.

the class SplitSegmentDialogFragment method collectDisplayItemsFromGroup.

private List<GpxDisplayItem> collectDisplayItemsFromGroup(GpxDisplayGroup group) {
    List<GpxDisplayItem> splitSegments = new ArrayList<>();
    boolean generalTrack = gpxItem.isGeneralTrack();
    boolean generalGroup = group.isGeneralTrack();
    if ((group.isSplitDistance() || group.isSplitTime()) && (!generalGroup && !generalTrack || generalGroup && generalTrack)) {
        boolean itemsForSelectedSegment = false;
        for (GpxDisplayItem item : group.getModifiableList()) {
            itemsForSelectedSegment = trkSegment.points.get(0).equals(item.locationStart) || itemsForSelectedSegment;
            if (itemsForSelectedSegment) {
                splitSegments.add(item);
            }
            if (trkSegment.points.get(trkSegment.points.size() - 1).equals(item.locationEnd)) {
                break;
            }
        }
    }
    return splitSegments;
}
Also used : GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList)

Example 27 with GpxDisplayItem

use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.

the class EditTrackGroupDialogFragment method deleteGroupItems.

private void deleteGroupItems() {
    Set<GpxDisplayItem> items = new HashSet<>(group.getModifiableList());
    new DeletePointsTask(app, group.getGpx(), items, this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : DeletePointsTask(net.osmand.plus.myplaces.DeletePointsTask) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) HashSet(java.util.HashSet)

Example 28 with GpxDisplayItem

use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.

the class SegmentGPXAdapter method getView.

@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
    View row = convertView;
    boolean create = false;
    if (row == null) {
        create = true;
        row = createGpxTabsView(parent, nightMode);
    }
    GpxDisplayItem item = getItem(position);
    if (item != null) {
        WrapContentHeightViewPager pager = row.findViewById(R.id.pager);
        PagerSlidingTabStrip tabLayout = row.findViewById(R.id.sliding_tabs);
        pager.setAdapter(new GPXItemPagerAdapter(app, item, displayHelper, nightMode, listener, false, false));
        if (create) {
            tabLayout.setViewPager(pager);
        } else {
            tabLayout.notifyDataSetChanged(true);
        }
    }
    return row;
}
Also used : PagerSlidingTabStrip(net.osmand.plus.views.controls.PagerSlidingTabStrip) WrapContentHeightViewPager(net.osmand.plus.views.controls.WrapContentHeightViewPager) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) View(android.view.View) NonNull(androidx.annotation.NonNull)

Example 29 with GpxDisplayItem

use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.

the class GPXLayer method drawSplitItems.

private void drawSplitItems(Canvas canvas, RotatedTileBox tileBox, List<GpxDisplayItem> items, DrawSettings settings) {
    final QuadRect latLonBounds = tileBox.getLatLonBounds();
    int r = (int) (12 * tileBox.getDensity());
    paintTextIcon.setTextSize(r);
    int dr = r * 3 / 2;
    float px = -1;
    float py = -1;
    for (int k = 0; k < items.size(); k++) {
        GpxDisplayItem i = items.get(k);
        WptPt point = i.locationEnd;
        if (point != null && point.lat >= latLonBounds.bottom && point.lat <= latLonBounds.top && point.lon >= latLonBounds.left && point.lon <= latLonBounds.right) {
            float x = tileBox.getPixXFromLatLon(point.lat, point.lon);
            float y = tileBox.getPixYFromLatLon(point.lat, point.lon);
            if (px != -1 || py != -1) {
                if (Math.abs(x - px) <= dr && Math.abs(y - py) <= dr) {
                    continue;
                }
            }
            px = x;
            py = y;
            String name = i.splitName;
            if (name != null) {
                int ind = name.indexOf(' ');
                if (ind > 0) {
                    name = name.substring(0, ind);
                }
                Rect bounds = new Rect();
                paintTextIcon.getTextBounds(name, 0, name.length(), bounds);
                float nameHalfWidth = bounds.width() / 2f;
                float nameHalfHeight = bounds.height() / 2f;
                float density = (float) Math.ceil(tileBox.getDensity());
                RectF rect = new RectF(x - nameHalfWidth - 2 * density, y + nameHalfHeight + 3 * density, x + nameHalfWidth + 3 * density, y - nameHalfHeight - 2 * density);
                canvas.drawRoundRect(rect, 0, 0, paintInnerRect);
                canvas.drawRoundRect(rect, 0, 0, paintOuterRect);
                canvas.drawText(name, x, y + nameHalfHeight, paintTextIcon);
            }
        }
    }
}
Also used : RectF(android.graphics.RectF) WptPt(net.osmand.GPXUtilities.WptPt) Rect(android.graphics.Rect) QuadRect(net.osmand.data.QuadRect) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint) SelectedGpxPoint(net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint)

Example 30 with GpxDisplayItem

use of net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.

the class MapActivity method readLocationToShow.

public void readLocationToShow() {
    showMapControls();
    OsmandMapTileView mapView = getMapView();
    LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude());
    LatLon latLonToShow = settings.getAndClearMapLocationToShow();
    PointDescription mapLabelToShow = settings.getAndClearMapLabelToShow(latLonToShow);
    Object toShow = settings.getAndClearObjectToShow();
    boolean editToShow = settings.getAndClearEditObjectToShow();
    int status = settings.isRouteToPointNavigateAndClear();
    String searchRequestToShow = settings.getAndClearSearchRequestToShow();
    if (status != 0 || searchRequestToShow != null || latLonToShow != null) {
        dismissSettingsScreens();
    }
    if (status != 0) {
        // always enable and follow and let calculate it (i.e.GPS is not accessible in a garage)
        Location loc = new Location("map");
        loc.setLatitude(mapView.getLatitude());
        loc.setLongitude(mapView.getLongitude());
        getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true, true);
        if (dashboardOnMap.isVisible()) {
            dashboardOnMap.hideDashboard();
        }
    }
    if (trackDetailsMenu.isVisible()) {
        trackDetailsMenu.show();
    }
    if (searchRequestToShow != null) {
        showQuickSearch(searchRequestToShow);
    }
    if (latLonToShow != null) {
        if (dashboardOnMap.isVisible()) {
            dashboardOnMap.hideDashboard();
        }
        // remember if map should come back to isMapLinkedToLocation=true
        getMapViewTrackingUtilities().setMapLinkedToLocation(false);
        if (mapLabelToShow != null && !mapLabelToShow.contextMenuDisabled()) {
            mapContextMenu.setMapCenter(latLonToShow);
            mapContextMenu.setMapPosition(mapView.getMapPosition());
            mapContextMenu.setCenterMarker(true);
            RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
            LatLon prevCenter = tb.getCenterLatLon();
            double border = 0.8;
            int tbw = (int) (tb.getPixWidth() * border);
            int tbh = (int) (tb.getPixHeight() * border);
            tb.setPixelDimensions(tbw, tbh);
            tb.setLatLonCenter(latLonToShow.getLatitude(), latLonToShow.getLongitude());
            tb.setZoom(ZOOM_LABEL_DISPLAY);
            while (!tb.containsLatLon(prevCenter.getLatitude(), prevCenter.getLongitude()) && tb.getZoom() > MIN_ZOOM_LABEL_DISPLAY) {
                tb.setZoom(tb.getZoom() - 1);
            }
            // mapContextMenu.setMapZoom(settings.getMapZoomToShow());
            mapContextMenu.setMapZoom(tb.getZoom());
            if (toShow instanceof GpxDisplayItem) {
                trackDetailsMenu.setGpxItem((GpxDisplayItem) toShow);
                trackDetailsMenu.show();
            } else if (mapRouteInfoMenu.isVisible()) {
                mapContextMenu.showMinimized(latLonToShow, mapLabelToShow, toShow);
                mapRouteInfoMenu.updateMenu();
                MapRouteInfoMenu.showLocationOnMap(this, latLonToShow.getLatitude(), latLonToShow.getLongitude());
            } else if (toShow instanceof GPXFile) {
                hideContextAndRouteInfoMenues();
                GPXFile gpxFile = (GPXFile) toShow;
                SelectedGpxFile selectedGpxFile;
                if (gpxFile.showCurrentTrack) {
                    selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
                } else {
                    selectedGpxFile = app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false, false, false, false);
                }
                TrackAppearanceFragment.showInstance(this, selectedGpxFile, null);
            } else if (toShow instanceof QuadRect) {
                QuadRect qr = (QuadRect) toShow;
                mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
            } else if (toShow instanceof NewGpxPoint) {
                NewGpxPoint newGpxPoint = (NewGpxPoint) toShow;
                QuadRect qr = newGpxPoint.getRect();
                mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
                getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint);
            } else if (toShow instanceof GpxData) {
                hideContextAndRouteInfoMenues();
                GpxData gpxData = (GpxData) toShow;
                QuadRect qr = gpxData.getRect();
                mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
                MeasurementEditingContext editingContext = new MeasurementEditingContext(app);
                editingContext.setGpxData(gpxData);
                MeasurementToolFragment.showInstance(getSupportFragmentManager(), editingContext);
            } else {
                mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
            }
            if (editToShow) {
                mapContextMenu.openEditor();
            }
        } else if (!latLonToShow.equals(cur)) {
            mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(), latLonToShow.getLongitude(), settings.getMapZoomToShow(), true);
        }
    }
}
Also used : MeasurementEditingContext(net.osmand.plus.measurementtool.MeasurementEditingContext) RotatedTileBox(net.osmand.data.RotatedTileBox) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) QuadRect(net.osmand.data.QuadRect) GpxData(net.osmand.plus.measurementtool.GpxData) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) LatLon(net.osmand.data.LatLon) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) PointDescription(net.osmand.data.PointDescription) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) GPXFile(net.osmand.GPXUtilities.GPXFile) Location(net.osmand.Location)

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