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);
}
});
}
}
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;
}
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);
}
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;
}
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;
}
Aggregations