|
|
|
|
@@ -21,7 +21,10 @@
|
|
|
|
|
*/
|
|
|
|
|
package com.TwentyCodes.android.IOIOTruck;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.PowerManager;
|
|
|
|
|
import android.os.PowerManager.WakeLock;
|
|
|
|
|
@@ -43,6 +46,9 @@ import com.TwentyCodes.android.location.CompassListener;
|
|
|
|
|
import com.TwentyCodes.android.location.GeoPointLocationListener;
|
|
|
|
|
import com.TwentyCodes.android.location.GeoUtils;
|
|
|
|
|
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,28 +63,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, OnLocationSelectedListener, OnClickListener, OnCheckedChangeListener, IOIOTruckThreadListener {
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "NavigationActivity";
|
|
|
|
|
private IOIOTruckManager mIOIOManager;
|
|
|
|
|
private MapFragment mMap;
|
|
|
|
|
private TextView mLog;
|
|
|
|
|
private GeoPoint mPoint;
|
|
|
|
|
private ProgressBar mProgress;
|
|
|
|
|
private int mMaxDistance = 0; //meters
|
|
|
|
|
private boolean isRunning = false;
|
|
|
|
|
private Button mGoButton;
|
|
|
|
|
private float mBearing;
|
|
|
|
|
private ScrollView mScrollView;
|
|
|
|
|
|
|
|
|
|
private boolean isScrollingEnabled = true;
|
|
|
|
|
private int mDistance;
|
|
|
|
|
private LogUpdater mLoggerThread;
|
|
|
|
|
private TextView mAccuracyTextView;
|
|
|
|
|
private TextView mLastUpdateTextView;
|
|
|
|
|
private long mLast;
|
|
|
|
|
private WakeLock mWakeLock;
|
|
|
|
|
private int mCount;
|
|
|
|
|
public class NavigationActivity extends FragmentActivity implements CompassListener, GeoPointLocationListener, OnLocationSelectedListener, OnClickListener, OnCheckedChangeListener, IOIOTruckThreadListener, OnDirectionsCompleteListener {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This thread will be used to update all the informational displays
|
|
|
|
|
@@ -92,23 +77,21 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|
|
|
|
* aborts the thread
|
|
|
|
|
* @author ricky barrette
|
|
|
|
|
*/
|
|
|
|
|
public void abort() {
|
|
|
|
|
public synchronized void abort() {
|
|
|
|
|
isAborted = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run(){
|
|
|
|
|
while (true) {
|
|
|
|
|
if (isAborted)
|
|
|
|
|
break;
|
|
|
|
|
while (!isAborted) {
|
|
|
|
|
updateLog("\nDistance: "+ mDistance +getString(R.string.m)
|
|
|
|
|
+"\nDrive: "+mIOIOManager.getDriveValue()
|
|
|
|
|
+"\nSteering: "+mIOIOManager.getSteerValue()
|
|
|
|
|
+"\nBearing: "+mBearing
|
|
|
|
|
+"\nisRunning: "+isRunning);
|
|
|
|
|
|
|
|
|
|
updateLastUpdateTextView();
|
|
|
|
|
|
|
|
|
|
if(mPoints != null)
|
|
|
|
|
updateLog("Point = "+mIndex +" of "+ mPoints.size());
|
|
|
|
|
updateLastUpdateTextView();
|
|
|
|
|
try {
|
|
|
|
|
sleep(1000);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
@@ -133,6 +116,27 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private static final String TAG = "NavigationActivity";
|
|
|
|
|
private IOIOTruckManager mIOIOManager;
|
|
|
|
|
private MapFragment mMap;
|
|
|
|
|
private TextView mLog;
|
|
|
|
|
private ProgressBar mProgress;
|
|
|
|
|
private boolean isRunning = false;
|
|
|
|
|
private Button mGoButton;
|
|
|
|
|
private float mBearing;
|
|
|
|
|
private ScrollView mScrollView;
|
|
|
|
|
private boolean isScrollingEnabled = true;
|
|
|
|
|
private int mDistance;
|
|
|
|
|
private LogUpdater mLoggerThread;
|
|
|
|
|
private TextView mAccuracyTextView;
|
|
|
|
|
private TextView mLastUpdateTextView;
|
|
|
|
|
private long mLast;
|
|
|
|
|
private WakeLock mWakeLock;
|
|
|
|
|
private int mCount = 0;
|
|
|
|
|
private ArrayList<GeoPoint> mPoints;
|
|
|
|
|
private int mIndex = 0;
|
|
|
|
|
private GeoPoint mDestPoint;
|
|
|
|
|
private ArrayList<PathOverlay> mWayPoints;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when the scrolling switch is checked
|
|
|
|
|
@@ -161,7 +165,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R.id.mark_my_lcoation_button:
|
|
|
|
|
GeoPoint point = mMap.getUserLocation();
|
|
|
|
|
final GeoPoint point = mMap.getUserLocation();
|
|
|
|
|
|
|
|
|
|
if(point != null){
|
|
|
|
|
mMap.onLocationSelected(point);
|
|
|
|
|
@@ -170,7 +174,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R.id.my_location_button:
|
|
|
|
|
GeoPoint user = mMap.getUserLocation();
|
|
|
|
|
final GeoPoint user = mMap.getUserLocation();
|
|
|
|
|
|
|
|
|
|
if(user != null){
|
|
|
|
|
mMap.setMapCenter(user);
|
|
|
|
|
@@ -181,44 +185,6 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* updates the go/stop button based on isRunning
|
|
|
|
|
* thread safe
|
|
|
|
|
* @author ricky barrette
|
|
|
|
|
*/
|
|
|
|
|
private void updateGoButton() {
|
|
|
|
|
updateGoButton(isRunning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the go/stop button to the provided value
|
|
|
|
|
* thread safe
|
|
|
|
|
* @param isRunnuing true = stop, false = go
|
|
|
|
|
* @author ricky barrette
|
|
|
|
|
*/
|
|
|
|
|
private void updateGoButton(final boolean isRun) {
|
|
|
|
|
mIOIOManager.setStatLedEnabled(!isRun);
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run(){
|
|
|
|
|
if(isRun){
|
|
|
|
|
mCount = 0;
|
|
|
|
|
mGoButton.setText(R.string.go);
|
|
|
|
|
isRunning = false;
|
|
|
|
|
updateLog(R.string.stop);
|
|
|
|
|
if(mLoggerThread != null)
|
|
|
|
|
mLoggerThread.abort();
|
|
|
|
|
} else {
|
|
|
|
|
mGoButton.setText(R.string.stop);
|
|
|
|
|
isRunning = true;
|
|
|
|
|
updateLog(R.string.go);
|
|
|
|
|
mLoggerThread = new LogUpdater();
|
|
|
|
|
mLoggerThread.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when there is an update from the compass
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
@@ -226,7 +192,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onCompassUpdate(float bearing) {
|
|
|
|
|
bearing = GeoUtils.calculateBearing(mMap.getUserLocation(), mPoint, bearing);
|
|
|
|
|
bearing = GeoUtils.calculateBearing(mMap.getUserLocation(), mMap.getDestination(), bearing);
|
|
|
|
|
|
|
|
|
|
if(bearing > 355 || bearing < 5)
|
|
|
|
|
mIOIOManager.setSteerValue(IOIOTruckValues.STEER_STRAIGHT);
|
|
|
|
|
@@ -269,40 +235,105 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|
|
|
|
findViewById(R.id.map_button).setOnClickListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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<PathOverlay> path = directionsOverlay.getPath();
|
|
|
|
|
|
|
|
|
|
if(path.size() > 0){
|
|
|
|
|
mWayPoints = new ArrayList<PathOverlay>();
|
|
|
|
|
ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();
|
|
|
|
|
points.add(path.get(0).getStartPoint());
|
|
|
|
|
for(PathOverlay item : path)
|
|
|
|
|
if(item.getEndPoint() != null) {
|
|
|
|
|
points.add(item.getEndPoint());
|
|
|
|
|
mWayPoints.add(new PathOverlay(item.getEndPoint(), 5, Color.GRAY));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mPoints = points;
|
|
|
|
|
mMap.setDestination(points.get(0));
|
|
|
|
|
mWayPoints.add(new PathOverlay(points.get(0), 5, Color.MAGENTA));
|
|
|
|
|
mMap.getMap().getOverlays().addAll(mWayPoints);
|
|
|
|
|
mWayPoints.addAll(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFirstFix(boolean isFirstFix) {
|
|
|
|
|
mMap.disableGPSProgess();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when android's location services have an update
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
* @see com.TwentyCodes.android.location.GeoPointLocationListener#onLocationChanged(com.google.android.maps.GeoPoint, int)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onLocationChanged(GeoPoint point, int accuracy) {
|
|
|
|
|
public synchronized void onLocationChanged(final GeoPoint point, final int accuracy) {
|
|
|
|
|
mLast = System.currentTimeMillis();
|
|
|
|
|
mAccuracyTextView.setText(accuracy+getString(R.string.m));
|
|
|
|
|
|
|
|
|
|
mDistance = updateProgress(point);
|
|
|
|
|
final GeoPoint currentDest = mMap.getDestination();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* here we will update the progress bar
|
|
|
|
|
*
|
|
|
|
|
* if we have a destination, check to see if we are there yet
|
|
|
|
|
* if we are then increment mCount
|
|
|
|
|
*/
|
|
|
|
|
if(mPoint != null)
|
|
|
|
|
if(GeoUtils.isIntersecting(point, (float) (accuracy / 1E3), mPoint, Debug.RADIUS, Debug.FUDGE_FACTOR)) {
|
|
|
|
|
if(point != null)
|
|
|
|
|
if(currentDest != null)
|
|
|
|
|
|
|
|
|
|
mCount++;
|
|
|
|
|
|
|
|
|
|
if(mCount > 5){
|
|
|
|
|
Log.v(TAG, "Dest Reached, Stopping");
|
|
|
|
|
mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP);
|
|
|
|
|
updateGoButton(true);
|
|
|
|
|
updateLog(R.string.dest_reached);
|
|
|
|
|
/*
|
|
|
|
|
* are we closer than 15 feet?
|
|
|
|
|
*/
|
|
|
|
|
if (GeoUtils.distanceKm(point, currentDest) < 0.009144) {
|
|
|
|
|
// if(GeoUtils.isIntersecting(point, (float) (accuracy / 1E3), currentDest, Debug.RADIUS, Debug.FUDGE_FACTOR)) {
|
|
|
|
|
updateLog("Count = "+ (++mCount));
|
|
|
|
|
/*
|
|
|
|
|
* if we get 6 positives, we are problay at our waypoint/dest
|
|
|
|
|
*/
|
|
|
|
|
if(mCount == 6){
|
|
|
|
|
|
|
|
|
|
mCount = 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* if the points list is null, or there are no more waypoints
|
|
|
|
|
*/
|
|
|
|
|
if(mPoints == null || mIndex == mPoints.size()){
|
|
|
|
|
mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP);
|
|
|
|
|
updateGoButton(true);
|
|
|
|
|
updateLog(R.string.dest_reached);
|
|
|
|
|
mMap.setDestination(null);
|
|
|
|
|
} else {
|
|
|
|
|
updateLog("Index = " + (++mIndex));
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* if there are more waypoints, then move on to the next
|
|
|
|
|
* otherwise move on to the dest
|
|
|
|
|
*/
|
|
|
|
|
if(mIndex < mPoints.size()) {
|
|
|
|
|
updateLog("Waypoint reached, moving to next");
|
|
|
|
|
mMap.setDestination(mPoints.get(mIndex));
|
|
|
|
|
} else {
|
|
|
|
|
updateLog("last Waypoint reached, moving to dest");
|
|
|
|
|
mMap.setDestination(mDestPoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateLog("New dest = "+ mMap.getDestination().toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
Log.v(TAG, "Driving Forward");
|
|
|
|
|
mCount = 0;
|
|
|
|
|
mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_FORWARD);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Log.v(TAG, "Driving Forward");
|
|
|
|
|
mCount = 0;
|
|
|
|
|
mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_FORWARD);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
Log.v(TAG, "Lost GPS signal, stopping");
|
|
|
|
|
else {
|
|
|
|
|
updateLog("Lost GPS signal (point was null), stopping");
|
|
|
|
|
mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -315,9 +346,23 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onLocationSelected(GeoPoint point) {
|
|
|
|
|
mPoint = point;
|
|
|
|
|
if(mWayPoints != null)
|
|
|
|
|
mMap.getMap().getOverlays().removeAll(mWayPoints);
|
|
|
|
|
mDestPoint = point;
|
|
|
|
|
mDistance = updateProgress(mMap.getUserLocation());
|
|
|
|
|
updateLog(getString(R.string.point_selected)+point.toString());
|
|
|
|
|
mIndex = 0;
|
|
|
|
|
mCount = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when the IOIOTruckThread has a log it wants to display
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
* @see com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener#onLogUpdate(java.lang.String)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onLogUpdate(String log) {
|
|
|
|
|
updateLog(log);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -353,7 +398,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();
|
|
|
|
|
|
|
|
|
|
@@ -362,6 +409,44 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|
|
|
|
mWakeLock.acquire();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* updates the go/stop button based on isRunning
|
|
|
|
|
* thread safe
|
|
|
|
|
* @author ricky barrette
|
|
|
|
|
*/
|
|
|
|
|
private void updateGoButton() {
|
|
|
|
|
updateGoButton(isRunning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the go/stop button to the provided value
|
|
|
|
|
* thread safe
|
|
|
|
|
* @param isRunnuing true = stop, false = go
|
|
|
|
|
* @author ricky barrette
|
|
|
|
|
*/
|
|
|
|
|
private void updateGoButton(final boolean isRun) {
|
|
|
|
|
mIOIOManager.setStatLedEnabled(!isRun);
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run(){
|
|
|
|
|
if(isRun){
|
|
|
|
|
mCount = 0;
|
|
|
|
|
mGoButton.setText(R.string.go);
|
|
|
|
|
isRunning = false;
|
|
|
|
|
updateLog(R.string.stop);
|
|
|
|
|
if(mLoggerThread != null)
|
|
|
|
|
mLoggerThread.abort();
|
|
|
|
|
} else {
|
|
|
|
|
mGoButton.setText(R.string.stop);
|
|
|
|
|
isRunning = true;
|
|
|
|
|
updateLog(R.string.go);
|
|
|
|
|
mLoggerThread = new LogUpdater();
|
|
|
|
|
mLoggerThread.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* updates the log with the provided string res
|
|
|
|
|
* thread safe
|
|
|
|
|
@@ -403,29 +488,10 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|
|
|
|
* @author ricky barrette
|
|
|
|
|
*/
|
|
|
|
|
private int updateProgress(GeoPoint point) {
|
|
|
|
|
int distance = (int) (GeoUtils.distanceKm(point, mPoint) * 1000);
|
|
|
|
|
if (distance > mMaxDistance) {
|
|
|
|
|
mMaxDistance = distance;
|
|
|
|
|
int distance = (int) (GeoUtils.distanceKm(point, mMap.getDestination()) * 1000);
|
|
|
|
|
if (distance > mProgress.getMax())
|
|
|
|
|
mProgress.setMax(distance);
|
|
|
|
|
}
|
|
|
|
|
mProgress.setProgress(distance);
|
|
|
|
|
return distance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when the IOIOTruckThread has a log it wants to display
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
* @see com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener#onLogUpdate(java.lang.String)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onLogUpdate(String log) {
|
|
|
|
|
updateLog(log);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFirstFix(boolean isFirstFix) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|