use of com.facebook.react.bridge.ReactMethod in project react-native-google-places by tolu360.
the class RNGooglePlacesModule method openAutocompleteModal.
/**
* Exposed React's methods
*/
@ReactMethod
public void openAutocompleteModal(ReadableMap options, final Promise promise) {
this.pendingPromise = promise;
String type = options.getString("type");
String country = options.getString("country");
country = country.isEmpty() ? null : country;
boolean useOverlay = options.getBoolean("useOverlay");
double latitude = options.getDouble("latitude");
double longitude = options.getDouble("longitude");
double radius = options.getDouble("radius");
LatLng center = new LatLng(latitude, longitude);
Activity currentActivity = getCurrentActivity();
try {
// The autocomplete activity requires Google Play Services to be available. The intent
// builder checks this and throws an exception if it is not the case.
PlaceAutocomplete.IntentBuilder intentBuilder = new PlaceAutocomplete.IntentBuilder(useOverlay ? PlaceAutocomplete.MODE_OVERLAY : PlaceAutocomplete.MODE_FULLSCREEN);
if (latitude != 0 && longitude != 0 && radius != 0) {
intentBuilder.setBoundsBias(this.getLatLngBounds(center, radius));
}
Intent intent = intentBuilder.setFilter(getFilterType(type, country)).build(currentActivity);
currentActivity.startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);
} catch (GooglePlayServicesRepairableException e) {
// Indicates that Google Play Services is either not installed or not up to date. Prompt
// the user to correct the issue.
GoogleApiAvailability.getInstance().getErrorDialog(currentActivity, e.getConnectionStatusCode(), AUTOCOMPLETE_REQUEST_CODE).show();
} catch (GooglePlayServicesNotAvailableException e) {
// Indicates that Google Play Services is not available and the problem is not easily
// resolvable.
String message = "Google Play Services is not available: " + GoogleApiAvailability.getInstance().getErrorString(e.errorCode);
Log.e(TAG, message);
rejectPromise("E_INTENT_ERROR", new Error("Google Play Services is not available"));
}
}
use of com.facebook.react.bridge.ReactMethod in project react-native-google-places by tolu360.
the class RNGooglePlacesModule method getCurrentPlace.
@ReactMethod
public void getCurrentPlace(final Promise promise) {
PendingResult<PlaceLikelihoodBuffer> results = Places.PlaceDetectionApi.getCurrentPlace(mGoogleApiClient, null);
PlaceLikelihoodBuffer likelyPlaces = results.await(60, TimeUnit.SECONDS);
final Status status = likelyPlaces.getStatus();
if (status.isSuccess()) {
if (likelyPlaces.getCount() == 0) {
WritableArray emptyResult = Arguments.createArray();
likelyPlaces.release();
promise.resolve(emptyResult);
return;
}
WritableArray likelyPlacesList = Arguments.createArray();
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
WritableMap map = propertiesMapForPlace(placeLikelihood.getPlace());
map.putDouble("likelihood", placeLikelihood.getLikelihood());
likelyPlacesList.pushMap(map);
}
// Release the buffer now that all data has been copied.
likelyPlaces.release();
promise.resolve(likelyPlacesList);
} else {
Log.i(TAG, "Error making places detection api call: " + status.getStatusMessage());
likelyPlaces.release();
promise.reject("E_PLACE_DETECTION_API_ERROR", new Error("Error making places detection api call: " + status.getStatusMessage()));
return;
}
}
use of com.facebook.react.bridge.ReactMethod in project react-native-turbolinks by lazaronixon.
the class RNTurbolinksModule method visitTabBar.
@ReactMethod
public void visitTabBar(ReadableArray routes, int selectedIndex) {
Activity act = getCurrentActivity();
Intent intent = new Intent(act, TabbedActivity.class);
intent.putExtra(INTENT_MESSAGE_HANDLER, messageHandler);
intent.putExtra(INTENT_USER_AGENT, userAgent);
intent.putExtra(INTENT_NAVIGATION_BAR_HIDDEN, navigationBarHidden);
intent.putExtra(INTENT_SELECTED_INDEX, selectedIndex);
intent.putExtra(INTENT_INITIAL, true);
intent.putParcelableArrayListExtra(INTENT_ROUTES, Arguments.toList(routes));
initialIntent = intent;
TurbolinksSession.resetDefault();
act.startActivity(intent);
}
use of com.facebook.react.bridge.ReactMethod in project react-native-fbsdk by facebook.
the class FBGraphRequestModule method start.
/**
* Send the batch of requests.
* @param requestBatch
* @param timeout
* @param batchCallback
*/
@ReactMethod
public void start(ReadableArray requestBatch, int timeout, Callback batchCallback) {
GraphRequestBatch batch = new GraphRequestBatch();
int potentialID = 0;
int batchID = 0;
synchronized (this) {
do {
batchID = potentialID++;
} while (mResponses.get(batchID) != null);
mResponses.put(batchID, Arguments.createMap());
}
for (int i = 0; i < requestBatch.size(); i++) {
GraphRequest request = buildRequest(requestBatch.getMap(i));
request.setCallback(new GraphRequestCallback(i, batchID));
batch.add(request);
}
batch.setTimeout(timeout);
GraphRequestBatchCallback callback = new GraphRequestBatchCallback(batchID, batchCallback);
batch.addCallback(callback);
batch.executeAsync();
}
use of com.facebook.react.bridge.ReactMethod in project react-native-fbsdk by facebook.
the class FBLoginManagerModule method setDefaultAudience.
/**
* Set {@link DefaultAudience} to use for sessions that post data to Facebook.
* @param defaultAudienceString must be one of the constants in Enum {@link DefaultAudience}.
* @throws {@link java.lang.IllegalArgumentException} if the argument is not a valid constant.
*/
@ReactMethod
public void setDefaultAudience(String defaultAudienceString) {
DefaultAudience defaultAudience = DefaultAudience.valueOf(defaultAudienceString.toUpperCase());
LoginManager.getInstance().setDefaultAudience(defaultAudience);
}
Aggregations