use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.
the class RouteInfoWidgetsFactory method createTimeControl.
public TextInfoWidget createTimeControl(final MapActivity map) {
final RoutingHelper routingHelper = map.getRoutingHelper();
final int time = R.drawable.widget_time_day;
final int timeN = R.drawable.widget_time_night;
final int timeToGo = R.drawable.widget_time_to_distance_day;
final int timeToGoN = R.drawable.widget_time_to_distance_night;
final OsmandApplication ctx = map.getMyApplication();
final OsmandPreference<Boolean> showArrival = ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME;
final TextInfoWidget leftTimeControl = new TextInfoWidget(map) {
private long cachedLeftTime = 0;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
setIcons(showArrival.get() ? time : timeToGo, showArrival.get() ? timeN : timeToGoN);
int time = 0;
if (routingHelper != null && routingHelper.isRouteCalculated()) {
// boolean followingMode = routingHelper.isFollowingMode();
time = routingHelper.getLeftTime();
if (time != 0) {
if (/*followingMode && */
showArrival.get()) {
long toFindTime = time * 1000 + System.currentTimeMillis();
if (Math.abs(toFindTime - cachedLeftTime) > 30000) {
cachedLeftTime = toFindTime;
setContentTitle(map.getString(R.string.access_arrival_time));
if (DateFormat.is24HourFormat(ctx)) {
// $NON-NLS-1$
setText(DateFormat.format("k:mm", toFindTime).toString(), null);
} else {
setText(DateFormat.format("h:mm", toFindTime).toString(), // $NON-NLS-1$
DateFormat.format("aa", toFindTime).toString());
}
return true;
}
} else {
if (Math.abs(time - cachedLeftTime) > 30) {
cachedLeftTime = time;
int hours = time / (60 * 60);
int minutes = (time / 60) % 60;
setContentTitle(map.getString(R.string.map_widget_time));
// $NON-NLS-1$
setText(String.format("%d:%02d", hours, minutes), null);
return true;
}
}
}
}
if (time == 0 && cachedLeftTime != 0) {
cachedLeftTime = 0;
setText(null, null);
return true;
}
return false;
}
};
leftTimeControl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showArrival.set(!showArrival.get());
leftTimeControl.setIcons(showArrival.get() ? time : timeToGo, showArrival.get() ? timeN : timeToGoN);
map.getMapView().refreshMap();
}
});
leftTimeControl.setText(null, null);
leftTimeControl.setIcons(showArrival.get() ? time : timeToGo, showArrival.get() ? timeN : timeToGoN);
return leftTimeControl;
}
use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.
the class RouteInfoWidgetsFactory method createBearingControl.
public TextInfoWidget createBearingControl(final MapActivity map) {
final int bearingResId = R.drawable.widget_bearing_day;
final int bearingNightResId = R.drawable.widget_bearing_night;
final int relativeBearingResId = R.drawable.widget_relative_bearing_day;
final int relativeBearingNightResId = R.drawable.widget_relative_bearing_night;
final OsmandApplication ctx = map.getMyApplication();
final OsmandPreference<Boolean> showRelativeBearing = ctx.getSettings().SHOW_RELATIVE_BEARING_OTHERWISE_REGULAR_BEARING;
final TextInfoWidget bearingControl = new TextInfoWidget(map) {
private int cachedDegrees;
private float MIN_SPEED_FOR_HEADING = 1f;
public LatLon getPointToNavigate() {
TargetPoint p = map.getPointToNavigate();
return p == null ? null : p.point;
}
@Override
public boolean updateInfo(DrawSettings drawSettings) {
boolean relative = showRelativeBearing.get();
boolean modeChanged = setIcons(relative ? relativeBearingResId : bearingResId, relative ? relativeBearingNightResId : bearingNightResId);
setContentTitle(relative ? R.string.map_widget_bearing : R.string.map_widget_magnetic_bearing);
int b = getBearing(relative);
if (degreesChanged(cachedDegrees, b) || modeChanged) {
cachedDegrees = b;
if (b != -1000) {
setText(String.valueOf(b) + "°" + (relative ? "" : " M"), null);
} else {
setText(null, null);
}
return true;
}
return false;
}
public int getBearing(boolean relative) {
int d = -1000;
Location myLocation = getOsmandApplication().getLocationProvider().getLastKnownLocation();
LatLon l = getPointToNavigate();
if (l == null) {
List<MapMarker> markers = getOsmandApplication().getMapMarkersHelper().getMapMarkers();
if (markers.size() > 0) {
l = markers.get(0).point;
}
}
if (myLocation != null && l != null) {
Location dest = new Location("");
dest.setLatitude(l.getLatitude());
dest.setLongitude(l.getLongitude());
dest.setBearing(myLocation.bearingTo(dest));
GeomagneticField destGf = new GeomagneticField((float) dest.getLatitude(), (float) dest.getLongitude(), (float) dest.getAltitude(), System.currentTimeMillis());
float bearingToDest = dest.getBearing() - destGf.getDeclination();
if (relative) {
float b = -1000;
Float heading = getOsmandApplication().getLocationProvider().getHeading();
if ((myLocation.getSpeed() < MIN_SPEED_FOR_HEADING || !myLocation.hasBearing()) && heading != null) {
b = heading;
} else if (myLocation.hasBearing()) {
GeomagneticField myLocGf = new GeomagneticField((float) myLocation.getLatitude(), (float) myLocation.getLongitude(), (float) myLocation.getAltitude(), System.currentTimeMillis());
b = myLocation.getBearing() - myLocGf.getDeclination();
}
if (b > -1000) {
bearingToDest -= b;
if (bearingToDest > 180f) {
bearingToDest -= 360f;
} else if (bearingToDest < -180f) {
bearingToDest += 360f;
}
d = (int) bearingToDest;
}
} else {
d = (int) bearingToDest;
}
}
return d;
}
};
bearingControl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showRelativeBearing.set(!showRelativeBearing.get());
map.refreshMap();
}
});
bearingControl.setText(null, null);
bearingControl.setIcons(!showRelativeBearing.get() ? bearingResId : relativeBearingResId, !showRelativeBearing.get() ? bearingNightResId : relativeBearingNightResId);
return bearingControl;
}
use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.
the class RouteInfoWidgetsFactory method createMaxSpeedControl.
public TextInfoWidget createMaxSpeedControl(final MapActivity map) {
final RoutingHelper rh = map.getMyApplication().getRoutingHelper();
final OsmAndLocationProvider locationProvider = map.getMyApplication().getLocationProvider();
final MapViewTrackingUtilities trackingUtilities = map.getMapViewTrackingUtilities();
final TextInfoWidget speedControl = new TextInfoWidget(map) {
private float cachedSpeed = 0;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
float mx = 0;
if ((rh == null || !rh.isFollowingMode() || rh.isDeviatedFromRoute() || rh.getCurrentGPXRoute() != null) && trackingUtilities.isMapLinkedToLocation()) {
RouteDataObject ro = locationProvider.getLastKnownRouteSegment();
if (ro != null) {
mx = ro.getMaximumSpeed(ro.bearingVsRouteDirection(locationProvider.getLastKnownLocation()));
}
} else if (rh != null) {
mx = rh.getCurrentMaxSpeed();
} else {
mx = 0f;
}
if (cachedSpeed != mx) {
cachedSpeed = mx;
if (cachedSpeed == 0) {
setText(null, null);
} else if (cachedSpeed == RouteDataObject.NONE_MAX_SPEED) {
setText(map.getString(R.string.max_speed_none), "");
} else {
String ds = OsmAndFormatter.getFormattedSpeed(cachedSpeed, map.getMyApplication());
int ls = ds.lastIndexOf(' ');
if (ls == -1) {
setText(ds, null);
} else {
setText(ds.substring(0, ls), ds.substring(ls + 1));
}
}
return true;
}
return false;
}
};
speedControl.setIcons(R.drawable.widget_max_speed_day, R.drawable.widget_max_speed_night);
speedControl.setText(null, null);
return speedControl;
}
use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.
the class RouteInfoWidgetsFactory method createSpeedControl.
public TextInfoWidget createSpeedControl(final MapActivity map) {
final OsmandApplication app = map.getMyApplication();
final TextInfoWidget speedControl = new TextInfoWidget(map) {
private float cachedSpeed = 0;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
Location loc = app.getLocationProvider().getLastKnownLocation();
// draw speed
if (loc != null && loc.hasSpeed()) {
// .1 mps == 0.36 kph
float minDelta = .1f;
// and use .02 instead of .03 to account for rounding effects.
if (cachedSpeed < 6) {
minDelta = .015f;
}
if (Math.abs(loc.getSpeed() - cachedSpeed) > minDelta) {
cachedSpeed = loc.getSpeed();
String ds = OsmAndFormatter.getFormattedSpeed(cachedSpeed, app);
int ls = ds.lastIndexOf(' ');
if (ls == -1) {
setText(ds, null);
} else {
setText(ds.substring(0, ls), ds.substring(ls + 1));
}
return true;
}
} else if (cachedSpeed != 0) {
cachedSpeed = 0;
setText(null, null);
return true;
}
return false;
}
};
speedControl.setIcons(R.drawable.widget_speed_day, R.drawable.widget_speed_night);
speedControl.setText(null, null);
return speedControl;
}
use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.
the class RouteInfoWidgetsFactory method createNextNextInfoControl.
public NextTurnInfoWidget createNextNextInfoControl(final Activity activity, final OsmandApplication app, boolean horisontalMini) {
final RoutingHelper routingHelper = app.getRoutingHelper();
final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(activity, app, horisontalMini) {
NextDirectionInfo calc1 = new NextDirectionInfo();
@Override
public boolean updateInfo(DrawSettings drawSettings) {
boolean followingMode = routingHelper.isFollowingMode() || app.getLocationProvider().getLocationSimulation().isRouteAnimating();
TurnType turnType = null;
boolean deviatedFromRoute = false;
int turnImminent = 0;
int nextTurnDistance = 0;
if (routingHelper != null && routingHelper.isRouteCalculated() && followingMode) {
deviatedFromRoute = routingHelper.isDeviatedFromRoute();
NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true);
if (!deviatedFromRoute) {
if (r != null) {
r = routingHelper.getNextRouteDirectionInfoAfter(r, calc1, true);
}
}
if (r != null && r.distanceTo > 0 && r.directionInfo != null) {
turnType = r.directionInfo.getTurnType();
turnImminent = r.imminent;
nextTurnDistance = r.distanceTo;
}
}
setTurnType(turnType);
setTurnImminent(turnImminent, deviatedFromRoute);
setTurnDistance(nextTurnDistance);
return true;
}
};
nextTurnInfo.setOnClickListener(new View.OnClickListener() {
// int i = 0;
@Override
public void onClick(View v) {
// uncomment to test turn info rendering
// final int l = TurnType.predefinedTypes.length;
// final int exits = 5;
// i++;
// if (i % (l + exits) >= l ) {
// nextTurnInfo.turnType = TurnType.valueOf("EXIT" + (i % (l + exits) - l + 1), true);
// nextTurnInfo.exitOut = (i % (l + exits) - l + 1)+"";
// float a = 180 - (i % (l + exits) - l + 1) * 50;
// nextTurnInfo.turnType.setTurnAngle(a < 0 ? a + 360 : a);
// } else {
// nextTurnInfo.turnType = TurnType.valueOf(TurnType.predefinedTypes[i % (TurnType.predefinedTypes.length + exits)], true);
// nextTurnInfo.exitOut = "";
// }
// nextTurnInfo.turnImminent = (nextTurnInfo.turnImminent + 1) % 3;
// nextTurnInfo.nextTurnDirection = 580;
// TurnPathHelper.calcTurnPath(nextTurnInfo.pathForTurn, nexsweepAngletTurnInfo.turnType,nextTurnInfo.pathTransform);
// showMiniMap = true;
}
});
// initial state
return nextTurnInfo;
}
Aggregations