use of com.google.android.gms.common.api.Status in project react-native-google-places by tolu360.
the class RNGooglePlacesModule method getAutocompletePredictions.
@ReactMethod
public void getAutocompletePredictions(String query, ReadableMap options, final Promise promise) {
String type = options.getString("type");
String country = options.getString("country");
country = country.isEmpty() ? null : country;
double latitude = options.getDouble("latitude");
double longitude = options.getDouble("longitude");
double radius = options.getDouble("radius");
LatLng center = new LatLng(latitude, longitude);
LatLngBounds bounds = null;
if (latitude != 0 && longitude != 0 && radius != 0) {
bounds = this.getLatLngBounds(center, radius);
}
PendingResult<AutocompletePredictionBuffer> results = Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, query, bounds, getFilterType(type, country));
AutocompletePredictionBuffer autocompletePredictions = results.await(60, TimeUnit.SECONDS);
final Status status = autocompletePredictions.getStatus();
if (status.isSuccess()) {
if (autocompletePredictions.getCount() == 0) {
WritableArray emptyResult = Arguments.createArray();
autocompletePredictions.release();
promise.resolve(emptyResult);
return;
}
WritableArray predictionsList = Arguments.createArray();
for (AutocompletePrediction prediction : autocompletePredictions) {
WritableMap map = Arguments.createMap();
map.putString("fullText", prediction.getFullText(null).toString());
map.putString("primaryText", prediction.getPrimaryText(null).toString());
map.putString("secondaryText", prediction.getSecondaryText(null).toString());
map.putString("placeID", prediction.getPlaceId().toString());
if (prediction.getPlaceTypes() != null) {
List<String> types = new ArrayList<>();
for (Integer placeType : prediction.getPlaceTypes()) {
types.add(findPlaceTypeLabelByPlaceTypeId(placeType));
}
map.putArray("types", Arguments.fromArray(types.toArray(new String[0])));
}
predictionsList.pushMap(map);
}
// Release the buffer now that all data has been copied.
autocompletePredictions.release();
promise.resolve(predictionsList);
} else {
Log.i(TAG, "Error making autocomplete prediction API call: " + status.toString());
autocompletePredictions.release();
promise.reject("E_AUTOCOMPLETE_ERROR", new Error("Error making autocomplete prediction API call: " + status.toString()));
return;
}
}
use of com.google.android.gms.common.api.Status in project react-native-google-places by tolu360.
the class RNGooglePlacesModule method onActivityResult.
/**
* Called after the autocomplete activity has finished to return its result.
*/
@Override
public void onActivityResult(Activity activity, final int requestCode, final int resultCode, final Intent data) {
// Check that the result was from the autocomplete widget.
if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
// Get the user's selected place from the Intent.
Place place = PlaceAutocomplete.getPlace(this.reactContext.getApplicationContext(), data);
Log.i(TAG, "Place Selected: " + place.getName());
WritableMap map = propertiesMapForPlace(place);
resolvePromise(map);
} else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
Status status = PlaceAutocomplete.getStatus(this.reactContext.getApplicationContext(), data);
Log.e(TAG, "Error: Status = " + status.toString());
rejectPromise("E_RESULT_ERROR", new Error(status.toString()));
} else if (resultCode == Activity.RESULT_CANCELED) {
// Indicates that the activity closed before a selection was made. For example if
// the user pressed the back button.
rejectPromise("E_USER_CANCELED", new Error("Search cancelled"));
}
}
if (requestCode == PLACE_PICKER_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
Place place = PlacePicker.getPlace(this.reactContext.getApplicationContext(), data);
Log.i(TAG, "Place Selected: " + place.getName());
WritableMap map = propertiesMapForPlace(place);
resolvePromise(map);
}
}
}
use of com.google.android.gms.common.api.Status in project hypertrack-live-android by hypertrack.
the class ActionManager method addGeofencingRequest.
public void addGeofencingRequest() {
if (geofencingRequest == null) {
return;
}
if (this.mGoogleAPIClient == null || !this.mGoogleAPIClient.isConnected()) {
this.addGeofencingRequest = true;
setupGoogleAPIClient();
return;
}
try {
Intent geofencingIntent = new Intent(mContext, GeofenceTransitionsIntentService.class);
mGeofencePendingIntent = PendingIntent.getService(mContext, 0, geofencingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
LocationServices.GeofencingApi.addGeofences(mGoogleAPIClient, geofencingRequest, mGeofencePendingIntent).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
HyperLog.i(TAG, "Geofence set at Expected Place");
addGeofencingRequest = false;
} else {
HyperLog.e(TAG, "Geofence error at Expected Place" + status.getStatusMessage());
addGeofencingRequest = true;
}
}
});
} catch (Exception exception) {
HyperLog.e(TAG, "Geofence error at Expected Place" + exception.getMessage());
CrashlyticsWrapper.log(exception);
}
}
use of com.google.android.gms.common.api.Status in project android_packages_apps_GmsCore by microg.
the class SafetyNetClientServiceImpl method attestWithApiKey.
@Override
public void attestWithApiKey(final ISafetyNetCallbacks callbacks, final byte[] nonce, String apiKey) throws RemoteException {
if (nonce == null) {
callbacks.onAttestationData(new Status(CommonStatusCodes.DEVELOPER_ERROR), null);
return;
}
if (!SafetyNetPrefs.get(context).isEnabled()) {
Log.d(TAG, "ignoring SafetyNet request, it's disabled");
callbacks.onAttestationData(Status.CANCELED, null);
return;
}
new Thread(new Runnable() {
@Override
public void run() {
try {
try {
attestation.buildPayload(nonce);
RemoteDroidGuardConnector conn = new RemoteDroidGuardConnector(context);
Bundle bundle = new Bundle();
bundle.putString("contentBinding", attestation.getPayloadHashBase64());
RemoteDroidGuardConnector.Result dg = conn.guard("attest", Long.toString(LastCheckinInfo.read(context).androidId), bundle);
if (!SafetyNetPrefs.get(context).isOfficial() || dg != null && dg.getStatusCode() == 0 && dg.getResult() != null) {
if (dg != null && dg.getStatusCode() == 0 && dg.getResult() != null) {
attestation.setDroidGaurdResult(Base64.encodeToString(dg.getResult(), Base64.NO_WRAP + Base64.NO_PADDING + Base64.URL_SAFE));
}
AttestationData data = new AttestationData(attestation.attest());
callbacks.onAttestationData(Status.SUCCESS, data);
} else {
callbacks.onAttestationData(dg == null ? Status.INTERNAL_ERROR : new Status(dg.getStatusCode()), null);
}
} catch (IOException e) {
Log.w(TAG, e);
callbacks.onAttestationData(Status.INTERNAL_ERROR, null);
}
} catch (RemoteException e) {
Log.w(TAG, e);
}
}
}).start();
}
use of com.google.android.gms.common.api.Status in project android_packages_apps_GmsCore by microg.
the class PlacePickerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
resultIntent = new Intent();
place = new PlaceImpl();
setContentView(R.layout.pick_place);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
if (getIntent().hasExtra(EXTRA_PRIMARY_COLOR)) {
toolbar.setBackgroundColor(getIntent().getIntExtra(EXTRA_PRIMARY_COLOR, 0));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
getWindow().setStatusBarColor(getIntent().getIntExtra(EXTRA_PRIMARY_COLOR_DARK, 0));
((TextView) findViewById(R.id.place_picker_title)).setTextColor(getIntent().getIntExtra(EXTRA_PRIMARY_COLOR_DARK, 0));
}
mapView = (BackendMapView) findViewById(R.id.map);
mapView.map().getEventLayer().enableRotation(false);
mapView.map().getEventLayer().enableTilt(false);
mapView.map().events.bind(this);
LatLngBounds latLngBounds = getIntent().getParcelableExtra(LocationConstants.EXTRA_BOUNDS);
if (latLngBounds != null) {
place.viewport = latLngBounds;
MapPosition mp = new MapPosition();
mp.setByBoundingBox(fromLatLngBounds(latLngBounds), mapView.map().getWidth(), mapView.map().getHeight());
mapView.map().getMapPosition(mp);
} else {
if (ActivityCompat.checkSelfPermission(PlacePickerActivity.this, ACCESS_FINE_LOCATION) != PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PlacePickerActivity.this, new String[] { ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION }, 0);
} else {
updateMapFromLocationManager();
}
}
findViewById(R.id.place_picker_select).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resultIntent.putExtra(LocationConstants.EXTRA_STATUS, SafeParcelUtil.asByteArray(new Status(CommonStatusCodes.SUCCESS)));
resultIntent.putExtra(LocationConstants.EXTRA_PLACE, SafeParcelUtil.asByteArray(place));
resultIntent.putExtra(LocationConstants.EXTRA_FINAL_BOUNDS, SafeParcelUtil.asByteArray(place.viewport));
setResult(RESULT_OK, resultIntent);
finish();
}
});
}
Aggregations