当前位置: 首页>>代码示例>>Java>>正文


Java ReadableMap.getType方法代码示例

本文整理汇总了Java中com.facebook.react.bridge.ReadableMap.getType方法的典型用法代码示例。如果您正苦于以下问题:Java ReadableMap.getType方法的具体用法?Java ReadableMap.getType怎么用?Java ReadableMap.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.facebook.react.bridge.ReadableMap的用法示例。


在下文中一共展示了ReadableMap.getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMapStrValue

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
/**
 * Reads a value from given <tt>ReadableMap</tt> and returns it as
 * a <tt>String</tt>. Note that integer value is converted to double, before
 * it gets converted to a string.
 * @param map the <tt>ReadableMap</tt> from which the value will be obtained
 * @param key the map's key under which the value has been mapped.
 * @return a <tt>String</tt> representation of the value if exists or
 * <tt>null</tt> if there is no value mapped for given <tt>key</tt>.
 */
public static String getMapStrValue(ReadableMap map, String key) {
    if(!map.hasKey(key)){
        return null;
    }
    ReadableType type = map.getType(key);
    switch (type) {
        case Boolean:
            return String.valueOf(map.getBoolean(key));
        case Number:
            // Don't know how to distinguish between Int and Double from
            // ReadableType.Number. 'getInt' will fail on double value,
            // while 'getDouble' works for both.
            // return String.valueOf(map.getInt(key));
            return String.valueOf(map.getDouble(key));
        case String:
            return map.getString(key);
        default:
            return null;
    }
}
 
开发者ID:angellsl10,项目名称:react-native-webrtc,代码行数:30,代码来源:ReactBridgeUtil.java

示例2: stackTraceToString

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
private String stackTraceToString(String message, ReadableArray stack) {
  StringBuilder stringBuilder = new StringBuilder(message).append(", stack:\n");
  for (int i = 0; i < stack.size(); i++) {
    ReadableMap frame = stack.getMap(i);
    stringBuilder
        .append(frame.getString("methodName"))
        .append("@")
        .append(stackFrameToModuleId(frame))
        .append(frame.getInt("lineNumber"));
    if (frame.hasKey("column") &&
        !frame.isNull("column") &&
        frame.getType("column") == ReadableType.Number) {
      stringBuilder
          .append(":")
          .append(frame.getInt("column"));
    }
    stringBuilder.append("\n");
  }
  return stringBuilder.toString();
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:21,代码来源:ExceptionsManagerModule.java

示例3: createIntent

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
private Intent createIntent(String action, ReadableMap extra) {
  final Intent intent = new Intent(action);
  for (
    ReadableMapKeySetIterator it = extra.keySetIterator();
    it.hasNextKey();
  ) {
    String key = it.nextKey();
    ReadableType type = extra.getType(key);
    switch(type) {
      case Null:
        break;
      case Boolean:
        intent.putExtra(key, extra.getBoolean(key));
        break;
      case Number:
        intent.putExtra(key, extra.getInt(key));
        break;
      case String:
        intent.putExtra(key, extra.getString(key));
        break;
      default:
        throw new IllegalArgumentException("Unsupported type " + type);
    }
  }
  return intent;
}
 
开发者ID:de-code,项目名称:react-native-android-speech-recognizer,代码行数:27,代码来源:RNAndroidSpeechRecognizerModule.java

示例4: createIceServers

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
private List<PeerConnection.IceServer> createIceServers(ReadableArray iceServersArray) {
    final int size = (iceServersArray == null) ? 0 : iceServersArray.size();
    List<PeerConnection.IceServer> iceServers = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        ReadableMap iceServerMap = iceServersArray.getMap(i);
        boolean hasUsernameAndCredential = iceServerMap.hasKey("username") && iceServerMap.hasKey("credential");
        if (iceServerMap.hasKey("url")) {
            if (hasUsernameAndCredential) {
                iceServers.add(new PeerConnection.IceServer(iceServerMap.getString("url"), iceServerMap.getString("username"), iceServerMap.getString("credential")));
            } else {
                iceServers.add(new PeerConnection.IceServer(iceServerMap.getString("url")));
            }
        } else if (iceServerMap.hasKey("urls")) {
            switch (iceServerMap.getType("urls")) {
                case String:
                    if (hasUsernameAndCredential) {
                        iceServers.add(new PeerConnection.IceServer(iceServerMap.getString("urls"), iceServerMap.getString("username"), iceServerMap.getString("credential")));
                    } else {
                        iceServers.add(new PeerConnection.IceServer(iceServerMap.getString("urls")));
                    }
                    break;
                case Array:
                    ReadableArray urls = iceServerMap.getArray("urls");
                    for (int j = 0; j < urls.size(); j++) {
                        String url = urls.getString(j);
                        if (hasUsernameAndCredential) {
                            iceServers.add(new PeerConnection.IceServer(url,iceServerMap.getString("username"), iceServerMap.getString("credential")));
                        } else {
                            iceServers.add(new PeerConnection.IceServer(url));
                        }
                    }
                    break;
            }
        }
    }
    return iceServers;
}
 
开发者ID:angellsl10,项目名称:react-native-webrtc,代码行数:38,代码来源:WebRTCModule.java

示例5: stackFrameToModuleId

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
static private String stackFrameToModuleId(ReadableMap frame) {
  if (frame.hasKey("file") &&
      !frame.isNull("file") &&
      frame.getType("file") == ReadableType.String) {
    final Matcher matcher = mJsModuleIdPattern.matcher(frame.getString("file"));
    if (matcher.find()) {
      return matcher.group(1) + ":";
    }
  }
  return "";
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:12,代码来源:ExceptionsManagerModule.java

示例6: toJSONObject

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
public static JSONObject toJSONObject(ReadableMap readableMap) throws JSONException {
  JSONObject jsonObject = new JSONObject();

  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    ReadableType type = readableMap.getType(key);

    switch (type) {
      case Null:
        jsonObject.put(key, null);
        break;
      case Boolean:
        jsonObject.put(key, readableMap.getBoolean(key));
        break;
      case Number:
        jsonObject.put(key, readableMap.getDouble(key));
        break;
      case String:
        jsonObject.put(key, readableMap.getString(key));
        break;
      case Map:
        jsonObject.put(key, MapUtil.toJSONObject(readableMap.getMap(key)));
        break;
      case Array:
        jsonObject.put(key, ArrayUtil.toJSONArray(readableMap.getArray(key)));
        break;
    }
  }

  return jsonObject;
}
 
开发者ID:davidstoneham,项目名称:react-native-mssql,代码行数:34,代码来源:MapUtil.java

示例7: toMap

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
public static Map<String, Object> toMap(ReadableMap readableMap) {
  Map<String, Object> map = new HashMap<>();
  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    ReadableType type = readableMap.getType(key);

    switch (type) {
      case Null:
        map.put(key, null);
        break;
      case Boolean:
        map.put(key, readableMap.getBoolean(key));
        break;
      case Number:
        map.put(key, readableMap.getDouble(key));
        break;
      case String:
        map.put(key, readableMap.getString(key));
        break;
      case Map:
        map.put(key, MapUtil.toMap(readableMap.getMap(key)));
        break;
      case Array:
        map.put(key, ArrayUtil.toArray(readableMap.getArray(key)));
        break;
    }
  }

  return map;
}
 
开发者ID:davidstoneham,项目名称:react-native-mssql,代码行数:33,代码来源:MapUtil.java

示例8: reactToJSON

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
public static JSONObject reactToJSON(ReadableMap readableMap) throws JSONException {
    JSONObject jsonObject = new JSONObject();
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    while(iterator.hasNextKey()){
        String key = iterator.nextKey();
        ReadableType valueType = readableMap.getType(key);
        switch (valueType){
            case Null:
                jsonObject.put(key,JSONObject.NULL);
                break;
            case Boolean:
                jsonObject.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                try {
                    jsonObject.put(key, readableMap.getInt(key));
                } catch(Exception e) {
                    jsonObject.put(key, readableMap.getDouble(key));
                }
                break;
            case String:
                jsonObject.put(key, readableMap.getString(key));
                break;
            case Map:
                jsonObject.put(key, reactToJSON(readableMap.getMap(key)));
                break;
            case Array:
                jsonObject.put(key, reactToJSON(readableMap.getArray(key)));
                break;
        }
    }

    return jsonObject;
}
 
开发者ID:whitedogg13,项目名称:react-native-nfc-manager,代码行数:35,代码来源:JsonConvert.java

示例9: getBlobFromUri

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
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;
}
 
开发者ID:joonhocho,项目名称:react-native-message-compose,代码行数:10,代码来源:RNMessageComposeModule.java

示例10: prepareInsertContentValues

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
private ContentValues prepareInsertContentValues(ReadableMap props, List<String> keys) {
    final ContentValues contentValues = new ContentValues();
    for (String key : keys) {
        if(props.getType(key) == ReadableType.Boolean) {
            contentValues.put(key, props.getBoolean(key));
        } else if(props.getType(key) == ReadableType.Number) {
            contentValues.put(key, props.getDouble(key));
        } else if(props.getType(key) == ReadableType.String) {
            contentValues.put(key, props.getString(key));
        }
    }
    return contentValues;
}
 
开发者ID:reneweb,项目名称:rnrecord,代码行数:14,代码来源:SaveCommand.java

示例11: convertMapToJson

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
private static JSONObject convertMapToJson(ReadableMap readableMap) throws JSONException {
  JSONObject object = new JSONObject();
  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    switch (readableMap.getType(key)) {
      case Null:
        object.put(key, JSONObject.NULL);
        break;
      case Boolean:
        object.put(key, readableMap.getBoolean(key));
        break;
      case Number:
        object.put(key, readableMap.getDouble(key));
        break;
      case String:
        object.put(key, readableMap.getString(key));
        break;
      case Map:
        object.put(key, convertMapToJson(readableMap.getMap(key)));
        break;
      case Array:
        object.put(key, convertArrayToJson(readableMap.getArray(key)));
        break;
    }
  }
  return object;
}
 
开发者ID:humaniq,项目名称:react-native-android-library-humaniq-api,代码行数:29,代码来源:ModelConverterUtils.java

示例12: toObject

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
/**
 * toObject extracts a value from a {@link ReadableMap} by its key,
 * and returns a POJO representing that object.
 *
 * @param readableMap The Map to containing the value to be converted
 * @param key         The key for the value to be converted
 * @return The converted POJO
 */
public static Object toObject(@Nullable ReadableMap readableMap, String key) {
    if (readableMap == null) {
        return null;
    }

    Object result;

    ReadableType readableType = readableMap.getType(key);
    switch (readableType) {
        case Null:
            result = key;
            break;
        case Boolean:
            result = readableMap.getBoolean(key);
            break;
        case Number:
            // Can be int or double.
            double tmp = readableMap.getDouble(key);
            if (tmp == (int) tmp) {
                result = (int) tmp;
            } else {
                result = tmp;
            }
            break;
        case String:
            result = readableMap.getString(key);
            break;
        case Map:
            result = toMap(readableMap.getMap(key));
            break;
        case Array:
            result = toList(readableMap.getArray(key));
            break;
        default:
            throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
    }

    return result;
}
 
开发者ID:hudl,项目名称:react-native-android-fragment,代码行数:48,代码来源:ReactUtil.java

示例13: toJSONObject

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
public static JSONObject toJSONObject(ReadableMap readableMap) throws JSONException {
    JSONObject jsonObject = new JSONObject();

    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = readableMap.getType(key);

        switch (type) {
            case Null:
                jsonObject.put(key, null);
                break;
            case Boolean:
                jsonObject.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                jsonObject.put(key, readableMap.getDouble(key));
                break;
            case String:
                jsonObject.put(key, readableMap.getString(key));
                break;
            case Map:
                jsonObject.put(key, MapUtil.toJSONObject(readableMap.getMap(key)));
                break;
            case Array:
                jsonObject.put(key, ArrayUtil.toJSONArray(readableMap.getArray(key)));
                break;
        }
    }

    return jsonObject;
}
 
开发者ID:dangerfarms,项目名称:react-native-batch,代码行数:34,代码来源:MapUtil.java

示例14: convertMapToJson

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
public static JSONObject convertMapToJson(ReadableMap readableMap) throws JSONException {
    JSONObject object = new JSONObject();
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        switch (readableMap.getType(key)) {
            case Null:
                object.put(key, JSONObject.NULL);
                break;
            case Boolean:
                object.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                object.put(key, readableMap.getDouble(key));
                break;
            case String:
                object.put(key, readableMap.getString(key));
                break;
            case Map:
                object.put(key, convertMapToJson(readableMap.getMap(key)));
                break;
            case Array:
                object.put(key, convertArrayToJson(readableMap.getArray(key)));
                break;
        }
    }
    return object;
}
 
开发者ID:salathegroup,项目名称:react-native-scandit,代码行数:29,代码来源:ReactBridgeHelpers.java

示例15: extractMapValue

import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
private Object extractMapValue(ReadableMap params, HashMap<String, Object> paramsMap, String key) {
    Object mapValue;
    if (ReadableType.Number == params.getType(key)) {
        try {
            mapValue = params.getInt(key);
        } catch (UnexpectedNativeTypeException e) {
            mapValue = params.getDouble(key);
        }
    } else {
        mapValue = paramsMap.get(key);
    }

    return mapValue;
}
 
开发者ID:CanalTP,项目名称:RNNavitiaSDK,代码行数:15,代码来源:RNNavitiaSDK.java


注:本文中的com.facebook.react.bridge.ReadableMap.getType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。