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

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:0adf91dfab53
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;
17
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;
23
24 import static com.squareup.picasso.Picasso.LoadedFrom.DISK;
25
26 class ResourceBitmapHunter extends BitmapHunter {
27 private final Context context;
28
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 }
34
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 }
40
41 @Override Picasso.LoadedFrom getLoadedFrom() {
42 return DISK;
43 }
44
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