Search in sources :

Example 1 with GpxSelectionHelper

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);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper)

Example 2 with GpxSelectionHelper

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();
            }
        });
    }
}
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 3 with GpxSelectionHelper

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);
}
Also used : Context(android.content.Context) EditText(android.widget.EditText) SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) Bundle(android.os.Bundle) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) FragmentActivity(androidx.fragment.app.FragmentActivity) OsmandTextFieldBoxes(net.osmand.plus.widgets.OsmandTextFieldBoxes) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) File(java.io.File) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 4 with GpxSelectionHelper

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;
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) Map(java.util.Map) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) NonNull(androidx.annotation.NonNull)

Example 5 with GpxSelectionHelper

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 "";
    }
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) MapActivity(net.osmand.plus.activities.MapActivity) NonNull(androidx.annotation.NonNull)

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