I have made an application in which there is gridview and when we we select any thumbnail on it we see the full size image in viewpager. But when i click on thumbnail and view image for many times i get out of memory in android.I have searched a lot and found one solution to use picasso instead of imageloader but i can not use picasso .I have do it with imageloader only. Can anyone please tell me the exact configuration and options for imageloader so that i do not get out of memory????
Please help i have tried many configuration changes.
public class ImagePagerAdapter extends PagerAdapter {
LayoutInflater inflater;
PhotoViewAttacher attacher;
PhotoViewAttacher pic;
private DisplayImageOptions options;
List<Image> IMAGES_LIST = AppController.getInstance().getPrefManger()
.getImages();
public ImagePagerAdapter(Context context) {
inflater = LayoutInflater.from(context);
options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.cacheOnDisc()
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.build();
}
@Override
public Object instantiateItem(ViewGroup container, final int position) {
final View imageLayout = inflater.inflate(
R.layout.item_pager_image, container, false);
assert imageLayout != null;
pos = position;
imageView = (TouchImageView) imageLayout.findViewById(R.id.image);
imageView.setTag(position);
imageView.setOnDoubleTapListener(new OnDoubleTapListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
try
{
timer.cancel();
}
catch(Exception ex){}
if(IMAGES_LIST.get(position).getType().equalsIgnoreCase("image"))
{
mHandler.removeCallbacks(r);
share.setVisibility(View.VISIBLE);
play.setVisibility(View.VISIBLE);
done.setVisibility(View.VISIBLE);
if (!isCopyImage.equals("yes")) {
gimmy.setVisibility(View.VISIBLE);
}
comment.setVisibility(View.VISIBLE);
count.setVisibility(View.VISIBLE);
caption.setVisibility(View.VISIBLE);
mHandler.postDelayed(r, 5 * 1000);
}
else{
mHandler.removeCallbacks(r);
done.setVisibility(View.VISIBLE);
mHandler.postDelayed(r, 5 * 1000);
}
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
// TODO Auto-generated method stub
Log.i("hello", "");
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
});
try{
final ProgressBar spinner = (ProgressBar) imageLayout
.findViewById(R.id.loading);
final ImageView videoplay = (ImageView) imageLayout
.findViewById(R.id.play);
if(IMAGES_LIST.get(position).getType().equalsIgnoreCase("image"))
{
videoplay.setVisibility(View.INVISIBLE);
ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(container.getContext());
config.memoryCache(new WeakMemoryCache());
config.denyCacheImageMultipleSizesInMemory();
config.discCache(new UnlimitedDiskCache(container.getContext().getCacheDir()));
imageLoader=ImageLoader.getInstance();
imageLoader.init(config.build());
imageLoader.displayImage(
AppConst.BASE_IMAGE_URL
+ IMAGES_LIST.get(position).getFileName(),
imageView, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
spinner.setVisibility(View.VISIBLE);
view.setVisibility(View.GONE);
}
@Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
String message = null;
switch (failReason.getType()) {
case IO_ERROR:
message = "Input/Output error";
break;
case DECODING_ERROR:
message = "Image can't be decoded";
break;
case NETWORK_DENIED:
message = "Downloads are denied";
break;
case OUT_OF_MEMORY:
message = "Out Of Memory error";
break;
case UNKNOWN:
message = "Unknown error";
break;
}
spinner.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri,
View view, Bitmap loadedImage) {
spinner.setVisibility(View.GONE);
view.setVisibility(View.VISIBLE);
}
});
container.addView(imageLayout, 0);
}