Search in sources :

Example 1 with TextInfoWidget

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

the class AudioVideoNotesPlugin method registerWidget.

private void registerWidget(MapActivity activity) {
    MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
    if (mapInfoLayer != null) {
        recordControl = new TextInfoWidget(activity);
        if (mediaRec != null && mediaRecFile != null) {
            updateRecordControl(activity, mediaRecFile);
        } else {
            recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.monitoring_rec_inactive));
            setRecordListener(recordControl, activity);
        }
        mapInfoLayer.registerSideWidget(recordControl, R.drawable.ic_action_micro_dark, R.string.map_widget_av_notes, "audionotes", false, 32);
        mapInfoLayer.recreateControls();
    }
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.TextInfoWidget) MapInfoLayer(net.osmand.plus.views.MapInfoLayer)

Example 2 with TextInfoWidget

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

the class MapillaryPlugin method createMonitoringControl.

private TextInfoWidget createMonitoringControl(final MapActivity map) {
    mapillaryControl = new TextInfoWidget(map);
    mapillaryControl.setText(map.getString(R.string.mapillary), "");
    mapillaryControl.setIcons(R.drawable.widget_mapillary_day, R.drawable.widget_mapillary_night);
    mapillaryControl.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            openMapillary(map, null);
        }
    });
    return mapillaryControl;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.TextInfoWidget) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View)

Example 3 with TextInfoWidget

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

the class OsmandAidlApi method registerRemoveMapWidgetReceiver.

private void registerRemoveMapWidgetReceiver(final MapActivity mapActivity) {
    removeMapWidgetReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String widgetId = intent.getStringExtra(AIDL_OBJECT_ID);
            if (widgetId != null) {
                MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
                TextInfoWidget widgetControl = widgetControls.get(widgetId);
                if (layer != null && widgetControl != null) {
                    layer.removeSideWidget(widgetControl);
                    widgetControls.remove(widgetId);
                    layer.recreateControls();
                }
            }
        }
    };
    mapActivity.registerReceiver(removeMapWidgetReceiver, new IntentFilter(AIDL_REMOVE_MAP_WIDGET));
}
Also used : Context(android.content.Context) TextInfoWidget(net.osmand.plus.views.mapwidgets.TextInfoWidget) IntentFilter(android.content.IntentFilter) MapInfoLayer(net.osmand.plus.views.MapInfoLayer) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 4 with TextInfoWidget

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

the class OsmandAidlApi method createWidgetControl.

private TextInfoWidget createWidgetControl(final MapActivity mapActivity, final String widgetId) {
    final TextInfoWidget control = new TextInfoWidget(mapActivity) {

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            AMapWidget widget = widgets.get(widgetId);
            if (widget != null) {
                String txt = widget.getText();
                String subtxt = widget.getDescription();
                boolean night = drawSettings != null && drawSettings.isNightMode();
                int icon = night ? getDrawableId(widget.getDarkIconName()) : getDrawableId(widget.getLightIconName());
                setText(txt, subtxt);
                if (icon != 0) {
                    setImageDrawable(icon);
                } else {
                    setImageDrawable(null);
                }
                return true;
            } else {
                return false;
            }
        }
    };
    control.updateInfo(null);
    control.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AMapWidget widget = widgets.get(widgetId);
            if (widget != null && widget.getIntentOnClick() != null) {
                app.startActivity(widget.getIntentOnClick());
            }
        }
    });
    return control;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.TextInfoWidget) AMapWidget(net.osmand.aidl.mapwidget.AMapWidget) View(android.view.View) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) FavouritePoint(net.osmand.data.FavouritePoint) AMapPoint(net.osmand.aidl.maplayer.point.AMapPoint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Example 5 with TextInfoWidget

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

the class ParkingPositionPlugin method createParkingPlaceInfoControl.

/**
 * @return the control to be added on a MapInfoLayer
 * that shows a distance between
 * the current position on the map
 * and the location of the parked car
 */
private TextInfoWidget createParkingPlaceInfoControl(final MapActivity map) {
    TextInfoWidget parkingPlaceControl = new TextInfoWidget(map) {

        private float[] calculations = new float[1];

        private int cachedMeters = 0;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            LatLon parkingPoint = parkingLayer.getParkingPoint();
            if (parkingPoint != null && !map.getRoutingHelper().isFollowingMode()) {
                OsmandMapTileView view = map.getMapView();
                int d = 0;
                if (d == 0) {
                    net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(), parkingPoint.getLatitude(), parkingPoint.getLongitude(), calculations);
                    d = (int) calculations[0];
                }
                if (distChanged(cachedMeters, d)) {
                    cachedMeters = d;
                    if (cachedMeters <= 20) {
                        cachedMeters = 0;
                        setText(null, null);
                    } else {
                        String ds = OsmAndFormatter.getFormattedDistance(cachedMeters, 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 (cachedMeters != 0) {
                cachedMeters = 0;
                setText(null, null);
                return true;
            }
            return false;
        }

        /**
         * Utility method.
         * @param oldDist
         * @param dist
         * @return
         */
        private boolean distChanged(int oldDist, int dist) {
            if (oldDist != 0 && Math.abs(oldDist - dist) < 30) {
                return false;
            }
            return true;
        }
    };
    parkingPlaceControl.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            OsmandMapTileView view = map.getMapView();
            AnimateDraggingMapThread thread = view.getAnimatedDraggingThread();
            LatLon parkingPoint = parkingPosition;
            if (parkingPoint != null) {
                int fZoom = view.getZoom() < 15 ? 15 : view.getZoom();
                thread.startMoving(parkingPoint.getLatitude(), parkingPoint.getLongitude(), fZoom, true);
            }
        }
    });
    parkingPlaceControl.setText(null, null);
    parkingPlaceControl.setIcons(R.drawable.widget_parking_day, R.drawable.widget_parking_night);
    return parkingPlaceControl;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.TextInfoWidget) LatLon(net.osmand.data.LatLon) AnimateDraggingMapThread(net.osmand.plus.views.AnimateDraggingMapThread) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) TextView(android.widget.TextView) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Aggregations

TextInfoWidget (net.osmand.plus.views.mapwidgets.TextInfoWidget)9 View (android.view.View)4 MapInfoLayer (net.osmand.plus.views.MapInfoLayer)4 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)4 AMapWidget (net.osmand.aidl.mapwidget.AMapWidget)3 DrawSettings (net.osmand.plus.views.OsmandMapLayer.DrawSettings)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 TextView (android.widget.TextView)2 AMapPoint (net.osmand.aidl.maplayer.point.AMapPoint)2 FavouritePoint (net.osmand.data.FavouritePoint)2 MapWidgetRegInfo (net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo)2 LatLon (net.osmand.data.LatLon)1 OsmAndTaskRunnable (net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 AnimateDraggingMapThread (net.osmand.plus.views.AnimateDraggingMapThread)1 MapInfoWidgetsFactory (net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory)1 TopTextView (net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView)1