Example usage for com.facebook.react.bridge WritableMap putArray

List of usage examples for com.facebook.react.bridge WritableMap putArray

Introduction

In this page you can find the example usage for com.facebook.react.bridge WritableMap putArray.

Prototype

void putArray(@NonNull String key, @Nullable ReadableArray value);

Source Link

Usage

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

License:Open Source License

public static WritableMap jsonToReact(final JSONObject jsonObject) throws JSONException {
    final WritableMap writableMap = Arguments.createMap();
    final Iterator iterator = jsonObject.keys();
    while (iterator.hasNext()) {
        final String key = (String) iterator.next();
        final Object value = jsonObject.get(key);
        if (value instanceof Float || value instanceof Double) {
            writableMap.putDouble(key, jsonObject.getDouble(key));
        } else if (value instanceof Number) {
            writableMap.putInt(key, jsonObject.getInt(key));
        } else if (value instanceof String) {
            writableMap.putString(key, jsonObject.getString(key));
        } else if (value instanceof JSONObject) {
            writableMap.putMap(key, jsonToReact(jsonObject.getJSONObject(key)));
        } else if (value instanceof JSONArray) {
            writableMap.putArray(key, jsonToReact(jsonObject.getJSONArray(key)));
        } else if (value instanceof Boolean) {
            writableMap.putBoolean(key, jsonObject.getBoolean(key));
        } else if (value == JSONObject.NULL) {
            writableMap.putNull(key);//from   w  ww .ja  va2  s  .co  m
        }
    }
    return writableMap;
}

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

License:Open Source License

public WritableMap toMap() {
    WritableMap profileMap = null;
    if (profile != null) {
        profileMap = Arguments.createMap();
        profileMap.putString(EMAIL_KEY, profile.getEmail());
        profileMap.putString(ID_KEY, profile.getId());
        profileMap.putString(NAME_KEY, profile.getName());
        profileMap.putString(NICKNAME_KEY, profile.getNickname());
        if (profile.getCreatedAt() != null) {
            profileMap.putString(CREATED_AT_KEY, formatter.format(profile.getCreatedAt()));
        }//from   w w w .  j a v a 2  s  . c  om
        profileMap.putString(PICTURE_KEY, profile.getPictureURL());
        Map<String, Object> info = new HashMap<>(profile.getExtraInfo());
        put("userMetadata", info.remove("user_metadata"), profileMap);
        put("appMetadata", info.remove("app_metadata"), profileMap);
        for (Map.Entry<String, Object> entry : info.entrySet()) {
            put(entry.getKey(), entry.getValue(), profileMap);
        }
        final WritableArray identities = Arguments.createArray();
        for (UserIdentity identity : profile.getIdentities()) {
            add(identity, identities);
        }
        profileMap.putArray("identities", identities);
    }
    return profileMap;
}

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

License:Open Source License

private void put(String key, List<?> list, WritableMap into) {
    if (list == null || list.isEmpty()) {
        return;//from   w  w w .  j a v a  2 s.co  m
    }

    final WritableArray array = Arguments.createArray();
    for (Object item : list) {
        if (item instanceof String) {
            array.pushString((String) item);
        }
        if (item instanceof Integer) {
            array.pushInt((Integer) item);
        }
        if (item instanceof Boolean) {
            array.pushBoolean((Boolean) item);
        }
        if (item instanceof Double) {
            array.pushDouble((Double) item);
        }
        if (item instanceof Date) {
            array.pushString(formatter.format(item));
        }
    }
    into.putArray(key, array);
}

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

License:Apache License

private WritableMap convertHashMapToMap(Map<String, Object> hashMap) {
    WritableMap writableMap = Arguments.createMap();

    for (Map.Entry<String, Object> entry : hashMap.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();

        if (value == null) {
            writableMap.putNull(key);//from w ww  .  jav  a  2  s  . co m
        } else if (value instanceof Boolean) {
            writableMap.putBoolean(key, (Boolean) value);
        } else if (value instanceof Double) {
            writableMap.putDouble(key, (Double) value);
        } else if (value instanceof Integer) {
            writableMap.putInt(key, (Integer) value);
        } else if (value instanceof Long) {
            writableMap.putDouble(key, (Long) value);
        } else if (value instanceof String) {
            writableMap.putString(key, (String) value);
        } else if (value instanceof Map) {
            writableMap.putMap(key, convertHashMapToMap((Map) value));
        } else if (value instanceof List) {
            writableMap.putArray(key, convertArrayToArrayList((List) value));
        }
    }

    return writableMap;
}

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

License:Apache License

/**
 * Handles the {@link BridgeCommand#DATASERVICE_ACTIVESTORESLIST} command.
 *///from   w  w w. j  ava 2  s  .  co m
private void handleActiveStoresList() {
    Log.d(LOG_TAG, "Handling DATASERVICE_ACTIVESTORESLIST message");
    List<SCDataStore> stores = sc.getDataService().getActiveStores();
    WritableMap eventPayload = Arguments.createMap();
    WritableArray storesArray = Arguments.createArray();
    for (SCDataStore store : stores) {
        storesArray.pushMap(getStoreMap(store));
    }
    eventPayload.putArray("stores", storesArray);
    sendEvent("storesList", eventPayload);
}

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

License:Apache License

/**
 * Handles the {@link BridgeCommand#DATASERVICE_FORMSLIST} command.
 *//*from w  w w  .  ja  v a 2s.c o  m*/
private void handleFormsList() {
    Log.d(LOG_TAG, "Handling DATASERVICE_FORMSLIST message");
    List<SCFormConfig> formConfigs = sc.getDataService().getDefaultStore().getFormConfigs();
    WritableMap eventPayload = Arguments.createMap();
    WritableArray formsArray = Arguments.createArray();
    for (SCFormConfig config : formConfigs) {
        formsArray.pushMap(getFormMap(config));
    }
    eventPayload.putArray("forms", formsArray);
    sendEvent("formsList", eventPayload);
}

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

License:Apache License

private WritableMap getFormMap(SCFormConfig formConfig) {
    WritableMap params = Arguments.createMap();
    params.putString("id", formConfig.getId());
    params.putString("name", formConfig.getName());
    params.putString("display_name", formConfig.getDisplayName());
    params.putString("layer_name", formConfig.getLayerName());
    WritableArray fields = Arguments.createArray();
    // for each field, create a WriteableMap with all the SCFormField params
    for (SCFormField field : formConfig.getFields()) {
        WritableMap fieldMap = Arguments.createMap();
        fieldMap.putString("id", field.getId());
        fieldMap.putString("key", field.getKey());
        fieldMap.putString("label", field.getLabel());
        if (field.isRequired() != null) {
            fieldMap.putBoolean("is_required", field.isRequired());
        }//  w  w  w . j  a v  a  2s  .c o  m
        if (field.getPosition() != null) {
            fieldMap.putInt("order", field.getPosition());
        }
        if (field.getType() != null) {
            fieldMap.putString("type", field.getType());
        }
        if (field.getInitialValue() != null) {
            fieldMap.putString("initial_value", String.valueOf(field.getInitialValue()));
        }
        if (field.getMaximum() != null) {
            fieldMap.putDouble("minimum", Double.valueOf(String.valueOf(field.getMinimum())));
        }
        if (field.getMaximum() != null) {
            fieldMap.putDouble("maximum", Double.valueOf(String.valueOf(field.getMaximum())));
        }
        if (field.isExclusiveMaximum() != null) {
            fieldMap.putBoolean("exclusive_maximum", field.isExclusiveMaximum());
        }
        if (field.isExclusiveMinimum() != null) {
            fieldMap.putBoolean("exclusive_minimum", field.isExclusiveMinimum());
        }
        if (field.isInteger() != null) {
            fieldMap.putBoolean("is_integer", field.isInteger());
        }
        if (field.getMaximumLength() != null) {
            fieldMap.putInt("maximum_length", field.getMaximumLength());
        }
        if (field.getMinimumLength() != null) {
            fieldMap.putInt("minimum_length", field.getMinimumLength());
        }
        if (field.getPattern() != null) {
            fieldMap.putString("pattern", field.getPattern());
        }
        fields.pushMap(fieldMap);
    }
    params.putArray("fields", fields);
    return params;
}

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

License:Apache License

private static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
    WritableMap map = new WritableNativeMap();

    Iterator<String> iterator = jsonObject.keys();
    while (iterator.hasNext()) {
        String key = iterator.next();
        Object value = jsonObject.get(key);
        if (value instanceof JSONObject) {
            map.putMap(key, convertJsonToMap((JSONObject) value));
        } else if (value instanceof JSONArray) {
            map.putArray(key, convertJsonToArray((JSONArray) value));
        } else if (value instanceof Boolean) {
            map.putBoolean(key, (Boolean) value);
        } else if (value instanceof Integer) {
            map.putInt(key, (Integer) value);
        } else if (value instanceof Double) {
            map.putDouble(key, (Double) value);
        } else if (value instanceof String) {
            map.putString(key, (String) value);
        } else {//from w w  w  .j a  v  a  2 s. c  om
            map.putString(key, value.toString());
        }
    }
    return map;
}

From source file:com.dylanvann.cameraroll.CameraRollManager.java

License:Open Source License

private static void putAlbums(ContentResolver resolver, Cursor cursor, WritableMap response) {
    WritableArray albums = new WritableNativeArray();
    int bucketIdIndex = cursor.getColumnIndex(Video.VideoColumns.BUCKET_ID);
    int bucketNameIndex = cursor.getColumnIndex(Video.VideoColumns.BUCKET_DISPLAY_NAME);
    int idIndex = cursor.getColumnIndex(FileColumns._ID);
    int mimeTypeIndex = cursor.getColumnIndex(FileColumns.MIME_TYPE);
    int mediaTypeIndex = cursor.getColumnIndex(FileColumns.MEDIA_TYPE);
    int dateModifiedIndex = cursor.getColumnIndex(FileColumns.DATE_MODIFIED);
    int widthIndex = IS_JELLY_BEAN_OR_LATER ? cursor.getColumnIndex(FileColumns.WIDTH) : -1;
    int heightIndex = IS_JELLY_BEAN_OR_LATER ? cursor.getColumnIndex(FileColumns.HEIGHT) : -1;
    HashMap<String, WritableMap> albumsMap = new HashMap<>();
    String assetCountKey = "assetCount";
    if (cursor.moveToFirst()) {
        {//from  ww w  .j av  a  2 s.co  m
            WritableMap album = new WritableNativeMap();
            album.putInt(assetCountKey, cursor.getCount());
            WritableArray previewAssets = new WritableNativeArray();
            WritableMap asset = new WritableNativeMap();
            putAssetInfo(resolver, cursor, asset, mediaTypeIndex, idIndex, widthIndex, heightIndex,
                    mimeTypeIndex, dateModifiedIndex);
            previewAssets.pushMap(asset);
            album.putArray("previewAssets", previewAssets);
            albumsMap.put("-1", album);
        }

        while (cursor.moveToNext()) {
            String albumId = cursor.getString(bucketIdIndex);
            if (!albumsMap.containsKey(albumId)) {
                WritableMap album = new WritableNativeMap();
                String albumName = cursor.getString(bucketNameIndex);
                album.putString("id", albumId);
                album.putString("title", albumName);
                album.putInt(assetCountKey, 1);
                WritableArray previewAssets = new WritableNativeArray();
                WritableMap asset = new WritableNativeMap();
                putAssetInfo(resolver, cursor, asset, mediaTypeIndex, idIndex, widthIndex, heightIndex,
                        mimeTypeIndex, dateModifiedIndex);
                previewAssets.pushMap(asset);
                album.putArray("previewAssets", previewAssets);
                albumsMap.put(albumId, album);
            } else {
                WritableMap album = albumsMap.get(albumId);
                int count = album.getInt(assetCountKey);
                album.putInt(assetCountKey, count + 1);
            }
        }
        Collection<WritableMap> albumsCollection = albumsMap.values();
        for (WritableMap album : albumsCollection) {
            albums.pushMap(album);
        }
    }
    response.putArray("albums", albums);
}

From source file:com.dylanvann.cameraroll.CameraRollManager.java

License:Open Source License

private static void putAssets(ContentResolver resolver, Cursor photos, WritableMap response, int limit) {
    WritableArray assets = new WritableNativeArray();
    photos.moveToFirst();/*from   w w w. j  a  v a 2s  . c o  m*/
    int idIndex = photos.getColumnIndex(FileColumns._ID);
    int mimeTypeIndex = photos.getColumnIndex(FileColumns.MIME_TYPE);
    int mediaTypeIndex = photos.getColumnIndex(FileColumns.MEDIA_TYPE);
    int dateModifiedIndex = photos.getColumnIndex(FileColumns.DATE_MODIFIED);
    int widthIndex = IS_JELLY_BEAN_OR_LATER ? photos.getColumnIndex(FileColumns.WIDTH) : -1;
    int heightIndex = IS_JELLY_BEAN_OR_LATER ? photos.getColumnIndex(FileColumns.HEIGHT) : -1;

    for (int i = 0; i < limit && !photos.isAfterLast(); i++) {
        WritableMap asset = new WritableNativeMap();
        boolean imageInfoSuccess = putAssetInfo(resolver, photos, asset, mediaTypeIndex, idIndex, widthIndex,
                heightIndex, mimeTypeIndex, dateModifiedIndex);
        if (imageInfoSuccess) {
            assets.pushMap(asset);
        } else {
            // we skipped an image because we couldn't get its details (e.g. width/height), so we
            // decrement i in order to correctly reach the limit, if the cursor has enough rows
            i--;
        }
        photos.moveToNext();
    }
    response.putArray("assets", assets);
}