forked from upstream-mirrors/OpenTracks
Preparing to further isolate non-UI code from map drawing.
This commit is contained in:
@@ -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,75 +933,79 @@ public class MyTracksMap extends MapActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private final LocationListener locationListener = new LocationListener() {
|
||||||
public void onProviderEnabled(String provider) {
|
@Override
|
||||||
if (provider.equals(MyTracksConstants.GPS_PROVIDER)) {
|
public void onProviderEnabled(String provider) {
|
||||||
messageText.setText(R.string.wait_for_fix);
|
if (provider.equals(MyTracksConstants.GPS_PROVIDER)) {
|
||||||
}
|
messageText.setText(R.string.wait_for_fix);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProviderDisabled(String provider) {
|
|
||||||
if (provider.equals(MyTracksConstants.GPS_PROVIDER)) {
|
|
||||||
messageText.setText(R.string.status_enable_gps);
|
|
||||||
messagePane.setVisibility(View.VISIBLE);
|
|
||||||
messagePane.setOnClickListener(this);
|
|
||||||
screen.requestLayout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLocationChanged(Location location) {
|
|
||||||
if (location.getProvider().equals(MyTracksConstants.GPS_PROVIDER)) {
|
|
||||||
// Recalculate the variation if there was a jump in location > 1km:
|
|
||||||
if (currentLocation == null
|
|
||||||
|| location.distanceTo(currentLocation) > 1000) {
|
|
||||||
setVariation(location);
|
|
||||||
}
|
}
|
||||||
currentLocation = location;
|
}
|
||||||
boolean haveGoodFixNow =
|
|
||||||
currentLocation.getAccuracy() < minRequiredAccuracy;
|
@Override
|
||||||
if (haveGoodFixNow != haveGoodFix) {
|
public void onProviderDisabled(String provider) {
|
||||||
haveGoodFix = haveGoodFixNow;
|
if (provider.equals(MyTracksConstants.GPS_PROVIDER)) {
|
||||||
messagePane.setVisibility(haveGoodFix ? View.GONE : View.VISIBLE);
|
messageText.setText(R.string.status_enable_gps);
|
||||||
|
messagePane.setVisibility(View.VISIBLE);
|
||||||
|
messagePane.setOnClickListener(MyTracksMap.this);
|
||||||
screen.requestLayout();
|
screen.requestLayout();
|
||||||
}
|
}
|
||||||
showCurrentLocation();
|
|
||||||
} else {
|
|
||||||
Log.d(MyTracksConstants.TAG,
|
|
||||||
"MyTracksMap: Network location update received.");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
public void onLocationChanged(Location location) {
|
||||||
if (provider.equals(MyTracksConstants.GPS_PROVIDER)) {
|
if (location.getProvider().equals(MyTracksConstants.GPS_PROVIDER)) {
|
||||||
switch (status) {
|
// Recalculate the variation if there was a jump in location > 1km:
|
||||||
case LocationProvider.OUT_OF_SERVICE:
|
if (currentLocation == null
|
||||||
case LocationProvider.TEMPORARILY_UNAVAILABLE:
|
|| location.distanceTo(currentLocation) > 1000) {
|
||||||
haveGoodFix = false;
|
setVariation(location);
|
||||||
messagePane.setVisibility(View.VISIBLE);
|
}
|
||||||
|
currentLocation = location;
|
||||||
|
boolean haveGoodFixNow =
|
||||||
|
currentLocation.getAccuracy() < minRequiredAccuracy;
|
||||||
|
if (haveGoodFixNow != haveGoodFix) {
|
||||||
|
haveGoodFix = haveGoodFixNow;
|
||||||
|
messagePane.setVisibility(haveGoodFix ? View.GONE : View.VISIBLE);
|
||||||
screen.requestLayout();
|
screen.requestLayout();
|
||||||
break;
|
}
|
||||||
|
showCurrentLocation();
|
||||||
|
} else {
|
||||||
|
Log.d(MyTracksConstants.TAG,
|
||||||
|
"MyTracksMap: Network location update received.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSensorChanged(SensorEvent se) {
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||||
synchronized (this) {
|
if (provider.equals(MyTracksConstants.GPS_PROVIDER)) {
|
||||||
float magneticHeading = se.values[0];
|
switch (status) {
|
||||||
double heading = magneticHeading + variation;
|
case LocationProvider.OUT_OF_SERVICE:
|
||||||
if (mapOverlay.setHeading((float) heading)) {
|
case LocationProvider.TEMPORARILY_UNAVAILABLE:
|
||||||
mapView.invalidate();
|
haveGoodFix = false;
|
||||||
|
messagePane.setVisibility(View.VISIBLE);
|
||||||
|
screen.requestLayout();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
@Override
|
private final SensorEventListener sensorListener = new SensorEventListener() {
|
||||||
public void onAccuracyChanged(Sensor s, int accuracy) {
|
@Override
|
||||||
// do nothing
|
public void onSensorChanged(SensorEvent se) {
|
||||||
}
|
synchronized (this) {
|
||||||
|
float magneticHeading = se.values[0];
|
||||||
|
double heading = magneticHeading + variation;
|
||||||
|
if (mapOverlay.setHeading((float) heading)) {
|
||||||
|
mapView.invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccuracyChanged(Sensor s, int accuracy) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private void readAllNewTrackPoints() {
|
private void readAllNewTrackPoints() {
|
||||||
int numPoints = mapOverlay.getNumLocations();
|
int numPoints = mapOverlay.getNumLocations();
|
||||||
|
|||||||
Reference in New Issue
Block a user