use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget in project Osmand by osmandapp.
the class RouteInfoWidgetsFactory method createPlainTimeControl.
public TextInfoWidget createPlainTimeControl(final MapActivity map) {
final OsmandApplication ctx = map.getMyApplication();
final TextInfoWidget plainTimeControl = new TextInfoWidget(map) {
private long cachedLeftTime = 0;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
long time = System.currentTimeMillis();
if (isUpdateNeeded() || time - cachedLeftTime > 5000) {
cachedLeftTime = time;
if (DateFormat.is24HourFormat(ctx)) {
// $NON-NLS-1$
setText(DateFormat.format("k:mm", time).toString(), null);
} else {
setText(DateFormat.format("h:mm", time).toString(), // $NON-NLS-1$
DateFormat.format("aa", time).toString());
}
}
return false;
}
};
plainTimeControl.setText(null, null);
plainTimeControl.setIcons(R.drawable.widget_time_day, R.drawable.widget_time_night);
return plainTimeControl;
}
use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget in project Osmand by osmandapp.
the class MapInfoWidgetsFactory method createAltitudeControl.
public TextInfoWidget createAltitudeControl(final MapActivity map) {
final TextInfoWidget altitudeControl = new TextInfoWidget(map) {
private int cachedAlt = 0;
@Override
public boolean updateInfo(DrawSettings d) {
// draw speed
Location loc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
if (loc != null && loc.hasAltitude()) {
double compAlt = loc.getAltitude();
if (isUpdateNeeded() || cachedAlt != (int) compAlt) {
cachedAlt = (int) compAlt;
String ds = OsmAndFormatter.getFormattedAlt(cachedAlt, map.getMyApplication());
int ls = ds.lastIndexOf(' ');
if (ls == -1) {
setText(ds, null);
} else {
setText(ds.substring(0, ls), ds.substring(ls + 1));
}
return true;
}
} else if (cachedAlt != 0) {
cachedAlt = 0;
setText(null, null);
return true;
}
return false;
}
@Override
public boolean isMetricSystemDepended() {
return true;
}
};
altitudeControl.setText(null, null);
altitudeControl.setIcons(R.drawable.widget_altitude_day, R.drawable.widget_altitude_night);
return altitudeControl;
}
use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget 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 && !rh.isCurrentGPXRouteV2())) && 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 (isUpdateNeeded() || 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;
}
@Override
public boolean isMetricSystemDepended() {
return true;
}
};
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.mapwidgets.widgets.TextInfoWidget 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;
private LatLon getNextTargetPoint() {
List<TargetPoint> points = getApplication().getTargetPointsHelper().getIntermediatePointsWithTarget();
return points.isEmpty() ? null : points.get(0).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 (isUpdateNeeded() || degreesChanged(cachedDegrees, b) || modeChanged) {
cachedDegrees = b;
if (b != -1000) {
setText(OsmAndFormatter.getFormattedAzimuth(b, getApplication()) + (relative ? "" : " M"), null);
} else {
setText(null, null);
}
return true;
}
return false;
}
@Override
public boolean isAngularUnitsDepended() {
return true;
}
public int getBearing(boolean relative) {
int d = -1000;
Location myLocation = getApplication().getLocationProvider().getLastKnownLocation();
LatLon l = getNextTargetPoint();
if (l == null) {
List<MapMarker> markers = getApplication().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 = getApplication().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(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.mapwidgets.widgets.TextInfoWidget 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 (isUpdateNeeded() || 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;
}
@Override
public boolean isMetricSystemDepended() {
return true;
}
};
speedControl.setIcons(R.drawable.widget_speed_day, R.drawable.widget_speed_night);
speedControl.setText(null, null);
return speedControl;
}
Aggregations