ImageFindTask.java 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package epson.print.imgsel;
  2. import android.content.ContentResolver;
  3. import android.graphics.Bitmap;
  4. import android.os.AsyncTask;
  5. import epson.print.ImageItem;
  6. import epson.print.imgsel.ImageFinder;
  7. import java.lang.ref.WeakReference;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. class ImageFindTask extends AsyncTask<ImageFinder, List<ImageItem>, Void> implements ImageFinder.Canceller {
  11. private static int IMAGE_QUERY_LIMIT = 32;
  12. String mFolderPath;
  13. WeakReference<ImageGridFragment> mFragmentReference;
  14. public ImageFindTask(ImageGridFragment imageGridFragment, String str) {
  15. this.mFragmentReference = new WeakReference<>(imageGridFragment);
  16. this.mFolderPath = str;
  17. }
  18. /* access modifiers changed from: protected */
  19. public Void doInBackground(ImageFinder... imageFinderArr) {
  20. ImageGridFragment imageGridFragment;
  21. List<ImageFileInfo> findImageInDirectory;
  22. if (imageFinderArr == null || imageFinderArr.length <= 0) {
  23. return null;
  24. }
  25. ImageFinder imageFinder = imageFinderArr[0];
  26. if (!(isCancelled() || imageFinder == null || (imageGridFragment = (ImageGridFragment) this.mFragmentReference.get()) == null || imageGridFragment.getActivity() == null || isCancelled() || (findImageInDirectory = imageFinder.findImageInDirectory(this.mFolderPath, getResolver(), this)) == null)) {
  27. ArrayList arrayList = new ArrayList();
  28. for (ImageFileInfo next : findImageInDirectory) {
  29. if (isCancelled()) {
  30. return null;
  31. }
  32. boolean isImageSelected = isImageSelected(next.mCanonicalPath);
  33. arrayList.add(new ImageItem((Bitmap) null, isImageSelected ? 1 : 0, next.mCanonicalPath, next.mMediaInfoId));
  34. if (arrayList.size() % IMAGE_QUERY_LIMIT == 0) {
  35. publishProgress(new List[]{arrayList});
  36. arrayList = new ArrayList();
  37. }
  38. }
  39. if (arrayList.size() > 0) {
  40. publishProgress(new List[]{arrayList});
  41. }
  42. }
  43. return null;
  44. }
  45. private ContentResolver getResolver() {
  46. FragmentActivity activity;
  47. ImageGridFragment imageGridFragment = (ImageGridFragment) this.mFragmentReference.get();
  48. if (imageGridFragment == null || (activity = imageGridFragment.getActivity()) == null) {
  49. return null;
  50. }
  51. return activity.getContentResolver();
  52. }
  53. private boolean isImageSelected(String str) {
  54. ImageGridFragment imageGridFragment = (ImageGridFragment) this.mFragmentReference.get();
  55. if (imageGridFragment == null) {
  56. return false;
  57. }
  58. return imageGridFragment.isImageSelected(str);
  59. }
  60. public boolean checkCanceled() {
  61. return isCancelled();
  62. }
  63. /* access modifiers changed from: protected */
  64. public void onPreExecute() {
  65. ImageGridFragment imageGridFragment = (ImageGridFragment) this.mFragmentReference.get();
  66. if (imageGridFragment != null) {
  67. imageGridFragment.clearItem();
  68. }
  69. }
  70. /* access modifiers changed from: protected */
  71. public void onProgressUpdate(List<ImageItem>... listArr) {
  72. ImageGridFragment imageGridFragment = (ImageGridFragment) this.mFragmentReference.get();
  73. if (imageGridFragment != null && listArr != null && listArr.length > 0) {
  74. imageGridFragment.addItem(listArr[0]);
  75. }
  76. }
  77. /* access modifiers changed from: protected */
  78. public void onPostExecute(Void voidR) {
  79. ImageGridFragment imageGridFragment = (ImageGridFragment) this.mFragmentReference.get();
  80. if (imageGridFragment != null) {
  81. imageGridFragment.updateData();
  82. }
  83. }
  84. }