VancedMicroG/play-services-location/src/main/java/org/microg/gms/location/FusedLocationProviderApiImp...

142 lines
5.3 KiB
Java
Raw Normal View History

2015-01-25 01:11:52 +00:00
/*
* Copyright 2013-2015 microG Project Team
2015-01-25 01:11:52 +00:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2015-01-15 19:11:31 +00:00
package org.microg.gms.location;
import android.app.PendingIntent;
import android.location.Location;
import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;
2015-01-19 00:46:08 +00:00
2015-01-15 19:11:31 +00:00
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
2015-01-19 00:46:08 +00:00
import com.google.android.gms.common.api.Result;
import com.google.android.gms.common.api.Status;
2015-01-15 19:11:31 +00:00
import com.google.android.gms.location.FusedLocationProviderApi;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
2015-01-19 00:46:08 +00:00
import com.google.android.gms.location.LocationServices;
2015-01-15 19:11:31 +00:00
2015-01-18 22:57:09 +00:00
import org.microg.gms.common.GmsConnector;
import org.microg.gms.common.api.ApiConnection;
2015-01-18 22:57:09 +00:00
2015-01-15 19:11:31 +00:00
public class FusedLocationProviderApiImpl implements FusedLocationProviderApi {
private static final String TAG = "GmsFusedApiImpl";
2015-01-19 00:46:08 +00:00
2015-01-15 19:11:31 +00:00
@Override
public Location getLastLocation(GoogleApiClient client) {
try {
2015-01-24 18:06:41 +00:00
Log.d(TAG, "getLastLocation(" + client + ")");
2015-01-15 19:11:31 +00:00
return LocationClientImpl.get(client).getLastLocation();
} catch (RemoteException e) {
Log.w(TAG, e);
return null;
}
}
@Override
2017-02-10 23:36:14 +00:00
public PendingResult<Status> requestLocationUpdates(GoogleApiClient client,
final LocationRequest request, final LocationListener listener) {
2015-01-19 00:46:08 +00:00
return callVoid(client, new Runnable() {
@Override
public void run(LocationClientImpl client) throws RemoteException {
client.requestLocationUpdates(request, listener);
}
});
2015-01-15 19:11:31 +00:00
}
@Override
2017-02-10 23:36:14 +00:00
public PendingResult<Status> requestLocationUpdates(GoogleApiClient client,
final LocationRequest request, final LocationListener listener,
final Looper looper) {
2015-01-19 00:46:08 +00:00
return callVoid(client, new Runnable() {
@Override
public void run(LocationClientImpl client) throws RemoteException {
client.requestLocationUpdates(request, listener, looper);
}
});
2015-01-15 19:11:31 +00:00
}
@Override
2017-02-10 23:36:14 +00:00
public PendingResult<Status> requestLocationUpdates(GoogleApiClient client,
final LocationRequest request, final PendingIntent callbackIntent) {
2015-01-19 00:46:08 +00:00
return callVoid(client, new Runnable() {
@Override
public void run(LocationClientImpl client) throws RemoteException {
client.requestLocationUpdates(request, callbackIntent);
}
});
2015-01-15 19:11:31 +00:00
}
@Override
2017-02-10 23:36:14 +00:00
public PendingResult<Status> removeLocationUpdates(GoogleApiClient client,
final LocationListener listener) {
2015-01-19 00:46:08 +00:00
return callVoid(client, new Runnable() {
@Override
public void run(LocationClientImpl client) throws RemoteException {
client.removeLocationUpdates(listener);
}
});
2015-01-15 19:11:31 +00:00
}
@Override
2017-02-10 23:36:14 +00:00
public PendingResult<Status> removeLocationUpdates(GoogleApiClient client,
final PendingIntent callbackIntent) {
2015-01-19 00:46:08 +00:00
return callVoid(client, new Runnable() {
@Override
public void run(LocationClientImpl client) throws RemoteException {
client.removeLocationUpdates(callbackIntent);
}
});
2015-01-15 19:11:31 +00:00
}
@Override
2017-02-10 23:36:14 +00:00
public PendingResult<Status> setMockMode(GoogleApiClient client, final boolean isMockMode) {
2015-01-19 00:46:08 +00:00
return callVoid(client, new Runnable() {
@Override
public void run(LocationClientImpl client) throws RemoteException {
client.setMockMode(isMockMode);
}
});
2015-01-15 19:11:31 +00:00
}
@Override
2017-02-10 23:36:14 +00:00
public PendingResult<Status> setMockLocation(GoogleApiClient client, final Location mockLocation) {
2015-01-19 00:46:08 +00:00
return callVoid(client, new Runnable() {
@Override
public void run(LocationClientImpl client) throws RemoteException {
client.setMockLocation(mockLocation);
}
});
2015-01-15 19:11:31 +00:00
}
2015-01-19 00:46:08 +00:00
2017-02-10 23:36:14 +00:00
private PendingResult<Status> callVoid(GoogleApiClient client, final Runnable runnable) {
return GmsConnector.call(client, LocationServices.API, new GmsConnector.Callback<LocationClientImpl, Status>() {
@Override
2017-02-10 23:36:14 +00:00
public void onClientAvailable(LocationClientImpl client, ResultProvider<Status> resultProvider) throws RemoteException {
runnable.run(client);
resultProvider.onResultAvailable(Status.SUCCESS);
}
});
2015-01-19 00:46:08 +00:00
}
private interface Runnable {
2015-03-31 21:56:13 +00:00
void run(LocationClientImpl client) throws RemoteException;
2015-01-19 00:46:08 +00:00
}
2015-01-15 19:11:31 +00:00
}