Search in sources :

Example 6 with ImageLoadingProgressListener

use of com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener 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 7 with ImageLoadingProgressListener

use of com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener 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)

Example 8 with ImageLoadingProgressListener

use of com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener in project Slide by ccrama.

the class AlbumPager method loadImage.

private static void loadImage(final View rootView, Fragment f, String url, boolean single) {
    final SubsamplingScaleImageView image = (SubsamplingScaleImageView) rootView.findViewById(R.id.image);
    image.setMinimumDpi(70);
    image.setMinimumTileDpi(240);
    ImageView fakeImage = new ImageView(f.getActivity());
    final TextView size = (TextView) rootView.findViewById(R.id.size);
    fakeImage.setLayoutParams(new LinearLayout.LayoutParams(image.getWidth(), image.getHeight()));
    fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
    ((Reddit) f.getActivity().getApplication()).getImageLoader().displayImage(url, new ImageViewAware(fakeImage), new DisplayImageOptions.Builder().resetViewBeforeLoading(true).cacheOnDisk(true).imageScaleType(single ? ImageScaleType.NONE : ImageScaleType.NONE_SAFE).cacheInMemory(false).build(), new ImageLoadingListener() {

        private View mView;

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

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

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            size.setVisibility(View.GONE);
            image.setImage(ImageSource.bitmap(loadedImage));
            (rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
        }

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

        @Override
        public void onProgressUpdate(String imageUri, View view, int current, int total) {
            size.setText(readableFileSize(total));
            ((ProgressBar) rootView.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) SubsamplingScaleImageView(me.ccrama.redditslide.Views.SubsamplingScaleImageView) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) GridView(android.widget.GridView) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) MediaVideoView(me.ccrama.redditslide.Views.MediaVideoView) SubsamplingScaleImageView(me.ccrama.redditslide.Views.SubsamplingScaleImageView) Bitmap(android.graphics.Bitmap) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) SubsamplingScaleImageView(me.ccrama.redditslide.Views.SubsamplingScaleImageView) LinearLayout(android.widget.LinearLayout)

Example 9 with ImageLoadingProgressListener

use of com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener in project LibreraReader by foobnix.

the class ImageLoader method loadImage.

/**
 * Adds load image task to execution pool. Image will be returned with
 * {@link ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)}
 * callback}. <br />
 * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be
 * called before this method call
 *
 * @param uri
 *            Image URI (i.e. "http://site.com/image.png",
 *            "file:///mnt/sdcard/image.png")
 * @param targetImageSize
 *            Minimal size for {@link Bitmap} which will be returned in
 *            {@linkplain ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)}
 *            callback}. Downloaded image will be decoded and scaled to
 *            {@link Bitmap} of the size which is <b>equal or larger</b>
 *            (usually a bit larger) than incoming targetImageSize.
 * @param options
 *            {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions
 *            Options} for image decoding and displaying. If <b>null</b> -
 *            default display image options
 *            {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions)
 *            from configuration} will be used.<br />
 * @param listener
 *            {@linkplain ImageLoadingListener Listener} for image loading
 *            process. Listener fires events on UI thread if this method is
 *            called on UI thread.
 * @param progressListener
 *            {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener
 *            Listener} for image loading progress. Listener fires events on
 *            UI thread if this method is called on UI thread. Caching on
 *            disk should be enabled in
 *            {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions
 *            options} to make this listener work.
 * @throws IllegalStateException
 *             if {@link #init(ImageLoaderConfiguration)} method wasn't
 *             called before
 */
public int loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
    checkConfiguration();
    if (targetImageSize == null) {
        targetImageSize = configuration.getMaxImageSize();
    }
    if (options == null) {
        options = configuration.defaultDisplayImageOptions;
    }
    NonViewAware imageAware = new NonViewAware(uri, targetImageSize, ViewScaleType.CROP);
    displayImage(uri, imageAware, options, listener, progressListener);
    return imageAware.getId();
}
Also used : NonViewAware(com.nostra13.universalimageloader.core.imageaware.NonViewAware)

Example 10 with ImageLoadingProgressListener

use of com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener in project Android-Universal-Image-Loader by nostra13.

the class ImageLoader method loadImage.

/**
 * Adds load image task to execution pool. Image will be returned with
 * {@link ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}.
 * <br />
 * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
 *
 * @param uri              Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
 * @param targetImageSize  Minimal size for {@link Bitmap} which will be returned in
 *                         {@linkplain ImageLoadingListener#onLoadingComplete(String, android.view.View,
 *                         android.graphics.Bitmap)} callback}. Downloaded image will be decoded
 *                         and scaled to {@link Bitmap} of the size which is <b>equal or larger</b> (usually a bit
 *                         larger) than incoming targetImageSize.
 * @param options          {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions Options} for image
 *                         decoding and displaying. If <b>null</b> - default display image options
 *                         {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions)
 *                         from configuration} will be used.<br />
 * @param listener         {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires
 *                         events on UI thread if this method is called on UI thread.
 * @param progressListener {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener
 *                         Listener} for image loading progress. Listener fires events on UI thread if this method
 *                         is called on UI thread. Caching on disk should be enabled in
 *                         {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions options} to make
 *                         this listener work.
 * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
 */
public void loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
    checkConfiguration();
    if (targetImageSize == null) {
        targetImageSize = configuration.getMaxImageSize();
    }
    if (options == null) {
        options = configuration.defaultDisplayImageOptions;
    }
    NonViewAware imageAware = new NonViewAware(uri, targetImageSize, ViewScaleType.CROP);
    displayImage(uri, imageAware, options, listener, progressListener);
}
Also used : NonViewAware(com.nostra13.universalimageloader.core.imageaware.NonViewAware)

Aggregations

Bitmap (android.graphics.Bitmap)8 View (android.view.View)8 ImageView (android.widget.ImageView)7 LinearLayout (android.widget.LinearLayout)7 FailReason (com.nostra13.universalimageloader.core.assist.FailReason)7 ImageViewAware (com.nostra13.universalimageloader.core.imageaware.ImageViewAware)7 ImageLoadingListener (com.nostra13.universalimageloader.core.listener.ImageLoadingListener)7 ImageLoadingProgressListener (com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener)7 Handler (android.os.Handler)5 File (java.io.File)5 IOException (java.io.IOException)5 Reddit (me.ccrama.redditslide.Reddit)5 MediaVideoView (me.ccrama.redditslide.Views.MediaVideoView)5 SubsamplingScaleImageView (me.ccrama.redditslide.Views.SubsamplingScaleImageView)5 ProgressBar (android.widget.ProgressBar)4 ValueAnimator (android.animation.ValueAnimator)3 GridView (android.widget.GridView)3 TextView (android.widget.TextView)3 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)3 AdapterView (android.widget.AdapterView)2