package com.antew.redditinpictures.library.ui;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;
import com.antew.redditinpictures.library.R;
import com.antew.redditinpictures.library.utils.Util;

public class About extends SherlockActivity {
    private ImageView mImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mImageView = (ImageView) findViewById(R.id.about_image);
        int size = Util.dpToPx(this, 100);
        mImageView.setImageBitmap(decodeSampledBitmapFromResource(getResources(), R.drawable.market_icon, size, size));

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }

        return super.onOptionsItemSelected(item);
    }

    public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {

        // First decode with inJustDecodeBounds=true to check dimensions
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeResource(res, resId, options);

        // Calculate inSampleSize
        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
        return BitmapFactory.decodeResource(res, resId, options);
    }

    public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;

        if (height > reqHeight || width > reqWidth) {
            if (width > height) {
                inSampleSize = Math.round((float) height / (float) reqHeight);
            } else {
                inSampleSize = Math.round((float) width / (float) reqWidth);
            }
        }
        return inSampleSize;
    }
}

@@ -484,16 +484,60 @@
 ageView;
+%0A    private static final int MAX_TRIES = 4;
 %0A%0A    @O
@@ -1835,64 +1835,331 @@
     
-return BitmapFactory.decodeResource(res, resId, options)
+Bitmap b = null;%0A        int i = 0;%0A        while (b == null && i %3C MAX_TRIES) %7B%0A            try %7B%0A                b = BitmapFactory.decodeResource(res, resId, options); %0A            %7D catch (OutOfMemoryError e) %7B%0A                options.inSampleSize *= 2;%0A            %7D%0A            i++;%0A        %7D%0A        %0A        return b
 ;%0A  

Update to make multiple tries decoding the Bitmap for the About page.