From f535320503a116417d4f664c232d9ca194066925 Mon Sep 17 00:00:00 2001 From: thorsten Date: Thu, 1 Mar 2018 10:46:07 +0100 Subject: [PATCH] Use osmdroid 6.0.1 / Generalize ArrayList --- OSMBonusPack/build.gradle | 2 +- .../clustering/RadiusMarkerClusterer.java | 2 +- .../osmdroid/bonuspack/kml/KmlDocument.java | 17 +++++++++-------- .../osmdroid/bonuspack/kml/KmlGeometry.java | 15 ++++++++------- .../bonuspack/kml/KmlGroundOverlay.java | 7 ++++--- .../bonuspack/kml/KmlMultiGeometry.java | 3 ++- .../osmdroid/bonuspack/kml/KmlPlacemark.java | 8 ++++---- .../osmdroid/bonuspack/kml/KmlPolygon.java | 19 ++++++++++--------- .../osmbonuspacktuto/MainActivity.java | 2 +- 9 files changed, 40 insertions(+), 35 deletions(-) diff --git a/OSMBonusPack/build.gradle b/OSMBonusPack/build.gradle index df1fae68..c306842b 100644 --- a/OSMBonusPack/build.gradle +++ b/OSMBonusPack/build.gradle @@ -22,7 +22,7 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile "com.android.support:support-v4:23.2.1" - compile 'org.osmdroid:osmdroid-android:5.6.5' + compile 'org.osmdroid:osmdroid-android:6.0.1' compile 'org.apache.commons:commons-lang3:3.3.2' compile 'com.google.code.gson:gson:2.7' compile 'com.squareup.okhttp3:okhttp:3.4.1' diff --git a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/clustering/RadiusMarkerClusterer.java b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/clustering/RadiusMarkerClusterer.java index f2875e31..fabd5cff 100644 --- a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/clustering/RadiusMarkerClusterer.java +++ b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/clustering/RadiusMarkerClusterer.java @@ -103,7 +103,7 @@ private StaticCluster createCluster(Marker m, MapView mapView) { Iterator it = mClonedMarkers.iterator(); while (it.hasNext()) { Marker neighbour = it.next(); - int distance = clusterPosition.distanceTo(neighbour.getPosition()); + double distance = clusterPosition.distanceToAsDouble(neighbour.getPosition()); if (distance <= mRadiusInMeters) { cluster.add(neighbour); it.remove(); diff --git a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlDocument.java b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlDocument.java index bb738979..8f1f1c2d 100644 --- a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlDocument.java +++ b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlDocument.java @@ -35,6 +35,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.zip.ZipEntry; @@ -158,7 +159,7 @@ protected static GeoPoint parseKmlCoord(String input){ } /** KML coordinates are: lon,lat{,alt} tuples separated by separators (space, tab, cr). */ - protected static ArrayList parseKmlCoordinates(String input){ + protected static List parseKmlCoordinates(String input){ LinkedList tmpCoords = new LinkedList(); int i = 0; int tupleStart = 0; @@ -188,7 +189,7 @@ protected static ArrayList parseKmlCoordinates(String input){ } i++; } - ArrayList coordinates = new ArrayList(tmpCoords.size()); + List coordinates = new ArrayList<>(tmpCoords.size()); coordinates.addAll(tmpCoords); return coordinates; } @@ -373,9 +374,9 @@ protected class KmlSaxHandler extends DefaultHandler { private StringBuilder mStringBuilder = new StringBuilder(1024); private KmlFeature mKmlCurrentFeature; private KmlGroundOverlay mKmlCurrentGroundOverlay; //if GroundOverlay, pointer to mKmlCurrentFeature - private ArrayList mKmlFeatureStack; + private List mKmlFeatureStack; private KmlGeometry mKmlCurrentGeometry; - private ArrayList mKmlGeometryStack; + private List mKmlGeometryStack; public KmlFolder mKmlRoot; Style mCurrentStyle; String mCurrentStyleId; @@ -393,9 +394,9 @@ public KmlSaxHandler(File file, ZipFile kmzContainer){ mFile = file; mKMZFile = kmzContainer; mKmlRoot = new KmlFolder(); - mKmlFeatureStack = new ArrayList(); + mKmlFeatureStack = new ArrayList<>(); mKmlFeatureStack.add(mKmlRoot); - mKmlGeometryStack = new ArrayList(); + mKmlGeometryStack = new ArrayList<>(); mIsNetworkLink = false; mIsInnerBoundary = false; } @@ -858,8 +859,8 @@ else if (element == KmlKeywords.GroundOverlay) } else { //inside a Polygon innerBoundaryIs element: new hole KmlPolygon polygon = (KmlPolygon) mKmlCurrentGeometry; if (polygon.mHoles == null) - polygon.mHoles = new ArrayList>(); - ArrayList hole = parseKmlCoordinates(mStringBuilder.toString()); + polygon.mHoles = new ArrayList<>(); + List hole = parseKmlCoordinates(mStringBuilder.toString()); polygon.mHoles.add(hole); } } diff --git a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlGeometry.java b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlGeometry.java index a5487e5f..112bc6e8 100644 --- a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlGeometry.java +++ b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlGeometry.java @@ -17,6 +17,7 @@ import java.io.Writer; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; /** * KML Geometry. This is an abstract class. @@ -29,7 +30,7 @@ public abstract class KmlGeometry implements Cloneable, Parcelable { /** KML id attribute, if any. Null if none. */ public String mId; /** coordinates of the geometry. If Point, one and only one entry. */ - public ArrayList mCoordinates; + public List mCoordinates; //----------------------------------------------------- // abstract methods @@ -49,7 +50,7 @@ public KmlGeometry(){ * @param coordinates * @return false if error */ - public static boolean writeKMLCoordinates(Writer writer, ArrayList coordinates){ + public static boolean writeKMLCoordinates(Writer writer, List coordinates){ try { writer.write(""); for (GeoPoint coord:coordinates){ @@ -82,7 +83,7 @@ public static JsonArray geoJSONPosition(GeoPoint position){ * @param coordinates * @return the GeoJSON array of Positions. */ - public static JsonArray geoJSONCoordinates(ArrayList coordinates){ + public static JsonArray geoJSONCoordinates(List coordinates){ JsonArray json = new JsonArray(); Iterator it = coordinates.iterator(); while(it.hasNext()) { @@ -92,8 +93,8 @@ public static JsonArray geoJSONCoordinates(ArrayList coordinates){ return json; } - public static ArrayList cloneArrayOfGeoPoint(ArrayList coords){ - ArrayList result = new ArrayList(coords.size()); + public static List cloneArrayOfGeoPoint(List coords){ + List result = new ArrayList<>(coords.size()); for (GeoPoint p:coords) result.add(p.clone()); return result; @@ -108,10 +109,10 @@ public static GeoPoint parseGeoJSONPosition(JsonArray json){ } /** parse a GeoJSON array of Positions: [ [lon, lat, alt],... [lon, lat, alt] ] */ - public static ArrayList parseGeoJSONPositions(JsonArray json){ + public static List parseGeoJSONPositions(JsonArray json){ if (json == null) return null; - ArrayList coordinates = new ArrayList(json.size()); + List coordinates = new ArrayList<>(json.size()); for (int i=0; i mCoordinates; + public List mCoordinates; public KmlGroundOverlay(){ super(); @@ -111,9 +112,9 @@ public void setLatLonBox(double north, double south, double east, double west){ GeoPoint pSE = mCoordinates.get(1); overlay.setPosition(GeoPoint.fromCenterBetween(pNW, pSE)); GeoPoint pNE = new GeoPoint(pNW.getLatitude(), pSE.getLongitude()); - int width = pNE.distanceTo(pNW); + double width = pNE.distanceToAsDouble(pNW); GeoPoint pSW = new GeoPoint(pSE.getLatitude(), pNW.getLongitude()); - int height = pSW.distanceTo(pNW); + double height = pSW.distanceToAsDouble(pNW); overlay.setDimensions((float)width, (float)height); } //TODO: else if size=4, nonrectangular quadrilateral diff --git a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlMultiGeometry.java b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlMultiGeometry.java index 7855d8b9..3b432e48 100644 --- a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlMultiGeometry.java +++ b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlMultiGeometry.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.Writer; import java.util.ArrayList; +import java.util.List; /** * KML MultiGeometry and/or GeoJSON GeometryCollection. @@ -47,7 +48,7 @@ public KmlMultiGeometry(JsonObject json){ } } else if ("MultiPoint".equals(type)){ JsonArray coordinates = json.get("coordinates").getAsJsonArray(); - ArrayList positions = parseGeoJSONPositions(coordinates); + List positions = parseGeoJSONPositions(coordinates); for (GeoPoint p:positions){ KmlPoint kmlPoint = new KmlPoint(p); mItems.add(kmlPoint); diff --git a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlPlacemark.java b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlPlacemark.java index b2005d9b..6aac7997 100644 --- a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlPlacemark.java +++ b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlPlacemark.java @@ -16,7 +16,7 @@ import org.osmdroid.views.overlay.Polyline; import java.io.Writer; -import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.Set; @@ -58,8 +58,8 @@ public KmlPlacemark(Polygon polygon, KmlDocument kmlDoc){ mName = polygon.getTitle(); mDescription = polygon.getSnippet(); mGeometry = new KmlPolygon(); - mGeometry.mCoordinates = (ArrayList)polygon.getPoints(); - ((KmlPolygon)mGeometry).mHoles = (ArrayList>)polygon.getHoles(); + mGeometry.mCoordinates = polygon.getPoints(); + ((KmlPolygon)mGeometry).mHoles = polygon.getHoles(); mVisibility = polygon.isEnabled(); //Style: Style style = new Style(); @@ -74,7 +74,7 @@ public KmlPlacemark(Polyline polyline, KmlDocument kmlDoc){ mName = polyline.getTitle(); mDescription = polyline.getSnippet(); mGeometry = new KmlLineString(); - mGeometry.mCoordinates = (ArrayList)polyline.getPoints(); + mGeometry.mCoordinates = polyline.getPoints(); mVisibility = polyline.isEnabled(); //Style: Style style = new Style(); diff --git a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlPolygon.java b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlPolygon.java index c28856c1..728162f3 100644 --- a/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlPolygon.java +++ b/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/kml/KmlPolygon.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.Writer; import java.util.ArrayList; +import java.util.List; /** * KML and/or GeoJSON Polygon @@ -25,7 +26,7 @@ public class KmlPolygon extends KmlGeometry { /** Polygon holes (can be null if none) */ - public ArrayList> mHoles; + public List> mHoles; static int mDefaultLayoutResId = BonusPackHelper.UNDEFINED_RES_ID; @@ -90,9 +91,9 @@ public KmlPolygon(JsonObject json){ mCoordinates = KmlGeometry.parseGeoJSONPositions(rings.get(0).getAsJsonArray()); //next rings are the holes: if (rings.size() > 1){ - mHoles = new ArrayList>(rings.size()-1); + mHoles = new ArrayList>(rings.size()-1); for (int i=1; i hole = KmlGeometry.parseGeoJSONPositions(rings.get(i).getAsJsonArray()); + List hole = KmlGeometry.parseGeoJSONPositions(rings.get(i).getAsJsonArray()); mHoles.add(hole); } } @@ -105,7 +106,7 @@ public KmlPolygon(JsonObject json){ writeKMLCoordinates(writer, mCoordinates); writer.write("\n\n"); if (mHoles != null){ - for (ArrayList hole:mHoles){ + for (List hole:mHoles){ writer.write("\n\n"); writeKMLCoordinates(writer, hole); writer.write("\n\n"); @@ -123,7 +124,7 @@ public KmlPolygon(JsonObject json){ JsonArray coords = new JsonArray(); coords.add(KmlGeometry.geoJSONCoordinates(mCoordinates)); if (mHoles != null) { - for (ArrayList hole:mHoles){ + for (List hole:mHoles){ coords.add(KmlGeometry.geoJSONCoordinates(hole)); } } @@ -143,8 +144,8 @@ public KmlPolygon(JsonObject json){ @Override public KmlPolygon clone(){ KmlPolygon kmlPolygon = (KmlPolygon)super.clone(); if (mHoles != null){ - kmlPolygon.mHoles = new ArrayList>(mHoles.size()); - for (ArrayList hole:mHoles){ + kmlPolygon.mHoles = new ArrayList<>(mHoles.size()); + for (List hole:mHoles){ kmlPolygon.mHoles.add(cloneArrayOfGeoPoint(hole)); } } @@ -161,7 +162,7 @@ public KmlPolygon(JsonObject json){ super.writeToParcel(out, flags); if (mHoles != null){ out.writeInt(mHoles.size()); - for (ArrayList l:mHoles) + for (List l:mHoles) out.writeList(l); } else out.writeInt(0); @@ -180,7 +181,7 @@ public KmlPolygon(Parcel in){ super(in); int holes = in.readInt(); if (holes != 0){ - mHoles = new ArrayList>(holes); + mHoles = new ArrayList<>(holes); for (int i=0; i l = in.readArrayList(GeoPoint.class.getClassLoader()); mHoles.add(l); diff --git a/OSMBonusPackTuto/src/main/java/com/example/osmbonuspacktuto/MainActivity.java b/OSMBonusPackTuto/src/main/java/com/example/osmbonuspacktuto/MainActivity.java index 5c3837e4..849cc1ae 100644 --- a/OSMBonusPackTuto/src/main/java/com/example/osmbonuspacktuto/MainActivity.java +++ b/OSMBonusPackTuto/src/main/java/com/example/osmbonuspacktuto/MainActivity.java @@ -78,7 +78,7 @@ public class MainActivity extends Activity implements MapEventsReceiver, MapView //Introduction super.onCreate(savedInstanceState); - boolean hwAccelerationOK = org.osmdroid.bonuspack.overlays.Polygon.SDKsupportsPathOp(); + boolean hwAccelerationOK = true; //org.osmdroid.bonuspack.overlays.Polygon.SDKsupportsPathOp(); Configuration.getInstance().setMapViewHardwareAccelerated(hwAccelerationOK); LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.main, null);