use of com.google.android.gms.common.api.GoogleApiClient in project PhoneProfilesPlus by henrichg.
the class LocationGeofenceEditorActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
// must by called before super.onCreate() for PreferenceActivity
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
GlobalGUIRoutines.setTheme(this, false, true, false);
else
GlobalGUIRoutines.setTheme(this, false, false, false);
GlobalGUIRoutines.setLanguage(getBaseContext());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location_geofence_editor);
mResultReceiver = new AddressResultReceiver(new Handler(getMainLooper()));
// Create a GoogleApiClient instance
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
PPApplication.logE("LocationGeofenceEditorActivity.LocationCallback", "xxx");
if (locationResult == null) {
return;
}
for (Location location : locationResult.getLocations()) {
mLastLocation = location;
PPApplication.logE("LocationGeofenceEditorActivity.LocationCallback", "location=" + location);
if (mLocation == null) {
mLocation = new Location(mLastLocation);
refreshActivity(true);
} else
updateEditedMarker(false);
}
}
};
createLocationRequest();
mResolvingError = savedInstanceState != null && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);
Intent intent = getIntent();
geofenceId = intent.getLongExtra(LocationGeofencePreference.EXTRA_GEOFENCE_ID, 0);
if (geofenceId > 0) {
geofence = DatabaseHandler.getInstance(getApplicationContext()).getGeofence(geofenceId);
mLocation = new Location("LOC");
mLocation.setLatitude(geofence._latitude);
mLocation.setLongitude(geofence._longitude);
}
if (geofence == null) {
geofenceId = 0;
geofence = new Geofence();
geofence._name = getString(R.string.event_preferences_location_new_location_name) + "_" + String.valueOf(DatabaseHandler.getInstance(getApplicationContext()).getGeofenceCount() + 1);
geofence._radius = 100;
}
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.location_editor_map);
mapFragment.getMapAsync(this);
radiusLabel = findViewById(R.id.location_pref_dlg_radius_seekbar_label);
SeekBar radiusSeekBar = findViewById(R.id.location_pref_dlg_radius_seekbar);
radiusSeekBar.setProgress(Math.round(geofence._radius / (float) 20.0) - 1);
radiusSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
geofence._radius = (progress + 1) * 20;
updateEditedMarker(false);
// Log.d("LocationGeofenceEditorActivity.onProgressChanged", "radius="+geofence._radius);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
geofenceNameEditText = findViewById(R.id.location_editor_geofence_name);
geofenceNameEditText.setText(geofence._name);
addressText = findViewById(R.id.location_editor_address_text);
okButton = findViewById(R.id.location_editor_ok);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = geofenceNameEditText.getText().toString();
if ((!name.isEmpty()) && (mLocation != null)) {
geofence._name = name;
geofence._latitude = mLocation.getLatitude();
geofence._longitude = mLocation.getLongitude();
if (geofenceId > 0) {
DatabaseHandler.getInstance(getApplicationContext()).updateGeofence(geofence);
} else {
DatabaseHandler.getInstance(getApplicationContext()).addGeofence(geofence);
/*synchronized (PPApplication.geofenceScannerMutex) {
// start location updates
if ((PhoneProfilesService.instance != null) && PhoneProfilesService.isGeofenceScannerStarted())
PhoneProfilesService.getGeofencesScanner().connectForResolve();
}*/
}
DatabaseHandler.getInstance(getApplicationContext()).checkGeofence(String.valueOf(geofence._id), 1);
Intent returnIntent = new Intent();
returnIntent.putExtra(LocationGeofencePreference.EXTRA_GEOFENCE_ID, geofence._id);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
}
});
Button cancelButton = findViewById(R.id.location_editor_cancel);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent returnIntent = new Intent();
setResult(Activity.RESULT_CANCELED, returnIntent);
finish();
}
});
AppCompatImageButton myLocationButton = findViewById(R.id.location_editor_my_location);
myLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mLastLocation != null)
mLocation = new Location(mLastLocation);
refreshActivity(true);
}
});
addressButton = findViewById(R.id.location_editor_address_btn);
addressButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getGeofenceAddress();
}
});
}
use of com.google.android.gms.common.api.GoogleApiClient in project connect-sdk-client-android by Ingenico-ePayments.
the class AndroidPayUtil method isAndroidPayAllowed.
private static boolean isAndroidPayAllowed(Collection<Integer> networks, Context context, C2sCommunicator communicator) {
GoogleApiClient client = new GoogleApiClient.Builder(context).addApi(Wallet.API, new Wallet.WalletOptions.Builder().setEnvironment(getWalletEnvironment(communicator)).build()).build();
client.connect();
IsReadyToPayRequest request = createIsReadyToPayRequest(networks);
PendingResult<BooleanResult> result = Wallet.Payments.isReadyToPay(client, request);
BooleanResult actualResult = result.await(Constants.ACCEPTABLE_WAIT_TIME_IN_MILISECONDS, TimeUnit.MILLISECONDS);
if (actualResult.getStatus().isSuccess()) {
return actualResult.getValue();
} else {
Log.e(TAG, "Error while making isReadyToPay call: " + actualResult.getStatus());
return false;
}
}
use of com.google.android.gms.common.api.GoogleApiClient in project CodenameOne by codenameone.
the class GoogleImpl method getClient.
private GoogleApiClient getClient(SuccessCallback<GoogleApiClient> onConnected) {
if (mGoogleApiClient == null) {
Context ctx = AndroidNativeUtil.getContext();
if (mGoogleApiClient == null) {
GoogleSignInOptions gso;
if (clientId != null && clientSecret != null) {
System.out.println("Generating GoogleSignIn for clientID=" + clientId);
List<Scope> includeScopes = new ArrayList<Scope>();
Scope firstScope = new Scope(Scopes.PROFILE);
if (scope != null) {
for (String str : Util.split(scope, " ")) {
if ("profile".equals(str)) {
// str = Scopes.PROFILE;
continue;
} else if ("email".equals(str)) {
str = Scopes.EMAIL;
} else if (Scopes.PROFILE.equals(str)) {
continue;
}
if (str.trim().isEmpty()) {
continue;
}
includeScopes.add(new Scope(str.trim()));
}
}
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(clientId).requestScopes(firstScope, includeScopes.toArray(new Scope[includeScopes.size()])).requestServerAuthCode(clientId).build();
} else {
System.out.println("Generating GoogleSignIn without ID token");
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build();
}
mGoogleApiClient = new GoogleApiClient.Builder(ctx).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
}
}
if (mGoogleApiClient.isConnected()) {
if (onConnected != null) {
onConnected.onSucess(mGoogleApiClient);
}
} else {
synchronized (onConnectedCallbacks) {
if (onConnected != null) {
onConnectedCallbacks.add(onConnected);
}
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);
}
}
}
return mGoogleApiClient;
}
use of com.google.android.gms.common.api.GoogleApiClient in project wire-android by wireapp.
the class LocationFragment method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isGooglePlayServicesAvailable()) {
googleApiClient = new GoogleApiClient.Builder(getContext()).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
googleApiClient.connect();
} else {
locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
}
mainHandler = new Handler();
handlerThread = new HandlerThread("Background handler");
handlerThread.start();
backgroundHandler = new Handler(handlerThread.getLooper());
geocoder = new Geocoder(getContext(), Locale.getDefault());
zoom = true;
// retrieve the accent color to be used for the paint
accentColor = AccentColor.defaultColor().color();
((BaseActivity) getContext()).injectJava(AccentColorController.class).accentColorForJava(new AccentColorCallback() {
@Override
public void color(AccentColor color) {
selectedLocationPin.setTextColor(color.color());
marker = null;
accentColor = color.color();
}
}, EventContext.Implicits$.MODULE$.global());
}
use of com.google.android.gms.common.api.GoogleApiClient in project Thesis by bajnax.
the class LeScanActivity method enableLocation.
public void enableLocation() {
if (googleApiClient == null) {
googleApiClient = new GoogleApiClient.Builder(LeScanActivity.this).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
googleApiClient.connect();
}
}).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d("Location error", "Location error " + connectionResult.getErrorCode());
}
}).build();
googleApiClient.connect();
}
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(30 * 1000);
locationRequest.setFastestInterval(5 * 1000);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
builder.setAlwaysShow(true);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
switch(status.getStatusCode()) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
try {
// requesting to enable Bluetooth
status.startResolutionForResult(LeScanActivity.this, REQUEST_ENABLE_LS);
} catch (IntentSender.SendIntentException e) {
// Ignore the error.
}
break;
}
}
});
}
Aggregations