Java Code Examples for com.facebook.react.bridge.ReadableArray#getType()
The following examples show how to use
com.facebook.react.bridge.ReadableArray#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SQLitePlugin.java From react-native-sqlite-storage with MIT License | 6 votes |
private void bindArgsToStatement(SQLiteStatement myStatement, ReadableArray sqlArgs) { for (int i = 0; i < sqlArgs.size(); i++) { ReadableType type = sqlArgs.getType(i); if (type == ReadableType.Number){ double tmp = sqlArgs.getDouble(i); if (tmp == (long) tmp) { myStatement.bindLong(i + 1, (long) tmp); } else { myStatement.bindDouble(i + 1, tmp); } } else if (sqlArgs.isNull(i)) { myStatement.bindNull(i + 1); } else { myStatement.bindString(i + 1, SQLitePluginConverter.getString(sqlArgs,i,"")); } } }
Example 2
Source File: SQLiteManager.java From react-native-android-sqlite with MIT License | 6 votes |
public void exec(final String sql, final ReadableArray values) { SQLiteStatement statement = Assertions.assertNotNull(db).compileStatement(sql); db.beginTransaction(); try { for (int i=0; i < values.size(); i++) { if (values.getType(i) == ReadableType.Number) { statement.bindLong(i+1, values.getInt(i)); } else { statement.bindString(i+1, values.getString(i)); } } statement.execute(); db.setTransactionSuccessful(); } catch (Exception e) { throw e; } finally { db.endTransaction(); } }
Example 3
Source File: SQLiteAndroidDatabase.java From react-native-sqlite-storage with MIT License | 6 votes |
private void bindArgsToStatement(SQLiteStatement myStatement, ReadableArray sqlArgs) { if (sqlArgs == null) return; for (int i = 0; i < sqlArgs.size(); i++) { ReadableType type = sqlArgs.getType(i); if (type == ReadableType.Number) { double tmp = sqlArgs.getDouble(i); if (tmp == (long) tmp) { myStatement.bindLong(i + 1, (long) tmp); } else { myStatement.bindDouble(i + 1, tmp); } } else if (sqlArgs.isNull(i)) { myStatement.bindNull(i + 1); } else { myStatement.bindString(i + 1, sqlArgs.getString(i)); } } }
Example 4
Source File: ReactNativeJson.java From react-native-fcm with MIT License | 6 votes |
public 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; } } return array; }
Example 5
Source File: ReactNativeJson.java From react-native-couchbase-lite with MIT License | 6 votes |
public 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; } } return array; }
Example 6
Source File: FirestackUtils.java From react-native-firestack with MIT License | 5 votes |
public static List<Object> recursivelyDeconstructReadableArray(ReadableArray readableArray) { List<Object> deconstructedList = new ArrayList<>(readableArray.size()); for (int i = 0; i < readableArray.size(); i++) { ReadableType indexType = readableArray.getType(i); switch(indexType) { case Null: deconstructedList.add(i, null); break; case Boolean: deconstructedList.add(i, readableArray.getBoolean(i)); break; case Number: deconstructedList.add(i, readableArray.getDouble(i)); break; case String: deconstructedList.add(i, readableArray.getString(i)); break; case Map: deconstructedList.add(i, FirestackUtils.recursivelyDeconstructReadableMap(readableArray.getMap(i))); break; case Array: deconstructedList.add(i, FirestackUtils.recursivelyDeconstructReadableArray(readableArray.getArray(i))); break; default: throw new IllegalArgumentException("Could not convert object at index " + i + "."); } } return deconstructedList; }
Example 7
Source File: FlurryModule.java From react-native-flurry-sdk with Apache License 2.0 | 5 votes |
private static List<String> toList(final ReadableArray readableArray) { if ((readableArray == null) || (readableArray.size() == 0)) { return null; } List<String> result = new ArrayList<>(); for (int i = 0; i < readableArray.size(); i++) { if (readableArray.getType(i) == ReadableType.String) { result.add(readableArray.getString(i)); } } return result; }
Example 8
Source File: OAuthManagerModule.java From react-native-oauth with MIT License | 5 votes |
public static List<Object> recursivelyDeconstructReadableArray(ReadableArray readableArray) { List<Object> deconstructedList = new ArrayList<>(readableArray.size()); for (int i = 0; i < readableArray.size(); i++) { ReadableType indexType = readableArray.getType(i); switch (indexType) { case Null: deconstructedList.add(i, null); break; case Boolean: deconstructedList.add(i, readableArray.getBoolean(i)); break; case Number: deconstructedList.add(i, readableArray.getDouble(i)); break; case String: deconstructedList.add(i, readableArray.getString(i)); break; case Map: deconstructedList.add(i, OAuthManagerModule.recursivelyDeconstructReadableMap(readableArray.getMap(i))); break; case Array: deconstructedList.add(i, OAuthManagerModule.recursivelyDeconstructReadableArray(readableArray.getArray(i))); break; default: throw new IllegalArgumentException("Could not convert object at index " + i + "."); } } return deconstructedList; }
Example 9
Source File: SQLitePluginConverter.java From react-native-sqlite-storage with MIT License | 5 votes |
/** * Returns the value at {@code index} if it exists, coercing it if * necessary. */ static String getString(ReadableArray array, int index, String defaultValue) { if (array == null){ return defaultValue; } try { ReadableType type = array.getType(index); switch (type) { case Number: double value = array.getDouble(index); if (value == (long) value) { return String.valueOf((long) value); } else { return String.valueOf(value); } case Boolean: return String.valueOf(array.getBoolean(index)); case String: return array.getString(index); case Null: return null; default: return defaultValue; } } catch(NoSuchKeyException ex){ return defaultValue; } }
Example 10
Source File: ArrayUtil.java From react-native-background-geolocation with Apache License 2.0 | 5 votes |
public static Object[] toArray(ReadableArray readableArray) { Object[] array = new Object[readableArray.size()]; for (int i = 0; i < readableArray.size(); i++) { ReadableType type = readableArray.getType(i); switch (type) { case Null: array[i] = null; break; case Boolean: array[i] = readableArray.getBoolean(i); break; case Number: array[i] = readableArray.getDouble(i); break; case String: array[i] = readableArray.getString(i); break; case Map: array[i] = MapUtil.toMap(readableArray.getMap(i)); break; case Array: array[i] = ArrayUtil.toArray(readableArray.getArray(i)); break; } } return array; }
Example 11
Source File: RealtimeMessagingAndroid.java From RCTRealtimeMessagingAndroid with MIT License | 5 votes |
private List<Object> recursivelyDeconstructReadableArray(ReadableArray readableArray) { List<Object> deconstructedList = new ArrayList<>(readableArray.size()); for (int i = 0; i < readableArray.size(); i++) { ReadableType indexType = readableArray.getType(i); switch(indexType) { case Null: deconstructedList.add(i, null); break; case Boolean: deconstructedList.add(i, readableArray.getBoolean(i)); break; case Number: deconstructedList.add(i, readableArray.getDouble(i)); break; case String: deconstructedList.add(i, readableArray.getString(i)); break; case Map: deconstructedList.add(i, recursivelyDeconstructReadableMap(readableArray.getMap(i))); break; case Array: deconstructedList.add(i, recursivelyDeconstructReadableArray(readableArray.getArray(i))); break; default: throw new IllegalArgumentException("Could not convert object at index " + i + "."); } } return deconstructedList; }
Example 12
Source File: SQLitePluginConverter.java From react-native-sqlite-storage with MIT License | 5 votes |
static Object get(ReadableArray array,int index,Object defaultValue){ if (array == null){ return defaultValue; } try { Object value = null; ReadableType type = array.getType(index); switch(type){ case Boolean: value = array.getBoolean(index); break; case Number: value = array.getDouble(index); break; case String: value = array.getString(index); break; case Map: value = array.getMap(index); break; case Array: value = array.getArray(index); break; case Null: break; } return value; } catch (NoSuchKeyException ex){ return defaultValue; } }
Example 13
Source File: RNDataWedgeIntentsModule.java From react-native-datawedge-intents with MIT License | 5 votes |
private List<Object> recursivelyDeconstructReadableArray(ReadableArray readableArray) { List<Object> deconstructedList = new ArrayList<>(readableArray.size()); for (int i = 0; i < readableArray.size(); i++) { ReadableType indexType = readableArray.getType(i); switch(indexType) { case Null: deconstructedList.add(i, null); break; case Boolean: deconstructedList.add(i, readableArray.getBoolean(i)); break; case Number: deconstructedList.add(i, readableArray.getDouble(i)); break; case String: deconstructedList.add(i, readableArray.getString(i)); break; case Map: deconstructedList.add(i, recursivelyDeconstructReadableMap(readableArray.getMap(i))); break; case Array: deconstructedList.add(i, recursivelyDeconstructReadableArray(readableArray.getArray(i))); break; default: throw new IllegalArgumentException("Could not convert object at index " + i + "."); } } return deconstructedList; }
Example 14
Source File: SegmentAnalyticsModule.java From react-native-segment-analytics with MIT License | 5 votes |
private List<Object> toArray(@Nullable ReadableArray readableArray) { if (readableArray == null) { return null; } List<Object> list = new ArrayList<>(); for (int i = 0; i < readableArray.size(); i++) { switch (readableArray.getType(i)) { case Null: list.add(null); break; case Boolean: list.add(readableArray.getBoolean(i)); break; case Number: list.add(readableArray.getDouble(i)); break; case String: list.add(readableArray.getString(i)); break; case Map: list.add(this.toMap(readableArray.getMap(i))); break; case Array: list.add(this.toArray(readableArray.getArray(i))); break; default: throw new IllegalArgumentException("Could not convert object at index: " + i + "."); } } return list; }
Example 15
Source File: DefaultNavigationImplementation.java From native-navigation with MIT License | 5 votes |
private static boolean arrayEqual( ReadableArray a, ReadableArray b ) { if (b.size() != a.size()) return false; for (int i = 0; i < a.size(); i++) { ReadableType type = a.getType(i); if (type != b.getType(i)) return false; switch (type) { case Null: break; case Boolean: if (b.getBoolean(i) != a.getBoolean(i)) return false; break; case Number: if (b.getDouble(i) != a.getDouble(i)) return false; break; case String: if (!b.getString(i).equals(a.getString(i))) return false; break; case Map: if (!mapEqual(a.getMap(i), b.getMap(i))) return false; break; case Array: if (!arrayEqual(a.getArray(i), b.getArray(i))) return false; break; default: Log.e(TAG, "Could not compare object with index: " + i + "."); } } return true; }
Example 16
Source File: RNMailComposeModule.java From react-native-mail-compose with MIT License | 5 votes |
private void addAttachments(Intent intent, ReadableArray attachments) { if (attachments == null) return; ArrayList<Uri> uris = new ArrayList<>(); for (int i = 0; i < attachments.size(); i++) { if (attachments.getType(i) == ReadableType.Map) { ReadableMap attachment = attachments.getMap(i); if (attachment != null) { byte[] blob = getBlob(attachment, "data"); String text = getString(attachment, "text"); // String mimeType = getString(attachment, "mimeType"); String filename = getString(attachment, "filename"); if (filename == null) { filename = UUID.randomUUID().toString(); } String ext = getString(attachment, "ext"); File tempFile = createTempFile(filename, ext); if (blob != null) { tempFile = writeBlob(tempFile, blob); } else if (text != null) { tempFile = writeText(tempFile, text); } if (tempFile != null) { uris.add(Uri.fromFile(tempFile)); } } } } if (uris.size() > 0) { intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } }
Example 17
Source File: JsonConvert.java From react-native-cordova with MIT License | 5 votes |
public static JSONArray reactToJSON(ReadableArray readableArray) throws JSONException { JSONArray jsonArray = new JSONArray(); for(int i=0; i < readableArray.size(); i++) { ReadableType valueType = readableArray.getType(i); switch (valueType){ case Null: jsonArray.put(JSONObject.NULL); break; case Boolean: jsonArray.put(readableArray.getBoolean(i)); break; case Number: try { jsonArray.put(readableArray.getInt(i)); } catch(Exception e) { jsonArray.put(readableArray.getDouble(i)); } break; case String: jsonArray.put(readableArray.getString(i)); break; case Map: jsonArray.put(reactToJSON(readableArray.getMap(i))); break; case Array: jsonArray.put(reactToJSON(readableArray.getArray(i))); break; } } return jsonArray; }
Example 18
Source File: ConversionUtil.java From react-native-eval with MIT License | 4 votes |
/** * 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. */ 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: 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(toMap(readableArray.getMap(index))); break; case Array: result = toList(readableArray.getArray(index)); break; default: throw new IllegalArgumentException("Could not convert object with index: " + index + "."); } } return result; }
Example 19
Source File: SQLiteManager.java From react-native-android-sqlite with MIT License | 4 votes |
public WritableArray query(final String sql, final ReadableArray values) { WritableArray data = Arguments.createArray(); // FLog.w(ReactConstants.TAG, "values.size()=%s", Integer.toString(values.size())); String[] args = new String[values.size()]; // FLog.w(ReactConstants.TAG, "sqlitemanager.query.args.length=%d", args.length); for ( int i=0; i < values.size(); i++) { if (values.getType(i) == ReadableType.Number) { args[i] = Integer.toString(values.getInt(i)); } else { args[i] = values.getString(i); } } Cursor cursor = db.rawQuery(sql, args); try { if (cursor.moveToFirst()) { do { WritableMap item = Arguments.createMap(); for (int i=0; i < cursor.getColumnCount(); i++) { switch( cursor.getType(i) ) { case Cursor.FIELD_TYPE_INTEGER: item.putInt(cursor.getColumnName(i), cursor.getInt(i)); break; default: item.putString(cursor.getColumnName(i), cursor.getString(i)); break; } } data.pushMap(item); } while (cursor.moveToNext()); } } catch (Exception e) { throw e; } finally { cursor.close(); } return data; }
Example 20
Source File: Utils.java From photo-viewer with Apache License 2.0 | 4 votes |
/** * Converts a ReadableArray into a Java List<> * * @param readableArray the ReadableArray to parse * @return a Java List<> if applicable */ 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: result.add(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: throw new IllegalArgumentException("Could not convert object with index: " + index + "."); } } return result; }