private SharePhotoContent createAndMapAttachments( final SharePhotoContent content, final UUID callId) { final SharePhotoContent.Builder contentBuilder = new SharePhotoContent.Builder().readFrom(content); final List<SharePhoto> photos = new ArrayList<>(); final List<NativeAppCallAttachmentStore.Attachment> attachments = new ArrayList<>(); for (int i = 0; i < content.getPhotos().size(); i++) { SharePhoto sharePhoto = content.getPhotos().get(i); final Bitmap photoBitmap = sharePhoto.getBitmap(); if (photoBitmap != null) { NativeAppCallAttachmentStore.Attachment attachment = NativeAppCallAttachmentStore.createAttachment(callId, photoBitmap); sharePhoto = new SharePhoto.Builder() .readFrom(sharePhoto) .setImageUrl(Uri.parse(attachment.getAttachmentUrl())) .setBitmap(null) .build(); attachments.add(attachment); } photos.add(sharePhoto); } contentBuilder.setPhotos(photos); NativeAppCallAttachmentStore.addAttachments(attachments); return contentBuilder.build(); } }
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)); } }
getResources(), DRAWABLES_HUMAN[playerChoice]); sharePhotoBuilder.setBitmap(bitmap); } else { sharePhotoBuilder.setImageUrl(Uri.parse(photoUri));
.setBitmap(image) .setUserGenerated(true) .build();
@LargeTest public void testCreateOpenGraphObjectWithBadImageType() throws InterruptedException { //only image urls are accepted for createOpenGraphObject Bitmap image = createTestBitmap(128); SharePhoto photo = new SharePhoto.Builder() .setBitmap(image) .setUserGenerated(true) .build(); ShareOpenGraphObject ogObject = new ShareOpenGraphObject.Builder() .putString("og:title", "a title") .putString("og:type", TEST_OG_OBJECT_TYPE) .putString("og:description", "a description") .putPhoto("og:image", photo) .build(); try { GraphRequest request = ShareGraphRequest.createOpenGraphObject(ogObject); request.executeAndWait(); //should fail because do not accept images without image_url fail(); } catch (Exception e){ if(!(e instanceof FacebookException && e.getMessage().equals("Unable to attach images"))){ fail(); } } }
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(); }
public static SharePhoto.Builder getPhotoBuilder(final PhotoBuilderType type) { final SharePhoto.Builder builder = new SharePhoto.Builder().setUserGenerated( PHOTO_USER_GENERATED); switch (type) { case BITMAP: builder.setBitmap(PHOTO_BITMAP); break; case LOCAL_URL: builder.setImageUrl(getTestPhotoImageUrl()); break; } return builder; }
@Test(expected = FacebookException.class) public void testItValidatesNullImageForPhotoShareByMessage() { SharePhotoContent.Builder spcBuilder = new SharePhotoContent.Builder(); SharePhoto sharePhoto = new SharePhoto.Builder().setImageUrl(null).setBitmap(null) .build(); SharePhotoContent sharePhotoContent = spcBuilder.addPhoto(sharePhoto).build(); ShareContentValidation.validateForMessage(sharePhotoContent); }
@Override public Builder readFrom(final SharePhoto model) { if (model == null) { return this; } return super.readFrom(model) .setBitmap(model.getBitmap()) .setImageUrl(model.getImageUrl()) .setUserGenerated(model.getUserGenerated()) .setCaption(model.getCaption()) ; }