本文整理汇总了Java中com.facebook.react.bridge.ReadableArray.getType方法的典型用法代码示例。如果您正苦于以下问题:Java ReadableArray.getType方法的具体用法?Java ReadableArray.getType怎么用?Java ReadableArray.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.react.bridge.ReadableArray
的用法示例。
在下文中一共展示了ReadableArray.getType方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSourceIdConstraint
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
/**
* Retreives "sourceId" constraint value.
* @param mediaConstraints a <tt>ReadableMap</tt> which represents "GUM"
* constraints argument
* @return String value of "sourceId" optional "GUM" constraint or
* <tt>null</tt> if not specified in the given map.
*/
private String getSourceIdConstraint(ReadableMap mediaConstraints) {
if (mediaConstraints.hasKey("optional")
&& mediaConstraints.getType("optional") == ReadableType.Array) {
ReadableArray optional = mediaConstraints.getArray("optional");
for (int i = 0, size = optional.size(); i < size; i++) {
if (optional.getType(i) == ReadableType.Map) {
ReadableMap option = optional.getMap(i);
if (option.hasKey("sourceId")
&& option.getType("sourceId") == ReadableType.String) {
return option.getString("sourceId");
}
}
}
}
return null;
}
示例2: getStringArray
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
private String[] getStringArray(ReadableMap map, String key) {
ReadableArray array = getArray(map, key);
if (array == null) return null;
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < array.size(); i++) {
if (array.getType(i) == ReadableType.String) {
String str = array.getString(i);
if (!isEmpty(str)) {
list.add(str);
}
}
}
String[] arr = new String[list.size()];
return list.toArray(arr);
}
示例3: convertArrayToJson
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
public static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException {
JSONArray array = new JSONArray();
for (int i = 0; i < readableArray.size(); i++) {
switch (readableArray.getType(i)) {
case Null:
break;
case Boolean:
array.put(readableArray.getBoolean(i));
break;
case Number:
array.put(readableArray.getDouble(i));
break;
case String:
array.put(readableArray.getString(i));
break;
case Map:
array.put(convertMapToJson(readableArray.getMap(i)));
break;
case Array:
array.put(convertArrayToJson(readableArray.getArray(i)));
break;
}
}
return array;
}
示例4: convertArrayToJson
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
private static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException {
JSONArray array = new JSONArray();
for (int i = 0; i < readableArray.size(); i++) {
switch (readableArray.getType(i)) {
case Null:
break;
case Boolean:
array.put(readableArray.getBoolean(i));
break;
case Number:
array.put(readableArray.getDouble(i));
break;
case String:
array.put(readableArray.getString(i));
break;
case Map:
array.put(convertMapToJson(readableArray.getMap(i)));
break;
case Array:
array.put(convertArrayToJson(readableArray.getArray(i)));
break;
}
}
return array;
}
示例5: parseMediaConstraints
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
/**
* Parses mandatory and optional "GUM" constraints described by a specific
* <tt>ReadableMap</tt>.
*
* @param constraints A <tt>ReadableMap</tt> which represents a JavaScript
* object specifying the constraints to be parsed into a
* <tt>MediaConstraints</tt> instance.
* @return A new <tt>MediaConstraints</tt> instance initialized with the
* mandatory and optional constraint keys and values specified by
* <tt>constraints</tt>.
*/
private MediaConstraints parseMediaConstraints(ReadableMap constraints) {
MediaConstraints mediaConstraints = new MediaConstraints();
if (constraints.hasKey("mandatory")
&& constraints.getType("mandatory") == ReadableType.Map) {
parseConstraints(
constraints.getMap("mandatory"),
mediaConstraints.mandatory);
} else {
Log.d(TAG, "mandatory constraints are not a map");
}
if (constraints.hasKey("optional")
&& constraints.getType("optional") == ReadableType.Array) {
ReadableArray optional = constraints.getArray("optional");
for (int i = 0, size = optional.size(); i < size; i++) {
if (optional.getType(i) == ReadableType.Map) {
parseConstraints(
optional.getMap(i),
mediaConstraints.optional);
}
}
} else {
Log.d(TAG, "optional constraints are not an array");
}
return mediaConstraints;
}
示例6: toJSONArray
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
public static JSONArray toJSONArray(ReadableArray readableArray) throws JSONException {
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < readableArray.size(); i++) {
ReadableType type = readableArray.getType(i);
switch (type) {
case Null:
jsonArray.put(i, null);
break;
case Boolean:
jsonArray.put(i, readableArray.getBoolean(i));
break;
case Number:
jsonArray.put(i, readableArray.getDouble(i));
break;
case String:
jsonArray.put(i, readableArray.getString(i));
break;
case Map:
jsonArray.put(i, MapUtil.toJSONObject(readableArray.getMap(i)));
break;
case Array:
jsonArray.put(i, ArrayUtil.toJSONArray(readableArray.getArray(i)));
break;
}
}
return jsonArray;
}
示例7: toArray
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
public static Object[] toArray(ReadableArray readableArray) {
Object[] array = new Object[readableArray.size()];
for (int i = 0; i < readableArray.size(); i++) {
ReadableType type = readableArray.getType(i);
switch (type) {
case Null:
array[i] = null;
break;
case Boolean:
array[i] = readableArray.getBoolean(i);
break;
case Number:
array[i] = readableArray.getDouble(i);
break;
case String:
array[i] = readableArray.getString(i);
break;
case Map:
array[i] = MapUtil.toMap(readableArray.getMap(i));
break;
case Array:
array[i] = ArrayUtil.toArray(readableArray.getArray(i));
break;
}
}
return array;
}
示例8: reactToJSON
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
public static JSONArray reactToJSON(ReadableArray readableArray) throws JSONException {
JSONArray jsonArray = new JSONArray();
for(int i=0; i < readableArray.size(); i++) {
ReadableType valueType = readableArray.getType(i);
switch (valueType){
case Null:
jsonArray.put(JSONObject.NULL);
break;
case Boolean:
jsonArray.put(readableArray.getBoolean(i));
break;
case Number:
try {
jsonArray.put(readableArray.getInt(i));
} catch(Exception e) {
jsonArray.put(readableArray.getDouble(i));
}
break;
case String:
jsonArray.put(readableArray.getString(i));
break;
case Map:
jsonArray.put(reactToJSON(readableArray.getMap(i)));
break;
case Array:
jsonArray.put(reactToJSON(readableArray.getArray(i)));
break;
}
}
return jsonArray;
}
示例9: toJSONArray
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
public static JSONArray toJSONArray(ReadableArray readableArray) throws JSONException {
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < readableArray.size(); i++) {
ReadableType type = readableArray.getType(i);
switch (type) {
case Null:
jsonArray.put(i, null);
break;
case Boolean:
jsonArray.put(i, readableArray.getBoolean(i));
break;
case Number:
jsonArray.put(i, readableArray.getDouble(i));
break;
case String:
jsonArray.put(i, readableArray.getString(i));
break;
case Map:
jsonArray.put(i, MapUtil.toJSONObject(readableArray.getMap(i)));
break;
case Array:
jsonArray.put(i, ArrayUtil.toJSONArray(readableArray.getArray(i)));
break;
}
}
return jsonArray;
}
示例10: toArray
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
public static Object[] toArray(ReadableArray readableArray) {
Object[] array = new Object[readableArray.size()];
for (int i = 0; i < readableArray.size(); i++) {
ReadableType type = readableArray.getType(i);
switch (type) {
case Null:
array[i] = null;
break;
case Boolean:
array[i] = readableArray.getBoolean(i);
break;
case Number:
array[i] = readableArray.getDouble(i);
break;
case String:
array[i] = readableArray.getString(i);
break;
case Map:
array[i] = MapUtil.toMap(readableArray.getMap(i));
break;
case Array:
array[i] = ArrayUtil.toArray(readableArray.getArray(i));
break;
}
}
return array;
}
示例11: toJSONArray
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
public static JSONArray toJSONArray(ReadableArray readableArray) throws JSONException {
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < readableArray.size(); i++) {
ReadableType type = readableArray.getType(i);
switch (type) {
case Null:
jsonArray.add(i, null);
break;
case Boolean:
jsonArray.add(i, readableArray.getBoolean(i));
break;
case Number:
jsonArray.add(i, readableArray.getDouble(i));
break;
case String:
jsonArray.add(i, readableArray.getString(i));
break;
case Map:
jsonArray.add(i, MapUtil.toJSONObject(readableArray.getMap(i)));
break;
case Array:
jsonArray.add(i, ArrayUtil.toJSONArray(readableArray.getArray(i)));
break;
}
}
return jsonArray;
}
示例12: addAttachments
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
private void addAttachments(Intent intent, ReadableArray attachments) {
if (attachments == null) return;
ArrayList<Uri> uris = new ArrayList<>();
for (int i = 0; i < attachments.size(); i++) {
if (attachments.getType(i) == ReadableType.Map) {
ReadableMap attachment = attachments.getMap(i);
if (attachment != null) {
byte[] blob = getBlob(attachment, "data");
String text = getString(attachment, "text");
// String mimeType = getString(attachment, "mimeType");
String filename = getString(attachment, "filename");
if (filename == null) {
filename = UUID.randomUUID().toString();
}
String ext = getString(attachment, "ext");
File tempFile = createTempFile(filename, ext);
if (blob != null) {
tempFile = writeBlob(tempFile, blob);
} else if (text != null) {
tempFile = writeText(tempFile, text);
}
if (tempFile != null) {
uris.add(Uri.fromFile(tempFile));
}
}
}
}
if (uris.size() > 0) {
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
}
}
示例13: toList
import com.facebook.react.bridge.ReadableArray; //导入方法依赖的package包/类
/**
* toList converts a {@link ReadableArray} into an ArrayList.
*
* @param readableArray The ReadableArray to be converted.
* @return An ArrayList containing the data that was in the ReadableArray.
*/
public static List<Object> toList(@Nullable ReadableArray readableArray) {
if (readableArray == null) {
return new ArrayList<>(0);
}
List<Object> result = new ArrayList<>(readableArray.size());
for (int index = 0; index < readableArray.size(); index++) {
ReadableType readableType = readableArray.getType(index);
switch (readableType) {
case Null:
result.add(String.valueOf(index));
break;
case Boolean:
result.add(readableArray.getBoolean(index));
break;
case Number:
// Can be int or double.
double tmp = readableArray.getDouble(index);
if (tmp == (int) tmp) {
result.add((int) tmp);
} else {
result.add(tmp);
}
break;
case String:
result.add(readableArray.getString(index));
break;
case Map:
result.add(toMap(readableArray.getMap(index)));
break;
case Array:
result = toList(readableArray.getArray(index));
break;
default:
throw new IllegalArgumentException("Could not convert object with index: " + index + ".");
}
}
return result;
}