diff --git a/LocationLib/bin/locationlib.jar b/LocationLib/bin/locationlib.jar
index cf4031b..5f07e6d 100644
Binary files a/LocationLib/bin/locationlib.jar and b/LocationLib/bin/locationlib.jar differ
diff --git a/LocationLib/res/layout/list_row.xml b/LocationLib/res/layout/list_row.xml
new file mode 100755
index 0000000..e6ab51b
--- /dev/null
+++ b/LocationLib/res/layout/list_row.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/LocationLib/res/layout/listview.xml b/LocationLib/res/layout/listview.xml
new file mode 100644
index 0000000..fd8cccf
--- /dev/null
+++ b/LocationLib/res/layout/listview.xml
@@ -0,0 +1,7 @@
+
+
+
+
\ No newline at end of file
diff --git a/LocationLib/src/com/TwentyCodes/android/fragments/DirectionsAdapter.java b/LocationLib/src/com/TwentyCodes/android/fragments/DirectionsAdapter.java
new file mode 100644
index 0000000..d9464ef
--- /dev/null
+++ b/LocationLib/src/com/TwentyCodes/android/fragments/DirectionsAdapter.java
@@ -0,0 +1,118 @@
+/**
+ * @author Twenty Codes, LLC
+ * @author ricky barrette
+ * @date Sep 22, 2010
+ */
+package com.TwentyCodes.android.fragments;
+
+import android.content.Context;
+import android.text.Html;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import com.TwentyCodes.android.location.R;
+import com.TwentyCodes.android.overlays.DirectionsOverlay;
+
+/**
+ * this is a custom listview adaptor that wills a listview that has 2 textviews in each row.
+ * @author ricky barrette
+ */
+public class DirectionsAdapter extends BaseAdapter {
+
+ private LayoutInflater mInflater;
+ private DirectionsOverlay mDirections;
+
+
+ /**
+ * Creates a new DirectionsAdapter
+ * @author ricky barrette
+ */
+ public DirectionsAdapter(Context context, DirectionsOverlay directions) {
+ mInflater = LayoutInflater.from(context);
+ mDirections = directions;
+ }
+
+ /**
+ * returns the size of the main list
+ * @see android.widget.Adapter#getCount()
+ * @return
+ * @author ricky barrette
+ */
+ @Override
+ public int getCount() {
+ return mDirections.getDirections().size() + 1;
+ }
+
+ /**
+ * (non-Javadoc)
+ * @see android.widget.Adapter#getItem(int)
+ * @param position
+ * @return
+ * @author ricky barrette
+ */
+ @Override
+ public Object getItem(int position) {
+ return position;
+ }
+
+ /**
+ * returns the current position in the list
+ * @see android.widget.Adapter#getItemId(int)
+ * @param position
+ * @return
+ * @author ricky barrette
+ */
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ /**
+ * inflates the row from xml, and sets the textviews to their intended vales
+ * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
+ * @param position
+ * @param convertView
+ * @param parent
+ * @return
+ * @author ricky barrette
+ */
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewHolder holder;
+ if (convertView == null) {
+ convertView = mInflater.inflate(R.layout.list_row, null);
+ holder = new ViewHolder();
+ holder.text = (TextView) convertView.findViewById(R.id.TextView01);
+ holder.text2 = (TextView) convertView.findViewById(R.id.TextView02);
+
+ convertView.setTag(holder);
+ } else {
+ holder = (ViewHolder) convertView.getTag();
+ }
+
+ /**
+ * Display the copyrights on the bottom of the directions list
+ */
+ if (position == mDirections.getDirections().size()){
+ holder.text.setText(mDirections.getCopyrights());
+ holder.text2.setText("");
+ } else {
+ holder.text.setText(Html.fromHtml(mDirections.getDirections().get(position)));
+ holder.text2.setText(mDirections.getDurations().get(position) +" : "+ mDirections.getDistances().get(position));
+ }
+ return convertView;
+ }
+
+ /**
+ * this class will hold the TextViews
+ * @author ricky barrette
+ */
+ class ViewHolder {
+ TextView text;
+ TextView text2;
+ }
+
+}
\ No newline at end of file
diff --git a/LocationLib/src/com/TwentyCodes/android/fragments/DirectionsListFragment.java b/LocationLib/src/com/TwentyCodes/android/fragments/DirectionsListFragment.java
new file mode 100644
index 0000000..f1d453d
--- /dev/null
+++ b/LocationLib/src/com/TwentyCodes/android/fragments/DirectionsListFragment.java
@@ -0,0 +1,97 @@
+/**
+ * DirectionsListFragment.java
+ * @date Nov 25, 2011
+ * @author ricky barrette
+ * @author Twenty Codes, LLC
+ */
+package com.TwentyCodes.android.fragments;
+
+import java.util.ArrayList;
+
+import android.support.v4.app.ListFragment;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+
+import com.TwentyCodes.android.location.OnDirectionSelectedListener;
+import com.TwentyCodes.android.overlays.DirectionsOverlay;
+import com.google.android.maps.GeoPoint;
+
+/**
+ * This fragment will be used to display directions to the user.
+ * When a specific direction is clicked, the corrispoding geopoint is returned via listener
+ * @author ricky barrette
+ */
+public class DirectionsListFragment extends ListFragment {
+
+ private OnDirectionSelectedListener mListener;
+ private ArrayList mPoints;
+
+ /**
+ * Creates a new Directions List Fragment
+ * @author ricky barrette
+ */
+ public DirectionsListFragment() {
+ super();
+ }
+
+ /**
+ * Creates a new Directions List Fragment
+ * @param listener
+ * @author ricky barrette
+ */
+ public DirectionsListFragment(OnDirectionSelectedListener listener) {
+ this();
+ mListener = listener;
+ }
+
+ /**
+ * Deletes all content in the listview
+ * @author ricky barrette
+ */
+ public void clear() {
+ this.setListAdapter(new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, new ArrayList()));
+ }
+
+ /**
+ * Called when a list item is clicked.
+ * Checks to see if the list item is a direction, if to it reports the selected direction's geopoint to the listener
+ * (non-Javadoc)
+ * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long)
+ */
+ @Override
+ public void onListItemClick(ListView l, View w, int position, long id) {
+ if(position < mPoints.size())
+ if(mListener != null)
+ mListener.onDirectionSelected(mPoints.get(position));
+ }
+
+ /**
+ * (non-Javadoc)
+ * @see android.support.v4.app.Fragment#onStart()
+ */
+ @Override
+ public void onStart() {
+ this.setListShown(true);
+ super.onStart();
+ }
+
+ /**
+ * Displays the directions from the provided DirectionsOverlay object
+ * @param directions
+ * @author ricky barrette
+ */
+ public void setDirections(final DirectionsOverlay directions) {
+ mPoints = directions.getPoints();
+ this.setListAdapter(new DirectionsAdapter(getActivity(), directions));
+ }
+
+ /**
+ * Sets the text to be displayed while the list is empty
+ * @param text
+ * @author ricky barrette
+ */
+ public void SetEmptyText(String text){
+ this.setEmptyText(text);
+ }
+}
diff --git a/LocationLib/src/com/TwentyCodes/android/location/MapFragmentBase.java b/LocationLib/src/com/TwentyCodes/android/fragments/MapFragmentBase.java
similarity index 90%
rename from LocationLib/src/com/TwentyCodes/android/location/MapFragmentBase.java
rename to LocationLib/src/com/TwentyCodes/android/fragments/MapFragmentBase.java
index 7466da7..72abe18 100644
--- a/LocationLib/src/com/TwentyCodes/android/location/MapFragmentBase.java
+++ b/LocationLib/src/com/TwentyCodes/android/fragments/MapFragmentBase.java
@@ -4,7 +4,7 @@
* @author ricky barrette
* @author Twenty Codes, LLC
*/
-package com.TwentyCodes.android.location;
+package com.TwentyCodes.android.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
@@ -12,6 +12,10 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import com.TwentyCodes.android.location.MapView;
+import com.TwentyCodes.android.location.R;
+import com.TwentyCodes.android.location.R.id;
+import com.TwentyCodes.android.location.R.layout;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.Overlay;
diff --git a/LocationLib/src/com/TwentyCodes/android/SkyHook/SkyHoookUserOverlayMapFragment.java b/LocationLib/src/com/TwentyCodes/android/fragments/SkyHoookUserOverlayMapFragment.java
similarity index 91%
rename from LocationLib/src/com/TwentyCodes/android/SkyHook/SkyHoookUserOverlayMapFragment.java
rename to LocationLib/src/com/TwentyCodes/android/fragments/SkyHoookUserOverlayMapFragment.java
index f72d6f8..91445ac 100644
--- a/LocationLib/src/com/TwentyCodes/android/SkyHook/SkyHoookUserOverlayMapFragment.java
+++ b/LocationLib/src/com/TwentyCodes/android/fragments/SkyHoookUserOverlayMapFragment.java
@@ -4,12 +4,12 @@
* @author ricky barrette
* @author Twenty Codes, LLC
*/
-package com.TwentyCodes.android.SkyHook;
+package com.TwentyCodes.android.fragments;
import com.TwentyCodes.android.location.CompassListener;
import com.TwentyCodes.android.location.GeoPointLocationListener;
-import com.TwentyCodes.android.location.MapFragmentBase;
import com.TwentyCodes.android.location.MapView;
+import com.TwentyCodes.android.overlays.SkyHookUserOverlay;
import com.google.android.maps.GeoPoint;
/**
@@ -88,7 +88,7 @@ public class SkyHoookUserOverlayMapFragment extends MapFragmentBase implements G
/**
* (non-Javadoc)
- * @see com.TwentyCodes.android.location.MapFragmentBase#onMapViewCreate(com.TwentyCodes.android.location.MapView)
+ * @see com.TwentyCodes.android.fragments.MapFragmentBase#onMapViewCreate(com.TwentyCodes.android.location.MapView)
*/
@Override
public void onMapViewCreate(MapView map) {
@@ -104,7 +104,7 @@ public class SkyHoookUserOverlayMapFragment extends MapFragmentBase implements G
/**
* (non-Javadoc)
- * @see com.TwentyCodes.android.location.MapFragmentBase#onPause()
+ * @see com.TwentyCodes.android.fragments.MapFragmentBase#onPause()
*/
@Override
public void onPause() {
@@ -115,7 +115,7 @@ public class SkyHoookUserOverlayMapFragment extends MapFragmentBase implements G
/**
* (non-Javadoc)
- * @see com.TwentyCodes.android.location.MapFragmentBase#onResume()
+ * @see com.TwentyCodes.android.fragments.MapFragmentBase#onResume()
*/
@Override
public void onResume() {
diff --git a/LocationLib/src/com/TwentyCodes/android/location/UserOverlayMapFragment.java b/LocationLib/src/com/TwentyCodes/android/fragments/UserOverlayMapFragment.java
similarity index 87%
rename from LocationLib/src/com/TwentyCodes/android/location/UserOverlayMapFragment.java
rename to LocationLib/src/com/TwentyCodes/android/fragments/UserOverlayMapFragment.java
index bc91270..0b1fd2c 100644
--- a/LocationLib/src/com/TwentyCodes/android/location/UserOverlayMapFragment.java
+++ b/LocationLib/src/com/TwentyCodes/android/fragments/UserOverlayMapFragment.java
@@ -4,8 +4,12 @@
* @author ricky barrette
* @author Twenty Codes, LLC
*/
-package com.TwentyCodes.android.location;
+package com.TwentyCodes.android.fragments;
+import com.TwentyCodes.android.location.CompassListener;
+import com.TwentyCodes.android.location.GeoPointLocationListener;
+import com.TwentyCodes.android.location.MapView;
+import com.TwentyCodes.android.overlays.UserOverlay;
import com.google.android.maps.GeoPoint;
/**
@@ -84,7 +88,7 @@ public class UserOverlayMapFragment extends MapFragmentBase implements GeoPointL
/**
* (non-Javadoc)
- * @see com.TwentyCodes.android.location.MapFragmentBase#onMapViewCreate(com.TwentyCodes.android.location.MapView)
+ * @see com.TwentyCodes.android.fragments.MapFragmentBase#onMapViewCreate(com.TwentyCodes.android.location.MapView)
*/
@Override
public void onMapViewCreate(MapView map) {
@@ -100,7 +104,7 @@ public class UserOverlayMapFragment extends MapFragmentBase implements GeoPointL
/**
* (non-Javadoc)
- * @see com.TwentyCodes.android.location.MapFragmentBase#onPause()
+ * @see com.TwentyCodes.android.fragments.MapFragmentBase#onPause()
*/
@Override
public void onPause() {
@@ -111,7 +115,7 @@ public class UserOverlayMapFragment extends MapFragmentBase implements GeoPointL
/**
* (non-Javadoc)
- * @see com.TwentyCodes.android.location.MapFragmentBase#onResume()
+ * @see com.TwentyCodes.android.fragments.MapFragmentBase#onResume()
*/
@Override
public void onResume() {
diff --git a/LocationLib/src/com/TwentyCodes/android/location/OnDirectionSelectedListener.java b/LocationLib/src/com/TwentyCodes/android/location/OnDirectionSelectedListener.java
new file mode 100644
index 0000000..8f546f8
--- /dev/null
+++ b/LocationLib/src/com/TwentyCodes/android/location/OnDirectionSelectedListener.java
@@ -0,0 +1,24 @@
+/**
+ * OnDirectionSelectedListener.java
+ * @date Mar 5, 2012
+ * @author ricky barrette
+ * @author Twenty Codes, LLC
+ */
+package com.TwentyCodes.android.location;
+
+import com.google.android.maps.GeoPoint;
+
+/**
+ * A simple interfrace for a directions list fragment
+ * @author ricky barrette
+ */
+public interface OnDirectionSelectedListener {
+
+ /**
+ * Called when the user selects a direction from a directions list
+ * @param point
+ * @author ricky barrette
+ */
+ public void onDirectionSelected(GeoPoint point);
+
+}
diff --git a/LocationLib/src/com/TwentyCodes/android/location/LocationSelectedListener.java b/LocationLib/src/com/TwentyCodes/android/location/OnLocationSelectedListener.java
similarity index 85%
rename from LocationLib/src/com/TwentyCodes/android/location/LocationSelectedListener.java
rename to LocationLib/src/com/TwentyCodes/android/location/OnLocationSelectedListener.java
index 61a0d25..a62cb75 100644
--- a/LocationLib/src/com/TwentyCodes/android/location/LocationSelectedListener.java
+++ b/LocationLib/src/com/TwentyCodes/android/location/OnLocationSelectedListener.java
@@ -6,7 +6,7 @@ import com.google.android.maps.GeoPoint;
* This interface will be used to pass the selected location from the dialogs to the listening instance
* @author ricky barrette
*/
-public interface LocationSelectedListener {
+public interface OnLocationSelectedListener {
public void onLocationSelected(GeoPoint point);
}
\ No newline at end of file
diff --git a/LocationLib/src/com/TwentyCodes/android/location/CompasOverlay.java b/LocationLib/src/com/TwentyCodes/android/overlays/CompasOverlay.java
similarity index 95%
rename from LocationLib/src/com/TwentyCodes/android/location/CompasOverlay.java
rename to LocationLib/src/com/TwentyCodes/android/overlays/CompasOverlay.java
index c5a47e4..1bc3c1e 100644
--- a/LocationLib/src/com/TwentyCodes/android/location/CompasOverlay.java
+++ b/LocationLib/src/com/TwentyCodes/android/overlays/CompasOverlay.java
@@ -4,7 +4,7 @@
* @author ricky barrette
* @author Twenty Codes, LLC
*/
-package com.TwentyCodes.android.location;
+package com.TwentyCodes.android.overlays;
import android.content.Context;
import android.content.res.Resources;
@@ -15,7 +15,11 @@ import android.graphics.Matrix;
import android.graphics.Point;
import android.util.TypedValue;
+import com.TwentyCodes.android.location.CompassListener;
+import com.TwentyCodes.android.location.CompassSensor;
+import com.TwentyCodes.android.location.GeoUtils;
import com.TwentyCodes.android.location.R;
+import com.TwentyCodes.android.location.R.drawable;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
diff --git a/LocationLib/src/com/TwentyCodes/android/overlays/DirectionsOverlay.java b/LocationLib/src/com/TwentyCodes/android/overlays/DirectionsOverlay.java
new file mode 100644
index 0000000..3a0d069
--- /dev/null
+++ b/LocationLib/src/com/TwentyCodes/android/overlays/DirectionsOverlay.java
@@ -0,0 +1,352 @@
+/**
+ * DirectionsOverlay.java
+ * @date Nov 10, 2011
+ * @author ricky barrette
+ * @author Twenty Codes, LLC
+ */
+package com.TwentyCodes.android.overlays;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.graphics.Color;
+import android.util.Log;
+
+import com.TwentyCodes.android.debug.Debug;
+import com.TwentyCodes.android.location.MapView;
+import com.google.android.maps.GeoPoint;
+
+/**
+ * This Overlay class will be used to display provided by the Google Directions API on a map
+ * @author ricky barrette
+ */
+public class DirectionsOverlay {
+
+ private static final String TAG = "DirectionsOverlay";
+ ArrayList mPath;
+ ArrayList mDirections;
+ private MapView mMapView;
+ private OnDirectionsCompleteListener mListener;
+ private String mCopyRights;
+ private ArrayList mPoints;
+ private ArrayList mDistance;
+ private ArrayList mDuration;
+ private ArrayList mWarnings;
+
+ /**
+ * Downloads and Creates a new DirectionsOverlay from the provided points
+ * @param origin point
+ * @param destination point
+ * @author ricky barrette
+ * @throws IOException
+ * @throws ClientProtocolException
+ * @throws IllegalStateException
+ * @throws JSONException
+ */
+ public DirectionsOverlay(MapView map, GeoPoint origin, GeoPoint destination, OnDirectionsCompleteListener listener) throws IllegalStateException, ClientProtocolException, IOException, JSONException {
+ mMapView = map;
+ mListener = listener;
+ String json = downloadJSON(generateUrl(origin, destination));
+ drawPath(json);
+ }
+
+ /**
+ * Creates a new DirectionsOverlay from the provided String JSON
+ * @param json
+ * @throws JSONException
+ * @author ricky barrette
+ */
+ public DirectionsOverlay(MapView map, String json, OnDirectionsCompleteListener listener) throws JSONException{
+ mListener = listener;
+ mMapView = map;
+ drawPath(json);
+ }
+
+ /**
+ * Downloads Google Directions JSON from the Internet
+ * @param url
+ * @return
+ * @throws IllegalStateException
+ * @throws ClientProtocolException
+ * @throws IOException
+ * @author ricky barrette
+ */
+ private String downloadJSON(String url) throws IllegalStateException, ClientProtocolException, IOException {
+ if(Debug.DEBUG)
+ Log.d(TAG, url);
+ if(url == null)
+ throw new NullPointerException();
+ StringBuffer response = new StringBuffer();
+ BufferedReader br = new BufferedReader(new InputStreamReader(new DefaultHttpClient().execute(new HttpGet(url)).getEntity().getContent()));
+ String buff = null;
+ while ((buff = br.readLine()) != null)
+ response.append(buff);
+ return response.toString();
+ }
+
+ /**
+ * Creates a new DirectionsOverlay from the json provided
+ * @param json of Google Directions API
+ * @author ricky barrette
+ * @return
+ * @throws JSONException
+ */
+ public void drawPath(String json) throws JSONException{
+ if(Debug.DEBUG){
+ Log.d(TAG, "drawPath");
+ Log.d(TAG, json);
+ }
+ mPath = new ArrayList();
+ mDirections = new ArrayList();
+ mPoints = new ArrayList();
+ mDistance = new ArrayList();
+ mDuration = new ArrayList();
+
+ //get first route
+ JSONObject route = new JSONObject(json).getJSONArray("routes").getJSONObject(0);
+
+ mCopyRights = route.getString("copyrights");
+ //route.getString("status");
+
+ JSONObject leg = route.getJSONArray("legs").getJSONObject(0);
+ getDistance(leg);
+ getDuration(leg);
+// mMapView.getOverlays().add(new PathOverlay(getGeoPoint(leg.getJSONObject("start_location")), 12, Color.GREEN));
+// mMapView.getOverlays().add(new PathOverlay(getGeoPoint(leg.getJSONObject("end_location")), 12, Color.RED));
+
+ leg.getString("start_address");
+ leg.getString("end_address");
+
+// JSONArray warnings = leg.getJSONArray("warnings");
+// for(int i = 0; i < warnings.length(); i++){
+// mWarnings.add(warnings.get)w
+// }w
+
+ /*
+ * here we will parse the steps of the directions
+ */
+ if(Debug.DEBUG)
+ Log.d(TAG, "processing steps");
+ JSONArray steps = leg.getJSONArray("steps");
+ JSONObject step = null;
+ for(int i = 0; i < steps.length(); i++){
+ if(Debug.DEBUG)
+ Log.d(TAG, "step "+i);
+
+ step = steps.getJSONObject(i);
+
+ if(Debug.DEBUG){
+ Log.d(TAG, "start "+getGeoPoint(step.getJSONObject("start_location")).toString());
+ Log.d(TAG, "end "+getGeoPoint(step.getJSONObject("end_location")).toString());
+ }
+
+// if(Debug.DEBUG)
+// mMapView.getOverlays().add(new PathOverlay(getGeoPoint(step.getJSONObject("start_location")), getGeoPoint(step.getJSONObject("end_location")), Color.MAGENTA));
+
+ decodePoly(step);
+
+ mDuration.add(getDuration(step));
+
+ mDistance.add(getDistance(step));
+
+ mDirections.add(step.getString("html_instructions"));
+// Log.d("TEST", step.getString("html_instructions"));
+ mPoints.add(getGeoPoint(step.getJSONObject("start_location")));
+
+ }
+ if(Debug.DEBUG)
+ Log.d(TAG, "finished parsing");
+
+ if(mMapView != null){
+ mMapView.getOverlays().addAll(mPath);
+ mMapView.postInvalidate();
+ }
+
+ if(mListener != null)
+ mListener.onDirectionsComplete(DirectionsOverlay.this);
+ }
+
+ /**
+ * @param origin
+ * @param destination
+ * @return The Google API url for our directions
+ * @author ricky barrette
+ */
+ private String generateUrl(GeoPoint origin, GeoPoint destination){
+ return "http://maps.googleapis.com/maps/api/directions/json?&origin="+
+ Double.toString(origin.getLatitudeE6() / 1.0E6)+
+ ","+
+ Double.toString(origin.getLongitudeE6() / 1.0E6)+
+ "&destination="+
+ Double.toString(destination.getLatitudeE6() / 1.0E6)+
+ ","+
+ Double.toString(destination.getLongitudeE6() / 1.0E6)+
+ "&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/
+ * @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;
+ }
+
+ }
+
+ /**
+ * Converts a JSON location object into a GeoPoint
+ * @param point
+ * @return Geopoint parsed from the provided JSON Object
+ * @throws JSONException
+ * @author ricky barrette
+ */
+ 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
+ * @author ricky barrette
+ */
+ public ArrayList getPath(){
+ 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
+ */
+ public ArrayList getPoints() {
+ 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
+ */
+ public ArrayList getWarnings() {
+ return mWarnings;
+ }
+}
\ 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
new file mode 100644
index 0000000..22e306d
--- /dev/null
+++ b/LocationLib/src/com/TwentyCodes/android/overlays/PathOverlay.java
@@ -0,0 +1,86 @@
+/**
+ * PathOverlay.java
+ * @date Nov 11, 2011
+ * @author ricky barrette
+ * @author Twenty Codes, LLC
+ */
+package com.TwentyCodes.android.overlays;
+
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Point;
+import android.graphics.RectF;
+
+import com.google.android.maps.GeoPoint;
+import com.google.android.maps.MapView;
+import com.google.android.maps.Overlay;
+import com.google.android.maps.Projection;
+
+/**
+ * This overlay class is used to draw a path and points on a map
+ * @author ricky barrette
+ */
+public class PathOverlay extends Overlay {
+
+ private static final int PATH = 0;
+ private static final int POINT = 1;
+ private GeoPoint mStart;
+ private GeoPoint mEnd;
+ private int mColor;
+ private int mMode;
+ private int mRadius;
+
+ /**
+ * Creates a new PathOverlay in path mode
+ * @author ricky barrette
+ */
+ public PathOverlay(GeoPoint start, GeoPoint end, int color) {
+ mStart = start;
+ mEnd = end;
+ mColor = color;
+ mMode = PATH;
+ }
+
+ /**
+ * Creates a new PathOverlay in point mode. This is used to draw end points.
+ * @param point
+ * @param radius
+ * @param color
+ * @author ricky barrette
+ */
+ public PathOverlay(GeoPoint point, int radius, int color){
+ mMode = POINT;
+ mRadius = radius;
+ mStart = point;
+ }
+
+ /**
+ *
+ * @param canvas canvas to be drawn on
+ * @param mapView
+ * @param shadow
+ * @param when
+ */
+ @Override
+ public void draw(Canvas canvas, MapView mapView, boolean shadow) {
+ Projection projection = mapView.getProjection();
+ Paint paint = new Paint();
+ paint.setColor(mColor);
+ paint.setAntiAlias(true);
+ Point point = new Point();
+ projection.toPixels(mStart, point);
+
+ switch (mMode){
+ case POINT:
+ RectF oval = new RectF(point.x - mRadius, point.y - mRadius, point.x + mRadius, point.y + mRadius);
+ canvas.drawOval(oval, paint);
+ case PATH:
+ Point point2 = new Point();
+ projection.toPixels(mEnd, point2);
+ paint.setStrokeWidth(5);
+ paint.setAlpha(120);
+ canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);
+ }
+ super.draw(canvas, mapView, shadow);
+ }
+}
\ No newline at end of file
diff --git a/LocationLib/src/com/TwentyCodes/android/location/RadiusOverlay.java b/LocationLib/src/com/TwentyCodes/android/overlays/RadiusOverlay.java
similarity index 93%
rename from LocationLib/src/com/TwentyCodes/android/location/RadiusOverlay.java
rename to LocationLib/src/com/TwentyCodes/android/overlays/RadiusOverlay.java
index 75ccc48..4ef0675 100644
--- a/LocationLib/src/com/TwentyCodes/android/location/RadiusOverlay.java
+++ b/LocationLib/src/com/TwentyCodes/android/overlays/RadiusOverlay.java
@@ -3,7 +3,7 @@
* @author ricky barrette
*/
-package com.TwentyCodes.android.location;
+package com.TwentyCodes.android.overlays;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -12,6 +12,8 @@ import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.RectF;
+import com.TwentyCodes.android.location.GeoUtils;
+import com.TwentyCodes.android.location.OnLocationSelectedListener;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
@@ -30,7 +32,7 @@ public class RadiusOverlay extends Overlay{
private float mRadius = 0;
private int mColor = Color.GREEN;
private GeoPoint mRadiusPoint;
- private LocationSelectedListener mListener;
+ private OnLocationSelectedListener mListener;
/**
* Creates a new RadiusOverlay
@@ -150,7 +152,7 @@ public class RadiusOverlay extends Overlay{
return 0;
}
- public void setLocationSelectedListener(LocationSelectedListener listener) {
+ public void setLocationSelectedListener(OnLocationSelectedListener listener) {
this.mListener = listener;
}
}
\ No newline at end of file
diff --git a/LocationLib/src/com/TwentyCodes/android/SkyHook/SkyHookUserOverlay.java b/LocationLib/src/com/TwentyCodes/android/overlays/SkyHookUserOverlay.java
similarity index 81%
rename from LocationLib/src/com/TwentyCodes/android/SkyHook/SkyHookUserOverlay.java
rename to LocationLib/src/com/TwentyCodes/android/overlays/SkyHookUserOverlay.java
index 1e01ba0..26f0fff 100644
--- a/LocationLib/src/com/TwentyCodes/android/SkyHook/SkyHookUserOverlay.java
+++ b/LocationLib/src/com/TwentyCodes/android/overlays/SkyHookUserOverlay.java
@@ -3,11 +3,11 @@
* @author ricky barrette
* @date Oct 2, 2010
*/
-package com.TwentyCodes.android.SkyHook;
+package com.TwentyCodes.android.overlays;
import android.content.Context;
-import com.TwentyCodes.android.location.UserOverlayBase;
+import com.TwentyCodes.android.SkyHook.SkyHook;
import com.google.android.maps.MapView;
/**
@@ -38,7 +38,7 @@ public class SkyHookUserOverlay extends UserOverlayBase{
/**
* Called when the location provider needs to be disabled
* (non-Javadoc)
- * @see com.TwentyCodes.android.location.UserOverlayBase#onMyLocationDisabled()
+ * @see com.TwentyCodes.android.overlays.UserOverlayBase#onMyLocationDisabled()
*/
@Override
public void onMyLocationDisabled() {
@@ -48,7 +48,7 @@ public class SkyHookUserOverlay extends UserOverlayBase{
/**
* Called when the location provider needs to be enabled
* (non-Javadoc)
- * @see com.TwentyCodes.android.location.UserOverlayBase#onMyLocationEnabled()
+ * @see com.TwentyCodes.android.overlays.UserOverlayBase#onMyLocationEnabled()
*/
@Override
public void onMyLocationEnabled() {
diff --git a/LocationLib/src/com/TwentyCodes/android/location/UserOverlay.java b/LocationLib/src/com/TwentyCodes/android/overlays/UserOverlay.java
similarity index 89%
rename from LocationLib/src/com/TwentyCodes/android/location/UserOverlay.java
rename to LocationLib/src/com/TwentyCodes/android/overlays/UserOverlay.java
index f67898d..fb9e504 100644
--- a/LocationLib/src/com/TwentyCodes/android/location/UserOverlay.java
+++ b/LocationLib/src/com/TwentyCodes/android/overlays/UserOverlay.java
@@ -3,10 +3,11 @@
* @author ricky barrette
* @date Dec 28, 2010
*/
-package com.TwentyCodes.android.location;
+package com.TwentyCodes.android.overlays;
import android.content.Context;
+import com.TwentyCodes.android.location.AndroidGPS;
import com.google.android.maps.MapView;
/**
diff --git a/LocationLib/src/com/TwentyCodes/android/location/UserOverlayBase.java b/LocationLib/src/com/TwentyCodes/android/overlays/UserOverlayBase.java
similarity index 97%
rename from LocationLib/src/com/TwentyCodes/android/location/UserOverlayBase.java
rename to LocationLib/src/com/TwentyCodes/android/overlays/UserOverlayBase.java
index 1d46356..c9fe986 100644
--- a/LocationLib/src/com/TwentyCodes/android/location/UserOverlayBase.java
+++ b/LocationLib/src/com/TwentyCodes/android/overlays/UserOverlayBase.java
@@ -4,7 +4,7 @@
* @author ricky barrette
* @author Twenty Codes, LLC
*/
-package com.TwentyCodes.android.location;
+package com.TwentyCodes.android.overlays;
import android.app.AlertDialog;
import android.app.ProgressDialog;
@@ -22,7 +22,12 @@ import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;
+import com.TwentyCodes.android.location.CompassListener;
+import com.TwentyCodes.android.location.GeoPointLocationListener;
+import com.TwentyCodes.android.location.GeoUtils;
import com.TwentyCodes.android.location.R;
+import com.TwentyCodes.android.location.R.drawable;
+import com.TwentyCodes.android.location.R.string;
import com.TwentyCodes.android.debug.Debug;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;