Search in sources :

Example 1 with SharePhotoContent

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

the class ShareDialog method canShowWebTypeCheck.

private static boolean canShowWebTypeCheck(Class<? extends ShareContent> contentType) {
    // If we don't have an instance of a ShareContent, then all we can do is check whether
    // this is a ShareLinkContent, which can be shared if configured properly.
    // The instance method version of this check is more accurate and should be used on
    // ShareDialog instances.
    // SharePhotoContent currently requires the user staging endpoint, so we need a user access
    // token, so we need to see if we have one
    final AccessToken accessToken = AccessToken.getCurrentAccessToken();
    final boolean haveUserAccessToken = accessToken != null && !accessToken.isExpired();
    return ShareLinkContent.class.isAssignableFrom(contentType) || ShareOpenGraphContent.class.isAssignableFrom(contentType) || (SharePhotoContent.class.isAssignableFrom(contentType) && haveUserAccessToken);
}
Also used : SharePhotoContent(com.facebook.share.model.SharePhotoContent) AccessToken(com.facebook.AccessToken)

Example 2 with SharePhotoContent

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

use of com.facebook.share.model.SharePhotoContent 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);
    } else if (shareContent instanceof ShareCameraEffectContent) {
        final ShareCameraEffectContent cameraEffectContent = (ShareCameraEffectContent) shareContent;
        // Put Bitmaps behind content uris.
        Bundle attachmentUrlsBundle = ShareInternalUtility.getTextureUrlBundle(cameraEffectContent, callId);
        nativeParams = create(cameraEffectContent, attachmentUrlsBundle, shouldFailOnDataError);
    } else if (shareContent instanceof ShareMessengerGenericTemplateContent) {
        final ShareMessengerGenericTemplateContent genericTemplateContent = (ShareMessengerGenericTemplateContent) shareContent;
        nativeParams = create(genericTemplateContent, shouldFailOnDataError);
    } else if (shareContent instanceof ShareMessengerOpenGraphMusicTemplateContent) {
        final ShareMessengerOpenGraphMusicTemplateContent openGraphMusicTemplateContent = (ShareMessengerOpenGraphMusicTemplateContent) shareContent;
        nativeParams = create(openGraphMusicTemplateContent, shouldFailOnDataError);
    } else if (shareContent instanceof ShareMessengerMediaTemplateContent) {
        final ShareMessengerMediaTemplateContent mediaTemplateContent = (ShareMessengerMediaTemplateContent) shareContent;
        nativeParams = create(mediaTemplateContent, shouldFailOnDataError);
    }
    return nativeParams;
}
Also used : ShareLinkContent(com.facebook.share.model.ShareLinkContent) SharePhotoContent(com.facebook.share.model.SharePhotoContent) ShareCameraEffectContent(com.facebook.share.model.ShareCameraEffectContent) Bundle(android.os.Bundle) ShareMessengerMediaTemplateContent(com.facebook.share.model.ShareMessengerMediaTemplateContent) JSONException(org.json.JSONException) ShareMessengerGenericTemplateContent(com.facebook.share.model.ShareMessengerGenericTemplateContent) ShareMediaContent(com.facebook.share.model.ShareMediaContent) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) JSONObject(org.json.JSONObject) FacebookException(com.facebook.FacebookException) ShareVideoContent(com.facebook.share.model.ShareVideoContent) ShareMessengerOpenGraphMusicTemplateContent(com.facebook.share.model.ShareMessengerOpenGraphMusicTemplateContent) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with SharePhotoContent

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

the class ShareContentValidationTest method testItValidatesNullImageForSharePhotoContentByApi.

@Test(expected = FacebookException.class)
public void testItValidatesNullImageForSharePhotoContentByApi() {
    SharePhotoContent.Builder spcBuilder = new SharePhotoContent.Builder();
    SharePhoto sharePhoto = new SharePhoto.Builder().setImageUrl(null).build();
    SharePhotoContent sharePhotoContent = spcBuilder.addPhoto(sharePhoto).build();
    ShareContentValidation.validateForApiShare(sharePhotoContent);
}
Also used : SharePhotoContent(com.facebook.share.model.SharePhotoContent) SharePhoto(com.facebook.share.model.SharePhoto) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with SharePhotoContent

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

the class HelloFacebookSampleActivity method postPhoto.

private void postPhoto() {
    Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon);
    SharePhoto sharePhoto = new SharePhoto.Builder().setBitmap(image).build();
    ArrayList<SharePhoto> photos = new ArrayList<>();
    photos.add(sharePhoto);
    SharePhotoContent sharePhotoContent = new SharePhotoContent.Builder().setPhotos(photos).build();
    if (canPresentShareDialogWithPhotos) {
        shareDialog.show(sharePhotoContent);
    } else if (hasPublishPermission()) {
        ShareApi.share(sharePhotoContent, shareCallback);
    } else {
        pendingAction = PendingAction.POST_PHOTO;
        // We need to get new permissions, then complete the action when we get called back.
        LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList(PERMISSION));
    }
}
Also used : SharePhotoContent(com.facebook.share.model.SharePhotoContent) Bitmap(android.graphics.Bitmap) SharePhoto(com.facebook.share.model.SharePhoto) ArrayList(java.util.ArrayList)

Aggregations

SharePhotoContent (com.facebook.share.model.SharePhotoContent)11 SharePhoto (com.facebook.share.model.SharePhoto)6 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Bundle (android.os.Bundle)3 ArrayList (java.util.ArrayList)3 JSONObject (org.json.JSONObject)3 Bitmap (android.graphics.Bitmap)2 FacebookException (com.facebook.FacebookException)2 ShareLinkContent (com.facebook.share.model.ShareLinkContent)2 ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)2 ShareVideoContent (com.facebook.share.model.ShareVideoContent)2 List (java.util.List)2 JSONException (org.json.JSONException)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)1 AccessToken (com.facebook.AccessToken)1 ShareApi (com.facebook.share.ShareApi)1 Sharer (com.facebook.share.Sharer)1 ShareCameraEffectContent (com.facebook.share.model.ShareCameraEffectContent)1 ShareMediaContent (com.facebook.share.model.ShareMediaContent)1