use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class SignedInActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
if (currentUser == null) {
startActivity(AuthUiActivity.createIntent(this));
finish();
return;
}
mIdpResponse = IdpResponse.fromResultIntent(getIntent());
setContentView(R.layout.signed_in_layout);
ButterKnife.bind(this);
populateProfile();
populateIdpToken();
}
use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class SignedInActivity method populateProfile.
@MainThread
private void populateProfile() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user.getPhotoUrl() != null) {
Glide.with(this).load(user.getPhotoUrl()).fitCenter().into(mUserProfilePicture);
}
mUserEmail.setText(TextUtils.isEmpty(user.getEmail()) ? "No email" : user.getEmail());
mUserDisplayName.setText(TextUtils.isEmpty(user.getDisplayName()) ? "No display name" : user.getDisplayName());
StringBuilder providerList = new StringBuilder(100);
providerList.append("Providers used: ");
if (user.getProviders() == null || user.getProviders().isEmpty()) {
providerList.append("none");
} else {
Iterator<String> providerIter = user.getProviders().iterator();
while (providerIter.hasNext()) {
String provider = providerIter.next();
if (GoogleAuthProvider.PROVIDER_ID.equals(provider)) {
providerList.append("Google");
} else if (FacebookAuthProvider.PROVIDER_ID.equals(provider)) {
providerList.append("Facebook");
} else if (EmailAuthProvider.PROVIDER_ID.equals(provider)) {
providerList.append("Password");
} else {
providerList.append(provider);
}
if (providerIter.hasNext()) {
providerList.append(", ");
}
}
}
mEnabledProviders.setText(providerList);
}
use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class ChatActivity method attachRecyclerViewAdapter.
private void attachRecyclerViewAdapter() {
Query lastFifty = mChatRef.limitToLast(50);
mAdapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(Chat.class, R.layout.message, ChatHolder.class, lastFifty) {
@Override
public void populateViewHolder(ChatHolder holder, Chat chat, int position) {
holder.setName(chat.getName());
holder.setText(chat.getMessage());
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser != null && chat.getUid().equals(currentUser.getUid())) {
holder.setIsSender(true);
} else {
holder.setIsSender(false);
}
}
@Override
protected void onDataChanged() {
// If there are no chat messages, show a view that invites the user to add a message.
mEmptyListMessage.setVisibility(mAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
}
};
// Scroll to bottom on new messages
mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
mManager.smoothScrollToPosition(mMessages, null, mAdapter.getItemCount());
}
});
mMessages.setAdapter(mAdapter);
}
use of com.google.firebase.auth.FirebaseUser in project quickstart-android by firebase.
the class FacebookLoginActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_facebook);
// Views
mStatusTextView = (TextView) findViewById(R.id.status);
mDetailTextView = (TextView) findViewById(R.id.detail);
findViewById(R.id.button_facebook_signout).setOnClickListener(this);
// [START initialize_auth]
// Initialize Firebase Auth
mAuth = FirebaseAuth.getInstance();
// [END initialize_auth]
// [START auth_state_listener]
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
// [START_EXCLUDE]
updateUI(user);
// [END_EXCLUDE]
}
};
// [END auth_state_listener]
// [START initialize_fblogin]
// Initialize Facebook Login button
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.button_facebook_login);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "facebook:onSuccess:" + loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Log.d(TAG, "facebook:onCancel");
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
@Override
public void onError(FacebookException error) {
Log.d(TAG, "facebook:onError", error);
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
});
// [END initialize_fblogin]
}
use of com.google.firebase.auth.FirebaseUser in project quickstart-android by firebase.
the class EmailPasswordActivity method sendEmailVerification.
private void sendEmailVerification() {
// Disable button
findViewById(R.id.verify_email_button).setEnabled(false);
// Send verification email
// [START send_email_verification]
final FirebaseUser user = mAuth.getCurrentUser();
user.sendEmailVerification().addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// [START_EXCLUDE]
// Re-enable button
findViewById(R.id.verify_email_button).setEnabled(true);
if (task.isSuccessful()) {
Toast.makeText(EmailPasswordActivity.this, "Verification email sent to " + user.getEmail(), Toast.LENGTH_SHORT).show();
} else {
Log.e(TAG, "sendEmailVerification", task.getException());
Toast.makeText(EmailPasswordActivity.this, "Failed to send verification email.", Toast.LENGTH_SHORT).show();
}
// [END_EXCLUDE]
}
});
// [END send_email_verification]
}
Aggregations