@@ -163,13 +163,16 @@ public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
163
163
updateDrawableAttrs ();
164
164
updateBackgroundDrawableAttrs (true );
165
165
166
- if (mMutateBackground ){
166
+ if (mMutateBackground ) {
167
167
// when setBackground() is called by View constructor, mMutateBackground is not loaded from the attribute,
168
168
// so it's false by default, what doesn't allow to create the RoundedDrawable. At this point, after load
169
169
// mMutateBackground and updated BackgroundDrawable to RoundedDrawable, the View's background drawable needs to
170
170
// be changed to this new drawable.
171
171
172
+ if (BuildConfig .VERSION_CODE >= Build .VERSION_CODES .JELLY_BEAN )
172
173
super .setBackground (mBackgroundDrawable );
174
+ else
175
+ super .setBackgroundDrawable (mBackgroundDrawable );
173
176
}
174
177
175
178
a .recycle ();
@@ -278,27 +281,22 @@ private Drawable resolveResource() {
278
281
279
282
@ Override
280
283
public void setBackground (Drawable background ) {
281
- mBackgroundDrawable = background ;
282
- updateBackgroundDrawableAttrs (true );
283
- if (BuildConfig .VERSION_CODE >= Build .VERSION_CODES .JELLY_BEAN )
284
- super .setBackground (mBackgroundDrawable );
285
- else
286
- super .setBackgroundDrawable (mBackgroundDrawable );
284
+ setBackgroundDrawable (background );
287
285
}
288
286
289
287
@ Override
290
288
public void setBackgroundResource (@ DrawableRes int resId ) {
291
289
if (mBackgroundResource != resId ) {
292
290
mBackgroundResource = resId ;
293
291
mBackgroundDrawable = resolveBackgroundResource ();
294
- setBackground (mBackgroundDrawable );
292
+ setBackgroundDrawable (mBackgroundDrawable );
295
293
}
296
294
}
297
295
298
296
@ Override
299
297
public void setBackgroundColor (int color ) {
300
298
mBackgroundDrawable = new ColorDrawable (color );
301
- setBackground (mBackgroundDrawable );
299
+ setBackgroundDrawable (mBackgroundDrawable );
302
300
}
303
301
304
302
private Drawable resolveBackgroundResource () {
@@ -320,15 +318,15 @@ private Drawable resolveBackgroundResource() {
320
318
}
321
319
322
320
private void updateDrawableAttrs () {
323
- updateAttrs (mDrawable );
321
+ updateAttrs (mDrawable , mScaleType );
324
322
}
325
323
326
324
private void updateBackgroundDrawableAttrs (boolean convert ) {
327
325
if (mMutateBackground ) {
328
326
if (convert ) {
329
327
mBackgroundDrawable = RoundedDrawable .fromDrawable (mBackgroundDrawable );
330
328
}
331
- updateBackgroundAttrs (mBackgroundDrawable );
329
+ updateAttrs (mBackgroundDrawable , ScaleType . FIT_XY );
332
330
}
333
331
}
334
332
@@ -357,12 +355,12 @@ private void applyColorMod() {
357
355
}
358
356
}
359
357
360
- private void updateAttrs (Drawable drawable ) {
358
+ private void updateAttrs (Drawable drawable , ScaleType scaleType ) {
361
359
if (drawable == null ) { return ; }
362
360
363
361
if (drawable instanceof RoundedDrawable ) {
364
362
((RoundedDrawable ) drawable )
365
- .setScaleType (mScaleType )
363
+ .setScaleType (scaleType )
366
364
.setBorderWidth (mBorderWidth )
367
365
.setBorderColor (mBorderColor )
368
366
.setOval (mIsOval )
@@ -382,47 +380,20 @@ private void updateAttrs(Drawable drawable) {
382
380
// loop through layers to and set drawable attrs
383
381
LayerDrawable ld = ((LayerDrawable ) drawable );
384
382
for (int i = 0 , layers = ld .getNumberOfLayers (); i < layers ; i ++) {
385
- updateAttrs (ld .getDrawable (i ));
386
- }
387
- }
388
- }
389
-
390
- private void updateBackgroundAttrs (Drawable drawable ) {
391
- if (drawable == null ) { return ; }
392
-
393
- if (drawable instanceof RoundedDrawable ) {
394
- ((RoundedDrawable ) drawable )
395
- //It's expected for a Background to fit the drawable to
396
- //cover all background, so its ScaleType should be FIT_XY
397
- .setScaleType (ScaleType .FIT_XY )
398
- .setBorderWidth (mBorderWidth )
399
- .setBorderColor (mBorderColor )
400
- .setOval (mIsOval )
401
- .setTileModeX (mTileModeX )
402
- .setTileModeY (mTileModeY );
403
-
404
- if (mCornerRadii != null ) {
405
- ((RoundedDrawable ) drawable ).setCornerRadius (
406
- mCornerRadii [Corner .TOP_LEFT ],
407
- mCornerRadii [Corner .TOP_RIGHT ],
408
- mCornerRadii [Corner .BOTTOM_RIGHT ],
409
- mCornerRadii [Corner .BOTTOM_LEFT ]);
410
- }
411
-
412
- applyColorMod ();
413
- } else if (drawable instanceof LayerDrawable ) {
414
- // loop through layers to and set drawable attrs
415
- LayerDrawable ld = ((LayerDrawable ) drawable );
416
- for (int i = 0 , layers = ld .getNumberOfLayers (); i < layers ; i ++) {
417
- updateBackgroundAttrs (ld .getDrawable (i ));
383
+ updateAttrs (ld .getDrawable (i ), scaleType );
418
384
}
419
385
}
420
386
}
421
387
422
388
@ Override
423
389
@ Deprecated
424
390
public void setBackgroundDrawable (Drawable background ) {
425
- setBackground (background );
391
+ mBackgroundDrawable = background ;
392
+ updateBackgroundDrawableAttrs (true );
393
+ if (BuildConfig .VERSION_CODE >= Build .VERSION_CODES .JELLY_BEAN )
394
+ super .setBackground (mBackgroundDrawable );
395
+ else
396
+ super .setBackgroundDrawable (mBackgroundDrawable );
426
397
}
427
398
428
399
/**
0 commit comments