Permalink
Browse files

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

  • Loading branch information...
2 parents 480e502 + adf143d commit 62e0b120e45fe437a689d8770e4a989cb521b258 @friedger friedger committed Sep 28, 2012
Showing with 409 additions and 306 deletions.
  1. +10 −38 acceptance/src/com/novoda/imageloader/acceptance/ImageLoaderDemoActivityTest.java
  2. +4 −11 core/src/main/java/com/novoda/imageloader/core/ImageManager.java
  3. +16 −4 core/src/main/java/com/novoda/imageloader/core/LoaderContext.java
  4. +17 −18 core/src/main/java/com/novoda/imageloader/core/bitmap/BitmapUtil.java
  5. +1 −11 core/src/main/java/com/novoda/imageloader/core/loader/ConcurrentLoader.java
  6. +6 −22 core/src/main/java/com/novoda/imageloader/core/loader/SimpleLoader.java
  7. +18 −12 core/src/main/java/com/novoda/imageloader/core/loader/util/LoaderTask.java
  8. +58 −20 core/src/main/java/com/novoda/imageloader/core/model/ImageTagFactory.java
  9. +7 −1 core/src/main/java/com/novoda/imageloader/core/model/ImageWrapper.java
  10. +78 −21 core/src/test/java/com/novoda/imageloader/core/ImageManagerTest.java
  11. +0 −22 core/src/test/java/com/novoda/imageloader/core/bitmap/BitmapUtilTest.java
  12. +23 −32 core/src/test/java/com/novoda/imageloader/core/file/util/FileUtilTest.java
  13. +13 −13 core/src/test/java/com/novoda/imageloader/core/model/ImageTagFactoryTest.java
  14. +15 −7 core/src/test/java/com/novoda/imageloader/core/model/ImageWrapperTest.java
  15. +1 −0 demo/assets/bugsense_api_key.txt
  16. +5 −0 demo/pom.xml
  17. +2 −5 demo/src/com/novoda/imageloader/demo/DemoApplication.java
  18. +10 −15 demo/src/com/novoda/imageloader/demo/activity/BigImages.java
  19. +17 −1 demo/src/com/novoda/imageloader/demo/activity/Demos.java
  20. +1 −1 demo/src/com/novoda/imageloader/demo/activity/ImageLongList.java
  21. +22 −28 demo/src/com/novoda/imageloader/demo/activity/LongSmallImageList.java
  22. +11 −20 demo/src/com/novoda/imageloader/demo/activity/base/SingleTableBaseListActivity.java
  23. +59 −0 demo/src/com/novoda/imageloader/demo/util/BugSenseHelper.java
  24. +15 −0 demo/src/com/novoda/imageloader/demo/util/BugsenseApiKeyFailedException.java
  25. +0 −4 pom.xml
@@ -1,13 +1,11 @@
package com.novoda.imageloader.acceptance;
import android.test.ActivityInstrumentationTestCase2;
-import android.test.UiThreadTest;
import android.widget.ListView;
-
import com.jayway.android.robotium.solo.Solo;
import com.novoda.imageloader.demo.activity.ImageLongList;
-public class ImageLoaderDemoActivityTest extends ActivityInstrumentationTestCase2<ImageLongList>{
+public class ImageLoaderDemoActivityTest extends ActivityInstrumentationTestCase2<ImageLongList> {
private static final int QUICK = 2;
@@ -22,42 +20,16 @@ public void testOpenTheActivity(){
solo = new Solo(getInstrumentation(), getActivity());
assertNotNull(solo);
}
-
- //TODO work in progress
- @UiThreadTest
- public void IGNORE_testLoadingImage() {
- solo = new Solo(getInstrumentation(), getActivity());
- list = getActivity().getListView();
- int i = 0;
- try {
- while (true) {
- list.setSelection(i);
- i++;
- }
- } catch (Exception e) {
- assertFalse("" + e.getMessage(), i == 0);
- }
- try {
- while (true) {
- list.setSelection(i);
- i--;
- }
- } catch (Exception e) {
- assertTrue("" + e.getMessage(), i > 0);
- }
- }
-
- private boolean isListAtTheTop() {
- return list.getFirstVisiblePosition() == 0;
- }
- private boolean isListAtTheBottom(){
- return list.getLastVisiblePosition() == (list.getCount() - 1);
- }
+ public void testScrollingThroughList() {
+ solo = new Solo(getInstrumentation(), getActivity());
+ list = getActivity().getListView();
- public void startNextActivity(){
-// btn = getActivity().getString(R.string.)
-// robotium.clickOnButton(btn);
- }
+ for (int i = 0; i < list.getCount(); i++) {
+ solo.scrollDown();
+ }
+
+ assertEquals(list.getLastVisiblePosition(), list.getSelectedItemPosition());
+ }
}
@@ -28,10 +28,6 @@
import com.novoda.imageloader.core.network.NetworkManager;
import com.novoda.imageloader.core.network.UrlNetworkManager;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* ImageManager has the responsibility to provide a
* simple and easy interface to access three fundamental part of the imageLoader
@@ -47,10 +43,8 @@
private LoaderContext loaderContext;
private Loader loader;
private CacheManager cacheManager;
- private List listenerStrongRef;
public ImageManager(Context context, LoaderSettings settings) {
- listenerStrongRef = new ArrayList();
this.loaderContext = new LoaderContext();
loaderContext.setSettings(settings);
loaderContext.setFileManager(new BasicFileManager(settings));
@@ -105,13 +99,12 @@ private void verifyPermission(Context c, String permission) {
}
}
- public void registerOnImageLoadedListener(OnImageLoadedListener listener) {
- WeakReference<OnImageLoadedListener> weakListener = new WeakReference<OnImageLoadedListener>(listener);
- listenerStrongRef.add(weakListener);
- loaderContext.setListener(weakListener);
+ public void setOnImageLoadedListener(OnImageLoadedListener listener) {
+ loaderContext.setListener(listener);
}
public void unRegisterOnImageLoadedListener(OnImageLoadedListener listener) {
- listenerStrongRef.remove(listener);
+ loaderContext.removeOnImageLoadedListener(listener.hashCode());
}
+
}
@@ -21,6 +21,7 @@
import com.novoda.imageloader.core.network.NetworkManager;
import java.lang.ref.WeakReference;
+import java.util.HashMap;
/**
* LoaderContext provides a generic context for the imageLoader
@@ -36,7 +37,12 @@
private CacheManager resBitmapCache;
private LoaderSettings settings;
private BitmapUtil bitmapUtil = new BitmapUtil();
- private WeakReference<OnImageLoadedListener> onImageLoadedListener;
+ private HashMap<Integer, WeakReference> weakListeners;
+ private int listenerKey;
+
+ public LoaderContext() {
+ weakListeners = new HashMap<Integer, WeakReference>();
+ }
public FileManager getFileManager() {
return fileManager;
@@ -82,12 +88,18 @@ public BitmapUtil getBitmapUtil() {
return bitmapUtil;
}
- public void setListener(WeakReference<OnImageLoadedListener> listener) {
- this.onImageLoadedListener = listener;
+ public void setListener(OnImageLoadedListener listener) {
+ listenerKey = listener.hashCode();
+ WeakReference<OnImageLoadedListener> weakReference = new WeakReference<OnImageLoadedListener>(listener);
+ weakListeners.put(listenerKey, weakReference);
}
public WeakReference<OnImageLoadedListener> getListener() {
- return onImageLoadedListener;
+ return (WeakReference<OnImageLoadedListener>) weakListeners.get(listenerKey);
+ }
+
+ public void removeOnImageLoadedListener(int listenerKey) {
+ weakListeners.remove(listenerKey);
}
}
@@ -15,17 +15,16 @@
*/
package com.novoda.imageloader.core.bitmap;
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-
import com.novoda.imageloader.core.model.ImageWrapper;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
/**
* Utility class abstract the usage of the BitmapFactory.
* It is shielding the users of this class from bugs and OutOfMemory exceptions.
@@ -35,8 +34,8 @@
private static final int BUFFER_SIZE = 64 * 1024;
- public Bitmap decodeFile(File f, int width, int height) {
- updateLastModifiedForCache(f);
+ public Bitmap decodeFile(File f, int width, int height) {
+ updateLastModifiedForCache(f);
int suggestedSize = height;
if (width > height) {
suggestedSize = width;
@@ -46,8 +45,8 @@ public Bitmap decodeFile(File f, int width, int height) {
return null;
}
return unscaledBitmap;
- }
-
+ }
+
public Bitmap decodeFileAndScale(File f, int width, int height) {
Bitmap unscaledBitmap = decodeFile(f, width, height);
if (unscaledBitmap == null) {
@@ -59,24 +58,24 @@ public Bitmap decodeFileAndScale(File f, int width, int height) {
@Deprecated
public Bitmap scaleResourceBitmap(Context c, int width, int height, int resourceId) {
- return decodeResourceBitmapAndScale(c, width, height, resourceId);
+ return decodeResourceBitmapAndScale(c, width, height, resourceId);
}
public Bitmap decodeResourceBitmap(Context c, int width, int height, int resourceId) {
Bitmap unscaledBitmap = null;
try {
- unscaledBitmap = BitmapFactory.decodeResource(c.getResources(), resourceId);
+ unscaledBitmap = BitmapFactory.decodeResource(c.getResources(), resourceId);
return unscaledBitmap;
} catch (final Throwable e) {
System.gc();
}
- return null;
+ return null;
}
-
- public Bitmap decodeResourceBitmapAndScale(Context c, int width, int height, int resourceId) {
+
+ public Bitmap decodeResourceBitmapAndScale(Context c, int width, int height, int resourceId) {
Bitmap unscaledBitmap = null;
try {
- unscaledBitmap = BitmapFactory.decodeResource(c.getResources(), resourceId);
+ unscaledBitmap = BitmapFactory.decodeResource(c.getResources(), resourceId);
return scaleBitmap(unscaledBitmap, width, height);
} catch (final Throwable e) {
System.gc();
@@ -92,7 +91,7 @@ public Bitmap decodeResourceBitmap(ImageWrapper w, int resId) {
public Bitmap scaleResourceBitmap(ImageWrapper w, int resId) {
return decodeResourceBitmapAndScale(w.getContext(), w.getWidth(), w.getHeight(), resId);
}
-
+
public Bitmap decodeResourceBitmapAndScale(ImageWrapper w, int resId) {
return decodeResourceBitmapAndScale(w.getContext(), w.getWidth(), w.getHeight(), resId);
}
@@ -123,7 +122,7 @@ public Bitmap scaleBitmap(Bitmap b, int width, int height) {
recycle(b);
return scaled;
}
-
+
public Bitmap decodeInputStream(InputStream is) {
Bitmap bitmap = null;
try {
@@ -16,9 +16,7 @@
package com.novoda.imageloader.core.loader;
import android.graphics.Bitmap;
-import android.util.Log;
import android.widget.ImageView;
-
import com.novoda.imageloader.core.LoaderContext;
import com.novoda.imageloader.core.exception.ImageNotFoundException;
import com.novoda.imageloader.core.loader.util.LoaderTask;
@@ -35,10 +33,6 @@ public ConcurrentLoader(LoaderContext loaderContext) {
@Override
public void load(ImageView imageView) {
ImageWrapper w = new ImageWrapper(imageView);
- if (w.getUrl() == null) {
- Log.w("ImageLoader", "You should never call load if you don't set a ImageTag on the view");
- return;
- }
try {
Bitmap b = loaderContext.getCache().get(w.getUrl(), w.getHeight(), w.getWidth());
if (b != null) {
@@ -73,11 +67,7 @@ private void setResource(ImageWrapper w, int resId) {
w.setBitmap(b);
return;
}
- if (loaderContext.getSettings().isAlwaysUseOriginalSize()){
- b = loaderContext.getBitmapUtil().decodeResourceBitmap(w, resId);
- } else {
- b = loaderContext.getBitmapUtil().decodeResourceBitmapAndScale(w, resId);
- }
+ b = loaderContext.getBitmapUtil().scaleResourceBitmap(w, resId);
loaderContext.getResBitmapCache().put("" + resId, b);
w.setBitmap(b);
}
@@ -15,17 +15,16 @@
*/
package com.novoda.imageloader.core.loader;
-import java.io.File;
-
import android.graphics.Bitmap;
import android.widget.ImageView;
-
import com.novoda.imageloader.core.LoaderContext;
import com.novoda.imageloader.core.exception.ImageNotFoundException;
import com.novoda.imageloader.core.loader.util.BitmapDisplayer;
import com.novoda.imageloader.core.loader.util.SingleThreadedLoader;
import com.novoda.imageloader.core.model.ImageWrapper;
+import java.io.File;
+
public class SimpleLoader implements Loader {
private LoaderContext loaderContext;
@@ -82,24 +81,13 @@ private Bitmap getBitmap(String url, int width, int height) {
if (url != null && url.length() >= 0) {
File f = loaderContext.getFileManager().getFile(url);
if (f.exists()) {
- Bitmap b;
- if (loaderContext.getSettings().isAlwaysUseOriginalSize()){
- b = loaderContext.getBitmapUtil().decodeFile(f, width, height);
- } else {
- b = loaderContext.getBitmapUtil().decodeFileAndScale(f, width, height);
- }
+ Bitmap b = loaderContext.getBitmapUtil().decodeFileAndScale(f, width, height);
if (b != null) {
return b;
}
}
loaderContext.getNetworkManager().retrieveImage(url, f);
-
- if (loaderContext.getSettings().isAlwaysUseOriginalSize()){
- return loaderContext.getBitmapUtil().decodeFile(f, width, height);
- } else {
- return loaderContext.getBitmapUtil().decodeFileAndScale(f, width, height);
- }
-
+ return loaderContext.getBitmapUtil().decodeFileAndScale(f, width, height);
}
return null;
}
@@ -110,13 +98,9 @@ private void setResource(ImageWrapper w, int resId) {
w.setBitmap(b);
return;
}
- if (loaderContext.getSettings().isAlwaysUseOriginalSize()){
- b = loaderContext.getBitmapUtil().decodeResourceBitmap(w, resId);
- } else {
- b = loaderContext.getBitmapUtil().decodeResourceBitmapAndScale(w, resId);
- }
+ b = loaderContext.getBitmapUtil().scaleResourceBitmap(w, resId);
loaderContext.getResBitmapCache().put("" + resId, b);
w.setBitmap(b);
}
-}
+}
Oops, something went wrong.

0 comments on commit 62e0b12

Please sign in to comment.