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

The following examples show how to use com.facebook.react.bridge.ReadableArray#size() . 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: RNAGSMapView.java    From react-native-arcgis-mapview with MIT License 6 votes vote down vote up
public void centerMap(ReadableArray args) {
    final ArrayList<Point> points = new ArrayList<>();
    for (int i = 0; i <  args.size(); i++) {
        ReadableMap item = args.getMap(i);
        if (item == null) {
            continue;
        }
        Double latitude = item.getDouble("latitude");
        Double longitude = item.getDouble("longitude");
        if(latitude == 0 || longitude == 0) {
            continue;
        }
        points.add(new Point(longitude, latitude, SpatialReferences.getWgs84()));
    }
    // Perform the recentering
    if (points.size() == 1) {
        mapView.setViewpointCenterAsync(points.get(0),60000);
    } else if (points.size() > 1) {
        PointCollection pointCollection = new PointCollection(points);
        Polygon polygon = new Polygon(pointCollection);
        mapView.setViewpointGeometryAsync(polygon, 50);
    }

}
 
Example 2
Source File: JSStackTrace.java    From react-native-GPay with MIT License 6 votes vote down vote up
public static String format(String message, ReadableArray stack) {
  StringBuilder stringBuilder = new StringBuilder(message).append(", stack:\n");
  for (int i = 0; i < stack.size(); i++) {
    ReadableMap frame = stack.getMap(i);
    stringBuilder
      .append(frame.getString("methodName"))
      .append("@")
      .append(stackFrameToModuleId(frame))
      .append(frame.getInt("lineNumber"));
    if (frame.hasKey("column") &&
      !frame.isNull("column") &&
      frame.getType("column") == ReadableType.Number) {
      stringBuilder
        .append(":")
        .append(frame.getInt("column"));
    }
    stringBuilder.append("\n");
  }
  return stringBuilder.toString();
}
 
Example 3
Source File: BaseViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@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 4
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 6 votes vote down vote up
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 5
Source File: SegmentAnalyticsModule.java    From react-native-segment-analytics with MIT License 5 votes vote down vote up
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 6
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 7
Source File: Web3WebviewManager.java    From react-native-web3-webview with MIT License 5 votes vote down vote up
@ReactProp(name = "originWhitelist")
public void setOriginWhitelist(
        WebView view,
        @NonNull ReadableArray originWhitelist) {
    Web3WebviewClient client = ((Web3Webview) view).getWeb3WebviewClient();
    if (client != null && originWhitelist != null) {
        List<Pattern> whiteList = new LinkedList<>();
        for (int i = 0 ; i < originWhitelist.size() ; i++) {
            whiteList.add(Pattern.compile(originWhitelist.getString(i)));
        }
        client.setOriginWhitelist(whiteList);
    }
}
 
Example 8
Source File: DivisionAnimatedNode.java    From react-native-GPay with MIT License 5 votes vote down vote up
public DivisionAnimatedNode(
    ReadableMap config,
    NativeAnimatedNodesManager nativeAnimatedNodesManager) {
  mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
  ReadableArray inputNodes = config.getArray("input");
  mInputNodes = new int[inputNodes.size()];
  for (int i = 0; i < mInputNodes.length; i++) {
    mInputNodes[i] = inputNodes.getInt(i);
  }
}
 
Example 9
Source File: OTSessionManager.java    From opentok-react-native with MIT License 5 votes vote down vote up
@ReactMethod
public void setJSComponentEvents(ReadableArray events) {

    for (int i = 0; i < events.size(); i++) {
        componentEvents.add(events.getString(i));
    }
}
 
Example 10
Source File: DefaultNavigationImplementation.java    From native-navigation with MIT License 5 votes vote down vote up
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 11
Source File: OTSessionManager.java    From opentok-react-native with MIT License 5 votes vote down vote up
@ReactMethod
public void setNativeEvents(ReadableArray events) {

    for (int i = 0; i < events.size(); i++) {
        jsEvents.add(events.getString(i));
    }
}
 
Example 12
Source File: RNBottomSheet.java    From react-native-bottom-sheet with MIT License 5 votes vote down vote up
@ReactMethod
public void showBottomSheetWithOptions(ReadableMap options, final Callback onSelect) {
    ReadableArray optionArray = options.getArray("options");
    final Integer cancelButtonIndex = options.getInt("cancelButtonIndex");

    final BottomSheet.Builder builder = new BottomSheet.Builder(this.getCurrentActivity());

    // create options
    Integer size = optionArray.size();
    for (int i = 0; i < size; i++) {
        builder.sheet(i, optionArray.getString(i));
    }

    builder.listener(new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == cancelButtonIndex) {
                dialog.dismiss();
            } else {
                onSelect.invoke(which);
            }
        }
    });

    UiThreadUtil.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            builder.build().show();
        }
    });
}
 
Example 13
Source File: NetworkingModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Extracts the headers from the Array. If the format is invalid, this method will return null.
 */
private @Nullable Headers extractHeaders(
    @Nullable ReadableArray headersArray,
    @Nullable ReadableMap requestData) {
  if (headersArray == null) {
    return null;
  }
  Headers.Builder headersBuilder = new Headers.Builder();
  for (int headersIdx = 0, size = headersArray.size(); headersIdx < size; headersIdx++) {
    ReadableArray header = headersArray.getArray(headersIdx);
    if (header == null || header.size() != 2) {
      return null;
    }
    String headerName = header.getString(0);
    String headerValue = header.getString(1);
    if (headerName == null || headerValue == null) {
      return null;
    }
    headersBuilder.add(headerName, headerValue);
  }
  if (headersBuilder.get(USER_AGENT_HEADER_NAME) == null && mDefaultUserAgent != null) {
    headersBuilder.add(USER_AGENT_HEADER_NAME, mDefaultUserAgent);
  }

  // Sanitize content encoding header, supported only when request specify payload as string
  boolean isGzipSupported = requestData != null && requestData.hasKey(REQUEST_BODY_KEY_STRING);
  if (!isGzipSupported) {
    headersBuilder.removeAll(CONTENT_ENCODING_HEADER_NAME);
  }

  return headersBuilder.build();
}
 
Example 14
Source File: SamsungHealthModule.java    From react-native-samsung-health with The Unlicense 5 votes vote down vote up
@ReactMethod
public void connect(ReadableArray permissions, Callback error, Callback success)
{
    // Add permission
    ConnectionListener listener = new ConnectionListener(this, error, success);
    for (int i = 0; i < permissions.size(); i++) {
        listener.addReadPermission(permissions.getString(i));
    }

    // Create a HealthDataStore instance and set its listener
    mStore = new HealthDataStore(getReactApplicationContext(), listener);
    // Request the connection to the health data store
    mStore.connectService();
}
 
Example 15
Source File: RNCallKeepModule.java    From react-native-callkeep with ISC License 5 votes vote down vote up
@ReactMethod
public void checkPhoneAccountPermission(ReadableArray optionalPermissions, Promise promise) {
    Activity currentActivity = this.getCurrentActivity();

    if (!isConnectionServiceAvailable()) {
        promise.reject(E_ACTIVITY_DOES_NOT_EXIST, "ConnectionService not available for this version of Android.");
        return;
    }
    if (currentActivity == null) {
        promise.reject(E_ACTIVITY_DOES_NOT_EXIST, "Activity doesn't exist");
        return;
    }
    String[] optionalPermsArr = new String[optionalPermissions.size()];
    for (int i = 0; i < optionalPermissions.size(); i++) {
        optionalPermsArr[i] = optionalPermissions.getString(i);
    }

    String[] allPermissions = Arrays.copyOf(permissions, permissions.length + optionalPermsArr.length);
    System.arraycopy(optionalPermsArr, 0, allPermissions, permissions.length, optionalPermsArr.length);

    hasPhoneAccountPromise = promise;

    if (!this.hasPermissions()) {
        requestPermissions(currentActivity, allPermissions, REQUEST_READ_PHONE_STATE);
         return;
    }

    promise.resolve(!hasPhoneAccount());
}
 
Example 16
Source File: RealtimeMessagingAndroid.java    From RCTRealtimeMessagingAndroid with MIT License 5 votes vote down vote up
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 17
Source File: ArrayConverter.java    From react-native-tensorflow with Apache License 2.0 5 votes vote down vote up
public static double[] readableArrayToDoubleArray(ReadableArray readableArray) {
    double[] arr = new double[readableArray.size()];
    for (int i = 0; i < readableArray.size(); i++) {
        arr[i] = readableArray.getDouble(i);
    }

    return arr;
}
 
Example 18
Source File: ArrayConverter.java    From react-native-tensorflow with Apache License 2.0 5 votes vote down vote up
public static byte[] readableArrayToByteBoolArray(ReadableArray readableArray) {
    byte[] bytesArr = new byte[readableArray.size() / 8 + 1];
    for (int entry = 0; entry < bytesArr.length; entry++) {
        for (int bit = 0; bit < 8; bit++) {
            if (readableArray.getBoolean(entry * 8 + bit)) {
                bytesArr[entry] |= (128 >> bit);
            }
        }
    }

    return bytesArr;
}
 
Example 19
Source File: SubtractionAnimatedNode.java    From react-native-GPay with MIT License 5 votes vote down vote up
public SubtractionAnimatedNode(
    ReadableMap config,
    NativeAnimatedNodesManager nativeAnimatedNodesManager) {
  mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
  ReadableArray inputNodes = config.getArray("input");
  mInputNodes = new int[inputNodes.size()];
  for (int i = 0; i < mInputNodes.length; i++) {
    mInputNodes[i] = inputNodes.getInt(i);
  }
}
 
Example 20
Source File: SunmiInnerPrinterModule.java    From react-native-sunmi-inner-printer with MIT License 4 votes vote down vote up
/**
 * 打印表格的一行,可以指定列宽、对齐方式
 *
 * @param colsTextArr  各列文本字符串数组
 * @param colsWidthArr 各列宽度数组(以英文字符计算, 每个中文字符占两个英文字符, 每个宽度大于0)
 * @param colsAlign    各列对齐方式(0居左, 1居中, 2居右)
 *                     备注: 三个参数的数组长度应该一致, 如果colsText[i]的宽度大于colsWidth[i], 则文本换行
 */
@ReactMethod
public void printColumnsText(ReadableArray colsTextArr, ReadableArray colsWidthArr, ReadableArray colsAlign, final Promise p) {
    final IWoyouService ss = woyouService;
    final String[] clst = new String[colsTextArr.size()];
    for (int i = 0; i < colsTextArr.size(); i++) {
        clst[i] = colsTextArr.getString(i);
    }
    final int[] clsw = new int[colsWidthArr.size()];
    for (int i = 0; i < colsWidthArr.size(); i++) {
        clsw[i] = colsWidthArr.getInt(i);
    }
    final int[] clsa = new int[colsAlign.size()];
    for (int i = 0; i < colsAlign.size(); i++) {
        clsa[i] = colsAlign.getInt(i);
    }
    ThreadPoolManager.getInstance().executeTask(new Runnable() {
        @Override
        public void run() {
            try {
                ss.printColumnsText(clst, clsw, clsa, new ICallback.Stub() {
                    @Override
                    public void onPrintResult(int par1, String par2) {
                        Log.d(TAG, "ON PRINT RES: " + par1 + ", " + par2);
                    }

                    @Override
                    public void onRunResult(boolean isSuccess) {
                        if (isSuccess) {
                            p.resolve(null);
                        } else {
                            p.reject("0", isSuccess + "");
                        }
                    }

                    @Override
                    public void onReturnString(String result) {
                        p.resolve(result);
                    }

                    @Override
                    public void onRaiseException(int code, String msg) {
                        p.reject("" + code, msg);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                Log.i(TAG, "ERROR: " + e.getMessage());
                p.reject("" + 0, e.getMessage());
            }
        }
    });
}