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.horcrux.svg.ImageView.java

License:Open Source License

@ReactProp(name = "src")
public void setSrc(@Nullable ReadableMap src) {
    if (src != null) {
        uriString = src.getString("uri");

        if (uriString == null || uriString.isEmpty()) {
            //TODO: give warning about this
            return;
        }//from ww w  .  jav  a2s.c  om

        if (src.hasKey("width") && src.hasKey("height")) {
            mImageWidth = src.getInt("width");
            mImageHeight = src.getInt("height");
        } else {
            mImageWidth = 0;
            mImageHeight = 0;
        }
        Uri mUri = Uri.parse(uriString);
        if (mUri.getScheme() == null) {
            ResourceDrawableIdHelper.getInstance().getResourceDrawableUri(mContext, uriString);
        }
    }
}

From source file:com.horcrux.svg.RNSVGImageShadowNode.java

License:Open Source License

@ReactProp(name = "src")
public void setSrc(@Nullable ReadableMap src) {
    if (src != null) {
        String uriString = src.getString("uri");

        if (uriString == null || uriString.isEmpty()) {
            //TODO: give warning about this
            return;
        }/*from ww w  .  ja  va  2  s . com*/

        mUri = Uri.parse(uriString);
    }
}

From source file:com.horcrux.svg.RNSVGTextShadowNode.java

License:Open Source License

private void applyTextPropertiesToPaint(Paint paint) {
    int alignment = mTextAlignment;
    switch (alignment) {
    case TEXT_ALIGNMENT_LEFT:
        paint.setTextAlign(Paint.Align.LEFT);
        break;//w ww  .  j  ava  2  s.  com
    case TEXT_ALIGNMENT_RIGHT:
        paint.setTextAlign(Paint.Align.RIGHT);
        break;
    case TEXT_ALIGNMENT_CENTER:
        paint.setTextAlign(Paint.Align.CENTER);
        break;
    }
    if (mFrame != null) {
        if (mFrame.hasKey(PROP_FONT)) {
            ReadableMap font = mFrame.getMap(PROP_FONT);
            if (font != null) {
                float fontSize = DEFAULT_FONT_SIZE;
                if (font.hasKey(PROP_FONT_SIZE)) {
                    fontSize = (float) font.getDouble(PROP_FONT_SIZE);
                }
                paint.setTextSize(fontSize * mScale);
                boolean isBold = font.hasKey(PROP_FONT_WEIGHT)
                        && "bold".equals(font.getString(PROP_FONT_WEIGHT));
                boolean isItalic = font.hasKey(PROP_FONT_STYLE)
                        && "italic".equals(font.getString(PROP_FONT_STYLE));
                int fontStyle;
                if (isBold && isItalic) {
                    fontStyle = Typeface.BOLD_ITALIC;
                } else if (isBold) {
                    fontStyle = Typeface.BOLD;
                } else if (isItalic) {
                    fontStyle = Typeface.ITALIC;
                } else {
                    fontStyle = Typeface.NORMAL;
                }
                // NB: if the font family is null / unsupported, the default one will be used
                paint.setTypeface(Typeface.create(font.getString(PROP_FONT_FAMILY), fontStyle));
            }
        }
    }
}

From source file:com.horcrux.svg.TSpanShadowNode.java

License:Open Source License

private void applyTextPropertiesToPaint(Paint paint) {
    ReadableMap font = getFontFromContext();

    paint.setTextAlign(Paint.Align.LEFT);

    float fontSize = (float) font.getDouble(PROP_FONT_SIZE);

    paint.setTextSize(fontSize * mScale);

    boolean isBold = font.hasKey(PROP_FONT_WEIGHT) && "bold".equals(font.getString(PROP_FONT_WEIGHT));
    boolean isItalic = font.hasKey(PROP_FONT_STYLE) && "italic".equals(font.getString(PROP_FONT_STYLE));

    int fontStyle;
    if (isBold && isItalic) {
        fontStyle = Typeface.BOLD_ITALIC;
    } else if (isBold) {
        fontStyle = Typeface.BOLD;/*from w w  w  .  j a v a 2 s .c  o m*/
    } else if (isItalic) {
        fontStyle = Typeface.ITALIC;
    } else {
        fontStyle = Typeface.NORMAL;
    }
    // NB: if the font family is null / unsupported, the default one will be used
    paint.setTypeface(Typeface.create(font.getString(PROP_FONT_FAMILY), fontStyle));
}

From source file:com.ibatimesheet.RNJSONUtils.java

License:Apache License

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;
        }/*from w  ww. j a va 2 s.c  o  m*/
    }
    return object;
}

From source file:com.lightappbuilder.lab4.lablibrary.rnviews.webview.ReactWebViewManager.java

License:Open Source License

@ReactProp(name = "source")
public void setSource(DynamicSizeWrapperView wrapperView, @Nullable ReadableMap source) {
    ReactWebView view = (ReactWebView) wrapperView.getWrappedChild();
    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  a v a2 s  .  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.microsoft.aad.adal.ReactNativeAdalPlugin.java

License:Open Source License

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

    try {/*from ww w  .j  av  a  2s.co  m*/
        String authority = obj.hasKey("authority") ? obj.getString("authority") : null;
        boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority")
                : false;

        getOrCreateContext(authority, validateAuthority);
        callback.invoke();

    } catch (Exception e) {
        callback.invoke(e.getMessage());
    }
}

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

License:Open Source License

@ReactMethod
public void acquireTokenAsync(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 redirectUri = obj.hasKey("redirectUri") ? obj.getString("redirectUri") : null;
    String userId = obj.hasKey("userId") ? obj.getString("userId") : null;
    String extraQueryParams = obj.hasKey("extraQueryParams") ? obj.getString("extraQueryParams") : null;

    try {// ww  w  .  j  a  v  a 2 s  .com
        authContext = getOrCreateContext(authority, validateAuthority);
    } catch (Exception e) {
        callback.invoke(e.getMessage());
        return;
    }

    if (userId != null) {
        ITokenCacheStore cache = authContext.getCache();
        if (cache instanceof ITokenStoreQuery) {

            List<TokenCacheItem> tokensForUserId = ((ITokenStoreQuery) cache).getTokensForUser(userId);
            if (tokensForUserId.size() > 0) {
                // Try to acquire alias for specified userId
                userId = tokensForUserId.get(0).getUserInfo().getDisplayableId();
            }
        }
    }

    authContext.acquireToken(this.getCurrentActivity(), resourceId, clientId, redirectUri, userId,
            SHOW_PROMPT_ALWAYS, extraQueryParams, new DefaultAuthenticationCallback(callback));
}

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

License:Open Source License

@ReactMethod
public void acquireTokenSilentAsync(ReadableMap obj, Callback callback) { //String authority, boolean validateAuthority, String resourceUrl, String clientId, String userId) {

    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;
    try {/*from  w ww  .  j  ava 2s . c o  m*/
        authContext = getOrCreateContext(authority, validateAuthority);

        //  We should retrieve userId from broker cache since local is always empty
        boolean useBroker = AuthenticationSettings.INSTANCE.getUseBroker();
        if (useBroker) {
            if (TextUtils.isEmpty(userId)) {
                // Get first user from account list
                userId = authContext.getBrokerUser();
            }

            for (UserInfo info : authContext.getBrokerUsers()) {
                if (info.getDisplayableId().equals(userId)) {
                    userId = info.getUserId();
                    break;
                }
            }
        }

    } catch (Exception e) {
        callback.invoke(e.getMessage());
        return;
    }

    authContext.acquireTokenSilentAsync(resourceId, clientId, userId,
            new DefaultAuthenticationCallback(callback));
}

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

License:Open Source License

@ReactMethod
public void tokenCacheReadItems(ReadableMap obj, Callback callback) throws JSONException {

    final AuthenticationContext authContext;
    String authority = obj.hasKey("authority") ? obj.getString("authority") : null;
    boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority") : false;

    try {//  w  w w .  j ava 2  s  .  c om
        authContext = getOrCreateContext(authority, validateAuthority);
    } catch (Exception e) {
        callback.invoke(e.getMessage());
        return;
    }

    WritableArray result = Arguments.createArray();
    ITokenCacheStore cache = authContext.getCache();

    if (cache instanceof ITokenStoreQuery) {
        Iterator<TokenCacheItem> cacheItems = ((ITokenStoreQuery) cache).getAll();

        while (cacheItems.hasNext()) {
            TokenCacheItem item = cacheItems.next();
            result.pushMap(tokenItemToJSON(item));
        }
    }

    callback.invoke(null, result);

}