Search in sources :

Example 16 with TextInfoWidget

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

the class OsmandAidlApi method registerAddMapWidgetReceiver.

private void registerAddMapWidgetReceiver(@NonNull MapActivity mapActivity) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    BroadcastReceiver addMapWidgetReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            MapActivity mapActivity = mapActivityRef.get();
            String widgetId = intent.getStringExtra(AIDL_OBJECT_ID);
            String packName = intent.getStringExtra(AIDL_PACKAGE_NAME);
            if (mapActivity != null && widgetId != null && packName != null) {
                ConnectedApp connectedApp = connectedApps.get(packName);
                if (connectedApp != null) {
                    AidlMapWidgetWrapper widget = connectedApp.getWidgets().get(widgetId);
                    MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
                    if (widget != null && layer != null) {
                        ApplicationMode.regWidgetVisibility(widget.getId(), (ApplicationMode[]) null);
                        TextInfoWidget control = connectedApp.createWidgetControl(mapActivity, widgetId);
                        connectedApp.getWidgetControls().put(widgetId, control);
                        int iconId = AndroidUtils.getDrawableId(app, widget.getMenuIconName());
                        int menuIconId = iconId != 0 ? iconId : ContextMenuItem.INVALID_ID;
                        String widgetKey = "aidl_widget_" + widgetId;
                        layer.registerSideWidget(control, menuIconId, widget.getMenuTitle(), widgetKey, false, widget.getOrder());
                        layer.recreateControls();
                    }
                }
            }
        }
    };
    registerReceiver(addMapWidgetReceiver, mapActivity, AIDL_ADD_MAP_WIDGET);
}
Also used : Context(android.content.Context) Intent(android.content.Intent) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) BroadcastReceiver(android.content.BroadcastReceiver) FavouritePoint(net.osmand.data.FavouritePoint) SuppressLint(android.annotation.SuppressLint) TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) WeakReference(java.lang.ref.WeakReference) MapInfoLayer(net.osmand.plus.views.layers.MapInfoLayer) MapActivity(net.osmand.plus.activities.MapActivity)

Example 17 with TextInfoWidget

use of net.osmand.plus.views.mapwidgets.widgets.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 = getParkingPosition();
            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 (isUpdateNeeded() || 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;
        }

        @Override
        public boolean isMetricSystemDepended() {
            return true;
        }

        /**
         * 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.widgets.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) FavouritePoint(net.osmand.data.FavouritePoint) DrawSettings(net.osmand.plus.views.layers.base.OsmandMapLayer.DrawSettings)

Example 18 with TextInfoWidget

use of net.osmand.plus.views.mapwidgets.widgets.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(v -> openMapillary(map, null));
    return mapillaryControl;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget)

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