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

The following are Jave code examples for showing how to use putMap() 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-twilio-chat   File: RCTConvert.java   Source Code and License Vote up 6 votes
public static WritableMap Member(Member member) {
    WritableMap map = Arguments.createMap();

    map.putMap("userInfo", UserInfo(member.getUserInfo()));
    if (member.getLastConsumedMessageIndex() == null) {
        map.putNull("lastConsumedMessageIndex");
    }
    else {
        map.putInt("lastConsumedMessageIndex", member.getLastConsumedMessageIndex().intValue());
    }
    if (member.getLastConsumptionTimestamp() == null) {
        map.putNull("lastConsumptionTimestamp");
    }
    else {
        map.putString("lastConsumptionTimestamp", member.getLastConsumptionTimestamp());
    }

    return map;
}
 
Example 2
Project: react-native-nfc-manager   File: JsonConvert.java   Source Code and License Vote up 6 votes
public static WritableMap jsonToReact(JSONObject jsonObject) throws JSONException {
    WritableMap writableMap = Arguments.createMap();
    Iterator iterator = jsonObject.keys();
    while(iterator.hasNext()) {
        String key = (String) iterator.next();
        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,jsonToReact(jsonObject.getJSONObject(key)));
        } else if (value instanceof JSONArray){
            writableMap.putArray(key, jsonToReact(jsonObject.getJSONArray(key)));
        } else if (value == JSONObject.NULL){
            writableMap.putNull(key);
        }
    }

    return writableMap;
}
 
Example 3
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 4
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 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: react-native-twilio-chat   File: RCTConvert.java   Source Code and License Vote up 6 votes
public static WritableMap Channel(Channel channel) {
    WritableMap map = Arguments.createMap();

    map.putString("sid", channel.getSid());
    map.putString("friendlyName", channel.getFriendlyName());
    map.putString("uniqueName", channel.getUniqueName());
    map.putString("status", channel.getStatus().toString());
    map.putString("type", channel.getType().toString());
    map.putString("synchronizationStatus", channel.getSynchronizationStatus().toString());
    map.putString("dateCreated", channel.getDateCreated().toString());
    map.putString("dateUpdated", channel.getDateUpdated().toString());
    WritableMap attributes = Arguments.createMap();
    try {
        attributes = jsonToWritableMap(channel.getAttributes());
    }
    catch (JSONException e) {}
    map.putMap("attributes", attributes);
    return map;
}
 
Example 7
Project: react-native-telephony   File: TelephonyModule.java   Source Code and License Vote up 6 votes
@Override
public void phoneSignalStrengthsUpdated(SignalStrength signalStrength) {
    WritableMap map = Arguments.createMap();
    map.putInt("cdmaDbm", signalStrength.getCdmaDbm());
    map.putInt("cdmaEcio()", signalStrength.getCdmaEcio());
    map.putInt("evdoDbm", signalStrength.getEvdoDbm());
    map.putInt("evdoEcio", signalStrength.getEvdoEcio());
    map.putInt("evdoSnr", signalStrength.getEvdoSnr());
    map.putInt("gsmBitErrorRate", signalStrength.getGsmBitErrorRate());
    map.putInt("gsmSignalStrength", signalStrength.getGsmSignalStrength());
    map.putBoolean("gsm", signalStrength.isGsm());

    WritableMap result = Arguments.createMap();
    result.putString("type", "LISTEN_SIGNAL_STRENGTHS");
    result.putMap("data", map);

    sendEvent(PHONE_STATE_LISTENER, result);
}
 
Example 8
Project: RNLearn_Project1   File: CameraRollManager.java   Source Code and License Vote up 5 votes
private static boolean putImageInfo(
    ContentResolver resolver,
    Cursor photos,
    WritableMap node,
    int idIndex,
    int widthIndex,
    int heightIndex) {
  WritableMap image = new WritableNativeMap();
  Uri photoUri = Uri.withAppendedPath(
      Images.Media.EXTERNAL_CONTENT_URI,
      photos.getString(idIndex));
  image.putString("uri", photoUri.toString());
  float width = -1;
  float height = -1;
  if (IS_JELLY_BEAN_OR_LATER) {
    width = photos.getInt(widthIndex);
    height = photos.getInt(heightIndex);
  }
  if (width <= 0 || height <= 0) {
    try {
      AssetFileDescriptor photoDescriptor = resolver.openAssetFileDescriptor(photoUri, "r");
      BitmapFactory.Options options = new BitmapFactory.Options();
      // Set inJustDecodeBounds to true so we don't actually load the Bitmap, but only get its
      // dimensions instead.
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFileDescriptor(photoDescriptor.getFileDescriptor(), null, options);
      photoDescriptor.close();

      width = options.outWidth;
      height = options.outHeight;
    } catch (IOException e) {
      FLog.e(ReactConstants.TAG, "Could not get width/height for " + photoUri.toString(), e);
      return false;
    }
  }
  image.putDouble("width", width);
  image.putDouble("height", height);
  node.putMap("image", image);
  return true;
}
 
Example 9
Project: react-native-stt   File: SpeechRecognitionListener.java   Source Code and License Vote up 5 votes
@Override
public void onReadyForSpeech(Bundle params) {
  Logger.debug(TAG, "onReadyForSpeech: " + params);
  WritableMap data = Arguments.createMap();
  data.putMap("params", Arguments.fromBundle(params));
  emit(SPEECH_TO_TEXT, data);
}
 
Example 10
Project: react-native-videoplayer   File: ReactVideoView.java   Source Code and License Vote up 5 votes
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {

    WritableMap error = Arguments.createMap();
    error.putInt(EVENT_PROP_WHAT, what);
    error.putInt(EVENT_PROP_EXTRA, extra);
    WritableMap event = Arguments.createMap();
    event.putMap(EVENT_PROP_ERROR, error);
    mEventEmitter.receiveEvent(getId(), Events.EVENT_ERROR.toString(), event);
    return true;
}
 
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-mssql   File: MapUtil.java   Source Code and License Vote up 5 votes
public static WritableMap toWritableMap(Map<String, Object> map) {
  WritableMap writableMap = Arguments.createMap();
  Iterator iterator = map.entrySet().iterator();

  while (iterator.hasNext()) {
    Map.Entry pair = (Map.Entry)iterator.next();
    Object value = pair.getValue();

    if (value == null) {
      writableMap.putNull((String) pair.getKey());
    } else if (value instanceof Boolean) {
      writableMap.putBoolean((String) pair.getKey(), (Boolean) value);
    } else if (value instanceof Double) {
      writableMap.putDouble((String) pair.getKey(), (Double) value);
    } else if (value instanceof Integer) {
      writableMap.putInt((String) pair.getKey(), (Integer) value);
    } else if (value instanceof String) {
      writableMap.putString((String) pair.getKey(), (String) value);
    } else if (value instanceof Map) {
      writableMap.putMap((String) pair.getKey(), MapUtil.toWritableMap((Map<String, Object>) value));
    } else if (value.getClass() != null && value.getClass().isArray()) {
      writableMap.putArray((String) pair.getKey(), ArrayUtil.toWritableArray((Object[]) value));
    }

    iterator.remove();
  }

  return writableMap;
}
 
Example 13
Project: react-native-sketch-view   File: RNSketchViewManager.java   Source Code and License Vote up 5 votes
private void sendEvent(View view, String eventType, WritableMap event) {
  WritableMap nativeEvent = Arguments.createMap();
  nativeEvent.putString("type", eventType);
  nativeEvent.putMap("event", event);
  ReactContext reactContext = (ReactContext) view.getContext();
  reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(view.getId(), "topChange", nativeEvent);
}
 
Example 14
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 15
Project: react-native-twilio-chat   File: RCTConvert.java   Source Code and License Vote up 5 votes
public static WritableMap UserInfo(UserInfo userInfo) {
    WritableMap map = Arguments.createMap();

    map.putString("identity", userInfo.getIdentity());
    map.putString("friendlyName", userInfo.getFriendlyName());
    map.putMap("attributes", jsonToWritableMap(userInfo.getAttributes()));
    map.putBoolean("isOnline", userInfo.isOnline());
    map.putBoolean("isNotifiable", userInfo.isNotifiable());

    return map;
}
 
Example 16
Project: RNLearn_Project1   File: CameraRollManager.java   Source Code and License Vote up 5 votes
private static void putLocationInfo(
    Cursor photos,
    WritableMap node,
    int longitudeIndex,
    int latitudeIndex) {
  double longitude = photos.getDouble(longitudeIndex);
  double latitude = photos.getDouble(latitudeIndex);
  if (longitude > 0 || latitude > 0) {
    WritableMap location = new WritableNativeMap();
    location.putDouble("longitude", longitude);
    location.putDouble("latitude", latitude);
    node.putMap("location", location);
  }
}
 
Example 17
Project: RNLearn_Project1   File: CameraRollManager.java   Source Code and License Vote up 5 votes
private static void putPageInfo(Cursor photos, WritableMap response, int limit) {
  WritableMap pageInfo = new WritableNativeMap();
  pageInfo.putBoolean("has_next_page", limit < photos.getCount());
  if (limit < photos.getCount()) {
    photos.moveToPosition(limit - 1);
    pageInfo.putString(
        "end_cursor",
        photos.getString(photos.getColumnIndex(Images.Media.DATE_TAKEN)));
  }
  response.putMap("page_info", pageInfo);
}
 
Example 18
Project: RNLearn_Project1   File: CameraRollManager.java   Source Code and License Vote up 5 votes
private static void putEdges(
    ContentResolver resolver,
    Cursor photos,
    WritableMap response,
    int limit) {
  WritableArray edges = new WritableNativeArray();
  photos.moveToFirst();
  int idIndex = photos.getColumnIndex(Images.Media._ID);
  int mimeTypeIndex = photos.getColumnIndex(Images.Media.MIME_TYPE);
  int groupNameIndex = photos.getColumnIndex(Images.Media.BUCKET_DISPLAY_NAME);
  int dateTakenIndex = photos.getColumnIndex(Images.Media.DATE_TAKEN);
  int widthIndex = IS_JELLY_BEAN_OR_LATER ? photos.getColumnIndex(Images.Media.WIDTH) : -1;
  int heightIndex = IS_JELLY_BEAN_OR_LATER ? photos.getColumnIndex(Images.Media.HEIGHT) : -1;
  int longitudeIndex = photos.getColumnIndex(Images.Media.LONGITUDE);
  int latitudeIndex = photos.getColumnIndex(Images.Media.LATITUDE);

  for (int i = 0; i < limit && !photos.isAfterLast(); i++) {
    WritableMap edge = new WritableNativeMap();
    WritableMap node = new WritableNativeMap();
    boolean imageInfoSuccess =
        putImageInfo(resolver, photos, node, idIndex, widthIndex, heightIndex);
    if (imageInfoSuccess) {
      putBasicNodeInfo(photos, node, mimeTypeIndex, groupNameIndex, dateTakenIndex);
      putLocationInfo(photos, node, longitudeIndex, latitudeIndex);

      edge.putMap("node", node);
      edges.pushMap(edge);
    } else {
      // we skipped an image because we couldn't get its details (e.g. width/height), so we
      // decrement i in order to correctly reach the limit, if the cursor has enough rows
      i--;
    }
    photos.moveToNext();
  }
  response.putArray("edges", edges);
}
 
Example 19
Project: react-native-region-monitor   File: RNRegionTransitionService.java   Source Code and License Vote up 4 votes
@Override
@Nullable
protected HeadlessJsTaskConfig getTaskConfig(Intent intent)
{
	if (intent.getExtras() == null)
	{
		return null;
	}

	GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);

	if (geofencingEvent.hasError())
	{
		// Suppress geofencing event with error
		Log.d(TAG, "Suppress geocoding event with error");
		return null;
	}

	WritableMap location = Arguments.createMap();
	location.putDouble("latitude", geofencingEvent.getTriggeringLocation().getLatitude());
	location.putDouble("longitude", geofencingEvent.getTriggeringLocation().getLongitude());

	WritableMap region = Arguments.createMap();
	region.putString("identifier", geofencingEvent.getTriggeringGeofences().get(0).getRequestId());

	WritableArray regionIdentifiers = Arguments.createArray();
	for (Geofence triggered: geofencingEvent.getTriggeringGeofences())
	{
		regionIdentifiers.pushString(triggered.getRequestId());
	}
	region.putArray("identifiers", regionIdentifiers);

	WritableMap jsArgs = Arguments.createMap();
	jsArgs.putMap("location", location);
	jsArgs.putMap("region", region);
	jsArgs.putBoolean("didEnter", geofencingEvent.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER);
	jsArgs.putBoolean("didExit", geofencingEvent.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_EXIT);
	//jsArgs.putBoolean("didDwell", geofencingEvent.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_DWELL);

	Log.d(TAG, "Report geofencing event to JS: " + jsArgs);
	return new HeadlessJsTaskConfig(RNRegionMonitorModule.TRANSITION_TASK_NAME, jsArgs, 0, true);
}
 
Example 20
Project: react-native-cameraroll   File: RNCameraRollModule.java   Source Code and License Vote up 4 votes
private static WritableArray buildAssets(Cursor assetsCursor, WritableMap response,
    int limit) {
    assetsCursor.moveToFirst();
    int idIndex = assetsCursor.getColumnIndex(Images.Media._ID);
    int mimeTypeIndex = assetsCursor.getColumnIndex(Images.Media.MIME_TYPE);
    int dateTakenIndex = assetsCursor.getColumnIndex(Images.Media.DATE_TAKEN);
    int widthIndex = assetsCursor.getColumnIndex(Images.Media.WIDTH);
    int heightIndex = assetsCursor.getColumnIndex(Images.Media.HEIGHT);
    int longitudeIndex = assetsCursor.getColumnIndex(Images.Media.LONGITUDE);
    int latitudeIndex = assetsCursor.getColumnIndex(Images.Media.LATITUDE);
    int filenameIndex = assetsCursor.getColumnIndex(Images.Media.DISPLAY_NAME);

    WritableArray assets = new WritableNativeArray();
    for (int i = 0; i < limit && !assetsCursor.isAfterLast(); i++) {
        WritableMap asset = new WritableNativeMap();
        asset.putDouble("width", assetsCursor.getInt(widthIndex));
        asset.putDouble("height", assetsCursor.getInt(heightIndex));
        asset.putString("filename", assetsCursor.getString(filenameIndex));
        asset.putDouble("timestamp", assetsCursor.getLong(dateTakenIndex) / 1000d);

        String mimeType = assetsCursor.getString(mimeTypeIndex);
        if (mimeType.startsWith("image/")) {
            Uri photoUri = Uri.withAppendedPath(Images.Media.EXTERNAL_CONTENT_URI,
                    assetsCursor.getString(idIndex));
            asset.putString("uri", photoUri.toString());
            asset.putString("type", "image");
        } else {
            Uri videoUri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                    assetsCursor.getString(idIndex));
            asset.putString("uri", videoUri.toString());
            asset.putString("type", "video");
        }

        double longitude = assetsCursor.getDouble(longitudeIndex);
        double latitude = assetsCursor.getDouble(latitudeIndex);
        if (longitude > 0 || latitude > 0) {
            WritableMap location = new WritableNativeMap();
            location.putDouble("longitude", longitude);
            location.putDouble("latitude", latitude);
            asset.putMap("location", location);
        }

        assets.pushMap(asset);
        assetsCursor.moveToNext();
    }
    return assets;
}