Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use osmdroid 6.0.1 / Generalize ArrayList #324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OSMBonusPack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private StaticCluster createCluster(Marker m, MapView mapView) {
Iterator<Marker> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<GeoPoint> parseKmlCoordinates(String input){
protected static List<GeoPoint> parseKmlCoordinates(String input){
LinkedList<GeoPoint> tmpCoords = new LinkedList<GeoPoint>();
int i = 0;
int tupleStart = 0;
Expand Down Expand Up @@ -188,7 +189,7 @@ protected static ArrayList<GeoPoint> parseKmlCoordinates(String input){
}
i++;
}
ArrayList<GeoPoint> coordinates = new ArrayList<GeoPoint>(tmpCoords.size());
List<GeoPoint> coordinates = new ArrayList<>(tmpCoords.size());
coordinates.addAll(tmpCoords);
return coordinates;
}
Expand Down Expand Up @@ -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<KmlFeature> mKmlFeatureStack;
private List<KmlFeature> mKmlFeatureStack;
private KmlGeometry mKmlCurrentGeometry;
private ArrayList<KmlGeometry> mKmlGeometryStack;
private List<KmlGeometry> mKmlGeometryStack;
public KmlFolder mKmlRoot;
Style mCurrentStyle;
String mCurrentStyleId;
Expand All @@ -393,9 +394,9 @@ public KmlSaxHandler(File file, ZipFile kmzContainer){
mFile = file;
mKMZFile = kmzContainer;
mKmlRoot = new KmlFolder();
mKmlFeatureStack = new ArrayList<KmlFeature>();
mKmlFeatureStack = new ArrayList<>();
mKmlFeatureStack.add(mKmlRoot);
mKmlGeometryStack = new ArrayList<KmlGeometry>();
mKmlGeometryStack = new ArrayList<>();
mIsNetworkLink = false;
mIsInnerBoundary = false;
}
Expand Down Expand Up @@ -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<GeoPoint>>();
ArrayList<GeoPoint> hole = parseKmlCoordinates(mStringBuilder.toString());
polygon.mHoles = new ArrayList<>();
List<GeoPoint> hole = parseKmlCoordinates(mStringBuilder.toString());
polygon.mHoles.add(hole);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<GeoPoint> mCoordinates;
public List<GeoPoint> mCoordinates;

//-----------------------------------------------------
// abstract methods
Expand All @@ -49,7 +50,7 @@ public KmlGeometry(){
* @param coordinates
* @return false if error
*/
public static boolean writeKMLCoordinates(Writer writer, ArrayList<GeoPoint> coordinates){
public static boolean writeKMLCoordinates(Writer writer, List<GeoPoint> coordinates){
try {
writer.write("<coordinates>");
for (GeoPoint coord:coordinates){
Expand Down Expand Up @@ -82,7 +83,7 @@ public static JsonArray geoJSONPosition(GeoPoint position){
* @param coordinates
* @return the GeoJSON array of Positions.
*/
public static JsonArray geoJSONCoordinates(ArrayList<GeoPoint> coordinates){
public static JsonArray geoJSONCoordinates(List<GeoPoint> coordinates){
JsonArray json = new JsonArray();
Iterator<GeoPoint> it = coordinates.iterator();
while(it.hasNext()) {
Expand All @@ -92,8 +93,8 @@ public static JsonArray geoJSONCoordinates(ArrayList<GeoPoint> coordinates){
return json;
}

public static ArrayList<GeoPoint> cloneArrayOfGeoPoint(ArrayList<GeoPoint> coords){
ArrayList<GeoPoint> result = new ArrayList<GeoPoint>(coords.size());
public static List<GeoPoint> cloneArrayOfGeoPoint(List<GeoPoint> coords){
List<GeoPoint> result = new ArrayList<>(coords.size());
for (GeoPoint p:coords)
result.add(p.clone());
return result;
Expand All @@ -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<GeoPoint> parseGeoJSONPositions(JsonArray json){
public static List<GeoPoint> parseGeoJSONPositions(JsonArray json){
if (json == null)
return null;
ArrayList<GeoPoint> coordinates = new ArrayList<GeoPoint>(json.size());
List<GeoPoint> coordinates = new ArrayList<>(json.size());
for (int i=0; i<json.size(); i++){
JsonArray position = json.get(i).getAsJsonArray();
GeoPoint p = KmlGeometry.parseGeoJSONPosition(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.InputStream;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

Expand All @@ -42,7 +43,7 @@ public class KmlGroundOverlay extends KmlFeature implements Cloneable, Parcelabl
/** GroundOverlay rotation - default = 0 */
public float mRotation;
/** NW and SE points - TODO: not the simplest way to handle that... */
public ArrayList<GeoPoint> mCoordinates;
public List<GeoPoint> mCoordinates;

public KmlGroundOverlay(){
super();
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -47,7 +48,7 @@ public KmlMultiGeometry(JsonObject json){
}
} else if ("MultiPoint".equals(type)){
JsonArray coordinates = json.get("coordinates").getAsJsonArray();
ArrayList<GeoPoint> positions = parseGeoJSONPositions(coordinates);
List<GeoPoint> positions = parseGeoJSONPositions(coordinates);
for (GeoPoint p:positions){
KmlPoint kmlPoint = new KmlPoint(p);
mItems.add(kmlPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -58,8 +58,8 @@ public KmlPlacemark(Polygon polygon, KmlDocument kmlDoc){
mName = polygon.getTitle();
mDescription = polygon.getSnippet();
mGeometry = new KmlPolygon();
mGeometry.mCoordinates = (ArrayList<GeoPoint>)polygon.getPoints();
((KmlPolygon)mGeometry).mHoles = (ArrayList<ArrayList<GeoPoint>>)polygon.getHoles();
mGeometry.mCoordinates = polygon.getPoints();
((KmlPolygon)mGeometry).mHoles = polygon.getHoles();
mVisibility = polygon.isEnabled();
//Style:
Style style = new Style();
Expand All @@ -74,7 +74,7 @@ public KmlPlacemark(Polyline polyline, KmlDocument kmlDoc){
mName = polyline.getTitle();
mDescription = polyline.getSnippet();
mGeometry = new KmlLineString();
mGeometry.mCoordinates = (ArrayList<GeoPoint>)polyline.getPoints();
mGeometry.mCoordinates = polyline.getPoints();
mVisibility = polyline.isEnabled();
//Style:
Style style = new Style();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +26,7 @@
public class KmlPolygon extends KmlGeometry {

/** Polygon holes (can be null if none) */
public ArrayList<ArrayList<GeoPoint>> mHoles;
public List<List<GeoPoint>> mHoles;

static int mDefaultLayoutResId = BonusPackHelper.UNDEFINED_RES_ID;

Expand Down Expand Up @@ -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<ArrayList<GeoPoint>>(rings.size()-1);
mHoles = new ArrayList<List<GeoPoint>>(rings.size()-1);
for (int i=1; i<rings.size(); i++){
ArrayList<GeoPoint> hole = KmlGeometry.parseGeoJSONPositions(rings.get(i).getAsJsonArray());
List<GeoPoint> hole = KmlGeometry.parseGeoJSONPositions(rings.get(i).getAsJsonArray());
mHoles.add(hole);
}
}
Expand All @@ -105,7 +106,7 @@ public KmlPolygon(JsonObject json){
writeKMLCoordinates(writer, mCoordinates);
writer.write("</LinearRing>\n</outerBoundaryIs>\n");
if (mHoles != null){
for (ArrayList<GeoPoint> hole:mHoles){
for (List<GeoPoint> hole:mHoles){
writer.write("<innerBoundaryIs>\n<LinearRing>\n");
writeKMLCoordinates(writer, hole);
writer.write("</LinearRing>\n</innerBoundaryIs>\n");
Expand All @@ -123,7 +124,7 @@ public KmlPolygon(JsonObject json){
JsonArray coords = new JsonArray();
coords.add(KmlGeometry.geoJSONCoordinates(mCoordinates));
if (mHoles != null) {
for (ArrayList<GeoPoint> hole:mHoles){
for (List<GeoPoint> hole:mHoles){
coords.add(KmlGeometry.geoJSONCoordinates(hole));
}
}
Expand All @@ -143,8 +144,8 @@ public KmlPolygon(JsonObject json){
@Override public KmlPolygon clone(){
KmlPolygon kmlPolygon = (KmlPolygon)super.clone();
if (mHoles != null){
kmlPolygon.mHoles = new ArrayList<ArrayList<GeoPoint>>(mHoles.size());
for (ArrayList<GeoPoint> hole:mHoles){
kmlPolygon.mHoles = new ArrayList<>(mHoles.size());
for (List<GeoPoint> hole:mHoles){
kmlPolygon.mHoles.add(cloneArrayOfGeoPoint(hole));
}
}
Expand All @@ -161,7 +162,7 @@ public KmlPolygon(JsonObject json){
super.writeToParcel(out, flags);
if (mHoles != null){
out.writeInt(mHoles.size());
for (ArrayList<GeoPoint> l:mHoles)
for (List<GeoPoint> l:mHoles)
out.writeList(l);
} else
out.writeInt(0);
Expand All @@ -180,7 +181,7 @@ public KmlPolygon(Parcel in){
super(in);
int holes = in.readInt();
if (holes != 0){
mHoles = new ArrayList<ArrayList<GeoPoint>>(holes);
mHoles = new ArrayList<>(holes);
for (int i=0; i<holes; i++){
ArrayList<GeoPoint> l = in.readArrayList(GeoPoint.class.getClassLoader());
mHoles.add(l);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down