From 0c995e02d34067ce237f0dfe63b46d4862ec82f1 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 10 Mar 2012 09:46:11 -0500 Subject: [PATCH] Added getters for PathOverlay points, refactored DirectionsOverlay Change-Id: Ia46352151dad96ae30c427d7776614555913c48b Signed-off-by: Ricky Barrette --- .../android/overlays/DirectionsOverlay.java | 240 +++++++++--------- .../android/overlays/PathOverlay.java | 18 +- 2 files changed, 138 insertions(+), 120 deletions(-) diff --git a/LocationLib/src/com/TwentyCodes/android/overlays/DirectionsOverlay.java b/LocationLib/src/com/TwentyCodes/android/overlays/DirectionsOverlay.java index 3a0d069..ffc6b08 100644 --- a/LocationLib/src/com/TwentyCodes/android/overlays/DirectionsOverlay.java +++ b/LocationLib/src/com/TwentyCodes/android/overlays/DirectionsOverlay.java @@ -31,9 +31,16 @@ import com.google.android.maps.GeoPoint; */ public class DirectionsOverlay { + /** + * @author ricky barrette + */ + public interface OnDirectionsCompleteListener{ + public void onDirectionsComplete(DirectionsOverlay directionsOverlay); + } + private static final String TAG = "DirectionsOverlay"; - ArrayList mPath; - ArrayList mDirections; + private ArrayList mPath; + private ArrayList mDirections; private MapView mMapView; private OnDirectionsCompleteListener mListener; private String mCopyRights; @@ -71,6 +78,62 @@ public class DirectionsOverlay { drawPath(json); } + /** + * Deocodes googles polyline + * @param encoded + * @return a list of geopoints representing the path + * @author Mark McClure http://facstaff.unca.edu/mcmcclur/googlemaps/encodepolyline/ + * @author ricky barrette + * @throws JSONException + */ + private void decodePoly(JSONObject step) throws JSONException { + if(Debug.DEBUG) + Log.d(TAG, "decodePoly"); + + String encoded = step.getJSONObject("polyline").getString("points"); + int index = 0, len = encoded.length(); + int lat = 0, lng = 0; + + GeoPoint last = null; + while (index < len) { + int b, shift = 0, result = 0; + do { + b = encoded.charAt(index++) - 63; + result |= (b & 0x1f) << shift; + shift += 5; + } while (b >= 0x20); + int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); + lat += dlat; + + shift = 0; + result = 0; + do { + b = encoded.charAt(index++) - 63; + result |= (b & 0x1f) << shift; + shift += 5; + } while (b >= 0x20); + int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); + lng += dlng; + + GeoPoint p = new GeoPoint((int) (((double) lat / 1E5) * 1E6), (int) (((double) lng / 1E5) * 1E6)); + + if(Debug.DEBUG){ + Log.d(TAG, "current = "+ p.toString()); + if(last != null) + Log.d(TAG, "last = "+ last.toString()); + } + + + if(last != null) + mPath.add(new PathOverlay(last, p, Color.RED)); +// else +// mPath.add(new PathOverlay(p, 5, Color.GREEN)); + + last = p; + } + + } + /** * Downloads Google Directions JSON from the Internet * @param url @@ -93,6 +156,7 @@ public class DirectionsOverlay { return response.toString(); } + /** * Creates a new DirectionsOverlay from the json provided * @param json of Google Directions API @@ -193,61 +257,58 @@ public class DirectionsOverlay { "&sensor=true&mode=walking"; } - /** - * Deocodes googles polyline - * @param encoded - * @return a list of geopoints representing the path - * @author Mark McClure http://facstaff.unca.edu/mcmcclur/googlemaps/encodepolyline/ + * @return * @author ricky barrette - * @throws JSONException */ - private void decodePoly(JSONObject step) throws JSONException { - if(Debug.DEBUG) - Log.d(TAG, "decodePoly"); - - String encoded = step.getJSONObject("polyline").getString("points"); - int index = 0, len = encoded.length(); - int lat = 0, lng = 0; - - GeoPoint last = null; - while (index < len) { - int b, shift = 0, result = 0; - do { - b = encoded.charAt(index++) - 63; - result |= (b & 0x1f) << shift; - shift += 5; - } while (b >= 0x20); - int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); - lat += dlat; - - shift = 0; - result = 0; - do { - b = encoded.charAt(index++) - 63; - result |= (b & 0x1f) << shift; - shift += 5; - } while (b >= 0x20); - int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); - lng += dlng; - - GeoPoint p = new GeoPoint((int) (((double) lat / 1E5) * 1E6), (int) (((double) lng / 1E5) * 1E6)); - - if(Debug.DEBUG){ - Log.d(TAG, "current = "+ p.toString()); - if(last != null) - Log.d(TAG, "last = "+ last.toString()); - } - - - if(last != null) - mPath.add(new PathOverlay(last, p, Color.RED)); - - last = p; - } - + public String getCopyrights(){ + return mCopyRights; } + /** + * @return + * @author ricky barrette + */ + public ArrayList getDirections() { + return mDirections; + } + + /** + * @param step + * @return the distance of a step + * @throws JSONException + * @author ricky barrette + */ + private String getDistance(JSONObject step) throws JSONException{ + return step.getJSONObject("distance").getString("text"); + } + + /** + * @return + * @author ricky barrette + */ + public ArrayList getDistances(){ + return mDistance; + } + + /** + * @param step + * @return the duration of a step + * @throws JSONException + * @author ricky barrette + */ + private String getDuration(JSONObject step) throws JSONException{ + return step.getJSONObject("duration").getString("text"); + } + + /** + * @return + * @author ricky barrette + */ + public ArrayList getDurations(){ + return mDuration; + } + /** * Converts a JSON location object into a GeoPoint * @param point @@ -258,26 +319,6 @@ public class DirectionsOverlay { private GeoPoint getGeoPoint(JSONObject point) throws JSONException{ return new GeoPoint((int) (point.getDouble("lat")*1E6), (int) (point.getDouble("lng")*1E6)); } - - /** - * @param step - * @return the duration of a step - * @throws JSONException - * @author ricky barrette - */ - private String getDuration(JSONObject step) throws JSONException{ - return step.getJSONObject("duration").getString("text"); - } - - /** - * @param step - * @return the distance of a step - * @throws JSONException - * @author ricky barrette - */ - private String getDistance(JSONObject step) throws JSONException{ - return step.getJSONObject("distance").getString("text"); - } /** * @return the array of PathOverlays @@ -287,29 +328,6 @@ public class DirectionsOverlay { return mPath; } - /** - * Removes the directions overlay from the map view - * @author ricky barrette - */ - public void removePath() { - if(mMapView.getOverlays().removeAll(mPath)); - } - - /** - * @author ricky barrette - */ - public interface OnDirectionsCompleteListener{ - public void onDirectionsComplete(DirectionsOverlay directionsOverlay); - } - - /** - * @return - * @author ricky barrette - */ - public ArrayList getDirections() { - return mDirections; - } - /** * @return * @author ricky barrette @@ -318,30 +336,6 @@ public class DirectionsOverlay { return mPoints; } - /** - * @return - * @author ricky barrette - */ - public ArrayList getDurations(){ - return mDuration; - } - - /** - * @return - * @author ricky barrette - */ - public ArrayList getDistances(){ - return mDistance; - } - - /** - * @return - * @author ricky barrette - */ - public String getCopyrights(){ - return mCopyRights; - } - /** * @return * @author ricky barrette @@ -349,4 +343,12 @@ public class DirectionsOverlay { public ArrayList getWarnings() { return mWarnings; } + + /** + * Removes the directions overlay from the map view + * @author ricky barrette + */ + public void removePath() { + if(mMapView.getOverlays().removeAll(mPath)); + } } \ No newline at end of file diff --git a/LocationLib/src/com/TwentyCodes/android/overlays/PathOverlay.java b/LocationLib/src/com/TwentyCodes/android/overlays/PathOverlay.java index 22ae866..f1b708c 100644 --- a/LocationLib/src/com/TwentyCodes/android/overlays/PathOverlay.java +++ b/LocationLib/src/com/TwentyCodes/android/overlays/PathOverlay.java @@ -53,7 +53,7 @@ public final class PathOverlay extends Overlay { mMode = POINT; mRadius = radius; mStart = point; - mEnd = null; + mEnd = mStart; mColor = color; } @@ -86,4 +86,20 @@ public final class PathOverlay extends Overlay { } super.draw(canvas, mapView, shadow); } + + /** + * @return the end point of this path + * @author ricky barrette + */ + public GeoPoint getEndPoint(){ + return this.mEnd; + } + + /** + * @return the start point of this path + * @author ricky barrette + */ + public GeoPoint getStartPoint(){ + return this.mStart; + } } \ No newline at end of file