|
10 | 10 |
|
11 | 11 | import android.location.Criteria;
|
12 | 12 | import android.location.Location;
|
| 13 | +import android.os.Parcel; |
| 14 | +import android.os.Parcelable; |
13 | 15 |
|
14 | 16 | import java.util.Locale;
|
15 | 17 |
|
|
32 | 34 | * </pre>
|
33 | 35 | */
|
34 | 36 |
|
35 |
| -public class ParseGeoPoint { |
| 37 | +public class ParseGeoPoint implements Parcelable { |
36 | 38 | static double EARTH_MEAN_RADIUS_KM = 6371.0;
|
37 | 39 | static double EARTH_MEAN_RADIUS_MILE = 3958.8;
|
38 | 40 |
|
@@ -68,6 +70,30 @@ public ParseGeoPoint(ParseGeoPoint point) {
|
68 | 70 | this(point.getLatitude(), point.getLongitude());
|
69 | 71 | }
|
70 | 72 |
|
| 73 | + /** |
| 74 | + * Creates a new point instance from a {@link Parcel} source. This is used when unparceling a |
| 75 | + * ParseGeoPoint. Subclasses that need Parcelable behavior should provide their own |
| 76 | + * {@link android.os.Parcelable.Creator} and override this constructor. |
| 77 | + * |
| 78 | + * @param source The recovered parcel. |
| 79 | + */ |
| 80 | + protected ParseGeoPoint(Parcel source) { |
| 81 | + this(source, ParseParcelDecoder.get()); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Creates a new point instance from a {@link Parcel} using the given {@link ParseParcelDecoder}. |
| 86 | + * The decoder is currently unused, but it might be in the future, plus this is the pattern we |
| 87 | + * are using in parcelable classes. |
| 88 | + * |
| 89 | + * @param source the parcel |
| 90 | + * @param decoder the decoder |
| 91 | + */ |
| 92 | + ParseGeoPoint(Parcel source, ParseParcelDecoder decoder) { |
| 93 | + setLatitude(source.readDouble()); |
| 94 | + setLongitude(source.readDouble()); |
| 95 | + } |
| 96 | + |
71 | 97 | /**
|
72 | 98 | * Set latitude. Valid range is (-90.0, 90.0). Extremes should not be used.
|
73 | 99 | *
|
@@ -268,4 +294,31 @@ public static void getCurrentLocationInBackground(long timeout, Criteria criteri
|
268 | 294 | public String toString() {
|
269 | 295 | return String.format(Locale.US, "ParseGeoPoint[%.6f,%.6f]", latitude, longitude);
|
270 | 296 | }
|
| 297 | + |
| 298 | + @Override |
| 299 | + public int describeContents() { |
| 300 | + return 0; |
| 301 | + } |
| 302 | + |
| 303 | + @Override |
| 304 | + public void writeToParcel(Parcel dest, int flags) { |
| 305 | + writeToParcel(dest, ParseParcelEncoder.get()); |
| 306 | + } |
| 307 | + |
| 308 | + void writeToParcel(Parcel dest, ParseParcelEncoder encoder) { |
| 309 | + dest.writeDouble(latitude); |
| 310 | + dest.writeDouble(longitude); |
| 311 | + } |
| 312 | + |
| 313 | + public final static Creator<ParseGeoPoint> CREATOR = new Creator<ParseGeoPoint>() { |
| 314 | + @Override |
| 315 | + public ParseGeoPoint createFromParcel(Parcel source) { |
| 316 | + return new ParseGeoPoint(source, ParseParcelDecoder.get()); |
| 317 | + } |
| 318 | + |
| 319 | + @Override |
| 320 | + public ParseGeoPoint[] newArray(int size) { |
| 321 | + return new ParseGeoPoint[size]; |
| 322 | + } |
| 323 | + }; |
271 | 324 | }
|
0 commit comments