16
16
package com .squareup .picasso ;
17
17
18
18
import android .content .Context ;
19
- import android .content .res .Resources ;
20
19
import android .graphics .Bitmap ;
21
20
import android .graphics .Canvas ;
22
21
import android .graphics .ColorFilter ;
33
32
import static android .graphics .Color .WHITE ;
34
33
import static com .squareup .picasso .Picasso .LoadedFrom .MEMORY ;
35
34
36
- final class PicassoDrawable extends Drawable {
35
+ final class PicassoDrawable extends BitmapDrawable {
37
36
// Only accessed from main thread.
38
37
private static final Paint DEBUG_PAINT = new Paint ();
39
-
40
38
private static final float FADE_DURATION = 200f ; //ms
41
39
42
40
/**
@@ -50,7 +48,7 @@ static void setBitmap(ImageView target, Context context, Bitmap bitmap,
50
48
((AnimationDrawable ) placeholder ).stop ();
51
49
}
52
50
PicassoDrawable drawable =
53
- new PicassoDrawable (context , placeholder , bitmap , loadedFrom , noFade , debugging );
51
+ new PicassoDrawable (context , bitmap , placeholder , loadedFrom , noFade , debugging );
54
52
target .setImageDrawable (drawable );
55
53
}
56
54
@@ -72,25 +70,22 @@ static void setPlaceholder(ImageView target, int placeholderResId, Drawable plac
72
70
private final boolean debugging ;
73
71
private final float density ;
74
72
private final Picasso .LoadedFrom loadedFrom ;
75
- final BitmapDrawable image ;
76
73
77
74
Drawable placeholder ;
78
75
79
76
long startTimeMillis ;
80
77
boolean animating ;
81
78
int alpha = 0xFF ;
82
79
83
- PicassoDrawable (Context context , Drawable placeholder , Bitmap bitmap ,
80
+ PicassoDrawable (Context context , Bitmap bitmap , Drawable placeholder ,
84
81
Picasso .LoadedFrom loadedFrom , boolean noFade , boolean debugging ) {
85
- Resources res = context .getResources ();
82
+ super ( context .getResources (), bitmap );
86
83
87
84
this .debugging = debugging ;
88
- this .density = res .getDisplayMetrics ().density ;
85
+ this .density = context . getResources () .getDisplayMetrics ().density ;
89
86
90
87
this .loadedFrom = loadedFrom ;
91
88
92
- this .image = new BitmapDrawable (res , bitmap );
93
-
94
89
boolean fade = loadedFrom != MEMORY && !noFade ;
95
90
if (fade ) {
96
91
this .placeholder = placeholder ;
@@ -101,23 +96,22 @@ static void setPlaceholder(ImageView target, int placeholderResId, Drawable plac
101
96
102
97
@ Override public void draw (Canvas canvas ) {
103
98
if (!animating ) {
104
- image .draw (canvas );
99
+ super .draw (canvas );
105
100
} else {
106
101
float normalized = (SystemClock .uptimeMillis () - startTimeMillis ) / FADE_DURATION ;
107
102
if (normalized >= 1f ) {
108
103
animating = false ;
109
104
placeholder = null ;
110
- image .draw (canvas );
105
+ super .draw (canvas );
111
106
} else {
112
107
if (placeholder != null ) {
113
108
placeholder .draw (canvas );
114
109
}
115
110
116
111
int partialAlpha = (int ) (alpha * normalized );
117
- image .setAlpha (partialAlpha );
118
- image .draw (canvas );
119
- image .setAlpha (alpha );
120
- invalidateSelf ();
112
+ setAlpha (partialAlpha );
113
+ super .draw (canvas );
114
+ setAlpha (alpha );
121
115
}
122
116
}
123
117
@@ -126,40 +120,25 @@ static void setPlaceholder(ImageView target, int placeholderResId, Drawable plac
126
120
}
127
121
}
128
122
129
- @ Override public int getIntrinsicWidth () {
130
- return image .getIntrinsicWidth ();
131
- }
132
-
133
- @ Override public int getIntrinsicHeight () {
134
- return image .getIntrinsicHeight ();
135
- }
136
-
137
123
@ Override public void setAlpha (int alpha ) {
138
- this .alpha = alpha ;
139
124
if (placeholder != null ) {
140
125
placeholder .setAlpha (alpha );
141
126
}
142
- image .setAlpha (alpha );
127
+ super .setAlpha (alpha );
143
128
}
144
129
145
130
@ Override public void setColorFilter (ColorFilter cf ) {
146
131
if (placeholder != null ) {
147
132
placeholder .setColorFilter (cf );
148
133
}
149
- image .setColorFilter (cf );
150
- }
151
-
152
- @ Override public int getOpacity () {
153
- return image .getOpacity ();
134
+ super .setColorFilter (cf );
154
135
}
155
136
156
137
@ Override protected void onBoundsChange (Rect bounds ) {
157
- super .onBoundsChange (bounds );
158
-
159
- image .setBounds (bounds );
160
138
if (placeholder != null ) {
161
139
placeholder .setBounds (bounds );
162
140
}
141
+ super .onBoundsChange (bounds );
163
142
}
164
143
165
144
private void drawDebugIndicator (Canvas canvas ) {
0 commit comments