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:org.jitsi.meet.sdk.OngoingConferenceTracker.java

License:Apache License

synchronized void onExternalAPIEvent(String name, ReadableMap data) {
    if (!data.hasKey("url")) {
        return;/*from   www .  ja  v  a 2s  .  c om*/
    }

    String url = data.getString("url");
    if (url == null) {
        return;
    }

    switch (name) {
    case CONFERENCE_WILL_JOIN:
        currentConference = url;
        updateListeners();
        break;

    case CONFERENCE_TERMINATED:
        if (url.equals(currentConference)) {
            currentConference = null;
            updateListeners();
        }
        break;
    }
}

From source file:org.th317erd.react.DynamicFontsModule.java

License:Open Source License

@ReactMethod
public void loadFontFromFile(final ReadableMap options, final Callback callback) {
    Activity currentActivity = getCurrentActivity();
    if (currentActivity == null) {
        callback.invoke("Invalid activity");
        return;//from   w w  w  . jav a2 s  .c o m
    }

    String filePath = options.hasKey("filePath") ? options.getString("filePath") : null,
            name = (options.hasKey("name")) ? options.getString("name") : null;

    if (filePath == null || filePath.length() == 0) {
        callback.invoke("filePath property empty");
        return;
    }

    File f = new File(filePath);

    if (f.exists() && f.canRead()) {
        boolean wasLoaded = false;
        try {
            Typeface typeface = Typeface.createFromFile(f);
            //Cache the font for react
            ReactFontManager.getInstance().setTypeface(name, typeface.getStyle(), typeface);
            wasLoaded = true;
        } catch (Throwable e) {
            callback.invoke(e.getMessage());
        } finally {
            if (wasLoaded) {
                callback.invoke(null, name);
            }
        }
    } else {
        callback.invoke("invalid file");
    }
}

From source file:org.th317erd.react.DynamicFontsModule.java

License:Open Source License

@ReactMethod
public void loadFont(final ReadableMap options, final Callback callback) throws Exception {
    Activity currentActivity = getCurrentActivity();
    if (currentActivity == null) {
        callback.invoke("Invalid activity");
        return;/* w  ww.j  av a  2  s .  com*/
    }

    String name = (options.hasKey("name")) ? options.getString("name") : null,
            data = (options.hasKey("data")) ? options.getString("data") : null, type = null;

    if (name == null || name.length() == 0) {
        callback.invoke("Name property empty");
        return;
    }

    if (data == null || data.length() == 0) {
        callback.invoke("Data property empty");
        return;
    }

    if (("data:").equalsIgnoreCase(data.substring(0, 5))) {
        Integer pos = data.indexOf(',');
        if (pos > 0) {
            String[] encodingParams = data.substring(5, pos).split(";");
            String mimeType = encodingParams[0];

            data = data.substring(pos + 1);

            if (("application/x-font-ttf").equalsIgnoreCase(mimeType)
                    || ("application/x-font-truetype").equalsIgnoreCase(mimeType)
                    || ("font/ttf").equalsIgnoreCase(mimeType)) {
                type = "ttf";
            } else if (("application/x-font-opentype").equalsIgnoreCase(mimeType)
                    || ("font/opentype").equalsIgnoreCase(mimeType)) {
                type = "otf";
            }
        }
    }

    if (options.hasKey("type"))
        type = options.getString("type");

    if (type == null)
        type = "ttf";

    try {
        byte[] decodedBytes = Base64.decode(data, Base64.DEFAULT);
        File cacheFile = new File(currentActivity.getCacheDir(), "tempFont" + (tempNameCounter++) + type);

        FileOutputStream stream = new FileOutputStream(cacheFile);
        try {
            stream.write(decodedBytes);
        } finally {
            stream.close();
        }

        //Load the font from the temporary file we just created
        Typeface typeface = Typeface.createFromFile(cacheFile);

        //Cache the font for react
        ReactFontManager.getInstance().setTypeface(name, typeface.getStyle(), typeface);

        cacheFile.delete();
    } catch (Exception e) {
        callback.invoke(e.getMessage());
    } finally {
        callback.invoke(null, name);
    }
}

From source file:rn.crashlytics.answers.AnswersModule.java

License:Open Source License

private static void addCustomAttribute(AnswersEvent event, ReadableMap attrMap, String attrKey) {
    ReadableType type = attrMap.getType(attrKey);
    switch (type) {
    case Number:
        event.putCustomAttribute(attrKey, attrMap.getDouble(attrKey));
        break;//w w  w  .j a v a2s.c o  m
    case String:
        event.putCustomAttribute(attrKey, attrMap.getString(attrKey));
        break;
    case Boolean:
        event.putCustomAttribute(attrKey, String.valueOf(attrMap.getBoolean(attrKey)));
        break;
    case Null:
        break; // skip
    default:
        throw new IllegalArgumentException("Can't handle Objects or Arrays");
    }
}