23
23
import android .content .res .TypedArray ;
24
24
import android .graphics .Bitmap ;
25
25
import android .graphics .Canvas ;
26
+ import android .graphics .drawable .Drawable ;
26
27
import android .util .AttributeSet ;
27
28
import android .view .View ;
28
29
import android .widget .ImageView ;
47
48
*/
48
49
public class KeyboardQuickSwitchTaskView extends ConstraintLayout {
49
50
51
+ private static final float THUMBNAIL_BLUR_RADIUS = 1f ;
52
+
50
53
@ ColorInt private final int mBorderColor ;
51
54
52
55
@ Nullable private BorderAnimator mBorderAnimator ;
@@ -89,10 +92,10 @@ public KeyboardQuickSwitchTaskView(
89
92
@ Override
90
93
protected void onFinishInflate () {
91
94
super .onFinishInflate ();
92
- mThumbnailView1 = findViewById (R .id .thumbnail1 );
93
- mThumbnailView2 = findViewById (R .id .thumbnail2 );
94
- mIcon1 = findViewById (R .id .icon1 );
95
- mIcon2 = findViewById (R .id .icon2 );
95
+ mThumbnailView1 = findViewById (R .id .thumbnail_1 );
96
+ mThumbnailView2 = findViewById (R .id .thumbnail_2 );
97
+ mIcon1 = findViewById (R .id .icon_1 );
98
+ mIcon2 = findViewById (R .id .icon_2 );
96
99
mContent = findViewById (R .id .content );
97
100
98
101
Resources resources = mContext .getResources ();
@@ -167,10 +170,7 @@ private void applyThumbnail(
167
170
@ Nullable ImageView thumbnailView ,
168
171
@ Nullable Task task ,
169
172
@ Nullable ThumbnailUpdateFunction updateFunction ) {
170
- if (thumbnailView == null ) {
171
- return ;
172
- }
173
- if (task == null ) {
173
+ if (thumbnailView == null || task == null ) {
174
174
return ;
175
175
}
176
176
if (updateFunction == null ) {
@@ -182,19 +182,30 @@ private void applyThumbnail(
182
182
}
183
183
184
184
private void applyThumbnail (
185
- @ NonNull ImageView thumbnailView , ThumbnailData thumbnailData ) {
185
+ @ NonNull ImageView thumbnailView ,
186
+ ThumbnailData thumbnailData ) {
186
187
Bitmap bm = thumbnailData == null ? null : thumbnailData .thumbnail ;
187
188
188
- thumbnailView .setVisibility (VISIBLE );
189
- thumbnailView .setImageBitmap (bm );
189
+ if (thumbnailView .getVisibility () != VISIBLE ) {
190
+ thumbnailView .setVisibility (VISIBLE );
191
+ }
192
+ thumbnailView .setImageDrawable (new BlurredBitmapDrawable (bm , THUMBNAIL_BLUR_RADIUS ));
190
193
}
191
194
192
195
private void applyIcon (@ Nullable ImageView iconView , @ Nullable Task task ) {
193
- if (iconView == null || task == null ) {
196
+ if (iconView == null || task == null || task . icon == null ) {
194
197
return ;
195
198
}
196
- iconView .setVisibility (VISIBLE );
197
- iconView .setImageDrawable (task .icon );
199
+ Drawable .ConstantState constantState = task .icon .getConstantState ();
200
+ if (constantState == null ) {
201
+ return ;
202
+ }
203
+ if (iconView .getVisibility () != VISIBLE ) {
204
+ iconView .setVisibility (VISIBLE );
205
+ }
206
+ // Use the bitmap directly since the drawable's scale can change
207
+ iconView .setImageDrawable (
208
+ constantState .newDrawable (getResources (), getContext ().getTheme ()));
198
209
}
199
210
200
211
protected interface ThumbnailUpdateFunction {
0 commit comments