private static Bundle createBaseParameters(ShareContent content, boolean dataErrorsFatal) { Bundle params = new Bundle(); Utility.putUri(params, ShareConstants.CONTENT_URL, content.getContentUrl()); Utility.putNonEmptyString(params, ShareConstants.PLACE_ID, content.getPlaceId()); Utility.putNonEmptyString(params, ShareConstants.REF, content.getRef()); params.putBoolean(ShareConstants.DATA_FAILURES_FATAL, dataErrorsFatal); List<String> peopleIds = content.getPeopleIds(); if (!Utility.isNullOrEmpty(peopleIds)) { params.putStringArrayList( ShareConstants.PEOPLE_IDS, new ArrayList<String>(peopleIds)); } return params; }
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 Bundle createBaseParameters(ShareContent content, boolean dataErrorsFatal) { Bundle params = new Bundle(); Utility.putUri(params, ShareConstants.LEGACY_LINK, content.getContentUrl()); Utility.putNonEmptyString(params, ShareConstants.LEGACY_PLACE_TAG, content.getPlaceId()); Utility.putNonEmptyString(params, ShareConstants.LEGACY_REF, content.getRef()); params.putBoolean(ShareConstants.LEGACY_DATA_FAILURES_FATAL, dataErrorsFatal); List<String> peopleIds = content.getPeopleIds(); if (!Utility.isNullOrEmpty(peopleIds)) { params.putStringArrayList( ShareConstants.LEGACY_FRIEND_TAGS, new ArrayList<>(peopleIds)); } 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; 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; }
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; }
@Override protected FacebookDialogBase<ShareContent, Sharer.Result> getDialog() { final ShareDialog dialog; if (ShareButton.this.getFragment() != null) { dialog = new ShareDialog(ShareButton.this.getFragment() , getRequestCode()); } else { dialog = new ShareDialog(getActivity(), getRequestCode()); } return dialog; }
/** * Sets the share content on the button. * @param shareContent The share content. */ public void setShareContent(final ShareContent shareContent) { this.shareContent = shareContent; if (!enabledExplicitlySet) { internalSetEnabled(canShare()); } }
@Override protected FacebookDialogBase<ShareContent, Sharer.Result> getDialog() { final MessageDialog dialog; if (SendButton.this.getFragment() != null) { dialog = new MessageDialog(SendButton.this.getFragment() , getRequestCode()); } else { dialog = new MessageDialog(getActivity(), getRequestCode()); } return dialog; }
@Test public void testFBShareBind_shareContentSet() throws Exception { int positionToShow = 0; when(recipeList.get(positionToShow)).thenReturn(recipe); shadowAdapter.itemVisible(positionToShow); View view = shadowAdapter.getViewForHolderPosition(positionToShow); ShareButton fbShare = (ShareButton) view.findViewById(R.id.fbShare); ShareContent shareContent = fbShare.getShareContent(); assertNotNull(shareContent); assertEquals(URL, shareContent.getContentUrl().toString()); }
@Test public void testFBSendBind_shareContentSet() throws Exception { int positionToShow = 0; when(recipeList.get(positionToShow)).thenReturn(recipe); shadowAdapter.itemVisible(positionToShow); View view = shadowAdapter.getViewForHolderPosition(positionToShow); SendButton fbSend = (SendButton) view.findViewById(R.id.fbSend); ShareContent shareContent = fbSend.getShareContent(); assertNotNull(shareContent); assertEquals(URL, shareContent.getContentUrl().toString()); }
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(); } }
private ShareContent getFacebookShareContent(@NonNull PlaceCheckin theCheckin, @NonNull Place place, String applink) { ShareOpenGraphObject.Builder objectBuilder = new ShareOpenGraphObject.Builder() .putString("og:type", "fitness.course") .putString("og:url", applink) .putString("og:title", getContext().getString(R.string.share_title, place.getName())); if (place.getDescription() != null) { objectBuilder.putString("og:description", place.getDescription()); } if (place.hasLocation()) { objectBuilder.putDouble("fitness:metrics:location:latitude", place.getLocation().getLatitude()); objectBuilder.putDouble("fitness:metrics:location:longitude", place.getLocation().getLongitude()); } // Create an action ShareOpenGraphAction.Builder actionBuilder = new ShareOpenGraphAction.Builder() .setActionType("fitness.walks") .putObject("fitness:course", objectBuilder.build()); if (theCheckin.getImageUrl(SHARE_IMAGE_WIDTH) != null) { SharePhoto photo = new SharePhoto.Builder() .setImageUrl(Uri.parse(theCheckin.getImageUrl(SHARE_IMAGE_WIDTH))) .setUserGenerated(true) .build(); ArrayList<SharePhoto> photoArray = new ArrayList<>(); photoArray.add(photo); actionBuilder.putPhotoArrayList("image", photoArray); } return new ShareOpenGraphContent.Builder() .setPreviewPropertyName("fitness:course") .setAction(actionBuilder.build()) .build(); }
@OnClick(R.id.button_social) public void share(final View view) { if (editing) { setTextAndHideKeyboard(view); } else { AlertDialog.Builder builder = new AlertDialog.Builder(context) .setTitle("Share with:") .setItems(MainActivity.SOCIAL_MEDIA_PLATFORMS, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: makeSnackbar(view, "Selected " + MainActivity.SOCIAL_MEDIA_PLATFORMS[0]); Bitmap crop = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); Bitmap preview = ((BitmapDrawable) previewImage.getDrawable()).getBitmap(); SharePhoto cropPhoto = new SharePhoto.Builder() .setBitmap(crop) .build(); SharePhoto previewPhoto = new SharePhoto.Builder() .setBitmap(preview) .build(); ShareContent shareContent = new ShareMediaContent.Builder() .addMedium(cropPhoto) .addMedium(previewPhoto) .build(); ShareDialog shareDialog = new ShareDialog((Activity) context); shareDialog.show(shareContent, ShareDialog.Mode.AUTOMATIC); break; } } }); builder.show(); } }
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; }
public static void validateForMessage(ShareContent content) { validate(content, getDefaultValidator()); }
public static void validateForNativeShare(ShareContent content) { validate(content, getDefaultValidator()); }
public static void validateForWebShare(ShareContent content) { validate(content, getWebShareValidator()); }
public static void validateForApiShare(ShareContent content) { validate(content, getApiValidator()); }
private void updateView() { if (!mAttached) return; Context context = getContext(); boolean userCanCheckin = CheckinRules.canCheckin(mPlace, mUserStats, mCheckinRules, mLocation); PlaceCheckin latestCheckin = (mPlace != null && mUserStats != null) ? mUserStats.getLatestCheckin(mPlace.getId()) : null; boolean userAlreadyVisited = latestCheckin != null; boolean latestCheckinIsPublic = latestCheckin != null && latestCheckin.isPublicCheckin(); boolean latestCheckinIsOld = latestCheckin != null && !latestCheckin.isFresherThan(SIX_HOURS_MS); String selfieUrl = latestCheckin != null ? latestCheckin.getImageUrl((int) (Utils.getDisplayWidth(context) * 0.2)) : null; boolean userOnline = Utils.isConnected(context); boolean showVisitContainer = userCanCheckin || !userAlreadyVisited; // update visit container mVisitContainer.setVisibility(showVisitContainer ? View.VISIBLE : View.GONE); String visitText; int visitButtonColor = ContextCompat.getColor(context, R.color.subtitleColor); int visitWithSelfieButtonColor = ContextCompat.getColor(context, R.color.subtitleColor); if (userCanCheckin) { visitText = context.getString(R.string.visit_possible); visitButtonColor = ContextCompat.getColor(context, R.color.accentColor); if (userOnline) { visitWithSelfieButtonColor = ContextCompat.getColor(context, R.color.accentColor); } } else if (mPlace != null && mPlace.hasLocation() && mLocation != null) { visitText = context.getString(R.string.visit_impossible_distance, Utils.formatDistance(context, mPlace.getDistanceTo(mLocation))); } else { visitText = context.getString(R.string.visit_impossible_location); } mVisitText.setText(visitText); mVisitButton.setTextColor(visitButtonColor); mVisitButton.setTag(R.id.USER_CHECKIN_OK, userCanCheckin); mVisitWithSelfieButton.setTextColor(visitWithSelfieButtonColor); mVisitWithSelfieButton.setTag(R.id.USER_CHECKIN_OK, userCanCheckin); // update share container mShareContainer.setVisibility(!showVisitContainer ? View.VISIBLE : View.GONE); int shareSignButtonColor = ContextCompat.getColor(context, userOnline ? R.color.accentColor : R.color.subtitleColor); mSignButton.setText(latestCheckinIsPublic || latestCheckinIsOld ? R.string.read_guestbook : R.string.sign_guestbook); mSignButton.setTextColor(shareSignButtonColor); String shareText = ""; ShareContent shareContent = null; if (mPlace != null && latestCheckin != null) { String timeSpan = Utils.getTimeSpanFromNow(latestCheckin.getTimestamp(), getContext().getString(R.string.just_now)); if (latestCheckinIsOld) { shareText = context.getString(R.string.you_visited_place_at, mPlace.getName(), timeSpan); } else if (userOnline) { shareText = context.getString(R.string.you_visited_place_at_congrats, mPlace.getName(), timeSpan); } else { shareText = context.getString(R.string.you_visited_place_at_congrats_offline, mPlace.getName(), timeSpan); } if (mAppLink != null && userOnline) { shareContent = getFacebookShareContent(latestCheckin, mPlace, mAppLink); } } mShareText.setText(shareText); mShareButton.setTextColor(shareSignButtonColor); mShareButton.setCompoundDrawablesWithIntrinsicBounds(userOnline ? mShareActive : mShareInactive, null, null, null); mShareFacebookButton.setTextColor(shareSignButtonColor); mShareFacebookButton.setCompoundDrawablesWithIntrinsicBounds(userOnline ? mFacebookActive : mFacebookInactive, null, null, null); mShareFacebookButton.setShareContent(shareContent); mShareFacebookButton.setEnabled(true); Picasso.with(context) .load(selfieUrl) .placeholder(userOnline && !latestCheckinIsOld ? mCameraActive : mCameraInactive) .error(userOnline && !latestCheckinIsOld ? mCameraActive : mCameraInactive) .fit() .into(mSelfieButton); }
public static void validateForApiShare(ShareContent content) { validate(content, getDefaultValidator()); }
/** * Returns the share content from the button. * @return The share content. */ public ShareContent getShareContent() { return this.shareContent; }
/** * Sets the share content on the button. * @param shareContent The share content. */ public void setShareContent(final ShareContent shareContent) { this.shareContent = shareContent; }