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

The following are Jave code examples for showing how to use putDouble() 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-scandit   File: ReactBridgeHelpers.java   Source Code and License Vote up 6 votes
public static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
    WritableMap map = new WritableNativeMap();

    Iterator<String> iterator = jsonObject.keys();
    while (iterator.hasNext()) {
        String key = iterator.next();
        Object value = jsonObject.get(key);
        if (value instanceof JSONObject) {
            map.putMap(key, convertJsonToMap((JSONObject) value));
        } else if (value instanceof JSONArray) {
            map.putArray(key, convertJsonToArray((JSONArray) value));
        } else if (value instanceof  Boolean) {
            map.putBoolean(key, (Boolean) value);
        } else if (value instanceof  Integer) {
            map.putInt(key, (Integer) value);
        } else if (value instanceof  Double) {
            map.putDouble(key, (Double) value);
        } else if (value instanceof String)  {
            map.putString(key, (String) value);
        } else {
            map.putString(key, value.toString());
        }
    }
    return map;
}
 
Example 2
Project: RNLearn_Project1   File: ReactWebViewManager.java   Source Code and License Vote up 6 votes
@Override
public void onReceivedError(
    WebView webView,
    int errorCode,
    String description,
    String failingUrl) {
  super.onReceivedError(webView, errorCode, description, failingUrl);
  mLastLoadFailed = true;

  // In case of an error JS side expect to get a finish event first, and then get an error event
  // Android WebView does it in the opposite way, so we need to simulate that behavior
  emitFinishEvent(webView, failingUrl);

  WritableMap eventData = createWebViewEvent(webView, failingUrl);
  eventData.putDouble("code", errorCode);
  eventData.putString("description", description);

  dispatchEvent(
      webView,
      new TopLoadingErrorEvent(webView.getId(), eventData));
}
 
Example 3
Project: RNLearn_Project1   File: ReactWebViewManager.java   Source Code and License Vote up 6 votes
@Override
public void onReceivedError(
    WebView webView,
    int errorCode,
    String description,
    String failingUrl) {
  super.onReceivedError(webView, errorCode, description, failingUrl);
  mLastLoadFailed = true;

  // In case of an error JS side expect to get a finish event first, and then get an error event
  // Android WebView does it in the opposite way, so we need to simulate that behavior
  emitFinishEvent(webView, failingUrl);

  WritableMap eventData = createWebViewEvent(webView, failingUrl);
  eventData.putDouble("code", errorCode);
  eventData.putString("description", description);

  dispatchEvent(
      webView,
      new TopLoadingErrorEvent(webView.getId(), eventData));
}
 
Example 4
Project: RNLearn_Project1   File: ReactRootView.java   Source Code and License Vote up 6 votes
private void checkForKeyboardEvents() {
  getRootView().getWindowVisibleDisplayFrame(mVisibleViewArea);
  final int heightDiff =
    DisplayMetricsHolder.getWindowDisplayMetrics().heightPixels - mVisibleViewArea.bottom;
  if (mKeyboardHeight != heightDiff && heightDiff > mMinKeyboardHeightDetected) {
    // keyboard is now showing, or the keyboard height has changed
    mKeyboardHeight = heightDiff;
    WritableMap params = Arguments.createMap();
    WritableMap coordinates = Arguments.createMap();
    coordinates.putDouble("screenY", PixelUtil.toDIPFromPixel(mVisibleViewArea.bottom));
    coordinates.putDouble("screenX", PixelUtil.toDIPFromPixel(mVisibleViewArea.left));
    coordinates.putDouble("width", PixelUtil.toDIPFromPixel(mVisibleViewArea.width()));
    coordinates.putDouble("height", PixelUtil.toDIPFromPixel(mKeyboardHeight));
    params.putMap("endCoordinates", coordinates);
    sendEvent("keyboardDidShow", params);
  } else if (mKeyboardHeight != 0 && heightDiff <= mMinKeyboardHeightDetected) {
    // keyboard is now hidden
    mKeyboardHeight = 0;
    sendEvent("keyboardDidHide", null);
  }
}
 
Example 5
Project: RNLearn_Project1   File: LocationModule.java   Source Code and License Vote up 6 votes
private static WritableMap locationToMap(Location location) {
  WritableMap map = Arguments.createMap();
  WritableMap coords = Arguments.createMap();
  coords.putDouble("latitude", location.getLatitude());
  coords.putDouble("longitude", location.getLongitude());
  coords.putDouble("altitude", location.getAltitude());
  coords.putDouble("accuracy", location.getAccuracy());
  coords.putDouble("heading", location.getBearing());
  coords.putDouble("speed", location.getSpeed());
  map.putMap("coords", coords);
  map.putDouble("timestamp", location.getTime());

  if (android.os.Build.VERSION.SDK_INT >= 18) {
    map.putBoolean("mocked", location.isFromMockProvider());
  }

  return map;
}
 
Example 6
Project: RNLearn_Project1   File: DeviceInfoModule.java   Source Code and License Vote up 6 votes
private WritableMap getDimensionsConstants() {
  DisplayMetrics windowDisplayMetrics = DisplayMetricsHolder.getWindowDisplayMetrics();
  DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics();

  WritableMap windowDisplayMetricsMap = Arguments.createMap();
  windowDisplayMetricsMap.putInt("width", windowDisplayMetrics.widthPixels);
  windowDisplayMetricsMap.putInt("height", windowDisplayMetrics.heightPixels);
  windowDisplayMetricsMap.putDouble("scale", windowDisplayMetrics.density);
  windowDisplayMetricsMap.putDouble("fontScale", mFontScale);
  windowDisplayMetricsMap.putDouble("densityDpi", windowDisplayMetrics.densityDpi);

  WritableMap screenDisplayMetricsMap = Arguments.createMap();
  screenDisplayMetricsMap.putInt("width", screenDisplayMetrics.widthPixels);
  screenDisplayMetricsMap.putInt("height", screenDisplayMetrics.heightPixels);
  screenDisplayMetricsMap.putDouble("scale", screenDisplayMetrics.density);
  screenDisplayMetricsMap.putDouble("fontScale", mFontScale);
  screenDisplayMetricsMap.putDouble("densityDpi", screenDisplayMetrics.densityDpi);

  WritableMap dimensionsMap = Arguments.createMap();
  dimensionsMap.putMap("windowPhysicalPixels", windowDisplayMetricsMap);
  dimensionsMap.putMap("screenPhysicalPixels", screenDisplayMetricsMap);

  return dimensionsMap;
}
 
Example 7
Project: RNLearn_Project1   File: ReactTextInputEvent.java   Source Code and License Vote up 5 votes
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 8
Project: RNLearn_Project1   File: ScrollEvent.java   Source Code and License Vote up 5 votes
private WritableMap serializeEventData() {
  WritableMap contentInset = Arguments.createMap();
  contentInset.putDouble("top", 0);
  contentInset.putDouble("bottom", 0);
  contentInset.putDouble("left", 0);
  contentInset.putDouble("right", 0);

  WritableMap contentOffset = Arguments.createMap();
  contentOffset.putDouble("x", PixelUtil.toDIPFromPixel(mScrollX));
  contentOffset.putDouble("y", PixelUtil.toDIPFromPixel(mScrollY));

  WritableMap contentSize = Arguments.createMap();
  contentSize.putDouble("width", PixelUtil.toDIPFromPixel(mContentWidth));
  contentSize.putDouble("height", PixelUtil.toDIPFromPixel(mContentHeight));

  WritableMap layoutMeasurement = Arguments.createMap();
  layoutMeasurement.putDouble("width", PixelUtil.toDIPFromPixel(mScrollViewWidth));
  layoutMeasurement.putDouble("height", PixelUtil.toDIPFromPixel(mScrollViewHeight));

  WritableMap event = Arguments.createMap();
  event.putMap("contentInset", contentInset);
  event.putMap("contentOffset", contentOffset);
  event.putMap("contentSize", contentSize);
  event.putMap("layoutMeasurement", layoutMeasurement);

  event.putInt("target", getViewTag());
  event.putBoolean("responderIgnoreScroll", true);
  return event;
}
 
Example 9
Project: RNLearn_Project1   File: DatePickerDialogTestCase.java   Source Code and License Vote up 5 votes
public void testPresetDate() {
  final WritableMap options = new WritableNativeMap();
  options.putDouble("date", getDateInMillis(2020, 5, 6));

  final DialogFragment datePickerFragment = showDialog(options);
  final DatePicker datePicker =
      ((DatePickerDialog) datePickerFragment.getDialog()).getDatePicker();

  assertEquals(2020, datePicker.getYear());
  assertEquals(5, datePicker.getMonth());
  assertEquals(6, datePicker.getDayOfMonth());
}
 
Example 10
Project: RNLearn_Project1   File: ContentSizeChangeEvent.java   Source Code and License Vote up 5 votes
@Override
public void dispatch(RCTEventEmitter rctEventEmitter) {
  WritableMap data = Arguments.createMap();
  data.putDouble("width", PixelUtil.toDIPFromPixel(mWidth));
  data.putDouble("height", PixelUtil.toDIPFromPixel(mHeight));
  rctEventEmitter.receiveEvent(getViewTag(), EVENT_NAME, data);
}
 
Example 11
Project: react-native-geo-fence   File: RNGeoFenceModule.java   Source Code and License Vote up 5 votes
/**
 * Resolves the pending promise for user current location request
 *
 * @param Location location to use for promise resolve
 *
 * @return void
 */
private void resolveLocationQueryPromise(Location location) {
    if (pendingPromise != null) {
        WritableMap writableMap = new WritableNativeMap();
        writableMap.putDouble("longitude", location.getLongitude());
        writableMap.putDouble("latitude", location.getLatitude());
        writableMap.putString("provider", location.getProvider());
        writableMap.putDouble("accuracy", location.getAccuracy());
        writableMap.putDouble("altitude", location.getAltitude());
        pendingPromise.resolve(writableMap);
    }
    pendingPromise = null;
}
 
Example 12
Project: react-native-android-text-to-speech   File: RNAndroidTextToSpeechModule.java   Source Code and License Vote up 5 votes
@ReactMethod
public void setDefaultPitch(float pitch, Promise promise) {
	if(notReady(promise)) return;

	int result = tts.setPitch(pitch);
	if(result == TextToSpeech.SUCCESS) {
		WritableMap map = Arguments.createMap();
		map.putString("status", "Success");
		map.putDouble("pitch", (double)pitch);
		promise.resolve(map);
	} else {
		promise.reject("error", "Unable to set pitch");
	}
}
 
Example 13
Project: react-native-stt   File: SpeechRecognitionListener.java   Source Code and License Vote up 5 votes
@Override
public void onRmsChanged(float rmsdB) {
  Logger.debug(TAG, "onRmsChanged: " + rmsdB);
  WritableMap data = Arguments.createMap();
  data.putDouble("rmsdB", rmsdB);
  emit(SPEECH_TO_TEXT, data);
}
 
Example 14
Project: RNLearn_Project1   File: ContentSizeChangeEvent.java   Source Code and License Vote up 5 votes
@Override
public void dispatch(RCTEventEmitter rctEventEmitter) {
  WritableMap data = Arguments.createMap();
  data.putDouble("width", PixelUtil.toDIPFromPixel(mWidth));
  data.putDouble("height", PixelUtil.toDIPFromPixel(mHeight));
  rctEventEmitter.receiveEvent(getViewTag(), EVENT_NAME, data);
}
 
Example 15
Project: RNLearn_Project1   File: ReactContentSizeChangedEvent.java   Source Code and License Vote up 5 votes
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();

  WritableMap contentSize = Arguments.createMap();
  contentSize.putDouble("width", mContentWidth);
  contentSize.putDouble("height", mContentHeight);
  eventData.putMap("contentSize", contentSize);

  eventData.putInt("target", getViewTag());
  return eventData;
}
 
Example 16
Project: react-native-twilio-chat   File: RCTConvert.java   Source Code and License Vote up 5 votes
public static WritableMap jsonToWritableMap(JSONObject jsonObject) {
    WritableMap writableMap = new WritableNativeMap();

    if (jsonObject == null) {
        return null;
    }


    Iterator<String> iterator = jsonObject.keys();
    if (!iterator.hasNext()) {
        return null;
    }


    try {
        while (iterator.hasNext()) {
            String key = iterator.next();
            Object value = jsonObject.get(key);
            if (value == null) {
                writableMap.putNull(key);
            } else if (value instanceof Boolean) {
                writableMap.putBoolean(key, (Boolean) value);
            } else if (value instanceof Integer) {
                writableMap.putInt(key, (Integer) value);
            } else if (value instanceof Double) {
                writableMap.putDouble(key, (Double) value);
            } else if (value instanceof String) {
                writableMap.putString(key, (String) value);
            } else if (value instanceof JSONObject) {
                writableMap.putMap(key, jsonToWritableMap((JSONObject) value));
            } else if (value instanceof JSONArray) {
                writableMap.putArray(key, jsonArrayToWritableArray((JSONArray) value));
            }
        }
    } catch (JSONException ex){
            // Do nothing and fail silently
    }

    return writableMap;
}
 
Example 17
Project: RNLearn_Project1   File: DrawerStateChangedEvent.java   Source Code and License Vote up 4 votes
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  eventData.putDouble("drawerState", getDrawerState());
  return eventData;
}
 
Example 18
Project: react-native-videoplayer   File: ReactVideoView.java   Source Code and License Vote up 4 votes
@Override
    public void onPrepared(MediaPlayer mp) {

        mMediaPlayerValid = true;
        mVideoDuration = mp.getDuration();

        WritableMap naturalSize = Arguments.createMap();
        naturalSize.putInt(EVENT_PROP_WIDTH, mp.getVideoWidth()*2);
        naturalSize.putInt(EVENT_PROP_HEIGHT, mp.getVideoHeight()*2);
//        if (mp.getVideoWidth() > mp.getVideoHeight())
//            naturalSize.putString(EVENT_PROP_ORIENTATION, "landscape");
//        else
//            naturalSize.putString(EVENT_PROP_ORIENTATION, "portrait");

        naturalSize.putString(EVENT_PROP_ORIENTATION, "landscape");
        WritableMap event = Arguments.createMap();
        event.putDouble(EVENT_PROP_DURATION, mVideoDuration / 1000.0);
        event.putDouble(EVENT_PROP_CURRENT_TIME, mp.getCurrentPosition() / 1000.0);
        event.putMap(EVENT_PROP_NATURALSIZE, naturalSize);
        // TODO: Actually check if you can.
        event.putBoolean(EVENT_PROP_FAST_FORWARD, true);
        event.putBoolean(EVENT_PROP_SLOW_FORWARD, true);
        event.putBoolean(EVENT_PROP_SLOW_REVERSE, true);
        event.putBoolean(EVENT_PROP_REVERSE, true);
        event.putBoolean(EVENT_PROP_FAST_FORWARD, true);
        event.putBoolean(EVENT_PROP_STEP_BACKWARD, true);
        event.putBoolean(EVENT_PROP_STEP_FORWARD, true);
        mEventEmitter.receiveEvent(getId(), Events.EVENT_LOAD.toString(), event);

        applyModifiers();

        if (mUseNativeControls) {
            initializeMediaControllerIfNeeded();
            mediaController.setMediaPlayer(this);
            mediaController.setAnchorView(this);

            videoControlHandler.post(new Runnable() {
                @Override
                public void run() {
                    mediaController.setEnabled(true);
                    mediaController.show();
                }
            });
        }
    }
 
Example 19
Project: RNLearn_Project1   File: DrawerStateChangedEvent.java   Source Code and License Vote up 4 votes
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  eventData.putDouble("drawerState", getDrawerState());
  return eventData;
}
 
Example 20
Project: RNLearn_Project1   File: DrawerSlideEvent.java   Source Code and License Vote up 4 votes
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  eventData.putDouble("offset", getOffset());
  return eventData;
}