27cd390800f3c168bb900c16085be7a41e73689d.svn-base 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.hjq.image;
  2. import android.app.Application;
  3. import android.content.Context;
  4. import android.graphics.drawable.Drawable;
  5. import com.bumptech.glide.Glide;
  6. import com.hjq.copy.R;
  7. /**
  8. * desc : Glide 加工厂
  9. */
  10. public final class GlideFactory implements ImageFactory<GlideHandler> {
  11. @Override
  12. public GlideHandler create() {
  13. return new GlideHandler();
  14. }
  15. @Override
  16. public void init(Application application, GlideHandler handler) {
  17. handler.setPlaceholder(getLoadingPic(application));
  18. handler.setError(getErrorPic(application));
  19. }
  20. @Override
  21. public Drawable getLoadingPic(Context context) {
  22. return context.getResources().getDrawable(R.mipmap.image_loading);
  23. }
  24. @Override
  25. public Drawable getErrorPic(Context context) {
  26. return context.getResources().getDrawable(R.mipmap.image_load_err);
  27. }
  28. @Override
  29. public void clear(final Context context) {
  30. // 清除内存缓存(必须在主线程)
  31. Glide.get(context).clearMemory();
  32. new Thread(new Runnable() {
  33. @Override
  34. public void run() {
  35. // 清除本地缓存(必须在子线程)
  36. Glide.get(context).clearDiskCache();
  37. }
  38. }).start();
  39. }
  40. }