use of com.facebook.Profile in project facebook-android-sdk by facebook.
the class FacebookLoginActivity method updateUI.
private void updateUI() {
Profile profile = Profile.getCurrentProfile();
if (profile != null) {
profilePictureView.setProfileId(profile.getId());
userNameView.setText(String.format("%s %s", profile.getFirstName(), profile.getLastName()));
} else {
profilePictureView.setProfileId(null);
userNameView.setText(getString(R.string.welcome));
}
}
use of com.facebook.Profile in project facebook-android-sdk by facebook.
the class SettingsFragment method setUpCallbacks.
private void setUpCallbacks() {
callbackManager = CallbackManager.Factory.create();
LoginManager manager = LoginManager.getInstance();
manager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Profile.fetchProfileForCurrentAccessToken();
}
@Override
public void onError(FacebookException exception) {
AccessToken.setCurrentAccessToken(null);
currentUserChanged();
}
@Override
public void onCancel() {
AccessToken.setCurrentAccessToken(null);
currentUserChanged();
}
});
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
Slot currentSlot = slotManager.getSelectedSlot();
AccessToken currentAccessToken = AccessToken.getCurrentAccessToken();
if (currentSlot != null && currentAccessToken != null && currentProfile != null) {
currentSlot.setUserInfo(new UserInfo(currentProfile.getName(), currentAccessToken));
currentUserChanged();
}
}
};
}
use of com.facebook.Profile in project facebook-android-sdk by facebook.
the class FacebookLoginActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facebook_login);
callbackManager = CallbackManager.Factory.create();
fbLoginButton = (LoginButton) findViewById(R.id._fb_login);
profilePictureView = (ProfilePictureView) findViewById(R.id.user_pic);
profilePictureView.setCropped(true);
userNameView = (TextView) findViewById(R.id.user_name);
final Button deAuthButton = (Button) findViewById(R.id.deauth);
deAuthButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!isLoggedIn()) {
Toast.makeText(FacebookLoginActivity.this, R.string.app_not_logged_in, Toast.LENGTH_LONG).show();
return;
}
GraphRequest.Callback callback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
try {
if (response.getError() != null) {
Toast.makeText(FacebookLoginActivity.this, getResources().getString(R.string.failed_to_deauth, response.toString()), Toast.LENGTH_LONG).show();
} else if (response.getJSONObject().getBoolean(SUCCESS)) {
LoginManager.getInstance().logOut();
// updateUI();?
}
} catch (JSONException ex) {
/* no op */
}
}
};
GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), GRAPH_PATH, new Bundle(), HttpMethod.DELETE, callback);
request.executeAsync();
}
});
final Button permsButton = (Button) findViewById(R.id.perms);
permsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(final View v) {
Intent selectPermsIntent = new Intent(FacebookLoginActivity.this, PermissionSelectActivity.class);
startActivityForResult(selectPermsIntent, PICK_PERMS_REQUEST);
}
});
// Callback registration
fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(final LoginResult loginResult) {
// App code
Toast.makeText(FacebookLoginActivity.this, R.string.success, Toast.LENGTH_LONG).show();
updateUI();
}
@Override
public void onCancel() {
// App code
Toast.makeText(FacebookLoginActivity.this, R.string.cancel, Toast.LENGTH_LONG).show();
}
@Override
public void onError(final FacebookException exception) {
// App code
Toast.makeText(FacebookLoginActivity.this, R.string.error, Toast.LENGTH_LONG).show();
}
});
new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(final Profile oldProfile, final Profile currentProfile) {
updateUI();
}
};
}
use of com.facebook.Profile in project facebook-android-sdk by facebook.
the class ProfileFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
callbackManager = CallbackManager.Factory.create();
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
setProfile(currentProfile);
}
};
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
// On AccessToken changes fetch the new profile which fires the event on
// the ProfileTracker if the profile is different
Profile.fetchProfileForCurrentAccessToken();
}
};
// Ensure that our profile is up to date
Profile.fetchProfileForCurrentAccessToken();
setProfile(Profile.getCurrentProfile());
}
Aggregations