Java 类com.facebook.react.bridge.WritableArray 实例源码

项目:react-native-ibeacons    文件:BeaconsAndroidModule.java   
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;
}
项目:react-native-webrtc    文件:WebRTCModule.java   
@ReactMethod
public void mediaStreamTrackGetSources(Callback callback){
    WritableArray array = Arguments.createArray();
    String[] names = new String[Camera.getNumberOfCameras()];

    for(int i = 0; i < Camera.getNumberOfCameras(); ++i) {
        WritableMap info = getCameraInfo(i);
        if (info != null) {
            array.pushMap(info);
        }
    }

    WritableMap audio = Arguments.createMap();
    audio.putString("label", "Audio");
    audio.putString("id", "audio-1");
    audio.putString("facing", "");
    audio.putString("kind", "audio");

    array.pushMap(audio);
    callback.invoke(array);
}
项目:react-native-android-speech-recognizer    文件:ArgumentsConverter.java   
public static void pushObject(WritableArray a, Object v) {
  if (v == null) {
    a.pushNull();
  } else if (v instanceof String) {
    a.pushString((String) v);
  } else if (v instanceof Bundle) {
    a.pushMap(fromBundle((Bundle) v));
  } else if (v instanceof Byte) {
    a.pushInt(((Byte) v) & 0xff);
  } else if (v instanceof Integer) {
    a.pushInt((Integer) v);
  } else if (v instanceof Float) {
    a.pushDouble((Float) v);
  } else if (v instanceof Double) {
    a.pushDouble((Double) v);
  } else if (v instanceof Boolean) {
    a.pushBoolean((Boolean) v);
  } else {
    throw new IllegalArgumentException("Unknown type " + v.getClass());
  }
}
项目:react-native-google-fit    文件:StepHistory.java   
private void processDataSet(DataSet dataSet, WritableArray map) {
    //Log.i(TAG, "Data returned for Data type: " + dataSet.getDataType().getName());

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    dateFormat.setTimeZone(TimeZone.getDefault());

    WritableMap stepMap = Arguments.createMap();

    for (DataPoint dp : dataSet.getDataPoints()) {
        Log.i(TAG, "\tData point:");
        Log.i(TAG, "\t\tType : " + dp.getDataType().getName());
        Log.i(TAG, "\t\tStart: " + dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
        Log.i(TAG, "\t\tEnd  : " + dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)));

        for(Field field : dp.getDataType().getFields()) {
            Log.i(TAG, "\t\tField: " + field.getName() +
                    " Value: " + dp.getValue(field));

            stepMap.putDouble("startDate", dp.getStartTime(TimeUnit.MILLISECONDS));
            stepMap.putDouble("endDate", dp.getEndTime(TimeUnit.MILLISECONDS));
            stepMap.putDouble("steps", dp.getValue(field).asInt());
            map.pushMap(stepMap);
        }
    }
}
项目:react-native-google-fit    文件:WeightsHistory.java   
private void processDataSet(DataSet dataSet, WritableArray map) {
    //Log.i(TAG, "Data returned for Data type: " + dataSet.getDataType().getName());
    Format formatter = new SimpleDateFormat("EEE");

    WritableMap stepMap = Arguments.createMap();


    for (DataPoint dp : dataSet.getDataPoints()) {
        String day = formatter.format(new Date(dp.getStartTime(TimeUnit.MILLISECONDS)));

        int i = 0;

        for (Field field : dp.getDataType().getFields()) {
            i++;
            if (i > 1) continue; //Get only average instance

            stepMap.putString("day", day);
            stepMap.putDouble("startDate", dp.getStartTime(TimeUnit.MILLISECONDS));
            stepMap.putDouble("endDate", dp.getEndTime(TimeUnit.MILLISECONDS));
            stepMap.putDouble("value", dp.getValue(field).asFloat());
        }
    }
    map.pushMap(stepMap);
}
项目:react-native-ir-manager    文件:RNIRManagerModule.java   
@ReactMethod
public void getCarrierFrequencies(Promise promise) {
    try {
        CarrierFrequencyRange[] carrierFrequencyRanges = manager.getCarrierFrequencies();
        WritableArray carrierFrequencies = Arguments.createArray();

        for (CarrierFrequencyRange carrierFrequencyRange : carrierFrequencyRanges) {
            WritableMap carrierFrequency = Arguments.createMap();
            carrierFrequency.putInt("minFrequency", carrierFrequencyRange.getMinFrequency());
            carrierFrequency.putInt("maxFrequency", carrierFrequencyRange.getMaxFrequency());
            carrierFrequencies.pushMap(carrierFrequency);
        }

        promise.resolve(carrierFrequencies);
    } catch (Exception e) {
        promise.reject(e);
    }

}
项目:react-native-sockets    文件:SocketsModule.java   
@ReactMethod
public void getIpAddress(Callback successCallback, Callback errorCallback) {
    WritableArray ipList = Arguments.createArray();
    try {
        Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (enumNetworkInterfaces.hasMoreElements()) {
            NetworkInterface networkInterface = enumNetworkInterfaces.nextElement();
            Enumeration<InetAddress> enumInetAddress = networkInterface.getInetAddresses();
            while (enumInetAddress.hasMoreElements()) {
                InetAddress inetAddress = enumInetAddress.nextElement();
                if (inetAddress.isSiteLocalAddress()) {
                    ipList.pushString(inetAddress.getHostAddress());
                }
            }
        }
    } catch (SocketException e) {
        Log.e(eTag, "getIpAddress SocketException", e);
        errorCallback.invoke(e.getMessage());
    }
    successCallback.invoke(ipList);
}
项目:react-native-scandit    文件:SGScanditPicker.java   
private void addResponse() {
    final String key = "result";
    Object value = getResponse();

    if (value instanceof Boolean)            promiseResponse.putBoolean(key, (Boolean)value);
    else if (value instanceof String)        promiseResponse.putString (key, (String)value);
    else if (value instanceof Double)        promiseResponse.putDouble (key, (Double)value);
    else if (value instanceof Integer)       promiseResponse.putInt    (key, (Integer)value);
    else if (value instanceof WritableMap)   promiseResponse.putMap    (key, (WritableMap) value);
    else if (value instanceof WritableArray) promiseResponse.putArray  (key, (WritableArray) value);
    else if (value == null)                  promiseResponse.putNull(key);

    if (promiseFailed) {
        promiseResponse.putString("type", "reject");
    } else {
        promiseResponse.putString("type", "resolve");
    }
}
项目:react-native-android-text-to-speech    文件:RNAndroidTextToSpeechModule.java   
@ReactMethod 
public void getAvailableLocales(Promise promise) {
    if(notReady(promise)) return;

    try {
        WritableArray localeList = Arguments.createArray();
        Locale[] localesArray = Locale.getAvailableLocales();
        for(Locale locale: localesArray) {
            int isAvailable = tts.isLanguageAvailable(locale);
            if(isAvailable == TextToSpeech.LANG_COUNTRY_AVAILABLE) {
                WritableMap newLocale = returnMapForLocale(locale);
                localeList.pushMap(newLocale);
            }
        }

        promise.resolve(localeList);
    } catch(Exception e) {
        promise.reject("error", "Unable to retrieve locales for getAvailableLocales()", e);
    }
}
项目:react-native-android-text-to-speech    文件:RNAndroidTextToSpeechModule.java   
@ReactMethod
public void getAvailableVoices(Promise promise) {
    if(notReady(promise)) return;

    try {
        WritableArray voicesList = Arguments.createArray();
        Voice[] array = tts.getVoices().toArray(new Voice[tts.getVoices().size()]);
        for(Voice voice: array) {
            WritableMap newVoice = returnMapForVoice(voice);
            voicesList.pushMap(newVoice);
        }

        promise.resolve(voicesList);
    } catch(Exception e) {
        promise.reject("not_found", "Unable to retrieve voices for getAvailableVoices()", e);
    }
}
项目:react-native-android-text-to-speech    文件:RNAndroidTextToSpeechModule.java   
@ReactMethod
public void getEnginesInfo(Promise promise) {
    if(notReady(promise)) return;

    try {
        WritableArray ttsInfo = Arguments.createArray();

        List<TextToSpeech.EngineInfo> engineList = tts.getEngines();
        Iterator iterator = engineList.iterator();
        while(iterator.hasNext()) {
            ttsInfo.pushString(iterator.next().toString());
        }

        promise.resolve(ttsInfo);
    } catch(Exception e) {
        promise.reject("error", "Unable to retrieve TTS Engine info for getEnginesInfo()", e);
    }
}
项目:react-native-geth    文件:GethHolder.java   
protected void writeStaticNodesFile(String enodes) {
    try {
        File dir = new File(this.reactContext
                .getFilesDir() + STATIC_NODES_FILES_PATH);
        if (dir.exists() == false) dir.mkdirs();
        File f = new File(dir, STATIC_NODES_FILES_NAME);
        if (f.exists() == false) {
            if (f.createNewFile() == true) {
                WritableArray staticNodes = new WritableNativeArray();
                staticNodes.pushString(enodes);
                Writer output = new BufferedWriter(new FileWriter(f));
                output.write(staticNodes.toString());
                output.close();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:react-native-stt    文件:LocalesBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
  Logger.debug(TAG, "onReceive");
  Bundle results = getResultExtras(true);
  WritableMap data = Arguments.createMap();
  if (results.containsKey(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE))
  {
    String languagePreference =
        results.getString(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE);
    data.putString("languagePreference", languagePreference);
  }
  if (results.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES))
  {
    List<String> supportedLanguages =
        results.getStringArrayList(
            RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);
    WritableArray languages =
        Arguments.fromArray(supportedLanguages.toArray(new String[0]));
    data.putArray("supportedLanguages", languages);
  }

  emit(SUPPORTED_LOCALES, data);
}
项目:RNLearn_Project1    文件:CatalystNativeJavaToJSArgumentsTestCase.java   
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();
}
项目:RNLearn_Project1    文件:CatalystNativeJavaToJSArgumentsTestCase.java   
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();
}
项目:react-native-android-library-humaniq-api    文件:ModelConverterUtils.java   
private 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;
}
项目:react-native-batch-push    文件:RNBatchPushModule.java   
@ReactMethod
public void fetchNewNotifications(String userID, String authKey, final Promise promise) {
  try {
    BatchInboxFetcher inboxFetcher = Batch.Inbox.getFetcher(userID, authKey);
    inboxFetcher.fetchNewNotifications(new BatchInboxFetcher.OnNewNotificationsFetchedListener() {
      public void onFetchSuccess(@NonNull List<BatchInboxNotificationContent> notifications, boolean foundNewNotifications, boolean endReached) {
        WritableArray jsNotifications = Arguments.createArray();

        for (BatchInboxNotificationContent notification : notifications) {
          Bundle payloadBundle = new Bundle();
          for (Map.Entry<String, String> entry : notification.getRawPayload().entrySet()) {
            payloadBundle.putString(entry.getKey(), entry.getValue());
          }
          WritableMap jsNotification = Arguments.createMap();
          jsNotification.putMap("payload", Arguments.fromBundle(payloadBundle));
          jsNotification.putString("title", notification.getTitle());
          jsNotification.putString("body", notification.getBody());
          jsNotification.putDouble("timestamp", notification.getDate().getTime());
          jsNotifications.pushMap(jsNotification);
        }

        promise.resolve(jsNotifications);
      }

      public void onFetchFailure(@NonNull String error) {
        promise.reject("BATCH_ERROR", "Error fetching new notifications: " + error);
      }
    });
  } catch (Exception exception) {
    Log.e("RNBatchPush", "Unknown exception: " + exception.getMessage());
  }
}
项目:react-native-alarm-notification    文件:ANModule.java   
@ReactMethod
public void getScheduledAlarms(Promise promise) {
    ArrayList<Bundle> bundles = anHelper.getScheduledAlarms();
    WritableArray array = Arguments.createArray();
    for(Bundle bundle:bundles){
        array.pushMap(Arguments.fromBundle(bundle));
    }
    promise.resolve(array);
}
项目:react-native-mssql    文件:ArrayUtil.java   
public static WritableArray toWritableArray(Object[] array) {
  WritableArray writableArray = Arguments.createArray();

  for (int i = 0; i < array.length; i++) {
    Object value = array[i];

    if (value == null) {
      writableArray.pushNull();
    }
    if (value instanceof Boolean) {
      writableArray.pushBoolean((Boolean) value);
    }
    if (value instanceof Double) {
      writableArray.pushDouble((Double) value);
    }
    if (value instanceof Integer) {
      writableArray.pushInt((Integer) value);
    }
    if (value instanceof String) {
      writableArray.pushString((String) value);
    }
    if (value instanceof Map) {
      writableArray.pushMap(MapUtil.toWritableMap((Map<String, Object>) value));
    }
    if (value.getClass().isArray()) {
      writableArray.pushArray(ArrayUtil.toWritableArray((Object[]) value));
    }
  }

  return writableArray;
}
项目:react-native-scandit    文件:SGScanditPicker.java   
public void didScan(ScanSession scanSession) {
    List<Barcode> newBarcodes = scanSession.getNewlyRecognizedCodes();

    WritableArray newlyRecognizedCodes = Arguments.createArray();
    for (Barcode barcode: newBarcodes) {
        newlyRecognizedCodes.pushMap(ScanditBarcodeHelpers.barcodeToWritableMap(barcode));
    }

    WritableMap event = Arguments.createMap();
    event.putArray(NEWLY_RECOGNIZED_CODES, newlyRecognizedCodes);

    eventDispatcher.dispatchEvent(new DidScanEvent(picker.getId(), event));
}
项目:react-native-google-fit    文件:StepHistory.java   
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       @Nullable WritableArray params) {
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(eventName, params);
}
项目:react-native-google-fit    文件:CalorieHistory.java   
private void processDataSet(DataSet dataSet, WritableArray map) {
    Log.i(TAG, "Data returned for Data type: " + dataSet.getDataType().getName());
    DateFormat dateFormat = DateFormat.getDateInstance();
    DateFormat timeFormat = DateFormat.getTimeInstance();
    Format formatter = new SimpleDateFormat("EEE");
    WritableMap stepMap = Arguments.createMap();


    for (DataPoint dp : dataSet.getDataPoints()) {
        Log.i(TAG, "Data point:");
        Log.i(TAG, "\tType: " + dp.getDataType().getName());
        Log.i(TAG, "\tStart: " + dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
        Log.i(TAG, "\tEnd: " + dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));

        String day = formatter.format(new Date(dp.getStartTime(TimeUnit.MILLISECONDS)));
        Log.i(TAG, "Day: " + day);

        for(Field field : dp.getDataType().getFields()) {
            Log.i("History", "\tField: " + field.getName() +
                  " Value: " + dp.getValue(field));

            stepMap.putString("day", day);
            stepMap.putDouble("startDate", dp.getStartTime(TimeUnit.MILLISECONDS));
            stepMap.putDouble("endDate", dp.getEndTime(TimeUnit.MILLISECONDS));
            float basal = 0;
            try {
                basal = getBasalAVG(dp.getEndTime(TimeUnit.MILLISECONDS));
            } catch (Exception e) {
                e.printStackTrace();
            }
            stepMap.putDouble("calorie", dp.getValue(field).asFloat() - basal);
            map.pushMap(stepMap);
        }
    }
}
项目:react-native-google-fit    文件:DistanceHistory.java   
private void processDataSet(DataSet dataSet, WritableArray map) {
    Log.i(TAG, "Data returned for Data type: " + dataSet.getDataType().getName());
    DateFormat dateFormat = DateFormat.getDateInstance();
    DateFormat timeFormat = DateFormat.getTimeInstance();
    Format formatter = new SimpleDateFormat("EEE");

    WritableMap stepMap = Arguments.createMap();


    for (DataPoint dp : dataSet.getDataPoints()) {
        Log.i(TAG, "Data point:");
        Log.i(TAG, "\tType: " + dp.getDataType().getName());
        Log.i(TAG, "\tStart: " + dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
        Log.i(TAG, "\tEnd: " + dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));

        String day = formatter.format(new Date(dp.getStartTime(TimeUnit.MILLISECONDS)));
        Log.i(TAG, "Day: " + day);

        for(Field field : dp.getDataType().getFields()) {
            Log.i("History", "\tField: " + field.getName() +
                    " Value: " + dp.getValue(field));

            stepMap.putString("day", day);
            stepMap.putDouble("startDate", dp.getStartTime(TimeUnit.MILLISECONDS));
            stepMap.putDouble("endDate", dp.getEndTime(TimeUnit.MILLISECONDS));
            stepMap.putDouble("distance", dp.getValue(field).asFloat());
            map.pushMap(stepMap);
        }
    }
}
项目:react-native-tensorflow    文件:ArrayConverter.java   
public static ReadableArray doubleArrayToReadableArray(double[] arr) {
    WritableArray writableArray = new WritableNativeArray();
    for (double d : arr) {
        writableArray.pushDouble(d);
    }

    return writableArray;
}
项目:react-native-tensorflow    文件:ArrayConverter.java   
public static ReadableArray floatArrayToReadableArray(float[] arr) {
    WritableArray writableArray = new WritableNativeArray();
    for (float f : arr) {
        writableArray.pushDouble(f);
    }

    return writableArray;
}
项目:react-native-tensorflow    文件:ArrayConverter.java   
public static ReadableArray intArrayToReadableArray(int[] arr) {
    WritableArray writableArray = new WritableNativeArray();
    for (int i : arr) {
        writableArray.pushInt(i);
    }

    return writableArray;
}
项目:react-native-tensorflow    文件:ArrayConverter.java   
public static ReadableArray byteArrayToBoolReadableArray(byte[] arr) {
    WritableArray writableArray = new WritableNativeArray();
    byte[] pos = new byte[]{(byte)0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1};

    for(int i = 0; i < arr.length; i++){
        for(int k = 0; k < 8; k++){
            boolean res = (arr[i] & pos[k]) != 0;
            writableArray.pushBoolean(res);
        }
    }

    return writableArray;
}
项目:react-native-twilio-chat    文件:RCTConvert.java   
public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) {
    WritableArray writableArray = new WritableNativeArray();

    try {
        if (jsonArray == null) {
            return null;
        }

        if (jsonArray.length() <= 0) {
            return null;
        }

        for (int i = 0 ; i < jsonArray.length(); i++) {
            Object value = jsonArray.get(i);
            if (value == null) {
                writableArray.pushNull();
            } else if (value instanceof Boolean) {
                writableArray.pushBoolean((Boolean) value);
            } else if (value instanceof Integer) {
                writableArray.pushInt((Integer) value);
            } else if (value instanceof Double) {
                writableArray.pushDouble((Double) value);
            } else if (value instanceof String) {
                writableArray.pushString((String) value);
            } else if (value instanceof JSONObject) {
                writableArray.pushMap(jsonToWritableMap((JSONObject) value));
            } else if (value instanceof JSONArray) {
                writableArray.pushArray(jsonArrayToWritableArray((JSONArray) value));
            }
        }
    } catch (JSONException e) {
        // Do nothing and fail silently
    }

    return writableArray;
}
项目:react-native-scandit    文件:ReactBridgeHelpers.java   
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;
}
项目:react-native-twilio-chat    文件:RCTConvert.java   
public static WritableArray ChannelDescriptors(ArrayList<ChannelDescriptor> channels) {
    WritableArray array = Arguments.createArray();

    for (ChannelDescriptor c : channels) {
        array.pushMap(ChannelDescriptor(c));
    }

    return array;
}
项目:react-native-twilio-chat    文件:RCTConvert.java   
public static WritableArray Members(ArrayList<Member> members) {
    WritableArray array = Arguments.createArray();

    for (Member m : members) {
        array.pushMap(Member(m));
    }

    return array;
}
项目:react-native-twilio-chat    文件:RCTConvert.java   
public static WritableArray Messages(List<Message> messages) {
    WritableArray array = Arguments.createArray();

    for (Message m : messages) {
        array.pushMap(Message(m));
    }

    return array;
}
项目:react-native-face-detect    文件:Converter.java   
public static WritableArray toMap(FaceResult[] faces, boolean mirror) {
  WritableArray array = Arguments.createArray();
  for (FaceResult face : faces) {
    array.pushMap(toMap(face, mirror));
  }
  return array;
}
项目:react-native-batch    文件:RNBatchModule.java   
@ReactMethod
public void fetchNewNotifications(String userID, String authKey, final Promise promise) {
    try {
        BatchInboxFetcher inboxFetcher = Batch.Inbox.getFetcher(userID, authKey);
        inboxFetcher.fetchNewNotifications(new BatchInboxFetcher.OnNewNotificationsFetchedListener() {
            public void onFetchSuccess(@NonNull List<BatchInboxNotificationContent> notifications, boolean foundNewNotifications, boolean endReached) {
                WritableArray jsNotifications = Arguments.createArray();

                for (BatchInboxNotificationContent notification : notifications) {
                    Bundle payloadBundle = new Bundle();
                    for (Map.Entry<String, String> entry : notification.getRawPayload().entrySet()) {
                        payloadBundle.putString(entry.getKey(), entry.getValue());
                    }
                    WritableMap jsNotification = Arguments.createMap();
                    jsNotification.putMap("payload", Arguments.fromBundle(payloadBundle));
                    jsNotification.putString("title", notification.getTitle());
                    jsNotification.putString("body", notification.getBody());
                    jsNotification.putDouble("timestamp", notification.getDate().getTime());
                    jsNotifications.pushMap(jsNotification);
                }

                promise.resolve(jsNotifications);
            }

            public void onFetchFailure(@NonNull String error) {
                promise.reject("BATCH_ERROR", "Error fetching new notifications: " + error);
            }
        });
    } catch (Exception exception) {
        Log.e("RNBatch", "Unknown exception: " + exception.getMessage());
    }
}
项目:react-native-batch    文件:ArrayUtil.java   
public static WritableArray toWritableArray(Object[] array) {
    WritableArray writableArray = Arguments.createArray();

    for (int i = 0; i < array.length; i++) {
        Object value = array[i];

        if (value == null) {
            writableArray.pushNull();
        }
        if (value instanceof Boolean) {
            writableArray.pushBoolean((Boolean) value);
        }
        if (value instanceof Double) {
            writableArray.pushDouble((Double) value);
        }
        if (value instanceof Integer) {
            writableArray.pushInt((Integer) value);
        }
        if (value instanceof String) {
            writableArray.pushString((String) value);
        }
        if (value instanceof Map) {
            writableArray.pushMap(MapUtil.toWritableMap((Map<String, Object>) value));
        }
        if (value.getClass().isArray()) {
            writableArray.pushArray(ArrayUtil.toWritableArray((Object[]) value));
        }
    }

    return writableArray;
}
项目:RNNavitiaSDK    文件:ArrayUtil.java   
public static WritableArray toWritableArray(Object[] array) {
    WritableArray writableArray = Arguments.createArray();

    for (int i = 0; i < array.length; i++) {
        Object value = array[i];

        if (value == null) {
            writableArray.pushNull();
        }
        if (value instanceof Boolean) {
            writableArray.pushBoolean((Boolean) value);
        }
        if (value instanceof Double) {
            writableArray.pushDouble((Double) value);
        }
        if (value instanceof Integer) {
            writableArray.pushInt((Integer) value);
        }
        if (value instanceof String) {
            writableArray.pushString((String) value);
        }
        if (value instanceof Map) {
            writableArray.pushMap(MapUtil.toWritableMap((Map<String, Object>) value));
        }
        if (value.getClass().isArray()) {
            writableArray.pushArray(ArrayUtil.toWritableArray((Object[]) value));
        }
    }

    return writableArray;
}
项目:react-native-event-bridge    文件:MainActivity.java   
@Override
public void onEventCallback(final String name, final ReadableMap info, final MSREventBridgeReceiverCallback callback) {
    Log.d(ReactConstants.TAG, this.getClass().getName() + ": Received event with callback: ".concat(name));

    final String activityClassName = this.getClass().getSimpleName();

    // Example how to load some async data
    if (name.equals(LoadDataEventName)) {
        final int count = info.getInt("count");

        // Simulate some data loading delay
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                WritableArray array = new WritableNativeArray();
                for (int i = 0; i < count; i++) {
                    array.pushString("Row " + i + " - " + activityClassName);
                }
                callback.onSuccess(array);
            }
        }, 2000);

        return;
    }

    // Emit callback
    WritableMap map = new WritableNativeMap();
    map.putString("key", "value");
    callback.onSuccess(map);
}
项目:react-native-event-bridge    文件:SecondActivity.java   
@Override
public void onEventCallback(final String name, final ReadableMap info, final MSREventBridgeReceiverCallback callback) {
    Log.d(ReactConstants.TAG, this.getClass().getName() + ": Received event  with callback: ".concat(name));

    final String activityClassName = this.getClass().getSimpleName();

    // Example how to load some async data
    if (name.equals(LoadDataEventName)) {
        final int count = info.getInt("count");

        // Simulate some data loading delay
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                WritableArray array = new WritableNativeArray();
                for (int i = 0; i < count; i++) {
                    // getSimpleName() does not work here for some reason
                    String className = this.getClass().getName();
                    array.pushString("Row " + i + " - " + activityClassName);
                }

                callback.onSuccess(array);
            }
        }, 2000);

        return;
    }

    // Emit callback
    WritableMap map = new WritableNativeMap();
    map.putString("key", "value");
    callback.onSuccess(map);
}
项目:react-native-ibeacons    文件:BeaconsAndroidModule.java   
@ReactMethod
public void getMonitoredRegions(Callback callback) {
    WritableArray array = new WritableNativeArray();
    for (Region region: mBeaconManager.getMonitoredRegions()) {
        WritableMap map = new WritableNativeMap();
        map.putString("identifier", region.getUniqueId());
        map.putString("uuid", region.getId1().toString());
        map.putInt("major", region.getId2() != null ? region.getId2().toInt() : 0);
        map.putInt("minor", region.getId3() != null ? region.getId3().toInt() : 0);
        array.pushMap(map);
    }
    callback.invoke(array);
}
项目:RNRxBluetooth    文件:RNRxBluetoothModule.java   
private void onByteArraysStream(byte[] bytes) {
    WritableMap params = Arguments.createMap();
    WritableArray data = new WritableNativeArray();
    for (byte b : bytes) {
        data.pushInt(UnsignedBytes.toInt(b));
    }
    params.putArray("payload", data);
    sendEventToJs(BT_RECEIVED_DATA, params);
}