ImageThumbnailTask.java 6.1 KB

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