Added waypoint dots to drawn path (overlay)
added a calls to set the compass's dest point when directions are generated, and when a waypoint is changed. refactored NavigationActivity (sorted) Change-Id: Ibbb0a5651a12b00dcce4b3973609adf1c1648632 Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -45,12 +45,9 @@ import com.google.android.maps.GeoPoint;
|
||||
public class MapFragment extends UserOverlayMapFragment implements OnLocationSelectedListener, OnDirectionsCompleteListener {
|
||||
|
||||
private final String TAG = "MapFragment";
|
||||
|
||||
private RadiusOverlay mRadiusOverlay;
|
||||
private OnLocationSelectedListener mLocationSelectedListener;
|
||||
|
||||
private OnDirectionsCompleteListener mDirectionsCompleteListener;
|
||||
|
||||
private DirectionsOverlay mDirectionsOverlay;
|
||||
|
||||
/**
|
||||
@@ -81,6 +78,8 @@ public class MapFragment extends UserOverlayMapFragment implements OnLocationSel
|
||||
@Override
|
||||
public void onLocationSelected(GeoPoint point) {
|
||||
|
||||
removePath();
|
||||
|
||||
setDestination(point);
|
||||
|
||||
if(mLocationSelectedListener != null)
|
||||
@@ -110,15 +109,21 @@ public class MapFragment extends UserOverlayMapFragment implements OnLocationSel
|
||||
super.onMapViewCreate(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the path if displayed
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void removePath(){
|
||||
if(mDirectionsOverlay != null)
|
||||
mDirectionsOverlay.removePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* (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();
|
||||
|
||||
public void setDestination(final GeoPoint destination) {
|
||||
if(mDirectionsCompleteListener != null)
|
||||
new Thread( new Runnable(){
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@ 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;
|
||||
@@ -64,30 +65,6 @@ import com.google.android.maps.GeoPoint;
|
||||
*/
|
||||
public class NavigationActivity extends FragmentActivity implements CompassListener, GeoPointLocationListener, OnLocationSelectedListener, OnClickListener, OnCheckedChangeListener, IOIOTruckThreadListener, OnDirectionsCompleteListener {
|
||||
|
||||
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;
|
||||
private ArrayList<GeoPoint> mPoints;
|
||||
private int mIndex = 0;
|
||||
private GeoPoint mDestPoint;
|
||||
|
||||
/**
|
||||
* This thread will be used to update all the informational displays
|
||||
* @author ricky barrette
|
||||
@@ -143,6 +120,29 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
private ArrayList<GeoPoint> mPoints;
|
||||
private int mIndex = 0;
|
||||
private GeoPoint mDestPoint;
|
||||
private ArrayList<PathOverlay> mWayPoints;
|
||||
|
||||
/**
|
||||
* Called when the scrolling switch is checked
|
||||
@@ -191,44 +191,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)
|
||||
@@ -249,7 +211,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
||||
|
||||
mBearing = bearing;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
|
||||
@@ -278,6 +240,39 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
||||
findViewById(R.id.my_location_button).setOnClickListener(this);
|
||||
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;
|
||||
mPoint = points.get(0);
|
||||
mMap.setDestination(mPoint);
|
||||
mWayPoints.add(new PathOverlay(mPoint, 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
|
||||
@@ -313,13 +308,18 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
||||
} else {
|
||||
mIndex ++;
|
||||
|
||||
if(mIndex <= mPoints.size()+1) {
|
||||
if(mIndex <= mPoints.size()) {
|
||||
updateLog("last Waypoint reached, moving to dest");
|
||||
mPoint = mPoints.get(mIndex);
|
||||
} else {
|
||||
updateLog("Waypoint reached, moving to next");
|
||||
mPoint = mDestPoint;
|
||||
}
|
||||
|
||||
/*
|
||||
* we have to notify the compass that the point has changed
|
||||
*/
|
||||
mMap.setDestination(mPoint);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -341,6 +341,8 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
||||
*/
|
||||
@Override
|
||||
public void onLocationSelected(GeoPoint point) {
|
||||
if(mWayPoints != null)
|
||||
mMap.getMap().getOverlays().removeAll(mWayPoints);
|
||||
mDestPoint = point;
|
||||
mDistance = updateProgress(mMap.getUserLocation());
|
||||
updateLog(getString(R.string.point_selected)+point.toString());
|
||||
@@ -348,6 +350,16 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the application is paused. We want to disconnect with the
|
||||
* IOIO at this point, as the user is no longer interacting with our
|
||||
@@ -369,7 +381,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
||||
mWakeLock.release();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see android.support.v4.app.FragmentActivity#onResume()
|
||||
@@ -391,7 +403,45 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
||||
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
|
||||
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
|
||||
@@ -441,35 +491,5 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user