Example usage for com.facebook.react.bridge Callback invoke

List of usage examples for com.facebook.react.bridge Callback invoke

Introduction

In this page you can find the example usage for com.facebook.react.bridge Callback invoke.

Prototype

public void invoke(Object... args);

Source Link

Document

Schedule javascript function execution represented by this Callback instance

Usage

From source file:com.reactnative.googlefit.GoogleFitModule.java

License:Open Source License

@ReactMethod
public void saveWeight(ReadableMap weightSample, Callback errorCallback, Callback successCallback) {

    try {/*from w ww . ja va 2s .c o  m*/
        successCallback.invoke(googleFitManager.getWeightsHistory().saveWeight(weightSample));
    } catch (IllegalViewOperationException e) {
        errorCallback.invoke(e.getMessage());
    }
}

From source file:com.reactnativefileintent.RNFileIntentModule.java

License:Open Source License

@ReactMethod
public void queryFileStat(final String uriString, final Callback callback) {
    Uri uri = Uri.parse(uriString);//from  w  ww . j a v  a 2  s .  c om
    WritableMap response = Arguments.createMap();

    ContentResolver cR = mReactContext.getContentResolver();
    Cursor cRCursor = cR.query(uri, null, null, null, null);
    int nameIndex = cRCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
    int sizeIndex = cRCursor.getColumnIndex(OpenableColumns.SIZE);
    cRCursor.moveToFirst();

    response.putString("fileName", cRCursor.getString(nameIndex));
    response.putString("fileSize", Long.toString(cRCursor.getLong(sizeIndex)));
    response.putString("mimeType", cR.getType(uri));
    response.putString("uri", uri.toString());
    callback.invoke(response);

    return;
}

From source file:com.reactnativefileintent.RNFileIntentModule.java

License:Open Source License

@ReactMethod
public void getReceivedFile(final Callback callback) {
    responseArray = Arguments.createArray();
    WritableMap respoonse = Arguments.createMap();
    Intent receivedIntent = getCurrentActivity().getIntent();
    String receivedAction = receivedIntent.getAction();
    String receivedType = receivedIntent.getType();
    ContentResolver cR = mReactContext.getContentResolver();

    if (Intent.ACTION_SEND.equals(receivedAction) && receivedType != null) {
        Uri receivedUri = (Uri) receivedIntent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (receivedUri != null) {
            Cursor cRCursor = cR.query(receivedUri, null, null, null, null);
            int nameIndex = cRCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
            int sizeIndex = cRCursor.getColumnIndex(OpenableColumns.SIZE);
            cRCursor.moveToFirst();//from www .  ja v a 2 s.  c  o m
            WritableMap respMap;
            respMap = Arguments.createMap();
            respMap.putString("action", receivedAction);
            respMap.putString("fileName", cRCursor.getString(nameIndex));
            respMap.putString("fileSize", Long.toString(cRCursor.getLong(sizeIndex)));
            respMap.putString("type", cR.getType(receivedUri));
            respMap.putString("uri", receivedUri.toString());
            responseArray.pushMap(respMap);
            callback.invoke(responseArray);
        } else {
            response.putBoolean("gotNothing", new Boolean("true"));
            callback.invoke(response);
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(receivedAction) && receivedType != null) {
        ArrayList<Uri> receivedUris = receivedIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (receivedUris != null) {
            for (Uri uri : receivedUris) {
                Cursor cRCursor = cR.query(uri, null, null, null, null);
                int nameIndex = cRCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
                int sizeIndex = cRCursor.getColumnIndex(OpenableColumns.SIZE);
                cRCursor.moveToFirst();
                WritableMap respMap;
                respMap = Arguments.createMap();
                respMap.putString("action", receivedAction);
                respMap.putString("fileName", cRCursor.getString(nameIndex));
                respMap.putString("fileSize", Long.toString(cRCursor.getLong(sizeIndex)));
                respMap.putString("type", cR.getType(uri));
                respMap.putString("uri", uri.toString());
                responseArray.pushMap(respMap);
            }
            callback.invoke(responseArray);
        } else {
            response.putBoolean("gotNothing", new Boolean("true"));
            callback.invoke(response);
        }
    } else {
        callback.invoke(responseArray);
    }
    return;
}

From source file:com.reactnativefileintent.RNFileIntentModule.java

License:Open Source License

@ReactMethod
public void requestFile(final String mimeTypeInput, final Callback callback) {
    int requestCode = GET_FILE_BY_MIME;
    Intent libraryIntent;//from  w w  w  .  j  a  v  a2  s  .  c  o m
    Activity currentActivity = getCurrentActivity();

    if (currentActivity == null) {
        response = Arguments.createMap();
        response.putString("error", "Cannot find current Activity");
        callback.invoke(response);
        return;
    }

    mimeType = mimeTypeInput;

    libraryIntent = new Intent(Intent.ACTION_GET_CONTENT);
    libraryIntent.setType(mimeType);

    if (libraryIntent.resolveActivity(mReactContext.getPackageManager()) == null) {
        response = Arguments.createMap();
        response.putString("error", "Failed to resolve intent activity");
        callback.invoke(response);
        return;
    }

    mCallback = callback;

    try {
        currentActivity.startActivityForResult(libraryIntent, requestCode);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        response = Arguments.createMap();
        response.putString("error", "Cannot launch file explorer");
        callback.invoke(response);
    }
}

From source file:com.remobile.cordova.CallbackContext.java

License:Apache License

public void sendPluginResult(PluginResult pluginResult) {
    int messageType = pluginResult.messageType;
    Callback callback = pluginResult.status == PluginResult.Status.OK.ordinal() ? success : error;
    if (callback == null) {
        return;//  w  w  w  .  j a va2 s  .  c  om
    }
    try {
        switch (messageType) {
        case PluginResult.MESSAGE_TYPE_JSON_ARRAY:
            callback.invoke(JsonConvert.jsonToReact(pluginResult.jsonArrayMessage));
            break;
        case PluginResult.MESSAGE_TYPE_JSON_OBJECT:
            callback.invoke(JsonConvert.jsonToReact(pluginResult.jsonObjectMessage));
            break;
        default:
            callback.invoke(pluginResult.strMessage);
            break;
        }
    } catch (JSONException ex) {
        error.invoke("Internal error converting results:" + ex.getMessage());
    }
}

From source file:com.titan.react.CommunicationJavaModule.java

License:Open Source License

@ReactMethod
public void js2NativeCallback(Callback callback) {
    callback.invoke("js2NativeCallback");
}

From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java

@ReactMethod
public void configure(ReadableMap config, final Callback success, final Callback failure) {
    if (configured) {
        return;//from   w  w  w.j a v a 2s  . com
    }

    configured = true;

    BackgroundGeolocation adapter = getAdapter();

    adapter.on(BackgroundGeolocation.EVENT_LOCATION, (new TSCallback() {
        @Override
        public void success(Object o) {
            onLocationChange((JSONObject) o);
        }

        @Override
        public void error(Object o) {
            onLocationError((Integer) o);
        }
    }));

    adapter.on(BackgroundGeolocation.EVENT_MOTIONCHANGE, (new TSCallback() {
        @Override
        public void success(Object o) {
            onMotionChange((JSONObject) o);
        }

        @Override
        public void error(Object o) {

        }
    }));

    adapter.on(BackgroundGeolocation.EVENT_ACTIVITYCHANGE, (new TSCallback() {
        @Override
        public void success(Object o) {
            onActivityChange((String) o);
        }

        @Override
        public void error(Object o) {

        }
    }));

    adapter.on(BackgroundGeolocation.EVENT_HTTP, (new TSCallback() {
        @Override
        public void success(Object o) {
            onHttpResponse((JSONObject) o);
        }

        @Override
        public void error(Object o) {
            onHttpResponse((JSONObject) o);
        }
    }));

    adapter.on(BackgroundGeolocation.EVENT_HEARTBEAT, (new TSCallback() {
        @Override
        public void success(Object o) {
            onHeartbeat((JSONObject) o);
        }

        @Override
        public void error(Object o) {

        }
    }));

    adapter.on(BackgroundGeolocation.EVENT_GEOFENCESCHANGE, (new TSCallback() {
        @Override
        public void success(Object o) {
            onGeofencesChange((JSONObject) o);
        }

        @Override
        public void error(Object o) {
        }
    }));

    adapter.on(BackgroundGeolocation.EVENT_GEOFENCE, (new TSCallback() {
        @Override
        public void success(Object o) {
            onGeofence((JSONObject) o);
        }

        @Override
        public void error(Object o) {

        }
    }));

    adapter.on(BackgroundGeolocation.EVENT_SCHEDULE, (new TSCallback() {
        @Override
        public void success(Object o) {
            onSchedule((JSONObject) o);
        }

        @Override
        public void error(Object o) {

        }
    }));

    adapter.on(BackgroundGeolocation.EVENT_PLAY_SERVICES_CONNECT_ERROR, (new TSCallback() {
        @Override
        public void success(Object o) {
            onPlayServicesConnectError((Integer) o);
        }

        @Override
        public void error(Object o) {

        }
    }));

    adapter.on(BackgroundGeolocation.EVENT_PROVIDERCHANGE, (new TSCallback() {
        @Override
        public void success(Object provider) {
            onProviderChange((JSONObject) provider);
        }

        @Override
        public void error(Object o) {
        }
    }));

    TSCallback callback = new TSCallback() {
        public void success(Object state) {
            success.invoke(getState());
        }

        public void error(Object error) {
            failure.invoke("Unknown error");
        }
    };
    adapter.configure(mapToJson(config), callback);
}

From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java

@ReactMethod
public void start(Callback success, Callback failure) {
    if (startCallback != null) {
        failure.invoke("Waiting for a previous start action to complete");
        return;//  w  w w .  j av  a 2  s .c o m
    }
    startCallback = new HashMap<>();
    startCallback.put("success", success);
    startCallback.put("failure", failure);

    if (hasPermission(ACCESS_COARSE_LOCATION) && hasPermission(ACCESS_FINE_LOCATION)) {
        setEnabled(true);
    } else {
        String[] permissions = { ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION };
        requestPermissions(REQUEST_ACTION_START, permissions);
    }
}

From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java

@ReactMethod
public void startSchedule(Callback success, Callback failure) {
    if (getAdapter().startSchedule()) {
        success.invoke(getState());
    } else {//from   www .  jav a  2 s.  c o m
        failure.invoke("Failed to start schedule.  Did you configure a #schedule?");
    }
}

From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java

@ReactMethod
public void stopSchedule(Callback success, Callback failure) {
    getAdapter().stopSchedule();
    success.invoke(getState());
}