Search in sources :

Example 1 with ReaderImageList

use of org.wordpress.android.ui.reader.models.ReaderImageList in project WordPress-Android by wordpress-mobile.

the class ReaderImageScanner method getImageList.

/*
     * returns a list of image URLs in the content up to the max above a certain width - pass zero
     * to include all images regardless of size
     */
public ReaderImageList getImageList(int maxImageCount, int minImageWidth) {
    ReaderImageList imageList = new ReaderImageList(mIsPrivate);
    if (!mContentContainsImages) {
        return imageList;
    }
    Matcher imgMatcher = IMG_TAG_PATTERN.matcher(mContent);
    while (imgMatcher.find()) {
        String imgTag = mContent.substring(imgMatcher.start(), imgMatcher.end());
        String imageUrl = ReaderHtmlUtils.getSrcAttrValue(imgTag);
        if (minImageWidth == 0) {
            imageList.addImageUrl(imageUrl);
        } else {
            int width = Math.max(ReaderHtmlUtils.getWidthAttrValue(imgTag), ReaderHtmlUtils.getIntQueryParam(imageUrl, "w"));
            if (width >= minImageWidth) {
                imageList.addImageUrl(imageUrl);
                if (maxImageCount > 0 && imageList.size() >= maxImageCount) {
                    break;
                }
            }
        }
    }
    return imageList;
}
Also used : Matcher(java.util.regex.Matcher) ReaderImageList(org.wordpress.android.ui.reader.models.ReaderImageList)

Example 2 with ReaderImageList

use of org.wordpress.android.ui.reader.models.ReaderImageList in project WordPress-Android by wordpress-mobile.

the class ReaderPhotoViewerActivity method loadImageList.

private void loadImageList() {
    // content will be empty when viewing a single image, otherwise content is HTML
    // so parse images from it
    final ReaderImageList imageList;
    if (TextUtils.isEmpty(mContent)) {
        imageList = new ReaderImageList(mIsPrivate);
    } else {
        int minImageWidth = mIsGallery ? ReaderConstants.MIN_GALLERY_IMAGE_WIDTH : 0;
        imageList = new ReaderImageScanner(mContent, mIsPrivate).getImageList(0, minImageWidth);
    }
    // make sure initial image is in the list
    if (!TextUtils.isEmpty(mInitialImageUrl) && !imageList.hasImageUrl(mInitialImageUrl)) {
        imageList.addImageUrl(0, mInitialImageUrl);
    }
    getAdapter().setImageList(imageList, mInitialImageUrl);
}
Also used : ReaderImageScanner(org.wordpress.android.ui.reader.utils.ReaderImageScanner) ReaderImageList(org.wordpress.android.ui.reader.models.ReaderImageList)

Example 3 with ReaderImageList

use of org.wordpress.android.ui.reader.models.ReaderImageList 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);
    }
}
Also used : PhotoViewerOption(org.wordpress.android.ui.reader.ReaderActivityLauncher.PhotoViewerOption) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) LayoutInflater(android.view.LayoutInflater) ReaderImageScanner(org.wordpress.android.ui.reader.utils.ReaderImageScanner) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) View(android.view.View) ReaderImageList(org.wordpress.android.ui.reader.models.ReaderImageList)

Aggregations

ReaderImageList (org.wordpress.android.ui.reader.models.ReaderImageList)3 ReaderImageScanner (org.wordpress.android.ui.reader.utils.ReaderImageScanner)2 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 Matcher (java.util.regex.Matcher)1 PhotoViewerOption (org.wordpress.android.ui.reader.ReaderActivityLauncher.PhotoViewerOption)1 WPNetworkImageView (org.wordpress.android.widgets.WPNetworkImageView)1