Search in sources :

Example 1 with RulerMode

use of net.osmand.plus.OsmandSettings.RulerMode in project Osmand by osmandapp.

the class MapInfoWidgetsFactory method createRulerControl.

public TextInfoWidget createRulerControl(final MapActivity map) {
    final String title = "—";
    final TextInfoWidget rulerControl = new TextInfoWidget(map) {

        RulerControlLayer rulerLayer = map.getMapLayers().getRulerControlLayer();

        LatLon cacheFirstTouchPoint = new LatLon(0, 0);

        LatLon cacheSecondTouchPoint = new LatLon(0, 0);

        LatLon cacheSingleTouchPoint = new LatLon(0, 0);

        boolean fingerAndLocDistWasShown;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            OsmandMapTileView view = map.getMapView();
            Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
            if (rulerLayer.isShowDistBetweenFingerAndLocation() && currentLoc != null) {
                if (!cacheSingleTouchPoint.equals(rulerLayer.getTouchPointLatLon())) {
                    cacheSingleTouchPoint = rulerLayer.getTouchPointLatLon();
                    setDistanceText(cacheSingleTouchPoint.getLatitude(), cacheSingleTouchPoint.getLongitude(), currentLoc.getLatitude(), currentLoc.getLongitude());
                    fingerAndLocDistWasShown = true;
                }
            } else if (rulerLayer.isShowTwoFingersDistance()) {
                if (!cacheFirstTouchPoint.equals(view.getFirstTouchPointLatLon()) || !cacheSecondTouchPoint.equals(view.getSecondTouchPointLatLon()) || fingerAndLocDistWasShown) {
                    cacheFirstTouchPoint = view.getFirstTouchPointLatLon();
                    cacheSecondTouchPoint = view.getSecondTouchPointLatLon();
                    setDistanceText(cacheFirstTouchPoint.getLatitude(), cacheFirstTouchPoint.getLongitude(), cacheSecondTouchPoint.getLatitude(), cacheSecondTouchPoint.getLongitude());
                    fingerAndLocDistWasShown = false;
                }
            } else {
                LatLon centerLoc = map.getMapLocation();
                if (currentLoc != null && centerLoc != null) {
                    if (map.getMapViewTrackingUtilities().isMapLinkedToLocation()) {
                        setDistanceText(0);
                    } else {
                        setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(), centerLoc.getLatitude(), centerLoc.getLongitude());
                    }
                } else {
                    setText(title, null);
                }
            }
            return true;
        }

        private void setDistanceText(float dist) {
            calculateAndSetText(dist);
        }

        private void setDistanceText(double firstLat, double firstLon, double secondLat, double secondLon) {
            float dist = (float) MapUtils.getDistance(firstLat, firstLon, secondLat, secondLon);
            calculateAndSetText(dist);
        }

        private void calculateAndSetText(float dist) {
            String distance = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication());
            int ls = distance.lastIndexOf(' ');
            setText(distance.substring(0, ls), distance.substring(ls + 1));
        }
    };
    rulerControl.setText(title, null);
    setRulerControlIcon(rulerControl, map.getMyApplication().getSettings().RULER_MODE.get());
    rulerControl.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            final RulerMode mode = map.getMyApplication().getSettings().RULER_MODE.get();
            RulerMode newMode = RulerMode.FIRST;
            if (mode == RulerMode.FIRST) {
                newMode = RulerMode.SECOND;
            } else if (mode == RulerMode.SECOND) {
                newMode = RulerMode.EMPTY;
            }
            setRulerControlIcon(rulerControl, newMode);
            map.getMyApplication().getSettings().RULER_MODE.set(newMode);
            map.refreshMap();
        }
    });
    return rulerControl;
}
Also used : RulerMode(net.osmand.plus.OsmandSettings.RulerMode) 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) LatLon(net.osmand.data.LatLon) RulerControlLayer(net.osmand.plus.views.RulerControlLayer) OnClickListener(android.view.View.OnClickListener) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) Location(net.osmand.Location)

Example 2 with RulerMode

use of net.osmand.plus.OsmandSettings.RulerMode in project Osmand by osmandapp.

the class RulerControlLayer method onDraw.

@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
    if (rulerModeOn()) {
        lineAttrs.updatePaints(view, settings, tb);
        lineFontAttrs.updatePaints(view, settings, tb);
        lineFontAttrs.paint.setStyle(Style.FILL);
        circleAttrs.updatePaints(view, settings, tb);
        circleAttrs.paint2.setStyle(Style.FILL);
        circleAttrsAlt.updatePaints(view, settings, tb);
        circleAttrsAlt.paint2.setStyle(Style.FILL);
        final QuadPoint center = tb.getCenterPixelPoint();
        final RulerMode mode = app.getSettings().RULER_MODE.get();
        final long currentTime = System.currentTimeMillis();
        if (cacheMultiTouchEndTime != view.getMultiTouchEndTime()) {
            cacheMultiTouchEndTime = view.getMultiTouchEndTime();
            refreshMapDelayed();
        }
        if (touched && view.isMultiTouch()) {
            touched = false;
            touchEndTime = currentTime;
        }
        if (tb.isZoomAnimated()) {
            wasZoom = true;
        }
        showTwoFingersDistance = !tb.isZoomAnimated() && !view.isWasZoomInMultiTouch() && currentTime - view.getMultiTouchStartTime() > DELAY_BEFORE_DRAW && (view.isMultiTouch() || currentTime - cacheMultiTouchEndTime < DRAW_TIME);
        showDistBetweenFingerAndLocation = !wasZoom && !showTwoFingersDistance && !view.isMultiTouch() && !touchOutside && touchStartTime - view.getMultiTouchStartTime() > DELAY_BEFORE_DRAW && currentTime - touchStartTime > DELAY_BEFORE_DRAW && (touched || currentTime - touchEndTime < DRAW_TIME);
        drawCenterIcon(canvas, tb, center, settings.isNightMode(), mode);
        Location currentLoc = app.getLocationProvider().getLastKnownLocation();
        if (showDistBetweenFingerAndLocation && currentLoc != null) {
            drawDistBetweenFingerAndLocation(canvas, tb, currentLoc, settings.isNightMode());
        } else if (showTwoFingersDistance) {
            drawTwoFingersDistance(canvas, tb, view.getFirstTouchPointLatLon(), view.getSecondTouchPointLatLon(), settings.isNightMode());
        }
        if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) {
            updateData(tb, center);
            RenderingLineAttributes attrs = mode == RulerMode.FIRST ? circleAttrs : circleAttrsAlt;
            for (int i = 1; i <= cacheDistances.size(); i++) {
                drawCircle(canvas, tb, i, center, attrs);
            }
        }
    }
}
Also used : RulerMode(net.osmand.plus.OsmandSettings.RulerMode) QuadPoint(net.osmand.data.QuadPoint) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint) Location(net.osmand.Location)

Aggregations

Location (net.osmand.Location)2 RulerMode (net.osmand.plus.OsmandSettings.RulerMode)2 Paint (android.graphics.Paint)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 LatLon (net.osmand.data.LatLon)1 QuadPoint (net.osmand.data.QuadPoint)1 DrawSettings (net.osmand.plus.views.OsmandMapLayer.DrawSettings)1 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)1 RulerControlLayer (net.osmand.plus.views.RulerControlLayer)1