Search in sources :

Example 6 with SelectedGpxFile

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

the class DashTrackFragment method setupGpxFiles.

private void setupGpxFiles() {
    View mainView = getView();
    final File dir = getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
    final OsmandApplication app = getMyApplication();
    if (app == null) {
        return;
    }
    final List<String> list = new ArrayList<String>();
    for (SelectedGpxFile sg : app.getSelectedGpxHelper().getSelectedGPXFiles()) {
        if (!sg.isShowCurrentTrack()) {
            GPXFile gpxFile = sg.getGpxFile();
            if (gpxFile != null) {
                list.add(gpxFile.path);
            }
        }
    }
    // 10 is the maximum length of the list. The actual length is determined later by
    // DashboardOnMap.handleNumberOfRows()
    int totalCount = 10;
    if (app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) {
        totalCount--;
    }
    if (list.size() < totalCount) {
        final List<GPXInfo> res = GpxUiHelper.getSortedGPXFilesInfoByDate(dir, true);
        for (GPXInfo r : res) {
            String name = r.getFileName();
            if (!list.contains(name)) {
                list.add(name);
                if (list.size() >= totalCount) {
                    break;
                }
            }
        }
    }
    if (list.size() == 0 && !OsmandPlugin.isActive(OsmandMonitoringPlugin.class)) {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
        return;
    } else {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
        DashboardOnMap.handleNumberOfRows(list, getMyApplication().getSettings(), ROW_NUMBER_TAG);
    }
    LinearLayout tracks = (LinearLayout) mainView.findViewById(R.id.items);
    tracks.removeAllViews();
    LayoutInflater inflater = getActivity().getLayoutInflater();
    if (OsmandPlugin.isActive(OsmandMonitoringPlugin.class)) {
        View view = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
        createCurrentTrackView(view);
        ((TextView) view.findViewById(R.id.name)).setText(R.string.shared_string_currently_recording_track);
        updateCurrentTrack(view, getActivity(), app);
        view.setOnClickListener(v -> openGpxContextMenu(null));
        view.findViewById(R.id.divider_dash).setVisibility(View.VISIBLE);
        tracks.addView(view);
        startHandler(view);
    }
    for (String filename : list) {
        File file = new File(filename);
        AvailableGPXFragment.GpxInfo info = new AvailableGPXFragment.GpxInfo();
        info.subfolder = "";
        info.file = file;
        View itemView = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
        AvailableGPXFragment.updateGpxInfoView(itemView, info, app, true, null);
        itemView.setOnClickListener(v -> openGpxContextMenu(file));
        ImageButton showOnMap = itemView.findViewById(R.id.show_on_map);
        showOnMap.setVisibility(View.VISIBLE);
        showOnMap.setContentDescription(getString(R.string.shared_string_show_on_map));
        updateShowOnMap(app, file, itemView, showOnMap);
        tracks.addView(itemView);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) GPXInfo(net.osmand.plus.helpers.GpxUiHelper.GPXInfo) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ImageButton(android.widget.ImageButton) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) LinearLayout(android.widget.LinearLayout) AvailableGPXFragment(net.osmand.plus.myplaces.ui.AvailableGPXFragment)

Example 7 with SelectedGpxFile

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

the class DashTrackFragment method updateShowOnMap.

private void updateShowOnMap(final OsmandApplication app, final File f, final View pView, final ImageButton showOnMap) {
    final GpxSelectionHelper selectedGpxHelper = app.getSelectedGpxHelper();
    final SelectedGpxFile selected = selectedGpxHelper.getSelectedFileByPath(f.getAbsolutePath());
    if (selected != null) {
        showOnMap.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_show_on_map, R.color.color_distance));
        showOnMap.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                selectedGpxHelper.selectGpxFile(selected.getGpxFile(), false, false);
                AvailableGPXFragment.GpxInfo info = new AvailableGPXFragment.GpxInfo();
                info.subfolder = "";
                info.file = f;
                AvailableGPXFragment.updateGpxInfoView(pView, info, app, true, null);
                updateShowOnMap(app, f, v, showOnMap);
            }
        });
    } else {
        showOnMap.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_show_on_map));
        showOnMap.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Runnable run = new Runnable() {

                    @Override
                    public void run() {
                        showOnMap(GPXUtilities.loadGPXFile(f));
                    }
                };
                run.run();
            }
        });
    }
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AvailableGPXFragment(net.osmand.plus.myplaces.ui.AvailableGPXFragment)

Example 8 with SelectedGpxFile

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

the class TrackAppearanceFragment method saveCustomColorsToTracks.

private void saveCustomColorsToTracks(int prevColor, int newColor) {
    List<GpxDataItem> gpxDataItems = gpxDbHelper.getItems();
    for (GpxDataItem dataItem : gpxDataItems) {
        if (prevColor == dataItem.getColor()) {
            gpxDbHelper.updateColor(dataItem, newColor);
        }
    }
    List<SelectedGpxFile> files = app.getSelectedGpxHelper().getSelectedGPXFiles();
    for (SelectedGpxFile selectedGpxFile : files) {
        if (prevColor == selectedGpxFile.getGpxFile().getColor(0)) {
            selectedGpxFile.getGpxFile().setColor(newColor);
        }
    }
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem)

Example 9 with SelectedGpxFile

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

the class TrackDisplayHelper method updateDisplayGroups.

public void updateDisplayGroups() {
    modifiedTime = gpxFile.modifiedTime;
    GpxSelectionHelper selectedGpxHelper = app.getSelectedGpxHelper();
    displayGroups = filteredGpxFile != null ? selectedGpxHelper.collectDisplayGroups(filteredGpxFile) : selectedGpxHelper.collectDisplayGroups(gpxFile);
    originalGroups.clear();
    for (GpxDisplayGroup g : displayGroups) {
        originalGroups.add(g.cloneInstance());
    }
    if (file != null) {
        SelectedGpxFile sf = selectedGpxHelper.getSelectedFileByPath(gpxFile.path);
        if (sf != null && file != null && sf.getDisplayGroups(app) != null) {
            displayGroups = sf.getDisplayGroups(app);
        }
    }
}
Also used : GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)

Example 10 with SelectedGpxFile

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

the class TrackDisplayHelper method setJoinSegments.

public boolean setJoinSegments(boolean joinSegments) {
    if (gpxDataItem != null) {
        boolean updated = app.getGpxDbHelper().updateJoinSegments(gpxDataItem, joinSegments);
        SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
        if (updated && selectedGpxFile != null) {
            selectedGpxFile.setJoinSegments(joinSegments);
        }
        return updated;
    }
    return false;
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)

Aggregations

SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)66 GPXFile (net.osmand.GPXUtilities.GPXFile)36 File (java.io.File)26 MapActivity (net.osmand.plus.activities.MapActivity)18 OsmandApplication (net.osmand.plus.OsmandApplication)17 ArrayList (java.util.ArrayList)13 WptPt (net.osmand.GPXUtilities.WptPt)12 GpxSelectionHelper (net.osmand.plus.track.helpers.GpxSelectionHelper)12 GpxDataItem (net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem)9 View (android.view.View)8 ImageView (android.widget.ImageView)8 TextView (android.widget.TextView)8 LatLon (net.osmand.data.LatLon)8 SelectedGpxPoint (net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint)6 NonNull (androidx.annotation.NonNull)5 Paint (android.graphics.Paint)4 CallbackWithObject (net.osmand.CallbackWithObject)4 MapMarker (net.osmand.plus.mapmarkers.MapMarker)4 GpxDisplayGroup (net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup)4 DialogInterface (android.content.DialogInterface)3