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

The following are Jave code examples for showing how to use putInt() of the com.facebook.react.bridge.WritableMap 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-android-library-humaniq-api   File: DownloadModule.java   Source Code and License Vote up 7 votes
/**
 * Checks download progress.
 */
private void checkProgress() {
  DownloadManager.Query query = new DownloadManager.Query();
  query.setFilterById(enqueue);
  Cursor cursor = dm.query(query);
  if (!cursor.moveToFirst()) {
    cursor.close();
    return;
  }
  long reference = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID));

  int bytes_downloaded =
      cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
  int bytes_total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));

  int progress = (int) ((bytes_downloaded * 100l) / bytes_total);
      WritableMap writableMap = new WritableNativeMap();
      writableMap.putInt("progress", progress);
      sendEvent(writableMap);

  if(progress >= 100) {
    future.cancel(true);
  }
}
 
Example 2
Project: react-native-blue-manager   File: Peripheral.java   Source Code and License Vote up 6 votes
public WritableMap asWritableMap() {

		WritableMap map = Arguments.createMap();

		try {
			map.putString("name", device.getName());
			map.putBoolean("connected", connected);
			map.putString("id", device.getAddress()); // mac address
			map.putMap("advertising", byteArrayToWritableMap(advertisingData));
			map.putInt("rssi", advertisingRSSI);
		} catch (Exception e) { // this shouldn't happen
			e.printStackTrace();
		}

		return map;
	}
 
Example 3
Project: RNLearn_Project1   File: NativeAnimatedModule.java   Source Code and License Vote up 6 votes
@ReactMethod
public void startListeningToAnimatedNodeValue(final int tag) {
  final AnimatedNodeValueListener listener = new AnimatedNodeValueListener() {
    public void onValueUpdate(double value) {
      WritableMap onAnimatedValueData = Arguments.createMap();
      onAnimatedValueData.putInt("tag", tag);
      onAnimatedValueData.putDouble("value", value);
      getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
          .emit("onAnimatedValueUpdate", onAnimatedValueData);
    }
  };

  mOperations.add(new UIThreadOperation() {
    @Override
    public void execute(NativeAnimatedNodesManager animatedNodesManager) {
      animatedNodesManager.startListeningToAnimatedNodeValue(tag, listener);
    }
  });
}
 
Example 4
Project: react-native-scandit   File: ScanditBarcodeHelpers.java   Source Code and License Vote up 5 votes
static public WritableMap barcodeToWritableMap(Barcode barcode) {
    WritableMap map = Arguments.createMap();
    map.putInt    ("compositeFlag",    barcode.getCompositeFlag());
    map.putString ("data",             barcode.getData());
    map.putBoolean("isRecognized",     barcode.isRecognized());
    map.putBoolean("isGs1DataCarrier", barcode.isGs1DataCarrier());
    map.putInt    ("symbolCount",      barcode.getSymbolCount());
    map.putInt    ("symbology",        barcode.getSymbology());
    map.putString ("symbologyName",    barcode.getSymbologyName());
    map.putMap    ("location",         quadrilateralToWritableMap(barcode.getLocation()));
    return map;
}
 
Example 5
Project: RNLearn_Project1   File: PositionError.java   Source Code and License Vote up 5 votes
public static WritableMap buildError(int code, String message) {
  WritableMap error = Arguments.createMap();
  error.putInt("code", code);
  if (message != null) {
    error.putString("message", message);
  }
  return error;
}
 
Example 6
Project: react-native-streaming-audio-player   File: RNAudioPlayerModule.java   Source Code and License Vote up 5 votes
@Override
public void onReceive(Context context, Intent intent) {
    WritableMap params = Arguments.createMap();

    switch(intent.getAction()) {
        case "update-position-event":
            int nCurrentPosition = intent.getIntExtra("currentPosition", 0);
            params.putInt("currentPosition", nCurrentPosition);
            sendEvent("onPlaybackPositionUpdated", params);
            break;
        case "change-playback-action-event":
            String strAction = intent.getStringExtra("action");
            params.putString("action", strAction);
            sendEvent("onPlaybackActionChanged", params);
            break;
        case "change-playback-state-event":
            int nState = intent.getIntExtra("state", 0);
            if (mStateMap.containsKey(nState)) {
                params.putString("state", mStateMap.get(nState));
                sendEvent("onPlaybackStateChanged", params);
            }
            break;
        case "playback-error-event":
            String strError = intent.getStringExtra("msg");
            params.putString("msg", strError);
            sendEvent("onPlaybackError", params);
        default:
            break;
    }
}
 
Example 7
Project: react-native-webrtc   File: PeerConnectionObserver.java   Source Code and License Vote up 5 votes
@Override
public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) {
    WritableMap params = Arguments.createMap();
    params.putInt("id", id);
    params.putString("iceConnectionState", iceConnectionStateString(iceConnectionState));

    webRTCModule.sendEvent("peerConnectionIceConnectionChanged", params);
}
 
Example 8
Project: react-native-webrtc   File: PeerConnectionObserver.java   Source Code and License Vote up 5 votes
@Override
public void onDataChannel(DataChannel dataChannel) {
    // XXX Unfortunately, the Java WebRTC API doesn't expose the id
    // of the underlying C++/native DataChannel (even though the
    // WebRTC standard defines the DataChannel.id property). As a
    // workaround, generated an id which will surely not clash with
    // the ids of the remotely-opened (and standard-compliant
    // locally-opened) DataChannels.
    int dataChannelId = -1;
    // The RTCDataChannel.id space is limited to unsigned short by
    // the standard:
    // https://www.w3.org/TR/webrtc/#dom-datachannel-id.
    // Additionally, 65535 is reserved due to SCTP INIT and
    // INIT-ACK chunks only allowing a maximum of 65535 streams to
    // be negotiated (as defined by the WebRTC Data Channel
    // Establishment Protocol).
    for (int i = 65536; i <= Integer.MAX_VALUE; ++i) {
        if (null == dataChannels.get(i, null)) {
            dataChannelId = i;
            break;
        }
    }
    if (-1 == dataChannelId) {
      return;
    }

    WritableMap dataChannelParams = Arguments.createMap();
    dataChannelParams.putInt("id", dataChannelId);
    dataChannelParams.putString("label", dataChannel.label());
    WritableMap params = Arguments.createMap();
    params.putInt("id", id);
    params.putMap("dataChannel", dataChannelParams);

    dataChannels.put(dataChannelId, dataChannel);
    registerDataChannelObserver(dataChannelId, dataChannel);

    webRTCModule.sendEvent("peerConnectionDidOpenDataChannel", params);
}
 
Example 9
Project: react-native-ibeacons   File: BeaconsAndroidModule.java   Source Code and License Vote up 5 votes
@ReactMethod
public void getMonitoredRegions(Callback callback) {
    WritableArray array = new WritableNativeArray();
    for (Region region: mBeaconManager.getMonitoredRegions()) {
        WritableMap map = new WritableNativeMap();
        map.putString("identifier", region.getUniqueId());
        map.putString("uuid", region.getId1().toString());
        map.putInt("major", region.getId2() != null ? region.getId2().toInt() : 0);
        map.putInt("minor", region.getId3() != null ? region.getId3().toInt() : 0);
        array.pushMap(map);
    }
    callback.invoke(array);
}
 
Example 10
Project: RNLearn_Project1   File: ReactSliderEvent.java   Source Code and License Vote up 5 votes
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  eventData.putInt("target", getViewTag());
  eventData.putDouble("value", getValue());
  eventData.putBoolean("fromUser", isFromUser());
  return eventData;
}
 
Example 11
Project: react-native-stt   File: SpeechRecognitionListener.java   Source Code and License Vote up 5 votes
@Override
public void onEvent(int eventType, Bundle params) {
  Logger.debug(TAG, "onEvent: " + eventType);
  WritableMap data = Arguments.createMap();
  data.putInt("eventType", eventType);
  data.putMap("params", Arguments.fromBundle(params));
  emit(SPEECH_TO_TEXT, data);
}
 
Example 12
Project: react-native-stt   File: SpeechRecognitionListener.java   Source Code and License Vote up 5 votes
@Override
public void onError(int error) {
  Logger.error(TAG, "onError: " + error);
  WritableMap data = Arguments.createMap();
  data.putInt("error", error);
  emit(SPEECH_TO_TEXT, data);
}
 
Example 13
Project: react-native-sketch-view   File: RNSketchViewManager.java   Source Code and License Vote up 5 votes
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 14
Project: react-native-android-speech-recognizer   File: ListenerMapRecognitionListener.java   Source Code and License Vote up 5 votes
@Override
public void onError(int error) {
  Log.i(TAG, "onError: " + error);
  if (isEnabled(ListenerEvents.ON_ERROR)) {
    WritableMap data = Arguments.createMap();
    data.putInt("error", error);
    emit(ListenerEvents.ON_ERROR, data);
  }
}
 
Example 15
Project: react-native-android-new-crosswalk   File: ProgressEvent.java   Source Code and License Vote up 4 votes
private WritableMap serializeEventData () {
    WritableMap eventData = Arguments.createMap();
    eventData.putInt("progress", progress);

    return eventData;
}
 
Example 16
Project: RNLearn_Project1   File: WebSocketModule.java   Source Code and License Vote up 4 votes
private void notifyWebSocketFailed(int id, String message) {
  WritableMap params = Arguments.createMap();
  params.putInt("id", id);
  params.putString("message", message);
  sendEvent("websocketFailed", params);
}
 
Example 17
Project: react-native-datepicker-component-android   File: RNDatePickerComponentEvent.java   Source Code and License Vote up 4 votes
private WritableMap serializeEventData() {
    WritableMap eventData = Arguments.createMap();
    eventData.putInt("target", getViewTag());
    eventData.putString("value", this.date);
    return eventData;
}
 
Example 18
Project: RNLearn_Project1   File: ReactSwitchEvent.java   Source Code and License Vote up 4 votes
private WritableMap serializeEventData() {
    WritableMap eventData = Arguments.createMap();
    eventData.putInt("target", getViewTag());
    eventData.putBoolean("value", getIsChecked());
    return eventData;
}
 
Example 19
Project: RNLearn_Project1   File: ReactTextInputBlurEvent.java   Source Code and License Vote up 4 votes
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  eventData.putInt("target", getViewTag());
  return eventData;
}
 
Example 20
Project: react-native-tabbed-view-pager-android   File: PageScrollEvent.java   Source Code and License Vote up 4 votes
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  eventData.putInt("position", mPosition);
  eventData.putDouble("offset", mOffset);
  return eventData;
}