Search in sources :

Example 21 with OnSuccessListener

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

the class GenericIdpFragment method signIn.

private void signIn() {
    // Could add custom scopes here
    ArrayList<String> scopes = new ArrayList<>();
    // Examples of provider ID: apple.com (Apple), microsoft.com (Microsoft), yahoo.com (Yahoo)
    String providerId = getProviderId();
    mAuth.startActivityForSignInWithProvider(requireActivity(), OAuthProvider.newBuilder(providerId, mAuth).setScopes(scopes).build()).addOnSuccessListener(new OnSuccessListener<AuthResult>() {

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

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.w(TAG, "activitySignIn:onFailure", e);
            showToast(getString(R.string.error_sign_in_failed));
        }
    });
}
Also used : ArrayList(java.util.ArrayList) AuthResult(com.google.firebase.auth.AuthResult) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 22 with OnSuccessListener

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

the class RestaurantDetailFragment method onRating.

@Override
public void onRating(Rating rating) {
    // In a transaction, add the new rating and update the aggregate totals
    addRating(mRestaurantRef, rating).addOnSuccessListener(requireActivity(), new OnSuccessListener<Void>() {

        @Override
        public void onSuccess(Void aVoid) {
            Log.d(TAG, "Rating added");
            // Hide keyboard and scroll to top
            hideKeyboard();
            mBinding.recyclerRatings.smoothScrollToPosition(0);
        }
    }).addOnFailureListener(requireActivity(), new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.w(TAG, "Add rating failed", e);
            // Show failure message and hide keyboard
            hideKeyboard();
            Snackbar.make(mBinding.getRoot(), "Failed to add rating", Snackbar.LENGTH_SHORT).show();
        }
    });
}
Also used : OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FirebaseFirestoreException(com.google.firebase.firestore.FirebaseFirestoreException)

Example 23 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project xabber-android by redsolution.

the class XabberLoginActivity method getCaptchaToken.

/**
 * CAPTCHA
 */
private void getCaptchaToken(final SignUpRepo signUpRepo) {
    SafetyNet.getClient(this).verifyWithRecaptcha(getString(R.string.RECAPTCHA_KEY)).addOnSuccessListener(this, new OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse>() {

        @Override
        public void onSuccess(SafetyNetApi.RecaptchaTokenResponse response) {
            // Indicates communication with reCAPTCHA service was
            // successful.
            String userResponseToken = response.getTokenResult();
            if (!userResponseToken.isEmpty()) {
                // Validate the user response token using the
                // reCAPTCHA siteverify API.
                Log.d(CAPTCHA_TOKEN, "Success: " + userResponseToken);
                signUpRepo.setCaptchaToken(userResponseToken);
                signUp(signUpRepo);
            }
        }
    }).addOnFailureListener(this, new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            if (e instanceof ApiException) {
                // An error occurred when communicating with the
                // reCAPTCHA service. Refer to the status code to
                // handle the error appropriately.
                ApiException apiException = (ApiException) e;
                int statusCode = apiException.getStatusCode();
                Log.d(CAPTCHA_TOKEN, "Error: " + CommonStatusCodes.getStatusCodeString(statusCode));
            } else {
                // A different, unknown type of error occurred.
                Log.d(CAPTCHA_TOKEN, "Error: " + e.getMessage());
            }
        }
    });
}
Also used : SafetyNetApi(com.google.android.gms.safetynet.SafetyNetApi) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) SocketTimeoutException(java.net.SocketTimeoutException) ApiException(com.google.android.gms.common.api.ApiException) ApiException(com.google.android.gms.common.api.ApiException)

Example 24 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project IITB-App by wncc.

the class FileComplaintFragment method getMapReady.

public void getMapReady() {
    mMapView.getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(GoogleMap map) {
            googleMap = map;
            UiSettings uiSettings = googleMap.getUiSettings();
            uiSettings.setAllGesturesEnabled(true);
            uiSettings.setZoomControlsEnabled(true);
            uiSettings.setMyLocationButtonEnabled(true);
            uiSettings.setIndoorLevelPickerEnabled(true);
            uiSettings.setScrollGesturesEnabled(true);
            if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, MY_PERMISSIONS_REQUEST_LOCATION);
            } else {
                googleMap.setMyLocationEnabled(true);
                googleMap.getUiSettings().setMyLocationButtonEnabled(true);
                googleMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {

                    @Override
                    public boolean onMyLocationButtonClick() {
                        locate();
                        return false;
                    }
                });
                FusedLocationProviderClient mFusedLocationClient = LocationServices.getFusedLocationProviderClient(getActivity());
                mFusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {

                    @Override
                    public void onSuccess(Location location) {
                        // Got last known location. In some rare situations this can be null.
                        if (location != null) {
                            // Logic to handle location object
                            Location = new LatLng(location.getLatitude(), location.getLongitude());
                            updateMap(Location, "Current Location", location.getLatitude() + ", " + location.getLongitude(), cursor);
                        } else {
                            Toast.makeText(getContext(), getString(R.string.getting_current_location), Toast.LENGTH_SHORT).show();
                        }
                    }
                });
                mFusedLocationClient.getLastLocation().addOnFailureListener(new OnFailureListener() {

                    @Override
                    public void onFailure(Exception e) {
                        e.printStackTrace();
                    }
                });
            }
        }
    });
}
Also used : GoogleMap(com.google.android.gms.maps.GoogleMap) UiSettings(com.google.android.gms.maps.UiSettings) OnMapReadyCallback(com.google.android.gms.maps.OnMapReadyCallback) FusedLocationProviderClient(com.google.android.gms.location.FusedLocationProviderClient) LatLng(com.google.android.gms.maps.model.LatLng) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) ApiException(com.google.android.gms.common.api.ApiException) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) Location(android.location.Location)

Example 25 with OnSuccessListener

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

the class RegisterEmailFragment method registerUser.

private void registerUser(final String email, final String name, final String password) {
    mHelper.getFirebaseAuth().createUserWithEmailAndPassword(email, password).addOnFailureListener(new TaskFailureLogger(TAG, "Error creating user")).addOnSuccessListener(new OnSuccessListener<AuthResult>() {

        @Override
        public void onSuccess(AuthResult authResult) {
            // Set display name
            UserProfileChangeRequest changeNameRequest = new UserProfileChangeRequest.Builder().setDisplayName(name).setPhotoUri(mUser.getPhotoUri()).build();
            final FirebaseUser user = authResult.getUser();
            user.updateProfile(changeNameRequest).addOnFailureListener(new TaskFailureLogger(TAG, "Error setting display name")).addOnCompleteListener(new OnCompleteListener<Void>() {

                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    // This executes even if the name change fails, since
                    // the account creation succeeded and we want to save
                    // the credential to SmartLock (if enabled).
                    mHelper.saveCredentialsOrFinish(mSaveSmartLock, getActivity(), user, password, new IdpResponse(EmailAuthProvider.PROVIDER_ID, email));
                }
            });
        }
    }).addOnFailureListener(getActivity(), new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            mHelper.dismissDialog();
            if (e instanceof FirebaseAuthWeakPasswordException) {
                // Password too weak
                mPasswordInput.setError(getResources().getQuantityString(R.plurals.error_weak_password, R.integer.min_password_length));
            } else if (e instanceof FirebaseAuthInvalidCredentialsException) {
                // Email address is malformed
                mEmailInput.setError(getString(R.string.invalid_email_address));
            } else if (e instanceof FirebaseAuthUserCollisionException) {
                // Collision with existing user email, it should be very hard for
                // the user to even get to this error due to CheckEmailFragment.
                mEmailInput.setError(getString(R.string.error_user_collision));
            } else {
                // General error message, this branch should not be invoked but
                // covers future API changes
                mEmailInput.setError(getString(R.string.email_account_creation_error));
            }
        }
    });
}
Also used : TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) FirebaseAuthWeakPasswordException(com.google.firebase.auth.FirebaseAuthWeakPasswordException) UserProfileChangeRequest(com.google.firebase.auth.UserProfileChangeRequest) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FirebaseAuthWeakPasswordException(com.google.firebase.auth.FirebaseAuthWeakPasswordException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) IdpResponse(com.firebase.ui.auth.IdpResponse)

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