mobile/android/thirdparty/com/squareup/picasso/ContentStreamBitmapHunter.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.ContentResolver;
    19 import android.content.Context;
    20 import android.graphics.Bitmap;
    21 import android.graphics.BitmapFactory;
    22 import java.io.IOException;
    23 import java.io.InputStream;
    25 import static com.squareup.picasso.Picasso.LoadedFrom.DISK;
    27 class ContentStreamBitmapHunter extends BitmapHunter {
    28   final Context context;
    30   ContentStreamBitmapHunter(Context context, Picasso picasso, Dispatcher dispatcher, Cache cache,
    31       Stats stats, Action action) {
    32     super(picasso, dispatcher, cache, stats, action);
    33     this.context = context;
    34   }
    36   @Override Bitmap decode(Request data)
    37       throws IOException {
    38     return decodeContentStream(data);
    39   }
    41   @Override Picasso.LoadedFrom getLoadedFrom() {
    42     return DISK;
    43   }
    45   protected Bitmap decodeContentStream(Request data) throws IOException {
    46     ContentResolver contentResolver = context.getContentResolver();
    47     BitmapFactory.Options options = null;
    48     if (data.hasSize()) {
    49       options = new BitmapFactory.Options();
    50       options.inJustDecodeBounds = true;
    51       InputStream is = null;
    52       try {
    53         is = contentResolver.openInputStream(data.uri);
    54         BitmapFactory.decodeStream(is, null, options);
    55       } finally {
    56         Utils.closeQuietly(is);
    57       }
    58       calculateInSampleSize(data.targetWidth, data.targetHeight, options);
    59     }
    60     InputStream is = contentResolver.openInputStream(data.uri);
    61     try {
    62       return BitmapFactory.decodeStream(is, null, options);
    63     } finally {
    64       Utils.closeQuietly(is);
    65     }
    66   }
    67 }

mercurial