Java Code Examples for com.facebook.react.bridge.WritableMap#putDouble()
The following examples show how to use
com.facebook.react.bridge.WritableMap#putDouble() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapUtil.java From vinci with Apache License 2.0 | 7 votes |
public static WritableMap toWritableMap(Map<String, Object> map) { WritableMap writableMap = Arguments.createMap(); Iterator iterator = map.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry pair = (Map.Entry) iterator.next(); Object value = pair.getValue(); if (value == null) { writableMap.putNull((String) pair.getKey()); } else if (value instanceof Boolean) { writableMap.putBoolean((String) pair.getKey(), (Boolean) value); } else if (value instanceof Double) { writableMap.putDouble((String) pair.getKey(), (Double) value); } else if (value instanceof Integer) { writableMap.putInt((String) pair.getKey(), (Integer) value); } else if (value instanceof String) { writableMap.putString((String) pair.getKey(), (String) value); } else if (value instanceof Map) { writableMap.putMap((String) pair.getKey(), MapUtil.toWritableMap((Map<String, Object>) value)); } else if (value.getClass() != null && value.getClass().isArray()) { writableMap.putArray((String) pair.getKey(), ArrayUtil.toWritableArray((Object[]) value)); } iterator.remove(); } return writableMap; }
Example 2
Source File: SQLitePlugin.java From react-native-sqlite-storage with MIT License | 6 votes |
@SuppressLint("NewApi") private void bindRow(WritableMap row, String key, Cursor cur, int i) { int curType = cur.getType(i); switch (curType) { case Cursor.FIELD_TYPE_NULL: row.putNull(key); break; case Cursor.FIELD_TYPE_INTEGER: row.putDouble(key, cur.getLong(i)); break; case Cursor.FIELD_TYPE_FLOAT: row.putDouble(key, cur.getDouble(i)); break; case Cursor.FIELD_TYPE_BLOB: row.putString(key, new String(Base64.encode(cur.getBlob(i), Base64.DEFAULT))); break; case Cursor.FIELD_TYPE_STRING: default: /* (not expected) */ row.putString(key, cur.getString(i)); break; } }
Example 3
Source File: RNTextSizeModule.java From react-native-text-size with BSD 2-Clause "Simplified" License | 6 votes |
@Nonnull private WritableMap fontInfoFromTypeface( @Nonnull final TextPaint textPaint, @Nonnull final Typeface typeface, @Nonnull final RNTextSizeConf conf ) { // Info is always in unscaled values final float density = getCurrentDensity(); final Paint.FontMetrics metrics = new Paint.FontMetrics(); final float lineHeight = textPaint.getFontMetrics(metrics); final WritableMap info = Arguments.createMap(); info.putString("fontFamily", conf.getString("fontFamily")); info.putString("fontWeight", typeface.isBold() ? "bold" : "normal"); info.putString("fontStyle", typeface.isItalic() ? "italic" : "normal"); info.putDouble("fontSize", textPaint.getTextSize() / density); info.putDouble("leading", metrics.leading / density); info.putDouble("ascender", metrics.ascent / density); info.putDouble("descender", metrics.descent / density); info.putDouble("top", metrics.top / density); info.putDouble("bottom", metrics.bottom / density); info.putDouble("lineHeight", lineHeight / density); info.putInt("_hash", typeface.hashCode()); return info; }
Example 4
Source File: RNStripeTerminalModule.java From react-native-stripe-terminal with MIT License | 6 votes |
WritableMap serializeReader(Reader reader) { WritableMap writableMap = Arguments.createMap(); if(reader!=null) { double batteryLevel = 0; if(reader.getBatteryLevel()!=null) batteryLevel = (double) reader.getBatteryLevel(); writableMap.putDouble(BATTERY_LEVEL, batteryLevel); int readerType = 0; if(reader.getDeviceType()!=null) readerType = reader.getDeviceType().ordinal(); writableMap.putInt(DEVICE_TYPE, readerType); String serial = ""; if(reader.getSerialNumber()!=null) serial = reader.getSerialNumber(); writableMap.putString(SERIAL_NUMBER, serial); String softwareVersion = ""; if(reader.getSoftwareVersion()!=null) softwareVersion = reader.getSoftwareVersion(); writableMap.putString(DEVICE_SOFTWARE_VERSION, softwareVersion); } return writableMap; }
Example 5
Source File: RNUtils.java From react-native-batch-push with MIT License | 6 votes |
public static WritableMap convertMapToWritableMap(Map<String, Object> input) { WritableMap output = new WritableNativeMap(); for(Map.Entry<String, Object> entry: input.entrySet()){ String key = entry.getKey(); Object value = entry.getValue(); if (value instanceof Map) { output.putMap(key, convertMapToWritableMap((Map<String, Object>) value)); } else if (value instanceof JSONArray) { output.putArray(key, convertArrayToWritableArray((Object[])value)); } else if (value instanceof Boolean) { output.putBoolean(key, (Boolean) value); } else if (value instanceof Integer) { output.putInt(key, (Integer) value); } else if (value instanceof Double) { output.putDouble(key, (Double) value); } else if (value instanceof String) { output.putString(key, (String) value); } else { output.putString(key, value.toString()); } } return output; }
Example 6
Source File: NativeAnimatedModule.java From react-native-GPay with MIT License | 6 votes |
@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); } }); }
Example 7
Source File: MusicControlEventEmitter.java From react-native-music-control with MIT License | 6 votes |
private static void sendEvent(ReactApplicationContext context, String type, Object value) { WritableMap data = Arguments.createMap(); data.putString("name", type); if (value != null) { 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); }
Example 8
Source File: ReactRootView.java From react-native-GPay with MIT License | 6 votes |
private void checkForKeyboardEvents() { getRootView().getWindowVisibleDisplayFrame(mVisibleViewArea); final int heightDiff = DisplayMetricsHolder.getWindowDisplayMetrics().heightPixels - mVisibleViewArea.bottom; if (mKeyboardHeight != heightDiff && heightDiff > mMinKeyboardHeightDetected) { // keyboard is now showing, or the keyboard height has changed mKeyboardHeight = heightDiff; WritableMap params = Arguments.createMap(); WritableMap coordinates = Arguments.createMap(); coordinates.putDouble("screenY", PixelUtil.toDIPFromPixel(mVisibleViewArea.bottom)); coordinates.putDouble("screenX", PixelUtil.toDIPFromPixel(mVisibleViewArea.left)); coordinates.putDouble("width", PixelUtil.toDIPFromPixel(mVisibleViewArea.width())); coordinates.putDouble("height", PixelUtil.toDIPFromPixel(mKeyboardHeight)); params.putMap("endCoordinates", coordinates); sendEvent("keyboardDidShow", params); } else if (mKeyboardHeight != 0 && heightDiff <= mMinKeyboardHeightDetected) { // keyboard is now hidden mKeyboardHeight = 0; sendEvent("keyboardDidHide", null); } }
Example 9
Source File: CameraRollManager.java From react-native-GPay with MIT License | 5 votes |
private static void putLocationInfo( Cursor photos, WritableMap node, int longitudeIndex, int latitudeIndex) { double longitude = photos.getDouble(longitudeIndex); double latitude = photos.getDouble(latitudeIndex); if (longitude > 0 || latitude > 0) { WritableMap location = new WritableNativeMap(); location.putDouble("longitude", longitude); location.putDouble("latitude", latitude); node.putMap("location", location); } }
Example 10
Source File: HeartrateHistory.java From react-native-google-fit with MIT License | 5 votes |
private void processDataSet(DataSet dataSet, WritableArray map) { //Log.i(TAG, "Data returned for Data type: " + dataSet.getDataType().getName()); Format formatter = new SimpleDateFormat("EEE"); // WritableMap stepMap = Arguments.createMap(); for (DataPoint dp : dataSet.getDataPoints()) { WritableMap stepMap = Arguments.createMap(); String day = formatter.format(new Date(dp.getStartTime(TimeUnit.MILLISECONDS))); int i = 0; for(Field field : dp.getDataType().getFields()) { i++; if (i > 1) continue; stepMap.putString("day", day); stepMap.putDouble("startDate", dp.getStartTime(TimeUnit.MILLISECONDS)); stepMap.putDouble("endDate", dp.getEndTime(TimeUnit.MILLISECONDS)); if (this.dataType == HealthDataTypes.TYPE_BLOOD_PRESSURE) { stepMap.putDouble("value2", dp.getValue(HealthFields.FIELD_BLOOD_PRESSURE_DIASTOLIC).asFloat()); stepMap.putDouble("value", dp.getValue(HealthFields.FIELD_BLOOD_PRESSURE_SYSTOLIC).asFloat()); } else { stepMap.putDouble("value", dp.getValue(field).asFloat()); } map.pushMap(stepMap); } } }
Example 11
Source File: ReactChatInputManager.java From aurora-imui with MIT License | 5 votes |
@Override public void receiveCommand(ChatInputView root, int commandId, @Nullable ReadableArray args) { switch (commandId) { case INIT_MENU_HEIGHT: if (args == null) { return; } mMenuContainerHeight = root.dp2px(args.getInt(0)); mSoftKeyboardHeight = mMenuContainerHeight; root.setMenuContainerHeight(mMenuContainerHeight); break; case CLOSE_SOFT_INPUT: EmoticonsKeyboardUtils.closeSoftKeyboard(root.getInputView()); break; case GET_INPUT_TEXT: EventBus.getDefault().post(new GetTextEvent(root.getInputView().getText().toString(), AuroraIMUIModule.GET_INPUT_TEXT_EVENT)); break; case RESET_MENU_STATE: try { WritableMap event = Arguments.createMap(); mShowMenu = args.getBoolean(0); mContext.getCurrentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); if (mInitState) { event.putDouble("height", mInitialChatInputHeight); } else { event.putDouble("height", calculateMenuHeight()); } mContext.getJSModule(RCTEventEmitter.class).receiveEvent(mChatInput.getId(), ON_INPUT_SIZE_CHANGED_EVENT, event); } catch (Exception e) { e.printStackTrace(); } break; } }
Example 12
Source File: GeolocationModule.java From react-native-baidu-map with MIT License | 5 votes |
@ReactMethod public void convertGPSCoor(double lat, double lng, Promise promise) { Log.i("convertGPSCoor", "convertGPSCoor"); LatLng latLng = getBaiduCoorFromGPSCoor(new LatLng(lat, lng)); WritableMap map = Arguments.createMap(); map.putDouble("latitude", latLng.latitude); map.putDouble("longitude", latLng.longitude); promise.resolve(map); }
Example 13
Source File: Manager.java From react-native-fitness with MIT License | 5 votes |
private void processStep(DataSet dataSet, WritableArray map) { WritableMap stepMap = Arguments.createMap(); for (DataPoint dp : dataSet.getDataPoints()) { for(Field field : dp.getDataType().getFields()) { stepMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS))); stepMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS))); stepMap.putDouble("quantity", dp.getValue(field).asInt()); map.pushMap(stepMap); } } }
Example 14
Source File: ArgumentUtils.java From react-native-pjsip with GNU General Public License v3.0 | 5 votes |
private static WritableMap fromJsonObject(JsonObject object) { WritableMap result = new WritableNativeMap(); for (Map.Entry<String, JsonElement> entry : object.entrySet()) { Object value = fromJson(entry.getValue()); if (value instanceof WritableMap) { result.putMap(entry.getKey(), (WritableMap) value); } else if (value instanceof WritableArray) { result.putArray(entry.getKey(), (WritableArray) value); } else if (value instanceof String) { result.putString(entry.getKey(), (String) value); } else if (value instanceof LazilyParsedNumber) { result.putInt(entry.getKey(), ((LazilyParsedNumber) value).intValue()); } else if (value instanceof Integer) { result.putInt(entry.getKey(), (Integer) value); } else if (value instanceof Double) { result.putDouble(entry.getKey(), (Double) value); } else if (value instanceof Boolean) { result.putBoolean(entry.getKey(), (Boolean) value); } else { Log.d("ArgumentUtils", "Unknown type: " + value.getClass().getName()); result.putNull(entry.getKey()); } } return result; }
Example 15
Source File: MapListener.java From react-native-baidu-map with MIT License | 5 votes |
@Override public void onMapClick(LatLng latLng) { WritableMap writableMap = Arguments.createMap(); writableMap.putDouble("latitude", latLng.latitude); writableMap.putDouble("longitude", latLng.longitude); mapView.getMap().hideInfoWindow(); sendEvent(mapView, "onMapClick", writableMap); }
Example 16
Source File: NavigationModule.java From react-native-navigation with MIT License | 5 votes |
@ReactMethod public void getNavigationConstants(Promise promise) { ReactApplicationContext ctx = getReactApplicationContext(); WritableMap constants = Arguments.createMap(); constants.putString(Constants.BACK_BUTTON_JS_KEY, Constants.BACK_BUTTON_ID); constants.putDouble(Constants.BOTTOM_TABS_HEIGHT_KEY, Constants.BOTTOM_TABS_HEIGHT); constants.putDouble(Constants.STATUS_BAR_HEIGHT_KEY, pxToDp(ctx, StatusBarUtils.getStatusBarHeight(ctx))); constants.putDouble(Constants.TOP_BAR_HEIGHT_KEY, pxToDp(ctx, UiUtils.getTopBarHeight(ctx))); promise.resolve(constants); }
Example 17
Source File: LocationModule.java From rn-background-location with MIT License | 5 votes |
@Override public void createEventReceiver() { mEventReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { LocationCoordinates locationCoordinates = mGson.fromJson( intent.getStringExtra(LOCATION_EVENT_DATA_NAME), LocationCoordinates.class); WritableMap eventData = Arguments.createMap(); eventData.putDouble( LocationForegroundService.JS_LOCATION_LAT_KEY, locationCoordinates.getLatitude()); eventData.putDouble( LocationForegroundService.JS_LOCATION_LON_KEY, locationCoordinates.getLongitude()); eventData.putDouble( LocationForegroundService.JS_LOCATION_TIME_KEY, locationCoordinates.getTimestamp()); // if you actually want to send events to JS side, it needs to be in the "Module" sendEventToJS(getReactApplicationContext(), LocationForegroundService.JS_LOCATION_EVENT_NAME, eventData); } }; }
Example 18
Source File: RNX5WebViewManager.java From react-native-x5 with MIT License | 5 votes |
private WritableMap createWebViewEvent(WebView webView, String url) { WritableMap event = Arguments.createMap(); event.putDouble("target", webView.getId()); // Don't use webView.getUrl() here, the URL isn't updated to the new value yet in callbacks // like onPageFinished event.putString("url", url); event.putBoolean("loading", !mLastLoadFailed && webView.getProgress() != 100); event.putString("title", webView.getTitle()); event.putBoolean("canGoBack", webView.canGoBack()); event.putBoolean("canGoForward", webView.canGoForward()); return event; }
Example 19
Source File: PageScrollEvent.java From react-native-tabbed-view-pager-android with MIT License | 4 votes |
private WritableMap serializeEventData() { WritableMap eventData = Arguments.createMap(); eventData.putInt("position", mPosition); eventData.putDouble("offset", mOffset); return eventData; }
Example 20
Source File: RNMlKitModule.java From react-native-firebase-mlkit with MIT License | 4 votes |
private WritableArray processFaceDetectionResult(List<FirebaseVisionFace> firebaseVisionFaces){ WritableArray data = Arguments.createArray(); if(firebaseVisionFaces.size() > 0){ WritableMap info = Arguments.createMap(); for (FirebaseVisionFace face : firebaseVisionFaces){ info = Arguments.createMap(); //face bounding box Rect faceBounding = face.getBoundingBox(); WritableMap faceBox = Arguments.createMap(); faceBox.putInt("top", faceBounding.top); faceBox.putInt("right", faceBounding.right); faceBox.putInt("bottom", faceBounding.bottom); faceBox.putInt("left", faceBounding.left); info.putMap("faceBoundingRect", faceBox); // If classification was enabled: if (face.getSmilingProbability() != FirebaseVisionFace.UNCOMPUTED_PROBABILITY) { float smileProb = face.getSmilingProbability(); info.putDouble("smileProbability", (double)smileProb); } if (face.getRightEyeOpenProbability() != FirebaseVisionFace.UNCOMPUTED_PROBABILITY) { float rightEyeOpenProb = face.getRightEyeOpenProbability(); info.putDouble("rightEyeOpenProbability", (double)rightEyeOpenProb); } // If face tracking was enabled: if (face.getTrackingId() != FirebaseVisionFace.INVALID_ID) { int id = face.getTrackingId(); info.putInt("faceTrackingId", id); } //eyes info.putArray("leftEyeContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.LEFT_EYE)); info.putArray("rightEyeContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.RIGHT_EYE)); //face info.putArray("faceContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.FACE)); //lower lip info.putArray("lowerLipBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.LOWER_LIP_BOTTOM)); info.putArray("lowerLipBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.LOWER_LIP_TOP)); //upper lip info.putArray("upperLipTopContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.UPPER_LIP_TOP)); info.putArray("upperLipBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.UPPER_LIP_BOTTOM)); //nose info.putArray("noiseBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.NOSE_BOTTOM)); info.putArray("noiseBridgeContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.NOSE_BRIDGE)); //left eyebrow info.putArray("leftEyeBrowBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.LEFT_EYEBROW_BOTTOM)); info.putArray("leftEyeBrowTopContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.LEFT_EYEBROW_TOP)); // right eyebrow info.putArray("rightEyeBrowBottomContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.RIGHT_EYEBROW_BOTTOM)); info.putArray("rightEyeBrowTopContourPoints", Utils.getContourPointsWritableArray(face, FirebaseVisionFaceContour.RIGHT_EYEBROW_TOP)); data.pushMap(info); } } return data; }