aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/CacheListActivity.java5
-rw-r--r--main/src/cgeo/geocaching/CgeoApplication.java97
-rw-r--r--main/src/cgeo/geocaching/CompassActivity.java35
-rw-r--r--main/src/cgeo/geocaching/EditWaypointActivity.java5
-rw-r--r--main/src/cgeo/geocaching/MainActivity.java9
-rw-r--r--main/src/cgeo/geocaching/NavigateAnyPointActivity.java7
-rw-r--r--main/src/cgeo/geocaching/SearchActivity.java5
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java4
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCMap.java38
-rw-r--r--main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java4
-rw-r--r--main/src/cgeo/geocaching/filter/DistanceFilter.java7
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java9
-rw-r--r--main/src/cgeo/geocaching/sensors/GeoData.java2
-rw-r--r--main/src/cgeo/geocaching/sensors/GeoDirHandler.java33
-rw-r--r--main/src/cgeo/geocaching/sensors/Sensors.java168
-rw-r--r--main/src/cgeo/geocaching/settings/SettingsActivity.java9
-rw-r--r--main/src/cgeo/geocaching/sorting/DateComparator.java4
-rw-r--r--main/src/cgeo/geocaching/ui/AddressListAdapter.java4
-rw-r--r--main/src/cgeo/geocaching/ui/CacheDetailsCreator.java4
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java4
20 files changed, 252 insertions, 201 deletions
diff --git a/main/src/cgeo/geocaching/CacheListActivity.java b/main/src/cgeo/geocaching/CacheListActivity.java
index 1b6a268..d0e9975 100644
--- a/main/src/cgeo/geocaching/CacheListActivity.java
+++ b/main/src/cgeo/geocaching/CacheListActivity.java
@@ -43,6 +43,7 @@ import cgeo.geocaching.network.Network;
import cgeo.geocaching.network.Send2CgeoDownloader;
import cgeo.geocaching.sensors.GeoData;
import cgeo.geocaching.sensors.GeoDirHandler;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.SettingsActivity;
import cgeo.geocaching.sorting.CacheComparator;
@@ -411,7 +412,7 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA
}
}
if (type == CacheListType.NEAREST) {
- coords = CgeoApplication.getInstance().currentGeo().getCoords();
+ coords = Sensors.getInstance().currentGeo().getCoords();
}
setTitle(title);
@@ -541,7 +542,7 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA
}
private void setAdapterCurrentCoordinates(final boolean forceSort) {
- adapter.setActualCoordinates(app.currentGeo().getCoords());
+ adapter.setActualCoordinates(Sensors.getInstance().currentGeo().getCoords());
if (forceSort) {
adapter.forceSort();
}
diff --git a/main/src/cgeo/geocaching/CgeoApplication.java b/main/src/cgeo/geocaching/CgeoApplication.java
index eea8154..1a25746 100644
--- a/main/src/cgeo/geocaching/CgeoApplication.java
+++ b/main/src/cgeo/geocaching/CgeoApplication.java
@@ -1,12 +1,6 @@
package cgeo.geocaching;
-import cgeo.geocaching.playservices.LocationProvider;
-import cgeo.geocaching.sensors.GeoData;
-import cgeo.geocaching.sensors.GeoDataProvider;
-import cgeo.geocaching.sensors.GpsStatusProvider;
-import cgeo.geocaching.sensors.GpsStatusProvider.Status;
-import cgeo.geocaching.sensors.OrientationProvider;
-import cgeo.geocaching.sensors.RotationProvider;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.OOMDumpingUncaughtExceptionHandler;
@@ -15,12 +9,6 @@ import cgeo.geocaching.utils.RxUtils;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
-import org.eclipse.jdt.annotation.NonNull;
-
-import rx.Observable;
-import rx.functions.Action1;
-import rx.functions.Func1;
-
import android.app.Application;
import android.view.ViewConfiguration;
@@ -32,21 +20,7 @@ public class CgeoApplication extends Application {
public boolean showLoginToast = true; //login toast shown just once.
private boolean liveMapHintShownInThisSession = false; // livemap hint has been shown
private static CgeoApplication instance;
- private Observable<GeoData> geoDataObservable;
- private Observable<GeoData> geoDataObservableLowPower;
- private Observable<Float> directionObservable;
- private Observable<Status> gpsStatusObservable;
- @NonNull private volatile GeoData currentGeo = GeoData.DUMMY_LOCATION;
- private volatile boolean hasValidLocation = false;
- private volatile float currentDirection = 0.0f;
private boolean isGooglePlayServicesAvailable = false;
- private final Action1<GeoData> rememberGeodataAction = new Action1<GeoData>() {
- @Override
- public void call(final GeoData geoData) {
- currentGeo = geoData;
- hasValidLocation = true;
- }
- };
public static void dumpOnOutOfMemory(final boolean enable) {
@@ -95,47 +69,14 @@ public class CgeoApplication extends Application {
isGooglePlayServicesAvailable = true;
}
Log.i("Google Play services are " + (isGooglePlayServicesAvailable ? "" : "not ") + "available");
- setupGeoDataObservables(Settings.useGooglePlayServices(), Settings.useLowPowerMode());
- setupDirectionObservable(Settings.useLowPowerMode());
- gpsStatusObservable = GpsStatusProvider.create(this).replay(1).refCount();
+ final Sensors sensors = Sensors.getInstance();
+ sensors.setupGeoDataObservables(Settings.useGooglePlayServices(), Settings.useLowPowerMode());
+ sensors.setupDirectionObservable(Settings.useLowPowerMode());
// Attempt to acquire an initial location before any real activity happens.
- geoDataObservableLowPower.subscribeOn(RxUtils.looperCallbacksScheduler).first().subscribe();
+ sensors.geoDataObservable(true).subscribeOn(RxUtils.looperCallbacksScheduler).first().subscribe();
}
- public void setupGeoDataObservables(final boolean useGooglePlayServices, final boolean useLowPowerLocation) {
- if (useGooglePlayServices) {
- geoDataObservable = LocationProvider.getMostPrecise(this).doOnNext(rememberGeodataAction);
- if (useLowPowerLocation) {
- geoDataObservableLowPower = LocationProvider.getLowPower(this).doOnNext(rememberGeodataAction);
- } else {
- geoDataObservableLowPower = geoDataObservable;
- }
- } else {
- geoDataObservable = RxUtils.rememberLast(GeoDataProvider.create(this).doOnNext(rememberGeodataAction));
- geoDataObservableLowPower = geoDataObservable;
- }
- }
-
- public void setupDirectionObservable(final boolean useLowPower) {
- directionObservable = RxUtils.rememberLast(RotationProvider.create(this, useLowPower).onErrorResumeNext(new Func1<Throwable, Observable<? extends Float>>() {
- @Override
- public Observable<? extends Float> call(final Throwable throwable) {
- return OrientationProvider.create(CgeoApplication.this);
- }
- }).onErrorResumeNext(new Func1<Throwable, Observable<? extends Float>>() {
- @Override
- public Observable<? extends Float> call(final Throwable throwable) {
- Log.e("Device orientation will not be available as no suitable sensors were found");
- return Observable.<Float>never().startWith(0.0f);
- }
- }).doOnNext(new Action1<Float>() {
- @Override
- public void call(final Float direction) {
- currentDirection = direction;
- }
- }));
- }
@Override
public void onLowMemory() {
@@ -143,34 +84,6 @@ public class CgeoApplication extends Application {
DataStore.removeAllFromCache();
}
- public Observable<GeoData> geoDataObservable(final boolean lowPower) {
- return lowPower ? geoDataObservableLowPower : geoDataObservable;
- }
-
- public Observable<Float> directionObservable() {
- return directionObservable;
- }
-
- public Observable<Status> gpsStatusObservable() {
- if (gpsStatusObservable == null) {
- gpsStatusObservable = GpsStatusProvider.create(this).share();
- }
- return gpsStatusObservable;
- }
-
- @NonNull
- public GeoData currentGeo() {
- return currentGeo;
- }
-
- public boolean hasValidLocation() {
- return hasValidLocation;
- }
-
- public float currentDirection() {
- return currentDirection;
- }
-
public boolean isLiveMapHintShownInThisSession() {
return liveMapHintShownInThisSession;
}
diff --git a/main/src/cgeo/geocaching/CompassActivity.java b/main/src/cgeo/geocaching/CompassActivity.java
index 1a1bad2..361582c 100644
--- a/main/src/cgeo/geocaching/CompassActivity.java
+++ b/main/src/cgeo/geocaching/CompassActivity.java
@@ -11,6 +11,7 @@ import cgeo.geocaching.maps.CGeoMap;
import cgeo.geocaching.sensors.GeoData;
import cgeo.geocaching.sensors.GeoDirHandler;
import cgeo.geocaching.sensors.GpsStatusProvider.Status;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.speech.SpeechService;
import cgeo.geocaching.ui.CompassView;
@@ -29,8 +30,6 @@ import rx.functions.Action1;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
-import android.hardware.Sensor;
-import android.hardware.SensorManager;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.Menu;
@@ -59,7 +58,6 @@ public class CompassActivity extends AbstractActionBarActivity {
private Geocache cache = null;
private Geopoint dstCoords = null;
private float cacheHeading = 0;
- private boolean hasMagneticFieldSensor;
private String description;
@Override
@@ -67,12 +65,6 @@ public class CompassActivity extends AbstractActionBarActivity {
super.onCreate(savedInstanceState, R.layout.compass_activity);
ButterKnife.inject(this);
- final SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
- hasMagneticFieldSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null;
- if (!hasMagneticFieldSensor) {
- Settings.setUseCompass(false);
- }
-
// get parameters
final Bundle extras = getIntent().getExtras();
if (extras == null) {
@@ -92,9 +84,7 @@ public class CompassActivity extends AbstractActionBarActivity {
setTarget(DataStore.loadWaypoint(waypointId));
}
else if (extras.containsKey(Intents.EXTRA_COORDS)) {
- final Geopoint coords = extras.getParcelable(Intents.EXTRA_COORDS);
- final String description = extras.getString(Intents.EXTRA_DESCRIPTION);
- setTarget(coords, description);
+ setTarget(extras.<Geopoint>getParcelable(Intents.EXTRA_COORDS), extras.getString(Intents.EXTRA_DESCRIPTION));
}
else {
setTarget(cache);
@@ -115,7 +105,7 @@ public class CompassActivity extends AbstractActionBarActivity {
@Override
public void onResume() {
super.onResume(geoDirHandler.start(GeoDirHandler.UPDATE_GEODIR),
- app.gpsStatusObservable().observeOn(AndroidSchedulers.mainThread()).subscribe(gpsStatusHandler));
+ Sensors.getInstance().gpsStatusObservable().observeOn(AndroidSchedulers.mainThread()).subscribe(gpsStatusHandler));
forceRefresh();
}
@@ -139,15 +129,14 @@ public class CompassActivity extends AbstractActionBarActivity {
private void forceRefresh() {
// Force a refresh of location and direction when data is available.
- final CgeoApplication app = CgeoApplication.getInstance();
- final GeoData geo = app.currentGeo();
- geoDirHandler.updateGeoDir(geo, app.currentDirection());
+ final Sensors sensors = Sensors.getInstance();
+ geoDirHandler.updateGeoDir(sensors.currentGeo(), sensors.currentDirection());
}
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.compass_activity_options, menu);
- menu.findItem(R.id.menu_compass_sensor).setVisible(hasMagneticFieldSensor);
+ menu.findItem(R.id.menu_compass_sensor).setVisible(Sensors.getInstance().hasMagneticFieldSensor());
if (cache != null) {
LoggingUI.addMenuItems(this, menu, cache);
}
@@ -226,12 +215,12 @@ public class CompassActivity extends AbstractActionBarActivity {
return super.onOptionsItemSelected(item);
}
- private void setTarget(final Geopoint coords, final String description) {
+ private void setTarget(final Geopoint coords, final String newDescription) {
setDestCoords(coords);
- setTargetDescription(description);
- updateDistanceInfo(app.currentGeo());
+ setTargetDescription(newDescription);
+ updateDistanceInfo(Sensors.getInstance().currentGeo());
- Log.d("destination set: " + description + " (" + dstCoords + ")");
+ Log.d("destination set: " + newDescription + " (" + dstCoords + ")");
}
private void setTarget(final @NonNull Waypoint waypoint) {
@@ -253,12 +242,12 @@ public class CompassActivity extends AbstractActionBarActivity {
private void setTargetDescription(final @Nullable String newDescription) {
description = newDescription;
- if (description == null) {
+ if (this.description == null) {
cacheInfoView.setVisibility(View.GONE);
return;
}
cacheInfoView.setVisibility(View.VISIBLE);
- cacheInfoView.setText(description);
+ cacheInfoView.setText(this.description);
}
private void updateDistanceInfo(final GeoData geo) {
diff --git a/main/src/cgeo/geocaching/EditWaypointActivity.java b/main/src/cgeo/geocaching/EditWaypointActivity.java
index 7cfb9f9..8cb947a 100644
--- a/main/src/cgeo/geocaching/EditWaypointActivity.java
+++ b/main/src/cgeo/geocaching/EditWaypointActivity.java
@@ -12,6 +12,7 @@ import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.location.GeopointFormatter;
import cgeo.geocaching.sensors.GeoData;
import cgeo.geocaching.sensors.GeoDirHandler;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.ui.dialog.CoordinatesInputDialog;
import cgeo.geocaching.ui.dialog.Dialogs;
@@ -308,7 +309,7 @@ public class EditWaypointActivity extends AbstractActionBarActivity implements C
@Override
protected void onPostExecute(final Geocache cache) {
- final CoordinatesInputDialog coordsDialog = CoordinatesInputDialog.getInstance(cache, geopoint, app.currentGeo());
+ final CoordinatesInputDialog coordsDialog = CoordinatesInputDialog.getInstance(cache, geopoint, Sensors.getInstance().currentGeo());
coordsDialog.setCancelable(true);
coordsDialog.show(getSupportFragmentManager(), "wpeditdialog");
}
@@ -391,7 +392,7 @@ public class EditWaypointActivity extends AbstractActionBarActivity implements C
return;
}
} else {
- coords = app.currentGeo().getCoords();
+ coords = Sensors.getInstance().currentGeo().getCoords();
}
if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) {
diff --git a/main/src/cgeo/geocaching/MainActivity.java b/main/src/cgeo/geocaching/MainActivity.java
index 321eaca..16a469d 100644
--- a/main/src/cgeo/geocaching/MainActivity.java
+++ b/main/src/cgeo/geocaching/MainActivity.java
@@ -19,6 +19,7 @@ import cgeo.geocaching.sensors.GeoData;
import cgeo.geocaching.sensors.GeoDirHandler;
import cgeo.geocaching.sensors.GpsStatusProvider;
import cgeo.geocaching.sensors.GpsStatusProvider.Status;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.SettingsActivity;
import cgeo.geocaching.ui.dialog.Dialogs;
@@ -226,11 +227,8 @@ public class MainActivity extends AbstractActionBarActivity {
@Override
public void onResume() {
super.onResume(locationUpdater.start(GeoDirHandler.UPDATE_GEODATA | GeoDirHandler.LOW_POWER),
- app.gpsStatusObservable().observeOn(AndroidSchedulers.mainThread()).subscribe(satellitesHandler));
+ Sensors.getInstance().gpsStatusObservable().observeOn(AndroidSchedulers.mainThread()).subscribe(satellitesHandler));
updateUserInfoHandler.sendEmptyMessage(-1);
- if (app.hasValidLocation()) {
- locationUpdater.updateGeoData(app.currentGeo());
- }
startBackgroundLogin();
init();
@@ -585,8 +583,7 @@ public class MainActivity extends AbstractActionBarActivity {
try {
addCoords = geo.getCoords();
final Geocoder geocoder = new Geocoder(MainActivity.this, Locale.getDefault());
- final Geopoint coords = app.currentGeo().getCoords();
- final List<Address> addresses = geocoder.getFromLocation(coords.getLatitude(), coords.getLongitude(), 1);
+ final List<Address> addresses = geocoder.getFromLocation(addCoords.getLatitude(), addCoords.getLongitude(), 1);
if (!addresses.isEmpty()) {
subscriber.onNext(formatAddress(addresses.get(0)));
}
diff --git a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java
index e75d6b1..d92e441 100644
--- a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java
+++ b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java
@@ -12,6 +12,7 @@ import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.location.GeopointFormatter;
import cgeo.geocaching.sensors.GeoData;
import cgeo.geocaching.sensors.GeoDirHandler;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.ui.AbstractViewHolder;
import cgeo.geocaching.ui.NavigationActionProvider;
@@ -286,7 +287,7 @@ public class NavigateAnyPointActivity extends AbstractActionBarActivity implemen
if (latButton.getText().length() > 0 && lonButton.getText().length() > 0) {
gp = new Geopoint(latButton.getText().toString() + " " + lonButton.getText().toString());
}
- final CoordinatesInputDialog coordsDialog = CoordinatesInputDialog.getInstance(null, gp, app.currentGeo());
+ final CoordinatesInputDialog coordsDialog = CoordinatesInputDialog.getInstance(null, gp, Sensors.getInstance().currentGeo());
coordsDialog.setCancelable(true);
coordsDialog.show(getSupportFragmentManager(),"wpedit_dialog");
}
@@ -477,7 +478,7 @@ public class NavigateAnyPointActivity extends AbstractActionBarActivity implemen
@Override
public void onClick(final View arg0) {
- final Geopoint coords = app.currentGeo().getCoords();
+ final Geopoint coords = Sensors.getInstance().currentGeo().getCoords();
latButton.setText(coords.format(GeopointFormatter.Format.LAT_DECMINUTE));
lonButton.setText(coords.format(GeopointFormatter.Format.LON_DECMINUTE));
changed = false;
@@ -507,7 +508,7 @@ public class NavigateAnyPointActivity extends AbstractActionBarActivity implemen
return null;
}
} else {
- coords = app.currentGeo().getCoords();
+ coords = Sensors.getInstance().currentGeo().getCoords();
}
// apply projection
diff --git a/main/src/cgeo/geocaching/SearchActivity.java b/main/src/cgeo/geocaching/SearchActivity.java
index 1606350..bb2ce2c 100644
--- a/main/src/cgeo/geocaching/SearchActivity.java
+++ b/main/src/cgeo/geocaching/SearchActivity.java
@@ -13,6 +13,7 @@ import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.location.GeopointFormatter;
import cgeo.geocaching.search.AutoCompleteAdapter;
import cgeo.geocaching.sensors.GeoData;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.ui.dialog.CoordinatesInputDialog;
import cgeo.geocaching.ui.dialog.Dialogs;
@@ -293,7 +294,7 @@ public class SearchActivity extends AbstractActionBarActivity implements Coordin
}
private void updateCoordinates() {
- final CoordinatesInputDialog coordsDialog = CoordinatesInputDialog.getInstance(null, null, app.currentGeo());
+ final CoordinatesInputDialog coordsDialog = CoordinatesInputDialog.getInstance(null, null, Sensors.getInstance().currentGeo());
coordsDialog.setCancelable(true);
coordsDialog.show(getSupportFragmentManager(), "wpedit_dialog");
}
@@ -309,7 +310,7 @@ public class SearchActivity extends AbstractActionBarActivity implements Coordin
final String lonText = StringUtils.trim(buttonLongitude.getText().toString());
if (StringUtils.isEmpty(latText) || StringUtils.isEmpty(lonText)) {
- final GeoData geo = app.currentGeo();
+ final GeoData geo = Sensors.getInstance().currentGeo();
buttonLatitude.setText(geo.getCoords().format(GeopointFormatter.Format.LAT_DECMINUTE));
buttonLongitude.setText(geo.getCoords().format(GeopointFormatter.Format.LON_DECMINUTE));
} else {
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java
index ccfd7a1..d14fca4 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java
@@ -1,10 +1,10 @@
package cgeo.geocaching.apps.cache.navi;
-import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.R;
import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.maps.MapProviderFactory;
import cgeo.geocaching.sensors.GeoData;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.utils.Log;
import android.app.Activity;
@@ -25,7 +25,7 @@ class GoogleMapsDirectionApp extends AbstractPointNavigationApp {
@Override
public void navigate(final Activity activity, final Geopoint coords) {
try {
- final GeoData geo = CgeoApplication.getInstance().currentGeo();
+ final GeoData geo = Sensors.getInstance().currentGeo();
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("http://maps.google.com/maps?f=d&saddr="
+ geo.getCoords().getLatitude() + "," + geo.getCoords().getLongitude() + "&daddr="
diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java
index 32c8b42..c353b40 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCMap.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java
@@ -1,6 +1,5 @@
package cgeo.geocaching.connector.gc;
-import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.DataStore;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.SearchResult;
@@ -9,12 +8,13 @@ import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.files.ParserException;
import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.GeopointFormatter.Format;
import cgeo.geocaching.location.Units;
import cgeo.geocaching.location.Viewport;
-import cgeo.geocaching.location.GeopointFormatter.Format;
import cgeo.geocaching.maps.LiveMapStrategy.Strategy;
import cgeo.geocaching.maps.LiveMapStrategy.StrategyFlag;
import cgeo.geocaching.network.Parameters;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.utils.Formatter;
import cgeo.geocaching.utils.JsonUtils;
@@ -47,7 +47,7 @@ import java.util.Set;
public class GCMap {
private static Viewport lastSearchViewport = null;
- public static SearchResult searchByGeocodes(Set<String> geocodes) {
+ public static SearchResult searchByGeocodes(final Set<String> geocodes) {
final SearchResult result = new SearchResult();
final String geocodeList = StringUtils.join(geocodes.toArray(), "|");
@@ -109,7 +109,7 @@ public class GCMap {
* Retrieved data.
* @return SearchResult. Never null.
*/
- public static SearchResult parseMapJSON(final String data, Tile tile, Bitmap bitmap, final Strategy strategy) {
+ public static SearchResult parseMapJSON(final String data, final Tile tile, final Bitmap bitmap, final Strategy strategy) {
final SearchResult searchResult = new SearchResult();
try {
@@ -142,13 +142,13 @@ public class GCMap {
}
// iterate over the data and construct all caches in this tile
- Map<String, List<UTFGridPosition>> positions = new HashMap<>(); // JSON id as key
- Map<String, List<UTFGridPosition>> singlePositions = new HashMap<>(); // JSON id as key
+ final Map<String, List<UTFGridPosition>> positions = new HashMap<>(); // JSON id as key
+ final Map<String, List<UTFGridPosition>> singlePositions = new HashMap<>(); // JSON id as key
for (final JsonNode rawKey: keys) {
final String key = rawKey.asText();
if (StringUtils.isNotBlank(key)) { // index 0 is empty
- UTFGridPosition pos = UTFGridPosition.fromString(key);
+ final UTFGridPosition pos = UTFGridPosition.fromString(key);
final ArrayNode dataForKey = (ArrayNode) dataObject.get(key);
for (final JsonNode cacheInfo: dataForKey) {
final String id = cacheInfo.get("i").asText();
@@ -174,18 +174,18 @@ public class GCMap {
}
final ArrayList<Geocache> caches = new ArrayList<>();
- for (Entry<String, List<UTFGridPosition>> entry : positions.entrySet()) {
- String id = entry.getKey();
- List<UTFGridPosition> pos = entry.getValue();
- UTFGridPosition xy = UTFGrid.getPositionInGrid(pos);
- Geocache cache = new Geocache();
+ for (final Entry<String, List<UTFGridPosition>> entry : positions.entrySet()) {
+ final String id = entry.getKey();
+ final List<UTFGridPosition> pos = entry.getValue();
+ final UTFGridPosition xy = UTFGrid.getPositionInGrid(pos);
+ final Geocache cache = new Geocache();
cache.setDetailed(false);
cache.setReliableLatLon(false);
cache.setGeocode(id);
cache.setName(nameCache.get(id));
cache.setCoords(tile.getCoord(xy), tile.getZoomLevel());
if (strategy.flags.contains(StrategyFlag.PARSE_TILES) && bitmap != null) {
- for (UTFGridPosition singlePos : singlePositions.get(id)) {
+ for (final UTFGridPosition singlePos : singlePositions.get(id)) {
if (IconDecoder.parseMapPNG(cache, bitmap, singlePos, tile.getZoomLevel())) {
break; // cache parsed
}
@@ -228,16 +228,16 @@ public class GCMap {
* @return
*/
public static SearchResult searchByViewport(final Viewport viewport, final MapTokens tokens) {
- int speed = (int) CgeoApplication.getInstance().currentGeo().getSpeed() * 60 * 60 / 1000; // in km/h
+ final int speed = (int) Sensors.getInstance().currentGeo().getSpeed() * 60 * 60 / 1000; // in km/h
Strategy strategy = Settings.getLiveMapStrategy();
if (strategy == Strategy.AUTO) {
strategy = speed >= 30 ? Strategy.FAST : Strategy.DETAILED;
}
- SearchResult result = searchByViewport(viewport, tokens, strategy);
+ final SearchResult result = searchByViewport(viewport, tokens, strategy);
if (Settings.isDebug()) {
- StringBuilder text = new StringBuilder(Formatter.SEPARATOR).append(strategy.getL10n()).append(Formatter.SEPARATOR).append(Units.getSpeed(speed));
+ final StringBuilder text = new StringBuilder(Formatter.SEPARATOR).append(strategy.getL10n()).append(Formatter.SEPARATOR).append(Units.getSpeed(speed));
result.setUrl(result.getUrl() + text);
}
@@ -340,7 +340,7 @@ public class GCMap {
final Geopoint center = viewport.getCenter();
if ((lastSearchViewport == null) || !lastSearchViewport.contains(center)) {
//FIXME We don't have a RecaptchaReceiver!?
- SearchResult search = GCParser.searchByCoords(center, Settings.getCacheType(), false, null);
+ final SearchResult search = GCParser.searchByCoords(center, Settings.getCacheType(), false, null);
if (search != null && !search.isEmpty()) {
final Set<String> geocodes = search.getGeocodes();
lastSearchViewport = DataStore.getBounds(geocodes);
@@ -366,8 +366,8 @@ public class GCMap {
* 4 = virtual, 11 = webcam, 137 = earth
* 8 = mystery, 1858 = whereigo
*/
- private static String getCacheTypeFilter(CacheType typeToDisplay) {
- Set<String> filterTypes = new HashSet<>();
+ private static String getCacheTypeFilter(final CacheType typeToDisplay) {
+ final Set<String> filterTypes = new HashSet<>();
// Put all types in set, remove what should be visible in a second step
filterTypes.addAll(Arrays.asList("2", "9", "5", "3", "6", "453", "13", "1304", "4", "11", "137", "8", "1858"));
switch (typeToDisplay) {
diff --git a/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java b/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java
index e8f20c9..65133fe 100644
--- a/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java
+++ b/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java
@@ -17,6 +17,7 @@ import cgeo.geocaching.connector.oc.UserInfo.UserInfoStatus;
import cgeo.geocaching.loaders.RecaptchaReceiver;
import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.location.Viewport;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.utils.CryptUtils;
@@ -175,8 +176,7 @@ public class OCApiLiveConnector extends OCApiConnector implements ISearchByCente
@Override
public SearchResult searchByKeyword(final @NonNull String name, final @NonNull RecaptchaReceiver recaptchaReceiver) {
- final Geopoint currentPos = CgeoApplication.getInstance().currentGeo().getCoords();
- return new SearchResult(OkapiClient.getCachesNamed(currentPos, name, this));
+ return new SearchResult(OkapiClient.getCachesNamed(Sensors.getInstance().currentGeo().getCoords(), name, this));
}
@Override
diff --git a/main/src/cgeo/geocaching/filter/DistanceFilter.java b/main/src/cgeo/geocaching/filter/DistanceFilter.java
index 3890571..93c240c 100644
--- a/main/src/cgeo/geocaching/filter/DistanceFilter.java
+++ b/main/src/cgeo/geocaching/filter/DistanceFilter.java
@@ -2,9 +2,10 @@ package cgeo.geocaching.filter;
import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.Geocache;
-import cgeo.geocaching.sensors.GeoData;
import cgeo.geocaching.R;
import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.sensors.GeoData;
+import cgeo.geocaching.sensors.Sensors;
import java.util.ArrayList;
import java.util.List;
@@ -14,11 +15,11 @@ class DistanceFilter extends AbstractFilter {
private final int minDistance;
private final int maxDistance;
- public DistanceFilter(String name, final int minDistance, final int maxDistance) {
+ public DistanceFilter(final String name, final int minDistance, final int maxDistance) {
super(name);
this.minDistance = minDistance;
this.maxDistance = maxDistance;
- geo = CgeoApplication.getInstance().currentGeo();
+ geo = Sensors.getInstance().currentGeo();
}
@Override
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 2868679..f2a5146 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -34,6 +34,7 @@ import cgeo.geocaching.maps.interfaces.MapViewImpl;
import cgeo.geocaching.maps.interfaces.OnMapDragListener;
import cgeo.geocaching.sensors.GeoData;
import cgeo.geocaching.sensors.GeoDirHandler;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.ui.dialog.LiveMapInfoDialogBuilder;
import cgeo.geocaching.utils.AngleUtils;
@@ -133,7 +134,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
// Those are initialized in onCreate() and will never be null afterwards
private Resources res;
private Activity activity;
- private CgeoApplication app;
private MapItemFactory mapItemFactory;
private String mapTitle;
final private LeastRecentlyUsedSet<Geocache> caches = new LeastRecentlyUsedSet<>(MAX_CACHES + DataStore.getAllCachesCount());
@@ -382,7 +382,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
// class init
res = this.getResources();
activity = this.getActivity();
- app = (CgeoApplication) activity.getApplication();
final MapProvider mapProvider = Settings.getMapProvider();
mapItemFactory = mapProvider.getMapItemFactory();
@@ -491,7 +490,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
});
}
- if (!app.isLiveMapHintShownInThisSession() && Settings.getLiveMapHintShowCount() <= 3) {
+ if (!CgeoApplication.getInstance().isLiveMapHintShownInThisSession() && Settings.getLiveMapHintShowCount() <= 3) {
LiveMapInfoDialogBuilder.create(activity).show();
}
}
@@ -955,7 +954,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
// minimum change of location in fraction of map width/height (whatever is smaller) for position overlay update
private static final float MIN_LOCATION_DELTA = 0.01f;
- Location currentLocation = CgeoApplication.getInstance().currentGeo();
+ Location currentLocation = Sensors.getInstance().currentGeo();
float currentHeading;
private long timeLastPositionOverlayCalculation = 0;
@@ -1539,7 +1538,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
if (myLocSwitch != null) {
myLocSwitch.setChecked(followMyLocation);
if (followMyLocation) {
- myLocationInMiddle(app.currentGeo());
+ myLocationInMiddle(Sensors.getInstance().currentGeo());
}
}
}
diff --git a/main/src/cgeo/geocaching/sensors/GeoData.java b/main/src/cgeo/geocaching/sensors/GeoData.java
index 880efd0..b8b16fd 100644
--- a/main/src/cgeo/geocaching/sensors/GeoData.java
+++ b/main/src/cgeo/geocaching/sensors/GeoData.java
@@ -91,7 +91,7 @@ public class GeoData extends Location {
final String homeLocationStr = Settings.getHomeLocation();
if (StringUtils.isNotBlank(homeLocationStr)) {
try {
- assert (homeLocationStr != null);
+ assert homeLocationStr != null;
final Geopoint homeLocation = new Geopoint(homeLocationStr);
Log.i("No last known location available, using home location");
final Location initialLocation = new Location(HOME_PROVIDER);
diff --git a/main/src/cgeo/geocaching/sensors/GeoDirHandler.java b/main/src/cgeo/geocaching/sensors/GeoDirHandler.java
index d043a4a..4743140 100644
--- a/main/src/cgeo/geocaching/sensors/GeoDirHandler.java
+++ b/main/src/cgeo/geocaching/sensors/GeoDirHandler.java
@@ -1,16 +1,11 @@
package cgeo.geocaching.sensors;
-import cgeo.geocaching.CgeoApplication;
-import cgeo.geocaching.settings.Settings;
-import cgeo.geocaching.utils.AngleUtils;
-
import org.apache.commons.lang3.tuple.ImmutablePair;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
-import rx.functions.Func1;
import rx.functions.Func2;
import rx.subscriptions.CompositeSubscription;
@@ -34,8 +29,6 @@ public abstract class GeoDirHandler {
public static final int UPDATE_GEODIR = 1 << 3;
public static final int LOW_POWER = 1 << 4;
- private static final CgeoApplication app = CgeoApplication.getInstance();
-
/**
* Update method called when new geodata is available. This method is called on the UI thread.
* {@link #start(int)} must be called with the {@link #UPDATE_GEODATA} flag set.
@@ -67,22 +60,6 @@ public abstract class GeoDirHandler {
public void updateGeoDir(final GeoData geoData, final float direction) {
}
- private static Observable<Float> fixedDirection() {
- return app.directionObservable().map(new Func1<Float, Float>() {
- @Override
- public Float call(final Float direction) {
- final GeoData geoData = app.currentGeo();
- return fixDirection(geoData, direction);
- }
- });
-
- }
-
- private static float fixDirection(final GeoData geoData, final float direction) {
- final boolean useGPSBearing = !Settings.isUseCompass() || geoData.getSpeed() > 5;
- return useGPSBearing ? AngleUtils.reverseDirectionNow(geoData.getBearing()) : direction;
- }
-
private static <T> Observable<T> throttleIfNeeded(final Observable<T> observable, final long windowDuration, final TimeUnit unit) {
return windowDuration > 0 ? observable.throttleFirst(windowDuration, unit) : observable;
}
@@ -108,8 +85,10 @@ public abstract class GeoDirHandler {
public Subscription start(final int flags, final long windowDuration, final TimeUnit unit) {
final CompositeSubscription subscriptions = new CompositeSubscription();
final boolean lowPower = (flags & LOW_POWER) != 0;
+ final Sensors sensors = Sensors.getInstance();
+
if ((flags & UPDATE_GEODATA) != 0) {
- subscriptions.add(throttleIfNeeded(app.geoDataObservable(lowPower), windowDuration, unit).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<GeoData>() {
+ subscriptions.add(throttleIfNeeded(sensors.geoDataObservable(lowPower), windowDuration, unit).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<GeoData>() {
@Override
public void call(final GeoData geoData) {
updateGeoData(geoData);
@@ -117,7 +96,7 @@ public abstract class GeoDirHandler {
}));
}
if ((flags & UPDATE_DIRECTION) != 0) {
- subscriptions.add(throttleIfNeeded(fixedDirection(), windowDuration, unit).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Float>() {
+ subscriptions.add(throttleIfNeeded(sensors.directionObservable(), windowDuration, unit).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Float>() {
@Override
public void call(final Float direction) {
updateDirection(direction);
@@ -126,10 +105,10 @@ public abstract class GeoDirHandler {
}
if ((flags & UPDATE_GEODIR) != 0) {
// combineOnLatest() does not implement backpressure handling, so we need to explicitely use a backpressure operator there.
- subscriptions.add(throttleIfNeeded(Observable.combineLatest(app.geoDataObservable(lowPower), app.directionObservable(), new Func2<GeoData, Float, ImmutablePair<GeoData, Float>>() {
+ subscriptions.add(throttleIfNeeded(Observable.combineLatest(sensors.geoDataObservable(lowPower), sensors.directionObservable(), new Func2<GeoData, Float, ImmutablePair<GeoData, Float>>() {
@Override
public ImmutablePair<GeoData, Float> call(final GeoData geoData, final Float direction) {
- return ImmutablePair.of(geoData, fixDirection(geoData, direction));
+ return ImmutablePair.of(geoData, direction);
}
}), windowDuration, unit).onBackpressureDrop().observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<ImmutablePair<GeoData, Float>>() {
@Override
diff --git a/main/src/cgeo/geocaching/sensors/Sensors.java b/main/src/cgeo/geocaching/sensors/Sensors.java
new file mode 100644
index 0000000..f548048
--- /dev/null
+++ b/main/src/cgeo/geocaching/sensors/Sensors.java
@@ -0,0 +1,168 @@
+package cgeo.geocaching.sensors;
+
+import cgeo.geocaching.CgeoApplication;
+import cgeo.geocaching.playservices.LocationProvider;
+import cgeo.geocaching.sensors.GpsStatusProvider.Status;
+import cgeo.geocaching.settings.Settings;
+import cgeo.geocaching.utils.AngleUtils;
+import cgeo.geocaching.utils.Log;
+import cgeo.geocaching.utils.RxUtils;
+
+import org.eclipse.jdt.annotation.NonNull;
+
+import rx.Observable;
+import rx.functions.Action1;
+import rx.functions.Func1;
+
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+public class Sensors {
+
+ private Observable<GeoData> geoDataObservable;
+ private Observable<GeoData> geoDataObservableLowPower;
+ private Observable<Float> directionObservable;
+ private Observable<Status> gpsStatusObservable;
+ @NonNull private volatile GeoData currentGeo = GeoData.DUMMY_LOCATION;
+ private volatile float currentDirection = 0.0f;
+ private volatile boolean hasValidLocation = false;
+ private final boolean hasMagneticFieldSensor;
+ private final CgeoApplication app = CgeoApplication.getInstance();
+
+ private static class InstanceHolder {
+ static final Sensors INSTANCE = new Sensors();
+ }
+
+ private final Action1<GeoData> rememberGeodataAction = new Action1<GeoData>() {
+ @Override
+ public void call(final GeoData geoData) {
+ currentGeo = geoData;
+ hasValidLocation = true;
+ }
+ };
+
+ private final Action1<Float> onNextrememberDirectionAction = new Action1<Float>() {
+ @Override
+ public void call(final Float direction) {
+ currentDirection = direction;
+ }
+ };
+
+ private Sensors() {
+ gpsStatusObservable = GpsStatusProvider.create(app).replay(1).refCount();
+ final SensorManager sensorManager = (SensorManager) app.getSystemService(Context.SENSOR_SERVICE);
+ hasMagneticFieldSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null;
+ }
+
+ public static final Sensors getInstance() {
+ return InstanceHolder.INSTANCE;
+ }
+
+ public void setupGeoDataObservables(final boolean useGooglePlayServices, final boolean useLowPowerLocation) {
+ if (useGooglePlayServices) {
+ geoDataObservable = LocationProvider.getMostPrecise(app).doOnNext(rememberGeodataAction);
+ if (useLowPowerLocation) {
+ geoDataObservableLowPower = LocationProvider.getLowPower(app).doOnNext(rememberGeodataAction);
+ } else {
+ geoDataObservableLowPower = geoDataObservable;
+ }
+ } else {
+ geoDataObservable = RxUtils.rememberLast(GeoDataProvider.create(app).doOnNext(rememberGeodataAction));
+ geoDataObservableLowPower = geoDataObservable;
+ }
+ }
+
+ private static final Func1<GeoData, Float> GPS_TO_DIRECTION = new Func1<GeoData, Float>() {
+ @Override
+ public Float call(final GeoData geoData) {
+ return AngleUtils.reverseDirectionNow(geoData.getBearing());
+ }
+ };
+
+ public void setupDirectionObservable(final boolean useLowPower) {
+ // If we have no magnetic sensor, there is no point in trying to setup any, we will always get the direction from the GPS.
+ if (!hasMagneticFieldSensor) {
+ Log.i("No magnetic field sensor, using only the GPS for the orientation");
+ directionObservable = RxUtils.rememberLast(geoDataObservableLowPower.map(GPS_TO_DIRECTION).doOnNext(onNextrememberDirectionAction));
+ return;
+ }
+
+ // Combine the magnetic direction observable with the GPS when compass is disabled or speed is high enough.
+
+ final AtomicBoolean useDirectionFromGps = new AtomicBoolean(false);
+
+ final Observable<Float> magneticDirectionObservable = RotationProvider.create(app, useLowPower).onErrorResumeNext(new Func1<Throwable, Observable<? extends Float>>() {
+ @Override
+ public Observable<? extends Float> call(final Throwable throwable) {
+ return OrientationProvider.create(app);
+ }
+ }).onErrorResumeNext(new Func1<Throwable, Observable<? extends Float>>() {
+ @Override
+ public Observable<? extends Float> call(final Throwable throwable) {
+ Log.e("Device orientation will not be available as no suitable sensors were found, disabling compass");
+ Settings.setUseCompass(false);
+ return Observable.<Float>never().startWith(0.0f);
+ }
+ }).filter(new Func1<Float, Boolean>() {
+ @Override
+ public Boolean call(final Float aFloat) {
+ final boolean compassWillBeUsed = Settings.isUseCompass() && !useDirectionFromGps.get();
+ if (compassWillBeUsed) {
+ Log.d("Using direction from compass: " + aFloat);
+ }
+ return compassWillBeUsed;
+ }
+ });
+
+ final Observable<Float> directionFromGpsObservable = geoDataObservable(true).filter(new Func1<GeoData, Boolean>() {
+ @Override
+ public Boolean call(final GeoData geoData) {
+ final boolean useGps = geoData.getSpeed() > 5.0f;
+ useDirectionFromGps.set(useGps);
+ final boolean gpsWillBeUsed = useGps || !Settings.isUseCompass();
+ if (gpsWillBeUsed) {
+ Log.d("Using direction from GPS");
+ }
+ return gpsWillBeUsed;
+ }
+ }).map(GPS_TO_DIRECTION);
+
+ directionObservable = Observable.merge(magneticDirectionObservable, directionFromGpsObservable);
+ }
+
+ public Observable<GeoData> geoDataObservable(final boolean lowPower) {
+ return lowPower ? geoDataObservableLowPower : geoDataObservable;
+ }
+
+ public Observable<Float> directionObservable() {
+ return directionObservable;
+ }
+
+ public Observable<Status> gpsStatusObservable() {
+ if (gpsStatusObservable == null) {
+ gpsStatusObservable = GpsStatusProvider.create(app).share();
+ }
+ return gpsStatusObservable;
+ }
+
+ @NonNull
+ public GeoData currentGeo() {
+ return currentGeo;
+ }
+
+ public boolean hasValidLocation() {
+ return hasValidLocation;
+ }
+
+ public float currentDirection() {
+ return currentDirection;
+ }
+
+ public boolean hasMagneticFieldSensor() {
+ return hasMagneticFieldSensor;
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/settings/SettingsActivity.java b/main/src/cgeo/geocaching/settings/SettingsActivity.java
index 662ba33..99de30f 100644
--- a/main/src/cgeo/geocaching/settings/SettingsActivity.java
+++ b/main/src/cgeo/geocaching/settings/SettingsActivity.java
@@ -12,6 +12,7 @@ import cgeo.geocaching.connector.gc.GCConnector;
import cgeo.geocaching.files.SimpleDirChooser;
import cgeo.geocaching.maps.MapProviderFactory;
import cgeo.geocaching.maps.interfaces.MapSource;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.utils.DatabaseBackupUtils;
import cgeo.geocaching.utils.DebugUtils;
import cgeo.geocaching.utils.Log;
@@ -421,11 +422,12 @@ public class SettingsActivity extends PreferenceActivity {
}
private void initGeoDirPreferences() {
+ final Sensors sensors = Sensors.getInstance();
final Preference playServices = getPreference(R.string.pref_googleplayservices);
playServices.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(final Preference preference, final Object newValue) {
- CgeoApplication.getInstance().setupGeoDataObservables((Boolean) newValue, Settings.useLowPowerMode());
+ sensors.setupGeoDataObservables((Boolean) newValue, Settings.useLowPowerMode());
return true;
}
});
@@ -433,10 +435,9 @@ public class SettingsActivity extends PreferenceActivity {
getPreference(R.string.pref_lowpowermode).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(final Preference preference, final Object newValue) {
- final CgeoApplication app = CgeoApplication.getInstance();
final Boolean useLowPower = (Boolean) newValue;
- app.setupGeoDataObservables(Settings.useGooglePlayServices(), useLowPower);
- app.setupDirectionObservable(useLowPower);
+ sensors.setupGeoDataObservables(Settings.useGooglePlayServices(), useLowPower);
+ sensors.setupDirectionObservable(useLowPower);
return true;
}
});
diff --git a/main/src/cgeo/geocaching/sorting/DateComparator.java b/main/src/cgeo/geocaching/sorting/DateComparator.java
index 6d294db..af50213 100644
--- a/main/src/cgeo/geocaching/sorting/DateComparator.java
+++ b/main/src/cgeo/geocaching/sorting/DateComparator.java
@@ -1,7 +1,7 @@
package cgeo.geocaching.sorting;
-import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.Geocache;
+import cgeo.geocaching.sensors.Sensors;
import java.util.ArrayList;
import java.util.Date;
@@ -22,7 +22,7 @@ class DateComparator extends AbstractCacheComparator {
final ArrayList<Geocache> list = new ArrayList<>();
list.add(cache1);
list.add(cache2);
- final DistanceComparator distanceComparator = new DistanceComparator(CgeoApplication.getInstance().currentGeo().getCoords(), list);
+ final DistanceComparator distanceComparator = new DistanceComparator(Sensors.getInstance().currentGeo().getCoords(), list);
return distanceComparator.compare(cache1, cache2);
}
return dateDifference;
diff --git a/main/src/cgeo/geocaching/ui/AddressListAdapter.java b/main/src/cgeo/geocaching/ui/AddressListAdapter.java
index 455954a..901bffc 100644
--- a/main/src/cgeo/geocaching/ui/AddressListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/AddressListAdapter.java
@@ -3,10 +3,10 @@ package cgeo.geocaching.ui;
import butterknife.InjectView;
import cgeo.geocaching.CacheListActivity;
-import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.R;
import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.location.Units;
+import cgeo.geocaching.sensors.Sensors;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
@@ -38,7 +38,7 @@ public class AddressListAdapter extends ArrayAdapter<Address> {
public AddressListAdapter(final Activity context) {
super(context, 0);
inflater = context.getLayoutInflater();
- location = CgeoApplication.getInstance().currentGeo().getCoords();
+ location = Sensors.getInstance().currentGeo().getCoords();
}
@Override
diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
index 7dd3847..de954aa 100644
--- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
+++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
@@ -2,13 +2,13 @@ package cgeo.geocaching.ui;
import butterknife.ButterKnife;
-import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.ICoordinates;
import cgeo.geocaching.R;
import cgeo.geocaching.Waypoint;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.location.Units;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.utils.Formatter;
import org.apache.commons.lang3.StringUtils;
@@ -118,7 +118,7 @@ public final class CacheDetailsCreator {
if (target.getCoords() == null) {
return null;
}
- return CgeoApplication.getInstance().currentGeo().getCoords().distanceTo(target);
+ return Sensors.getInstance().currentGeo().getCoords().distanceTo(target);
}
public void addRating(final Geocache cache) {
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index f080761..34cac01 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -3,7 +3,6 @@ package cgeo.geocaching.ui;
import butterknife.InjectView;
import cgeo.geocaching.CacheDetailActivity;
-import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.R;
import cgeo.geocaching.enumerations.CacheListType;
@@ -11,6 +10,7 @@ import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.filter.IFilter;
import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.sensors.GeoData;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.sorting.CacheComparator;
import cgeo.geocaching.sorting.DistanceComparator;
@@ -119,7 +119,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
public CacheListAdapter(final Activity activity, final List<Geocache> list, final CacheListType cacheListType) {
super(activity, 0, list);
- final GeoData currentGeo = CgeoApplication.getInstance().currentGeo();
+ final GeoData currentGeo = Sensors.getInstance().currentGeo();
coords = currentGeo.getCoords();
this.res = activity.getResources();
this.list = list;