ImageThumbnailTask.java 6.2 KB

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