Search in sources :

Example 41 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project FirebaseAuth-Android by jirawatee.

the class EmailPasswordActivity method onClick.

@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.email_create_account_button:
            createAccount(mEdtEmail.getText().toString(), mEdtPassword.getText().toString());
            break;
        case R.id.email_sign_in_button:
            signIn(mEdtEmail.getText().toString(), mEdtPassword.getText().toString());
            break;
        case R.id.sign_out_button:
            signOut();
            break;
        case R.id.verify_button:
            findViewById(R.id.verify_button).setEnabled(false);
            final FirebaseUser firebaseUser = mAuth.getCurrentUser();
            firebaseUser.sendEmailVerification().addOnCompleteListener(this, new OnCompleteListener<Void>() {

                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        Toast.makeText(EmailPasswordActivity.this, "Verification email sent to " + firebaseUser.getEmail(), Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(EmailPasswordActivity.this, task.getException().getMessage(), Toast.LENGTH_LONG).show();
                    }
                    findViewById(R.id.verify_button).setEnabled(true);
                }
            });
            break;
    }
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 42 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project FirebaseAuth-Android by jirawatee.

the class GoogleSignInActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_google);
    mImageView = findViewById(R.id.logo);
    mTextViewProfile = findViewById(R.id.profile);
    SignInButton signInButton = findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_WIDE);
    signInButton.setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);
    findViewById(R.id.disconnect_button).setOnClickListener(this);
    // Configure Google Sign In
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.default_web_client_id)).requestEmail().build();
    mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, this).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            updateUI(user);
        }
    };
}
Also used : SignInButton(com.google.android.gms.common.SignInButton) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions) FirebaseUser(com.google.firebase.auth.FirebaseUser) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 43 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project GogoNew by kuldeep725.

the class Login method onStart.

@Override
public void onStart() {
    super.onStart();
    // new MapsActivity().showInternetStatus();
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser currentUser = mAuth.getCurrentUser();
    mAuth.addAuthStateListener(new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
        }
    });
    if (currentUser != null) {
        Intent i = new Intent(Login.this, MapsActivity.class);
        startActivity(i);
        finish();
    }
}
Also used : Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 44 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project GogoNew by kuldeep725.

the class MapsActivity method onStart.

@Override
public void onStart() {
    super.onStart();
    Log.d(TAG, "onStart fired ..............");
    if (!checkPermissions()) {
        requestPermissions();
    }
    FirebaseAuth mAuth = FirebaseAuth.getInstance();
    FirebaseUser currentUser = mAuth.getCurrentUser();
    if (currentUser == null) {
        Intent i = new Intent(MapsActivity.this, Login.class);
        startActivity(i);
        finish();
    }
    showInternetStatus();
    SharedPreferences loginPrefs = getSharedPreferences("userId", MODE_PRIVATE);
    userEmail = loginPrefs.getString("email", "User id");
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    View headerView = navigationView.getHeaderView(0);
    TextView tv = (TextView) headerView.findViewById(R.id.user_id);
    tv.setText(userEmail);
    SharedPreferences prefs = getSharedPreferences("onStop", MODE_PRIVATE);
    // boolean floatingClickable = prefs.getBoolean(floatingClickableState, Boolean.TRUE);
    radiobuttonId = prefs.getInt(radioButtonString, 0);
    flagSendOrCancel = prefs.getInt("flagSendOrCancel", 0);
    int bus = prefs.getInt(whichBus, 0);
    theKey = prefs.getString(keyString, null);
    pickMeRadioButtonId = prefs.getInt("pickMeRadioButton", -1);
    minName = prefs.getString(minNameStr, null);
    Log.e(TAG, "onStart-> pickMeRadioButtonId = " + pickMeRadioButtonId);
    Log.d(TAG, "flagSendOrCancel" + " = " + flagSendOrCancel);
    Log.d(TAG, "radiobuttonId" + " = " + radiobuttonId);
    Log.d(TAG, whichBus + " = " + bus);
    Log.d(TAG, "theKey = " + theKey);
    Log.d(TAG, "minName = " + minName);
    checkBusSelection = radiobuttonId;
    BUS = prefs.getString("pickMeBus", null);
    if (BUS == null) {
        BUS = "b" + checkBusSelection;
    }
    if (flagSendOrCancel != 0) {
        floatingButton.setImageResource(R.drawable.ic_cancel_white_24dp);
        floatingButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.myRed)));
        pickMeDone = true;
    }
    if (checkPermissions()) {
        mGoogleApiClient.connect();
        Log.e(TAG, "mGoogleApiClient is connected");
    } else {
        Log.e(TAG, "mGoogleApiClient is not connected");
    }
    mDatabase.addChildEventListener(new ChildEventListener() {

        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            Log.d(TAG, "dataSnapshot.getKey()  = " + dataSnapshot.getKey());
            Log.d(TAG, "dataSnapshot.getChildrenCount() = " + dataSnapshot.getChildrenCount());
            /*check whether onChildAdded has already run once**/
            if (flagOnChild == 1)
                return;
            noOfBuses = dataSnapshot.getChildrenCount();
            Log.d(TAG, "noOfBuses = " + noOfBuses);
            // Log.d(TAG, "String s = " + s);
            createRadioButtons();
            if (radiobuttonId != 0) {
                // Log.d(TAG, "MAKING radiobutton setChecked(true)...");
                radiobutton = (RadioButton) findViewById(radiobuttonId);
                Log.d(TAG, "radiobutton @onStart = " + radiobutton.toString());
                radiobutton.setTextColor(Color.parseColor(primeColorString));
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    radiobutton.setBackground(getDrawable(R.drawable.underline));
                } else {
                    radiobutton.setPaintFlags(radiobutton.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
                }
                radiobutton.setClickable(true);
                radiobutton.setChecked(false);
                lastButton = radiobutton;
                Log.d(TAG, "checkbusSelection = " + checkBusSelection);
            }
            if (pickMeRadioButtonId != -1) {
                pickMeRadioButton = (RadioButton) findViewById(pickMeRadioButtonId);
                pickMeRadioButton.setTypeface(Typeface.DEFAULT_BOLD);
                pickMeRadioButton.setTextColor(getResources().getColor(R.color.primeColor));
            }
            flagOnChild = 1;
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {
        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
Also used : NavigationView(android.support.design.widget.NavigationView) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser) RadioButton(android.widget.RadioButton) DataSnapshot(com.google.firebase.database.DataSnapshot) NavigationView(android.support.design.widget.NavigationView) View(android.view.View) TextView(android.widget.TextView) Paint(android.graphics.Paint) DatabaseError(com.google.firebase.database.DatabaseError) TextView(android.widget.TextView) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 45 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project quickstart-android by firebase.

the class PhoneAuthFragment 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);
    if (mVerificationInProgress && validatePhoneNumber()) {
        startPhoneNumberVerification(mBinding.fieldPhoneNumber.getText().toString());
    }
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser)

Aggregations

FirebaseUser (com.google.firebase.auth.FirebaseUser)115 AuthResult (com.google.firebase.auth.AuthResult)29 Intent (android.content.Intent)23 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)16 AuthCredential (com.google.firebase.auth.AuthCredential)14 DatabaseReference (com.google.firebase.database.DatabaseReference)13 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)12 DataSnapshot (com.google.firebase.database.DataSnapshot)12 DatabaseError (com.google.firebase.database.DatabaseError)12 ValueEventListener (com.google.firebase.database.ValueEventListener)11 View (android.view.View)10 Button (android.widget.Button)10 Task (com.google.android.gms.tasks.Task)10 NonNull (android.support.annotation.NonNull)8 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)7 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)7 TextView (android.widget.TextView)6 Test (org.junit.Test)6 Context (android.content.Context)5 SharedPreferences (android.content.SharedPreferences)5