use of com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks in project braintree_android by braintree.
the class BraintreeFragment method getGoogleApiClient.
protected GoogleApiClient getGoogleApiClient() {
if (getActivity() == null) {
postCallback(new GoogleApiClientException(ErrorType.NotAttachedToActivity, 1));
return null;
}
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity()).addApi(Wallet.API, new Wallet.WalletOptions.Builder().setEnvironment(GooglePayment.getEnvironment(getConfiguration().getAndroidPay())).setTheme(WalletConstants.THEME_LIGHT).build()).build();
}
if (!mGoogleApiClient.isConnected() && !mGoogleApiClient.isConnecting()) {
mGoogleApiClient.registerConnectionCallbacks(new ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
postCallback(new GoogleApiClientException(ErrorType.ConnectionSuspended, i));
}
});
mGoogleApiClient.registerConnectionFailedListener(new OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
postCallback(new GoogleApiClientException(ErrorType.ConnectionFailed, connectionResult.getErrorCode()));
}
});
mGoogleApiClient.connect();
}
return mGoogleApiClient;
}
use of com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks in project iNaturalistAndroid by inaturalist.
the class INaturalistService method getLocation.
private void getLocation(final IOnLocation callback) {
if (!mApp.isLocationEnabled(null)) {
Log.e(TAG, "getLocation: Location not enabled");
// Location not enabled
new Thread(new Runnable() {
@Override
public void run() {
callback.onLocation(null);
}
}).start();
return;
}
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
Log.e(TAG, "getLocation: resultCode = " + resultCode);
if (ConnectionResult.SUCCESS == resultCode) {
// User Google Play services if available
if ((mLocationClient != null) && (mLocationClient.isConnected())) {
// Location client already initialized and connected - use it
new Thread(new Runnable() {
@Override
public void run() {
callback.onLocation(getLastKnownLocationFromClient());
}
}).start();
} else {
// Connect to the place services
mLocationClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(new ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
// Connected successfully
new Thread(new Runnable() {
@Override
public void run() {
callback.onLocation(getLastKnownLocationFromClient());
mLocationClient.disconnect();
}
}).start();
}
@Override
public void onConnectionSuspended(int i) {
}
}).addOnConnectionFailedListener(new OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
// Couldn't connect
new Thread(new Runnable() {
@Override
public void run() {
callback.onLocation(null);
mLocationClient.disconnect();
}
}).start();
}
}).build();
mLocationClient.connect();
}
} else {
// Use GPS alone for place
new Thread(new Runnable() {
@Override
public void run() {
callback.onLocation(getLocationFromGPS());
}
}).start();
}
}
Aggregations