Search in sources :

Example 16 with DrawSettings

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;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) RoutingHelper(net.osmand.plus.routing.RoutingHelper) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Example 17 with DrawSettings

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;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) GeomagneticField(android.hardware.GeomagneticField) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings) LatLon(net.osmand.data.LatLon) Location(net.osmand.Location)

Example 18 with DrawSettings

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;
}
Also used : 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.OsmandMapLayer.DrawSettings)

Example 19 with DrawSettings

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;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings) Location(net.osmand.Location)

Example 20 with DrawSettings

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;
}
Also used : NextDirectionInfo(net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TurnType(net.osmand.router.TurnType) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Aggregations

DrawSettings (net.osmand.plus.views.OsmandMapLayer.DrawSettings)20 View (android.view.View)10 TextView (android.widget.TextView)9 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)9 Paint (android.graphics.Paint)7 ImageView (android.widget.ImageView)7 OsmandApplication (net.osmand.plus.OsmandApplication)6 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)6 Location (net.osmand.Location)4 LatLon (net.osmand.data.LatLon)4 RoutingHelper (net.osmand.plus.routing.RoutingHelper)3 TextInfoWidget (net.osmand.plus.views.mapwidgets.TextInfoWidget)3 Message (android.os.Message)2 OnClickListener (android.view.View.OnClickListener)2 OsmAndLocationProvider (net.osmand.plus.OsmAndLocationProvider)2 OsmandSettings (net.osmand.plus.OsmandSettings)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 GeomagneticField (android.hardware.GeomagneticField)1 ListPopupWindow (android.support.v7.widget.ListPopupWindow)1