Search in sources :

Example 6 with SharePhoto

use of com.facebook.share.model.SharePhoto 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) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with SharePhoto

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

the class RpsFragment method getThrowAction.

private ShareOpenGraphAction getThrowAction() {
    // The OG objects have their own bitmaps we could rely on, but in order to demonstrate
    // attaching an in-memory bitmap (e.g., a game screencap) we'll send the bitmap explicitly
    // ourselves.
    ImageButton view = gestureImages[playerChoice];
    BitmapDrawable drawable = (BitmapDrawable) view.getBackground();
    final Bitmap bitmap = drawable.getBitmap();
    return new ShareOpenGraphAction.Builder().setActionType(OpenGraphConsts.THROW_ACTION_TYPE).putString("fb_sample_rps:gesture", getBuiltInGesture(playerChoice)).putString("fb_sample_rps:opposing_gesture", getBuiltInGesture(computerChoice)).putPhotoArrayList("og:image", new ArrayList<SharePhoto>() {

        {
            add(new SharePhoto.Builder().setBitmap(bitmap).build());
        }
    }).build();
}
Also used : Bitmap(android.graphics.Bitmap) SharePhoto(com.facebook.share.model.SharePhoto) ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ArrayList(java.util.ArrayList) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 8 with SharePhoto

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

the class ShareInternalUtility method getAttachment.

private static NativeAppCallAttachmentStore.Attachment getAttachment(UUID callId, ShareMedia medium) {
    Bitmap bitmap = null;
    Uri uri = null;
    if (medium instanceof SharePhoto) {
        SharePhoto photo = (SharePhoto) medium;
        bitmap = photo.getBitmap();
        uri = photo.getImageUrl();
    } else if (medium instanceof ShareVideo) {
        ShareVideo video = (ShareVideo) medium;
        uri = video.getLocalUrl();
    }
    NativeAppCallAttachmentStore.Attachment attachment = null;
    if (bitmap != null) {
        attachment = NativeAppCallAttachmentStore.createAttachment(callId, bitmap);
    } else if (uri != null) {
        attachment = NativeAppCallAttachmentStore.createAttachment(callId, uri);
    }
    return attachment;
}
Also used : Bitmap(android.graphics.Bitmap) NativeAppCallAttachmentStore(com.facebook.internal.NativeAppCallAttachmentStore) SharePhoto(com.facebook.share.model.SharePhoto) ShareVideo(com.facebook.share.model.ShareVideo) Uri(android.net.Uri)

Example 9 with SharePhoto

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

the class RpsFragment method publishResult.

private void publishResult() {
    if (shouldImplicitlyPublish && canPublish()) {
        String photoUri = PHOTO_URIS[playerChoice];
        SharePhoto.Builder sharePhotoBuilder = new SharePhoto.Builder();
        if (photoUri == null) {
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), DRAWABLES_HUMAN[playerChoice]);
            sharePhotoBuilder.setBitmap(bitmap);
        } else {
            sharePhotoBuilder.setImageUrl(Uri.parse(photoUri));
        }
        sharePhotoBuilder.setUserGenerated(false);
        final SharePhoto gesturePhoto = sharePhotoBuilder.build();
        ShareOpenGraphObject gameObject = createGameObject(gesturePhoto);
        ShareOpenGraphAction playAction = createPlayActionWithGame(gameObject);
        ShareOpenGraphContent content = new ShareOpenGraphContent.Builder().setAction(playAction).setPreviewPropertyName("game").build();
        ShareApi.share(content, new FacebookCallback<Sharer.Result>() {

            @Override
            public void onSuccess(Sharer.Result result) {
                Log.i(TAG, "Posted OG Action with id: " + result.getPostId());
            }

            @Override
            public void onCancel() {
            // This should not happen
            }

            @Override
            public void onError(FacebookException error) {
                Log.e(TAG, "Play action creation failed: " + error.getMessage());
            }
        });
    }
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphObject(com.facebook.share.model.ShareOpenGraphObject) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) LoginResult(com.facebook.login.LoginResult) Bitmap(android.graphics.Bitmap) SharePhoto(com.facebook.share.model.SharePhoto) Sharer(com.facebook.share.Sharer)

Example 10 with SharePhoto

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

the class SelectionFragment method createOpenGraphContent.

private ShareOpenGraphContent createOpenGraphContent() {
    ShareOpenGraphAction.Builder actionBuilder = createEatActionBuilder();
    boolean userGenerated = false;
    if (photoUri != null) {
        String photoUriString = photoUri.toString();
        Pair<File, Integer> fileAndMinDimension = getImageFileAndMinDimension();
        userGenerated = fileAndMinDimension.second >= USER_GENERATED_MIN_SIZE;
        if (fileAndMinDimension != null) {
            final SharePhoto actionPhoto = new SharePhoto.Builder().setImageUrl(Uri.parse(photoUriString)).setUserGenerated(userGenerated).build();
            actionBuilder.putPhotoArrayList("image", new ArrayList<SharePhoto>() {

                {
                    add(actionPhoto);
                }
            });
        }
    }
    return new ShareOpenGraphContent.Builder().setAction(actionBuilder.build()).setPreviewPropertyName("meal").build();
}
Also used : SharePhoto(com.facebook.share.model.SharePhoto) ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent)

Aggregations

SharePhoto (com.facebook.share.model.SharePhoto)17 Bitmap (android.graphics.Bitmap)6 SharePhotoContent (com.facebook.share.model.SharePhotoContent)5 ShareOpenGraphAction (com.facebook.share.model.ShareOpenGraphAction)4 ArrayList (java.util.ArrayList)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Uri (android.net.Uri)3 LargeTest (android.test.suitebuilder.annotation.LargeTest)3 ShareOpenGraphObject (com.facebook.share.model.ShareOpenGraphObject)3 Bundle (android.os.Bundle)2 Sharer (com.facebook.share.Sharer)2 ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 JSONArray (org.json.JSONArray)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 FacebookException (com.facebook.FacebookException)1