aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2015-01-04 16:23:40 +0100
committerBananeweizen <bananeweizen@gmx.de>2015-01-04 16:30:41 +0100
commita18407f7a0547cd5c2a645e7948bc4925026332f (patch)
treec18c632a1387cfe98cd82545e388a35c63298c8b /main/src
parentd1a6842ba7f8147e2b9590331a504b82ebde944c (diff)
downloadcgeo-a18407f7a0547cd5c2a645e7948bc4925026332f.zip
cgeo-a18407f7a0547cd5c2a645e7948bc4925026332f.tar.gz
cgeo-a18407f7a0547cd5c2a645e7948bc4925026332f.tar.bz2
fix #4585: split play services
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/enumerations/WaypointType.java2
-rw-r--r--main/src/cgeo/geocaching/playservices/LocationProvider.java30
2 files changed, 18 insertions, 14 deletions
diff --git a/main/src/cgeo/geocaching/enumerations/WaypointType.java b/main/src/cgeo/geocaching/enumerations/WaypointType.java
index 707b9f3..732a665 100644
--- a/main/src/cgeo/geocaching/enumerations/WaypointType.java
+++ b/main/src/cgeo/geocaching/enumerations/WaypointType.java
@@ -39,7 +39,7 @@ public enum WaypointType {
* inverse lookup of waypoint IDs<br/>
* non public so that <code>null</code> handling can be handled centrally in the enum type itself
*/
- private static final Map<String, WaypointType> FIND_BY_ID = new HashMap();
+ private static final Map<String, WaypointType> FIND_BY_ID = new HashMap<>();
private static final Set<WaypointType> ALL_TYPES_EXCEPT_OWN_AND_ORIGINAL_TMP = new HashSet<>();
static {
for (final WaypointType wt : values()) {
diff --git a/main/src/cgeo/geocaching/playservices/LocationProvider.java b/main/src/cgeo/geocaching/playservices/LocationProvider.java
index 8e42729..9d193b5 100644
--- a/main/src/cgeo/geocaching/playservices/LocationProvider.java
+++ b/main/src/cgeo/geocaching/playservices/LocationProvider.java
@@ -6,11 +6,10 @@ import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.RxUtils;
import com.google.android.gms.common.ConnectionResult;
-import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
-import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
-import com.google.android.gms.location.LocationClient;
+import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
+import com.google.android.gms.location.LocationServices;
import rx.Observable;
import rx.Observable.OnSubscribe;
@@ -28,7 +27,7 @@ import android.os.Bundle;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-public class LocationProvider implements ConnectionCallbacks, OnConnectionFailedListener, LocationListener {
+public class LocationProvider implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
private static final LocationRequest LOCATION_REQUEST =
LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(2000).setFastestInterval(250);
@@ -38,7 +37,7 @@ public class LocationProvider implements ConnectionCallbacks, OnConnectionFailed
private static final AtomicInteger lowPowerCount = new AtomicInteger(0);
private static LocationProvider instance = null;
private static final ReplaySubject<GeoData> subject = ReplaySubject.createWithSize(1);
- private final LocationClient locationClient;
+ private final GoogleApiClient locationClient;
private static synchronized LocationProvider getInstance(final Context context) {
if (instance == null) {
@@ -51,13 +50,13 @@ public class LocationProvider implements ConnectionCallbacks, OnConnectionFailed
if (locationClient.isConnected()) {
if (mostPreciseCount.get() > 0) {
Log.d("LocationProvider: requesting most precise locations");
- locationClient.requestLocationUpdates(LOCATION_REQUEST, this, RxUtils.looperCallbacksLooper);
+ LocationServices.FusedLocationApi.requestLocationUpdates(locationClient, LOCATION_REQUEST, this, RxUtils.looperCallbacksLooper);
} else if (lowPowerCount.get() > 0) {
Log.d("LocationProvider: requesting low-power locations");
- locationClient.requestLocationUpdates(LOCATION_REQUEST_LOW_POWER, this, RxUtils.looperCallbacksLooper);
+ LocationServices.FusedLocationApi.requestLocationUpdates(locationClient, LOCATION_REQUEST_LOW_POWER, this, RxUtils.looperCallbacksLooper);
} else {
Log.d("LocationProvider: stopping location requests");
- locationClient.removeLocationUpdates(this);
+ LocationServices.FusedLocationApi.removeLocationUpdates(locationClient, this);
}
}
}
@@ -127,7 +126,11 @@ public class LocationProvider implements ConnectionCallbacks, OnConnectionFailed
private LocationProvider(final Context context) {
final GeoData initialLocation = GeoData.getInitialLocation(context);
subject.onNext(initialLocation != null ? initialLocation : GeoData.DUMMY_LOCATION);
- locationClient = new LocationClient(context, this, this);
+ locationClient = new GoogleApiClient.Builder(context)
+ .addApi(LocationServices.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
locationClient.connect();
}
@@ -137,10 +140,6 @@ public class LocationProvider implements ConnectionCallbacks, OnConnectionFailed
}
@Override
- public void onDisconnected() {
- }
-
- @Override
public void onConnectionFailed(final ConnectionResult connectionResult) {
Log.e("cannot connect to Google Play location service: " + connectionResult);
subject.onError(new RuntimeException("Connection failed: " + connectionResult));
@@ -153,4 +152,9 @@ public class LocationProvider implements ConnectionCallbacks, OnConnectionFailed
}
subject.onNext(new GeoData(location));
}
+
+ @Override
+ public void onConnectionSuspended(final int arg0) {
+ // empty
+ }
}