本文整理了Java中com.bumptech.glide.util.Util.assertMainThread()
方法的一些代码示例,展示了Util.assertMainThread()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.assertMainThread()
方法的具体详情如下:
包路径:com.bumptech.glide.util.Util
类名称:Util
方法名:assertMainThread
[英]Throws an java.lang.IllegalArgumentException if called on a thread other than the main thread.
[中]
代码示例来源: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
/**
* Performs {@link #resumeRequests()} recursively for all managers that are contextually
* descendant to this manager based on the Activity/Fragment hierarchy. The hierarchical semantics
* are identical as for {@link #pauseRequestsRecursive()}.
*/
// Public API.
@SuppressWarnings("unused")
public synchronized void resumeRequestsRecursive() {
Util.assertMainThread();
resumeRequests();
for (RequestManager requestManager : treeNode.getDescendants()) {
requestManager.resumeRequests();
}
}
代码示例来源: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
/**
* Adjusts Glide's current and maximum memory usage based on the given {@link MemoryCategory}.
*
* <p> The default {@link MemoryCategory} is {@link MemoryCategory#NORMAL}.
* {@link MemoryCategory#HIGH} increases Glide's maximum memory usage by up to 50% and
* {@link MemoryCategory#LOW} decreases Glide's maximum memory usage by 50%. This method should be
* used to temporarily increase or decrease memory usage for a single Activity or part of the app.
* Use {@link GlideBuilder#setMemoryCache(MemoryCache)} to put a permanent memory size if you want
* to change the default. </p>
*
* @return the previous MemoryCategory used by Glide.
*/
@SuppressWarnings("WeakerAccess") // Public API
@NonNull
public MemoryCategory setMemoryCategory(@NonNull MemoryCategory memoryCategory) {
// 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.setSizeMultiplier(memoryCategory.getMultiplier());
bitmapPool.setSizeMultiplier(memoryCategory.getMultiplier());
MemoryCategory oldCategory = this.memoryCategory;
this.memoryCategory = memoryCategory;
return oldCategory;
}
代码示例来源:origin: bumptech/glide
Util.assertMainThread();
Preconditions.checkNotNull(view);
代码示例来源:origin: guolindev/giffun
@Override
public void onEngineJobCancelled(EngineJob engineJob, Key key) {
Util.assertMainThread();
EngineJob current = jobs.get(key);
if (engineJob.equals(current)) {
jobs.remove(key);
}
}
代码示例来源:origin: guolindev/giffun
@Override
public void onResourceRemoved(final Resource<?> resource) {
Util.assertMainThread();
resourceRecycler.recycle(resource);
}
代码示例来源:origin: guolindev/giffun
/**
* Restarts any loads that have not yet completed.
*
* @see #isPaused()
* @see #pauseRequests()
*/
public void resumeRequests() {
Util.assertMainThread();
requestTracker.resumeRequests();
}
代码示例来源:origin: guolindev/giffun
/**
* Returns true if loads for this {@link RequestManager} are currently paused.
*
* @see #pauseRequests()
* @see #resumeRequests()
*/
public boolean isPaused() {
Util.assertMainThread();
return requestTracker.isPaused();
}
代码示例来源:origin: guolindev/giffun
public void release(Resource resource) {
Util.assertMainThread();
if (resource instanceof EngineResource) {
((EngineResource) resource).release();
} else {
throw new IllegalArgumentException("Cannot release anything but an EngineResource");
}
}
代码示例来源:origin: guolindev/giffun
/**
* Cancels any in progress loads, but does not clear resources of completed loads.
*
* @see #isPaused()
* @see #resumeRequests()
*/
public void pauseRequests() {
Util.assertMainThread();
requestTracker.pauseRequests();
}
代码示例来源:origin: guolindev/giffun
public void recycle(Resource<?> resource) {
Util.assertMainThread();
if (isRecycling) {
// If a resource has sub-resources, releasing a sub resource can cause it's parent to be synchronously
// evicted which leads to a recycle loop when the parent releases it's children. Posting breaks this loop.
handler.obtainMessage(ResourceRecyclerCallback.RECYCLE_RESOURCE, resource).sendToTarget();
} else {
isRecycling = true;
resource.recycle();
isRecycling = false;
}
}
代码示例来源:origin: guolindev/giffun
public void removeCallback(ResourceCallback cb) {
Util.assertMainThread();
if (hasResource || hasException) {
addIgnoredCallback(cb);
} else {
cbs.remove(cb);
if (cbs.isEmpty()) {
cancel();
}
}
}
代码示例来源:origin: guolindev/giffun
public void addCallback(ResourceCallback cb) {
Util.assertMainThread();
if (hasResource) {
cb.onResourceReady(engineResource);
} else if (hasException) {
cb.onException(exception);
} else {
cbs.add(cb);
}
}
代码示例来源:origin: guolindev/giffun
/**
* 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);
}
代码示例来源:origin: guolindev/giffun
/**
* 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();
}
代码示例来源:origin: guolindev/giffun
@Override
public void onResourceReleased(Key cacheKey, EngineResource resource) {
Util.assertMainThread();
activeResources.remove(cacheKey);
if (resource.isCacheable()) {
cache.put(cacheKey, resource);
} else {
resourceRecycler.recycle(resource);
}
}
代码示例来源:origin: guolindev/giffun
@SuppressWarnings("unchecked")
@Override
public void onEngineJobComplete(Key key, EngineResource<?> resource) {
Util.assertMainThread();
// A null resource indicates that the load failed, usually due to an exception.
if (resource != null) {
resource.setResourceListener(key, this);
if (resource.isCacheable()) {
activeResources.put(key, new ResourceWeakReference(key, resource, getReferenceQueue()));
}
}
// TODO: should this check that the engine job is still current?
jobs.remove(key);
}
代码示例来源:origin: guolindev/giffun
/**
* Performs {@link #resumeRequests()} recursively for all managers that are contextually descendant
* to this manager based on the Activity/Fragment hierarchy. The hierarchical semantics are identical as for
* {@link #pauseRequestsRecursive()}.
*/
public void resumeRequestsRecursive() {
Util.assertMainThread();
resumeRequests();
for (RequestManager requestManager : treeNode.getDescendants()) {
requestManager.resumeRequests();
}
}
代码示例来源:origin: guolindev/giffun
/**
* Cancel any pending loads Glide may have for the target and free any resources (such as {@link Bitmap}s) that may
* have been loaded for the target so they may be reused.
*
* @param target The Target to cancel loads for.
*/
public static void clear(Target<?> target) {
Util.assertMainThread();
Request request = target.getRequest();
if (request != null) {
request.clear();
target.setRequest(null);
}
}
内容来源于网络,如有侵权,请联系作者删除!