Context menu: OsMo menu ready
This commit is contained in:
parent
1d621dff59
commit
1f553c1c14
5 changed files with 56 additions and 14 deletions
|
@ -93,8 +93,8 @@ public class MapContextMenu extends MenuTitleController {
|
|||
return init(latLon, pointDescription, object, false);
|
||||
}
|
||||
|
||||
public boolean init(LatLon latLon, PointDescription pointDescription, Object object, boolean reload) {
|
||||
if (!reload && isVisible()) {
|
||||
public boolean init(LatLon latLon, PointDescription pointDescription, Object object, boolean update) {
|
||||
if (!update && isVisible()) {
|
||||
if (this.object == null || !this.object.equals(object)) {
|
||||
hide();
|
||||
} else {
|
||||
|
@ -105,6 +105,7 @@ public class MapContextMenu extends MenuTitleController {
|
|||
if (this.object != null) {
|
||||
clearSelectedObject(this.object);
|
||||
}
|
||||
setSelectedObject(object);
|
||||
|
||||
if (pointDescription == null) {
|
||||
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();
|
||||
if (fragment != null) {
|
||||
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() {
|
||||
active = false;
|
||||
hide();
|
||||
|
@ -171,6 +180,21 @@ public class MapContextMenu extends MenuTitleController {
|
|||
}
|
||||
|
||||
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) {
|
||||
for (OsmandMapLayer l : mapActivity.getMapView().getLayers()) {
|
||||
if (l instanceof ContextMenuLayer.IContextMenuProvider) {
|
||||
|
|
|
@ -2,6 +2,8 @@ package net.osmand.plus.mapcontextmenu.details;
|
|||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -49,8 +51,19 @@ public class OsMoMenuController extends MenuController {
|
|||
|
||||
@Override
|
||||
public String getTypeStr() {
|
||||
// todo
|
||||
return "";
|
||||
OsmandApplication app = getMapActivity().getMyApplication();
|
||||
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
|
||||
|
|
|
@ -53,7 +53,11 @@ public class TargetPointMenuController extends MenuController {
|
|||
|
||||
@Override
|
||||
public String getNameStr() {
|
||||
return targetPoint.getOriginalPointDescription().getSimpleName(getMapActivity(), false);
|
||||
if (targetPoint.getOriginalPointDescription() != null) {
|
||||
return targetPoint.getOriginalPointDescription().getSimpleName(getMapActivity(), false);
|
||||
} else {
|
||||
return targetPoint.getOnlyName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.content.DialogInterface;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -156,7 +155,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
PointDescription pointDescription = favorite.getPointDescription();
|
||||
pointDescription.setLat(favorite.getLatitude());
|
||||
pointDescription.setLon(favorite.getLongitude());
|
||||
menu.refreshMenu(latLon, pointDescription, favorite);
|
||||
menu.update(latLon, pointDescription, favorite);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -349,7 +349,8 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
ContextMenuLayer cl = map.getMapLayers().getContextMenuLayer();
|
||||
final boolean sameObject;
|
||||
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 {
|
||||
sameObject = false;
|
||||
}
|
||||
|
@ -374,13 +375,14 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
schedule = false;
|
||||
if (sameObject) {
|
||||
Location l = device.getLastLocation();
|
||||
map.getContextMenu().show(new LatLon(l.getLatitude(), l.getLongitude()), getObjectName(device), device);
|
||||
//cl.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), getObjectDescription(device));
|
||||
//cl.setSelectedObject(device);
|
||||
if (centered) {
|
||||
map.getContextMenu().setMapCenter(loc);
|
||||
}
|
||||
map.getContextMenu().showOrUpdate(new LatLon(l.getLatitude(), l.getLongitude()),
|
||||
getObjectName(device), device);
|
||||
}
|
||||
if (centered) {
|
||||
map.getMapView().setLatLon(loc.getLatitude(),
|
||||
loc.getLongitude());
|
||||
map.getMapView().setLatLon(loc.getLatitude(), loc.getLongitude());
|
||||
}
|
||||
map.getMapView().refreshMap();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue