From 6d8779e65aa461fbcb6e3965a8e895e27bb9d082 Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Tue, 3 Jan 2017 16:14:45 +0200 Subject: [PATCH] add osm bug action --- OsmAnd/res/values/strings.xml | 2 + .../osmand/plus/osmedit/OsmEditingPlugin.java | 12 +++-- .../plus/quickaction/QuickActionFactory.java | 51 +++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 95f12bd3c6..11bbb51601 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2471,6 +2471,7 @@ If you need help with OsmAnd application, please contact our support team: suppo Take audio note Take video note Take photo note + Add OSM bug Voice On/Off Add GPX waypoint Add Parking place @@ -2491,6 +2492,7 @@ If you need help with OsmAnd application, please contact our support team: suppo Tap on action will add audio note to the specified location. Tap on action will add video note to the specified location. Tap on action will add photo note to the specified location. + Tap on action will add OSM bug note to the specified location. Tap on action will disable or enable voice during navigation. Tap on action will add Parking place to the specified location. Show favorite dialog diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index d910aed155..083332c01c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -180,10 +180,7 @@ public class OsmEditingPlugin extends OsmandPlugin { editPoiDialogFragment.show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG); } else if (resId == R.string.context_menu_item_open_note) { - if (osmBugsLayer == null) { - registerLayers(mapActivity); - } - osmBugsLayer.openBug(latitude, longitude, ""); + openOsmNote(mapActivity, latitude, longitude); } else if (resId == R.string.poi_context_menu_delete) { new EditPoiDialogFragment.ShowDeleteDialogAsyncTask(mapActivity) .execute((Amenity) selectedObj); @@ -228,6 +225,13 @@ public class OsmEditingPlugin extends OsmandPlugin { .setListener(listener).createItem()); } + public void openOsmNote(MapActivity mapActivity, double latitude, double longitude) { + if (osmBugsLayer == null) { + registerLayers(mapActivity); + } + osmBugsLayer.openBug(latitude, longitude, ""); + } + @Override public void addMyPlacesTab(FavoritesActivity favoritesActivity, List mTabs, Intent intent) { if (getDBPOI().getOpenstreetmapPoints().size() > 0 || getDBBug().getOsmbugsPoints().size() > 0) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java index e8156db842..5ea5c80f1d 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java @@ -24,6 +24,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment; import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment; +import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.widgets.AutoCompleteTextViewEx; @@ -92,6 +93,11 @@ public class QuickActionFactory { quickActions.add(new ParkingAction()); } + if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) { + + quickActions.add(new AddOSMBugAction()); + } + quickActions.add(new QuickAction(0, R.string.quick_action_add_configure_map)); quickActions.add(new ShowHideFavoritesAction()); quickActions.add(new ShowHidePoiAction()); @@ -139,6 +145,9 @@ public class QuickActionFactory { case NavigationVoiceAction.TYPE: return new NavigationVoiceAction(); + case AddOSMBugAction.TYPE: + return new AddOSMBugAction(); + default: return new QuickAction(); } @@ -181,6 +190,9 @@ public class QuickActionFactory { case NavigationVoiceAction.TYPE: return new NavigationVoiceAction(quickAction); + case AddOSMBugAction.TYPE: + return new AddOSMBugAction(quickAction); + default: return quickAction; } @@ -767,4 +779,43 @@ public class QuickActionFactory { parent.addView(view); } } + + public static class AddOSMBugAction extends QuickAction { + public static final int TYPE = 12; + + protected AddOSMBugAction() { + id = System.currentTimeMillis(); + type = TYPE; + nameRes = R.string.quick_action_add_osm_bug; + iconRes = R.drawable.ic_action_bug_dark; + } + + public AddOSMBugAction(QuickAction quickAction) { + super(quickAction); + } + + @Override + public void execute(MapActivity activity) { + + LatLon latLon = activity.getMapView() + .getCurrentRotatedTileBox() + .getCenterLatLon(); + + OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); + if (plugin != null) + plugin.openOsmNote(activity, latLon.getLatitude(), latLon.getLongitude()); + } + + @Override + public void drawUI(ViewGroup parent, MapActivity activity) { + + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.quick_action_with_text, parent, false); + + ((TextView) view.findViewById(R.id.text)).setText( + R.string.quick_action_add_osm_bug_discr); + + parent.addView(view); + } + } }