Added bearing widget (without icon yet)

This commit is contained in:
Alexey Kulish 2016-04-14 18:56:12 +03:00
parent ddff8519f7
commit 2e2bb2d938
6 changed files with 87 additions and 5 deletions

View file

@ -10,6 +10,7 @@
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="map_widget_bearing">Bearing</string>
<string name="access_disable_offroute_recalc">Don\'t change route when you are off the way</string>
<string name="access_disable_offroute_recalc_descr">Prevent automatic route recalculation when you are quite far from the right way</string>
<string name="access_disable_wrong_direction_recalc">Don\'t change route by wrong direction</string>

View file

@ -67,6 +67,7 @@ public class ApplicationMode {
// right
regWidget("intermediate_distance", exceptDefault);
regWidget("distance", exceptDefault);
regWidget("bearing", none);
regWidget("time", exceptDefault);
regWidget("speed", exceptPedestrianAndDefault);
regWidget("max_speed", CAR);

View file

@ -119,6 +119,8 @@ public class MapInfoLayer extends OsmandMapLayer {
registerSideWidget(intermediateDist, R.drawable.ic_action_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, 3);
TextInfoWidget dist = ric.createDistanceControl(map);
registerSideWidget(dist, R.drawable.ic_action_target, R.string.map_widget_distance, "distance", false, 5);
TextInfoWidget bearing = ric.createBearingControl(map);
registerSideWidget(bearing, R.drawable.ic_action_target, R.string.map_widget_bearing, "bearing", false, 7);
TextInfoWidget time = ric.createTimeControl(map);
registerSideWidget(time, R.drawable.ic_action_time, R.string.map_widget_time, "time", false, 10);

View file

@ -358,7 +358,10 @@ public class MapWidgetRegistry {
Set<MapWidgetRegInfo> groupTitle, final ApplicationMode mode) {
for (final MapWidgetRegInfo r : groupTitle) {
if (mode == ApplicationMode.DEFAULT) {
if ("intermediate_distance".equals(r.key) || "distance".equals(r.key) || "time".equals(r.key)) {
if ("intermediate_distance".equals(r.key)
|| "distance".equals(r.key)
|| "bearing".equals(r.key)
|| "time".equals(r.key)) {
continue;
}
}

View file

@ -4,7 +4,7 @@ package net.osmand.plus.views.mapwidgets;
import java.util.*;
import android.graphics.*;
import android.util.ArrayMap;
import net.osmand.Location;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon;
@ -490,8 +490,79 @@ public class RouteInfoWidgetsFactory {
};
return distanceControl;
}
public abstract static class BearingToPointInfoControl extends TextInfoWidget {
private final OsmandMapTileView view;
private float[] calculations = new float[2];
private int cachedDegrees;
public BearingToPointInfoControl(MapActivity ma, int res, int resNight) {
super(ma);
this.view = ma.getMapView();
if (res != 0 && resNight != 0) {
setIcons(res, resNight);
}
setText(null, null);
setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
click(view);
}
});
}
protected void click(final OsmandMapTileView view) {
AnimateDraggingMapThread thread = view.getAnimatedDraggingThread();
LatLon pointToNavigate = getPointToNavigate();
if (pointToNavigate != null) {
int fZoom = view.getZoom() < 15 ? 15 : view.getZoom();
thread.startMoving(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true);
}
}
@Override
public boolean updateInfo(DrawSettings drawSettings) {
int b = getBearing();
if (distChanged(cachedDegrees, b)) {
cachedDegrees = b;
if (b >= 0) {
setText(String.valueOf(b) + "°", null);
} else {
setText(null, null);
}
return true;
}
return false;
}
public abstract LatLon getPointToNavigate();
public int getBearing() {
int d = -1;
Location myLocation = getOsmandApplication().getLocationProvider().getLastKnownLocation();
LatLon l = getPointToNavigate();
if (myLocation != null && l != null) {
Location.distanceBetween(myLocation.getLatitude(), myLocation.getLongitude(), l.getLatitude(), l.getLongitude(), calculations);
d = (int) calculations[1];
}
return d;
}
}
public TextInfoWidget createBearingControl(final MapActivity map) {
BearingToPointInfoControl bearingControl = new BearingToPointInfoControl(map,R.drawable.widget_target_day,
R.drawable.widget_target_night) {
@Override
public LatLon getPointToNavigate() {
TargetPoint p = map.getPointToNavigate();
return p == null ? null : p.point;
}
};
return bearingControl;
}
private static Path getPathFromTurnType(List<Path> paths, int laneType, Path defaultType, float coef) {
if(laneType == 0) {

View file

@ -42,7 +42,11 @@ public class TextInfoWidget {
smallTextViewShadow = (TextView) view.findViewById(R.id.widget_text_small_shadow);
smallTextView = (TextView) view.findViewById(R.id.widget_text_small);
}
public OsmandApplication getOsmandApplication() {
return app;
}
public View getView() {
return view;
}