Search in sources :

Example 1 with OsmAndLocationProvider

use of net.osmand.plus.OsmAndLocationProvider in project Osmand by osmandapp.

the class MapViewTrackingUtilities method backToLocationImpl.

public void backToLocationImpl(int zoom) {
    if (mapView != null) {
        OsmAndLocationProvider locationProvider = app.getLocationProvider();
        if (!isMapLinkedToLocation()) {
            setMapLinkedToLocation(true);
            net.osmand.Location lastKnownLocation = locationProvider.getLastKnownLocation();
            if (lastKnownLocation != null) {
                AnimateDraggingMapThread thread = mapView.getAnimatedDraggingThread();
                int fZoom = mapView.getZoom() < zoom ? zoom : mapView.getZoom();
                movingToMyLocation = true;
                thread.startMoving(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), fZoom, false, new Runnable() {

                    @Override
                    public void run() {
                        movingToMyLocation = false;
                    }
                });
            }
            mapView.refreshMap();
        }
        if (locationProvider.getLastKnownLocation() == null) {
            app.showToastMessage(R.string.unknown_location);
        }
    }
}
Also used : OsmAndLocationProvider(net.osmand.plus.OsmAndLocationProvider) AnimateDraggingMapThread(net.osmand.plus.views.AnimateDraggingMapThread) Location(net.osmand.Location)

Example 2 with OsmAndLocationProvider

use of net.osmand.plus.OsmAndLocationProvider in project Osmand by osmandapp.

the class MapInfoWidgetsFactory method createGPSInfoControl.

public TextInfoWidget createGPSInfoControl(final MapActivity map) {
    final OsmandApplication app = map.getMyApplication();
    final OsmAndLocationProvider loc = app.getLocationProvider();
    final TextInfoWidget gpsInfoControl = new TextInfoWidget(map) {

        private int u = -1;

        private int f = -1;

        @Override
        public boolean updateInfo(DrawSettings d) {
            GPSInfo gpsInfo = loc.getGPSInfo();
            if (gpsInfo.usedSatellites != u || gpsInfo.foundSatellites != f) {
                u = gpsInfo.usedSatellites;
                f = gpsInfo.foundSatellites;
                setText(gpsInfo.usedSatellites + "/" + gpsInfo.foundSatellites, "");
                return true;
            }
            return false;
        }
    };
    gpsInfoControl.setIcons(R.drawable.widget_gps_info_day, R.drawable.widget_gps_info_night);
    gpsInfoControl.setText(null, null);
    gpsInfoControl.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            new StartGPSStatus(map).run();
        }
    });
    return gpsInfoControl;
}
Also used : OsmAndLocationProvider(net.osmand.plus.OsmAndLocationProvider) OsmandApplication(net.osmand.plus.OsmandApplication) OnClickListener(android.view.View.OnClickListener) GPSInfo(net.osmand.plus.OsmAndLocationProvider.GPSInfo) StartGPSStatus(net.osmand.plus.activities.actions.StartGPSStatus) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Example 3 with OsmAndLocationProvider

use of net.osmand.plus.OsmAndLocationProvider in project Osmand by osmandapp.

the class DashSimulateFragment method initView.

@Override
public View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = getActivity().getLayoutInflater().inflate(R.layout.dash_common_fragment, container, false);
    TextView header = (TextView) view.findViewById(R.id.fav_text);
    header.setText(TITLE_ID);
    ((Button) view.findViewById(R.id.show_all)).setVisibility(View.GONE);
    LinearLayout tracks = (LinearLayout) view.findViewById(R.id.items);
    View item = inflater.inflate(R.layout.dash_simulate_item, null, false);
    tracks.addView(item);
    final OsmAndLocationProvider loc = getMyApplication().getLocationProvider();
    OnClickListener listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            loc.getLocationSimulation().startStopRouteAnimation(getActivity());
            dashboard.hideDashboard();
        }
    };
    item.setOnClickListener(listener);
    ImageButton actionButton = (ImageButton) item.findViewById(R.id.stop);
    actionButton.setOnClickListener(listener);
    actionButton.setContentDescription(getString(R.string.animate_route));
    ((TextView) item.findViewById(R.id.name)).setText(R.string.animate_route);
    item.findViewById(R.id.divider).setVisibility(View.VISIBLE);
    return view;
}
Also used : OsmAndLocationProvider(net.osmand.plus.OsmAndLocationProvider) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) LinearLayout(android.widget.LinearLayout)

Example 4 with OsmAndLocationProvider

use of net.osmand.plus.OsmAndLocationProvider in project Osmand by osmandapp.

the class DashSimulateFragment method onOpenDash.

@Override
public void onOpenDash() {
    OsmAndLocationProvider loc = getMyApplication().getLocationProvider();
    boolean routeAnimating = loc.getLocationSimulation().isRouteAnimating();
    ((TextView) getView().findViewById(R.id.name)).setText(routeAnimating ? R.string.animate_route_off : R.string.animate_route);
    ImageButton actionButton = (ImageButton) getView().findViewById(R.id.stop);
    actionButton.setImageDrawable(!routeAnimating ? getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_play_dark) : getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_rec_stop));
    actionButton.setContentDescription(getString(routeAnimating ? R.string.animate_route_off : R.string.animate_route));
}
Also used : OsmAndLocationProvider(net.osmand.plus.OsmAndLocationProvider) ImageButton(android.widget.ImageButton) TextView(android.widget.TextView)

Example 5 with OsmAndLocationProvider

use of net.osmand.plus.OsmAndLocationProvider 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)

Aggregations

OsmAndLocationProvider (net.osmand.plus.OsmAndLocationProvider)5 TextView (android.widget.TextView)3 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 ImageButton (android.widget.ImageButton)2 DrawSettings (net.osmand.plus.views.OsmandMapLayer.DrawSettings)2 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 Location (net.osmand.Location)1 RouteDataObject (net.osmand.binary.RouteDataObject)1 GPSInfo (net.osmand.plus.OsmAndLocationProvider.GPSInfo)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 StartGPSStatus (net.osmand.plus.activities.actions.StartGPSStatus)1 MapViewTrackingUtilities (net.osmand.plus.base.MapViewTrackingUtilities)1 RoutingHelper (net.osmand.plus.routing.RoutingHelper)1 AnimateDraggingMapThread (net.osmand.plus.views.AnimateDraggingMapThread)1 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)1