ImageThumbnailTask.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.Util.EPLog;
  7. import epson.print.imgsel.ImageFinder;
  8. import java.io.IOException;
  9. import java.lang.ref.WeakReference;
  10. import java.util.LinkedList;
  11. public class ImageThumbnailTask extends AsyncTask<Void, ImageItem, Void> implements ImageFinder.Canceller {
  12. private static final int RETRY_CHECKLIST = 100;
  13. private static final int RETRY_SUSPEND = 1000;
  14. private static final String TAG = "ImageThumbnailTask";
  15. private volatile boolean finish = false;
  16. private volatile LinkedList<ImageItem> imageItems;
  17. WeakReference<ImageGridFragment> mFragmentReference;
  18. private volatile boolean suspend = false;
  19. public ImageThumbnailTask(ImageGridFragment imageGridFragment) {
  20. this.mFragmentReference = new WeakReference<>(imageGridFragment);
  21. this.imageItems = new LinkedList<>();
  22. }
  23. protected Void doInBackground(Void... voidArr) {
  24. Bitmap bitmap;
  25. EPLog.d(TAG, "Enter doInBackground");
  26. ContentResolver resolver = getResolver();
  27. while (true) {
  28. ImageItem first = getFirst();
  29. if ((first != null || !this.finish) && !isCancelled()) {
  30. if (first == null) {
  31. try {
  32. EPLog.d(TAG, "Wait doInBackground");
  33. Thread.sleep(100);
  34. } catch (InterruptedException e) {
  35. e.printStackTrace();
  36. }
  37. } else {
  38. try {
  39. EPLog.d(TAG, "createThumbnail " + first.getPath());
  40. bitmap = AltThumbnailCache.createThumbnail(first.getPath(), resolver, first.getDatabaseId());
  41. } catch (IOException e2) {
  42. e2.printStackTrace();
  43. bitmap = null;
  44. }
  45. publishProgress(new ImageItem[]{new ImageItem(bitmap, 0, first.getPath(), first.getDatabaseId())});
  46. if (this.suspend) {
  47. EPLog.d(TAG, "Enter suspend");
  48. while (this.suspend && !isCancelled()) {
  49. try {
  50. Thread.sleep(1000);
  51. } catch (InterruptedException unused) {
  52. }
  53. }
  54. EPLog.d(TAG, "Leave suspend");
  55. }
  56. }
  57. }
  58. }
  59. EPLog.d(TAG, "Leave doInBackground");
  60. return null;
  61. }
  62. protected void onProgressUpdate(ImageItem... imageItemArr) {
  63. ImageGridFragment imageGridFragment = (ImageGridFragment) this.mFragmentReference.get();
  64. if (imageGridFragment != null && imageItemArr != null && imageItemArr.length > 0) {
  65. imageGridFragment.updateItem(imageItemArr[0]);
  66. }
  67. }
  68. private synchronized ImageItem getFirst() {
  69. if (this.imageItems != null) {
  70. if (this.imageItems.size() > 0) {
  71. return this.imageItems.remove(0);
  72. }
  73. }
  74. return null;
  75. }
  76. /* access modifiers changed from: package-private */
  77. /* JADX WARNING: Code restructure failed: missing block: B:12:0x0037, code lost:
  78. return;
  79. */
  80. /* Code decompiled incorrectly, please refer to instructions dump. */
  81. public synchronized void moveToFirst(epson.print.ImageItem r5) {
  82. /*
  83. r4 = this;
  84. monitor-enter(r4)
  85. java.util.LinkedList<epson.print.ImageItem> r0 = r4.imageItems // Catch:{ all -> 0x0038 }
  86. if (r0 != 0) goto L_0x0007
  87. monitor-exit(r4)
  88. return
  89. L_0x0007:
  90. java.util.LinkedList<epson.print.ImageItem> r0 = r4.imageItems // Catch:{ all -> 0x0038 }
  91. int r0 = r0.indexOf(r5) // Catch:{ all -> 0x0038 }
  92. r1 = -1
  93. if (r0 != r1) goto L_0x0011
  94. goto L_0x0036
  95. L_0x0011:
  96. java.lang.String r1 = "ImageThumbnailTask"
  97. java.lang.StringBuilder r2 = new java.lang.StringBuilder // Catch:{ all -> 0x0038 }
  98. r2.<init>() // Catch:{ all -> 0x0038 }
  99. java.lang.String r3 = "moveToFirst "
  100. r2.append(r3) // Catch:{ all -> 0x0038 }
  101. java.lang.String r5 = r5.getPath() // Catch:{ all -> 0x0038 }
  102. r2.append(r5) // Catch:{ all -> 0x0038 }
  103. java.lang.String r5 = r2.toString() // Catch:{ all -> 0x0038 }
  104. epson.print.Util.EPLog.d(r1, r5) // Catch:{ all -> 0x0038 }
  105. java.util.LinkedList<epson.print.ImageItem> r5 = r4.imageItems // Catch:{ all -> 0x0038 }
  106. java.util.LinkedList<epson.print.ImageItem> r1 = r4.imageItems // Catch:{ all -> 0x0038 }
  107. java.lang.Object r0 = r1.remove(r0) // Catch:{ all -> 0x0038 }
  108. r5.addFirst(r0) // Catch:{ all -> 0x0038 }
  109. L_0x0036:
  110. monitor-exit(r4)
  111. return
  112. L_0x0038:
  113. r5 = move-exception
  114. monitor-exit(r4)
  115. throw r5
  116. */
  117. throw new UnsupportedOperationException("Method not decompiled: epson.print.imgsel.ImageThumbnailTask.moveToFirst(epson.print.ImageItem):void");
  118. }
  119. private synchronized void addLast(ImageItem imageItem) {
  120. if (this.imageItems != null) {
  121. this.imageItems.addLast(imageItem);
  122. }
  123. }
  124. public void setFinish(boolean z) {
  125. this.finish = z;
  126. }
  127. public void setSuspend(boolean z) {
  128. this.suspend = z;
  129. }
  130. private ContentResolver getResolver() {
  131. FragmentActivity activity;
  132. ImageGridFragment imageGridFragment = (ImageGridFragment) this.mFragmentReference.get();
  133. if (imageGridFragment == null || (activity = imageGridFragment.getActivity()) == null) {
  134. return null;
  135. }
  136. return activity.getContentResolver();
  137. }
  138. public boolean checkCanceled() {
  139. return isCancelled();
  140. }
  141. }