use of net.osmand.Location in project Osmand by osmandapp.
the class MapActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(AndroidUiHelper.getScreenOrientation(this));
long tm = System.currentTimeMillis();
app = getMyApplication();
settings = app.getSettings();
app.applyTheme(this);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
boolean portraitMode = AndroidUiHelper.isOrientationPortrait(this);
boolean largeDevice = AndroidUiHelper.isXLargeDevice(this);
landscapeLayout = !portraitMode && !largeDevice;
mapContextMenu.setMapActivity(this);
super.onCreate(savedInstanceState);
// Full screen is not used here
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
if (Build.VERSION.SDK_INT >= 21) {
enterToFullScreen();
// Navigation Drawer:
AndroidUtils.addStatusBarPadding21v(this, findViewById(R.id.menuItems));
}
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int w = dm.widthPixels;
int h = dm.heightPixels - statusBarHeight;
mapView = new OsmandMapTileView(this, w, h);
if (app.getAppInitializer().checkAppVersionChanged() && WhatsNewDialogFragment.SHOW) {
SecondSplashScreenFragment.SHOW = false;
WhatsNewDialogFragment.SHOW = false;
new WhatsNewDialogFragment().show(getSupportFragmentManager(), null);
}
mapActions = new MapActivityActions(this);
mapLayers = new MapActivityLayers(this);
if (mapViewTrackingUtilities == null) {
mapViewTrackingUtilities = new MapViewTrackingUtilities(app);
}
dashboardOnMap.createDashboardView();
checkAppInitialization();
parseLaunchIntentLocation();
mapView.setTrackBallDelegate(new OsmandMapTileView.OnTrackBallListener() {
@Override
public boolean onTrackBallEvent(MotionEvent e) {
showAndHideMapPosition();
return MapActivity.this.onTrackballEvent(e);
}
});
mapView.setAccessibilityActions(new MapAccessibilityActions(this));
mapViewTrackingUtilities.setMapView(mapView);
// to not let it gc
downloaderCallback = new IMapDownloaderCallback() {
@Override
public void tileDownloaded(DownloadRequest request) {
if (request != null && !request.error && request.fileToSave != null) {
ResourceManager mgr = app.getResourceManager();
mgr.tileDownloaded(request);
}
if (request == null || !request.error) {
mapView.tileDownloaded(request);
}
}
};
app.getResourceManager().getMapTileDownloader().addDownloaderCallback(downloaderCallback);
createProgressBarForRouting();
mapLayers.createLayers(mapView);
updateStatusBarColor();
// it tries to continue the last route
if (settings.FOLLOW_THE_ROUTE.get() && !app.getRoutingHelper().isRouteCalculated() && !app.getRoutingHelper().isRouteBeingCalculated()) {
FailSafeFuntions.restoreRoutingMode(this);
} else if (!app.getRoutingHelper().isRoutePlanningMode() && !settings.FOLLOW_THE_ROUTE.get() && app.getTargetPointsHelper().getAllPoints().size() > 0) {
app.getRoutingHelper().clearCurrentRoute(null, new ArrayList<LatLon>());
app.getTargetPointsHelper().removeAllWayPoints(false, false);
}
if (!settings.isLastKnownMapLocation()) {
// show first time when application ran
net.osmand.Location location = app.getLocationProvider().getFirstTimeRunDefaultLocation();
mapViewTrackingUtilities.setMapLinkedToLocation(true);
if (location != null) {
mapView.setLatLon(location.getLatitude(), location.getLongitude());
mapView.setIntZoom(14);
}
}
addDialogProvider(mapActions);
OsmandPlugin.onMapActivityCreate(this);
importHelper = new ImportHelper(this, getMyApplication(), getMapView());
wakeLockHelper = new WakeLockHelper(getMyApplication());
if (System.currentTimeMillis() - tm > 50) {
System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
}
mapView.refreshMap(true);
mapActions.updateDrawerMenu();
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
screenOffReceiver = new ScreenOffReceiver();
registerReceiver(screenOffReceiver, filter);
app.getAidlApi().onCreateMapActivity(this);
mIsDestroyed = false;
}
use of net.osmand.Location in project Osmand by osmandapp.
the class SearchPOIActivity method updateLocation.
@Override
public void updateLocation(net.osmand.Location location) {
boolean handled = false;
if (location != null && filter != null) {
net.osmand.Location searchedLocation = lastSearchedLocation;
if (searchedLocation == null) {
if (!isNameSearch()) {
runNewSearchQuery(location, NEW_SEARCH_INIT);
}
handled = true;
} else if (location.distanceTo(searchedLocation) > MIN_DISTANCE_TO_RESEARCH) {
searchedLocation = location;
runNewSearchQuery(location, SEARCH_AGAIN);
handled = true;
} else if (location.distanceTo(searchedLocation) > MIN_DISTANCE_TO_REFRESH) {
handled = true;
}
} else {
if (location != null) {
handled = true;
}
}
if (handled) {
this.location = location;
ListView lv = getListView();
final int index = lv.getFirstVisiblePosition();
View v = lv.getChildAt(0);
final int top = (v == null) ? 0 : v.getTop();
accessibilityAssistant.lockEvents();
amenityAdapter.notifyDataSetChanged();
lv.setSelectionFromTop(index, top);
updateButtonState(false);
accessibilityAssistant.unlockEvents();
navigationInfo.updateLocation(location);
}
}
use of net.osmand.Location in project Osmand by osmandapp.
the class SearchPOIActivity method updateIntent.
public void updateIntent(Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle.containsKey(SEARCH_LAT) && bundle.containsKey(SEARCH_LON)) {
// $NON-NLS-1$
location = new net.osmand.Location("internal");
location.setLatitude(bundle.getDouble(SEARCH_LAT));
location.setLongitude(bundle.getDouble(SEARCH_LON));
}
searchNearBy = bundle.containsKey(SEARCH_NEARBY);
String filterId = bundle.getString(AMENITY_FILTER);
this.filter = app.getPoiFilters().getFilterById(filterId);
if (filter != null) {
if (filter.isEmpty() && !isNameSearch()) {
showEditActivity(filter);
} else {
filter.clearPreviousZoom();
// run query again
runNewSearchQuery(location, NEW_SEARCH_INIT);
}
} else {
amenityAdapter.setNewModel(Collections.<Amenity>emptyList());
finish();
}
}
use of net.osmand.Location in project Osmand by osmandapp.
the class TargetPointsHelper method updateRoutingHelper.
private void updateRoutingHelper() {
LatLon start = settings.getPointToStart();
Location lastKnownLocation = ctx.getLocationProvider().getLastKnownLocation();
List<LatLon> is = getIntermediatePointsLatLonNavigation();
if ((routingHelper.isFollowingMode() && lastKnownLocation != null) || start == null) {
routingHelper.setFinalAndCurrentLocation(settings.getPointToNavigate(), is, lastKnownLocation);
} else {
Location loc = wrap(start);
routingHelper.setFinalAndCurrentLocation(settings.getPointToNavigate(), is, loc);
}
}
use of net.osmand.Location in project Osmand by osmandapp.
the class TargetPointsHelper method wrap.
private Location wrap(LatLon l) {
if (l == null) {
return null;
}
Location loc = new Location("map");
loc.setLatitude(l.getLatitude());
loc.setLongitude(l.getLongitude());
return loc;
}
Aggregations