List of usage examples for com.facebook.react.bridge ReadableMap hasKey
boolean hasKey(@NonNull String name);
From source file:com.silklabs.react.blobs.WebSocketModule.java
License:Open Source License
@ReactMethod public void connect(final String url, @Nullable final ReadableArray protocols, @Nullable final ReadableMap headers, final int id) { OkHttpClient client = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS) .writeTimeout(10, TimeUnit.SECONDS).readTimeout(0, TimeUnit.MINUTES) // Disable timeouts for read .build();//from w w w .j av a 2 s .c o m Request.Builder builder = new Request.Builder().tag(id).url(url); if (headers != null) { ReadableMapKeySetIterator iterator = headers.keySetIterator(); if (!headers.hasKey("origin")) { builder.addHeader("origin", setDefaultOrigin(url)); } while (iterator.hasNextKey()) { String key = iterator.nextKey(); if (ReadableType.String.equals(headers.getType(key))) { builder.addHeader(key, headers.getString(key)); } else { FLog.w(ReactConstants.TAG, "Ignoring: requested " + key + ", value not a string"); } } } else { builder.addHeader("origin", setDefaultOrigin(url)); } if (protocols != null && protocols.size() > 0) { StringBuilder protocolsValue = new StringBuilder(""); for (int i = 0; i < protocols.size(); i++) { String v = protocols.getString(i).trim(); if (!v.isEmpty() && !v.contains(",")) { protocolsValue.append(v); protocolsValue.append(","); } } if (protocolsValue.length() > 0) { protocolsValue.replace(protocolsValue.length() - 1, protocolsValue.length(), ""); builder.addHeader("Sec-WebSocket-Protocol", protocolsValue.toString()); } } WebSocketCall.create(client, builder.build()).enqueue(new WebSocketListener() { @Override public void onOpen(WebSocket webSocket, Response response) { mWebSocketConnections.put(id, webSocket); WritableMap params = Arguments.createMap(); params.putInt("id", id); sendEvent("websocketOpen", params); } @Override public void onClose(int code, String reason) { WritableMap params = Arguments.createMap(); params.putInt("id", id); params.putInt("code", code); params.putString("reason", reason); sendEvent("websocketClosed", params); } @Override public void onFailure(IOException e, Response response) { notifyWebSocketFailed(id, e.getMessage()); } @Override public void onPong(Buffer buffer) { } @Override public void onMessage(ResponseBody response) throws IOException { WritableMap params = Arguments.createMap(); params.putInt("id", id); if (mBlobsEnabled.containsKey(id) && mBlobsEnabled.get(id) && response.contentType() == WebSocket.BINARY) { byte[] data; try { data = response.source().readByteArray(); } catch (IOException e) { notifyWebSocketFailed(id, e.getMessage()); return; } WritableMap blob = Arguments.createMap(); blob.putString("blobId", BlobModule.store(data)); blob.putInt("offset", 0); blob.putInt("size", data.length); params.putMap("data", blob); params.putString("type", "blob"); } else { String message; try { if (response.contentType() == WebSocket.BINARY) { message = Base64.encodeToString(response.source().readByteArray(), Base64.NO_WRAP); } else { message = response.source().readUtf8(); } } catch (IOException e) { notifyWebSocketFailed(id, e.getMessage()); return; } params.putString("data", message); params.putString("type", response.contentType() == WebSocket.BINARY ? "binary" : "text"); } try { response.source().close(); } catch (IOException e) { FLog.e(ReactConstants.TAG, "Could not close BufferedSource for WebSocket id " + id, e); } sendEvent("websocketMessage", params); } }); // Trigger shutdown of the dispatcher's executor so this process can exit cleanly client.dispatcher().executorService().shutdown(); }
From source file:com.testproject.webview.XWalkViewManager.java
License:Open Source License
@ReactProp(name = "source") public void setSource(XWalkView view, @Nullable ReadableMap source) { if (source != null) { if (source.hasKey("html")) { String html = source.getString("html"); if (source.hasKey("baseUrl")) { view.load(source.getString("baseUrl"), html); } else { view.load(null, html);/*from w w w.j a v a2 s .c o m*/ } 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); view.load(url, null); return; } } view.load(null, BLANK_URL); }
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);//from w w w . j ava 2 s. com } 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:io.github.douglasjunior.ReactNativeEasyBluetooth.core.CoreModule.java
License:Open Source License
public void init(ReadableMap config, Promise promise) { Log.d(TAG, "config: " + config); try {// w w w.j av a 2 s.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.tradle.RNBlinkIDModule.java
@ReactMethod public void scan(ReadableMap opts, final Promise promise) { String licenseKey = getString(opts, "licenseKey"); if (licenseKey == null) { licenseKey = this.licenseKey; }//from w w w . j av a 2s . c om resetForNextScan(); this.scanPromise = promise; this.opts = opts; Activity currentActivity = getCurrentActivity(); Intent intent = new Intent(currentActivity, ScanCard.class); intent.putExtra(ScanCard.EXTRAS_LICENSE_KEY, licenseKey); intent.putExtra(ScanCard.EXTRAS_CAMERA_TYPE, (Parcelable) CameraType.CAMERA_BACKFACE); RecognitionSettings settings = new RecognitionSettings(); RecognizerSettings[] recognizerSettings = getRecognitionSettings(opts); if (!RecognizerCompatibility.cameraHasAutofocus(CameraType.CAMERA_BACKFACE, reactContext)) { int length = recognizerSettings.length; recognizerSettings = RecognizerSettingsUtils .filterOutRecognizersThatRequireAutofocus(recognizerSettings); if (recognizerSettings.length != length) { reject(E_FAILED_NO_AUTOFOCUS); return; } } settings.setRecognizerSettingsArray(recognizerSettings); if (opts.hasKey("timeout")) { settings.setNumMsBeforeTimeout(opts.getInt("timeout")); } intent.putExtra(ScanCard.EXTRAS_RECOGNITION_SETTINGS, settings); // pass implementation of image listener that will obtain document images intent.putExtra(ScanCard.EXTRAS_IMAGE_LISTENER, new MyImageListener()); // pass image metadata settings that specifies which images will be obtained intent.putExtra(ScanCard.EXTRAS_IMAGE_METADATA_SETTINGS, getImageMetadataSettings(opts)); // Starting Activity currentActivity.startActivityForResult(intent, SCAN_REQUEST_CODE); }
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:io.tradle.RNBlinkIDModule.java
private boolean getBoolean(ReadableMap map, String key) { return map.hasKey(key) ? map.getBoolean(key) : false; }
From source file:io.tradle.RNBlinkIDModule.java
private MetadataSettings.ImageMetadataSettings getImageMetadataSettings(ReadableMap opts) { MetadataSettings.ImageMetadataSettings ims = new MetadataSettings.ImageMetadataSettings(); String imagePath = getString(opts, "imagePath"); boolean outputBase64 = getBoolean(opts, "base64"); boolean needImage = imagePath != null || outputBase64; if (needImage) { // enable returning of dewarped images, if they are available ims.setDewarpedImageEnabled(true); // enable returning of image that was used to obtain valid scanning result if (opts.hasKey(TYPE_USDL)) { ims.setSuccessfulScanFrameEnabled(true); }//from www .j a va2 s . c o m } return ims; }
From source file:io.tradle.RNBlinkIDModule.java
private RecognizerSettings[] getRecognitionSettings(ReadableMap opts) { // TODO: interpret actual settings ArrayList<RecognizerSettings> settings = new ArrayList<>(); if (opts.hasKey(TYPE_USDL)) { USDLRecognizerSettings sett = new USDLRecognizerSettings(); sett.setUncertainScanning(false); // disable scanning of barcodes that do not have quiet zone // as defined by the standard sett.setNullQuietZoneAllowed(false); settings.add(sett);/*from w w w . j a v a2 s.c o m*/ } if (opts.hasKey(TYPE_EUDL)) { ReadableMap eudlOpts = opts.getMap(TYPE_EUDL); EUDLCountry country = null; String countryStr = getString(opts, "issuer"); if (countryStr != null) { countryStr = countryStr.toUpperCase(); country = countryToEUDLCountry.get(countryStr); } if (country == null) country = EUDLCountry.EUDL_COUNTRY_AUTO; EUDLRecognizerSettings sett = new EUDLRecognizerSettings(country); sett.setShowFullDocument(getBoolean(eudlOpts, "showFullDocument")); settings.add(sett); } if (opts.hasKey(TYPE_MRTD)) { ReadableMap mrtdOpts = opts.getMap(TYPE_MRTD); MRTDRecognizerSettings sett = new MRTDRecognizerSettings(); sett.setShowFullDocument(getBoolean(mrtdOpts, "showFullDocument")); settings.add(sett); } return settings.toArray(new RecognizerSettings[settings.size()]); }
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//from w ww . j a v a2 s . c om * @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); } }