Wpt context menu fixes

This commit is contained in:
Alexey Kulish 2015-11-14 19:59:30 +03:00
parent ba1c7848bc
commit 308cdae795
3 changed files with 43 additions and 23 deletions

View file

@ -203,6 +203,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
originalGPX = null;
measurementPoints.clear();
calculateDistance();
activity.getContextMenu().close();
} else if (id == R.string.shared_string_save_as_gpx) {
saveGpx(activity);
} else if (id == R.string.distance_measurement_load_gpx) {
@ -637,25 +638,40 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) {
if(o instanceof WptPt) {
final WptPt p = (WptPt) o;
OnContextMenuClick listener = new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.delete_point) {
for (int i = 0; i < measurementPoints.size(); i++) {
Iterator<WptPt> it = measurementPoints.get(i).iterator();
while (it.hasNext()) {
if (it.next() == p) {
it.remove();
boolean containsPoint = false;
for (int i = 0; i < measurementPoints.size(); i++) {
Iterator<WptPt> it = measurementPoints.get(i).iterator();
while (it.hasNext()) {
if (it.next() == p) {
containsPoint = true;
break;
}
}
}
if (containsPoint) {
OnContextMenuClick listener = new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.delete_point) {
for (int i = 0; i < measurementPoints.size(); i++) {
Iterator<WptPt> it = measurementPoints.get(i).iterator();
while (it.hasNext()) {
if (it.next() == p) {
it.remove();
}
}
}
calculateDistance();
if (adapter.getContext() instanceof MapActivity) {
((MapActivity)adapter.getContext()).getContextMenu().close();
}
}
calculateDistance();
return true;
}
return true;
}
};
adapter.item(R.string.delete_point).iconColor(R.drawable.ic_action_delete_dark).listen(listener).reg();
};
adapter.item(R.string.delete_point).iconColor(R.drawable.ic_action_delete_dark).listen(listener).reg();
}
}
}

View file

@ -246,12 +246,14 @@ public class MapContextMenu extends MenuTitleController {
}
public void close() {
active = false;
if (this.object != null) {
clearSelectedObject(this.object);
if (active) {
active = false;
if (this.object != null) {
clearSelectedObject(this.object);
}
hide();
mapActivity.refreshMap();
}
hide();
mapActivity.refreshMap();
}
public void hide() {

View file

@ -23,7 +23,6 @@ import net.osmand.ValueHolder;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmAndFormatter;
@ -144,8 +143,11 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
adapter.item(R.string.context_menu_item_add_waypoint).iconColor(R.drawable.ic_action_gnew_label_dark)
.listen(listener).reg();
if (selectedObj instanceof WptPt) {
adapter.item(R.string.context_menu_item_edit_waypoint).iconColor(R.drawable.ic_action_edit_dark)
.listen(listener).reg();
WptPt pt = (WptPt) selectedObj;
if (app.getSelectedGpxHelper().getSelectedGPXFile(pt) != null) {
adapter.item(R.string.context_menu_item_edit_waypoint).iconColor(R.drawable.ic_action_edit_dark)
.listen(listener).reg();
}
}
}