Example usage for com.facebook.react.bridge ReadableArray getInt

List of usage examples for com.facebook.react.bridge ReadableArray getInt

Introduction

In this page you can find the example usage for com.facebook.react.bridge ReadableArray getInt.

Prototype

int getInt(int index);

Source Link

Usage

From source file:com.horcrux.svg.RenderableShadowNode.java

License:Open Source License

private void setupPaint(Paint paint, float opacity, ReadableArray colors) {
    int colorType = colors.getInt(0);
    if (colorType == 0) {
        // solid color
        paint.setARGB((int) (colors.size() > 4 ? colors.getDouble(4) * opacity * 255 : opacity * 255),
                (int) (colors.getDouble(1) * 255), (int) (colors.getDouble(2) * 255),
                (int) (colors.getDouble(3) * 255));
    } else if (colorType == 1) {
        RectF box = new RectF();
        mPath.computeBounds(box, true);/*  w  ww .ja v a  2 s . c o m*/

        Brush brush = getSvgShadowNode().getDefinedBrush(colors.getString(1));
        if (brush != null) {
            brush.setupPaint(paint, box, mScale, opacity);
        }
    }

}

From source file:com.horcrux.svg.RenderableView.java

License:Open Source License

private void setupPaint(Paint paint, float opacity, ReadableArray colors) {
    int colorType = colors.getInt(0);
    switch (colorType) {
    case 0:/* w  w  w.j a  va 2  s  .  c om*/
        // solid color
        paint.setARGB((int) (colors.size() > 4 ? colors.getDouble(4) * opacity * 255 : opacity * 255),
                (int) (colors.getDouble(1) * 255), (int) (colors.getDouble(2) * 255),
                (int) (colors.getDouble(3) * 255));
        break;
    case 1: {
        Brush brush = getSvgView().getDefinedBrush(colors.getString(1));
        if (brush != null) {
            brush.setupPaint(paint, mBox, mScale, opacity);
        }
        break;
    }
    case 2: {
        int brush = getSvgView().mTintColor;
        paint.setColor(brush);
        break;
    }
    }

}

From source file:com.horcrux.svg.RNSVGPathShadowNode.java

License:Open Source License

private void setupPaint(Paint paint, float opacity, ReadableArray colors, @Nullable RectF box) {
    int colorType = colors.getInt(0);
    if (colorType == 0) {
        // solid color
        paint.setARGB((int) (colors.size() > 4 ? colors.getDouble(4) * opacity * 255 : opacity * 255),
                (int) (colors.getDouble(1) * 255), (int) (colors.getDouble(2) * 255),
                (int) (colors.getDouble(3) * 255));
    } else if (colorType == 1 || colorType == 2) {
        if (box == null) {
            box = new RectF();
            mPath.computeBounds(box, true);
        }/*w  ww.  ja  v  a  2s. c o m*/

        int startColorsPosition = colorType == 1 ? 5 : 7;

        int stopsCount = (colors.size() - startColorsPosition) / 5;
        int[] stopsColors = new int[stopsCount];
        float[] stops = new float[stopsCount];
        float height = box.height();
        float width = box.width();
        float midX = box.centerX();
        float midY = box.centerY();
        float offsetX = (midX - width / 2);
        float offsetY = (midY - height / 2);

        parseGradientStops(colors, stopsCount, stops, stopsColors, startColorsPosition);

        if (colorType == 1) {
            float x1 = PropHelper.fromPercentageToFloat(colors.getString(1), width, offsetX, mScale);
            float y1 = PropHelper.fromPercentageToFloat(colors.getString(2), height, offsetY, mScale);
            float x2 = PropHelper.fromPercentageToFloat(colors.getString(3), width, offsetX, mScale);
            float y2 = PropHelper.fromPercentageToFloat(colors.getString(4), height, offsetY, mScale);
            paint.setShader(new LinearGradient(x1, y1, x2, y2, stopsColors, stops, Shader.TileMode.CLAMP));
        } else {
            float rx = PropHelper.fromPercentageToFloat(colors.getString(3), width, 0f, mScale);
            float ry = PropHelper.fromPercentageToFloat(colors.getString(4), height, 0f, mScale);
            float cx = PropHelper.fromPercentageToFloat(colors.getString(5), width, offsetX, mScale);
            float cy = PropHelper.fromPercentageToFloat(colors.getString(6), height, offsetY, mScale)
                    / (ry / rx);
            // TODO: do not support focus point.
            //float fx = PropHelper.fromPercentageToFloat(colors.getString(1), width, offsetX) * mScale;
            //float fy = PropHelper.fromPercentageToFloat(colors.getString(2), height, offsetY) * mScale / (ry / rx);
            Shader radialGradient = new RadialGradient(cx, cy, rx, stopsColors, stops, Shader.TileMode.CLAMP);

            Matrix radialMatrix = new Matrix();
            radialMatrix.preScale(1f, ry / rx);
            radialGradient.setLocalMatrix(radialMatrix);
            paint.setShader(radialGradient);
        }
    } else {
        // TODO: Support pattern.
        FLog.w(ReactConstants.TAG, "RNSVG: Color type " + colorType + " not supported!");
    }

}

From source file:com.reactnative.swiper.viewpager.ReactViewPagerManager.java

License:Open Source License

@Override
public void receiveCommand(ReactViewPager viewPager, int commandType, @Nullable ReadableArray args) {
    Assertions.assertNotNull(viewPager);
    Assertions.assertNotNull(args);/*from   w w  w  .  j  ava2  s  .  c  o m*/
    switch (commandType) {
    case COMMAND_SET_PAGE: {
        viewPager.setCurrentItemFromJs(args.getInt(0), true);
        return;
    }
    case COMMAND_SET_PAGE_WITHOUT_ANIMATION: {
        viewPager.setCurrentItemFromJs(args.getInt(0), false);
        return;
    }
    default:
        throw new IllegalArgumentException(String.format("Unsupported command %d received by %s.", commandType,
                getClass().getSimpleName()));
    }
}

From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java

private static JSONArray arrayToJson(ReadableArray readableArray) throws JSONException {
    JSONArray jsonArray = new JSONArray();
    for (int i = 0; i < readableArray.size(); i++) {
        ReadableType valueType = readableArray.getType(i);
        switch (valueType) {
        case Null:
            jsonArray.put(JSONObject.NULL);
            break;
        case Boolean:
            jsonArray.put(readableArray.getBoolean(i));
            break;
        case Number:
            jsonArray.put(readableArray.getInt(i));
            break;
        case String:
            jsonArray.put(readableArray.getString(i));
            break;
        case Map:
            jsonArray.put(mapToJson(readableArray.getMap(i)));
            break;
        case Array:
            jsonArray.put(arrayToJson(readableArray.getArray(i)));
            break;
        }/*www  .j  a  va2s  .c  o m*/
    }
    return jsonArray;
}

From source file:com.tuniu.rnbrige.SwipeRefreshLayoutManager.java

License:Open Source License

@ReactProp(name = "colors")
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);
        }//from w  w w. ja  va2  s .c  om
        view.setColorSchemeColors(colorValues);
    } else {
        view.setColorSchemeColors();
    }
}

From source file:io.github.douglasjunior.ReactNativeEasyBluetooth.core.CoreModule.java

License:Open Source License

public void writeIntArray(ReadableArray data, Promise promise) {
    Log.d(TAG, "writeIntArray: " + data);

    try {//  ww  w  .j a va  2s .c  o  m
        if (!validateServiceConfig(promise))
            return;

        byte[] bytes = new byte[data.size()];

        for (int i = 0; i < data.size(); i++) {
            bytes[i] = (byte) data.getInt(i);
        }

        mService.write(bytes);
        promise.resolve(null);
    } catch (Exception ex) {
        ex.printStackTrace();
        promise.reject(ex);
    }
}

From source file:versioned.host.exp.exponent.modules.api.components.svg.RNSVGPathShadowNode.java

License:Open Source License

private void setupPaint(Paint paint, float opacity, ReadableArray colors, @Nullable RectF box) {
    int colorType = colors.getInt(0);
    if (colorType == 0) {
        // solid color
        paint.setARGB((int) (colors.size() > 4 ? colors.getDouble(4) * opacity * 255 : opacity * 255),
                (int) (colors.getDouble(1) * 255), (int) (colors.getDouble(2) * 255),
                (int) (colors.getDouble(3) * 255));
    } else if (colorType == 1) {
        if (box == null) {
            box = new RectF();
            mPath.computeBounds(box, true);
        }//  w w w . j  av  a  2 s . com
        PropHelper.RNSVGBrush brush = getSvgShadowNode().getDefinedBrush(colors.getString(1));
        if (brush != null) {
            brush.setupPaint(paint, box, mScale, opacity);
        }
    } else {
        // TODO: Support pattern.
        FLog.w(ReactConstants.TAG, "RNSVG: Color type " + colorType + " not supported!");
    }

}