use of org.wordpress.android.ui.reader.ReaderActivityLauncher.PhotoViewerOption in project WordPress-Android by wordpress-mobile.
the class ReaderLinkMovementMethod method onTouchEvent.
@Override
public boolean onTouchEvent(@NonNull TextView textView, @NonNull Spannable buffer, @NonNull MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= textView.getTotalPaddingLeft();
y -= textView.getTotalPaddingTop();
x += textView.getScrollX();
y += textView.getScrollY();
Layout layout = textView.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ImageSpan[] images = buffer.getSpans(off, off, ImageSpan.class);
if (images != null && images.length > 0) {
EnumSet<PhotoViewerOption> options = EnumSet.noneOf(PhotoViewerOption.class);
if (mIsPrivate) {
options.add(ReaderActivityLauncher.PhotoViewerOption.IS_PRIVATE_IMAGE);
}
String imageUrl = StringUtils.notNullStr(images[0].getSource());
ReaderActivityLauncher.showReaderPhotoViewer(textView.getContext(), imageUrl, null, textView, options, (int) event.getX(), (int) event.getY());
return true;
}
}
try {
return super.onTouchEvent(textView, buffer, event);
} catch (ActivityNotFoundException e) {
AppLog.e(AppLog.T.UTILS, e);
return false;
}
}
use of org.wordpress.android.ui.reader.ReaderActivityLauncher.PhotoViewerOption in project WordPress-Android by wordpress-mobile.
the class ReaderThumbnailStrip method loadThumbnails.
public void loadThumbnails(long blogId, long postId, boolean isPrivate) {
// get rid of any views already added
mView.removeAllViews();
// get this post's content and scan it for images suitable in a gallery
final String content = ReaderPostTable.getPostText(blogId, postId);
final ReaderImageList imageList = new ReaderImageScanner(content, isPrivate).getImageList(IMAGE_COUNT, ReaderConstants.MIN_GALLERY_IMAGE_WIDTH);
if (imageList.size() < IMAGE_COUNT) {
mView.setVisibility(View.GONE);
return;
}
final EnumSet<PhotoViewerOption> photoViewerOptions = EnumSet.of(PhotoViewerOption.IS_GALLERY_IMAGE);
if (isPrivate) {
photoViewerOptions.add(PhotoViewerOption.IS_PRIVATE_IMAGE);
}
// add a separate imageView for each image up to the max
int numAdded = 0;
LayoutInflater inflater = LayoutInflater.from(getContext());
for (final String imageUrl : imageList) {
View view = inflater.inflate(R.layout.reader_thumbnail_strip_image, mView, false);
WPNetworkImageView imageView = (WPNetworkImageView) view.findViewById(R.id.thumbnail_strip_image);
mView.addView(view);
String photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, mThumbnailWidth, mThumbnailHeight);
imageView.setImageUrl(photonUrl, WPNetworkImageView.ImageType.PHOTO);
// tapping a thumbnail opens the photo viewer
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
ReaderActivityLauncher.showReaderPhotoViewer(view.getContext(), imageUrl, content, view, photoViewerOptions, 0, 0);
}
});
numAdded++;
if (numAdded >= IMAGE_COUNT) {
break;
}
}
if (mView.getVisibility() != View.VISIBLE) {
AniUtils.fadeIn(mView, AniUtils.Duration.SHORT);
}
}
use of org.wordpress.android.ui.reader.ReaderActivityLauncher.PhotoViewerOption in project WordPress-Android by wordpress-mobile.
the class MediaItemFragment method refreshViews.
private void refreshViews(MediaModel mediaModel) {
if (!isAdded() || mediaModel == null) {
return;
}
// check whether or not to show the edit button
String state = mediaModel.getUploadState();
mIsLocal = MediaUtils.isLocalFile(state);
if (mIsLocal && getActivity() != null) {
getActivity().invalidateOptionsMenu();
}
String caption = mediaModel.getCaption();
if (TextUtils.isEmpty(caption)) {
mCaptionView.setVisibility(View.GONE);
} else {
mCaptionView.setText(caption);
mCaptionView.setVisibility(View.VISIBLE);
}
String desc = mediaModel.getDescription();
if (TextUtils.isEmpty(desc)) {
mDescriptionView.setVisibility(View.GONE);
} else {
mDescriptionView.setText(desc);
mDescriptionView.setVisibility(View.VISIBLE);
}
mDateView.setText(mediaModel.getUploadDate());
if (getView() != null) {
TextView txtDateLabel = (TextView) getView().findViewById(R.id.media_listitem_details_date_label);
txtDateLabel.setText(mIsLocal ? R.string.media_details_label_date_added : R.string.media_details_label_date_uploaded);
}
String fileURL = mediaModel.getUrl();
String fileName = mediaModel.getFileName();
mImageUri = TextUtils.isEmpty(fileURL) ? mediaModel.getFilePath() : fileURL;
boolean isValidImage = MediaUtils.isValidImage(mImageUri);
mFileNameView.setText(fileName);
float mediaWidth = mediaModel.getWidth();
float mediaHeight = mediaModel.getHeight();
// image and dimensions
if (isValidImage) {
int screenWidth = DisplayUtils.getDisplayPixelWidth(getActivity());
int screenHeight = DisplayUtils.getDisplayPixelHeight(getActivity());
// determine size for display
int imageWidth;
int imageHeight;
boolean isFullWidth;
if (mediaWidth == 0 || mediaHeight == 0) {
imageWidth = screenWidth;
imageHeight = screenHeight / 2;
isFullWidth = true;
} else if (mediaWidth > mediaHeight) {
float ratio = mediaHeight / mediaWidth;
imageWidth = Math.min(screenWidth, (int) mediaWidth);
imageHeight = (int) (imageWidth * ratio);
isFullWidth = (imageWidth == screenWidth);
} else {
float ratio = mediaWidth / mediaHeight;
imageHeight = Math.min(screenHeight / 2, (int) mediaHeight);
imageWidth = (int) (imageHeight * ratio);
isFullWidth = false;
}
// set the imageView's parent height to match the image so it takes up space while
// the image is loading
FrameLayout frameView = (FrameLayout) getView().findViewById(R.id.layout_image_frame);
frameView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, imageHeight));
// add padding to the frame if the image isn't full-width
if (!isFullWidth) {
int hpadding = getResources().getDimensionPixelSize(R.dimen.content_margin);
int vpadding = getResources().getDimensionPixelSize(R.dimen.margin_extra_large);
frameView.setPadding(hpadding, vpadding, hpadding, vpadding);
}
if (mIsLocal) {
final String filePath = mediaModel.getFilePath();
loadLocalImage(mImageView, filePath, imageWidth, imageHeight);
} else {
// Allow non-private wp.com and Jetpack blogs to use photon to get a higher res thumbnail
String thumbnailURL;
if (SiteUtils.isPhotonCapable(mSite)) {
thumbnailURL = StringUtils.getPhotonUrl(mImageUri, imageWidth);
} else {
thumbnailURL = UrlUtils.removeQuery(mImageUri) + "?w=" + imageWidth;
}
mImageView.setImageUrl(thumbnailURL, WPNetworkImageView.ImageType.PHOTO);
}
} else {
// not an image so show placeholder icon
int placeholderResId = WordPressMediaUtils.getPlaceholder(mImageUri);
mImageView.setDefaultImageResId(placeholderResId);
mImageView.showDefaultImage();
}
// show dimens & file ext together
String dimens = (mediaWidth > 0 && mediaHeight > 0) ? (int) mediaWidth + " x " + (int) mediaHeight : null;
String fileExt = TextUtils.isEmpty(fileURL) ? null : fileURL.replaceAll(".*\\.(\\w+)$", "$1").toUpperCase();
boolean hasDimens = !TextUtils.isEmpty(dimens);
boolean hasExt = !TextUtils.isEmpty(fileExt);
if (hasDimens & hasExt) {
mFileTypeView.setText(fileExt + ", " + dimens);
mFileTypeView.setVisibility(View.VISIBLE);
} else if (hasExt) {
mFileTypeView.setText(fileExt);
mFileTypeView.setVisibility(View.VISIBLE);
} else {
mFileTypeView.setVisibility(View.GONE);
}
// enable fullscreen photo for non-local
if (!mIsLocal && isValidImage) {
mImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EnumSet<PhotoViewerOption> imageOptions = EnumSet.noneOf(PhotoViewerOption.class);
if (mSite.isPrivate()) {
imageOptions.add(PhotoViewerOption.IS_PRIVATE_IMAGE);
}
ReaderActivityLauncher.showReaderPhotoViewer(v.getContext(), mImageUri, imageOptions);
}
});
}
}
Aggregations