Java Code Examples for com.facebook.react.modules.core.DeviceEventManagerModule

The following examples show how to use com.facebook.react.modules.core.DeviceEventManagerModule. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: react-native-tus-client   Source File: RNTusClientModule.java    License: MIT License 6 votes vote down vote up
protected void makeAttempt() throws ProtocolException, IOException {
  uploader = client.resumeOrCreateUpload(upload);
  uploader.setChunkSize(1024);
  uploader.setRequestPayloadSize(10 * 1024 * 1024);

  do {
    long totalBytes = upload.getSize();
    long bytesUploaded = uploader.getOffset();
    WritableMap params = Arguments.createMap();
    params.putString("uploadId", uploadId);
    params.putDouble("bytesWritten", bytesUploaded);
    params.putDouble("bytesTotal", totalBytes);
    reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(ON_PROGRESS, params);
  }while(uploader.uploadChunk() > -1 && !shouldFinish);

  uploader.finish();
}
 
Example 2
Source Project: react-native-GPay   Source File: NativeAnimatedModule.java    License: MIT License 6 votes vote down vote up
@ReactMethod
public void startListeningToAnimatedNodeValue(final int tag) {
  final AnimatedNodeValueListener listener = new AnimatedNodeValueListener() {
    public void onValueUpdate(double value) {
      WritableMap onAnimatedValueData = Arguments.createMap();
      onAnimatedValueData.putInt("tag", tag);
      onAnimatedValueData.putDouble("value", value);
      getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
          .emit("onAnimatedValueUpdate", onAnimatedValueData);
    }
  };

  mOperations.add(new UIThreadOperation() {
    @Override
    public void execute(NativeAnimatedNodesManager animatedNodesManager) {
      animatedNodesManager.startListeningToAnimatedNodeValue(tag, listener);
    }
  });
}
 
Example 3
Source Project: react-native-android-sms-listener   Source File: SmsReceiver.java    License: MIT License 6 votes vote down vote up
private void receiveMessage(SmsMessage message) {
    if (mContext == null) {
        return;
    }

    if (! mContext.hasActiveCatalystInstance()) {
        return;
    }

    Log.d(
        SmsListenerPackage.TAG,
        String.format("%s: %s", message.getOriginatingAddress(), message.getMessageBody())
    );

    WritableNativeMap receivedMessage = new WritableNativeMap();

    receivedMessage.putString("originatingAddress", message.getOriginatingAddress());
    receivedMessage.putString("body", message.getMessageBody());

    mContext
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit(EVENT, receivedMessage);
}
 
Example 4
@ReactMethod
public void lockToLandscape() {
    final Activity activity = getCurrentActivity();
    if (activity == null) return;
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    isLocked = true;

    // force send an UI orientation event
    lastOrientationValue = "LANDSCAPE-LEFT";
    WritableMap params = Arguments.createMap();
    params.putString("orientation", lastOrientationValue);
    if (ctx.hasActiveCatalystInstance()) {
        ctx
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit("orientationDidChange", params);
    }

    // send a locked event
    WritableMap lockParams = Arguments.createMap();
    lockParams.putString("orientation", lastOrientationValue);
    if (ctx.hasActiveCatalystInstance()) {
        ctx
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit("lockDidChange", lockParams);
    }
}
 
Example 5
@ReactMethod
public void lockToLandscapeLeft() {
    final Activity activity = getCurrentActivity();
    if (activity == null) return;
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    isLocked = true;

    // force send an UI orientation event
    lastOrientationValue = "LANDSCAPE-LEFT";
    WritableMap params = Arguments.createMap();
    params.putString("orientation", lastOrientationValue);
    if (ctx.hasActiveCatalystInstance()) {
        ctx
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit("orientationDidChange", params);
    }

    // send a locked event
    WritableMap lockParams = Arguments.createMap();
    lockParams.putString("orientation", lastOrientationValue);
    if (ctx.hasActiveCatalystInstance()) {
        ctx
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit("lockDidChange", lockParams);
    }
}
 
Example 6
@ReactMethod
public void lockToLandscapeRight() {
    final Activity activity = getCurrentActivity();
    if (activity == null) return;
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
    isLocked = true;

    // force send an UI orientation event
    lastOrientationValue = "LANDSCAPE-RIGHT";
    WritableMap params = Arguments.createMap();
    params.putString("orientation", lastOrientationValue);
    if (ctx.hasActiveCatalystInstance()) {
        ctx
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit("orientationDidChange", params);
    }

    // send a locked event
    WritableMap lockParams = Arguments.createMap();
    lockParams.putString("orientation", lastOrientationValue);
    if (ctx.hasActiveCatalystInstance()) {
        ctx
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit("lockDidChange", lockParams);
    }
}
 
Example 7
@Override
public void onError(TwilioAccessManager twilioAccessManager, String s) {
    WritableMap params = Arguments.createMap();
    params.putString("error",s);
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit("accessManager:tokenExpired",params);
}
 
Example 8
Source Project: react-native-sound-player   Source File: RNSoundPlayerModule.java    License: MIT License 5 votes vote down vote up
private void sendEvent(ReactApplicationContext reactContext,
                     String eventName,
                     @Nullable WritableMap params) {
  reactContext
      .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
      .emit(eventName, params);
}
 
Example 9
Source Project: react-native-tapjoy   Source File: MyTJEarnedCurrencyListener.java    License: MIT License 5 votes vote down vote up
@Override
public void onEarnedCurrency(final String currencyName, final int amount) {
    final WritableMap responseMap = Arguments.createMap();

    responseMap.putString(TapjoyModule.EARNED_CURRENCY_NAME, currencyName);
    responseMap.putInt(TapjoyModule.EARNED_CURRENCY_VALUE, amount);

    reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(TapjoyModule.Events.EVENT_PLACEMENT_EARNED_CURRENCY.toString(), responseMap);
}
 
Example 10
Source Project: dingo   Source File: PIPVideoPlayerModule.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static void sendEvent(ReactContext reactContext,
                        String eventName,
                        WritableMap params) {

    reactContext
    .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
    .emit(eventName, params);
}
 
Example 11
@Override
public void onFaceDetection(Camera.Face[] faces, Camera camera) {
    if (faces.length > 0) {
        Matrix matrix = new Matrix();
        boolean frontCamera = (getCameraType() == RCTCameraModule.RCT_CAMERA_TYPE_FRONT);

        int height = getHeight();
        int width = getWidth();

        matrix.setScale(frontCamera ? -1 : 1, 1);
        matrix.postRotate(RCTCamera.getInstance().getOrientation());
        matrix.postScale(width / 2000f, height / 2000f);
        matrix.postTranslate(width / 2f, height / 2f);

        double pixelDensity = getPixelDensity();

        for (Camera.Face face : faces) {
            RectF faceRect = new RectF(face.rect);
            matrix.mapRect(faceRect);

            WritableMap faceEvent;
            faceEvent = Arguments.createMap();
            faceEvent.putInt("faceID", face.id);
            faceEvent.putBoolean("isFrontCamera", frontCamera);

            faceEvent.putDouble("x", faceRect.left / pixelDensity);
            faceEvent.putDouble("y", faceRect.top / pixelDensity);
            faceEvent.putDouble("h", faceRect.height() / pixelDensity);
            faceEvent.putDouble("w", faceRect.width() / pixelDensity);

            ((ReactContext) getContext()).getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                    .emit("CameraFaceDetected", faceEvent);
        }
    }
}
 
Example 12
Source Project: react-native-sms-retriever   Source File: SmsBroadcastReceiver.java    License: MIT License 5 votes vote down vote up
private void emitJSEvent(@NonNull final String key, final String message) {
    if (mContext == null) {
        return;
    }

    if (!mContext.hasActiveCatalystInstance()) {
        return;
    }

    WritableNativeMap map = new WritableNativeMap();
    map.putString(key, message);

    mContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(SMS_EVENT, map);
}
 
Example 13
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
    return Arrays.asList(
            DeviceEventManagerModule.RCTDeviceEventEmitter.class,
            JSTimersExecution.class,
            RCTEventEmitter.class,
            RCTNativeAppEventEmitter.class,
            com.facebook.react.bridge.Systrace.class,
            JSCHeapCapture.HeapCapture.class
    );
}
 
Example 14
Source Project: imsdk-android   Source File: RNContactsFragment.java    License: MIT License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       @Nullable WritableMap params) {
    try {
        reactContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    } catch (Exception _ex) {
        // null bridge
    }
}
 
Example 15
Source Project: imsdk-android   Source File: RNMineFragment.java    License: MIT License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       @Nullable WritableMap params) {
    try {
        reactContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    } catch (Exception _ex) {
        // null bridge
    }
}
 
Example 16
/**
 * Set the application orientation
 */
private void setApplicationOrientation(int rotation) {

    if(rotation>3||rotation<1)rotation = 0;

    switch ((getApplicationOrientationAsNumber() + rotation) % 4) {
        case 0:
            mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        case 1:
            mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            break;
        case 2:
            mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
            break;
        case 3:
            mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            break;
    }

    WritableNativeMap data = getDataMap();
    try {
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit("orientationDidChange", data);
    } catch (RuntimeException e) {
        Log.e("ERROR ", "java.lang.RuntimeException: Trying to invoke JS before CatalystInstance has been set!");
    }

}
 
Example 17
Source Project: react-native-lanscan   Source File: LANScanModule.java    License: MIT License 5 votes vote down vote up
protected void sendEvent(ReactContext reactContext,
                         String eventName,
                         @Nullable Object params) {
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(eventName, params);
    //Log.wtf("EVENT : ", "TRIGGERED EVENT " + eventName);
}
 
Example 18
Source Project: aurora-imui   Source File: AuroraIMUIModule.java    License: MIT License 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(LoadedEvent event) {
    Log.d(REACT_MSG_LIST_MODULE, "Message did load");
    if (event.getAction().equals(RCT_MESSAGE_LIST_LOADED_ACTION)) {
        getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(MESSAGE_LIST_DID_LOAD_EVENT, null);
    }
}
 
Example 19
private void sendEvent(String status, String message) {
  WritableMap params = Arguments.createMap();
  params.putString("status", status);
  params.putString("message", message);
  reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
    .emit("FINGERPRINT_IDENTIFY_STATUS", params);
}
 
Example 20
public void onResume(final Activity activity) {
    // SEE: https://docs.pusher.com/beams/reference/android
    Log.i("PUSHER_WRAPPER", "onResume subscribing with activity " + getActivityName(activity));
    System.out.print("onResume subscribing with activity " + getActivityName(activity));

    PushNotifications.setOnMessageReceivedListenerForVisibleActivity(
            activity,
            new PushNotificationReceivedListener() {
                @Override
                public void onMessageReceived(RemoteMessage remoteMessage) {
                    // Arguments.createMap seems to be for testing
                    // see:
                    // https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/bridge/WritableNativeMap.java#L16
                    // WritableMap map = Arguments.createMap();
                    final WritableMap map = new WritableNativeMap();
                    RemoteMessage.Notification notification = remoteMessage.getNotification();

                    if (notification != null) {
                        map.putString("body", notification.getBody());
                        map.putString("title", notification.getTitle());
                        map.putString("tag", notification.getTag());
                        map.putString("click_action", notification.getClickAction());
                        map.putString("icon", notification.getIcon());
                        map.putString("color", notification.getColor());
                        // map.putString("link", notification.getLink());

                        context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                                .emit(notificationEvent, map);
                        // System.out.print(remoteMessage.toString());
                        Log.d("PUSHER_WRAPPER", "Notification received: " + notification.toString());
                    } else {
                        Log.d("PUSHER_WRAPPER", "No notification received");
                    }
                }
            });
}
 
Example 21
Source Project: react-native-flurry-sdk   Source File: FlurryModule.java    License: Apache License 2.0 5 votes vote down vote up
private void sendEvent(EventType type, String key, boolean value) {
    WritableMap params = Arguments.createMap();
    params.putString("Type", type.getName());
    if (key != null) {
        params.putBoolean(key, value);
    }

    sReactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(FLURRY_CONFIG_EVENT, params);
}
 
Example 22
Source Project: react-native-firestack   Source File: FirestackUtils.java    License: MIT License 5 votes vote down vote up
/**
* send a JS event
**/
public static void sendEvent(final ReactContext context,
  final String eventName,
  final WritableMap params) {
  if (context.hasActiveCatalystInstance()) {
    context
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit(eventName, params);
  } else {
    Log.d(TAG, "Waiting for CatalystInstance before sending event");
  }
}
 
Example 23
Source Project: react-native-flurry-sdk   Source File: FlurryModule.java    License: Apache License 2.0 5 votes vote down vote up
private static void sendEvent(EventType type, String token) {
    WritableMap params = Arguments.createMap();
    params.putString("Type", type.getName());
    params.putString("Token", token);

    sReactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(FLURRY_MESSAGING_EVENT, params);
}
 
Example 24
Source Project: react-native-file-viewer   Source File: RNFileViewerModule.java    License: MIT License 5 votes vote down vote up
private void sendEvent(String eventName, Integer currentId, String errorMessage) {
  WritableMap params = Arguments.createMap();
  params.putInt("id", currentId);
  if(errorMessage != null) {
    params.putString("error", errorMessage);
  }
  reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
    .emit(eventName, params);
}
 
Example 25
Source Project: opentok-react-native   Source File: OTSessionManager.java    License: MIT License 5 votes vote down vote up
private void sendEventWithString(ReactContext reactContext, String eventName, String eventString) {

        if (Utils.contains(jsEvents, eventName) || Utils.contains(componentEvents, eventName)) {
            reactContext
                    .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                    .emit(eventName, eventString);
        }
    }
 
Example 26
@Override
public void returnPictureTakenResult(String resultType, String resultMessage) {
    WritableMap params = Arguments.createMap();
    params.putString("type", resultType);
    params.putString("message", resultMessage);
    mContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit("cameraResult", params);
}
 
Example 27
Source Project: react-native-zip-archive   Source File: RNZipArchiveModule.java    License: MIT License 5 votes vote down vote up
protected void updateProgress(long extractedBytes, long totalSize, String zipFilePath) {
  // Ensure progress can't overflow 1
  double progress = Math.min((double) extractedBytes / (double) totalSize, 1);
  Log.d(TAG, String.format("updateProgress: %.0f%%", progress * 100));

  WritableMap map = Arguments.createMap();
  map.putString(EVENT_KEY_FILENAME, zipFilePath);
  map.putDouble(EVENT_KEY_PROGRESS, progress);
  getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
          .emit(PROGRESS_EVENT_NAME, map);
}
 
Example 28
Source Project: react-native-workers   Source File: RNWorkersModule.java    License: Apache License 2.0 5 votes vote down vote up
@ReactMethod
public void sendMessageToWorker(final int port, final String message) {
    final ReactApplicationContext context = RNWorkersManager.getInstance().getWorkerReactContext(port);
    if (context == null) {
        return;
    }

    context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit("RNWorkers", message);
}
 
Example 29
Source Project: react-native-tapjoy   Source File: MyTJPlacementListener.java    License: MIT License 5 votes vote down vote up
private void fireEvent(String eventName, WritableMap resp) {
    if (reactContext.hasActiveCatalystInstance()) {
        reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, resp);
    } else {
        Log.d(TAG, "Waiting for CatalystInstance before sending event.");
    }
}
 
Example 30
Source Project: react-native-GPay   Source File: AccessibilityInfoModule.java    License: MIT License 5 votes vote down vote up
private void updateAndSendChangeEvent(boolean enabled) {
    if (mEnabled != enabled) {
        mEnabled = enabled;
        getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(EVENT_NAME, mEnabled);
    }
}