List of usage examples for com.facebook.react.bridge ReadableMap getArray
@Nullable ReadableArray getArray(@NonNull String name);
From source file:com.adjust.nativemodule.AdjustUtil.java
License:Open Source License
/** * toObject extracts a value from a {@link ReadableMap} by its key, * and returns a POJO representing that object. * //w w w .ja v a 2s .com * @param readableMap The Map to containing the value to be converted * @param key The key for the value to be converted * @return The converted POJO */ private static Object toObject(@Nullable ReadableMap readableMap, String key) { if (readableMap == null) { return null; } Object result = null; ReadableType readableType = readableMap.getType(key); switch (readableType) { case Null: result = null; break; case Boolean: result = readableMap.getBoolean(key); break; case Number: // Can be int or double. double tmp = readableMap.getDouble(key); if (tmp == (int) tmp) { result = (int) tmp; } else { result = tmp; } break; case String: result = readableMap.getString(key); break; case Map: result = toMap(readableMap.getMap(key)); break; case Array: result = toList(readableMap.getArray(key)); break; default: AdjustFactory.getLogger().error("Could not convert object with key: " + key + "."); } return result; }
From source file:com.amazonaws.reactnative.core.AWSRNClientMarshaller.java
License:Open Source License
public static Object toObject(@Nullable ReadableMap readableMap, String key) { if (readableMap == null) { return null; }/* w w w . j ava 2 s. c o m*/ Object result; final ReadableType readableType = readableMap.getType(key); switch (readableType) { case Null: result = key; break; case Boolean: result = readableMap.getBoolean(key); break; case Number: // Can be int or double. double tmp = readableMap.getDouble(key); if (tmp == (int) tmp) { result = (int) tmp; } else { result = tmp; } break; case String: result = readableMap.getString(key); break; case Map: result = readableMapToMap(readableMap.getMap(key)); break; case Array: result = readableArrayToList(readableMap.getArray(key)); break; default: throw new IllegalArgumentException("Could not convert object with key: " + key + "."); } return result; }
From source file:com.auth0.lock.react.bridge.ShowOptions.java
License:Open Source License
public ShowOptions(@Nullable ReadableMap options) { if (options == null) { return;//from w ww . j a v a2 s . com } if (options.hasKey(CLOSABLE_KEY)) { closable = options.getBoolean(CLOSABLE_KEY); Log.d(TAG, CLOSABLE_KEY + closable); } if (options.hasKey(DISABLE_SIGNUP)) { disableSignUp = options.getBoolean(DISABLE_SIGNUP); Log.d(TAG, DISABLE_SIGNUP + disableSignUp); } if (options.hasKey(DISABLE_RESET_PASSWORD)) { disableResetPassword = options.getBoolean(DISABLE_RESET_PASSWORD); Log.d(TAG, DISABLE_RESET_PASSWORD + disableResetPassword); } if (options.hasKey(USE_MAGIC_LINK_KEY)) { useMagicLink = options.getBoolean(USE_MAGIC_LINK_KEY); Log.d(TAG, USE_MAGIC_LINK_KEY + useMagicLink); } if (options.hasKey(AUTH_PARAMS_KEY)) { ReadableMap reactMap = options.getMap(AUTH_PARAMS_KEY); authParams = OptionsHelper.convertReadableMapToMap(reactMap); Log.d(TAG, AUTH_PARAMS_KEY + authParams); } if (options.hasKey(CONNECTIONS_KEY)) { ReadableArray connections = options.getArray(CONNECTIONS_KEY); List<String> list = new ArrayList<>(connections.size()); for (int i = 0; i < connections.size(); i++) { String connectionName = connections.getString(i); switch (connectionName) { case LockReactModule.CONNECTION_EMAIL: connectionType = LockReactModule.CONNECTION_EMAIL; break; case LockReactModule.CONNECTION_SMS: connectionType = LockReactModule.CONNECTION_SMS; break; } list.add(connectionName); } this.connections = new String[list.size()]; this.connections = list.toArray(this.connections); Log.d(TAG, CONNECTIONS_KEY + list); } }
From source file:com.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java
License:Apache License
private HashMap<String, Object> convertMapToHashMap(ReadableMap readableMap) { HashMap<String, Object> json = new HashMap<>(); ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); switch (readableMap.getType(key)) { case Null: json.put(key, null);/*from ww w. ja va2 s . co m*/ break; case Boolean: json.put(key, readableMap.getBoolean(key)); break; case Number: json.put(key, readableMap.getDouble(key)); break; case String: json.put(key, readableMap.getString(key)); break; case Map: json.put(key, convertMapToHashMap(readableMap.getMap(key))); break; case Array: json.put(key, convertArrayToArrayList(readableMap.getArray(key))); break; } } return json; }
From source file:com.boundlessgeo.spatialconnect.jsbridge.SCBridge.java
License:Apache License
private static JSONObject convertMapToJson(ReadableMap readableMap) { JSONObject object = new JSONObject(); ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); try {/*w w w . j a v a 2s . co m*/ while (iterator.hasNextKey()) { String key = iterator.nextKey(); switch (readableMap.getType(key)) { case Null: object.put(key, JSONObject.NULL); break; case Boolean: object.put(key, readableMap.getBoolean(key)); break; case Number: object.put(key, readableMap.getDouble(key)); break; case String: object.put(key, readableMap.getString(key)); break; case Map: object.put(key, convertMapToJson(readableMap.getMap(key))); break; case Array: object.put(key, convertArrayToJson(readableMap.getArray(key))); break; } } } catch (JSONException e) { Log.e(LOG_TAG, "Could not convert to json"); e.printStackTrace(); } return object; }
From source file:com.dylanvann.cameraroll.CameraRollManager.java
License:Open Source License
/** * Get photos from {@link MediaStore.Images}, most recent first. * * @param params a map containing the following keys: * <ul>/*from ww w .j a v a 2 s .c o m*/ * <li>first (mandatory): a number representing the number of photos to fetch</li> * <li> * after (optional): a cursor that matches page_info[end_cursor] returned by a * previous call to {@link #getPhotos} * </li> * <li>groupName (optional): an album name</li> * <li> * mimeType (optional): restrict returned images to a specific mimetype (e.g. * image/jpeg) * </li> * </ul> * @param promise the Promise to be resolved when the photos are loaded; for a format of the * parameters passed to this callback, see {@code getPhotosReturnChecker} in CameraRoll.js */ @ReactMethod public void getPhotos(final ReadableMap params, final Promise promise) { int first = params.getInt("first"); String after = params.hasKey("after") ? params.getString("after") : null; String albumId = params.hasKey("albumId") ? params.getString("albumId") : null; ReadableArray mimeTypes = params.hasKey("mimeTypes") ? params.getArray("mimeTypes") : null; if (params.hasKey("groupTypes")) { throw new JSApplicationIllegalArgumentException("groupTypes is not supported on Android"); } new GetPhotosTask(getReactApplicationContext(), first, after, albumId, mimeTypes, promise) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.hijridatepicker.HijriDatePickerAndroidModule.java
License:Open Source License
private Bundle createFragmentArguments(ReadableMap options, Promise promise) { final Bundle args = new Bundle(); try {/* w ww .j ava 2 s . com*/ if (options.hasKey(ARG_DATE) && !options.isNull(ARG_DATE)) { if (!parseOptionsWithKey(ARG_DATE, options, args, promise)) return null; } if (options.hasKey(ARG_MINDATE) && !options.isNull(ARG_MINDATE)) { if (!parseOptionsWithKey(ARG_MINDATE, options, args, promise)) return null; } if (options.hasKey(ARG_MAXDATE) && !options.isNull(ARG_MAXDATE)) { if (!parseOptionsWithKey(ARG_MAXDATE, options, args, promise)) return null; } if (options.hasKey(ARG_MODE) && !options.isNull(ARG_MODE)) { args.putString(ARG_MODE, options.getString(ARG_MODE)); } if (options.hasKey(ARG_WEEK_DAY_LABELS) && !options.isNull(ARG_WEEK_DAY_LABELS)) { args.putStringArrayList(ARG_WEEK_DAY_LABELS, toStringArrayList(options.getArray(ARG_WEEK_DAY_LABELS))); } } catch (Exception e) { promise.reject(ERROR_PARSING_OPTIONS, "Exception happened while parsing options, details: " + e.getMessage()); return null; } return args; }
From source file:com.ibatimesheet.RNJSONUtils.java
License:Apache License
public static JSONObject convertMapToJson(ReadableMap readableMap) throws JSONException { JSONObject object = new JSONObject(); ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); switch (readableMap.getType(key)) { case Null: object.put(key, JSONObject.NULL); break; case Boolean: object.put(key, readableMap.getBoolean(key)); break; case Number: object.put(key, readableMap.getDouble(key)); break; case String: object.put(key, readableMap.getString(key)); break; case Map: object.put(key, convertMapToJson(readableMap.getMap(key))); break; case Array: object.put(key, convertArrayToJson(readableMap.getArray(key))); break; }//from ww w .jav a2 s . co m } return object; }
From source file:com.microsoft.appcenter.reactnative.analytics.ReactNativeUtils.java
License:Open Source License
public static JSONObject convertReadableMapToJsonObject(ReadableMap map) throws JSONException { JSONObject jsonObj = new JSONObject(); ReadableMapKeySetIterator it = map.keySetIterator(); while (it.hasNextKey()) { String key = it.nextKey(); ReadableType type = map.getType(key); switch (type) { case Map: jsonObj.put(key, convertReadableMapToJsonObject(map.getMap(key))); break; case Array: jsonObj.put(key, convertReadableArrayToJsonArray(map.getArray(key))); break; case String: jsonObj.put(key, map.getString(key)); break; case Number: Double number = map.getDouble(key); if ((number == Math.floor(number)) && !Double.isInfinite(number)) { jsonObj.put(key, number.longValue()); } else { jsonObj.put(key, number.doubleValue()); }//from ww w . ja va 2s .co m break; case Boolean: jsonObj.put(key, map.getBoolean(key)); break; default: jsonObj.put(key, null); break; } } return jsonObj; }
From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java
private static JSONObject mapToJson(ReadableMap map) { ReadableMapKeySetIterator iterator = map.keySetIterator(); JSONObject json = new JSONObject(); try {/*from w ww .j av a2s. c om*/ while (iterator.hasNextKey()) { String key = iterator.nextKey(); switch (map.getType(key)) { case String: json.put(key, map.getString(key)); break; case Boolean: json.put(key, map.getBoolean(key)); break; case Number: json.put(key, map.getDouble(key)); break; case Map: json.put(key, mapToJson(map.getMap(key))); break; case Array: json.put(key, arrayToJson(map.getArray(key))); break; } } } catch (JSONException e) { e.printStackTrace(); } return json; }