From fa424cb5610b846c0ad4474177f06c2d4501b3d8 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Thu, 27 Jun 2019 15:23:52 +0300 Subject: [PATCH] #7076 - added info in current location in context menu --- .../src/main/java/net/osmand/Location.java | 43 +++++++++++++- OsmAnd/res/values/strings.xml | 2 + .../osmand/plus/OsmAndLocationProvider.java | 7 +++ .../plus/mapcontextmenu/MenuController.java | 57 +++++++++++++++++++ .../controllers/MyLocationMenuController.java | 3 +- 5 files changed, 109 insertions(+), 3 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/Location.java b/OsmAnd-java/src/main/java/net/osmand/Location.java index 70b96d3854..615e96f0a7 100644 --- a/OsmAnd-java/src/main/java/net/osmand/Location.java +++ b/OsmAnd-java/src/main/java/net/osmand/Location.java @@ -41,6 +41,8 @@ public class Location { private float mBearing = 0.0f; private boolean mHasAccuracy = false; private float mAccuracy = 0.0f; + private boolean mHasVerticalAccuracy = false; + private float mVerticalAccuracy = 0.0f; // Cache the inputs and outputs of computeDistanceAndBearing // so calls to distanceTo() and bearingTo() can share work @@ -89,6 +91,8 @@ public class Location { mBearing = l.mBearing; mHasAccuracy = l.mHasAccuracy; mAccuracy = l.mAccuracy; + mHasVerticalAccuracy = l.mHasVerticalAccuracy; + mVerticalAccuracy = l.mVerticalAccuracy; } /** @@ -494,6 +498,41 @@ public class Location { mHasAccuracy = false; } + + /** + * Returns true if the provider is able to report vertical accuracy information, + * false otherwise. The default implementation returns false. + */ + public boolean hasVerticalAccuracy() { + return mHasVerticalAccuracy; + } + + /** + * Returns the accuracy of the fix in meters. If hasVerticalAccuracy() is false, + * 0.0 is returned. + */ + public float getVerticalAccuracy() { + return mVerticalAccuracy; + } + + /** + * Sets the accuracy of this fix. Following this call, hasVerticalAccuracy() + * will return true. + */ + public void setVerticalAccuracy(float verticalAccuracy) { + this.mVerticalAccuracy = verticalAccuracy; + mHasVerticalAccuracy = true; + } + + /** + * Clears the vertical accuracy of this fix. Following this call, hasVerticalAccuracy() + * will return false. + */ + public void removeVerticalAccuracy() { + mVerticalAccuracy = 0.0f; + mHasVerticalAccuracy = false; + } + @Override public String toString() { return "Location[mProvider=" + mProvider + ",mTime=" + mTime + @@ -506,7 +545,9 @@ public class Location { ",mHasBearing=" + mHasBearing + ",mBearing=" + mBearing + ",mHasAccuracy=" + mHasAccuracy + - ",mAccuracy=" + mAccuracy; + ",mAccuracy=" + mAccuracy + + ",mHasVerticalAccuracy=" + mHasVerticalAccuracy + + ",mVerticalAccuracy=" + mVerticalAccuracy; } diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index cac2b5cbeb..a9b22d3df3 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,8 @@ Thx - Hardy --> + Precision horizontal: %1$s, vertical: %2$s + Precision horizontal: %s Personal transporter Monowheel Scooter diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index dbf7fb8d03..bee5ec06d0 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -1,5 +1,7 @@ package net.osmand.plus; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -667,6 +669,11 @@ public class OsmAndLocationProvider implements SensorEventListener { if (l.hasAccuracy()) { r.setAccuracy(l.getAccuracy()); } + if (VERSION.SDK_INT >= VERSION_CODES.O) { + if (l.hasVerticalAccuracy()) { + r.setVerticalAccuracy(l.getVerticalAccuracyMeters()); + } + } if (l.hasSpeed()) { r.setSpeed(l.getSpeed()); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index c8d7f8fe6d..1ac4aeff1d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -20,7 +20,9 @@ import android.widget.LinearLayout; import java.util.Map; import net.osmand.AndroidUtils; import net.osmand.IndexConstants; +import net.osmand.Location; import net.osmand.NativeLibrary.RenderedObject; +import net.osmand.PlatformUtil; import net.osmand.aidl.maplayer.point.AMapPoint; import net.osmand.binary.BinaryMapDataObject; import net.osmand.binary.BinaryMapIndexReader.TagValuePair; @@ -35,6 +37,8 @@ import net.osmand.map.WorldRegion; import net.osmand.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; @@ -85,6 +89,7 @@ import java.lang.ref.WeakReference; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import org.apache.commons.logging.Log; public abstract class MenuController extends BaseMenuController implements CollapseExpandListener { @@ -126,6 +131,8 @@ public abstract class MenuController extends BaseMenuController implements Colla protected List openingHoursInfo; + private static final Log LOG = PlatformUtil.getLog(MenuController.class); + public MenuController(MenuBuilder builder, PointDescription pointDescription, MapActivity mapActivity) { super(mapActivity); this.pointDescription = pointDescription; @@ -270,6 +277,11 @@ public abstract class MenuController extends BaseMenuController implements Colla } public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { + if (pointDescription.isMyLocation()) { + addSpeedToPlainItems(); + addAltitudeToPlainItems(); + addPrecisionToPlainItems(); + } addMyLocationToPlainItems(latLon); } @@ -283,6 +295,51 @@ public abstract class MenuController extends BaseMenuController implements Colla } } + protected void addSpeedToPlainItems() { + final MapActivity mapActivity = getMapActivity(); + if (getMapActivity() != null) { + final OsmandApplication app = mapActivity.getMyApplication(); + Location l = app.getLocationProvider().getLastKnownLocation(); + if (l != null && l.hasSpeed() && l.getSpeed() > 0f) { + String speed = OsmAndFormatter.getFormattedSpeed(l.getSpeed(), app); + addPlainMenuItem(R.drawable.ic_action_speed, null, speed, false, false, null); + } + } + } + + protected void addAltitudeToPlainItems() { + final MapActivity mapActivity = getMapActivity(); + final OsmandApplication app = mapActivity.getMyApplication(); + if (getMapActivity() != null && app != null) { + Location l = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); + if (l != null && l.hasAltitude() && l.getAltitude() > 0f) { + String alt = OsmAndFormatter.getFormattedAlt(l.getAltitude(), app); + addPlainMenuItem(R.drawable.ic_action_altitude_average, null, alt, false, false, null); + } + } + } + + protected void addPrecisionToPlainItems() { + final MapActivity mapActivity = getMapActivity(); + final OsmandApplication app = mapActivity.getMyApplication(); + if (getMapActivity() != null && app != null) { + Location l = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); + if (l != null && l.hasAccuracy()) { + String acc; + if (l.hasVerticalAccuracy()) { + acc = String.format(app.getString(R.string.precision_hdop_and_vdop), + OsmAndFormatter.getFormattedDistance(l.getAccuracy(), app), + OsmAndFormatter.getFormattedDistance(l.getVerticalAccuracy(), app)); + } else { + acc = String.format(app.getString(R.string.precision_hdop), + OsmAndFormatter.getFormattedDistance(l.getAccuracy(), app)); + } + + addPlainMenuItem(R.drawable.ic_action_ruler_circle, null, acc, false, false, null); + } + } + } + public PointDescription getPointDescription() { return pointDescription; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java index b37185175c..237f3d0daf 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java @@ -52,8 +52,7 @@ public class MyLocationMenuController extends MenuController { public Drawable getRightIcon() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - ApplicationMode appMode = mapActivity.getMyApplication().getSettings().getApplicationMode(); - return mapActivity.getResources().getDrawable(appMode.getResourceLocationDay()); + return mapActivity.getResources().getDrawable(R.drawable.ic_action_location_color); } else { return null; }