Java Code Examples for com.facebook.react.bridge.ReadableMap#keySetIterator()
The following examples show how to use
com.facebook.react.bridge.ReadableMap#keySetIterator() .
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: RCTConvert.java From react-native-twilio-chat with MIT License | 6 votes |
public static HashMap<String, Object> readableMapToHashMap(ReadableMap readableMap) { if (readableMap == null) { return null; } HashMap map = new HashMap<String, Object>(); ReadableMapKeySetIterator keySetIterator = readableMap.keySetIterator(); while (keySetIterator.hasNextKey()) { String key = keySetIterator.nextKey(); ReadableType type = readableMap.getType(key); switch(type) { case String: map.put(key, readableMap.getString(key)); break; case Map: HashMap<String, Object> attributes = new RCTConvert().readableMapToHashMap(readableMap.getMap(key)); map.put(key, attributes); break; default: // do nothing } } return map; }
Example 2
Source File: RCTConvert.java From react-native-twilio-ip-messaging with MIT License | 6 votes |
public static HashMap<String, Object> readableMapToHashMap(ReadableMap readableMap) { if (readableMap == null) { return null; } HashMap map = new HashMap<String, Object>(); ReadableMapKeySetIterator keySetIterator = readableMap.keySetIterator(); while (keySetIterator.hasNextKey()) { String key = keySetIterator.nextKey(); ReadableType type = readableMap.getType(key); switch(type) { case String: map.put(key, readableMap.getString(key)); break; case Map: HashMap<String, Object> attributes = new RCTConvert().readableMapToHashMap(readableMap.getMap(key)); map.put(key, attributes); break; default: // do nothing } } return map; }
Example 3
Source File: FlurryModule.java From react-native-flurry-sdk with Apache License 2.0 | 6 votes |
@ReactMethod public void getConfigStringMap(ReadableMap keyAndDefault, Promise promise) { try { WritableMap map = Arguments.createMap(); if (keyAndDefault != null) { ReadableMapKeySetIterator iterator = keyAndDefault.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); String defaultValue = keyAndDefault.getString(key); map.putString(key, FlurryConfig.getInstance().getString(key, defaultValue)); } } promise.resolve(map); } catch (IllegalViewOperationException e) { promise.reject("Flurry.getConfigString", e); } }
Example 4
Source File: MapUtil.java From react-native-app-auth with MIT License | 5 votes |
public static HashMap<String, String> readableMapToHashMap(@Nullable ReadableMap readableMap) { HashMap<String, String> hashMap = new HashMap<>(); if (readableMap != null) { ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); while (iterator.hasNextKey()) { String nextKey = iterator.nextKey(); hashMap.put(nextKey, readableMap.getString(nextKey)); } } return hashMap; }
Example 5
Source File: Downloader.java From react-native-simple-download-manager with MIT License | 5 votes |
public DownloadManager.Request createRequest(String url, ReadableMap headers, ReadableMap requestConfig) { String downloadTitle = requestConfig.getString("downloadTitle"); String downloadDescription = requestConfig.getString("downloadTitle"); String saveAsName = requestConfig.getString("saveAsName"); Boolean external = requestConfig.getBoolean("external"); String external_path = requestConfig.getString("path"); Boolean allowedInRoaming = requestConfig.getBoolean("allowedInRoaming"); Boolean allowedInMetered = requestConfig.getBoolean("allowedInMetered"); Boolean showInDownloads = requestConfig.getBoolean("showInDownloads"); Uri downloadUri = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(downloadUri); ReadableMapKeySetIterator iterator = headers.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); request.addRequestHeader(key, headers.getString(key)); } if(external){ request.setDestinationInExternalPublicDir(external_path, saveAsName); }else{ request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, saveAsName); } request.setTitle(downloadTitle); request.setDescription(downloadDescription); request.setAllowedOverRoaming(allowedInRoaming); request.setAllowedOverMetered(allowedInMetered); request.setVisibleInDownloadsUi(showInDownloads); request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); return request; }
Example 6
Source File: JSONParser.java From react-native-navigation with MIT License | 5 votes |
public JSONObject parse(ReadableMap map) { try { ReadableMapKeySetIterator it = map.keySetIterator(); JSONObject result = new JSONObject(); while (it.hasNextKey()) { String key = it.nextKey(); switch (map.getType(key)) { case String: result.put(key, map.getString(key)); break; case Number: result.put(key, parseNumber(map, key)); break; case Boolean: result.put(key, map.getBoolean(key)); break; case Array: result.put(key, parse(map.getArray(key))); break; case Map: result.put(key, parse(map.getMap(key))); break; default: break; } } return result; } catch (JSONException e) { throw new RuntimeException(e); } }
Example 7
Source File: PjActions.java From react-native-pjsip with GNU General Public License v3.0 | 5 votes |
private static void formatIntent(Intent intent, ReadableMap configuration) { if (configuration == null) { return; } ReadableMapKeySetIterator it = configuration.keySetIterator(); while (it.hasNextKey()) { String key = it.nextKey(); switch (configuration.getType(key)) { case Null: intent.putExtra(key, (String) null); break; case String: intent.putExtra(key, configuration.getString(key)); break; case Number: intent.putExtra(key, configuration.getInt(key)); break; case Boolean: intent.putExtra(key, configuration.getBoolean(key)); break; case Map: intent.putExtra(key, (Serializable) formatMap(configuration.getMap(key))); break; default: Log.w(TAG, "Unable to put extra information for intent: unknown type \""+ configuration.getType(key) +"\""); break; } } }
Example 8
Source File: MapUtil.java From vinci with Apache License 2.0 | 5 votes |
public static JSONObject toJSONObject(ReadableMap readableMap) throws JSONException { JSONObject jsonObject = new JSONObject(); ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType type = readableMap.getType(key); switch (type) { case Null: jsonObject.put(key, null); break; case Boolean: jsonObject.put(key, readableMap.getBoolean(key)); break; case Number: jsonObject.put(key, readableMap.getDouble(key)); break; case String: jsonObject.put(key, readableMap.getString(key)); break; case Map: jsonObject.put(key, MapUtil.toJSONObject(readableMap.getMap(key))); break; case Array: jsonObject.put(key, ArrayUtil.toJSONArray(readableMap.getArray(key))); break; } } return jsonObject; }
Example 9
Source File: ReactVideoView.java From react-native-video with MIT License | 5 votes |
/** * toStringMap converts a {@link ReadableMap} into a HashMap. * * @param readableMap The ReadableMap to be conveted. * @return A HashMap containing the data that was in the ReadableMap. * @see 'Adapted from https://github.com/artemyarulin/react-native-eval/blob/master/android/src/main/java/com/evaluator/react/ConversionUtil.java' */ public static Map<String, String> toStringMap(@Nullable ReadableMap readableMap) { Map<String, String> result = new HashMap<>(); if (readableMap == null) return result; com.facebook.react.bridge.ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); result.put(key, readableMap.getString(key)); } return result; }
Example 10
Source File: MapUtil.java From react-native-background-geolocation with Apache License 2.0 | 5 votes |
public static Map<String, Object> toMap(ReadableMap readableMap) { Map<String, Object> map = new HashMap<>(); ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType type = readableMap.getType(key); switch (type) { case Null: map.put(key, null); break; case Boolean: map.put(key, readableMap.getBoolean(key)); break; case Number: map.put(key, readableMap.getDouble(key)); break; case String: map.put(key, readableMap.getString(key)); break; case Map: map.put(key, MapUtil.toMap(readableMap.getMap(key))); break; case Array: map.put(key, ArrayUtil.toArray(readableMap.getArray(key))); break; } } return map; }
Example 11
Source File: ReactNativeJson.java From react-native-fcm with MIT License | 5 votes |
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; } } return object; }
Example 12
Source File: OAuthManagerModule.java From react-native-oauth with MIT License | 5 votes |
@ReactMethod public void configureProvider( final String providerName, final ReadableMap params, @Nullable final Callback onComplete ) { Log.i(TAG, "configureProvider for " + providerName); // Save callback url for later String callbackUrlStr = params.getString("callback_url"); _callbackUrls.add(callbackUrlStr); Log.d(TAG, "Added callback url " + callbackUrlStr + " for providler " + providerName); // Keep configuration map HashMap<String, Object> cfg = new HashMap<String,Object>(); ReadableMapKeySetIterator iterator = params.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType readableType = params.getType(key); switch(readableType) { case String: String val = params.getString(key); // String escapedVal = Uri.encode(val); cfg.put(key, val); break; default: throw new IllegalArgumentException("Could not read object with key: " + key); } } _configuration.put(providerName, cfg); onComplete.invoke(null, true); }
Example 13
Source File: IntercomModule.java From react-native-intercom with MIT License | 5 votes |
private Map<String, Object> recursivelyDeconstructReadableMap(ReadableMap readableMap) { ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); Map<String, Object> deconstructedMap = new HashMap<>(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType type = readableMap.getType(key); switch (type) { case Null: deconstructedMap.put(key, null); break; case Boolean: deconstructedMap.put(key, readableMap.getBoolean(key)); break; case Number: deconstructedMap.put(key, readableMap.getDouble(key)); break; case String: deconstructedMap.put(key, readableMap.getString(key)); break; case Map: deconstructedMap.put(key, recursivelyDeconstructReadableMap(readableMap.getMap(key))); break; case Array: deconstructedMap.put(key, recursivelyDeconstructReadableArray(readableMap.getArray(key))); break; default: throw new IllegalArgumentException("Could not convert object with key: " + key + "."); } } return deconstructedMap; }
Example 14
Source File: FirestackUtils.java From react-native-firestack with MIT License | 5 votes |
public static Map<String, Object> recursivelyDeconstructReadableMap(ReadableMap readableMap) { ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); Map<String, Object> deconstructedMap = new HashMap<>(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType type = readableMap.getType(key); switch (type) { case Null: deconstructedMap.put(key, null); break; case Boolean: deconstructedMap.put(key, readableMap.getBoolean(key)); break; case Number: deconstructedMap.put(key, readableMap.getDouble(key)); break; case String: deconstructedMap.put(key, readableMap.getString(key)); break; case Map: deconstructedMap.put(key, FirestackUtils.recursivelyDeconstructReadableMap(readableMap.getMap(key))); break; case Array: deconstructedMap.put(key, FirestackUtils.recursivelyDeconstructReadableArray(readableMap.getArray(key))); break; default: throw new IllegalArgumentException("Could not convert object with key: " + key + "."); } } return deconstructedMap; }
Example 15
Source File: Utils.java From magnet-client with Mozilla Public License 2.0 | 4 votes |
/** * Converts a react native readable map into a JSON object. * * @param readableMap map to convert to JSON Object * @return JSON Object that contains the readable map properties */ @Nullable public static JSONObject readableMapToJson(ReadableMap readableMap) { JSONObject jsonObject = new JSONObject(); if (readableMap == null) { return null; } ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); if (!iterator.hasNextKey()) { return null; } while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType readableType = readableMap.getType(key); try { switch (readableType) { case Null: jsonObject.put(key, null); break; case Boolean: jsonObject.put(key, readableMap.getBoolean(key)); break; case Number: // Can be int or double. jsonObject.put(key, readableMap.getInt(key)); break; case String: jsonObject.put(key, readableMap.getString(key)); break; case Map: jsonObject.put(key, readableMapToJson(readableMap.getMap(key))); break; case Array: jsonObject.put(key, readableMap.getArray(key)); default: // Do nothing and fail silently } } catch (JSONException ex) { // Do nothing and fail silently } } return jsonObject; }
Example 16
Source File: RNX5WebViewManager.java From react-native-x5 with MIT License | 4 votes |
@ReactProp(name = "source") public void setSource(WebView view, @Nullable ReadableMap source) { if (source != null) { if (source.hasKey("html")) { String html = source.getString("html"); if (source.hasKey("baseUrl")) { view.loadDataWithBaseURL( source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null); } else { view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING); } return; } if (source.hasKey("uri")) { String url = source.getString("uri"); String previousUrl = view.getUrl(); if (previousUrl != null && previousUrl.equals(url)) { return; } if (source.hasKey("method")) { String method = source.getString("method"); if (method.equals(HTTP_METHOD_POST)) { byte[] postData = null; if (source.hasKey("body")) { String body = source.getString("body"); try { postData = body.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { postData = body.getBytes(); } } if (postData == null) { postData = new byte[0]; } view.postUrl(url, postData); return; } } HashMap<String, String> headerMap = new HashMap<>(); if (source.hasKey("headers")) { ReadableMap headers = source.getMap("headers"); ReadableMapKeySetIterator iter = headers.keySetIterator(); while (iter.hasNextKey()) { String key = iter.nextKey(); if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) { if (view.getSettings() != null) { view.getSettings().setUserAgentString(headers.getString(key)); } } else { headerMap.put(key, headers.getString(key)); } } } view.loadUrl(url, headerMap); return; } } view.loadUrl(BLANK_URL); }
Example 17
Source File: ReactWebViewManager.java From react-native-GPay with MIT License | 4 votes |
@ReactProp(name = "source") public void setSource(WebView view, @Nullable ReadableMap source) { if (source != null) { if (source.hasKey("html")) { String html = source.getString("html"); if (source.hasKey("baseUrl")) { view.loadDataWithBaseURL( source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null); } else { view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING); } return; } if (source.hasKey("uri")) { String url = source.getString("uri"); String previousUrl = view.getUrl(); if (previousUrl != null && previousUrl.equals(url)) { return; } if (source.hasKey("method")) { String method = source.getString("method"); if (method.equals(HTTP_METHOD_POST)) { byte[] postData = null; if (source.hasKey("body")) { String body = source.getString("body"); try { postData = body.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { postData = body.getBytes(); } } if (postData == null) { postData = new byte[0]; } view.postUrl(url, postData); return; } } HashMap<String, String> headerMap = new HashMap<>(); if (source.hasKey("headers")) { ReadableMap headers = source.getMap("headers"); ReadableMapKeySetIterator iter = headers.keySetIterator(); while (iter.hasNextKey()) { String key = iter.nextKey(); if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) { if (view.getSettings() != null) { view.getSettings().setUserAgentString(headers.getString(key)); } } else { headerMap.put(key, headers.getString(key)); } } } view.loadUrl(url, headerMap); return; } } view.loadUrl(BLANK_URL); }
Example 18
Source File: PhotoViewWrapper.java From react-native-image-zoom with MIT License | 4 votes |
public void setSource(ReadableMap params) { mParams = params; @Nullable Uri mUri = null; String source = params.hasKey("uri") ? params.getString("uri") : null; String thumbnail = params.hasKey("thumbnail") ? params.getString("thumbnail") : null; ReadableMap headers = params.hasKey("headers") ? params.getMap("headers") : null; //handle base64 if (source.startsWith("data:image/png;base64,")){ Glide .with(this.getContext()) .load(Base64.decode(source.replaceAll("data:image\\/.*;base64,", ""), Base64.DEFAULT)) .into(this) ; return; } boolean useStorageFile = false ; // handle bundled app resources try { mUri = Uri.parse(source); // Verify scheme is set, so that relative uri (used by static resources) are not handled. if (mUri.getScheme() == null) { mUri = null; } else if( !mUri.getScheme().equals("http") && !mUri.getScheme().equals("https") ){ useStorageFile = true ; if (!mInitialized) { this.setImageURI(mUri); } } } catch (Exception e) { // ignore malformed uri, then attempt to extract resource ID. } if (mUri == null) { mUri = mResourceDrawableIdHelper.getResourceDrawableUri( this.getContext(), source ); Glide .with(this.getContext()) .load(mUri) .into(this); } else if (useStorageFile) { Glide .with(this.getContext()) .load(mUri) .into(this); } else { // Handle an http / https address RequestListener listener = this.getRequestListener(); LazyHeaders.Builder lazyHeaders = new LazyHeaders.Builder(); Log.d("null headers", String.valueOf(headers != null)); if(headers != null){ ReadableMapKeySetIterator it = headers.keySetIterator(); Log.d("next headers", String.valueOf(it.hasNextKey())); while(it.hasNextKey()){ String Key = it.nextKey(); lazyHeaders.addHeader(Key, headers.getString(Key)); } } Log.d("thing", mUri.toString()); DrawableRequestBuilder builder = Glide .with(this.getContext()) .load(new GlideUrl(mUri.toString(), lazyHeaders.build())) .listener(listener); //set thumbnails if(thumbnail != null) { DrawableRequestBuilder<String> thumbnailRequest = Glide .with(this.getContext()) .load(thumbnail); builder = builder.thumbnail(thumbnailRequest); } builder.into(this); } this.setChangeListeners(); }
Example 19
Source File: TwilioVoiceModule.java From react-native-twilio-programmable-voice with MIT License | 4 votes |
@ReactMethod public void connect(ReadableMap params) { if (BuildConfig.DEBUG) { Log.d(TAG, "connect params: "+params); } WritableMap errParams = Arguments.createMap(); if (accessToken == null) { errParams.putString("err", "Invalid access token"); eventManager.sendEvent(EVENT_DEVICE_NOT_READY, errParams); return; } if (params == null) { errParams.putString("err", "Invalid parameters"); eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, errParams); return; } else if (!params.hasKey("To")) { errParams.putString("err", "Invalid To parameter"); eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, errParams); return; } toNumber = params.getString("To"); if (params.hasKey("ToName")) { toName = params.getString("ToName"); } twiMLParams.clear(); ReadableMapKeySetIterator iterator = params.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType readableType = params.getType(key); switch (readableType) { case Null: twiMLParams.put(key, ""); break; case Boolean: twiMLParams.put(key, String.valueOf(params.getBoolean(key))); break; case Number: // Can be int or double. twiMLParams.put(key, String.valueOf(params.getDouble(key))); break; case String: twiMLParams.put(key, params.getString(key)); break; default: Log.d(TAG, "Could not convert with key: " + key + "."); break; } } activeCall = Voice.call(getReactApplicationContext(), accessToken, twiMLParams, callListener); }
Example 20
Source File: Jsons.java From react-native-pili with MIT License | 4 votes |
public static JSONObject readableMapToJson(ReadableMap readableMap) { JSONObject jsonObject = new JSONObject(); if (readableMap == null) { return null; } ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); if (!iterator.hasNextKey()) { return null; } while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType readableType = readableMap.getType(key); try { switch (readableType) { case Null: jsonObject.put(key, null); break; case Boolean: jsonObject.put(key, readableMap.getBoolean(key)); break; case Number: // Can be int or double. jsonObject.put(key, readableMap.getInt(key)); break; case String: jsonObject.put(key, readableMap.getString(key)); break; case Map: jsonObject.put(key, readableMapToJson(readableMap.getMap(key))); break; case Array: jsonObject.put(key, readableMap.getArray(key)); default: // Do nothing and fail silently } } catch (JSONException ex) { // Do nothing and fail silently } } return jsonObject; }