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

The following are Jave code examples for showing how to use putArray() of the com.facebook.react.bridge.WritableMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: react-native-ibeacons   File: BeaconsAndroidModule.java   Source Code and License Vote up 9 votes
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 2
Project: react-native-nfc-manager   File: JsonConvert.java   Source Code and License Vote up 6 votes
public static WritableMap jsonToReact(JSONObject jsonObject) throws JSONException {
    WritableMap writableMap = Arguments.createMap();
    Iterator iterator = jsonObject.keys();
    while(iterator.hasNext()) {
        String key = (String) iterator.next();
        Object value = jsonObject.get(key);
        if (value instanceof Float || value instanceof Double) {
            writableMap.putDouble(key, jsonObject.getDouble(key));
        } else if (value instanceof Number) {
            writableMap.putInt(key, jsonObject.getInt(key));
        } else if (value instanceof String) {
            writableMap.putString(key, jsonObject.getString(key));
        } else if (value instanceof JSONObject) {
            writableMap.putMap(key,jsonToReact(jsonObject.getJSONObject(key)));
        } else if (value instanceof JSONArray){
            writableMap.putArray(key, jsonToReact(jsonObject.getJSONArray(key)));
        } else if (value == JSONObject.NULL){
            writableMap.putNull(key);
        }
    }

    return writableMap;
}
 
Example 3
Project: react-native-twilio-chat   File: RCTConvert.java   Source Code and License Vote up 6 votes
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 4
Project: react-native-stt   File: LocalesBroadcastReceiver.java   Source Code and License Vote up 6 votes
@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);
}
 
Example 5
Project: react-native-scandit   File: ReactBridgeHelpers.java   Source Code and License Vote up 6 votes
public static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
    WritableMap map = new WritableNativeMap();

    Iterator<String> iterator = jsonObject.keys();
    while (iterator.hasNext()) {
        String key = iterator.next();
        Object value = jsonObject.get(key);
        if (value instanceof JSONObject) {
            map.putMap(key, convertJsonToMap((JSONObject) value));
        } else if (value instanceof JSONArray) {
            map.putArray(key, convertJsonToArray((JSONArray) value));
        } else if (value instanceof  Boolean) {
            map.putBoolean(key, (Boolean) value);
        } else if (value instanceof  Integer) {
            map.putInt(key, (Integer) value);
        } else if (value instanceof  Double) {
            map.putDouble(key, (Double) value);
        } else if (value instanceof String)  {
            map.putString(key, (String) value);
        } else {
            map.putString(key, value.toString());
        }
    }
    return map;
}
 
Example 6
Project: react-native-mssql   File: MapUtil.java   Source Code and License Vote up 5 votes
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 7
Project: react-native-android-speech-recognizer   File: ListenerMapRecognitionListener.java   Source Code and License Vote up 5 votes
@Override
public void onBufferReceived(byte[] buffer) {
  Log.d(TAG, "onBufferReceived");
  if (isEnabled(ListenerEvents.ON_BUFFER_RECEIVED)) {
    WritableMap data = Arguments.createMap();
    data.putArray("buffer", ArgumentsConverter.fromArray(buffer));
    emit(ListenerEvents.ON_BUFFER_RECEIVED, data);
  }
}
 
Example 8
Project: react-native-android-speech-recognizer   File: ArgumentsConverter.java   Source Code and License Vote up 5 votes
public static WritableMap fromBundle(Bundle bundle) {
  WritableMap map = Arguments.createMap();
  for (String key: bundle.keySet()) {
    Object value = bundle.get(key);
    if (value == null) {
      map.putNull(key);
    } else if (value.getClass().isArray()) {
      map.putArray(key, Arguments.fromArray(value));
    } else if (value instanceof String) {
      map.putString(key, (String) value);
    } else if (value instanceof Number) {
      if (value instanceof Integer) {
        map.putInt(key, (Integer) value);
      } else {
        map.putDouble(key, ((Number) value).doubleValue());
      }
    } else if (value instanceof Boolean) {
      map.putBoolean(key, (Boolean) value);
    } else if (value instanceof Bundle) {
      map.putMap(key, fromBundle((Bundle) value));
    } else if (value instanceof List) {
      map.putArray(key, fromArray(((List) value).toArray()));
    } else {
      throw new IllegalArgumentException("Could not convert " + value.getClass());
    }
  }
  return map;
}
 
Example 9
Project: react-native-twilio-chat   File: RCTConvert.java   Source Code and License Vote up 5 votes
public static WritableMap jsonToWritableMap(JSONObject jsonObject) {
    WritableMap writableMap = new WritableNativeMap();

    if (jsonObject == null) {
        return null;
    }


    Iterator<String> iterator = jsonObject.keys();
    if (!iterator.hasNext()) {
        return null;
    }


    try {
        while (iterator.hasNext()) {
            String key = iterator.next();
            Object value = jsonObject.get(key);
            if (value == null) {
                writableMap.putNull(key);
            } else if (value instanceof Boolean) {
                writableMap.putBoolean(key, (Boolean) value);
            } else if (value instanceof Integer) {
                writableMap.putInt(key, (Integer) value);
            } else if (value instanceof Double) {
                writableMap.putDouble(key, (Double) value);
            } else if (value instanceof String) {
                writableMap.putString(key, (String) value);
            } else if (value instanceof JSONObject) {
                writableMap.putMap(key, jsonToWritableMap((JSONObject) value));
            } else if (value instanceof JSONArray) {
                writableMap.putArray(key, jsonArrayToWritableArray((JSONArray) value));
            }
        }
    } catch (JSONException ex){
            // Do nothing and fail silently
    }

    return writableMap;
}
 
Example 10
Project: react-native-batch   File: MapUtil.java   Source Code and License Vote up 5 votes
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 11
Project: RNNavitiaSDK   File: MapUtil.java   Source Code and License Vote up 5 votes
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 12
Project: react-native-stt   File: SpeechRecognitionListener.java   Source Code and License Vote up 5 votes
@Override
public void onBufferReceived(byte[] buffer) {
  Logger.debug(TAG, "onBufferReceived");
  WritableMap data = Arguments.createMap();
  data.putArray("buffer", Arguments.fromArray(buffer));
  emit(SPEECH_TO_TEXT, data);
}
 
Example 13
Project: RNLearn_Project1   File: CameraRollManager.java   Source Code and License Vote up 5 votes
private static void putEdges(
    ContentResolver resolver,
    Cursor photos,
    WritableMap response,
    int limit) {
  WritableArray edges = new WritableNativeArray();
  photos.moveToFirst();
  int idIndex = photos.getColumnIndex(Images.Media._ID);
  int mimeTypeIndex = photos.getColumnIndex(Images.Media.MIME_TYPE);
  int groupNameIndex = photos.getColumnIndex(Images.Media.BUCKET_DISPLAY_NAME);
  int dateTakenIndex = photos.getColumnIndex(Images.Media.DATE_TAKEN);
  int widthIndex = IS_JELLY_BEAN_OR_LATER ? photos.getColumnIndex(Images.Media.WIDTH) : -1;
  int heightIndex = IS_JELLY_BEAN_OR_LATER ? photos.getColumnIndex(Images.Media.HEIGHT) : -1;
  int longitudeIndex = photos.getColumnIndex(Images.Media.LONGITUDE);
  int latitudeIndex = photos.getColumnIndex(Images.Media.LATITUDE);

  for (int i = 0; i < limit && !photos.isAfterLast(); i++) {
    WritableMap edge = new WritableNativeMap();
    WritableMap node = new WritableNativeMap();
    boolean imageInfoSuccess =
        putImageInfo(resolver, photos, node, idIndex, widthIndex, heightIndex);
    if (imageInfoSuccess) {
      putBasicNodeInfo(photos, node, mimeTypeIndex, groupNameIndex, dateTakenIndex);
      putLocationInfo(photos, node, longitudeIndex, latitudeIndex);

      edge.putMap("node", node);
      edges.pushMap(edge);
    } else {
      // we skipped an image because we couldn't get its details (e.g. width/height), so we
      // decrement i in order to correctly reach the limit, if the cursor has enough rows
      i--;
    }
    photos.moveToNext();
  }
  response.putArray("edges", edges);
}
 
Example 14
Project: react-native-android-library-humaniq-api   File: ModelConverterUtils.java   Source Code and License Vote up 5 votes
public static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
  WritableMap map = new WritableNativeMap();

  Iterator<String> iterator = jsonObject.keys();
  while (iterator.hasNext()) {
    String key = iterator.next();
    Object value = jsonObject.get(key);
    if (value instanceof JSONObject) {
      map.putMap(key, convertJsonToMap((JSONObject) value));
    } else if (value instanceof JSONArray) {
      map.putArray(key, convertJsonToArray((JSONArray) value));
    } else if (value instanceof Boolean) {
      map.putBoolean(key, (Boolean) value);
    } else if (value instanceof Integer) {
      map.putInt(key, (Integer) value);
    } else if (value instanceof Double) {
      System.out.println("double");
      map.putDouble(key, (Double) value);
    } else if (value instanceof String) {
      map.putString(key, (String) value);
      System.out.println("string");
    } else {
      map.putString(key, value.toString());
    }
  }
  return map;
}
 
Example 15
Project: react-native-scandit   File: SGScanditPicker.java   Source Code and License Vote up 5 votes
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));
}
 
Example 16
Project: react-native-blue-manager   File: Peripheral.java   Source Code and License Vote up 4 votes
public WritableMap asWritableMap(BluetoothGatt gatt) {

		WritableMap map = asWritableMap();

		WritableArray servicesArray = Arguments.createArray();
		WritableArray characteristicsArray = Arguments.createArray();

		if (connected && gatt != null) {
			for (BluetoothGattService service : gatt.getServices()) {
				WritableMap serviceMap = Arguments.createMap();
				serviceMap.putString("uuid", UUIDHelper.uuidToString(service.getUuid()));



				for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
					WritableMap characteristicsMap = Arguments.createMap();

					characteristicsMap.putString("service", UUIDHelper.uuidToString(service.getUuid()));
					characteristicsMap.putString("characteristic", UUIDHelper.uuidToString(characteristic.getUuid()));

					characteristicsMap.putMap("properties", Helper.decodeProperties(characteristic));

					if (characteristic.getPermissions() > 0) {
						characteristicsMap.putMap("permissions", Helper.decodePermissions(characteristic));
					}


					WritableArray descriptorsArray = Arguments.createArray();

					for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) {
						WritableMap descriptorMap = Arguments.createMap();
						descriptorMap.putString("uuid", UUIDHelper.uuidToString(descriptor.getUuid()));
						if (descriptor.getValue() != null)
							descriptorMap.putString("value", Base64.encodeToString(descriptor.getValue(), Base64.NO_WRAP));
						else
							descriptorMap.putString("value", null);

						if (descriptor.getPermissions() > 0) {
							descriptorMap.putMap("permissions", Helper.decodePermissions(descriptor));
						}
						descriptorsArray.pushMap(descriptorMap);
					}
					if (descriptorsArray.size() > 0) {
						characteristicsMap.putArray("descriptors", descriptorsArray);
					}
					characteristicsArray.pushMap(characteristicsMap);
				}
				servicesArray.pushMap(serviceMap);
			}
			map.putArray("services", servicesArray);
			map.putArray("characteristics", characteristicsArray);
		}

		return map;
	}
 
Example 17
Project: react-native-cameraroll   File: RNCameraRollModule.java   Source Code and License Vote up 4 votes
@Override
protected void doInBackgroundGuarded(Void... params) {
    StringBuilder query = new StringBuilder("1");
    List<String> queryArgs = new ArrayList<>();
    if (!TextUtils.isEmpty(mStart)) {
        query.append(" AND " + QUERY_DATE_TAKEN);
        queryArgs.add(mStart);
    }
    Uri uri;
    if (mAssetType == null || "all".equals(mAssetType)) {
        uri = MediaStore.Files.getContentUri("external");
        query.append(" AND (" + Images.Media.MIME_TYPE + " LIKE ? OR "
                + Images.Media.MIME_TYPE + " LIKE ?) ");
        queryArgs.add("image/%");
        queryArgs.add("video/%");
    } else if ("image".equals(mAssetType)) {
        uri = Images.Media.EXTERNAL_CONTENT_URI;
        query.append(" AND " + Images.Media.MIME_TYPE + " LIKE ? ");
        queryArgs.add("image/%");
    } else if ("video".equals(mAssetType)) {
        uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
        query.append(" AND " + Images.Media.MIME_TYPE + " LIKE ? ");
        queryArgs.add("video/%");
    } else {
        mPromise.reject(ERROR_INVALID_ASSET_TYPE, "Invalid assetType: " + mAssetType);
        return;
    }
    WritableMap response = new WritableNativeMap();
    ContentResolver resolver = mContext.getContentResolver();
    try {
        Cursor assetsCursor = resolver.query(
                uri,
                FIELDS,
                query.toString(),
                queryArgs.toArray(new String[queryArgs.size()]),
                Images.Media.DATE_TAKEN + " DESC, " + Images.Media.DATE_MODIFIED +
                    " DESC LIMIT " + (mLimit + 1));
        if (assetsCursor == null) {
            mPromise.reject(ERROR_UNABLE_TO_LOAD, "Could not get assets");
        } else {
            try {
                response.putArray("assets", buildAssets(assetsCursor, response, mLimit));
                response.putMap("page_info", buildPageInfo(assetsCursor, response, mLimit));
            } finally {
                assetsCursor.close();
                mPromise.resolve(response);
            }
        }
    } catch (SecurityException e) {
        mPromise.reject(
                ERROR_PERMISSION_DENIED,
                "Could not get assets: need READ_EXTERNAL_STORAGE permission",
                e);
    }
}
 
Example 18
Project: react-native-region-monitor   File: RNRegionTransitionService.java   Source Code and License Vote up 4 votes
@Override
@Nullable
protected HeadlessJsTaskConfig getTaskConfig(Intent intent)
{
	if (intent.getExtras() == null)
	{
		return null;
	}

	GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);

	if (geofencingEvent.hasError())
	{
		// Suppress geofencing event with error
		Log.d(TAG, "Suppress geocoding event with error");
		return null;
	}

	WritableMap location = Arguments.createMap();
	location.putDouble("latitude", geofencingEvent.getTriggeringLocation().getLatitude());
	location.putDouble("longitude", geofencingEvent.getTriggeringLocation().getLongitude());

	WritableMap region = Arguments.createMap();
	region.putString("identifier", geofencingEvent.getTriggeringGeofences().get(0).getRequestId());

	WritableArray regionIdentifiers = Arguments.createArray();
	for (Geofence triggered: geofencingEvent.getTriggeringGeofences())
	{
		regionIdentifiers.pushString(triggered.getRequestId());
	}
	region.putArray("identifiers", regionIdentifiers);

	WritableMap jsArgs = Arguments.createMap();
	jsArgs.putMap("location", location);
	jsArgs.putMap("region", region);
	jsArgs.putBoolean("didEnter", geofencingEvent.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER);
	jsArgs.putBoolean("didExit", geofencingEvent.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_EXIT);
	//jsArgs.putBoolean("didDwell", geofencingEvent.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_DWELL);

	Log.d(TAG, "Report geofencing event to JS: " + jsArgs);
	return new HeadlessJsTaskConfig(RNRegionMonitorModule.TRANSITION_TASK_NAME, jsArgs, 0, true);
}
 
Example 19
Project: react-native-geo-fence   File: GeofenceTransitionsIntentService.java   Source Code and License Vote up 4 votes
/**
 * Handles incoming intents.
 * @param intent sent by Location Services. This Intent is provided to Location
 *               Services (inside a PendingIntent) when addGeofences() is called.
 */
@Override
protected void onHandleIntent(Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        String errorMessage = GeofenceErrorMessages.getErrorString(this,
                geofencingEvent.getErrorCode());
        Log.e(TAG, errorMessage);
        return;
    }

    // Get the transition type.
    int geofenceTransition = geofencingEvent.getGeofenceTransition();

    // Test that the reported transition was of interest.
    if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
            geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {

        // Get the geofences that were triggered. A single event can trigger multiple geofences.
        List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
        WritableArray writableArray = new WritableNativeArray();

        for (int i = 0; i < triggeringGeofences.size(); i++) {
            Geofence geofence = triggeringGeofences.get(i);
            String key = geofence.getRequestId();
            ReadableMap geofenceMap = getGeofenceFromKey(key);
            WritableMap writableMap = new WritableNativeMap();
            writableMap.merge(geofenceMap);
            writableMap.putString("transition", getTransitionString(geofenceTransition));
            writableArray.pushMap(writableMap);
        }

        // create final event emitter object argument
        WritableMap finalEventEmitterObject = new WritableNativeMap();
        finalEventEmitterObject.putArray("data", writableArray);
        finalEventEmitterObject.putString("event", "geofenceTrigger");

        SReactApplicationContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit("GeofenceEvent", finalEventEmitterObject);
    } else {
        // Log the error.
        Log.e(TAG, "Geofence transition error: invalid transition type " + geofenceTransition);
    }
}
 
Example 20
Project: react-native-camera-face-detector   File: RCTCameraViewFinder.java   Source Code and License Vote up 4 votes
@Override
protected Void doInBackground(Void... ignored) {
    if (isCancelled()) {
        return null;
    }

    Camera.Size size = camera.getParameters().getPreviewSize();

    int width = size.width;
    int height = size.height;

    // rotate for zxing if orientation is portrait
    if (RCTCamera.getInstance().getActualDeviceOrientation() == 0) {
        byte[] rotated = new byte[imageData.length];
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                rotated[x * height + height - y - 1] = imageData[x + y * width];
            }
        }
        width = size.height;
        height = size.width;
        imageData = rotated;
    }

    try {
        PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(imageData, width, height, 0, 0, width, height, false);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        Result result = _multiFormatReader.decodeWithState(bitmap);

        ReactContext reactContext = RCTCameraModule.getReactContextSingleton();
        WritableMap event = Arguments.createMap();
        WritableArray resultPoints = Arguments.createArray();
        ResultPoint[] points = result.getResultPoints();
        if(points != null) {
            for (ResultPoint point : points) {
                WritableMap newPoint = Arguments.createMap();
                newPoint.putString("x", String.valueOf(point.getX()));
                newPoint.putString("y", String.valueOf(point.getY()));
                resultPoints.pushMap(newPoint);
            }
        }

        event.putArray("bounds", resultPoints);
        event.putString("data", result.getText());
        event.putString("type", result.getBarcodeFormat().toString());
        reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("CameraBarCodeReadAndroid", event);

    } catch (Throwable t) {
        // meh
    } finally {
        _multiFormatReader.reset();
        RCTCameraViewFinder.barcodeScannerTaskLock = false;
        return null;
    }
}