Search in sources :

Example 21 with Location

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;
}
Also used : IntentFilter(android.content.IntentFilter) IMapDownloaderCallback(net.osmand.map.MapTileDownloader.IMapDownloaderCallback) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) ArrayList(java.util.ArrayList) DownloadRequest(net.osmand.map.MapTileDownloader.DownloadRequest) WhatsNewDialogFragment(net.osmand.plus.dialogs.WhatsNewDialogFragment) ResourceManager(net.osmand.plus.resources.ResourceManager) DisplayMetrics(android.util.DisplayMetrics) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) MapAccessibilityActions(net.osmand.access.MapAccessibilityActions) MotionEvent(android.view.MotionEvent) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) WakeLockHelper(net.osmand.plus.helpers.WakeLockHelper) ImportHelper(net.osmand.plus.helpers.ImportHelper) Location(net.osmand.Location)

Example 22 with Location

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);
    }
}
Also used : ListView(android.widget.ListView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) Location(net.osmand.Location)

Example 23 with 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();
    }
}
Also used : Bundle(android.os.Bundle) Location(net.osmand.Location)

Example 24 with Location

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);
    }
}
Also used : LatLon(net.osmand.data.LatLon) Location(net.osmand.Location)

Example 25 with Location

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;
}
Also used : Location(net.osmand.Location)

Aggregations

Location (net.osmand.Location)105 LatLon (net.osmand.data.LatLon)37 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)29 ArrayList (java.util.ArrayList)21 LocationPoint (net.osmand.data.LocationPoint)21 View (android.view.View)13 OsmandApplication (net.osmand.plus.OsmandApplication)12 Paint (android.graphics.Paint)11 TextView (android.widget.TextView)11 ImageView (android.widget.ImageView)10 RouteDataObject (net.osmand.binary.RouteDataObject)9 WptPt (net.osmand.plus.GPXUtilities.WptPt)9 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)7 PointDescription (net.osmand.data.PointDescription)6 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 IOException (java.io.IOException)5 QuadPoint (net.osmand.data.QuadPoint)5 MapActivity (net.osmand.plus.activities.MapActivity)5