com.facebook.react.bridge.WritableNativeArray Java Examples

The following examples show how to use com.facebook.react.bridge.WritableNativeArray. 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: CameraRollModule.java    From rn-camera-roll with MIT License 7 votes vote down vote up
@ReactMethod
public void getCameraImages(ReadableMap data, Callback onSuccess) {
    WritableNativeArray result = new WritableNativeArray();

    for(CameraImage imageData : CameraImagesManager.getCameraImages(this.context,
            data.getInt("first"), data.hasKey("after") ? data.getString("after") : "")) {
        WritableMap imageDataMap = new WritableNativeMap();
        imageDataMap.putString("uri", imageData.getLocalPath());
        imageDataMap.putInt("width", imageData.getWidth());
        imageDataMap.putInt("height", imageData.getHeight());
        imageDataMap.putInt("orientation", imageData.getOrientation());
        imageDataMap.putString("timestamp", Long.toString(imageData.getTimestamp()));

        result.pushMap(imageDataMap);
    }

    onSuccess.invoke(result);
}
 
Example #2
Source File: BeaconsAndroidModule.java    From react-native-beacons-android with MIT License 6 votes vote down vote up
private WritableMap createRangingResponse(Collection<Beacon> beacons, Region region) {
    WritableMap map = new WritableNativeMap();
    map.putString("identifier", region.getUniqueId());
    map.putString("uuid", region.getId1() != null ? region.getId1().toString() : "");
    WritableArray a = new WritableNativeArray();
    for (Beacon beacon : beacons) {
        WritableMap b = new WritableNativeMap();
        b.putString("uuid", beacon.getId1().toString());
        b.putInt("major", beacon.getId2().toInt());
        b.putInt("minor", beacon.getId3().toInt());
        b.putInt("rssi", beacon.getRssi());
        b.putDouble("distance", beacon.getDistance());
        b.putString("proximity", getProximity(beacon.getDistance()));
        a.pushMap(b);
    }
    map.putArray("beacons", a);
    return map;
}
 
Example #3
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
@ReactMethod
public void selectMemberFromGroup(ReadableMap params, Callback callback) {
    String groupId = params.getString("groupId");
    String searchText = params.getString("searchText");
    List<Nick> userList = ConnectionUtil.getInstance().selectMemberFromGroup(groupId, searchText);
    WritableNativeArray array = new WritableNativeArray();

    for (int i = 0; i < userList.size(); i++) {
        Nick nick = userList.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("xmppId", nick.getXmppId());
        map.putString("headerUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("UserList", array);
    re.putBoolean("ok", true);
    callback.invoke(re);
}
 
Example #4
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 查询不在星标联系人的好友
 *
 * @param callback
 */
@ReactMethod
public void selectFriendsNotInStarContacts(Callback callback) {
    List<Nick> list = IMDatabaseManager.getInstance().selectFriendsNotInStarContacts();
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < list.size(); i++) {
        Nick nick = list.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("Name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("XmppId", nick.getXmppId());
        map.putString("HeaderUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("contacts", array);
    callback.invoke(re);
}
 
Example #5
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
@ReactMethod
public void selectUserNotInStartContacts(String key, Callback callback) {
    List<Nick> list = IMDatabaseManager.getInstance().selectUserNotInStartContacts(key);
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < list.size(); i++) {
        Nick nick = list.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("Name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("XmppId", nick.getXmppId());
        map.putString("HeaderUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("users", array);
    callback.invoke(re);
}
 
Example #6
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
@ReactMethod
public void selectStarOrBlackContacts(String pkey, Callback callback) {
    List<Nick> list = IMDatabaseManager.getInstance().selectStarOrBlackContactsAsNick(pkey);
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < list.size(); i++) {
        Nick nick = list.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("Name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("XmppId", nick.getXmppId());
        map.putString("HeaderUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("data", array);
    callback.invoke(re);
}
 
Example #7
Source File: ReactNativeJson.java    From react-native-couchbase-lite with MIT License 6 votes vote down vote up
public static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException {
    WritableArray array = new WritableNativeArray();

    for (int i = 0; i < jsonArray.length(); i++) {
        Object value = jsonArray.get(i);
        if (value instanceof JSONObject) {
            array.pushMap(convertJsonToMap((JSONObject) value));
        } else if (value instanceof JSONArray) {
            array.pushArray(convertJsonToArray((JSONArray) value));
        } else if (value instanceof Boolean) {
            array.pushBoolean((Boolean) value);
        } else if (value instanceof Integer) {
            array.pushInt((Integer) value);
        } else if (value instanceof Double) {
            array.pushDouble((Double) value);
        } else if (value instanceof String) {
            array.pushString((String) value);
        } else {
            array.pushString(value.toString());
        }
    }
    return array;
}
 
Example #8
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
@ReactMethod
public void selectGroupMemberForKick(ReadableMap params, Callback callback) {
    String groupId = params.getString("groupId");
    List<Nick> userList = ConnectionUtil.getInstance().selectGroupMemberForKick(groupId);
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < userList.size(); i++) {
        Nick nick = userList.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("xmppId", nick.getXmppId());
        map.putString("headerUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("UserList", array);
    re.putBoolean("ok", true);
    callback.invoke(re);
}
 
Example #9
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 根据好友
 *
 * @param params
 * @param callback
 */
@ReactMethod
public void selectFriendsForGroupAdd(ReadableMap params, Callback callback) {
    String groupId = params.getString("groupId");
    List<Nick> userList = ConnectionUtil.getInstance().selectFriendsForGroupAdd(groupId);
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < userList.size(); i++) {
        Nick nick = userList.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("xmppId", nick.getXmppId());
        map.putString("headerUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        map.putString("desc",nick.getDescInfo());
        map.putBoolean("friend", true);
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("UserList", array);
    re.putBoolean("ok", true);
    callback.invoke(re);

}
 
Example #10
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 根据文字搜索联系人
 *
 * @param params
 * @param callback
 */
@ReactMethod
public void selectUserListByText(ReadableMap params, Callback callback) {
    String groupId = params.getString("groupId");
    String searchText = params.getString("searchText");
    List<Nick> userList = ConnectionUtil.getInstance().SelectUserListBySearchText(groupId, searchText);
    WritableNativeArray array = new WritableNativeArray();

    for (int i = 0; i < userList.size(); i++) {
        Nick nick = userList.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("xmppId", nick.getXmppId());
        map.putString("headerUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        map.putBoolean("hasInGroup", nick.isInGroup());
        map.putString("desc",nick.getDescInfo());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("UserList", array);
    re.putBoolean("ok", true);
    callback.invoke(re);
}
 
Example #11
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 根据搜索字段获取群组
 *
 * @param searchText
 * @param callback
 */
@ReactMethod
public void searchGroupListWithKey(String searchText, Callback callback) {
    List<Nick> nickList = ConnectionUtil.getInstance().SelectGroupListBySearchText(searchText, 100);
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < nickList.size(); i++) {
        Nick n = nickList.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("title", n.getName());
        map.putString("GroupId", n.getGroupId());
        String url = n.getHeaderSrc();
        if (TextUtils.isEmpty(url)) {
            url = defaultMucImage;
        }
        map.putString("HeaderUri", url);
        map.putString("Name", n.getName());
        array.pushMap(map);
    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("groupList", array);
    callback.invoke(re);
}
 
Example #12
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 获取群列表
 *
 * @param callback
 */
@ReactMethod
public void getGroupList(Callback callback) {
    List<Nick> nickList = ConnectionUtil.getInstance().SelectAllGroup();
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < nickList.size(); i++) {
        Nick n = nickList.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("title", n.getName());
        map.putString("GroupId", n.getGroupId());
        String url = n.getHeaderSrc();
        if (TextUtils.isEmpty(url)) {
            url = defaultMucImage;
        }
        map.putString("HeaderUri", url);
        map.putString("Name", n.getName());
        array.pushMap(map);
    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("groupList", array);
    callback.invoke(re);
}
 
Example #13
Source File: ReactVideoView.java    From react-native-video with MIT License 6 votes vote down vote up
public void onTimedMetaDataAvailable(MediaPlayer mp, TimedMetaData data) {
    WritableMap event = Arguments.createMap();

    try {
        String rawMeta  = new String(data.getMetaData(), "UTF-8");
        WritableMap id3 = Arguments.createMap();

        id3.putString(EVENT_PROP_METADATA_VALUE, rawMeta.substring(rawMeta.lastIndexOf("\u0003") + 1));
        id3.putString(EVENT_PROP_METADATA_IDENTIFIER, "id3/TDEN");

        WritableArray metadata = new WritableNativeArray();

        metadata.pushMap(id3);

        event.putArray(EVENT_PROP_METADATA, metadata);
        event.putDouble(EVENT_PROP_TARGET, getId());
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    mEventEmitter.receiveEvent(getId(), Events.EVENT_TIMED_METADATA.toString(), event);
}
 
Example #14
Source File: RNInstabugReactnativeModule.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
private WritableArray convertArrayListToWritableArray(List arrayList) {
    WritableArray writableArray = new WritableNativeArray();

    for(int i = 0; i < arrayList.size(); i++) {
        Object object = arrayList.get(i);

        if(object instanceof String) {
            writableArray.pushString((String) object);
        }
        else {
            JSONObject jsonObject = objectToJSONObject(object);
            writableArray.pushMap((WritableMap) jsonObject);
        }
    }

    return writableArray;

}
 
Example #15
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
@ReactMethod
public void searchFilesByXmppId(String xmppid, Callback callback) {
    WritableNativeArray writableNativeArray = new WritableNativeArray();
    JSONArray jsonArray = ConnectionUtil.getInstance().searchFilesMsgByXmppid(xmppid);
    for (int i = 0; i < jsonArray.length(); i++) {
        try {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            WritableNativeMap writableNativeMap = new WritableNativeMap();
            writableNativeMap.putString("from", jsonObject.optString("from"));
            writableNativeMap.putString("content", jsonObject.optString("content"));
            writableNativeMap.putString("time", jsonObject.optString("time"));
            writableNativeMap.putString("name", jsonObject.optString("name"));
            writableNativeMap.putString("headerSrc", jsonObject.optString("headerSrc"));
            writableNativeArray.pushMap(writableNativeMap);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
    if (callback != null) {
        WritableNativeMap map = new WritableNativeMap();
        map.putArray("files", writableNativeArray);
        callback.invoke(map);
    }
}
 
Example #16
Source File: RNSensitiveInfoModule.java    From react-native-sensitive-info with MIT License 6 votes vote down vote up
@ReactMethod
public void getAllItems(ReadableMap options, Promise pm) {

    String name = sharedPreferences(options);

    Map<String, ?> allEntries = prefs(name).getAll();
    WritableArray resultData = new WritableNativeArray();

    for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
        WritableMap entryMap = new WritableNativeMap();

        entryMap.putString("key", entry.getKey());
        entryMap.putString("value", entry.getValue().toString());
        entryMap.putString("service", name);
        resultData.pushMap(entryMap);
    }

    WritableArray resultWrapper = new WritableNativeArray();
    resultWrapper.pushArray(resultData);
    pm.resolve(resultWrapper);
}
 
Example #17
Source File: RNUtils.java    From react-native-batch-push with MIT License 6 votes vote down vote up
public static WritableArray convertArrayToWritableArray(Object[] input) {
    WritableArray output = new WritableNativeArray();

    for (int i = 0; i < input.length; i++) {
        Object value = input[i];
        if (value instanceof Map) {
            output.pushMap(convertMapToWritableMap((Map<String, Object>) value));
        } else if (value instanceof  JSONArray) {
            output.pushArray(convertArrayToWritableArray((Object[]) value));
        } else if (value instanceof  Boolean) {
            output.pushBoolean((Boolean) value);
        } else if (value instanceof  Integer) {
            output.pushInt((Integer) value);
        } else if (value instanceof  Double) {
            output.pushDouble((Double) value);
        } else if (value instanceof String)  {
            output.pushString((String) value);
        } else {
            output.pushString(value.toString());
        }
    }
    return output;
}
 
Example #18
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 获取日历功能城市列表
 *
 * @param callback
 */
@ReactMethod
public void getTripCity(Callback callback) {

    List<CityLocal.DataBean> list = IMDatabaseManager.getInstance().getCityList();
    WritableNativeMap map = new WritableNativeMap();
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < list.size(); i++) {
        WritableNativeMap item = new WritableNativeMap();
        item.putString("CityName", list.get(i).getCityName());
        item.putInt("CityId", list.get(i).getId());
        array.pushMap(item);
    }
    map.putBoolean("ok", true);
    map.putArray("cityList", array);
    callback.invoke(map);

}
 
Example #19
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 获取日历功能区域列表
 *
 * @param callback
 */
@ReactMethod
public void getTripArea(Callback callback) {
    List<AreaLocal.DataBean.ListBean> list = IMDatabaseManager.getInstance().getAreaList();
    WritableNativeMap map = new WritableNativeMap();
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < list.size(); i++) {
        WritableNativeMap item = new WritableNativeMap();
        item.putString("AddressName", list.get(i).getAreaName());
        item.putInt("AddressNumber", list.get(i).getAreaID());
        item.putString("rStartTime", list.get(i).getMorningStarts());
        item.putString("rEndTime", list.get(i).getEveningEnds());
        array.pushMap(item);
    }
    map.putBoolean("ok", true);
    map.putArray("areaList", array);
    callback.invoke(map);


}
 
Example #20
Source File: CatalystNativeJavaToJSArgumentsTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testStringWithMultibyteUTF8Characters() {
  TestJavaToJSArgumentsModule jsModule = mInstance.getJSModule(TestJavaToJSArgumentsModule.class);

  WritableNativeMap map = new WritableNativeMap();
  map.putString("two-bytes", "\u00A2");
  map.putString("three-bytes", "\u20AC");
  map.putString("four-bytes", "\uD83D\uDE1C");
  map.putString(
      "mixed",
      "\u017C\u00F3\u0142\u0107 g\u0119\u015Bl\u0105 \u6211 \uD83D\uDE0E ja\u017A\u0107");

  jsModule.receiveMapWithMultibyteUTF8CharacterString(map);
  waitForBridgeAndUIIdle();
  mAssertModule.verifyAssertsAndReset();

  WritableArray array = new WritableNativeArray();
  array.pushString("\u00A2");
  array.pushString("\u20AC");
  array.pushString("\uD83D\uDE1C");
  array.pushString(
      "\u017C\u00F3\u0142\u0107 g\u0119\u015Bl\u0105 \u6211 \uD83D\uDE0E ja\u017A\u0107");

  jsModule.receiveArrayWithMultibyteUTF8CharacterString(array);
  waitForBridgeAndUIIdle();
  mAssertModule.verifyAssertsAndReset();
}
 
Example #21
Source File: NotificationModule.java    From things-notification with Apache License 2.0 6 votes vote down vote up
@ReactMethod
public void getInstalledApps(Promise promise) {
    WritableNativeArray params = new WritableNativeArray();
    PackageManager pm = reactContext.getPackageManager();
    List<ApplicationInfo> apps = pm.getInstalledApplications(0);
    for(ApplicationInfo app : apps) {
        if ((pm.getLaunchIntentForPackage(app.packageName) != null) &&
                !thisApp.equals(app.packageName)) {
            WritableNativeMap param = new WritableNativeMap();
            String appName = app.loadLabel(pm).toString();
            String appPackage = app.packageName;
            String appIcon = saveIcon(appPackage, app.loadIcon(pm));
            //Log.d(TAG, "name: "+appName);
            //Log.d(TAG, "app: "+appPackage);
            //Log.d(TAG, "icon: "+appIcon);
            param.putString("name", appName);
            param.putString("app", appPackage);
            param.putString("icon", appIcon);
            //sendEvent("installedApps", param);
            params.pushMap(param);
        }
    }
    promise.resolve(params);
}
 
Example #22
Source File: CatalystNativeJavaToJSArgumentsTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testMapWithNullStringValue() {
  WritableNativeMap map = new WritableNativeMap();
  map.putString("string", null);
  map.putArray("array", null);
  map.putMap("map", null);

  WritableNativeArray array = new WritableNativeArray();
  array.pushString(null);
  array.pushArray(null);
  array.pushMap(null);

  mInstance.getJSModule(TestJavaToJSArgumentsModule.class)
      .receiveMapAndArrayWithNullValues(map, array);
  waitForBridgeAndUIIdle();
  mAssertModule.verifyAssertsAndReset();
}
 
Example #23
Source File: CatalystNativeJavaToJSArgumentsTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testMapWithArrays() {
  WritableNativeMap map = new WritableNativeMap();
  WritableNativeArray a1 = new WritableNativeArray();
  WritableNativeArray a2 = new WritableNativeArray();
  a1.pushDouble(3);
  a1.pushDouble(1);
  a1.pushDouble(4);
  a2.pushDouble(1);
  a2.pushDouble(9);
  map.putArray("array1", a1);
  map.putArray("array2", a2);

  mInstance.getJSModule(TestJavaToJSArgumentsModule.class).receiveMapWithArrays(map);
  waitForBridgeAndUIIdle();
  mAssertModule.verifyAssertsAndReset();
}
 
Example #24
Source File: CheckoutResultConverter.java    From react-native-square-reader-sdk with Apache License 2.0 6 votes vote down vote up
public WritableMap toJSObject(CheckoutResult result) {
    // We use this "Ignore if null" principle for all returned dictionary
    WritableMap mapToReturn = new WritableNativeMap();
    if (result.getTransactionId() != null) {
        mapToReturn.putString("transactionId", result.getTransactionId());
    }
    mapToReturn.putString("transactionClientId", result.getTransactionClientId());
    mapToReturn.putString("locationId", result.getLocationId());
    mapToReturn.putString("createdAt", DateFormatUtils.formatISO8601UTC(result.getCreatedAt()));
    Money totalMoney = result.getTotalMoney();
    mapToReturn.putMap("totalMoney", moneyConverter.toJSObject(totalMoney));
    Money totalTipMoney = result.getTotalTipMoney();
    mapToReturn.putMap("totalTipMoney", moneyConverter.toJSObject(totalTipMoney));

    WritableArray jsTenders = new WritableNativeArray();
    for (Tender tender : result.getTenders()) {
        jsTenders.pushMap(tenderConverter.toJSObject(tender));
    }
    mapToReturn.putArray("tenders", jsTenders);

    return mapToReturn;
}
 
Example #25
Source File: JSONEncoder.java    From react-native-google-fitness with MIT License 6 votes vote down vote up
public static WritableNativeArray convertDataSet(DataSet dataSet) {
    WritableNativeArray jsonDataSet = new WritableNativeArray();
    for (DataPoint dp : dataSet.getDataPoints()) {
        WritableNativeMap jsonDataPoint = new WritableNativeMap();

        jsonDataPoint.putString("type", dp.getDataType().getName());
        jsonDataPoint.putString("source", dp.getOriginalDataSource().getAppPackageName());
        jsonDataPoint.putString("start", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
        jsonDataPoint.putString("end", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)));

        WritableNativeArray jsonFieldValuePairs = new WritableNativeArray();
        for (Field field : dp.getDataType().getFields()) {
            WritableNativeMap jsonFieldValuePair = new WritableNativeMap();
            jsonFieldValuePair.putString("field", field.getName());
            jsonFieldValuePair.putString("value", dp.getValue(field).toString());
            jsonFieldValuePairs.pushMap(jsonFieldValuePair);
        }
        jsonDataPoint.putArray("fields", jsonFieldValuePairs);

        jsonDataSet.pushMap(jsonDataPoint);
    }
    return jsonDataSet;
}
 
Example #26
Source File: ReactNativeJson.java    From react-native-fcm with MIT License 6 votes vote down vote up
public static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException {
    WritableArray array = new WritableNativeArray();

    for (int i = 0; i < jsonArray.length(); i++) {
        Object value = jsonArray.get(i);
        if (value instanceof JSONObject) {
            array.pushMap(convertJsonToMap((JSONObject) value));
        } else if (value instanceof  JSONArray) {
            array.pushArray(convertJsonToArray((JSONArray) value));
        } else if (value instanceof  Boolean) {
            array.pushBoolean((Boolean) value);
        } else if (value instanceof  Integer) {
            array.pushInt((Integer) value);
        } else if (value instanceof  Double) {
            array.pushDouble((Double) value);
        } else if (value instanceof String)  {
            array.pushString((String) value);
        } else {
            array.pushString(value.toString());
        }
    }
    return array;
}
 
Example #27
Source File: AccountManagerModule.java    From react-native-account-manager with MIT License 6 votes vote down vote up
@ReactMethod
public void getAccountsByType (String accountType, Promise promise) {
		manager = AccountManager.get(_reactContext);
		Account[] account_list = manager.getAccountsByType(accountType);
		WritableNativeArray result = new WritableNativeArray();

		for(Account account: account_list)
		{
			Integer index = indexForAccount(account);

			WritableNativeMap account_object = new WritableNativeMap();
			account_object.putInt("_index", (int)index);
			account_object.putString("name", account.name);
			account_object.putString("type", account.type);
			result.pushMap(account_object);
		}

		promise.resolve(result);
}
 
Example #28
Source File: RNSecureStorageModule.java    From react-native-secure-storage with MIT License 6 votes vote down vote up
@ReactMethod
public void getAllKeys(String service, Promise promise) {
    try {
        service = getDefaultServiceIfNull(service);
        final PrefsStorage prefsStorage = new PrefsStorage(getReactApplicationContext(), service);
        String[] allKeys = prefsStorage.getAllKeys();
        WritableArray keyArray = new WritableNativeArray();
        for (String key : allKeys) {
            keyArray.pushString(key);
        }
        promise.resolve(keyArray);
        return;
    } catch (Exception e) {
        Log.e(SECURE_STORAGE_MODULE, e.getMessage());
        promise.reject(E_KEYSTORE_ACCESS_ERROR, e);
    }
}
 
Example #29
Source File: ActivityStarterModule.java    From react-native-android-activity with MIT License 6 votes vote down vote up
@ReactMethod
void callJavaScript() {
    Activity activity = getCurrentActivity();
    if (activity != null) {
        MainApplication application = (MainApplication) activity.getApplication();
        ReactNativeHost reactNativeHost = application.getReactNativeHost();
        ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
        ReactContext reactContext = reactInstanceManager.getCurrentReactContext();

        if (reactContext != null) {
            CatalystInstance catalystInstance = reactContext.getCatalystInstance();
            WritableNativeArray params = new WritableNativeArray();
            params.pushString("Hello, JavaScript!");

            // AFAIK, this approach to communicate from Java to JavaScript is officially undocumented.
            // Use at own risk; prefer events.
            // Note: Here we call 'alert', which shows UI. If this is done from an activity that
            // doesn't forward lifecycle events to React Native, it wouldn't work.
            catalystInstance.callFunction("JavaScriptVisibleToJava", "alert", params);
        }
    }
}
 
Example #30
Source File: FabricEventEmitter.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Destroys `touches` by removing touch objects at indices `indices`. This is
 * to maintain compatibility with W3C touch "end" events, where the active
 * touches don't include the set that has just been "ended".
 *
 * This method was originally in ReactNativeRenderer.js
 *
 * TODO: this method is a copy from ReactNativeRenderer.removeTouchesAtIndices and it needs
 * to be rewritten in a more efficient way,
 *
 * @param touches {@link WritableArray} Deserialized touch objects.
 * @param indices {WritableArray} Indices to remove from `touches`.
 * @return {Array<Touch>} Subsequence of removed touch objects.
 */
private Pair<WritableArray, WritableArray> removeTouchesAtIndices(WritableArray touches, WritableArray indices) {
  WritableArray rippedOut = new WritableNativeArray();
  // use an unsafe downcast to alias to nullable elements,
  // so we can delete and then compact.
  WritableArray tempTouches = new WritableNativeArray();
  Set<Integer> rippedOutIndices = new HashSet<>();
  for (int i = 0; i < indices.size(); i++) {
    int index = indices.getInt(i);
    rippedOut.pushMap(getWritableMap(touches.getMap(index)));
    rippedOutIndices.add(index);
  }
  for (int j = 0 ; j < touches.size() ; j++) {
    if (!rippedOutIndices.contains(j)) {
      tempTouches.pushMap(getWritableMap(touches.getMap(j)));
    }
  }

  return new Pair<>(rippedOut, tempTouches);
}