Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-10-29 15:25:34 +01:00
commit d2538cd212
5 changed files with 56 additions and 14 deletions

View file

@ -93,8 +93,8 @@ public class MapContextMenu extends MenuTitleController {
return init(latLon, pointDescription, object, false); return init(latLon, pointDescription, object, false);
} }
public boolean init(LatLon latLon, PointDescription pointDescription, Object object, boolean reload) { public boolean init(LatLon latLon, PointDescription pointDescription, Object object, boolean update) {
if (!reload && isVisible()) { if (!update && isVisible()) {
if (this.object == null || !this.object.equals(object)) { if (this.object == null || !this.object.equals(object)) {
hide(); hide();
} else { } else {
@ -105,6 +105,7 @@ public class MapContextMenu extends MenuTitleController {
if (this.object != null) { if (this.object != null) {
clearSelectedObject(this.object); clearSelectedObject(this.object);
} }
setSelectedObject(object);
if (pointDescription == null) { if (pointDescription == null) {
this.pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude()); this.pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
@ -145,7 +146,7 @@ public class MapContextMenu extends MenuTitleController {
} }
} }
public void refreshMenu(LatLon latLon, PointDescription pointDescription, Object object) { public void update(LatLon latLon, PointDescription pointDescription, Object object) {
MapContextMenuFragment fragment = findMenuFragment(); MapContextMenuFragment fragment = findMenuFragment();
if (fragment != null) { if (fragment != null) {
init(latLon, pointDescription, object, true); init(latLon, pointDescription, object, true);
@ -153,6 +154,14 @@ public class MapContextMenu extends MenuTitleController {
} }
} }
public void showOrUpdate(LatLon latLon, PointDescription pointDescription, Object object) {
if (isVisible() && this.object != null && this.object.equals(object)) {
update(latLon, pointDescription, object);
} else {
show(latLon, pointDescription, object);
}
}
public void close() { public void close() {
active = false; active = false;
hide(); hide();
@ -171,6 +180,21 @@ public class MapContextMenu extends MenuTitleController {
} }
private void clearSelectedObject(Object object) { private void clearSelectedObject(Object object) {
if (object != null) {
for (OsmandMapLayer l : mapActivity.getMapView().getLayers()) {
if (l instanceof ContextMenuLayer.IContextMenuProvider) {
PointDescription pointDescription = ((ContextMenuLayer.IContextMenuProvider) l).getObjectName(object);
if (pointDescription != null) {
if (l instanceof ContextMenuLayer.IContextMenuProviderSelection) {
((ContextMenuLayer.IContextMenuProviderSelection) l).clearSelectedObject();
}
}
}
}
}
}
private void setSelectedObject(Object object) {
if (object != null) { if (object != null) {
for (OsmandMapLayer l : mapActivity.getMapView().getLayers()) { for (OsmandMapLayer l : mapActivity.getMapView().getLayers()) {
if (l instanceof ContextMenuLayer.IContextMenuProvider) { if (l instanceof ContextMenuLayer.IContextMenuProvider) {

View file

@ -2,6 +2,8 @@ package net.osmand.plus.mapcontextmenu.details;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import net.osmand.Location;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -49,8 +51,19 @@ public class OsMoMenuController extends MenuController {
@Override @Override
public String getTypeStr() { public String getTypeStr() {
// todo OsmandApplication app = getMapActivity().getMyApplication();
return ""; StringBuilder sb = new StringBuilder();
final Location l = device.getLastLocation();
if(l != null && l.hasSpeed()) {
sb.append(OsmAndFormatter.getFormattedSpeed(l.getSpeed(), app));
sb.append("");
}
Location myLocation = app.getLocationProvider().getLastKnownLocation();
if (myLocation != null) {
float dist = myLocation.distanceTo(l);
sb.append(OsmAndFormatter.getFormattedDistance(dist, app));
}
return sb.toString();
} }
@Override @Override

View file

@ -53,7 +53,11 @@ public class TargetPointMenuController extends MenuController {
@Override @Override
public String getNameStr() { public String getNameStr() {
if (targetPoint.getOriginalPointDescription() != null) {
return targetPoint.getOriginalPointDescription().getSimpleName(getMapActivity(), false); return targetPoint.getOriginalPointDescription().getSimpleName(getMapActivity(), false);
} else {
return targetPoint.getOnlyName();
}
} }
@Override @Override

View file

@ -6,7 +6,6 @@ import android.content.DialogInterface;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -156,7 +155,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
PointDescription pointDescription = favorite.getPointDescription(); PointDescription pointDescription = favorite.getPointDescription();
pointDescription.setLat(favorite.getLatitude()); pointDescription.setLat(favorite.getLatitude());
pointDescription.setLon(favorite.getLongitude()); pointDescription.setLon(favorite.getLongitude());
menu.refreshMenu(latLon, pointDescription, favorite); menu.update(latLon, pointDescription, favorite);
} }
} }

View file

@ -349,7 +349,8 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
ContextMenuLayer cl = map.getMapLayers().getContextMenuLayer(); ContextMenuLayer cl = map.getMapLayers().getContextMenuLayer();
final boolean sameObject; final boolean sameObject;
if (map.getContextMenu().getObject() instanceof OsMoDevice && cl.isVisible()) { if (map.getContextMenu().getObject() instanceof OsMoDevice && cl.isVisible()) {
sameObject = Algorithms.objectEquals(device.trackerId, ((OsMoDevice) map.getContextMenu().getObject()).trackerId); sameObject = Algorithms.objectEquals(device.trackerId,
((OsMoDevice) map.getContextMenu().getObject()).trackerId);
} else { } else {
sameObject = false; sameObject = false;
} }
@ -374,13 +375,14 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
schedule = false; schedule = false;
if (sameObject) { if (sameObject) {
Location l = device.getLastLocation(); Location l = device.getLastLocation();
map.getContextMenu().show(new LatLon(l.getLatitude(), l.getLongitude()), getObjectName(device), device); if (centered) {
//cl.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), getObjectDescription(device)); map.getContextMenu().setMapCenter(loc);
//cl.setSelectedObject(device); }
map.getContextMenu().showOrUpdate(new LatLon(l.getLatitude(), l.getLongitude()),
getObjectName(device), device);
} }
if (centered) { if (centered) {
map.getMapView().setLatLon(loc.getLatitude(), map.getMapView().setLatLon(loc.getLatitude(), loc.getLongitude());
loc.getLongitude());
} }
map.getMapView().refreshMap(); map.getMapView().refreshMap();
} }