Search in sources :

Example 26 with SelectedGpxFile

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

the class HistoryCard method updateContent.

@SuppressLint("DefaultLocale")
@Override
protected void updateContent() {
    final List<SearchResult> list = new ArrayList<>();
    for (SearchResult searchResult : searchResults) {
        if (searchResult.object instanceof HistoryEntry) {
            list.add(searchResult);
        }
    }
    LinearLayout items = view.findViewById(R.id.items);
    items.removeAllViews();
    boolean showLimitExceeds = list.size() > limit + 1;
    Context themedContext = UiUtilities.getThemedContext(activity, nightMode);
    LayoutInflater inflater = UiUtilities.getInflater(mapActivity, nightMode);
    int iconColorId = nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light;
    int iconColor = ContextCompat.getColor(app, iconColorId);
    for (int i = 0; i < list.size(); i++) {
        if (showLimitExceeds && i >= limit) {
            break;
        }
        SearchResult searchResult = list.get(i);
        LinearLayout view;
        QuickSearchListItem listItem = new QuickSearchListItem(app, searchResult);
        if (searchResult.objectType == ObjectType.GPX_TRACK) {
            view = (LinearLayout) inflater.inflate(R.layout.search_gpx_list_item, items, false);
            GPXInfo gpxInfo = (GPXInfo) searchResult.relatedObject;
            QuickSearchListAdapter.bindGpxTrack(view, listItem, gpxInfo);
            ImageView icon = view.findViewById(R.id.icon);
            icon.setImageDrawable(UiUtilities.tintDrawable(listItem.getIcon(), iconColor));
            view.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String fileName = gpxInfo.getFileName();
                    SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByName(fileName);
                    if (selectedGpxFile != null) {
                        GPXFile gpxFile = selectedGpxFile.getGpxFile();
                        mapActivity.getMapRouteInfoMenu().selectTrack(gpxFile);
                    } else {
                        CallbackWithObject<GPXFile[]> callback = result -> {
                            MapActivity mapActivity = getMapActivity();
                            if (mapActivity != null) {
                                mapActivity.getMapRouteInfoMenu().selectTrack(result[0]);
                            }
                            return true;
                        };
                        File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
                        GpxUiHelper.loadGPXFileInDifferentThread(mapActivity, callback, dir, null, fileName);
                    }
                }
            });
        } else {
            view = (LinearLayout) inflater.inflate(R.layout.search_list_item, items, false);
            QuickSearchListAdapter.bindSearchResult(view, listItem);
            ImageView icon = view.findViewById(R.id.imageView);
            icon.setImageDrawable(UiUtilities.tintDrawable(listItem.getIcon(), iconColor));
            final HistoryEntry entry = (HistoryEntry) searchResult.object;
            view.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    app.getTargetPointsHelper().navigateToPoint(searchResult.location, true, -1, entry.getName());
                }
            });
        }
        View itemContainer = view.findViewById(R.id.searchListItemLayout);
        itemContainer.setBackground(UiUtilities.getSelectableDrawable(themedContext));
        itemContainer.setMinimumHeight(getDimen(R.dimen.route_info_card_item_height));
        int margin = getDimen(R.dimen.route_info_list_text_padding);
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, AndroidUtils.dpToPx(app, 1));
        AndroidUtils.setMargins(params, margin, 0, 0, 0);
        View divider = view.findViewById(R.id.divider);
        divider.setLayoutParams(params);
        AndroidUiHelper.updateVisibility(divider, !showLimitExceeds || i < limit);
        items.addView(view);
    }
    View showAllButton = view.findViewById(R.id.show_all_button);
    if (showLimitExceeds) {
        ((TextView) view.findViewById(R.id.show_all_title)).setText(app.getString(R.string.show_more).toUpperCase());
        showAllButton.setVisibility(View.VISIBLE);
        showAllButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (limit < 10) {
                    limit = 10;
                } else {
                    limit += 10;
                }
                updateContent();
                setLayoutNeeded();
            }
        });
    } else {
        showAllButton.setVisibility(View.GONE);
    }
    ((TextView) view.findViewById(R.id.gpx_card_title)).setText(R.string.shared_string_history);
}
Also used : Context(android.content.Context) LayoutParams(android.widget.LinearLayout.LayoutParams) GPXInfo(net.osmand.plus.helpers.GpxUiHelper.GPXInfo) ArrayList(java.util.ArrayList) SearchResult(net.osmand.search.core.SearchResult) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) CallbackWithObject(net.osmand.CallbackWithObject) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) LayoutInflater(android.view.LayoutInflater) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) TextView(android.widget.TextView) ImageView(android.widget.ImageView) 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) MapActivity(net.osmand.plus.activities.MapActivity) SuppressLint(android.annotation.SuppressLint)

Example 27 with SelectedGpxFile

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

the class TrackMenuFragment method loadSelectedGpxFile.

public static void loadSelectedGpxFile(@NonNull MapActivity mapActivity, @Nullable String path, boolean showCurrentTrack, final CallbackWithObject<SelectedGpxFile> callback) {
    OsmandApplication app = mapActivity.getMyApplication();
    SelectedGpxFile selectedGpxFile;
    if (showCurrentTrack) {
        selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
    } else {
        selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(path);
    }
    if (selectedGpxFile != null) {
        callback.processResult(selectedGpxFile);
    } else if (!Algorithms.isEmpty(path)) {
        final ProgressDialog[] progress = new ProgressDialog[1];
        if (AndroidUtils.isActivityNotDestroyed(mapActivity)) {
            String title = app.getString(R.string.loading_smth, "");
            progress[0] = ProgressDialog.show(mapActivity, title, app.getString(R.string.loading_data));
        }
        final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
        GpxFileLoaderTask gpxFileLoaderTask = new GpxFileLoaderTask(new File(path), new CallbackWithObject<GPXFile>() {

            @Override
            public boolean processResult(GPXFile result) {
                SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().selectGpxFile(result, true, false);
                if (selectedGpxFile != null) {
                    callback.processResult(selectedGpxFile);
                }
                MapActivity mapActivity = mapActivityRef.get();
                if (progress[0] != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) {
                    progress[0].dismiss();
                }
                return true;
            }
        });
        gpxFileLoaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : CallbackWithObject(net.osmand.CallbackWithObject) OsmandApplication(net.osmand.plus.OsmandApplication) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) WeakReference(java.lang.ref.WeakReference) GpxFileLoaderTask(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxFileLoaderTask) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) MapActivity(net.osmand.plus.activities.MapActivity)

Example 28 with SelectedGpxFile

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

the class TrackMenuFragment method deleteAndSaveSegment.

private void deleteAndSaveSegment(TrkSegment segment) {
    if (deleteSegment(segment)) {
        GPXFile gpx = displayHelper.getGpx();
        if (gpx != null) {
            boolean showOnMap = GpxSelectionHelper.isGpxFileSelected(app, gpx);
            SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().selectGpxFile(gpx, showOnMap, false);
            saveGpx(showOnMap ? selectedGpxFile : null, gpx);
        }
    }
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile)

Example 29 with SelectedGpxFile

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

the class TrackMenuFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    app = requireMyApplication();
    displayHelper = new TrackDisplayHelper(app);
    updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache();
    toolbarHeightPx = getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
    if (selectedGpxFile == null && savedInstanceState != null) {
        String path = savedInstanceState.getString(TRACK_FILE_NAME);
        boolean showCurrentTrack = savedInstanceState.getBoolean(CURRENT_RECORDING);
        MapActivity mapActivity = requireMapActivity();
        loadSelectedGpxFile(mapActivity, path, showCurrentTrack, new CallbackWithObject<SelectedGpxFile>() {

            @Override
            public boolean processResult(SelectedGpxFile result) {
                setSelectedGpxFile(result);
                onSelectedGpxFileAvailable();
                if (getView() != null) {
                    initContent(getView());
                }
                return true;
            }
        });
        if (savedInstanceState.containsKey(KEY_LATITUDE) && savedInstanceState.containsKey(KEY_LONGITUDE)) {
            double latitude = savedInstanceState.getDouble(KEY_LATITUDE);
            double longitude = savedInstanceState.getDouble(KEY_LONGITUDE);
            latLon = new LatLon(latitude, longitude);
        }
    } else if (selectedGpxFile != null) {
        onSelectedGpxFileAvailable();
        if (FileUtils.isTempFile(app, getGpx().path)) {
            app.getSelectedGpxHelper().selectGpxFile(selectedGpxFile.getGpxFile(), true, false);
        }
    }
    FragmentActivity activity = requireMyActivity();
    activity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {

        public void handleOnBackPressed() {
            if (getCurrentMenuState() != MenuState.HEADER_ONLY && isPortrait()) {
                openMenuHeaderOnly();
            } else {
                dismiss();
                MapActivity mapActivity = getMapActivity();
                if (mapActivity != null) {
                    MapContextMenu contextMenu = mapActivity.getContextMenu();
                    PointDescription pointDescription = contextMenu.getPointDescription();
                    if (pointDescription != null && pointDescription.isGpxPoint()) {
                        contextMenu.init(contextMenu.getLatLon(), pointDescription, contextMenu.getObject());
                        contextMenu.show();
                    } else if (Algorithms.objectEquals(callingFragmentTag, QuickSearchDialogFragment.TAG)) {
                        mapActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false);
                    } else {
                        mapActivity.launchPrevActivityIntent();
                    }
                }
            }
        }
    });
}
Also used : MapContextMenu(net.osmand.plus.mapcontextmenu.MapContextMenu) LatLon(net.osmand.data.LatLon) FragmentActivity(androidx.fragment.app.FragmentActivity) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) OnBackPressedCallback(androidx.activity.OnBackPressedCallback) PointDescription(net.osmand.data.PointDescription) TrackDisplayHelper(net.osmand.plus.track.helpers.TrackDisplayHelper) MapActivity(net.osmand.plus.activities.MapActivity)

Example 30 with SelectedGpxFile

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

the class TrackMenuFragment method onCardButtonPressed.

@Override
public void onCardButtonPressed(@NonNull BaseCard card, int buttonIndex) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null) {
        return;
    }
    FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
    GPXFile gpxFile = getGpx();
    if (card instanceof OptionsCard || card instanceof OverviewCard || card instanceof SegmentsCard) {
        if (buttonIndex == SHOW_ON_MAP_BUTTON_INDEX) {
            if (FileUtils.isTempFile(app, getGpx().path)) {
                File srcFile = displayHelper.getFile();
                File destFIle = new File(app.getAppPath(IndexConstants.GPX_TRAVEL_DIR), srcFile.getName());
                onFileMove(srcFile, destFIle);
                gpxFile = getGpx();
            } else {
                boolean gpxFileSelected = !isGpxFileSelected(app, gpxFile);
                app.getSelectedGpxHelper().selectGpxFile(gpxFile, gpxFileSelected, false);
            }
            updateContent();
            mapActivity.refreshMap();
        } else if (buttonIndex == APPEARANCE_BUTTON_INDEX) {
            TrackAppearanceFragment.showInstance(mapActivity, selectedGpxFile, this);
        } else if (buttonIndex == DIRECTIONS_BUTTON_INDEX) {
            GPXFile gpxFileToDisplay = displayHelper.getGpxFileToDisplay();
            if (gpxFileToDisplay != null) {
                if (gpxFileToDisplay.getNonEmptySegmentsCount() > 1) {
                    TrackSelectSegmentBottomSheet.showInstance(fragmentManager, gpxFileToDisplay, this);
                } else {
                    GpxNavigationHelper.startNavigationForGpx(gpxFileToDisplay, mapActivity);
                    dismiss();
                }
            }
        }
        if (buttonIndex == JOIN_GAPS_BUTTON_INDEX) {
            displayHelper.setJoinSegments(!displayHelper.isJoinSegments());
            mapActivity.refreshMap();
            if (segmentsCard != null) {
                segmentsCard.updateContent();
            }
        } else if (buttonIndex == ANALYZE_ON_MAP_BUTTON_INDEX) {
            new OpenGpxDetailsTask(selectedGpxFile, null, mapActivity).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            dismiss();
        } else if (buttonIndex == ANALYZE_BY_INTERVALS_BUTTON_INDEX) {
            TrkSegment segment = gpxFile.getGeneralSegment();
            if (segment == null) {
                List<TrkSegment> segments = gpxFile.getNonEmptyTrkSegments(false);
                if (!Algorithms.isEmpty(segments)) {
                    segment = segments.get(0);
                }
            }
            GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] { GpxDisplayItemType.TRACK_SEGMENT };
            List<GpxDisplayItem> items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes));
            if (segment != null && !Algorithms.isEmpty(items)) {
                SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment);
            }
        } else if (buttonIndex == SHARE_BUTTON_INDEX) {
            OsmandApplication app = mapActivity.getMyApplication();
            if (gpxFile.showCurrentTrack) {
                GpxUiHelper.saveAndShareCurrentGpx(app, gpxFile);
            } else if (!Algorithms.isEmpty(gpxFile.path)) {
                GpxUiHelper.saveAndShareGpxWithAppearance(app, gpxFile);
            }
        } else if (buttonIndex == UPLOAD_OSM_BUTTON_INDEX) {
            OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getActivePlugin(OsmEditingPlugin.class);
            if (osmEditingPlugin != null) {
                GpxInfo gpxInfo = new GpxInfo();
                gpxInfo.gpx = gpxFile;
                gpxInfo.file = new File(gpxFile.path);
                osmEditingPlugin.sendGPXFiles(mapActivity, this, gpxInfo);
            }
        } else if (buttonIndex == EDIT_BUTTON_INDEX) {
            app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false);
            dismiss();
            String fileName = Algorithms.getFileWithoutDirs(gpxFile.path);
            MeasurementToolFragment.showInstance(fragmentManager, fileName, false);
        } else if (buttonIndex == RENAME_BUTTON_INDEX) {
            FileUtils.renameFile(mapActivity, new File(gpxFile.path), this, true);
        } else if (buttonIndex == CHANGE_FOLDER_BUTTON_INDEX) {
            MoveGpxFileBottomSheet.showInstance(fragmentManager, this, gpxFile.path, true, false);
        } else if (buttonIndex == GPS_FILTER_BUTTON_INDEX) {
            GpsFilterFragment.showInstance(fragmentManager, selectedGpxFile, this);
        } else if (buttonIndex == DELETE_BUTTON_INDEX) {
            String fileName = Algorithms.getFileWithoutDirs(gpxFile.path);
            AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(mapActivity, isNightMode()));
            builder.setTitle(getString(R.string.delete_confirmation_msg, fileName));
            builder.setMessage(R.string.are_you_sure);
            final String gpxFilePath = gpxFile.path;
            builder.setNegativeButton(R.string.shared_string_cancel, null).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (FileUtils.removeGpxFile(app, new File(gpxFilePath))) {
                        dismiss();
                    }
                }
            });
            builder.show();
        }
    } else if (card instanceof TrackPointsCard) {
        if (buttonIndex == ADD_WAYPOINT_INDEX) {
            PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, app.getString(R.string.add_waypoint));
            QuadRect rect = displayHelper.getRect();
            NewGpxPoint newGpxPoint = new NewGpxPoint(gpxFile, pointDescription, rect);
            mapActivity.getMapView().fitRectToMap(rect.left, rect.right, rect.top, rect.bottom, (int) rect.width(), (int) rect.height(), 0);
            mapActivity.getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint);
            hide();
        } else if (buttonIndex == DELETE_WAYPOINTS_INDEX) {
            TrackPointsCard pointsCard = (TrackPointsCard) card;
            if (pointsCard.isSelectionMode()) {
                pointsCard.deleteItemsAction();
            } else {
                pointsCard.setSelectionMode(true);
            }
        } else if (buttonIndex == OPEN_WAYPOINT_INDEX) {
            dismiss();
        }
    } else if (card instanceof PointsGroupsCard) {
        PointsGroupsCard groupsCard = (PointsGroupsCard) card;
        GpxDisplayGroup group = groupsCard.getSelectedGroup();
        if (pointsCard != null) {
            pointsCard.setSelectedGroup(group);
            if (group != null) {
                fitSelectedPointsGroupOnMap(group);
            } else {
                fitTrackOnMap();
            }
        }
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) OsmandApplication(net.osmand.plus.OsmandApplication) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) DialogInterface(android.content.DialogInterface) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) OpenGpxDetailsTask(net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.OpenGpxDetailsTask) QuadRect(net.osmand.data.QuadRect) PointsGroupsCard(net.osmand.plus.track.cards.PointsGroupsCard) SegmentsCard(net.osmand.plus.track.cards.SegmentsCard) TrackPointsCard(net.osmand.plus.track.cards.TrackPointsCard) MapActivity(net.osmand.plus.activities.MapActivity) OptionsCard(net.osmand.plus.track.cards.OptionsCard) OverviewCard(net.osmand.plus.track.cards.OverviewCard) GpxInfo(net.osmand.plus.myplaces.ui.AvailableGPXFragment.GpxInfo) TrkSegment(net.osmand.GPXUtilities.TrkSegment) GpxDisplayItemType(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItemType) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) FragmentManager(androidx.fragment.app.FragmentManager) PointDescription(net.osmand.data.PointDescription) OnClickListener(android.view.View.OnClickListener) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File)

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