1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/com/squareup/picasso/ResourceBitmapHunter.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 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.Context; 1.22 +import android.content.res.Resources; 1.23 +import android.graphics.Bitmap; 1.24 +import android.graphics.BitmapFactory; 1.25 +import java.io.IOException; 1.26 + 1.27 +import static com.squareup.picasso.Picasso.LoadedFrom.DISK; 1.28 + 1.29 +class ResourceBitmapHunter extends BitmapHunter { 1.30 + private final Context context; 1.31 + 1.32 + ResourceBitmapHunter(Context context, Picasso picasso, Dispatcher dispatcher, Cache cache, 1.33 + Stats stats, Action action) { 1.34 + super(picasso, dispatcher, cache, stats, action); 1.35 + this.context = context; 1.36 + } 1.37 + 1.38 + @Override Bitmap decode(Request data) throws IOException { 1.39 + Resources res = Utils.getResources(context, data); 1.40 + int id = Utils.getResourceId(res, data); 1.41 + return decodeResource(res, id, data); 1.42 + } 1.43 + 1.44 + @Override Picasso.LoadedFrom getLoadedFrom() { 1.45 + return DISK; 1.46 + } 1.47 + 1.48 + private Bitmap decodeResource(Resources resources, int id, Request data) { 1.49 + BitmapFactory.Options bitmapOptions = null; 1.50 + if (data.hasSize()) { 1.51 + bitmapOptions = new BitmapFactory.Options(); 1.52 + bitmapOptions.inJustDecodeBounds = true; 1.53 + BitmapFactory.decodeResource(resources, id, bitmapOptions); 1.54 + calculateInSampleSize(data.targetWidth, data.targetHeight, bitmapOptions); 1.55 + } 1.56 + return BitmapFactory.decodeResource(resources, id, bitmapOptions); 1.57 + } 1.58 +}