Search in sources :

Example 26 with ReactMethod

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"));
    }
}
Also used : Activity(android.app.Activity) Intent(android.content.Intent) LatLng(com.google.android.gms.maps.model.LatLng) GooglePlayServicesRepairableException(com.google.android.gms.common.GooglePlayServicesRepairableException) PlaceAutocomplete(com.google.android.gms.location.places.ui.PlaceAutocomplete) GooglePlayServicesNotAvailableException(com.google.android.gms.common.GooglePlayServicesNotAvailableException) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 27 with ReactMethod

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;
    }
}
Also used : Status(com.google.android.gms.common.api.Status) PlaceLikelihoodBuffer(com.google.android.gms.location.places.PlaceLikelihoodBuffer) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) PlaceLikelihood(com.google.android.gms.location.places.PlaceLikelihood) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 28 with ReactMethod

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);
}
Also used : GenericActivity(com.lazaronixon.rnturbolinks.activities.GenericActivity) WebActivity(com.lazaronixon.rnturbolinks.activities.WebActivity) TabbedActivity(com.lazaronixon.rnturbolinks.activities.TabbedActivity) NativeActivity(com.lazaronixon.rnturbolinks.activities.NativeActivity) Activity(android.app.Activity) Intent(android.content.Intent) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 29 with ReactMethod

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();
}
Also used : GraphRequest(com.facebook.GraphRequest) GraphRequestBatch(com.facebook.GraphRequestBatch) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 30 with ReactMethod

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);
}
Also used : DefaultAudience(com.facebook.login.DefaultAudience) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

ReactMethod (com.facebook.react.bridge.ReactMethod)82 Activity (android.app.Activity)21 Intent (android.content.Intent)11 WritableMap (com.facebook.react.bridge.WritableMap)11 Bundle (android.os.Bundle)9 ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)6 WritableArray (com.facebook.react.bridge.WritableArray)6 ArrayList (java.util.ArrayList)5 Camera (android.hardware.Camera)4 NativeViewHierarchyManager (com.facebook.react.uimanager.NativeViewHierarchyManager)4 UIBlock (com.facebook.react.uimanager.UIBlock)4 UIManagerModule (com.facebook.react.uimanager.UIManagerModule)4 ShareContent (com.facebook.share.model.ShareContent)4 LayoutNode (com.reactnativenavigation.options.LayoutNode)4 LoginManager (com.facebook.login.LoginManager)3 ReactActivity (com.facebook.react.ReactActivity)3 LatLng (com.google.android.gms.maps.model.LatLng)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 RemoteException (android.os.RemoteException)2 JSApplicationIllegalArgumentException (com.facebook.react.bridge.JSApplicationIllegalArgumentException)2