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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial