From df3397eb406aa7c8703e22a6ec1cab75e921c5f9 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 6 Sep 2018 15:19:39 +0300 Subject: [PATCH] Add constants for mapObjects --- OsmAnd-java/src/main/java/net/osmand/data/MapObject.java | 5 +++++ .../controllers/RenderedObjectMenuController.java | 8 +++++--- .../net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java | 9 +++++---- .../net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java | 9 +++++---- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/MapObject.java b/OsmAnd-java/src/main/java/net/osmand/data/MapObject.java index 71caa0bdc2..8c345239d6 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/MapObject.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/MapObject.java @@ -18,6 +18,11 @@ import net.sf.junidecode.Junidecode; public abstract class MapObject implements Comparable { public static final MapObjectComparator BY_NAME_COMPARATOR = new MapObjectComparator(); + + public static final byte AMENITY_ID_RIGHT_SHIFT = 1; + public static final byte NON_AMENITY_ID_RIGHT_SHIFT = 7; + + public static final byte WAY_MODULO_REMAINDER = 1; protected String name = null; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java index d0988ad488..f657a6f2fe 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java @@ -4,6 +4,7 @@ import android.support.annotation.NonNull; import net.osmand.NativeLibrary.RenderedObject; import net.osmand.data.LatLon; +import net.osmand.data.MapObject; import net.osmand.data.PointDescription; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; @@ -115,14 +116,15 @@ public class RenderedObjectMenuController extends MenuController { boolean osmEditingEnabled = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null; if (osmEditingEnabled && renderedObject.getId() != null && renderedObject.getId() > 0 && - (renderedObject.getId() % 2 == 1 || (renderedObject.getId() >> 7) < Integer.MAX_VALUE)) { + (renderedObject.getId() % 2 == MapObject.AMENITY_ID_RIGHT_SHIFT + || (renderedObject.getId() >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT) < Integer.MAX_VALUE)) { String link; - if ((renderedObject.getId() >> 6) % 2 == 1) { + if ((renderedObject.getId() >> 6) % 2 == MapObject.WAY_MODULO_REMAINDER) { link = "https://www.openstreetmap.org/node/"; } else { link = "https://www.openstreetmap.org/way/"; } - addPlainMenuItem(R.drawable.ic_action_info_dark, null, link + (renderedObject.getId() >> 7), true, true, null); + addPlainMenuItem(R.drawable.ic_action_info_dark, null, link + (renderedObject.getId() >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT), true, true, null); } addMyLocationToPlainItems(latLon); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java index cc4927eaf3..c55e2099ed 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java @@ -83,17 +83,18 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { @Override public Entity loadEntity(MapObject mapObject) { Long objectId = mapObject.getId(); - if (!(objectId != null && objectId > 0 && (objectId % 2 == 1 || (objectId >> 7) < Integer.MAX_VALUE))) { + if (!(objectId != null && objectId > 0 && (objectId % 2 == MapObject.AMENITY_ID_RIGHT_SHIFT + || (objectId >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT) < Integer.MAX_VALUE))) { return null; } Amenity amenity = null; long entityId; - boolean isWay = objectId % 2 == 1; // check if mapObject is a way + boolean isWay = objectId % 2 == MapObject.WAY_MODULO_REMAINDER; // check if mapObject is a way if (mapObject instanceof Amenity) { amenity = (Amenity) mapObject; - entityId = mapObject.getId() >> 1; + entityId = mapObject.getId() >> MapObject.AMENITY_ID_RIGHT_SHIFT; } else { - entityId = mapObject.getId() >> 7; + entityId = mapObject.getId() >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT; } PoiType poiType = null; if (amenity != null) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java index bb937a7c57..15b60f2a57 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java @@ -414,15 +414,16 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { @Override public Entity loadEntity(MapObject object) { Long objectId = object.getId(); - if (!(objectId != null && objectId > 0 && (objectId % 2 == 1 || (objectId >> 7) < Integer.MAX_VALUE))) { + if (!(objectId != null && objectId > 0 && (objectId % 2 == MapObject.AMENITY_ID_RIGHT_SHIFT + || (objectId >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT) < Integer.MAX_VALUE))) { return null; } - boolean isWay = objectId % 2 == 1;// check if mapObject is a way + boolean isWay = objectId % 2 == MapObject.WAY_MODULO_REMAINDER;// check if mapObject is a way long entityId; if (object instanceof Amenity) { - entityId = objectId >> 1; + entityId = objectId >> MapObject.AMENITY_ID_RIGHT_SHIFT; } else { - entityId = objectId >> 7; + entityId = objectId >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT; } try { String api = isWay ? "api/0.6/way/" : "api/0.6/node/";