private static void validatePhoto(SharePhoto photo) { if (photo == null) { throw new FacebookException("Cannot share a null SharePhoto"); } Bitmap photoBitmap = photo.getBitmap(); Uri photoUri = photo.getImageUrl(); if (photoBitmap == null && photoUri == null) { throw new FacebookException("SharePhoto does not have a Bitmap or ImageUrl specified"); } }
@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()) ; }
@Override public SharePhoto build() { return new SharePhoto(this); }
public static void assertEquals(final SharePhoto a, final SharePhoto b) { Assert.assertEquals(a.getBitmap(), b.getBitmap()); Assert.assertEquals(a.getImageUrl(), b.getImageUrl()); Assert.assertEquals(a.getUserGenerated(), b.getUserGenerated()); }
return; final Bitmap bitmap = photo.getBitmap(); final Uri photoUri = photo.getImageUrl(); String caption = photo.getCaption(); if (caption == null) { caption = this.getMessage();
@Test public void testPhotoBuilder() { final SharePhoto photo = ShareModelTestUtility .getPhotoBuilder(ShareModelTestUtility.PhotoBuilderType.LOCAL_URL) .build(); assertEquals(ShareModelTestUtility.getTestPhotoImageUrl(), photo.getImageUrl()); assertEquals(ShareModelTestUtility.PHOTO_USER_GENERATED, photo.getUserGenerated()); ShareModelTestUtility.assertEquals(photo, TestUtils.parcelAndUnparcel(photo)); } }
@Override public JSONObject toJSONObject(SharePhoto photo) { Uri photoUri = photo.getImageUrl(); JSONObject photoJSONObject = new JSONObject(); try { photoJSONObject.put( NativeProtocol.IMAGE_URL_KEY, photoUri.toString()); } catch (Exception e) { throw new FacebookException("Unable to attach images", e); } return photoJSONObject; } });
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 Bundle getSharePhotoCommonParameters(SharePhoto photo, SharePhotoContent photoContent) throws JSONException{ Bundle params = photo.getParameters(); if (!params.containsKey("place") && !Utility.isNullOrEmpty(photoContent.getPlaceId())) { params.putString("place", photoContent.getPlaceId()); } if (!params.containsKey("tags") && !Utility.isNullOrEmpty(photoContent.getPeopleIds())) { final List<String> peopleIds = photoContent.getPeopleIds(); if (!Utility.isNullOrEmpty(peopleIds)) { JSONArray tags = new JSONArray(); for (String id : peopleIds) { JSONObject tag = new JSONObject(); tag.put("tag_uid", id); tags.put(tag); } params.putString("tags", tags.toString()); } } if (!params.containsKey("ref") && !Utility.isNullOrEmpty(photoContent.getRef())) { params.putString("ref", photoContent.getRef()); } return params; }
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(); } return getAttachment(callId, uri, bitmap); }
private static void validatePhotoForApi(SharePhoto photo, Validator validator) { validatePhoto(photo); Bitmap photoBitmap = photo.getBitmap(); Uri photoUri = photo.getImageUrl(); if (photoBitmap == null && Utility.isWebUri(photoUri) && !validator.isOpenGraphContent()) { throw new FacebookException( "Cannot set the ImageUrl of a SharePhoto to the Uri of an image on the " + "web when sharing SharePhotoContent"); } }
private static void validatePhotoForNativeDialog(SharePhoto photo, Validator validator) { validatePhotoForApi(photo, validator); if (photo.getBitmap() != null || !Utility.isWebUri(photo.getImageUrl())) { Validate.hasContentProvider(FacebookSdk.getApplicationContext()); } }
private void stagePhoto(final SharePhoto photo, final CollectionMapper.OnMapValueCompleteListener onPhotoStagedListener) { final Bitmap bitmap = photo.getBitmap(); final Uri imageUrl = photo.getImageUrl(); if ((bitmap != null) || (imageUrl != null)) { final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {