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);
}
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();
}
}
});
}
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();
}
}
});
}
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");
}
}
});
}
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);
}
Aggregations