本文整理汇总了Java中com.facebook.react.modules.core.DeviceEventManagerModule类的典型用法代码示例。如果您正苦于以下问题:Java DeviceEventManagerModule类的具体用法?Java DeviceEventManagerModule怎么用?Java DeviceEventManagerModule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DeviceEventManagerModule类属于com.facebook.react.modules.core包,在下文中一共展示了DeviceEventManagerModule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SendEvent
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
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);
}
示例2: listenVolume
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
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);
}
示例3: handleMediaRowData
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
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);
}
}
示例4: onReceive
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
@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);
}
}
示例5: onNewIntent
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
/**
* 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);
}
}
示例6: createJSModules
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
@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;
}
示例7: startListeningToAnimatedNodeValue
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
@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);
}
});
}
示例8: onSensorChanged
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
@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;
}
}
示例9: receiveMessage
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
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);
}
示例10: onError
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
@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();
}
}
示例11: onNewIntent
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
@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);
}
}
示例12: onSensorChanged
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
@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);
}
}
示例13: onReceive
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
@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);
}
示例14: sendEvent
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
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);
}
示例15: onActivityResult
import com.facebook.react.modules.core.DeviceEventManagerModule; //导入依赖的package包/类
@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);
}
}