Permalink
Browse files

[sample] Update BitmapCache sample

Update to use v2.1 of the library. Properly use the new CacheableBitmapDrawable.
  • Loading branch information...
1 parent 2223cb4 commit 33e44bcdf664224ab9e286731b0827fdf06a7031 @chrisbanes chrisbanes committed with Jan 24, 2013
@@ -2,10 +2,10 @@
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
- <classpathentry kind="lib" path="libs/Android-BitmapCache-2.0.jar"/>
<classpathentry kind="lib" path="libs/android-support-v4.jar"/>
<classpathentry kind="lib" path="libs/disklrucache-1.3.0.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
+ <classpathentry kind="lib" path="libs/Android-BitmapCache-2.1.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
Binary file not shown.
Binary file not shown.
@@ -20,23 +20,23 @@
import org.lucasr.smoothie.samples.bitmapcache.PatternsListAdapter.ViewHolder;
import uk.co.senab.bitmapcache.BitmapLruCache;
-import uk.co.senab.bitmapcache.CacheableBitmapWrapper;
+import uk.co.senab.bitmapcache.CacheableBitmapDrawable;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.view.View;
import android.widget.Adapter;
-public class PatternsListLoader extends ItemLoader<String, CacheableBitmapWrapper> {
+public class PatternsListLoader extends ItemLoader<String, CacheableBitmapDrawable> {
final BitmapLruCache mCache;
public PatternsListLoader(BitmapLruCache cache) {
mCache = cache;
}
@Override
- public CacheableBitmapWrapper loadItemFromMemory(String url) {
+ public CacheableBitmapDrawable loadItemFromMemory(String url) {
return mCache.getFromMemoryCache(url);
}
@@ -46,8 +46,8 @@ public String getItemParams(Adapter adapter, int position) {
}
@Override
- public CacheableBitmapWrapper loadItem(String url) {
- CacheableBitmapWrapper wrapper = mCache.get(url);
+ public CacheableBitmapDrawable loadItem(String url) {
+ CacheableBitmapDrawable wrapper = mCache.get(url);
if (wrapper == null) {
wrapper = mCache.put(url, HttpHelper.loadImage(url));
}
@@ -56,24 +56,23 @@ public CacheableBitmapWrapper loadItem(String url) {
}
@Override
- public void displayItem(View itemView, CacheableBitmapWrapper result, boolean fromMemory) {
+ public void displayItem(View itemView, CacheableBitmapDrawable result, boolean fromMemory) {
ViewHolder holder = (ViewHolder) itemView.getTag();
if (result == null) {
holder.title.setText("Failed");
return;
}
- BitmapDrawable patternDrawable = new BitmapDrawable(itemView.getResources(), result.getBitmap());
- patternDrawable.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
+ result.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
if (fromMemory) {
- holder.image.setImageDrawable(patternDrawable);
+ holder.image.setImageDrawable(result);
} else {
BitmapDrawable emptyDrawable = new BitmapDrawable(itemView.getResources());
TransitionDrawable fadeInDrawable =
- new TransitionDrawable(new Drawable[] { emptyDrawable, patternDrawable });
+ new TransitionDrawable(new Drawable[] { emptyDrawable, result });
holder.image.setImageDrawable(fadeInDrawable);
fadeInDrawable.startTransition(200);

0 comments on commit 33e44bc

Please sign in to comment.