Search in sources :

Example 11 with TextInfoWidget

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;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) OsmandApplication(net.osmand.plus.OsmandApplication) DrawSettings(net.osmand.plus.views.layers.base.OsmandMapLayer.DrawSettings)

Example 12 with TextInfoWidget

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;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) MGRSPoint(com.jwetherell.openmap.common.MGRSPoint) LatLonPoint(com.jwetherell.openmap.common.LatLonPoint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) UTMPoint(com.jwetherell.openmap.common.UTMPoint) DrawSettings(net.osmand.plus.views.layers.base.OsmandMapLayer.DrawSettings) Location(net.osmand.Location)

Example 13 with TextInfoWidget

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;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) OsmAndLocationProvider(net.osmand.plus.OsmAndLocationProvider) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) RouteDataObject(net.osmand.binary.RouteDataObject) RoutingHelper(net.osmand.plus.routing.RoutingHelper) DrawSettings(net.osmand.plus.views.layers.base.OsmandMapLayer.DrawSettings)

Example 14 with TextInfoWidget

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;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.mapmarkers.MapMarker) GeomagneticField(android.hardware.GeomagneticField) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) DrawSettings(net.osmand.plus.views.layers.base.OsmandMapLayer.DrawSettings) TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) LatLon(net.osmand.data.LatLon) Location(net.osmand.Location)

Example 15 with TextInfoWidget

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;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) OsmandApplication(net.osmand.plus.OsmandApplication) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) DrawSettings(net.osmand.plus.views.layers.base.OsmandMapLayer.DrawSettings) Location(net.osmand.Location)

Aggregations

TextInfoWidget (net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget)18 DrawSettings (net.osmand.plus.views.layers.base.OsmandMapLayer.DrawSettings)12 OsmandApplication (net.osmand.plus.OsmandApplication)7 Location (net.osmand.Location)4 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)4 MapInfoLayer (net.osmand.plus.views.layers.MapInfoLayer)4 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3 View (android.view.View)3 TextView (android.widget.TextView)3 LatLon (net.osmand.data.LatLon)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 Paint (android.graphics.Paint)2 OnClickListener (android.view.View.OnClickListener)2 ImageView (android.widget.ImageView)2 LatLonPoint (com.jwetherell.openmap.common.LatLonPoint)2 MGRSPoint (com.jwetherell.openmap.common.MGRSPoint)2 UTMPoint (com.jwetherell.openmap.common.UTMPoint)2 WeakReference (java.lang.ref.WeakReference)2