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); }
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); } }
@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); } }
/** * 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); } }
@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; }
@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); } }); }
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); }
@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; } }
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); }
@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(); } }
@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); } }
@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); } }
@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); }
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); }
@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); } }
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) { reactContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(eventName, params); }
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableArray params) { reactContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(eventName, params); }
@ReactMethod public void postMessage(String data) { if (parentContext == null) { return; } parentContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("Thread" + String.valueOf(threadId), data); }
public void postMessage(String message) { if (reactContext == null) { return; } reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("ThreadMessage", message); }
@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); }
@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); }
@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); }
@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); }
private void sendEvent(ReactApplicationContext reactContext, String eventName, @Nullable WritableMap params) { reactContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(eventName, params); }
@ReactMethod public void toggleElementInspector() { if (!useDeveloperSupport) return; DevInternalSettings mDevSettings = (DevInternalSettings) devManager.getDevSettings(); mDevSettings.setElementInspectorEnabled(!mDevSettings.isElementInspectorEnabled()); reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("toggleElementInspector", null); }
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..."); } }
private void sendEvent(String eventName, String utteranceId) { WritableMap params = Arguments.createMap(); params.putString("utteranceId", utteranceId); getReactApplicationContext() .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(eventName, params); }
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()); } }
private void sendEvent(ReactContext reactContext, String eventName, WritableMap params) { reactContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(eventName, params); }
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); }
@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); }
private void updateAndSendChangeEvent(boolean enabled) { if (mEnabled != enabled) { mEnabled = enabled; getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(EVENT_NAME, mEnabled); } }