當前位置: 首頁>>代碼示例>>Java>>正文


Java FirebaseAuth.AuthStateListener方法代碼示例

本文整理匯總了Java中com.google.firebase.auth.FirebaseAuth.AuthStateListener方法的典型用法代碼示例。如果您正苦於以下問題:Java FirebaseAuth.AuthStateListener方法的具體用法?Java FirebaseAuth.AuthStateListener怎麽用?Java FirebaseAuth.AuthStateListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.firebase.auth.FirebaseAuth的用法示例。


在下文中一共展示了FirebaseAuth.AuthStateListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: subscribe

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override public void subscribe(final ObservableEmitter<FirebaseAuth> emitter) {
  final FirebaseAuth.AuthStateListener listener = new FirebaseAuth.AuthStateListener() {
    @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
      if (!emitter.isDisposed()) {
        emitter.onNext(firebaseAuth);
      }
    }
  };

  instance.addAuthStateListener(listener);

  emitter.setDisposable(Disposables.fromAction(new Action() {
    @Override public void run() throws Exception {
      instance.removeAuthStateListener(listener);
    }
  }));
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:18,代碼來源:AuthStateChangesOnSubscribe.java

示例2: onCreate

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    fbAuth = FirebaseAuth.getInstance();
    fbUser = FirebaseAuth.getInstance().getCurrentUser();
    authStateListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if (fbUser == null){
                Log.v("FIREBASE", "--Logout");
            }
        }
    };

    //register("[email protected]", "makunat10");
    //signIn("[email protected]", "makunat10");
}
 
開發者ID:marckregio,項目名稱:maklib,代碼行數:20,代碼來源:FirebaseAuthActivity.java

示例3: init

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
public void init() {
	// Initialize listener.
	// ...

	mAuth = FirebaseAuth.getInstance();

	mAuthListener = new FirebaseAuth.AuthStateListener() {

		@Override
		public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
			FirebaseUser user = firebaseAuth.getCurrentUser();
			if (user != null) {
				Utils.d("E&P:onAuthStateChanged:signed_in:" + user.getUid());
				successSignIn(user);
			} else {
				// User is signed out
				Utils.d("E&P:onAuthStateChanged:signed_out");
				successSignOut();
			}

			// update user details;
		}
	};
}
 
開發者ID:FrogSquare,項目名稱:GodotFireBase,代碼行數:25,代碼來源:EmailAndPassword.java

示例4: onCreateView

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    mView = inflater.inflate(R.layout.frag_request,container,false);

    mRequests = new ArrayList<>();

    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            mUser = firebaseAuth.getCurrentUser();

        }
    };

    //mRequests.add(new Request("Name1","9PM"));
    //mRequests.add(new Request("Name2","9PM"));
    //mRequests.add(new Request("Name3","9PM"));

    initViews();
    setUpRecyclerView();
    getRequests();

    return mView;
}
 
開發者ID:PalisadoesFoundation,項目名稱:do-road,代碼行數:27,代碼來源:ReqeustFragment.java

示例5: initFirebase

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
private void initFirebase() {
    //Khoi tao thanh phan de dang nhap, dang ky
    mAuth = FirebaseAuth.getInstance();
    authUtils = new AuthUtils();
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                StaticConfig.UID = user.getUid();
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
                if (firstTimeAccess) {
                    startActivity(new Intent(LoginActivity.this, HomeActivity.class));
                    LoginActivity.this.finish();
                }
            } else {
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            firstTimeAccess = false;
        }
    };

    //Khoi tao dialog waiting khi dang nhap
    waitingDialog = new LovelyProgressDialog(this).setCancelable(false);
}
 
開發者ID:ansarisufiyan777,項目名稱:Show_Chat,代碼行數:27,代碼來源:LoginActivity.java

示例6: authListener

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
public void authListener(final OnLoginFinishedListener listener){
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            user = firebaseAuth.getCurrentUser();
            if (user != null) {
               if(signInWithGoogle){
                  listener.onLoginGoogleSuccess();

                }
                else if(registerWithMail){
                    listener.onRegisterMailSuccess();
                }
                else {
                   listener.onLoginMailSuccess();
               }

            } else {
                // User is signed out
                // Log.d(TAG, "onAuthStateChanged:signed_out");
            }
        }
    };
}
 
開發者ID:jcolladosp,項目名稱:PimPam,代碼行數:26,代碼來源:LoginInteractorImpl.java

示例7: initializeFirebaseAuth

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
private void initializeFirebaseAuth() {
        // Initialize Firebase Auth
        mAuth = FirebaseAuth.getInstance();
        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");
//                    signOut();
                }
            }
        };
    }
 
開發者ID:cache117,項目名稱:social-journal,代碼行數:19,代碼來源:SettingsActivity.java

示例8: registerFirebase

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
protected void registerFirebase() {
    firebaseListener =
            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());
                        onLoginComplete();
                    } else {
                        // User is signed out
                        Log.d(TAG, "onAuthStateChanged:signed_out");
                    }
                }
            };
}
 
開發者ID:Pavou,項目名稱:Stalker,代碼行數:18,代碼來源:AuthenticateFragment.java

示例9: init

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
public void init() {
	TwitterAuthConfig authConfig = new TwitterAuthConfig(
	activity.getString(R.string.twitter_consumer_key),
	activity.getString(R.string.twitter_consumer_secret));

	Fabric.with(activity, new Twitter(authConfig));

	mAuth = FirebaseAuth.getInstance();

	twitterAuthClient = new TwitterAuthClient();
	mAuthListener = new FirebaseAuth.AuthStateListener() {
		@Override
		public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
			FirebaseUser user = firebaseAuth.getCurrentUser();

			if (user != null) {
				// User is signed in
				for (UserInfo usr : user.getProviderData()) {
					if (usr.getProviderId().equals("twitter.com")) {
						Utils.d("Twitter:AuthStateChanged:signed_in:"+
						user.getUid());

						successSignIn(user);
					}
				}

			} else {
				// User is signed out
				Utils.d("Twitter:onAuthStateChanged:signed_out");
				successSignOut();
			}

			// update firebase auth dets.
		}
	};

	onStart();
}
 
開發者ID:FrogSquare,項目名稱:GodotFireBase,代碼行數:39,代碼來源:TwitterSignIn.java

示例10: onCreate

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
/**
 * The activity launched
 * @param savedInstanceState - current app state
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    // init views
    mSignInButton = findViewById(R.id.sign_in_button);
    mSignInButton.setOnClickListener(this);
    mProgressBar = findViewById(R.id.sign_in_progress);
    mDatabase = DatabaseManager.getInstance();
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        /**
         * Handle a change in user's sign in status
         * @param firebaseAuth - the user's authentication
         */
        @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");
            }
        }
    };
    // Configure sign-in to request the user's ID, email address, and basic
    // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail()
            .requestIdToken(getString(R.string.default_web_client_id)).build();
    // Build a GoogleApiClient with access to the Google Sign-In API and the options specified by gso.
    mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
}
 
開發者ID:iskandergaba,項目名稱:Botanist,代碼行數:41,代碼來源:LoginActivity.java

示例11: onCreate

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_drawer);
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    //redirect if user is null i.e not logged in or registered
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if(firebaseAuth.getCurrentUser()==null){
                startActivity(new Intent(NavigationDrawerActivity.this, LoginPageActivity.class));
            }
        }
    };

    //set the initial fragment
    HomeFragment homeFragment = new HomeFragment();
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.fragment_container, homeFragment);
    fragmentTransaction.commit();

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    
    navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    View view = navigationView.getHeaderView(0);
    //set email in navigation drawer
    TextView navUserEmail = view.findViewById(R.id.nav_user_email);
    navUserEmail.setText(mAuth.getCurrentUser().getEmail());
    //set user name in navigation drawer
    TextView navUserName = view.findViewById(R.id.nav_user_name);
    navUserName.setText(mAuth.getCurrentUser().getDisplayName());
}
 
開發者ID:casualmill,項目名稱:IIITconnect,代碼行數:41,代碼來源:NavigationDrawerActivity.java

示例12: onCreate

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int mUIFlag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LOW_PROFILE
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

    getWindow().getDecorView().setSystemUiVisibility(mUIFlag);

    setContentView(R.layout.activity_login);
    ButterKnife.bind(this);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

    auth = FirebaseAuth.getInstance();
    authListener = 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");
            }
        }
    };

    moveClouds();
}
 
開發者ID:adithya321,項目名稱:Instincts-2k17,代碼行數:34,代碼來源:LoginActivity.java

示例13: onCreate

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_auth);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    mAuth = FirebaseAuth.getInstance();
    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());
                startActivity(new Intent(AuthActivity.this, HomeActivity.class));
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
        }
    };

    mGoogleSignIn = (SignInButton)findViewById(R.id.google_sign_in);
    TextView buttonText = (TextView) mGoogleSignIn.getChildAt(0);
    buttonText.setText(R.string.login_google);
    mGoogleSignIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            signIn();
        }
    });
    GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();
    mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
            .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
                    Toast.makeText(AuthActivity.this, "Coneccao Falhou",Toast.LENGTH_SHORT).show();
                }
            })
            .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
            .build();

    callbackManager = CallbackManager.Factory.create();

    loginButton = (LoginButton) findViewById(R.id.loginButton);
    loginButton.setReadPermissions(Arrays.asList("email"));
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
            Toast.makeText(getApplicationContext(), R.string.cancel_login, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(FacebookException error) {
            Toast.makeText(getApplicationContext(), R.string.error_login, Toast.LENGTH_SHORT).show();
        }
    });
}
 
開發者ID:braulio94,項目名稱:Quadro,代碼行數:67,代碼來源:AuthActivity.java

示例14: onCreate

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // LUKE - 12/9/17 - lock orientation to portrait mode
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        setContentView(R.layout.activity_login);

        // TODO: 10/31/17 JD update the ui function, modify layout to conform to material standards, welcome user already logged in

        // Login form
        mEmailField = (AutoCompleteTextView) findViewById(R.id.email);
        mPasswordField = (EditText) findViewById(R.id.password);

        //TODO 12/5/17 Remove prior to release
        //For Testing
        mEmailField.setText("[email protected]");
        mPasswordField.setText("123456");

        findViewById(R.id.email_sign_in_button).setOnClickListener(this);

        // TODO: 12/5/17 KB implement logout procedure
        findViewById(R.id.email_sign_out_button).setOnClickListener(this);

        mAuth = FirebaseAuth.getInstance();
        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());
                    // This should change the display to 'logout' or 'change role'
                } else {
                    // User is signed out
                    Log.d(TAG, "onAuthStateChanged:signed_out");
                    // Default view.
                    // Pull the buttons, click listeners, and other setup in here.
                }
                // TODO: 11/18/17 JD what's the purpose behind the listenere beyond logging?
            }
        };
        mAuth.addAuthStateListener(mAuthListener);
        mAnalyticsInstance = FirebaseAnalytics.getInstance(this);

//        mUserManager = new UserManager();
    }
 
開發者ID:panzerama,項目名稱:Dispatch,代碼行數:49,代碼來源:LoginActivity.java

示例15: onCreate

import com.google.firebase.auth.FirebaseAuth; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.google_auth_api_key))
            .requestEmail()
            .build();

    auth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener(){
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            final FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d("USER signed in", "onAuthStateChanged:signed_in:" + user.getUid());

                database = FirebaseDatabase.getInstance().getReference();
                database.child("users").child(user.getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        if(!dataSnapshot.exists()){
                            database.child("users").child(user.getUid())
                                    .setValue(new User(user.getDisplayName()));
                        }
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });
            } else {
                // User is signed out
                Log.d("USER signed out", "onAuthStateChanged:signed_out");
            }
        }
    };

    // Build a GoogleApiClient with access to the Google Sign-In API and the
    // options specified by gso.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_STANDARD);

    findViewById(R.id.sign_in_button).setOnClickListener(this);
}
 
開發者ID:mremondi,項目名稱:Hyke,代碼行數:54,代碼來源:LoginActivity.java


注:本文中的com.google.firebase.auth.FirebaseAuth.AuthStateListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。