Search in sources :

Example 21 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class TrackBitmapDrawer method refreshTrackBitmap.

public void refreshTrackBitmap() {
    currentTrackColor = app.getSettings().CURRENT_TRACK_COLOR.get();
    if (mapBitmap != null && isDrawEnabled()) {
        SelectedGpxFile sf;
        GPXFile gpxFile = getGpx();
        if (gpxFile != null) {
            if (gpxFile.showCurrentTrack) {
                sf = app.getSavingTrackHelper().getCurrentTrack();
            } else {
                sf = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
                if (sf == null) {
                    sf = new SelectedGpxFile();
                    GpxDataItem gpxDataItem = getGpxDataItem();
                    if (gpxDataItem != null) {
                        sf.setJoinSegments(gpxDataItem.isJoinSegments());
                    }
                }
                sf.setGpxFile(gpxFile, app);
            }
            Bitmap bmp = mapBitmap.copy(mapBitmap.getConfig(), true);
            Canvas canvas = new Canvas(bmp);
            drawTrack(canvas, rotatedTileBox, sf);
            drawPoints(canvas, rotatedTileBox, sf);
            mapTrackBitmap = bmp;
            Bitmap selectedPointBitmap = drawSelectedPoint();
            for (TrackBitmapDrawerListener l : listeners) {
                if (selectedPointBitmap != null && l.isTrackBitmapSelectionSupported()) {
                    l.drawTrackBitmap(selectedPointBitmap);
                } else {
                    l.drawTrackBitmap(mapTrackBitmap);
                }
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) Canvas(android.graphics.Canvas) GPXFile(net.osmand.GPXUtilities.GPXFile)

Example 22 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class TrackEditCard method updateContent.

@Override
protected void updateContent() {
    String fileName = null;
    File file = null;
    if (!Algorithms.isEmpty(gpxFile.path)) {
        file = new File(gpxFile.path);
        fileName = gpxFile.path;
    } else if (!Algorithms.isEmpty(gpxFile.tracks)) {
        fileName = gpxFile.tracks.get(0).name;
    }
    if (Algorithms.isEmpty(fileName)) {
        fileName = app.getString(R.string.shared_string_gpx_track);
    }
    GPXInfo gpxInfo = new GPXInfo(fileName, file != null ? file.lastModified() : 0, file != null ? file.length() : 0);
    GPXTrackAnalysis analysis = null;
    if (file != null) {
        GpxDataItem dataItem = getDataItem(gpxInfo);
        if (dataItem != null) {
            analysis = dataItem.getAnalysis();
        }
    } else {
        analysis = gpxFile.getAnalysis(0);
    }
    String title = GpxUiHelper.getGpxTitle(Algorithms.getFileWithoutDirs(fileName));
    GPXRouteParamsBuilder routeParams = app.getRoutingHelper().getCurrentGPXRoute();
    if (gpxFile.getNonEmptySegmentsCount() > 1 && routeParams != null && routeParams.getSelectedSegment() != -1) {
        int selectedSegmentCount = routeParams.getSelectedSegment() + 1;
        int totalSegmentCount = routeParams.getFile().getNonEmptyTrkSegments(false).size();
        title = app.getString(R.string.of, selectedSegmentCount, totalSegmentCount) + ", " + title;
    }
    GpxUiHelper.updateGpxInfoView(view, title, gpxInfo, analysis, app);
    if (gpxFile.getNonEmptySegmentsCount() > 1 && routeParams != null && routeParams.getSelectedSegment() != -1 && gpxFile.getNonEmptySegmentsCount() > routeParams.getSelectedSegment()) {
        TextView distanceView = view.findViewById(R.id.distance);
        TextView timeView = view.findViewById(R.id.time);
        ImageView timeIcon = view.findViewById(R.id.time_icon);
        AndroidUiHelper.updateVisibility(view.findViewById(R.id.points_icon), false);
        AndroidUiHelper.updateVisibility(view.findViewById(R.id.points_count), false);
        List<GPXUtilities.TrkSegment> segments = gpxFile.getNonEmptyTrkSegments(false);
        GPXUtilities.TrkSegment segment = segments.get(routeParams.getSelectedSegment());
        double distance = TrackSelectSegmentAdapter.getDistance(segment);
        long time = TrackSelectSegmentAdapter.getSegmentTime(segment);
        boolean timeAvailable = time != 1;
        if (timeAvailable) {
            timeView.setText(Algorithms.formatDuration((int) (time / 1000), app.accessibilityEnabled()));
        }
        AndroidUiHelper.updateVisibility(timeView, timeAvailable);
        AndroidUiHelper.updateVisibility(timeIcon, timeAvailable);
        distanceView.setText(OsmAndFormatter.getFormattedDistance((float) distance, app));
    }
    ImageButton editButton = view.findViewById(R.id.show_on_map);
    editButton.setVisibility(View.VISIBLE);
    editButton.setImageDrawable(getContentIcon(R.drawable.ic_action_edit_dark));
    editButton.setOnClickListener(v -> notifyCardPressed());
    int minCardHeight = getDimen(R.dimen.setting_list_item_large_height);
    int listContentPadding = getDimen(R.dimen.list_content_padding);
    LinearLayout container = view.findViewById(R.id.container);
    container.setMinimumHeight(minCardHeight);
    AndroidUtils.setPadding(container, listContentPadding, 0, 0, 0);
    int activeColor = getActiveColor();
    int bgColor = ColorUtilities.getColorWithAlpha(activeColor, 0.1f);
    view.setBackgroundDrawable(new ColorDrawable(bgColor));
}
Also used : GPXInfo(net.osmand.plus.helpers.GpxUiHelper.GPXInfo) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) GPXUtilities(net.osmand.GPXUtilities) ImageButton(android.widget.ImageButton) ColorDrawable(android.graphics.drawable.ColorDrawable) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) TextView(android.widget.TextView) ImageView(android.widget.ImageView) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) LinearLayout(android.widget.LinearLayout)

Example 23 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class ExportItemsBottomSheet method getTrackDescr.

private String getTrackDescr(@NonNull File file, long lastModified, long size, GpxAppearanceInfo appearanceInfo) {
    String folder = "";
    File parent = file.getParentFile();
    if (parent != null) {
        folder = Algorithms.capitalizeFirstLetter(parent.getName());
    }
    if (exportMode) {
        GpxDataItem dataItem = getDataItem(file, gpxDataItemCallback);
        if (dataItem != null) {
            return getTrackDescrForDataItem(dataItem);
        }
    } else if (appearanceInfo != null) {
        String dist = OsmAndFormatter.getFormattedDistance(appearanceInfo.totalDistance, app);
        String points = appearanceInfo.wptPoints + " " + getString(R.string.shared_string_gpx_points).toLowerCase();
        String descr = getString(R.string.ltr_or_rtl_combine_via_bold_point, folder, dist);
        return getString(R.string.ltr_or_rtl_combine_via_comma, descr, points);
    } else {
        String date = OsmAndFormatter.getFormattedDate(app, lastModified);
        String formattedSize = AndroidUtils.formatSize(app, size);
        String descr = getString(R.string.ltr_or_rtl_combine_via_bold_point, folder, date);
        return getString(R.string.ltr_or_rtl_combine_via_comma, descr, formattedSize);
    }
    return null;
}
Also used : GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) File(java.io.File)

Example 24 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class GPXLayer method getAvailableOrDefaultColoringType.

private String getAvailableOrDefaultColoringType(SelectedGpxFile selectedGpxFile) {
    GPXFile gpxFile = selectedGpxFile.getGpxFileToDisplay();
    if (hasTrackDrawInfoForTrack(gpxFile)) {
        return trackDrawInfo.getColoringType().getName(trackDrawInfo.getRouteInfoAttribute());
    }
    GpxDataItem dataItem = null;
    String defaultColoringType = ColoringType.TRACK_SOLID.getName(null);
    ColoringType coloringType = null;
    String routeInfoAttribute = null;
    boolean isCurrentTrack = gpxFile.showCurrentTrack;
    if (isCurrentTrack) {
        coloringType = currentTrackColoringTypePref.get();
        routeInfoAttribute = currentTrackRouteInfoAttributePref.get();
    } else {
        dataItem = gpxDbHelper.getItem(new File(gpxFile.path));
        if (dataItem != null) {
            coloringType = ColoringType.getNonNullTrackColoringTypeByName(dataItem.getColoringType());
            routeInfoAttribute = ColoringType.getRouteInfoAttribute(dataItem.getColoringType());
        }
    }
    if (coloringType == null) {
        return defaultColoringType;
    } else if (!coloringType.isAvailableInSubscription(view.getApplication(), routeInfoAttribute, false)) {
        return defaultColoringType;
    } else if (getCachedTrack(selectedGpxFile).isColoringTypeAvailable(coloringType, routeInfoAttribute)) {
        return coloringType.getName(routeInfoAttribute);
    } else {
        if (!isCurrentTrack) {
            gpxDbHelper.updateColoringType(dataItem, defaultColoringType);
        }
        return defaultColoringType;
    }
}
Also used : ColoringType(net.osmand.plus.routing.ColoringType) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File)

Example 25 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class GpxSelectionHelper method processSplit.

public static boolean processSplit(@Nullable OsmandApplication app, @Nullable SelectedGpxFile fileToProcess) {
    if (app == null || app.isApplicationInitializing()) {
        return false;
    }
    List<GpxDataItem> items = app.getGpxDbHelper().getSplitItems();
    for (GpxDataItem dataItem : items) {
        String path = dataItem.getFile().getAbsolutePath();
        SelectedGpxFile selectedGpxFile;
        GPXFile gpxFileToProcess = fileToProcess == null ? null : fileToProcess.getGpxFile();
        if (gpxFileToProcess != null && path.equals(gpxFileToProcess.path)) {
            selectedGpxFile = fileToProcess;
        } else {
            selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(path);
        }
        if (selectedGpxFile == null || fileToProcess != null && !fileToProcess.equals(selectedGpxFile)) {
            continue;
        }
        if (selectedGpxFile.getGpxFile() != null) {
            GPXFile gpxFile = selectedGpxFile.getGpxFile();
            List<GpxDisplayGroup> displayGroups = processSplit(app, dataItem, gpxFile);
            selectedGpxFile.setDisplayGroups(displayGroups, app);
        }
    }
    return fileToProcess == null || fileToProcess.splitProcessed;
}
Also used : GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) GPXFile(net.osmand.GPXUtilities.GPXFile)

Aggregations

GpxDataItem (net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem)28 File (java.io.File)18 GPXFile (net.osmand.GPXUtilities.GPXFile)18 SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)16 GPXTrackAnalysis (net.osmand.GPXUtilities.GPXTrackAnalysis)8 GpxDataItemCallback (net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback)6 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 View (android.view.View)4 AGpxFile (net.osmand.aidl.gpx.AGpxFile)4 ASelectedGpxFile (net.osmand.aidl.gpx.ASelectedGpxFile)4 ASqliteDbFile (net.osmand.aidl.tiles.ASqliteDbFile)4 SuppressLint (android.annotation.SuppressLint)3 ArrayList (java.util.ArrayList)3 OsmandApplication (net.osmand.plus.OsmandApplication)3 Bundle (android.os.Bundle)2 SpannableString (android.text.SpannableString)2 LinearLayout (android.widget.LinearLayout)2 Nullable (androidx.annotation.Nullable)2 List (java.util.List)2