Preparing to further isolate non-UI code from map drawing.

This commit is contained in:
Rodrigo Damazio
2010-09-22 22:10:36 -03:00
parent 2cb3963138
commit c6512f1376
@@ -70,8 +70,8 @@ import android.widget.Toast;
* @author Leif Hendrik Wilden * @author Leif Hendrik Wilden
*/ */
public class MyTracksMap extends MapActivity public class MyTracksMap extends MapActivity
implements LocationListener, SensorEventListener, View.OnTouchListener, implements View.OnTouchListener, View.OnClickListener,
View.OnClickListener, SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener {
private static final int TRACKPOINT_BUFFER_SIZE = 1024; private static final int TRACKPOINT_BUFFER_SIZE = 1024;
// Saved instance state keys: // Saved instance state keys:
@@ -532,10 +532,10 @@ public class MyTracksMap extends MapActivity
+ gpsProvider.getName()); + gpsProvider.getName());
} }
locationManager.requestLocationUpdates(gpsProvider.getName(), locationManager.requestLocationUpdates(gpsProvider.getName(),
0 /*minTime*/, 0 /*minDist*/, this); 0 /*minTime*/, 0 /*minDist*/, locationListener);
try { try {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
1000 * 60 * 5 /*minTime*/, 0 /*minDist*/, this); 1000 * 60 * 5 /*minTime*/, 0 /*minDist*/, locationListener);
} catch (RuntimeException e) { } catch (RuntimeException e) {
// If anything at all goes wrong with getting a cell location do not // If anything at all goes wrong with getting a cell location do not
// abort. Cell location is not essential to this app. // abort. Cell location is not essential to this app.
@@ -553,7 +553,7 @@ public class MyTracksMap extends MapActivity
Log.d(MyTracksConstants.TAG, Log.d(MyTracksConstants.TAG,
"MyTracksMap: Now registering sensor listeners."); "MyTracksMap: Now registering sensor listeners.");
sensorManager.registerListener( sensorManager.registerListener(
this, compass, SensorManager.SENSOR_DELAY_UI); sensorListener, compass, SensorManager.SENSOR_DELAY_UI);
} }
/** /**
@@ -563,12 +563,12 @@ public class MyTracksMap extends MapActivity
if (locationManager != null) { if (locationManager != null) {
Log.d(MyTracksConstants.TAG, Log.d(MyTracksConstants.TAG,
"MyTracksMap: Now unregistering location listeners."); "MyTracksMap: Now unregistering location listeners.");
locationManager.removeUpdates(this); locationManager.removeUpdates(locationListener);
} }
if (sensorManager != null) { if (sensorManager != null) {
Log.d(MyTracksConstants.TAG, Log.d(MyTracksConstants.TAG,
"MyTracksMap: Now unregistering sensor listeners."); "MyTracksMap: Now unregistering sensor listeners.");
sensorManager.unregisterListener(this); sensorManager.unregisterListener(sensorListener);
} }
} }
@@ -881,8 +881,7 @@ public class MyTracksMap extends MapActivity
public void onClick(View v) { public void onClick(View v) {
if (v == messagePane) { if (v == messagePane) {
launchMyLocationSettings(); launchMyLocationSettings();
} } else if (v == optionsBtn) {
if (v == optionsBtn) {
optionsBtn.performLongClick(); optionsBtn.performLongClick();
} }
} }
@@ -934,6 +933,7 @@ public class MyTracksMap extends MapActivity
} }
} }
private final LocationListener locationListener = new LocationListener() {
@Override @Override
public void onProviderEnabled(String provider) { public void onProviderEnabled(String provider) {
if (provider.equals(MyTracksConstants.GPS_PROVIDER)) { if (provider.equals(MyTracksConstants.GPS_PROVIDER)) {
@@ -946,7 +946,7 @@ public class MyTracksMap extends MapActivity
if (provider.equals(MyTracksConstants.GPS_PROVIDER)) { if (provider.equals(MyTracksConstants.GPS_PROVIDER)) {
messageText.setText(R.string.status_enable_gps); messageText.setText(R.string.status_enable_gps);
messagePane.setVisibility(View.VISIBLE); messagePane.setVisibility(View.VISIBLE);
messagePane.setOnClickListener(this); messagePane.setOnClickListener(MyTracksMap.this);
screen.requestLayout(); screen.requestLayout();
} }
} }
@@ -987,7 +987,9 @@ public class MyTracksMap extends MapActivity
} }
} }
} }
};
private final SensorEventListener sensorListener = new SensorEventListener() {
@Override @Override
public void onSensorChanged(SensorEvent se) { public void onSensorChanged(SensorEvent se) {
synchronized (this) { synchronized (this) {
@@ -1003,6 +1005,7 @@ public class MyTracksMap extends MapActivity
public void onAccuracyChanged(Sensor s, int accuracy) { public void onAccuracyChanged(Sensor s, int accuracy) {
// do nothing // do nothing
} }
};
private void readAllNewTrackPoints() { private void readAllNewTrackPoints() {
int numPoints = mapOverlay.getNumLocations(); int numPoints = mapOverlay.getNumLocations();