/** * Entry-point to the code that performs the like/unlike action. */ public void toggleLike(Activity activity, Fragment fragment, Bundle analyticsParameters) { boolean shouldLikeObject = !this.isObjectLiked; if (canUseOGPublish()) { // Update UI Like state optimistically updateLikeState(shouldLikeObject); if (isPendingLikeOrUnlike) { // If the user toggled the button quickly, and there is still a publish underway, // don't fire off another request. Also log this behavior. getAppEventsLogger().logSdkEvent( AnalyticsEvents.EVENT_LIKE_VIEW_DID_UNDO_QUICKLY, null, analyticsParameters); } else if (!publishLikeOrUnlikeAsync(shouldLikeObject, analyticsParameters)) { // We were not able to send a graph request to unlike or like the object // Undo the optimistic state-update and show the dialog instead updateLikeState(!shouldLikeObject); presentLikeDialog(activity, fragment, analyticsParameters); } } else { presentLikeDialog(activity, fragment, analyticsParameters); } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.com_facebook_usersettingsfragment, container, false); loginButton = (LoginButton) view.findViewById(R.id.com_facebook_usersettingsfragment_login_button); loginButton.setProperties(loginButtonProperties); loginButton.setFragment(this); loginButton.setLoginLogoutEventName(AnalyticsEvents.EVENT_USER_SETTINGS_USAGE); Session session = getSession(); if (session != null && !session.equals(Session.getActiveSession())) { loginButton.setSession(session); } connectedStateLabel = (TextView) view.findViewById(R.id.com_facebook_usersettingsfragment_profile_name); // if no background is set for some reason, then default to Facebook blue if (view.getBackground() == null) { view.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue)); } else { view.getBackground().setDither(true); } return view; }
/** * Launches an activity in the Facebook application to present the desired dialog. This method returns a * PendingCall that contains a unique ID associated with this call to the Facebook application. In general, * a calling Activity should use UiLifecycleHelper to handle incoming activity results, in order to ensure * proper processing of the results from this dialog. * * @return a PendingCall containing the unique call ID corresponding to this call to the Facebook application */ public PendingCall present() { logDialogActivity(activity, fragment, getEventName(appCall.getRequestIntent()), AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_COMPLETED); if (onPresentCallback != null) { try { onPresentCallback.onPresent(activity); } catch (Exception e) { throw new FacebookException(e); } } if (fragment != null) { fragment.startActivityForResult(appCall.getRequestIntent(), appCall.getRequestCode()); } else { activity.startActivityForResult(appCall.getRequestIntent(), appCall.getRequestCode()); } return appCall; }
static private String getEventName(String action, boolean hasPhotos) { String eventName; if (action.equals(NativeProtocol.ACTION_FEED_DIALOG)) { eventName = hasPhotos ? AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_PHOTO_SHARE : AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_SHARE; } else if (action.equals(NativeProtocol.ACTION_MESSAGE_DIALOG)) { eventName = hasPhotos ? AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_PHOTO_MESSAGE : AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_MESSAGE; } else if (action.equals(NativeProtocol.ACTION_OGACTIONPUBLISH_DIALOG)) { eventName = AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_OG_SHARE; } else if (action.equals(NativeProtocol.ACTION_OGMESSAGEPUBLISH_DIALOG)) { eventName = AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_OG_MESSAGE; } else { throw new FacebookException("An unspecified action was presented"); } return eventName; }
/** * Constructs a FacebookDialog with an Intent that is correctly populated to present the dialog within * the Facebook application. * * @return a FacebookDialog instance */ public FacebookDialog build() { validate(); Bundle extras = new Bundle(); putExtra(extras, NativeProtocol.EXTRA_APPLICATION_ID, applicationId); putExtra(extras, NativeProtocol.EXTRA_APPLICATION_NAME, applicationName); extras = setBundleExtras(extras); String action = getActionForFeatures(getDialogFeatures()); int protocolVersion = getProtocolVersionForNativeDialog(activity, action, getMinVersionForFeatures(getDialogFeatures())); Intent intent = NativeProtocol.createPlatformActivityIntent(activity, action, protocolVersion, extras); if (intent == null) { logDialogActivity(activity, fragment, getEventName(action, extras.containsKey(NativeProtocol.EXTRA_PHOTOS)), AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_FAILED); throw new FacebookException( "Unable to create Intent; this likely means the Facebook app is not installed."); } appCall.setRequestIntent(intent); return new FacebookDialog(activity, fragment, appCall, getOnPresentCallback()); }
@Override boolean tryAuthorize(AuthorizationRequest request) { applicationId = request.getApplicationId(); Intent intent = NativeProtocol.createLoginDialog20121101Intent(context, request.getApplicationId(), new ArrayList<String>(request.getPermissions()), request.getDefaultAudience().getNativeProtocolAudience()); if (intent == null) { return false; } callId = intent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_CALL_ID); addLoggingExtra(EVENT_EXTRAS_APP_CALL_ID, callId); addLoggingExtra(EVENT_EXTRAS_PROTOCOL_VERSION, intent.getIntExtra(NativeProtocol.EXTRA_PROTOCOL_VERSION, 0)); addLoggingExtra(EVENT_EXTRAS_PERMISSIONS, TextUtils.join(",", intent.getStringArrayListExtra(NativeProtocol.EXTRA_PERMISSIONS))); addLoggingExtra(EVENT_EXTRAS_WRITE_PRIVACY, intent.getStringExtra(NativeProtocol.EXTRA_WRITE_PRIVACY)); logEvent(AnalyticsEvents.EVENT_NATIVE_LOGIN_DIALOG_START, AnalyticsEvents.PARAMETER_NATIVE_LOGIN_DIALOG_START_TIME, callId); return tryIntent(intent, request.getRequestCode()); }
@Override boolean tryAuthorize(AuthorizationRequest request) { applicationId = request.getApplicationId(); Intent intent = NativeProtocol.createLoginDialog20121101Intent(context, request.getApplicationId(), new ArrayList<String>(request.getPermissions()), request.getDefaultAudience().getNativeProtocolAudience()); if (intent == null) { return false; } callId = intent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_CALL_ID); addLoggingExtra(EVENT_EXTRAS_APP_CALL_ID, callId); addLoggingExtra(EVENT_EXTRAS_PROTOCOL_VERSION, ""+intent.getIntExtra(NativeProtocol.EXTRA_PROTOCOL_VERSION,0)); addLoggingExtra(EVENT_EXTRAS_PERMISSIONS, TextUtils.join(",", intent.getStringArrayListExtra(NativeProtocol.EXTRA_PERMISSIONS))); addLoggingExtra(EVENT_EXTRAS_WRITE_PRIVACY, intent.getStringExtra(NativeProtocol.EXTRA_WRITE_PRIVACY)); logEvent(AnalyticsEvents.EVENT_NATIVE_LOGIN_DIALOG_START, AnalyticsEvents.PARAMETER_NATIVE_LOGIN_DIALOG_START_TIME, callId); return tryIntent(intent, request.getRequestCode()); }