Search in sources :

Example 6 with TextInfoWidget

use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget in project Osmand by osmandapp.

the class AudioVideoNotesPlugin method registerWidget.

private void registerWidget(final MapActivity activity) {
    MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
    if (mapInfoLayer != null) {
        recordControl = new TextInfoWidget(activity) {

            private Integer cachedAction;

            private Boolean cachedRecording;

            @Override
            public boolean updateInfo(DrawSettings drawSettings) {
                boolean recording = isRecording();
                Integer action = AV_DEFAULT_ACTION.get();
                if (!Algorithms.objectEquals(recording, cachedRecording) || !Algorithms.objectEquals(action, cachedAction)) {
                    cachedAction = action;
                    cachedRecording = recording;
                    if (recording) {
                        setText(app.getString(R.string.shared_string_control_stop), null);
                        setIcons(R.drawable.widget_icon_av_active, R.drawable.widget_icon_av_active_night);
                    } else {
                        setText(app.getString(R.string.shared_string_control_start), null);
                        switch(action) {
                            case AV_DEFAULT_ACTION_VIDEO:
                                setIcons(R.drawable.widget_av_video_day, R.drawable.widget_av_video_night);
                                break;
                            case AV_DEFAULT_ACTION_TAKEPICTURE:
                                setIcons(R.drawable.widget_av_photo_day, R.drawable.widget_av_photo_night);
                                break;
                            case AV_DEFAULT_ACTION_AUDIO:
                                setIcons(R.drawable.widget_av_audio_day, R.drawable.widget_av_audio_night);
                                break;
                            default:
                                setIcons(R.drawable.widget_icon_av_inactive_day, R.drawable.widget_icon_av_inactive_night);
                                break;
                        }
                    }
                }
                return false;
            }
        };
        recordControl.setOnClickListener(v -> {
            if (isRecording()) {
                stopRecording(mapActivity, false);
            } else {
                defaultAction(mapActivity);
            }
        });
        mapInfoLayer.registerSideWidget(recordControl, new AudioVideoNotesWidgetState(app, AV_DEFAULT_ACTION), "audionotes", false, 32);
        mapInfoLayer.recreateControls();
    }
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) MapInfoLayer(net.osmand.plus.views.layers.MapInfoLayer) DrawSettings(net.osmand.plus.views.layers.base.OsmandMapLayer.DrawSettings)

Example 7 with TextInfoWidget

use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget in project Osmand by osmandapp.

the class MapInfoWidgetsFactory method createRadiusRulerControl.

public TextInfoWidget createRadiusRulerControl(final MapActivity map) {
    final String title = "—";
    final TextInfoWidget radiusRulerControl = new TextInfoWidget(map) {

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
            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));
        }
    };
    radiusRulerControl.setText(title, null);
    setRulerControlIcon(radiusRulerControl, map.getMyApplication().getSettings().RADIUS_RULER_MODE.get());
    radiusRulerControl.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            final RadiusRulerMode mode = map.getMyApplication().getSettings().RADIUS_RULER_MODE.get();
            RadiusRulerMode newMode = RadiusRulerMode.FIRST;
            if (mode == RadiusRulerMode.FIRST) {
                newMode = RadiusRulerMode.SECOND;
            } else if (mode == RadiusRulerMode.SECOND) {
                newMode = RadiusRulerMode.EMPTY;
            }
            setRulerControlIcon(radiusRulerControl, newMode);
            map.getMyApplication().getSettings().RADIUS_RULER_MODE.set(newMode);
            map.refreshMap();
        }
    });
    return radiusRulerControl;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) LatLon(net.osmand.data.LatLon) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RadiusRulerMode(net.osmand.plus.views.layers.RadiusRulerControlLayer.RadiusRulerMode) 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 8 with TextInfoWidget

use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget 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 (isUpdateNeeded() || 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 : TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) 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) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) DrawSettings(net.osmand.plus.views.layers.base.OsmandMapLayer.DrawSettings)

Example 9 with TextInfoWidget

use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget in project Osmand by osmandapp.

the class RouteInfoWidgetsFactory method createBatteryControl.

public TextInfoWidget createBatteryControl(final MapActivity map) {
    final int battery = R.drawable.widget_battery_day;
    final int batteryN = R.drawable.widget_battery_night;
    final int batteryCharging = R.drawable.widget_battery_charging_day;
    final int batteryChargingN = R.drawable.widget_battery_charging_night;
    final OsmandApplication ctx = map.getMyApplication();
    final TextInfoWidget batteryControl = new TextInfoWidget(map) {

        private long cachedLeftTime = 0;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            long time = System.currentTimeMillis();
            if (isUpdateNeeded() || time - cachedLeftTime > 1000) {
                cachedLeftTime = time;
                Intent batteryIntent = ctx.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
                int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
                int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
                int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
                if (level == -1 || scale == -1 || status == -1) {
                    setText("?", null);
                    setIcons(battery, batteryN);
                } else {
                    boolean charging = ((status == BatteryManager.BATTERY_STATUS_CHARGING) || (status == BatteryManager.BATTERY_STATUS_FULL));
                    setText(String.format("%d%%", (level * 100) / scale), null);
                    setIcons(charging ? batteryCharging : battery, charging ? batteryChargingN : batteryN);
                }
            }
            return false;
        }
    };
    batteryControl.setText(null, null);
    batteryControl.setIcons(battery, batteryN);
    return batteryControl;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) IntentFilter(android.content.IntentFilter) OsmandApplication(net.osmand.plus.OsmandApplication) Intent(android.content.Intent) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) DrawSettings(net.osmand.plus.views.layers.base.OsmandMapLayer.DrawSettings)

Example 10 with TextInfoWidget

use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget in project Osmand by osmandapp.

the class RouteInfoWidgetsFactory method createTimeControl.

public TextInfoWidget createTimeControl(final MapActivity map, final boolean intermediate) {
    final RoutingHelper routingHelper = map.getRoutingHelper();
    final OsmandApplication ctx = map.getMyApplication();
    final OsmandPreference<Boolean> showArrival = intermediate ? ctx.getSettings().SHOW_INTERMEDIATE_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME : ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME;
    final TextInfoWidget leftTimeControl = new TextInfoWidget(map) {

        private long cachedLeftTime = 0;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            setTimeControlIcons(this, showArrival.get(), intermediate);
            int time = 0;
            if (routingHelper != null && routingHelper.isRouteCalculated()) {
                // boolean followingMode = routingHelper.isFollowingMode();
                time = intermediate ? routingHelper.getLeftTimeNextIntermediate() : 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(v -> {
        showArrival.set(!showArrival.get());
        setTimeControlIcons(leftTimeControl, showArrival.get(), intermediate);
        map.refreshMap();
    });
    leftTimeControl.setText(null, null);
    setTimeControlIcons(leftTimeControl, showArrival.get(), intermediate);
    return leftTimeControl;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) OsmandApplication(net.osmand.plus.OsmandApplication) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) DrawSettings(net.osmand.plus.views.layers.base.OsmandMapLayer.DrawSettings)

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