Search in sources :

Example 1 with ShareVideoContent

use of com.facebook.share.model.ShareVideoContent 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 ShareVideoContent

use of com.facebook.share.model.ShareVideoContent 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 ShareVideoContent

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

the class ShareContentValidationTest method testItDoesNotAcceptShareVideoContentByWeb.

@Test(expected = FacebookException.class)
public void testItDoesNotAcceptShareVideoContentByWeb() {
    SharePhoto previewPhoto = buildSharePhoto("https://facebook.com/awesome.gif");
    ShareVideoContent shareVideoContent = new ShareVideoContent.Builder().setPreviewPhoto(previewPhoto).build();
    ShareContentValidation.validateForWebShare(shareVideoContent);
}
Also used : SharePhoto(com.facebook.share.model.SharePhoto) ShareVideoContent(com.facebook.share.model.ShareVideoContent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with ShareVideoContent

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

the class ShareContentValidationTest method testItValidatesEmptyPreviewPhotoForShareVideoContentByMessage.

// -ShareVideoContent
@Test(expected = FacebookException.class)
public void testItValidatesEmptyPreviewPhotoForShareVideoContentByMessage() {
    ShareVideoContent sharePhoto = new ShareVideoContent.Builder().setPreviewPhoto(null).build();
    ShareContentValidation.validateForMessage(sharePhoto);
}
Also used : ShareVideoContent(com.facebook.share.model.ShareVideoContent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ShareVideoContent

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

the class RequestTests method testUploadVideoFile.

@LargeTest
public void testUploadVideoFile() throws IOException, URISyntaxException {
    File tempFile = null;
    try {
        tempFile = createTempFileFromAsset("DarkScreen.mov");
        ShareVideo video = new ShareVideo.Builder().setLocalUrl(Uri.fromFile(tempFile)).build();
        ShareVideoContent content = new ShareVideoContent.Builder().setVideo(video).build();
        final ShareApi shareApi = new ShareApi(content);
        final AtomicReference<String> videoId = new AtomicReference<>(null);
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                shareApi.share(new FacebookCallback<Sharer.Result>() {

                    @Override
                    public void onSuccess(Sharer.Result result) {
                        videoId.set(result.getPostId());
                        notifyShareFinished();
                    }

                    @Override
                    public void onCancel() {
                        notifyShareFinished();
                    }

                    @Override
                    public void onError(FacebookException error) {
                        notifyShareFinished();
                    }

                    private void notifyShareFinished() {
                        synchronized (shareApi) {
                            shareApi.notifyAll();
                        }
                    }
                });
            }
        });
        synchronized (shareApi) {
            shareApi.wait(REQUEST_TIMEOUT_MILLIS);
        }
        assertNotNull(videoId.get());
    } catch (Exception ex) {
        fail();
    } finally {
        if (tempFile != null) {
            tempFile.delete();
        }
    }
}
Also used : ShareVideo(com.facebook.share.model.ShareVideo) AtomicReference(java.util.concurrent.atomic.AtomicReference) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) IOException(java.io.IOException) ShareVideoContent(com.facebook.share.model.ShareVideoContent) Sharer(com.facebook.share.Sharer) File(java.io.File) ShareApi(com.facebook.share.ShareApi) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

ShareVideoContent (com.facebook.share.model.ShareVideoContent)6 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)3 Bundle (android.os.Bundle)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)2 FacebookException (com.facebook.FacebookException)2 ShareApi (com.facebook.share.ShareApi)2 Sharer (com.facebook.share.Sharer)2 ShareLinkContent (com.facebook.share.model.ShareLinkContent)2 ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)2 SharePhotoContent (com.facebook.share.model.SharePhotoContent)2 ShareVideo (com.facebook.share.model.ShareVideo)2 File (java.io.File)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2