Search in sources :

Example 11 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-system-setting by c19354837.

the class SystemSetting method listenVolume.

private void listenVolume(final ReactApplicationContext reactContext) {
    volumeBR = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("android.media.VOLUME_CHANGED_ACTION")) {
                WritableMap para = Arguments.createMap();
                para.putDouble("value", getNormalizationVolume(VOL_MUSIC));
                para.putDouble(VOL_VOICE_CALL, getNormalizationVolume(VOL_VOICE_CALL));
                para.putDouble(VOL_SYSTEM, getNormalizationVolume(VOL_SYSTEM));
                para.putDouble(VOL_RING, getNormalizationVolume(VOL_RING));
                para.putDouble(VOL_MUSIC, getNormalizationVolume(VOL_MUSIC));
                para.putDouble(VOL_ALARM, getNormalizationVolume(VOL_ALARM));
                para.putDouble(VOL_NOTIFICATION, getNormalizationVolume(VOL_NOTIFICATION));
                reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("EventVolume", para);
            }
        }
    };
    filter = new IntentFilter("android.media.VOLUME_CHANGED_ACTION");
    reactContext.registerReceiver(volumeBR, filter);
}
Also used : Context(android.content.Context) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) DeviceEventManagerModule(com.facebook.react.modules.core.DeviceEventManagerModule) IntentFilter(android.content.IntentFilter) WritableMap(com.facebook.react.bridge.WritableMap) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 12 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-camera by react-native-community.

the class CameraModule method stopRecording.

@ReactMethod
public void stopRecording(final int viewTag) {
    final ReactApplicationContext context = getReactApplicationContext();
    UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {

        @Override
        public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
            final RNCameraView cameraView;
            try {
                cameraView = (RNCameraView) nativeViewHierarchyManager.resolveView(viewTag);
                if (cameraView.isCameraOpened()) {
                    cameraView.stopRecording();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 13 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-camera by react-native-community.

the class CameraModule method getSupportedRatios.

@ReactMethod
public void getSupportedRatios(final int viewTag, final Promise promise) {
    final ReactApplicationContext context = getReactApplicationContext();
    UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {

        @Override
        public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
            final RNCameraView cameraView;
            try {
                cameraView = (RNCameraView) nativeViewHierarchyManager.resolveView(viewTag);
                WritableArray result = Arguments.createArray();
                if (cameraView.isCameraOpened()) {
                    Set<AspectRatio> ratios = cameraView.getSupportedAspectRatios();
                    for (AspectRatio ratio : ratios) {
                        result.pushString(ratio.toString());
                    }
                    promise.resolve(result);
                } else {
                    promise.reject("E_CAMERA_UNAVAILABLE", "Camera is not running");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) AspectRatio(com.google.android.cameraview.AspectRatio) Set(java.util.Set) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) WritableArray(com.facebook.react.bridge.WritableArray) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 14 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-camera by react-native-community.

the class CameraModule method takePicture.

@ReactMethod
public void takePicture(final ReadableMap options, final int viewTag, final Promise promise) {
    final ReactApplicationContext context = getReactApplicationContext();
    final File cacheDirectory = mScopedContext.getCacheDirectory();
    UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {

        @Override
        public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
            RNCameraView cameraView = (RNCameraView) nativeViewHierarchyManager.resolveView(viewTag);
            try {
                if (!Build.FINGERPRINT.contains("generic")) {
                    if (cameraView.isCameraOpened()) {
                        cameraView.takePicture(options, promise, cacheDirectory);
                    } else {
                        promise.reject("E_CAMERA_UNAVAILABLE", "Camera is not running");
                    }
                } else {
                    Bitmap image = RNCameraViewHelper.generateSimulatorPhoto(cameraView.getWidth(), cameraView.getHeight());
                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    image.compress(Bitmap.CompressFormat.JPEG, 100, stream);
                    new ResolveTakenPictureAsyncTask(stream.toByteArray(), promise, options, cacheDirectory).execute();
                }
            } catch (Exception e) {
                promise.reject("E_CAMERA_BAD_VIEWTAG", "takePictureAsync: Expected a Camera component");
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) Bitmap(android.graphics.Bitmap) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) File(java.io.File) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager) ResolveTakenPictureAsyncTask(org.reactnative.camera.tasks.ResolveTakenPictureAsyncTask) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 15 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-fbads by callstack.

the class NativeAdManager method sendAppEvent.

/**
 * Helper for sending events back to Javascript.
 *
 * @param eventName
 * @param params
 */
private void sendAppEvent(String eventName, Object params) {
    ReactApplicationContext context = this.getReactApplicationContext();
    if (context == null || !context.hasActiveCatalystInstance()) {
        return;
    }
    context.getJSModule(RCTNativeAppEventEmitter.class).emit(eventName, params);
}
Also used : RCTNativeAppEventEmitter(com.facebook.react.modules.core.RCTNativeAppEventEmitter) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext)

Aggregations

ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)21 ReactMethod (com.facebook.react.bridge.ReactMethod)10 ReactInstanceManager (com.facebook.react.ReactInstanceManager)5 Intent (android.content.Intent)4 Handler (android.os.Handler)4 InterstitialAd (com.facebook.ads.InterstitialAd)4 ReactContext (com.facebook.react.bridge.ReactContext)4 NativeViewHierarchyManager (com.facebook.react.uimanager.NativeViewHierarchyManager)4 UIBlock (com.facebook.react.uimanager.UIBlock)4 UIManagerModule (com.facebook.react.uimanager.UIManagerModule)4 ReactApplication (com.facebook.react.ReactApplication)3 WritableMap (com.facebook.react.bridge.WritableMap)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 IntentFilter (android.content.IntentFilter)2 NativeAdsManager (com.facebook.ads.NativeAdsManager)2 RCTNativeAppEventEmitter (com.facebook.react.modules.core.RCTNativeAppEventEmitter)2 File (java.io.File)2 Activity (android.app.Activity)1 Bitmap (android.graphics.Bitmap)1