Java Code Examples for com.google.firebase.auth.FirebaseUser#getDisplayName()

The following examples show how to use com.google.firebase.auth.FirebaseUser#getDisplayName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From snippets-android with Apache License 2.0 8 votes vote down vote up
public void getUserProfile() {
    // [START get_user_profile]
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        // Name, email address, and profile photo Url
        String name = user.getDisplayName();
        String email = user.getEmail();
        Uri photoUrl = user.getPhotoUrl();

        // Check if user's email is verified
        boolean emailVerified = user.isEmailVerified();

        // The user's ID, unique to the Firebase project. Do NOT use this value to
        // authenticate with your backend server, if you have one. Use
        // FirebaseUser.getIdToken() instead.
        String uid = user.getUid();
    }
    // [END get_user_profile]
}
 
Example 2
Source File: MainActivity.java    From protrip with MIT License 7 votes vote down vote up
private void onSignedInInitialize(FirebaseUser firebaseUser) {

        //Firebase Auth
        User user = new User(firebaseUser.getDisplayName(),
                firebaseUser.getPhotoUrl(),
                firebaseUser.getEmail(), firebaseUser.getUid());
        mUsername = user.getUsername();
        mUserAvatarUrl = user.getAvatarUrl();
        mUserEmail = user.getEmailId();
        mUid = user.getUid();
        tvUserName.setText(mUsername);
        tvUserEmail.setVisibility(View.VISIBLE);
        tvUserEmail.setText(mUserEmail);
        logoutItem.setVisible(true);
        favoritesItem.setVisible(true);
        if (mUserAvatarUrl != null) {
            Picasso.with(this).load(mUserAvatarUrl).
                    placeholder(R.drawable.ic_account_circle_white_24dp).
                    transform(new CircleTransform()).
                    fit().
                    into(ivAvatar);
        }


    }
 
Example 3
Source File: ProfileActivity.java    From friendlypix-android with Apache License 2.0 6 votes vote down vote up
private void showSignedInUI(FirebaseUser firebaseUser) {
    Log.d(TAG, "Showing signed in UI");
    mSignInUi.setVisibility(View.GONE);
    mProfileUi.setVisibility(View.VISIBLE);
    mProfileUsername.setVisibility(View.VISIBLE);
    mProfilePhoto.setVisibility(View.VISIBLE);
    if (firebaseUser.getDisplayName() != null) {
        mProfileUsername.setText(firebaseUser.getDisplayName());
    }

    if (firebaseUser.getPhotoUrl() != null) {
        GlideUtil.loadProfileIcon(firebaseUser.getPhotoUrl().toString(), mProfilePhoto);
    }
    Map<String, Object> updateValues = new HashMap<>();
    updateValues.put("displayName", firebaseUser.getDisplayName() != null ? firebaseUser.getDisplayName() : "Anonymous");
    updateValues.put("photoUrl", firebaseUser.getPhotoUrl() != null ? firebaseUser.getPhotoUrl().toString() : null);

    FirebaseUtil.getPeopleRef().child(firebaseUser.getUid()).updateChildren(
            updateValues,
            new DatabaseReference.CompletionListener() {
                @Override
                public void onComplete(DatabaseError firebaseError, DatabaseReference databaseReference) {
                    if (firebaseError != null) {
                        Toast.makeText(ProfileActivity.this,
                                "Couldn't save user data: " + firebaseError.getMessage(),
                                Toast.LENGTH_LONG).show();
                    }
                }
            });
}
 
Example 4
Source File: PlaceDetailActivity.java    From protrip with MIT License 6 votes vote down vote up
private void onSignedInInitialize(FirebaseUser firebaseUser) {
    User user = new User(firebaseUser.getDisplayName(),
            firebaseUser.getPhotoUrl(),
            firebaseUser.getEmail(),
            firebaseUser.getUid());

    mUsername = user.getUsername();
    mUserAvatarUrl = user.getAvatarUrl();
    mUserEmail = user.getEmailId();
    mUid = user.getUid();

    mFavsDbRef = mFirebaseDatabase.getReference().getRoot().child(mUid + "/favoritePlaces");
    isFavourite(this, place_id);
}
 
Example 5
Source File: UserModel.java    From openwebnet-android with MIT License 6 votes vote down vote up
private Builder(FirebaseUser firebaseUser) {
    this.userId = firebaseUser.getUid();
    this.email = firebaseUser.getEmail();
    this.name = firebaseUser.getDisplayName();
    this.phoneNumber = firebaseUser.getPhoneNumber();
    this.photoUrl = firebaseUser.getPhotoUrl() == null ? null : firebaseUser.getPhotoUrl().toString();

    // https://stackoverflow.com/questions/4212320/get-the-current-language-in-device
    this.iso3Language = Locale.getDefault().getISO3Language();
    this.iso3Country = Locale.getDefault().getISO3Country();
    this.locale = ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()).toLanguageTags();

    this.createdAt = firebaseUser.getMetadata() != null ?
        new Date(firebaseUser.getMetadata().getCreationTimestamp()) : new Date();
    this.modifiedAt = new Date();
}
 
Example 6
Source File: MainActivity.java    From white-label-event-app with Apache License 2.0 6 votes vote down vote up
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
    final FirebaseUser user = firebaseAuth.getCurrentUser();
    if (user != null) {
        LOGGER.fine("onAuthStateChanged: " + user.getUid());
        navigationHeaderView.showViewId(R.id.vg_profile);
        final TextView tv_name = (TextView) navigationHeaderView.findViewById(R.id.tv_name);
        final String name = user.getDisplayName();
        tv_name.setText(name != null ? name : "[No name]");
        final Uri photoUrl = user.getPhotoUrl();
        Glide
            .with(MainActivity.this)
            .load(photoUrl)
            .centerCrop()
            .placeholder(R.drawable.nopic)
            .into((ImageView) navigationHeaderView.findViewById(R.id.iv_pic));
        if (state.isRequestingSignin) {
            Toast.makeText(
                MainActivity.this,
                getString(R.string.msg_sign_in_thank_you, user.getDisplayName()),
                Toast.LENGTH_SHORT).show();
            state.isRequestingSignin = false;
        }
    }
    else {
        LOGGER.fine("onAuthStateChanged: signed out");
        navigationHeaderView.showViewId(R.id.button_sign_in);
        ((TextView) navigationHeaderView.findViewById(R.id.tv_name)).setText(null);
        ((ImageView) navigationHeaderView.findViewById(R.id.iv_pic)).setImageBitmap(null);
    }
}
 
Example 7
Source File: ChatAuthentication.java    From chat21-android-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
private  IChatUser convertFirebaseUserToChatUser (FirebaseUser firebaseUser) {
    if (firebaseUser!=null){
        return new ChatUser(firebaseUser.getUid(), firebaseUser.getDisplayName());
    }else {
        return null;
    }
}
 
Example 8
Source File: Rating.java    From firestore-android-arch-components with Apache License 2.0 5 votes vote down vote up
public Rating(FirebaseUser user, double rating, String text) {
    this.userId = user.getUid();
    this.userName = user.getDisplayName();
    if (TextUtils.isEmpty(this.userName)) {
        this.userName = user.getEmail();
    }

    this.rating = rating;
    this.text = text;
}
 
Example 9
Source File: Rating.java    From friendlyeats-android with Apache License 2.0 5 votes vote down vote up
public Rating(FirebaseUser user, double rating, String text) {
    this.userId = user.getUid();
    this.userName = user.getDisplayName();
    if (TextUtils.isEmpty(this.userName)) {
        this.userName = user.getEmail();
    }

    this.rating = rating;
    this.text = text;
}
 
Example 10
Source File: MainActivity.java    From snippets-android with Apache License 2.0 5 votes vote down vote up
private void gamesGetUserInfo() {
    FirebaseAuth mAuth = FirebaseAuth.getInstance();

    // [START games_get_user_info]
    FirebaseUser user = mAuth.getCurrentUser();
    String playerName = user.getDisplayName();

    // The user's Id, unique to the Firebase project.
    // Do NOT use this value to authenticate with your backend server, if you
    // have one; use FirebaseUser.getIdToken() instead.
    String uid = user.getUid();
    // [END games_get_user_info]
}
 
Example 11
Source File: Rating.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
public Rating(FirebaseUser user, double rating, String text) {
    this.userId = user.getUid();
    this.userName = user.getDisplayName();
    if (TextUtils.isEmpty(this.userName)) {
        this.userName = user.getEmail();
    }

    this.rating = rating;
    this.text = text;
}
 
Example 12
Source File: SignInUI.java    From stockita-point-of-sale with MIT License 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {

        case RC_SIGN_IN:

            if (resultCode == RESULT_OK) {
                // user is signed in!

                /**
                 * Get a reference for the current signed in user, and get the
                 * email and the UID
                 */
                FirebaseUser userProfile = FirebaseAuth.getInstance().getCurrentUser();

                if (userProfile != null) {


                    // Get the photo Url
                    Uri photoUri = userProfile.getPhotoUrl();
                    final String photoUrl = photoUri != null ? photoUri.getPath() : null;

                    // Get the user name and store them in SharedPreferences for later use.
                    final String profileName = userProfile.getDisplayName();

                    // Get the user email and store them in SharedPreferences for later use.
                    final String profileEmail = userProfile.getEmail();

                    // Get the user UID and sore them in SharedPreferences for later use.
                    final String profileUid = userProfile.getUid();

                    // Encoded the email that the user just signed in with
                    String encodedUserEmail = Utility.encodeEmail(profileEmail);

                    // Register the current sign in data in SharedPreferences for later use
                    Utility.registerTheCurrentLogin(getBaseContext(), profileName, profileUid, encodedUserEmail, photoUrl);

                    // Initialize the Firebase reference to the /users/<userUid> location
                    final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference()
                            .child(Constants.FIREBASE_USER_LOCATION)
                            .child(profileUid);

                    // Listener for a single value event, only one time this listener will be triggered
                    databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
                        @Override
                        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                            // Check if hasChildren means already exists
                            if (!dataSnapshot.hasChildren()) {

                                /**
                                 * Create this new user into /users/ node in Firebase
                                 */
                                Utility.createUser(getBaseContext(), profileName, profileUid, profileEmail, photoUrl);
                            }

                        }

                        @Override
                        public void onCancelled(@NonNull DatabaseError databaseError) {

                            // Get the message in to the logcat
                            Log.e("check if users exist", databaseError.getMessage());
                        }
                    });
                }

                // When signed in then start the main activity
                startActivity(new Intent(this, MainActivity.class));
                finish();

            } else {
                // user is not signed in. Maybe just wait for the user to press
                // "sign in" again, or show a message
                Log.e(TAG_LOG, "not failed to sign in");
            }
    }
}
 
Example 13
Source File: FirestackAuth.java    From react-native-firestack with MIT License 5 votes vote down vote up
private WritableMap getUserMap() {
    WritableMap userMap = Arguments.createMap();

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    if (user != null) {
      final String email = user.getEmail();
      final String uid   = user.getUid();
      final String provider = user.getProviderId();
      final String name = user.getDisplayName();
      final Uri photoUrl = user.getPhotoUrl();

      userMap.putString("email", email);
      userMap.putString("uid", uid);
      userMap.putString("providerId", provider);
      userMap.putBoolean("emailVerified", user.isEmailVerified());
      userMap.putBoolean("anonymous", user.isAnonymous());
      if (name != null) {
        userMap.putString("displayName", name);
      }

      if (photoUrl != null) {
        userMap.putString("photoUrl", photoUrl.toString());
      }
    } else {
      userMap.putString("msg", "no user");
    }

    return userMap;
}
 
Example 14
Source File: FirebaseUtil.java    From friendlypix-android with Apache License 2.0 4 votes vote down vote up
public static Author getAuthor() {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user == null) return null;
    return new Author(user.getDisplayName(), user.getPhotoUrl().toString(), user.getUid());
}