本文整理匯總了Java中com.facebook.react.bridge.WritableNativeMap類的典型用法代碼示例。如果您正苦於以下問題:Java WritableNativeMap類的具體用法?Java WritableNativeMap怎麽用?Java WritableNativeMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
WritableNativeMap類屬於com.facebook.react.bridge包,在下文中一共展示了WritableNativeMap類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createRangingResponse
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的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.WritableNativeMap; //導入依賴的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: addToGalleryAndNotify
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的package包/類
public static void addToGalleryAndNotify(Context context, File imageFile, final Promise promise) {
final WritableMap response = new WritableNativeMap();
response.putString("path", Uri.fromFile(imageFile).toString());
// borrowed from react-native CameraRollManager, it finds and returns the 'internal'
// representation of the image uri that was just saved.
// e.g. content://media/external/images/media/123
MediaScannerConnection.scanFile(
context,
new String[]{imageFile.getAbsolutePath()},
null,
new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
promise.resolve(response);
}
});
}
示例4: getSessionInfo
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的package包/類
@ReactMethod
public void getSessionInfo(final Promise callback) {
Taplytics.getSessionInfo(new SessionInfoRetrievedListener() {
@Override
public void sessionInfoRetrieved(HashMap hashMap) {
WritableMap resultData = new WritableNativeMap();
if(hashMap.containsKey("session_id")){
resultData.putString("session_id", (String) hashMap.get("session_id"));
}
if(hashMap.containsKey("appUser_id")){
resultData.putString("appUser_id", (String) hashMap.get("appUser_id"));
}
callback.resolve(resultData);
}
});
}
示例5: checkDownloadStatus
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的package包/類
public WritableMap checkDownloadStatus(long downloadId) {
DownloadManager.Query downloadQuery = new DownloadManager.Query();
downloadQuery.setFilterById(downloadId);
Cursor cursor = downloadManager.query(downloadQuery);
HashMap<String, String> result = new HashMap<>();
if (cursor.moveToFirst()) {
result = getDownloadStatus(cursor, downloadId);
} else {
result.put("status", "UNKNOWN");
result.put("reason", "COULD_NOT_FIND");
result.put("downloadId", String.valueOf(downloadId));
}
WritableMap wmap = new WritableNativeMap();
for (HashMap.Entry<String, String> entry : result.entrySet()) {
wmap.putString(entry.getKey(), entry.getValue());
}
return wmap;
}
示例6: checkProgress
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的package包/類
/**
* Checks download progress.
*/
private void checkProgress() {
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(enqueue);
Cursor cursor = dm.query(query);
if (!cursor.moveToFirst()) {
cursor.close();
return;
}
long reference = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID));
int bytes_downloaded =
cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
int bytes_total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
int progress = (int) ((bytes_downloaded * 100l) / bytes_total);
WritableMap writableMap = new WritableNativeMap();
writableMap.putInt("progress", progress);
sendEvent(writableMap);
if(progress >= 100) {
future.cancel(true);
}
}
示例7: resolveImage
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的package包/類
private void resolveImage(final File imageFile, int width, int height, final Promise promise, boolean addToMediaStore) {
final WritableMap response = new WritableNativeMap();
response.putString("path", Uri.fromFile(imageFile).toString());
response.putInt("width", width);
response.putInt("height", height);
if(addToMediaStore) {
// borrowed from react-native CameraRollManager, it finds and returns the 'internal'
// representation of the image uri that was just saved.
// e.g. content://media/external/images/media/123
MediaScannerConnection.scanFile(
_reactContext,
new String[]{imageFile.getAbsolutePath()},
null,
null);
}
promise.resolve(response);
}
示例8: auth
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的package包/類
@ReactMethod
public void auth(Promise promise) {
if (HSinterface == null){
promise.reject("-1", "init failed");
return;
}
int ret = HSinterface.Authenticate();
WritableMap result = new WritableNativeMap();
if (ret == 1){
result.putString("code", ret+"");
result.putString("msg", "success");
promise.resolve(result);
}else if (ret == 2){
result.putString("code", ret+"");
result.putString("msg", "auth failed");
promise.resolve(result);
}else if (ret == 0){
promise.reject("0", "connect failed");
}
}
示例9: onException
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的package包/類
@Override
public boolean onException(
Exception e,
GlideUrl uri,
Target<GlideDrawable> target,
boolean isFirstResource
) {
OkHttpProgressGlideModule.forget(uri.toStringUrl());
if (!(target instanceof ImageViewTarget)) {
return false;
}
ImageViewWithUrl view = (ImageViewWithUrl) ((ImageViewTarget) target).getView();
ThemedReactContext context = (ThemedReactContext) view.getContext();
RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
int viewId = view.getId();
eventEmitter.receiveEvent(viewId, REACT_ON_ERROR_EVENT, new WritableNativeMap());
eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_END_EVENT, new WritableNativeMap());
return false;
}
示例10: onResourceReady
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的package包/類
@Override
public boolean onResourceReady(
GlideDrawable resource,
GlideUrl uri,
Target<GlideDrawable> target,
boolean isFromMemoryCache,
boolean isFirstResource
) {
if (!(target instanceof ImageViewTarget)) {
return false;
}
ImageViewWithUrl view = (ImageViewWithUrl) ((ImageViewTarget) target).getView();
ThemedReactContext context = (ThemedReactContext) view.getContext();
RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
int viewId = view.getId();
eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_EVENT, new WritableNativeMap());
eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_END_EVENT, new WritableNativeMap());
return false;
}
示例11: convertLocationToJSON
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的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;
}
示例12: onReceive
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的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);
}
}
示例13: attachMeasuredRootViewToInstance
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的package包/類
private void attachMeasuredRootViewToInstance(
ReactRootView rootView,
CatalystInstance catalystInstance) {
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachMeasuredRootViewToInstance");
UiThreadUtil.assertOnUiThread();
// Reset view content as it's going to be populated by the application content from JS
rootView.removeAllViews();
rootView.setId(View.NO_ID);
UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class);
int rootTag = uiManagerModule.addMeasuredRootView(rootView);
rootView.setRootViewTag(rootTag);
@Nullable Bundle launchOptions = rootView.getLaunchOptions();
WritableMap initialProps = Arguments.makeNativeMap(launchOptions);
String jsAppModuleName = rootView.getJSModuleName();
WritableNativeMap appParams = new WritableNativeMap();
appParams.putDouble("rootTag", rootTag);
appParams.putMap("initialProps", initialProps);
catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
rootView.onAttachedToReactInstance();
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
示例14: addEntry
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的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());
}
}
示例15: testShowBasicShareDialog
import com.facebook.react.bridge.WritableNativeMap; //導入依賴的package包/類
public void testShowBasicShareDialog() {
final WritableMap content = new WritableNativeMap();
content.putString("message", "Hello, ReactNative!");
final WritableMap options = new WritableNativeMap();
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CHOOSER);
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
ActivityMonitor monitor = getInstrumentation().addMonitor(intentFilter, null, true);
getTestModule().showShareDialog(content, options);
waitForBridgeAndUIIdle();
getInstrumentation().waitForIdleSync();
assertEquals(1, monitor.getHits());
assertEquals(1, mRecordingModule.getOpened());
assertEquals(0, mRecordingModule.getErrors());
}