Search in sources :

Example 16 with GpxSelectionHelper

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

the class TripRecordingBottomSheet method createShowTrackItem.

public static void createShowTrackItem(LinearLayout showTrackContainer, AppCompatImageView trackAppearanceIcon, Integer showTrackId, final Fragment target, final boolean nightMode, final Runnable hideOnClickButtonAppearance) {
    FragmentActivity activity = target.getActivity();
    if (activity == null) {
        AndroidUiHelper.updateVisibility(showTrackContainer, false);
        return;
    }
    final OsmandApplication app = (OsmandApplication) activity.getApplication();
    final GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
    final CardView buttonShowTrack = showTrackContainer.findViewById(R.id.compound_container);
    final CardView buttonAppearance = showTrackContainer.findViewById(R.id.additional_button_container);
    TextView showTrackTextView = buttonShowTrack.findViewById(R.id.title);
    if (showTrackId != null) {
        showTrackTextView.setText(showTrackId);
    }
    SelectedGpxFile selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
    boolean showCurrentTrack = gpxSelectionHelper.getSelectedCurrentRecordingTrack() != null;
    final CompoundButton showTrackCompound = buttonShowTrack.findViewById(R.id.compound_button);
    showTrackCompound.setChecked(showCurrentTrack);
    UiUtilities.setupCompoundButton(showTrackCompound, nightMode, GLOBAL);
    setShowTrackItemBackground(buttonShowTrack, showTrackCompound.isChecked(), nightMode);
    buttonShowTrack.setOnClickListener(v -> {
        boolean checked = !showTrackCompound.isChecked();
        showTrackCompound.setChecked(checked);
        gpxSelectionHelper.selectGpxFile(selectedGpxFile.getGpxFile(), checked, false);
        setShowTrackItemBackground(buttonShowTrack, checked, nightMode);
        createItem(app, nightMode, buttonAppearance, ItemType.APPEARANCE, checked, null);
    });
    updateTrackIcon(app, trackAppearanceIcon);
    createItem(app, nightMode, buttonAppearance, ItemType.APPEARANCE, showTrackCompound.isChecked(), null);
    if (activity instanceof MapActivity) {
        buttonAppearance.setOnClickListener(v -> {
            if (showTrackCompound.isChecked()) {
                hideOnClickButtonAppearance.run();
                TrackAppearanceFragment.showInstance((MapActivity) activity, selectedGpxFile, target);
            }
        });
    }
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) OsmandApplication(net.osmand.plus.OsmandApplication) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) CompoundButton(android.widget.CompoundButton) MapActivity(net.osmand.plus.activities.MapActivity)

Example 17 with GpxSelectionHelper

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

the class GpxUiHelper method makeGpxDisplayItem.

public static GpxDisplayItem makeGpxDisplayItem(@NonNull OsmandApplication app, @NonNull GPXFile gpxFile, @NonNull ChartPointLayer chartPointLayer) {
    GpxDisplayGroup group = null;
    if (!Algorithms.isEmpty(gpxFile.tracks)) {
        GpxSelectionHelper helper = app.getSelectedGpxHelper();
        String groupName = helper.getGroupName(gpxFile);
        group = helper.buildGpxDisplayGroup(gpxFile, 0, groupName);
    }
    if (group != null && group.getModifiableList().size() > 0) {
        GpxDisplayItem gpxItem = group.getModifiableList().get(0);
        if (gpxItem != null) {
            gpxItem.chartPointLayer = chartPointLayer;
        }
        return gpxItem;
    }
    return null;
}
Also used : GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) SpannableString(android.text.SpannableString)

Example 18 with GpxSelectionHelper

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

the class ExternalApiHelper method saveAndNavigateGpx.

public static void saveAndNavigateGpx(MapActivity mapActivity, final GPXFile gpxFile, final boolean force, final boolean checkLocationPermission) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    if (Algorithms.isEmpty(gpxFile.path)) {
        OsmandApplication app = mapActivity.getMyApplication();
        String destFileName = "route" + IndexConstants.GPX_FILE_EXT;
        File destDir = app.getAppPath(IndexConstants.GPX_IMPORT_DIR);
        File destFile = app.getAppPath(IndexConstants.GPX_IMPORT_DIR + destFileName);
        while (destFile.exists()) {
            destFileName = AndroidUtils.createNewFileName(destFileName);
            destFile = new File(destDir, destFileName);
        }
        gpxFile.path = destFile.getAbsolutePath();
    }
    new SaveGpxAsyncTask(new File(gpxFile.path), gpxFile, new SaveGpxListener() {

        @Override
        public void gpxSavingStarted() {
        }

        @Override
        public void gpxSavingFinished(Exception errorMessage) {
            MapActivity mapActivity = mapActivityRef.get();
            if (errorMessage == null && mapActivity != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) {
                OsmandApplication app = mapActivity.getMyApplication();
                GpxSelectionHelper helper = app.getSelectedGpxHelper();
                SelectedGpxFile selectedGpx = helper.getSelectedFileByPath(gpxFile.path);
                if (selectedGpx != null) {
                    selectedGpx.setGpxFile(gpxFile, app);
                } else {
                    helper.selectGpxFile(gpxFile, true, false);
                }
                final RoutingHelper routingHelper = app.getRoutingHelper();
                if (routingHelper.isFollowingMode() && !force) {
                    mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            MapActivity mapActivity = mapActivityRef.get();
                            if (mapActivity != null && !routingHelper.isFollowingMode()) {
                                ExternalApiHelper.startNavigation(mapActivity, gpxFile, checkLocationPermission);
                            }
                        }
                    });
                } else {
                    startNavigation(mapActivity, gpxFile, checkLocationPermission);
                }
            }
        }
    }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) SaveGpxListener(net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener) DialogInterface(android.content.DialogInterface) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) RoutingHelper(net.osmand.plus.routing.RoutingHelper) SaveGpxAsyncTask(net.osmand.plus.track.SaveGpxAsyncTask) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) WeakReference(java.lang.ref.WeakReference) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) MapActivity(net.osmand.plus.activities.MapActivity)

Example 19 with GpxSelectionHelper

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

the class FileUtils method renameGpxFile.

public static File renameGpxFile(@NonNull OsmandApplication app, @NonNull File src, @NonNull File dest) {
    if (!dest.getParentFile().exists()) {
        dest.getParentFile().mkdirs();
    }
    if (src.renameTo(dest)) {
        GpxSelectionHelper helper = app.getSelectedGpxHelper();
        SelectedGpxFile selected = helper.getSelectedFileByPath(src.getAbsolutePath());
        app.getGpxDbHelper().rename(src, dest);
        app.getQuickActionRegistry().onRenameGpxFile(src.getAbsolutePath(), dest.getAbsolutePath());
        if (selected != null && selected.getGpxFile() != null) {
            selected.resetSplitProcessed();
            selected.getGpxFile().path = dest.getAbsolutePath();
            helper.updateSelectedGpxFile(selected);
        }
        return dest;
    }
    return null;
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper)

Example 20 with GpxSelectionHelper

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

the class FileUtils method removeGpxFile.

public static boolean removeGpxFile(@NonNull OsmandApplication app, @NonNull File file) {
    if (file.exists()) {
        GpxSelectionHelper helper = app.getSelectedGpxHelper();
        SelectedGpxFile selected = helper.getSelectedFileByPath(file.getAbsolutePath());
        file.delete();
        app.getGpxDbHelper().remove(file);
        if (selected != null && selected.getGpxFile() != null) {
            helper.selectGpxFile(selected.getGpxFile(), false, false);
        }
        return true;
    }
    return false;
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper)

Aggregations

GpxSelectionHelper (net.osmand.plus.track.helpers.GpxSelectionHelper)20 SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)12 File (java.io.File)9 GPXFile (net.osmand.GPXUtilities.GPXFile)8 WptPt (net.osmand.GPXUtilities.WptPt)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 MapActivity (net.osmand.plus.activities.MapActivity)3 SavingTrackHelper (net.osmand.plus.track.helpers.SavingTrackHelper)3 Bundle (android.os.Bundle)2 View (android.view.View)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 FavouritePoint (net.osmand.data.FavouritePoint)2 GpxDataItem (net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 AsyncTask (android.os.AsyncTask)1 Editable (android.text.Editable)1