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

The following are Jave code examples for showing how to use getInt() of the com.facebook.react.bridge.ReadableArray class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: react-native-sketch-view   File: RNSketchViewManager.java   Source Code and License Vote up 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 2
Project: react-native-taptargetview   File: RNTapTargetViewModule.java   Source Code and License Vote up 6 votes
@ReactMethod
public void ShowSequence(final ReadableArray views, final ReadableMap props, final Promise promise) {
    final Activity activity = this.getCurrentActivity();
    final List<TapTarget> targetViews = new ArrayList<TapTarget>();

    for (int i = 0;i < views.size();i++) {
        int view = views.getInt(i);
        targetViews.add(this.generateTapTarget(view, props.getMap(String.valueOf(view))));
    }

    this.getCurrentActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            TapTargetSequence tapTargetSequence = new TapTargetSequence(activity).targets(targetViews);
            tapTargetSequence.continueOnCancel(true);
            tapTargetSequence.start();
        }
    });

}
 
Example 3
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   Source Code and License Vote up 6 votes
/**
 * 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 4
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   Source Code and License Vote up 6 votes
/**
 * Simplified version of manageChildren that only deals with adding children views
 */
public void setChildren(
  int tag,
  ReadableArray childrenTags) {
  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 5
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   Source Code and License Vote up 6 votes
/**
 * 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 6
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   Source Code and License Vote up 6 votes
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 7
Project: react-native-tensorflow   File: ArrayConverter.java   Source Code and License Vote up 5 votes
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 8
Project: react-native-ir-manager   File: RNIRManagerModule.java   Source Code and License Vote up 5 votes
@ReactMethod
public void transmit(Integer carrierFrequency, ReadableArray burstsPattern, Promise promise) {
    int[] pattern = new int[burstsPattern.size()];

    for (int i = 0; i < burstsPattern.size(); i++) {
        pattern[i] = burstsPattern.getInt(i);
    }

    try {
        manager.transmit(carrierFrequency, pattern);
        promise.resolve(true);
    } catch (Exception e) {
        promise.reject(e);
    }
}
 
Example 9
Project: RNLearn_Project1   File: VibrationModule.java   Source Code and License Vote up 5 votes
@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 10
Project: RNLearn_Project1   File: SwipeRefreshLayoutManager.java   Source Code and License Vote up 5 votes
@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 11
Project: RNLearn_Project1   File: VibrationModule.java   Source Code and License Vote up 5 votes
@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 12
Project: RNLearn_Project1   File: SwipeRefreshLayoutManager.java   Source Code and License Vote up 5 votes
@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 13
Project: RNLearn_Project1   File: AdditionAnimatedNode.java   Source Code and License Vote up 5 votes
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 14
Project: RNLearn_Project1   File: DivisionAnimatedNode.java   Source Code and License Vote up 5 votes
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 15
Project: RNLearn_Project1   File: MultiplicationAnimatedNode.java   Source Code and License Vote up 5 votes
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
Project: react-native-sunmi-inner-printer   File: SunmiInnerPrinterModule.java   Source Code and License Vote up 4 votes
/**
 * 打印表格的一行,可以指定列宽、对齐方式
 *
 * @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 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());
            }
        }
    });
}
 
Example 17
Project: RNLearn_Project1   File: MoveProxy.java   Source Code and License Vote up 4 votes
/**
 * Initialize MoveProxy with given moveFrom and moveTo arrays.
 */
public void setup(ReadableArray moveFrom, ReadableArray moveTo) {
  mMoveTo = moveTo;

  if (moveFrom == null) {
    setSize(0);
    return;
  }

  int size = moveFrom.size();
  int requiredSpace = size + size;
  if (mMapping.length < requiredSpace) {
    mMapping = new int[requiredSpace];
    mChildren = new FlatShadowNode[size];
  }

  setSize(size);

  // Array contains data in the following way:
  // [ k0, v0, k1, v1, k2, v2, ... ]
  //
  // where vi = moveFrom.getInt(ki)

  // We don't technically *need* to store vi, but they are accessed so often that it makes sense
  // to cache it instead of calling ReadableArray.getInt() all the time.

  // Sorting algorithm will reorder ki/vi pairs in such a way that vi < v(i+1)

  // Code below is an insertion sort, adapted from DualPivotQuicksort.doSort()

  // At each step i, we got the following data:

  // [k0, v0, k1, v2, .. k(i-1), v(i-1), unused...]
  // where v0 < v1 < v2 ... < v(i-1)
  //
  // This holds true for step i = 0 (array of size one is sorted)
  // Again, k0 = 0, v0 = moveFrom.getInt(k0)
  setKeyValue(0, 0, moveFrom.getInt(0));

  // At each of the next steps, we grab a new key and walk back until we find first key that is
  // less than current, shifting key/value pairs if they are larger than current key.
  for (int i = 1; i < size; i++) {
    // this is our next key
    int current = moveFrom.getInt(i);

    // this loop will find correct position for it
    int j;

    // At this point, array is like this: [ k0, v0, k1, v1, k2, v2, ..., k(i-1), v(i-1), ... ]
    for (j = i - 1; j >= 0; j--) {
      if (moveFromToValue(j) < current) {
        break;
      }

      // value at index j is < current value, shift that value and its key
      setKeyValue(j + 1, moveFromToIndex(j), moveFromToValue(j));
    }

    setKeyValue(j + 1, i, current);
  }
}
 
Example 18
Project: RNLearn_Project1   File: FlatUIImplementation.java   Source Code and License Vote up 4 votes
/**
 * Adds all children from addChildTags and moveFrom/moveTo.
 */
private void addChildren(
    ReactShadowNode parentNode,
    @Nullable ReadableArray addChildTags,
    @Nullable ReadableArray addAtIndices) {

  int prevIndex = -1;

  int moveToIndex;
  int moveToChildIndex;
  if (mMoveProxy.size() == 0) {
    moveToIndex = Integer.MAX_VALUE;
    moveToChildIndex = Integer.MAX_VALUE;
  } else {
    moveToIndex = 0;
    moveToChildIndex = mMoveProxy.getMoveTo(0);
  }

  int numNodesToAdd;
  int addToIndex;
  int addToChildIndex;
  if (addAtIndices == null) {
    numNodesToAdd = 0;
    addToIndex = Integer.MAX_VALUE;
    addToChildIndex = Integer.MAX_VALUE;
  } else {
    numNodesToAdd = addAtIndices.size();
    addToIndex = 0;
    addToChildIndex = addAtIndices.getInt(0);
  }

  // both mMoveProxy and addChildTags are already sorted, but combined order is not sorted. Use
  // a merge step from mergesort to walk over both arrays and extract elements in sorted order.

  while (true) {
    if (addToChildIndex < moveToChildIndex) {
      ReactShadowNode addToChild = resolveShadowNode(addChildTags.getInt(addToIndex));
      addChildAt(parentNode, addToChild, addToChildIndex, prevIndex);
      prevIndex = addToChildIndex;

      ++addToIndex;
      if (addToIndex == numNodesToAdd) {
        addToChildIndex = Integer.MAX_VALUE;
      } else {
        addToChildIndex = addAtIndices.getInt(addToIndex);
      }
    } else if (moveToChildIndex < addToChildIndex) {
      ReactShadowNode moveToChild = mMoveProxy.getChildMoveTo(moveToIndex);
      addChildAt(parentNode, moveToChild, moveToChildIndex, prevIndex);
      prevIndex = moveToChildIndex;

      ++moveToIndex;
      if (moveToIndex == mMoveProxy.size()) {
        moveToChildIndex = Integer.MAX_VALUE;
      } else {
        moveToChildIndex = mMoveProxy.getMoveTo(moveToIndex);
      }
    } else {
      // moveToChildIndex == addToChildIndex can only be if both are equal to Integer.MAX_VALUE
      // which means that we exhausted both arrays, and all children are added.
      break;
    }
  }
}
 
Example 19
Project: RNLearn_Project1   File: MoveProxy.java   Source Code and License Vote up 4 votes
/**
 * Initialize MoveProxy with given moveFrom and moveTo arrays.
 */
public void setup(ReadableArray moveFrom, ReadableArray moveTo) {
  mMoveTo = moveTo;

  if (moveFrom == null) {
    setSize(0);
    return;
  }

  int size = moveFrom.size();
  int requiredSpace = size + size;
  if (mMapping.length < requiredSpace) {
    mMapping = new int[requiredSpace];
    mChildren = new FlatShadowNode[size];
  }

  setSize(size);

  // Array contains data in the following way:
  // [ k0, v0, k1, v1, k2, v2, ... ]
  //
  // where vi = moveFrom.getInt(ki)

  // We don't technically *need* to store vi, but they are accessed so often that it makes sense
  // to cache it instead of calling ReadableArray.getInt() all the time.

  // Sorting algorithm will reorder ki/vi pairs in such a way that vi < v(i+1)

  // Code below is an insertion sort, adapted from DualPivotQuicksort.doSort()

  // At each step i, we got the following data:

  // [k0, v0, k1, v2, .. k(i-1), v(i-1), unused...]
  // where v0 < v1 < v2 ... < v(i-1)
  //
  // This holds true for step i = 0 (array of size one is sorted)
  // Again, k0 = 0, v0 = moveFrom.getInt(k0)
  setKeyValue(0, 0, moveFrom.getInt(0));

  // At each of the next steps, we grab a new key and walk back until we find first key that is
  // less than current, shifting key/value pairs if they are larger than current key.
  for (int i = 1; i < size; i++) {
    // this is our next key
    int current = moveFrom.getInt(i);

    // this loop will find correct position for it
    int j;

    // At this point, array is like this: [ k0, v0, k1, v1, k2, v2, ..., k(i-1), v(i-1), ... ]
    for (j = i - 1; j >= 0; j--) {
      if (moveFromToValue(j) < current) {
        break;
      }

      // value at index j is < current value, shift that value and its key
      setKeyValue(j + 1, moveFromToIndex(j), moveFromToValue(j));
    }

    setKeyValue(j + 1, i, current);
  }
}
 
Example 20
Project: RNLearn_Project1   File: FlatUIImplementation.java   Source Code and License Vote up 4 votes
/**
 * Removes all children defined by moveFrom and removeFrom from a given parent,
 * preparing elements in moveFrom to be re-added at proper index.
 */
private void removeChildren(
    ReactShadowNode parentNode,
    @Nullable ReadableArray moveFrom,
    @Nullable ReadableArray moveTo,
    @Nullable ReadableArray removeFrom) {

  int prevIndex = Integer.MAX_VALUE;

  mMoveProxy.setup(moveFrom, moveTo);

  int moveFromIndex = mMoveProxy.size() - 1;
  int moveFromChildIndex = (moveFromIndex == -1) ? -1 : mMoveProxy.getMoveFrom(moveFromIndex);

  int numToRemove = removeFrom == null ? 0 : removeFrom.size();
  int[] indicesToRemove = new int[numToRemove];
  if (numToRemove > 0) {
    Assertions.assertNotNull(removeFrom);
    for (int i = 0; i < numToRemove; i++) {
      int indexToRemove = removeFrom.getInt(i);
      indicesToRemove[i] = indexToRemove;
    }
  }

  // this isn't guaranteed to be sorted actually
  Arrays.sort(indicesToRemove);

  int removeFromIndex;
  int removeFromChildIndex;
  if (removeFrom == null) {
    removeFromIndex = -1;
    removeFromChildIndex = -1;
  } else {
    removeFromIndex = indicesToRemove.length - 1;
    removeFromChildIndex = indicesToRemove[removeFromIndex];
  }

  // both moveFrom and removeFrom are already sorted, but combined order is not sorted. Use
  // a merge step from mergesort to walk over both arrays and extract elements in sorted order.

  while (true) {
    if (moveFromChildIndex > removeFromChildIndex) {
      moveChild(removeChildAt(parentNode, moveFromChildIndex, prevIndex), moveFromIndex);
      prevIndex = moveFromChildIndex;

      --moveFromIndex;
      moveFromChildIndex = (moveFromIndex == -1) ? -1 : mMoveProxy.getMoveFrom(moveFromIndex);
    } else if (removeFromChildIndex > moveFromChildIndex) {
      removeChild(removeChildAt(parentNode, removeFromChildIndex, prevIndex), parentNode);
      prevIndex = removeFromChildIndex;

      --removeFromIndex;
      removeFromChildIndex = (removeFromIndex == -1) ? -1 : indicesToRemove[removeFromIndex];
    } else {
      // moveFromChildIndex == removeFromChildIndex can only be if both are equal to -1
      // which means that we exhausted both arrays, and all children are removed.
      break;
    }
  }
}