Search in sources :

Example 16 with OnSuccessListener

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

the class TextRecognizerAsyncTask method doInBackground.

@Override
protected Void doInBackground(Void... ignored) {
    if (isCancelled() || mDelegate == null) {
        return null;
    }
    TextRecognizer detector = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS);
    InputImage image = InputImage.fromByteArray(mImageData, mWidth, mHeight, getFirebaseRotation(), InputImage.IMAGE_FORMAT_YV12);
    detector.process(image).addOnSuccessListener(new OnSuccessListener<Text>() {

        @Override
        public void onSuccess(Text firebaseVisionText) {
            List<Text.TextBlock> textBlocks = firebaseVisionText.getTextBlocks();
            WritableArray serializedData = serializeEventData(textBlocks);
            mDelegate.onTextRecognized(serializedData);
            mDelegate.onTextRecognizerTaskCompleted();
        }
    }).addOnFailureListener(new OnFailureListener() {

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

Example 17 with OnSuccessListener

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

the class MyDownloadService method downloadFromPath.

private void downloadFromPath(final String downloadPath) {
    Log.d(TAG, "downloadFromPath:" + downloadPath);
    // Mark task started
    taskStarted();
    showProgressNotification(getString(R.string.progress_downloading), 0, 0);
    // Download and get total bytes
    mStorageRef.child(downloadPath).getStream(new StreamDownloadTask.StreamProcessor() {

        @Override
        public void doInBackground(StreamDownloadTask.TaskSnapshot taskSnapshot, InputStream inputStream) throws IOException {
            long totalBytes = taskSnapshot.getTotalByteCount();
            long bytesDownloaded = 0;
            byte[] buffer = new byte[1024];
            int size;
            while ((size = inputStream.read(buffer)) != -1) {
                bytesDownloaded += size;
                showProgressNotification(getString(R.string.progress_downloading), bytesDownloaded, totalBytes);
            }
            // Close the stream at the end of the Task
            inputStream.close();
        }
    }).addOnSuccessListener(new OnSuccessListener<StreamDownloadTask.TaskSnapshot>() {

        @Override
        public void onSuccess(StreamDownloadTask.TaskSnapshot taskSnapshot) {
            Log.d(TAG, "download:SUCCESS");
            // Send success broadcast with number of bytes downloaded
            broadcastDownloadFinished(downloadPath, taskSnapshot.getTotalByteCount());
            showDownloadFinishedNotification(downloadPath, (int) taskSnapshot.getTotalByteCount());
            // Mark task completed
            taskCompleted();
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
            Log.w(TAG, "download:FAILURE", exception);
            // Send failure broadcast
            broadcastDownloadFinished(downloadPath, -1);
            showDownloadFinishedNotification(downloadPath, -1);
            // Mark task completed
            taskCompleted();
        }
    });
}
Also used : InputStream(java.io.InputStream) StreamDownloadTask(com.google.firebase.storage.StreamDownloadTask) IOException(java.io.IOException) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) IOException(java.io.IOException)

Example 18 with OnSuccessListener

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

the class MainActivity method onCreate.

// [START on_create]
@Override
protected void onCreate(Bundle savedInstanceState) {
    // [START_EXCLUDE]
    super.onCreate(savedInstanceState);
    ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    TextView linkSendTextView = binding.linkViewSend;
    final TextView linkReceiveTextView = binding.linkViewReceive;
    // Validate that the developer has set the app code.
    validateAppCode();
    // Create a deep link and display it in the UI
    final Uri deepLink = buildDeepLink(Uri.parse(DEEP_LINK_URL), 0);
    linkSendTextView.setText(deepLink.toString());
    // Share button click listener
    binding.buttonShare.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            shareDeepLink(deepLink.toString());
        }
    });
    // [END_EXCLUDE]
    // [START get_deep_link]
    FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()).addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {

        @Override
        public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
            // Get deep link from result (may be null if no link is found)
            Uri deepLink = null;
            if (pendingDynamicLinkData != null) {
                deepLink = pendingDynamicLinkData.getLink();
            }
            // Display deep link in the UI
            if (deepLink != null) {
                Snackbar.make(findViewById(android.R.id.content), "Found deep link!", Snackbar.LENGTH_LONG).show();
                linkReceiveTextView.setText(deepLink.toString());
            } else {
                Log.d(TAG, "getDynamicLink: no link found");
            }
        // [END_EXCLUDE]
        }
    }).addOnFailureListener(this, new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.w(TAG, "getDynamicLink:onFailure", e);
        }
    });
// [END get_deep_link]
}
Also used : PendingDynamicLinkData(com.google.firebase.dynamiclinks.PendingDynamicLinkData) TextView(android.widget.TextView) ActivityMainBinding(com.google.firebase.quickstart.deeplinks.databinding.ActivityMainBinding) Uri(android.net.Uri) TextView(android.widget.TextView) View(android.view.View) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 19 with OnSuccessListener

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

the class MultiFactorEnrollFragment method enrollWithPhoneAuthCredential.

private void enrollWithPhoneAuthCredential(PhoneAuthCredential credential) {
    FirebaseAuth.getInstance().getCurrentUser().getMultiFactor().enroll(PhoneMultiFactorGenerator.getAssertion(credential), /* displayName= */
    null).addOnSuccessListener(new OnSuccessListener<Void>() {

        @Override
        public void onSuccess(Void aVoid) {
            Toast.makeText(getContext(), "MFA enrollment was successful", Toast.LENGTH_LONG).show();
            NavHostFragment.findNavController(MultiFactorEnrollFragment.this).popBackStack();
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.d(TAG, "MFA failure", e);
            Toast.makeText(getContext(), "MFA enrollment was unsuccessful. " + e, Toast.LENGTH_LONG).show();
        }
    });
}
Also used : OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FirebaseException(com.google.firebase.FirebaseException)

Example 20 with OnSuccessListener

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

the class GenericIdpFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser currentUser = mAuth.getCurrentUser();
    updateUI(currentUser);
    // Look for a pending auth result
    Task<AuthResult> pending = mAuth.getPendingAuthResult();
    if (pending != null) {
        pending.addOnSuccessListener(new OnSuccessListener<AuthResult>() {

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

            @Override
            public void onFailure(@NonNull Exception e) {
                Log.w(TAG, "checkPending:onFailure", e);
            }
        });
    } else {
        Log.d(TAG, "checkPending: null");
    }
}
Also used : AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) 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