Java Code Examples for com.facebook.react.bridge.ReadableMapKeySetIterator

The following examples show how to use com.facebook.react.bridge.ReadableMapKeySetIterator. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: imsdk-android   Source File: QimRNBModule.java    License: MIT License 6 votes vote down vote up
/**
 * 群踢人
 *
 * @param params
 */
@ReactMethod
public void kickGroupMember(ReadableMap params, Callback callback) {
    final String groupId = params.getString("groupId");
    ReadableMap map = params.getMap("members");
    ReadableMapKeySetIterator keySet = map.keySetIterator();
    Map<String, String> memberMap = new HashMap<>();
    while (keySet.hasNextKey()) {
        ReadableMap item = map.getMap(keySet.nextKey());
        String userId = item.getString("xmppId");
        String name = item.getString("name");
        memberMap.put(name, userId);
    }
    if (TextUtils.isEmpty(groupId) || memberMap.size() == 0) {
        return;
    }
    ConnectionUtil.getInstance().delGroupMember(groupId, memberMap);
    sendEvent("closeKickMembers", new WritableNativeMap());
    toast("成员已移除");
}
 
Example 2
Source Project: react-native-flurry-sdk   Source File: FlurryModule.java    License: Apache License 2.0 6 votes vote down vote up
@ReactMethod
public void getConfigStringMap(ReadableMap keyAndDefault, Promise promise) {
    try {
        WritableMap map = Arguments.createMap();
        if (keyAndDefault != null) {
            ReadableMapKeySetIterator iterator = keyAndDefault.keySetIterator();
            while (iterator.hasNextKey()) {
                String key = iterator.nextKey();
                String defaultValue = keyAndDefault.getString(key);
                map.putString(key, FlurryConfig.getInstance().getString(key, defaultValue));
            }
        }
        promise.resolve(map);
    } catch (IllegalViewOperationException e) {
        promise.reject("Flurry.getConfigString", e);
    }
}
 
Example 3
Source Project: react-native-flurry-sdk   Source File: FlurryModule.java    License: Apache License 2.0 6 votes vote down vote up
private static Map<String, String> toMap(final ReadableMap readableMap) {
    if (readableMap == null) {
        return null;
    }

    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    if (!iterator.hasNextKey()) {
        return null;
    }

    Map<String, String> result = new HashMap<>();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        result.put(key, readableMap.getString(key));
    }

    return result;
}
 
Example 4
Source Project: react-native-GPay   Source File: NativeViewHierarchyOptimizer.java    License: MIT License 6 votes vote down vote up
private static boolean isLayoutOnlyAndCollapsable(@Nullable ReactStylesDiffMap props) {
  if (props == null) {
    return true;
  }

  if (props.hasKey(ViewProps.COLLAPSABLE) && !props.getBoolean(ViewProps.COLLAPSABLE, true)) {
    return false;
  }

  ReadableMapKeySetIterator keyIterator = props.mBackingMap.keySetIterator();
  while (keyIterator.hasNextKey()) {
    if (!ViewProps.isLayoutOnly(props.mBackingMap, keyIterator.nextKey())) {
      return false;
    }
  }
  return true;
}
 
Example 5
public void testMapIterateOverMapWithBasicTypes() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithBasicTypes();
  waitForBridgeAndUIIdle();

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

  ReadableMapKeySetIterator mapIterator = map.keySetIterator();
  Set<String> keys = new HashSet<String>();
  while (mapIterator.hasNextKey()) {
    keys.add(mapIterator.nextKey());
  }

  Set<String> expectedKeys = new HashSet<String>(
      Arrays.asList("stringKey", "doubleKey", "intKey", "booleanKey", "nullKey"));
  assertEquals(keys, expectedKeys);
}
 
Example 6
public void testMapIterateOverNestedMaps() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnNestedMap();
  waitForBridgeAndUIIdle();

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

  ReadableMapKeySetIterator firstLevelIterator = map.keySetIterator();
  String firstLevelKey = firstLevelIterator.nextKey();
  assertEquals(firstLevelKey, "weHaveToGoDeeper");

  ReadableNativeMap secondMap = map.getMap("weHaveToGoDeeper");
  ReadableMapKeySetIterator secondLevelIterator = secondMap.keySetIterator();
  String secondLevelKey = secondLevelIterator.nextKey();
  assertEquals(secondLevelKey, "inception");
  assertTrue(secondMap.getBoolean(secondLevelKey));
}
 
Example 7
Source Project: photo-viewer   Source File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Converts Facebook's ReadableMap to a Java Map<>
 *
 * @param readableMap The Readable Map to parse
 * @return a Java Map<> to be used in memory
 */
public static Map<String, Object> toMap(@Nullable ReadableMap readableMap) {
    if (readableMap == null) {
        return null;
    }

    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    if (!iterator.hasNextKey()) {
        return null;
    }

    Map<String, Object> result = new HashMap<>();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        result.put(key, toObject(readableMap, key));
    }

    return result;
}
 
Example 8
Source Project: react-native-twilio-chat   Source File: RCTConvert.java    License: MIT License 6 votes vote down vote up
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;
}
 
Example 9
Source Project: react-native-twilio-ip-messaging   Source File: RCTConvert.java    License: MIT License 6 votes vote down vote up
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;
}
 
Example 10
private static Map<String, String> toMap(@Nullable ReadableMap readableMap) {
  if (readableMap == null) {
    return null;
  }

  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
  if (!iterator.hasNextKey()) {
    return null;
  }

  Map<String, String> result = new HashMap<>();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    result.put(key, readableMap.getString(key));
  }

  return result;
}
 
Example 11
Source Project: react-native-oauth   Source File: OAuthManagerProviders.java    License: MIT License 6 votes vote down vote up
static private OAuthRequest addParametersToRequest(
  OAuthRequest request,
  final String access_token,
  @Nullable final ReadableMap params
) {
  if (params != null && params.hasKey("params")) {
    ReadableMapKeySetIterator iterator = params.keySetIterator();
    while (iterator.hasNextKey()) {
      String key = iterator.nextKey();
      ReadableType readableType = params.getType(key);
      switch(readableType) {
        case String:
          String val = params.getString(key);
          // String escapedVal = Uri.encode(val);
          if (val.equals("access_token")) {
            val = access_token;
          }
          request.addParameter(key, val);
          break;
        default:
          throw new IllegalArgumentException("Could not read object with key: " + key);
      }
    }
  }
  return request;
}
 
Example 12
Source Project: react-native-smooch   Source File: ReactNativeSmooch.java    License: MIT License 6 votes vote down vote up
private Map<String, Object> getUserProperties(ReadableMap properties) {
    ReadableMapKeySetIterator iterator = properties.keySetIterator();
    Map<String, Object> userProperties = new HashMap<>();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = properties.getType(key);
        if (type == ReadableType.Boolean) {
            userProperties.put(key, properties.getBoolean(key));
        } else if (type == ReadableType.Number) {
            userProperties.put(key, properties.getDouble(key));
        } else if (type == ReadableType.String) {
            userProperties.put(key, properties.getString(key));
        }
    }

    return userProperties;
}
 
Example 13
Source Project: react-native-arcgis-mapview   Source File: RNAGSGraphicsOverlay.java    License: MIT License 5 votes vote down vote up
private static Map<String, Object> readableMapToMap(ReadableMap rawMap) {
    Map<String, Object> map = new HashMap<>();
    ReadableMapKeySetIterator iterator = rawMap.keySetIterator();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        map.put(key, rawMap.getString(key));
    }
    return map;
}
 
Example 14
public static SipMessageDTO fromReadableMap(ReadableMap data) {
    SipMessageDTO result = new SipMessageDTO();

    if (data.hasKey("targetURI")) {
        result.setTargetUri(data.getString("targetURI"));
    }
    if (data.hasKey("headers")) {
        ReadableMap headersData = data.getMap("headers");
        ReadableMapKeySetIterator headersIt = headersData.keySetIterator();
        Map<String, String> headers = new HashMap<>();

        while (headersIt.hasNextKey()) {
            String key = headersIt.nextKey();
            headers.put(key, headersData.getString(key));
        }

        result.setHeaders(headers);
    }
    if (data.hasKey("contentType")) {
        result.setContentType(data.getString("contentType"));
    }
    if (data.hasKey("body")) {
        result.setBody(data.getString("body"));
    }

    return result;
}
 
Example 15
Source Project: react-native-sip   Source File: PjActions.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static void formatIntent(Intent intent, ReadableMap configuration) {
    if (configuration == null) {
        return;
    }

    ReadableMapKeySetIterator it = configuration.keySetIterator();
    while (it.hasNextKey()) {
        String key = it.nextKey();

        switch (configuration.getType(key)) {
            case Null:
                intent.putExtra(key, (String) null);
                break;
            case String:
                intent.putExtra(key, configuration.getString(key));
                break;
            case Number:
                intent.putExtra(key, configuration.getInt(key));
                break;
            case Boolean:
                intent.putExtra(key, configuration.getBoolean(key));
                break;
            case Map:
                intent.putExtra(key, (Serializable) formatMap(configuration.getMap(key)));
                break;
            default:
                Log.w(TAG, "Unable to put extra information for intent: unknown type \""+ configuration.getType(key) +"\"");
                break;
        }
    }
}
 
Example 16
Source Project: react-native-sip   Source File: PjActions.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static Map<String, Object> formatMap(ReadableMap map) {
    Map<String, Object> value = new HashMap<>();
    ReadableMapKeySetIterator mapIt = map.keySetIterator();

    while (mapIt.hasNextKey()) {
        String mapKey = mapIt.nextKey();

        switch (map.getType(mapKey)) {
            case Null:
                value.put(mapKey, null);
                break;
            case String:
                value.put(mapKey, map.getString(mapKey));
                break;
            case Number:
                value.put(mapKey, map.getInt(mapKey));
                break;
            case Boolean:
                value.put(mapKey, map.getBoolean(mapKey));
                break;
            case Array:
                value.put(mapKey, map.getArray(mapKey).toArrayList());
                break;
            case Map:
                value.put(mapKey, formatMap(map.getMap(mapKey)));
                break;
            default:
                Log.w(TAG, "Unable to put extra information for intent: unknown type \""+ map.getType(mapKey) +"\"");
                break;
        }
    }

    return value;
}
 
Example 17
Source Project: react-native-kakao-links   Source File: RNKakaoLinkModule.java    License: MIT License 5 votes vote down vote up
private Map<String, String> createTemplateArgsMap(ReadableMap templateArgs) {
  Map<String, String> templateArgsMap = new HashMap<>();
  ReadableMapKeySetIterator templateArgsKeys = templateArgs.keySetIterator();
  while (templateArgsKeys.hasNextKey()) {
    String key = templateArgsKeys.nextKey();
    String value = templateArgs.getString(key);
    templateArgsMap.put(key, value);
  }
  return templateArgsMap;
}
 
Example 18
Source Project: react-native-kakao-links   Source File: RNKakaoLinkModule.java    License: MIT License 5 votes vote down vote up
private Map<String, String> createServerCallbackArgsMap(ReadableMap serverCallbackArgs) {
  Map<String, String> serverCallbackArgsMap = new HashMap<>();
  ReadableMapKeySetIterator serverCallbackArgsKeys = serverCallbackArgs.keySetIterator();
  while (serverCallbackArgsKeys.hasNextKey()) {
    String key = serverCallbackArgsKeys.nextKey();
    String value = serverCallbackArgs.getString(key);
    serverCallbackArgsMap.put(key, value);
  }
  return serverCallbackArgsMap;
}
 
Example 19
Source Project: react-native-GPay   Source File: ReactOkHttpNetworkFetcher.java    License: MIT License 5 votes vote down vote up
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 20
Source Project: react-native-GPay   Source File: ViewManagerPropertyUpdater.java    License: MIT License 5 votes vote down vote up
public static <T extends ViewManager, V extends View> void updateProps(
    T manager,
    V v,
    ReactStylesDiffMap props) {
  ViewManagerSetter<T, V> setter = findManagerSetter(manager.getClass());
  ReadableMap propMap = props.mBackingMap;
  ReadableMapKeySetIterator iterator = propMap.keySetIterator();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    setter.setProperty(manager, v, key, props);
  }
}
 
Example 21
Source Project: react-native-GPay   Source File: ViewManagerPropertyUpdater.java    License: MIT License 5 votes vote down vote up
public static <T extends ReactShadowNode> void updateProps(T node, ReactStylesDiffMap props) {
  ShadowNodeSetter<T> setter = findNodeSetter(node.getClass());
  ReadableMap propMap = props.mBackingMap;
  ReadableMapKeySetIterator iterator = propMap.keySetIterator();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    setter.setProperty(node, key, props);
  }
}
 
Example 22
Source Project: react-native-GPay   Source File: StyleAnimatedNode.java    License: MIT License 5 votes vote down vote up
StyleAnimatedNode(ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager) {
  ReadableMap style = config.getMap("style");
  ReadableMapKeySetIterator iter = style.keySetIterator();
  mPropMapping = new HashMap<>();
  while (iter.hasNextKey()) {
    String propKey = iter.nextKey();
    int nodeIndex = style.getInt(propKey);
    mPropMapping.put(propKey, nodeIndex);
  }
  mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
}
 
Example 23
Source Project: react-native-GPay   Source File: PropsAnimatedNode.java    License: MIT License 5 votes vote down vote up
PropsAnimatedNode(ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager, UIImplementation uiImplementation) {
  ReadableMap props = config.getMap("props");
  ReadableMapKeySetIterator iter = props.keySetIterator();
  mPropNodeMapping = new HashMap<>();
  while (iter.hasNextKey()) {
    String propKey = iter.nextKey();
    int nodeIndex = props.getInt(propKey);
    mPropNodeMapping.put(propKey, nodeIndex);
  }
  mPropMap = new JavaOnlyMap();
  mDiffMap = new ReactStylesDiffMap(mPropMap);
  mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
  mUIImplementation = uiImplementation;
}
 
Example 24
Source Project: react-native-GPay   Source File: PropsAnimatedNode.java    License: MIT License 5 votes vote down vote up
public void restoreDefaultValues() {
  ReadableMapKeySetIterator it = mPropMap.keySetIterator();
  while(it.hasNextKey()) {
    mPropMap.putNull(it.nextKey());
  }

  mUIImplementation.synchronouslyUpdateViewOnUIThread(
    mConnectedViewTag,
    mDiffMap);
}
 
Example 25
public void testInvalidIteratorExceptionThrown() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithBasicTypes();
  waitForBridgeAndUIIdle();

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

  ReadableMapKeySetIterator mapIterator = map.keySetIterator();
  while (mapIterator.hasNextKey()) {
    mapIterator.nextKey();
  }
  assertInvalidIteratorExceptionThrown(mapIterator);
}
 
Example 26
private static void assertInvalidIteratorExceptionThrown(
    ReadableMapKeySetIterator iterator) {
  boolean gotException = false;
  try {
    iterator.nextKey();
  } catch (InvalidIteratorException expected) {
    gotException = true;
  }

  assertTrue(gotException);
}
 
Example 27
Source Project: react-native-batch-push   Source File: RNUtils.java    License: MIT License 5 votes vote down vote up
@Nullable
public static BatchEventData convertSerializedEventDataToEventData(@Nullable ReadableMap serializedEventData) {
    if (serializedEventData == null) {
        return null;
    }

    BatchEventData batchEventData = new BatchEventData();
    ReadableArray tags = serializedEventData.getArray("tags");

    for (int i = 0; i < tags.size(); i++) {
        batchEventData.addTag(tags.getString(i));
    }

    ReadableMap attributes = serializedEventData.getMap("attributes");
    ReadableMapKeySetIterator iterator = attributes.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableMap valueMap = attributes.getMap(key);

        String type = valueMap.getString("type");
        if ("string".equals(type)) {
            batchEventData.put(key, valueMap.getString("value"));
        } else if ("boolean".equals(type)) {
            batchEventData.put(key, valueMap.getBoolean("value"));
        } else if ("integer".equals(type)) {
            batchEventData.put(key, valueMap.getDouble("value"));
        } else if ("float".equals(type)) {
            batchEventData.put(key, valueMap.getDouble("value"));
        } else {
            Log.e("RNBatchPush", "Invalid parameter : Unknown event_data.attributes type (" + type + ")");
        }
    }

    return batchEventData;
}
 
Example 28
Source Project: react-native-simple-download-manager   Source File: Downloader.java    License: MIT License 5 votes vote down vote up
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 external = requestConfig.getBoolean("external");
    String external_path = requestConfig.getString("path");

    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));
    }

    

    if(external){
        request.setDestinationInExternalPublicDir(external_path, saveAsName);

    }else{
        request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, saveAsName);

    }

    request.setTitle(downloadTitle);
    request.setDescription(downloadDescription);
    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 29
Source Project: react-native-app-auth   Source File: MapUtil.java    License: MIT License 5 votes vote down vote up
public static HashMap<String, String> readableMapToHashMap(@Nullable ReadableMap readableMap) {

        HashMap<String, String> hashMap = new HashMap<>();
        if (readableMap != null) {
            ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
            while (iterator.hasNextKey()) {
                String nextKey = iterator.nextKey();
                hashMap.put(nextKey, readableMap.getString(nextKey));
            }
        }

        return hashMap;
    }
 
Example 30
private static boolean mapEqual(
    ReadableMap a,
    ReadableMap b
) {
  ReadableMapKeySetIterator iterator = b.keySetIterator();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    if (!a.hasKey(key)) return false;
    ReadableType type = b.getType(key);
    if (type != a.getType(key)) return false;
    switch (type) {
      case Null:
        break;
      case Boolean:
        if (a.getBoolean(key) != b.getBoolean(key)) return false;
        break;
      case Number:
        if (a.getDouble(key) != b.getDouble(key)) return false;
        break;
      case String:
        if (!a.getString(key).equals(b.getString(key))) return false;
        break;
      case Map:
        if (!mapEqual(a.getMap(key), b.getMap(key))) return false;
        break;
      case Array:
        if (!arrayEqual(a.getArray(key), b.getArray(key))) return false;
        break;
      default:
        Log.e(TAG, "Could not convert object with key: " + key + ".");
    }
  }
  return true;
}