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

The following examples show how to use com.facebook.react.bridge.ReadableArray#getInt() . 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 vote down vote up
@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: RCTChirpSDKModule.java    From chirp-react-native with Apache License 2.0 6 votes vote down vote up
/**
 * send(data)
 *
 * Encodes a payload of bytes, and sends to the speaker.
 */
@ReactMethod
public void send(ReadableArray data) {
    byte[] payload = new byte[data.size()];
    for (int i = 0; i < data.size(); i++) {
        payload[i] = (byte)data.getInt(i);
    }

    long maxSize = chirp.maxPayloadLength();
    if (maxSize < payload.length) {
        onError(context, "Invalid payload");
        return;
    }
    ChirpError error = chirp.send(payload);
    if (error.getCode() > 0) {
        onError(context, error.getMessage());
    }
}
 
Example 3
Source File: ZBarDecoder.java    From react-native-barcode with MIT License 6 votes vote down vote up
@Override
public void setFormats(ReadableArray formats) {
    if (formats.size() > 0) {
        // clear all formats
        mScanner.setConfig(Symbol.NONE, Config.ENABLE, 0);
        for (int i = 0; i < formats.size(); i++) {
            int format = formats.getInt(i);
            if (format != -1) {
                mScanner.setConfig(formatToSymbol(format), Config.ENABLE, 1);
            }
        }
    } else {
        // set all formats
        mScanner.setConfig(Symbol.NONE, Config.ENABLE, 1);
    }
}
 
Example 4
Source File: NativeViewHierarchyManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Simplified version of constructManageChildrenErrorMessage that only deals with adding children
 * views
 */
private static String constructSetChildrenErrorMessage(
  ViewGroup viewToManage,
  ViewGroupManager viewManager,
  ReadableArray childrenTags) {
  ViewAtIndex[] viewsToAdd = new ViewAtIndex[childrenTags.size()];
  for (int i = 0; i < childrenTags.size(); i++) {
    viewsToAdd[i] = new ViewAtIndex(childrenTags.getInt(i), i);
  }
  return constructManageChildrenErrorMessage(
    viewToManage,
    viewManager,
    null,
    viewsToAdd,
    null
  );
}
 
Example 5
Source File: NativeViewHierarchyManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Simplified version of manageChildren that only deals with adding children views
 */
public synchronized void setChildren(
  int tag,
  ReadableArray childrenTags) {
  UiThreadUtil.assertOnUiThread();
  ViewGroup viewToManage = (ViewGroup) mTagsToViews.get(tag);
  ViewGroupManager viewManager = (ViewGroupManager) resolveViewManager(tag);

  for (int i = 0; i < childrenTags.size(); i++) {
    View viewToAdd = mTagsToViews.get(childrenTags.getInt(i));
    if (viewToAdd == null) {
      throw new IllegalViewOperationException(
        "Trying to add unknown view tag: "
          + childrenTags.getInt(i) + "\n detail: " +
          constructSetChildrenErrorMessage(
            viewToManage,
            viewManager,
            childrenTags));
    }
    viewManager.addView(viewToManage, viewToAdd, i);
  }
}
 
Example 6
Source File: RNShadowTextGradient.java    From react-native-text-gradient with MIT License 6 votes vote down vote up
@SuppressWarnings("unused")
@ReactProp(name = "colors")
public void setColors(ReadableArray colors) {
  if (colors != null) {
    int[] _colors = new int[colors.size()];

    for (int i = 0; i < _colors.length; i++) {
      _colors[i] = colors.getInt(i);
    }

    mColors = _colors;

  } else {
    mColors = null;
  }

  markUpdated();
}
 
Example 7
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
private void arrayGetByType(ReadableArray array, int index, String typeToAskFor) {
  if (typeToAskFor.equals("double")) {
    array.getDouble(index);
  } else if (typeToAskFor.equals("int")) {
    array.getInt(index);
  } else if (typeToAskFor.equals("string")) {
    array.getString(index);
  } else if (typeToAskFor.equals("array")) {
    array.getArray(index);
  } else if (typeToAskFor.equals("map")) {
    array.getMap(index);
  } else if (typeToAskFor.equals("boolean")) {
    array.getBoolean(index);
  } else {
    throw new RuntimeException("Unknown type: " + typeToAskFor);
  }
}
 
Example 8
Source File: BottomSheetBehaviorManager.java    From react-native-bottom-sheet-behavior with MIT License 6 votes vote down vote up
@Override
public void receiveCommand(BottomSheetBehaviorView view, int commandType, @Nullable ReadableArray args) {
    switch (commandType) {
      case COMMAND_SET_REQUEST_LAYOUT:
          setRequestLayout(view);
          return;
      case COMMAND_SET_BOTTOM_SHEET_STATE:
          setBottomSheetState(view, args);
          return;
      case COMMAND_ATTACH_NESTED_SCROLL_CHILD:
          int nestedScrollId = args.getInt(0);
          ViewGroup child = (ViewGroup) view.getRootView().findViewById(nestedScrollId);
          if (child != null && child instanceof NestedScrollView) {
              this.attachNestedScrollChild(view, (NestedScrollView) child);
          }
          return;

      default:
          throw new JSApplicationIllegalArgumentException("Invalid Command");
    }
}
 
Example 9
Source File: BridgeUtils.java    From react-native-mp-android-chart with MIT License 5 votes vote down vote up
public static int[] convertToIntArray(ReadableArray readableArray) {
    int[] array = new int[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] = readableArray.getInt(i);
    }

    return array;
}
 
Example 10
Source File: ArrayConverter.java    From react-native-tensorflow with Apache License 2.0 5 votes vote down vote up
public static int[] readableArrayToIntArray(ReadableArray readableArray) {
    int[] arr = new int[readableArray.size()];
    for (int i = 0; i < readableArray.size(); i++) {
        arr[i] = readableArray.getInt(i);
    }

    return arr;
}
 
Example 11
Source File: JSONParser.java    From react-native-navigation with MIT License 5 votes vote down vote up
private static Object parseNumber(ReadableArray arr, int index) {
    try {
        Double doubleValue = arr.getDouble(index);
        if(doubleValue % 1 == 0){
            return arr.getInt(index);
        }
        return doubleValue;
    } catch (Exception e) {
        return arr.getInt(index);
    }
}
 
Example 12
Source File: SmartRefreshLayoutManager.java    From react-native-SmartRefreshLayout with Apache License 2.0 5 votes vote down vote up
@Override
public void receiveCommand(ReactSmartRefreshLayout root, int commandId, @Nullable ReadableArray args) {
    switch (commandId){
        case COMMAND_FINISH_REFRESH_ID:
            int delayed=args.getInt(0);
            boolean success=args.getBoolean(1);
            if(delayed>=0){
                root.finishRefresh(delayed,success);
            }else{
                root.finishRefresh(success);
            }
            break;
        default:break;
    }
}
 
Example 13
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 14
Source File: AdditionAnimatedNode.java    From react-native-GPay with MIT License 5 votes vote down vote up
public AdditionAnimatedNode(
    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 15
Source File: MultiplicationAnimatedNode.java    From react-native-GPay with MIT License 5 votes vote down vote up
public MultiplicationAnimatedNode(
    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 16
Source File: OptionsHelper.java    From react-native-lock with MIT License 5 votes vote down vote up
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 17
Source File: VibrationModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactMethod
public void vibrateByPattern(ReadableArray pattern, int repeat) {
  long[] patternLong = new long[pattern.size()];
  for (int i = 0; i < pattern.size(); i++) {
    patternLong[i] = pattern.getInt(i);
  }

  Vibrator v = (Vibrator) getReactApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
  if (v != null) {
    v.vibrate(patternLong, repeat);
  }
}
 
Example 18
Source File: SwipeRefreshLayoutManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactProp(name = "colors", customType = "ColorArray")
public void setColors(ReactSwipeRefreshLayout view, @Nullable ReadableArray colors) {
  if (colors != null) {
    int[] colorValues = new int[colors.size()];
    for (int i = 0; i < colors.size(); i++) {
      colorValues[i] = colors.getInt(i);
    }
    view.setColorSchemeColors(colorValues);
  } else {
    view.setColorSchemeColors();
  }
}
 
Example 19
Source File: ZXingDecoder.java    From react-native-barcode with MIT License 5 votes vote down vote up
@Override
public void setFormats(ReadableArray formats) {
    mSymbols.clear();
    if (formats.size() > 0) {
        for (int i = 0; i < formats.size(); i++) {
            int format = formats.getInt(i);
            if (format != -1) {
                mSymbols.add(formatToSymbol(format));
            }
        }
        mHints.put(DecodeHintType.POSSIBLE_FORMATS, mSymbols);
    } else {
        mHints.remove(DecodeHintType.POSSIBLE_FORMATS);
    }
}
 
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());
            }
        }
    });
}