Skip to content

Instantly share code, notes, and snippets.

@siisee11
Last active May 24, 2020 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siisee11/f0693f4cc484710380388d7ab6e00d67 to your computer and use it in GitHub Desktop.
Save siisee11/f0693f4cc484710380388d7ab6e00d67 to your computer and use it in GitHub Desktop.
public class ProfileActivity extends AppCompatActivity implements View.OnClickListener{
public static final String GOOGLE_ACCOUNT = "google_account";
private TextView profileName, profileEmail;
private ImageView profileImage;
private GoogleSignInAccount mGoogleSignInAccount;
private GoogleSignInClient mGoogleSignInClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
profileName = findViewById(R.id.profile_text);
profileEmail = findViewById(R.id.profile_email);
profileImage = findViewById(R.id.profile_image);
findViewById(R.id.sign_out).setOnClickListener(this);
mGoogleSignInAccount = getIntent().getParcelableExtra(GOOGLE_ACCOUNT);
setDataOnView();
}
private void setDataOnView() {
// implementation 'com.squareup.picasso:picasso:2.71828'
Picasso.get().load(mGoogleSignInAccount.getPhotoUrl()).centerInside().fit().into(profileImage);
profileName.setText(mGoogleSignInAccount.getDisplayName());
profileEmail.setText(mGoogleSignInAccount.getEmail());
}
@Override
public void onClick(View v) {
switch (v.getId()) {
// ...
case R.id.sign_out:
signOut();
break;
// ...
}
}
private void signOut() {
mGoogleSignInClient.signOut().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
//On Succesfull signout we navigate the user back to LoginActivity
Intent intent=new Intent(ProfileActivity.this,LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment