/** * Returns the allocated byte size of the given bitmap. * * @see #getBitmapByteSize(android.graphics.Bitmap) * @deprecated Use {@link #getBitmapByteSize(android.graphics.Bitmap)} instead. Scheduled to be * removed in Glide 4.0. */ @Deprecated public static int getSize(@NonNull Bitmap bitmap) { return getBitmapByteSize(bitmap); }
public final boolean isValidOverride() { return Util.isValidDimensions(overrideWidth, overrideHeight); }
private String calculateHexStringDigest(Key key) { PoolableDigestContainer container = Preconditions.checkNotNull(digestPool.acquire()); try { key.updateDiskCacheKey(container.messageDigest); // calling digest() will automatically reset() return Util.sha256BytesToHex(container.messageDigest.digest()); } finally { digestPool.release(container); } }
@Override public boolean equals(Object obj) { if (obj instanceof GifUrlSet) { GifUrlSet other = (GifUrlSet) obj; return Util.bothNullOrEqual(original, other.original) && Util.bothNullOrEqual(fixed_width, other.fixed_width) && Util.bothNullOrEqual(fixed_height, other.fixed_height); } return false; }
/** * Returns {@code true} if called on a background thread, {@code false} otherwise. */ public static boolean isOnBackgroundThread() { return !isOnMainThread(); }
/** * Clears some memory with the exact amount depending on the given level. * * @see android.content.ComponentCallbacks2#onTrimMemory(int) */ public void trimMemory(int level) { // Engine asserts this anyway when removing resources, fail faster and consistently Util.assertMainThread(); // memory cache needs to be trimmed before bitmap pool to trim re-pooled Bitmaps too. See #687. memoryCache.trimMemory(level); bitmapPool.trimMemory(level); arrayPool.trimMemory(level); }
/** * Clears disk cache. * * <p> * This method should always be called on a background thread, since it is a blocking call. * </p> */ // Public API. @SuppressWarnings({"unused", "WeakerAccess"}) public void clearDiskCache() { Util.assertBackgroundThread(); engine.clearDiskCache(); }
/** * Returns the hex string of the given byte array representing a SHA256 hash. */ @NonNull public static String sha256BytesToHex(@NonNull byte[] bytes) { synchronized (SHA_256_CHARS) { return bytesToHex(bytes, SHA_256_CHARS); } }
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") PreloadTargetQueue(int size) { queue = Util.createQueue(size); for (int i = 0; i < size; i++) { queue.offer(new PreloadTarget()); } }
/** * Returns the in memory size of {@link android.graphics.Bitmap} with the given width, height, and * {@link android.graphics.Bitmap.Config}. */ public static int getBitmapByteSize(int width, int height, @Nullable Bitmap.Config config) { return width * height * getBytesPerPixel(config); }
@Override public boolean equals(Object o) { if (o instanceof Key) { Key other = (Key) o; return size == other.size && Util.bothNullOrEqual(config, other.config); } return false; }
/** * Throws an {@link java.lang.IllegalArgumentException} if called on a thread other than the main * thread. */ public static void assertMainThread() { if (!isOnMainThread()) { throw new IllegalArgumentException("You must call this method on the main thread"); } }
/** * Clears as much memory as possible. * * @see android.content.ComponentCallbacks#onLowMemory() * @see android.content.ComponentCallbacks2#onLowMemory() */ public void clearMemory() { // Engine asserts this anyway when removing resources, fail faster and consistently Util.assertMainThread(); // memory cache needs to be cleared before bitmap pool to clear re-pooled Bitmaps too. See #687. memoryCache.clearMemory(); bitmapPool.clearMemory(); arrayPool.clearMemory(); }
private synchronized R doGet(Long timeoutMillis) throws ExecutionException, InterruptedException, TimeoutException { if (assertBackgroundThread && !isDone()) { Util.assertBackgroundThread();
/** * Returns the hex string of the given byte array representing a SHA1 hash. */ public static String sha1BytesToHex(byte[] bytes) { synchronized (SHA_1_CHARS) { return bytesToHex(bytes, SHA_1_CHARS); } }
public PreloadTargetQueue(int size) { queue = Util.createQueue(size); for (int i = 0; i < size; i++) { queue.offer(new PreloadTarget()); } }
/** * Returns the in memory size of {@link Bitmap} with the given width, height, and * {@link Bitmap.Config}. */ public static int getBitmapByteSize(int width, int height, Bitmap.Config config) { return width * height * getBytesPerPixel(config); }
@Override public String logBitmap(Bitmap bitmap) { int size = Util.getBitmapByteSize(bitmap); return getBitmapString(size, bitmap.getConfig()); }
/** * Creates a new {@code CustomTarget} that will return the given {@code width} and {@code height} * as the requested size (unless overridden by * {@link com.bumptech.glide.request.RequestOptions#override(int)} in the request). * * @param width The requested width (>= 0, or == Target.SIZE_ORIGINAL). * @param height The requested height (>= 0, or == Target.SIZE_ORIGINAL). */ public CustomTarget(int width, int height) { if (!Util.isValidDimensions(width, height)) { throw new IllegalArgumentException( "Width and height must both be > 0 or Target#SIZE_ORIGINAL, but given" + " width: " + width + " and height: " + height); } this.width = width; this.height = height; }
@Override public boolean equals(Object obj) { if (obj instanceof GifResult) { GifResult other = (GifResult) obj; return Util.bothNullOrEqual(id, other.id) && Util.bothNullOrEqual(images, other.images); } return false; }