List of usage examples for com.facebook.react.bridge ReadableMap getString
@Nullable String getString(@NonNull String name);
From source file:com.testweb.views.ReactAdvancedWebViewManager.java
License:Open Source License
@ReactProp(name = "source") public void setSource(WebView view, @Nullable ReadableMap source) { if (source != null) { Log.e("ReactTag", source.toString()); 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);/*w w w .jav a 2s .c om*/ } else { view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING); } return; } if (source.hasKey("uri")) { String url = source.getString("uri"); 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(); headerMap.put(key, headers.getString(key)); } } view.loadUrl(url, headerMap); return; } } view.loadUrl(BLANK_URL); }
From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java
private static JSONObject mapToJson(ReadableMap map) { ReadableMapKeySetIterator iterator = map.keySetIterator(); JSONObject json = new JSONObject(); try {/*w w w .jav a2s .c o m*/ 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; }
From source file:io.github.douglasjunior.ReactNativeEasyBluetooth.core.CoreModule.java
License:Open Source License
public void init(ReadableMap config, Promise promise) { Log.d(TAG, "config: " + config); try {/* ww w. j a v a2s.co m*/ if (!validateBluetoothAdapter(promise)) return; BluetoothConfiguration bluetoothConfig = new BluetoothConfiguration(); bluetoothConfig.context = getReactApplicationContext(); bluetoothConfig.bluetoothServiceClass = mBluetoothServiceClass; bluetoothConfig.deviceName = config.getString("deviceName"); bluetoothConfig.characterDelimiter = config.getString("characterDelimiter").charAt(0); bluetoothConfig.bufferSize = config.getInt("bufferSize"); if (config.hasKey("uuid")) bluetoothConfig.uuid = UUID.fromString(config.getString("uuid")); if (config.hasKey("uuidService")) bluetoothConfig.uuidService = UUID.fromString(config.getString("uuidService")); if (config.hasKey("uuidCharacteristic")) bluetoothConfig.uuidCharacteristic = UUID.fromString(config.getString("uuidCharacteristic")); if (config.hasKey("transport")) bluetoothConfig.transport = config.getInt("transport"); bluetoothConfig.callListenersInMainThread = false; BluetoothService.init(bluetoothConfig); mService = BluetoothService.getDefaultInstance(); mService.setOnScanCallback(this); mService.setOnEventCallback(this); mWriter = new BluetoothWriter(mService); WritableNativeMap returnConfig = new WritableNativeMap(); returnConfig.merge(config); promise.resolve(returnConfig); } catch (Exception ex) { ex.printStackTrace(); promise.reject(ex); } }
From source file:io.github.douglasjunior.ReactNativeEasyBluetooth.core.CoreModule.java
License:Open Source License
public void connect(ReadableMap device, final Promise promise) throws InterruptedException { Log.d(TAG, "connect: " + device); try {/* ww w . j a v a2s .com*/ if (!validateServiceConfig(promise)) return; String address = device.getString("address"); String name = device.getString("name"); if (!mBluetoothAdapter.checkBluetoothAddress(address)) { promise.reject(new IllegalArgumentException("Invalid device address: " + address)); return; } BluetoothDevice btDevice = mBluetoothAdapter.getRemoteDevice(address); mService.connect(btDevice); Thread.sleep(2000); while (mService.getStatus() == BluetoothStatus.CONNECTING) { Thread.yield(); } if (mService.getStatus() == BluetoothStatus.CONNECTED) { promise.resolve(wrapDevice(btDevice, 0)); } else { promise.reject(new IllegalStateException("Unable to connect to: " + name + " [" + address + "]")); } } catch (Exception ex) { ex.printStackTrace(); promise.reject(ex); } }
From source file:io.tradle.RNBlinkIDModule.java
private String getString(ReadableMap map, String key) { return map.hasKey(key) ? map.getString(key) : null; }
From source file:it.near.sdk.reactnative.rnnearitsdk.RNNearItUtils.java
License:Mozilla Public License
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);/*from ww w .java2 s. c o m*/ 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, toJSONObject(readableMap.getMap(key))); break; case Array: jsonObject.put(key, toJSONArray(readableMap.getArray(key))); break; } } return jsonObject; }
From source file:it.near.sdk.reactnative.rnnearitsdk.RNNearItUtils.java
License:Mozilla Public License
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);//from w ww . j a v a2 s.c o m 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, toMap(readableMap.getMap(key))); break; case Array: map.put(key, toArray(readableMap.getArray(key))); break; } } return map; }
From source file:org.jitsi.meet.sdk.externalapi.ExternalAPIModule.java
License:Apache License
/** * Dispatches an event that occurred on JavaScript to the view's listener. * * @param name The name of the event./*from w ww . j a v a 2 s .c om*/ * @param data The details/specifics of the event to send determined * by/associated with the specified {@code name}. * @param scope */ @ReactMethod public void sendEvent(String name, ReadableMap data, String scope) { // The JavaScript App needs to provide uniquely identifying information // to the native ExternalAPI module so that the latter may match the // former to the native JitsiMeetView which hosts it. JitsiMeetView view = JitsiMeetView.findViewByExternalAPIScope(scope); if (view == null) { return; } JitsiMeetViewListener listener = view.getListener(); if (listener == null) { return; } // TODO Converting a ReadableMap to a HashMap is not supported until // React Native 0.46. HashMap<String, Object> dataMap = new HashMap<>(); switch (name) { case "CONFERENCE_FAILED": dataMap.put("error", data.getString("error")); dataMap.put("url", data.getString("url")); listener.onConferenceFailed(dataMap); break; case "CONFERENCE_JOINED": dataMap.put("url", data.getString("url")); listener.onConferenceJoined(dataMap); break; case "CONFERENCE_LEFT": dataMap.put("url", data.getString("url")); listener.onConferenceLeft(dataMap); break; case "CONFERENCE_WILL_JOIN": dataMap.put("url", data.getString("url")); listener.onConferenceWillJoin(dataMap); break; case "CONFERENCE_WILL_LEAVE": dataMap.put("url", data.getString("url")); listener.onConferenceWillLeave(dataMap); break; } }
From source file:org.jitsi.meet.sdk.invite.AddPeopleController.java
License:Apache License
/** * Caches results received by the search into a local map for use * later when the items are submitted. Submission requires the full * map of information, but only the IDs are returned back to the delegate. * Using this map means we don't have to send the whole map back to the delegate. * * @param results// www . j a v a2 s . c o m * @param query */ void receivedResultsForQuery(ReadableArray results, String query) { AddPeopleControllerListener listener = getListener(); if (listener != null) { List<Map<String, Object>> jvmResults = new ArrayList<>(); // cache results for use in submission later // convert to jvm array for (int i = 0; i < results.size(); i++) { ReadableMap map = results.getMap(i); if (map.hasKey("id")) { items.put(map.getString("id"), map); } else if (map.hasKey("type") && map.getString("type").equals("phone") && map.hasKey("number")) { items.put(map.getString("number"), map); } else { Log.w("AddPeopleController", "Received result without id and that was not a phone number, so not adding it to suggestions: " + map); } jvmResults.add(map.toHashMap()); } listener.onReceivedResults(this, jvmResults, query); } }
From source file:org.jitsi.meet.sdk.ListenerUtils.java
License:Apache License
/** * Initializes a new {@code HashMap} instance with the key-value * associations of a specific {@code ReadableMap}. * * @param readableMap the {@code ReadableMap} specifying the key-value * associations with which the new {@code HashMap} instance is to be * initialized.//from www. j a va 2 s . c om * @return a new {@code HashMap} instance initialized with the key-value * associations of the specified {@code readableMap}. */ private static HashMap<String, Object> toHashMap(ReadableMap readableMap) { HashMap<String, Object> hashMap = new HashMap<>(); for (ReadableMapKeySetIterator i = readableMap.keySetIterator(); i.hasNextKey();) { String key = i.nextKey(); hashMap.put(key, readableMap.getString(key)); } return hashMap; }