use of com.facebook.react.bridge.ReactApplicationContext in project react-native-push-notification by zo0r.
the class RNPushNotificationListenerService method onMessageReceived.
@Override
public void onMessageReceived(String from, final Bundle bundle) {
JSONObject data = getPushData(bundle.getString("data"));
if (data != null) {
if (!bundle.containsKey("message")) {
bundle.putString("message", data.optString("alert", "Notification received"));
}
if (!bundle.containsKey("title")) {
bundle.putString("title", data.optString("title", null));
}
if (!bundle.containsKey("sound")) {
bundle.putString("soundName", data.optString("sound", null));
}
if (!bundle.containsKey("color")) {
bundle.putString("color", data.optString("color", null));
}
final int badge = data.optInt("badge", -1);
if (badge >= 0) {
ApplicationBadgeHelper.INSTANCE.setApplicationIconBadgeNumber(this, badge);
}
}
Log.v(LOG_TAG, "onMessageReceived: " + bundle);
// We need to run this on the main thread, as the React code assumes that is true.
// Namely, DevServerHelper constructs a Handler() without a Looper, which triggers:
// "Can't create handler inside thread that has not called Looper.prepare()"
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
public void run() {
// Construct and load our normal React JS code bundle
ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
ReactContext context = mReactInstanceManager.getCurrentReactContext();
// If it's constructed, send a notification
if (context != null) {
handleRemotePushNotification((ReactApplicationContext) context, bundle);
} else {
// Otherwise wait for construction, then send the notification
mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
public void onReactContextInitialized(ReactContext context) {
handleRemotePushNotification((ReactApplicationContext) context, bundle);
}
});
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
// Construct it in the background
mReactInstanceManager.createReactContextInBackground();
}
}
}
});
}
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");
}
}
});
}
Aggregations