List of usage examples for com.facebook.react.bridge WritableMap putNull
void putNull(@NonNull String key);
From source file:com.amazonaws.reactnative.core.AWSRNClientMarshaller.java
License:Open Source License
public static WritableMap jsonToReact(final JSONObject jsonObject) throws JSONException { final WritableMap writableMap = Arguments.createMap(); final Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { final String key = (String) iterator.next(); final 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 instanceof Boolean) { writableMap.putBoolean(key, jsonObject.getBoolean(key)); } else if (value == JSONObject.NULL) { writableMap.putNull(key); }/*from w ww . ja v a 2 s. co m*/ } return writableMap; }
From source file:com.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java
License:Apache License
private WritableMap convertHashMapToMap(Map<String, Object> hashMap) { WritableMap writableMap = Arguments.createMap(); for (Map.Entry<String, Object> entry : hashMap.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value == null) { writableMap.putNull(key); } else if (value instanceof Boolean) { writableMap.putBoolean(key, (Boolean) value); } else if (value instanceof Double) { writableMap.putDouble(key, (Double) value); } else if (value instanceof Integer) { writableMap.putInt(key, (Integer) value); } else if (value instanceof Long) { writableMap.putDouble(key, (Long) value); } else if (value instanceof String) { writableMap.putString(key, (String) value); } else if (value instanceof Map) { writableMap.putMap(key, convertHashMapToMap((Map) value)); } else if (value instanceof List) { writableMap.putArray(key, convertArrayToArrayList((List) value)); }/*from www . j a v a2 s . c o m*/ } return writableMap; }
From source file:com.microsoft.appcenter.reactnative.crashes.RNUtils.java
License:Open Source License
public static WritableMap convertJsonObjectToWritableMap(JSONObject jsonObj) throws JSONException { WritableMap map = Arguments.createMap(); Iterator<String> it = jsonObj.keys(); while (it.hasNext()) { String key = it.next();/* ww w . j a va 2 s . c o m*/ Object obj; obj = jsonObj.get(key); if (obj instanceof JSONObject) map.putMap(key, convertJsonObjectToWritableMap((JSONObject) obj)); else if (obj instanceof JSONArray) map.putArray(key, convertJsonArrayToWritableArray((JSONArray) obj)); else if (obj instanceof String) map.putString(key, (String) obj); else if (obj instanceof Double) map.putDouble(key, (Double) obj); else if (obj instanceof Integer) map.putInt(key, (Integer) obj); else if (obj instanceof Boolean) map.putBoolean(key, (Boolean) obj); else if (obj == null) map.putNull(key); else throw new JSONException("Unrecognized object: " + obj); } return map; }
From source file:com.reactlibrary.ScanditBarcodeHelpers.java
License:Apache License
static public WritableMap jsonObjectToWritableMap(JSONObject json) { WritableMap map = Arguments.createMap(); Iterator<?> keys = json.keys(); while (keys.hasNext()) { String key = (String) keys.next(); try {//from w w w . ja v a2 s . c om Object value = json.get(key); if (value instanceof Boolean) map.putBoolean(key, (Boolean) value); else if (value instanceof String) map.putString(key, (String) value); else if (value instanceof Double) map.putDouble(key, (Double) value); else if (value instanceof Integer) map.putInt(key, (Integer) value); else if (value instanceof WritableMap) map.putMap(key, (WritableMap) value); else if (value instanceof WritableArray) map.putArray(key, (WritableArray) value); else if (value == null) map.putNull(key); else if (value instanceof JSONArray) { map.putArray(key, jsonArrayToWritableArray((JSONArray) value)); } else if (value instanceof JSONObject) { map.putMap(key, jsonObjectToWritableMap((JSONObject) value)); } else Log.e("React", "Value type not handled: " + value.getClass()); } catch (JSONException e) { Log.e("React", "Could not append value of settings key '" + key + "'"); } } return map; }
From source file:com.shahenlibrary.Trimmer.Trimmer.java
License:Open Source License
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static void getVideoInfo(String path, Promise promise, ReactApplicationContext ctx) { FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever(); try {//w w w . j a v a2s .c o m if (VideoEdit.shouldUseURI(path)) { mmr.setDataSource(ctx, Uri.parse(path)); } else { mmr.setDataSource(path); } int duration = Integer .parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION)); int width = Integer .parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)); int height = Integer .parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)); int orientation = Integer .parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION)); // METADATA_KEY_FRAMERATE returns a float or int or might not exist Integer frameRate = VideoEdit .getIntFromString(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_FRAMERATE)); // METADATA_KEY_VARIANT_BITRATE returns a int or might not exist Integer bitrate = VideoEdit.getIntFromString( mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VARIANT_BITRATE)); if (orientation == 90 || orientation == 270) { width = width + height; height = width - height; width = width - height; } WritableMap event = Arguments.createMap(); WritableMap size = Arguments.createMap(); size.putInt(Events.WIDTH, width); size.putInt(Events.HEIGHT, height); event.putMap(Events.SIZE, size); event.putInt(Events.DURATION, duration / 1000); event.putInt(Events.ORIENTATION, orientation); if (frameRate != null) { event.putInt(Events.FRAMERATE, frameRate); } else { event.putNull(Events.FRAMERATE); } if (bitrate != null) { event.putInt(Events.BITRATE, bitrate); } else { event.putNull(Events.BITRATE); } promise.resolve(event); } finally { mmr.release(); } }
From source file:com.tkporter.fabrictwitterkit.FabricTwitterKitUtils.java
License:MIT License
private static WritableMap jsonToWritableMap(final JSONObject jsonObject) throws JSONException { final WritableMap writableMap = Arguments.createMap(); final Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { final String key = (String) iterator.next(); final 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, jsonToWritableMap(jsonObject.getJSONObject(key))); } else if (value instanceof JSONArray) { writableMap.putArray(key, jsonToWritableArray(jsonObject.getJSONArray(key))); } else if (value instanceof Boolean) { writableMap.putBoolean(key, jsonObject.getBoolean(key)); } else if (value == JSONObject.NULL) { writableMap.putNull(key); }//from w w w. ja v a2 s.c o m } return writableMap; }
From source file:it.near.sdk.reactnative.rnnearitsdk.RNNearItUtils.java
License:Mozilla Public License
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(), toWritableMap((Map<String, Object>) value)); } else if (value.getClass() != null && value.getClass().isArray()) { writableMap.putArray((String) pair.getKey(), toWritableArray((Object[]) value)); }/*from w w w. j a va 2s. c o m*/ } return writableMap; }