package org.appsroid.fxpro.bitmap;

import org.appsroid.fxpro.library.MemoryManagement;
import org.appsroid.fxpro.library.UriToUrl;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;

public class BitmapLoader {

	public Bitmap load(Context context, int[] holderDimention, String image_url) throws Exception {
		BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
		bitmapOptions.inJustDecodeBounds = true;
		BitmapFactory.decodeFile(image_url, bitmapOptions);

		int inSampleSize = 1;

		final int outWidth = bitmapOptions.outWidth;
		final int outHeight = bitmapOptions.outHeight;

		final int holderWidth = holderDimention[0];
		final int holderHeight = holderDimention[1];

		// Calculation inSampleSize
		if (outHeight > holderHeight || outWidth > holderWidth) {
			final int halfWidth = outWidth / 2;
			final int halfHeight = outHeight / 2;

			while ((halfHeight / inSampleSize) > holderHeight && (halfWidth / inSampleSize) > holderWidth) {
				inSampleSize *= 2;
			}
		}

		bitmapOptions.inSampleSize = inSampleSize;

		// Decoding bitmap
		bitmapOptions.inJustDecodeBounds = false;
		return BitmapProcessing.modifyOrientation(BitmapFactory.decodeFile(image_url, bitmapOptions), image_url);
	}
	
	public Bitmap load(Context context, int[] holderDimention, Uri image_uri) throws Exception {
		String image_url = UriToUrl.get(context, image_uri);
		if (image_url != null) {
			return load(context, holderDimention, image_url);
		}
		return null;
	}
	
	public Bitmap load(Context context, String image_url) throws Exception {
		BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
		
		bitmapOptions.inJustDecodeBounds = true;
		BitmapFactory.decodeFile(image_url, bitmapOptions);
		
		final float imageSize = (float) bitmapOptions.outWidth * (float) bitmapOptions.outHeight * 4.0f / 1024.0f / 1024.0f; // MB
		
		bitmapOptions.inSampleSize = (int) Math.pow(2, Math.floor(imageSize / MemoryManagement.free(context)));
		bitmapOptions.inJustDecodeBounds = false;
		
		return BitmapProcessing.modifyOrientation(BitmapFactory.decodeFile(image_url, bitmapOptions), image_url);
	}

}

@@ -333,25 +333,25 @@
  holderDimen
-t
+s
 ion, String 
@@ -702,25 +702,25 @@
  holderDimen
-t
+s
 ion%5B0%5D;%0A%09%09fi
@@ -753,17 +753,17 @@
 derDimen
-t
+s
 ion%5B1%5D;%0A
@@ -1341,25 +1341,25 @@
  holderDimen
-t
+s
 ion, Uri ima
@@ -1502,17 +1502,17 @@
 derDimen
-t
+s
 ion, ima

Update BitmapLoader.java