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

The following are top voted examples for showing how to use com.facebook.react.modules.core.DeviceEventManagerModule. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: react-native-libmuse   File: LibMuseModule.java   Source Code and License 8 votes vote down vote up
public void SendEvent(String eventName, Object... args) {
	WritableArray argsList = Arguments.createArray();
	for (Object arg : args) {
		if (arg == null)
			argsList.pushNull();
		else if (arg instanceof Boolean)
			argsList.pushBoolean((Boolean)arg);
		else if (arg instanceof Integer)
			argsList.pushInt((Integer)arg);
		else if (arg instanceof Double)
			argsList.pushDouble((Double)arg);
		else if (arg instanceof String)
			argsList.pushString((String)arg);
		else if (arg instanceof WritableArray)
			argsList.pushArray((WritableArray)arg);
		else {
			//Assert(arg instanceof WritableMap, "Event args must be one of: WritableArray, Boolean")
			if (!(arg instanceof WritableMap))
				throw new RuntimeException("Event args must be one of: Boolean, Integer, Double, String, WritableArray, WritableMap");
			argsList.pushMap((WritableMap)arg);
		}
	}

	DeviceEventManagerModule.RCTDeviceEventEmitter jsModuleEventEmitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
	jsModuleEventEmitter.emit(eventName, argsList);
}
 
Example 2
Project: react-native-system-setting   File: SystemSetting.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 3
Project: react-native-screenshot-detect   File: ScreenShotDetectModule.java   Source Code and License 6 votes vote down vote up
private void handleMediaRowData(String data, long dateTaken, int width, int height) {
    if (checkScreenShot(data, dateTaken, width, height)) {
        Log.d(TAG, "ScreenShot: path = " + data + "; size = " + width + " * " + height
                + "; date = " + dateTaken);
        WritableMap map = Arguments.createMap();

        try {
            map.putString("url", data);
            map.putDouble("timeStamp", dateTaken);
            // TODO 回调方法。
            if (!checkCallback(data)) {

                mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                        .emit(ScreenShotEvent, map);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        // 如果在观察区间媒体数据库有数据改变,又不符合截屏规则,则输出到 log 待分析
        Log.w(TAG, "Media content changed, but not screenshot: path = " + data
                + "; size = " + width + " * " + height + "; date = " + dateTaken);
    }
}
 
Example 4
Project: react-native-connectivity-status   File: RNConnectivityStatusModule.java   Source Code and License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  final String action = intent.getAction();

  if (action != null && action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
    final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
            BluetoothAdapter.ERROR);
    boolean active = false;
    switch (state) {
      case BluetoothAdapter.STATE_OFF:
        active = false;
        break;
      case BluetoothAdapter.STATE_ON:
        active = true;
        break;
    }

    final WritableMap eventMap = new WritableNativeMap();
    eventMap.putString(EVENT_TYPE, "bluetooth");
    eventMap.putBoolean(EVENT_STATUS, active);
    getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(RN_CONNECTIVITY_STATUS_TOPIC, eventMap);
  }
}
 
Example 5
Project: RNLearn_Project1   File: ReactInstanceManager.java   Source Code and License 6 votes vote down vote up
/**
 * This method will give JS the opportunity to receive intents via Linking.
 */
public void onNewIntent(Intent intent) {
  if (mCurrentReactContext == null) {
    FLog.w(ReactConstants.TAG, "Instance detached from instance manager");
  } else {
    String action = intent.getAction();
    Uri uri = intent.getData();

    if (Intent.ACTION_VIEW.equals(action) && uri != null) {
      DeviceEventManagerModule deviceEventManagerModule =
              Assertions.assertNotNull(mCurrentReactContext).getNativeModule(DeviceEventManagerModule.class);
      deviceEventManagerModule.emitNewIntentReceived(uri);
    }

    mCurrentReactContext.onNewIntent(mCurrentActivity, intent);
  }
}
 
Example 6
Project: RNLearn_Project1   File: CoreModulesPackage.java   Source Code and License 6 votes vote down vote up
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
  List<Class<? extends JavaScriptModule>> jsModules = new ArrayList<>(Arrays.asList(
      DeviceEventManagerModule.RCTDeviceEventEmitter.class,
      JSTimersExecution.class,
      RCTEventEmitter.class,
      RCTNativeAppEventEmitter.class,
      AppRegistry.class,
      com.facebook.react.bridge.Systrace.class,
      HMRClient.class));

  if (ReactBuildConfig.DEBUG) {
    jsModules.add(DebugComponentOwnershipModule.RCTDebugComponentOwnership.class);
    jsModules.add(JSCHeapCapture.HeapCapture.class);
    jsModules.add(JSCSamplingProfiler.SamplingProfiler.class);
  }

  return jsModules;
}
 
Example 7
Project: RNLearn_Project1   File: NativeAnimatedModule.java   Source Code and 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 8
Project: RNLearn_Project1   File: ReactInstanceManager.java   Source Code and License 6 votes vote down vote up
/**
 * This method will give JS the opportunity to receive intents via Linking.
 */
public void onNewIntent(Intent intent) {
  if (mCurrentReactContext == null) {
    FLog.w(ReactConstants.TAG, "Instance detached from instance manager");
  } else {
    String action = intent.getAction();
    Uri uri = intent.getData();

    if (Intent.ACTION_VIEW.equals(action) && uri != null) {
      DeviceEventManagerModule deviceEventManagerModule =
              Assertions.assertNotNull(mCurrentReactContext).getNativeModule(DeviceEventManagerModule.class);
      deviceEventManagerModule.emitNewIntentReceived(uri);
    }

    mCurrentReactContext.onNewIntent(mCurrentActivity, intent);
  }
}
 
Example 9
Project: RNLearn_Project1   File: CoreModulesPackage.java   Source Code and License 6 votes vote down vote up
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
  List<Class<? extends JavaScriptModule>> jsModules = new ArrayList<>(Arrays.asList(
      DeviceEventManagerModule.RCTDeviceEventEmitter.class,
      JSTimersExecution.class,
      RCTEventEmitter.class,
      RCTNativeAppEventEmitter.class,
      AppRegistry.class,
      com.facebook.react.bridge.Systrace.class,
      HMRClient.class));

  if (ReactBuildConfig.DEBUG) {
    jsModules.add(DebugComponentOwnershipModule.RCTDebugComponentOwnership.class);
    jsModules.add(JSCHeapCapture.HeapCapture.class);
    jsModules.add(JSCSamplingProfiler.SamplingProfiler.class);
  }

  return jsModules;
}
 
Example 10
Project: RNLearn_Project1   File: NativeAnimatedModule.java   Source Code and 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 11
Project: react-native-heading   File: ReactNativeHeadingModule.java   Source Code and License 6 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    if( event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR ){
        // calculate th rotation matrix
        SensorManager.getRotationMatrixFromVector(rMat, event.values);
        // get the azimuth value (orientation[0]) in degree

        newAzimuth = (int) ((((( Math.toDegrees( SensorManager.getOrientation( rMat, orientation )[0] ) + 360 ) % 360) -
                      ( Math.toDegrees( SensorManager.getOrientation( rMat, orientation )[2] ))) +360) % 360);

        //dont react to changes smaller than the filter value
        if (Math.abs(mAzimuth - newAzimuth) < mFilter) {
            return;
        }

        getReactApplicationContext()
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit("headingUpdated", (int) newAzimuth);

        mAzimuth = newAzimuth;
    }
}
 
Example 12
Project: react-native-android-sms-listener   File: SmsReceiver.java   Source Code and 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 13
Project: houndify-smart-mirror   File: MainActivity.java   Source Code and License 6 votes vote down vote up
@Override
public void onError(final Exception ex, final VoiceSearchInfo voiceSearchInfo) {
    Log.d("MirrorApp", voiceSearchInfo.getErrorType().toString() + "\n\n" + exceptionToString(ex));

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    String json = new String();

    WritableMap params = Arguments.createMap();
    params.putString("error", json);

    ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
    reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit("houndifyResponseError", params);

    if ( phraseSpotterReader == null ) {
        startPhraseSpotting();
    }
}
 
Example 14
Project: Ironman   File: XReactInstanceManagerImpl.java   Source Code and License 6 votes vote down vote up
@Override
public void onNewIntent(Intent intent) {
  if (mCurrentReactContext == null) {
    FLog.w(ReactConstants.TAG, "Instance detached from instance manager");
  } else {
    String action = intent.getAction();
    Uri uri = intent.getData();

    if (Intent.ACTION_VIEW.equals(action) && uri != null) {
      DeviceEventManagerModule deviceEventManagerModule =
              Assertions.assertNotNull(mCurrentReactContext).getNativeModule(DeviceEventManagerModule.class);
      deviceEventManagerModule.emitNewIntentReceived(uri);
    }

    mCurrentReactContext.onNewIntent(mCurrentActivity, intent);
  }
}
 
Example 15
Project: Ironman   File: CoreModulesPackage.java   Source Code and License 6 votes vote down vote up
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
  List<Class<? extends JavaScriptModule>> jsModules = new ArrayList<>(Arrays.asList(
      DeviceEventManagerModule.RCTDeviceEventEmitter.class,
      JSTimersExecution.class,
      RCTEventEmitter.class,
      RCTNativeAppEventEmitter.class,
      AppRegistry.class,
      com.facebook.react.bridge.Systrace.class,
      HMRClient.class));

  if (ReactBuildConfig.DEBUG) {
    jsModules.add(DebugComponentOwnershipModule.RCTDebugComponentOwnership.class);
    jsModules.add(JSCHeapCapture.HeapCapture.class);
    jsModules.add(JSCSamplingProfiler.SamplingProfiler.class);
  }

  return jsModules;
}
 
Example 16
Project: Ironman   File: NativeAnimatedModule.java   Source Code and 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 17
Project: react-native-simple-compass   File: RNSimpleCompassModule.java   Source Code and License 6 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    if( event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR ){
        // calculate th rotation matrix
        SensorManager.getRotationMatrixFromVector(rMat, event.values);
        // get the azimuth value (orientation[0]) in degree
        int newAzimuth = (int) ( Math.toDegrees( SensorManager.getOrientation( rMat, orientation )[0] ) + 360 ) % 360;

        //dont react to changes smaller than the filter value
        if (Math.abs(mAzimuth - newAzimuth) < mFilter) {
            return;
        }

        mAzimuth = newAzimuth;

        getReactApplicationContext()
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit("HeadingUpdated", mAzimuth);
    }
}
 
Example 18
Project: rn-notification   File: NotificationModule.java   Source Code and License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();

    // Focus the application
    String packageName = context.getApplicationContext().getPackageName();
    Intent focusIntent = context.getPackageManager().getLaunchIntentForPackage(packageName).cloneFilter();

    focusIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

    final Activity activity = getActivity();
    if (activity != null) {
        activity.startActivity(focusIntent);
    }

    // Send event to JS
    WritableMap params = Arguments.createMap();
    params.putInt("id", extras.getInt(NotificationEventReceiver.NOTIFICATION_ID));
    params.putString("payload", extras.getString(NotificationEventReceiver.PAYLOAD));

    getReactApplicationContext()
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit("RNNotification:press", params);

    this.setResultCode(Activity.RESULT_OK);
}
 
Example 19
Project: react-native-music-control   File: MusicControlListener.java   Source Code and License 6 votes vote down vote up
private static void sendEvent(ReactApplicationContext context, String type, Object value) {
    WritableMap data = Arguments.createMap();
    data.putString("name", type);

    if(value == null) {
        // NOOP
    } else if(value instanceof Double || value instanceof Float) {
        data.putDouble("value", (double)value);
    } else if(value instanceof Boolean) {
        data.putBoolean("value", (boolean)value);
    } else if(value instanceof Integer) {
        data.putInt("value", (int)value);
    }

    context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("RNMusicControlEvent", data);
}
 
Example 20
Project: react-native-system-setting   File: SystemSetting.java   Source Code and License 5 votes vote down vote up
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
    SysSettings setting = SysSettings.get(requestCode);
    if (setting != SysSettings.UNKNOW) {
        mContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(setting.event, null);
        mContext.removeActivityEventListener(this);
    }
}
 
Example 21
Project: react-native-google-fit   File: GoogleFitManager.java   Source Code and License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       @Nullable WritableMap params) {
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(eventName, params);
}
 
Example 22
Project: react-native-google-fit   File: StepHistory.java   Source Code and License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       @Nullable WritableArray params) {
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(eventName, params);
}
 
Example 23
Project: react-native-google-fit   File: StepSensor.java   Source Code and License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       @Nullable WritableMap params) {
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(eventName, params);
}
 
Example 24
Project: react-native-google-fit   File: StepCounter.java   Source Code and License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       @Nullable WritableMap params) {
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(eventName, params);
}
 
Example 25
Project: react-native-threads   File: ThreadSelfModule.java   Source Code and License 5 votes vote down vote up
@ReactMethod
public void postMessage(String data) {
    if (parentContext == null) { return; }

    parentContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit("Thread" + String.valueOf(threadId), data);
}
 
Example 26
Project: react-native-threads   File: JSThread.java   Source Code and License 5 votes vote down vote up
public void postMessage(String message) {
    if (reactContext == null) {
        return;
    }

    reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit("ThreadMessage", message);
}
 
Example 27
Project: react-native-twilio-chat   File: RCTTwilioAccessManager.java   Source Code and License 5 votes vote down vote up
@Override
public void onError(AccessManager twilioAccessManager, String s) {
    WritableMap params = Arguments.createMap();
    params.putString("error",s);
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit("accessManager:tokenInvalid",params);
}
 
Example 28
Project: react-native-sunmi-inner-printer   File: PrinterReceiver.java   Source Code and License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent data) {
    String action = data.getAction();
    String type = "PrinterStatus";
    Log.d("PrinterReceiver", action);
        SunmiInnerPrinterModule.reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(type, action);
}
 
Example 29
Project: react-native-call-events   File: CallStateListener.java   Source Code and License 5 votes vote down vote up
@Override
public void onCallStateChanged(int state, String incomingNumber) {
    final Context context = reactContext.getApplicationContext();
    final Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    WritableMap params = this.createMap();
    params.putString("phonenumber", incomingNumber);
    if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
        params.putString("state", "CALL_STATE_OFFHOOK");
        if( returnOnCall ) {
            context.startActivity(i);
        }
    }
    if (TelephonyManager.CALL_STATE_RINGING == state) {
        params.putString("state", "CALL_STATE_RINGING");
        if( returnOnCall ) {
            context.startActivity(i);
        }
    }
    if (TelephonyManager.CALL_STATE_IDLE == state) {
        params.putString("state", "CALL_STATE_END");
        if ( returnOnEnd ) {
            context.startActivity(i);
        }
    }

    reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("callStatusUpdate", params);
}
 
Example 30
Project: react-native-call-events   File: CallStateListenerTest.java   Source Code and License 5 votes vote down vote up
@Before
public void setup() {
    when(mockReactContext.getApplicationContext()).thenReturn(mockApplicationContext);
    when(mockApplicationContext.getPackageManager()).thenReturn(mockPackageManager);
    when(mockApplicationContext.getPackageName()).thenReturn(FAKE_PACKAGE_NAME);
    when(mockPackageManager.getLaunchIntentForPackage(FAKE_PACKAGE_NAME)).thenReturn(mockIntent);
    when(mockActivity.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mockTelephonyManager);
    when(mockReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)).thenReturn(mockEmitter);
}
 
Example 31
Project: react-native-sound-player   File: RNSoundPlayerModule.java   Source Code and 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 32
Project: react-native-devsettings-android   File: DevSettingsModule.java   Source Code and License 5 votes vote down vote up
@ReactMethod
public void toggleElementInspector() {
    if (!useDeveloperSupport) return;
    DevInternalSettings mDevSettings = (DevInternalSettings) devManager.getDevSettings();
    mDevSettings.setElementInspectorEnabled(!mDevSettings.isElementInspectorEnabled());
    reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit("toggleElementInspector", null);
}
 
Example 33
Project: react-native-fused-location   File: FusedLocationModule.java   Source Code and License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) {
    if (reactContext.hasActiveCatalystInstance()) {
        reactContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    } else {
        Log.i(TAG, "Waiting for CatalystInstance...");
    }
}
 
Example 34
Project: React-Native-Music-Player   File: MusicPlayerModule.java   Source Code and License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       @Nullable WritableMap params) {
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(eventName, params);
}
 
Example 35
Project: react-native-android-text-to-speech   File: RNAndroidTextToSpeechModule.java   Source Code and License 5 votes vote down vote up
private void sendEvent(String eventName, String utteranceId) {
	WritableMap params = Arguments.createMap();
	params.putString("utteranceId", utteranceId);
	getReactApplicationContext()
		.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
		.emit(eventName, params);
}
 
Example 36
Project: RNRxBluetooth   File: RNRxBluetoothModule.java   Source Code and License 5 votes vote down vote up
private void sendEventToJs(String eventName, @Nullable WritableMap params) {
    try {
        if (reactContext.hasActiveCatalystInstance()) {
            if (debug) {
                Log.d(TAG, "Sending event: " + eventName);
            }
            reactContext
                    .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                    .emit(eventName, params);
        }
    } catch (Exception error) {
        error.printStackTrace();
        Log.e(TAG, error.toString());
    }
}
 
Example 37
Project: react-native-network-connection-class   File: Module.java   Source Code and License 5 votes vote down vote up
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       WritableMap params) {
  reactContext
    .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
    .emit(eventName, params);
}
 
Example 38
Project: react-native-fingerprint-identify   File: RNFingerprintIdentifyModule.java   Source Code and License 5 votes vote down vote up
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 39
Project: react-native-connectivity-status   File: RNConnectivityStatusModule.java   Source Code and License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  final boolean locationEnabled = intent.getAction() != null
          && intent.getAction().matches(LocationManager.PROVIDERS_CHANGED_ACTION)
          && checkLocation();

  final WritableMap eventMap = new WritableNativeMap();
  eventMap.putString(EVENT_TYPE, "location");
  eventMap.putBoolean(EVENT_STATUS, locationEnabled);
  getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(RN_CONNECTIVITY_STATUS_TOPIC, eventMap);
}
 
Example 40
Project: RNLearn_Project1   File: AccessibilityInfoModule.java   Source Code and 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);
    }
}