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

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

Introduction

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

Prototype

@Nullable
    String getString(@NonNull String name);

Source Link

Usage

From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java

License:Open Source License

@ReactMethod
public void tokenCacheDeleteItem(ReadableMap obj, Callback callback) {

    final AuthenticationContext authContext;
    String authority = obj.hasKey("authority") ? obj.getString("authority") : null;
    boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority") : false;
    String resourceId = obj.hasKey("resourceId") ? obj.getString("resourceId") : null;
    String clientId = obj.hasKey("clientId") ? obj.getString("clientId") : null;
    String userId = obj.hasKey("userId") ? obj.getString("userId") : null;
    String itemAuthority = obj.hasKey("itemAuthority") ? obj.getString("itemAuthority") : null;
    boolean isMultipleResourceRefreshToken = obj.hasKey("isMultipleResourceRefreshToken")
            ? obj.getBoolean("isMultipleResourceRefreshToken")
            : false;/*from  ww  w  .jav a  2  s .co  m*/

    try {
        authContext = getOrCreateContext(authority, validateAuthority);
    } catch (Exception e) {
        callback.invoke(e.getMessage());
        return;
    }

    String key = CacheKey.createCacheKey(itemAuthority, resourceId, clientId, isMultipleResourceRefreshToken,
            userId, "1");
    authContext.getCache().removeItem(key);

    callback.invoke();
}

From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java

License:Open Source License

@ReactMethod
public void tokenCacheClear(ReadableMap obj, Callback callback) {
    final AuthenticationContext authContext;
    String authority = obj.hasKey("authority") ? obj.getString("authority") : null;
    boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority") : false;
    try {//from w  w w  .j  av  a  2 s.c o m
        authContext = getOrCreateContext(authority, validateAuthority);
    } catch (Exception e) {
        callback.invoke(e.getMessage());
        return;
    }

    authContext.getCache().removeAll();
    callback.invoke();
}

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 2 s  .  co m

            break;
        case Boolean:
            jsonObj.put(key, map.getBoolean(key));
            break;
        default:
            jsonObj.put(key, null);
            break;
        }
    }

    return jsonObj;
}

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));
        }// w w w  .j a v  a  2 s .c om
    }

    return stringMap;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@ReactMethod//from ww  w . ja  v  a2  s.  c om
public void startFromLibrary(ReadableMap service) {
    String type = service.getString("bindingType");
    try {
        AppCenter.startFromLibrary(mApplication, new Class[] { Class.forName(type) });
    } catch (ClassNotFoundException e) {
        AppCenterLog.error(LOG_TAG, "Unable to resolve App Center module", e);
    }
}

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

License:Open Source License

private static Object toObject(@Nullable ReadableMap readableMap, String key) {
    if (readableMap == null) {
        return null;
    }//from   w  w w .  j  av a2 s .c  o  m

    Object result;
    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:
        throw new IllegalArgumentException("Could not convert object with key: " + 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);//w  ww .  j  a v a2 s. c o  m
            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.microsoft.appcenter.reactnative.crashes.AppCenterReactNativeCrashesModule.java

License:Open Source License

@ReactMethod
public void sendErrorAttachments(ReadableArray attachments, String errorId) {
    try {/*from  ww w.  jav  a 2s. c o  m*/
        Collection<ErrorAttachmentLog> attachmentLogs = new LinkedList<>();
        for (int i = 0; i < attachments.size(); i++) {
            ReadableMap jsAttachment = attachments.getMap(i);
            String fileName = null;
            if (jsAttachment.hasKey(FILE_NAME_FIELD)) {
                fileName = jsAttachment.getString(FILE_NAME_FIELD);
            }
            if (jsAttachment.hasKey(TEXT_FIELD)) {
                String text = jsAttachment.getString(TEXT_FIELD);
                attachmentLogs.add(ErrorAttachmentLog.attachmentWithText(text, fileName));
            } else {
                String encodedData = jsAttachment.getString(DATA_FIELD);
                byte[] data = Base64.decode(encodedData, Base64.DEFAULT);
                String contentType = jsAttachment.getString(CONTENT_TYPE_FIELD);
                attachmentLogs.add(ErrorAttachmentLog.attachmentWithBinary(data, fileName, contentType));
            }
        }
        WrapperSdkExceptionManager.sendErrorAttachments(errorId, attachmentLogs);
    } catch (Exception e) {
        AppCenterReactNativeCrashesUtils.logError("Failed to get error attachment for report: " + errorId);
        AppCenterReactNativeCrashesUtils.logError(Log.getStackTraceString(e));
    }
}

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.  ja  v a  2s  . c  o m
            } 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 ww .j  a v a  2  s.com*/
        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));
        }
    }
}