use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget 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(() -> {
int dn1;
int d1;
if (globalRecord) {
if (liveMonitoringEnabled) {
dn1 = R.drawable.widget_live_monitoring_rec_big_night;
d1 = R.drawable.widget_live_monitoring_rec_big_day;
} else {
dn1 = R.drawable.widget_monitoring_rec_big_night;
d1 = R.drawable.widget_monitoring_rec_big_day;
}
} else {
if (liveMonitoringEnabled) {
dn1 = R.drawable.widget_live_monitoring_rec_small_night;
d1 = R.drawable.widget_live_monitoring_rec_small_day;
} else {
dn1 = R.drawable.widget_monitoring_rec_small_night;
d1 = R.drawable.widget_monitoring_rec_small_day;
}
}
setIcons(d1, dn1);
}, 500);
}
return true;
}
};
monitoringControl.updateInfo(null);
// monitoringControl.addView(child);
monitoringControl.setOnClickListener(v -> controlDialog(map));
return monitoringControl;
}
use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget in project Osmand by osmandapp.
the class OsmandAidlApi method registerRemoveMapWidgetReceiver.
private void registerRemoveMapWidgetReceiver(@NonNull MapActivity mapActivity) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
BroadcastReceiver removeMapWidgetReceiver = 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) {
MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
TextInfoWidget widgetControl = connectedApp.getWidgetControls().get(widgetId);
if (layer != null && widgetControl != null) {
layer.removeSideWidget(widgetControl);
connectedApp.getWidgetControls().remove(widgetId);
layer.recreateControls();
}
}
}
}
};
registerReceiver(removeMapWidgetReceiver, mapActivity, AIDL_REMOVE_MAP_WIDGET);
}
use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget in project Osmand by osmandapp.
the class ConnectedApp method registerWidgetControls.
void registerWidgetControls(@NonNull MapActivity mapActivity) {
for (AidlMapWidgetWrapper widget : widgets.values()) {
MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
if (layer != null) {
TextInfoWidget control = createWidgetControl(mapActivity, widget.getId());
widgetControls.put(widget.getId(), control);
int iconId = AndroidUtils.getDrawableId(mapActivity.getMyApplication(), widget.getMenuIconName());
int menuIconId = iconId != 0 ? iconId : ContextMenuItem.INVALID_ID;
String widgetKey = "aidl_widget_" + widget.getId();
layer.registerSideWidget(control, menuIconId, widget.getMenuTitle(), widgetKey, false, widget.getOrder());
}
}
}
use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget in project Osmand by osmandapp.
the class ConnectedApp method createWidgetControl.
TextInfoWidget createWidgetControl(final MapActivity mapActivity, final String widgetId) {
TextInfoWidget control = new TextInfoWidget(mapActivity) {
private boolean init = true;
private String cachedTxt;
private String cachedSubtext;
private Boolean cachedNight;
private Integer cachedIcon;
@Override
public boolean updateInfo(OsmandMapLayer.DrawSettings drawSettings) {
AidlMapWidgetWrapper widget = widgets.get(widgetId);
if (widget != null) {
String txt = widget.getText();
String subtext = widget.getDescription();
boolean night = drawSettings != null && drawSettings.isNightMode();
int icon = AndroidUtils.getDrawableId(mapActivity.getMyApplication(), night ? widget.getDarkIconName() : widget.getLightIconName());
if (init || !Algorithms.objectEquals(txt, cachedTxt) || !Algorithms.objectEquals(subtext, cachedSubtext) || !Algorithms.objectEquals(night, cachedNight) || !Algorithms.objectEquals(icon, cachedIcon)) {
init = false;
cachedTxt = txt;
cachedSubtext = subtext;
cachedNight = night;
cachedIcon = icon;
setText(txt, subtext);
if (icon != 0) {
setImageDrawable(icon);
} else {
setImageDrawable(null);
}
return true;
}
return false;
} else {
setText(null, null);
setImageDrawable(null);
return true;
}
}
};
control.updateInfo(null);
control.setOnClickListener(v -> {
AidlMapWidgetWrapper widget = widgets.get(widgetId);
if (widget != null && widget.getIntentOnClick() != null) {
app.startActivity(widget.getIntentOnClick());
}
});
return control;
}
use of net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget in project Osmand by osmandapp.
the class MapInfoLayer method registerAllControls.
private void registerAllControls(@NonNull MapActivity map) {
rulerWidgets = new ArrayList<>();
RouteInfoWidgetsFactory ric = new RouteInfoWidgetsFactory();
MapInfoWidgetsFactory mic = new MapInfoWidgetsFactory();
MapMarkersWidgetsFactory mwf = map.getMapLayers().getMapMarkersLayer().getWidgetsFactory();
OsmandApplication app = view.getApplication();
lanesControl = RouteInfoWidgetsFactory.createLanesControl(map, view);
TextState ts = calculateTextState();
streetNameView = new TopTextView(map.getMyApplication(), map);
updateStreetName(false, ts);
topCoordinatesView = new TopCoordinatesView(map.getMyApplication(), map);
updateTopCoordinates(false, ts);
topToolbarView = new TopToolbarView(map);
updateTopToolbar(false);
alarmControl = RouteInfoWidgetsFactory.createAlarmInfoControl(app, map);
alarmControl.setVisibility(false);
elevationProfileWidget = new ElevationProfileWidget(map);
setupRulerWidget(mapRulerLayout);
// register left stack
registerSideWidget(null, R.drawable.ic_action_compass, R.string.map_widget_compass, WIDGET_COMPASS, true, 4);
NextTurnWidget bigInfoControl = ric.createNextInfoControl(map, app, false);
registerSideWidget(bigInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn, WIDGET_NEXT_TURN, true, 5);
NextTurnWidget smallInfoControl = ric.createNextInfoControl(map, app, true);
registerSideWidget(smallInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn_small, WIDGET_NEXT_TURN_SMALL, true, 6);
NextTurnWidget nextNextInfoControl = ric.createNextNextInfoControl(map, app, true);
registerSideWidget(nextNextInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_next_turn, WIDGET_NEXT_NEXT_TURN, true, 7);
// register right stack
// priorityOrder: 10s navigation-related, 20s position-related, 30s recording- and other plugin-related, 40s general device information, 50s debugging-purpose
TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map);
registerSideWidget(intermediateDist, R.drawable.ic_action_intermediate, R.string.map_widget_intermediate_distance, WIDGET_INTERMEDIATE_DISTANCE, false, 13);
TextInfoWidget intermediateTime = ric.createTimeControl(map, true);
registerSideWidget(intermediateTime, new TimeWidgetState(app, true), WIDGET_INTERMEDIATE_TIME, false, 14);
TextInfoWidget dist = ric.createDistanceControl(map);
registerSideWidget(dist, R.drawable.ic_action_target, R.string.map_widget_distance, WIDGET_DISTANCE, false, 15);
TextInfoWidget time = ric.createTimeControl(map, false);
registerSideWidget(time, new TimeWidgetState(app, false), WIDGET_TIME, false, 16);
TextInfoWidget marker = mwf.createMapMarkerControl(map, true);
registerSideWidget(marker, R.drawable.ic_action_flag, R.string.map_marker_1st, WIDGET_MARKER_1, false, 17);
TextInfoWidget bearing = ric.createBearingControl(map);
registerSideWidget(bearing, new BearingWidgetState(app), WIDGET_BEARING, false, 18);
TextInfoWidget marker2nd = mwf.createMapMarkerControl(map, false);
registerSideWidget(marker2nd, R.drawable.ic_action_flag, R.string.map_marker_2nd, WIDGET_MARKER_2, false, 19);
TextInfoWidget speed = ric.createSpeedControl(map);
registerSideWidget(speed, R.drawable.ic_action_speed, R.string.map_widget_speed, WIDGET_SPEED, false, 20);
TextInfoWidget maxspeed = ric.createMaxSpeedControl(map);
registerSideWidget(maxspeed, R.drawable.ic_action_speed_limit, R.string.map_widget_max_speed, WIDGET_MAX_SPEED, false, 21);
TextInfoWidget alt = mic.createAltitudeControl(map);
registerSideWidget(alt, R.drawable.ic_action_altitude, R.string.map_widget_altitude, WIDGET_ALTITUDE, false, 23);
TextInfoWidget gpsInfo = mic.createGPSInfoControl(map);
registerSideWidget(gpsInfo, R.drawable.ic_action_gps_info, R.string.map_widget_gps_info, WIDGET_GPS_INFO, false, 28);
TextInfoWidget plainTime = ric.createPlainTimeControl(map);
registerSideWidget(plainTime, R.drawable.ic_action_time, R.string.map_widget_plain_time, WIDGET_PLAIN_TIME, false, 41);
TextInfoWidget battery = ric.createBatteryControl(map);
registerSideWidget(battery, R.drawable.ic_action_battery, R.string.map_widget_battery, WIDGET_BATTERY, false, 42);
TextInfoWidget radiusRuler = mic.createRadiusRulerControl(map);
registerSideWidget(radiusRuler, new CompassRulerWidgetState(app), WIDGET_RADIUS_RULER, false, 43);
}
Aggregations