1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/com/squareup/picasso/AssetBitmapHunter.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,51 @@ 1.4 +package com.squareup.picasso; 1.5 + 1.6 +import android.content.Context; 1.7 +import android.content.res.AssetManager; 1.8 +import android.graphics.Bitmap; 1.9 +import android.graphics.BitmapFactory; 1.10 +import java.io.IOException; 1.11 +import java.io.InputStream; 1.12 + 1.13 +import static com.squareup.picasso.Picasso.LoadedFrom.DISK; 1.14 + 1.15 +class AssetBitmapHunter extends BitmapHunter { 1.16 + private AssetManager assetManager; 1.17 + 1.18 + public AssetBitmapHunter(Context context, Picasso picasso, Dispatcher dispatcher, Cache cache, 1.19 + Stats stats, Action action) { 1.20 + super(picasso, dispatcher, cache, stats, action); 1.21 + assetManager = context.getAssets(); 1.22 + } 1.23 + 1.24 + @Override Bitmap decode(Request data) throws IOException { 1.25 + String filePath = data.uri.toString().substring(ASSET_PREFIX_LENGTH); 1.26 + return decodeAsset(filePath); 1.27 + } 1.28 + 1.29 + @Override Picasso.LoadedFrom getLoadedFrom() { 1.30 + return DISK; 1.31 + } 1.32 + 1.33 + Bitmap decodeAsset(String filePath) throws IOException { 1.34 + BitmapFactory.Options options = null; 1.35 + if (data.hasSize()) { 1.36 + options = new BitmapFactory.Options(); 1.37 + options.inJustDecodeBounds = true; 1.38 + InputStream is = null; 1.39 + try { 1.40 + is = assetManager.open(filePath); 1.41 + BitmapFactory.decodeStream(is, null, options); 1.42 + } finally { 1.43 + Utils.closeQuietly(is); 1.44 + } 1.45 + calculateInSampleSize(data.targetWidth, data.targetHeight, options); 1.46 + } 1.47 + InputStream is = assetManager.open(filePath); 1.48 + try { 1.49 + return BitmapFactory.decodeStream(is, null, options); 1.50 + } finally { 1.51 + Utils.closeQuietly(is); 1.52 + } 1.53 + } 1.54 +}