diff --git a/IOIOTruck/assets/exceptionhandler.properties b/IOIOTruck/assets/exceptionhandler.properties index 910dadd..0d0db1f 100644 --- a/IOIOTruck/assets/exceptionhandler.properties +++ b/IOIOTruck/assets/exceptionhandler.properties @@ -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 diff --git a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/Main.java b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/Main.java index b2e4c43..bab5fa8 100644 --- a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/Main.java +++ b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/Main.java @@ -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); diff --git a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java index 3102058..8c4fc63 100644 --- a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java +++ b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java @@ -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) @@ -73,7 +96,7 @@ public class MapFragment extends UserOverlayMapFragment implements LocationSelec } else if(Debug.DEBUG) Log.d(TAG, "onLocationSelected() Location was null"); } - + /** * (non-Javadoc) * @see com.TwentyCodes.android.location.UserOverlayMapFragment#onMapViewCreate(com.TwentyCodes.android.location.MapView) @@ -88,13 +111,55 @@ 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){ - mLocationSelectedListener = listener; + public void setDirectionsCompleteListener(OnDirectionsCompleteListener listener){ + mDirectionsCompleteListener = listener; } + /** + * @param listener + * @author ricky barrette + */ + public void setLocationSelectedListener(OnLocationSelectedListener listener){ + mLocationSelectedListener = listener; + } + /** * @param radius meters * @author ricky barrette diff --git a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java index f93e211..74fc20f 100644 --- a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java +++ b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java @@ -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 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(); @@ -421,5 +451,25 @@ public class NavigationActivity extends FragmentActivity implements CompassListe public void onLogUpdate(String log) { 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 points = new ArrayList(); + 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(); + } } \ No newline at end of file