4
4
import android .content .res .Resources .Theme ;
5
5
import android .graphics .drawable .Drawable ;
6
6
import android .util .Log ;
7
+
8
+ import androidx .annotation .AnyRes ;
7
9
import androidx .annotation .DrawableRes ;
8
10
import androidx .annotation .GuardedBy ;
9
11
import androidx .annotation .NonNull ;
@@ -387,7 +389,7 @@ public boolean isAnyResourceSet() {
387
389
private Drawable getErrorDrawable () {
388
390
if (errorDrawable == null ) {
389
391
errorDrawable = requestOptions .getErrorPlaceholder ();
390
- if (errorDrawable == null && requestOptions .getErrorId () > 0 ) {
392
+ if (errorDrawable == null && isValidId ( requestOptions .getErrorId ()) ) {
391
393
errorDrawable = loadDrawable (requestOptions .getErrorId ());
392
394
}
393
395
}
@@ -398,7 +400,7 @@ private Drawable getErrorDrawable() {
398
400
private Drawable getPlaceholderDrawable () {
399
401
if (placeholderDrawable == null ) {
400
402
placeholderDrawable = requestOptions .getPlaceholderDrawable ();
401
- if (placeholderDrawable == null && requestOptions .getPlaceholderId () > 0 ) {
403
+ if (placeholderDrawable == null && isValidId ( requestOptions .getPlaceholderId ()) ) {
402
404
placeholderDrawable = loadDrawable (requestOptions .getPlaceholderId ());
403
405
}
404
406
}
@@ -409,13 +411,20 @@ private Drawable getPlaceholderDrawable() {
409
411
private Drawable getFallbackDrawable () {
410
412
if (fallbackDrawable == null ) {
411
413
fallbackDrawable = requestOptions .getFallbackDrawable ();
412
- if (fallbackDrawable == null && requestOptions .getFallbackId () > 0 ) {
414
+ if (fallbackDrawable == null && isValidId ( requestOptions .getFallbackId ()) ) {
413
415
fallbackDrawable = loadDrawable (requestOptions .getFallbackId ());
414
416
}
415
417
}
416
418
return fallbackDrawable ;
417
419
}
418
420
421
+ /**
422
+ * @see android.content.res.ResourceId.isValid
423
+ */
424
+ private static boolean isValidId (int id ) {
425
+ return id != -1 && (id & 0xff000000 ) != 0 && (id & 0x00ff0000 ) != 0 ;
426
+ }
427
+
419
428
@ GuardedBy ("requestLock" )
420
429
private Drawable loadDrawable (@ DrawableRes int resourceId ) {
421
430
Theme theme =
0 commit comments