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