com.facebook.SessionState Java Examples

The following examples show how to use com.facebook.SessionState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoginFragment.java    From KlyphMessenger with MIT License 6 votes vote down vote up
private void onSessionStateChange(Session session, SessionState state, Exception exception)
{
	if (getView() != null)
	{
		if (state.isOpened())
		{
			authButton.setVisibility(View.GONE);
			progressBar.setVisibility(View.VISIBLE);
		}
		else if (state.isClosed())
		{
			authButton.setVisibility(View.VISIBLE);
			progressBar.setVisibility(View.GONE);
		}
	}
}
 
Example #2
Source File: FriendPickerSampleActivity.java    From FacebookNewsfeedSample-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    resultsTextView = (TextView) findViewById(R.id.resultsTextView);
    pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton);
    pickFriendsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickFriends();
        }
    });

    lifecycleHelper = new UiLifecycleHelper(this, new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            onSessionStateChanged(session, state, exception);
        }
    });
    lifecycleHelper.onCreate(savedInstanceState);

    ensureOpenSession();
}
 
Example #3
Source File: MainActivity.java    From FacebookNewsfeedSample-Android with Apache License 2.0 6 votes vote down vote up
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (isResumed) {
        FragmentManager manager = getSupportFragmentManager();
        int backStackSize = manager.getBackStackEntryCount();
        for (int i = 0; i < backStackSize; i++) {
            manager.popBackStack();
        }
        // check for the OPENED state instead of session.isOpened() since for the
        // OPENED_TOKEN_UPDATED state, the selection fragment should already be showing.
        if (state.equals(SessionState.OPENED)) {
            showFragment(SELECTION, false);
        } else if (state.isClosed()) {
            showFragment(SPLASH, false);
        }
    }
}
 
Example #4
Source File: LoginFragment.java    From Klyph with MIT License 6 votes vote down vote up
private void onSessionStateChange(Session session, SessionState state, Exception exception)
{
	if (getView() != null)
	{
		if (state.isOpened())
		{
			authButton.setVisibility(View.GONE);
			progressBar.setVisibility(View.VISIBLE);
		}
		else if (state.isClosed())
		{
			authButton.setVisibility(View.VISIBLE);
			progressBar.setVisibility(View.GONE);
		}
	}
}
 
Example #5
Source File: FacebookContactMatcher.java    From buddycloud-android with Apache License 2.0 6 votes vote down vote up
protected void authFB(final Activity activity, 
		final ModelCallback<JSONArray> callback) {
	Session.openActiveSession(activity, true,
			new Session.StatusCallback() {
		@Override
		public void call(Session session, SessionState state,
				Exception exception) {
			if (exception != null) {
				callback.error(exception);
				return;
			}
			if (session.isOpened()) {
				getFriends(activity, session, callback);
			}
		}
	});
}
 
Example #6
Source File: LoginActivity.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void call(Session session, SessionState state, Exception exception) {
	if (session.isOpened()) {
		setFacebookSession(session);
		// make request to the /me API
		Request.newMeRequest(session, new Request.GraphUserCallback() {

			// callback after Graph API response with user object
			@Override
			public void onCompleted(GraphUser user, Response response) {
				if (user != null) {
					Toast.makeText(LoginActivity.this,
							"Hello " + user.getName(), Toast.LENGTH_LONG)
							.show();
				}
			}
		}).executeAsync();
	}
}
 
Example #7
Source File: FacebookFragment.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the current state of the session or null if no session has been created.
 * 
 * @return the current state of the session
 */
protected final SessionState getSessionState() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getState() : null;
    }
    return null;
}
 
Example #8
Source File: FriendPickerSampleActivity.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
private boolean ensureOpenSession() {
    if (Session.getActiveSession() == null ||
            !Session.getActiveSession().isOpened()) {
        Session.openActiveSession(this, true, new Session.StatusCallback() {
            @Override
            public void call(Session session, SessionState state, Exception exception) {
                onSessionStateChanged(session, state, exception);
            }
        });
        return false;
    }
    return true;
}
 
Example #9
Source File: LoginUsingLoginFragmentActivity.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.login_fragment_activity);

    FragmentManager fragmentManager = getSupportFragmentManager();
    userSettingsFragment = (UserSettingsFragment) fragmentManager.findFragmentById(R.id.login_fragment);
    userSettingsFragment.setSessionStatusCallback(new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            Log.d("LoginUsingLoginFragmentActivity", String.format("New session state: %s", state.toString()));
        }
    });
}
 
Example #10
Source File: FacebookFragment.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the current state of the session or null if no session has been created.
 * 
 * @return the current state of the session
 */
protected final SessionState getSessionState() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getState() : null;
    }
    return null;
}
 
Example #11
Source File: SessionTracker.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void call(Session session, SessionState state, Exception exception) {
    if (wrapped != null && isTracking()) {
        wrapped.call(session, state, exception);
    }
    // if we're not tracking the Active Session, and the current session
    // is closed, then start tracking the Active Session.
    if (session == SessionTracker.this.session && state.isClosed()) {
        setSession(null);
    }
}
 
Example #12
Source File: FacebookFragment.java    From HypFacebook with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Gets the current state of the session or null if no session has been created.
 * 
 * @return the current state of the session
 */
protected final SessionState getSessionState() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getState() : null;
    }
    return null;
}
 
Example #13
Source File: FacebookFragment.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the current state of the session or null if no session has been created.
 * 
 * @return the current state of the session
 */
protected final SessionState getSessionState() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getState() : null;
    }
    return null;
}
 
Example #14
Source File: LoginButton.java    From KlyphMessenger with MIT License 5 votes vote down vote up
@Override
public void call(Session session, SessionState state,
                 Exception exception) {
    fetchUserInfo();
    setButtonText();

    // if the client has a status callback registered, call it, otherwise
    // call the default handleError method, but don't call both
    if (properties.sessionStatusCallback != null) {
        properties.sessionStatusCallback.call(session, state, exception);
    } else if (exception != null) {
        handleError(exception);
    }
}
 
Example #15
Source File: SessionTracker.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
@Override
public void call(Session session, SessionState state, Exception exception) {
    if (wrapped != null && isTracking()) {
        wrapped.call(session, state, exception);
    }
    // if we're not tracking the Active Session, and the current session
    // is closed, then start tracking the Active Session.
    if (session == SessionTracker.this.session && state.isClosed()) {
        setSession(null);
    }
}
 
Example #16
Source File: TitledFragmentActivity.java    From KlyphMessenger with MIT License 5 votes vote down vote up
protected void onSessionStateChange(final Session session, SessionState state, Exception exception)
{
	if (session != null && session.isOpened())
	{
		if (state.equals(SessionState.OPENED_TOKEN_UPDATED))
		{
			tokenUpdated();
		}
	}
}
 
Example #17
Source File: PickerFragment.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    sessionTracker = new SessionTracker(getActivity(), new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (!session.isOpened()) {
                // When a session is closed, we want to clear out our data so it is not visible to subsequent users
                clearResults();
            }
        }
    });

    setSettingsFromBundle(savedInstanceState);

    loadingStrategy = createLoadingStrategy();
    loadingStrategy.attach(adapter);

    selectionStrategy = createSelectionStrategy();
    selectionStrategy.readSelectionFromBundle(savedInstanceState, SELECTION_BUNDLE_KEY);

    // Should we display a title bar? (We need to do this after we've retrieved our bundle settings.)
    if (showTitleBar) {
        inflateTitleBar((ViewGroup) getView());
    }

    if (activityCircle != null && savedInstanceState != null) {
        boolean shown = savedInstanceState.getBoolean(ACTIVITY_CIRCLE_SHOW_KEY, false);
        if (shown) {
            displayActivityCircle();
        } else {
            // Should be hidden already, but just to be sure.
            hideActivityCircle();
        }
    }
}
 
Example #18
Source File: SessionTracker.java    From HypFacebook with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void call(Session session, SessionState state, Exception exception) {
    if (wrapped != null && isTracking()) {
        wrapped.call(session, state, exception);
    }
    // if we're not tracking the Active Session, and the current session
    // is closed, then start tracking the Active Session.
    if (session == SessionTracker.this.session && state.isClosed()) {
        setSession(null);
    }
}
 
Example #19
Source File: FriendPickerSampleActivity.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
private void onSessionStateChanged(Session session, SessionState state, Exception exception) {
    if (pickFriendsWhenSessionOpened && state.isOpened()) {
        pickFriendsWhenSessionOpened = false;

        startPickFriendsActivity();
    }
}
 
Example #20
Source File: PlacePickerSampleActivity.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
private boolean ensureOpenSession() {
    if (Session.getActiveSession() == null ||
            !Session.getActiveSession().isOpened()) {
        Session.openActiveSession(this, true, new Session.StatusCallback() {
            @Override
            public void call(Session session, SessionState state, Exception exception) {
                onSessionStateChanged(session, state, exception);
            }
        });
        return false;
    }
    return true;
}
 
Example #21
Source File: MainActivity.java    From KlyphMessenger with MIT License 5 votes vote down vote up
@Override
protected void onSessionStateChange(Session session, SessionState state, Exception exception)
{
	Log.d("MainActivity", "onSessionStateChange");
	super.onSessionStateChange(session, state, exception);
	updateView();
}
 
Example #22
Source File: FacebookFragment.java    From KlyphMessenger with MIT License 5 votes vote down vote up
/**
 * Gets the current state of the session or null if no session has been created.
 * 
 * @return the current state of the session
 */
protected final SessionState getSessionState() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getState() : null;
    }
    return null;
}
 
Example #23
Source File: SessionTracker.java    From KlyphMessenger with MIT License 5 votes vote down vote up
@Override
public void call(Session session, SessionState state, Exception exception) {
    if (wrapped != null && isTracking()) {
        wrapped.call(session, state, exception);
    }
    // if we're not tracking the Active Session, and the current session
    // is closed, then start tracking the Active Session.
    if (session == SessionTracker.this.session && state.isClosed()) {
        setSession(null);
    }
}
 
Example #24
Source File: PickerFragment.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    sessionTracker = new SessionTracker(getActivity(), new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (!session.isOpened()) {
                // When a session is closed, we want to clear out our data so it is not visible to subsequent users
                clearResults();
            }
        }
    });

    setSettingsFromBundle(savedInstanceState);

    loadingStrategy = createLoadingStrategy();
    loadingStrategy.attach(adapter);

    selectionStrategy = createSelectionStrategy();
    selectionStrategy.readSelectionFromBundle(savedInstanceState, SELECTION_BUNDLE_KEY);

    // Should we display a title bar? (We need to do this after we've retrieved our bundle settings.)
    if (showTitleBar) {
        inflateTitleBar((ViewGroup) getView());
    }

    if (activityCircle != null && savedInstanceState != null) {
        boolean shown = savedInstanceState.getBoolean(ACTIVITY_CIRCLE_SHOW_KEY, false);
        if (shown) {
            displayActivityCircle();
        } else {
            // Should be hidden already, but just to be sure.
            hideActivityCircle();
        }
    }
}
 
Example #25
Source File: FacebookFragment.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the current state of the session or null if no session has been created.
 * 
 * @return the current state of the session
 */
protected final SessionState getSessionState() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getState() : null;
    }
    return null;
}
 
Example #26
Source File: SessionTracker.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void call(Session session, SessionState state, Exception exception) {
    if (wrapped != null && isTracking()) {
        wrapped.call(session, state, exception);
    }
    // if we're not tracking the Active Session, and the current session
    // is closed, then start tracking the Active Session.
    if (session == SessionTracker.this.session && state.isClosed()) {
        setSession(null);
    }
}
 
Example #27
Source File: SessionTracker.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void call(Session session, SessionState state, Exception exception) {
    if (wrapped != null && isTracking()) {
        wrapped.call(session, state, exception);
    }
    // if we're not tracking the Active Session, and the current session
    // is closed, then start tracking the Active Session.
    if (session == SessionTracker.this.session && state.isClosed()) {
        setSession(null);
    }
}
 
Example #28
Source File: FacebookFragment.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
/**
 * Gets the current state of the session or null if no session has been created.
 * 
 * @return the current state of the session
 */
protected final SessionState getSessionState() {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        return (currentSession != null) ? currentSession.getState() : null;
    }
    return null;
}
 
Example #29
Source File: SessionTracker.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@Override
public void call(Session session, SessionState state, Exception exception) {
    if (wrapped != null && isTracking()) {
        wrapped.call(session, state, exception);
    }
    // if we're not tracking the Active Session, and the current session
    // is closed, then start tracking the Active Session.
    if (session == SessionTracker.this.session && state.isClosed()) {
        setSession(null);
    }
}
 
Example #30
Source File: FacebookShareActivity.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
private void onSessionStateChange(Session session, SessionState state, Exception exception)
{
    if(exception != null)
    {
        // Handle exception here.
        Log.v("Facebook CALLBACK", "Facebook login error " + exception);
        return;
    }
    if (state != null && state.isOpened()) {

        if (session.isPermissionGranted(PERMISSION))
        {
            if (mPendingAction)
            {
                // Session ready to make requests.
                postImageToFacebook();
                mPendingAction = false;
            }
        }
        else
        {
            // Get the permissions if we don't have them.
            session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, PERMISSION));
        }
    }
    else if (state.isClosed())
    {
        // Session logged out.
        return;
    }
}