Merge branch 'r3.3'

This commit is contained in:
Chumva 2019-03-21 11:42:37 +02:00
commit 3bec665fdc
18 changed files with 181 additions and 43 deletions

View file

@ -4,6 +4,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.MapObject;
import net.osmand.data.QuadPoint;

View file

@ -11,6 +11,10 @@
Thx - Hardy
-->
<string name="shared_string_degrees">Degrees</string>
<string name="shared_string_milliradians">Milliradians</string>
<string name="angular_measeurement">Angular measurement units</string>
<string name="angular_measeurement_descr">Change what azimuth is measured in.</string>
<string name="avoid_pt_types_descr">Select public transport types to avoid for navigation:</string>
<string name="quick_action_day_night_mode">%s mode</string>
<string name="avoid_pt_types">Avoid transport types…</string>

View file

@ -9,6 +9,7 @@
<!-- ListPreference android:key="map_preferred_locale" android:title="@string/map_preferred_locale" android:summary="@string/map_preferred_locale_descr"></ListPreference -->
<ListPreference android:key="default_metric_system" android:title="@string/unit_of_length" android:summary="@string/unit_of_length_descr"></ListPreference>
<ListPreference android:key="coordinates_format" android:title="@string/coords_format" android:summary="@string/coords_format_descr"></ListPreference>
<ListPreference android:key="angular_measurement" android:title="@string/angular_measeurement" android:summary="@string/angular_measeurement_descr"></ListPreference>
</PreferenceCategory>

View file

@ -9,6 +9,7 @@ import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.plus.OsmandSettings.AngularConstants;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.OsmandSettings.SpeedConstants;
import net.osmand.util.Algorithms;
@ -165,7 +166,23 @@ public class OsmAndFormatter {
return df.format(meters / mainUnitInMeters) + " " + app.getString(mainUnitStr);
}
public static String getFormattedAzimuth(float bearing, OsmandApplication app) {
int azimuth;
if (bearing < 0.0) {
azimuth = (int) (360 + bearing);
} else {
azimuth = (int) bearing;
}
if (app.getSettings().ANGULAR_UNITS.get() == AngularConstants.MILLIRADS) {
return (int) (azimuth * 17.4533) + " " + AngularConstants.MILLIRADS.getUnitSymbol();
} else {
return azimuth + AngularConstants.DEGREES.getUnitSymbol();
}
}
public static String getFormattedDistance(float meters, OsmandApplication ctx) {
return getFormattedDistance(meters, ctx, true);
}

View file

@ -930,6 +930,17 @@ public class OsmandSettings {
;
}.makeGlobal();
//public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeGlobal();
public final OsmandPreference<AngularConstants> ANGULAR_UNITS = new EnumIntPreference<AngularConstants>(
"angular_measurement", AngularConstants.DEGREES, AngularConstants.values()) {
@Override
protected AngularConstants getValue(Object prefs, AngularConstants defaultValue) {
return super.getValue(prefs, defaultValue);
}
}.makeGlobal();
public final OsmandPreference<SpeedConstants> SPEED_SYSTEM = new EnumIntPreference<SpeedConstants>(
"default_speed_system", SpeedConstants.KILOMETERS_PER_HOUR, SpeedConstants.values()) {
@ -2900,6 +2911,27 @@ public class OsmandSettings {
}
public enum AngularConstants {
DEGREES(R.string.shared_string_degrees, "°"),
MILLIRADS(R.string.shared_string_milliradians, "mil");
private final int key;
private final String unit;
AngularConstants(int key, String unit) {
this.key = key;
this.unit = unit;
}
public String toHumanString(Context ctx) {
return ctx.getString(key);
}
public String getUnitSymbol() {
return unit;
}
}
public enum AutoZoomMap {
FARTHEST(R.string.auto_zoom_farthest, 1f, 15.5f),
FAR(R.string.auto_zoom_far, 1.4f, 17f),

View file

@ -443,6 +443,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override
public void start() {
setupRouteCalculationProgressBar(pb);
mapRouteInfoMenu.routeCalculationStarted();
}
@Override
@ -1499,8 +1500,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if (zoom != null) {
z = Integer.parseInt(zoom);
}
settings.setMapLocationToShow(lt, ln, z, new PointDescription(
PointDescription.POINT_TYPE_MARKER, getString(R.string.shared_location)));
settings.setMapLocationToShow(lt, ln, z, new PointDescription(lt, ln));
} catch (NumberFormatException e) {
LOG.error("error", e);
}

View file

@ -38,6 +38,7 @@ import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.AngularConstants;
import net.osmand.plus.OsmandSettings.DrivingRegion;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.R;
@ -209,6 +210,13 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
entries[4] = PointDescription.formatToHumanString(this, PointDescription.OLC_FORMAT);
registerListPreference(settings.COORDINATES_FORMAT, screen, entries, cvls);
AngularConstants[] ac = AngularConstants.values();
entries = new String[ac.length];
for (int i = 0; i < entries.length; i++) {
entries[i] = ac[i].toHumanString(getMyApplication());
}
registerListPreference(settings.ANGULAR_UNITS, screen, entries, ac);
// See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/
// Hardy maintenance 2016-05-29:
// - Include languages if their translation is >= ~10% (but any language will be visible if it is the device's system locale)

View file

@ -63,11 +63,6 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TargetPoint start = targetPointsHelper.getPointToStart();
if (start != null) {
targetPointsHelper.navigateToPoint(new LatLon(start.getLatitude(), start.getLongitude()),
false, 0, start.getOriginalPointDescription());
}
targetPointsHelper.setStartPoint(latLon, true, name);
dismiss();
}

View file

@ -704,11 +704,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}
private List<TransportStopRoute> filterNearbyTransportRoutes(List<TransportStopRoute> routes, List<TransportStopRoute> filterFromRoutes) {
if (filterFromRoutes == null) {
return routes;
List<TransportStopRoute> nearbyFilteredTransportStopRoutes = filterTransportRoutes(routes);
if (filterFromRoutes == null || filterFromRoutes.isEmpty()) {
return nearbyFilteredTransportStopRoutes;
}
List<TransportStopRoute> filteredRoutes = new ArrayList<>();
for (TransportStopRoute route : routes) {
for (TransportStopRoute route : nearbyFilteredTransportStopRoutes) {
if (!containsRef(filterFromRoutes, route.route)) {
filteredRoutes.add(route);
}

View file

@ -360,9 +360,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
measurementLayer.setOnMeasureDistanceToCenterListener(new MeasurementToolLayer.OnMeasureDistanceToCenter() {
@Override
public void onMeasure(float distance) {
public void onMeasure(float distance, float bearing) {
String distStr = OsmAndFormatter.getFormattedDistance(distance, mapActivity.getMyApplication());
distanceToCenterTv.setText(" " + distStr);
String azimuthStr = OsmAndFormatter.getFormattedAzimuth(bearing, getMyApplication());
distanceToCenterTv.setText(String.format(" %s • %s", distStr, azimuthStr));
}
});

View file

@ -7,6 +7,7 @@ import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
@ -201,12 +202,16 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
drawCenterIcon(canvas, tb, tb.getCenterPixelPoint(), settings.isNightMode());
if (measureDistanceToCenterListener != null) {
float distance = 0;
float bearing = 0;
if (editingCtx.getPointsCount() > 0) {
WptPt lastPoint = editingCtx.getPoints().get(editingCtx.getPointsCount() - 1);
LatLon centerLatLon = tb.getCenterLatLon();
distance = (float) MapUtils.getDistance(lastPoint.lat, lastPoint.lon, centerLatLon.getLatitude(), centerLatLon.getLongitude());
distance = (float) MapUtils.getDistance(
lastPoint.lat, lastPoint.lon, centerLatLon.getLatitude(), centerLatLon.getLongitude());
bearing = getLocationFromLL(lastPoint.lat, lastPoint.lon)
.bearingTo(getLocationFromLL(centerLatLon.getLatitude(), centerLatLon.getLongitude()));
}
measureDistanceToCenterListener.onMeasure(distance);
measureDistanceToCenterListener.onMeasure(distance, bearing);
}
}
@ -411,6 +416,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
return false;
}
private Location getLocationFromLL(double lat, double lon) {
Location l = new Location("");
l.setLatitude(lat);
l.setLongitude(lon);
return l;
}
interface OnSingleTapListener {
void onAddPoint();
@ -423,6 +435,6 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
}
interface OnMeasureDistanceToCenter {
void onMeasure(float distance);
void onMeasure(float distance, float bearing);
}
}

View file

@ -13,6 +13,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.Location;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
@ -31,6 +32,7 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementTool
private MeasurementAdapterListener listener;
private boolean nightMode;
private final ActionType actionType;
private final static String BULLET = "";
public MeasurementToolAdapter(MapActivity mapActivity, List<WptPt> points, ActionType actionType) {
this.mapActivity = mapActivity;
@ -88,15 +90,29 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementTool
if (!TextUtils.isEmpty(pointDesc)) {
holder.descr.setText(pointDesc);
} else {
String text = "";
Location l1;
Location l2;
if (pos < 1) {
holder.descr.setText(mapActivity.getString(R.string.shared_string_control_start));
text = mapActivity.getString(R.string.shared_string_control_start);
if (mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null) {
l1 = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
l2 = getLocationFromLL(points.get(0).lat, points.get(0).lon);
text = text
+ BULLET + OsmAndFormatter.getFormattedDistance(l1.distanceTo(l2), mapActivity.getMyApplication())
+ BULLET + OsmAndFormatter.getFormattedAzimuth(l1.bearingTo(l2), mapActivity.getMyApplication());
}
holder.descr.setText(text);
} else {
float dist = 0;
for (int i = 1; i <= pos; i++) {
dist += MapUtils.getDistance(points.get(i - 1).lat, points.get(i - 1).lon,
points.get(i).lat, points.get(i).lon);
l1 = getLocationFromLL(points.get(i - 1).lat, points.get(i - 1).lon);
l2 = getLocationFromLL(points.get(i).lat, points.get(i).lon);
dist += l1.distanceTo(l2);
text = OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication())
+ BULLET + OsmAndFormatter.getFormattedAzimuth(l1.bearingTo(l2), mapActivity.getMyApplication());
}
holder.descr.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
holder.descr.setText(text);
}
}
if (actionType == ActionType.EDIT_SEGMENT) {
@ -131,6 +147,13 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementTool
});
}
private Location getLocationFromLL(double lat, double lon) {
Location l = new Location("");
l.setLatitude(lat);
l.setLongitude(lon);
return l;
}
@Override
public int getItemCount() {
return points.size();

View file

@ -55,7 +55,6 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.AvoidSpecificRoads;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
@ -388,6 +387,17 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
}
}
public void routeCalculationStarted() {
WeakReference<MapRouteInfoMenuFragment> fragmentRef = findMenuFragment();
MapRouteInfoMenuFragment fragment = fragmentRef != null ? fragmentRef.get() : null;
if (fragmentRef != null && fragment.isVisible()) {
setRouteCalculationInProgress(true);
fragment.updateRouteCalculationProgress(0);
fragment.updateControlButtons();
fragment.updateInfo();
}
}
public void updateRouteCalculationProgress(int progress) {
WeakReference<MapRouteInfoMenuFragment> fragmentRef = findMenuFragment();
MapRouteInfoMenuFragment fragment = fragmentRef != null ? fragmentRef.get() : null;
@ -403,12 +413,17 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
public void routeCalculationFinished() {
WeakReference<MapRouteInfoMenuFragment> fragmentRef = findMenuFragment();
MapRouteInfoMenuFragment fragment = fragmentRef != null ? fragmentRef.get() : null;
if (fragmentRef != null && fragment.isVisible()) {
setRouteCalculationInProgress(false);
fragment.hideRouteCalculationProgressBar();
fragment.updateControlButtons();
fragment.updateInfo();
fragment.openMenuHalfScreen();
OsmandApplication app = getApp();
if (app != null && fragmentRef != null && fragment.isVisible()) {
boolean routeCalculating = app.getRoutingHelper().isRouteBeingCalculated() || app.getTransportRoutingHelper().isRouteBeingCalculated();
if (setRouteCalculationInProgress(routeCalculating)) {
fragment.updateControlButtons();
fragment.updateInfo();
if (!routeCalculationInProgress) {
fragment.hideRouteCalculationProgressBar();
fragment.openMenuHalfScreen();
}
}
}
}
@ -466,7 +481,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
mainView = main;
OsmandApplication app = mapActivity.getMyApplication();
nightMode = app.getDaynightHelper().isNightModeForMapControls();
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
updateStartPointView();
updateWaypointsView();
@ -476,11 +490,26 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
updateApplicationModesOptions();
updateOptionsButtons();
updateCards();
}
private void updateCards() {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return;
}
OsmandApplication app = mapActivity.getMyApplication();
nightMode = app.getDaynightHelper().isNightModeForMapControls();
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
RoutingHelper routingHelper = app.getRoutingHelper();
menuCards.clear();
boolean bottomShadowVisible = true;
if (isBasicRouteCalculated()) {
GPXFile gpx = GpxUiHelper.makeGpxFromRoute(app.getRoutingHelper().getRoute(), app);
GPXFile gpx = GpxUiHelper.makeGpxFromRoute(routingHelper.getRoute(), app);
if (gpx != null) {
menuCards.add(new SimpleRouteCard(mapActivity, gpx));
}
@ -498,8 +527,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
}
bottomShadowVisible = routes.size() == 0;
} else if (routeCalculationInProgress) {
WarningCard warningCard = new WarningCard(mapActivity);
menuCards.add(warningCard);
if (app.getTargetPointsHelper().hasTooLongDistanceToNavigate() || routingHelper.isPublicTransportMode()) {
// WarningCard card
WarningCard warningCard = new WarningCard(mapActivity);
menuCards.add(warningCard);
}
} else {
// Home/work card
HomeWorkCard homeWorkCard = new HomeWorkCard(mapActivity);

View file

@ -32,12 +32,10 @@ import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.osm.edit.Node;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.LockableScrollView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
@ -46,7 +44,6 @@ import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.widgets.ImageViewExProgress;
import net.osmand.plus.widgets.TextViewExProgress;
import net.osmand.router.TransportRoutePlanner.TransportRouteResult;
import net.osmand.util.MapUtils;
@ -629,6 +626,11 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
boolean canceled = false;
@Override
public void onAnimationStart(Animator animation) {
moving = true;
}
@Override
public void onAnimationCancel(Animator animation) {
canceled = true;
@ -636,6 +638,7 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
@Override
public void onAnimationEnd(Animator animation) {
moving = false;
if (!canceled) {
if (needCloseMenu) {
menu.hide();
@ -798,7 +801,9 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
if (menu != null) {
menu.updateInfo(view);
applyDayNightMode();
runLayoutListener();
if (!moving) {
runLayoutListener();
}
}
}
@ -836,9 +841,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
}
TextViewExProgress textViewExProgress = (TextViewExProgress) view.findViewById(R.id.start_button_descr);
textViewExProgress.percent = progress / 100f;
int color = nightMode ? R.color.main_font_dark : R.color.card_and_list_background_light;
textViewExProgress.color1 = ContextCompat.getColor(mapActivity, color);
textViewExProgress.color2 = ContextCompat.getColor(mapActivity, R.color.description_font_and_bottom_sheet_icons);
textViewExProgress.invalidate();
}

View file

@ -1901,7 +1901,10 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
public CumulativeInfo getRouteDirectionCumulativeInfo(int position, List<RouteDirectionInfo> routeDirections) {
CumulativeInfo cumulativeInfo = new CumulativeInfo();
for (int i = position; i < routeDirections.size(); i++) {
if (position >= routeDirections.size()) {
return cumulativeInfo;
}
for (int i = 0; i < position; i++) {
RouteDirectionInfo routeDirectionInfo = routeDirections.get(i);
cumulativeInfo.time += routeDirectionInfo.getExpectedTime();
cumulativeInfo.distance += routeDirectionInfo.distance;

View file

@ -64,6 +64,7 @@ public class RoutingHelper {
private String lastRouteCalcErrorShort;
private long recalculateCountInInterval = 0;
private int evalWaitInterval = 0;
private boolean waitingNextJob;
private ApplicationMode mode;
private OsmandSettings settings;
@ -872,6 +873,7 @@ public class RoutingHelper {
public void run() {
synchronized (RoutingHelper.this) {
currentRunningJob = this;
waitingNextJob = prevRunningJob != null;
}
if(prevRunningJob != null) {
while(prevRunningJob.isAlive()){
@ -883,6 +885,7 @@ public class RoutingHelper {
}
synchronized (RoutingHelper.this) {
currentRunningJob = this;
waitingNextJob = false;
}
}
lastRouteCalcError = null;
@ -1086,8 +1089,8 @@ public class RoutingHelper {
return mode == ApplicationMode.PUBLIC_TRANSPORT;
}
public boolean isRouteBeingCalculated(){
return currentRunningJob instanceof RouteRecalculationThread;
public boolean isRouteBeingCalculated() {
return currentRunningJob instanceof RouteRecalculationThread || waitingNextJob;
}
private void showMessage(final String msg){

View file

@ -63,6 +63,7 @@ public class TransportRoutingHelper {
private String lastRouteCalcError;
private String lastRouteCalcErrorShort;
private long lastTimeEvaluatedRoute = 0;
private boolean waitingNextJob;
private TransportRouteCalculationProgressCallback progressRoute;
@ -253,7 +254,7 @@ public class TransportRoutingHelper {
}
public boolean isRouteBeingCalculated() {
return currentRunningJob instanceof RouteRecalculationThread;
return currentRunningJob instanceof RouteRecalculationThread || waitingNextJob;
}
private void setNewRoute(final List<TransportRouteResult> res) {
@ -584,6 +585,7 @@ public class TransportRoutingHelper {
public void run() {
synchronized (TransportRoutingHelper.this) {
currentRunningJob = this;
waitingNextJob = prevRunningJob != null;
}
if (prevRunningJob != null) {
while (prevRunningJob.isAlive()) {
@ -595,6 +597,7 @@ public class TransportRoutingHelper {
}
synchronized (TransportRoutingHelper.this) {
currentRunningJob = this;
waitingNextJob = false;
}
}

View file

@ -681,7 +681,7 @@ public class RouteInfoWidgetsFactory {
if (degreesChanged(cachedDegrees, b) || modeChanged) {
cachedDegrees = b;
if (b != -1000) {
setText(String.valueOf(b) + "°" + (relative ? "" : " M"), null);
setText(OsmAndFormatter.getFormattedAzimuth(b, getOsmandApplication()) + (relative ? "" : " M"), null);
} else {
setText(null, null);
}