Search in sources :

Example 6 with Reddit

use of me.ccrama.redditslide.Reddit in project Slide by ccrama.

the class ListViewRemoteViewsFactory method getViewAt.

// Given the position (index) of a WidgetItem in the array, use the item's text value in
// combination with the app widget item XML file to construct a RemoteViews object.
public RemoteViews getViewAt(int position) {
    // position will always range from 0 to getCount() - 1.
    // Construct a RemoteViews item based on the app widget item XML file, and set the
    // text based on the position.
    int view = R.layout.submission_widget_light;
    switch(SubredditWidgetProvider.getViewType(id, mContext)) {
        case 1:
        case 0:
            if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
                view = R.layout.submission_widget_light;
            } else {
                view = R.layout.submission_widget;
            }
            break;
        case 2:
            if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
                view = R.layout.submission_widget_compact_light;
            } else {
                view = R.layout.submission_widget_compact;
            }
            break;
    }
    final RemoteViews rv = new RemoteViews(mContext.getPackageName(), view);
    try {
        // feed row
        Submission data = records.get(position);
        rv.setTextViewText(R.id.title, Html.fromHtml(data.getTitle()));
        rv.setTextViewText(R.id.score, data.getScore() + "");
        rv.setTextViewText(R.id.comments, data.getCommentCount() + "");
        rv.setTextViewText(R.id.information, data.getAuthor() + " " + TimeUtils.getTimeAgo(data.getCreated().getTime(), mContext));
        rv.setTextViewText(R.id.subreddit, data.getSubredditName());
        rv.setTextColor(R.id.subreddit, Palette.getColor(data.getSubredditName()));
        if (SubredditWidgetProvider.getViewType(id, mContext) == 1) {
            Thumbnails s = data.getThumbnails();
            rv.setViewVisibility(R.id.thumbimage2, View.GONE);
            if (s != null && s.getVariations() != null && s.getSource() != null) {
                rv.setImageViewBitmap(R.id.bigpic, ((Reddit) mContext.getApplicationContext()).getImageLoader().loadImageSync(Html.fromHtml(data.getThumbnails().getSource().getUrl()).toString()));
                rv.setViewVisibility(R.id.bigpic, View.VISIBLE);
            } else {
                rv.setViewVisibility(R.id.bigpic, View.GONE);
            }
        } else {
            if (SubredditWidgetProvider.getViewType(id, mContext) != 2) {
                rv.setViewVisibility(R.id.bigpic, View.GONE);
            }
            if (data.getThumbnailType() == Submission.ThumbnailType.URL) {
                rv.setImageViewBitmap(R.id.thumbimage2, ((Reddit) mContext.getApplicationContext()).getImageLoader().loadImageSync(data.getThumbnail()));
                rv.setViewVisibility(R.id.thumbimage2, View.VISIBLE);
            } else {
                rv.setViewVisibility(R.id.thumbimage2, View.GONE);
            }
        }
        switch(SubredditWidgetProvider.getViewType(id, mContext)) {
            case 1:
            case 0:
                if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
                } else {
                    rv.setTextColor(R.id.title, Color.WHITE);
                    rv.setTextColor(R.id.score, Color.WHITE);
                    rv.setTextColor(R.id.comments, Color.WHITE);
                    rv.setTextColor(R.id.information, Color.WHITE);
                }
                break;
            case 2:
                if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
                } else {
                    rv.setTextColor(R.id.title, Color.WHITE);
                    rv.setTextColor(R.id.score, Color.WHITE);
                    rv.setTextColor(R.id.comments, Color.WHITE);
                    rv.setTextColor(R.id.information, Color.WHITE);
                }
                break;
        }
        Bundle infos = new Bundle();
        infos.putString(OpenContent.EXTRA_URL, data.getPermalink());
        infos.putBoolean("popup", true);
        final Intent activityIntent = new Intent();
        activityIntent.putExtras(infos);
        activityIntent.setAction(data.getTitle());
        rv.setOnClickFillInIntent(R.id.card, activityIntent);
    } catch (Exception e) {
    }
    return rv;
}
Also used : RemoteViews(android.widget.RemoteViews) Submission(net.dean.jraw.models.Submission) Reddit(me.ccrama.redditslide.Reddit) Bundle(android.os.Bundle) Thumbnails(net.dean.jraw.models.Thumbnails) Intent(android.content.Intent)

Example 7 with Reddit

use of me.ccrama.redditslide.Reddit in project Slide by ccrama.

the class MediaView method displayImage.

public void displayImage(final String urlB) {
    LogUtil.v("Displaying " + urlB);
    final String url = StringEscapeUtils.unescapeHtml4(urlB);
    if (!imageShown) {
        actuallyLoaded = url;
        final SubsamplingScaleImageView i = (SubsamplingScaleImageView) findViewById(R.id.submission_image);
        i.setMinimumDpi(70);
        i.setMinimumTileDpi(240);
        final ProgressBar bar = (ProgressBar) findViewById(R.id.progress);
        bar.setIndeterminate(false);
        bar.setProgress(0);
        final Handler handler = new Handler();
        final Runnable progressBarDelayRunner = new Runnable() {

            public void run() {
                bar.setVisibility(View.VISIBLE);
            }
        };
        handler.postDelayed(progressBarDelayRunner, 500);
        ImageView fakeImage = new ImageView(MediaView.this);
        fakeImage.setLayoutParams(new LinearLayout.LayoutParams(i.getWidth(), i.getHeight()));
        fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
        File f = ((Reddit) getApplicationContext()).getImageLoader().getDiscCache().get(url);
        if (f != null && f.exists()) {
            imageShown = true;
            i.setOnImageEventListener(new SubsamplingScaleImageView.OnImageEventListener() {

                @Override
                public void onReady() {
                }

                @Override
                public void onImageLoaded() {
                }

                @Override
                public void onPreviewLoadError(Exception e) {
                }

                @Override
                public void onImageLoadError(Exception e) {
                    imageShown = false;
                    LogUtil.v("No image displayed");
                }

                @Override
                public void onTileLoadError(Exception e) {
                }
            });
            try {
                i.setImage(ImageSource.uri(f.getAbsolutePath()));
            } catch (Exception e) {
                imageShown = false;
            // todo  i.setImage(ImageSource.bitmap(loadedImage));
            }
            (findViewById(R.id.progress)).setVisibility(View.GONE);
            handler.removeCallbacks(progressBarDelayRunner);
            previous = i.scale;
            final float base = i.scale;
            i.postDelayed(new Runnable() {

                @Override
                public void run() {
                    i.setOnZoomChangedListener(new SubsamplingScaleImageView.OnZoomChangedListener() {

                        @Override
                        public void onZoomLevelChanged(float zoom) {
                            if (zoom > previous && !hidden && zoom > base) {
                                hidden = true;
                                final View base = findViewById(R.id.gifheader);
                                ValueAnimator va = ValueAnimator.ofFloat(1.0f, 0.2f);
                                // in millis
                                int mDuration = 250;
                                va.setDuration(mDuration);
                                va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                                    public void onAnimationUpdate(ValueAnimator animation) {
                                        Float value = (Float) animation.getAnimatedValue();
                                        base.setAlpha(value);
                                    }
                                });
                                va.start();
                            // hide
                            } else if (zoom <= previous && hidden) {
                                hidden = false;
                                final View base = findViewById(R.id.gifheader);
                                ValueAnimator va = ValueAnimator.ofFloat(0.2f, 1.0f);
                                // in millis
                                int mDuration = 250;
                                va.setDuration(mDuration);
                                va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                                    public void onAnimationUpdate(ValueAnimator animation) {
                                        Float value = (Float) animation.getAnimatedValue();
                                        base.setAlpha(value);
                                    }
                                });
                                va.start();
                            // unhide
                            }
                            previous = zoom;
                        }
                    });
                }
            }, 2000);
        } else {
            final TextView size = (TextView) findViewById(R.id.size);
            ((Reddit) getApplication()).getImageLoader().displayImage(url, new ImageViewAware(fakeImage), new DisplayImageOptions.Builder().resetViewBeforeLoading(true).cacheOnDisk(true).imageScaleType(ImageScaleType.NONE).cacheInMemory(false).build(), new ImageLoadingListener() {

                private View mView;

                @Override
                public void onLoadingStarted(String imageUri, View view) {
                    imageShown = true;
                    size.setVisibility(View.VISIBLE);
                    mView = view;
                }

                @Override
                public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    Log.v(LogUtil.getTag(), "LOADING FAILED");
                    imageShown = false;
                }

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    imageShown = true;
                    size.setVisibility(View.GONE);
                    File f = ((Reddit) getApplicationContext()).getImageLoader().getDiscCache().get(url);
                    if (f != null && f.exists()) {
                        i.setImage(ImageSource.uri(f.getAbsolutePath()));
                    } else {
                        i.setImage(ImageSource.bitmap(loadedImage));
                    }
                    (findViewById(R.id.progress)).setVisibility(View.GONE);
                    handler.removeCallbacks(progressBarDelayRunner);
                    previous = i.scale;
                    final float base = i.scale;
                    i.setOnZoomChangedListener(new SubsamplingScaleImageView.OnZoomChangedListener() {

                        @Override
                        public void onZoomLevelChanged(float zoom) {
                            if (zoom > previous && !hidden && zoom > base) {
                                hidden = true;
                                final View base = findViewById(R.id.gifheader);
                                ValueAnimator va = ValueAnimator.ofFloat(1.0f, 0.2f);
                                // in millis
                                int mDuration = 250;
                                va.setDuration(mDuration);
                                va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                                    public void onAnimationUpdate(ValueAnimator animation) {
                                        Float value = (Float) animation.getAnimatedValue();
                                        base.setAlpha(value);
                                    }
                                });
                                va.start();
                            // hide
                            } else if (zoom <= previous && hidden) {
                                hidden = false;
                                final View base = findViewById(R.id.gifheader);
                                ValueAnimator va = ValueAnimator.ofFloat(0.2f, 1.0f);
                                // in millis
                                int mDuration = 250;
                                va.setDuration(mDuration);
                                va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                                    public void onAnimationUpdate(ValueAnimator animation) {
                                        Float value = (Float) animation.getAnimatedValue();
                                        base.setAlpha(value);
                                    }
                                });
                                va.start();
                            // unhide
                            }
                            previous = zoom;
                        }
                    });
                }

                @Override
                public void onLoadingCancelled(String imageUri, View view) {
                    Log.v(LogUtil.getTag(), "LOADING CANCELLED");
                }
            }, new ImageLoadingProgressListener() {

                @Override
                public void onProgressUpdate(String imageUri, View view, int current, int total) {
                    size.setText(readableFileSize(total));
                    ((ProgressBar) findViewById(R.id.progress)).setProgress(Math.round(100.0f * current / total));
                }
            });
        }
    }
}
Also used : ImageLoadingProgressListener(com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ValueAnimator(android.animation.ValueAnimator) Bitmap(android.graphics.Bitmap) Reddit(me.ccrama.redditslide.Reddit) TextView(android.widget.TextView) ImageView(android.widget.ImageView) SubsamplingScaleImageView(me.ccrama.redditslide.Views.SubsamplingScaleImageView) ProgressBar(android.widget.ProgressBar) ImageViewAware(com.nostra13.universalimageloader.core.imageaware.ImageViewAware) ImageLoadingListener(com.nostra13.universalimageloader.core.listener.ImageLoadingListener) Handler(android.os.Handler) SubsamplingScaleImageView(me.ccrama.redditslide.Views.SubsamplingScaleImageView) ImageView(android.widget.ImageView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) View(android.view.View) TextView(android.widget.TextView) MediaVideoView(me.ccrama.redditslide.Views.MediaVideoView) SubsamplingScaleImageView(me.ccrama.redditslide.Views.SubsamplingScaleImageView) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) File(java.io.File) LinearLayout(android.widget.LinearLayout)

Example 8 with Reddit

use of me.ccrama.redditslide.Reddit in project Slide by ccrama.

the class HeaderImageLinkView method doImageAndText.

public void doImageAndText(final Submission submission, boolean full, String baseSub, boolean news) {
    boolean fullImage = ContentType.fullImage(type);
    thumbUsed = false;
    setVisibility(View.VISIBLE);
    String url = "";
    boolean forceThumb = false;
    thumbImage2.setImageResource(android.R.color.transparent);
    boolean loadLq = (((!NetworkUtil.isConnectedWifi(getContext()) && SettingValues.lowResMobile) || SettingValues.lowResAlways));
    if (type == ContentType.Type.SELF && SettingValues.hideSelftextLeadImage || SettingValues.noImages && submission.isSelfPost()) {
        setVisibility(View.GONE);
        if (wrapArea != null)
            wrapArea.setVisibility(View.GONE);
        thumbImage2.setVisibility(View.GONE);
    } else {
        if (submission.getThumbnails() != null) {
            int height = submission.getThumbnails().getSource().getHeight();
            int width = submission.getThumbnails().getSource().getWidth();
            if (full) {
                if (!fullImage && height < dpToPx(50) && type != ContentType.Type.SELF) {
                    forceThumb = true;
                } else if (SettingValues.cropImage) {
                    backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, dpToPx(200)));
                } else {
                    double h = getHeightFromAspectRatio(height, width);
                    if (h != 0) {
                        if (h > 3200) {
                            backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 3200));
                        } else {
                            backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) h));
                        }
                    } else {
                        backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                    }
                }
            } else if (SettingValues.bigPicCropped) {
                if (!fullImage && height < dpToPx(50)) {
                    forceThumb = true;
                } else {
                    backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, dpToPx(200)));
                }
            } else if (fullImage || height >= dpToPx(50)) {
                double h = getHeightFromAspectRatio(height, width);
                if (h != 0) {
                    if (h > 3200) {
                        backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 3200));
                    } else {
                        backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) h));
                    }
                } else {
                    backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                }
            } else {
                forceThumb = true;
            }
        }
        JsonNode thumbnail = submission.getDataNode().get("thumbnail");
        Submission.ThumbnailType thumbnailType;
        if (!submission.getDataNode().get("thumbnail").isNull()) {
            thumbnailType = submission.getThumbnailType();
        } else {
            thumbnailType = Submission.ThumbnailType.NONE;
        }
        JsonNode node = submission.getDataNode();
        if (!SettingValues.ignoreSubSetting && node != null && node.has("sr_detail") && node.get("sr_detail").has("show_media") && !node.get("sr_detail").get("show_media").asBoolean()) {
            thumbnailType = Submission.ThumbnailType.NONE;
        }
        if (SettingValues.noImages && loadLq) {
            setVisibility(View.GONE);
            if (!full && !submission.isSelfPost()) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                if (full && !submission.isSelfPost())
                    wrapArea.setVisibility(View.VISIBLE);
            }
            thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.web));
            thumbUsed = true;
        } else if (submission.isNsfw() && SettingValues.getIsNSFWEnabled() || (baseSub != null && submission.isNsfw() && SettingValues.hideNSFWCollection && (baseSub.equals("frontpage") || baseSub.equals("all") || baseSub.contains("+") || baseSub.equals("popular")))) {
            setVisibility(View.GONE);
            if (!full || forceThumb) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            if (submission.isSelfPost() && full) {
                wrapArea.setVisibility(View.GONE);
            } else {
                thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.nsfw));
                thumbUsed = true;
            }
            loadedUrl = submission.getUrl();
        } else if (submission.getDataNode().get("spoiler").asBoolean()) {
            setVisibility(View.GONE);
            if (!full || forceThumb) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            if (submission.isSelfPost() && full) {
                wrapArea.setVisibility(View.GONE);
            } else {
                thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.spoiler));
                thumbUsed = true;
            }
            loadedUrl = submission.getUrl();
        } else if (type != ContentType.Type.IMAGE && type != ContentType.Type.SELF && (!thumbnail.isNull() && (thumbnailType != Submission.ThumbnailType.URL)) || thumbnail.asText().isEmpty() && !submission.isSelfPost()) {
            setVisibility(View.GONE);
            if (!full) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.web));
            thumbUsed = true;
            loadedUrl = submission.getUrl();
        } else if (type == ContentType.Type.IMAGE && !thumbnail.isNull() && !thumbnail.asText().isEmpty()) {
            if (loadLq && submission.getThumbnails() != null && submission.getThumbnails().getVariations() != null && submission.getThumbnails().getVariations().length > 0) {
                if (ContentType.isImgurImage(submission.getUrl())) {
                    url = submission.getUrl();
                    url = url.substring(0, url.lastIndexOf(".")) + (SettingValues.lqLow ? "m" : (SettingValues.lqMid ? "l" : "h")) + url.substring(url.lastIndexOf("."), url.length());
                } else {
                    int length = submission.getThumbnails().getVariations().length;
                    if (SettingValues.lqLow && length >= 3) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[2].getUrl()).toString();
                    } else if (SettingValues.lqMid && length >= 4) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[3].getUrl()).toString();
                    } else if (length >= 5) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[length - 1].getUrl()).toString();
                    } else {
                        url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
                    }
                }
                lq = true;
            } else {
                if (submission.getDataNode().has("preview") && submission.getDataNode().get("preview").get("images").get(0).get("source").has("height")) {
                    // Load the preview image which has probably already been cached in memory instead of the direct link
                    url = submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
                } else {
                    url = submission.getUrl();
                }
            }
            if (!full && !SettingValues.isPicsEnabled(baseSub) || forceThumb) {
                if (!submission.isSelfPost() || full) {
                    if (!full) {
                        thumbImage2.setVisibility(View.VISIBLE);
                    } else {
                        wrapArea.setVisibility(View.VISIBLE);
                    }
                    loadedUrl = url;
                    if (!full) {
                        ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2);
                    } else {
                        ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2, bigOptions);
                    }
                } else {
                    thumbImage2.setVisibility(View.GONE);
                }
                setVisibility(View.GONE);
            } else {
                loadedUrl = url;
                if (!full) {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop);
                } else {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop, bigOptions);
                }
                setVisibility(View.VISIBLE);
                if (!full) {
                    thumbImage2.setVisibility(View.GONE);
                } else {
                    wrapArea.setVisibility(View.GONE);
                }
            }
        } else if (submission.getThumbnails() != null) {
            if (loadLq && submission.getThumbnails().getVariations().length != 0) {
                if (ContentType.isImgurImage(submission.getUrl())) {
                    url = submission.getUrl();
                    url = url.substring(0, url.lastIndexOf(".")) + (SettingValues.lqLow ? "m" : (SettingValues.lqMid ? "l" : "h")) + url.substring(url.lastIndexOf("."), url.length());
                } else {
                    int length = submission.getThumbnails().getVariations().length;
                    if (SettingValues.lqLow && length >= 3) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[2].getUrl()).toString();
                    } else if (SettingValues.lqMid && length >= 4) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[3].getUrl()).toString();
                    } else if (length >= 5) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[length - 1].getUrl()).toString();
                    } else {
                        url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
                    }
                }
                lq = true;
            } else {
                url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
            }
            if (!SettingValues.isPicsEnabled(baseSub) && !full || forceThumb || (news && submission.getScore() < 5000)) {
                if (!full) {
                    thumbImage2.setVisibility(View.VISIBLE);
                } else {
                    wrapArea.setVisibility(View.VISIBLE);
                }
                loadedUrl = url;
                ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2);
                setVisibility(View.GONE);
            } else {
                loadedUrl = url;
                if (!full) {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop);
                } else {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop, bigOptions);
                }
                setVisibility(View.VISIBLE);
                if (!full) {
                    thumbImage2.setVisibility(View.GONE);
                } else {
                    wrapArea.setVisibility(View.GONE);
                }
            }
        } else if (!thumbnail.isNull() && submission.getThumbnail() != null && (submission.getThumbnailType() == Submission.ThumbnailType.URL || (!thumbnail.isNull() && submission.isNsfw() && SettingValues.getIsNSFWEnabled()))) {
            if (!full) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            loadedUrl = url;
            ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2);
            setVisibility(View.GONE);
        } else {
            if (!full) {
                thumbImage2.setVisibility(View.GONE);
            } else {
                wrapArea.setVisibility(View.GONE);
            }
            setVisibility(View.GONE);
        }
        if (full) {
            if (wrapArea.getVisibility() == View.VISIBLE) {
                title = secondTitle;
                info = secondSubTitle;
                setBottomSheet(wrapArea, submission, full);
            } else {
                title = findViewById(R.id.textimage);
                info = findViewById(R.id.subtextimage);
                if (forceThumb || (submission.isNsfw() && submission.getThumbnailType() == Submission.ThumbnailType.NSFW || type != ContentType.Type.IMAGE && type != ContentType.Type.SELF && !submission.getDataNode().get("thumbnail").isNull() && (submission.getThumbnailType() != Submission.ThumbnailType.URL))) {
                    setBottomSheet(thumbImage2, submission, full);
                } else {
                    setBottomSheet(this, submission, full);
                }
            }
        } else {
            title = findViewById(R.id.textimage);
            info = findViewById(R.id.subtextimage);
            setBottomSheet(thumbImage2, submission, full);
            setBottomSheet(this, submission, full);
        }
        if (SettingValues.smallTag && !full && !news) {
            title = (TextView) findViewById(R.id.tag);
            findViewById(R.id.tag).setVisibility(View.VISIBLE);
            info = null;
        } else {
            findViewById(R.id.tag).setVisibility(View.GONE);
            title.setVisibility(View.VISIBLE);
            info.setVisibility(View.VISIBLE);
        }
        if (SettingValues.smallTag && !full && !news) {
            ((TransparentTagTextView) title).init(getContext());
        }
        title.setText(ContentType.getContentDescription(submission, getContext()));
        if (info != null)
            info.setText(submission.getDomain());
    }
}
Also used : Submission(net.dean.jraw.models.Submission) Reddit(me.ccrama.redditslide.Reddit) RelativeLayout(android.widget.RelativeLayout) JsonNode(com.fasterxml.jackson.databind.JsonNode) TransparentTagTextView(me.ccrama.redditslide.Views.TransparentTagTextView)

Example 9 with Reddit

use of me.ccrama.redditslide.Reddit in project Slide by ccrama.

the class PopMediaView method displayImage.

public void displayImage(final String url, final View v) {
    final SubsamplingScaleImageView i = (SubsamplingScaleImageView) v.findViewById(R.id.submission_image);
    i.setMinimumDpi(70);
    i.setMinimumTileDpi(240);
    final ProgressBar bar = (ProgressBar) v.findViewById(R.id.progress);
    bar.setIndeterminate(false);
    bar.setProgress(0);
    final Handler handler = new Handler();
    final Runnable progressBarDelayRunner = new Runnable() {

        public void run() {
            bar.setVisibility(View.VISIBLE);
        }
    };
    handler.postDelayed(progressBarDelayRunner, 500);
    ImageView fakeImage = new ImageView(v.getContext());
    fakeImage.setLayoutParams(new LinearLayout.LayoutParams(i.getWidth(), i.getHeight()));
    fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
    File f = ((Reddit) v.getContext().getApplicationContext()).getImageLoader().getDiscCache().get(url);
    if (f != null && f.exists()) {
        try {
            i.setImage(ImageSource.uri(f.getAbsolutePath()));
        } catch (Exception e) {
        // todo  i.setImage(ImageSource.bitmap(loadedImage));
        }
        (v.findViewById(R.id.progress)).setVisibility(View.GONE);
        handler.removeCallbacks(progressBarDelayRunner);
    } else {
        ((Reddit) v.getContext().getApplicationContext()).getImageLoader().displayImage(url, new ImageViewAware(fakeImage), new DisplayImageOptions.Builder().resetViewBeforeLoading(true).cacheOnDisk(true).imageScaleType(ImageScaleType.NONE).cacheInMemory(false).build(), new ImageLoadingListener() {

            private View mView;

            @Override
            public void onLoadingStarted(String imageUri, View view) {
                mView = view;
            }

            @Override
            public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                Log.v(LogUtil.getTag(), "LOADING FAILED");
            }

            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                File f = ((Reddit) v.getContext().getApplicationContext()).getImageLoader().getDiscCache().get(url);
                if (f != null && f.exists()) {
                    i.setImage(ImageSource.uri(f.getAbsolutePath()));
                } else {
                    i.setImage(ImageSource.bitmap(loadedImage));
                }
                (v.findViewById(R.id.progress)).setVisibility(View.GONE);
                handler.removeCallbacks(progressBarDelayRunner);
            }

            @Override
            public void onLoadingCancelled(String imageUri, View view) {
                Log.v(LogUtil.getTag(), "LOADING CANCELLED");
            }
        }, new ImageLoadingProgressListener() {

            @Override
            public void onProgressUpdate(String imageUri, View view, int current, int total) {
                ((ProgressBar) v.findViewById(R.id.progress)).setProgress(Math.round(100.0f * current / total));
            }
        });
    }
}
Also used : ImageViewAware(com.nostra13.universalimageloader.core.imageaware.ImageViewAware) ImageLoadingListener(com.nostra13.universalimageloader.core.listener.ImageLoadingListener) ImageLoadingProgressListener(com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener) Handler(android.os.Handler) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Bitmap(android.graphics.Bitmap) Reddit(me.ccrama.redditslide.Reddit) ImageView(android.widget.ImageView) ProgressBar(android.widget.ProgressBar) File(java.io.File) LinearLayout(android.widget.LinearLayout)

Example 10 with Reddit

use of me.ccrama.redditslide.Reddit in project Slide by ccrama.

the class MediaFragment method displayImage.

public void displayImage(final String urlB) {
    final String url = StringEscapeUtils.unescapeHtml4(urlB);
    if (!imageShown) {
        actuallyLoaded = url;
        final SubsamplingScaleImageView i = (SubsamplingScaleImageView) rootView.findViewById(R.id.submission_image);
        i.setMinimumDpi(70);
        i.setMinimumTileDpi(240);
        final ProgressBar bar = (ProgressBar) rootView.findViewById(R.id.progress);
        bar.setIndeterminate(false);
        LogUtil.v("Displaying image " + url);
        bar.setProgress(0);
        final Handler handler = new Handler();
        final Runnable progressBarDelayRunner = new Runnable() {

            public void run() {
                bar.setVisibility(View.VISIBLE);
            }
        };
        handler.postDelayed(progressBarDelayRunner, 500);
        ImageView fakeImage = new ImageView(getActivity());
        fakeImage.setLayoutParams(new LinearLayout.LayoutParams(i.getWidth(), i.getHeight()));
        fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
        File f = ((Reddit) getActivity().getApplicationContext()).getImageLoader().getDiscCache().get(url);
        if (f != null && f.exists()) {
            imageShown = true;
            try {
                i.setImage(ImageSource.uri(f.getAbsolutePath()));
            } catch (Exception e) {
            // todo  i.setImage(ImageSource.bitmap(loadedImage));
            }
            (rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
            handler.removeCallbacks(progressBarDelayRunner);
            previous = i.scale;
            final float base = i.scale;
            i.setOnZoomChangedListener(new SubsamplingScaleImageView.OnZoomChangedListener() {

                @Override
                public void onZoomLevelChanged(float zoom) {
                    if (zoom > previous && !hidden && zoom > base) {
                        hidden = true;
                        final View base = rootView.findViewById(R.id.base);
                        ValueAnimator va = ValueAnimator.ofFloat(1.0f, 0.2f);
                        // in millis
                        int mDuration = 250;
                        va.setDuration(mDuration);
                        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                            public void onAnimationUpdate(ValueAnimator animation) {
                                Float value = (Float) animation.getAnimatedValue();
                                base.setAlpha(value);
                            }
                        });
                        va.start();
                    // hide
                    } else if (zoom <= previous && hidden) {
                        hidden = false;
                        final View base = rootView.findViewById(R.id.base);
                        ValueAnimator va = ValueAnimator.ofFloat(0.2f, 1.0f);
                        // in millis
                        int mDuration = 250;
                        va.setDuration(mDuration);
                        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                            public void onAnimationUpdate(ValueAnimator animation) {
                                Float value = (Float) animation.getAnimatedValue();
                                base.setAlpha(value);
                            }
                        });
                        va.start();
                    // unhide
                    }
                    previous = zoom;
                }
            });
        } else {
            ((Reddit) getActivity().getApplicationContext()).getImageLoader().displayImage(url, new ImageViewAware(fakeImage), new DisplayImageOptions.Builder().resetViewBeforeLoading(true).cacheOnDisk(true).imageScaleType(ImageScaleType.NONE).cacheInMemory(false).build(), new ImageLoadingListener() {

                private View mView;

                @Override
                public void onLoadingStarted(String imageUri, View view) {
                    imageShown = true;
                    mView = view;
                }

                @Override
                public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    Log.v(LogUtil.getTag(), "LOADING FAILED");
                }

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    imageShown = true;
                    File f = null;
                    if (getActivity() != null) {
                        f = ((Reddit) getActivity().getApplicationContext()).getImageLoader().getDiscCache().get(url);
                    }
                    if (f != null && f.exists()) {
                        i.setImage(ImageSource.uri(f.getAbsolutePath()));
                    } else {
                        i.setImage(ImageSource.bitmap(loadedImage));
                    }
                    (rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
                    handler.removeCallbacks(progressBarDelayRunner);
                    previous = i.scale;
                    final float base = i.scale;
                    i.setOnZoomChangedListener(new SubsamplingScaleImageView.OnZoomChangedListener() {

                        @Override
                        public void onZoomLevelChanged(float zoom) {
                            if (zoom > previous && !hidden && zoom > base) {
                                hidden = true;
                                final View base = rootView.findViewById(R.id.base);
                                ValueAnimator va = ValueAnimator.ofFloat(1.0f, 0.2f);
                                // in millis
                                int mDuration = 250;
                                va.setDuration(mDuration);
                                va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                                    public void onAnimationUpdate(ValueAnimator animation) {
                                        Float value = (Float) animation.getAnimatedValue();
                                        base.setAlpha(value);
                                    }
                                });
                                va.start();
                            // hide
                            } else if (zoom <= previous && hidden) {
                                hidden = false;
                                final View base = rootView.findViewById(R.id.base);
                                ValueAnimator va = ValueAnimator.ofFloat(0.2f, 1.0f);
                                // in millis
                                int mDuration = 250;
                                va.setDuration(mDuration);
                                va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                                    public void onAnimationUpdate(ValueAnimator animation) {
                                        Float value = (Float) animation.getAnimatedValue();
                                        base.setAlpha(value);
                                    }
                                });
                                va.start();
                            // unhide
                            }
                            previous = zoom;
                        }
                    });
                }

                @Override
                public void onLoadingCancelled(String imageUri, View view) {
                    Log.v(LogUtil.getTag(), "LOADING CANCELLED");
                }
            }, new ImageLoadingProgressListener() {

                @Override
                public void onProgressUpdate(String imageUri, View view, int current, int total) {
                    ((ProgressBar) rootView.findViewById(R.id.progress)).setProgress(Math.round(100.0f * current / total));
                }
            });
        }
    }
}
Also used : ImageLoadingProgressListener(com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ValueAnimator(android.animation.ValueAnimator) Bitmap(android.graphics.Bitmap) Reddit(me.ccrama.redditslide.Reddit) ImageView(android.widget.ImageView) SubsamplingScaleImageView(me.ccrama.redditslide.Views.SubsamplingScaleImageView) ProgressBar(android.widget.ProgressBar) ImageViewAware(com.nostra13.universalimageloader.core.imageaware.ImageViewAware) ImageLoadingListener(com.nostra13.universalimageloader.core.listener.ImageLoadingListener) Handler(android.os.Handler) SubsamplingScaleImageView(me.ccrama.redditslide.Views.SubsamplingScaleImageView) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) View(android.view.View) MediaVideoView(me.ccrama.redditslide.Views.MediaVideoView) SubsamplingScaleImageView(me.ccrama.redditslide.Views.SubsamplingScaleImageView) IOException(java.io.IOException) File(java.io.File) LinearLayout(android.widget.LinearLayout)

Aggregations

Reddit (me.ccrama.redditslide.Reddit)11 View (android.view.View)9 Bitmap (android.graphics.Bitmap)8 FailReason (com.nostra13.universalimageloader.core.assist.FailReason)8 ImageLoadingListener (com.nostra13.universalimageloader.core.listener.ImageLoadingListener)8 ImageView (android.widget.ImageView)6 Handler (android.os.Handler)5 LinearLayout (android.widget.LinearLayout)5 ImageViewAware (com.nostra13.universalimageloader.core.imageaware.ImageViewAware)5 ImageLoadingProgressListener (com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener)5 File (java.io.File)5 IOException (java.io.IOException)5 Submission (net.dean.jraw.models.Submission)5 ProgressBar (android.widget.ProgressBar)4 ContentType (me.ccrama.redditslide.ContentType)4 MediaVideoView (me.ccrama.redditslide.Views.MediaVideoView)4 ValueAnimator (android.animation.ValueAnimator)3 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)3 SubsamplingScaleImageView (me.ccrama.redditslide.Views.SubsamplingScaleImageView)3 URISyntaxException (java.net.URISyntaxException)2