use of com.google.firebase.auth.FirebaseUser in project RSAndroidApp by RailwayStations.
the class SignInActivity method handleFirebaseAuthResult.
private void handleFirebaseAuthResult(AuthResult authResult) {
if (authResult != null) {
// Welcome the user
FirebaseUser user = authResult.getUser();
Toast.makeText(this, "Welcome " + user.getEmail(), Toast.LENGTH_SHORT).show();
// Go back to the main activity
startActivity(new Intent(this, AuthActivity.class));
}
}
use of com.google.firebase.auth.FirebaseUser in project priend by TakoJ.
the class ProfileActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
firebaseAuth = FirebaseAuth.getInstance();
FirebaseUser user = firebaseAuth.getCurrentUser();
mStorageRef = FirebaseStorage.getInstance().getReference();
SharedPreferences sharedPreferences = getSharedPreferences("email", Context.MODE_PRIVATE);
//유저 uid받기
userUid = sharedPreferences.getString("uid", user.getUid());
//유저 email(아이디)받기
userEmail = sharedPreferences.getString("email", user.getEmail());
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();
if (firebaseAuth.getCurrentUser() == null) {
finish();
startActivity(new Intent(this, LoginActivity.class));
}
// 이 activity가 켜졌을 때 권한설정 물어보기
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, 1);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
// butterknife: view binder , list adapter 할때도 간편한 코드 구현가능
petImage = (ImageView) findViewById(R.id.petImage);
btn_UploadPicture = (Button) findViewById(R.id.btn_UploadPicture);
textViewUserEmail = (TextView) findViewById(R.id.textViewUserEmail);
textViewUserEmail.setText(user.getEmail() + "님의 반려동물");
buttonLogout = (Button) findViewById(R.id.buttonLogout);
buttonLogout.setOnClickListener(this);
petImage = (ImageView) findViewById(R.id.petImage);
btn_UploadPicture = (Button) findViewById(R.id.btn_UploadPicture);
petName = (EditText) findViewById(R.id.petName);
petAge = (EditText) findViewById(R.id.petAge);
radiogroup_gender = (RadioGroup) findViewById(R.id.radiogroup_gender);
radioGender_male = (RadioButton) findViewById(R.id.radioGender_male);
radioGender_female = (RadioButton) findViewById(R.id.radioGender_female);
radiogroup_type = (RadioGroup) findViewById(R.id.radiogroup_type);
radio_dog = (RadioButton) findViewById(R.id.radio_dog);
radio_cat = (RadioButton) findViewById(R.id.radio_cat);
radiogroup_size = (RadioGroup) findViewById(R.id.radiogroup_size);
radioSize_small = (RadioButton) findViewById(R.id.radioSize_small);
radioSize_middle = (RadioButton) findViewById(R.id.radioSize_middle);
radioSize_large = (RadioButton) findViewById(R.id.radioSize_large);
btn_profilefinish = (Button) findViewById(R.id.btn_profilefinish);
btn_UploadPicture.setOnClickListener(this);
btn_profilefinish.setOnClickListener(this);
loadSavedPreferences();
//원래 사진받아오는 자리
new DownloadImage().execute();
}
use of com.google.firebase.auth.FirebaseUser in project quickstart-android by firebase.
the class FacebookLoginActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_facebook);
// Views
mStatusTextView = (TextView) findViewById(R.id.status);
mDetailTextView = (TextView) findViewById(R.id.detail);
findViewById(R.id.button_facebook_signout).setOnClickListener(this);
// [START initialize_auth]
// Initialize Firebase 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]
// [START initialize_fblogin]
// Initialize Facebook Login button
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.button_facebook_login);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "facebook:onSuccess:" + loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Log.d(TAG, "facebook:onCancel");
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
@Override
public void onError(FacebookException error) {
Log.d(TAG, "facebook:onError", error);
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
});
// [END initialize_fblogin]
}
use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class RegisterEmailFragment method registerUser.
private void registerUser(final String email, final String name, final String password) {
mHelper.getFirebaseAuth().createUserWithEmailAndPassword(email, password).addOnFailureListener(new TaskFailureLogger(TAG, "Error creating user")).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
// Set display name
UserProfileChangeRequest changeNameRequest = new UserProfileChangeRequest.Builder().setDisplayName(name).setPhotoUri(mUser.getPhotoUri()).build();
final FirebaseUser user = authResult.getUser();
user.updateProfile(changeNameRequest).addOnFailureListener(new TaskFailureLogger(TAG, "Error setting display name")).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// This executes even if the name change fails, since
// the account creation succeeded and we want to save
// the credential to SmartLock (if enabled).
mHelper.saveCredentialsOrFinish(mSaveSmartLock, getActivity(), user, password, new IdpResponse(EmailAuthProvider.PROVIDER_ID, email));
}
});
}
}).addOnFailureListener(getActivity(), new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mHelper.dismissDialog();
if (e instanceof FirebaseAuthWeakPasswordException) {
// Password too weak
mPasswordInput.setError(getResources().getQuantityString(R.plurals.error_weak_password, R.integer.min_password_length));
} else if (e instanceof FirebaseAuthInvalidCredentialsException) {
// Email address is malformed
mEmailInput.setError(getString(R.string.invalid_email_address));
} else if (e instanceof FirebaseAuthUserCollisionException) {
// Collision with existing user email, it should be very hard for
// the user to even get to this error due to CheckEmailFragment.
mEmailInput.setError(getString(R.string.error_user_collision));
} else {
// General error message, this branch should not be invoked but
// covers future API changes
mEmailInput.setError(getString(R.string.email_account_creation_error));
}
}
});
}
use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class WelcomeBackPasswordPromptTest method testSignInButton_signsInAndSavesCredentials.
@Test
@Config(shadows = { BaseHelperShadow.class, ActivityHelperShadow.class })
public void testSignInButton_signsInAndSavesCredentials() {
// initialize mocks
new ActivityHelperShadow();
reset(ActivityHelperShadow.sSaveSmartLock);
WelcomeBackPasswordPrompt welcomeBackActivity = createActivity();
EditText passwordField = (EditText) welcomeBackActivity.findViewById(R.id.password);
passwordField.setText(TestConstants.PASSWORD);
FirebaseUser mockFirebaseUser = mock(FirebaseUser.class);
when(ActivityHelperShadow.sFirebaseAuth.signInWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD)).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
when(mockFirebaseUser.getDisplayName()).thenReturn(TestConstants.NAME);
when(mockFirebaseUser.getEmail()).thenReturn(TestConstants.EMAIL);
when(mockFirebaseUser.getPhotoUrl()).thenReturn(TestConstants.PHOTO_URI);
Button signIn = (Button) welcomeBackActivity.findViewById(R.id.button_done);
signIn.performClick();
verify(ActivityHelperShadow.sFirebaseAuth).signInWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD);
verifySmartLockSave(EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL, TestConstants.PASSWORD);
}
Aggregations