List of usage examples for com.facebook.react.bridge WritableNativeArray WritableNativeArray
public WritableNativeArray()
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 a v a 2s .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()) { {/* w w w. ja v a2 s . 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 w w w . j a v a 2s. co 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.ibatimesheet.RNJSONUtils.java
License:Apache License
public 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 ww w . ja va 2 s . c o m*/ array.pushString(value.toString()); } } return array; }
From source file:com.microsoft.c3p.reactnative.C3PReactModule.java
License:Open Source License
private static WritableNativeArray convertArrayResult(JavaScriptValue arrayResult) { WritableNativeArray convertedResult = new WritableNativeArray(); for (JavaScriptValue value : arrayResult.getArrayItems()) { switch (value.getType()) { case Null: convertedResult.pushNull();/* w w w . jav a 2 s .c o m*/ break; case Boolean: convertedResult.pushBoolean(value.getBoolean()); break; case Number: convertedResult.pushDouble(value.getDouble()); break; case String: convertedResult.pushString(value.getString()); break; case Object: convertedResult.pushMap(C3PReactModule.convertObjectResult(value)); break; case Array: convertedResult.pushArray(C3PReactModule.convertArrayResult(value)); break; } } return convertedResult; }
From source file:com.sogilis.ReactNativeBluetooth.events.EventBuilders.java
License:Apache License
public static WritableArray serviceArray(BluetoothDevice device, List<BluetoothGattService> services) { WritableArray array = new WritableNativeArray(); for (BluetoothGattService service : services) { array.pushMap(serviceMap(device, service)); }//from w w w . ja v a2 s . c o m return array; }
From source file:com.sogilis.ReactNativeBluetooth.events.EventBuilders.java
License:Apache License
private static WritableArray characteristicArray(BluetoothDevice device, List<BluetoothGattCharacteristic> characteristics) { WritableArray array = new WritableNativeArray(); for (BluetoothGattCharacteristic characteristic : characteristics) { array.pushMap(characteristicMap(device, characteristic)); }//from www .ja va 2 s. c om return array; }
From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java
@ReactMethod public void removeGeofences(final Callback success, final Callback failure) { // TODO allow JS api to delete a list-of-geofences. TSCallback callback = new TSCallback() { @Override/*w w w . java 2 s . c om*/ public void success(Object o) { success.invoke((Boolean) o); } @Override public void error(Object o) { failure.invoke((String) o); } }; try { // TODO accept WritableArray geofences from Client js API, allowing to remove a set of geofences WritableArray geofences = new WritableNativeArray(); getAdapter().removeGeofences(arrayToJson(geofences), callback); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java
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(jsonToMap((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 ww w .j a va2s . c o m array.pushString(value.toString()); } } return array; }
From source file:io.github.douglasjunior.ReactNativeEasyBluetooth.core.CoreModule.java
License:Open Source License
public void getBoundedDevices(final Promise promise) { try {/*from w w w . ja va2 s.c om*/ if (!validateBluetoothAdapter(promise)) return; WritableNativeArray devices = new WritableNativeArray(); for (BluetoothDevice btDevice : mBluetoothAdapter.getBondedDevices()) { WritableNativeMap device = wrapDevice(btDevice, 0); devices.pushMap(device); } Log.d(TAG, "getBoundedDevices: " + devices); promise.resolve(devices); } catch (Exception ex) { ex.printStackTrace(); promise.reject(ex); } }