Skip to content
Browse files

some javadoc, clean up of the demo app

  • Loading branch information...
1 parent f5aed13 commit 2d95e5f0f785d73f8e430a69b2e65abe415be07c @luigi-agosti luigi-agosti committed
Showing with 357 additions and 174 deletions.
  1. +10 −0 core/src/main/java/com/novoda/imageloader/core/ImageManager.java
  2. +7 −0 core/src/main/java/com/novoda/imageloader/core/LoaderContext.java
  3. +13 −0 core/src/main/java/com/novoda/imageloader/core/LoaderSettings.java
  4. +4 −0 core/src/main/java/com/novoda/imageloader/core/bitmap/BitmapUtil.java
  5. +5 −0 core/src/main/java/com/novoda/imageloader/core/cache/CacheManager.java
  6. +14 −0 core/src/main/java/com/novoda/imageloader/core/cache/LruBitmapCache.java
  7. +0 −41 core/src/main/java/com/novoda/imageloader/core/cache/MapCache.java
  8. +4 −0 core/src/main/java/com/novoda/imageloader/core/cache/NoCache.java
  9. +5 −0 core/src/main/java/com/novoda/imageloader/core/cache/SoftMapCache.java
  10. +7 −0 core/src/main/java/com/novoda/imageloader/core/cache/pakage.html
  11. +1 −1 core/src/main/java/com/novoda/imageloader/core/cache/{ → util}/LruCache.java
  12. +3 −0 core/src/main/java/com/novoda/imageloader/core/file/FileManager.java
  13. +7 −0 core/src/main/java/com/novoda/imageloader/core/pakage.html
  14. +4 −0 core/src/main/java/com/novoda/imageloader/core/util/DirectLoader.java
  15. +4 −0 core/src/main/java/com/novoda/imageloader/core/util/pakage.html
  16. +0 −4 demo/AndroidManifest.xml
  17. +51 −0 demo/README.textile
  18. +0 −1 demo/res/values/arrays.xml
  19. +0 −1 demo/res/values/strings.xml
  20. +41 −15 demo/src/com/novoda/imageloader/demo/DemoApplication.java
  21. +55 −0 demo/src/com/novoda/imageloader/demo/activity/BigImages.java
  22. +3 −3 demo/src/com/novoda/imageloader/demo/activity/Demos.java
  23. +4 −1 demo/src/com/novoda/imageloader/demo/activity/DirectLoading.java
  24. +0 −22 demo/src/com/novoda/imageloader/demo/activity/FromCacheOnly.java
  25. +51 −4 demo/src/com/novoda/imageloader/demo/activity/ImageLongList.java
  26. +51 −7 demo/src/com/novoda/imageloader/demo/activity/LongSmallImageList.java
  27. +5 −53 demo/src/com/novoda/imageloader/demo/activity/base/SingleTableBaseListActivity.java
  28. +3 −9 demo/src/com/novoda/imageloader/demo/provider/CustomUriMatcher.java
  29. +5 −8 demo/src/com/novoda/imageloader/demo/provider/DatabaseManager.java
  30. +0 −4 demo/src/com/novoda/imageloader/demo/provider/ImageLoaderDemoProvider.java
View
10 core/src/main/java/com/novoda/imageloader/core/ImageManager.java
@@ -29,6 +29,16 @@
import com.novoda.imageloader.core.network.NetworkManager;
import com.novoda.imageloader.core.network.UrlNetworkLoader;
+/**
+ * ImageManager has the responsibility to provide a
+ * simple and easy interface to access three fundamental part of the imageLoader
+ * library : the FileManager, the NetworkManager, and the CacheManager.
+ * An ImageManager instance can be instantiated at the application level and used
+ * statically across the application.
+ *
+ * Manifest.permission.WRITE_EXTERNAL_STORAGE and Manifest.permission.INTERNET are
+ * currently necessary for the imageLoader library to work properly.
+ */
public class ImageManager {
private LoaderContext loaderContext;
View
7 core/src/main/java/com/novoda/imageloader/core/LoaderContext.java
@@ -20,6 +20,13 @@
import com.novoda.imageloader.core.file.FileManager;
import com.novoda.imageloader.core.network.NetworkManager;
+/**
+ * LoaderContext provides a generic context for the imageLoader
+ * where different objects can access different levels of caching,
+ * the BitmapUtil, and all the customized settings.
+ *
+ * This class is supposed to be used internally.
+ */
public class LoaderContext {
private FileManager fileManager;
private NetworkManager networkManager;
View
13 core/src/main/java/com/novoda/imageloader/core/LoaderSettings.java
@@ -23,6 +23,11 @@
import com.novoda.imageloader.core.cache.CacheManager;
import com.novoda.imageloader.core.file.util.FileUtil;
+/**
+ * LoaderSettings is the main class used to customize the behavior of the imageLoader.
+ * To provide a more user friendly way to set different parameters it is possible to use
+ * a builder : SettingsBuilder.
+ */
public class LoaderSettings {
private static final long DEFAULT_EXPIRATION_PERIOD = 7l * 24l * 3600l * 1000l;
@@ -123,6 +128,9 @@ public void setUseAsyncTasks(boolean useAsyncTasks) {
this.useAsyncTasks = useAsyncTasks;
}
+ /**
+ * Builder for the LoaderSettings.
+ */
public static class SettingsBuilder {
private LoaderSettings settings;
@@ -160,6 +168,11 @@ public SettingsBuilder withAsyncTasks(boolean useAsyncTasks) {
settings.setUseAsyncTasks(useAsyncTasks);
return this;
}
+
+ public SettingsBuilder withCacheDir(File file) {
+ settings.setCacheDir(file);
+ return this;
+ }
public LoaderSettings build(Context context) {
settings.setCacheDir(new FileUtil().prepareCacheDirectory(context));
View
4 core/src/main/java/com/novoda/imageloader/core/bitmap/BitmapUtil.java
@@ -26,6 +26,10 @@
import com.novoda.imageloader.core.model.ImageWrapper;
+/**
+ * Utility class abstract the usage of the BitmapFactory.
+ * It is shielding the users of this class from bugs and OutOfMemory exceptions.
+ */
public class BitmapUtil {
private static final int BUFFER_SIZE = 64 * 1024;
View
5 core/src/main/java/com/novoda/imageloader/core/cache/CacheManager.java
@@ -17,6 +17,11 @@
import android.graphics.Bitmap;
+/**
+ * Interface for all the in memory cache managers.
+ * There are three main type of memory cache managers :
+ * NoChace, SoftMapCache, and LruBitmapCache
+ */
public interface CacheManager {
Bitmap get(String url, int width, int height);
View
14 core/src/main/java/com/novoda/imageloader/core/cache/LruBitmapCache.java
@@ -17,10 +17,18 @@
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;
+/**
+ * LruBitmapCache overcome the issue with soft reference cache.
+ * It is in fact keeping all the certain amount of images in memory.
+ * The size of the memory used for cache depends on the memory that the android
+ * SDK provide to the application and the percentage specified (by default is 25MB).
+ */
public class LruBitmapCache implements CacheManager {
public static final int DEFAULT_MEMORY_CACHE_PERCENTAGE = 25;
@@ -29,6 +37,7 @@
private int capacity;
/**
+ * It is possible to set a specific percentage of memory to be used only for images.
* @param context
* @param percentageOfMemoryForCache 1-80
*/
@@ -57,6 +66,11 @@ public LruBitmapCache(Context context, int percentageOfMemoryForCache) {
reset();
}
+ /**
+ * Setting the default memory size to 25% percent of the total memory
+ * available of the application.
+ * @param context
+ */
public LruBitmapCache(Context context) {
this(context, DEFAULT_MEMORY_CACHE_PERCENTAGE);
}
View
41 core/src/main/java/com/novoda/imageloader/core/cache/MapCache.java
@@ -1,41 +0,0 @@
-/**
- * Copyright 2012 Novoda Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.novoda.imageloader.core.cache;
-
-import java.util.HashMap;
-
-import android.graphics.Bitmap;
-
-public class MapCache implements CacheManager {
-
- private HashMap<String, Bitmap> cache = new HashMap<String, Bitmap>();
-
- @Override
- public Bitmap get(String url, int width, int height) {
- return cache.get(url);
- }
-
- @Override
- public void put(String url, Bitmap bmp) {
- cache.put(url, bmp);
- }
-
- @Override
- public void clean() {
- cache.clear();
- }
-
-}
View
4 core/src/main/java/com/novoda/imageloader/core/cache/NoCache.java
@@ -17,6 +17,10 @@
import android.graphics.Bitmap;
+/**
+ * This cache manager do not keep image in memory.
+ * Can be useful in some scenario.
+ */
public class NoCache implements CacheManager {
@Override
View
5 core/src/main/java/com/novoda/imageloader/core/cache/SoftMapCache.java
@@ -20,6 +20,11 @@
import android.graphics.Bitmap;
+/**
+ * Very simple version of memory cache using soft reference.
+ * Soft Reference do not provide the best solution for memory cache in android.
+ * This because the garbage collector is removing very quickly soft referenced objects.
+ */
public class SoftMapCache implements CacheManager {
private HashMap<String, SoftReference<Bitmap>> cache = new HashMap<String, SoftReference<Bitmap>>();
View
7 core/src/main/java/com/novoda/imageloader/core/cache/pakage.html
@@ -0,0 +1,7 @@
+<html>
+<body>
+This package contains all the classes with the responsibility to manage memory cache.<br>
+@See NoCache
+@See LruBitmapCache
+@See SoftMapCache
+</body>
View
2 ...voda/imageloader/core/cache/LruCache.java → ...imageloader/core/cache/util/LruCache.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.novoda.imageloader.core.cache;
+package com.novoda.imageloader.core.cache.util;
import java.util.LinkedHashMap;
import java.util.Map;
View
3 core/src/main/java/com/novoda/imageloader/core/file/FileManager.java
@@ -19,6 +19,9 @@
import android.graphics.Bitmap;
+/**
+ * FileManager is an interface marking all the implementation of file cache managers.
+ */
public interface FileManager {
void clean();
View
7 core/src/main/java/com/novoda/imageloader/core/pakage.html
@@ -0,0 +1,7 @@
+<html>
+<body>
+ImageLoader is a simple library to help you download, display and cache images in your Android applications.<br>
+<a href="http://androidimageloader.com/"></a><br>
+@See ImageManager
+@See LoaderSettings
+</body>
View
4 core/src/main/java/com/novoda/imageloader/core/util/DirectLoader.java
@@ -9,6 +9,10 @@
import com.novoda.imageloader.core.network.NetworkManager;
import com.novoda.imageloader.core.network.UrlNetworkLoader;
+/**
+ * Direct loader make use of the NetworkManager and the BitmapUtil
+ * to provide a direct way to get a Bitmap given a http url.
+ */
public class DirectLoader {
private NetworkManager networkManager;
View
4 core/src/main/java/com/novoda/imageloader/core/util/pakage.html
@@ -0,0 +1,4 @@
+<html>
+<body>
+This package contains a few classes that are not yet well define, so use them carefully.<br>
+</body>
View
4 demo/AndroidManifest.xml
@@ -40,10 +40,6 @@
android:label="@string/large_list" />
<activity
- android:name=".activity.FromCacheOnly"
- android:label="@string/cache_only" />
-
- <activity
android:name=".activity.DirectLoading"
android:label="@string/direct_loader" />
View
51 demo/README.textile
@@ -0,0 +1,51 @@
+h1. ImageLoader demo
+
+ImageLoader provides a demo application so that you can quickly see potential use cases for the imageLoader library
+
+"Install the ImageLoader application":https://play.google.com/store/apps/details?id=com.novoda.imageloader.demo
+
+h2. Examples
+
+Generally a good way to use the imageLoader is to initialize an instance in the Application class and keep a static reference that can be accessed from every part of the app.
+
+<pre><code>
+private static ImageManager imageManager;
+
+@Override
+public void onCreate() {
+ super.onCreate();
+ normalImageManagerSettings();
+}
+
+private void normalImageManagerSettings() {
+ imageManager = new ImageManager(this, new SettingsBuilder()
+ .withCacheManager(new LruBitmapCache(this)).build(this));
+}
+</code></pre>
+
+h3. Long list of images
+
+
+h3. Long list of small images
+
+
+h3. Big images
+
+This activity is to demo the stability with very big images.
+
+h3. Direct Loading
+
+If you don't want to use the async feature of the image loader, but you don't want to set up a HttpClient or a UrlConnection to get the image, you can use the ImageLoader library to do it.
+
+<pre><code>
+import com.novoda.imageloader.core.util.DirectLoader;
+
+DirectLoader dl = new DirectLoader();
+Bitmap b = dl.download("http://www.asianweek.com/wp-content/uploads/2012/03/microsoft_logo11.jpg");
+</code></pre>
+
+This functionality should be used carefully as interface may change in the next few releases and outside of the main thread.
+
+h3. Gallery Demo
+
+Work in progress...
View
1 demo/res/values/arrays.xml
@@ -5,7 +5,6 @@
<item>@string/long_list</item>
<item>@string/long_small_list</item>
<item>@string/large_list</item>
- <item>@string/cache_only</item>
<item>@string/direct_loader</item>
</string-array>
</resources>
View
1 demo/res/values/strings.xml
@@ -4,7 +4,6 @@
<string name="app_name">ImageLoader Demo</string>
<string name="long_list">Long List</string>
<string name="long_small_list">Long Small Image List</string>
- <string name="cache_only">Cached Only</string>
<string name="large_list">Large Images</string>
<string name="direct_loader">Direct Loader</string>
</resources>
View
56 demo/src/com/novoda/imageloader/demo/DemoApplication.java
@@ -1,5 +1,7 @@
package com.novoda.imageloader.demo;
+import java.io.File;
+
import android.app.Application;
import com.novoda.imageloader.core.ImageManager;
@@ -9,32 +11,56 @@
public class DemoApplication extends Application {
- /*
- * TODO Initialise the image manager in your application.
- * You can have more than one if you need different settings.
+ /**
+ * It is possible to keep a static reference across the
+ * application of the image loader.
*/
private static ImageManager imageManager;
- private static ImageManager thumbnailImageLoader;
@Override
public void onCreate() {
super.onCreate();
- // TODO Initialise your image manager settings.
- LoaderSettings settings = new SettingsBuilder().withDisconnectOnEveryCall(true).build(this);
- imageManager = new ImageManager(this, settings);
+
+ normalImageManagerSettings();
+ }
- settings = new SettingsBuilder().withDisconnectOnEveryCall(true).withAsyncTasks(false)
- .withCacheManager(new LruBitmapCache(this)).build(this);
- thumbnailImageLoader = new ImageManager(this, settings);
+ /**
+ * Normal image manager settings
+ */
+ private void normalImageManagerSettings() {
+ imageManager = new ImageManager(this, new SettingsBuilder()
+ .withCacheManager(new LruBitmapCache(this)).build(this));
}
- // TODO Create a method to access your image manager.
- public static ImageManager getImageLoader() {
- return imageManager;
+ /**
+ * There are different settings that you can use to customize
+ * the usage of the image loader for your application.
+ */
+ @SuppressWarnings("unused")
+ private void verboseImageManagerSettings() {
+ SettingsBuilder settingsBuilder = new SettingsBuilder();
+ //You can force the urlConnection to disconnect after every call.
+ settingsBuilder.withDisconnectOnEveryCall(true);
+ //We have different types of cache, check cache package for more info
+ settingsBuilder.withCacheManager(new LruBitmapCache(this));
+ //You can set a specific read timeout
+ settingsBuilder.withReadTimeout(30000);
+ //You can set a specific connection timeout
+ settingsBuilder.withConnectionTimeout(30000);
+ //You can disable the multi-threading ability to download image
+ settingsBuilder.withAsyncTasks(false);
+ //You can set a specific directory for caching files on the sdcard
+ settingsBuilder.withCacheDir(new File("/something"));
+
+ LoaderSettings loaderSettings = settingsBuilder.build(this);
+ imageManager = new ImageManager(this, loaderSettings);
}
- public static ImageManager getThumbnailImageLoader() {
- return thumbnailImageLoader;
+ /**
+ * Convenient method of access the imageLoader
+ */
+ public static ImageManager getImageLoader() {
+ return imageManager;
}
}
View
55 demo/src/com/novoda/imageloader/demo/activity/BigImages.java
@@ -1,12 +1,67 @@
package com.novoda.imageloader.demo.activity;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.view.View;
+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;
+import com.novoda.imageloader.demo.R;
import com.novoda.imageloader.demo.activity.base.SingleTableBaseListActivity;
+/**
+ * This is an example using really big images and see
+ * how the image loader can keep up with the memory limitations of android.
+ */
public class BigImages extends SingleTableBaseListActivity {
+ /**
+ * TODO
+ * Generally we can keep an instance of the
+ * image loader and the imageTagFactory.
+ */
+ private ImageManager imageManager;
+ private ImageTagFactory imageTagFactory;
+
@Override
protected String getTableName() {
return BigImages.class.getSimpleName().toLowerCase();
}
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.single_table_base_list_activity);
+ /**
+ * TODO
+ * Need to prepare imageLoader and imageTagFactory
+ */
+ imageManager = DemoApplication.getImageLoader();
+ imageTagFactory = new ImageTagFactory(this, R.drawable.bg_img_loading);
+ imageTagFactory.setErrorImageId(R.drawable.bg_img_notfound);
+ setAdapter();
+ }
+
+ /**
+ * TODO
+ * Generally you will have a binder where you have to set the image.
+ * This is an example of using the imageManager to load
+ */
+ @Override
+ protected ViewBinder getViewBinder() {
+ return new ViewBinder() {
+ @Override
+ public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
+ String url = cursor.getString(columnIndex);
+ ((ImageView) view).setTag(imageTagFactory.build(url));
+ imageManager.getLoader().load((ImageView) view);
+ return true;
+ }
+
+ };
+ }
}
View
6 demo/src/com/novoda/imageloader/demo/activity/Demos.java
@@ -10,6 +10,9 @@
import com.novoda.imageloader.demo.R;
+/**
+ * Nothing really interesting here just a dashboard.
+ */
public class Demos extends Activity implements OnItemClickListener {
@Override
@@ -33,9 +36,6 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
startActivity(new Intent(Demos.this, BigImages.class));
break;
case 3:
- startActivity(new Intent(Demos.this, FromCacheOnly.class));
- break;
- case 4:
startActivity(new Intent(Demos.this, DirectLoading.class));
}
}
View
5 demo/src/com/novoda/imageloader/demo/activity/DirectLoading.java
@@ -8,6 +8,9 @@
import com.novoda.imageloader.core.util.DirectLoader;
import com.novoda.imageloader.demo.R;
+/**
+ * Direct loading example.
+ */
public class DirectLoading extends Activity {
private ImageView imageView;
@@ -22,7 +25,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onResume() {
super.onResume();
- /*
+ /**
* TODO Don't use the direct loader like this.
* It's useful for downloading a Bitmap to display in a notification.
* You need to handle the threading yourself.
View
22 demo/src/com/novoda/imageloader/demo/activity/FromCacheOnly.java
@@ -1,22 +0,0 @@
-package com.novoda.imageloader.demo.activity;
-
-import com.novoda.imageloader.core.model.ImageTagFactory;
-import com.novoda.imageloader.demo.DemoApplication;
-import com.novoda.imageloader.demo.R;
-import com.novoda.imageloader.demo.activity.base.SingleTableBaseListActivity;
-
-public class FromCacheOnly extends SingleTableBaseListActivity {
-
- @Override
- protected String getTableName() {
- return FromCacheOnly.class.getSimpleName().toLowerCase();
- }
-
- protected void prepareLoader() {
- // TODO You can tell the the image manager to load from cache only in the tag factory.
- imageManager = DemoApplication.getImageLoader();
- imageTagFactory = new ImageTagFactory(this, R.drawable.bg_img_loading);
- imageTagFactory.setErrorImageId(R.drawable.bg_img_notfound);
- imageTagFactory.setUseOnlyCache(true);
- }
-}
View
55 demo/src/com/novoda/imageloader/demo/activity/ImageLongList.java
@@ -1,24 +1,71 @@
package com.novoda.imageloader.demo.activity;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.view.View;
+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;
import com.novoda.imageloader.demo.R;
import com.novoda.imageloader.demo.activity.base.SingleTableBaseListActivity;
+/**
+ * Example of setting a specific image size.
+ * Not that you can ask the imageLoader to store the small image as files.
+ * In this way you don't need to scale images every time
+ */
public class ImageLongList extends SingleTableBaseListActivity {
private static final int SIZE = 400;
+
+ /**
+ * TODO
+ * Generally we can keep an instance of the
+ * image loader and the imageTagFactory.
+ */
+ private ImageManager imageManager;
+ private ImageTagFactory imageTagFactory;
- protected void prepareLoader() {
- // TODO Setup image tag factory parameters.
+ @Override
+ protected String getTableName() {
+ return ImageLongList.class.getSimpleName().toLowerCase();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.single_table_base_list_activity);
+ /**
+ * TODO
+ * Need to prepare imageLoader and imageTagFactory
+ */
imageManager = DemoApplication.getImageLoader();
imageTagFactory = new ImageTagFactory(SIZE, SIZE, R.drawable.bg_img_loading);
imageTagFactory.setErrorImageId(R.drawable.bg_img_notfound);
+ imageTagFactory.setSaveThumbnail(true);
+ setAdapter();
}
+ /**
+ * TODO
+ * Generally you will have a binder where you have to set the image.
+ * This is an example of using the imageManager to load
+ */
@Override
- protected String getTableName() {
- return ImageLongList.class.getSimpleName().toLowerCase();
+ protected ViewBinder getViewBinder() {
+ return new ViewBinder() {
+ @Override
+ public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
+ String url = cursor.getString(columnIndex);
+ ((ImageView) view).setTag(imageTagFactory.build(url));
+ imageManager.getLoader().load((ImageView) view);
+ return true;
+ }
+
+ };
}
}
View
58 demo/src/com/novoda/imageloader/demo/activity/LongSmallImageList.java
@@ -1,30 +1,74 @@
package com.novoda.imageloader.demo.activity;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.view.View;
+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;
import com.novoda.imageloader.demo.R;
import com.novoda.imageloader.demo.activity.base.SingleTableBaseListActivity;
+/**
+ * Very similar to imageLongList example.
+ */
public class LongSmallImageList extends SingleTableBaseListActivity {
private static final int SIZE = 80;
+ /**
+ * TODO
+ * Generally we can keep an instance of the
+ * image loader and the imageTagFactory.
+ */
+ private ImageManager imageManager;
+ private ImageTagFactory imageTagFactory;
+
+ @Override
+ protected String getTableName() {
+ return LongSmallImageList.class.getSimpleName().toLowerCase();
+ }
+
@Override
protected int getImageItem() {
return R.layout.small_image_item;
}
-
+
@Override
- protected void prepareLoader() {
- // TODO Setup image tag factory parameters.
- imageManager = DemoApplication.getThumbnailImageLoader();
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.single_table_base_list_activity);
+ /**
+ * TODO
+ * Need to prepare imageLoader and imageTagFactory
+ */
+ imageManager = DemoApplication.getImageLoader();
imageTagFactory = new ImageTagFactory(SIZE, SIZE, R.drawable.bg_img_loading);
imageTagFactory.setErrorImageId(R.drawable.bg_img_notfound);
+ imageTagFactory.setSaveThumbnail(true);
+ setAdapter();
}
-
+
+ /**
+ * TODO
+ * Generally you will have a binder where you have to set the image.
+ * This is an example of using the imageManager to load
+ */
@Override
- protected String getTableName() {
- return LongSmallImageList.class.getSimpleName().toLowerCase();
+ protected ViewBinder getViewBinder() {
+ return new ViewBinder() {
+ @Override
+ public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
+ String url = cursor.getString(columnIndex);
+ ((ImageView) view).setTag(imageTagFactory.build(url));
+ imageManager.getLoader().load((ImageView) view);
+ return true;
+ }
+
+ };
}
}
View
58 demo/src/com/novoda/imageloader/demo/activity/base/SingleTableBaseListActivity.java
@@ -3,16 +3,10 @@
import android.app.ListActivity;
import android.database.Cursor;
import android.net.Uri;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.SimpleCursorAdapter.ViewBinder;
-import com.novoda.imageloader.core.ImageManager;
-import com.novoda.imageloader.core.model.ImageTagFactory;
-import com.novoda.imageloader.demo.DemoApplication;
import com.novoda.imageloader.demo.R;
public abstract class SingleTableBaseListActivity extends ListActivity {
@@ -20,55 +14,11 @@
private static final String[] FROM = new String[] { "url" };
private static final int[] TO = new int[] { R.id.list_item_image };
- // TODO add this to your class
- protected ImageManager imageManager;
- protected ImageTagFactory imageTagFactory;
- //
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.single_table_base_list_activity);
- // TODO add this to your class
- prepareLoader();
- //
- setAdapter();
- }
-
- protected void prepareLoader() {
- imageManager = DemoApplication.getImageLoader();
- imageTagFactory = new ImageTagFactory(this, R.drawable.bg_img_loading);
- imageTagFactory.setErrorImageId(R.drawable.bg_img_notfound);
- }
-
- protected void load(View view) {
- // TODO add this to your class
- imageManager.getLoader().load((ImageView) view);
- //
- }
-
protected int getImageItem() {
return R.layout.image_item;
}
-
- private ViewBinder getViewBinder() {
- return new ViewBinder() {
- @Override
- public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
- setTag(view, cursor, columnIndex);
- return true;
- }
-
- };
- }
-
- protected void setTag(View view, Cursor cursor, int columnIndex) {
- String url = cursor.getString(columnIndex);
- ((ImageView) view).setTag(imageTagFactory.build(url));
- load(view);
- }
-
- private SimpleCursorAdapter initAdapter() {
+
+ protected SimpleCursorAdapter initAdapter() {
return new SimpleCursorAdapter(this, getImageItem(), getCursor(), FROM, TO);
}
@@ -79,7 +29,7 @@ private Cursor getCursor() {
protected abstract String getTableName();
- private void setAdapter() {
+ protected void setAdapter() {
SimpleCursorAdapter adapter = initAdapter();
ListView lv = getListView();
ViewBinder binder = getViewBinder();
@@ -89,4 +39,6 @@ private void setAdapter() {
lv.setAdapter(adapter);
}
+ protected abstract ViewBinder getViewBinder();
+
}
View
12 demo/src/com/novoda/imageloader/demo/provider/CustomUriMatcher.java
@@ -1,13 +1,12 @@
package com.novoda.imageloader.demo.provider;
+import android.content.UriMatcher;
+import android.net.Uri;
+
import com.novoda.imageloader.demo.activity.BigImages;
-import com.novoda.imageloader.demo.activity.FromCacheOnly;
import com.novoda.imageloader.demo.activity.ImageLongList;
import com.novoda.imageloader.demo.activity.LongSmallImageList;
-import android.content.UriMatcher;
-import android.net.Uri;
-
public class CustomUriMatcher extends UriMatcher {
public static final String IMAGE_COLLECTION_TYPE = "vnd.android.cursor.dir/vnd.imageloader.demo."
@@ -18,10 +17,6 @@
+ BigImages.class.getSimpleName().toLowerCase();
public static final int IMAGE_BIGIMAGES_INCOMING_COLLECTION = 40;
- public static final String IMAGE_FROMCACHEONLY_COLLECTION_TYPE = "vnd.android.cursor.dir/vnd.imageloader.demo."
- + FromCacheOnly.class.getSimpleName().toLowerCase();
- public static final int IMAGE_FROMCACHEONLY_INCOMING_COLLECTION = 60;
-
public static final String IMAGE_LONGSMALLIMAGELIST_COLLECTION_TYPE = "vnd.android.cursor.dir/vnd.imageloader.demo."
+ LongSmallImageList.class.getSimpleName().toLowerCase();
public static final int IMAGE_LONGSMALLIMAGELIST_INCOMING_COLLECTION = 80;
@@ -39,7 +34,6 @@ public CustomUriMatcher() {
public void setUp() {
add(ImageLongList.class.getSimpleName().toLowerCase(), IMAGE_INCOMING_COLLECTION);
add(BigImages.class.getSimpleName().toLowerCase(), IMAGE_BIGIMAGES_INCOMING_COLLECTION);
- add(FromCacheOnly.class.getSimpleName().toLowerCase(), IMAGE_FROMCACHEONLY_INCOMING_COLLECTION);
add(LongSmallImageList.class.getSimpleName().toLowerCase(), IMAGE_LONGSMALLIMAGELIST_INCOMING_COLLECTION);
}
View
13 demo/src/com/novoda/imageloader/demo/provider/DatabaseManager.java
@@ -4,18 +4,17 @@
import java.util.ArrayList;
import java.util.List;
-import com.novoda.imageloader.demo.activity.BigImages;
-import com.novoda.imageloader.demo.activity.FromCacheOnly;
-import com.novoda.imageloader.demo.activity.ImageLongList;
-import com.novoda.imageloader.demo.activity.LongSmallImageList;
-import com.novoda.imageloader.demo.activity.base.SingleTableBaseListActivity;
-
import android.content.Context;
import android.content.res.AssetManager;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
+import com.novoda.imageloader.demo.activity.BigImages;
+import com.novoda.imageloader.demo.activity.ImageLongList;
+import com.novoda.imageloader.demo.activity.LongSmallImageList;
+import com.novoda.imageloader.demo.activity.base.SingleTableBaseListActivity;
+
public class DatabaseManager extends SQLiteOpenHelper {
private Context context;
@@ -40,7 +39,6 @@ private void create(SQLiteDatabase db) {
List<String> stms = new ArrayList<String>();
addCreateStm(stms, ImageLongList.class);
addCreateStm(stms, BigImages.class);
- addCreateStm(stms, FromCacheOnly.class);
addCreateStm(stms, LongSmallImageList.class);
AssetManager mngr = context.getAssets();
try {
@@ -65,7 +63,6 @@ private void drop(SQLiteDatabase db) {
List<String> stms = new ArrayList<String>();
addDropStm(stms, ImageLongList.class);
addDropStm(stms, BigImages.class);
- addDropStm(stms, FromCacheOnly.class);
addDropStm(stms, LongSmallImageList.class);
exec(db, stms);
}
View
4 demo/src/com/novoda/imageloader/demo/provider/ImageLoaderDemoProvider.java
@@ -33,10 +33,6 @@ public String getType(Uri uri) {
type = CustomUriMatcher.IMAGE_BIGIMAGES_COLLECTION_TYPE;
break;
}
- case CustomUriMatcher.IMAGE_FROMCACHEONLY_INCOMING_COLLECTION: {
- type = CustomUriMatcher.IMAGE_FROMCACHEONLY_COLLECTION_TYPE;
- break;
- }
default: {
Log.e("ImageLoader", "Problem with query, not Implemented for : " + uri);
throw new RuntimeException("Problem with query, not Implemented for : " + uri);

0 comments on commit 2d95e5f

Please sign in to comment.
Something went wrong with that request. Please try again.