/** * Constructor. * @param activity the Activity which is presenting the native Open Graph action publish dialog; * must not be null * @param action the Open Graph action to be published, which must contain a reference to at least one * Open Graph object with the property name specified by setPreviewPropertyName; the action * must have had its type specified via the {@link OpenGraphAction#setType(String)} method * @param actionType the type of the Open Graph action to be published, which should be the namespace-qualified * name of the action type (e.g., "myappnamespace:myactiontype"); this will override the type * of the action passed in. * @param previewPropertyName the name of a property on the Open Graph action that contains the * Open Graph object which will be displayed as a preview to the user */ @Deprecated public OpenGraphActionDialogBuilder(Activity activity, OpenGraphAction action, String actionType, String previewPropertyName) { super(activity); Validate.notNull(action, "action"); Validate.notNullOrEmpty(actionType, "actionType"); Validate.notNullOrEmpty(previewPropertyName, "previewPropertyName"); if (action.getProperty(previewPropertyName) == null) { throw new IllegalArgumentException( "A property named \"" + previewPropertyName + "\" was not found on the action. The name of " + "the preview property must match the name of an action property."); } String typeOnAction = action.getType(); if (!Utility.isNullOrEmpty(typeOnAction) && !typeOnAction.equals(actionType)) { throw new IllegalArgumentException("'actionType' must match the type of 'action' if it is specified. " + "Consider using OpenGraphActionDialogBuilder(Activity activity, OpenGraphAction action, " + "String previewPropertyName) instead."); } this.action = action; this.actionType = actionType; this.previewPropertyName = previewPropertyName; }
/** * Constructor. * @param activity the Activity which is presenting the native Open Graph action publish dialog; * must not be null * @param action the Open Graph action to be published, which must contain a reference to at least one * Open Graph object with the property name specified by setPreviewPropertyName; the action * must have had its type specified via the {@link OpenGraphAction#setType(String)} method * @param previewPropertyName the name of a property on the Open Graph action that contains the * Open Graph object which will be displayed as a preview to the user */ public OpenGraphActionDialogBuilder(Activity activity, OpenGraphAction action, String previewPropertyName) { super(activity); Validate.notNull(action, "action"); Validate.notNullOrEmpty(action.getType(), "action.getType()"); Validate.notNullOrEmpty(previewPropertyName, "previewPropertyName"); if (action.getProperty(previewPropertyName) == null) { throw new IllegalArgumentException( "A property named \"" + previewPropertyName + "\" was not found on the action. The name of " + "the preview property must match the name of an action property."); } this.action = action; this.actionType = action.getType(); this.previewPropertyName = previewPropertyName; }
/** * Constructor. * * @param activity the Activity which is presenting the native Open Graph action publish dialog; * must not be null * @param action the Open Graph action to be published, which must contain a reference to at least one * Open Graph object with the property name specified by setPreviewPropertyName; the action * must have had its type specified via the {@link OpenGraphAction#setType(String)} method * @param actionType the type of the Open Graph action to be published, which should be the namespace-qualified * name of the action type (e.g., "myappnamespace:myactiontype"); this will override the type * of the action passed in. * @param previewPropertyName the name of a property on the Open Graph action that contains the * Open Graph object which will be displayed as a preview to the user */ @Deprecated public OpenGraphDialogBuilderBase(Activity activity, OpenGraphAction action, String actionType, String previewPropertyName) { super(activity); Validate.notNull(action, "action"); Validate.notNullOrEmpty(actionType, "actionType"); Validate.notNullOrEmpty(previewPropertyName, "previewPropertyName"); if (action.getProperty(previewPropertyName) == null) { throw new IllegalArgumentException( "A property named \"" + previewPropertyName + "\" was not found on the action. The name of " + "the preview property must match the name of an action property."); } String typeOnAction = action.getType(); if (!Utility.isNullOrEmpty(typeOnAction) && !typeOnAction.equals(actionType)) { throw new IllegalArgumentException("'actionType' must match the type of 'action' if it is specified. " + "Consider using OpenGraphDialogBuilderBase(Activity activity, OpenGraphAction action, " + "String previewPropertyName) instead."); } this.action = action; this.actionType = actionType; this.previewPropertyName = previewPropertyName; }
/** * Constructor. * * @param activity the Activity which is presenting the native Open Graph action publish dialog; * must not be null * @param action the Open Graph action to be published, which must contain a reference to at least one * Open Graph object with the property name specified by setPreviewPropertyName; the action * must have had its type specified via the {@link OpenGraphAction#setType(String)} method * @param previewPropertyName the name of a property on the Open Graph action that contains the * Open Graph object which will be displayed as a preview to the user */ public OpenGraphDialogBuilderBase(Activity activity, OpenGraphAction action, String previewPropertyName) { super(activity); Validate.notNull(action, "action"); Validate.notNullOrEmpty(action.getType(), "action.getType()"); Validate.notNullOrEmpty(previewPropertyName, "previewPropertyName"); if (action.getProperty(previewPropertyName) == null) { throw new IllegalArgumentException( "A property named \"" + previewPropertyName + "\" was not found on the action. The name of " + "the preview property must match the name of an action property."); } this.action = action; this.actionType = action.getType(); this.previewPropertyName = previewPropertyName; }
@Deprecated public OpenGraphDialogBuilderBase(Activity paramActivity, OpenGraphAction paramOpenGraphAction, String paramString1, String paramString2) { super(); Validate.notNull(paramOpenGraphAction, "action"); Validate.notNullOrEmpty(paramString1, "actionType"); Validate.notNullOrEmpty(paramString2, "previewPropertyName"); if (paramOpenGraphAction.getProperty(paramString2) == null) throw new IllegalArgumentException("A property named \"" + paramString2 + "\" was not found on the action. The name of the preview property must match the name of an action property."); String str = paramOpenGraphAction.getType(); if ((!Utility.isNullOrEmpty(str)) && (!str.equals(paramString1))) throw new IllegalArgumentException("'actionType' must match the type of 'action' if it is specified. Consider using OpenGraphDialogBuilderBase(Activity activity, OpenGraphAction action, String previewPropertyName) instead."); this.action = paramOpenGraphAction; this.actionType = paramString1; this.previewPropertyName = paramString2; }
private void shareToFB(Context context, String badgeName) { String description = context.getResources().getText(context.getResources() .getIdentifier(badgeName + "FB", "string", context.getPackageName())).toString(); String imgURL = context.getResources().getText(context.getResources() .getIdentifier(badgeName + "imgURL", "string", context.getPackageName())).toString(); if (FacebookDialog.canPresentOpenGraphActionDialog(context.getApplicationContext(), FacebookDialog.OpenGraphActionDialogFeature.OG_ACTION_DIALOG)) { OpenGraphObject badge = OpenGraphObject.Factory.createForPost (OpenGraphObject.class, "exercisemeapp:badge", "I earned a new badge!", imgURL, null, description); OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class); action.setProperty("badge", badge); action.setType("exercisemeapp:earn"); FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "badge") .build(); uiHelper.trackPendingDialogCall(shareDialog.present()); } else { Toast.makeText(getActivity(), "Facebook not available", Toast.LENGTH_SHORT).show(); } }
public void testOpenGraphActionImageAttachments() throws JSONException { OpenGraphAction action = OpenGraphAction.Factory.createForPost("foo"); action.setProperty("foo", "bar"); FacebookDialog.OpenGraphActionDialogBuilder builder = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "foo"); Bitmap bitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ALPHA_8); builder.setImageAttachmentsForAction(Arrays.asList(bitmap)); List<JSONObject> images = action.getImage(); assertNotNull(images); assertTrue(images.size() == 1); List<String> attachmentNames = builder.getImageAttachmentNames(); assertNotNull(attachmentNames); assertTrue(attachmentNames.size() == 1); String attachmentName = getAttachmentNameFromContentUri(images.get(0).getString("url")); assertEquals(attachmentNames.get(0), attachmentName); }
public void testOpenGraphObjectImageAttachments() throws JSONException { OpenGraphAction action = OpenGraphAction.Factory.createForPost("foo"); OpenGraphObject object = OpenGraphObject.Factory.createForPost("bar"); action.setProperty("foo", object); FacebookDialog.OpenGraphActionDialogBuilder builder = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "foo"); Bitmap bitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ALPHA_8); builder.setImageAttachmentsForObject("foo", Arrays.asList(bitmap)); List<GraphObject> images = object.getImage(); assertNotNull(images); assertTrue(images.size() == 1); List<String> attachmentNames = builder.getImageAttachmentNames(); assertNotNull(attachmentNames); assertTrue(attachmentNames.size() == 1); String attachmentName = getAttachmentNameFromContentUri((String) images.get(0).getProperty("url")); assertEquals(attachmentNames.get(0), attachmentName); }
public static void shareToFB(Activity activity, String quoteText, UiLifecycleHelper uiHelper) { if (FacebookDialog.canPresentOpenGraphActionDialog(activity.getApplicationContext(), FacebookDialog.OpenGraphActionDialogFeature.OG_ACTION_DIALOG)) { OpenGraphObject quote = OpenGraphObject.Factory.createForPost (OpenGraphObject.class, "speakeasydevfest:post", "I loved this quote!", "http://i.imgur.com/ec9p33P.jpg", null, "\"" + quoteText + "\""); OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class); action.setProperty("quote", quote); action.setType("speakeasydevfest:love"); FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(activity, action, "quote") .build(); uiHelper.trackPendingDialogCall(shareDialog.present()); } else { Toast.makeText(activity, "Facebook not available", Toast.LENGTH_SHORT).show(); } }
/** * Creates a new Request configured to publish an Open Graph action. * * @param session * the Session to use, or null; if non-null, the session must be in an opened state * @param openGraphAction * the Open Graph object to create; must not be null, and must have a non-empty 'type' * @param callback * a callback that will be called when the request is completed to handle success or error conditions * @return a Request that is ready to execute */ public static Request newPostOpenGraphActionRequest(Session session, OpenGraphAction openGraphAction, Callback callback) { if (openGraphAction == null) { throw new FacebookException("openGraphAction cannot be null"); } if (Utility.isNullOrEmpty(openGraphAction.getType())) { throw new FacebookException("openGraphAction must have non-null 'type' property"); } String path = String.format(MY_ACTION_FORMAT, openGraphAction.getType()); return newPostRequest(session, path, openGraphAction, callback); }