Search in sources :

Example 1 with WritableArray

use of com.facebook.react.bridge.WritableArray in project react-native-camera by react-native-community.

the class FacesDetectedEvent method serializeEventData.

private WritableMap serializeEventData() {
    WritableArray facesList = Arguments.createArray();
    for (int i = 0; i < mFaces.size(); i++) {
        Face face = mFaces.valueAt(i);
        WritableMap serializedFace = FaceDetectorUtils.serializeFace(face, mScaleX, mScaleY);
        if (mImageDimensions.getFacing() == CameraView.FACING_FRONT) {
            serializedFace = FaceDetectorUtils.rotateFaceX(serializedFace, mImageDimensions.getWidth(), mScaleX);
        } else {
            serializedFace = FaceDetectorUtils.changeAnglesDirection(serializedFace);
        }
        facesList.pushMap(serializedFace);
    }
    WritableMap event = Arguments.createMap();
    event.putString("type", "face");
    event.putArray("faces", facesList);
    event.putInt("target", getViewTag());
    return event;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) Face(com.google.android.gms.vision.face.Face)

Example 2 with WritableArray

use of com.facebook.react.bridge.WritableArray in project react-native-camera by react-native-community.

the class TextRecognizedEvent method serializeText.

private WritableMap serializeText(Text text) {
    WritableMap encodedText = Arguments.createMap();
    WritableArray components = Arguments.createArray();
    for (Text component : text.getComponents()) {
        components.pushMap(serializeText(component));
    }
    encodedText.putArray("components", components);
    encodedText.putString("value", text.getValue());
    WritableMap origin = Arguments.createMap();
    origin.putDouble("x", text.getBoundingBox().left * this.mScaleX);
    origin.putDouble("y", text.getBoundingBox().top * this.mScaleY);
    WritableMap size = Arguments.createMap();
    size.putDouble("width", text.getBoundingBox().width() * this.mScaleX);
    size.putDouble("height", text.getBoundingBox().height() * this.mScaleY);
    WritableMap bounds = Arguments.createMap();
    bounds.putMap("origin", origin);
    bounds.putMap("size", size);
    encodedText.putMap("bounds", bounds);
    String type_;
    if (text instanceof TextBlock) {
        type_ = "block";
    } else if (text instanceof Line) {
        type_ = "line";
    } else /*if (text instanceof Element)*/
    {
        type_ = "element";
    }
    encodedText.putString("type", type_);
    return encodedText;
}
Also used : Line(com.google.android.gms.vision.text.Line) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) Text(com.google.android.gms.vision.text.Text) TextBlock(com.google.android.gms.vision.text.TextBlock)

Example 3 with WritableArray

use of com.facebook.react.bridge.WritableArray in project react-native-video by react-native-community.

the class VideoEventEmitter method timedMetadata.

void timedMetadata(Metadata metadata) {
    WritableArray metadataArray = Arguments.createArray();
    for (int i = 0; i < metadata.length(); i++) {
        Id3Frame frame = (Id3Frame) metadata.get(i);
        String value = "";
        if (frame instanceof TextInformationFrame) {
            TextInformationFrame txxxFrame = (TextInformationFrame) frame;
            value = txxxFrame.value;
        }
        String identifier = frame.id;
        WritableMap map = Arguments.createMap();
        map.putString("identifier", identifier);
        map.putString("value", value);
        metadataArray.pushMap(map);
    }
    WritableMap event = Arguments.createMap();
    event.putArray(EVENT_PROP_TIMED_METADATA, metadataArray);
    receiveEvent(EVENT_TIMED_METADATA, event);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) Id3Frame(com.google.android.exoplayer2.metadata.id3.Id3Frame) TextInformationFrame(com.google.android.exoplayer2.metadata.id3.TextInformationFrame)

Example 4 with WritableArray

use of com.facebook.react.bridge.WritableArray in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method getCurrentPlace.

@ReactMethod
public void getCurrentPlace(final Promise promise) {
    PendingResult<PlaceLikelihoodBuffer> results = Places.PlaceDetectionApi.getCurrentPlace(mGoogleApiClient, null);
    PlaceLikelihoodBuffer likelyPlaces = results.await(60, TimeUnit.SECONDS);
    final Status status = likelyPlaces.getStatus();
    if (status.isSuccess()) {
        if (likelyPlaces.getCount() == 0) {
            WritableArray emptyResult = Arguments.createArray();
            likelyPlaces.release();
            promise.resolve(emptyResult);
            return;
        }
        WritableArray likelyPlacesList = Arguments.createArray();
        for (PlaceLikelihood placeLikelihood : likelyPlaces) {
            WritableMap map = propertiesMapForPlace(placeLikelihood.getPlace());
            map.putDouble("likelihood", placeLikelihood.getLikelihood());
            likelyPlacesList.pushMap(map);
        }
        // Release the buffer now that all data has been copied.
        likelyPlaces.release();
        promise.resolve(likelyPlacesList);
    } else {
        Log.i(TAG, "Error making places detection api call: " + status.getStatusMessage());
        likelyPlaces.release();
        promise.reject("E_PLACE_DETECTION_API_ERROR", new Error("Error making places detection api call: " + status.getStatusMessage()));
        return;
    }
}
Also used : Status(com.google.android.gms.common.api.Status) PlaceLikelihoodBuffer(com.google.android.gms.location.places.PlaceLikelihoodBuffer) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) PlaceLikelihood(com.google.android.gms.location.places.PlaceLikelihood) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 5 with WritableArray

use of com.facebook.react.bridge.WritableArray in project react-native-camera by lwansbrough.

the class FaceDetectorAsyncTask method serializeEventData.

private WritableArray serializeEventData(List<Face> faces) {
    WritableArray facesList = Arguments.createArray();
    for (Face face : faces) {
        WritableMap serializedFace = FaceDetectorUtils.serializeFace(face, mScaleX, mScaleY, mWidth, mHeight, mPaddingLeft, mPaddingTop);
        if (mImageDimensions.getFacing() == CameraView.FACING_FRONT) {
            serializedFace = FaceDetectorUtils.rotateFaceX(serializedFace, mImageDimensions.getWidth(), mScaleX);
        } else {
            serializedFace = FaceDetectorUtils.changeAnglesDirection(serializedFace);
        }
        facesList.pushMap(serializedFace);
    }
    return facesList;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) Face(com.google.mlkit.vision.face.Face)

Aggregations

WritableArray (com.facebook.react.bridge.WritableArray)30 WritableMap (com.facebook.react.bridge.WritableMap)24 ReactMethod (com.facebook.react.bridge.ReactMethod)6 Text (com.google.mlkit.vision.text.Text)5 Face (com.google.mlkit.vision.face.Face)4 ReadableMap (com.facebook.react.bridge.ReadableMap)3 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)3 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)3 InputImage (com.google.mlkit.vision.common.InputImage)3 Bundle (android.os.Bundle)2 ReadableArray (com.facebook.react.bridge.ReadableArray)2 Status (com.google.android.gms.common.api.Status)2 Face (com.google.android.gms.vision.face.Face)2 TextBlock (com.google.android.gms.vision.text.TextBlock)2 Barcode (com.google.mlkit.vision.barcode.Barcode)2 ResultPoint (com.google.zxing.ResultPoint)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1