Search in sources :

Example 6 with GpxSelectionHelper

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

the class OsmandAidlApi method finishGpxImport.

@SuppressLint("StaticFieldLeak")
private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) {
    final int col = GpxAppearanceAdapter.parseTrackColor(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
    if (!destinationExists) {
        GpxDataItem gpxDataItem = new GpxDataItem(destination, col);
        gpxDataItem.setApiImported(true);
        app.getGpxDbHelper().add(gpxDataItem);
    } else {
        GpxDataItem item = app.getGpxDbHelper().getItem(destination);
        if (item != null) {
            app.getGpxDbHelper().updateColor(item, col);
        }
    }
    final GpxSelectionHelper helper = app.getSelectedGpxHelper();
    final SelectedGpxFile selectedGpx = helper.getSelectedFileByName(destination.getName());
    if (selectedGpx != null) {
        if (show) {
            new AsyncTask<File, Void, GPXFile>() {

                @Override
                protected GPXFile doInBackground(File... files) {
                    return GPXUtilities.loadGPXFile(files[0]);
                }

                @Override
                protected void onPostExecute(GPXFile gpx) {
                    if (gpx.error == null) {
                        if (col != -1) {
                            gpx.setColor(col);
                        }
                        selectedGpx.setGpxFile(gpx, app);
                        refreshMap();
                    }
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, destination);
        } else {
            helper.selectGpxFile(selectedGpx.getGpxFile(), false, false);
            refreshMap();
        }
    } else if (show) {
        new AsyncTask<File, Void, GPXFile>() {

            @Override
            protected GPXFile doInBackground(File... files) {
                return GPXUtilities.loadGPXFile(files[0]);
            }

            @Override
            protected void onPostExecute(GPXFile gpx) {
                if (gpx.error == null) {
                    helper.selectGpxFile(gpx, true, false);
                    refreshMap();
                }
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, destination);
    }
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) ASelectedGpxFile(net.osmand.aidl.gpx.ASelectedGpxFile) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) AsyncTask(android.os.AsyncTask) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) ASqliteDbFile(net.osmand.aidl.tiles.ASqliteDbFile) File(java.io.File) ASelectedGpxFile(net.osmand.aidl.gpx.ASelectedGpxFile) AGpxFile(net.osmand.aidl.gpx.AGpxFile) FavouritePoint(net.osmand.data.FavouritePoint) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 7 with GpxSelectionHelper

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

the class AppInitializer method onCreateApplication.

public void onCreateApplication() {
    // always update application mode to default
    OsmandSettings osmandSettings = app.getSettings();
    if (osmandSettings.FOLLOW_THE_ROUTE.get()) {
        ApplicationMode savedMode = osmandSettings.readApplicationMode();
        if (!osmandSettings.APPLICATION_MODE.get().getStringKey().equals(savedMode.getStringKey())) {
            osmandSettings.setApplicationMode(savedMode);
        }
    } else {
        osmandSettings.setApplicationMode(osmandSettings.DEFAULT_APPLICATION_MODE.get());
    }
    startTime = System.currentTimeMillis();
    getLazyRoutingConfig();
    app.applyTheme(app);
    startupInit(app.reconnectToBRouter(), IBRouterService.class);
    app.backupHelper = startupInit(new BackupHelper(app), BackupHelper.class);
    app.inAppPurchaseHelper = startupInit(new InAppPurchaseHelperImpl(app), InAppPurchaseHelperImpl.class);
    app.poiTypes = startupInit(MapPoiTypes.getDefaultNoInit(), MapPoiTypes.class);
    app.transportRoutingHelper = startupInit(new TransportRoutingHelper(app), TransportRoutingHelper.class);
    app.routingHelper = startupInit(new RoutingHelper(app), RoutingHelper.class);
    app.routingOptionsHelper = startupInit(new RoutingOptionsHelper(app), RoutingOptionsHelper.class);
    app.resourceManager = startupInit(new ResourceManager(app), ResourceManager.class);
    app.daynightHelper = startupInit(new DayNightHelper(app), DayNightHelper.class);
    app.locationProvider = startupInit(new OsmAndLocationProvider(app), OsmAndLocationProvider.class);
    app.avoidSpecificRoads = startupInit(new AvoidSpecificRoads(app), AvoidSpecificRoads.class);
    app.avoidRoadsHelper = startupInit(new AvoidRoadsHelper(app), AvoidRoadsHelper.class);
    app.savingTrackHelper = startupInit(new SavingTrackHelper(app), SavingTrackHelper.class);
    app.analyticsHelper = startupInit(new AnalyticsHelper(app), AnalyticsHelper.class);
    app.notificationHelper = startupInit(new NotificationHelper(app), NotificationHelper.class);
    app.liveMonitoringHelper = startupInit(new LiveMonitoringHelper(app), LiveMonitoringHelper.class);
    app.selectedGpxHelper = startupInit(new GpxSelectionHelper(app, app.savingTrackHelper), GpxSelectionHelper.class);
    app.gpxDbHelper = startupInit(new GpxDbHelper(app), GpxDbHelper.class);
    app.favoritesHelper = startupInit(new FavouritesHelper(app), FavouritesHelper.class);
    app.waypointHelper = startupInit(new WaypointHelper(app), WaypointHelper.class);
    app.aidlApi = startupInit(new OsmandAidlApi(app), OsmandAidlApi.class);
    app.regions = startupInit(new OsmandRegions(), OsmandRegions.class);
    updateRegionVars();
    app.poiFilters = startupInit(new PoiFiltersHelper(app), PoiFiltersHelper.class);
    app.rendererRegistry = startupInit(new RendererRegistry(app), RendererRegistry.class);
    app.geocodingLookupService = startupInit(new GeocodingLookupService(app), GeocodingLookupService.class);
    app.targetPointsHelper = startupInit(new TargetPointsHelper(app), TargetPointsHelper.class);
    app.mapMarkersDbHelper = startupInit(new MapMarkersDbHelper(app), MapMarkersDbHelper.class);
    app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class);
    app.searchUICore = startupInit(new QuickSearchHelper(app), QuickSearchHelper.class);
    app.mapViewTrackingUtilities = startupInit(new MapViewTrackingUtilities(app), MapViewTrackingUtilities.class);
    app.osmandMap = startupInit(new OsmandMap(app), OsmandMap.class);
    // TODO TRAVEL_OBF_HELPER check ResourceManager and use TravelObfHelper
    TravelHelper travelHelper = !TravelDbHelper.checkIfDbFileExists(app) ? new TravelObfHelper(app) : new TravelDbHelper(app);
    app.travelHelper = startupInit(travelHelper, TravelHelper.class);
    app.travelRendererHelper = startupInit(new TravelRendererHelper(app), TravelRendererHelper.class);
    app.lockHelper = startupInit(new LockHelper(app), LockHelper.class);
    app.fileSettingsHelper = startupInit(new FileSettingsHelper(app), FileSettingsHelper.class);
    app.networkSettingsHelper = startupInit(new NetworkSettingsHelper(app), NetworkSettingsHelper.class);
    app.quickActionRegistry = startupInit(new QuickActionRegistry(app.getSettings()), QuickActionRegistry.class);
    app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class);
    app.oprAuthHelper = startupInit(new OprAuthHelper(app), OprAuthHelper.class);
    app.onlineRoutingHelper = startupInit(new OnlineRoutingHelper(app), OnlineRoutingHelper.class);
    app.launcherShortcutsHelper = startupInit(new LauncherShortcutsHelper(app), LauncherShortcutsHelper.class);
    app.gpsFilterHelper = startupInit(new GpsFilterHelper(app), GpsFilterHelper.class);
    app.downloadTilesHelper = startupInit(new DownloadTilesHelper(app), DownloadTilesHelper.class);
    initOpeningHoursParser();
}
Also used : DayNightHelper(net.osmand.plus.helpers.DayNightHelper) OsmOAuthHelper(net.osmand.plus.plugins.osmedit.oauth.OsmOAuthHelper) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) AvoidSpecificRoads(net.osmand.plus.helpers.AvoidSpecificRoads) BackupHelper(net.osmand.plus.backup.BackupHelper) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) WaypointHelper(net.osmand.plus.helpers.WaypointHelper) OnlineRoutingHelper(net.osmand.plus.onlinerouting.OnlineRoutingHelper) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) SavingTrackHelper(net.osmand.plus.track.helpers.SavingTrackHelper) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) TravelObfHelper(net.osmand.plus.wikivoyage.data.TravelObfHelper) AvoidRoadsHelper(net.osmand.plus.routing.AvoidRoadsHelper) GpxDbHelper(net.osmand.plus.track.helpers.GpxDbHelper) OsmandRegions(net.osmand.map.OsmandRegions) LauncherShortcutsHelper(net.osmand.plus.helpers.LauncherShortcutsHelper) RendererRegistry(net.osmand.plus.render.RendererRegistry) DownloadTilesHelper(net.osmand.plus.plugins.rastermaps.DownloadTilesHelper) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) QuickActionRegistry(net.osmand.plus.quickaction.QuickActionRegistry) AnalyticsHelper(net.osmand.plus.helpers.AnalyticsHelper) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper) OsmandMap(net.osmand.plus.views.OsmandMap) TravelDbHelper(net.osmand.plus.wikivoyage.data.TravelDbHelper) MapMarkersDbHelper(net.osmand.plus.mapmarkers.MapMarkersDbHelper) GpsFilterHelper(net.osmand.plus.track.helpers.GpsFilterHelper) OnlineRoutingHelper(net.osmand.plus.onlinerouting.OnlineRoutingHelper) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TransportRoutingHelper(net.osmand.plus.routing.TransportRoutingHelper) ResourceManager(net.osmand.plus.resources.ResourceManager) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) TravelRendererHelper(net.osmand.plus.render.TravelRendererHelper) LiveMonitoringHelper(net.osmand.plus.plugins.monitoring.LiveMonitoringHelper) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) MapPoiTypes(net.osmand.osm.MapPoiTypes) QuickSearchHelper(net.osmand.plus.search.QuickSearchHelper) NetworkSettingsHelper(net.osmand.plus.backup.NetworkSettingsHelper) RoutingOptionsHelper(net.osmand.plus.routepreparationmenu.RoutingOptionsHelper) MapMarkersHelper(net.osmand.plus.mapmarkers.MapMarkersHelper) NotificationHelper(net.osmand.plus.notifications.NotificationHelper) InAppPurchaseHelperImpl(net.osmand.plus.inapp.InAppPurchaseHelperImpl) TransportRoutingHelper(net.osmand.plus.routing.TransportRoutingHelper) FileSettingsHelper(net.osmand.plus.settings.backend.backup.FileSettingsHelper) OprAuthHelper(net.osmand.plus.plugins.openplacereviews.OprAuthHelper) OsmandAidlApi(net.osmand.aidl.OsmandAidlApi) LockHelper(net.osmand.plus.helpers.LockHelper)

Example 8 with GpxSelectionHelper

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

the class WptPtEditorFragmentNew method doUpdateWpt.

private void doUpdateWpt(String name, String category, String description) {
    WptPt wpt = getWpt();
    WptPtEditor editor = getWptPtEditor();
    SavingTrackHelper savingTrackHelper = getSavingTrackHelper();
    GpxSelectionHelper selectedGpxHelper = getSelectedGpxHelper();
    if (wpt != null && editor != null && savingTrackHelper != null && selectedGpxHelper != null) {
        GPXFile gpx = editor.getGpxFile();
        if (gpx != null) {
            if (gpx.showCurrentTrack) {
                savingTrackHelper.updatePointData(wpt, wpt.getLatitude(), wpt.getLongitude(), System.currentTimeMillis(), description, name, category, color, iconName, backgroundTypeName);
                if (!editor.isGpxSelected()) {
                    selectedGpxHelper.setGpxFileToDisplay(gpx);
                }
            } else {
                gpx.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(), System.currentTimeMillis(), description, name, category, color, iconName, backgroundTypeName);
                saveGpx(getMyApplication(), gpx, editor.isGpxSelected());
            }
            syncGpx(gpx);
        }
    }
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) SavingTrackHelper(net.osmand.plus.track.helpers.SavingTrackHelper) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) GPXFile(net.osmand.GPXUtilities.GPXFile)

Example 9 with GpxSelectionHelper

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

the class AddTracksGroupBottomSheetDialogFragment method onItemClick.

@Override
protected void onItemClick(int position) {
    GpxDataItem dataItem = gpxList.get(position - 1);
    GPXTrackAnalysis analysis = dataItem.getAnalysis();
    if (analysis != null && analysis.wptCategoryNames != null && analysis.wptCategoryNames.size() > 1) {
        Bundle args = new Bundle();
        args.putString(SelectWptCategoriesBottomSheetDialogFragment.GPX_FILE_PATH_KEY, dataItem.getFile().getAbsolutePath());
        SelectWptCategoriesBottomSheetDialogFragment fragment = new SelectWptCategoriesBottomSheetDialogFragment();
        fragment.setArguments(args);
        fragment.setUsedOnMap(false);
        fragment.show(getParentFragment().getChildFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
    } else {
        OsmandApplication app = getMyApplication();
        if (app != null) {
            GpxSelectionHelper selectionHelper = app.getSelectedGpxHelper();
            File gpx = dataItem.getFile();
            if (selectionHelper.getSelectedFileByPath(gpx.getAbsolutePath()) == null) {
                GPXFile res = GPXUtilities.loadGPXFile(gpx);
                selectionHelper.selectGpxFile(res, true, false, false, false, false);
            }
            app.getMapMarkersHelper().addOrEnableGpxGroup(gpx);
        }
    }
    dismiss();
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) Bundle(android.os.Bundle) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File)

Example 10 with GpxSelectionHelper

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

the class MapMarkersHelper method syncTrackGroup.

private void syncTrackGroup(@NonNull MapMarkersGroup group, @NonNull List<MapMarker> existingMarkers) {
    GpxSelectionHelper gpxHelper = ctx.getSelectedGpxHelper();
    File file = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + group.getId());
    if (!file.exists() || !file.isFile()) {
        removeFromGroupsList(group);
        return;
    }
    SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(file.getAbsolutePath());
    GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
    group.setVisible(gpx != null || group.isVisibleUntilRestart());
    if (gpx == null || group.isDisabled()) {
        removeGroupActiveMarkers(group, true);
        return;
    }
    int colorIndex = -1;
    boolean addAll = group.getWptCategories() == null || group.getWptCategories().isEmpty();
    List<WptPt> gpxPoints = new ArrayList<>(gpx.getPoints());
    for (WptPt wptPt : gpxPoints) {
        if (addAll || group.getWptCategories().contains(wptPt.category) || (wptPt.category == null && group.getWptCategories().contains(""))) {
            if (colorIndex == -1) {
                colorIndex = mapMarkers.isEmpty() ? 0 : (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
            } else {
                colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
            }
            MapMarker mapMarker = ItineraryDataHelper.fromWpt(ctx, wptPt, group);
            mapMarker.colorIndex = colorIndex;
            existingMarkers.add(mapMarker);
        }
    }
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) ArrayList(java.util.ArrayList) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) FavouritePoint(net.osmand.data.FavouritePoint)

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