Search in sources :

Example 1 with ReactContext

use of com.facebook.react.bridge.ReactContext in project gl-react-native by ProjectSeptemberInc.

the class GLCanvas method capture.

private void capture() {
    Bitmap capture = createSnapshot();
    ReactContext reactContext = (ReactContext) getContext();
    RCTEventEmitter eventEmitter = reactContext.getJSModule(RCTEventEmitter.class);
    for (CaptureConfig config : captureConfigs) {
        String result = null, error = null;
        boolean isPng = config.type.equals("png");
        boolean isJpeg = !isPng && (config.type.equals("jpg") || config.type.equals("jpeg"));
        boolean isWebm = !isPng && !isJpeg && config.type.equals("webm");
        boolean isBase64 = config.format.equals("base64");
        boolean isFile = !isBase64 && config.format.equals("file");
        Bitmap.CompressFormat compressFormat = isPng ? Bitmap.CompressFormat.PNG : isJpeg ? Bitmap.CompressFormat.JPEG : isWebm ? Bitmap.CompressFormat.WEBP : null;
        int quality = (int) (100 * config.quality);
        if (compressFormat == null) {
            error = "Unsupported capture type '" + config.type + "'";
        } else if (isBase64) {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                capture.compress(compressFormat, quality, baos);
                String frame = "data:image/png;base64," + Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
                baos.close();
                result = frame;
            } catch (Exception e) {
                e.printStackTrace();
                error = "Could not capture as base64: " + e.getMessage();
            }
        } else if (isFile) {
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(config.filePath);
                capture.compress(compressFormat, quality, fileOutputStream);
                fileOutputStream.close();
                result = "file://" + config.filePath;
            } catch (Exception e) {
                e.printStackTrace();
                error = "Could not write file: " + e.getMessage();
            }
        } else {
            error = "Unsupported capture format '" + config.format + "'";
        }
        WritableMap response = Arguments.createMap();
        response.putMap("config", config.toMap());
        if (error != null)
            response.putString("error", error);
        if (result != null)
            response.putString("result", result);
        eventEmitter.receiveEvent(getId(), "captureFrame", response);
    }
    captureConfigs = new ArrayList<>();
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) RCTEventEmitter(com.facebook.react.uimanager.events.RCTEventEmitter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GLException(android.opengl.GLException) Bitmap(android.graphics.Bitmap) ReactContext(com.facebook.react.bridge.ReactContext) ThemedReactContext(com.facebook.react.uimanager.ThemedReactContext) FileOutputStream(java.io.FileOutputStream)

Example 2 with ReactContext

use of com.facebook.react.bridge.ReactContext in project gl-react-native by ProjectSeptemberInc.

the class GLCanvas method dispatchOnLoad.

private void dispatchOnLoad() {
    WritableMap event = Arguments.createMap();
    ReactContext reactContext = (ReactContext) getContext();
    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "load", event);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) ReactContext(com.facebook.react.bridge.ReactContext) ThemedReactContext(com.facebook.react.uimanager.ThemedReactContext) RCTEventEmitter(com.facebook.react.uimanager.events.RCTEventEmitter)

Example 3 with ReactContext

use of com.facebook.react.bridge.ReactContext in project gl-react-native by ProjectSeptemberInc.

the class GLCanvas method dispatchOnProgress.

private void dispatchOnProgress(double progress, int loaded, int total) {
    WritableMap event = Arguments.createMap();
    event.putDouble("progress", Double.isNaN(progress) ? 0.0 : progress);
    event.putInt("loaded", loaded);
    event.putInt("total", total);
    ReactContext reactContext = (ReactContext) getContext();
    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "progress", event);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) ReactContext(com.facebook.react.bridge.ReactContext) ThemedReactContext(com.facebook.react.uimanager.ThemedReactContext) RCTEventEmitter(com.facebook.react.uimanager.events.RCTEventEmitter)

Example 4 with ReactContext

use of com.facebook.react.bridge.ReactContext in project react-native-push-notification by zo0r.

the class RNPushNotification method requestPermissions.

@ReactMethod
public void requestPermissions(String senderID) {
    ReactContext reactContext = getReactApplicationContext();
    Intent GCMService = new Intent(reactContext, RNPushNotificationRegistrationService.class);
    GCMService.putExtra("senderID", senderID);
    reactContext.startService(GCMService);
}
Also used : ReactContext(com.facebook.react.bridge.ReactContext) Intent(android.content.Intent) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 5 with ReactContext

use of com.facebook.react.bridge.ReactContext in project react-native-fbsdk by facebook.

the class RCTLoginButton method init.

public void init() {
    mAccessTokenTracker = new AccessTokenTracker() {

        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            if (currentAccessToken == null) {
                WritableMap event = Arguments.createMap();
                event.putString("type", "logoutFinished");
                ReactContext context = (ReactContext) getContext();
                context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
            }
        }
    };
    this.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", null);
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", false);
            result.putArray("grantedPermissions", Arguments.fromJavaArgs(setToStringArray(loginResult.getRecentlyGrantedPermissions())));
            result.putArray("declinedPermissions", Arguments.fromJavaArgs(setToStringArray(loginResult.getRecentlyDeniedPermissions())));
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }

        @Override
        public void onError(FacebookException error) {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", error.toString());
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", false);
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }

        @Override
        public void onCancel() {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", null);
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", true);
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }
    });
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) WritableMap(com.facebook.react.bridge.WritableMap) ThemedReactContext(com.facebook.react.uimanager.ThemedReactContext) ReactContext(com.facebook.react.bridge.ReactContext) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult)

Aggregations

ReactContext (com.facebook.react.bridge.ReactContext)7 WritableMap (com.facebook.react.bridge.WritableMap)4 ThemedReactContext (com.facebook.react.uimanager.ThemedReactContext)4 RCTEventEmitter (com.facebook.react.uimanager.events.RCTEventEmitter)3 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 GLException (android.opengl.GLException)1 Handler (android.os.Handler)1 AccessToken (com.facebook.AccessToken)1 AccessTokenTracker (com.facebook.AccessTokenTracker)1 FacebookException (com.facebook.FacebookException)1 LoginResult (com.facebook.login.LoginResult)1 ReactApplication (com.facebook.react.ReactApplication)1 ReactInstanceManager (com.facebook.react.ReactInstanceManager)1 ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)1 ReactMethod (com.facebook.react.bridge.ReactMethod)1 UIManagerModule (com.facebook.react.uimanager.UIManagerModule)1 EventDispatcher (com.facebook.react.uimanager.events.EventDispatcher)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1