Class Util

java.lang.Object
com.bumptech.glide.util.Util

public final class Util extends Object
A collection of assorted utility classes.
  • Method Details

    • sha256BytesToHex

      @NonNull public static String sha256BytesToHex(@NonNull byte[] bytes)
      Returns the hex string of the given byte array representing a SHA256 hash.
    • getSize

      @Deprecated public static int getSize(@NonNull Bitmap bitmap)
      Deprecated.
      Use getBitmapByteSize(android.graphics.Bitmap) instead. Scheduled to be removed in Glide 4.0.
      Returns the allocated byte size of the given bitmap.
      See Also:
    • getBitmapByteSize

      public static int getBitmapByteSize(@NonNull Bitmap bitmap)
      Returns the in memory size of the given Bitmap in bytes.
    • getBitmapByteSize

      public static int getBitmapByteSize(int width, int height, @Nullable Bitmap.Config config)
      Returns the in memory size of Bitmap with the given width, height, and Bitmap.Config.
    • getBytesPerPixel

      public static int getBytesPerPixel(@Nullable Bitmap.Config config)
      Returns the number of bytes required to store each pixel of a Bitmap with the given config.

      Defaults to Bitmap.Config.ARGB_8888 if config is null.

    • isValidDimensions

      public static boolean isValidDimensions(int width, int height)
      Returns true if width and height are both > 0 and/or equal to Target.SIZE_ORIGINAL.
    • isValidDimension

      public static boolean isValidDimension(int dimen)
    • postOnUiThread

      public static void postOnUiThread(Runnable runnable)
      Posts the given runnable to the UI thread using a shared Handler.
    • removeCallbacksOnUiThread

      public static void removeCallbacksOnUiThread(Runnable runnable)
      Removes the given runnable from the UI threads queue if it is still queued.
    • assertMainThread

      public static void assertMainThread()
      Throws an IllegalArgumentException if called on a thread other than the main thread.
    • assertBackgroundThread

      public static void assertBackgroundThread()
      Throws an IllegalArgumentException if called on the main thread.
    • isOnMainThread

      public static boolean isOnMainThread()
      Returns true if called on the main thread, false otherwise.
    • isOnBackgroundThread

      public static boolean isOnBackgroundThread()
      Returns true if called on a background thread, false otherwise.
    • createQueue

      @NonNull public static <T> Queue<T> createQueue(int size)
      Creates a Queue of the given size using Glide's preferred implementation.
    • getSnapshot

      @NonNull public static <T> List<T> getSnapshot(@NonNull Collection<T> other)
      Returns a copy of the given list that is safe to iterate over and perform actions that may modify the original list.

      See #303, #375, #322, #2262.

    • bothNullOrEqual

      public static boolean bothNullOrEqual(@Nullable Object a, @Nullable Object b)
      Null-safe equivalent of a.equals(b).
      See Also:
    • bothModelsNullEquivalentOrEquals

      public static boolean bothModelsNullEquivalentOrEquals(@Nullable Object a, @Nullable Object b)
    • bothBaseRequestOptionsNullEquivalentOrEquals

      public static boolean bothBaseRequestOptionsNullEquivalentOrEquals(@Nullable BaseRequestOptions<?> a, @Nullable BaseRequestOptions<?> b)
    • hashCode

      public static int hashCode(int value)
    • hashCode

      public static int hashCode(int value, int accumulator)
    • hashCode

      public static int hashCode(float value)
    • hashCode

      public static int hashCode(float value, int accumulator)
    • hashCode

      public static int hashCode(@Nullable Object object, int accumulator)
    • hashCode

      public static int hashCode(boolean value, int accumulator)
    • hashCode

      public static int hashCode(boolean value)