use of net.osmand.plus.track.helpers.GpxSelectionHelper in project Osmand by osmandapp.
the class SelectWptCategoriesBottomSheetDialogFragment method updateAddOrEnableGroupWptCategories.
private void updateAddOrEnableGroupWptCategories() {
OsmandApplication app = getMyApplication();
GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpxFile.path);
if (selectedGpxFile == null) {
gpxSelectionHelper.selectGpxFile(gpxFile, true, false, false, false, false);
}
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
if (group == null) {
group = mapMarkersHelper.addOrEnableGroup(gpxFile);
}
mapMarkersHelper.updateGroupWptCategories(group, selectedCategories);
mapMarkersHelper.runSynchronization(group);
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper 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();
}
});
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper in project Osmand by osmandapp.
the class SaveGPXBottomSheet method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
Bundle args = getArguments();
if (args != null && args.containsKey(KEY_FILE_NAME)) {
String fileName = args.getString(KEY_FILE_NAME);
savedGpxFile = new File(fileName);
initialGpxName = Algorithms.getFileNameWithoutExtension(savedGpxFile);
newGpxName = initialGpxName;
} else {
dismiss();
}
Context ctx = requireContext();
GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
int textPrimaryColor = ColorUtilities.getPrimaryTextColorId(nightMode);
View mainView = UiUtilities.getInflater(ctx, nightMode).inflate(R.layout.save_gpx_fragment, null);
if (savedInstanceState != null) {
openTrack = savedInstanceState.getBoolean(OPEN_TRACK_ATTR);
showOnMap = savedInstanceState.getBoolean(SHOW_ON_MAP_ATTR);
} else {
showOnMap = gpxSelectionHelper.getSelectedCurrentRecordingTrack() != null;
}
OsmandTextFieldBoxes textBox = mainView.findViewById(R.id.name_text_box);
if (nightMode) {
textBox.setPrimaryColor(ContextCompat.getColor(app, R.color.active_color_primary_dark));
}
int iconColor = ColorUtilities.getDefaultIconColorId(nightMode);
textBox.setClearButton(getIcon(R.drawable.ic_action_remove_circle, iconColor));
EditText nameEditText = mainView.findViewById(R.id.name_edit_text);
nameEditText.setText(initialGpxName);
nameEditText.setTextColor(ContextCompat.getColor(ctx, textPrimaryColor));
nameEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
newGpxName = s.toString();
}
@Override
public void afterTextChanged(Editable s) {
Editable text = nameEditText.getText();
if (text.length() >= 1) {
if (ILLEGAL_FILE_NAME_CHARACTERS.matcher(text).find()) {
nameEditText.setError(app.getString(R.string.file_name_containes_illegal_char));
}
}
}
});
nameEditText.setOnEditorActionListener((v, actionId, event) -> {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
finish();
return true;
}
return false;
});
nameEditText.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus) {
FragmentActivity activity = getActivity();
if (activity != null) {
nameEditText.setSelection(nameEditText.getText().length());
AndroidUtils.showSoftKeyboard(activity, nameEditText);
}
}
});
SwitchCompat showOnMapButton = mainView.findViewById(R.id.btn_show_on_map);
showOnMapButton.setChecked(showOnMap);
showOnMapButton.setOnCheckedChangeListener((buttonView, isChecked) -> showOnMap = !showOnMap);
SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder().setCustomView(mainView).create();
items.add(titleItem);
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper in project Osmand by osmandapp.
the class MapLayerMenuListener method getAlreadySelectedGpx.
@NonNull
private List<String> getAlreadySelectedGpx() {
GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper();
List<SelectedGpxFile> selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles();
List<String> files = GpxUiHelper.getSelectedTrackPaths(mapActivity.getMyApplication());
if (selectedGpxFiles.isEmpty()) {
Map<GPXFile, Long> fls = selectedGpxHelper.getSelectedGpxFilesBackUp();
for (Map.Entry<GPXFile, Long> f : fls.entrySet()) {
if (!Algorithms.isEmpty(f.getKey().path)) {
File file = new File(f.getKey().path);
if (file.exists() && !file.isDirectory()) {
files.add(f.getKey().path);
}
}
}
}
return files;
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper in project Osmand by osmandapp.
the class WptPtMenuController method getTypeStr.
@NonNull
@Override
public String getTypeStr() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
GpxSelectionHelper helper = mapActivity.getMyApplication().getSelectedGpxHelper();
SelectedGpxFile selectedGpxFile = helper.getSelectedGPXFile(wpt);
StringBuilder sb = new StringBuilder();
sb.append(mapActivity.getString(R.string.shared_string_waypoint));
sb.append(", ");
if (selectedGpxFile != null) {
File file = new File(selectedGpxFile.getGpxFile().path);
String gpxName = file.getName().replace(IndexConstants.GPX_FILE_EXT, "").replace("/", " ").replace("_", " ");
sb.append(gpxName);
}
return sb.toString();
} else {
return "";
}
}
Aggregations