Wed, 31 Dec 2014 06:09:35 +0100
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.graphics.Bitmap;
20 import android.graphics.drawable.Drawable;
21 import android.widget.ImageView;
23 class ImageViewAction extends Action<ImageView> {
25 Callback callback;
27 ImageViewAction(Picasso picasso, ImageView imageView, Request data, boolean skipCache,
28 boolean noFade, int errorResId, Drawable errorDrawable, String key, Callback callback) {
29 super(picasso, imageView, data, skipCache, noFade, errorResId, errorDrawable, key);
30 this.callback = callback;
31 }
33 @Override public void complete(Bitmap result, Picasso.LoadedFrom from) {
34 if (result == null) {
35 throw new AssertionError(
36 String.format("Attempted to complete action with no result!\n%s", this));
37 }
39 ImageView target = this.target.get();
40 if (target == null) {
41 return;
42 }
44 Context context = picasso.context;
45 boolean debugging = picasso.debugging;
46 PicassoDrawable.setBitmap(target, context, result, from, noFade, debugging);
48 if (callback != null) {
49 callback.onSuccess();
50 }
51 }
53 @Override public void error() {
54 ImageView target = this.target.get();
55 if (target == null) {
56 return;
57 }
58 if (errorResId != 0) {
59 target.setImageResource(errorResId);
60 } else if (errorDrawable != null) {
61 target.setImageDrawable(errorDrawable);
62 }
64 if (callback != null) {
65 callback.onError();
66 }
67 }
69 @Override void cancel() {
70 super.cancel();
71 if (callback != null) {
72 callback = null;
73 }
74 }
75 }