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);
}
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;
}
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;
}
Aggregations