本文整理了Java中com.bumptech.glide.util.Util
类的一些代码示例,展示了Util
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util
类的具体详情如下:
包路径:com.bumptech.glide.util.Util
类名称:Util
[英]A collection of assorted utility classes.
[中]各种各样的实用程序类的集合。
代码示例来源:origin: bumptech/glide
/**
* 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);
}
代码示例来源:origin: bumptech/glide
public final boolean isValidOverride() {
return Util.isValidDimensions(overrideWidth, overrideHeight);
}
代码示例来源:origin: bumptech/glide
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);
}
}
代码示例来源:origin: bumptech/glide
@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;
}
代码示例来源:origin: bumptech/glide
/**
* Returns {@code true} if called on a background thread, {@code false} otherwise.
*/
public static boolean isOnBackgroundThread() {
return !isOnMainThread();
}
代码示例来源:origin: bumptech/glide
/**
* 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);
}
代码示例来源:origin: bumptech/glide
/**
* 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();
}
代码示例来源:origin: bumptech/glide
/**
* 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);
}
}
代码示例来源:origin: bumptech/glide
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
PreloadTargetQueue(int size) {
queue = Util.createQueue(size);
for (int i = 0; i < size; i++) {
queue.offer(new PreloadTarget());
}
}
代码示例来源:origin: bumptech/glide
/**
* 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);
}
代码示例来源:origin: bumptech/glide
@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;
}
代码示例来源:origin: bumptech/glide
/**
* 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");
}
}
代码示例来源:origin: bumptech/glide
/**
* 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();
}
代码示例来源:origin: bumptech/glide
private synchronized R doGet(Long timeoutMillis)
throws ExecutionException, InterruptedException, TimeoutException {
if (assertBackgroundThread && !isDone()) {
Util.assertBackgroundThread();
代码示例来源:origin: guolindev/giffun
/**
* 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);
}
}
代码示例来源:origin: guolindev/giffun
public PreloadTargetQueue(int size) {
queue = Util.createQueue(size);
for (int i = 0; i < size; i++) {
queue.offer(new PreloadTarget());
}
}
代码示例来源:origin: guolindev/giffun
/**
* 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);
}
代码示例来源:origin: bumptech/glide
@Override
public String logBitmap(Bitmap bitmap) {
int size = Util.getBitmapByteSize(bitmap);
return getBitmapString(size, bitmap.getConfig());
}
代码示例来源:origin: bumptech/glide
/**
* 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;
}
代码示例来源:origin: bumptech/glide
@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;
}
内容来源于网络,如有侵权,请联系作者删除!