Skip to content

Commit

Permalink
Added support for memory saving image presentation: Config.ARGB_4444 …
Browse files Browse the repository at this point in the history
…- showLowQualityImages(boolean showLowQualityImages)
  • Loading branch information
Dariusz Kalinowski committed Jun 12, 2013
1 parent 82e1295 commit 504fd08
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/com/androidquery/callback/AbstractAjaxCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.Xml;
Expand Down Expand Up @@ -152,6 +153,9 @@ public abstract class AbstractAjaxCallback<T, K> implements Runnable{
private boolean uiCallback = true;
private int retry = 0;

//Darek
private boolean showLowQualityImages;

@SuppressWarnings("unchecked")
private K self(){
return (K) this;
Expand Down Expand Up @@ -294,6 +298,18 @@ public K retry(int retry){
return self();
}

/**
* Darek
*
* @param type the type
* @return self
*/
public K showLowQualityImages(boolean showLowQualityImages){
this.showLowQualityImages = showLowQualityImages;
return self();
}


/**
* Set the transformer that transform raw data to desired type.
* If not set, default transformer will be used.
Expand Down Expand Up @@ -636,8 +652,17 @@ protected T transform(String url, byte[] data, AjaxStatus status){

if(data != null){

if(type.equals(Bitmap.class)){
return (T) BitmapFactory.decodeByteArray(data, 0, data.length);
if(type.equals(Bitmap.class)){

// Solution for out of memory error
// http://stackoverflow.com/a/8527745/2075875
BitmapFactory.Options bfOptions=new BitmapFactory.Options();
bfOptions.inDither=false; //Disable Dithering mode
bfOptions.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared
bfOptions.inInputShareable=true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
bfOptions.inPreferredConfig = (showLowQualityImages) ? Config.ARGB_4444 : Config.ARGB_8888;

return (T) BitmapFactory.decodeByteArray(data, 0, data.length, bfOptions);
}

if(type.equals(JSONObject.class)){
Expand Down

0 comments on commit 504fd08

Please sign in to comment.