本文整理汇总了Java中com.facebook.react.bridge.WritableMap类的典型用法代码示例。如果您正苦于以下问题:Java WritableMap类的具体用法?Java WritableMap怎么用?Java WritableMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WritableMap类属于com.facebook.react.bridge包,在下文中一共展示了WritableMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onNewIntent
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
@Override
public void onNewIntent(Intent intent)
{
String action = intent.getAction();
// Log.i("!intent! ", action);
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] id = tag.getId();
String serialNumber = bytesToHex(id);
WritableMap idData = Arguments.createMap();
idData.putString("id", serialNumber);
sendEvent(this.reactContext, "NFCCardID", idData);
}
示例2: getTaskConfig
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
@Override
protected @Nullable HeadlessJsTaskConfig getTaskConfig(Intent intent) {
Bundle extras = intent.getExtras();
// If extras have been passed to the intent, pass them on into the JS as taskData
// which can be accessed as the first param.
WritableMap data = /* extras != null ? Arguments.fromBundle(extras) : */ Arguments.createMap();
int timeout = extras.getInt("timeout");
Log.d(TAG, String.format("Returning HeadlessJsTaskConfig, timeout=%s ms", timeout));
return new HeadlessJsTaskConfig(
// The the task was registered with in JS - must match
"BackgroundTask",
data,
TimeUnit.SECONDS.toMillis(timeout)
);
}
示例3: share
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
/**
* Open a chooser dialog to send text content to other apps.
*
* Refer http://developer.android.com/intl/ko/training/sharing/send.html
*
* @param content the data to send
* @param dialogTitle the title of the chooser dialog
*/
@ReactMethod
public void share(ReadableMap content, String dialogTitle, Promise promise) {
if (content == null) {
promise.reject(ERROR_INVALID_CONTENT, "Content cannot be null");
return;
}
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setTypeAndNormalize("text/plain");
if (content.hasKey("title")) {
intent.putExtra(Intent.EXTRA_SUBJECT, content.getString("title"));
}
if (content.hasKey("message")) {
intent.putExtra(Intent.EXTRA_TEXT, content.getString("message"));
}
Intent chooser = Intent.createChooser(intent, dialogTitle);
chooser.addCategory(Intent.CATEGORY_DEFAULT);
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
currentActivity.startActivity(chooser);
} else {
getReactApplicationContext().startActivity(chooser);
}
WritableMap result = Arguments.createMap();
result.putString("action", ACTION_SHARED);
promise.resolve(result);
} catch (Exception e) {
promise.reject(ERROR_UNABLE_TO_OPEN_DIALOG, "Failed to open share dialog");
}
}
示例4: returnMapForVoice
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
private WritableMap returnMapForVoice(Voice voice) {
WritableMap voiceData = Arguments.createMap();
voiceData.putString("voiceName", voice.getName());
voiceData.putString("languageName", voice.getLocale().getDisplayLanguage());
voiceData.putString("languageCode", voice.getLocale().getISO3Language());
voiceData.putString("languageString", voice.getLocale().toString());
voiceData.putString("countryName", voice.getLocale().getDisplayCountry());
voiceData.putString("countryCode", voice.getLocale().getISO3Country());
return voiceData;
}
开发者ID:echo8795,项目名称:react-native-android-text-to-speech,代码行数:12,代码来源:RNAndroidTextToSpeechModule.java
示例5: Message
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
public static WritableMap Message(Message message) {
WritableMap map = Arguments.createMap();
map.putString("sid", message.getSid());
map.putInt("index", (int) message.getMessageIndex());
map.putString("author", message.getAuthor());
map.putString("body", message.getMessageBody());
map.putString("timestamp", message.getTimeStamp());
WritableMap attributes = Arguments.createMap();
try {
attributes = jsonToWritableMap(message.getAttributes());
}
catch (JSONException e) {}
map.putMap("attributes", attributes);
return map;
}
示例6: convertLocationToJSON
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
private WritableMap convertLocationToJSON(Location l) {
WritableMap params = new WritableNativeMap();
params.putDouble("latitude", l.getLatitude());
params.putDouble("longitude", l.getLongitude());
params.putDouble("accuracy", l.getAccuracy());
params.putDouble("altitude", l.getAltitude());
params.putDouble("bearing", l.getBearing());
params.putString("provider", l.getProvider());
params.putDouble("speed", l.getSpeed());
params.putString("timestamp", Long.toString(l.getTime()));
boolean isMock = false;
if (android.os.Build.VERSION.SDK_INT >= 18) {
isMock = l.isFromMockProvider();
} else {
isMock = !Settings.Secure.getString(getReactApplicationContext().getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
}
params.putBoolean("mocked", isMock);
return params;
}
示例7: testCallback
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
public void testCallback() throws Throwable {
final WritableMap options = new WritableNativeMap();
options.putDouble("date", getDateInMillis(2020, 5, 6));
final DialogFragment datePickerFragment = showDialog(options);
runTestOnUiThread(
new Runnable() {
@Override
public void run() {
((DatePickerDialog) datePickerFragment.getDialog())
.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
}
});
getInstrumentation().waitForIdleSync();
waitForBridgeAndUIIdle();
assertEquals(0, mRecordingModule.getErrors());
assertEquals(1, mRecordingModule.getDates().size());
assertEquals(2020, (int) mRecordingModule.getDates().get(0)[0]);
assertEquals(5, (int) mRecordingModule.getDates().get(0)[1]);
assertEquals(6, (int) mRecordingModule.getDates().get(0)[2]);
}
示例8: jsonToReact
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
public static WritableMap jsonToReact(JSONObject jsonObject) throws JSONException {
WritableMap writableMap = Arguments.createMap();
Iterator iterator = jsonObject.keys();
while(iterator.hasNext()) {
String key = (String) iterator.next();
Object value = jsonObject.get(key);
if (value instanceof Float || value instanceof Double) {
writableMap.putDouble(key, jsonObject.getDouble(key));
} else if (value instanceof Number) {
writableMap.putInt(key, jsonObject.getInt(key));
} else if (value instanceof String) {
writableMap.putString(key, jsonObject.getString(key));
} else if (value instanceof JSONObject) {
writableMap.putMap(key,jsonToReact(jsonObject.getJSONObject(key)));
} else if (value instanceof JSONArray){
writableMap.putArray(key, jsonToReact(jsonObject.getJSONArray(key)));
} else if (value == JSONObject.NULL){
writableMap.putNull(key);
}
}
return writableMap;
}
示例9: onReceivedError
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
@Override
public void onReceivedError(
WebView webView,
int errorCode,
String description,
String failingUrl) {
super.onReceivedError(webView, errorCode, description, failingUrl);
mLastLoadFailed = true;
// In case of an error JS side expect to get a finish event first, and then get an error event
// Android WebView does it in the opposite way, so we need to simulate that behavior
emitFinishEvent(webView, failingUrl);
WritableMap eventData = createWebViewEvent(webView, failingUrl);
eventData.putDouble("code", errorCode);
eventData.putString("description", description);
dispatchEvent(
webView,
new TopLoadingErrorEvent(webView.getId(), eventData));
}
示例10: onDataPoint
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
@Override
public void onDataPoint(DataPoint dataPoint) {
DataType type = dataPoint.getDataType();
Log.i(TAG, "Detected DataPoint type: " + type);
for (final Field field : type.getFields()) {
final Value value = dataPoint.getValue(field);
Log.i(TAG, "Detected DataPoint field: " + field.getName());
Log.i(TAG, "Detected DataPoint value: " + value);
/* activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mReactContext.getApplicationContext(), "Field: " + field.getName() + " Value: " + value, Toast.LENGTH_SHORT).show();
}
});*/
if(type.equals(DataType.TYPE_STEP_COUNT_CUMULATIVE)) {
WritableMap map = Arguments.createMap();
map.putDouble("steps", value.asInt());
sendEvent(this.mReactContext, "StepChangedEvent", map);
}
}
}
示例11: onCallStateChanged_CALL_STATE_IDLE_returnOnEndTrue
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
@Test
public void onCallStateChanged_CALL_STATE_IDLE_returnOnEndTrue() {
CallStateListener instance = getInstance(false, true, mockReactContext);
instance.onCallStateChanged(TelephonyManager.CALL_STATE_IDLE, "8675309");
//always set the return flags
verify(mockIntent).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//Should always fire the event back to Javascript
WritableMap expected = new MockWritableMap();
expected.putString("phonenumber", "8675309");
expected.putString("state", "CALL_STATE_END");
verify(mockEmitter).emit("callStatusUpdate", expected);
//should launch the app
verify(mockApplicationContext).startActivity(mockIntent);
}
示例12: onCallStateChanged_CALL_STATE_RINGING_returnOnCallFalse
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
@Test
public void onCallStateChanged_CALL_STATE_RINGING_returnOnCallFalse() {
CallStateListener instance = getInstance(false, true, mockReactContext);
instance.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, "8675309");
//always set the return flags
verify(mockIntent).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//Should always fire the event back to Javascript
WritableMap expected = new MockWritableMap();
expected.putString("phonenumber", "8675309");
expected.putString("state", "CALL_STATE_RINGING");
verify(mockEmitter).emit("callStatusUpdate", expected);
//should not attempt to launch the app
verify(mockApplicationContext, never()).startActivity(any(Intent.class));
}
示例13: asWritableMap
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
public WritableMap asWritableMap() {
WritableMap map = Arguments.createMap();
try {
map.putString("name", device.getName());
map.putBoolean("connected", connected);
map.putString("id", device.getAddress()); // mac address
map.putMap("advertising", byteArrayToWritableMap(advertisingData));
map.putInt("rssi", advertisingRSSI);
} catch (Exception e) { // this shouldn't happen
e.printStackTrace();
}
return map;
}
示例14: onCallStateChanged_CALL_STATE_OFFHOOK_returnOnCallFalse
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
@Test
public void onCallStateChanged_CALL_STATE_OFFHOOK_returnOnCallFalse() {
CallStateListener instance = getInstance(false, true, mockReactContext);
instance.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, "8675309");
//always set the return flags
verify(mockIntent).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//Should always fire the event back to Javascript
WritableMap expected = new MockWritableMap();
expected.putString("phonenumber", "8675309");
expected.putString("state", "CALL_STATE_OFFHOOK");
verify(mockEmitter).emit("callStatusUpdate", expected);
//should not attempt to launch the app
verify(mockApplicationContext, never()).startActivity(any(Intent.class));
}
示例15: onDateSet
import com.facebook.react.bridge.WritableMap; //导入依赖的package包/类
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
if (!mPromiseResolved && getReactApplicationContext().hasActiveCatalystInstance()) {
WritableMap result = new WritableNativeMap();
result.putString("action", ACTION_DATE_SET);
result.putInt("year", year);
result.putInt("month", month);
result.putInt("day", day);
mPromise.resolve(result);
mPromiseResolved = true;
}
}