Java Code Examples for com.facebook.react.bridge.WritableMap#putBoolean()

The following examples show how to use com.facebook.react.bridge.WritableMap#putBoolean() . 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 check out the related API usage on the sidebar.
Example 1
Source File: MapUtil.java    From vinci with Apache License 2.0 7 votes vote down vote up
public static WritableMap toWritableMap(Map<String, Object> map) {
    WritableMap writableMap = Arguments.createMap();
    Iterator iterator = map.entrySet().iterator();

    while (iterator.hasNext()) {
        Map.Entry pair = (Map.Entry) iterator.next();
        Object value = pair.getValue();

        if (value == null) {
            writableMap.putNull((String) pair.getKey());
        } else if (value instanceof Boolean) {
            writableMap.putBoolean((String) pair.getKey(), (Boolean) value);
        } else if (value instanceof Double) {
            writableMap.putDouble((String) pair.getKey(), (Double) value);
        } else if (value instanceof Integer) {
            writableMap.putInt((String) pair.getKey(), (Integer) value);
        } else if (value instanceof String) {
            writableMap.putString((String) pair.getKey(), (String) value);
        } else if (value instanceof Map) {
            writableMap.putMap((String) pair.getKey(), MapUtil.toWritableMap((Map<String, Object>) value));
        } else if (value.getClass() != null && value.getClass().isArray()) {
            writableMap.putArray((String) pair.getKey(), ArrayUtil.toWritableArray((Object[]) value));
        }

        iterator.remove();
    }

    return writableMap;
}
 
Example 2
Source File: RNUtils.java    From react-native-batch-push with MIT License 6 votes vote down vote up
public static WritableMap convertMapToWritableMap(Map<String, Object> input) {
    WritableMap output = new WritableNativeMap();

     for(Map.Entry<String, Object> entry: input.entrySet()){
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value instanceof Map) {
            output.putMap(key, convertMapToWritableMap((Map<String, Object>) value));
        } else if (value instanceof JSONArray) {
            output.putArray(key, convertArrayToWritableArray((Object[])value));
        } else if (value instanceof  Boolean) {
            output.putBoolean(key, (Boolean) value);
        } else if (value instanceof  Integer) {
            output.putInt(key, (Integer) value);
        } else if (value instanceof  Double) {
            output.putDouble(key, (Double) value);
        } else if (value instanceof String)  {
            output.putString(key, (String) value);
        } else {
            output.putString(key, value.toString());
        }
    }
    return output;
}
 
Example 3
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
     * 获取用户通知是否显示详情
     *
     * @param callback
     */
    @ReactMethod
    public void getNotifyPushDetailsState(Callback callback) {

//        CurrentPreference.ProFile proFile = CurrentPreference.getInstance().getProFile();
//        WritableMap map = new WritableNativeMap();
////        WritableMap params = new WritableNativeMap();
////        params.putBoolean("getNotifySoundState",proFile.isTurnOnMsgSound());
//        map.putBoolean("state", proFile.isShowContentPush());
//        callback.invoke(map);

        WritableMap map = new WritableNativeMap();
        boolean state = ConnectionUtil.getInstance().getPushStateBy(PushSettinsStatus.SHOW_CONTENT);
        map.putBoolean("state", state);
        callback.invoke(map);
    }
 
Example 4
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
     * 获取通知声音状态
     *
     * @param callback
     */
    @ReactMethod
    public void getNotifySoundState(Callback callback) {
//        CurrentPreference.ProFile proFile = CurrentPreference.getInstance().getProFile();
//        WritableMap map = new WritableNativeMap();
////        WritableMap params = new WritableNativeMap();
////        params.putBoolean("getNotifySoundState",proFile.isTurnOnMsgSound());
//        map.putBoolean("state", proFile.isTurnOnMsgSound());
//        callback.invoke(map);

        WritableMap map = new WritableNativeMap();
        boolean state = ConnectionUtil.getInstance().getPushStateBy(PushSettinsStatus.SOUND_INAPP);
        map.putBoolean("state", state);
        callback.invoke(map);

    }
 
Example 5
Source File: TelephonyModule.java    From react-native-telephony with MIT License 6 votes vote down vote up
@Override
public void phoneSignalStrengthsUpdated(SignalStrength signalStrength) {
    WritableMap map = Arguments.createMap();
    map.putInt("cdmaDbm", signalStrength.getCdmaDbm());
    map.putInt("cdmaEcio()", signalStrength.getCdmaEcio());
    map.putInt("evdoDbm", signalStrength.getEvdoDbm());
    map.putInt("evdoEcio", signalStrength.getEvdoEcio());
    map.putInt("evdoSnr", signalStrength.getEvdoSnr());
    map.putInt("gsmBitErrorRate", signalStrength.getGsmBitErrorRate());
    map.putInt("gsmSignalStrength", signalStrength.getGsmSignalStrength());
    map.putBoolean("gsm", signalStrength.isGsm());

    WritableMap result = Arguments.createMap();
    result.putString("type", "LISTEN_SIGNAL_STRENGTHS");
    result.putMap("data", map);

    sendEvent(PHONE_STATE_LISTENER, result);
}
 
Example 6
Source File: RNHceModule.java    From react-native-nfc-hce with Apache License 2.0 6 votes vote down vote up
private WritableMap supportNFC() {
    NfcManager manager = (NfcManager) this.reactContext.getSystemService(this.reactContext.NFC_SERVICE);
    NfcAdapter adapter = manager.getDefaultAdapter();
    WritableMap map = Arguments.createMap();
    if (adapter != null) {
        map.putBoolean("support", true);
        if (adapter.isEnabled()) {
            map.putBoolean("enabled", true);
        } else {
            map.putBoolean("enabled", false);
        }
    } else {
        map.putBoolean("support", false);
        map.putBoolean("enabled", false);
    }

    return map;
}
 
Example 7
Source File: RCTConvert.java    From react-native-twilio-chat with MIT License 6 votes vote down vote up
public static WritableMap Paginator(Object paginator, String sid, String type) {
    WritableMap map = Arguments.createMap();
    WritableMap _paginator = Arguments.createMap();
    switch (type) {
        case "Channel":
            _paginator.putArray("items", Channels(((Paginator<Channel>)paginator).getItems()));
            _paginator.putBoolean("hasNextPage", ((Paginator<Channel>)paginator).hasNextPage());
            break;
        case "ChannelDescriptor":
            _paginator.putArray("items", ChannelDescriptors(((Paginator<ChannelDescriptor>)paginator).getItems()));
            _paginator.putBoolean("hasNextPage", ((Paginator<ChannelDescriptor>)paginator).hasNextPage());
            break;
        case "Member":
            _paginator.putArray("items", Members(((Paginator<Member>)paginator).getItems()));
            _paginator.putBoolean("hasNextPage", ((Paginator<Member>)paginator).hasNextPage());
            break;
    }
    map.putString("sid", sid);
    map.putString("type", type);
    map.putMap("paginator", _paginator);
    return map;
}
 
Example 8
Source File: InAppBillingBridge.java    From react-native-billing with MIT License 6 votes vote down vote up
private WritableMap mapTransactionDetails(TransactionDetails details) {
    WritableMap map = Arguments.createMap();

    map.putString("receiptData", details.purchaseInfo.responseData.toString());

    if (details.purchaseInfo.signature != null)
        map.putString("receiptSignature", details.purchaseInfo.signature.toString());

    PurchaseData purchaseData = details.purchaseInfo.purchaseData;

    map.putString("productId", purchaseData.productId);
    map.putString("orderId", purchaseData.orderId);
    map.putString("purchaseToken", purchaseData.purchaseToken);
    map.putString("purchaseTime", purchaseData.purchaseTime == null
      ? "" : purchaseData.purchaseTime.toString());
    map.putString("purchaseState", purchaseData.purchaseState == null
      ? "" : purchaseData.purchaseState.toString());
    map.putBoolean("autoRenewing", purchaseData.autoRenewing);

    if (purchaseData.developerPayload != null)
        map.putString("developerPayload", purchaseData.developerPayload);

    return map;
}
 
Example 9
Source File: NavigationBarColorModule.java    From react-native-navigation-bar-color with MIT License 6 votes vote down vote up
@ReactMethod
public void showNavigationBar(Promise promise) {
    try {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (getCurrentActivity() != null) {
                    View decorView = getCurrentActivity().getWindow().getDecorView();
                    int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
                    decorView.setSystemUiVisibility(uiOptions);
                }
            }
        });
    } catch (IllegalViewOperationException e) {
        WritableMap map = Arguments.createMap();
        map.putBoolean("success", false);
        promise.reject("error", e);
    }
}
 
Example 10
Source File: RNKakaoLinkModule.java    From react-native-kakao-links with MIT License 5 votes vote down vote up
@Override
public void onSuccess(T result) {
  // 템플릿 밸리데이션과 쿼터 체크가 성공적으로 끝남. 톡에서 정상적으로 보내졌는지 보장은 할 수 없다. 전송 성공 유무는 서버콜백 기능을 이용하여야 한다.
  WritableMap map = Arguments.createMap();
  map.putBoolean("success", true);
  KakaoLinkResponse kakaoResponse = (KakaoLinkResponse) result;
  map.putString("argumentMsg", kakaoResponse.getArgumentMsg().toString());
  promise.resolve(map);
}
 
Example 11
Source File: ReactSliderEvent.java    From react-native-GPay with MIT License 5 votes vote down vote up
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  eventData.putInt("target", getViewTag());
  eventData.putDouble("value", getValue());
  eventData.putBoolean("fromUser", isFromUser());
  return eventData;
}
 
Example 12
Source File: CameraRollManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
private static void putPageInfo(Cursor photos, WritableMap response, int limit) {
  WritableMap pageInfo = new WritableNativeMap();
  pageInfo.putBoolean("has_next_page", limit < photos.getCount());
  if (limit < photos.getCount()) {
    photos.moveToPosition(limit - 1);
    pageInfo.putString(
        "end_cursor",
        photos.getString(photos.getColumnIndex(Images.Media.DATE_TAKEN)));
  }
  response.putMap("page_info", pageInfo);
}
 
Example 13
Source File: CatalystNativeJavaToJSReturnValuesTestCase.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactMethod(isBlockingSynchronousMethod = true)
WritableMap getMap() {
  WritableMap map = new WritableNativeMap();
  map.putBoolean("a", true);
  map.putBoolean("b", false);
  return map;
}
 
Example 14
Source File: QimRNBModule.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
     * 获取用户通知震动状态
     *
     * @param callback
     */
    @ReactMethod
    public void getNotifyVibrationState(Callback callback) {
//        CurrentPreference.ProFile proFile = CurrentPreference.getInstance().getProFile();
//        WritableMap map = new WritableNativeMap();
////        WritableMap params = new WritableNativeMap();
////        params.putBoolean("getNotifySoundState",proFile.isTurnOnMsgSound());
//        map.putBoolean("state", proFile.isTurnOnMsgShock());
//        callback.invoke(map);

        WritableMap map = new WritableNativeMap();
        boolean state = ConnectionUtil.getInstance().getPushStateBy(PushSettinsStatus.VIBRATE_INAPP);
        map.putBoolean("state", state);
        callback.invoke(map);
    }
 
Example 15
Source File: NavigationStateChangeEvent.java    From react-native-crosswalk-webview-plus with MIT License 5 votes vote down vote up
private WritableMap serializeEventData () {
    WritableMap eventData = Arguments.createMap();
    eventData.putString("title", title);
    eventData.putBoolean("loading", isLoading);
    eventData.putString("url", url);
    eventData.putBoolean("canGoBack", canGoBack);
    eventData.putBoolean("canGoForward", canGoForward);

    return eventData;
}
 
Example 16
Source File: RNKakaoLoginsModule.java    From react-native-kakao-login with MIT License 5 votes vote down vote up
private void handleOptionalBooleanWithMap(WritableMap map, String key, OptionalBoolean bool){
    switch(bool){
        case NONE:
            map.putNull(key);
            break;
        default:
            map.putBoolean(key, bool.getBoolean());
            break;
    }
}
 
Example 17
Source File: FirestackModule.java    From react-native-firestack with MIT License 4 votes vote down vote up
@Override
public void onHostPause() {
    WritableMap params = Arguments.createMap();
    params.putBoolean("isForeground", false);
    FirestackUtils.sendEvent(mReactContext, "FirestackAppState", params);
}
 
Example 18
Source File: FirestackUtils.java    From react-native-firestack with MIT License 4 votes vote down vote up
public static WritableMap dataSnapshotToMap(String name, 
  String path, 
  DataSnapshot dataSnapshot) {
    WritableMap data = Arguments.createMap();

    data.putString("key", dataSnapshot.getKey());
    data.putBoolean("exists", dataSnapshot.exists());
    data.putBoolean("hasChildren", dataSnapshot.hasChildren());

    data.putDouble("childrenCount", dataSnapshot.getChildrenCount());
    if (!dataSnapshot.hasChildren()) {
      Object value = dataSnapshot.getValue();
      String type = value!=null ? value.getClass().getName() : "";
      switch (type) {
        case "java.lang.Boolean":
          data.putBoolean("value", (Boolean)value);
          break;
        case "java.lang.Long":
          Long longVal = (Long) value;
          data.putDouble("value", (double)longVal);
          break;
        case "java.lang.Double":
          data.putDouble("value", (Double) value);
          break;
        case "java.lang.String":
          data.putString("value",(String) value);
          break;
        default:
          data.putString("value", null);
      }
    } else{
      WritableMap valueMap = FirestackUtils.castSnapshotValue(dataSnapshot);
      data.putMap("value", valueMap);
    }

    // Child keys
    WritableArray childKeys = FirestackUtils.getChildKeys(dataSnapshot);
    data.putArray("childKeys", childKeys);

    Object priority = dataSnapshot.getPriority();
    if (priority == null) {
      data.putString("priority", null);
    } else {
      data.putString("priority", priority.toString());
    }

    WritableMap eventMap = Arguments.createMap();
    eventMap.putString("eventName", name);
    eventMap.putMap("snapshot", data);
    eventMap.putString("path", path);
    return eventMap;
}
 
Example 19
Source File: RNCallKeepModule.java    From react-native-callkeep with ISC License 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    WritableMap args = Arguments.createMap();
    HashMap<String, String> attributeMap = (HashMap<String, String>)intent.getSerializableExtra("attributeMap");

    switch (intent.getAction()) {
        case ACTION_END_CALL:
            args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
            sendEventToJS("RNCallKeepPerformEndCallAction", args);
            break;
        case ACTION_ANSWER_CALL:
            args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
            sendEventToJS("RNCallKeepPerformAnswerCallAction", args);
            break;
        case ACTION_HOLD_CALL:
            args.putBoolean("hold", true);
            args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
            sendEventToJS("RNCallKeepDidToggleHoldAction", args);
            break;
        case ACTION_UNHOLD_CALL:
            args.putBoolean("hold", false);
            args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
            sendEventToJS("RNCallKeepDidToggleHoldAction", args);
            break;
        case ACTION_MUTE_CALL:
            args.putBoolean("muted", true);
            args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
            sendEventToJS("RNCallKeepDidPerformSetMutedCallAction", args);
            break;
        case ACTION_UNMUTE_CALL:
            args.putBoolean("muted", false);
            args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
            sendEventToJS("RNCallKeepDidPerformSetMutedCallAction", args);
            break;
        case ACTION_DTMF_TONE:
            args.putString("digits", attributeMap.get("DTMF"));
            args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
            sendEventToJS("RNCallKeepDidPerformDTMFAction", args);
            break;
        case ACTION_ONGOING_CALL:
            args.putString("handle", attributeMap.get(EXTRA_CALL_NUMBER));
            args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID));
            args.putString("name", attributeMap.get(EXTRA_CALLER_NAME));
            sendEventToJS("RNCallKeepDidReceiveStartCallAction", args);
            break;
        case ACTION_AUDIO_SESSION:
            sendEventToJS("RNCallKeepDidActivateAudioSession", null);
            break;
        case ACTION_CHECK_REACHABILITY:
            sendEventToJS("RNCallKeepCheckReachability", null);
            break;
        case ACTION_WAKE_APP:
            Intent headlessIntent = new Intent(reactContext, RNCallKeepBackgroundMessagingService.class);
            headlessIntent.putExtra("callUUID", attributeMap.get(EXTRA_CALL_UUID));
            headlessIntent.putExtra("name", attributeMap.get(EXTRA_CALLER_NAME));
            headlessIntent.putExtra("handle", attributeMap.get(EXTRA_CALL_NUMBER));
            Log.d(TAG, "wakeUpApplication: " + attributeMap.get(EXTRA_CALL_UUID) + ", number : " + attributeMap.get(EXTRA_CALL_NUMBER) + ", displayName:" + attributeMap.get(EXTRA_CALLER_NAME));

            ComponentName name = reactContext.startService(headlessIntent);
            if (name != null) {
                HeadlessJsTaskService.acquireWakeLockNow(reactContext);
            }
            break;
    }
}
 
Example 20
Source File: ReactSwitchEvent.java    From react-native-GPay with MIT License 4 votes vote down vote up
private WritableMap serializeEventData() {
    WritableMap eventData = Arguments.createMap();
    eventData.putInt("target", getViewTag());
    eventData.putBoolean("value", getIsChecked());
    return eventData;
}