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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/com/squareup/picasso/ContentStreamBitmapHunter.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +/*
     1.5 + * Copyright (C) 2013 Square, Inc.
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +package com.squareup.picasso;
    1.20 +
    1.21 +import android.content.ContentResolver;
    1.22 +import android.content.Context;
    1.23 +import android.graphics.Bitmap;
    1.24 +import android.graphics.BitmapFactory;
    1.25 +import java.io.IOException;
    1.26 +import java.io.InputStream;
    1.27 +
    1.28 +import static com.squareup.picasso.Picasso.LoadedFrom.DISK;
    1.29 +
    1.30 +class ContentStreamBitmapHunter extends BitmapHunter {
    1.31 +  final Context context;
    1.32 +
    1.33 +  ContentStreamBitmapHunter(Context context, Picasso picasso, Dispatcher dispatcher, Cache cache,
    1.34 +      Stats stats, Action action) {
    1.35 +    super(picasso, dispatcher, cache, stats, action);
    1.36 +    this.context = context;
    1.37 +  }
    1.38 +
    1.39 +  @Override Bitmap decode(Request data)
    1.40 +      throws IOException {
    1.41 +    return decodeContentStream(data);
    1.42 +  }
    1.43 +
    1.44 +  @Override Picasso.LoadedFrom getLoadedFrom() {
    1.45 +    return DISK;
    1.46 +  }
    1.47 +
    1.48 +  protected Bitmap decodeContentStream(Request data) throws IOException {
    1.49 +    ContentResolver contentResolver = context.getContentResolver();
    1.50 +    BitmapFactory.Options options = null;
    1.51 +    if (data.hasSize()) {
    1.52 +      options = new BitmapFactory.Options();
    1.53 +      options.inJustDecodeBounds = true;
    1.54 +      InputStream is = null;
    1.55 +      try {
    1.56 +        is = contentResolver.openInputStream(data.uri);
    1.57 +        BitmapFactory.decodeStream(is, null, options);
    1.58 +      } finally {
    1.59 +        Utils.closeQuietly(is);
    1.60 +      }
    1.61 +      calculateInSampleSize(data.targetWidth, data.targetHeight, options);
    1.62 +    }
    1.63 +    InputStream is = contentResolver.openInputStream(data.uri);
    1.64 +    try {
    1.65 +      return BitmapFactory.decodeStream(is, null, options);
    1.66 +    } finally {
    1.67 +      Utils.closeQuietly(is);
    1.68 +    }
    1.69 +  }
    1.70 +}

mercurial