ImageThumbnailTask.java 5.9 KB

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