Search in sources :

Example 11 with DrawSettings

use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.

the class OsmandMonitoringPlugin method createMonitoringControl.

/**
 * creates (if it wasn't created previously) the control to be added on a MapInfoLayer that shows a monitoring state (recorded/stopped)
 */
private TextInfoWidget createMonitoringControl(final MapActivity map) {
    monitoringControl = new TextInfoWidget(map) {

        long lastUpdateTime;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            if (isSaving) {
                setText(map.getString(R.string.shared_string_save), "");
                setIcons(R.drawable.widget_monitoring_rec_big_day, R.drawable.widget_monitoring_rec_big_night);
                return true;
            }
            String txt = map.getString(R.string.monitoring_control_start);
            String subtxt = null;
            int dn;
            int d;
            long last = lastUpdateTime;
            final boolean globalRecord = settings.SAVE_GLOBAL_TRACK_TO_GPX.get();
            final boolean isRecording = app.getSavingTrackHelper().getIsRecording();
            float dist = app.getSavingTrackHelper().getDistance();
            // make sure widget always shows recorded track distance if unsaved track exists
            if (dist > 0) {
                last = app.getSavingTrackHelper().getLastTimeUpdated();
                String ds = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication());
                int ls = ds.lastIndexOf(' ');
                if (ls == -1) {
                    txt = ds;
                } else {
                    txt = ds.substring(0, ls);
                    subtxt = ds.substring(ls + 1);
                }
            }
            final boolean liveMonitoringEnabled = liveMonitoringHelper.isLiveMonitoringEnabled();
            if (globalRecord) {
                // indicates global recording (+background recording)
                if (liveMonitoringEnabled) {
                    dn = R.drawable.widget_live_monitoring_rec_big_night;
                    d = R.drawable.widget_live_monitoring_rec_big_day;
                } else {
                    dn = R.drawable.widget_monitoring_rec_big_night;
                    d = R.drawable.widget_monitoring_rec_big_day;
                }
            } else if (isRecording) {
                // indicates (profile-based, configured in settings) recording (looks like is only active during nav in follow mode)
                if (liveMonitoringEnabled) {
                    dn = R.drawable.widget_live_monitoring_rec_small_night;
                    d = R.drawable.widget_live_monitoring_rec_small_day;
                } else {
                    dn = R.drawable.widget_monitoring_rec_small_night;
                    d = R.drawable.widget_monitoring_rec_small_day;
                }
            } else {
                dn = R.drawable.widget_monitoring_rec_inactive_night;
                d = R.drawable.widget_monitoring_rec_inactive_day;
            }
            setText(txt, subtxt);
            setIcons(d, dn);
            if ((last != lastUpdateTime) && (globalRecord || isRecording)) {
                lastUpdateTime = last;
                // blink implementation with 2 indicator states (global logging + profile/navigation logging)
                if (liveMonitoringEnabled) {
                    dn = R.drawable.widget_live_monitoring_rec_small_night;
                    d = R.drawable.widget_live_monitoring_rec_small_day;
                } else {
                    dn = R.drawable.widget_monitoring_rec_small_night;
                    d = R.drawable.widget_monitoring_rec_small_day;
                }
                setIcons(d, dn);
                map.getMyApplication().runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        int dn;
                        int d;
                        if (globalRecord) {
                            if (liveMonitoringEnabled) {
                                dn = R.drawable.widget_live_monitoring_rec_big_night;
                                d = R.drawable.widget_live_monitoring_rec_big_day;
                            } else {
                                dn = R.drawable.widget_monitoring_rec_big_night;
                                d = R.drawable.widget_monitoring_rec_big_day;
                            }
                        } else {
                            if (liveMonitoringEnabled) {
                                dn = R.drawable.widget_live_monitoring_rec_small_night;
                                d = R.drawable.widget_live_monitoring_rec_small_day;
                            } else {
                                dn = R.drawable.widget_monitoring_rec_small_night;
                                d = R.drawable.widget_monitoring_rec_small_day;
                            }
                        }
                        setIcons(d, dn);
                    }
                }, 500);
            }
            return true;
        }
    };
    monitoringControl.updateInfo(null);
    // monitoringControl.addView(child);
    monitoringControl.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            controlDialog(map, true);
        }
    });
    return monitoringControl;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.TextInfoWidget) OsmAndTaskRunnable(net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) TextView(android.widget.TextView) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Example 12 with DrawSettings

use of net.osmand.plus.views.OsmandMapLayer.DrawSettings 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 13 with DrawSettings

use of net.osmand.plus.views.OsmandMapLayer.DrawSettings 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 (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;
        }
    };
    altitudeControl.setText(null, null);
    altitudeControl.setIcons(R.drawable.widget_altitude_day, R.drawable.widget_altitude_night);
    return altitudeControl;
}
Also used : DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings) Location(net.osmand.Location)

Example 14 with DrawSettings

use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.

the class OsmandMapTileView method refreshBufferImage.

private void refreshBufferImage(final DrawSettings drawSettings) {
    if (mapRenderer != null) {
        return;
    }
    if (!baseHandler.hasMessages(BASE_REFRESH_MESSAGE) || drawSettings.isUpdateVectorRendering()) {
        Message msg = Message.obtain(baseHandler, new Runnable() {

            @Override
            public void run() {
                baseHandler.removeMessages(BASE_REFRESH_MESSAGE);
                try {
                    DrawSettings param = drawSettings;
                    Boolean currentNightMode = nightMode;
                    if (currentNightMode != null && currentNightMode != param.isNightMode()) {
                        param = new DrawSettings(currentNightMode, true);
                        resetDefaultColor();
                    }
                    if (handler.hasMessages(MAP_FORCE_REFRESH_MESSAGE)) {
                        if (!param.isUpdateVectorRendering()) {
                            param = new DrawSettings(drawSettings.isNightMode(), true);
                        }
                        handler.removeMessages(MAP_FORCE_REFRESH_MESSAGE);
                    }
                    refreshBaseMapInternal(currentViewport.copy(), param);
                    sendRefreshMapMsg(param, 0);
                } catch (Exception e) {
                    LOG.error(e.getMessage(), e);
                }
            }
        });
        msg.what = drawSettings.isUpdateVectorRendering() ? MAP_FORCE_REFRESH_MESSAGE : BASE_REFRESH_MESSAGE;
        // baseHandler.sendMessageDelayed(msg, 0);
        baseHandler.sendMessage(msg);
    }
}
Also used : Message(android.os.Message) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Example 15 with DrawSettings

use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.

the class OsmandMapTileView method sendRefreshMapMsg.

private void sendRefreshMapMsg(final DrawSettings drawSettings, int delay) {
    if (!handler.hasMessages(MAP_REFRESH_MESSAGE) || drawSettings.isUpdateVectorRendering()) {
        Message msg = Message.obtain(handler, new Runnable() {

            @Override
            public void run() {
                DrawSettings param = drawSettings;
                handler.removeMessages(MAP_REFRESH_MESSAGE);
                refreshMapInternal(param);
            }
        });
        msg.what = MAP_REFRESH_MESSAGE;
        if (delay > 0) {
            handler.sendMessageDelayed(msg, delay);
        } else {
            handler.sendMessage(msg);
        }
    }
}
Also used : Message(android.os.Message) 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