當前位置: 首頁>>代碼示例>>Java>>正文


Java ReadableType類代碼示例

本文整理匯總了Java中com.facebook.react.bridge.ReadableType的典型用法代碼示例。如果您正苦於以下問題:Java ReadableType類的具體用法?Java ReadableType怎麽用?Java ReadableType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ReadableType類屬於com.facebook.react.bridge包,在下文中一共展示了ReadableType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getSourceIdConstraint

import com.facebook.react.bridge.ReadableType; //導入依賴的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;
}
 
開發者ID:angellsl10,項目名稱:react-native-webrtc,代碼行數:26,代碼來源:WebRTCModule.java

示例2: getMapStrValue

import com.facebook.react.bridge.ReadableType; //導入依賴的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

示例3: createIntent

import com.facebook.react.bridge.ReadableType; //導入依賴的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: readableMapToHashMap

import com.facebook.react.bridge.ReadableType; //導入依賴的package包/類
public static HashMap<String, Object> readableMapToHashMap(ReadableMap readableMap) {
    if (readableMap == null) {
        return null;
    }
    HashMap map = new HashMap<String, Object>();
    ReadableMapKeySetIterator keySetIterator = readableMap.keySetIterator();
    while (keySetIterator.hasNextKey()) {
        String key = keySetIterator.nextKey();
        ReadableType type = readableMap.getType(key);
        switch(type) {
            case String:
                map.put(key, readableMap.getString(key));
                break;
            case Map:
                HashMap<String, Object> attributes = new RCTConvert().readableMapToHashMap(readableMap.getMap(key));
                map.put(key, attributes);
                break;
            default:
                // do nothing
        }
    }
    return map;
}
 
開發者ID:ccm-innovation,項目名稱:react-native-twilio-chat,代碼行數:24,代碼來源:RCTConvert.java

示例5: getStringArray

import com.facebook.react.bridge.ReadableType; //導入依賴的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);
}
 
開發者ID:joonhocho,項目名稱:react-native-mail-compose,代碼行數:18,代碼來源:RNMailComposeModule.java

示例6: buildCreateQuery

import com.facebook.react.bridge.ReadableType; //導入依賴的package包/類
private StringBuilder buildCreateQuery(String tableName, ReadableMap props, List<String> keys) {
    final StringBuilder queryBuilder = new StringBuilder("CREATE TABLE IF NOT EXISTS ").append(tableName).append(" ");
    queryBuilder.append("(");
    queryBuilder.append("id INTEGER PRIMARY KEY AUTOINCREMENT");
    for (String key : keys) {
        String propType = null;
        if(props.getType(key) == ReadableType.Boolean) {
            propType = "BOOLEAN";
        } else if(props.getType(key) == ReadableType.String) {
            propType = "TEXT";
        } else if(props.getType(key) == ReadableType.Number) {
            propType = "DOUBLE";
        }

        if(propType != null) {
            queryBuilder.append(", ").append(key).append(" ").append(propType);
        }
    }
    queryBuilder.append(")");
    return queryBuilder;
}
 
開發者ID:reneweb,項目名稱:rnrecord,代碼行數:22,代碼來源:SaveCommand.java

示例7: buildQueryArgument

import com.facebook.react.bridge.ReadableType; //導入依賴的package包/類
private ArrayList<String> buildQueryArgument(List<String> keys, ReadableMap query) {
    final ArrayList<String> arguments = new ArrayList<>();

    for (String key : keys) {
        ReadableType type = query.getType(key);
        if(type == ReadableType.Boolean) {
            arguments.add(String.valueOf(query.getBoolean(key)));
        } else if(type == ReadableType.Number) {
            arguments.add(String.valueOf(query.getDouble(key)));
        } else if(type == ReadableType.String) {
            arguments.add(String.valueOf(query.getString(key)));
        }
    }

    return arguments;
}
 
開發者ID:reneweb,項目名稱:rnrecord,代碼行數:17,代碼來源:FindCommand.java

示例8: stackTraceToString

import com.facebook.react.bridge.ReadableType; //導入依賴的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

示例9: setFromDynamic

import com.facebook.react.bridge.ReadableType; //導入依賴的package包/類
void setFromDynamic(Dynamic dynamic) {
  if (dynamic.isNull()) {
    unit = YogaUnit.UNDEFINED;
    value = YogaConstants.UNDEFINED;
  } else if (dynamic.getType() == ReadableType.String) {
    final String s = dynamic.asString();
    if (s.equals("auto")) {
      unit = YogaUnit.AUTO;
      value = YogaConstants.UNDEFINED;
    } else if (s.endsWith("%")) {
      unit = YogaUnit.PERCENT;
      value = Float.parseFloat(s.substring(0, s.length() - 1));
    } else {
      throw new IllegalArgumentException("Unknown value: " + s);
    }
  } else {
    unit = YogaUnit.POINT;
    value = PixelUtil.toPixelFromDIP(dynamic.asDouble());
  }
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:21,代碼來源:LayoutShadowNode.java

示例10: convertToRadians

import com.facebook.react.bridge.ReadableType; //導入依賴的package包/類
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);
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:18,代碼來源:TransformHelper.java

示例11: testGetTypeFromArray

import com.facebook.react.bridge.ReadableType; //導入依賴的package包/類
public void testGetTypeFromArray() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class)
      .returnArrayWithStringDoubleIntMapArrayBooleanNull();
  waitForBridgeAndUIIdle();

  List<ReadableArray> calls = mRecordingTestModule.getArrayCalls();
  assertEquals(1, calls.size());
  ReadableArray array = calls.get(0);

  assertEquals(ReadableType.String, array.getType(0));
  assertEquals(ReadableType.Number, array.getType(1));
  assertEquals(ReadableType.Number, array.getType(2));
  assertEquals(ReadableType.Map, array.getType(3));
  assertEquals(ReadableType.Array, array.getType(4));
  assertEquals(ReadableType.Boolean, array.getType(5));
  assertEquals(ReadableType.Null, array.getType(6));
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:18,代碼來源:CatalystNativeJSToJavaParametersTestCase.java

示例12: testGetTypeFromMap

import com.facebook.react.bridge.ReadableType; //導入依賴的package包/類
public void testGetTypeFromMap() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class)
      .returnMapWithStringDoubleIntMapArrayBooleanNull();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableMap map = calls.get(0);

  assertEquals(ReadableType.String, map.getType("string"));
  assertEquals(ReadableType.Number, map.getType("double"));
  assertEquals(ReadableType.Number, map.getType("int"));
  assertEquals(ReadableType.Map, map.getType("map"));
  assertEquals(ReadableType.Array, map.getType("array"));
  assertEquals(ReadableType.Boolean, map.getType("boolean"));
  assertEquals(ReadableType.Null, map.getType("null"));
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:18,代碼來源:CatalystNativeJSToJavaParametersTestCase.java

示例13: testIntOutOfRangeThrown

import com.facebook.react.bridge.ReadableType; //導入依賴的package包/類
public void testIntOutOfRangeThrown() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnArrayWithLargeInts();
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithLargeInts();
  waitForBridgeAndUIIdle();

  assertEquals(1, mRecordingTestModule.getArrayCalls().size());
  assertEquals(1, mRecordingTestModule.getMapCalls().size());

  ReadableArray array = mRecordingTestModule.getArrayCalls().get(0);
  assertNotNull(array);

  ReadableMap map = mRecordingTestModule.getMapCalls().get(0);
  assertNotNull(map);

  assertEquals(ReadableType.Number, array.getType(0));
  assertUnexpectedTypeExceptionThrown(array, 0, "int");
  assertEquals(ReadableType.Number, array.getType(1));
  assertUnexpectedTypeExceptionThrown(array, 1, "int");

  assertEquals(ReadableType.Number, map.getType("first"));
  assertUnexpectedTypeExceptionThrown(map, "first", "int");
  assertEquals(ReadableType.Number, map.getType("second"));
  assertUnexpectedTypeExceptionThrown(map, "second", "int");
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:25,代碼來源:CatalystNativeJSToJavaParametersTestCase.java

示例14: stackTraceToString

import com.facebook.react.bridge.ReadableType; //導入依賴的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(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:john1jan,項目名稱:ReactNativeSignatureExample,代碼行數:20,代碼來源:ExceptionsManagerModule.java

示例15: createEntry

import com.facebook.react.bridge.ReadableType; //導入依賴的package包/類
@Override
BubbleEntry createEntry(ReadableArray yValues, int index) {
    if (!ReadableType.Map.equals(yValues.getType(index))) {
        throw new IllegalArgumentException("Invalid BubbleEntry data");
    }

    ReadableMap entry = yValues.getMap(index);
    if(!BridgeUtils.validate(entry, ReadableType.Number, "value") ||
            !BridgeUtils.validate(entry, ReadableType.Number, "size")) {
        throw new IllegalArgumentException("Invalid BubbleEntry data");
    }

    float value = (float) entry.getDouble("value");
    float size = (float) entry.getDouble("size");

    return new BubbleEntry(index, value, size);
}
 
開發者ID:mskec,項目名稱:react-native-mp-android-chart,代碼行數:18,代碼來源:BubbleChartManager.java


注:本文中的com.facebook.react.bridge.ReadableType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。