Search in sources :

Example 36 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class WaypointDialogHelper method switchStartAndFinish.

// switch start & finish
private static void switchStartAndFinish(TargetPointsHelper targetPointsHelper, TargetPoint finish, Activity ctx, TargetPoint start, OsmandApplication app, WaypointDialogHelper helper) {
    targetPointsHelper.setStartPoint(new LatLon(finish.getLatitude(), finish.getLongitude()), false, finish.getPointDescription(ctx));
    if (start == null) {
        Location loc = app.getLocationProvider().getLastKnownLocation();
        if (loc != null) {
            targetPointsHelper.navigateToPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), true, -1);
        }
    } else {
        targetPointsHelper.navigateToPoint(new LatLon(start.getLatitude(), start.getLongitude()), true, -1, start.getPointDescription(ctx));
    }
    updateControls(ctx, helper);
}
Also used : LatLon(net.osmand.data.LatLon) Location(net.osmand.Location)

Example 37 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class WaypointDialogHelper method sortAllTargets.

@SuppressLint("StaticFieldLeak")
public static void sortAllTargets(final OsmandApplication app, final Activity activity, final WaypointDialogHelper helper) {
    new AsyncTask<Void, Void, int[]>() {

        ProgressDialog dlg = null;

        long startDialogTime = 0;

        List<TargetPoint> intermediates;

        protected void onPreExecute() {
            startDialogTime = System.currentTimeMillis();
            dlg = new ProgressDialog(activity);
            dlg.setTitle("");
            dlg.setMessage(activity.getResources().getString(R.string.intermediate_items_sort_by_distance));
            dlg.show();
        }

        protected int[] doInBackground(Void[] params) {
            TargetPointsHelper targets = app.getTargetPointsHelper();
            intermediates = targets.getIntermediatePointsWithTarget();
            Location cll = app.getLocationProvider().getLastKnownLocation();
            ArrayList<TargetPoint> lt = new ArrayList<>(intermediates);
            TargetPoint start;
            if (cll != null) {
                LatLon ll = new LatLon(cll.getLatitude(), cll.getLongitude());
                start = TargetPoint.create(ll, null);
            } else if (app.getTargetPointsHelper().getPointToStart() != null) {
                TargetPoint ps = app.getTargetPointsHelper().getPointToStart();
                LatLon ll = new LatLon(ps.getLatitude(), ps.getLongitude());
                start = TargetPoint.create(ll, null);
            } else {
                start = lt.get(0);
            }
            TargetPoint end = lt.remove(lt.size() - 1);
            ArrayList<LatLon> al = new ArrayList<>();
            for (TargetPoint p : lt) {
                al.add(p.point);
            }
            return new TspAnt().readGraph(al, start.point, end.point).solve();
        }

        protected void onPostExecute(int[] result) {
            if (dlg != null) {
                long t = System.currentTimeMillis();
                if (t - startDialogTime < 500) {
                    app.runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            dlg.dismiss();
                        }
                    }, 500 - (t - startDialogTime));
                } else {
                    dlg.dismiss();
                }
            }
            List<TargetPoint> alocs = new ArrayList<>();
            for (int i : result) {
                if (i > 0) {
                    TargetPoint loc = intermediates.get(i - 1);
                    alocs.add(loc);
                }
            }
            intermediates.clear();
            intermediates.addAll(alocs);
            TargetPointsHelper targets = app.getTargetPointsHelper();
            List<TargetPoint> cur = targets.getIntermediatePointsWithTarget();
            boolean eq = true;
            for (int j = 0; j < cur.size() && j < intermediates.size(); j++) {
                if (cur.get(j) != intermediates.get(j)) {
                    eq = false;
                    break;
                }
            }
            if (!eq) {
                targets.reorderAllTargetPoints(intermediates, true);
            }
            if (helper.helperCallbacks != null) {
                helper.helperCallbacks.reloadAdapter();
            }
            updateRouteInfoMenu(activity);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ArrayList(java.util.ArrayList) TspAnt(net.osmand.TspAnt) ProgressDialog(android.app.ProgressDialog) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) List(java.util.List) ArrayList(java.util.ArrayList) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) Location(net.osmand.Location) SuppressLint(android.annotation.SuppressLint)

Example 38 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class WaypointDialogHelper method getStandardPoints.

protected List<Object> getStandardPoints() {
    final List<Object> points = new ArrayList<>();
    boolean rc = waypointHelper.isRouteCalculated();
    for (int i = 0; i < WaypointHelper.MAX; i++) {
        List<LocationPointWrapper> tp = waypointHelper.getWaypoints(i);
        if ((rc || i == WaypointHelper.WAYPOINTS || i == WaypointHelper.TARGETS) && waypointHelper.isTypeVisible(i)) {
            if (points.size() > 0) {
                points.add(true);
            }
            points.add(i);
            if (i == WaypointHelper.TARGETS) {
                TargetPoint start = app.getTargetPointsHelper().getPointToStart();
                if (start == null) {
                    LatLon latLon;
                    Location loc = app.getLocationProvider().getLastKnownLocation();
                    if (loc != null) {
                        latLon = new LatLon(loc.getLatitude(), loc.getLongitude());
                    } else {
                        latLon = new LatLon(mapActivity.getMapView().getLatitude(), mapActivity.getMapView().getLongitude());
                    }
                    start = TargetPoint.createStartPoint(latLon, new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActivity.getString(R.string.shared_string_my_location)));
                } else {
                    String oname = start.getOnlyName().length() > 0 ? start.getOnlyName() : (mapActivity.getString(R.string.route_descr_map_location) + " " + mapActivity.getString(R.string.route_descr_lat_lon, start.getLatitude(), start.getLongitude()));
                    start = TargetPoint.createStartPoint(new LatLon(start.getLatitude(), start.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_LOCATION, oname));
                }
                points.add(new LocationPointWrapper(null, WaypointHelper.TARGETS, start, 0f, 0));
            } else if ((i == WaypointHelper.POI || i == WaypointHelper.FAVORITES || i == WaypointHelper.WAYPOINTS) && rc) {
                if (waypointHelper.isTypeEnabled(i)) {
                    points.add(new RadiusItem(i));
                }
            }
            if (tp != null && tp.size() > 0) {
                points.addAll(tp);
            }
            points.add(false);
        }
    }
    return points;
}
Also used : ArrayList(java.util.ArrayList) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) SuppressLint(android.annotation.SuppressLint) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) Location(net.osmand.Location)

Example 39 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class WaypointHelper method getMostImportantAlarm.

public AlarmInfo getMostImportantAlarm(MetricsConstants mc, boolean showCameras) {
    Location lastProjection = app.getRoutingHelper().getLastProjection();
    float mxspeed = route.getCurrentMaxSpeed();
    float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f;
    AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, lastProjection, delta);
    if (speedAlarm != null) {
        getVoiceRouter().announceSpeedAlarm(speedAlarm.getIntValue(), lastProjection.getSpeed());
    }
    AlarmInfo mostImportant = speedAlarm;
    int value = speedAlarm != null ? speedAlarm.updateDistanceAndGetPriority(0, 0) : Integer.MAX_VALUE;
    float speed = lastProjection != null && lastProjection.hasSpeed() ? lastProjection.getSpeed() : 0;
    if (ALARMS < pointsProgress.size()) {
        int kIterator = pointsProgress.get(ALARMS);
        List<LocationPointWrapper> lp = locationPoints.get(ALARMS);
        while (kIterator < lp.size()) {
            AlarmInfo inf = (AlarmInfo) lp.get(kIterator).point;
            int currentRoute = route.getCurrentRoute();
            if (inf.getLocationIndex() < currentRoute && inf.getLastLocationIndex() != -1 && inf.getLastLocationIndex() < currentRoute) {
            // skip
            } else {
                if (inf.getType() == AlarmInfoType.TUNNEL && inf.getLastLocationIndex() != -1 && currentRoute > inf.getLocationIndex() && currentRoute < inf.getLastLocationIndex()) {
                    inf.setFloatValue(route.getDistanceToPoint(inf.getLastLocationIndex()));
                }
                int d = route.getDistanceToPoint(inf.getLocationIndex());
                if (d > LONG_ANNOUNCE_RADIUS) {
                    break;
                }
                float time = speed > 0 ? d / speed : Integer.MAX_VALUE;
                int vl = inf.updateDistanceAndGetPriority(time, d);
                if (vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)) {
                    mostImportant = inf;
                    value = vl;
                }
            }
            kIterator++;
        }
    }
    return mostImportant;
}
Also used : AlarmInfo(net.osmand.plus.routing.AlarmInfo) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location)

Example 40 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class FirstUsageWizardFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    final OsmandApplication app = getMyApplication();
    switch(wizardType) {
        case SEARCH_LOCATION:
            if (searchLocationByIp) {
                final Map<String, String> pms = new LinkedHashMap<>();
                pms.put("version", Version.getFullVersion(app));
                try {
                    pms.put("aid", Secure.getString(app.getContentResolver(), Secure.ANDROID_ID));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                new AsyncTask<Void, Void, String>() {

                    @Override
                    protected String doInBackground(Void... params) {
                        try {
                            return AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/geo-ip", pms, "Requesting location by IP...", false, false);
                        } catch (Exception e) {
                            logError("Requesting location by IP error: ", e);
                            return null;
                        }
                    }

                    @Override
                    protected void onPostExecute(String response) {
                        if (response != null) {
                            try {
                                JSONObject obj = new JSONObject(response);
                                double latitude = obj.getDouble("latitude");
                                double longitude = obj.getDouble("longitude");
                                if (latitude == 0 && longitude == 0) {
                                    showNoLocationFragment(getActivity());
                                } else {
                                    location = new Location("geo-ip");
                                    location.setLatitude(latitude);
                                    location.setLongitude(longitude);
                                    showSearchMapFragment(getActivity());
                                }
                            } catch (Exception e) {
                                logError("JSON parsing error: ", e);
                                showNoLocationFragment(getActivity());
                            }
                        } else {
                            showNoLocationFragment(getActivity());
                        }
                    }
                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                FragmentActivity activity = getActivity();
                if (!OsmAndLocationProvider.isLocationPermissionAvailable(activity)) {
                    ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, FIRST_USAGE_LOCATION_PERMISSION);
                } else {
                    app.getLocationProvider().addLocationListener(this);
                    locationSearchTimer = new Timer();
                    locationSearchTimer.schedule(new TimerTask() {

                        @Override
                        public void run() {
                            FragmentActivity a = getActivity();
                            if (a != null) {
                                showNoLocationFragment(a);
                            }
                        }
                    }, 1000 * 10);
                }
            }
            break;
        case NO_INTERNET:
            break;
        case NO_LOCATION:
            break;
        case SEARCH_MAP:
            if (app.isApplicationInitializing()) {
                app.getAppInitializer().addListener(this);
            } else {
                if (!downloadThread.getIndexes().isDownloadedFromInternet) {
                    waitForIndexes = true;
                    downloadThread.runReloadIndexFilesSilent();
                } else {
                    searchMap();
                }
            }
            break;
        case MAP_FOUND:
            break;
        case MAP_DOWNLOAD:
            if (!startDownload(0)) {
                startDownload(1);
            }
            if (localDownloadRegion != null) {
                downloadThread.initSettingsFirstMap(localDownloadRegion);
            }
            break;
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) FragmentActivity(android.support.v4.app.FragmentActivity) JSONObject(org.json.JSONObject) Timer(java.util.Timer) TimerTask(java.util.TimerTask) 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