private boolean validatePermissions(List<String> permissions, LoginAuthorizationType authType) { if (LoginAuthorizationType.PUBLISH.equals(authType)) { if (Utility.isNullOrEmpty(permissions)) { throw new IllegalArgumentException( "Permissions for publish actions cannot be null or empty."); } } AccessToken accessToken = AccessToken.getCurrentAccessToken(); if (accessToken != null) { if (!Utility.isSubset(permissions, accessToken.getPermissions())) { Log.e(TAG, "Cannot set additional permissions with existing AccessToken."); return false; } } return true; }
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; }
public void setPublishPermissions(List<String> permissions) { if (LoginAuthorizationType.READ.equals(authorizationType)) { throw new UnsupportedOperationException("Cannot call setPublishPermissions after " + "setReadPermissions has been called."); } if (Utility.isNullOrEmpty(permissions)) { throw new IllegalArgumentException( "Permissions for publish actions cannot be null or empty."); } this.permissions = permissions; authorizationType = LoginAuthorizationType.PUBLISH; }
public void setReadPermissions(List<String> permissions) { if (LoginAuthorizationType.PUBLISH.equals(authorizationType)) { throw new UnsupportedOperationException( "Cannot call setReadPermissions after setPublishPermissions has been called."); } if (validatePermissions(permissions, LoginAuthorizationType.READ)) { this.permissions = permissions; authorizationType = LoginAuthorizationType.READ; } }
public void setPublishPermissions(List<String> permissions) { if (LoginAuthorizationType.READ.equals(authorizationType)) { throw new UnsupportedOperationException( "Cannot call setPublishPermissions after setReadPermissions has been called."); } if (validatePermissions(permissions, LoginAuthorizationType.PUBLISH)) { this.permissions = permissions; authorizationType = LoginAuthorizationType.PUBLISH; } }
@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); }
@Override public void onClick(View 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); callExternalOnClickListener(v); }
@Override public void onClick(View 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); callExternalOnClickListener(v); }