mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Merge pull request #627 from dbrant/master
Clean up image loading code, and switch to using Fresco.
This commit is contained in:
commit
6232e35816
7 changed files with 76 additions and 251 deletions
|
|
@ -8,16 +8,15 @@ import android.app.Application;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Build;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.util.LruCache;
|
||||
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.toolbox.BasicNetwork;
|
||||
import com.android.volley.toolbox.DiskBasedCache;
|
||||
import com.android.volley.toolbox.HurlStack;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.stetho.Stetho;
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.TotalSizeLimitedDiscCache;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
|
|
@ -188,51 +187,21 @@ public class CommonsApplication extends Application {
|
|||
.build();
|
||||
ImageLoader.getInstance().init(imageLoaderConfiguration);
|
||||
|
||||
Fresco.initialize(this);
|
||||
|
||||
// Initialize EventLogging
|
||||
EventLog.setApp(this);
|
||||
|
||||
// based off https://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
|
||||
// Cache for 1/8th of available VM memory
|
||||
long maxMem = Runtime.getRuntime().maxMemory();
|
||||
if (maxMem < 48L * 1024L * 1024L) {
|
||||
// Cache only one bitmap if VM memory is too small (such as Nexus One);
|
||||
Timber.d("Skipping bitmap cache; max mem is: %d", maxMem);
|
||||
imageCache = new LruCache<>(1);
|
||||
} else {
|
||||
int cacheSize = (int) (maxMem / (1024 * 8));
|
||||
Timber.d("Bitmap cache size %d from max mem %d", cacheSize, maxMem);
|
||||
imageCache = new LruCache<String, Bitmap>(cacheSize) {
|
||||
@Override
|
||||
protected int sizeOf(String key, Bitmap bitmap) {
|
||||
int bitmapSize;
|
||||
bitmapSize = bitmap.getByteCount();
|
||||
//For caching area -> categories
|
||||
cacheData = new CacheController();
|
||||
|
||||
// The cache size will be measured in kilobytes rather than number of items.
|
||||
return bitmapSize / 1024;
|
||||
}
|
||||
};
|
||||
}
|
||||
DiskBasedCache cache = new DiskBasedCache(getCacheDir(), 16 * 1024 * 1024);
|
||||
volleyQueue = new RequestQueue(cache, new BasicNetwork(new HurlStack()));
|
||||
volleyQueue.start();
|
||||
}
|
||||
|
||||
private com.android.volley.toolbox.ImageLoader imageLoader;
|
||||
private LruCache<String, Bitmap> imageCache;
|
||||
|
||||
public com.android.volley.toolbox.ImageLoader getImageLoader() {
|
||||
if(imageLoader == null) {
|
||||
imageLoader = new com.android.volley.toolbox.ImageLoader(getVolleyQueue(), new com.android.volley.toolbox.ImageLoader.ImageCache() {
|
||||
@Override
|
||||
public Bitmap getBitmap(String key) {
|
||||
return imageCache.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putBitmap(String key, Bitmap bitmap) {
|
||||
imageCache.put(key, bitmap);
|
||||
}
|
||||
});
|
||||
imageLoader.setBatchedResponseDelay(0);
|
||||
}
|
||||
return imageLoader;
|
||||
public MWApi getApi() {
|
||||
return api;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue