use of net.osmand.plus.views.OsmandMapLayer.DrawSettings 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(new Runnable() {
@Override
public void run() {
int dn;
int d;
if (globalRecord) {
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 (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);
}
}, 500);
}
return true;
}
};
monitoringControl.updateInfo(null);
// monitoringControl.addView(child);
monitoringControl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
controlDialog(map, true);
}
});
return monitoringControl;
}
use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.
the class MapInfoWidgetsFactory method createRulerControl.
public TextInfoWidget createRulerControl(final MapActivity map) {
final String title = "—";
final TextInfoWidget rulerControl = new TextInfoWidget(map) {
RulerControlLayer rulerLayer = map.getMapLayers().getRulerControlLayer();
LatLon cacheFirstTouchPoint = new LatLon(0, 0);
LatLon cacheSecondTouchPoint = new LatLon(0, 0);
LatLon cacheSingleTouchPoint = new LatLon(0, 0);
boolean fingerAndLocDistWasShown;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
OsmandMapTileView view = map.getMapView();
Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
if (rulerLayer.isShowDistBetweenFingerAndLocation() && currentLoc != null) {
if (!cacheSingleTouchPoint.equals(rulerLayer.getTouchPointLatLon())) {
cacheSingleTouchPoint = rulerLayer.getTouchPointLatLon();
setDistanceText(cacheSingleTouchPoint.getLatitude(), cacheSingleTouchPoint.getLongitude(), currentLoc.getLatitude(), currentLoc.getLongitude());
fingerAndLocDistWasShown = true;
}
} else if (rulerLayer.isShowTwoFingersDistance()) {
if (!cacheFirstTouchPoint.equals(view.getFirstTouchPointLatLon()) || !cacheSecondTouchPoint.equals(view.getSecondTouchPointLatLon()) || fingerAndLocDistWasShown) {
cacheFirstTouchPoint = view.getFirstTouchPointLatLon();
cacheSecondTouchPoint = view.getSecondTouchPointLatLon();
setDistanceText(cacheFirstTouchPoint.getLatitude(), cacheFirstTouchPoint.getLongitude(), cacheSecondTouchPoint.getLatitude(), cacheSecondTouchPoint.getLongitude());
fingerAndLocDistWasShown = false;
}
} else {
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));
}
};
rulerControl.setText(title, null);
setRulerControlIcon(rulerControl, map.getMyApplication().getSettings().RULER_MODE.get());
rulerControl.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
final RulerMode mode = map.getMyApplication().getSettings().RULER_MODE.get();
RulerMode newMode = RulerMode.FIRST;
if (mode == RulerMode.FIRST) {
newMode = RulerMode.SECOND;
} else if (mode == RulerMode.SECOND) {
newMode = RulerMode.EMPTY;
}
setRulerControlIcon(rulerControl, newMode);
map.getMyApplication().getSettings().RULER_MODE.set(newMode);
map.refreshMap();
}
});
return rulerControl;
}
use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.
the class MapInfoWidgetsFactory method createAltitudeControl.
public TextInfoWidget createAltitudeControl(final MapActivity map) {
final TextInfoWidget altitudeControl = new TextInfoWidget(map) {
private int cachedAlt = 0;
@Override
public boolean updateInfo(DrawSettings d) {
// draw speed
Location loc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
if (loc != null && loc.hasAltitude()) {
double compAlt = loc.getAltitude();
if (cachedAlt != (int) compAlt) {
cachedAlt = (int) compAlt;
String ds = OsmAndFormatter.getFormattedAlt(cachedAlt, 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 (cachedAlt != 0) {
cachedAlt = 0;
setText(null, null);
return true;
}
return false;
}
};
altitudeControl.setText(null, null);
altitudeControl.setIcons(R.drawable.widget_altitude_day, R.drawable.widget_altitude_night);
return altitudeControl;
}
use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.
the class OsmandMapTileView method refreshBufferImage.
private void refreshBufferImage(final DrawSettings drawSettings) {
if (mapRenderer != null) {
return;
}
if (!baseHandler.hasMessages(BASE_REFRESH_MESSAGE) || drawSettings.isUpdateVectorRendering()) {
Message msg = Message.obtain(baseHandler, new Runnable() {
@Override
public void run() {
baseHandler.removeMessages(BASE_REFRESH_MESSAGE);
try {
DrawSettings param = drawSettings;
Boolean currentNightMode = nightMode;
if (currentNightMode != null && currentNightMode != param.isNightMode()) {
param = new DrawSettings(currentNightMode, true);
resetDefaultColor();
}
if (handler.hasMessages(MAP_FORCE_REFRESH_MESSAGE)) {
if (!param.isUpdateVectorRendering()) {
param = new DrawSettings(drawSettings.isNightMode(), true);
}
handler.removeMessages(MAP_FORCE_REFRESH_MESSAGE);
}
refreshBaseMapInternal(currentViewport.copy(), param);
sendRefreshMapMsg(param, 0);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
});
msg.what = drawSettings.isUpdateVectorRendering() ? MAP_FORCE_REFRESH_MESSAGE : BASE_REFRESH_MESSAGE;
// baseHandler.sendMessageDelayed(msg, 0);
baseHandler.sendMessage(msg);
}
}
use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.
the class OsmandMapTileView method sendRefreshMapMsg.
private void sendRefreshMapMsg(final DrawSettings drawSettings, int delay) {
if (!handler.hasMessages(MAP_REFRESH_MESSAGE) || drawSettings.isUpdateVectorRendering()) {
Message msg = Message.obtain(handler, new Runnable() {
@Override
public void run() {
DrawSettings param = drawSettings;
handler.removeMessages(MAP_REFRESH_MESSAGE);
refreshMapInternal(param);
}
});
msg.what = MAP_REFRESH_MESSAGE;
if (delay > 0) {
handler.sendMessageDelayed(msg, delay);
} else {
handler.sendMessage(msg);
}
}
}
Aggregations