本文整理匯總了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;
}
}
示例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();
}
示例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;
}
示例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 "";
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}