Java Code Examples for com.facebook.react.bridge.ReadableMap.getString()

The following are Jave code examples for showing how to use getString() of the com.facebook.react.bridge.ReadableMap 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: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   Source Code and License Vote up 6 votes
private void mapGetByType(ReadableMap map, String key, String typeToAskFor) {
  if (typeToAskFor.equals("double")) {
    map.getDouble(key);
  } else if (typeToAskFor.equals("int")) {
    map.getInt(key);
  } else if (typeToAskFor.equals("string")) {
    map.getString(key);
  } else if (typeToAskFor.equals("array")) {
    map.getArray(key);
  } else if (typeToAskFor.equals("map")) {
    map.getMap(key);
  } else if (typeToAskFor.equals("boolean")) {
    map.getBoolean(key);
  } else {
    throw new RuntimeException("Unknown type: " + typeToAskFor);
  }
}
 
Example 2
Project: react-native-webrtc   File: WebRTCModule.java   Source Code and License Vote up 6 votes
@ReactMethod
public void peerConnectionAddICECandidate(ReadableMap candidateMap, final int id, final Callback callback) {
    boolean result = false;
    PeerConnection peerConnection = getPeerConnection(id);
    Log.d(TAG, "peerConnectionAddICECandidate() start");
    if (peerConnection != null) {
        IceCandidate candidate = new IceCandidate(
            candidateMap.getString("sdpMid"),
            candidateMap.getInt("sdpMLineIndex"),
            candidateMap.getString("candidate")
        );
        result = peerConnection.addIceCandidate(candidate);
    } else {
        Log.d(TAG, "peerConnectionAddICECandidate() peerConnection is null");
    }
    callback.invoke(result);
    Log.d(TAG, "peerConnectionAddICECandidate() end");
}
 
Example 3
Project: RNLearn_Project1   File: ReactToolbar.java   Source Code and License Vote up 6 votes
/**
 * Sets an icon for a specific icon source. If the uri indicates an icon
 * to be somewhere remote (http/https) or on the local filesystem, it uses fresco to load it.
 * Otherwise it loads the Drawable from the Resources and directly returns it via a callback
 */
private void setIconSource(ReadableMap source, IconControllerListener controllerListener, DraweeHolder holder) {

  String uri = source != null ? source.getString(PROP_ICON_URI) : null;

  if (uri == null) {
    controllerListener.setIconImageInfo(null);
    controllerListener.setDrawable(null);
  } else if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("file://")) {
    controllerListener.setIconImageInfo(getIconImageInfo(source));
    DraweeController controller = Fresco.newDraweeControllerBuilder()
            .setUri(Uri.parse(uri))
            .setControllerListener(controllerListener)
            .setOldController(holder.getController())
            .build();
    holder.setController(controller);
    holder.getTopLevelDrawable().setVisible(true, true);
  } else {
    controllerListener.setDrawable(getDrawableByName(uri));
  }

}
 
Example 4
Project: RNLearn_Project1   File: TransformHelper.java   Source Code and License Vote up 6 votes
private static double convertToRadians(ReadableMap transformMap, String key) {
  double value;
  boolean inRadians = true;
  if (transformMap.getType(key) == ReadableType.String) {
    String stringValue = transformMap.getString(key);
    if (stringValue.endsWith("rad")) {
      stringValue = stringValue.substring(0, stringValue.length() - 3);
    } else if (stringValue.endsWith("deg")) {
      inRadians = false;
      stringValue = stringValue.substring(0, stringValue.length() - 3);
    }
    value = Float.parseFloat(stringValue);
  } else {
    value = transformMap.getDouble(key);
  }
  return inRadians ? value : MatrixMathHelper.degreesToRadians(value);
}
 
Example 5
Project: react-native-android-piliplayer   File: PLVideoTextureViewManager.java   Source Code and License Vote up 6 votes
/**
 * 设置source属性,包括是否是直播流,解码类型,准备时长,是否有缓存等
 *
 * @param plVideoTextureView
 * @param source
 */
@ReactProp(name = "source")
public void setSource(PLVideoTextureView plVideoTextureView, ReadableMap source) {
    AVOptions avOptions = new AVOptions();
     uri = source.getString("uri");//视频连接地址
    //得到解码类型
    int mediaCodec = source.hasKey("mediaCodec") ? source.getInt("mediaCodec") : AVOptions.MEDIA_CODEC_SW_DECODE;
    //得到视频准备时间
    int timeout = source.hasKey("timeout") ? source.getInt("timeout") : 10 * 1000;
    //得到是否是直播流
    boolean liveStreaming = source.hasKey("liveStreaming") ? source.getBoolean("liveStreaming") : false;
    //得到是否应用缓存
    boolean cache = source.hasKey("cache") ? source.getBoolean("cache") : false;
    boolean started=source.hasKey("started")?source.getBoolean("started"):true;
    avOptions.setInteger(AVOptions.KEY_MEDIACODEC, mediaCodec);
    avOptions.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, timeout);
    avOptions.setInteger(AVOptions.KEY_LIVE_STREAMING, liveStreaming ? 1 : 0);
    if (!liveStreaming && cache) {
        avOptions.setString(AVOptions.KEY_CACHE_DIR, Config.DEFAULT_CACHE_DIR);
    }
    plVideoTextureView.setAVOptions(avOptions);
    //MediaController mediaController = new MediaController(themedReactContext, !liveStreaming, liveStreaming);
   // plVideoTextureView.setMediaController(mediaController);
    plVideoTextureView.setVideoPath(uri);
}
 
Example 6
Project: RNLearn_Project1   File: TransformHelper.java   Source Code and License Vote up 6 votes
private static double convertToRadians(ReadableMap transformMap, String key) {
  double value;
  boolean inRadians = true;
  if (transformMap.getType(key) == ReadableType.String) {
    String stringValue = transformMap.getString(key);
    if (stringValue.endsWith("rad")) {
      stringValue = stringValue.substring(0, stringValue.length() - 3);
    } else if (stringValue.endsWith("deg")) {
      inRadians = false;
      stringValue = stringValue.substring(0, stringValue.length() - 3);
    }
    value = Float.parseFloat(stringValue);
  } else {
    value = transformMap.getDouble(key);
  }
  return inRadians ? value : MatrixMathHelper.degreesToRadians(value);
}
 
Example 7
Project: react-native-twilio-chat   File: RCTTwilioChatChannels.java   Source Code and License Vote up 6 votes
@ReactMethod
public void createChannel(ReadableMap options, final Promise promise) {
    final JSONObject attributes = RCTConvert.readableMapToJson(options.getMap("attributes"));
    final String uniqueName = options.getString("uniqueName");
    String friendlyName = options.getString("friendlyName");
    Channel.ChannelType type = (options.getString("type").compareTo("CHANNEL_TYPE_PRIVATE") == 0) ? Channel.ChannelType.PRIVATE : Channel.ChannelType.PUBLIC;

    channels().channelBuilder()
            .withUniqueName(uniqueName)
            .withFriendlyName(friendlyName)
            .withType(type)
            .withAttributes(attributes)
            .build(new CallbackListener<Channel>() {
                @Override
                public void onError(final ErrorInfo errorInfo) {
                    super.onError(errorInfo);
                    promise.reject("create-channel-error", "Error occurred while attempting to createChannel.");
                }

                @Override
                public void onSuccess(final Channel newChannel) {
                    promise.resolve(RCTConvert.Channel(newChannel));
                }
            });
}
 
Example 8
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   Source Code and License Vote up 6 votes
private void mapGetByType(ReadableMap map, String key, String typeToAskFor) {
  if (typeToAskFor.equals("double")) {
    map.getDouble(key);
  } else if (typeToAskFor.equals("int")) {
    map.getInt(key);
  } else if (typeToAskFor.equals("string")) {
    map.getString(key);
  } else if (typeToAskFor.equals("array")) {
    map.getArray(key);
  } else if (typeToAskFor.equals("map")) {
    map.getMap(key);
  } else if (typeToAskFor.equals("boolean")) {
    map.getBoolean(key);
  } else {
    throw new RuntimeException("Unknown type: " + typeToAskFor);
  }
}
 
Example 9
Project: RNLearn_Project1   File: ReactOkHttpNetworkFetcher.java   Source Code and License Vote up 5 votes
private Map<String, String> getHeaders(ReadableMap readableMap) {
  if (readableMap == null) {
      return null;
  }
  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
  Map<String, String> map = new HashMap<>();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    String value = readableMap.getString(key);
    map.put(key, value);
  }
  return map;
}
 
Example 10
Project: react-native-mail-compose   File: RNMailComposeModule.java   Source Code and License Vote up 5 votes
private byte[] getBlobFromUri(ReadableMap map, String key) {
    if (map.hasKey(key) && map.getType(key) == ReadableType.String) {
        String uri = map.getString(key);
        if (uri != null && !uri.isEmpty()) {
            return byteArrayFromUrl(uri);
        }
    }
    return null;
}
 
Example 11
Project: RNLearn_Project1   File: ReactWebViewManager.java   Source Code and License Vote up 5 votes
@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
  if (source != null) {
    if (source.hasKey("html")) {
      String html = source.getString("html");
      if (source.hasKey("baseUrl")) {
        view.loadDataWithBaseURL(
            source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);
      } else {
        view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
      }
      return;
    }
    if (source.hasKey("uri")) {
      String url = source.getString("uri");
      String previousUrl = view.getUrl();
      if (previousUrl != null && previousUrl.equals(url)) {
        return;
      }
      if (source.hasKey("method")) {
        String method = source.getString("method");
        if (method.equals(HTTP_METHOD_POST)) {
          byte[] postData = null;
          if (source.hasKey("body")) {
            String body = source.getString("body");
            try {
              postData = body.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
              postData = body.getBytes();
            }
          }
          if (postData == null) {
            postData = new byte[0];
          }
          view.postUrl(url, postData);
          return;
        }
      }
      HashMap<String, String> headerMap = new HashMap<>();
      if (source.hasKey("headers")) {
        ReadableMap headers = source.getMap("headers");
        ReadableMapKeySetIterator iter = headers.keySetIterator();
        while (iter.hasNextKey()) {
          String key = iter.nextKey();
          if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
            if (view.getSettings() != null) {
              view.getSettings().setUserAgentString(headers.getString(key));
            }
          } else {
            headerMap.put(key, headers.getString(key));
          }
        }
      }
      view.loadUrl(url, headerMap);
      return;
    }
  }
  view.loadUrl(BLANK_URL);
}
 
Example 12
Project: react-native-pili-player   File: PiliLiveViewManager.java   Source Code and License Vote up 5 votes
@ReactProp(name = "source")
    public void setSource(PLVideoView mVideoView, ReadableMap source) {
        AVOptions options = new AVOptions();
        String uri = source.getString("uri");
        boolean mediaController = source.hasKey("controller") && source.getBoolean("controller");
        int avFrameTimeout = source.hasKey("timeout") ? source.getInt("timeout") : -1;        //10 * 1000 ms
        //boolean liveStreaming = source.hasKey("live") && source.getBoolean("live");  //1 or 0 // 1 -> live
        boolean codec = source.hasKey("hardCodec") && source.getBoolean("hardCodec");  //1 or 0  // 1 -> hw codec enable, 0 -> disable [recommended]
        // the unit of timeout is ms
        if (avFrameTimeout >= 0) {
            options.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, avFrameTimeout);
        }
        // Some optimization with buffering mechanism when be set to 1
        options.setInteger(AVOptions.KEY_LIVE_STREAMING, 1);
//        }

        // 1 -> hw codec enable, 0 -> disable [recommended]
        if (codec) {
            options.setInteger(AVOptions.KEY_MEDIACODEC, 1);
        } else {
            options.setInteger(AVOptions.KEY_MEDIACODEC, 0);
        }

        mVideoView.setAVOptions(options);

        // After setVideoPath, the play will start automatically
        // mVideoView.start() is not required

        mVideoView.setVideoPath(uri);

//        if (mediaController) {
//            // You can also use a custom `MediaController` widget
//            MediaController mMediaController = new MediaController(reactContext, false, isLiveStreaming(uri));
//            mVideoView.setMediaController(mMediaController);
//        }

    }
 
Example 13
Project: react-native-simple-download-manager   File: Downloader.java   Source Code and License Vote up 5 votes
public DownloadManager.Request createRequest(String url, ReadableMap headers, ReadableMap requestConfig) {
    String downloadTitle = requestConfig.getString("downloadTitle");
    String downloadDescription = requestConfig.getString("downloadTitle");
    String saveAsName = requestConfig.getString("saveAsName");
    Boolean allowedInRoaming = requestConfig.getBoolean("allowedInRoaming");
    Boolean allowedInMetered = requestConfig.getBoolean("allowedInMetered");
    Boolean showInDownloads = requestConfig.getBoolean("showInDownloads");

    Uri downloadUri = Uri.parse(url);
    DownloadManager.Request request = new DownloadManager.Request(downloadUri);

    ReadableMapKeySetIterator iterator = headers.keySetIterator();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        request.addRequestHeader(key, headers.getString(key));
    }

    request.setTitle(downloadTitle);
    request.setDescription(downloadDescription);
    request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, saveAsName);
    request.setAllowedOverRoaming(allowedInRoaming);
    request.setAllowedOverMetered(allowedInMetered);
    request.setVisibleInDownloadsUi(showInDownloads);
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    return request;
}
 
Example 14
Project: react-native-udesk   File: UdeskModule.java   Source Code and License Vote up 5 votes
public static @NonNull boolean hasAndNotEmpty(@NonNull final ReadableMap target,
                                              @NonNull final String key)
{
    if (!target.hasKey(key))
    {
        return false;
    }

    final String value = target.getString(key);

    return !TextUtils.isEmpty(value);
}
 
Example 15
Project: react-native-cameraroll   File: RNCameraRollModule.java   Source Code and License Vote up 5 votes
@ReactMethod
public void getAssets(final ReadableMap params, final Promise promise) {
    String start = params.hasKey("start") ? params.getString("start") : null;
    int limit = params.getInt("limit");
    String assetType = params.getString("assetType");

    new GetAssetsTask(
            getReactApplicationContext(),
            start,
            limit,
            assetType,
            promise)
            .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example 16
Project: react-native-mail-compose   File: RNMailComposeModule.java   Source Code and License Vote up 5 votes
private byte[] getBlob(ReadableMap map, String key) {
    if (map.hasKey(key) && map.getType(key) == ReadableType.String) {
        String base64 = map.getString(key);
        if (base64 != null && !base64.isEmpty()) {
            return Base64.decode(base64, 0);
        }
    }
    return null;
}
 
Example 17
Project: RNLearn_Project1   File: NativeAnimatedNodesManager.java   Source Code and License Vote up 5 votes
public void startAnimatingNode(
  int animationId,
  int animatedNodeTag,
  ReadableMap animationConfig,
  Callback endCallback) {
  AnimatedNode node = mAnimatedNodes.get(animatedNodeTag);
  if (node == null) {
    throw new JSApplicationIllegalArgumentException("Animated node with tag " + animatedNodeTag +
      " does not exists");
  }
  if (!(node instanceof ValueAnimatedNode)) {
    throw new JSApplicationIllegalArgumentException("Animated node should be of type " +
      ValueAnimatedNode.class.getName());
  }
  String type = animationConfig.getString("type");
  final AnimationDriver animation;
  if ("frames".equals(type)) {
    animation = new FrameBasedAnimationDriver(animationConfig);
  } else if ("spring".equals(type)) {
    animation = new SpringAnimation(animationConfig);
  } else if ("decay".equals(type)) {
    animation = new DecayAnimation(animationConfig);
  } else {
    throw new JSApplicationIllegalArgumentException("Unsupported animation type: " + type);
  }
  animation.mId = animationId;
  animation.mEndCallback = endCallback;
  animation.mAnimatedValue = (ValueAnimatedNode) node;
  mActiveAnimations.put(animationId, animation);
}
 
Example 18
Project: react-native-message-compose   File: RNMessageComposeModule.java   Source Code and License Vote up 4 votes
private String getString(ReadableMap map, String key) {
    if (map.hasKey(key) && map.getType(key) == ReadableType.String) {
        return map.getString(key);
    }
    return null;
}
 
Example 19
Project: react-native-mail-compose   File: RNMailComposeModule.java   Source Code and License Vote up 4 votes
private String getString(ReadableMap map, String key) {
    if (map.hasKey(key) && map.getType(key) == ReadableType.String) {
        return map.getString(key);
    }
    return null;
}
 
Example 20
Project: RNLearn_Project1   File: NetworkingModule.java   Source Code and License Vote up 4 votes
private @Nullable MultipartBody.Builder constructMultipartBody(
    ExecutorToken ExecutorToken,
    ReadableArray body,
    String contentType,
    int requestId) {
  RCTDeviceEventEmitter eventEmitter = getEventEmitter(ExecutorToken);
  MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
  multipartBuilder.setType(MediaType.parse(contentType));

  for (int i = 0, size = body.size(); i < size; i++) {
    ReadableMap bodyPart = body.getMap(i);

    // Determine part's content type.
    ReadableArray headersArray = bodyPart.getArray("headers");
    Headers headers = extractHeaders(headersArray, null);
    if (headers == null) {
      ResponseUtil.onRequestError(
        eventEmitter,
        requestId,
        "Missing or invalid header format for FormData part.",
        null);
      return null;
    }
    MediaType partContentType = null;
    String partContentTypeStr = headers.get(CONTENT_TYPE_HEADER_NAME);
    if (partContentTypeStr != null) {
      partContentType = MediaType.parse(partContentTypeStr);
      // Remove the content-type header because MultipartBuilder gets it explicitly as an
      // argument and doesn't expect it in the headers array.
      headers = headers.newBuilder().removeAll(CONTENT_TYPE_HEADER_NAME).build();
    }

    if (bodyPart.hasKey(REQUEST_BODY_KEY_STRING)) {
      String bodyValue = bodyPart.getString(REQUEST_BODY_KEY_STRING);
      multipartBuilder.addPart(headers, RequestBody.create(partContentType, bodyValue));
    } else if (bodyPart.hasKey(REQUEST_BODY_KEY_URI)) {
      if (partContentType == null) {
        ResponseUtil.onRequestError(
          eventEmitter,
          requestId,
          "Binary FormData part needs a content-type header.",
          null);
        return null;
      }
      String fileContentUriStr = bodyPart.getString(REQUEST_BODY_KEY_URI);
      InputStream fileInputStream =
          RequestBodyUtil.getFileInputStream(getReactApplicationContext(), fileContentUriStr);
      if (fileInputStream == null) {
        ResponseUtil.onRequestError(
          eventEmitter,
          requestId,
          "Could not retrieve file for uri " + fileContentUriStr,
          null);
        return null;
      }
      multipartBuilder.addPart(headers, RequestBodyUtil.create(partContentType, fileInputStream));
    } else {
      ResponseUtil.onRequestError(eventEmitter, requestId, "Unrecognized FormData part.", null);
    }
  }
  return multipartBuilder;
}