1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.exoplatform.widget;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.exoplatform.utils.image.ExoPicasso;
25
26 import com.squareup.picasso.Target;
27
28 import android.content.Context;
29 import android.util.AttributeSet;
30 import android.widget.TextView;
31
32
33
34
35
36
37
38 public class PicassoTextView extends TextView {
39
40 private List<Target> mTargets;
41
42 public PicassoTextView(Context context, AttributeSet attrs, int defStyle) {
43 super(context, attrs, defStyle);
44 }
45
46 public PicassoTextView(Context context, AttributeSet attrs) {
47 super(context, attrs);
48 }
49
50 public PicassoTextView(Context context) {
51 super(context);
52 }
53
54 @Override
55 protected void onDetachedFromWindow() {
56 if (mTargets != null) {
57 for (Target target : mTargets) {
58 if (target != null) {
59 ExoPicasso.picasso(getContext()).cancelRequest(target);
60 }
61 }
62 }
63 super.onDetachedFromWindow();
64 }
65
66 public void addTarget(Target target) {
67 if (mTargets == null) {
68 mTargets = new ArrayList<Target>();
69 }
70 mTargets.add(target);
71 }
72 }