0

I am using a RemoteViewsFactory to populate a listview in a widget.

The widget contains a Images. What is the best approach to load the bitmaps and setImageView() on the remote view?

Many thanks.

FlashAsh80
  • 1,357
  • 1
  • 16
  • 27
  • Did you look here? https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/sample/src/com/nostra13/example/universalimageloader/widget/UILWidgetProvider.java – nostra13 Feb 17 '13 at 19:12
  • Hi NOSTRA, thanks. I did look there first. And although it's got a good example of populating an imageview with a Widget Provider. I don't believe I can use this method quite the same when using a RemoteViewsFactory for populating a listview (in a widget) dynamically. At least from my limited understanding widgets. – FlashAsh80 Feb 17 '13 at 23:14
  • What I believe I may need, is a way of getting the bitmaps from the ImageLoader synchronously. Not sure if that's possible? – FlashAsh80 Feb 17 '13 at 23:17
  • UIL doesn't provide methods for synchronous getting of images but you always can find a workaround. I'll post it as the answer. – nostra13 Feb 24 '13 at 15:27

1 Answers1

2

The way to load images synchronously (works for 'loadImage(...)' and displayImage(...)):

final Object lock = new Object();
boolean loaded = false;
ImageSize targetImageSize = new ImageSize(70, 70);
ImageLoader.getInstance().loadImage(imageUri, targetImageSize, options, new SimpleImageLoadingListener() {
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        loaded = true;
        // Do whatever you want with loadedImage

        synchronize(lock) {
            lock.notifyAll();
        }
    }
});
if (!loaded) {
    synchronize(lock) {
        lock.wait();
    }
}
nostra13
  • 12,377
  • 3
  • 33
  • 43
  • Thanks NOSTRA, since I posted this question, I have changed my design in my widget so I don't use a listview. Although, I've not tried it out, I will mark this as the answer as this should allow you to populate images within the remoteviewsfactory – FlashAsh80 Feb 25 '13 at 09:53
  • Nostra, this approach doesn't work - it executes lock.wait() line, and it seems to download the images, but none of the callbacks of ImageLoadingListener is executed (except onLoadingStarted). Thus notify is never called and the method never returns. – User Aug 05 '13 at 12:31