Skip to content

Commit 75fabeb

Browse files
committed
Merge pull request #741 from garvankeeley/amend727
Amendment to 727, track locations when the activity is not showing.
2 parents 8992e1c + f0e3c81 commit 75fabeb

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

src/org/mozilla/mozstumbler/client/MainApp.java

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.mozilla.mozstumbler.BuildConfig;
2121
import org.mozilla.mozstumbler.R;
2222
import org.mozilla.mozstumbler.client.cellscanner.DefaultCellScanner;
23+
import org.mozilla.mozstumbler.client.mapview.MapActivity;
2324
import org.mozilla.mozstumbler.service.AppGlobals;
2425
import org.mozilla.mozstumbler.service.Prefs;
2526
import org.mozilla.mozstumbler.service.StumblerService;
@@ -88,6 +89,9 @@ public void onServiceConnected(ComponentName className, IBinder binder) {
8889

8990
AppGlobals.dataStorageManager.setMaxStorageOnDisk(MAX_BYTES_DISK_STORAGE);
9091
AppGlobals.dataStorageManager.setMaxWeeksStored(MAX_WEEKS_OLD_STORED);
92+
93+
MapActivity.createGpsTrackLocationReceiver(MainApp.this);
94+
9195
Log.d(LOGTAG, "Service connected");
9296
if (mMainActivity != null) {
9397
mMainActivity.updateUiOnMainThread();

src/org/mozilla/mozstumbler/client/mapview/MapActivity.java

+34-12
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ public final class MapActivity extends Activity {
6666
private static final String LON_KEY = "longitude";
6767
private static final String LOCATIONS_KEY = "locations";
6868

69-
private final ArrayList<GeoPoint> mLocations = new ArrayList<GeoPoint>();
70-
7169
private MapView mMap;
7270
private PathOverlay mPathOverlay;
7371
private AccuracyCircleOverlay mAccuracyOverlay;
@@ -77,6 +75,34 @@ public final class MapActivity extends Activity {
7775
Timer mGetUrl = new Timer();
7876
TilesOverlay mCoverageTilesOverlay = null;
7977

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+
80106
private class ReporterBroadcastReceiver extends BroadcastReceiver {
81107
public void reset()
82108
{
@@ -119,6 +145,7 @@ protected void onCreate(Bundle savedInstanceState) {
119145
sGPSColor = getResources().getColor(R.color.gps_track);
120146
mPathOverlay = new PathOverlay(sGPSColor, this);
121147
mMap.getOverlays().add(mPathOverlay);
148+
mPathOverlay.getPaint().setStrokeWidth(8.0f);
122149

123150
mFirstLocationFix = true;
124151
int zoomLevel = DEFAULT_ZOOM; // Default to seeing the world, until we get a fix
@@ -130,21 +157,17 @@ protected void onCreate(Bundle savedInstanceState) {
130157
final double longitude = savedInstanceState.getDouble(LON_KEY);
131158
mMap.getController().setCenter(new GeoPoint(latitude, longitude));
132159
}
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-
}
141160
} else {
142161
final StumblerService service = ((MainApp) getApplication()).getService();
143162
final GeoPoint lastLoc = new GeoPoint(service.getLatitude(), service.getLongitude());
144163
mMap.getController().setCenter(lastLoc);
145164
}
146165
mMap.getController().setZoom(zoomLevel);
147166

167+
for (GeoPoint p : sGpsTrackLocationReceiver.mLocations) {
168+
mPathOverlay.addPoint(p);
169+
}
170+
148171
Log.d(LOGTAG, "onCreate");
149172

150173
// @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) {
344367
bundle.putInt(ZOOM_KEY, mMap.getZoomLevel());
345368
bundle.putDouble(LON_KEY, mMap.getMapCenter().getLongitude());
346369
bundle.putDouble(LAT_KEY, mMap.getMapCenter().getLatitude());
347-
bundle.putParcelableArrayList(LOCATIONS_KEY, mLocations);
348370
}
349371

350372
@Override
@@ -374,6 +396,7 @@ private void updateUI(StumblerService service) {
374396
service.getAPCount());
375397
}
376398

399+
377400
private final class GetLocationAndMapItTask extends AsyncTask<StumblerService, Void, Location> {
378401
@Override
379402
public Location doInBackground(StumblerService... params) {
@@ -387,7 +410,6 @@ public Location doInBackground(StumblerService... params) {
387410
final double longitude = result.getLongitude();
388411
if (Math.abs(latitude) >= 0.01 && Math.abs(longitude) >= 0.01) {
389412
final GeoPoint point = new GeoPoint(result.getLatitude(), result.getLongitude());
390-
mLocations.add(point);
391413
mPathOverlay.addPoint(point);
392414
}
393415
return result;

0 commit comments

Comments
 (0)