本文整理匯總了Java中com.firebase.client.Firebase.AuthStateListener方法的典型用法代碼示例。如果您正苦於以下問題:Java Firebase.AuthStateListener方法的具體用法?Java Firebase.AuthStateListener怎麽用?Java Firebase.AuthStateListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.firebase.client.Firebase
的用法示例。
在下文中一共展示了Firebase.AuthStateListener方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: settingFirebase
import com.firebase.client.Firebase; //導入方法依賴的package包/類
/**
* ***************************************************************************
*/
private Firebase settingFirebase(String urlFirebase, String child) {
Firebase firebase = new Firebase(urlFirebase).child(child);
firebase.authWithPassword(mUsernameMail, mUsernamePwd, new AuthResultHandler("password"));
mAuthStateListener = new Firebase.AuthStateListener() {
@Override
public void onAuthStateChanged(AuthData authData) {
setAuthenticatedUser(authData);
}
};
firebase.addAuthStateListener(mAuthStateListener);
firebase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
return firebase;
}
示例2: onCreate
import com.firebase.client.Firebase; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.PLUS_LOGIN))
.requestScopes(new Scope(Scopes.PLUS_ME))
.requestScopes(new Scope("https://picasaweb.google.com/data/"))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleLoginButton.setSize(SignInButton.SIZE_WIDE);
mFirebaseRef = new Firebase(Constants.FIREBASE_URL);
mAuthProgressDialog = new ProgressDialog(this);
mAuthProgressDialog.setTitle(getString(R.string.login_activity_progress_dialog_title));
mAuthProgressDialog.setMessage(getString(R.string.login_activity_progress_dialog_message));
mAuthProgressDialog.setCancelable(false);
mAuthProgressDialog.show();
mAuthStateListener = new Firebase.AuthStateListener() {
@Override
public void onAuthStateChanged(AuthData authData) {
mAuthProgressDialog.dismiss();
/**
* If there is a valid session to be restored, start MainActivity.
* No need to pass data via SharedPreferences because app
* already holds userName/provider data from the latest session
*/
if (authData != null) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
}
};
}