com.bumptech.glide.util.Util.assertMainThread()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(289)

本文整理了Java中com.bumptech.glide.util.Util.assertMainThread()方法的一些代码示例,展示了Util.assertMainThread()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.assertMainThread()方法的具体详情如下:
包路径:com.bumptech.glide.util.Util
类名称:Util
方法名:assertMainThread

Util.assertMainThread介绍

[英]Throws an java.lang.IllegalArgumentException if called on a thread other than the main thread.
[中]

代码示例

代码示例来源:origin: bumptech/glide

  1. /**
  2. * Clears some memory with the exact amount depending on the given level.
  3. *
  4. * @see android.content.ComponentCallbacks2#onTrimMemory(int)
  5. */
  6. public void trimMemory(int level) {
  7. // Engine asserts this anyway when removing resources, fail faster and consistently
  8. Util.assertMainThread();
  9. // memory cache needs to be trimmed before bitmap pool to trim re-pooled Bitmaps too. See #687.
  10. memoryCache.trimMemory(level);
  11. bitmapPool.trimMemory(level);
  12. arrayPool.trimMemory(level);
  13. }

代码示例来源:origin: bumptech/glide

  1. /**
  2. * Performs {@link #resumeRequests()} recursively for all managers that are contextually
  3. * descendant to this manager based on the Activity/Fragment hierarchy. The hierarchical semantics
  4. * are identical as for {@link #pauseRequestsRecursive()}.
  5. */
  6. // Public API.
  7. @SuppressWarnings("unused")
  8. public synchronized void resumeRequestsRecursive() {
  9. Util.assertMainThread();
  10. resumeRequests();
  11. for (RequestManager requestManager : treeNode.getDescendants()) {
  12. requestManager.resumeRequests();
  13. }
  14. }

代码示例来源:origin: bumptech/glide

  1. /**
  2. * Clears as much memory as possible.
  3. *
  4. * @see android.content.ComponentCallbacks#onLowMemory()
  5. * @see android.content.ComponentCallbacks2#onLowMemory()
  6. */
  7. public void clearMemory() {
  8. // Engine asserts this anyway when removing resources, fail faster and consistently
  9. Util.assertMainThread();
  10. // memory cache needs to be cleared before bitmap pool to clear re-pooled Bitmaps too. See #687.
  11. memoryCache.clearMemory();
  12. bitmapPool.clearMemory();
  13. arrayPool.clearMemory();
  14. }

代码示例来源:origin: bumptech/glide

  1. /**
  2. * Adjusts Glide's current and maximum memory usage based on the given {@link MemoryCategory}.
  3. *
  4. * <p> The default {@link MemoryCategory} is {@link MemoryCategory#NORMAL}.
  5. * {@link MemoryCategory#HIGH} increases Glide's maximum memory usage by up to 50% and
  6. * {@link MemoryCategory#LOW} decreases Glide's maximum memory usage by 50%. This method should be
  7. * used to temporarily increase or decrease memory usage for a single Activity or part of the app.
  8. * Use {@link GlideBuilder#setMemoryCache(MemoryCache)} to put a permanent memory size if you want
  9. * to change the default. </p>
  10. *
  11. * @return the previous MemoryCategory used by Glide.
  12. */
  13. @SuppressWarnings("WeakerAccess") // Public API
  14. @NonNull
  15. public MemoryCategory setMemoryCategory(@NonNull MemoryCategory memoryCategory) {
  16. // Engine asserts this anyway when removing resources, fail faster and consistently
  17. Util.assertMainThread();
  18. // memory cache needs to be trimmed before bitmap pool to trim re-pooled Bitmaps too. See #687.
  19. memoryCache.setSizeMultiplier(memoryCategory.getMultiplier());
  20. bitmapPool.setSizeMultiplier(memoryCategory.getMultiplier());
  21. MemoryCategory oldCategory = this.memoryCategory;
  22. this.memoryCategory = memoryCategory;
  23. return oldCategory;
  24. }

代码示例来源:origin: bumptech/glide

  1. Util.assertMainThread();
  2. Preconditions.checkNotNull(view);

代码示例来源:origin: guolindev/giffun

  1. @Override
  2. public void onEngineJobCancelled(EngineJob engineJob, Key key) {
  3. Util.assertMainThread();
  4. EngineJob current = jobs.get(key);
  5. if (engineJob.equals(current)) {
  6. jobs.remove(key);
  7. }
  8. }

代码示例来源:origin: guolindev/giffun

  1. @Override
  2. public void onResourceRemoved(final Resource<?> resource) {
  3. Util.assertMainThread();
  4. resourceRecycler.recycle(resource);
  5. }

代码示例来源:origin: guolindev/giffun

  1. /**
  2. * Restarts any loads that have not yet completed.
  3. *
  4. * @see #isPaused()
  5. * @see #pauseRequests()
  6. */
  7. public void resumeRequests() {
  8. Util.assertMainThread();
  9. requestTracker.resumeRequests();
  10. }

代码示例来源:origin: guolindev/giffun

  1. /**
  2. * Returns true if loads for this {@link RequestManager} are currently paused.
  3. *
  4. * @see #pauseRequests()
  5. * @see #resumeRequests()
  6. */
  7. public boolean isPaused() {
  8. Util.assertMainThread();
  9. return requestTracker.isPaused();
  10. }

代码示例来源:origin: guolindev/giffun

  1. public void release(Resource resource) {
  2. Util.assertMainThread();
  3. if (resource instanceof EngineResource) {
  4. ((EngineResource) resource).release();
  5. } else {
  6. throw new IllegalArgumentException("Cannot release anything but an EngineResource");
  7. }
  8. }

代码示例来源:origin: guolindev/giffun

  1. /**
  2. * Cancels any in progress loads, but does not clear resources of completed loads.
  3. *
  4. * @see #isPaused()
  5. * @see #resumeRequests()
  6. */
  7. public void pauseRequests() {
  8. Util.assertMainThread();
  9. requestTracker.pauseRequests();
  10. }

代码示例来源:origin: guolindev/giffun

  1. public void recycle(Resource<?> resource) {
  2. Util.assertMainThread();
  3. if (isRecycling) {
  4. // If a resource has sub-resources, releasing a sub resource can cause it's parent to be synchronously
  5. // evicted which leads to a recycle loop when the parent releases it's children. Posting breaks this loop.
  6. handler.obtainMessage(ResourceRecyclerCallback.RECYCLE_RESOURCE, resource).sendToTarget();
  7. } else {
  8. isRecycling = true;
  9. resource.recycle();
  10. isRecycling = false;
  11. }
  12. }

代码示例来源:origin: guolindev/giffun

  1. public void removeCallback(ResourceCallback cb) {
  2. Util.assertMainThread();
  3. if (hasResource || hasException) {
  4. addIgnoredCallback(cb);
  5. } else {
  6. cbs.remove(cb);
  7. if (cbs.isEmpty()) {
  8. cancel();
  9. }
  10. }
  11. }

代码示例来源:origin: guolindev/giffun

  1. public void addCallback(ResourceCallback cb) {
  2. Util.assertMainThread();
  3. if (hasResource) {
  4. cb.onResourceReady(engineResource);
  5. } else if (hasException) {
  6. cb.onException(exception);
  7. } else {
  8. cbs.add(cb);
  9. }
  10. }

代码示例来源:origin: guolindev/giffun

  1. /**
  2. * Clears some memory with the exact amount depending on the given level.
  3. *
  4. * @see android.content.ComponentCallbacks2#onTrimMemory(int)
  5. */
  6. public void trimMemory(int level) {
  7. // Engine asserts this anyway when removing resources, fail faster and consistently
  8. Util.assertMainThread();
  9. // memory cache needs to be trimmed before bitmap pool to trim re-pooled Bitmaps too. See #687.
  10. memoryCache.trimMemory(level);
  11. bitmapPool.trimMemory(level);
  12. }

代码示例来源:origin: guolindev/giffun

  1. /**
  2. * Clears as much memory as possible.
  3. *
  4. * @see android.content.ComponentCallbacks#onLowMemory()
  5. * @see android.content.ComponentCallbacks2#onLowMemory()
  6. */
  7. public void clearMemory() {
  8. // Engine asserts this anyway when removing resources, fail faster and consistently
  9. Util.assertMainThread();
  10. // memory cache needs to be cleared before bitmap pool to clear re-pooled Bitmaps too. See #687.
  11. memoryCache.clearMemory();
  12. bitmapPool.clearMemory();
  13. }

代码示例来源:origin: guolindev/giffun

  1. @Override
  2. public void onResourceReleased(Key cacheKey, EngineResource resource) {
  3. Util.assertMainThread();
  4. activeResources.remove(cacheKey);
  5. if (resource.isCacheable()) {
  6. cache.put(cacheKey, resource);
  7. } else {
  8. resourceRecycler.recycle(resource);
  9. }
  10. }

代码示例来源:origin: guolindev/giffun

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public void onEngineJobComplete(Key key, EngineResource<?> resource) {
  4. Util.assertMainThread();
  5. // A null resource indicates that the load failed, usually due to an exception.
  6. if (resource != null) {
  7. resource.setResourceListener(key, this);
  8. if (resource.isCacheable()) {
  9. activeResources.put(key, new ResourceWeakReference(key, resource, getReferenceQueue()));
  10. }
  11. }
  12. // TODO: should this check that the engine job is still current?
  13. jobs.remove(key);
  14. }

代码示例来源:origin: guolindev/giffun

  1. /**
  2. * Performs {@link #resumeRequests()} recursively for all managers that are contextually descendant
  3. * to this manager based on the Activity/Fragment hierarchy. The hierarchical semantics are identical as for
  4. * {@link #pauseRequestsRecursive()}.
  5. */
  6. public void resumeRequestsRecursive() {
  7. Util.assertMainThread();
  8. resumeRequests();
  9. for (RequestManager requestManager : treeNode.getDescendants()) {
  10. requestManager.resumeRequests();
  11. }
  12. }

代码示例来源:origin: guolindev/giffun

  1. /**
  2. * Cancel any pending loads Glide may have for the target and free any resources (such as {@link Bitmap}s) that may
  3. * have been loaded for the target so they may be reused.
  4. *
  5. * @param target The Target to cancel loads for.
  6. */
  7. public static void clear(Target<?> target) {
  8. Util.assertMainThread();
  9. Request request = target.getRequest();
  10. if (request != null) {
  11. request.clear();
  12. target.setRequest(null);
  13. }
  14. }

相关文章