use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.
the class PointNavigationLayer method applyNewObjectPosition.
@Override
public void applyNewObjectPosition(@NonNull Object o, @NonNull LatLon position, @Nullable ContextMenuLayer.ApplyMovedObjectCallback callback) {
boolean result = false;
TargetPoint newTargetPoint = null;
if (o instanceof TargetPoint) {
TargetPointsHelper targetPointsHelper = getApplication().getTargetPointsHelper();
TargetPoint oldPoint = (TargetPoint) o;
if (oldPoint.start) {
targetPointsHelper.setStartPoint(position, true, null);
newTargetPoint = targetPointsHelper.getPointToStart();
} else if (oldPoint == targetPointsHelper.getPointToNavigate()) {
targetPointsHelper.navigateToPoint(position, true, -1, null);
newTargetPoint = targetPointsHelper.getPointToNavigate();
} else if (oldPoint.intermediate) {
List<TargetPoint> points = targetPointsHelper.getIntermediatePointsWithTarget();
int i = points.indexOf(oldPoint);
if (i != -1) {
newTargetPoint = new TargetPoint(position, new PointDescription(PointDescription.POINT_TYPE_LOCATION, ""));
points.set(i, newTargetPoint);
targetPointsHelper.reorderAllTargetPoints(points, true);
}
}
result = true;
}
if (callback != null) {
callback.onApplyMovedObject(result, newTargetPoint == null ? o : newTargetPoint);
}
}
use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.
the class PointNavigationLayer method onDraw.
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
if (tb.getZoom() < 3) {
return;
}
updateBitmaps(false);
OsmandApplication app = getApplication();
TargetPointsHelper targetPoints = app.getTargetPointsHelper();
TargetPoint pointToStart = targetPoints.getPointToStart();
if (pointToStart != null) {
if (isLocationVisible(tb, pointToStart)) {
int marginX = mStartPoint.getWidth() / 6;
int marginY = mStartPoint.getHeight();
float locationX = getPointX(tb, pointToStart);
float locationY = getPointY(tb, pointToStart);
canvas.rotate(-tb.getRotate(), locationX, locationY);
canvas.drawBitmap(mStartPoint, locationX - marginX, locationY - marginY, mBitmapPaint);
canvas.rotate(tb.getRotate(), locationX, locationY);
}
}
int index = 0;
for (TargetPoint ip : targetPoints.getIntermediatePoints()) {
index++;
if (isLocationVisible(tb, ip)) {
int marginX = mIntermediatePoint.getWidth() / 6;
int marginY = mIntermediatePoint.getHeight();
float locationX = getPointX(tb, ip);
float locationY = getPointY(tb, ip);
canvas.rotate(-tb.getRotate(), locationX, locationY);
canvas.drawBitmap(mIntermediatePoint, locationX - marginX, locationY - marginY, mBitmapPaint);
marginX = mIntermediatePoint.getWidth() / 3;
canvas.drawText(index + "", locationX + marginX, locationY - 3 * marginY / 5, mTextPaint);
canvas.rotate(tb.getRotate(), locationX, locationY);
}
}
TargetPoint pointToNavigate = targetPoints.getPointToNavigate();
if (isLocationVisible(tb, pointToNavigate)) {
int marginX = mTargetPoint.getWidth() / 6;
int marginY = mTargetPoint.getHeight();
float locationX = getPointX(tb, pointToNavigate);
float locationY = getPointY(tb, pointToNavigate);
canvas.rotate(-tb.getRotate(), locationX, locationY);
canvas.drawBitmap(mTargetPoint, locationX - marginX, locationY - marginY, mBitmapPaint);
canvas.rotate(tb.getRotate(), locationX, locationY);
}
}
use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.
the class MapControlsLayer method replaceDestination.
public void replaceDestination(@NonNull LatLon latLon, @Nullable PointDescription pointDescription) {
RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
if (pointDescription == null) {
pointDescription = getPointDescriptionForTarget(latLon, null);
}
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getContextMenu().close();
}
final TargetPointsHelper targets = app.getTargetPointsHelper();
targets.navigateToPoint(latLon, true, -1, pointDescription);
} else {
addDestination(latLon, pointDescription);
}
}
use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.
the class MapActivity method onResume.
@Override
protected void onResume() {
super.onResume();
MapActivity mapViewMapActivity = getMapView().getMapActivity();
if (activityRestartNeeded || !getMapLayers().hasMapActivity() || (mapViewMapActivity != null && mapViewMapActivity != this)) {
activityRestartNeeded = false;
recreate();
return;
}
long tm = System.currentTimeMillis();
FragmentManager fragmentManager = getSupportFragmentManager();
if (app.getMapMarkersHelper().getPlanRouteContext().isFragmentVisible()) {
PlanRouteFragment.showInstance(this);
}
if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) {
if (!dashboardOnMap.isVisible()) {
if (settings.SHOW_DASHBOARD_ON_START.get()) {
dashboardOnMap.setDashboardVisibility(true, DashboardOnMap.staticVisibleType);
} else {
OsmAndAppCustomization customization = app.getAppCustomization();
if (customization.isFeatureEnabled(FRAGMENT_CRASH_ID) && CrashBottomSheetDialogFragment.shouldShow(settings, this)) {
SecondSplashScreenFragment.SHOW = false;
CrashBottomSheetDialogFragment.showInstance(fragmentManager);
} else if (customization.isFeatureEnabled(FRAGMENT_RATE_US_ID) && RateUsHelper.shouldShowRateDialog(app)) {
SecondSplashScreenFragment.SHOW = false;
RateUsHelper.showRateDialog(this);
}
}
} else {
dashboardOnMap.updateDashboard();
}
}
dashboardOnMap.updateLocation(true, true, false);
boolean showStorageMigrationScreen = false;
if (getFragment(WhatsNewDialogFragment.TAG) == null || WhatsNewDialogFragment.wasNotShown()) {
if (getFragment(SharedStorageWarningFragment.TAG) == null && SharedStorageWarningFragment.dialogShowRequired(app)) {
showStorageMigrationScreen = true;
SecondSplashScreenFragment.SHOW = false;
SharedStorageWarningFragment.showInstance(getSupportFragmentManager(), true);
}
}
getMyApplication().getNotificationHelper().refreshNotifications();
// fixing bug with action bar appearing on android 2.3.3
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
// for voice navigation
ApplicationMode routingAppMode = getRoutingHelper().getAppMode();
if (routingAppMode != null && settings.AUDIO_MANAGER_STREAM.getModeValue(routingAppMode) != null) {
setVolumeControlStream(settings.AUDIO_MANAGER_STREAM.getModeValue(routingAppMode));
} else {
setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
applicationModeListener = change -> app.runInUIThread(this::updateApplicationModeSettings);
settings.APPLICATION_MODE.addListener(applicationModeListener);
updateApplicationModeSettings();
// if destination point was changed try to recalculate route
TargetPointsHelper targets = app.getTargetPointsHelper();
RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode() && (!Algorithms.objectEquals(targets.getPointToNavigate().point, routingHelper.getFinalLocation()) || !Algorithms.objectEquals(targets.getIntermediatePointsLatLonNavigation(), routingHelper.getIntermediatePoints()))) {
targets.updateRouteAndRefresh(true);
}
app.getLocationProvider().resumeAllUpdates();
OsmandMapTileView mapView = getMapView();
if (settings.isLastKnownMapLocation() && !intentLocation) {
LatLon l = settings.getLastKnownMapLocation();
mapView.setLatLon(l.getLatitude(), l.getLongitude());
mapView.setIntZoom(settings.getLastKnownMapZoom());
} else {
intentLocation = false;
}
settings.MAP_ACTIVITY_ENABLED.set(true);
showAndHideMapPosition();
readLocationToShow();
OsmandPlugin.checkInstalledMarketPlugins(app, this);
OsmandPlugin.onMapActivityResume(this);
intentHelper.parseContentIntent();
mapView.refreshMap(true);
if (atlasMapRendererView != null) {
atlasMapRendererView.handleOnResume();
}
app.getLauncherShortcutsHelper().updateLauncherShortcuts();
app.getDownloadThread().setUiActivity(this);
boolean routeWasFinished = routingHelper.isRouteWasFinished();
if (routeWasFinished && !DestinationReachedMenu.wasShown()) {
DestinationReachedMenu.show(this);
}
routingHelper.addListener(this);
app.getMapMarkersHelper().addListener(this);
QuickSearchDialogFragment searchDialogFragment = getQuickSearchDialogFragment();
if (searchDialogFragment != null) {
if (searchDialogFragment.isSearchHidden()) {
searchDialogFragment.hide();
searchDialogFragment.restoreToolbar();
}
}
if (System.currentTimeMillis() - tm > 50) {
System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
}
boolean showOsmAndWelcomeScreen = true;
final Intent intent = getIntent();
if (intent != null && intent.hasExtra(FirstUsageWelcomeFragment.SHOW_OSMAND_WELCOME_SCREEN)) {
showOsmAndWelcomeScreen = intent.getBooleanExtra(FirstUsageWelcomeFragment.SHOW_OSMAND_WELCOME_SCREEN, true);
}
boolean showWelcomeScreen = ((app.getAppInitializer().isFirstTime() && Version.isDeveloperVersion(app)) || !app.getResourceManager().isAnyMapInstalled()) && FirstUsageWelcomeFragment.SHOW && settings.SHOW_OSMAND_WELCOME_SCREEN.get() && showOsmAndWelcomeScreen && !showStorageMigrationScreen;
if (!showWelcomeScreen && !permissionDone && !app.getAppInitializer().isFirstTime()) {
if (!permissionAsked) {
if (app.isExternalStorageDirectoryReadOnly() && !showStorageMigrationScreen && fragmentManager.findFragmentByTag(SharedStorageWarningFragment.TAG) == null && fragmentManager.findFragmentByTag(SettingsScreenType.DATA_STORAGE.fragmentName) == null) {
if (DownloadActivity.hasPermissionToWriteExternalStorage(this)) {
Bundle args = new Bundle();
args.putBoolean(FIRST_USAGE, true);
BaseSettingsFragment.showInstance(this, SettingsScreenType.DATA_STORAGE, null, args, null);
} else {
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, DownloadActivity.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
}
}
} else {
if (permissionGranted) {
RestartActivity.doRestart(this, getString(R.string.storage_permission_restart_is_required));
} else if (fragmentManager.findFragmentByTag(SettingsScreenType.DATA_STORAGE.fragmentName) == null) {
Bundle args = new Bundle();
args.putBoolean(FIRST_USAGE, true);
BaseSettingsFragment.showInstance(this, SettingsScreenType.DATA_STORAGE, null, args, null);
}
permissionAsked = false;
permissionGranted = false;
permissionDone = true;
}
}
enableDrawer();
if (showWelcomeScreen && FirstUsageWelcomeFragment.showInstance(fragmentManager)) {
SecondSplashScreenFragment.SHOW = false;
} else if (SendAnalyticsBottomSheetDialogFragment.shouldShowDialog(app)) {
SendAnalyticsBottomSheetDialogFragment.showInstance(app, fragmentManager, null);
}
FirstUsageWelcomeFragment.SHOW = false;
if (isFirstScreenShowing() && (!settings.SHOW_OSMAND_WELCOME_SCREEN.get() || !showOsmAndWelcomeScreen)) {
FirstUsageWelcomeFragment welcomeFragment = getFirstUsageWelcomeFragment();
if (welcomeFragment != null) {
welcomeFragment.closeWelcomeFragment();
}
FirstUsageWizardFragment wizardFragment = getFirstUsageWizardFragment();
if (wizardFragment != null) {
wizardFragment.closeWizard();
}
}
if (SecondSplashScreenFragment.SHOW && SecondSplashScreenFragment.showInstance(fragmentManager)) {
SecondSplashScreenFragment.SHOW = false;
SecondSplashScreenFragment.VISIBLE = true;
mapView.setOnDrawMapListener(this);
splashScreenTimer = new Timer();
splashScreenTimer.schedule(new TimerTask() {
@Override
public void run() {
app.runInUIThread(() -> dismissSecondSplashScreen());
}
}, SECOND_SPLASH_TIME_OUT);
} else {
if (SecondSplashScreenFragment.VISIBLE) {
dismissSecondSplashScreen();
}
applyScreenOrientation();
}
settings.MAP_SCREEN_ORIENTATION.addListener(mapScreenOrientationSettingListener);
settings.USE_SYSTEM_SCREEN_TIMEOUT.addListener(useSystemScreenTimeoutListener);
extendedMapActivity.onResume(this);
}
use of net.osmand.plus.helpers.TargetPointsHelper 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();
}
Aggregations