mobile/android/thirdparty/com/squareup/picasso/AssetBitmapHunter.java

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:868ec5f7f7d7
1 package com.squareup.picasso;
2
3 import android.content.Context;
4 import android.content.res.AssetManager;
5 import android.graphics.Bitmap;
6 import android.graphics.BitmapFactory;
7 import java.io.IOException;
8 import java.io.InputStream;
9
10 import static com.squareup.picasso.Picasso.LoadedFrom.DISK;
11
12 class AssetBitmapHunter extends BitmapHunter {
13 private AssetManager assetManager;
14
15 public AssetBitmapHunter(Context context, Picasso picasso, Dispatcher dispatcher, Cache cache,
16 Stats stats, Action action) {
17 super(picasso, dispatcher, cache, stats, action);
18 assetManager = context.getAssets();
19 }
20
21 @Override Bitmap decode(Request data) throws IOException {
22 String filePath = data.uri.toString().substring(ASSET_PREFIX_LENGTH);
23 return decodeAsset(filePath);
24 }
25
26 @Override Picasso.LoadedFrom getLoadedFrom() {
27 return DISK;
28 }
29
30 Bitmap decodeAsset(String filePath) throws IOException {
31 BitmapFactory.Options options = null;
32 if (data.hasSize()) {
33 options = new BitmapFactory.Options();
34 options.inJustDecodeBounds = true;
35 InputStream is = null;
36 try {
37 is = assetManager.open(filePath);
38 BitmapFactory.decodeStream(is, null, options);
39 } finally {
40 Utils.closeQuietly(is);
41 }
42 calculateInSampleSize(data.targetWidth, data.targetHeight, options);
43 }
44 InputStream is = assetManager.open(filePath);
45 try {
46 return BitmapFactory.decodeStream(is, null, options);
47 } finally {
48 Utils.closeQuietly(is);
49 }
50 }
51 }

mercurial