Java Code Examples for com.facebook.Session#isOpened()

The following examples show how to use com.facebook.Session#isOpened() . 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: FacebookFragment.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 6 votes vote down vote up
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
 
Example 2
Source File: FacebookFragment.java    From FacebookNewsfeedSample-Android with Apache License 2.0 6 votes vote down vote up
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
 
Example 3
Source File: FacebookFragment.java    From KlyphMessenger with MIT License 6 votes vote down vote up
private void openSession(String applicationId, List<String> permissions,
        SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
    if (sessionTracker != null) {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = new Session.OpenRequest(this).
                    setPermissions(permissions).
                    setLoginBehavior(behavior).
                    setRequestCode(activityCode);
            if (SessionAuthorizationType.PUBLISH.equals(authType)) {
                currentSession.openForPublish(openRequest);
            } else {
                currentSession.openForRead(openRequest);
            }
        }
    }
}
 
Example 4
Source File: LoginFragment.java    From Klyph with MIT License 5 votes vote down vote up
@Override
public void onResume()
{
	super.onResume();

	Session session = Session.getActiveSession();
	if (session != null && (session.isOpened() || session.isClosed()))
	{
		onSessionStateChange(session, session.getState(), null);
	}

	uiHelper.onResume();
}
 
Example 5
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 6
Source File: SessionTracker.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the current Session that's being tracked if it's open, 
 * otherwise returns null.
 * 
 * @return the current Session if it's open, otherwise returns null
 */
public Session getOpenSession() {
    Session openSession = getSession();
    if (openSession != null && openSession.isOpened()) {
        return openSession;
    }
    return null;
}
 
Example 7
Source File: HypFacebookFrag.java    From HypFacebook with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
*
*
* @public
* @return	void
*/
public void authorize( ){
	trace("authorize");
	Session session = Session.getActiveSession();
       if (!session.isOpened() && !session.isClosed() ) {
           session.openForRead( new Session.OpenRequest(this).setCallback( callback ) );
       } else {
           Session.openActiveSession( getActivity( ), this , true , callback );
       }

}
 
Example 8
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 9
Source File: MainActivity.java    From Klyph with MIT License 5 votes vote down vote up
@Override
public void onResume()
{
	Log.d("MainActivity", "onResume");
	super.onResume();

	Session session = Session.getActiveSession();
	if (session != null && (session.isOpened() || session.isClosed()))
	{
		onSessionStateChange(session, session.getState(), null);
		refreshUserPics();
	}
}
 
Example 10
Source File: LoginButton.java    From KlyphMessenger with MIT License 5 votes vote down vote up
private boolean validatePermissions(List<String> permissions,
        SessionAuthorizationType authType, Session currentSession) {
    if (SessionAuthorizationType.PUBLISH.equals(authType)) {
        if (Utility.isNullOrEmpty(permissions)) {
            throw new IllegalArgumentException("Permissions for publish actions cannot be null or empty.");
        }
    }
    if (currentSession != null && currentSession.isOpened()) {
        if (!Utility.isSubset(permissions, currentSession.getPermissions())) {
            Log.e(TAG, "Cannot set additional permissions when session is already open.");
            return false;
        }
    }
    return true;
}
 
Example 11
Source File: TitledFragmentActivity.java    From Klyph 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 12
Source File: FacebookShareActivity.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    // For scenarios where the main activity is launched and user
    // session is not null, the session state change notification
    // may not be triggered. Trigger it if it's open/closed.
    Session session = Session.getActiveSession();
    if (session != null && (session.isOpened() || session.isClosed())) {
        onSessionStateChange(session, session.getState(), null);
    }
    uiHelper.onResume();
}
 
Example 13
Source File: SessionTracker.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the current Session that's being tracked if it's open, 
 * otherwise returns null.
 * 
 * @return the current Session if it's open, otherwise returns null
 */
public Session getOpenSession() {
    Session openSession = getSession();
    if (openSession != null && openSession.isOpened()) {
        return openSession;
    }
    return null;
}
 
Example 14
Source File: SessionTracker.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the current Session that's being tracked if it's open, 
 * otherwise returns null.
 * 
 * @return the current Session if it's open, otherwise returns null
 */
public Session getOpenSession() {
    Session openSession = getSession();
    if (openSession != null && openSession.isOpened()) {
        return openSession;
    }
    return null;
}
 
Example 15
Source File: MainActivity.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResumeFragments() {
    super.onResumeFragments();
    Session session = Session.getActiveSession();

    if (session != null && session.isOpened()) {
        // if the session is already open, try to show the selection fragment
        showFragment(SELECTION, false);
    } else {
        // otherwise present the splash screen and ask the user to login.
        showFragment(SPLASH, false);
    }
}
 
Example 16
Source File: FacebookFragment.java    From giraff-android with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    // For scenarios where the main activity is launched and user
    // session is not null, the session state change notification
    // may not be triggered. Trigger it if it's open/closed.
    Session session = Session.getActiveSession();
    if (session != null &&
            (session.isOpened() || session.isClosed()) ) {
        onSessionStateChange(session, session.getState(), null);
    }
    uiHelper.onResume();
}
 
Example 17
Source File: SessionLoginFragment.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
private void onClickLogin() {
    Session session = Session.getActiveSession();
    if (!session.isOpened() && !session.isClosed()) {
        session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
    } else {
        Session.openActiveSession(getActivity(), this, true, statusCallback);
    }
}
 
Example 18
Source File: LoginButton.java    From Klyph with MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
    Context context = getContext();
    final Session openSession = sessionTracker.getOpenSession();

    if (openSession != null) {
        // If the Session is currently open, it must mean we need to log out
        if (confirmLogout) {
            // Create a confirmation dialog
            String logout = getResources().getString(R.string.com_facebook_loginview_log_out_action);
            String cancel = getResources().getString(R.string.com_facebook_loginview_cancel_action);
            String message;
            if (user != null && user.getName() != null) {
                message = String.format(getResources().getString(R.string.com_facebook_loginview_logged_in_as), user.getName());
            } else {
                message = getResources().getString(R.string.com_facebook_loginview_logged_in_using_facebook);
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setMessage(message)
                   .setCancelable(true)
                   .setPositiveButton(logout, new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int which) {
                           openSession.closeAndClearTokenInformation();
                       }
                   })
                   .setNegativeButton(cancel, null);
            builder.create().show();
        } else {
            openSession.closeAndClearTokenInformation();
        }
    } else {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            sessionTracker.setSession(null);
            Session session = new Session.Builder(context).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = null;
            if (parentFragment != null) {
                openRequest = new Session.OpenRequest(parentFragment);
            } else if (context instanceof Activity) {
                openRequest = new Session.OpenRequest((Activity)context);
            }

            if (openRequest != null) {
                openRequest.setDefaultAudience(properties.defaultAudience);
                openRequest.setPermissions(properties.permissions);
                openRequest.setLoginBehavior(properties.loginBehavior);

                if (SessionAuthorizationType.PUBLISH.equals(properties.authorizationType)) {
                    currentSession.openForPublish(openRequest);
                } else {
                    currentSession.openForRead(openRequest);
                }
            }
        }
    }

    AppEventsLogger logger = AppEventsLogger.newLogger(getContext());

    Bundle parameters = new Bundle();
    parameters.putInt("logging_in", (openSession != null) ? 0 : 1);

    logger.logSdkEvent(loginLogoutEventName, null, parameters);
}
 
Example 19
Source File: LoginFragment.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(final View v) {

    switch (v.getId()) {

        case R.id.button_facebook_login: {
            GoogleAnalyticsManager
                    .getInstance()
                    .sendEvent(new EventBuilder(Categories.CONVERSION, Actions.SIGN_IN_ATTEMPT)
                                       .set(ParamKeys.TYPE, ParamValues.FACEBOOK));
            final Session session = Session.getActiveSession();
            if (!session.isOpened() && !session.isClosed()) {
                session.openForRead(new Session.OpenRequest(this)
                                            .setPermissions(Arrays
                                                                    .asList(AppConstants
                                                                                    .FBPERMISSIONS))
                                            .setCallback(this));
            } else {
                Session.openActiveSession(getActivity(), this, true, this);
            }
            break;
        }

        case R.id.button_google_login: {
            GoogleAnalyticsManager
                    .getInstance()
                    .sendEvent(new EventBuilder(Categories.CONVERSION, Actions.SIGN_IN_ATTEMPT)
                                       .set(ParamKeys.TYPE, ParamValues.GOOGLE));
            ((AuthActivity) getActivity()).getPlusManager().login();
            break;
        }

        case R.id.button_submit: {
            if (isInputValid()) {
                GoogleAnalyticsManager
                        .getInstance()
                        .sendEvent(
                                new EventBuilder(Categories.CONVERSION, Actions.SIGN_IN_ATTEMPT)
                                        .set(ParamKeys.TYPE, ParamValues.EMAIL)
                        );
                login(mEmailEditText.getText().toString(), mPasswordEditText
                        .getText().toString());
            }
            break;
        }

        case R.id.forgot_password: {
            showForgotPasswordDialog();

        }
    }
}
 
Example 20
Source File: FragmentSocialTimeline.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    Logger.d("FragmentSocialTimeline", " onCreate");
    super.onCreate(savedInstanceState);
    if (savedInstanceState == null) {
        init();
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {

        fbhelper = new UiLifecycleHelper(getActivity(), new Session.StatusCallback() {
            @Override
            public void call(final Session session, SessionState state, Exception exception) {
                if (!AptoideUtils.AccountUtils.isLoggedIn(Aptoide.getContext()) || removeAccount) {
                    try {
                        final AccountManager mAccountManager = AccountManager.get(getActivity());

                        if (session.isOpened()) {
                            Request.newMeRequest(session, new Request.GraphUserCallback() {
                                @Override
                                public void onCompleted(final GraphUser user, Response response) {

                                    if (removeAccount && mAccountManager.getAccountsByType(Aptoide.getConfiguration().getAccountType()).length > 0) {
                                        mAccountManager.removeAccount(mAccountManager.getAccountsByType(Aptoide.getConfiguration().getAccountType())[0], new AccountManagerCallback<Boolean>() {
                                            @Override
                                            public void run(AccountManagerFuture<Boolean> future) {
                                                startLogin(user, session);
                                            }
                                        }, new Handler(Looper.getMainLooper()));
                                    } else {

                                        startLogin(user, session);
                                    }
                                }
                            }).executeAsync();

                        }
                    } catch (Exception e) {
                        Toast.makeText(Aptoide.getContext(), R.string.error_occured, Toast.LENGTH_LONG).show();
                        loginError();
                    }
                }
            }
        });

        fbhelper.onCreate(savedInstanceState);
    }
}