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

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

Introduction

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

Prototype

@Nullable
    ReadableMap getMap(@NonNull String name);

Source Link

Usage

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 w  w .  ja va  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. 
 * /*  ww w.  ja  va2 s  .co  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  a2 s.com*/

    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.auth0.lock.react.bridge.ShowOptions.java

License:Open Source License

public ShowOptions(@Nullable ReadableMap options) {
    if (options == null) {
        return;//from   w ww  .j  a v a  2 s. c  o 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.blockablewebview.BlockableWebViewManager.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);//from  w ww .ja  va2s.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();
                    headerMap.put(key, headers.getString(key));
                }
            }
            view.loadUrl(url, headerMap);
            return;
        }
    }
    view.loadUrl(BLANK_URL);
}

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);// www .j a  v  a  2s .c o  m
            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

/**
 * Handles a message sent from Javascript.  Expects the message envelope to look like:
 * <code>{"action":<integer>,"payload":<JSON Object>}</code>
 *
 * @param message/*from   w w  w .  j  a va  2s. c  om*/
 */
@ReactMethod
public void handler(ReadableMap message) {
    Log.d(LOG_TAG, "Received message from JS: " + message.toString());
    message = message.getMap("data");

    if (message == null && message.equals("undefined")) {
        Log.w(LOG_TAG, "data message was null or undefined");
        return;
    } else {
        // parse bridge message to determine command
        Integer actionNumber = message.getInt("action");
        BridgeCommand command = BridgeCommand.fromActionNumber(actionNumber);
        if (command.equals(BridgeCommand.START_ALL_SERVICES)) {
            handleStartAllServices();
        }
        if (command.equals(BridgeCommand.SENSORSERVICE_GPS)) {
            handleSensorServiceGps(message);
        }
        if (command.equals(BridgeCommand.DATASERVICE_ACTIVESTORESLIST)) {
            handleActiveStoresList();
        }
        if (command.equals(BridgeCommand.DATASERVICE_ACTIVESTOREBYID)) {
            handleActiveStoreById(message);
        }
        if (command.equals(BridgeCommand.DATASERVICE_GEOSPATIALQUERYALL)
                || command.equals(BridgeCommand.DATASERVICE_SPATIALQUERYALL)) {
            handleQueryAll(message);
        }
        if (command.equals(BridgeCommand.DATASERVICE_UPDATEFEATURE)) {
            handleUpdateFeature(message);
        }
        if (command.equals(BridgeCommand.DATASERVICE_DELETEFEATURE)) {
            handleDeleteFeature(message);
        }
        if (command.equals(BridgeCommand.DATASERVICE_CREATEFEATURE)) {
            handleCreateFeature(message);
        }
        if (command.equals(BridgeCommand.DATASERVICE_FORMSLIST)) {
            handleFormsList();
        }
    }
}

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

License:Apache License

/**
 * Handles all the {@link BridgeCommand#DATASERVICE_ACTIVESTOREBYID} commands.
 *
 * @param message// w w  w  . j  ava2 s . c o  m
 */
private void handleActiveStoreById(ReadableMap message) {
    Log.d(LOG_TAG, "Handling ACTIVESTOREBYID message :" + message.toString());
    String storeId = message.getMap("payload").getString("storeId");
    SCDataStore store = sc.getDataService().getStoreById(storeId);
    sendEvent("store", getStoreMap(store));
}

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

License:Apache License

/**
 * Handles the {@link BridgeCommand#DATASERVICE_UPDATEFEATURE} command.
 *
 * @param message/*from   w w w .  jav a 2s  .c om*/
 */
private void handleUpdateFeature(ReadableMap message) {
    Log.d(LOG_TAG, "Handling UPDATEFEATURE message :" + message.toString());
    try {
        SCSpatialFeature featureToUpdate = getFeatureToUpdate(message.getMap("payload").getString("feature"));
        sc.getDataService().getStoreById(featureToUpdate.getKey().getStoreId()).update(featureToUpdate)
                .subscribeOn(Schedulers.io()).subscribe(new Subscriber<SCSpatialFeature>() {
                    @Override
                    public void onCompleted() {
                        Log.d(LOG_TAG, "update completed");
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e(LOG_TAG, "onError()\n" + e.getLocalizedMessage());
                    }

                    @Override
                    public void onNext(SCSpatialFeature updated) {
                        Log.d(LOG_TAG, "feature updated!");
                        //TODO: send this over some "update" stream
                    }
                });
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

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

License:Apache License

/**
 * Handles the {@link BridgeCommand#DATASERVICE_CREATEFEATURE} command.
 *
 * @param message//from  w w  w . j  a  va2s  . c  o  m
 */
private void handleCreateFeature(ReadableMap message) {
    Log.d(LOG_TAG, "Handling CREATEFEATURE message :" + message.toString());
    try {
        SCSpatialFeature newFeature = getNewFeature(message.getMap("payload"));
        // if no store was specified, use the default store
        if (newFeature.getKey().getStoreId() == null || newFeature.getKey().getStoreId().isEmpty()) {
            newFeature.setStoreId(DefaultStore.NAME);
        }
        sc.getDataService().getStoreById(newFeature.getKey().getStoreId()).create(newFeature)
                .subscribeOn(Schedulers.io()).subscribe(new Subscriber<SCSpatialFeature>() {
                    @Override
                    public void onCompleted() {
                        Log.d(LOG_TAG, "create completed");
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        Log.e(LOG_TAG, "onError()\n" + e.getLocalizedMessage());
                    }

                    @Override
                    public void onNext(SCSpatialFeature feature) {
                        try {
                            // base64 encode id and set it before sending across wire
                            String encodedId = feature.getKey().encodedCompositeKey();
                            feature.setId(encodedId);
                            sendEvent("createFeature", feature.toJson());
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                    }
                });
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}