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;
}
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;
}
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);
}
});
}
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]
}
});
}
Aggregations