List of usage examples for com.facebook.react.bridge WritableArray pushMap
void pushMap(@Nullable ReadableMap map);
From source file:com.amazonaws.reactnative.core.AWSRNClientMarshaller.java
License:Open Source License
public static WritableArray jsonToReact(final JSONArray jsonArray) throws JSONException { final WritableArray writableArray = Arguments.createArray(); for (int i = 0; i < jsonArray.length(); i++) { final Object value = jsonArray.get(i); if (value instanceof Float || value instanceof Double) { writableArray.pushDouble(jsonArray.getDouble(i)); } else if (value instanceof Number) { writableArray.pushInt(jsonArray.getInt(i)); } else if (value instanceof String) { writableArray.pushString(jsonArray.getString(i)); } else if (value instanceof Boolean) { writableArray.pushBoolean(jsonArray.getBoolean(i)); } else if (value instanceof JSONObject) { writableArray.pushMap(jsonToReact(jsonArray.getJSONObject(i))); } else if (value instanceof JSONArray) { writableArray.pushArray(jsonToReact(jsonArray.getJSONArray(i))); } else if (value == JSONObject.NULL) { writableArray.pushNull();//from ww w. java 2s . co m } } return writableArray; }
From source file:com.auth0.lock.react.bridge.UserProfileBridge.java
License:Open Source License
private void add(UserIdentity identity, WritableArray into) { final WritableMap map = Arguments.createMap(); map.putString("userId", identity.getId()); map.putString("connection", identity.getConnection()); map.putString("provider", identity.getProvider()); map.putBoolean("social", identity.isSocial()); put("profileData", identity.getProfileInfo(), map); into.pushMap(map); }
From source file:com.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java
License:Apache License
private WritableArray convertArrayToArrayList(List list) { WritableArray writableArray = Arguments.createArray(); if (list.size() < 1) { return writableArray; }// w w w.jav a2s . co m Object firstObject = list.get(0); if (firstObject == null) { for (int i = 0; i < list.size(); i++) { writableArray.pushNull(); } } else if (firstObject instanceof Boolean) { for (Object object : list) { writableArray.pushBoolean((boolean) object); } } else if (firstObject instanceof Double) { for (Object object : list) { writableArray.pushDouble((double) object); } } else if (firstObject instanceof Integer) { for (Object object : list) { writableArray.pushInt((int) object); } } else if (firstObject instanceof Long) { for (Object object : list) { writableArray.pushDouble((long) object); } } else if (firstObject instanceof String) { for (Object object : list) { writableArray.pushString((String) object); } } else if (firstObject instanceof Map) { for (Object object : list) { writableArray.pushMap(convertHashMapToMap((Map) object)); } } else if (firstObject instanceof List) { for (Object object : list) { writableArray.pushArray(convertArrayToArrayList((List) object)); } } return writableArray; }
From source file:com.boundlessgeo.spatialconnect.jsbridge.SCBridge.java
License:Apache License
/** * Handles the {@link BridgeCommand#DATASERVICE_ACTIVESTORESLIST} command. *//*from www.ja va 2s . c om*/ 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 . j av a2 s . c om*/ 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()); }/*from w w w .ja v a2 s.co 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 WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException { WritableArray array = new WritableNativeArray(); for (int i = 0; i < jsonArray.length(); i++) { Object value = jsonArray.get(i); if (value instanceof JSONObject) { array.pushMap(convertJsonToMap((JSONObject) value)); } else if (value instanceof JSONArray) { array.pushArray(convertJsonToArray((JSONArray) value)); } else if (value instanceof Boolean) { array.pushBoolean((Boolean) value); } else if (value instanceof Integer) { array.pushInt((Integer) value); } else if (value instanceof Double) { array.pushDouble((Double) value); } else if (value instanceof String) { array.pushString((String) value); } else {/*from w w w . j av a 2 s .c om*/ array.pushString(value.toString()); } } return array; }
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()) { {/* www . j a va2s. c o 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 ww w. j a v a 2 s .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); }
From source file:com.geniem.rnble.RNBLEModule.java
License:Open Source License
@ReactMethod public void discoverCharacteristics(final String peripheralUuid, final String serviceUuid, ReadableArray characteristicUuids) { Log.d(TAG, "discoverCharacteristics"); WritableArray requestedCharacteristics = Arguments.createArray(); List<BluetoothGattCharacteristic> filteredCharacteristics = new ArrayList<BluetoothGattCharacteristic>(); for (BluetoothGattService service : this.discoveredServices) { String uuid = service.getUuid().toString(); //filter requested service if (uuid != null && uuid.equalsIgnoreCase(serviceUuid)) { List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); //remove characteristics from the characteristics list based on requested characteristicUuids if (characteristicUuids != null && characteristicUuids.size() > 0) { for (int i = 0; i < characteristicUuids.size(); i++) { Iterator<BluetoothGattCharacteristic> iterator = characteristics.iterator(); while (iterator.hasNext()) { BluetoothGattCharacteristic characteristic = iterator.next(); if (characteristicUuids.getString(i) .equalsIgnoreCase(characteristic.getUuid().toString())) { filteredCharacteristics.add(characteristic); break; }//from www. j av a2 s. co m } } } // if no filter uuids given, just pass all else { Iterator<BluetoothGattCharacteristic> iterator = characteristics.iterator(); while (iterator.hasNext()) { BluetoothGattCharacteristic characteristic = iterator.next(); filteredCharacteristics.add(characteristic); } } //process characteristics for (BluetoothGattCharacteristic c : filteredCharacteristics) { WritableArray properties = Arguments.createArray(); int propertyBitmask = c.getProperties(); if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_BROADCAST) != 0) { properties.pushString("boradcast"); } if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_READ) != 0) { properties.pushString("read"); } if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0) { properties.pushString("writeWithoutResponse"); } if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0) { properties.pushString("write"); } if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) { properties.pushString("notify"); } if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) { properties.pushString("indicaste"); } if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0) { properties.pushString("authenticatedSignedWrites"); } if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) != 0) { properties.pushString("extendedProperties"); } WritableMap characteristicObject = Arguments.createMap(); characteristicObject.putArray("properties", properties); characteristicObject.putString("uuid", toNobleUuid(c.getUuid().toString())); requestedCharacteristics.pushMap(characteristicObject); } break; } } WritableMap params = Arguments.createMap(); params.putString("peripheralUuid", peripheralUuid); params.putString("serviceUuid", toNobleUuid(serviceUuid)); params.putArray("characteristics", requestedCharacteristics); this.sendEvent("ble.characteristicsDiscover", params); }