Search in sources :

Example 1 with ShareLinkContent

use of com.facebook.share.model.ShareLinkContent in project facebook-android-sdk by facebook.

the class NativeDialogParameters method create.

public static Bundle create(UUID callId, ShareContent shareContent, boolean shouldFailOnDataError) {
    Validate.notNull(shareContent, "shareContent");
    Validate.notNull(callId, "callId");
    Bundle nativeParams = null;
    if (shareContent instanceof ShareLinkContent) {
        final ShareLinkContent linkContent = (ShareLinkContent) shareContent;
        nativeParams = create(linkContent, shouldFailOnDataError);
    } else if (shareContent instanceof SharePhotoContent) {
        final SharePhotoContent photoContent = (SharePhotoContent) shareContent;
        List<String> photoUrls = ShareInternalUtility.getPhotoUrls(photoContent, callId);
        nativeParams = create(photoContent, photoUrls, shouldFailOnDataError);
    } else if (shareContent instanceof ShareVideoContent) {
        final ShareVideoContent videoContent = (ShareVideoContent) shareContent;
        String videoUrl = ShareInternalUtility.getVideoUrl(videoContent, callId);
        nativeParams = create(videoContent, videoUrl, shouldFailOnDataError);
    } else if (shareContent instanceof ShareOpenGraphContent) {
        final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent;
        try {
            JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall(callId, openGraphContent);
            openGraphActionJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject(openGraphActionJSON, false);
            nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError);
        } catch (final JSONException e) {
            throw new FacebookException("Unable to create a JSON Object from the provided ShareOpenGraphContent: " + e.getMessage());
        }
    } else if (shareContent instanceof ShareMediaContent) {
        final ShareMediaContent mediaContent = (ShareMediaContent) shareContent;
        List<Bundle> mediaInfos = ShareInternalUtility.getMediaInfos(mediaContent, callId);
        nativeParams = create(mediaContent, mediaInfos, shouldFailOnDataError);
    }
    return nativeParams;
}
Also used : ShareLinkContent(com.facebook.share.model.ShareLinkContent) SharePhotoContent(com.facebook.share.model.SharePhotoContent) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) FacebookException(com.facebook.FacebookException) ShareVideoContent(com.facebook.share.model.ShareVideoContent) JSONException(org.json.JSONException) ArrayList(java.util.ArrayList) List(java.util.List) ShareMediaContent(com.facebook.share.model.ShareMediaContent) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent)

Example 2 with ShareLinkContent

use of com.facebook.share.model.ShareLinkContent in project facebook-android-sdk by facebook.

the class LegacyNativeDialogParameters method create.

public static Bundle create(UUID callId, ShareContent shareContent, boolean shouldFailOnDataError) {
    Validate.notNull(shareContent, "shareContent");
    Validate.notNull(callId, "callId");
    Bundle nativeParams = null;
    if (shareContent instanceof ShareLinkContent) {
        final ShareLinkContent linkContent = (ShareLinkContent) shareContent;
        nativeParams = create(linkContent, shouldFailOnDataError);
    } else if (shareContent instanceof SharePhotoContent) {
        final SharePhotoContent photoContent = (SharePhotoContent) shareContent;
        List<String> photoUrls = ShareInternalUtility.getPhotoUrls(photoContent, callId);
        nativeParams = create(photoContent, photoUrls, shouldFailOnDataError);
    } else if (shareContent instanceof ShareVideoContent) {
        final ShareVideoContent videoContent = (ShareVideoContent) shareContent;
        nativeParams = create(videoContent, shouldFailOnDataError);
    } else if (shareContent instanceof ShareOpenGraphContent) {
        final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent;
        try {
            JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall(callId, openGraphContent);
            nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError);
        } catch (final JSONException e) {
            throw new FacebookException("Unable to create a JSON Object from the provided ShareOpenGraphContent: " + e.getMessage());
        }
    }
    return nativeParams;
}
Also used : ShareLinkContent(com.facebook.share.model.ShareLinkContent) SharePhotoContent(com.facebook.share.model.SharePhotoContent) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) FacebookException(com.facebook.FacebookException) ShareVideoContent(com.facebook.share.model.ShareVideoContent) JSONException(org.json.JSONException) ArrayList(java.util.ArrayList) List(java.util.List) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent)

Example 3 with ShareLinkContent

use of com.facebook.share.model.ShareLinkContent in project facebook-android-sdk by facebook.

the class HelloFacebookSampleActivity method postStatusUpdate.

private void postStatusUpdate() {
    Profile profile = Profile.getCurrentProfile();
    ShareLinkContent linkContent = new ShareLinkContent.Builder().setContentTitle("Hello Facebook").setContentDescription("The 'Hello Facebook' sample  showcases simple Facebook integration").setContentUrl(Uri.parse("http://developers.facebook.com/docs/android")).build();
    if (canPresentShareDialog) {
        shareDialog.show(linkContent);
    } else if (profile != null && hasPublishPermission()) {
        ShareApi.share(linkContent, shareCallback);
    } else {
        pendingAction = PendingAction.POST_STATUS_UPDATE;
    }
}
Also used : ShareLinkContent(com.facebook.share.model.ShareLinkContent)

Example 4 with ShareLinkContent

use of com.facebook.share.model.ShareLinkContent in project facebook-android-sdk by facebook.

the class ShareContentValidationTest method testItValidatesNotHttpForShareLinkContentByNative.

@Test(expected = FacebookException.class)
public void testItValidatesNotHttpForShareLinkContentByNative() {
    Uri imageUri = Uri.parse("ftp://facebook.com/awesome-content.gif");
    ShareLinkContent linkContent = buildShareLinkContent(imageUri);
    ShareContentValidation.validateForNativeShare(linkContent);
}
Also used : ShareLinkContent(com.facebook.share.model.ShareLinkContent) Uri(android.net.Uri) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ShareLinkContent

use of com.facebook.share.model.ShareLinkContent in project facebook-android-sdk by facebook.

the class ShareContentValidationTest method testItAcceptsHttpForShareLinkContent.

@Test
public void testItAcceptsHttpForShareLinkContent() {
    Uri imageUri = Uri.parse("http://facebook.com/awesome-content.gif");
    ShareLinkContent linkContent = buildShareLinkContent(imageUri);
    ShareContentValidation.validateForApiShare(linkContent);
    ShareContentValidation.validateForMessage(linkContent);
    ShareContentValidation.validateForNativeShare(linkContent);
    ShareContentValidation.validateForWebShare(linkContent);
}
Also used : ShareLinkContent(com.facebook.share.model.ShareLinkContent) Uri(android.net.Uri) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ShareLinkContent (com.facebook.share.model.ShareLinkContent)9 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Uri (android.net.Uri)4 FacebookException (com.facebook.FacebookException)3 ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)3 Bundle (android.os.Bundle)2 SharePhotoContent (com.facebook.share.model.SharePhotoContent)2 ShareVideoContent (com.facebook.share.model.ShareVideoContent)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Intent (android.content.Intent)1 ShareMediaContent (com.facebook.share.model.ShareMediaContent)1