Updated to meet the refactored location library
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
Binary file not shown.
@@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/TextView01"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="20dip"
|
|
||||||
android:textColor="#000000"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/TextView02"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="20dip"
|
|
||||||
android:textColor="#000000"
|
|
||||||
android:layout_gravity="right"
|
|
||||||
android:paddingRight="10dip"
|
|
||||||
/>
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@android:id/list"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent" >
|
|
||||||
|
|
||||||
</ListView>
|
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
android:id="@+id/map_fragment"
|
android:id="@+id/map_fragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
class="com.TwentyCodes.android.SkyHook.SkyHoookUserOverlayMapFragment" >
|
class="com.TwentyCodes.android.fragments.SkyHoookUserOverlayMapFragment" >
|
||||||
|
|
||||||
<!-- Preview: layout=@layout/map_fragment -->
|
<!-- Preview: layout=@layout/map_fragment -->
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|||||||
@@ -1,117 +0,0 @@
|
|||||||
/**
|
|
||||||
* @author Twenty Codes, LLC
|
|
||||||
* @author ricky barrette
|
|
||||||
* @date Sep 22, 2010
|
|
||||||
*/
|
|
||||||
package com.TwentyCodes.android.FindMyCarLib;
|
|
||||||
|
|
||||||
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.FindMyCarLib.UI.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;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -29,15 +29,15 @@ import android.util.Log;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.CustomViewPager;
|
import com.TwentyCodes.android.FindMyCarLib.UI.CustomViewPager;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.DirectionsOverlay;
|
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.fragments.DirectionsListFragment;
|
import com.TwentyCodes.android.FindMyCarLib.UI.fragments.DirectionsListFragment;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.fragments.DirectionsListFragment.OnDirectionSelectedListener;
|
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.fragments.MapFragment;
|
import com.TwentyCodes.android.FindMyCarLib.UI.fragments.MapFragment;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.fragments.MapFragment.MapFragmentListener;
|
import com.TwentyCodes.android.FindMyCarLib.UI.fragments.MapFragment.MapFragmentListener;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.fragments.NotesFragment;
|
import com.TwentyCodes.android.FindMyCarLib.UI.fragments.NotesFragment;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.debug.Debug;
|
import com.TwentyCodes.android.FindMyCarLib.debug.Debug;
|
||||||
import com.TwentyCodes.android.SkyHook.SkyHookRegistration;
|
import com.TwentyCodes.android.SkyHook.SkyHookRegistration;
|
||||||
import com.TwentyCodes.android.exception.ExceptionHandler;
|
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||||
|
import com.TwentyCodes.android.location.OnDirectionSelectedListener;
|
||||||
|
import com.TwentyCodes.android.overlays.DirectionsOverlay;
|
||||||
import com.google.ads.AdRequest;
|
import com.google.ads.AdRequest;
|
||||||
import com.google.ads.AdView;
|
import com.google.ads.AdView;
|
||||||
import com.google.android.maps.GeoPoint;
|
import com.google.android.maps.GeoPoint;
|
||||||
@@ -542,7 +542,7 @@ public class Main extends FragmentActivity implements RegistrationCallback, MapF
|
|||||||
/**
|
/**
|
||||||
* called when a direction is selected
|
* called when a direction is selected
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see com.TwentyCodes.android.FindMyCarLib.UI.fragments.DirectionsListFragment.OnDirectionSelectedListener#onDirectionSelected(com.google.android.maps.GeoPoint)
|
* @see com.TwentyCodes.android.location.DirectionsListFragment.OnDirectionSelectedListener#onDirectionSelected(com.google.android.maps.GeoPoint)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onDirectionSelected(GeoPoint point) {
|
public void onDirectionSelected(GeoPoint point) {
|
||||||
|
|||||||
@@ -1,352 +0,0 @@
|
|||||||
/**
|
|
||||||
* DirectionsOverlay.java
|
|
||||||
* @date Nov 10, 2011
|
|
||||||
* @author ricky barrette
|
|
||||||
* @author Twenty Codes, LLC
|
|
||||||
*/
|
|
||||||
package com.TwentyCodes.android.FindMyCarLib.UI;
|
|
||||||
|
|
||||||
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.FindMyCarLib.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<PathOverlay> mPath;
|
|
||||||
ArrayList<String> mDirections;
|
|
||||||
private MapView mMapView;
|
|
||||||
private OnDirectionsCompleteListener mListener;
|
|
||||||
private String mCopyRights;
|
|
||||||
private ArrayList<GeoPoint> mPoints;
|
|
||||||
private ArrayList<String> mDistance;
|
|
||||||
private ArrayList<String> mDuration;
|
|
||||||
private ArrayList<String> 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<PathOverlay>();
|
|
||||||
mDirections = new ArrayList<String>();
|
|
||||||
mPoints = new ArrayList<GeoPoint>();
|
|
||||||
mDistance = new ArrayList<String>();
|
|
||||||
mDuration = new ArrayList<String>();
|
|
||||||
|
|
||||||
//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<PathOverlay> 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<String> getDirections() {
|
|
||||||
return mDirections;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public ArrayList<GeoPoint> getPoints() {
|
|
||||||
return mPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public ArrayList<String> getDurations(){
|
|
||||||
return mDuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public ArrayList<String> getDistances(){
|
|
||||||
return mDistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public String getCopyrights(){
|
|
||||||
return mCopyRights;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public ArrayList<String> getWarnings() {
|
|
||||||
return mWarnings;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
/**
|
|
||||||
* PathOverlay.java
|
|
||||||
* @date Nov 11, 2011
|
|
||||||
* @author ricky barrette
|
|
||||||
* @author Twenty Codes, LLC
|
|
||||||
*/
|
|
||||||
package com.TwentyCodes.android.FindMyCarLib.UI;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +1,32 @@
|
|||||||
/**
|
/**
|
||||||
* DirectionsListFragment.java
|
* DirectionsListFragment.java
|
||||||
* @date Nov 25, 2011
|
* @date Mar 5, 2012
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
* @author Twenty Codes, LLC
|
* @author Twenty Codes, LLC
|
||||||
*/
|
*/
|
||||||
package com.TwentyCodes.android.FindMyCarLib.UI.fragments;
|
package com.TwentyCodes.android.FindMyCarLib.UI.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.FindMyCarLib.DirectionsAdapter;
|
|
||||||
import com.TwentyCodes.android.FindMyCarLib.Main;
|
import com.TwentyCodes.android.FindMyCarLib.Main;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.R;
|
import com.TwentyCodes.android.FindMyCarLib.R;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.DirectionsOverlay;
|
import com.TwentyCodes.android.location.OnDirectionSelectedListener;
|
||||||
import com.google.android.maps.GeoPoint;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This fragment will be used to display directions to the user.
|
* This is our direction's list fragment.
|
||||||
* When a specific direction is clicked, the corrispoding geopoint is returned via listener
|
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class DirectionsListFragment extends ListFragment {
|
public class DirectionsListFragment extends com.TwentyCodes.android.fragments.DirectionsListFragment {
|
||||||
|
|
||||||
public interface OnDirectionSelectedListener{
|
|
||||||
public void onDirectionSelected(GeoPoint SelectedPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
private OnDirectionSelectedListener mListener;
|
|
||||||
private ArrayList<GeoPoint> mPoints;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Directions List Fragment
|
* Creates a new Directions List Fragment
|
||||||
|
* @param listener
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public DirectionsListFragment() {
|
public DirectionsListFragment(OnDirectionSelectedListener listener) {
|
||||||
super();
|
super(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* We override onstart to set emptry list messasges
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see android.support.v4.app.Fragment#onStart()
|
* @see android.support.v4.app.Fragment#onStart()
|
||||||
*/
|
*/
|
||||||
@@ -55,44 +40,4 @@ public class DirectionsListFragment extends ListFragment {
|
|||||||
super.onStart();
|
super.onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new Directions List Fragment
|
|
||||||
* @param listener
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public DirectionsListFragment(OnDirectionSelectedListener listener) {
|
|
||||||
this();
|
|
||||||
mListener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes all content in the listview
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public void clear() {
|
|
||||||
this.setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, new ArrayList<String>()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,14 +38,14 @@ import com.TwentyCodes.android.FindMyCarLib.Main;
|
|||||||
import com.TwentyCodes.android.FindMyCarLib.ParkignTimerActivity;
|
import com.TwentyCodes.android.FindMyCarLib.ParkignTimerActivity;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.R;
|
import com.TwentyCodes.android.FindMyCarLib.R;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.Settings;
|
import com.TwentyCodes.android.FindMyCarLib.Settings;
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.DirectionsOverlay;
|
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.DirectionsOverlay.OnDirectionsCompleteListener;
|
|
||||||
import com.TwentyCodes.android.FindMyCarLib.UI.FindMyCarOverlay;
|
import com.TwentyCodes.android.FindMyCarLib.UI.FindMyCarOverlay;
|
||||||
import com.TwentyCodes.android.SkyHook.SkyHoookUserOverlayMapFragment;
|
import com.TwentyCodes.android.fragments.SkyHoookUserOverlayMapFragment;
|
||||||
import com.TwentyCodes.android.location.GeoPointLocationListener;
|
import com.TwentyCodes.android.location.GeoPointLocationListener;
|
||||||
import com.TwentyCodes.android.location.GeoUtils;
|
import com.TwentyCodes.android.location.GeoUtils;
|
||||||
import com.TwentyCodes.android.location.MapView;
|
import com.TwentyCodes.android.location.MapView;
|
||||||
import com.TwentyCodes.android.location.MidPoint;
|
import com.TwentyCodes.android.location.MidPoint;
|
||||||
|
import com.TwentyCodes.android.overlays.DirectionsOverlay;
|
||||||
|
import com.TwentyCodes.android.overlays.DirectionsOverlay.OnDirectionsCompleteListener;
|
||||||
import com.google.android.maps.GeoPoint;
|
import com.google.android.maps.GeoPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user