List of usage examples for com.facebook.react.bridge ReadableArray getString
@Nullable
String getString(int index);
From source file:co.rewen.statex.AsyncLocalStorageUtil.java
License:Open Source License
/** * Build the String[] arguments needed for an SQL selection, i.e.: * {a, b, c}//from ww w.ja va2 s .c om * to be used in the SQL select statement: WHERE key in (?, ?, ?) */ /* package */ static String[] buildKeySelectionArgs(ReadableArray keys, int start, int count) { String[] selectionArgs = new String[count]; for (int keyIndex = 0; keyIndex < count; keyIndex++) { selectionArgs[keyIndex] = keys.getString(start + keyIndex); } return selectionArgs; }
From source file:co.rewen.statex.StateX.java
License:Open Source License
public static ArrayList<String> toStringArray(ReadableArray array) { ArrayList<String> strings = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { strings.add(array.getString(i)); }/*from w w w . ja v a 2 s. c o m*/ return strings; }
From source file:co.rewen.statex.StateXModule.java
License:Open Source License
/** * Given an array of keys, this returns a map of (key, value) pairs for the keys found, and * (key, null) for the keys that haven't been found. *///from www. j ava 2 s.com @ReactMethod public void multiGet(final ReadableArray keys, final Callback callback) { if (keys == null) { callback.invoke(AsyncStorageErrorUtil.getInvalidKeyError(null), null); return; } new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { if (!ensureDatabase()) { callback.invoke(AsyncStorageErrorUtil.getDBError(null), null); return; } String[] columns = { KEY_COLUMN, VALUE_COLUMN }; HashSet<String> keysRemaining = SetBuilder.newHashSet(); WritableArray data = Arguments.createArray(); for (int keyStart = 0; keyStart < keys.size(); keyStart += MAX_SQL_KEYS) { int keyCount = Math.min(keys.size() - keyStart, MAX_SQL_KEYS); Cursor cursor = mStateXDatabaseSupplier.get().query(TABLE_STATE, columns, AsyncLocalStorageUtil.buildKeySelection(keyCount), AsyncLocalStorageUtil.buildKeySelectionArgs(keys, keyStart, keyCount), null, null, null); keysRemaining.clear(); try { if (cursor.getCount() != keys.size()) { // some keys have not been found - insert them with null into the final array for (int keyIndex = keyStart; keyIndex < keyStart + keyCount; keyIndex++) { keysRemaining.add(keys.getString(keyIndex)); } } if (cursor.moveToFirst()) { do { WritableArray row = Arguments.createArray(); row.pushString(cursor.getString(0)); row.pushString(cursor.getString(1)); data.pushArray(row); keysRemaining.remove(cursor.getString(0)); } while (cursor.moveToNext()); } } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage()), null); return; } finally { cursor.close(); } for (String key : keysRemaining) { WritableArray row = Arguments.createArray(); row.pushString(key); row.pushNull(); data.pushArray(row); } keysRemaining.clear(); } callback.invoke(null, data); } }.execute(); }
From source file:com.adjust.nativemodule.AdjustUtil.java
License:Open Source License
/** * toList converts a {@link ReadableArray} into an ArrayList. * /* ww w . ja v a2s . co m*/ * @param readableArray The ReadableArray to be conveted. * @return An ArrayList containing the data that was in the ReadableArray. */ public static List<Object> toList(@Nullable ReadableArray readableArray) { if (readableArray == null) { return null; } List<Object> result = new ArrayList<>(readableArray.size()); for (int index = 0; index < readableArray.size(); index++) { ReadableType readableType = readableArray.getType(index); switch (readableType) { case Null: break; case Boolean: result.add(readableArray.getBoolean(index)); break; case Number: // Can be int or double. double tmp = readableArray.getDouble(index); if (tmp == (int) tmp) { result.add((int) tmp); } else { result.add(tmp); } break; case String: result.add(readableArray.getString(index)); break; case Map: result.add(toMap(readableArray.getMap(index))); break; case Array: result = toList(readableArray.getArray(index)); break; default: AdjustFactory.getLogger().error("Could not convert object with index: " + index + "."); } } return result; }
From source file:com.amazonaws.reactnative.core.AWSRNClientMarshaller.java
License:Open Source License
/** * toList converts a {@link ReadableArray} into an ArrayList. * * @param readableArray The ReadableArray to be conveted. * @return An ArrayList containing the data that was in the ReadableArray. *//*from www . j ava 2 s . c o m*/ public static List<Object> readableArrayToList(final @Nullable ReadableArray readableArray) { if (readableArray == null) { return null; } List<Object> result = new ArrayList<>(readableArray.size()); for (int index = 0; index < readableArray.size(); index++) { final ReadableType readableType = readableArray.getType(index); switch (readableType) { case Null: result.add(String.valueOf(index)); break; case Boolean: result.add(readableArray.getBoolean(index)); break; case Number: // Can be int or double. double tmp = readableArray.getDouble(index); if (tmp == (int) tmp) { result.add((int) tmp); } else { result.add(tmp); } break; case String: result.add(readableArray.getString(index)); break; case Map: result.add(readableMapToMap(readableArray.getMap(index))); break; case Array: result = readableArrayToList(readableArray.getArray(index)); break; default: throw new IllegalArgumentException("Could not convert object with index: " + index + "."); } } 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 w w.j a v a2 s .co 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.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java
License:Apache License
@ReactMethod public void addRasterLayers(final ReadableArray storeIdArray) { UIManagerModule uiManager = this.reactContext.getNativeModule(UIManagerModule.class); uiManager.addUIBlock(new UIBlock() { public void execute(NativeViewHierarchyManager nvhm) { List<String> storeIds = new ArrayList<>(storeIdArray.size()); for (int index = 0; index < storeIdArray.size(); index++) { storeIds.add(storeIdArray.getString(index)); }/*from w w w. j av a2s. c om*/ List<SCDataStore> stores = SpatialConnect.getInstance().getDataService().getActiveStores(); for (SCDataStore store : stores) { List<TileOverlay> tiles = tileoverlays.get(store.getStoreId()); if (storeIds.contains(store.getStoreId())) { if (tiles == null) { if (store instanceof GeoPackageStore && ((GeoPackageStore) store).getTileSources().size() > 0) { SCRasterStore rs = new GpkgRasterSource((GeoPackageStore) store); List<TileOverlay> newTiles = new ArrayList<TileOverlay>(); for (String tableName : rs.rasterLayers()) { TileOverlay t = rs.overlayFromLayer(tableName, mGoogleMap); newTiles.add(t); } tileoverlays.put(store.getStoreId(), newTiles); } } } else { if (tiles != null) { for (TileOverlay tile : tiles) { tile.remove(); } tileoverlays.remove(store.getStoreId()); } } } } }); }
From source file:com.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java
License:Apache License
private ArrayList<Object> convertArrayToArrayList(ReadableArray readableArray) { ArrayList<Object> jsonArray = new ArrayList<>(); for (int i = 0; i < readableArray.size(); i++) { switch (readableArray.getType(i)) { case Null: break; case Boolean: jsonArray.add(readableArray.getBoolean(i)); break; case Number: jsonArray.add(readableArray.getDouble(i)); break; case String: jsonArray.add(readableArray.getString(i)); break; case Map: jsonArray.add(convertMapToHashMap(readableArray.getMap(i))); break; case Array: jsonArray.add(convertArrayToArrayList(readableArray.getArray(i))); break; }//w ww . j ava 2s . c om } return jsonArray; }
From source file:com.boundlessgeo.spatialconnect.jsbridge.SCBridge.java
License:Apache License
private static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException { JSONArray array = new JSONArray(); for (int i = 0; i < readableArray.size(); i++) { switch (readableArray.getType(i)) { case Null: break; case Boolean: array.put(readableArray.getBoolean(i)); break; case Number: array.put(readableArray.getDouble(i)); break; case String: array.put(readableArray.getString(i)); break; case Map: array.put(convertMapToJson(readableArray.getMap(i))); break; case Array: array.put(convertArrayToJson(readableArray.getArray(i))); break; }// w ww . jav a 2s .c om } return array; }
From source file:com.geniem.rnble.RNBLEModule.java
License:Open Source License
@ReactMethod public void discoverServices(final String peripheralUuid, ReadableArray uuids) { Log.d(TAG, "discoverServices"); WritableArray filteredServiceUuids = Arguments.createArray(); if (bluetoothGatt != null && this.discoveredServices != null && uuids != null && uuids.size() > 0) { //filter discovered services for (BluetoothGattService service : this.discoveredServices) { String uuid = service.getUuid().toString(); for (int i = 0; i < uuids.size(); i++) { if (uuid.equalsIgnoreCase(uuids.getString(i))) { filteredServiceUuids.pushString(toNobleUuid(uuid)); }//from w ww . j a va 2 s. c om } } } else if (uuids == null || uuids.size() == 0) { //if no uuids are requested return all discovered service uuids for (BluetoothGattService service : this.discoveredServices) { String uuid = service.getUuid().toString(); filteredServiceUuids.pushString(toNobleUuid(uuid)); } } WritableMap params = Arguments.createMap(); params.putString("peripheralUuid", peripheralUuid); params.putArray("serviceUuids", filteredServiceUuids); this.sendEvent("ble.servicesDiscover", params); }