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

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 package com.squareup.picasso;
     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;
    10 import static com.squareup.picasso.Picasso.LoadedFrom.DISK;
    12 class AssetBitmapHunter extends BitmapHunter {
    13   private AssetManager assetManager;
    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   }
    21   @Override Bitmap decode(Request data) throws IOException {
    22     String filePath = data.uri.toString().substring(ASSET_PREFIX_LENGTH);
    23     return decodeAsset(filePath);
    24   }
    26   @Override Picasso.LoadedFrom getLoadedFrom() {
    27     return DISK;
    28   }
    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