@@ -66,8 +66,6 @@ public final class MapActivity extends Activity {
66
66
private static final String LON_KEY = "longitude" ;
67
67
private static final String LOCATIONS_KEY = "locations" ;
68
68
69
- private final ArrayList <GeoPoint > mLocations = new ArrayList <GeoPoint >();
70
-
71
69
private MapView mMap ;
72
70
private PathOverlay mPathOverlay ;
73
71
private AccuracyCircleOverlay mAccuracyOverlay ;
@@ -77,6 +75,34 @@ public final class MapActivity extends Activity {
77
75
Timer mGetUrl = new Timer ();
78
76
TilesOverlay mCoverageTilesOverlay = null ;
79
77
78
+ static GpsTrackLocationReceiver sGpsTrackLocationReceiver ;
79
+
80
+ public static void createGpsTrackLocationReceiver (Context context ) {
81
+ sGpsTrackLocationReceiver = new GpsTrackLocationReceiver ();
82
+ LocalBroadcastManager .getInstance (context ).registerReceiver (sGpsTrackLocationReceiver , new IntentFilter (GPSScanner .ACTION_GPS_UPDATED ));
83
+ Log .d (LOGTAG , "Received location" );
84
+ }
85
+
86
+ // Create in MainApp, used to grab locations at all times, for drawing the GPS track on the map
87
+ // The location list stored here is only used in MapActivity onCreate to bootstrap the mPathOverlay
88
+ public static class GpsTrackLocationReceiver extends BroadcastReceiver {
89
+ ArrayList <GeoPoint > mLocations = new ArrayList <GeoPoint >();
90
+
91
+ @ Override
92
+ public void onReceive (Context context , Intent intent ) {
93
+ String action = intent .getAction ();
94
+ String subject = intent .getStringExtra (Intent .EXTRA_SUBJECT );
95
+ assert (action .equals (GPSScanner .ACTION_GPS_UPDATED ));
96
+ if (!subject .equals (GPSScanner .SUBJECT_NEW_LOCATION ))
97
+ return ;
98
+
99
+ Location newPosition = intent .getParcelableExtra (GPSScanner .NEW_LOCATION_ARG_LOCATION );
100
+ if (newPosition != null ) {
101
+ mLocations .add (new GeoPoint (newPosition ));
102
+ }
103
+ }
104
+ }
105
+
80
106
private class ReporterBroadcastReceiver extends BroadcastReceiver {
81
107
public void reset ()
82
108
{
@@ -119,6 +145,7 @@ protected void onCreate(Bundle savedInstanceState) {
119
145
sGPSColor = getResources ().getColor (R .color .gps_track );
120
146
mPathOverlay = new PathOverlay (sGPSColor , this );
121
147
mMap .getOverlays ().add (mPathOverlay );
148
+ mPathOverlay .getPaint ().setStrokeWidth (8.0f );
122
149
123
150
mFirstLocationFix = true ;
124
151
int zoomLevel = DEFAULT_ZOOM ; // Default to seeing the world, until we get a fix
@@ -130,21 +157,17 @@ protected void onCreate(Bundle savedInstanceState) {
130
157
final double longitude = savedInstanceState .getDouble (LON_KEY );
131
158
mMap .getController ().setCenter (new GeoPoint (latitude , longitude ));
132
159
}
133
- if (savedInstanceState .containsKey (LOCATIONS_KEY )) {
134
- final List <GeoPoint > prevLocations = savedInstanceState .getParcelableArrayList (LOCATIONS_KEY );
135
- mLocations .clear ();
136
- mLocations .addAll (prevLocations );
137
- for (GeoPoint p : prevLocations ) {
138
- mPathOverlay .addPoint (p );
139
- }
140
- }
141
160
} else {
142
161
final StumblerService service = ((MainApp ) getApplication ()).getService ();
143
162
final GeoPoint lastLoc = new GeoPoint (service .getLatitude (), service .getLongitude ());
144
163
mMap .getController ().setCenter (lastLoc );
145
164
}
146
165
mMap .getController ().setZoom (zoomLevel );
147
166
167
+ for (GeoPoint p : sGpsTrackLocationReceiver .mLocations ) {
168
+ mPathOverlay .addPoint (p );
169
+ }
170
+
148
171
Log .d (LOGTAG , "onCreate" );
149
172
150
173
// @TODO: we do a similar "read from URL" in Updater, AbstractCommunicator, make one function for this
@@ -344,7 +367,6 @@ protected void onSaveInstanceState(Bundle bundle) {
344
367
bundle .putInt (ZOOM_KEY , mMap .getZoomLevel ());
345
368
bundle .putDouble (LON_KEY , mMap .getMapCenter ().getLongitude ());
346
369
bundle .putDouble (LAT_KEY , mMap .getMapCenter ().getLatitude ());
347
- bundle .putParcelableArrayList (LOCATIONS_KEY , mLocations );
348
370
}
349
371
350
372
@ Override
@@ -374,6 +396,7 @@ private void updateUI(StumblerService service) {
374
396
service .getAPCount ());
375
397
}
376
398
399
+
377
400
private final class GetLocationAndMapItTask extends AsyncTask <StumblerService , Void , Location > {
378
401
@ Override
379
402
public Location doInBackground (StumblerService ... params ) {
@@ -387,7 +410,6 @@ public Location doInBackground(StumblerService... params) {
387
410
final double longitude = result .getLongitude ();
388
411
if (Math .abs (latitude ) >= 0.01 && Math .abs (longitude ) >= 0.01 ) {
389
412
final GeoPoint point = new GeoPoint (result .getLatitude (), result .getLongitude ());
390
- mLocations .add (point );
391
413
mPathOverlay .addPoint (point );
392
414
}
393
415
return result ;
0 commit comments