mobile/android/thirdparty/com/squareup/picasso/ResourceBitmapHunter.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.

     1 /*
     2  * Copyright (C) 2013 Square, Inc.
     3  *
     4  * Licensed under the Apache License, Version 2.0 (the "License");
     5  * you may not use this file except in compliance with the License.
     6  * You may obtain a copy of the License at
     7  *
     8  *      http://www.apache.org/licenses/LICENSE-2.0
     9  *
    10  * Unless required by applicable law or agreed to in writing, software
    11  * distributed under the License is distributed on an "AS IS" BASIS,
    12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  * See the License for the specific language governing permissions and
    14  * limitations under the License.
    15  */
    16 package com.squareup.picasso;
    18 import android.content.Context;
    19 import android.content.res.Resources;
    20 import android.graphics.Bitmap;
    21 import android.graphics.BitmapFactory;
    22 import java.io.IOException;
    24 import static com.squareup.picasso.Picasso.LoadedFrom.DISK;
    26 class ResourceBitmapHunter extends BitmapHunter {
    27   private final Context context;
    29   ResourceBitmapHunter(Context context, Picasso picasso, Dispatcher dispatcher, Cache cache,
    30       Stats stats, Action action) {
    31     super(picasso, dispatcher, cache, stats, action);
    32     this.context = context;
    33   }
    35   @Override Bitmap decode(Request data) throws IOException {
    36     Resources res = Utils.getResources(context, data);
    37     int id = Utils.getResourceId(res, data);
    38     return decodeResource(res, id, data);
    39   }
    41   @Override Picasso.LoadedFrom getLoadedFrom() {
    42     return DISK;
    43   }
    45   private Bitmap decodeResource(Resources resources, int id, Request data) {
    46     BitmapFactory.Options bitmapOptions = null;
    47     if (data.hasSize()) {
    48       bitmapOptions = new BitmapFactory.Options();
    49       bitmapOptions.inJustDecodeBounds = true;
    50       BitmapFactory.decodeResource(resources, id, bitmapOptions);
    51       calculateInSampleSize(data.targetWidth, data.targetHeight, bitmapOptions);
    52     }
    53     return BitmapFactory.decodeResource(resources, id, bitmapOptions);
    54   }
    55 }

mercurial