Search in sources :

Example 1 with Profile

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));
    }
}
Also used : Profile(com.facebook.Profile)

Example 2 with Profile

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();
            }
        }
    };
}
Also used : LoginManager(com.facebook.login.LoginManager) ProfileTracker(com.facebook.ProfileTracker) FacebookException(com.facebook.FacebookException) AccessToken(com.facebook.AccessToken) LoginResult(com.facebook.login.LoginResult) Profile(com.facebook.Profile)

Example 3 with Profile

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();
        }
    };
}
Also used : GraphRequest(com.facebook.GraphRequest) Bundle(android.os.Bundle) LoginResult(com.facebook.login.LoginResult) JSONException(org.json.JSONException) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) ProfilePictureView(com.facebook.login.widget.ProfilePictureView) Profile(com.facebook.Profile) FacebookCallback(com.facebook.FacebookCallback) ProfileTracker(com.facebook.ProfileTracker) Button(android.widget.Button) LoginButton(com.facebook.login.widget.LoginButton) GraphResponse(com.facebook.GraphResponse) FacebookException(com.facebook.FacebookException)

Example 4 with Profile

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());
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) ProfileTracker(com.facebook.ProfileTracker) AccessToken(com.facebook.AccessToken) Profile(com.facebook.Profile)

Aggregations

Profile (com.facebook.Profile)4 ProfileTracker (com.facebook.ProfileTracker)3 AccessToken (com.facebook.AccessToken)2 FacebookException (com.facebook.FacebookException)2 LoginResult (com.facebook.login.LoginResult)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 View (android.view.View)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 AccessTokenTracker (com.facebook.AccessTokenTracker)1 FacebookCallback (com.facebook.FacebookCallback)1 GraphRequest (com.facebook.GraphRequest)1 GraphResponse (com.facebook.GraphResponse)1 LoginManager (com.facebook.login.LoginManager)1 LoginButton (com.facebook.login.widget.LoginButton)1 ProfilePictureView (com.facebook.login.widget.ProfilePictureView)1 JSONException (org.json.JSONException)1