Example usage for com.facebook.react.bridge ReadableMap keySetIterator

List of usage examples for com.facebook.react.bridge ReadableMap keySetIterator

Introduction

In this page you can find the example usage for com.facebook.react.bridge ReadableMap keySetIterator.

Prototype

@NonNull
    ReadableMapKeySetIterator keySetIterator();

Source Link

Usage

From source file:com.microsoft.appcenter.reactnative.analytics.ReactNativeUtils.java

License:Open Source License

public static Map<String, String> convertReadableMapToStringMap(ReadableMap map) throws JSONException {
    Map<String, String> stringMap = new HashMap<>();
    ReadableMapKeySetIterator it = map.keySetIterator();
    while (it.hasNextKey()) {
        String key = it.nextKey();
        ReadableType type = map.getType(key);
        // Only support storing strings. Non-string data must be stringified in JS.
        if (type == ReadableType.String) {
            stringMap.put(key, map.getString(key));
        }/*from  w  ww  .ja va  2s  .  c  o  m*/
    }

    return stringMap;
}

From source file:com.microsoft.appcenter.reactnative.appcenter.ReactNativeUtils.java

License:Open Source License

private static Map<String, Object> toMap(@Nullable ReadableMap readableMap) {
    if (readableMap == null) {
        return null;
    }//from  w  w  w  .  j a v a2  s. c om

    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    if (!iterator.hasNextKey()) {
        return null;
    }

    Map<String, Object> result = new HashMap<>();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        result.put(key, toObject(readableMap, key));
    }

    return result;
}

From source file:com.microsoft.appcenter.reactnative.appcenter.ReactNativeUtils.java

License:Open Source License

static CustomProperties toCustomProperties(ReadableMap readableMap) {
    CustomProperties properties = new CustomProperties();
    ReadableMapKeySetIterator keyIt = readableMap.keySetIterator();
    while (keyIt.hasNextKey()) {
        String key = keyIt.nextKey();
        ReadableMap valueObject = readableMap.getMap(key);
        String type = valueObject.getString("type");
        switch (type) {
        case "clear":
            properties.clear(key);//from w  w w.j a v a2  s .c  om
            break;

        case "string":
            properties.set(key, valueObject.getString("value"));
            break;

        case "number":
            properties.set(key, valueObject.getDouble("value"));
            break;

        case "boolean":
            properties.set(key, valueObject.getBoolean("value"));
            break;

        case "date-time":
            properties.set(key, new Date((long) valueObject.getDouble("value")));
            break;
        }
    }
    return properties;
}

From source file:com.phxrb.CWebView.RNWebViewManager.java

License:Open Source License

@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);/*w  w w .  jav a 2 s.com*/
            } 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);
}

From source file:com.pspdfkit.react.ConfigurationAdapter.java

License:Open Source License

public ConfigurationAdapter(@NonNull Context context, ReadableMap configuration) {
    ReadableMapKeySetIterator iterator = configuration.keySetIterator();
    boolean hasConfiguration = iterator.hasNextKey();
    this.configuration = new PdfActivityConfiguration.Builder(context);
    if (hasConfiguration) {
        if (configuration.hasKey(PAGE_SCROLL_DIRECTION)) {
            configurePageScrollDirection(configuration.getString(PAGE_SCROLL_DIRECTION));
        }/*from w w  w . j  a  v a  2  s .  c o m*/
        if (configuration.hasKey(PAGE_SCROLL_CONTINUOUS)) {
            configurePageScrollContinuous(configuration.getBoolean(PAGE_SCROLL_CONTINUOUS));
        }
        if (configuration.hasKey(FIT_PAGE_TO_WIDTH)) {
            configureFitPageToWidth(configuration.getBoolean(FIT_PAGE_TO_WIDTH));
        }
        if (configuration.hasKey(INLINE_SEARCH)) {
            configureInlineSearch(configuration.getBoolean(INLINE_SEARCH));
        }
        if (configuration.hasKey(USER_INTERFACE_VIEW_MODE)) {
            configureUserInterfaceViewMode(configuration.getString(USER_INTERFACE_VIEW_MODE));
        }
        if (configuration.hasKey(START_PAGE)) {
            configureStartPage(configuration.getInt(START_PAGE));
        }
        if (configuration.hasKey(SHOW_SEARCH_ACTION)) {
            configureShowSearchAction(configuration.getBoolean(SHOW_SEARCH_ACTION));
        }
        if (configuration.hasKey(IMMERSIVE_MODE)) {
            configureImmersiveMode(configuration.getBoolean(IMMERSIVE_MODE));
        }
        if (configuration.hasKey(SHOW_THUMBNAIL_GRID_ACTION)) {
            configureShowThumbnailGridAction(configuration.getBoolean(SHOW_THUMBNAIL_GRID_ACTION));
        }
        if (configuration.hasKey(SHOW_OUTLINE_ACTION)) {
            configureShowOutlineAction(configuration.getBoolean(SHOW_OUTLINE_ACTION));
        }
        if (configuration.hasKey(SHOW_ANNOTATION_LIST_ACTION)) {
            configureShowAnnotationListAction(configuration.getBoolean(SHOW_ANNOTATION_LIST_ACTION));
        }
        if (configuration.hasKey(SHOW_PAGE_NUMBER_OVERLAY)) {
            configureShowPageNumberOverlay(configuration.getBoolean(SHOW_PAGE_NUMBER_OVERLAY));
        }
        if (configuration.hasKey(SHOW_PAGE_LABELS)) {
            configureShowPageLabels(configuration.getBoolean(SHOW_PAGE_LABELS));
        }
        if (configuration.hasKey(GRAY_SCALE)) {
            configureGrayScale(configuration.getBoolean(GRAY_SCALE));
        }
        if (configuration.hasKey(INVERT_COLORS)) {
            configureInvertColors(configuration.getBoolean(INVERT_COLORS));
        }
        if (configuration.hasKey(ENABLE_ANNOTATION_EDITING)) {
            configureEnableAnnotationEditing(configuration.getBoolean(ENABLE_ANNOTATION_EDITING));
        }
        if (configuration.hasKey(SHOW_SHARE_ACTION)) {
            configureShowShareAction(configuration.getBoolean(SHOW_SHARE_ACTION));
        }
        if (configuration.hasKey(SHOW_PRINT_ACTION)) {
            configureShowPrintAction(configuration.getBoolean(SHOW_PRINT_ACTION));
        }
        if (configuration.hasKey(ENABLE_TEXT_SELECTION)) {
            configureEnableTextSelection(configuration.getBoolean(ENABLE_TEXT_SELECTION));
        }
        if (configuration.hasKey(SHOW_THUMBNAIL_BAR)) {
            configureShowThumbnailBar(configuration.getString(SHOW_THUMBNAIL_BAR));
        }
        if (configuration.hasKey(SHOW_DOCUMENT_INFO_VIEW)) {
            configureDocumentInfoView(configuration.getBoolean(SHOW_DOCUMENT_INFO_VIEW));
        }
        if (configuration.hasKey(SHOW_DOCUMENT_TITLE_OVERLAY)) {
            configureShowDocumentTitleOverlay(configuration.getBoolean(SHOW_DOCUMENT_TITLE_OVERLAY));
        }
        if (configuration.hasKey(PAGE_MODE)) {
            configurePageMode(configuration.getString(PAGE_MODE));
        }
        if (configuration.hasKey(FIRST_PAGE_ALWAYS_SINGLE)) {
            configureFirstPageAlwaysSingle(configuration.getBoolean(FIRST_PAGE_ALWAYS_SINGLE));
        }
    }
}

From source file:com.roihuapp.CacheClearableWebViewManager.java

License:Open Source License

@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);// ww w  .j  ava2 s .  c o  m
            } 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.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  ww .  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);/* www . java2 s  .com*/
            }
            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  ww  .j a v a2  s . 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 {/*from www  .  jav  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;
}