Merge pull request #4975 from osmandapp/osm_notes_options

Fix #4740
This commit is contained in:
Alexander Sytnyk 2018-02-01 18:28:44 +02:00 committed by GitHub
commit 55306a9761
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 178 additions and 6 deletions

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="show_closed_notes">Show closed notes</string>
<string name="switch_osm_notes_visibility_desc">Show/Hide OSM Notes on the map.</string>
<string name="gpx_file_desc">GPX - suitable for export to JOSM or other OSM editors.</string>
<string name="osc_file_desc">OSC - suitable for export to OpenStreetMap.</string>
<string name="gpx_file">GPX file</string>

View file

@ -1161,6 +1161,8 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> SHOW_OSM_BUGS = new BooleanPreference("show_osm_bugs", false).makeGlobal();
public final CommonPreference<Boolean> SHOW_CLOSED_OSM_BUGS = new BooleanPreference("show_closed_osm_bugs", false).makeGlobal();
public final CommonPreference<Integer> SHOW_OSM_BUGS_MIN_ZOOM = new IntPreference("show_osm_bugs_min_zoom", 8).makeGlobal();
public final CommonPreference<String> MAP_INFO_CONTROLS = new StringPreference("map_info_controls", "").makeProfile();
{

View file

@ -76,6 +76,7 @@ import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu;
import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu.LocalRoutingParameter;
import net.osmand.plus.mapillary.MapillaryFiltersFragment;
import net.osmand.plus.mapillary.MapillaryPlugin.MapillaryFirstDialogFragment;
import net.osmand.plus.osmedit.OsmNotesMenu;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
@ -189,7 +190,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
UNDERLAY_MAP,
MAPILLARY,
CONTOUR_LINES,
HILLSHADE
HILLSHADE,
OSM_NOTES
}
private Map<DashboardActionButtonType, DashboardActionButton> actionButtons = new HashMap<>();
@ -428,6 +430,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
tv.setText(R.string.srtm_plugin_name);
} else if (visibleType == DashboardType.HILLSHADE) {
tv.setText(R.string.layer_hillshade);
} else if (visibleType == DashboardType.OSM_NOTES) {
tv.setText(R.string.osm_notes);
}
ImageView edit = (ImageView) dashboardView.findViewById(R.id.toolbar_edit);
edit.setVisibility(View.GONE);
@ -822,7 +826,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
&& visibleType != DashboardType.CONFIGURE_SCREEN
&& visibleType != DashboardType.CONFIGURE_MAP
&& visibleType != DashboardType.CONTOUR_LINES
&& visibleType != DashboardType.HILLSHADE) {
&& visibleType != DashboardType.HILLSHADE
&& visibleType != DashboardType.OSM_NOTES) {
listView.setDivider(dividerDrawable);
listView.setDividerHeight(dpToPx(1f));
} else {
@ -879,6 +884,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
cm = ContourLinesMenu.createListAdapter(mapActivity);
} else if (visibleType == DashboardType.HILLSHADE) {
cm = HillshadeMenu.createListAdapter(mapActivity);
} else if (visibleType == DashboardType.OSM_NOTES) {
cm = OsmNotesMenu.createListAdapter(mapActivity);
}
if (cm != null) {
updateListAdapter(cm);

View file

@ -50,7 +50,6 @@ import java.util.List;
public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider {
private static final Log log = PlatformUtil.getLog(OsmBugsLayer.class);
private final static int startZoom = 8;
private final OsmEditingPlugin plugin;
private OsmandMapTileView view;
@ -65,6 +64,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
private OsmBugsLocalUtil local;
private MapLayerData<List<OpenStreetNote>> data;
private int startZoom;
public OsmBugsLayer(MapActivity activity, OsmEditingPlugin plugin) {
this.activity = activity;
this.plugin = plugin;
@ -116,6 +117,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
startZoom = activity.getMyApplication().getSettings().SHOW_OSM_BUGS_MIN_ZOOM.get();
if (tileBox.getZoom() >= startZoom) {
// request to load
data.queryNewData(tileBox);
@ -127,7 +129,11 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
List<OpenStreetNote> fullObjects = new ArrayList<>();
List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>();
boolean showClosed = activity.getMyApplication().getSettings().SHOW_CLOSED_OSM_BUGS.get();
for (OpenStreetNote o : objects) {
if (!o.isOpened() && !showClosed) {
continue;
}
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
@ -146,6 +152,9 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
}
}
for (OpenStreetNote o : fullObjects) {
if (!o.isOpened() && !showClosed) {
continue;
}
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
Bitmap b;
@ -200,9 +209,13 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
final int rad = getRadiusBug(tb);
int radius = rad * 3 / 2;
int small = rad * 3 / 4;
boolean showClosed = activity.getMyApplication().getSettings().SHOW_CLOSED_OSM_BUGS.get();
try {
for (int i = 0; i < objects.size(); i++) {
OpenStreetNote n = objects.get(i);
if (!n.isOpened() && !showClosed) {
continue;
}
int x = (int) tb.getPixXFromLatLon(n.getLatitude(), n.getLongitude());
int y = (int) tb.getPixYFromLatLon(n.getLatitude(), n.getLongitude());
if (Math.abs(x - ex) <= radius && Math.abs(y - ey) <= radius) {

View file

@ -15,6 +15,7 @@ import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.osm.PoiType;
@ -30,6 +31,7 @@ import net.osmand.plus.activities.EnumAdapter;
import net.osmand.plus.activities.EnumAdapter.IEnumWithResource;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.myplaces.AvailableGPXFragment;
import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo;
@ -258,11 +260,23 @@ public class OsmEditingPlugin extends OsmandPlugin {
@Override
public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_osm_bugs, mapActivity)
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.layer_osm_bugs, mapActivity)
.setSelected(settings.SHOW_OSM_BUGS.get())
.setIcon(R.drawable.ic_action_bug_dark)
.setColor(settings.SHOW_OSM_BUGS.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setListener(new ContextMenuAdapter.ItemClickListener() {
.setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
if (itemId == R.string.layer_osm_bugs) {
mapActivity.getDashboard().setDashboardVisibility(true,
DashboardType.OSM_NOTES, AndroidUtils.getCenterViewCoordinates(view));
return false;
}
return true;
}
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
@ -279,7 +293,6 @@ public class OsmEditingPlugin extends OsmandPlugin {
})
.setPosition(16)
.createItem());
}
@Override

View file

@ -0,0 +1,135 @@
package net.osmand.plus.osmedit;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.ArrayAdapter;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import java.util.Arrays;
public class OsmNotesMenu {
private static Integer[] zoomIntValues = {8, 9, 10, 11, 12, 13, 14, 15, 16};
public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity) {
ContextMenuAdapter adapter = new ContextMenuAdapter();
adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
createLayersItems(adapter, mapActivity);
return adapter;
}
private static void createLayersItems(final ContextMenuAdapter adapter, final MapActivity mapActivity) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
final OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin == null) {
return;
}
final int osmNotesStringId = R.string.layer_osm_bugs;
final int showZoomLevelStringId = R.string.show_from_zoom_level;
final int showClosedNotesStringId = R.string.show_closed_notes;
final OsmandPreference<Boolean> showOsmBugsPref = settings.SHOW_OSM_BUGS;
final CommonPreference<Boolean> showClosedOsmBugsPref = settings.SHOW_CLOSED_OSM_BUGS;
final CommonPreference<Integer> showOsmBugsZoomPref = settings.SHOW_OSM_BUGS_MIN_ZOOM;
final String[] zoomStrings = getZoomStrings(mapActivity);
ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId,
final int position, boolean isChecked, int[] viewCoordinates) {
if (itemId == osmNotesStringId) {
showOsmBugsPref.set(isChecked);
plugin.updateLayers(mapActivity.getMapView(), mapActivity);
mapActivity.refreshMap();
mapActivity.getDashboard().refreshContent(true);
} else if (itemId == showZoomLevelStringId) {
int checked = Arrays.asList(zoomIntValues).indexOf(showOsmBugsZoomPref.get());
new AlertDialog.Builder(mapActivity)
.setTitle(R.string.show_from_zoom_level)
.setSingleChoiceItems(zoomStrings, checked, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showOsmBugsZoomPref.set(zoomIntValues[which]);
ContextMenuItem item = adapter.getItem(position);
if (item != null) {
item.setDescription(zoomStrings[which]);
adapter.notifyDataSetChanged();
}
mapActivity.refreshMap();
dialog.dismiss();
}
})
.setNegativeButton(R.string.shared_string_dismiss, null)
.show();
} else if (itemId == showClosedNotesStringId) {
showClosedOsmBugsPref.set(isChecked);
mapActivity.refreshMap();
}
return false;
}
};
boolean showOsmBugs = showOsmBugsPref.get();
boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
int toggleIconColorId;
if (showOsmBugs) {
toggleIconColorId = nightMode ? R.color.color_dialog_buttons_dark : R.color.color_dialog_buttons_light;
} else {
toggleIconColorId = nightMode ? 0 : R.color.icon_color;
}
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(osmNotesStringId, mapActivity)
.setDescription(mapActivity.getString(R.string.switch_osm_notes_visibility_desc))
.setIcon(R.drawable.ic_action_bug_dark)
.setColor(toggleIconColorId)
.setListener(l)
.setSelected(showOsmBugs)
.createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(showZoomLevelStringId, mapActivity)
.setDescription(zoomStrings[Arrays.asList(zoomIntValues).indexOf(showOsmBugsZoomPref.get())])
.setLayout(R.layout.list_item_single_line_descrition_narrow)
.setIcon(R.drawable.ic_action_map_magnifier)
.setListener(l)
.setClickable(showOsmBugs)
.createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(showClosedNotesStringId, mapActivity)
.setIcon(R.drawable.ic_action_note_dark)
.setListener(l)
.setSelected(showClosedOsmBugsPref.get())
.setClickable(showOsmBugs)
.hideDivider(true)
.createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setLayout(R.layout.card_bottom_divider)
.setClickable(false)
.createItem());
}
private static String[] getZoomStrings(Context context) {
String[] res = new String[zoomIntValues.length];
for (int i = 0; i < zoomIntValues.length; i++) {
String strVal = String.valueOf(zoomIntValues[i]);
res[i] = i == 0 ? context.getString(R.string.rendering_value_default_name) + " (" + strVal + ")" : strVal;
}
return res;
}
}