public void setReadPermissions(List<String> permissions) { if (LoginAuthorizationType.PUBLISH.equals(authorizationType)) { throw new UnsupportedOperationException( "Cannot call setReadPermissions after " + "setPublishPermissions has been called."); } this.permissions = permissions; authorizationType = LoginAuthorizationType.READ; }
@Override public void onClick(View v) { callExternalOnClickListener(v); Context context = getContext(); AccessToken accessToken = AccessToken.getCurrentAccessToken(); if (accessToken != null) { // 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; Profile profile = Profile.getCurrentProfile(); if (profile != null && profile.getName() != null) { message = String.format( getResources().getString(R.string.com_facebook_loginview_logged_in_as), profile.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) { getLoginManager().logOut(); } }) .setNegativeButton(cancel, null); builder.create().show(); } else { getLoginManager().logOut(); } } else { LoginManager loginManager = getLoginManager(); loginManager.setDefaultAudience(getDefaultAudience()); loginManager.setLoginBehavior(getLoginBehavior()); if (LoginAuthorizationType.PUBLISH.equals(properties.authorizationType)) { if (LoginButton.this.getFragment() != null) { loginManager.logInWithPublishPermissions( LoginButton.this.getFragment(), properties.permissions); } else { loginManager.logInWithPublishPermissions( LoginButton.this.getActivity(), properties.permissions); } } else { if (LoginButton.this.getFragment() != null) { loginManager.logInWithReadPermissions( LoginButton.this.getFragment(), properties.permissions); } else { loginManager.logInWithReadPermissions( LoginButton.this.getActivity(), properties.permissions); } } } AppEventsLogger logger = AppEventsLogger.newLogger(getContext()); Bundle parameters = new Bundle(); parameters.putInt("logging_in", (accessToken != null) ? 0 : 1); logger.logSdkEvent(loginLogoutEventName, null, parameters); }