Java Code Examples for com.facebook.react.bridge.ReadableArray#getMap()

The following examples show how to use com.facebook.react.bridge.ReadableArray#getMap() . 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: BubbleChartManager.java    From react-native-mp-android-chart with MIT License 6 votes vote down vote up
@Override
BubbleEntry createEntry(ReadableArray yValues, int index) {
    if (!ReadableType.Map.equals(yValues.getType(index))) {
        throw new IllegalArgumentException("Invalid BubbleEntry data");
    }

    ReadableMap entry = yValues.getMap(index);
    if(!BridgeUtils.validate(entry, ReadableType.Number, "value") ||
            !BridgeUtils.validate(entry, ReadableType.Number, "size")) {
        throw new IllegalArgumentException("Invalid BubbleEntry data");
    }

    float value = (float) entry.getDouble("value");
    float size = (float) entry.getDouble("size");

    return new BubbleEntry(index, value, size);
}
 
Example 2
Source File: RNDocViewerModule.java    From react-native-doc-viewer with MIT License 6 votes vote down vote up
@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 3
Source File: RNDocViewerModule.java    From react-native-doc-viewer with MIT License 6 votes vote down vote up
@ReactMethod
public void openDocb64(ReadableArray args, Callback callback) {
    final ReadableMap arg_object = args.getMap(0);
    try {
      if (arg_object.getString("base64") != null && arg_object.getString("fileName") != null && arg_object.getString("fileType") != null) {
          // parameter parsing
          final String base64 = arg_object.getString("base64");
          final String fileName =arg_object.getString("fileName");
          final String fileType =arg_object.getString("fileType");
          final Boolean cache = arg_object.getBoolean("cache");
          //Bytes
          final byte[] bytesData = android.util.Base64.decode(base64,android.util.Base64.DEFAULT);
          System.out.println("BytesData" + bytesData);
          // Begin the Download Task
          new FileDownloaderAsyncTask(callback, "", cache, fileName, fileType, bytesData).execute();
      }else{
          callback.invoke(false);
      }
     } catch (Exception e) {
          callback.invoke(e.getMessage());
     }


}
 
Example 4
Source File: RNDocViewerModule.java    From react-native-doc-viewer with MIT License 6 votes vote down vote up
@ReactMethod
public void openDoc(ReadableArray args, Callback callback) {
    final ReadableMap arg_object = args.getMap(0);
    try {
      if (arg_object.getString("url") != null && arg_object.getString("fileName") != 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 5
Source File: HydrationHistory.java    From react-native-google-fit with MIT License 6 votes vote down vote up
public boolean save(ReadableArray hydrationArray) {
  DataSource hydrationSource = this.getDataSource();
  ArrayList<DataPoint> dataPoints = new ArrayList<DataPoint>();
  ArrayList<DataSet> dataSets = new ArrayList<DataSet>();
  for (int index = 0 ; index < hydrationArray.size() ; index++) {
    ReadableMap hydrationSample = hydrationArray.getMap(index);
    if (hydrationSample != null) {
      dataPoints.add(DataPoint.builder(hydrationSource)
        .setTimestamp((long) hydrationSample.getDouble("date"), TimeUnit.MILLISECONDS)
        .setField(Field.FIELD_VOLUME, (float) hydrationSample.getDouble("waterConsumed"))
        .build());
    }
    if (dataPoints.size() % MAX_DATAPOINTS_PER_SINGLE_REQUEST == 0) {
      // Be sure to limit each individual request to 1000 datapoints. Exceeding this limit could result in an error.
      // https://developers.google.com/fit/android/history#insert_data
      dataSets.add(DataSet.builder(hydrationSource).addAll(dataPoints).build());
      dataPoints.clear();
    }
  }
  if (dataPoints.size() > 0) {
    dataSets.add(DataSet.builder(hydrationSource).addAll(dataPoints).build());
  }
  new SaveDataHelper(dataSets, googleFitManager).execute();

  return true;
}
 
Example 6
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testArrayWithMaps() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnArrayWithMaps();
  waitForBridgeAndUIIdle();

  List<ReadableArray> calls = mRecordingTestModule.getArrayCalls();
  assertEquals(1, calls.size());
  ReadableArray array = calls.get(0);
  assertEquals(2, array.size());

  assertFalse(array.isNull(0));
  ReadableMap m1 = array.getMap(0);
  ReadableMap m2 = array.getMap(1);

  assertEquals("m1v1", m1.getString("m1k1"));
  assertEquals("m1v2", m1.getString("m1k2"));
  assertEquals("m2v1", m2.getString("m2k1"));
}
 
Example 7
Source File: UserProfileBridgeTest.java    From react-native-lock with MIT License 6 votes vote down vote up
@Test
public void shouldBridgeIdentity() throws Exception {
    final UserProfile profile = withIdentities(INFO_AUTH0_COM, "facebook");
    final ReadableMap map = bridge(profile);

    assertThat(map.getString(EMAIL), equalTo(profile.getEmail()));

    final ReadableArray identities = map.getArray("identities");
    assertThat(identities.size(), is(1));

    final ReadableMap identityMap = identities.getMap(0);
    final UserIdentity identity = profile.getIdentities().get(0);
    assertThat(identityMap.getString("provider"), equalTo(identity.getProvider()));
    assertThat(identityMap.getString("connection"), equalTo(identity.getConnection()));
    assertThat(identityMap.getString("userId"), equalTo(identity.getId()));
    assertThat(identityMap.getBoolean("social"), equalTo(identity.isSocial()));
    assertThat(identityMap.getMap("profileData"), is(notNullValue()));
}
 
Example 8
Source File: StackTraceHelper.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Convert a JavaScript stack trace (see {@code parseErrorStack} JS module) to an array of
 * {@link StackFrame}s.
 */
public static StackFrame[] convertJsStackTrace(@Nullable ReadableArray stack) {
  int size = stack != null ? stack.size() : 0;
  StackFrame[] result = new StackFrame[size];
  for (int i = 0; i < size; i++) {
    ReadableType type = stack.getType(i);
    if (type == ReadableType.Map) {
      ReadableMap frame = stack.getMap(i);
      String methodName = frame.getString("methodName");
      String fileName = frame.getString("file");
      int lineNumber = -1;
      if (frame.hasKey(LINE_NUMBER_KEY) && !frame.isNull(LINE_NUMBER_KEY)) {
        lineNumber = frame.getInt(LINE_NUMBER_KEY);
      }
      int columnNumber = -1;
      if (frame.hasKey(COLUMN_KEY) && !frame.isNull(COLUMN_KEY)) {
        columnNumber = frame.getInt(COLUMN_KEY);
      }
      result[i] = new StackFrameImpl(fileName, methodName, lineNumber, columnNumber);
    } else if (type == ReadableType.String) {
      result[i] = new StackFrameImpl(null, stack.getString(i), -1, -1);
    }
  }
  return result;
}
 
Example 9
Source File: CandleStickChartManager.java    From react-native-mp-android-chart with MIT License 6 votes vote down vote up
@Override
CandleEntry createEntry(ReadableArray yValues, int index) {
    if (!ReadableType.Map.equals(yValues.getType(index))) {
        throw new IllegalArgumentException();
    }

    ReadableMap entryData = yValues.getMap(index);
    if (!BridgeUtils.validate(entryData, ReadableType.Number, "shadowH") ||
            !BridgeUtils.validate(entryData, ReadableType.Number, "shadowL") ||
            !BridgeUtils.validate(entryData, ReadableType.Number, "open") ||
            !BridgeUtils.validate(entryData, ReadableType.Number, "close")) {
        throw new IllegalArgumentException("CandleStick data must contain: shadowH, shadowL, open and close values");
    }

    float shadowH = (float) entryData.getDouble("shadowH");
    float shadowL = (float) entryData.getDouble("shadowL");
    float open = (float) entryData.getDouble("open");
    float close = (float) entryData.getDouble("close");

    return new CandleEntry(index, shadowH, shadowL, open, close);
}
 
Example 10
Source File: RNAGSGraphicsOverlay.java    From react-native-arcgis-mapview with MIT License 6 votes vote down vote up
public RNAGSGraphicsOverlay(ReadableMap rawData, GraphicsOverlay graphicsOverlay) {
    this.referenceId = rawData.getString("referenceId");
    ReadableArray pointImageDictionaryRaw = rawData.getArray("pointGraphics");
    pointImageDictionary = new HashMap<>();
    this.graphicsOverlay = graphicsOverlay;

    for (int i = 0; i < pointImageDictionaryRaw.size(); i++) {
        ReadableMap item = pointImageDictionaryRaw.getMap(i);
        if (item.hasKey("graphicId")) {
            String graphicId = item.getString("graphicId");
            String uri = item.getMap("graphic").getString("uri");
            pointImageDictionary.put(graphicId, uri);
        }
    }
    // Create graphics within overlay
    ReadableArray rawPoints = rawData.getArray("points");
    for (int i = 0; i < rawPoints.size(); i++) {
        addGraphicsLoop(rawPoints.getMap(i));

    }
}
 
Example 11
Source File: ReactListViewManager.java    From react-native-recycler-listview with MIT License 5 votes vote down vote up
private void prepareMovieData(ReadableMap map){

        ReadableArray obj = map.getArray("names");
        for(int i = 0; i <obj.size() ; i++){
            ReadableMap objMap = obj.getMap(i);
            ListViewCell cell = new ListViewCell(objMap.getString("title"),objMap.getString("subtitle"));
            list.add(cell);
        }


        mAdapter.notifyDataSetChanged();
    }
 
Example 12
Source File: ChartBaseManager.java    From react-native-mp-android-chart with MIT License 5 votes vote down vote up
/**
 *
 * Dataset config details: https://github.com/PhilJay/MPAndroidChart/wiki/DataSet-classes-in-detail
 */
@ReactProp(name = "data")
public void setData(Chart chart, ReadableMap propMap) {
    if (!BridgeUtils.validate(propMap, ReadableType.Array, "datasets")) {
        return;
    }

    String[] xValues = new String[0];
    if (BridgeUtils.validate(propMap, ReadableType.Array, "xValues")) {
        xValues = BridgeUtils.convertToStringArray(propMap.getArray("xValues"));
    }

    ChartData<IDataSet<U>> chartData = createData(xValues);

    ReadableArray datasets = propMap.getArray("datasets");
    for (int i = 0; i < datasets.size(); i++) {
        ReadableMap dataset = datasets.getMap(i);

        // TODO validation
        ReadableArray yValues = dataset.getArray("yValues");
        String label = dataset.getString("label");

        ArrayList<U> entries = createEntries(yValues);

        IDataSet<U> lineDataSet = createDataSet(entries, label);

        if (BridgeUtils.validate(dataset, ReadableType.Map, "config")) {
            dataSetConfig(lineDataSet, dataset.getMap("config"));
        }

        chartData.addDataSet(lineDataSet);
    }

    chart.setData(chartData);
    chart.invalidate();
}
 
Example 13
Source File: ReactPickerManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactProp(name = "items")
public void setItems(ReactPicker view, @Nullable ReadableArray items) {
  if (items != null) {
    ReadableMap[] data = new ReadableMap[items.size()];
    for (int i = 0; i < items.size(); i++) {
      data[i] = items.getMap(i);
    }
    ReactPickerAdapter adapter = new ReactPickerAdapter(view.getContext(), data);
    adapter.setPrimaryTextColor(view.getPrimaryColor());
    view.setAdapter(adapter);
  } else {
    view.setAdapter(null);
  }
}
 
Example 14
Source File: MidtransModule.java    From react-native-payment-gateway with MIT License 5 votes vote down vote up
/**
 * required for Mandiri Bill and BCA klikPay, Optional for other payment
 * @param itemDetails ReadableArray, holds information about item purchased by user TransactionRequest takes an array list of item details
 * @param transactionRequest object to request payment
 */
private void setItemDetail(ReadableArray itemDetails, TransactionRequest transactionRequest){
    ArrayList<ItemDetails> itemDetailsList = new ArrayList<>();
    for(int a=0; a < itemDetails.size(); a++){
        ReadableMap rmItem = itemDetails.getMap(a);
        String id = rmItem.getString("id");
        int price = rmItem.getInt("price");
        int qty = rmItem.getInt("qty");
        String name = rmItem.getString("name");
        itemDetailsList.add(new ItemDetails(id, price, qty, name));
    }
    transactionRequest.setItemDetails(itemDetailsList);
}
 
Example 15
Source File: ArcGISMapManager.java    From react-native-arcgis-sdk-demo with Apache License 2.0 5 votes vote down vote up
@ReactProp(name = "layers")
public void setLayers(MapView view, @Nullable ReadableArray layers) {
    Log.v(REACT_CLASS, "set layers");

    if (layers == null || layers.size() < 1) {
        Log.v(REACT_CLASS, "set layers: adding default layer");
        mapView.addLayer(new ArcGISTiledMapServiceLayer(DEFAULT_LAYER));
    } else {
        mapView.removeAll();
        for (int i = 0; i < layers.size(); i++) {
            ReadableMap layer = layers.getMap(i);
            String type = layer.getString("type");
            String url = layer.getString("url");

            if (!url.equals("")) {
                if (type.equals("ArcGISTiledMapServiceLayer")) {
                    Log.v(REACT_CLASS, "set layers: adding ArcGISTiledMapServiceLayer:" + url);
                    mapView.addLayer(new ArcGISTiledMapServiceLayer(url));
                } else if (type.equals("ArcGISFeatureLayer")) {
                    Log.v(REACT_CLASS, "set layers: adding ArcGISFeatureLayer:" + url);
                    mapView.addLayer(new ArcGISFeatureLayer(url, ArcGISFeatureLayer.MODE.SNAPSHOT));
                } else {
                    Log.v(REACT_CLASS, "set layers: unrecognized layer: " + type);
                }
            } else {
                Log.v(REACT_CLASS, "set layers: invalid url:" + url);
            }
        }
    }
}
 
Example 16
Source File: RNAGSMapView.java    From react-native-arcgis-mapview with MIT License 5 votes vote down vote up
public void setInitialMapCenter(ReadableArray initialCenter) {
    ArrayList<Point> points = new ArrayList<>();
    for (int i = 0; i < initialCenter.size(); i++) {
        ReadableMap item = initialCenter.getMap(i);
        if (item == null) {
            continue;
        }
        Double latitude = item.getDouble("latitude");
        Double longitude = item.getDouble("longitude");
        if (latitude == 0 || longitude == 0) {
            continue;
        }
        Point point = new Point(longitude, latitude, SpatialReferences.getWgs84());
        points.add(point);
    }
    // If no points exist, add a sample point
    if (points.size() == 0) {
        points.add(new Point(36.244797,-94.148060, SpatialReferences.getWgs84()));
    }
    if (points.size() == 1) {
        mapView.getMap().setInitialViewpoint(new Viewpoint(points.get(0),10000));
    } else {
        Polygon polygon = new Polygon(new PointCollection(points));
        Viewpoint viewpoint = viewpointFromPolygon(polygon);
        mapView.getMap().setInitialViewpoint(viewpoint);
    }
}
 
Example 17
Source File: RNYandexMapKitManager.java    From react-native-yandexmapkit with MIT License 5 votes vote down vote up
@Override
public void receiveCommand(RNYandexMapKitView view, int commandId, @Nullable ReadableArray args) {
    switch (commandId) {
        case ANIMATE_TO_COORDINATE:
            GeoPoint coordinate = null;
            ReadableMap latlon = args.getMap(0);
            if (latlon != null){
                double latitude = latlon.getDouble("latitude");
                double longitude = latlon.getDouble("longitude");
                coordinate = new GeoPoint(latitude, longitude);
            }
            view.animateToCoordinate(coordinate);
            break;
    }
}
 
Example 18
Source File: RCTImageSequenceManager.java    From react-native-image-sequence with MIT License 5 votes vote down vote up
/**
 * @param view
 * @param images an array of ReadableMap's {uri: "http://...."} return value of the resolveAssetSource(....)
 */
@ReactProp(name = "images")
public void setImages(final RCTImageSequenceView view, ReadableArray images) {
    ArrayList<String> uris = new ArrayList<>();
    for (int index = 0; index < images.size(); index++) {
        ReadableMap map = images.getMap(index);
        uris.add(map.getString("uri"));
    }

    view.setImages(uris);
}
 
Example 19
Source File: TransformHelper.java    From react-native-GPay with MIT License 4 votes vote down vote up
public static void processTransform(ReadableArray transforms, double[] result) {
  double[] helperMatrix = sHelperMatrix.get();
  MatrixMathHelper.resetIdentityMatrix(result);

  for (int transformIdx = 0, size = transforms.size(); transformIdx < size; transformIdx++) {
    ReadableMap transform = transforms.getMap(transformIdx);
    String transformType = transform.keySetIterator().nextKey();

    MatrixMathHelper.resetIdentityMatrix(helperMatrix);
    if ("matrix".equals(transformType)) {
      ReadableArray matrix = transform.getArray(transformType);
      for (int i = 0; i < 16; i++) {
        helperMatrix[i] = matrix.getDouble(i);
      }
    } else if ("perspective".equals(transformType)) {
      MatrixMathHelper.applyPerspective(helperMatrix, transform.getDouble(transformType));
    } else if ("rotateX".equals(transformType)) {
      MatrixMathHelper.applyRotateX(
        helperMatrix,
        convertToRadians(transform, transformType));
    } else if ("rotateY".equals(transformType)) {
      MatrixMathHelper.applyRotateY(
        helperMatrix,
        convertToRadians(transform, transformType));
    } else if ("rotate".equals(transformType) || "rotateZ".equals(transformType)) {
      MatrixMathHelper.applyRotateZ(
        helperMatrix,
        convertToRadians(transform, transformType));
    } else if ("scale".equals(transformType)) {
      double scale = transform.getDouble(transformType);
      MatrixMathHelper.applyScaleX(helperMatrix, scale);
      MatrixMathHelper.applyScaleY(helperMatrix, scale);
    } else if ("scaleX".equals(transformType)) {
      MatrixMathHelper.applyScaleX(helperMatrix, transform.getDouble(transformType));
    } else if ("scaleY".equals(transformType)) {
      MatrixMathHelper.applyScaleY(helperMatrix, transform.getDouble(transformType));
    } else if ("translate".equals(transformType)) {
      ReadableArray value = transform.getArray(transformType);
      double x = value.getDouble(0);
      double y = value.getDouble(1);
      double z = value.size() > 2 ? value.getDouble(2) : 0d;
      MatrixMathHelper.applyTranslate3D(helperMatrix, x, y, z);
    } else if ("translateX".equals(transformType)) {
      MatrixMathHelper.applyTranslate2D(helperMatrix, transform.getDouble(transformType), 0d);
    } else if ("translateY".equals(transformType)) {
      MatrixMathHelper.applyTranslate2D(helperMatrix, 0d, transform.getDouble(transformType));
    } else if ("skewX".equals(transformType)) {
      MatrixMathHelper.applySkewX(
        helperMatrix,
        convertToRadians(transform, transformType));
    } else if ("skewY".equals(transformType)) {
      MatrixMathHelper.applySkewY(
        helperMatrix,
        convertToRadians(transform, transformType));
    } else {
      throw new JSApplicationIllegalArgumentException("Unsupported transform type: "
        + transformType);
    }

    MatrixMathHelper.multiplyInto(result, result, helperMatrix);
  }
}
 
Example 20
Source File: MerryPhotoViewManager.java    From photo-viewer with Apache License 2.0 4 votes vote down vote up
@ReactProp(name = "data")
public void setData(MerryPhotoView merryPhotoView, @Nonnull ReadableArray prop) {

    MerryPhotoData[] merryPhotoDatas = new MerryPhotoData[]{};

    ArrayList<MerryPhotoData> list = new ArrayList<>();

    for (int i = 0; i < prop.size(); i++) {


        try {
            MerryPhotoData merryPhotoData = new MerryPhotoData() {
            };
            ReadableMap rm = prop.getMap(i);

            if (rm.hasKey("source")) {
                merryPhotoData.source = rm.getMap("source");

            }
            if (rm.hasKey("summary")) {
                merryPhotoData.summary = rm.getString("summary");

            }
            if (rm.hasKey("summaryColor")) {
                merryPhotoData.summaryColor = rm.getInt("summaryColor");

            }
            if (rm.hasKey("title")) {
                merryPhotoData.title = rm.getString("title");

            }
            if (rm.hasKey("titleColor")) {
                merryPhotoData.titleColor = rm.getInt("titleColor");
            }
            list.add(merryPhotoData);

        } catch (Exception e) {
            Log.e("PHOTO_VIEWER: ", e.toString());
        }


    }

    merryPhotoView.setData(list.toArray(merryPhotoDatas));
}