2015-01-25 01:11:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014-2015 µg Project Team
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
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
|
2015-01-19 00:46:08 +00:00
|
|
|
public PendingResult requestLocationUpdates(GoogleApiClient client,
|
2015-01-22 02:07:09 +00:00
|
|
|
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
|
2015-01-19 00:46:08 +00:00
|
|
|
public PendingResult requestLocationUpdates(GoogleApiClient client,
|
2015-01-22 02:07:09 +00:00
|
|
|
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
|
2015-01-19 00:46:08 +00:00
|
|
|
public PendingResult requestLocationUpdates(GoogleApiClient client,
|
2015-01-22 02:07:09 +00:00
|
|
|
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
|
2015-01-19 00:46:08 +00:00
|
|
|
public PendingResult removeLocationUpdates(GoogleApiClient client,
|
2015-01-22 02:07:09 +00:00
|
|
|
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
|
|
|
|
public PendingResult removeLocationUpdates(GoogleApiClient client,
|
2015-01-22 02:07:09 +00:00
|
|
|
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
|
2015-01-19 00:46:08 +00:00
|
|
|
public PendingResult setMockMode(GoogleApiClient client, final boolean isMockMode) {
|
|
|
|
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
|
2015-01-19 00:46:08 +00:00
|
|
|
public PendingResult setMockLocation(GoogleApiClient client, final Location mockLocation) {
|
|
|
|
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
|
|
|
|
|
|
|
private PendingResult callVoid(GoogleApiClient client, final Runnable runnable) {
|
|
|
|
return new GmsConnector<>(client, LocationServices.API,
|
|
|
|
new GmsConnector.Callback<LocationClientImpl, Result>() {
|
|
|
|
@Override
|
|
|
|
public Result onClientAvailable(LocationClientImpl client) throws
|
|
|
|
RemoteException {
|
|
|
|
runnable.run(client);
|
|
|
|
return Status.SUCCESS;
|
|
|
|
}
|
|
|
|
}).connect();
|
|
|
|
}
|
|
|
|
|
|
|
|
private interface Runnable {
|
|
|
|
public void run(LocationClientImpl client) throws RemoteException;
|
|
|
|
}
|
|
|
|
|
2015-01-15 19:11:31 +00:00
|
|
|
}
|