Permalink
Browse files

Merge branch 'develop' of github.com:novoda/ImageLoader into develop

  • Loading branch information...
2 parents cbe88dd + acde9b9 commit f9441ac561bf607828851bb04e337623bd8d491d @friedger friedger committed Sep 28, 2012
@@ -15,13 +15,12 @@
*/
package com.novoda.imageloader.core.cache;
-import java.lang.reflect.Method;
-
-import com.novoda.imageloader.core.cache.util.LruCache;
-
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
+import com.novoda.imageloader.core.cache.util.LruCache;
+
+import java.lang.reflect.Method;
/**
* LruBitmapCache overcome the issue with soft reference cache.
@@ -76,11 +75,20 @@ public LruBitmapCache(Context context) {
}
private void reset() {
+ if (cache!= null) {
+ cache.evictAll();
+ }
cache = new LruCache<String, Bitmap>(capacity) {
@Override
protected int sizeOf(String key, Bitmap bitmap) {
return bitmap.getRowBytes()*bitmap.getHeight();
}
+
+ @Override
+ protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue) {
+ oldValue.recycle();
+ super.entryRemoved(evicted, key, oldValue, newValue); //To change body of overridden methods use File | Settings | File Templates.
+ }
};
}
@@ -4,12 +4,32 @@
android:layout_height="fill_parent"
android:orientation="vertical" >
-<!-- added by dwa012 -->
+ <LinearLayout
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:orientation="horizontal">
<Button
android:id="@+id/refresh_button"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="refresh" />
+ android:layout_weight="1"
+ android:text="Refresh" />
+
+ <Button
+ android:id="@+id/null_tag_button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="Null Tag" />
+
+ <Button
+ android:id="@+id/null_url_button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="Null URL" />
+
+ </LinearLayout>
<ListView
android:id="@android:id/android:list"
@@ -4,8 +4,6 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter.ViewBinder;
import com.novoda.imageloader.core.ImageManager;
@@ -46,18 +44,7 @@ public void onCreate(Bundle savedInstanceState) {
imageTagFactory = ImageTagFactory.getInstance(this, R.drawable.bg_img_loading);
imageTagFactory.setErrorImageId(R.drawable.bg_img_notfound);
setAdapter();
- initButton();
- }
-
- private void initButton() {
- Button button = (Button) this.findViewById(R.id.refresh_button);
- button.setOnClickListener(new OnClickListener(){
-
- @Override
- public void onClick(View v) {
- refreshData();
- }
- });
+ initButtons();
}
@Override
@@ -84,7 +71,7 @@ protected ViewBinder getViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
String url = cursor.getString(columnIndex);
- ((ImageView) view).setTag(imageTagFactory.build(url));
+ ((ImageView) view).setTag(getTag(imageTagFactory, url));
imageManager.getLoader().load((ImageView) view);
return true;
}
@@ -3,11 +3,8 @@
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter.ViewBinder;
-
import com.novoda.imageloader.core.ImageManager;
import com.novoda.imageloader.core.model.ImageTagFactory;
import com.novoda.imageloader.demo.DemoApplication;
@@ -49,19 +46,7 @@ public void onCreate(Bundle savedInstanceState) {
imageTagFactory.setErrorImageId(R.drawable.bg_img_notfound);
imageTagFactory.setSaveThumbnail(true);
setAdapter();
-
- //added by dwa012
- Button button = (Button) this.findViewById(R.id.refresh_button);
- button.setOnClickListener(new OnClickListener(){
-
- @Override
- public void onClick(View v) {
- refreshData();
-
-
- }
-
- });
+ initButtons();
}
/**
@@ -75,7 +60,7 @@ protected ViewBinder getViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
String url = cursor.getString(columnIndex);
- ((ImageView) view).setTag(imageTagFactory.build(url));
+ ((ImageView) view).setTag(getTag(imageTagFactory, url));
imageManager.getLoader().load((ImageView) view);
return true;
}
@@ -3,8 +3,6 @@
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter.ViewBinder;
import com.novoda.imageloader.core.ImageManager;
@@ -16,13 +14,15 @@
/**
* Very similar to imageLongList example.
*/
-public class LongSmallImageList extends SingleTableBaseListActivity implements OnClickListener {
+public class LongSmallImageList extends SingleTableBaseListActivity {
private static final int SIZE = 80;
private ImageManager imageManager;
private ImageTagFactory imageTagFactory;
-
+ private boolean null_tag;
+ private boolean null_url;
+
@Override
protected String getTableName() {
return LongSmallImageList.class.getSimpleName().toLowerCase();
@@ -41,7 +41,7 @@ public void onCreate(Bundle savedInstanceState) {
imageManager = DemoApplication.getImageLoader();
imageTagFactory = createImageTagFactory();
setAdapter();
- initRefreshButton();
+ initButtons();
}
private ImageTagFactory createImageTagFactory() {
@@ -54,16 +54,6 @@ private ImageTagFactory createImageTagFactory() {
return imageTagFactory;
}
- private void initRefreshButton() {
- Button button = (Button) this.findViewById(R.id.refresh_button);
- button.setOnClickListener(this);
- }
-
- @Override
- public void onClick(View v) {
- refreshData();
- }
-
/**
* Generally you will have a binder where you have to set the image.
* This is an example of using the imageManager to load
@@ -74,11 +64,12 @@ protected ViewBinder getViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
String url = cursor.getString(columnIndex);
- ((ImageView) view).setTag(imageTagFactory.build(url));
+ ((ImageView) view).setTag(getTag(imageTagFactory, url));
imageManager.getLoader().load((ImageView) view);
return true;
}
};
}
+
}
@@ -3,15 +3,22 @@
import android.app.ListActivity;
import android.database.Cursor;
import android.net.Uri;
+import android.view.View;
+import android.widget.Button;
import android.widget.SimpleCursorAdapter;
import android.widget.SimpleCursorAdapter.ViewBinder;
+import com.novoda.imageloader.core.model.ImageTag;
+import com.novoda.imageloader.core.model.ImageTagFactory;
import com.novoda.imageloader.demo.R;
-public abstract class SingleTableBaseListActivity extends ListActivity {
+public abstract class SingleTableBaseListActivity extends ListActivity implements View.OnClickListener {
private static final String[] FROM = new String[] { "url" };
private static final int[] TO = new int[] { R.id.list_item_image };
-
+
+ private boolean null_tag;
+ private boolean null_url;
+
private SimpleCursorAdapter adapter;
protected int getImageItem() {
@@ -44,4 +51,43 @@ protected void refreshData(){
adapter.notifyDataSetChanged();
}
+ protected void initButtons() {
+ Button button = (Button) this.findViewById(R.id.refresh_button);
+ button.setOnClickListener(this);
+ button = (Button) this.findViewById(R.id.null_tag_button);
+ button.setOnClickListener(this);
+ button = (Button) this.findViewById(R.id.null_url_button);
+ button.setOnClickListener(this);
+ }
+
+ @Override
+ public void onClick(View v) {
+ switch(v.getId()) {
+ case R.id.refresh_button:
+ null_tag = false;
+ null_url = false;
+ refreshData();
+ break;
+ case R.id.null_tag_button:
+ null_tag = !null_tag;
+ refreshData();
+ break;
+ case R.id.null_url_button:
+ null_url = !null_url;
+ refreshData();
+ break;
+ }
+ }
+
+ protected ImageTag getTag(ImageTagFactory imageTagFactory, String url) {
+ if (null_tag) {
+ return null;
+ }
+ if (null_url) {
+ return imageTagFactory.build(null);
+ }
+ return imageTagFactory.build(url);
+ }
+
+
}

0 comments on commit f9441ac

Please sign in to comment.