features) {
113 | this.mFeatures.clear();
114 | if (features != null) {
115 | this.mFeatures.addAll(features);
116 | }
117 | }
118 |
119 | /**
120 | * {@inheritDoc}
121 | */
122 | @Override
123 | public String getType() {
124 | return GeoJSON.TYPE_FEATURE_COLLECTION;
125 | }
126 |
127 | /**
128 | * {@inheritDoc}
129 | */
130 | @Override
131 | public JSONObject toJSON() throws JSONException {
132 | JSONObject json = super.toJSON();
133 |
134 | JSONArray features = new JSONArray();
135 | for (Feature feature : this.mFeatures) {
136 | features.put(feature.toJSON());
137 | }
138 |
139 | json.put(JSON_FEATURES, features);
140 |
141 | return json;
142 | }
143 |
144 | }
145 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/GeoJSON.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import com.cocoahero.android.geojson.util.JSONUtils;
4 | import com.cocoahero.android.geojson.util.StreamUtils;
5 |
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 |
12 | public class GeoJSON {
13 |
14 | // ------------------------------------------------------------------------
15 | // Public Constants
16 | // ------------------------------------------------------------------------
17 |
18 | public static final String TYPE_POINT = "Point";
19 |
20 | public static final String TYPE_MULTI_POINT = "MultiPoint";
21 |
22 | public static final String TYPE_LINE_STRING = "LineString";
23 |
24 | public static final String TYPE_MULTI_LINE_STRING = "MultiLineString";
25 |
26 | public static final String TYPE_POLYGON = "Polygon";
27 |
28 | public static final String TYPE_MULTI_POLYGON = "MultiPolygon";
29 |
30 | public static final String TYPE_GEOMETRY_COLLECTION = "GeometryCollection";
31 |
32 | public static final String TYPE_FEATURE = "Feature";
33 |
34 | public static final String TYPE_FEATURE_COLLECTION = "FeatureCollection";
35 |
36 | // ------------------------------------------------------------------------
37 | // Class Methods
38 | // ------------------------------------------------------------------------
39 |
40 | /**
41 | * Parses the given JSONObject as GeoJSON and returns a concrete subclass of
42 | * {@link GeoJSONObject} corresponding to the type of the root object.
43 | *
44 | * Example:
45 | *
46 | * {
47 | * "type": "Feature",
48 | * "geometry": {
49 | * "type": "Point",
50 | * "coordinates": [125.6, 10.1]
51 | * },
52 | * }
53 | *
54 | *
55 | * The above GeoJSON would return an instance of {@link Feature}.
56 | *
57 | * @param json
58 | * A {@link JSONObject} to parse as GeoJSON
59 | *
60 | * @return A concrete subclass instance of {@link GeoJSONObject}.
61 | *
62 | * @throws IllegalArgumentException
63 | * If the given object is not a valid GeoJSON type.
64 | */
65 | public static GeoJSONObject parse(JSONObject json) {
66 | String type = JSONUtils.optString(json, GeoJSONObject.JSON_TYPE);
67 |
68 | if (TYPE_POINT.equalsIgnoreCase(type)) {
69 | return new Point(json);
70 | }
71 |
72 | if (TYPE_MULTI_POINT.equalsIgnoreCase(type)) {
73 | return new MultiPoint(json);
74 | }
75 |
76 | if (TYPE_LINE_STRING.equalsIgnoreCase(type)) {
77 | return new LineString(json);
78 | }
79 |
80 | if (TYPE_MULTI_LINE_STRING.equalsIgnoreCase(type)) {
81 | return new MultiLineString(json);
82 | }
83 |
84 | if (TYPE_POLYGON.equalsIgnoreCase(type)) {
85 | return new Polygon(json);
86 | }
87 |
88 | if (TYPE_MULTI_POLYGON.equalsIgnoreCase(type)) {
89 | return new MultiPolygon(json);
90 | }
91 |
92 | if (TYPE_GEOMETRY_COLLECTION.equalsIgnoreCase(type)) {
93 | return new GeometryCollection(json);
94 | }
95 |
96 | if (TYPE_FEATURE.equalsIgnoreCase(type)) {
97 | return new Feature(json);
98 | }
99 |
100 | if (TYPE_FEATURE_COLLECTION.equalsIgnoreCase(type)) {
101 | return new FeatureCollection(json);
102 | }
103 |
104 | throw new IllegalArgumentException("The type '" + type + "' is not a valid GeoJSON type.");
105 | }
106 |
107 | /**
108 | * Parses the given {@link String} into a {@link JSONObject}, and then
109 | * passes it to {@link GeoJSON#parse(JSONObject)}.
110 | *
111 | * @param jsonString
112 | * A {@link String} to parse as GeoJSON
113 | *
114 | * @return A concrete subclass instance of {@link GeoJSONObject}.
115 | *
116 | * @throws JSONException
117 | */
118 | public static GeoJSONObject parse(String jsonString) throws JSONException {
119 | return parse(new JSONObject(jsonString));
120 | }
121 |
122 | /**
123 | * Parses the given {@link InputStream} into a {@link JSONObject}, and then
124 | * passes it to {@link GeoJSON#parse(JSONObject)}.
125 | *
126 | * @param stream
127 | * An {@link InputStream} to parse as GeoJSON
128 | *
129 | * @return A concrete subclass instance of {@link GeoJSONObject}.
130 | *
131 | * @throws IOException
132 | * @throws JSONException
133 | */
134 | public static GeoJSONObject parse(InputStream stream) throws IOException, JSONException {
135 | return parse(StreamUtils.toString(stream));
136 | }
137 |
138 | }
139 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/GeoJSONObject.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | /**
10 | * The abstract interface of all GeoJSON objects.
11 | */
12 | public abstract class GeoJSONObject implements Parcelable {
13 |
14 | // ------------------------------------------------------------------------
15 | // Public Constants
16 | // ------------------------------------------------------------------------
17 |
18 | public static final String JSON_TYPE = "type";
19 |
20 | // ------------------------------------------------------------------------
21 | // Class Methods
22 | // ------------------------------------------------------------------------
23 |
24 | protected static GeoJSONObject readParcel(Parcel parcel) {
25 | String json = parcel.readString();
26 | try {
27 | return GeoJSON.parse(json);
28 | }
29 | catch (JSONException e) {
30 | throw new RuntimeException(e);
31 | }
32 | }
33 |
34 | // ------------------------------------------------------------------------
35 | // Constructor
36 | // ------------------------------------------------------------------------
37 |
38 | public GeoJSONObject() {
39 | // Default Constructor
40 | }
41 |
42 | public GeoJSONObject(JSONObject json) {
43 |
44 | }
45 |
46 | // ------------------------------------------------------------------------
47 | // Parcelable Interface
48 | // ------------------------------------------------------------------------
49 |
50 | public static final Parcelable.Creator CREATOR = new Creator() {
51 | @Override
52 | public GeoJSONObject createFromParcel(Parcel in) {
53 | return readParcel(in);
54 | }
55 |
56 | @Override
57 | public GeoJSONObject[] newArray(int size) {
58 | return new GeoJSONObject[size];
59 | }
60 | };
61 |
62 | @Override
63 | public int describeContents() {
64 | return 0;
65 | }
66 |
67 | @Override
68 | public void writeToParcel(Parcel dest, int flags) {
69 | try {
70 | dest.writeString(this.toJSON().toString());
71 | }
72 | catch (JSONException e) {
73 | throw new RuntimeException(e);
74 | }
75 | }
76 |
77 | // ------------------------------------------------------------------------
78 | // Public Methods
79 | // ------------------------------------------------------------------------
80 |
81 | /**
82 | * The type of GeoJSON object. This will be one of the constants defined in
83 | * {@link GeoJSON}, such as {@link GeoJSON#TYPE_FEATURE}.
84 | *
85 | * @return The type of GeoJSON object.
86 | */
87 | public abstract String getType();
88 |
89 | /**
90 | * Formats the object's attributes as GeoJSON.
91 | *
92 | * @return A GeoJSON formatted {@link JSONObject}
93 | *
94 | * @throws JSONException
95 | */
96 | public JSONObject toJSON() throws JSONException {
97 | JSONObject json = new JSONObject();
98 |
99 | json.put(JSON_TYPE, this.getType());
100 |
101 | return json;
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/Geometry.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import org.json.JSONArray;
4 | import org.json.JSONException;
5 | import org.json.JSONObject;
6 |
7 | /**
8 | * An intermediate, abstract class that acts as a common base for all GeoJSON
9 | * geometry types.
10 | */
11 | public abstract class Geometry extends GeoJSONObject {
12 |
13 | // ------------------------------------------------------------------------
14 | // Public Constants
15 | // ------------------------------------------------------------------------
16 |
17 | public static final String JSON_COORDINATES = "coordinates";
18 |
19 | // ------------------------------------------------------------------------
20 | // Constructors
21 | // ------------------------------------------------------------------------
22 |
23 | public Geometry() {
24 | // Default Constructor
25 | }
26 |
27 | public Geometry(JSONObject json) {
28 | super(json);
29 | }
30 |
31 | // ------------------------------------------------------------------------
32 | // Public Methods
33 | // ------------------------------------------------------------------------
34 |
35 | /**
36 | * {@inheritDoc}
37 | */
38 | @Override
39 | public JSONObject toJSON() throws JSONException {
40 | JSONObject json = super.toJSON();
41 |
42 | json.put(JSON_COORDINATES, new JSONArray());
43 |
44 | return json;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/GeometryCollection.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import org.json.JSONArray;
7 | import org.json.JSONException;
8 | import org.json.JSONObject;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | public class GeometryCollection extends Geometry {
14 |
15 | // ------------------------------------------------------------------------
16 | // Public Constants
17 | // ------------------------------------------------------------------------
18 |
19 | public static final String JSON_GEOMETRIES = "geometries";
20 |
21 | // ------------------------------------------------------------------------
22 | // Instance Variables
23 | // ------------------------------------------------------------------------
24 |
25 | private final List mGeometries = new ArrayList();
26 |
27 | // ------------------------------------------------------------------------
28 | // Constructors
29 | // ------------------------------------------------------------------------
30 |
31 | /**
32 | * Creates an empty geometry collection.
33 | */
34 | public GeometryCollection() {
35 | // Default Constructor
36 | }
37 |
38 | /**
39 | * Parses the given {@link JSONObject} as a geometry collection.
40 | *
41 | * @param json
42 | */
43 | public GeometryCollection(JSONObject json) {
44 | super(json);
45 |
46 | JSONArray geometries = json.optJSONArray(JSON_GEOMETRIES);
47 | if (geometries != null) {
48 | for (int i = 0; i < geometries.length(); i++) {
49 | JSONObject geometry = geometries.optJSONObject(i);
50 | if (geometry != null) {
51 | this.mGeometries.add((Geometry) GeoJSON.parse(geometry));
52 | }
53 | }
54 | }
55 | }
56 |
57 | // ------------------------------------------------------------------------
58 | // Parcelable Interface
59 | // ------------------------------------------------------------------------
60 |
61 | public static final Parcelable.Creator CREATOR = new Creator() {
62 | @Override
63 | public GeometryCollection createFromParcel(Parcel in) {
64 | return (GeometryCollection) readParcel(in);
65 | }
66 |
67 | @Override
68 | public GeometryCollection[] newArray(int size) {
69 | return new GeometryCollection[size];
70 | }
71 | };
72 |
73 | // ------------------------------------------------------------------------
74 | // Public Methods
75 | // ------------------------------------------------------------------------
76 |
77 | /**
78 | * Adds a {@link Geometry} to this geometry collection.
79 | *
80 | * @param geometry
81 | */
82 | public void addGeometry(Geometry geometry) {
83 | this.mGeometries.add(geometry);
84 | }
85 |
86 | /**
87 | * Removes the given {@link Geometry} from this geometry collection.
88 | *
89 | * @param geometry
90 | */
91 | public void removeGeometry(Geometry geometry) {
92 | this.mGeometries.remove(geometry);
93 | }
94 |
95 | /**
96 | * Returns a list of all the {@link Geometry} contained within this geometry
97 | * collection.
98 | *
99 | * @return a list of all the {@link Geometry} in this geometry collection.
100 | */
101 | public List getGeometries() {
102 | return this.mGeometries;
103 | }
104 |
105 | /**
106 | * Sets the list of geometries contained within this geometry collection.
107 | * All previously existing geometries are removed as a result of setting
108 | * this property.
109 | *
110 | * @param geometries
111 | */
112 | public void setGeometries(List geometries) {
113 | this.mGeometries.clear();
114 | if (geometries != null) {
115 | this.mGeometries.addAll(geometries);
116 | }
117 | }
118 |
119 | /**
120 | * {@inheritDoc}
121 | */
122 | @Override
123 | public String getType() {
124 | return GeoJSON.TYPE_GEOMETRY_COLLECTION;
125 | }
126 |
127 | /**
128 | * {@inheritDoc}
129 | */
130 | @Override
131 | public JSONObject toJSON() throws JSONException {
132 | JSONObject json = super.toJSON();
133 |
134 | JSONArray geometries = new JSONArray();
135 | for (Geometry geometry : this.mGeometries) {
136 | geometries.put(geometry.toJSON());
137 | }
138 |
139 | json.put(JSON_GEOMETRIES, geometries);
140 |
141 | return json;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/LineString.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import java.util.List;
4 |
5 | import org.json.JSONArray;
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | import android.os.Parcel;
10 | import android.os.Parcelable;
11 |
12 | public class LineString extends Geometry {
13 |
14 | // ------------------------------------------------------------------------
15 | // Instance Variables
16 | // ------------------------------------------------------------------------
17 |
18 | private final PositionList mPositionList = new PositionList();
19 |
20 | // ------------------------------------------------------------------------
21 | // Constructors
22 | // ------------------------------------------------------------------------
23 |
24 | public LineString() {
25 | // Default Constructor
26 | }
27 |
28 | public LineString(JSONObject json) {
29 | super(json);
30 |
31 | this.setPositions(json.optJSONArray(JSON_COORDINATES));
32 | }
33 |
34 | public LineString(JSONArray positions) {
35 | this.setPositions(positions);
36 | }
37 |
38 | // ------------------------------------------------------------------------
39 | // Parcelable Interface
40 | // ------------------------------------------------------------------------
41 |
42 | public static final Parcelable.Creator CREATOR = new Creator() {
43 | @Override
44 | public LineString createFromParcel(Parcel in) {
45 | return (LineString) readParcel(in);
46 | }
47 |
48 | @Override
49 | public LineString[] newArray(int size) {
50 | return new LineString[size];
51 | }
52 | };
53 |
54 | // ------------------------------------------------------------------------
55 | // Public Methods
56 | // ------------------------------------------------------------------------
57 |
58 | public void addPosition(Position position) {
59 | this.mPositionList.addPosition(position);
60 | }
61 |
62 | public void removePosition(Position position) {
63 | this.mPositionList.removePosition(position);
64 | }
65 |
66 | public List getPositions() {
67 | return this.mPositionList.getPositions();
68 | }
69 |
70 | public void setPositions(JSONArray positions) {
71 | this.mPositionList.setPositions(positions);
72 | }
73 |
74 | public void setPositions(List positions) {
75 | this.mPositionList.setPositions(positions);
76 | }
77 |
78 | public boolean isLinearRing() {
79 | return this.mPositionList.isLinearRing();
80 | }
81 |
82 | @Override
83 | public String getType() {
84 | return GeoJSON.TYPE_LINE_STRING;
85 | }
86 |
87 | @Override
88 | public JSONObject toJSON() throws JSONException {
89 | JSONObject json = super.toJSON();
90 |
91 | json.put(JSON_COORDINATES, this.mPositionList.toJSON());
92 |
93 | return json;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiLineString.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.json.JSONArray;
7 | import org.json.JSONException;
8 | import org.json.JSONObject;
9 |
10 | import android.os.Parcel;
11 | import android.os.Parcelable;
12 |
13 | public class MultiLineString extends Geometry {
14 |
15 | // ------------------------------------------------------------------------
16 | // Instance Variables
17 | // ------------------------------------------------------------------------
18 |
19 | private final List mLineStrings = new ArrayList();
20 |
21 | // ------------------------------------------------------------------------
22 | // Constructors
23 | // ------------------------------------------------------------------------
24 |
25 | public MultiLineString() {
26 | // Default Constructor
27 | }
28 |
29 | public MultiLineString(JSONObject json) {
30 | super(json);
31 |
32 | this.setLineStrings(json.optJSONArray(JSON_COORDINATES));
33 | }
34 |
35 | public MultiLineString(JSONArray lineStrings) {
36 | this.setLineStrings(lineStrings);
37 | }
38 |
39 | // ------------------------------------------------------------------------
40 | // Parcelable Interface
41 | // ------------------------------------------------------------------------
42 |
43 | public static final Parcelable.Creator CREATOR = new Creator() {
44 | @Override
45 | public MultiLineString createFromParcel(Parcel in) {
46 | return (MultiLineString) readParcel(in);
47 | }
48 |
49 | @Override
50 | public MultiLineString[] newArray(int size) {
51 | return new MultiLineString[size];
52 | }
53 | };
54 |
55 | // ------------------------------------------------------------------------
56 | // Public Methods
57 | // ------------------------------------------------------------------------
58 |
59 | public void addLineString(LineString lineString) {
60 | this.mLineStrings.add(lineString);
61 | }
62 |
63 | public void removeLineString(LineString lineString) {
64 | this.mLineStrings.remove(lineString);
65 | }
66 |
67 | public List getLineStrings() {
68 | return this.mLineStrings;
69 | }
70 |
71 | public void setLineStrings(JSONArray lineStrings) {
72 | this.mLineStrings.clear();
73 | if (lineStrings != null) {
74 | for (int i = 0; i < lineStrings.length(); i++) {
75 | JSONArray lineJSON = lineStrings.optJSONArray(i);
76 | if (lineJSON != null) {
77 | this.mLineStrings.add(new LineString(lineJSON));
78 | }
79 | }
80 | }
81 | }
82 |
83 | public void setLineStrings(List lineStrings) {
84 | this.mLineStrings.clear();
85 | if (lineStrings != null) {
86 | this.mLineStrings.addAll(lineStrings);
87 | }
88 | }
89 |
90 | @Override
91 | public String getType() {
92 | return GeoJSON.TYPE_MULTI_LINE_STRING;
93 | }
94 |
95 | @Override
96 | public JSONObject toJSON() throws JSONException {
97 | JSONObject json = super.toJSON();
98 |
99 | JSONArray strings = new JSONArray();
100 | for (LineString line : this.mLineStrings) {
101 | JSONArray lineJSON = new JSONArray();
102 | for (Position position : line.getPositions()) {
103 | lineJSON.put(position.toJSON());
104 | }
105 | strings.put(lineJSON);
106 | }
107 | json.put(JSON_COORDINATES, strings);
108 |
109 | return json;
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiPoint.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import java.util.List;
4 |
5 | import org.json.JSONArray;
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | import android.os.Parcel;
10 | import android.os.Parcelable;
11 |
12 | public class MultiPoint extends Geometry {
13 |
14 | // ------------------------------------------------------------------------
15 | // Instance Variables
16 | // ------------------------------------------------------------------------
17 |
18 | private final PositionList mPositionList = new PositionList();
19 |
20 | // ------------------------------------------------------------------------
21 | // Constructors
22 | // ------------------------------------------------------------------------
23 |
24 | public MultiPoint() {
25 | // Default Constructor
26 | }
27 |
28 | public MultiPoint(JSONObject json) {
29 | super(json);
30 |
31 | this.setPositions(json.optJSONArray(JSON_COORDINATES));
32 | }
33 |
34 | public MultiPoint(JSONArray positions) {
35 | this.setPositions(positions);
36 | }
37 |
38 | // ------------------------------------------------------------------------
39 | // Parcelable Interface
40 | // ------------------------------------------------------------------------
41 |
42 | public static final Parcelable.Creator CREATOR = new Creator() {
43 | @Override
44 | public MultiPoint createFromParcel(Parcel in) {
45 | return (MultiPoint) readParcel(in);
46 | }
47 |
48 | @Override
49 | public MultiPoint[] newArray(int size) {
50 | return new MultiPoint[size];
51 | }
52 | };
53 |
54 | // ------------------------------------------------------------------------
55 | // Public Methods
56 | // ------------------------------------------------------------------------
57 |
58 | public void addPosition(Position position) {
59 | this.mPositionList.addPosition(position);
60 | }
61 |
62 | public void removePosition(Position position) {
63 | this.mPositionList.removePosition(position);
64 | }
65 |
66 | public List getPositions() {
67 | return this.mPositionList.getPositions();
68 | }
69 |
70 | public void setPositions(JSONArray positions) {
71 | this.mPositionList.setPositions(positions);
72 | }
73 |
74 | public void setPositions(List positions) {
75 | this.mPositionList.setPositions(positions);
76 | }
77 |
78 | @Override
79 | public String getType() {
80 | return GeoJSON.TYPE_MULTI_POINT;
81 | }
82 |
83 | @Override
84 | public JSONObject toJSON() throws JSONException {
85 | JSONObject json = super.toJSON();
86 |
87 | json.put(JSON_COORDINATES, this.mPositionList.toJSON());
88 |
89 | return json;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiPolygon.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.json.JSONArray;
7 | import org.json.JSONException;
8 | import org.json.JSONObject;
9 |
10 | import android.os.Parcel;
11 | import android.os.Parcelable;
12 |
13 | public class MultiPolygon extends Geometry {
14 |
15 | // ------------------------------------------------------------------------
16 | // Instance Variables
17 | // ------------------------------------------------------------------------
18 |
19 | private final List mPolygons = new ArrayList();
20 |
21 | // ------------------------------------------------------------------------
22 | // Constructors
23 | // ------------------------------------------------------------------------
24 |
25 | public MultiPolygon() {
26 | // Default Constructor
27 | }
28 |
29 | public MultiPolygon(JSONObject json) {
30 | super(json);
31 |
32 | this.setPolygons(json.optJSONArray(JSON_COORDINATES));
33 | }
34 |
35 | // ------------------------------------------------------------------------
36 | // Parcelable Interface
37 | // ------------------------------------------------------------------------
38 |
39 | public static final Parcelable.Creator CREATOR = new Creator() {
40 | @Override
41 | public MultiPolygon createFromParcel(Parcel in) {
42 | return (MultiPolygon) readParcel(in);
43 | }
44 |
45 | @Override
46 | public MultiPolygon[] newArray(int size) {
47 | return new MultiPolygon[size];
48 | }
49 | };
50 |
51 | // ------------------------------------------------------------------------
52 | // Public Methods
53 | // ------------------------------------------------------------------------
54 |
55 | public void addPolygon(Polygon polygon) {
56 | this.mPolygons.add(polygon);
57 | }
58 |
59 | public void removePolygon(Polygon polygon) {
60 | this.mPolygons.remove(polygon);
61 | }
62 |
63 | public List getPolygons() {
64 | return this.mPolygons;
65 | }
66 |
67 | public void setPolygons(JSONArray polygons) {
68 | this.mPolygons.clear();
69 | if (polygons != null) {
70 | for (int i = 0; i < polygons.length(); i++) {
71 | JSONArray polyJSON = polygons.optJSONArray(i);
72 | if (polyJSON != null) {
73 | this.mPolygons.add(new Polygon(polyJSON));
74 | }
75 | }
76 | }
77 | }
78 |
79 | public void setPolygons(List polygons) {
80 | this.mPolygons.clear();
81 | if (polygons != null) {
82 | this.mPolygons.addAll(polygons);
83 | }
84 | }
85 |
86 | @Override
87 | public String getType() {
88 | return GeoJSON.TYPE_MULTI_POLYGON;
89 | }
90 |
91 | @Override
92 | public JSONObject toJSON() throws JSONException {
93 | JSONObject json = super.toJSON();
94 |
95 | JSONArray polygons = new JSONArray();
96 | for (Polygon polygon : this.mPolygons) {
97 | JSONArray ringJSON = new JSONArray();
98 | for (Ring ring : polygon.getRings()) {
99 | ringJSON.put(ring.toJSON());
100 | }
101 | polygons.put(ringJSON);
102 | }
103 | json.put(JSON_COORDINATES, polygons);
104 |
105 | return json;
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/Point.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import org.json.JSONArray;
4 | import org.json.JSONException;
5 | import org.json.JSONObject;
6 |
7 | import android.os.Parcel;
8 | import android.os.Parcelable;
9 |
10 | public class Point extends Geometry {
11 |
12 | // ------------------------------------------------------------------------
13 | // Instance Variables
14 | // ------------------------------------------------------------------------
15 |
16 | private Position mPosition;
17 |
18 | // ------------------------------------------------------------------------
19 | // Constructors
20 | // ------------------------------------------------------------------------
21 |
22 | public Point() {
23 | // Default Constructor
24 | }
25 |
26 | public Point(JSONObject json) {
27 | super(json);
28 |
29 | this.setPosition(json.optJSONArray(JSON_COORDINATES));
30 | }
31 |
32 | public Point(JSONArray position) {
33 | this.setPosition(position);
34 | }
35 |
36 | public Point(Position position) {
37 | this.setPosition(position);
38 | }
39 |
40 | public Point(double latitude, double longitude) {
41 | this.mPosition = new Position(latitude, longitude);
42 | }
43 |
44 | public Point(double latitude, double longitude, double altitude) {
45 | this.mPosition = new Position(latitude, longitude, altitude);
46 | }
47 |
48 | // ------------------------------------------------------------------------
49 | // Parcelable Interface
50 | // ------------------------------------------------------------------------
51 |
52 | public static final Parcelable.Creator CREATOR = new Creator() {
53 | @Override
54 | public Point createFromParcel(Parcel in) {
55 | return (Point) readParcel(in);
56 | }
57 |
58 | @Override
59 | public Point[] newArray(int size) {
60 | return new Point[size];
61 | }
62 | };
63 |
64 | // ------------------------------------------------------------------------
65 | // Public Methods
66 | // ------------------------------------------------------------------------
67 |
68 | public Position getPosition() {
69 | return this.mPosition;
70 | }
71 |
72 | public void setPosition(Position position) {
73 | this.mPosition = position;
74 | }
75 |
76 | public void setPosition(JSONArray position) {
77 | if (position != null) {
78 | this.mPosition = new Position(position);
79 | }
80 | else {
81 | this.mPosition = null;
82 | }
83 | }
84 |
85 | @Override
86 | public String getType() {
87 | return GeoJSON.TYPE_POINT;
88 | }
89 |
90 | @Override
91 | public JSONObject toJSON() throws JSONException {
92 | JSONObject json = super.toJSON();
93 |
94 | if (this.mPosition != null) {
95 | json.put(JSON_COORDINATES, this.mPosition.toJSON());
96 | }
97 |
98 | return json;
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/Polygon.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.json.JSONArray;
7 | import org.json.JSONException;
8 | import org.json.JSONObject;
9 |
10 | import android.os.Parcel;
11 | import android.os.Parcelable;
12 |
13 | public class Polygon extends Geometry {
14 |
15 | // ------------------------------------------------------------------------
16 | // Instance Variables
17 | // ------------------------------------------------------------------------
18 |
19 | private final List mRings = new ArrayList();
20 |
21 | // ------------------------------------------------------------------------
22 | // Constructors
23 | // ------------------------------------------------------------------------
24 |
25 | public Polygon() {
26 | // Default Constructor
27 | }
28 |
29 | public Polygon(Ring ring) {
30 | this.addRing(ring);
31 | }
32 |
33 | public Polygon(JSONObject json) {
34 | super(json);
35 |
36 | this.setRings(json.optJSONArray(JSON_COORDINATES));
37 | }
38 |
39 | public Polygon(JSONArray rings) {
40 | this.setRings(rings);
41 | }
42 |
43 | // ------------------------------------------------------------------------
44 | // Parcelable Interface
45 | // ------------------------------------------------------------------------
46 |
47 | public static final Parcelable.Creator CREATOR = new Creator() {
48 | @Override
49 | public Polygon createFromParcel(Parcel in) {
50 | return (Polygon) readParcel(in);
51 | }
52 |
53 | @Override
54 | public Polygon[] newArray(int size) {
55 | return new Polygon[size];
56 | }
57 | };
58 |
59 | // ------------------------------------------------------------------------
60 | // Public Methods
61 | // ------------------------------------------------------------------------
62 |
63 | public void addRing(Ring ring) {
64 | this.mRings.add(ring);
65 | }
66 |
67 | public void removeRing(Ring ring) {
68 | this.mRings.remove(ring);
69 | }
70 |
71 | public List getRings() {
72 | return this.mRings;
73 | }
74 |
75 | public void setRings(JSONArray rings) {
76 | this.mRings.clear();
77 | if (rings != null) {
78 | for (int i = 0; i < rings.length(); i++) {
79 | JSONArray ringJSON = rings.optJSONArray(i);
80 | if (ringJSON != null) {
81 | this.mRings.add(new Ring(ringJSON));
82 | }
83 | }
84 | }
85 | }
86 |
87 | public void setRings(List rings) {
88 | this.mRings.clear();
89 | if (rings != null) {
90 | this.mRings.addAll(rings);
91 | }
92 | }
93 |
94 | @Override
95 | public String getType() {
96 | return GeoJSON.TYPE_POLYGON;
97 | }
98 |
99 | @Override
100 | public JSONObject toJSON() throws JSONException {
101 | JSONObject json = super.toJSON();
102 |
103 | JSONArray rings = new JSONArray();
104 | for (Ring ring : this.mRings) {
105 | rings.put(ring.toJSON());
106 | }
107 | json.put(JSON_COORDINATES, rings);
108 |
109 | return json;
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/Position.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import java.util.Arrays;
4 |
5 | import org.json.JSONArray;
6 | import org.json.JSONException;
7 |
8 | import android.location.Location;
9 | import android.os.Parcel;
10 | import android.os.Parcelable;
11 |
12 | public class Position implements Parcelable {
13 |
14 | // ------------------------------------------------------------------------
15 | // Private Constants
16 | // ------------------------------------------------------------------------
17 |
18 | private static final int LON_IDX = 0;
19 |
20 | private static final int LAT_IDX = 1;
21 |
22 | private static final int ALT_IDX = 2;
23 |
24 | // ------------------------------------------------------------------------
25 | // Instance Variables
26 | // ------------------------------------------------------------------------
27 |
28 | private final double[] mStorage = new double[3];
29 |
30 | // ------------------------------------------------------------------------
31 | // Constructors
32 | // ------------------------------------------------------------------------
33 |
34 | public Position(JSONArray array) {
35 | this.mStorage[LON_IDX] = array.optDouble(LON_IDX, 0);
36 | this.mStorage[LAT_IDX] = array.optDouble(LAT_IDX, 0);
37 | this.mStorage[ALT_IDX] = array.optDouble(ALT_IDX, 0);
38 | }
39 |
40 | public Position(double[] array) {
41 | if (array.length == 2) {
42 | this.mStorage[LON_IDX] = array[LON_IDX];
43 | this.mStorage[LAT_IDX] = array[LAT_IDX];
44 | }
45 | else if (array.length == 3) {
46 | this.mStorage[LON_IDX] = array[LON_IDX];
47 | this.mStorage[LAT_IDX] = array[LAT_IDX];
48 | this.mStorage[ALT_IDX] = array[ALT_IDX];
49 | }
50 | }
51 |
52 | public Position(double latitude, double longitude) {
53 | this.mStorage[LAT_IDX] = latitude;
54 | this.mStorage[LON_IDX] = longitude;
55 | }
56 |
57 | public Position(double latitude, double longitude, double altitude) {
58 | this.mStorage[LAT_IDX] = latitude;
59 | this.mStorage[LON_IDX] = longitude;
60 | this.mStorage[ALT_IDX] = altitude;
61 | }
62 |
63 | public Position(Location location) {
64 | this.mStorage[LAT_IDX] = location.getLatitude();
65 | this.mStorage[LON_IDX] = location.getLongitude();
66 | this.mStorage[ALT_IDX] = location.getAltitude();
67 | }
68 |
69 | private Position(Parcel parcel) {
70 | this(parcel.createDoubleArray());
71 | }
72 |
73 | // ------------------------------------------------------------------------
74 | // Parcelable Interface
75 | // ------------------------------------------------------------------------
76 |
77 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
78 | @Override
79 | public Position createFromParcel(Parcel in) {
80 | return new Position(in);
81 | }
82 |
83 | @Override
84 | public Position[] newArray(int size) {
85 | return new Position[size];
86 | }
87 | };
88 |
89 | @Override
90 | public int describeContents() {
91 | return 0;
92 | }
93 |
94 | @Override
95 | public void writeToParcel(Parcel dest, int flags) {
96 | dest.writeDoubleArray(this.mStorage);
97 | }
98 |
99 | // ------------------------------------------------------------------------
100 | // Public Methods
101 | // ------------------------------------------------------------------------
102 |
103 | public double getLatitude() {
104 | return this.mStorage[LAT_IDX];
105 | }
106 |
107 | public void setLatitude(double latitude) {
108 | this.mStorage[LAT_IDX] = latitude;
109 | }
110 |
111 | public double getLongitude() {
112 | return this.mStorage[LON_IDX];
113 | }
114 |
115 | public void setLongitude(double longitude) {
116 | this.mStorage[LON_IDX] = longitude;
117 | }
118 |
119 | public double getAltitude() {
120 | return this.mStorage[ALT_IDX];
121 | }
122 |
123 | public void setAltitude(double altitude) {
124 | this.mStorage[ALT_IDX] = altitude;
125 | }
126 |
127 | public JSONArray toJSON() throws JSONException {
128 | JSONArray coordinates = new JSONArray();
129 |
130 | coordinates.put(LAT_IDX, this.getLatitude());
131 | coordinates.put(LON_IDX, this.getLongitude());
132 | coordinates.put(ALT_IDX, this.getAltitude());
133 |
134 | return coordinates;
135 | }
136 |
137 | public Location toLocation() {
138 | Location location = new Location("GeoJSON");
139 |
140 | location.setLatitude(this.getLatitude());
141 | location.setLongitude(this.getLongitude());
142 | location.setAltitude(this.getAltitude());
143 |
144 | return location;
145 | }
146 |
147 | public double[] toArray() {
148 | return this.mStorage;
149 | }
150 |
151 | @Override
152 | public boolean equals(Object object) {
153 | if (this == object) {
154 | return true;
155 | }
156 |
157 | if (!(object instanceof Position)) {
158 | return false;
159 | }
160 |
161 | Position aPosition = (Position) object;
162 |
163 | return Arrays.equals(this.mStorage, aPosition.mStorage);
164 | }
165 |
166 | @Override
167 | public int hashCode() {
168 | return Arrays.hashCode(this.mStorage);
169 | }
170 |
171 | @Override
172 | public String toString() {
173 | return Arrays.toString(this.mStorage);
174 | }
175 |
176 | }
177 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/PositionList.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.json.JSONArray;
7 | import org.json.JSONException;
8 |
9 | import android.os.Parcel;
10 | import android.os.Parcelable;
11 |
12 | import com.cocoahero.android.geojson.util.ListUtils;
13 |
14 | public class PositionList implements Parcelable {
15 |
16 | // ------------------------------------------------------------------------
17 | // Instance Variables
18 | // ------------------------------------------------------------------------
19 |
20 | private final List mPositions = new ArrayList();
21 |
22 | // ------------------------------------------------------------------------
23 | // Constructors
24 | // ------------------------------------------------------------------------
25 |
26 | public PositionList() {
27 | // Default Constructor
28 | }
29 |
30 | public PositionList(JSONArray positions) {
31 | this.setPositions(positions);
32 | }
33 |
34 | public PositionList(double[][] positions) {
35 | for (int i = 0; i < positions.length; i++) {
36 | this.addPosition(new Position(positions[i]));
37 | }
38 | }
39 |
40 | protected PositionList(Parcel parcel) {
41 | this.setPositions(parcel.createTypedArrayList(Position.CREATOR));
42 | }
43 |
44 | // ------------------------------------------------------------------------
45 | // Parcelable Interface
46 | // ------------------------------------------------------------------------
47 |
48 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
49 | @Override
50 | public PositionList createFromParcel(Parcel in) {
51 | return new PositionList(in);
52 | }
53 |
54 | @Override
55 | public PositionList[] newArray(int size) {
56 | return new PositionList[size];
57 | }
58 | };
59 |
60 | @Override
61 | public int describeContents() {
62 | return 0;
63 | }
64 |
65 | @Override
66 | public void writeToParcel(Parcel dest, int flags) {
67 | dest.writeTypedList(this.mPositions);
68 | }
69 |
70 | // ------------------------------------------------------------------------
71 | // Public Methods
72 | // ------------------------------------------------------------------------
73 |
74 | public List getPositions() {
75 | return this.mPositions;
76 | }
77 |
78 | public void addPosition(Position position) {
79 | this.mPositions.add(position);
80 | }
81 |
82 | public void addPositions(PositionList positions) {
83 | this.mPositions.addAll(positions.mPositions);
84 | }
85 |
86 | public void addPositions(List positions) {
87 | this.mPositions.addAll(positions);
88 | }
89 |
90 | public void removePosition(Position position) {
91 | this.mPositions.remove(position);
92 | }
93 |
94 | public void removePositions(PositionList positions) {
95 | this.mPositions.removeAll(positions.mPositions);
96 | }
97 |
98 | public void removePositions(List positions) {
99 | this.mPositions.removeAll(positions);
100 | }
101 |
102 | public void clearPositions() {
103 | this.mPositions.clear();
104 | }
105 |
106 | public void setPositions(JSONArray positions) {
107 | this.mPositions.clear();
108 | if (positions != null) {
109 | for (int i = 0; i < positions.length(); i++) {
110 | JSONArray position = positions.optJSONArray(i);
111 | if (position != null) {
112 | this.mPositions.add(new Position(position));
113 | }
114 | }
115 | }
116 | }
117 |
118 | public void setPositions(PositionList positions) {
119 | this.mPositions.clear();
120 | if (positions != null) {
121 | this.mPositions.addAll(positions.mPositions);
122 | }
123 | }
124 |
125 | public void setPositions(List positions) {
126 | this.mPositions.clear();
127 | if (positions != null) {
128 | this.mPositions.addAll(positions);
129 | }
130 | }
131 |
132 | public Position getHead() {
133 | return ListUtils.getHead(this.mPositions);
134 | }
135 |
136 | public Position getTail() {
137 | return ListUtils.getTail(this.mPositions);
138 | }
139 |
140 | public boolean isLinearRing() {
141 | if (this.mPositions.size() < 4) {
142 | return false;
143 | }
144 |
145 | Position head = this.getHead();
146 | Position tail = this.getTail();
147 |
148 | return head.equals(tail);
149 | }
150 |
151 | public JSONArray toJSON() throws JSONException {
152 | JSONArray positions = new JSONArray();
153 |
154 | for (Position position : this.mPositions) {
155 | positions.put(position.toJSON());
156 | }
157 |
158 | return positions;
159 | }
160 |
161 | }
162 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/Ring.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson;
2 |
3 | import org.json.JSONArray;
4 |
5 | import android.os.Parcel;
6 | import android.os.Parcelable;
7 |
8 | public class Ring extends PositionList {
9 |
10 | // ------------------------------------------------------------------------
11 | // Constructors
12 | // ------------------------------------------------------------------------
13 |
14 | public Ring() {
15 | // Default Constructor
16 | }
17 |
18 | public Ring(JSONArray positions) {
19 | super(positions);
20 | }
21 |
22 | public Ring(double[][] positions) {
23 | super(positions);
24 | }
25 |
26 | protected Ring(Parcel parcel) {
27 | super(parcel);
28 | }
29 |
30 | // ------------------------------------------------------------------------
31 | // Parcelable Interface
32 | // ------------------------------------------------------------------------
33 |
34 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
35 | @Override
36 | public Ring createFromParcel(Parcel in) {
37 | return new Ring(in);
38 | }
39 |
40 | @Override
41 | public Ring[] newArray(int size) {
42 | return new Ring[size];
43 | }
44 | };
45 |
46 | // ------------------------------------------------------------------------
47 | // Public Methods
48 | // ------------------------------------------------------------------------
49 |
50 | public void close() {
51 | if (!this.isLinearRing()) {
52 | this.addPosition(this.getHead());
53 | }
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/util/JSONUtils.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson.util;
2 |
3 | import org.json.JSONArray;
4 | import org.json.JSONObject;
5 |
6 | public class JSONUtils {
7 |
8 | public static boolean isEmpty(JSONObject json) {
9 | return (json == null) || (json.length() <= 0);
10 | }
11 |
12 | public static boolean isEmpty(JSONArray json) {
13 | return (json == null) || (json.length() <= 0);
14 | }
15 |
16 | public static String optString(JSONObject json, String name) {
17 | return optString(json, name, null);
18 | }
19 |
20 | public static String optString(JSONObject json, String name, String fallback) {
21 | if (json != null) {
22 | if (!json.isNull(name)) {
23 | return json.optString(name, fallback);
24 | }
25 | return fallback;
26 | }
27 | return null;
28 | }
29 |
30 | public static String optString(JSONArray json, int index) {
31 | return optString(json, index, null);
32 | }
33 |
34 | public static String optString(JSONArray json, int index, String fallback) {
35 | if (json != null) {
36 | if (!json.isNull(index)) {
37 | return json.optString(index, fallback);
38 | }
39 | return fallback;
40 | }
41 | return null;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/util/ListUtils.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson.util;
2 |
3 | import java.util.List;
4 |
5 | public class ListUtils {
6 |
7 | public static T getHead(List list) {
8 | if (list == null || list.isEmpty()) {
9 | return null;
10 | }
11 | return list.get(0);
12 | }
13 |
14 | public static T getTail(List list) {
15 | if (list == null || list.isEmpty()) {
16 | return null;
17 | }
18 | return list.get(list.size() - 1);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/androidgeojson/src/main/java/com/cocoahero/android/geojson/util/StreamUtils.java:
--------------------------------------------------------------------------------
1 | package com.cocoahero.android.geojson.util;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.InputStreamReader;
6 |
7 | public class StreamUtils {
8 |
9 | /**
10 | * Decodes the contents of the provided {@link InputStream} into a
11 | * {@link String} using the UTF-8 charset.
12 | *
13 | * @param byteStream The {@link InputStream} to decode.
14 | * @return A {@link String} representation of the stream's contents.
15 | * @throws IOException
16 | */
17 | public static String toString(InputStream byteStream) throws IOException {
18 | return toString(byteStream, "UTF-8");
19 | }
20 |
21 | /**
22 | * Decodes the contents of the provided {@link InputStream} into a
23 | * {@link String} using the charset denoted by the charsetName parameter.
24 | *
25 | * @param byteStream The {@link InputStream} to decode.
26 | * @param charsetName The charset used to decode the stream.
27 | * @return A {@link String} representation of the stream's contents.
28 | * @throws IOException
29 | */
30 | public static String toString(InputStream byteStream, String charsetName) throws IOException {
31 | char[] buffer = new char[1024];
32 |
33 | StringBuilder builder = new StringBuilder();
34 |
35 | InputStreamReader reader = new InputStreamReader(byteStream, charsetName);
36 |
37 | for (int length = 0; (length = reader.read(buffer)) >= 0;) {
38 | builder.append(buffer, 0, length);
39 | }
40 |
41 | reader.close();
42 |
43 | return builder.toString();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | repositories {
4 | mavenCentral()
5 | }
6 | dependencies {
7 | classpath 'com.android.tools.build:gradle:1.1.3'
8 | }
9 | }
10 |
11 | allprojects {
12 | repositories {
13 | mavenCentral()
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cocoahero/android-geojson/eec45c0a5429d5c8fb0c2536e135084f87aa958a/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jan 13 10:21:30 CST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':androidgeojson'
2 |
--------------------------------------------------------------------------------