Giter VIP home page Giter VIP logo

urlimageviewhelper's Introduction

This library has been deprecated, use ion instead:

http://github.com/koush/ion

UrlImageViewHelper

UrlImageViewHelper will fill an ImageView with an image that is found at a URL.

Sample Project

The sample will do a Google Image Search and load/show the results asynchronously.

Download

Download the latest JAR or grab via Maven:

<dependency>
    <groupId>com.koushikdutta.urlimageviewhelper</groupId>
    <artifactId>urlimageviewhelper</artifactId>
    <version>(insert latest version)</version>
</dependency>

Usage

UrlImageViewHelper will automatically download and manage all the web images and ImageViews. Duplicate urls will not be loaded into memory twice. Bitmap memory is managed by using a weak reference hash table, so as soon as the image is no longer used by you, it will be garbage collected automatically.

Usage is simple:

UrlImageViewHelper.setUrlDrawable(imageView, "http://example.com/image.png");

Want a placeholder image while it is being downloaded?

UrlImageViewHelper.setUrlDrawable(imageView, "http://example.com/image.png", R.drawable.placeholder);

Don't want to use a placeholder resource, but a drawable instead?

UrlImageViewHelper.setUrlDrawable(imageView, "http://example.com/image.png", drawable);

What if you want to preload images for snazzy fast loading?

UrlImageViewHelper.loadUrlDrawable(context, "http://example.com/image.png");

What if you only want to cache the images for a minute?

// Note that the 3rd argument "null" is an optional interstitial
// placeholder image.
UrlImageViewHelper.setUrlDrawable(imageView, "http://example.com/image.png", null, 60000);

UrlImageViewHelper is pretty smart. It can even load the photo for an Android contact if given a Contact Content Provider URI.

UrlImageViewHelper.setUrlDrawable(imageView, "content://com.android.contacts/contacts/1115", R.drawable.dummy_contact_photo);

FAQ

Does it work in list adapters when views are reused? (convertView)

Yes.

Featured Implementations

  • ROM Manager
  • Carbon
  • Let me know if you use this library, so I can add it to the list!

urlimageviewhelper's People

Contributors

abhishekmukherg avatar cimnine avatar dglinenko avatar easetheworld avatar jnugh avatar koush avatar pedronveloso avatar scottferg avatar seanoshea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

urlimageviewhelper's Issues

Keep showing default image, when you're trying to show something that isn't an image.

I'm using a GET method to get resized images from the server. If the user has an avatar this methods gives me the url of the resized image, but if the user doesn't have an avatar this method returns me an error page.
I'm thinking how I can modify your code for checking if what I'm downloading is an image or something else (like an html, php... file) to keep showing the default image if there's no image in the url, but I don't know how. I think it could be a good idea to modify it, it's not a bug or a problem but it can be helpful.

close() not called

I turned on strict mode
public static void activateStrictMode(Context context) {
if (Util.isDebugMode(context)) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll() // for all detectable problems
// .detectDiskReads()
// .detectDiskWrites()
// .detectNetwork()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
}
}

and got this....

9696-9705/com.sickboots.sickvideos E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:272)
at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:282)
at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:495)
at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)
at com.koushikdutta.urlimageviewhelper.HttpUrlDownloader$1.doInBackground(HttpUrlDownloader.java:51)
at com.koushikdutta.urlimageviewhelper.HttpUrlDownloader$1.doInBackground(HttpUrlDownloader.java:29)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)

How to get progress (percent) when downloading image from url

How to get progress (percent) when downloading image from url .
I think i should customize code at HttpUrlDownloader.java

Here it's what i'm going so far ::

                while (true) {
                    final URL u = new URL(thisUrl);
                    urlConnection = (HttpURLConnection) u.openConnection();
                    urlConnection.setInstanceFollowRedirects(true);

                    if (mRequestPropertiesCallback != null) {
                        final ArrayList<NameValuePair> props = mRequestPropertiesCallback.getHeadersForRequest(context, url);
                        if (props != null) {
                            for (final NameValuePair pair : props) {
                                urlConnection.addRequestProperty(pair.getName(), pair.getValue());
                            }
                        }
                    }

                    if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_MOVED_TEMP
                            && urlConnection.getResponseCode() != HttpURLConnection.HTTP_MOVED_PERM)
                        break;
                    thisUrl = urlConnection.getHeaderField("Location");
                }

                if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
                    UrlImageViewHelper.clog("Response Code: " + urlConnection.getResponseCode());
                    return null;
                }
                is = urlConnection.getInputStream();

                //customize
                int fileLength = urlConnection.getContentLength();
                byte data[] = new byte[1024];
                long total = 0;
                int count;
                while ((count = is.read(data)) != -1) {
                    total += count;
                    publishProgress((int) (total * 100 / fileLength));
                }
                callback.onDownloadComplete(HttpUrlDownloader.this, is, null);
                return null;

I can get progress by publishProgress , but when progress = 100% then ImageView not show

Sorry , My English is bad :( .Help me !!

Images are awalys in a small size.

Is there a way to get the real size of the image? A need to load one image, just on, in the screen, but with the library, it always in a different size (smaller size).

Compatibility with API level 7

Hi, I changed the async download task in UrlImageViewHelper to following code in order to compile for API version 7.
(Line 213 onwards...)

                URL u_url = new URL(url);

                HttpURLConnection urlConnection = (HttpURLConnection) u_url.openConnection();
                urlConnection.setRequestMethod("GET");
                urlConnection.setDoOutput(true);

                urlConnection.connect();

                FileOutputStream outfile = context.openFileOutput(filename, Context.MODE_PRIVATE);
                InputStream inputStream = urlConnection.getInputStream();

                byte[] buffer = new byte[1024];
                int bufferLength = 0;

                while ((bufferLength = inputStream.read(buffer)) > 0 ) {
                    outfile.write(buffer, 0, bufferLength);
                }

                outfile.close();
                inputStream.close();

                FileInputStream  fis = context.openFileInput(filename);

                return loadDrawableFromStream(context, fis);

java.util.concurrent.RejectedExecutionException

First off thanks for the great library it has saved my day a lot of times!!!

I'm using your library to populate items on a listview which contains all of the users facebook friends, and I have to show the friend's photo.

I'm using the simplest form of the library like this:
UrlImageViewHelper.setUrlDrawable(iv, url);

It has happened only a handful of times that I get the exception below. I was wondering if there is any configuration I can change to solve this issue.

E/AndroidRuntime(21066): FATAL EXCEPTION: main
E/AndroidRuntime(21066): java.util.concurrent.RejectedExecutionException: Task android.os.AsyncTask$3@423b40f8 rejected from java.util.concurrent.ThreadPoolExecutor@41989790[Running, pool size = 128, active threads = 128, queued tasks = 9, completed tasks = 54]
E/AndroidRuntime(21066): at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1967)
E/AndroidRuntime(21066): at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:782)
E/AndroidRuntime(21066): at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1303)
E/AndroidRuntime(21066): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:564)
E/AndroidRuntime(21066): at com.samsung.samsungolympics.util.urlimageviewhelper.UrlImageViewHelper.setUrlDrawable(UrlImageViewHelper.java:316)
E/AndroidRuntime(21066): at com.samsung.samsungolympics.util.urlimageviewhelper.UrlImageViewHelper.setUrlDrawable(UrlImageViewHelper.java:82)
E/AndroidRuntime(21066): at com.samsung.samsungolympics.register.AdapterOrderedByLetter.bindView(AdapterOrderedByLetter.java:153)
E/AndroidRuntime(21066): at com.samsung.samsungolympics.register.AdapterOrderedByLetter.getView(AdapterOrderedByLetter.java:137)
E/AndroidRuntime(21066): at android.widget.AbsListView.obtainView(AbsListView.java:2195)
E/AndroidRuntime(21066): at android.widget.ListView.makeAndAddView(ListView.java:1774)
E/AndroidRuntime(21066): at android.widget.ListView.fillDown(ListView.java:672)
E/AndroidRuntime(21066): at android.widget.ListView.fillGap(ListView.java:636)
E/AndroidRuntime(21066): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5257)
E/AndroidRuntime(21066): at android.widget.AbsListView$TwFlingRunnable.run(AbsListView.java:4150)
E/AndroidRuntime(21066): at android.os.Handler.handleCallback(Handler.java:605)
E/AndroidRuntime(21066): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(21066): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(21066): at android.app.ActivityThread.main(ActivityThread.java:4512)
E/AndroidRuntime(21066): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(21066): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(21066): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
E/AndroidRuntime(21066): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
E/AndroidRuntime(21066): at dalvik.system.NativeStart.main(Native Method)

Need to know when image is finished downloading, and possible return bitmap/drawable/imageview

Hello, I am using loadUrlDrawable to cache images before hand based on a url. My dilemma is that I want to post process the returned image (blur, specifically) once it is received. But outside of the library I can't tell if the image has been received, I'm not sure where to add something to your library to tell me this, and I'm definitely not sure where to put my JNI blur function. It takes bitmaps.

I've done image downloading myself before, but I really like how this library caches things and uses memory.

Maybe I'll cross-post this on stackoverflow

urlimage cache location question

hi, thanks for creating this awesome library.

by default this library caches bitmaps (.urlimage files) into files directory.

  • is there an option to move it into cache directory? so users can delete the cache by "clear cache" button in android settings.
  • or do i just fork this and change it manually?
  • is there any particular reason why you used files and not cache directory?
    thanks.

Images change in list view

I am using this to populate ImageViews held in a ListView and it seems like the first visible ImageView will display all of the images as they are downloaded from the URL. I believe this does not happen for cached images, but if they are downloaded then it will do this cycling thing.

List-view loads wrong image

I loading images from URL in a custom array adapter as follows
UrlImageViewHelper.setUrlDrawable(profile_image, url, R.drawable.defaultprofileimage);
Wrong images are loaded in list item. This happens without scrolling and with scrolling.

junit.framework.assertionfailederror

I am using thumbnails in a listview, this listview is in a viewpager. The thumbnails are already cached with urlimageviewhelper (or it may still be retrieving them). The thumbnails are loaded within the listview adapter using UrlImageViewHelper.setUrlDrawable(... , ... )

The crash if it happens points to a piece of UrlImageViewHelper drawable code. line 436 Assert.assertTrue(!mAllCache.contains(zd)); , junit.framework.assertionfailederror

Now, the listview will be rendering views for itself, as well as the viewpager rendering the left and right views (containing listviews caching). My Listviews also use a "viewholder" .So this would seem like a demanding process yes

Do I need to catch the assertionfailederror or something? I never saw this before until I made this imageview rendering monstrosity (listviews in viewpager)

Rotation Bug

I am not quite sure if this is an ImageView, JPEG or UrlImageViewHelper specific issue, but I'd like to inform you about the problem. (I have written an stackoverflow question to explore the subject: http://stackoverflow.com/questions/14419449/how-does-the-jpeg-orientation-feature-work)

To summarize the issue: A JPEG image, displayed correctly in a browser, will be displayed differently (rotated by 90°) on Android using the UrlImageViewHelper. The image in the browser loads from left to right. When I load normal images (that are loading from top to bottom in my browser) with the UrlImageViewHelper, they will be displayed perfectly.

Other Applications (OSX Preview, every Browser and the iOS ImageView) do not have any problems with the image. The only difference is (as mentioned above), that the image will be loaded from right to left.

If you believe, that this is not an UrlImageViewHelper specific problem, please close this issue.

'content://' uri support

Thank you for developing UrlImageViewHelper.

I want to use UrlImageViewHelper for local image (MediaStore.Images.Thumbnails)
but it doesn't seem to support content:// type uri except ContactsContract.Contacts.CONTENT_URI.

I modified UrlImageViewHelper - mDefaultDownloader - doInBackground like below

if (url.startsWith(ContentResolver.SCHEME_CONTENT)) {
final ContentResolver cr = context.getContentResolver();
if (url.startsWith(ContactsContract.Contacts.CONTENT_URI.toString())) {
is = ContactsContract.Contacts.openContactPhotoInputStream(cr, Uri.parse(url));
} else {
is = cr.openInputStream(Uri.parse(url));
}
}

and it works as expected.

Is there any particular reason for not supporting this feature?
(memory, file i/o or something)

If this works (or at least for MediaStore.XXX), it would save me some time.

Assertion in UrlImageViewHelper

I am working on an application that requires the rapid manipulation of alot of images, and they are going into a list view where I am recycling the views in the adapter. However, I am having instances an assertion in setUrlDrawable(Context,ImageView,String,Drawable) on line 497. I just cloned the repo today.

Other than that, the library seems to be holding up rather well.

Fail to cache

I'm using the latest sources from NIO branch, and sometimes I get this:

08-27 13:13:31.324: ERROR/AndroidRuntime(5972): FATAL EXCEPTION: main
java.lang.NullPointerException: key == null || value == null
at android.util.LruCache.put(LruCache.java:167)
at com.koushikdutta.urlimageviewhelper.UrlLruCache.put(UrlLruCache.java:9)
at com.koushikdutta.urlimageviewhelper.UrlImageViewHelper$2.run(UrlImageViewHelper.java:287)
at com.koushikdutta.urlimageviewhelper.UrlImageViewHelper$4$1.onPostExecute(UrlImageViewHelper.java:396)
at com.koushikdutta.urlimageviewhelper.UrlImageViewHelper$4$1.onPostExecute(UrlImageViewHelper.java:350)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4928)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)

Don't scale images to a lower resolution than their target dimensions

Currently if useBitmapScaling is set to true (which is the default) the bitmaps will be resized to the submultiple of their native resolution immediately lower than the target dimensions, which substantially reduces the image quality. It would be better if the bitmaps were resized to the submultiple immediately higher than the target dimensions, except in cases where this would be larger than the max texture resolution of 2048x2048.

Using with a RemoteViews object?

Sorry if I'm posting this in the wrong location; I'm kind of new to the social part of GitHub. :)

Anyway, I've been using UrlImageViewHelper in the ListFragments in my News & Weather app with great success (kudos on what you've done, it's a great helper!)

But now I'm trying to get it to work with an AppWidgetProvider, where there is no ImageView available. Instead, images are set on the AppWidgetProvider's RemoteViews object using the setImageViewBitmap(), setImageViewResource(), and setImageViewUri() methods.

Is there a way to utilize UrlImageViewHelper with a RemoteViews, perhaps adding a new method like:

UrlImageViewHelper.setRemoteViewsUriDrawable(remoteViews, R.id.some_widget_icon, "http://www.example.com/some/image/url.png") ??

Any ideas here? Thanks!!!

java.lang.NoClassDefFoundError

I'm getting a very odd, hard to reproduce error. This occurs ONLY when the app has been uploaded to play.google.com. Another oddity is I have multiple apps running the same codebase (exactly) and this doesn't occur in the other builds.....

Thoughts?

I/dalvikvm(13872): Could not find method com.koushikdutta.urlimageviewhelper.UrlImageViewHelper.setUrlDrawable, referenced from method com.mobileigniter.android.acr.MIViewerActivity.updateLauncherView
W/dalvikvm(13872): VFY: unable to resolve static method 1293: Lcom/koushikdutta/urlimageviewhelper/UrlImageViewHelper;.setUrlDrawable (Landroid/widget/ImageView;Ljava/lang/String;)V
D/dalvikvm(13872): VFY: replacing opcode 0x71 at 0x0020
I/webclipboard(13872): clipservice: android.sec.clipboard.ClipboardExManager@412aa830
I/System.out(13872): updateLauncherView
D/AndroidRuntime(13872): Shutting down VM
W/dalvikvm(13872): threadid=1: thread exiting with uncaught exception (group=0x40b921f8)
E/AndroidRuntime(13872): FATAL EXCEPTION: main
E/AndroidRuntime(13872): java.lang.NoClassDefFoundError: com.koushikdutta.urlimageviewhelper.UrlImageViewHelper
E/AndroidRuntime(13872): at com.mobileigniter.android.acr.MIViewerActivity.updateLauncherView(MIViewerActivity.java:162)
E/AndroidRuntime(13872): at com.mobileigniter.android.acr.MIViewerActivity.onStart(MIViewerActivity.java:90)
E/AndroidRuntime(13872): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1137)
E/AndroidRuntime(13872): at android.app.Activity.performStart(Activity.java:4475)
E/AndroidRuntime(13872): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1943)
E/AndroidRuntime(13872): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
E/AndroidRuntime(13872): at android.app.ActivityThread.access$600(ActivityThread.java:128)
E/AndroidRuntime(13872): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
E/AndroidRuntime(13872): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(13872): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(13872): at android.app.ActivityThread.main(ActivityThread.java:4514)
E/AndroidRuntime(13872): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(13872): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(13872): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
E/AndroidRuntime(13872): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
E/AndroidRuntime(13872): at dalvik.system.NativeStart.main(Native Method)
W/A

Adding ProgressBar

I tried adding progressbar in which after the image is loaded, i'll set the visibility of the progressbar to "gone". But only the first image has no progressBar or sometimes the first and last, the rest, the progressbar is still present.

Avoid shrinking

First of all thanks for a great lib! It would be nice to have a flag to avoid shrinking/resampling of the downloaded image.

Improvement: No callback when the image fail to load.

Hello Koush,

For the need of my project, I had to check if the image was loaded correctly from the url.

Currently, there is no support for that:
"callback An instance of UrlImageViewCallback that is called when the image successfully finishes loading"

I just wanted to know if this is on purpose or if a onFail could be added in the library:

public interface UrlImageViewCallback {
void onLoaded(ImageView imageView, Drawable loadedDrawable, String url, boolean loadedFromCache);
void onFail(ImageView imageView, String url);
}

Thank a lot for your work.

Same image, multiple sizes, display problems.

Hi. I have a problem. I am not sure if its related to your library or not but I think it is.
I have multiple imageViews in various activities for the same image. What differs are the imageView attributes, android:layout_width, android:layout_height, android:scaleType.

The problem is, when I go to the first activity the image renders correctly. Then I go to the 2nd activity which has other imageVIew with different size for the same image. If I go back to the 1st activity the image size/scale is screwed. Itś like its saving the resized image in the cache and because its the same image, the other imageView doenst use the image in the original size to apply the scale/resize.

I hope I was clear.

Removing a URL from cache

I try to access same URL for loading an image for a user.

I use UrlImageViewHelper.setDrawable(imageView,url) in my UserProfile activity

So when I update image at that URL, I call UrlImageViewHelper.remove(url,this) in my activity which I believe should remove that URL from cache and get updated image on calling UrlImageViewHelper.setDrawable(imageView,url) but it doesn't work. It fetches image from cache.

Is the context "this"wrong? in UrlImageViewHelper.remove(url,this)
What should I use instead?

coffee feature broken

------- "Android library that sets an ImageView's contents from a url. Manages image downloading, caching, and makes your coffee too." ---------

I woke up this morning, and my coffee pot was empty, came over here to check and see if there were any open/closed issues that would maybe help me and there weren't any. Im not sure if anyone else is having this issue or not. Hopefully someone can fix this soon...really love coffee... Great project guys, keep up the great work.

------ (funny issue, not to be taken seriously) lol

How to clear *.imageurl files on finish app?

Good afternoon.
I will replace that in the "files" on your accumulated cached images *.imageurl.
Is it possible to clear these files when you close the program?
I understand that if you do not, the size of the folder will continue to increase until the end disk space, right?
Sorry for bad English

Load image from SD card ?

Is there a way using this library load image from sdcard ?

My image files are in sdcard and i need to bitmap and display now which takes a little time to display.

"/mnt/sdcard/20130527_224148.jpg"

from cache returns true and really imagebitmap is null

Hi,
Sorry, my english is not very good. I'm from Catalonia.

I am using your fabulous urlimageviewHelper.
I found a possible error. My activity has a receiver internet changes.

  1. I disconnected internet.
  2. I open an activity with a list of images.
  3. urlimageviewhelper try to download the images but no internet, so it does nothing.
    Callback OnLoaded returns:
    cache: false, url: http://xxx.com/1360/?width=94&height=74

(It seems that stores a null value in the hash)

  1. I connect internet, and when the receiver receives connection, I do adapter.setNotifyDatasetChanged ().

  2. Urlimageviewhelper find images in cache, but really not downloaded before and returns a null imageBitmap.
    Callback OnLoaded returns:
    cache: true, url: http://xxx.com/1360/?width=94&height=74

How I can fix this?
One posible solution is using cacheDurationMs = 0, but it seems not the best solution... (Now i have tried to use cacheDurationMs = 0 and not working...) the problem is urlimageviewhelper returns null images..

THANKS! and GOOD JOB!

Loading Images on recycled GridView cells

I may be using it wrong, but images are appearing on recycled cells in my GridView, essentially making duplicates. Is this how it's supposed to work, or am I doing something wrong?

If I have 4 images in a 3-column GridView, I get:
[image 1] [image 2] [image 3]
[image 4] [image 2] [image 1]
[image 1]

I read a bit more of your code, and added some logs to the part with the comment: "since listviews recycle their views, we need to take note of which url this view is waiting for". I'm assuming this doesn't take into consideration what would happen if the view is set to null?

Option for disabling disk cache?

I'm not sure there is option for disabling disk cache and I just couldn't found it.

If I use content:// type url, all data are already in the disk so I don't want them to be internally cached for saving space and consistency sake.

Out of memory error when using View Pager to load images.

Hello, i'm rather new at Android development. I'm using a view pager to load in an array of Urls for displaying. I am getting an out of memory error when swiping through the images. I do not notice any patterns when this happens, But I do notice it if I swipe fast. This is my first time implementing a View Pager so I may be missing something important. Has anyone ever used UrlImageViewHelper with a view pager? I will paste the code I have to see if we can figure out the root of the problem. I feel like the most important piece I am missing is with the PagerAdapter. Here is the code:

private class ImagePagerAdapter extends PagerAdapter {

    private ArrayList<String> images = new ArrayList<String>();
    private LayoutInflater inflater;

    ImagePagerAdapter(ArrayList<String> imageUrls) {
        this.images = imageUrls;
        inflater = getLayoutInflater();
    }

    @Override
    public void destroyItem(ViewGroup container, int position ,Object object) {
        ((ViewPager) container).removeView((View) object);
    }


    @Override
    public int getCount() {
        return images.size();
    }


    @Override
    public Object instantiateItem(final ViewGroup view, int position) {
        final View imageLayout = inflater.inflate(R.layout.activity_imagedetailitem, view, false);
        final ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);
        final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loading);
        spinner.setVisibility(View.VISIBLE);

        UrlImageViewHelper.setUrlDrawable(imageView, imageUrls.get(position), null, UrlImageViewHelper.CACHE_DURATION_ONE_DAY, new UrlImageViewCallback() {

            @Override
            public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url,
                    boolean loadedFromCache) {

                if (loadedBitmap == null) {
                    //Error loading image
                    Toast.makeText(TLImageDetailsActivity.this, "Failed to load image", Toast.LENGTH_SHORT).show();
                } else {
                    System.out.println("Successfully loaded image");
                    //Image was successfully loaded
                    ((ViewPager) view).addView(imageLayout, 0);

                    spinner.setVisibility(View.GONE);
                }

            }
        });
        return imageLayout;

    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view.equals(object);
    }

    @Override  
       public void finishUpdate(View arg0) {}  

       @Override  
       public void restoreState(Parcelable arg0, ClassLoader arg1) {}  

       @Override  
       public Parcelable saveState() {  
           return null;  
       }  

       @Override  
       public void startUpdate(View arg0) {}  

     }  //end of page adapter

Here is the output from LogCat:
04-01 16:37:30.212: E/AndroidRuntime(18279): FATAL EXCEPTION: AsyncTask #3
04-01 16:37:30.212: E/AndroidRuntime(18279): java.lang.RuntimeException: An error occured while executing doInBackground()
04-01 16:37:30.212: E/AndroidRuntime(18279): at android.os.AsyncTask$3.done(AsyncTask.java:200)
04-01 16:37:30.212: E/AndroidRuntime(18279): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
04-01 16:37:30.212: E/AndroidRuntime(18279): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
04-01 16:37:30.212: E/AndroidRuntime(18279): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
04-01 16:37:30.212: E/AndroidRuntime(18279): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
04-01 16:37:30.212: E/AndroidRuntime(18279): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
04-01 16:37:30.212: E/AndroidRuntime(18279): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
04-01 16:37:30.212: E/AndroidRuntime(18279): at java.lang.Thread.run(Thread.java:1027)
04-01 16:37:30.212: E/AndroidRuntime(18279): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget(Heap Size=7111KB, Allocated=3616KB, Bitmap Size=25807KB)
04-01 16:37:30.212: E/AndroidRuntime(18279): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-01 16:37:30.212: E/AndroidRuntime(18279): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:694)
04-01 16:37:30.212: E/AndroidRuntime(18279): at com.koushikdutta.urlimageviewhelper.UrlImageViewHelper.loadBitmapFromStream(UrlImageViewHelper.java:117)
04-01 16:37:30.212: E/AndroidRuntime(18279): at com.koushikdutta.urlimageviewhelper.UrlImageViewHelper.access$3(UrlImageViewHelper.java:94)
04-01 16:37:30.212: E/AndroidRuntime(18279): at com.koushikdutta.urlimageviewhelper.UrlImageViewHelper$1.onDownloadComplete(UrlImageViewHelper.java:589)
04-01 16:37:30.212: E/AndroidRuntime(18279): at com.koushikdutta.urlimageviewhelper.UrlImageViewHelper$3.doInBackground(UrlImageViewHelper.java:655)
04-01 16:37:30.212: E/AndroidRuntime(18279): at com.koushikdutta.urlimageviewhelper.UrlImageViewHelper$3.doInBackground(UrlImageViewHelper.java:1)
04-01 16:37:30.212: E/AndroidRuntime(18279): at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-01 16:37:30.212: E/AndroidRuntime(18279): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
04-01 16:37:30.212: E/AndroidRuntime(18279): ... 4 more

Thank you so much for providing me with your helper class :) (sorry for a big wall of mess, hopefully it's not too painful)

fixed: can't cache using service context

Hello, I am doing an network call in a thread in a service, the response contains urls which I would like to cache. UrlImageViewHelper.loadUrlDrawable(context, "http://example.com/image.png"); requires an Activity context to get access to some bitmap controls, but my service does not have an activity context.

How can I cache here?

EDIT:
I changed prepareResources() to this, your code commented out
//final Activity act = (Activity)context;
//act.getWindowManager().getDefaultDisplay().getMetrics(mMetrics);
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay().getMetrics(mMetrics);

Callback OnLoaded not called when two instances of the same image are being loaded

I have two separate activities that each load the same external image with UrlImageViewHelper.setUrlDrawable. If the user switches to the second activity before the image has loaded in the first activity, then the OnLoaded callback will be called only in the first activity and not in the second when it does finish loading.

This is a problem for me because I have a ProgressBar indicating that the image is loading in both activities, but I have no way to remove it in the second activity in this case.

Request for Javadocs

Just wondering if you're open to the suggestion of adding javadoc comments to your code. It looks clear enough, but I'm sorry to say that I'm lazy, so javadocs would really help. If you don't want to write javadocs, but are open to the idea of adding some, I can add some for you eventually, for other lazy freeloaders like me. I find that clear, complete javadocs are a lot more helpful than wikis and how-to guides. Thanks for your open-source work btw.

Issue after changing the orientation

I have an issue with UrlImageViewHelper after changing the orientation: the image are resized with an unexpected size.

I believe it is due to the fact you cache mMetrics with the DisplayMetrics associated to the orientation of the first call. It then lead to issues when using mMetrics.widthPixels since it may not be valid anymore after a change of orientation.

1.0.4

multiple layouts - different layout parameters.

I have an app that uses the same image in multiple layouts. The ImageView has different layout parameters in each layout, i.e. margin, padding, height, width, etc.
I noticed that when navigating from a ListActivity to a "detail" activity for the selected list item that the image in the list would change based on the layout parameters in the detail activity which also displays the image.

I was able to work around this by caching the Bitmap and not the Drawable. Downside is that my default drawable needs to be an image, which is fine for my app.

Other than that your code worked like a charm!

Force Image Update

Is there anyway to force a image to update?

First time this image loads it is cached for 3 days which is fine. But if some condition happens i want to force it to update even if its cached. Is this currently possible?

Thank you

Use custom view with the library

Hello, I am trying to use a custom view with the the library, but I always get a ClassCast exception in the ondraw.What do I have to change?

Callback & loadUrlDrawable

I really enjoy your lib but I'm facing a problem while using UrlImageViewHelper.loadUrlDrawable with a callback. The callback was fired only when the image was in cache.

I dig a little in the code and found that in the Runnable "completion" in UrlImageViewHelper.java line 500, the callback is launched only if there is at least on imageview which there is not in my case.

I'm not sure if it's the cleanest way to fix this but I added this lines at the end of the Runnable:

if(downloads.size() == 0 && callback != null) {
    callback.onLoaded(null, loader.result, url, false);
}

Image not showing until after scrolling in listview

I'm using the UrlImageViewHelper with a ViewPager with ListFragments and when I enter the screen all ImageViews in the listview are white. They do not hold the placeholder and also do not get updated when the image is received.

When I scroll down the new views appearing at the bottom do show results and placeholders. When I scoll up the also work fine. So it seems everything works fine when the views are reused, but initially they don't work.

Too many connections

I have this situation where I need to load many images. But too many concurrent threads doesn't work. Is there any solution for this?

cleanup method uses the wrong path to the files to be deleted

Hi -

First of all, thanks for a very useful component. Just wanted to point out that your cleanup function does not do what it's supposed to at least on the 2 devices I used, a Nexus 1 and a Galaxy Nexus, both GSM/ATT. It looks like in the delete loop, you are using the plain file string:
File f = new File(file);
where it needs to be something like this:
File f = new File(context.getFilesDir() + "/"+file )

I needed this to work in order to create a general cache cleanup method so my app can remove cached images when the user changes accounts.

On a different note, have you thought about adding a listener that would notify when images are done loading. I tried it myself but I've been failing because of the multi-thread nature of the class.

Thanks.
Ovi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.