diff --git a/library/src/main/java/com/bumptech/glide/request/SingleRequest.java b/library/src/main/java/com/bumptech/glide/request/SingleRequest.java index 3bea82af4a..c95f61a123 100644 --- a/library/src/main/java/com/bumptech/glide/request/SingleRequest.java +++ b/library/src/main/java/com/bumptech/glide/request/SingleRequest.java @@ -4,6 +4,8 @@ import android.content.res.Resources.Theme; import android.graphics.drawable.Drawable; import android.util.Log; + +import androidx.annotation.AnyRes; import androidx.annotation.DrawableRes; import androidx.annotation.GuardedBy; import androidx.annotation.NonNull; @@ -387,8 +389,7 @@ public boolean isAnyResourceSet() { private Drawable getErrorDrawable() { if (errorDrawable == null) { errorDrawable = requestOptions.getErrorPlaceholder(); - if (errorDrawable == null && requestOptions.getErrorId() != -1 && - (requestOptions.getErrorId() & 0xff000000) != 0 && (requestOptions.getErrorId() & 0x00ff0000) != 0) { + if (errorDrawable == null && isValidId(requestOptions.getErrorId())) { errorDrawable = loadDrawable(requestOptions.getErrorId()); } } @@ -399,8 +400,7 @@ private Drawable getErrorDrawable() { private Drawable getPlaceholderDrawable() { if (placeholderDrawable == null) { placeholderDrawable = requestOptions.getPlaceholderDrawable(); - if (placeholderDrawable == null && requestOptions.getPlaceholderId() != -1 && - (requestOptions.getPlaceholderId() & 0xff000000) != 0 && (requestOptions.getPlaceholderId() & 0x00ff0000) != 0) { + if (placeholderDrawable == null && isValidId(requestOptions.getPlaceholderId())) { placeholderDrawable = loadDrawable(requestOptions.getPlaceholderId()); } } @@ -411,14 +411,20 @@ private Drawable getPlaceholderDrawable() { private Drawable getFallbackDrawable() { if (fallbackDrawable == null) { fallbackDrawable = requestOptions.getFallbackDrawable(); - if (fallbackDrawable == null && requestOptions.getFallbackId() != -1 && - (requestOptions.getFallbackId() & 0xff000000) != 0 && (requestOptions.getFallbackId() & 0x00ff0000) != 0) { + if (fallbackDrawable == null && isValidId(requestOptions.getFallbackId())) { fallbackDrawable = loadDrawable(requestOptions.getFallbackId()); } } return fallbackDrawable; } + /** + * @see android.content.res.ResourceId.isValid + */ + private static boolean isValidId(int id) { + return id != -1 && (id & 0xff000000) != 0 && (id & 0x00ff0000) != 0; + } + @GuardedBy("requestLock") private Drawable loadDrawable(@DrawableRes int resourceId) { Theme theme =