aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/CompassActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/CompassActivity.java')
-rw-r--r--main/src/cgeo/geocaching/CompassActivity.java35
1 files changed, 24 insertions, 11 deletions
diff --git a/main/src/cgeo/geocaching/CompassActivity.java b/main/src/cgeo/geocaching/CompassActivity.java
index 025d938..6913b2a 100644
--- a/main/src/cgeo/geocaching/CompassActivity.java
+++ b/main/src/cgeo/geocaching/CompassActivity.java
@@ -8,19 +8,23 @@ import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Units;
import cgeo.geocaching.maps.CGeoMap;
-import cgeo.geocaching.sensors.DirectionProvider;
import cgeo.geocaching.sensors.GeoDirHandler;
+import cgeo.geocaching.sensors.GpsStatusProvider.Status;
import cgeo.geocaching.sensors.IGeoData;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.speech.SpeechService;
import cgeo.geocaching.ui.CompassView;
import cgeo.geocaching.ui.LoggingUI;
+import cgeo.geocaching.utils.AngleUtils;
import cgeo.geocaching.utils.Formatter;
import cgeo.geocaching.utils.Log;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.Nullable;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.functions.Action1;
+
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
@@ -118,7 +122,9 @@ public class CompassActivity extends AbstractActionBarActivity {
@Override
public void onResume() {
- super.onResume(geoDirHandler.start(GeoDirHandler.UPDATE_GEODIR));
+ super.onResume(geoDirHandler.start(GeoDirHandler.UPDATE_GEODIR),
+ app.gpsStatusObservable().observeOn(AndroidSchedulers.mainThread()).subscribe(gpsStatusHandler));
+ forceRefresh();
}
@Override
@@ -138,13 +144,14 @@ public class CompassActivity extends AbstractActionBarActivity {
setTitle();
setDestCoords();
setCacheInfo();
+ forceRefresh();
+ }
+ private void forceRefresh() {
// Force a refresh of location and direction when data is available.
final CgeoApplication app = CgeoApplication.getInstance();
final IGeoData geo = app.currentGeo();
- if (geo != null) {
- geoDirHandler.updateGeoDir(geo, app.currentDirection());
- }
+ geoDirHandler.updateGeoDir(geo, app.currentDirection());
}
@Override
@@ -259,16 +266,22 @@ public class CompassActivity extends AbstractActionBarActivity {
headingView.setText(Math.round(cacheHeading) + "°");
}
+ private final Action1<Status> gpsStatusHandler = new Action1<Status>() {
+ @Override
+ public void call(final Status gpsStatus) {
+ if (gpsStatus.satellitesVisible >= 0) {
+ navSatellites.setText(res.getString(R.string.loc_sat) + ": " + gpsStatus.satellitesFixed + "/" + gpsStatus.satellitesVisible);
+ } else {
+ navSatellites.setText("");
+ }
+ }
+ };
+
private final GeoDirHandler geoDirHandler = new GeoDirHandler() {
@Override
public void updateGeoDir(final IGeoData geo, final float dir) {
try {
if (geo.getCoords() != null) {
- if (geo.getSatellitesVisible() >= 0) {
- navSatellites.setText(res.getString(R.string.loc_sat) + ": " + geo.getSatellitesFixed() + "/" + geo.getSatellitesVisible());
- } else {
- navSatellites.setText("");
- }
navType.setText(res.getString(geo.getLocationProvider().resourceId));
if (geo.getAccuracy() >= 0) {
@@ -286,7 +299,7 @@ public class CompassActivity extends AbstractActionBarActivity {
navLocation.setText(res.getString(R.string.loc_trying));
}
- updateNorthHeading(DirectionProvider.getDirectionNow(dir));
+ updateNorthHeading(AngleUtils.getDirectionNow(dir));
} catch (final RuntimeException e) {
Log.w("Failed to LocationUpdater location.");
}