private static void validate(ShareContent content, Validator validator) throws FacebookException { if (content == null) { throw new FacebookException("Must provide non-null content to share"); } if (content instanceof ShareLinkContent) { validator.validate((ShareLinkContent) content); } else if (content instanceof SharePhotoContent) { validator.validate((SharePhotoContent) content); } else if (content instanceof ShareVideoContent) { validator.validate((ShareVideoContent) content); } else if (content instanceof ShareOpenGraphContent) { validator.validate((ShareOpenGraphContent) content); } }
private static void validatePhotoContent( SharePhotoContent photoContent, Validator validator) { List<SharePhoto> photos = photoContent.getPhotos(); if (photos == null || photos.isEmpty()) { throw new FacebookException("Must specify at least one Photo in SharePhotoContent."); } if (photos.size() > ShareConstants.MAXIMUM_PHOTO_COUNT) { throw new FacebookException( String.format( Locale.ROOT, "Cannot add more than %d photos.", ShareConstants.MAXIMUM_PHOTO_COUNT)); } for (SharePhoto photo : photos) { validator.validate(photo); } }
public void openFbDialog(int v) { boolean installed = appInstalledOrNot("com.facebook.katana"); if (installed) { Bitmap image = getPersonalHeartRateBitmap(v); SharePhoto photo = new SharePhoto.Builder() .setBitmap(image) .build(); SharePhotoContent photoContent = new SharePhotoContent.Builder() .addPhoto(photo) .build(); mShareDialog.show(photoContent); } else { ShareLinkContent linkContent = new ShareLinkContent.Builder() .setContentTitle(String.format(mContext.getString(R.string.share_message_format), v)) .setContentDescription( String.format(mContext.getString(R.string.share_message_format), v)) .setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=fr.machada.bpm")) .build(); mShareDialog.show(linkContent); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(this.getApplicationContext()); callbackManager = CallbackManager.Factory.create(); shareDialog = new ShareDialog(this); shareDialog.registerCallback( callbackManager, shareCallback); // Can we present the share dialog for regular links? canPresentShareDialog = ShareDialog.canShow( ShareLinkContent.class); // Can we present the share dialog for photos? canPresentShareDialogWithPhotos = ShareDialog.canShow( SharePhotoContent.class); }
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()); } } return nativeParams; }
private static Bundle create( SharePhotoContent photoContent, List<String> imageUrls, boolean dataErrorsFatal) { Bundle params = createBaseParameters(photoContent, dataErrorsFatal); params.putStringArrayList(ShareConstants.PHOTOS, new ArrayList<>(imageUrls)); return params; }
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; }
private static Bundle create( SharePhotoContent photoContent, List<String> imageUrls, boolean dataErrorsFatal) { Bundle params = createBaseParameters(photoContent, dataErrorsFatal); params.putStringArrayList(ShareConstants.LEGACY_PHOTOS, new ArrayList<>(imageUrls)); return params; }
public void shareImage(ArrayList<String> cards){ try { List<SharePhoto> convertCards = new ArrayList<SharePhoto>(); SharePhoto photo; for (int i = 0; i < cards.size(); i++) { Uri uri = Uri.fromFile(new File(cards.get(i))); Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri); int nh = (int) (bitmap.getHeight() * (1024.0 / bitmap.getWidth())); Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 1024, nh, true); photo = new SharePhoto.Builder() .setBitmap(scaled) .build(); convertCards.add(photo); } ShareContent content = new SharePhotoContent.Builder().addPhotos(convertCards).build(); if(ShareDialog.canShow(SharePhotoContent.class)){ shareDialog.show(content); } } catch (Exception e) { e.printStackTrace(); } }
/** * Handle Facebook */ public static void shareImageOnFace(Activity activity, RelativeLayout photoContent, View v) { // Cria conteudo para ser publicado no face SharePhoto photo = new SharePhoto.Builder().setBitmap(ImageUtil.drawBitmap(photoContent)).build(); SharePhotoContent content = new SharePhotoContent.Builder() .addPhoto(photo) .setShareHashtag(new ShareHashtag.Builder().setHashtag(HASHTAG).build()) .build(); new ShareDialog(activity).show(content); }
private void publishImage(Bitmap img) { SharePhoto photo = new SharePhoto.Builder() .setBitmap(img) .build(); SharePhotoContent content = new SharePhotoContent.Builder() .addPhoto(photo) .build(); Log.e("abc", content.toString()); shareDialog.show(content); }
/** * share bitmap content. * @param bitmap */ public void sharePhoto(Bitmap bitmap) { SharePhoto photo = new SharePhoto.Builder() .setBitmap(bitmap) .build(); SharePhotoContent photoContent = new SharePhotoContent.Builder().addPhoto(photo).build(); ShareDialog shareDialog = new ShareDialog(activity); if (ShareDialog.canShow(SharePhotoContent.class)) { shareDialog.show(photoContent); } }
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; final ShareOpenGraphAction action = openGraphContent.getAction(); try { JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall( callId, action); 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()); } } return nativeParams; }
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; final ShareOpenGraphAction action = openGraphContent.getAction(); try { JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall( callId, action); 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; }
@Override public void SharePhoto(SharePhotoContent sharePhotoContent) { if (canPresentShareDialogWithPhotos) { shareDialog.show(sharePhotoContent); } else if (hasPublishPermission()) { ShareApi.share(sharePhotoContent, shareCallback); } else { LoginManager.getInstance().logInWithPublishPermissions( this, Arrays.asList(Permission.PUBLISH_ACTION.getValue())); } }
@Override public void validate(final SharePhotoContent photoContent) { throw new FacebookException("Cannot share SharePhotoContent via web sharing dialogs"); }
public void validate(final SharePhotoContent photoContent) { validatePhotoContent(photoContent, this); }
void SharePhoto(SharePhotoContent sharePhotoContent);