Java Code Examples for com.facebook.react.bridge.WritableMap#putInt()

The following examples show how to use com.facebook.react.bridge.WritableMap#putInt() . 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: RNTextSizeModule.java    From react-native-text-size with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Nonnull
private WritableMap fontInfoFromTypeface(
        @Nonnull final TextPaint textPaint,
        @Nonnull final Typeface typeface,
        @Nonnull final RNTextSizeConf conf
) {
    // Info is always in unscaled values
    final float density = getCurrentDensity();
    final Paint.FontMetrics metrics = new Paint.FontMetrics();
    final float lineHeight = textPaint.getFontMetrics(metrics);

    final WritableMap info = Arguments.createMap();
    info.putString("fontFamily", conf.getString("fontFamily"));
    info.putString("fontWeight", typeface.isBold() ? "bold" : "normal");
    info.putString("fontStyle", typeface.isItalic() ? "italic" : "normal");
    info.putDouble("fontSize", textPaint.getTextSize() / density);
    info.putDouble("leading", metrics.leading / density);
    info.putDouble("ascender", metrics.ascent / density);
    info.putDouble("descender", metrics.descent / density);
    info.putDouble("top", metrics.top / density);
    info.putDouble("bottom", metrics.bottom / density);
    info.putDouble("lineHeight", lineHeight / density);
    info.putInt("_hash", typeface.hashCode());
    return info;
}
 
Example 2
Source File: FabricTwitterKitUtils.java    From react-native-fabric-twitterkit with MIT License 6 votes vote down vote up
private static WritableMap jsonToWritableMap(final JSONObject jsonObject) throws JSONException {
    final WritableMap writableMap = Arguments.createMap();
    final Iterator iterator = jsonObject.keys();
    while (iterator.hasNext()) {
        final String key = (String) iterator.next();
        final Object value = jsonObject.get(key);
        if (value instanceof Float || value instanceof Double) {
            writableMap.putDouble(key, jsonObject.getDouble(key));
        } else if (value instanceof Number) {
            writableMap.putInt(key, jsonObject.getInt(key));
        } else if (value instanceof String) {
            writableMap.putString(key, jsonObject.getString(key));
        } else if (value instanceof JSONObject) {
            writableMap.putMap(key, jsonToWritableMap(jsonObject.getJSONObject(key)));
        } else if (value instanceof JSONArray) {
            writableMap.putArray(key, jsonToWritableArray(jsonObject.getJSONArray(key)));
        } else if (value instanceof Boolean) {
            writableMap.putBoolean(key, jsonObject.getBoolean(key));
        } else if (value == JSONObject.NULL) {
            writableMap.putNull(key);
        }
    }
    return writableMap;
}
 
Example 3
Source File: RNRtmpView.java    From react-native-rtmpview with MIT License 6 votes vote down vote up
public void onPlaybackStateChanged(RNRtmpPlaybackState playbackState, Throwable error) {
    WritableMap event = Arguments.createMap();
    event.putString("state", playbackState.getFieldDescription());
    event.putInt("playback_state", mPlayer.getPlaybackState());
    event.putBoolean("play_when_ready", mPlayer.getPlayWhenReady());

    if (error != null) {
        event.putString("error", error.toString());
    }

    event.putMap("qos", getQos());

    ReactContext reactContext = (ReactContext)getContext();
    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
            getId(),
            Events.EVENT_PLAYBACK_STATE.toString(),
            event);
}
 
Example 4
Source File: RNTextSizeModule.java    From react-native-text-size with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This is for 'fontFromFontStyle', makes the minimal info required.
 * @param suffix The font variant
 * @param fontSize Font size in SP
 * @param letterSpacing Sugest this to user
 * @return map with specs
 */
private WritableMap makeFontSpecs(String suffix, int fontSize, double letterSpacing, boolean upcase) {
    final WritableMap map = Arguments.createMap();
    final String roboto = "sans-serif";

    // In Android, the fontFamily determines the weight
    map.putString("fontFamily", suffix != null ? (roboto + suffix) : roboto);
    map.putInt("fontSize", fontSize);

    if (RNTextSizeConf.supportLetterSpacing()) {
        map.putDouble("letterSpacing", letterSpacing);
    }

    if (upcase && RNTextSizeConf.supportUpperCaseTransform()) {
        map.putString("textTransform", "uppercase");
    }

    return map;
}
 
Example 5
Source File: RNAGSMapView.java    From react-native-arcgis-mapview with MIT License 6 votes vote down vote up
private WritableMap createPointMap(MotionEvent e){
    android.graphics.Point screenPoint = new android.graphics.Point(((int) e.getX()), ((int) e.getY()));
    WritableMap screenPointMap = Arguments.createMap();
    screenPointMap.putInt("x",screenPoint.x);
    screenPointMap.putInt("y",screenPoint.y);
    Point mapPoint = mMapView.screenToLocation(screenPoint);
    WritableMap mapPointMap = Arguments.createMap();
    if (mapPoint != null) {
        Point latLongPoint = ((Point) GeometryEngine.project(mapPoint, SpatialReferences.getWgs84()));
        mapPointMap.putDouble("latitude", latLongPoint.getY());
        mapPointMap.putDouble("longitude", latLongPoint.getX());
    }
    WritableMap map = Arguments.createMap();
    map.putMap("screenPoint", screenPointMap);
    map.putMap("mapPoint",mapPointMap);
    return map;
}
 
Example 6
Source File: YouTubeView.java    From react-native-youtube with MIT License 5 votes vote down vote up
public void didChangeToQuality(String param) {
    WritableMap event = Arguments.createMap();
    event.putString("quality", param);
    event.putInt("target", getId());
    ReactContext reactContext = getReactContext();
    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "quality", event);
}
 
Example 7
Source File: ArgumentUtils.java    From react-native-pjsip with GNU General Public License v3.0 5 votes vote down vote up
private static WritableMap fromJsonObject(JsonObject object) {
    WritableMap result = new WritableNativeMap();

    for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
        Object value = fromJson(entry.getValue());

        if (value instanceof WritableMap) {
            result.putMap(entry.getKey(), (WritableMap) value);
        } else if (value instanceof WritableArray) {
            result.putArray(entry.getKey(), (WritableArray) value);
        } else if (value instanceof String) {
            result.putString(entry.getKey(), (String) value);
        } else if (value instanceof LazilyParsedNumber) {
            result.putInt(entry.getKey(), ((LazilyParsedNumber) value).intValue());
        } else if (value instanceof Integer) {
            result.putInt(entry.getKey(), (Integer) value);
        } else if (value instanceof Double) {
            result.putDouble(entry.getKey(), (Double) value);
        } else if (value instanceof Boolean) {
            result.putBoolean(entry.getKey(), (Boolean) value);
        } else {
            Log.d("ArgumentUtils", "Unknown type: " + value.getClass().getName());
            result.putNull(entry.getKey());
        }
    }

    return result;
}
 
Example 8
Source File: ReactTextInputEvent.java    From react-native-GPay with MIT License 5 votes vote down vote up
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  WritableMap range = Arguments.createMap();
  range.putDouble("start", mRangeStart);
  range.putDouble("end", mRangeEnd);

  eventData.putString("text", mText);
  eventData.putString("previousText", mPreviousText);
  eventData.putMap("range", range);

  eventData.putInt("target", getViewTag());
  return eventData;
}
 
Example 9
Source File: TcpSocketModule.java    From react-native-tcp-socket with MIT License 5 votes vote down vote up
@Override
public void onError(Integer id, String error) {
    WritableMap eventParams = Arguments.createMap();
    eventParams.putInt("id", id);
    eventParams.putString("error", error);

    sendEvent("error", eventParams);
}
 
Example 10
Source File: ActivityRecognizer.java    From react-native-activity-recognition with GNU General Public License v2.0 5 votes vote down vote up
private void onUpdate(ArrayList<DetectedActivity> detectedActivities) {
    WritableMap params = Arguments.createMap();
    for (DetectedActivity activity : detectedActivities) {
        params.putInt(DetectionService.getActivityString(activity.getType()), activity.getConfidence());
    }
    sendEvent("DetectedActivity", params);
}
 
Example 11
Source File: CustomTwilioVideoView.java    From react-native-twilio-video-webrtc with MIT License 5 votes vote down vote up
private WritableMap convertVideoTrackStats(RemoteVideoTrackStats vs) {
    WritableMap result = new WritableNativeMap();
    WritableMap dimensions = new WritableNativeMap();
    dimensions.putInt("height", vs.dimensions.height);
    dimensions.putInt("width", vs.dimensions.width);
    result.putMap("dimensions", dimensions);
    result.putInt("frameRate", vs.frameRate);
    convertBaseTrackStats(vs, result);
    convertRemoteTrackStats(vs, result);
    return result;
}
 
Example 12
Source File: ErrorEvent.java    From react-native-crosswalk-webview-plus with MIT License 5 votes vote down vote up
private WritableMap serializeEventData () {
    WritableMap eventData = Arguments.createMap();
    eventData.putInt("errorNumber", errorNumber);
    eventData.putString("errorMessage", errorMessage);
    eventData.putString("url", url);

    return eventData;
}
 
Example 13
Source File: ReactSliderEvent.java    From react-native-GPay with MIT License 5 votes vote down vote up
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  eventData.putInt("target", getViewTag());
  eventData.putDouble("value", getValue());
  eventData.putBoolean("fromUser", isFromUser());
  return eventData;
}
 
Example 14
Source File: CustomTwilioVideoView.java    From react-native-twilio-video-webrtc with MIT License 5 votes vote down vote up
private WritableMap convertLocalAudioTrackStats(LocalAudioTrackStats as) {
    WritableMap result = new WritableNativeMap();
    result.putInt("audioLevel", as.audioLevel);
    result.putInt("jitter", as.jitter);
    convertBaseTrackStats(as, result);
    convertLocalTrackStats(as, result);
    return result;
}
 
Example 15
Source File: BlobModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void onMessage(ByteString bytes, WritableMap params) {
  byte[] data = bytes.toByteArray();

  WritableMap blob = Arguments.createMap();

  blob.putString("blobId", store(data));
  blob.putInt("offset", 0);
  blob.putInt("size", data.length);

  params.putMap("data", blob);
  params.putString("type", "blob");
}
 
Example 16
Source File: ReactUsbSerialModule.java    From react-native-usbserial with MIT License 5 votes vote down vote up
@ReactMethod
public void getDeviceListAsync(Promise p) {

    try {
        UsbManager usbManager = getUsbManager();

        HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
        WritableArray deviceArray = Arguments.createArray();

        for (String key: usbDevices.keySet()) {
            UsbDevice device = usbDevices.get(key);
            WritableMap map = Arguments.createMap();

            map.putString("name", device.getDeviceName());
            map.putInt("deviceId", device.getDeviceId());
            map.putInt("productId", device.getProductId());
            map.putInt("vendorId", device.getVendorId());
            map.putString("deviceName", device.getDeviceName());

            deviceArray.pushMap(map);
        }

        p.resolve(deviceArray);
    } catch (Exception e) {
        p.reject(e);
    }
}
 
Example 17
Source File: RNSketchViewManager.java    From react-native-sketch-view with MIT License 5 votes vote down vote up
private void onSaveSketch(SketchViewContainer root, SketchFile sketchFile) {
  WritableMap event = Arguments.createMap();
  event.putString("localFilePath", sketchFile.localFilePath);
  event.putInt("imageWidth", sketchFile.width);
  event.putInt("imageHeight", sketchFile.height);
  sendEvent(root, "onSaveSketch", event);
}
 
Example 18
Source File: SocketServer.java    From react-native-sockets with MIT License 5 votes vote down vote up
@Override
public void run() {
    try {
        serverSocket = new ServerSocket(socketServerPORT);

        isOpen = true;
        WritableMap eventParams = Arguments.createMap();
        sendEvent(mReactContext, event_connect, eventParams);

        while (isOpen) {
            Socket socket = serverSocket.accept();
            count++;

            mClients.put(socket.getPort(), socket);

            eventParams = Arguments.createMap();
            eventParams.putInt("id", socket.getPort());

            sendEvent(mReactContext, event_clientConnect, eventParams);

            Log.d(eTag, "#" + count + " from " + socket.getInetAddress() + ":" + socket.getPort());

            Thread socketServerReplyThread = new Thread(new SocketServerReplyThread(socket));
            socketServerReplyThread.start();
        }
    } catch (IOException e) {
        handleIOException(e);
    }
}
 
Example 19
Source File: CustomTwilioVideoView.java    From react-native-twilio-video-webrtc with MIT License 5 votes vote down vote up
private WritableMap convertAudioTrackStats(RemoteAudioTrackStats as) {
    WritableMap result = new WritableNativeMap();
    result.putInt("audioLevel", as.audioLevel);
    result.putInt("jitter", as.jitter);
    convertBaseTrackStats(as, result);
    convertRemoteTrackStats(as, result);
    return result;
}
 
Example 20
Source File: ReactAztecBlurEvent.java    From react-native-aztec with GNU General Public License v2.0 4 votes vote down vote up
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  eventData.putInt("target", getViewTag());
  return eventData;
}