use of com.google.firebase.auth.FirebaseAuth 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);
}
};
}
use of com.google.firebase.auth.FirebaseAuth 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();
}
}
use of com.google.firebase.auth.FirebaseAuth 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) {
}
});
}
use of com.google.firebase.auth.FirebaseAuth in project MadMax by deviz92.
the class MainActivity method onStart.
@Override
protected void onStart() {
super.onStart();
Log.i(TAG, "onStart");
startingIntent = getIntent();
currentFragment = startingIntent.getIntExtra("currentFragment", 1);
// start declaration of a listener on all the current user data -> attached in onStart()
currentUserListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d(TAG, "onDataChange currentUserref");
if (currentUser == null) {
// makeText(MainActivity.this, "Ricreato user", Toast.LENGTH_SHORT).show(); // todo: di debug, da rimuovere
currentUser = new User();
}
currentUser.setID(currentUID);
currentUser.setName(dataSnapshot.child("name").getValue(String.class));
currentUser.setSurname(dataSnapshot.child("surname").getValue(String.class));
currentUser.setUsername(dataSnapshot.child("username").getValue(String.class));
currentUser.setProfileImage(dataSnapshot.child("image").getValue(String.class));
currentUser.setEmail(dataSnapshot.child("email").getValue(String.class));
currentUser.setPassword(dataSnapshot.child("password").getValue(String.class));
Log.d(TAG, "taken basic data of currentUser " + currentUser.toString());
// get user friends's IDs
if (dataSnapshot.child("friends").hasChildren())
for (DataSnapshot friend : dataSnapshot.child("friends").getChildren()) {
if (!friend.hasChild("deleted") || !friend.child("deleted").getValue(Boolean.class))
currentUser.getUserFriends().put(friend.getKey(), null);
}
// get user groups's IDs
if (dataSnapshot.child("groups").hasChildren())
for (DataSnapshot group : dataSnapshot.child("groups").getChildren()) {
if (group.getValue(Boolean.class))
currentUser.getUserGroups().put(group.getKey(), null);
}
Log.d(TAG, "Taken friends and groups, now creating the adapter");
if (currentFragment != null) {
viewPager.setCurrentItem(currentFragment);
updateFab(currentFragment);
} else {
viewPager.setCurrentItem(1);
updateFab(1);
}
// load nav menu header data for the current user
loadNavHeader();
Log.d(TAG, "logged user name: " + currentUser.getName());
Log.d(TAG, "logged user surname: " + currentUser.getSurname());
Uri data = startingIntent.getData();
if (data != null) {
inviterID = data.getQueryParameter("inviterID");
groupToBeAddedID = data.getQueryParameter("groupToBeAddedID");
} else {
// retrieving data from the intent inviterID & groupToBeAddedID as the group ID where to add the current user
if (startingIntent.hasExtra("inviterID")) {
// to be used to set the current user as friend of the inviter
Log.d(TAG, "there is an invite");
inviterID = startingIntent.getStringExtra("inviterID");
startingIntent.removeExtra("inviterID");
}
if (startingIntent.hasExtra("groupToBeAddedID")) {
groupToBeAddedID = startingIntent.getStringExtra("groupToBeAddedID");
startingIntent.removeExtra("groupToBeAddedID");
}
}
// control if user that requires the friendship is already a friend
if (inviterID != null) {
if (!currentUser.getUserFriends().containsKey(inviterID)) {
FirebaseUtils.getInstance().addFriend(inviterID);
inviterID = null;
makeText(MainActivity.this, getString(R.string.new_friend), Toast.LENGTH_LONG).show();
}
/*else
makeText(MainActivity.this, getString(R.string.already_friends), Toast.LENGTH_LONG).show();*/
}
// control if user is already part of requested group
if (groupToBeAddedID != null) {
if (!currentUser.getUserGroups().containsKey(groupToBeAddedID)) {
// currentUser.joinGroup(groupToBeAddedID); //todo usare questa? non aggiorna il numero dei membri
currentUser.getUserGroups().put(groupToBeAddedID, null);
FirebaseUtils.getInstance().joinGroupFirebase(currentUID, groupToBeAddedID);
groupToBeAddedID = null;
makeText(MainActivity.this, getString(R.string.join_group), Toast.LENGTH_LONG).show();
}
// else
// makeText(MainActivity.this, getString(R.string.already_in_group) + "\""+currentUser.getUserGroups().get(groupToBeAddedID).getName()+"\"", Toast.LENGTH_LONG).show();
}
if (startingIntent.hasExtra("notificationTitle")) {
Intent notificationIntent = null;
switch(startingIntent.getStringExtra("notificationTitle")) {
case "notification_invite":
if (startingIntent.hasExtra("groupID")) {
notificationIntent = new Intent(getApplicationContext(), GroupDetailActivity.class);
notificationIntent.putExtra("groupID", startingIntent.getStringExtra("groupID"));
}
break;
case "notification_expense_added":
if (startingIntent.hasExtra("groupID")) {
notificationIntent = new Intent(getApplicationContext(), ExpenseDetailActivity.class);
notificationIntent.putExtra("groupID", startingIntent.getStringExtra("groupID"));
if (startingIntent.hasExtra("expenseID")) {
notificationIntent.putExtra("expenseID", startingIntent.getStringExtra("expenseID"));
}
}
break;
case "notification_expense_removed":
if (startingIntent.hasExtra("groupID")) {
notificationIntent = new Intent(getApplicationContext(), GroupDetailActivity.class);
notificationIntent.putExtra("groupID", startingIntent.getStringExtra("groupID"));
}
break;
case "notification_proposalExpense_added":
if (startingIntent.hasExtra("expenseID")) {
notificationIntent = new Intent(getApplicationContext(), PendingExpenseDetailActivity.class);
notificationIntent.putExtra("expenseID", startingIntent.getStringExtra("expenseID"));
}
break;
}
if (notificationIntent != null) {
notificationIntent.putExtra("userID", currentUID);
startingIntent.removeExtra("notificationTitle");
startActivityForResult(notificationIntent, REQUEST_NOTIFICATION);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
// TODO: come gestire?
Log.d(TAG, "getting current user failed");
}
};
// end of listener declaration on all the current user data
authListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
Log.d(TAG, "onAuthStateChanged");
currentFirebaseUser = firebaseAuth.getCurrentUser();
if (currentFirebaseUser != null && currentFirebaseUser.isEmailVerified()) {
// getting reference to the user from db
currentUID = currentFirebaseUser.getUid();
currentUserRef = usersRef.child(currentUID);
// take refreshed toked and save it to use FCM
currentUserRef.child("token").setValue(FirebaseInstanceId.getInstance().getToken());
Log.d(TAG, "device token: " + FirebaseInstanceId.getInstance().getToken());
// attach a listener on all the current user data
currentUserRef.addValueEventListener(currentUserListener);
} else {
Log.d(TAG, "current user is null, so go to login activity");
Intent goToLogin = new Intent(getApplicationContext(), LoginSignUpActivity.class);
// currentUser = null;
startActivity(goToLogin);
auth.removeAuthStateListener(authListener);
finish();
}
}
};
// attach the listener to the FirebaseAuth instance
auth.addAuthStateListener(authListener);
}
use of com.google.firebase.auth.FirebaseAuth in project FirebaseUI-Android by firebase.
the class AuthUiActivity method getSignInIntent.
private Intent getSignInIntent(@Nullable String link) {
AuthUI.SignInIntentBuilder builder = getAuthUI().createSignInIntentBuilder().setTheme(getSelectedTheme()).setLogo(getSelectedLogo()).setAvailableProviders(getSelectedProviders()).setIsSmartLockEnabled(mBinding.credentialSelectorEnabled.isChecked(), mBinding.hintSelectorEnabled.isChecked());
if (mBinding.customLayout.isChecked()) {
AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout.Builder(R.layout.auth_method_picker_custom_layout).setGoogleButtonId(R.id.custom_google_signin_button).setEmailButtonId(R.id.custom_email_signin_clickable_text).setTosAndPrivacyPolicyId(R.id.custom_tos_pp).build();
builder.setTheme(R.style.CustomTheme);
builder.setAuthMethodPickerLayout(customLayout);
}
if (getSelectedTosUrl() != null && getSelectedPrivacyPolicyUrl() != null) {
builder.setTosAndPrivacyPolicyUrls(getSelectedTosUrl(), getSelectedPrivacyPolicyUrl());
}
if (link != null) {
builder.setEmailLink(link);
}
FirebaseAuth auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null && auth.getCurrentUser().isAnonymous()) {
builder.enableAnonymousUsersAutoUpgrade();
}
return builder.build();
}
Aggregations