Search in sources :

Example 16 with FirebaseUser

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();
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 17 with FirebaseUser

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);
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser) MainThread(android.support.annotation.MainThread)

Example 18 with FirebaseUser

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);
}
Also used : Query(com.google.firebase.database.Query) RecyclerView(android.support.v7.widget.RecyclerView) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 19 with FirebaseUser

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]
}
Also used : FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) LoginButton(com.facebook.login.widget.LoginButton) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 20 with FirebaseUser

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]
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser)

Aggregations

FirebaseUser (com.google.firebase.auth.FirebaseUser)27 AuthResult (com.google.firebase.auth.AuthResult)7 Button (android.widget.Button)6 FakeAuthResult (com.firebase.ui.auth.testhelpers.FakeAuthResult)6 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)6 BuildConfig (com.firebase.ui.auth.BuildConfig)5 Test (org.junit.Test)5 NonNull (android.support.annotation.NonNull)4 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)4 Config (org.robolectric.annotation.Config)4 Bitmap (android.graphics.Bitmap)3 EditText (android.widget.EditText)3 ActivityHelperShadow (com.firebase.ui.auth.testhelpers.ActivityHelperShadow)3 TaskFailureLogger (com.firebase.ui.auth.ui.TaskFailureLogger)3 Task (com.google.android.gms.tasks.Task)3 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)3 StorageReference (com.google.firebase.storage.StorageReference)3 UploadTask (com.google.firebase.storage.UploadTask)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Intent (android.content.Intent)2