Back to project page DistributedMemory.
The source code is released under:
Apache License
If you think the Android project DistributedMemory listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.faudroids.distributedmemory.ui; // w w w . j av a2s . c o m import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import java.io.IOException; import java.util.HashMap; import java.util.Map; import javax.inject.Inject; import timber.log.Timber; final class BitmapCache { private final AssetManager assetManager; private final Map<String, Bitmap> cache = new HashMap<>(); @Inject public BitmapCache(AssetManager assetManager) { this.assetManager = assetManager; } public Bitmap getBitmap(String fileName) { if (cache.containsKey(fileName)) return cache.get(fileName); try { Bitmap bitmap = BitmapFactory.decodeStream(assetManager.open(fileName)); cache.put(fileName, bitmap); return bitmap; } catch (IOException ioe) { Timber.e("failed to load bitmap", ioe); return null; } } }