Java Code Examples for com.facebook.react.bridge.ReadableArray
The following examples show how to use
com.facebook.react.bridge.ReadableArray. These examples are extracted from open source projects.
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 Project: react-native-doc-viewer Source File: RNDocViewerModule.java License: MIT License | 6 votes |
@ReactMethod public void openDocBinaryinUrl(ReadableArray args, Callback callback) { final ReadableMap arg_object = args.getMap(0); try { if (arg_object.getString("url") != null && arg_object.getString("fileName") != null && arg_object.getString("fileType") != null) { // parameter parsing final String url = arg_object.getString("url"); final String fileName =arg_object.getString("fileName"); final String fileType =arg_object.getString("fileType"); final Boolean cache =arg_object.getBoolean("cache"); final byte[] bytesData = new byte[0]; // Begin the Download Task new FileDownloaderAsyncTask(callback, url, cache, fileName, fileType, bytesData).execute(); }else{ callback.invoke(false); } } catch (Exception e) { callback.invoke(e.getMessage()); } }
Example 2
Source Project: react-native-arcgis-mapview Source File: RNArcGISMapViewManager.java License: MIT License | 6 votes |
@Override public void receiveCommand(RNAGSMapView mapView, int command, ReadableArray args) { Assertions.assertNotNull(mapView); Assertions.assertNotNull(args); switch (command) { case SHOW_CALLOUT: mapView.showCallout(args.getMap(0));return; case CENTER_MAP: mapView.centerMap(args.getArray(0));return; case ADD_GRAPHICS_OVERLAY: mapView.addGraphicsOverlay(args.getMap(0));return; case REMOVE_GRAPHICS_OVERLAY: mapView.removeGraphicsOverlay(args.getString(0));return; case ADD_POINTS_TO_OVERLAY: mapView.addPointsToOverlay(args.getMap(0));return; case REMOVE_POINTS_FROM_OVERLAY: mapView.removePointsFromOverlay(args.getMap(0));return; case UPDATE_POINTS_IN_GRAPHICS_OVERLAY: mapView.updatePointsInGraphicsOverlay(args.getMap(0));return; case ROUTE_GRAPHICS_OVERLAY: mapView.routeGraphicsOverlay(args.getMap(0));return; case SET_ROUTE_IS_VISIBLE: mapView.setRouteIsVisible(args.getBoolean(0));return; case DISPOSE: mapView.onHostDestroy(); } }
Example 3
Source Project: react-native-ble-manager Source File: BleManager.java License: Apache License 2.0 | 6 votes |
@ReactMethod public void scan(ReadableArray serviceUUIDs, final int scanSeconds, boolean allowDuplicates, ReadableMap options, Callback callback) { Log.d(LOG_TAG, "scan"); if (getBluetoothAdapter() == null) { Log.d(LOG_TAG, "No bluetooth support"); callback.invoke("No bluetooth support"); return; } if (!getBluetoothAdapter().isEnabled()) { return; } synchronized (peripherals) { for (Iterator<Map.Entry<String, Peripheral>> iterator = peripherals.entrySet().iterator(); iterator .hasNext();) { Map.Entry<String, Peripheral> entry = iterator.next(); if (!entry.getValue().isConnected()) { iterator.remove(); } } } if (scanManager != null) scanManager.scan(serviceUUIDs, scanSeconds, options, callback); }
Example 4
Source Project: react-native-jw-media-player Source File: RNJWPlayerViewManager.java License: MIT License | 6 votes |
@Override public void receiveCommand(RNJWPlayerView root, int commandId, @Nullable ReadableArray args) { super.receiveCommand(root, commandId, args); switch (commandId) { case COMMAND_PLAY: play(root); break; case COMMAND_PAUSE: pause(root); break; case COMMAND_STOP: stop(root); break; case COMMAND_TOGGLE_SPEED: toggleSpeed(root); break; default: //do nothing!!!! } }
Example 5
Source Project: react-native-android-sqlite Source File: DBManager.java License: MIT License | 6 votes |
@ReactMethod public void exec(final String sql, final ReadableArray values, final Callback callback) { new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void ...params) { try { mDb.exec(sql, values); } catch(Exception e) { FLog.w(ReactConstants.TAG, "Exception in database exec: ", e); callback.invoke(ErrorUtil.getError(null, e.getMessage()), null); } callback.invoke(); } }.execute(); }
Example 6
Source Project: Instabug-React-Native Source File: RNInstabugBugReportingModule.java License: MIT License | 6 votes |
/** * Sets the enabled report types to be shown in the prompt. Bug or Feedback or both. * @param types * @see BugReporting.ReportType */ @SuppressLint("WrongConstant") @ReactMethod public void setReportTypes(ReadableArray types) { Object[] objectArray = ArrayUtil.toArray(types); String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class); final int[] parsedReportTypes = new int[stringArray.length]; for (int i = 0; i < stringArray.length; i++) { parsedReportTypes[i] = (int) ArgsRegistry.getRawValue(stringArray[i]); } MainThreadHandler.runOnMainThread(new Runnable() { @Override public void run() { try { BugReporting.setReportTypes(parsedReportTypes); } catch (Exception e) { e.printStackTrace(); } } }); }
Example 7
Source Project: react-native-GPay Source File: BaseViewManager.java License: MIT License | 6 votes |
@ReactProp(name = PROP_ACCESSIBILITY_STATES) public void setViewStates(T view, ReadableArray accessibilityStates) { view.setSelected(false); view.setEnabled(true); if (accessibilityStates == null) { return; } for (int i = 0; i < accessibilityStates.size(); i++) { String state = accessibilityStates.getString(i); if (state.equals("selected")) { view.setSelected(true); } else if (state.equals("disabled")) { view.setEnabled(false); } } }
Example 8
Source Project: Instabug-React-Native Source File: RNInstabugBugReportingModule.java License: MIT License | 6 votes |
/** * Sets the options for the features in the SDK * * @param optionValues the invocation option value */ @ReactMethod public void setOptions(final ReadableArray optionValues) { MainThreadHandler.runOnMainThread(new Runnable() { @Override public void run() { try { Object[] objectArray = ArrayUtil.toArray(optionValues); String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class); for (String option : stringArray) { BugReporting.setOptions((int) ArgsRegistry.getRawValue(option)); } } catch (Exception e) { e.printStackTrace(); } } }); }
Example 9
Source Project: react-native-GPay Source File: ReactToolbar.java License: MIT License | 6 votes |
void setActions(@Nullable ReadableArray actions) { Menu menu = getMenu(); menu.clear(); mActionsHolder.clear(); if (actions != null) { for (int i = 0; i < actions.size(); i++) { ReadableMap action = actions.getMap(i); MenuItem item = menu.add(Menu.NONE, Menu.NONE, i, action.getString(PROP_ACTION_TITLE)); if (action.hasKey(PROP_ACTION_ICON)) { setMenuItemIcon(item, action.getMap(PROP_ACTION_ICON)); } int showAsAction = action.hasKey(PROP_ACTION_SHOW) ? action.getInt(PROP_ACTION_SHOW) : MenuItem.SHOW_AS_ACTION_NEVER; if (action.hasKey(PROP_ACTION_SHOW_WITH_TEXT) && action.getBoolean(PROP_ACTION_SHOW_WITH_TEXT)) { showAsAction = showAsAction | MenuItem.SHOW_AS_ACTION_WITH_TEXT; } item.setShowAsAction(showAsAction); } } }
Example 10
Source Project: react-native-kakao-links Source File: RNKakaoLinkModule.java License: MIT License | 6 votes |
private LocationTemplate createLocationTemplate(ReadableMap options) { LocationTemplate.Builder locationTemplate = LocationTemplate.newBuilder( options.getString("address"), createContentObject(options.getMap("content")) ); String addressTitle = options.getString("addressTitle"); if (addressTitle != null) { locationTemplate.setAddressTitle(addressTitle); } ReadableMap social = options.getMap("social"); if (social != null) { locationTemplate.setSocial(createSocialObject(social)); } ReadableArray buttons = options.getArray("buttons"); if (buttons != null) { for (int i = 0; i < buttons.size(); i++) { locationTemplate.addButton(createButtonObject(buttons.getMap(i))); } } return locationTemplate.build(); }
Example 11
Source Project: react-native-square-reader-sdk Source File: CheckoutModule.java License: Apache License 2.0 | 6 votes |
static private Set<AdditionalPaymentType> buildAdditionalPaymentTypes(ReadableArray additionalPaymentTypes) { Set<AdditionalPaymentType> types = new LinkedHashSet<>(); if (additionalPaymentTypes != null) { for (int i = 0; i < additionalPaymentTypes.size(); i++) { String typeName = additionalPaymentTypes.getString(i); switch (typeName) { case "cash": types.add(AdditionalPaymentType.CASH); break; case "manual_card_entry": types.add(AdditionalPaymentType.MANUAL_CARD_ENTRY); break; case "other": types.add(AdditionalPaymentType.OTHER); break; default: throw new RuntimeException("Unexpected payment type: " + typeName); } } } return types; }
Example 12
Source Project: react-native-GPay Source File: CatalystNativeJSToJavaParametersTestCase.java License: MIT License | 6 votes |
public void testIntOutOfRangeThrown() { mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnArrayWithLargeInts(); mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithLargeInts(); waitForBridgeAndUIIdle(); assertEquals(1, mRecordingTestModule.getArrayCalls().size()); assertEquals(1, mRecordingTestModule.getMapCalls().size()); ReadableArray array = mRecordingTestModule.getArrayCalls().get(0); assertNotNull(array); ReadableMap map = mRecordingTestModule.getMapCalls().get(0); assertNotNull(map); assertEquals(ReadableType.Number, array.getType(0)); assertUnexpectedTypeExceptionThrown(array, 0, "int"); assertEquals(ReadableType.Number, array.getType(1)); assertUnexpectedTypeExceptionThrown(array, 1, "int"); assertEquals(ReadableType.Number, map.getType("first")); assertUnexpectedTypeExceptionThrown(map, "first", "int"); assertEquals(ReadableType.Number, map.getType("second")); assertUnexpectedTypeExceptionThrown(map, "second", "int"); }
Example 13
Source Project: Instabug-React-Native Source File: RNInstabugReactnativeModule.java License: MIT License | 6 votes |
@ReactMethod public void hideView(final ReadableArray ids) { MainThreadHandler.runOnMainThread(new Runnable() { @Override public void run() { UIManagerModule uiManagerModule = getReactApplicationContext().getNativeModule(UIManagerModule.class); uiManagerModule.prependUIBlock(new UIBlock() { @Override public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) { final View[] arrayOfViews = new View[ids.size()]; for (int i = 0; i < ids.size(); i++) { int viewId = (int) ids.getDouble(i); try { arrayOfViews[i] = nativeViewHierarchyManager.resolveView(viewId); } catch(Exception e) { e.printStackTrace(); } } Instabug.setViewsAsPrivate(arrayOfViews); } }); } }); }
Example 14
Source Project: react-native-sketch-view Source File: RNSketchViewManager.java License: MIT License | 6 votes |
@Override public void receiveCommand(SketchViewContainer root, int commandId, @Nullable ReadableArray args) { Assertions.assertNotNull(root); switch (commandId) { case COMMAND_CLEAR_SKETCH: root.sketchView.clear(); return; case COMMAND_CHANGE_TOOL: Assertions.assertNotNull(args); int toolId = args.getInt(0); root.sketchView.setToolType(toolId); return; case COMMAND_SAVE_SKETCH: try { SketchFile sketchFile = root.saveToLocalCache(); onSaveSketch(root, sketchFile); return; } catch (IOException e) { e.printStackTrace(); } default: throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Unsupported command %d.", commandId)); } }
Example 15
Source Project: react-native-firestack Source File: FirestackDatabase.java License: MIT License | 6 votes |
@ReactMethod public void on(final String path, final ReadableArray modifiers, final String name, final Callback callback) { FirestackDBReference ref = this.getDBHandle(path); WritableMap resp = Arguments.createMap(); if (name.equals("value")) { ref.addValueEventListener(name, modifiers); } else { ref.addChildEventListener(name, modifiers); } this.saveDBHandle(path, ref); resp.putString("result", "success"); Log.d(TAG, "Added listener " + name + " for " + ref); resp.putString("handle", path); callback.invoke(null, resp); }
Example 16
Source Project: react-native-GPay Source File: NetworkRecordingModuleMock.java License: MIT License | 6 votes |
@ReactMethod public final void sendRequest( String method, String url, int requestId, ReadableArray headers, ReadableMap data, final String responseType, boolean incrementalUpdates, int timeout, boolean withCredentials) { mLastRequestId = requestId; mRequestCount++; mRequestMethod = method; mRequestURL = url; mRequestHeaders = headers; mRequestData = data; if (mRequestListener != null) { mRequestListener.onRequest(method, url, headers, data); } if (mCompleteRequest) { onResponseReceived(requestId, mResponseCode, null); onDataReceived(requestId, mResponseBody); onRequestComplete(requestId, null); } }
Example 17
Source Project: photo-viewer Source File: Utils.java License: Apache License 2.0 | 6 votes |
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(readableMapToJson(readableArray.getMap(i))); break; case Array: array.put(convertArrayToJson(readableArray.getArray(i))); break; } } return array; }
Example 18
Source Project: react-native-batch-push Source File: RNUtils.java License: MIT License | 5 votes |
@Nullable public static BatchEventData convertSerializedEventDataToEventData(@Nullable ReadableMap serializedEventData) { if (serializedEventData == null) { return null; } BatchEventData batchEventData = new BatchEventData(); ReadableArray tags = serializedEventData.getArray("tags"); for (int i = 0; i < tags.size(); i++) { batchEventData.addTag(tags.getString(i)); } ReadableMap attributes = serializedEventData.getMap("attributes"); ReadableMapKeySetIterator iterator = attributes.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableMap valueMap = attributes.getMap(key); String type = valueMap.getString("type"); if ("string".equals(type)) { batchEventData.put(key, valueMap.getString("value")); } else if ("boolean".equals(type)) { batchEventData.put(key, valueMap.getBoolean("value")); } else if ("integer".equals(type)) { batchEventData.put(key, valueMap.getDouble("value")); } else if ("float".equals(type)) { batchEventData.put(key, valueMap.getDouble("value")); } else { Log.e("RNBatchPush", "Invalid parameter : Unknown event_data.attributes type (" + type + ")"); } } return batchEventData; }
Example 19
Source Project: react-native-node Source File: RNNodeModule.java License: MIT License | 5 votes |
@ReactMethod public void start(ReadableArray args) { Log.d(TAG, "Launching an intent for RNNodeService..."); Intent intent = new Intent(_reactContext, RNNodeService.class); intent.putExtra("args", this.toStringArrayList(args)); _reactContext.startService(intent); }
Example 20
Source Project: react-native-tensorflow Source File: ArrayConverter.java License: Apache License 2.0 | 5 votes |
public static ReadableArray doubleArrayToReadableArray(double[] arr) { WritableArray writableArray = new WritableNativeArray(); for (double d : arr) { writableArray.pushDouble(d); } return writableArray; }
Example 21
Source Project: native-navigation Source File: DefaultNavigationImplementation.java License: 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 22
Source Project: react-native-scratch Source File: RNTScratchViewManager.java License: MIT License | 5 votes |
@Override public void receiveCommand(ScratchView view, int commandId, @javax.annotation.Nullable ReadableArray args) { super.receiveCommand(view, commandId, args); if (commandId == 0) { view.reset(); } }
Example 23
Source Project: art Source File: PropHelper.java License: MIT License | 5 votes |
/** * Converts {@link ReadableArray} to an array of {@code float}. Returns newly created array. * * @return a {@code float[]} if converted successfully, or {@code null} if {@param value} was * {@code null}. */ /*package*/ static @Nullable float[] toFloatArray(@Nullable ReadableArray value) { if (value != null) { float[] result = new float[value.size()]; toFloatArray(value, result); return result; } return null; }
Example 24
Source Project: react-native-sqlite-storage Source File: SQLitePluginConverter.java License: 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 25
Source Project: art Source File: ARTVirtualNode.java License: MIT License | 5 votes |
@ReactProp(name = "transform") public void setTransform(@Nullable ReadableArray transformArray) { if (transformArray != null) { int matrixSize = PropHelper.toFloatArray(transformArray, sMatrixData); if (matrixSize == 6) { setupMatrix(); } else if (matrixSize != -1) { throw new JSApplicationIllegalArgumentException("Transform matrices must be of size 6"); } } else { mMatrix = null; } markUpdated(); }
Example 26
Source Project: react-native-mp-android-chart Source File: BridgeUtils.java License: MIT License | 5 votes |
public static float[] convertToFloatArray(ReadableArray readableArray) { float[] array = new float[readableArray.size()]; for (int i = 0; i < readableArray.size(); i++) { if (!ReadableType.Number.equals(readableArray.getType(i))) { throw new IllegalArgumentException("Expecting array of numbers"); } array[i] = (float) readableArray.getDouble(i); } return array; }
Example 27
Source Project: react-native-GPay Source File: UIManagerModule.java License: MIT License | 5 votes |
@ReactMethod public void dispatchViewManagerCommand(int reactTag, int commandId, @Nullable ReadableArray commandArgs) { //TODO: this is a temporary approach to support ViewManagerCommands in Fabric until // the dispatchViewManagerCommand() method is supported by Fabric JS API. UIManagerHelper.getUIManager(getReactApplicationContext(), ViewUtil.getUIManagerType(reactTag)) .dispatchCommand(reactTag, commandId, commandArgs); }
Example 28
Source Project: react-native-smart-barcode Source File: RCTCaptureManager.java License: MIT License | 5 votes |
@Override public void receiveCommand(CaptureView root, int commandId, @Nullable ReadableArray config) { // super.receiveCommand(root, commandId, config); if (commandId == CHANGE_SHOW) { this.changeWidthHeight(config.getMap(0)); } }
Example 29
Source Project: react-native-GPay Source File: ViewManagersPropertyCache.java License: MIT License | 5 votes |
private static PropSetter createPropSetter( ReactProp annotation, Method method, Class<?> propTypeClass) { if (propTypeClass == Dynamic.class) { return new DynamicPropSetter(annotation, method); } else if (propTypeClass == boolean.class) { return new BooleanPropSetter(annotation, method, annotation.defaultBoolean()); } else if (propTypeClass == int.class) { return new IntPropSetter(annotation, method, annotation.defaultInt()); } else if (propTypeClass == float.class) { return new FloatPropSetter(annotation, method, annotation.defaultFloat()); } else if (propTypeClass == double.class) { return new DoublePropSetter(annotation, method, annotation.defaultDouble()); } else if (propTypeClass == String.class) { return new StringPropSetter(annotation, method); } else if (propTypeClass == Boolean.class) { return new BoxedBooleanPropSetter(annotation, method); } else if (propTypeClass == Integer.class) { return new BoxedIntPropSetter(annotation, method); } else if (propTypeClass == ReadableArray.class) { return new ArrayPropSetter(annotation, method); } else if (propTypeClass == ReadableMap.class) { return new MapPropSetter(annotation, method); } else { throw new RuntimeException("Unrecognized type: " + propTypeClass + " for method: " + method.getDeclaringClass().getName() + "#" + method.getName()); } }
Example 30
Source Project: react-native-baidu-map Source File: LatLngUtil.java License: MIT License | 5 votes |
public static List<LatLng> fromReadableArray(ReadableArray readableArray) { List<LatLng> list = new ArrayList<>(); int size = readableArray.size(); for (int i = 0; i < size; i++) { list.add(fromReadableMap(readableArray.getMap(i))); } return list; }