com.facebook.widget
Class UserSettingsFragment

java.lang.Object
  extended by android.support.v4.app.Fragment
      extended by com.facebook.widget.UserSettingsFragment
All Implemented Interfaces:
ComponentCallbacks, View.OnCreateContextMenuListener

public class UserSettingsFragment
extends Fragment

A Fragment that displays a Login/Logout button as well as the user's profile picture and name when logged in.

This Fragment will create and use the active session upon construction if it has the available data (if the app ID is specified in the manifest). It will also open the active session if it does not require user interaction (i.e. if the session is in the SessionState.CREATED_TOKEN_LOADED state. Developers can override the use of the active session by calling the setSession(com.facebook.Session) method.


Nested Class Summary
 
Nested classes/interfaces inherited from class android.support.v4.app.Fragment
Fragment.InstantiationException, Fragment.SavedState
 
Constructor Summary
UserSettingsFragment()
           
 
Method Summary
 void clearPermissions()
          Clears the permissions currently associated with this LoginButton.
protected  void closeSession()
          Closes the current session.
protected  void closeSessionAndClearTokenInformation()
          Closes the current session as well as clearing the token cache.
protected  String getAccessToken()
          Gets the access token associated with the current session or null if no session has been created.
 SessionDefaultAudience getDefaultAudience()
          Gets the default audience to use when the session is opened.
protected  Date getExpirationDate()
          Gets the date at which the current session will expire or null if no session has been created.
 SessionLoginBehavior getLoginBehavior()
          Gets the login behavior for the session that will be opened.
 LoginButton.OnErrorListener getOnErrorListener()
          Returns the current OnErrorListener for this instance of UserSettingsFragment.
protected  Session getSession()
          Gets the current Session.
protected  List<String> getSessionPermissions()
          Gets the permissions associated with the current session or null if no session has been created.
protected  SessionState getSessionState()
          Gets the current state of the session or null if no session has been created.
 Session.StatusCallback getSessionStatusCallback()
          Sets the callback interface that will be called whenever the status of the Session associated with this LoginButton changes.
protected  boolean isSessionOpen()
          Determines whether the current session is open.
 void onActivityCreated(Bundle savedInstanceState)
           
 void onActivityResult(int requestCode, int resultCode, Intent data)
          Called when the activity that was launched exits.
 void onCreate(Bundle savedInstanceState)
           
 View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
           
 void onDestroy()
           
 void onResume()
           
protected  void onSessionStateChange(SessionState state, Exception exception)
          Called when the session state changes.
protected  void openSession()
          Opens a new session.
protected  void openSessionForPublish(String applicationId, List<String> permissions)
          Opens a new session with publish permissions.
protected  void openSessionForPublish(String applicationId, List<String> permissions, SessionLoginBehavior behavior, int activityCode)
          Opens a new session with publish permissions.
protected  void openSessionForRead(String applicationId, List<String> permissions)
          Opens a new session with read permissions.
protected  void openSessionForRead(String applicationId, List<String> permissions, SessionLoginBehavior behavior, int activityCode)
          Opens a new session with read permissions.
 void setDefaultAudience(SessionDefaultAudience defaultAudience)
          Sets the default audience to use when the session is opened.
 void setLoginBehavior(SessionLoginBehavior loginBehavior)
          Sets the login behavior for the session that will be opened.
 void setOnErrorListener(LoginButton.OnErrorListener onErrorListener)
          Sets an OnErrorListener for this instance of UserSettingsFragment to call into when certain exceptions occur.
 void setPublishPermissions(List<String> permissions)
          Set the permissions to use when the session is opened.
 void setReadPermissions(List<String> permissions)
          Set the permissions to use when the session is opened.
 void setSession(Session newSession)
          Set the Session object to use instead of the active Session.
 void setSessionStatusCallback(Session.StatusCallback callback)
          Sets the callback interface that will be called whenever the status of the Session associated with this LoginButton changes.
 
Methods inherited from class android.support.v4.app.Fragment
dump, equals, getActivity, getArguments, getChildFragmentManager, getFragmentManager, getId, getLayoutInflater, getLoaderManager, getParentFragment, getResources, getRetainInstance, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, hashCode, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isRemoving, isResumed, isVisible, onAttach, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateContextMenu, onCreateOptionsMenu, onDestroyOptionsMenu, onDestroyView, onDetach, onHiddenChanged, onInflate, onLowMemory, onOptionsItemSelected, onOptionsMenuClosed, onPause, onPrepareOptionsMenu, onSaveInstanceState, onStart, onStop, onViewCreated, onViewStateRestored, registerForContextMenu, setArguments, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setRetainInstance, setTargetFragment, setUserVisibleHint, startActivity, startActivityForResult, toString, unregisterForContextMenu
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UserSettingsFragment

public UserSettingsFragment()
Method Detail

onCreateView

public View onCreateView(LayoutInflater inflater,
                         ViewGroup container,
                         Bundle savedInstanceState)
Overrides:
onCreateView in class Fragment

onCreate

public void onCreate(Bundle savedInstanceState)
Overrides:
onCreate in class Fragment

onResume

public void onResume()
Overrides:
onResume in class Fragment
Throws:
FacebookException - if errors occur during the loading of user information

setSession

public void setSession(Session newSession)
Set the Session object to use instead of the active Session. Since a Session cannot be reused, if the user logs out from this Session, and tries to log in again, a new Active Session will be used instead.

If the passed in session is currently opened, this method will also attempt to load some user information for display (if needed).

Parameters:
newSession - the Session object to use
Throws:
FacebookException - if errors occur during the loading of user information

setDefaultAudience

public void setDefaultAudience(SessionDefaultAudience defaultAudience)
Sets the default audience to use when the session is opened. This value is only useful when specifying write permissions for the native login dialog.

Parameters:
defaultAudience - the default audience value to use

getDefaultAudience

public SessionDefaultAudience getDefaultAudience()
Gets the default audience to use when the session is opened. This value is only useful when specifying write permissions for the native login dialog.

Returns:
the default audience value to use

setReadPermissions

public void setReadPermissions(List<String> permissions)
Set the permissions to use when the session is opened. The permissions here can only be read permissions. If any publish permissions are included, the login attempt by the user will fail. The LoginButton can only be associated with either read permissions or publish permissions, but not both. Calling both setReadPermissions and setPublishPermissions on the same instance of LoginButton will result in an exception being thrown unless clearPermissions is called in between.

This method is only meaningful if called before the session is open. If this is called after the session is opened, and the list of permissions passed in is not a subset of the permissions granted during the authorization, it will log an error.

Since the session can be automatically opened when the UserSettingsFragment is constructed, it's important to always pass in a consistent set of permissions to this method, or manage the setting of permissions outside of the LoginButton class altogether (by managing the session explicitly).

Parameters:
permissions - the read permissions to use
Throws:
UnsupportedOperationException - if setPublishPermissions has been called

setPublishPermissions

public void setPublishPermissions(List<String> permissions)
Set the permissions to use when the session is opened. The permissions here should only be publish permissions. If any read permissions are included, the login attempt by the user may fail. The LoginButton can only be associated with either read permissions or publish permissions, but not both. Calling both setReadPermissions and setPublishPermissions on the same instance of LoginButton will result in an exception being thrown unless clearPermissions is called in between.

This method is only meaningful if called before the session is open. If this is called after the session is opened, and the list of permissions passed in is not a subset of the permissions granted during the authorization, it will log an error.

Since the session can be automatically opened when the LoginButton is constructed, it's important to always pass in a consistent set of permissions to this method, or manage the setting of permissions outside of the LoginButton class altogether (by managing the session explicitly).

Parameters:
permissions - the read permissions to use
Throws:
UnsupportedOperationException - if setReadPermissions has been called
IllegalArgumentException - if permissions is null or empty

clearPermissions

public void clearPermissions()
Clears the permissions currently associated with this LoginButton.


setLoginBehavior

public void setLoginBehavior(SessionLoginBehavior loginBehavior)
Sets the login behavior for the session that will be opened. If null is specified, the default (SessionLoginBehavior.SSO_WITH_FALLBACK will be used.

Parameters:
loginBehavior - The SessionLoginBehavior that specifies what behaviors should be attempted during authorization.

getLoginBehavior

public SessionLoginBehavior getLoginBehavior()
Gets the login behavior for the session that will be opened. If null is returned, the default (SessionLoginBehavior.SSO_WITH_FALLBACK will be used.

Returns:
loginBehavior The SessionLoginBehavior that specifies what behaviors should be attempted during authorization.

setOnErrorListener

public void setOnErrorListener(LoginButton.OnErrorListener onErrorListener)
Sets an OnErrorListener for this instance of UserSettingsFragment to call into when certain exceptions occur.

Parameters:
onErrorListener - The listener object to set

getOnErrorListener

public LoginButton.OnErrorListener getOnErrorListener()
Returns the current OnErrorListener for this instance of UserSettingsFragment.

Returns:
The OnErrorListener

setSessionStatusCallback

public void setSessionStatusCallback(Session.StatusCallback callback)
Sets the callback interface that will be called whenever the status of the Session associated with this LoginButton changes.

Parameters:
callback - the callback interface

getSessionStatusCallback

public Session.StatusCallback getSessionStatusCallback()
Sets the callback interface that will be called whenever the status of the Session associated with this LoginButton changes.

Returns:
the callback interface

onSessionStateChange

protected void onSessionStateChange(SessionState state,
                                    Exception exception)
Called when the session state changes. Override this method to take action on session state changes.

Parameters:
state - the new state
exception - any exceptions that occurred during the state change

onActivityCreated

public void onActivityCreated(Bundle savedInstanceState)
Overrides:
onActivityCreated in class Fragment

onActivityResult

public void onActivityResult(int requestCode,
                             int resultCode,
                             Intent data)
Called when the activity that was launched exits. This method manages session information when a session is opened. If this method is overridden in subclasses, be sure to call super.onActivityResult(...) first.

Overrides:
onActivityResult in class Fragment

onDestroy

public void onDestroy()
Overrides:
onDestroy in class Fragment

getSession

protected final Session getSession()
Gets the current Session.

Returns:
the current Session object.

isSessionOpen

protected final boolean isSessionOpen()
Determines whether the current session is open.

Returns:
true if the current session is open

getSessionState

protected final SessionState getSessionState()
Gets the current state of the session or null if no session has been created.

Returns:
the current state of the session

getAccessToken

protected final String getAccessToken()
Gets the access token associated with the current session or null if no session has been created.

Returns:
the access token

getExpirationDate

protected final Date getExpirationDate()
Gets the date at which the current session will expire or null if no session has been created.

Returns:
the date at which the current session will expire

closeSession

protected final void closeSession()
Closes the current session.


closeSessionAndClearTokenInformation

protected final void closeSessionAndClearTokenInformation()
Closes the current session as well as clearing the token cache.


getSessionPermissions

protected final List<String> getSessionPermissions()
Gets the permissions associated with the current session or null if no session has been created.

Returns:
the permissions associated with the current session

openSession

protected final void openSession()
Opens a new session. This method will use the application id from the associated meta-data value and an empty list of permissions.


openSessionForRead

protected final void openSessionForRead(String applicationId,
                                        List<String> permissions)
Opens a new session with read permissions. If either applicationID or permissions is null, this method will default to using the values from the associated meta-data value and an empty list respectively.

Parameters:
applicationId - the applicationID, can be null
permissions - the permissions list, can be null

openSessionForRead

protected final void openSessionForRead(String applicationId,
                                        List<String> permissions,
                                        SessionLoginBehavior behavior,
                                        int activityCode)
Opens a new session with read permissions. If either applicationID or permissions is null, this method will default to using the values from the associated meta-data value and an empty list respectively.

Parameters:
applicationId - the applicationID, can be null
permissions - the permissions list, can be null
behavior - the login behavior to use with the session
activityCode - the activity code to use for the SSO activity

openSessionForPublish

protected final void openSessionForPublish(String applicationId,
                                           List<String> permissions)
Opens a new session with publish permissions. If either applicationID is null, this method will default to using the value from the associated meta-data value. The permissions list cannot be null.

Parameters:
applicationId - the applicationID, can be null
permissions - the permissions list, cannot be null

openSessionForPublish

protected final void openSessionForPublish(String applicationId,
                                           List<String> permissions,
                                           SessionLoginBehavior behavior,
                                           int activityCode)
Opens a new session with publish permissions. If either applicationID is null, this method will default to using the value from the associated meta-data value. The permissions list cannot be null.

Parameters:
applicationId - the applicationID, can be null
permissions - the permissions list, cannot be null
behavior - the login behavior to use with the session
activityCode - the activity code to use for the SSO activity