Search in sources :

Example 41 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project react-native-camera by lwansbrough.

the class FileFaceDetectionAsyncTask method doInBackground.

@Override
protected Void doInBackground(Void... voids) {
    if (isCancelled()) {
        return null;
    }
    mRNFaceDetector = detectorForOptions(mOptions, mContext);
    try {
        ExifInterface exif = new ExifInterface(mPath);
        mOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
    } catch (IOException e) {
        Log.e(ERROR_TAG, "Reading orientation from file `" + mPath + "` failed.", e);
    }
    try {
        InputImage image = InputImage.fromFilePath(mContext, Uri.parse(mUri));
        FaceDetector detector = mRNFaceDetector.getDetector();
        detector.process(image).addOnSuccessListener(new OnSuccessListener<List<Face>>() {

            @Override
            public void onSuccess(List<Face> faces) {
                serializeEventData(faces);
            }
        }).addOnFailureListener(new OnFailureListener() {

            @Override
            public void onFailure(Exception e) {
                Log.e(ERROR_TAG, "Text recognition task failed", e);
                mPromise.reject(ERROR_TAG, "Text recognition task failed", e);
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
        Log.e(ERROR_TAG, "Creating Firebase Image from uri" + mUri + "failed", e);
        mPromise.reject(ERROR_TAG, "Creating Firebase Image from uri" + mUri + "failed", e);
    }
    return null;
}
Also used : RNFaceDetector(org.reactnative.facedetector.RNFaceDetector) FaceDetector(com.google.mlkit.vision.face.FaceDetector) ExifInterface(androidx.exifinterface.media.ExifInterface) List(java.util.List) IOException(java.io.IOException) Face(com.google.mlkit.vision.face.Face) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) InputImage(com.google.mlkit.vision.common.InputImage) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) IOException(java.io.IOException)

Example 42 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project react-native-camera by lwansbrough.

the class BarcodeDetectorAsyncTask method doInBackground.

@Override
protected Void doInBackground(Void... ignored) {
    if (isCancelled() || mDelegate == null || mBarcodeDetector == null) {
        return null;
    }
    InputImage image = InputImage.fromByteArray(mImageData, mWidth, mHeight, getFirebaseRotation(), InputImage.IMAGE_FORMAT_YV12);
    BarcodeScanner barcode = mBarcodeDetector.getDetector();
    barcode.process(image).addOnSuccessListener(new OnSuccessListener<List<Barcode>>() {

        @Override
        public void onSuccess(List<Barcode> barcodes) {
            WritableArray serializedBarcodes = serializeEventData(barcodes);
            mDelegate.onBarcodesDetected(serializedBarcodes, mWidth, mHeight, mImageData);
            mDelegate.onBarcodeDetectingTaskCompleted();
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(Exception e) {
            Log.e(TAG, "Text recognition task failed" + e);
            mDelegate.onBarcodeDetectingTaskCompleted();
        }
    });
    return null;
}
Also used : WritableArray(com.facebook.react.bridge.WritableArray) Barcode(com.google.mlkit.vision.barcode.Barcode) BarcodeScanner(com.google.mlkit.vision.barcode.BarcodeScanner) List(java.util.List) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) InputImage(com.google.mlkit.vision.common.InputImage) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 43 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project quickstart-android by firebase.

the class MainActivity method signInAnonymously.

private void signInAnonymously() {
    // Sign in anonymously. Authentication is required to read or write from Firebase Storage.
    showProgressBar(getString(R.string.progress_auth));
    mAuth.signInAnonymously().addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {

        @Override
        public void onSuccess(AuthResult authResult) {
            Log.d(TAG, "signInAnonymously:SUCCESS");
            hideProgressBar();
            updateUI(authResult.getUser());
        }
    }).addOnFailureListener(this, new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
            Log.e(TAG, "signInAnonymously:FAILURE", exception);
            hideProgressBar();
            updateUI(null);
        }
    });
}
Also used : AuthResult(com.google.firebase.auth.AuthResult) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 44 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project quickstart-android by firebase.

the class MyUploadService method uploadFromUri.

// [START upload_from_uri]
private void uploadFromUri(final Uri fileUri) {
    Log.d(TAG, "uploadFromUri:src:" + fileUri.toString());
    // [START_EXCLUDE]
    taskStarted();
    showProgressNotification(getString(R.string.progress_uploading), 0, 0);
    // [END_EXCLUDE]
    // [START get_child_ref]
    // Get a reference to store file at photos/<FILENAME>.jpg
    final StorageReference photoRef = mStorageRef.child("photos").child(fileUri.getLastPathSegment());
    // [END get_child_ref]
    // Upload file to Firebase Storage
    Log.d(TAG, "uploadFromUri:dst:" + photoRef.getPath());
    photoRef.putFile(fileUri).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {

        @Override
        public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
            showProgressNotification(getString(R.string.progress_uploading), taskSnapshot.getBytesTransferred(), taskSnapshot.getTotalByteCount());
        }
    }).continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {

        @Override
        public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
            // Forward any exceptions
            if (!task.isSuccessful()) {
                throw task.getException();
            }
            Log.d(TAG, "uploadFromUri: upload success");
            // Request the public download URL
            return photoRef.getDownloadUrl();
        }
    }).addOnSuccessListener(new OnSuccessListener<Uri>() {

        @Override
        public void onSuccess(@NonNull Uri downloadUri) {
            // Upload succeeded
            Log.d(TAG, "uploadFromUri: getDownloadUri success");
            // [START_EXCLUDE]
            broadcastUploadFinished(downloadUri, fileUri);
            showUploadFinishedNotification(downloadUri, fileUri);
            taskCompleted();
        // [END_EXCLUDE]
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
            // Upload failed
            Log.w(TAG, "uploadFromUri:onFailure", exception);
            // [START_EXCLUDE]
            broadcastUploadFinished(null, fileUri);
            showUploadFinishedNotification(null, fileUri);
            taskCompleted();
        // [END_EXCLUDE]
        }
    });
}
Also used : Task(com.google.android.gms.tasks.Task) UploadTask(com.google.firebase.storage.UploadTask) StorageReference(com.google.firebase.storage.StorageReference) Uri(android.net.Uri) UploadTask(com.google.firebase.storage.UploadTask) OnProgressListener(com.google.firebase.storage.OnProgressListener) NonNull(androidx.annotation.NonNull) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)44 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)43 StorageReference (com.google.firebase.storage.StorageReference)13 UploadTask (com.google.firebase.storage.UploadTask)10 File (java.io.File)9 AuthResult (com.google.firebase.auth.AuthResult)8 Uri (android.net.Uri)7 ApiException (com.google.android.gms.common.api.ApiException)6 FileDownloadTask (com.google.firebase.storage.FileDownloadTask)6 IOException (java.io.IOException)6 ResolvableApiException (com.google.android.gms.common.api.ResolvableApiException)5 LocationSettingsResponse (com.google.android.gms.location.LocationSettingsResponse)4 InputImage (com.google.mlkit.vision.common.InputImage)4 NonNull (android.support.annotation.NonNull)3 View (android.view.View)3 WritableArray (com.facebook.react.bridge.WritableArray)3 TaskFailureLogger (com.firebase.ui.auth.ui.TaskFailureLogger)3 FirebaseUser (com.google.firebase.auth.FirebaseUser)3 OnProgressListener (com.google.firebase.storage.OnProgressListener)3 StorageMetadata (com.google.firebase.storage.StorageMetadata)3