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

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

Introduction

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

Prototype

boolean getBoolean(@NonNull String name);

Source Link

Usage

From source file:com.adjust.nativemodule.Adjust.java

License:Open Source License

@ReactMethod
public void create(ReadableMap mapConfig) {
    String environment = null;// ww w .  ja  va 2  s.  c  om
    String appToken = null;
    String defaultTracker = null;
    String processName = null;
    String sdkPrefix = null;
    String logLevel = null;
    boolean eventBufferingEnabled = false;
    String userAgent = null;
    boolean sendInBackground = false;
    boolean shouldLaunchDeeplink = false;
    double delayStart = 0.0;
    boolean isLogLevelSuppress = false;

    // Check for isLogLevelSuppress.
    if (!mapConfig.isNull("logLevel")) {
        logLevel = mapConfig.getString("logLevel");

        if (logLevel.equals("SUPPRESS")) {
            isLogLevelSuppress = true;
        }
    }

    // Check for appToken and environment.
    appToken = mapConfig.getString("appToken");
    environment = mapConfig.getString("environment");

    final AdjustConfig adjustConfig = new AdjustConfig(getReactApplicationContext(), appToken, environment,
            isLogLevelSuppress);

    if (!adjustConfig.isValid()) {
        return;
    }

    // Log level
    if (!mapConfig.isNull("logLevel")) {
        logLevel = mapConfig.getString("logLevel");

        if (logLevel.equals("VERBOSE")) {
            adjustConfig.setLogLevel(LogLevel.VERBOSE);
        } else if (logLevel.equals("DEBUG")) {
            adjustConfig.setLogLevel(LogLevel.DEBUG);
        } else if (logLevel.equals("INFO")) {
            adjustConfig.setLogLevel(LogLevel.INFO);
        } else if (logLevel.equals("WARN")) {
            adjustConfig.setLogLevel(LogLevel.WARN);
        } else if (logLevel.equals("ERROR")) {
            adjustConfig.setLogLevel(LogLevel.ERROR);
        } else if (logLevel.equals("ASSERT")) {
            adjustConfig.setLogLevel(LogLevel.ASSERT);
        } else if (logLevel.equals("SUPPRESS")) {
            adjustConfig.setLogLevel(LogLevel.SUPRESS);
        } else {
            adjustConfig.setLogLevel(LogLevel.INFO);
        }
    }

    // Event buffering
    if (!mapConfig.isNull("eventBufferingEnabled")) {
        eventBufferingEnabled = mapConfig.getBoolean("eventBufferingEnabled");
        adjustConfig.setEventBufferingEnabled(eventBufferingEnabled);
    }

    // SDK prefix
    if (!mapConfig.isNull("sdkPrefix")) {
        sdkPrefix = mapConfig.getString("sdkPrefix");
        adjustConfig.setSdkPrefix(sdkPrefix);
    }

    // Main process name
    if (!mapConfig.isNull("processName")) {
        processName = mapConfig.getString("processName");
        adjustConfig.setProcessName(processName);
    }

    // Default tracker
    if (!mapConfig.isNull("defaultTracker")) {
        defaultTracker = mapConfig.getString("defaultTracker");
        adjustConfig.setDefaultTracker(defaultTracker);
    }

    // User agent
    if (!mapConfig.isNull("userAgent")) {
        userAgent = mapConfig.getString("userAgent");
        adjustConfig.setUserAgent(userAgent);
    }

    // Background tracking
    if (!mapConfig.isNull("sendInBackground")) {
        sendInBackground = mapConfig.getBoolean("sendInBackground");
        adjustConfig.setSendInBackground(sendInBackground);
    }

    // Launching deferred deep link
    if (!mapConfig.isNull("shouldLaunchDeeplink")) {
        shouldLaunchDeeplink = mapConfig.getBoolean("shouldLaunchDeeplink");
        this.shouldLaunchDeeplink = shouldLaunchDeeplink;
    }

    // Delayed start
    if (!mapConfig.isNull("delayStart")) {
        delayStart = mapConfig.getDouble("delayStart");
        adjustConfig.setDelayStart(delayStart);
    }

    // Attribution callback
    if (attributionCallback) {
        adjustConfig.setOnAttributionChangedListener(this);
    }

    // Event tracking succeeded callback
    if (eventTrackingSucceededCallback) {
        adjustConfig.setOnEventTrackingSucceededListener(this);
    }

    // Event tracking failed callback
    if (eventTrackingFailedCallback) {
        adjustConfig.setOnEventTrackingFailedListener(this);
    }

    // Session tracking succeeded callback
    if (sessionTrackingSucceededCallback) {
        adjustConfig.setOnSessionTrackingSucceededListener(this);
    }

    // Session tracking failed callback
    if (sessionTrackingFailedCallback) {
        adjustConfig.setOnSessionTrackingFailedListener(this);
    }

    // Deferred deeplink callback listener
    if (deferredDeeplinkCallback) {
        adjustConfig.setOnDeeplinkResponseListener(this);
    }

    com.adjust.sdk.Adjust.onCreate(adjustConfig);
    com.adjust.sdk.Adjust.onResume();
}

From source file:com.adjust.nativemodule.AdjustUtil.java

License:Open Source License

/** 
 * toObject extracts a value from a {@link ReadableMap} by its key, 
 * and returns a POJO representing that object. 
 * /*from  w  w  w  . jav a  2s .com*/
 * @param readableMap The Map to containing the value to be converted 
 * @param key The key for the value to be converted 
 * @return The converted POJO 
 */
private static Object toObject(@Nullable ReadableMap readableMap, String key) {
    if (readableMap == null) {
        return null;
    }

    Object result = null;

    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:
        AdjustFactory.getLogger().error("Could not convert object with key: " + key + ".");
    }

    return result;
}

From source file:com.amazonaws.reactnative.core.AWSRNClientMarshaller.java

License:Open Source License

public static Object toObject(@Nullable ReadableMap readableMap, String key) {
    if (readableMap == null) {
        return null;
    }//from   w w  w .  jav  a 2s. co m

    Object result;

    final ReadableType readableType = readableMap.getType(key);
    switch (readableType) {
    case Null:
        result = key;
        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 = readableMapToMap(readableMap.getMap(key));
        break;
    case Array:
        result = readableArrayToList(readableMap.getArray(key));
        break;
    default:
        throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
    }

    return result;
}

From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java

License:Open Source License

@ReactMethod
public void createDownloadRequest(final ReadableMap options, final Callback callback) {
    if (requestMap == null) {
        callback.invoke("Error: AWSS3TransferUtility is not initialized", null);
        return;/*from   w  w w .j  a  v  a2s  .co m*/
    }
    final String[] params = { BUCKET, KEY, PATH, SUBSCRIBE, COMPLETIONHANDLER };
    for (int i = 0; i < params.length; i++) {
        if (!options.hasKey(params[i])) {
            callback.invoke(params[i] + " is not supplied", null);
            return;
        }
    }
    final Map<String, Object> map = new ConcurrentHashMap<>();
    map.put(BUCKET, options.getString(BUCKET));
    map.put(KEY, options.getString(KEY));
    map.put(PATH, Environment.getExternalStorageDirectory() + options.getString(PATH));
    map.put(TYPE, DOWNLOAD);
    map.put(SUBSCRIBE, options.getBoolean(SUBSCRIBE));
    map.put(COMPLETIONHANDLER, options.getBoolean(COMPLETIONHANDLER));
    final UUID uuid = UUID.randomUUID();
    requestMap.put(uuid.toString(), map);
    callback.invoke(null, uuid.toString());
}

From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java

License:Open Source License

@ReactMethod
public void createUploadRequest(final ReadableMap options, final Callback callback) {
    if (requestMap == null) {
        callback.invoke("Error: AWSS3TransferUtility is not initialized", null);
        return;/*  www  .j av  a 2 s .c  om*/
    }
    final String[] params = { BUCKET, KEY, PATH, SUBSCRIBE, COMPLETIONHANDLER };
    for (int i = 0; i < params.length; i++) {
        if (!options.hasKey(params[i])) {
            callback.invoke(params[i] + " is not supplied", null);
            return;
        }
    }
    final Map<String, Object> map = new ConcurrentHashMap<>();
    map.put(BUCKET, options.getString(BUCKET));
    map.put(KEY, options.getString(KEY));
    map.put(PATH, options.getString(PATH));
    map.put(SUBSCRIBE, options.getBoolean(SUBSCRIBE));
    map.put(COMPLETIONHANDLER, options.getBoolean(COMPLETIONHANDLER));
    map.put(TYPE, UPLOAD);
    final UUID uuid = UUID.randomUUID();
    requestMap.put(uuid.toString(), map);
    callback.invoke(null, uuid.toString());
}

From source file:com.auth0.lock.react.bridge.ShowOptions.java

License:Open Source License

public ShowOptions(@Nullable ReadableMap options) {
    if (options == null) {
        return;//w ww.  j  av a2 s  .  co m
    }

    if (options.hasKey(CLOSABLE_KEY)) {
        closable = options.getBoolean(CLOSABLE_KEY);
        Log.d(TAG, CLOSABLE_KEY + closable);
    }

    if (options.hasKey(DISABLE_SIGNUP)) {
        disableSignUp = options.getBoolean(DISABLE_SIGNUP);
        Log.d(TAG, DISABLE_SIGNUP + disableSignUp);
    }

    if (options.hasKey(DISABLE_RESET_PASSWORD)) {
        disableResetPassword = options.getBoolean(DISABLE_RESET_PASSWORD);
        Log.d(TAG, DISABLE_RESET_PASSWORD + disableResetPassword);
    }

    if (options.hasKey(USE_MAGIC_LINK_KEY)) {
        useMagicLink = options.getBoolean(USE_MAGIC_LINK_KEY);
        Log.d(TAG, USE_MAGIC_LINK_KEY + useMagicLink);
    }

    if (options.hasKey(AUTH_PARAMS_KEY)) {
        ReadableMap reactMap = options.getMap(AUTH_PARAMS_KEY);
        authParams = OptionsHelper.convertReadableMapToMap(reactMap);
        Log.d(TAG, AUTH_PARAMS_KEY + authParams);
    }

    if (options.hasKey(CONNECTIONS_KEY)) {
        ReadableArray connections = options.getArray(CONNECTIONS_KEY);
        List<String> list = new ArrayList<>(connections.size());
        for (int i = 0; i < connections.size(); i++) {
            String connectionName = connections.getString(i);
            switch (connectionName) {
            case LockReactModule.CONNECTION_EMAIL:
                connectionType = LockReactModule.CONNECTION_EMAIL;
                break;
            case LockReactModule.CONNECTION_SMS:
                connectionType = LockReactModule.CONNECTION_SMS;
                break;
            }
            list.add(connectionName);
        }
        this.connections = new String[list.size()];
        this.connections = list.toArray(this.connections);
        Log.d(TAG, CONNECTIONS_KEY + list);
    }
}

From source file:com.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java

License:Apache License

private HashMap<String, Object> convertMapToHashMap(ReadableMap readableMap) {
    HashMap<String, Object> json = new HashMap<>();
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        switch (readableMap.getType(key)) {
        case Null:
            json.put(key, null);//from   w ww.  j a  v  a2 s  .c om
            break;
        case Boolean:
            json.put(key, readableMap.getBoolean(key));
            break;
        case Number:
            json.put(key, readableMap.getDouble(key));
            break;
        case String:
            json.put(key, readableMap.getString(key));
            break;
        case Map:
            json.put(key, convertMapToHashMap(readableMap.getMap(key)));
            break;
        case Array:
            json.put(key, convertArrayToArrayList(readableMap.getArray(key)));
            break;
        }
    }

    return json;
}

From source file:com.boundlessgeo.spatialconnect.jsbridge.SCBridge.java

License:Apache License

private static JSONObject convertMapToJson(ReadableMap readableMap) {
    JSONObject object = new JSONObject();
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    try {//from ww w  .  j  a  v a2  s  .  co m

        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;
            }
        }
    } catch (JSONException e) {
        Log.e(LOG_TAG, "Could not convert to json");
        e.printStackTrace();
    }
    return object;
}

From source file:com.google.android.cameraview.Camera1.java

License:Apache License

void takePictureInternal(final ReadableMap options) {
    if (!isPictureCaptureInProgress.getAndSet(true)) {

        if (options.hasKey("orientation") && options.getInt("orientation") != Constants.ORIENTATION_AUTO) {
            mOrientation = options.getInt("orientation");
            int rotation = orientationEnumToRotation(mOrientation);
            mCameraParameters.setRotation(calcCameraRotation(rotation));
            mCamera.setParameters(mCameraParameters);
        }//from ww  w . j  a  v  a2s .  c  o  m

        mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
            @Override
            public void onPictureTaken(byte[] data, Camera camera) {
                isPictureCaptureInProgress.set(false);
                camera.cancelAutoFocus();
                if (options.hasKey("pauseAfterCapture") && !options.getBoolean("pauseAfterCapture")) {
                    camera.startPreview();
                    mIsPreviewActive = true;
                    if (mIsScanning) {
                        camera.setPreviewCallback(Camera1.this);
                    }
                } else {
                    camera.stopPreview();
                    mIsPreviewActive = false;
                    camera.setPreviewCallback(null);
                }

                mOrientation = Constants.ORIENTATION_AUTO;
                mCallback.onPictureTaken(data, displayOrientationToOrientationEnum(mDeviceOrientation));
            }
        });
    }
}

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