I'm currently working on a slideshow-app which displays multiple images with animation in a own implementation of ImageSwitcher. Before the ImageSwitcher gets displayed, I preload (cache) the images with Picasso with fetch()
.
The following method will be called when the next image should load:
public void setImageSource(final String url) {
final ImageView image = (ImageView) this.getNextView();
image.setVisibility(View.VISIBLE);
BitmapDrawable drawable = (BitmapDrawable) image.getDrawable();
if (drawable != null && drawable.getBitmap() != null) {
drawable.getBitmap().recycle();
}
PicassoUtils.getPicassoWithBasicAuthorizationFrom(user, getContext())
.load(url)
.noFade()
.fit()
.centerCrop()
.into(image);
showNext();
}
The image.setVisibility(View.VISIBLE)
is needed to make picasso able to read the dimensions of the ImageView. And the recycling is needed to save memory, because when I do not do recycle the imageView the memory rises on every image switch.
But I have a big problem. The time between images is fixed and Picasso takes some time to load the image (even from the local cache) into the imageView, so I have a small delay.
The question is, how can I preload the next image?