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.adjust.nativemodule.Adjust.java

License:Open Source License

@ReactMethod
public void create(ReadableMap mapConfig) {
    String environment = null;/*  ww w.  j  a  v a 2 s  .  c  o  m*/
    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.Adjust.java

License:Open Source License

@ReactMethod
public void trackEvent(ReadableMap mapEvent) {
    final String eventToken = mapEvent.getString("eventToken");
    final String currency = mapEvent.getString("currency");
    final String transactionId = mapEvent.getString("transactionId");
    final Map<String, Object> callbackParameters = AdjustUtil.toMap(mapEvent.getMap("callbackParameters"));
    final Map<String, Object> partnerParameters = AdjustUtil.toMap(mapEvent.getMap("partnerParameters"));

    AdjustEvent event = new AdjustEvent(eventToken);

    if (event.isValid()) {
        if (!mapEvent.isNull("revenue")) {
            event.setRevenue(mapEvent.getDouble("revenue"), currency);
        }//from   w ww. j  a  v  a 2  s.  co m

        if (null != callbackParameters) {
            for (Map.Entry<String, Object> entry : callbackParameters.entrySet()) {
                event.addCallbackParameter(entry.getKey(), entry.getValue().toString());
            }
        }

        if (null != partnerParameters) {
            for (Map.Entry<String, Object> entry : partnerParameters.entrySet()) {
                event.addPartnerParameter(entry.getKey(), entry.getValue().toString());
            }
        }

        if (null != transactionId) {
            event.setOrderId(transactionId);
        }

        com.adjust.sdk.Adjust.trackEvent(event);
    }
}

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. 
 * //w w  w.  j  a v  a2  s  .  c o m
 * @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 ww . ja  v a  2s.c  o  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.core.AWSRNCognitoCredentials.java

License:Open Source License

@ReactMethod
public void initWithOptions(final ReadableMap options) throws IllegalArgumentException {
    if (!options.hasKey(IDENTITY_POOL_ID) || !options.hasKey(REGION)) {
        throw new IllegalArgumentException("identity_pool_id and/or region not supplied");
    } else {/*w ww . ja v a2s  . co  m*/
        credentialsProvider = new CognitoCachingCredentialsProvider(getReactApplicationContext(),
                options.getString(IDENTITY_POOL_ID), Regions.fromName(options.getString(REGION)),
                new AWSRNClientConfiguration().withUserAgent(SERVICE_NAME));
        credentialsProvider.registerIdentityChangedListener(new IdentityChangedListener() {
            @Override
            public void identityChanged(final String oldidentityid, final String newidentityid) {
                final WritableMap params = Arguments.createMap();
                params.putString(CURRENT, newidentityid);
                params.putString(PREVIOUS, oldidentityid);
                sendEvent(getReactApplicationContext(), IDENTITYCHANGE, params);
            }
        });
    }
}

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

License:Open Source License

@ReactMethod
public void setLogins(final ReadableMap logins) {
    final Map<String, String> userLogins = new HashMap<String, String>();
    final ReadableMapKeySetIterator loginsIterable = logins.keySetIterator();
    while (loginsIterable.hasNextKey()) {
        final String key = loginsIterable.nextKey();
        userLogins.put(keyConverter(key), logins.getString(key));
    }/*  w  w  w. jav  a  2 s.  co m*/
    if (userLogins.size() != 0) {
        credentialsProvider.setLogins(userLogins);
    }
}

From source file:com.amazonaws.reactnative.dynamodb.AWSRNDynamoDBClient.java

License:Open Source License

@ReactMethod
public void initWithOptions(final ReadableMap options) {
    if (!options.hasKey("region")) {
        throw new IllegalArgumentException("expected region key");
    }/* w  w w  .  ja va  2 s.  c om*/
    final AWSRNCognitoCredentials credentials = this.getReactApplicationContext()
            .getNativeModule(AWSRNCognitoCredentials.class);
    if (credentials.getCredentialsProvider() == null) {
        throw new IllegalArgumentException("AWSCognitoCredentials is not initialized");
    }
    gson = new GsonBuilder().setFieldNamingStrategy(FieldNamingPolicy.UPPER_CAMEL_CASE)
            .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getSerializer())
            .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getDeserializer()).create();
    dynamodbClient = new AmazonDynamoDBClient(credentials.getCredentialsProvider(),
            new AWSRNClientConfiguration().withUserAgent("DynamoDB"));
    dynamodbClient.setRegion(Region.getRegion(Regions.fromName(options.getString("region"))));
}

From source file:com.amazonaws.reactnative.lambda.AWSRNLambdaClient.java

License:Open Source License

@ReactMethod
public void initWithOptions(final ReadableMap options) {
    if (!options.hasKey("region")) {
        throw new IllegalArgumentException("expected region key");
    }/*w  w  w.j  a  v a2 s  .  co m*/
    final AWSRNCognitoCredentials credentials = this.getReactApplicationContext()
            .getNativeModule(AWSRNCognitoCredentials.class);
    if (credentials.getCredentialsProvider() == null) {
        throw new IllegalArgumentException("AWSCognitoCredentials is not initialized");
    }
    gson = new GsonBuilder().setFieldNamingStrategy(FieldNamingPolicy.UPPER_CAMEL_CASE)
            .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getSerializer())
            .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getDeserializer()).create();
    lambdaClient = new AWSLambdaClient(credentials.getCredentialsProvider(),
            new AWSRNClientConfiguration().withUserAgent("Lambda"));
    lambdaClient.setRegion(Region.getRegion(Regions.fromName(options.getString("region"))));
}

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

License:Open Source License

@ReactMethod
public void initWithOptions(final ReadableMap options) {
    if (!options.hasKey(REGION)) {
        throw new IllegalArgumentException("region not supplied");
    }/* w w w.j  a  va2  s  .c o m*/
    final AWSRNCognitoCredentials credentials = this.getReactApplicationContext()
            .getNativeModule(AWSRNCognitoCredentials.class);
    if (credentials.getCredentialsProvider() == null) {
        throw new IllegalArgumentException("AWSCognitoCredentials is not initialized");
    }
    final AmazonS3 s3 = new AmazonS3Client(credentials.getCredentialsProvider(),
            new AWSRNClientConfiguration().withUserAgent("AWSS3TransferUtility"));
    s3.setRegion(Region.getRegion(Regions.fromName(options.getString(REGION))));
    transferUtility = new TransferUtility(s3, getReactApplicationContext());
}

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 ww  .ja  va  2 s .  com
    }
    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());
}