aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-04-27 12:10:35 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-04-27 12:10:35 +0200
commit7f988b48aff7d6f1eb2dcd91b3004c1a12e727fc (patch)
treee25af0a85247d04b50fcc6b6ef7eff9b91d5bcbe /main
parent75a8a8d1c70b23a2867345043e36e850a6c16502 (diff)
downloadcgeo-7f988b48aff7d6f1eb2dcd91b3004c1a12e727fc.zip
cgeo-7f988b48aff7d6f1eb2dcd91b3004c1a12e727fc.tar.gz
cgeo-7f988b48aff7d6f1eb2dcd91b3004c1a12e727fc.tar.bz2
Use IGeoData to provide GPS enabled information on home screen
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/cgeo.java79
1 files changed, 28 insertions, 51 deletions
diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java
index 1d266e6..63200d6 100644
--- a/main/src/cgeo/geocaching/cgeo.java
+++ b/main/src/cgeo/geocaching/cgeo.java
@@ -10,6 +10,7 @@ import cgeo.geocaching.geopoint.HumanDistance;
import cgeo.geocaching.geopoint.IConversion;
import cgeo.geocaching.maps.CGeoMap;
import cgeo.geocaching.ui.Formatter;
+import cgeo.geocaching.utils.IObserver;
import cgeo.geocaching.utils.Log;
import org.apache.commons.collections.CollectionUtils;
@@ -27,7 +28,6 @@ import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.location.Address;
import android.location.Geocoder;
-import android.location.GpsStatus;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
@@ -69,7 +69,6 @@ public class cgeo extends AbstractActivity {
private LocationManager locationManager;
final private UpdateLocation locationUpdater = new UpdateLocation();
- private boolean gpsEnabled = false;
private Handler updateUserInfoHandler = new Handler() {
@@ -129,40 +128,40 @@ public class cgeo extends AbstractActivity {
}
};
- private class SatellitesHandler extends Handler {
+ private class SatellitesHandler extends Handler implements IObserver<IGeoData> {
- final private static int NO_GPS = 0;
- final private static int SATELLITES = 1;
+ private boolean gpsEnabled = false;
+ private int satellitesFixed = 0;
+ private int satellitesVisible = 0;
@Override
public void handleMessage(final Message msg) {
- String satellites = "";
- switch (msg.what) {
- case NO_GPS:
- satellites = res.getString(R.string.loc_gps_disabled);
- break;
- case SATELLITES:
- final int satellitesFixed = msg.arg1;
- final int satellitesVisible = msg.arg2;
- if (satellitesFixed > 0) {
- satellites = res.getString(R.string.loc_sat) + ": " + satellitesFixed + '/' + satellitesVisible;
- } else if (satellitesVisible >= 0) {
- satellites = res.getString(R.string.loc_sat) + ": 0/" + satellitesVisible;
- }
- break;
+ final IGeoData data = (IGeoData) msg.obj;
+ if (data.getGpsEnabled() == gpsEnabled &&
+ data.getSatellitesFixed() == satellitesFixed &&
+ data.getSatellitesVisible() == satellitesVisible) {
+ return;
}
- final TextView navSatellites = (TextView) findViewById(R.id.nav_satellites);
- navSatellites.setText(satellites);
- }
+ gpsEnabled = data.getGpsEnabled();
+ satellitesFixed = data.getSatellitesFixed();
+ satellitesVisible = data.getSatellitesVisible();
- public void noGps() {
- obtainMessage(NO_GPS).sendToTarget();
+ final TextView navSatellites = (TextView) findViewById(R.id.nav_satellites);
+ if (gpsEnabled) {
+ if (satellitesFixed > 0) {
+ navSatellites.setText(res.getString(R.string.loc_sat) + ": " + satellitesFixed + '/' + satellitesVisible);
+ } else if (satellitesVisible >= 0) {
+ navSatellites.setText(res.getString(R.string.loc_sat) + ": 0/" + satellitesVisible);
+ }
+ } else {
+ navSatellites.setText(res.getString(R.string.loc_gps_disabled));
+ }
}
- public void satellites(final int fixed, final int visible) {
- obtainMessage(SATELLITES, fixed, visible).sendToTarget();
+ @Override
+ public void update(final IGeoData data) {
+ obtainMessage(0, data).sendToTarget();
}
-
}
private SatellitesHandler satellitesHandler = new SatellitesHandler();
@@ -183,21 +182,6 @@ public class cgeo extends AbstractActivity {
}
};
- private final GpsStatus.Listener gpsListener = new GpsStatus.Listener() {
-
- @Override
- public void onGpsStatusChanged(int event) {
- if (event == GpsStatus.GPS_EVENT_STARTED && !gpsEnabled) {
- satellitesHandler.satellites(0, 0);
- gpsEnabled = true;
- } else if (event == GpsStatus.GPS_EVENT_STOPPED && gpsEnabled) {
- satellitesHandler.noGps();
- gpsEnabled = false;
- }
- }
-
- };
-
public cgeo() {
super("c:geo-main-screen");
}
@@ -257,8 +241,7 @@ public class cgeo extends AbstractActivity {
public void onResume() {
super.onResume();
app.addGeoObserver(locationUpdater);
- gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
- locationManager.addGpsStatusListener(gpsListener);
+ app.addGeoObserver(satellitesHandler);
updateUserInfoHandler.sendEmptyMessage(-1);
init();
}
@@ -281,7 +264,7 @@ public class cgeo extends AbstractActivity {
public void onPause() {
initialized = false;
app.deleteGeoObserver(locationUpdater);
- locationManager.removeGpsStatusListener(gpsListener);
+ app.deleteGeoObserver(satellitesHandler);
super.onPause();
}
@@ -594,12 +577,6 @@ public class cgeo extends AbstractActivity {
nearestView.setBackgroundResource(R.drawable.main_nearby);
}
- if (!gpsEnabled) {
- satellitesHandler.noGps();
- } else {
- satellitesHandler.satellites(geo.getSatellitesFixed(), geo.getSatellitesVisible());
- }
-
navType.setText(res.getString(geo.getLocationProvider().resourceId));
if (geo.getAccuracyNow() >= 0) {