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