本文整理汇总了Java中com.facebook.react.bridge.WritableNativeArray类的典型用法代码示例。如果您正苦于以下问题:Java WritableNativeArray类的具体用法?Java WritableNativeArray怎么用?Java WritableNativeArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WritableNativeArray类属于com.facebook.react.bridge包,在下文中一共展示了WritableNativeArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRangingResponse
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
private WritableMap createRangingResponse(Collection<Beacon> beacons, Region region) {
WritableMap map = new WritableNativeMap();
map.putString("identifier", region.getUniqueId());
map.putString("uuid", region.getId1() != null ? region.getId1().toString() : "");
WritableArray a = new WritableNativeArray();
for (Beacon beacon : beacons) {
WritableMap b = new WritableNativeMap();
b.putString("uuid", beacon.getId1().toString());
b.putInt("major", beacon.getId2().toInt());
b.putInt("minor", beacon.getId3().toInt());
b.putInt("rssi", beacon.getRssi());
b.putDouble("distance", beacon.getDistance());
b.putString("proximity", getProximity(beacon.getDistance()));
a.pushMap(b);
}
map.putArray("beacons", a);
return map;
}
示例2: testStringWithMultibyteUTF8Characters
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
public void testStringWithMultibyteUTF8Characters() {
TestJavaToJSArgumentsModule jsModule = mInstance.getJSModule(TestJavaToJSArgumentsModule.class);
WritableNativeMap map = new WritableNativeMap();
map.putString("two-bytes", "\u00A2");
map.putString("three-bytes", "\u20AC");
map.putString("four-bytes", "\uD83D\uDE1C");
map.putString(
"mixed",
"\u017C\u00F3\u0142\u0107 g\u0119\u015Bl\u0105 \u6211 \uD83D\uDE0E ja\u017A\u0107");
jsModule.receiveMapWithMultibyteUTF8CharacterString(map);
waitForBridgeAndUIIdle();
mAssertModule.verifyAssertsAndReset();
WritableArray array = new WritableNativeArray();
array.pushString("\u00A2");
array.pushString("\u20AC");
array.pushString("\uD83D\uDE1C");
array.pushString(
"\u017C\u00F3\u0142\u0107 g\u0119\u015Bl\u0105 \u6211 \uD83D\uDE0E ja\u017A\u0107");
jsModule.receiveArrayWithMultibyteUTF8CharacterString(array);
waitForBridgeAndUIIdle();
mAssertModule.verifyAssertsAndReset();
}
示例3: writeStaticNodesFile
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
protected void writeStaticNodesFile(String enodes) {
try {
File dir = new File(this.reactContext
.getFilesDir() + STATIC_NODES_FILES_PATH);
if (dir.exists() == false) dir.mkdirs();
File f = new File(dir, STATIC_NODES_FILES_NAME);
if (f.exists() == false) {
if (f.createNewFile() == true) {
WritableArray staticNodes = new WritableNativeArray();
staticNodes.pushString(enodes);
Writer output = new BufferedWriter(new FileWriter(f));
output.write(staticNodes.toString());
output.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: callJavaScript
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
@ReactMethod
void callJavaScript() {
Activity activity = getCurrentActivity();
if (activity != null) {
MainApplication application = (MainApplication) activity.getApplication();
ReactNativeHost reactNativeHost = application.getReactNativeHost();
ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
if (reactContext != null) {
CatalystInstance catalystInstance = reactContext.getCatalystInstance();
WritableNativeArray params = new WritableNativeArray();
params.pushString("Hello, JavaScript!");
catalystInstance.callFunction("JavaScriptVisibleToJava", "alert", params);
}
}
}
示例5: makeNativeArray
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
/**
* This overload is like the above, but uses reflection to operate on any
* primitive or object type.
*/
public static <T> WritableNativeArray makeNativeArray(final Object objects) {
if (objects == null) {
return new WritableNativeArray();
}
// No explicit check for objects's type here. If it's not an array, the
// Array methods will throw IllegalArgumentException.
return makeNativeArray(new AbstractList() {
public int size() {
return Array.getLength(objects);
}
public Object get(int index) {
return Array.get(objects, index);
}
});
}
示例6: addEntry
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
private static void addEntry(WritableNativeMap nativeMap, String key, Object value) {
value = makeNativeObject(value);
if (value == null) {
nativeMap.putNull(key);
} else if (value instanceof Boolean) {
nativeMap.putBoolean(key, (Boolean) value);
} else if (value instanceof Integer) {
nativeMap.putInt(key, (Integer) value);
} else if (value instanceof Number) {
nativeMap.putDouble(key, ((Number) value).doubleValue());
} else if (value instanceof String) {
nativeMap.putString(key, (String) value);
} else if (value instanceof WritableNativeArray) {
nativeMap.putArray(key, (WritableNativeArray) value);
} else if (value instanceof WritableNativeMap) {
nativeMap.putMap(key, (WritableNativeMap) value);
} else {
throw new IllegalArgumentException("Could not convert " + value.getClass());
}
}
示例7: testMapWithArrays
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
public void testMapWithArrays() {
WritableNativeMap map = new WritableNativeMap();
WritableNativeArray a1 = new WritableNativeArray();
WritableNativeArray a2 = new WritableNativeArray();
a1.pushDouble(3);
a1.pushDouble(1);
a1.pushDouble(4);
a2.pushDouble(1);
a2.pushDouble(9);
map.putArray("array1", a1);
map.putArray("array2", a2);
mInstance.getJSModule(TestJavaToJSArgumentsModule.class).receiveMapWithArrays(map);
waitForBridgeAndUIIdle();
mAssertModule.verifyAssertsAndReset();
}
示例8: testMapWithNullStringValue
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
public void testMapWithNullStringValue() {
WritableNativeMap map = new WritableNativeMap();
map.putString("string", null);
map.putArray("array", null);
map.putMap("map", null);
WritableNativeArray array = new WritableNativeArray();
array.pushString(null);
array.pushArray(null);
array.pushMap(null);
mInstance.getJSModule(TestJavaToJSArgumentsModule.class)
.receiveMapAndArrayWithNullValues(map, array);
waitForBridgeAndUIIdle();
mAssertModule.verifyAssertsAndReset();
}
示例9: getConstants
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
@DoNotStrip
public NativeArray getConstants() {
BaseJavaModule baseJavaModule = getModule();
ReactMarker.logMarker(GET_CONSTANTS_START, getName());
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "Map constants")
.arg("moduleName", getName())
.flush();
Map<String, Object> map = baseJavaModule.getConstants();
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "WritableNativeMap constants")
.arg("moduleName", getName())
.flush();
ReactMarker.logMarker(CONVERT_CONSTANTS_START, getName());
WritableNativeMap writableNativeMap;
try {
writableNativeMap = Arguments.makeNativeMap(map);
} finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
WritableNativeArray array = new WritableNativeArray();
array.pushMap(writableNativeMap);
ReactMarker.logMarker(CONVERT_CONSTANTS_END);
ReactMarker.logMarker(GET_CONSTANTS_END);
return array;
}
示例10: rGetIDs
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
/**
* React method to get all notification ids.
*/
@ReactMethod
public void rGetIDs(
Callback errorCallback,
Callback successCallback
) {
try {
ArrayList<Integer> ids = mNotificationManager.getIDs();
WritableArray rids = new WritableNativeArray();
for (Integer id: ids) {
rids.pushInt(id);
}
successCallback.invoke((ReadableArray) rids);
} catch (Exception e) {
errorCallback.invoke(e.getMessage());
Log.e("ReactSystemNotification", "NotificationModule: rGetIDs Error: " + Log.getStackTraceString(e));
}
}
示例11: getConstants
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
@DoNotStrip
public NativeArray getConstants() {
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "Map constants")
.arg("moduleName", getName())
.flush();
Map<String, Object> map = getModule().getConstants();
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "WritableNativeMap constants")
.arg("moduleName", getName())
.flush();
WritableNativeMap writableNativeMap;
try {
writableNativeMap = Arguments.makeNativeMap(map);
} finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
WritableNativeArray array = new WritableNativeArray();
array.pushMap(writableNativeMap);
return array;
}
示例12: getInstalledApps
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
@ReactMethod
public void getInstalledApps(Promise promise) {
WritableNativeArray params = new WritableNativeArray();
PackageManager pm = reactContext.getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(0);
for(ApplicationInfo app : apps) {
if ((pm.getLaunchIntentForPackage(app.packageName) != null) &&
!thisApp.equals(app.packageName)) {
WritableNativeMap param = new WritableNativeMap();
String appName = app.loadLabel(pm).toString();
String appPackage = app.packageName;
String appIcon = saveIcon(appPackage, app.loadIcon(pm));
//Log.d(TAG, "name: "+appName);
//Log.d(TAG, "app: "+appPackage);
//Log.d(TAG, "icon: "+appIcon);
param.putString("name", appName);
param.putString("app", appPackage);
param.putString("icon", appIcon);
//sendEvent("installedApps", param);
params.pushMap(param);
}
}
promise.resolve(params);
}
示例13: reactArrayFromJson
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
static WritableArray reactArrayFromJson(JSONArray json) throws JSONException {
WritableArray result = new WritableNativeArray();
for (int i = 0; i < json.length(); i++) {
Object value = json.get(i);
if (value == null || value == JSONObject.NULL) {
result.pushNull();
} else if (value instanceof Boolean) {
result.pushBoolean((Boolean)value);
} else if (value instanceof Integer) {
result.pushInt((Integer)value);
} else if (value instanceof Double) {
result.pushDouble((Double)value);
} else if (value instanceof String) {
result.pushString((String)value);
} else if (value instanceof JSONObject) {
result.pushMap(reactMapFromJson((JSONObject)value));
} else if (value instanceof JSONArray) {
result.pushArray(reactArrayFromJson((JSONArray)value));
} else {
throw new RuntimeException("Bad value in JSON array: " + value.toString());
}
}
return result;
}
示例14: findEventCalendars
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
private WritableNativeArray findEventCalendars() {
Cursor cursor;
ContentResolver cr = reactContext.getContentResolver();
Uri uri = CalendarContract.Calendars.CONTENT_URI;
cursor = cr.query(uri, new String[]{
CalendarContract.Calendars._ID,
CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
CalendarContract.Calendars.ACCOUNT_NAME,
CalendarContract.Calendars.IS_PRIMARY,
CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL,
CalendarContract.Calendars.ALLOWED_AVAILABILITY
}, null, null, null);
return serializeEventCalendars(cursor);
}
示例15: calendarAllowedAvailabilitiesFromDBString
import com.facebook.react.bridge.WritableNativeArray; //导入依赖的package包/类
private WritableNativeArray calendarAllowedAvailabilitiesFromDBString(String dbString) {
WritableNativeArray availabilitiesStrings = new WritableNativeArray();
for(String availabilityId: dbString.split(",")) {
switch(Integer.parseInt(availabilityId)) {
case CalendarContract.Events.AVAILABILITY_BUSY:
availabilitiesStrings.pushString("busy");
break;
case CalendarContract.Events.AVAILABILITY_FREE:
availabilitiesStrings.pushString("free");
break;
case CalendarContract.Events.AVAILABILITY_TENTATIVE:
availabilitiesStrings.pushString("tentative");
break;
}
}
return availabilitiesStrings;
}