Inital Commit of my mulitiple point navigation changes

Change-Id: I33996d4aaf6200b25cd46e95aba78330494c09a9
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-03-10 10:03:17 -05:00
parent fe5962a816
commit e5f274993c
4 changed files with 136 additions and 19 deletions

View File

@@ -13,7 +13,7 @@
# get is the path to your json retrieval script
# app is the redmine project name
# tracker is the redmine tracker
server = http://rickbarrette.dyndns.org:8080/redmine/exceptionhandler
server = http://rickbarrette.dyndns.org:8888
app = IOIO Truck
tracker = Development Bug

View File

@@ -47,6 +47,8 @@ public class Main extends Activity implements OnClickListener {
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
setContentView(R.layout.main);
// Integer.parseInt("poop");
findViewById(R.id.test_activity_button).setOnClickListener(this);
findViewById(R.id.nav_activity_button).setOnClickListener(this);
findViewById(R.id.camera_activity_button).setOnClickListener(this);

View File

@@ -21,12 +21,19 @@
*/
package com.TwentyCodes.android.IOIOTruck;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import android.util.Log;
import com.TwentyCodes.android.location.LocationSelectedListener;
import com.TwentyCodes.android.fragments.UserOverlayMapFragment;
import com.TwentyCodes.android.location.MapView;
import com.TwentyCodes.android.location.RadiusOverlay;
import com.TwentyCodes.android.location.UserOverlayMapFragment;
import com.TwentyCodes.android.location.OnLocationSelectedListener;
import com.TwentyCodes.android.overlays.DirectionsOverlay;
import com.TwentyCodes.android.overlays.DirectionsOverlay.OnDirectionsCompleteListener;
import com.TwentyCodes.android.overlays.RadiusOverlay;
import com.google.android.maps.GeoPoint;
/**
@@ -35,12 +42,16 @@ import com.google.android.maps.GeoPoint;
* Specifically this map view will allow user to select a point on the map via RadiusOverlay
* @author ricky barrette
*/
public class MapFragment extends UserOverlayMapFragment implements LocationSelectedListener {
public class MapFragment extends UserOverlayMapFragment implements OnLocationSelectedListener, OnDirectionsCompleteListener {
private final String TAG = "MapFragment";
private RadiusOverlay mRadiusOverlay;
private LocationSelectedListener mLocationSelectedListener;
private OnLocationSelectedListener mLocationSelectedListener;
private OnDirectionsCompleteListener mDirectionsCompleteListener;
private DirectionsOverlay mDirectionsOverlay;
/**
* Creates a new MapFragment
@@ -50,6 +61,18 @@ public class MapFragment extends UserOverlayMapFragment implements LocationSelec
super();
}
/**
* Called whrn the directions overlay is finished getting the directions.
* (non-Javadoc)
* @see com.TwentyCodes.android.overlays.DirectionsOverlay.OnDirectionsCompleteListener#onDirectionsComplete(com.TwentyCodes.android.overlays.DirectionsOverlay)
*/
@Override
public void onDirectionsComplete(DirectionsOverlay directionsOverlay) {
mDirectionsOverlay = directionsOverlay;
if(mDirectionsCompleteListener != null)
mDirectionsCompleteListener.onDirectionsComplete(directionsOverlay);
}
/**
* Called when a point is selected on the map
* (non-Javadoc)
@@ -88,10 +111,52 @@ public class MapFragment extends UserOverlayMapFragment implements LocationSelec
}
/**
* (non-Javadoc)
* @see com.TwentyCodes.android.fragments.UserOverlayMapFragment#setDestination(com.google.android.maps.GeoPoint)
*/
@Override
public void setDestination(final GeoPoint destination) {
if(mDirectionsOverlay != null)
mDirectionsOverlay.removePath();
if(mDirectionsCompleteListener != null)
new Thread( new Runnable(){
@Override
public void run(){
try {
new DirectionsOverlay(getMap(), getUserLocation(), destination, MapFragment.this);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
super.setDestination(destination);
}
/**
* sets the distener for the directions overlay
* @param listener
* @author ricky barrette
*/
public void setLocationSelectedListener(LocationSelectedListener listener){
public void setDirectionsCompleteListener(OnDirectionsCompleteListener listener){
mDirectionsCompleteListener = listener;
}
/**
* @param listener
* @author ricky barrette
*/
public void setLocationSelectedListener(OnLocationSelectedListener listener){
mLocationSelectedListener = listener;
}

View File

@@ -21,6 +21,8 @@
*/
package com.TwentyCodes.android.IOIOTruck;
import java.util.ArrayList;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
@@ -42,7 +44,10 @@ import com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListene
import com.TwentyCodes.android.location.CompassListener;
import com.TwentyCodes.android.location.GeoPointLocationListener;
import com.TwentyCodes.android.location.GeoUtils;
import com.TwentyCodes.android.location.LocationSelectedListener;
import com.TwentyCodes.android.location.OnLocationSelectedListener;
import com.TwentyCodes.android.overlays.DirectionsOverlay;
import com.TwentyCodes.android.overlays.DirectionsOverlay.OnDirectionsCompleteListener;
import com.TwentyCodes.android.overlays.PathOverlay;
import com.google.android.maps.GeoPoint;
@@ -57,7 +62,7 @@ import com.google.android.maps.GeoPoint;
* + drive the truck forward or reverse to best navigate to the selected point
* @author ricky barrette
*/
public class NavigationActivity extends FragmentActivity implements CompassListener, GeoPointLocationListener, LocationSelectedListener, OnClickListener, OnCheckedChangeListener, IOIOTruckThreadListener {
public class NavigationActivity extends FragmentActivity implements CompassListener, GeoPointLocationListener, OnLocationSelectedListener, OnClickListener, OnCheckedChangeListener, IOIOTruckThreadListener, OnDirectionsCompleteListener {
private static final String TAG = "NavigationActivity";
private IOIOTruckManager mIOIOManager;
@@ -79,6 +84,9 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
private long mLast;
private WakeLock mWakeLock;
private int mCount;
private ArrayList<GeoPoint> mPoints;
private int mIndex = 0;
private GeoPoint mDestPoint;
/**
* This thread will be used to update all the informational displays
@@ -106,6 +114,8 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
+"\nSteering: "+mIOIOManager.getSteerValue()
+"\nBearing: "+mBearing
+"\nisRunning: "+isRunning);
if(mPoints != null)
updateLog("Point = "+mIndex +" of "+ mPoints.size());
updateLastUpdateTextView();
@@ -282,19 +292,35 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
mDistance = updateProgress(point);
/*
* here we will update the progress bar
*
* if we have a destination, check to see if we are there yet
*/
if(mPoint != null)
if(GeoUtils.isIntersecting(point, (float) (accuracy / 1E3), mPoint, Debug.RADIUS, Debug.FUDGE_FACTOR)) {
mCount++;
/*
* if we get 5 positives, we are at our waypoint/dest
*/
if(mCount > 5){
Log.v(TAG, "Dest Reached, Stopping");
mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP);
updateGoButton(true);
updateLog(R.string.dest_reached);
/*
* if ther points list is null, or there are no more points
*/
if(mPoints == null || mIndex == mPoints.size()+1){
mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP);
updateGoButton(true);
updateLog(R.string.dest_reached);
} else {
mIndex ++;
if(mIndex <= mPoints.size()+1) {
updateLog("last Waypoint reached, moving to dest");
mPoint = mPoints.get(mIndex);
} else {
updateLog("Waypoint reached, moving to next");
mPoint = mDestPoint;
}
}
}
} else {
Log.v(TAG, "Driving Forward");
@@ -315,9 +341,11 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
*/
@Override
public void onLocationSelected(GeoPoint point) {
mPoint = point;
mDestPoint = point;
mDistance = updateProgress(mMap.getUserLocation());
updateLog(getString(R.string.point_selected)+point.toString());
mIndex = 0;
mCount = 0;
}
/**
@@ -353,7 +381,9 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
mMap.setCompassListener(this);
mMap.setGeoPointLocationListener(this);
mMap.setLocationSelectedListener(this);
mMap.setDirectionsCompleteListener(this);
mMap.setRadius((int) (Debug.RADIUS * 1E3));
mMap.enableGPSProgess();
mIOIOManager = new IOIOTruckManager(this, this);
mIOIOManager.start();
@@ -422,4 +452,24 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
updateLog(log);
}
/**
* called when the directions overlay is generated
* (non-Javadoc)
* @see com.TwentyCodes.android.overlays.DirectionsOverlay.OnDirectionsCompleteListener#onDirectionsComplete(com.TwentyCodes.android.overlays.DirectionsOverlay)
*/
@Override
public void onDirectionsComplete(DirectionsOverlay directionsOverlay) {
ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();
for(PathOverlay item : directionsOverlay.getPath())
if(item.getEndPoint() != null)
points.add(item.getEndPoint());
mPoints = points;
mPoint = points.get(points.size()-1);
}
@Override
public void onFirstFix(boolean isFirstFix) {
mMap.disableGPSProgess();
}
}