当前位置: 首页>>代码示例>>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;未经允许,请勿转载。