From 75a8a8d1c70b23a2867345043e36e850a6c16502 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Fri, 27 Apr 2012 12:10:34 +0200 Subject: Add GPS enabled information to the IGeoData interface --- main/src/cgeo/geocaching/GeoDataProvider.java | 24 ++++++++++++++++++++---- main/src/cgeo/geocaching/IGeoData.java | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'main') diff --git a/main/src/cgeo/geocaching/GeoDataProvider.java b/main/src/cgeo/geocaching/GeoDataProvider.java index b7a5341..fe942c4 100644 --- a/main/src/cgeo/geocaching/GeoDataProvider.java +++ b/main/src/cgeo/geocaching/GeoDataProvider.java @@ -46,6 +46,7 @@ class GeoDataProvider extends MemorySubject { public float accuracyNow = -1f; public int satellitesVisible = 0; public int satellitesFixed = 0; + public boolean gpsEnabled = false; @Override public Location getLocation() { @@ -73,6 +74,11 @@ class GeoDataProvider extends MemorySubject { } @Override + public boolean getGpsEnabled() { + return gpsEnabled; + } + + @Override public float getSpeedNow() { return speedNow; } @@ -253,6 +259,7 @@ class GeoDataProvider extends MemorySubject { @Override public void onGpsStatusChanged(final int event) { + boolean changed = false; if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) { final GpsStatus status = geoManager.getGpsStatus(null); final Iterator statusIterator = status.getSatellites().iterator(); @@ -268,7 +275,6 @@ class GeoDataProvider extends MemorySubject { satellites++; } - boolean changed = false; if (satellites != current.satellitesVisible) { current.satellitesVisible = satellites; changed = true; @@ -277,10 +283,20 @@ class GeoDataProvider extends MemorySubject { current.satellitesFixed = fixed; changed = true; } + } else if (event == GpsStatus.GPS_EVENT_STARTED && !current.gpsEnabled) { + current.gpsEnabled = true; + current.satellitesFixed = 0; + current.satellitesVisible = 0; + changed = true; + } else if (event == GpsStatus.GPS_EVENT_STOPPED && current.gpsEnabled) { + current.gpsEnabled = false; + current.satellitesFixed = 0; + current.satellitesVisible = 0; + changed = true; + } - if (changed) { - selectBest(null); - } + if (changed) { + selectBest(null); } } } diff --git a/main/src/cgeo/geocaching/IGeoData.java b/main/src/cgeo/geocaching/IGeoData.java index d703d1a..7758a97 100644 --- a/main/src/cgeo/geocaching/IGeoData.java +++ b/main/src/cgeo/geocaching/IGeoData.java @@ -14,6 +14,7 @@ public interface IGeoData { public float getBearingNow(); public float getSpeedNow(); public float getAccuracyNow(); + public boolean getGpsEnabled(); public int getSatellitesVisible(); public int getSatellitesFixed(); -- cgit v1.1