Merge pull request #7116 from osmandapp/issue_7076

Issue 7076
This commit is contained in:
vshcherb 2019-06-27 17:35:37 +02:00 committed by GitHub
commit a18c3c8b83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 109 additions and 3 deletions

View file

@ -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;
}

View file

@ -22,6 +22,8 @@
• Fixed compass button behavior during navigation\n\n
• Bug fixes\n\n
</string>
<string name="precision_hdop_and_vdop">Precision horizontal: %1$s, vertical: %2$s</string>
<string name="precision_hdop">Precision horizontal: %s</string>
<string name="app_mode_personal_transporter">Personal transporter</string>
<string name="app_mode_monowheel">Monowheel</string>
<string name="app_mode_scooter">Scooter</string>

View file

@ -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());
}

View file

@ -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<OpeningHours.Info> 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;
}

View file

@ -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;
}