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 {
|
public class MapFragment extends UserOverlayMapFragment implements OnLocationSelectedListener, OnDirectionsCompleteListener {
|
||||||
|
|
||||||
private final String TAG = "MapFragment";
|
private final String TAG = "MapFragment";
|
||||||
|
|
||||||
private RadiusOverlay mRadiusOverlay;
|
private RadiusOverlay mRadiusOverlay;
|
||||||
private OnLocationSelectedListener mLocationSelectedListener;
|
private OnLocationSelectedListener mLocationSelectedListener;
|
||||||
|
|
||||||
private OnDirectionsCompleteListener mDirectionsCompleteListener;
|
private OnDirectionsCompleteListener mDirectionsCompleteListener;
|
||||||
|
|
||||||
private DirectionsOverlay mDirectionsOverlay;
|
private DirectionsOverlay mDirectionsOverlay;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,6 +78,8 @@ public class MapFragment extends UserOverlayMapFragment implements OnLocationSel
|
|||||||
@Override
|
@Override
|
||||||
public void onLocationSelected(GeoPoint point) {
|
public void onLocationSelected(GeoPoint point) {
|
||||||
|
|
||||||
|
removePath();
|
||||||
|
|
||||||
setDestination(point);
|
setDestination(point);
|
||||||
|
|
||||||
if(mLocationSelectedListener != null)
|
if(mLocationSelectedListener != null)
|
||||||
@@ -110,15 +109,21 @@ public class MapFragment extends UserOverlayMapFragment implements OnLocationSel
|
|||||||
super.onMapViewCreate(map);
|
super.onMapViewCreate(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the path if displayed
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public void removePath(){
|
||||||
|
if(mDirectionsOverlay != null)
|
||||||
|
mDirectionsOverlay.removePath();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see com.TwentyCodes.android.fragments.UserOverlayMapFragment#setDestination(com.google.android.maps.GeoPoint)
|
* @see com.TwentyCodes.android.fragments.UserOverlayMapFragment#setDestination(com.google.android.maps.GeoPoint)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setDestination(final GeoPoint destination) {
|
public void setDestination(final GeoPoint destination) {
|
||||||
if(mDirectionsOverlay != null)
|
|
||||||
mDirectionsOverlay.removePath();
|
|
||||||
|
|
||||||
if(mDirectionsCompleteListener != null)
|
if(mDirectionsCompleteListener != null)
|
||||||
new Thread( new Runnable(){
|
new Thread( new Runnable(){
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ package com.TwentyCodes.android.IOIOTruck;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.PowerManager.WakeLock;
|
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 {
|
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
|
* This thread will be used to update all the informational displays
|
||||||
* @author ricky barrette
|
* @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
|
* 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
|
* Called when there is an update from the compass
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
@@ -279,6 +241,39 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
findViewById(R.id.map_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
|
* Called when android's location services have an update
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
@@ -313,13 +308,18 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
} else {
|
} else {
|
||||||
mIndex ++;
|
mIndex ++;
|
||||||
|
|
||||||
if(mIndex <= mPoints.size()+1) {
|
if(mIndex <= mPoints.size()) {
|
||||||
updateLog("last Waypoint reached, moving to dest");
|
updateLog("last Waypoint reached, moving to dest");
|
||||||
mPoint = mPoints.get(mIndex);
|
mPoint = mPoints.get(mIndex);
|
||||||
} else {
|
} else {
|
||||||
updateLog("Waypoint reached, moving to next");
|
updateLog("Waypoint reached, moving to next");
|
||||||
mPoint = mDestPoint;
|
mPoint = mDestPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we have to notify the compass that the point has changed
|
||||||
|
*/
|
||||||
|
mMap.setDestination(mPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -341,6 +341,8 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onLocationSelected(GeoPoint point) {
|
public void onLocationSelected(GeoPoint point) {
|
||||||
|
if(mWayPoints != null)
|
||||||
|
mMap.getMap().getOverlays().removeAll(mWayPoints);
|
||||||
mDestPoint = point;
|
mDestPoint = point;
|
||||||
mDistance = updateProgress(mMap.getUserLocation());
|
mDistance = updateProgress(mMap.getUserLocation());
|
||||||
updateLog(getString(R.string.point_selected)+point.toString());
|
updateLog(getString(R.string.point_selected)+point.toString());
|
||||||
@@ -348,6 +350,16 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
mCount = 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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the application is paused. We want to disconnect with the
|
* 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
|
* IOIO at this point, as the user is no longer interacting with our
|
||||||
@@ -392,6 +404,44 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
mWakeLock.acquire();
|
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
|
* updates the log with the provided string res
|
||||||
* thread safe
|
* thread safe
|
||||||
@@ -442,34 +492,4 @@ public class NavigationActivity extends FragmentActivity implements CompassListe
|
|||||||
return 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