Java Code Examples for com.facebook.react.bridge.ReadableArray#getDouble()
The following examples show how to use
com.facebook.react.bridge.ReadableArray#getDouble() .
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: ARTVirtualNode.java From art with MIT License | 6 votes |
@ReactProp(name = "shadow") public void setShadow(@Nullable ReadableArray shadowArray) { if (shadowArray != null) { mShadowOpacity = (float)shadowArray.getDouble(1); mShadowRadius = (float)shadowArray.getDouble(2); mShadowOffsetX = (float)shadowArray.getDouble(3); mShadowOffsetY = (float)shadowArray.getDouble(4); int color = shadowArray.getInt(0); if (mShadowOpacity < 1) { color = ColorUtils.setAlphaComponent(color, (int)(mShadowOpacity * 255)); } mShadowColor = color; } else { mShadowColor = 0; mShadowOpacity = 0; mShadowRadius = 0; mShadowOffsetX = 0; mShadowOffsetY = 0; } markUpdated(); }
Example 2
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 3
Source File: FrameBasedAnimationDriver.java From react-native-GPay with MIT License | 6 votes |
@Override public void resetConfig(ReadableMap config) { ReadableArray frames = config.getArray("frames"); int numberOfFrames = frames.size(); if (mFrames == null || mFrames.length != numberOfFrames) { mFrames = new double[numberOfFrames]; } for (int i = 0; i < numberOfFrames; i++) { mFrames[i] = frames.getDouble(i); } mToValue = config.hasKey("toValue") ? config.getDouble("toValue") : 0; mIterations = config.hasKey("iterations") ? config.getInt("iterations") : 1; mCurrentLoop = 1; mHasFinished = mIterations == 0; mStartFrameTimeNanos = -1; }
Example 4
Source File: BaiduMapViewManager.java From BaiduMapKit with MIT License | 6 votes |
/** * 显示地理标记 * * @param mapView * @param array */ @ReactProp(name="marker") public void setMarker(MapView mapView, ReadableArray array) { Log.d(TAG, "marker:" + array); if (array != null) { for (int i = 0; i < array.size(); i++) { ReadableArray sub = array.getArray(i); //定义Maker坐标点 LatLng point = new LatLng(sub.getDouble(0), sub.getDouble(1)); //构建Marker图标 BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding); //构建MarkerOption,用于在地图上添加Marker OverlayOptions option = new MarkerOptions() .position(point) .icon(bitmap) .draggable(true); //在地图上添加Marker,并显示 mapView.getMap().addOverlay(option); } } }
Example 5
Source File: DirectedScrollViewManager.java From react-native-directed-scrollview with MIT License | 6 votes |
@Override public void receiveCommand(DirectedScrollView view, int commandType, @Nullable ReadableArray args) { super.receiveCommand(view, commandType, args); switch (commandType) { case COMMAND_SCROLL_TO: Double translateX = args.getDouble(0); Double translateY = args.getDouble(1); Boolean animated = args.getBoolean(2); view.scrollTo(translateX, translateY, animated); break; case COMMAND_ZOOM_TO_START: view.scrollTo(0.0, 0.0, args.getBoolean(0)); break; default: throw new IllegalArgumentException(String.format("Unsupported command %d received by %s.", commandType, getClass().getSimpleName())); } }
Example 6
Source File: RNShadowTextGradient.java From react-native-text-gradient with MIT License | 6 votes |
@SuppressWarnings("unused") @ReactProp(name = "locations") public void setLocations(ReadableArray locations) { if (locations != null) { float[] _locations = new float[locations.size()]; for (int i = 0; i < _locations.length; i++) { _locations[i] = (float) locations.getDouble(i); } mLocations = _locations; } else { mLocations = null; } markUpdated(); }
Example 7
Source File: OptionsHelper.java From react-native-lock with MIT License | 5 votes |
public static ArrayList convertReadableArrayToArray(ReadableArray reactArray) { ArrayList<Object> array = new ArrayList<>(); for (int i=0, size = reactArray.size(); i<size; ++i) { Object object = null; switch (reactArray.getType(i)) { case Array: object = convertReadableArrayToArray(reactArray.getArray(i)); break; case Boolean: object = reactArray.getBoolean(i); break; case Map: object = convertReadableMapToMap(reactArray.getMap(i)); break; case Null: object = null; break; case Number: try { object = reactArray.getDouble(i); } catch (java.lang.ClassCastException e) { object = reactArray.getInt(i); } break; case String: object = reactArray.getString(i); break; default: Log.e(TAG, "Unknown type: " + reactArray.getType(i) + " for index: " + i); } array.add(object); } return array; }
Example 8
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 9
Source File: ArrayUtil.java From vinci 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 10
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 11
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 12
Source File: ArrayUtil.java From Instabug-React-Native with MIT License | 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 13
Source File: Utils.java From react-native-update with MIT License | 5 votes |
public static JSONArray convertReadableToJsonArray(ReadableArray arr) { JSONArray jsonArr = new JSONArray(); for (int i=0; i<arr.size(); i++) { ReadableType type = arr.getType(i); switch (type) { case Map: jsonArr.put(convertReadableToJsonObject(arr.getMap(i))); break; case Array: jsonArr.put(convertReadableToJsonArray(arr.getArray(i))); break; case String: jsonArr.put(arr.getString(i)); break; case Number: Double number = arr.getDouble(i); if ((number == Math.floor(number)) && !Double.isInfinite(number)) { // This is a whole number. jsonArr.put(number.longValue()); } else { try { jsonArr.put(number.doubleValue()); } catch (JSONException jsonException) { throw new RuntimeException("Unable to put value " + arr.getDouble(i) + " in JSONArray"); } } break; case Boolean: jsonArr.put(arr.getBoolean(i)); break; case Null: jsonArr.put(null); break; } } return jsonArr; }
Example 14
Source File: InterpolationAnimatedNode.java From react-native-GPay with MIT License | 5 votes |
private static double[] fromDoubleArray(ReadableArray ary) { double[] res = new double[ary.size()]; for (int i = 0; i < res.length; i++) { res[i] = ary.getDouble(i); } return res; }
Example 15
Source File: SQLitePlugin.java From react-native-sqlite-storage with MIT License | 4 votes |
/** * Get rows results from query cursor. * * @return results in string form */ private WritableMap executeSqlStatementNDK(String query, ReadableArray queryArgs, CallbackContext cbc) throws Exception { WritableMap rowsResult = Arguments.createMap(); boolean hasRows; SQLiteStatement myStatement = null; try { try { myStatement = mydb.prepareStatement(query); if (queryArgs != null) { for (int i = 0; i < queryArgs.size(); ++i) { ReadableType type = queryArgs.getType(i); if (type == ReadableType.Number){ double tmp = queryArgs.getDouble(i); if (tmp == (long) tmp) { myStatement.bindLong(i + 1, (long) tmp); } else { myStatement.bindDouble(i + 1, tmp); } } else if (queryArgs.isNull(i)) { myStatement.bindNull(i + 1); } else { myStatement.bindTextNativeString(i + 1, SQLitePluginConverter.getString(queryArgs,i,"")); } } } hasRows = myStatement.step(); } catch (Exception ex) { FLog.e(TAG, "SQLitePlugin.executeSql[Batch]() failed", ex); throw ex; } // If query result has rows if (hasRows) { WritableArray rowsArrayResult = Arguments.createArray(); String key; int colCount = myStatement.getColumnCount(); // Build up JSON result object for each row do { WritableMap row = Arguments.createMap(); for (int i = 0; i < colCount; ++i) { key = myStatement.getColumnName(i); switch (myStatement.getColumnType(i)) { case SQLColumnType.NULL: row.putNull(key); break; case SQLColumnType.REAL: row.putDouble(key, myStatement.getColumnDouble(i)); break; case SQLColumnType.INTEGER: row.putDouble(key, myStatement.getColumnLong(i)); break; case SQLColumnType.BLOB: case SQLColumnType.TEXT: default: row.putString(key, myStatement.getColumnTextNativeString(i)); } } rowsArrayResult.pushMap(row); } while (myStatement.step()); rowsResult.putArray("rows", rowsArrayResult); } } finally { if (myStatement != null) { myStatement.dispose(); } } return rowsResult; }
Example 16
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; }
Example 17
Source File: ReactUtil.java From react-native-android-fragment with Apache License 2.0 | 4 votes |
/** * toList converts a {@link ReadableArray} into an ArrayList. * * @param readableArray The ReadableArray to be converted. * @return An ArrayList containing the data that was in the ReadableArray. */ public static List<Object> toList(@Nullable ReadableArray readableArray) { if (readableArray == null) { return new ArrayList<>(0); } 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 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: ChartBaseManager.java From react-native-mp-android-chart with MIT License | 4 votes |
U createEntry(ReadableArray yValues, int index) { return (U) new Entry((float) yValues.getDouble(index), index); }
Example 20
Source File: PropHelper.java From react-native-GPay with MIT License | 3 votes |
/** * Converts given {@link ReadableArray} to an array of {@code float}. Writes result to the array * passed in {@param into}. This method will write to the output array up to the number of items * from the input array. If the input array is longer than output the remaining part of the input * will not be converted. * * @param value input array * @param into output array * @return number of items copied from input to the output array */ /*package*/ static int toFloatArray(ReadableArray value, float[] into) { int length = value.size() > into.length ? into.length : value.size(); for (int i = 0; i < length; i++) { into[i] = (float) value.getDouble(i); } return value.size(); }