@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mAuth = FirebaseAuth.getInstance(); mDatabase = new Firebase(Const.FIREBASE_URL + "stuffs"); 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 { // User is signed out Log.d(TAG, "onAuthStateChanged:signed_out"); Intent errorIntent = new Intent(getActivity(), SignInActivity.class); startActivity(errorIntent); Toast.makeText(getActivity(), "Some error arose, please relogin", Toast.LENGTH_SHORT) .show(); } } }; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* Setup the Google API object to allow Google logins */ mAuth = FirebaseAuth.getInstance(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_in); mAuth = FirebaseAuth.getInstance(); initGoogleSignIn(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_google); // Views mStatusTextView = (TextView) findViewById(R.id.status); mDetailTextView = (TextView) findViewById(R.id.detail); // Button listeners findViewById(R.id.sign_in_button).setOnClickListener(this); findViewById(R.id.sign_out_button).setOnClickListener(this); findViewById(R.id.disconnect_button).setOnClickListener(this); // [START config_signin] // Configure Google Sign In GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.default_web_client_id)) .requestEmail() .build(); // [END config_signin] mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); // [START initialize_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] }
private void initUI() { firebaseAuth = FirebaseAuth.getInstance(); if (firebaseAuth.getCurrentUser() != null) { startActivity(new Intent(this, MainActivity.class)); finish(); } tilEmail = (TextInputLayout) findViewById(R.id.tilEmail); clGeneral = (CoordinatorLayout) findViewById(R.id.clGeneral); tilPassword = (TextInputLayout) findViewById(R.id.tilPassword); tieEmail = (TextInputEditText) findViewById(R.id.tieEmail); tiePassword = (TextInputEditText) findViewById(R.id.tiePassword); btnLogin = (AppCompatButton) findViewById(R.id.btnLogin); lblRecoveryPassword = (AppCompatTextView) findViewById(R.id.lblRecoveryPassword); lblCreateAccount = (AppCompatTextView) findViewById(R.id.lblCreateAccount); btnLogin.setOnClickListener(this); lblRecoveryPassword.setOnClickListener(this); lblCreateAccount.setOnClickListener(this); tieEmail.addTextChangedListener(new CustomTextWatcher(tieEmail)); tiePassword.addTextChangedListener(new CustomTextWatcher(tiePassword)); tiePassword.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_GO) { btnLogin.performClick(); return true; } return false; } }); }