AltThumbnailCache.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package epson.print.imgsel;
  2. import android.content.Context;
  3. import android.content.SharedPreferences;
  4. import android.graphics.Bitmap;
  5. import android.graphics.BitmapFactory;
  6. import android.graphics.Matrix;
  7. import epson.common.Constants;
  8. import epson.print.IprintApplication;
  9. import epson.print.Util.EPLog;
  10. import java.io.File;
  11. public class AltThumbnailCache extends File {
  12. public static final String CACHE_DIR_NAME = "thumbnail";
  13. private static final boolean DEFAULT_USE_MEDIASTORE_THUMBNAIL = true;
  14. private static final String TAG = "ThumbnailCache";
  15. private static final int TARGET_SIZE_MICRO_THUMBNAIL = 96;
  16. static boolean bUseMediaStoreThumbnail = true;
  17. private static final long serialVersionUID = 1;
  18. long modified = -1;
  19. File realObject = null;
  20. public static void initThumbnailCache(Context context) {
  21. initCacheDirectory();
  22. bUseMediaStoreThumbnail = loadUseMediaStoreValue(context);
  23. }
  24. public static void setThumbnailCreateMethod(Context context, boolean z) {
  25. bUseMediaStoreThumbnail = z;
  26. saveUseMediaStoreValue(context, bUseMediaStoreThumbnail);
  27. deleteCacheDirectory();
  28. initCacheDirectory();
  29. }
  30. protected static boolean loadUseMediaStoreValue(Context context) {
  31. return getThumbnailCacheSharedPreferences(context).getBoolean(Constants.USE_MEDIASTORE_THUMBNAIL, true);
  32. }
  33. protected static void saveUseMediaStoreValue(Context context, boolean z) {
  34. SharedPreferences.Editor edit = getThumbnailCacheSharedPreferences(context).edit();
  35. edit.putBoolean(Constants.USE_MEDIASTORE_THUMBNAIL, z);
  36. edit.commit();
  37. }
  38. protected static SharedPreferences getThumbnailCacheSharedPreferences(Context context) {
  39. return context.getSharedPreferences(Constants.PREFS_PHOTO, 0);
  40. }
  41. public static boolean isUseMediaStoreThumbnail() {
  42. return bUseMediaStoreThumbnail;
  43. }
  44. public AltThumbnailCache(String str) {
  45. super(str);
  46. if (!exists()) {
  47. return;
  48. }
  49. if (isDirectory()) {
  50. for (File file : listFiles()) {
  51. if (!file.isDirectory()) {
  52. this.realObject = file;
  53. try {
  54. this.modified = Long.parseLong(file.getName());
  55. } catch (NumberFormatException e) {
  56. EPLog.e(TAG, e.getMessage());
  57. }
  58. }
  59. }
  60. } else if (isFile()) {
  61. delete();
  62. }
  63. }
  64. public boolean setLastModified(long j) {
  65. delete();
  66. this.modified = j;
  67. this.realObject = new File(getPath(), String.valueOf(j));
  68. return true;
  69. }
  70. public long lastModified() {
  71. return this.modified;
  72. }
  73. public String getCachePath() {
  74. if (!exists()) {
  75. mkdir();
  76. }
  77. return this.realObject.getPath();
  78. }
  79. static File getCacheDirectory() {
  80. return new File(IprintApplication.getInstance().getExternalCacheDir(), CACHE_DIR_NAME);
  81. }
  82. public static void initCacheDirectory() {
  83. File cacheDirectory = getCacheDirectory();
  84. if (!cacheDirectory.exists()) {
  85. cacheDirectory.mkdirs();
  86. }
  87. }
  88. public static void deleteCacheDirectory() {
  89. File cacheDirectory = getCacheDirectory();
  90. if (cacheDirectory.exists()) {
  91. deleteDirectory(cacheDirectory);
  92. }
  93. }
  94. public static void deleteDirectory(File file) {
  95. if (file.exists()) {
  96. if (!file.isDirectory()) {
  97. file.delete();
  98. return;
  99. }
  100. for (File file2 : file.listFiles()) {
  101. if (file2.isDirectory()) {
  102. deleteDirectory(file2);
  103. }
  104. if (file2.exists()) {
  105. file2.delete();
  106. }
  107. }
  108. }
  109. }
  110. /* JADX WARNING: Removed duplicated region for block: B:14:0x004e A[Catch:{ OutOfMemoryError -> 0x0073, Exception -> 0x0071 }] */
  111. /* JADX WARNING: Removed duplicated region for block: B:18:0x005f */
  112. /* JADX WARNING: Removed duplicated region for block: B:32:0x007e */
  113. /* Code decompiled incorrectly, please refer to instructions dump. */
  114. public static android.graphics.Bitmap createThumbnail(java.lang.String r8, android.content.ContentResolver r9, long r10) throws java.io.IOException {
  115. /*
  116. java.io.File r0 = new java.io.File
  117. r0.<init>(r8)
  118. java.io.File r1 = new java.io.File
  119. java.io.File r2 = getCacheDirectory()
  120. int r3 = r8.hashCode()
  121. java.lang.String r3 = java.lang.String.valueOf(r3)
  122. r1.<init>(r2, r3)
  123. java.lang.String r1 = r1.toString()
  124. epson.print.imgsel.AltThumbnailCache r2 = new epson.print.imgsel.AltThumbnailCache
  125. r2.<init>(r1)
  126. r1 = 0
  127. boolean r3 = r2.exists() // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  128. if (r3 == 0) goto L_0x0049
  129. long r3 = r2.lastModified() // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  130. long r5 = r0.lastModified() // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  131. int r7 = (r3 > r5 ? 1 : (r3 == r5 ? 0 : -1))
  132. if (r7 != 0) goto L_0x0046
  133. android.graphics.BitmapFactory$Options r3 = new android.graphics.BitmapFactory$Options // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  134. r3.<init>() // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  135. android.graphics.Bitmap$Config r4 = android.graphics.Bitmap.Config.RGB_565 // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  136. r3.inPreferredConfig = r4 // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  137. java.lang.String r4 = r2.getCachePath() // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  138. android.graphics.Bitmap r3 = android.graphics.BitmapFactory.decodeFile(r4, r3) // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  139. if (r3 == 0) goto L_0x004a
  140. return r3
  141. L_0x0046:
  142. r2.delete() // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  143. L_0x0049:
  144. r3 = r1
  145. L_0x004a:
  146. boolean r4 = bUseMediaStoreThumbnail // Catch:{ OutOfMemoryError -> 0x0073, Exception -> 0x0071 }
  147. if (r4 == 0) goto L_0x005f
  148. r4 = 3
  149. android.graphics.Bitmap r1 = android.provider.MediaStore.Images.Thumbnails.getThumbnail(r9, r10, r4, r1) // Catch:{ OutOfMemoryError -> 0x0073, Exception -> 0x0071 }
  150. if (r1 == 0) goto L_0x007c
  151. epson.print.EPImageUtil r9 = new epson.print.EPImageUtil // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  152. r9.<init>() // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  153. android.graphics.Bitmap r1 = r9.check_rotate(r8, r1) // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  154. goto L_0x007c
  155. L_0x005f:
  156. r9 = 96
  157. android.graphics.Bitmap r1 = createThumbnail(r8, r9) // Catch:{ OutOfMemoryError -> 0x0073, Exception -> 0x0071 }
  158. if (r1 == 0) goto L_0x007c
  159. epson.print.EPImageUtil r9 = new epson.print.EPImageUtil // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  160. r9.<init>() // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  161. android.graphics.Bitmap r1 = r9.check_rotate(r8, r1) // Catch:{ OutOfMemoryError -> 0x0078, Exception -> 0x0076 }
  162. goto L_0x007c
  163. L_0x0071:
  164. r1 = r3
  165. goto L_0x007c
  166. L_0x0073:
  167. r8 = move-exception
  168. r1 = r3
  169. goto L_0x0079
  170. L_0x0076:
  171. goto L_0x007c
  172. L_0x0078:
  173. r8 = move-exception
  174. L_0x0079:
  175. r8.printStackTrace()
  176. L_0x007c:
  177. if (r1 == 0) goto L_0x009b
  178. long r8 = r0.lastModified()
  179. r2.setLastModified(r8)
  180. java.io.FileOutputStream r8 = new java.io.FileOutputStream
  181. java.lang.String r9 = r2.getCachePath()
  182. r8.<init>(r9)
  183. android.graphics.Bitmap$CompressFormat r9 = android.graphics.Bitmap.CompressFormat.JPEG
  184. r10 = 80
  185. r1.compress(r9, r10, r8)
  186. r8.flush()
  187. r8.close()
  188. L_0x009b:
  189. return r1
  190. */
  191. throw new UnsupportedOperationException("Method not decompiled: epson.print.imgsel.AltThumbnailCache.createThumbnail(java.lang.String, android.content.ContentResolver, long):android.graphics.Bitmap");
  192. }
  193. public static Bitmap createThumbnail(String str, int i) {
  194. Bitmap bitmap;
  195. try {
  196. BitmapFactory.Options options = new BitmapFactory.Options();
  197. options.inJustDecodeBounds = true;
  198. BitmapFactory.decodeFile(str, options);
  199. if (options.outWidth != 0) {
  200. if (options.outHeight != 0) {
  201. int min = Math.min(options.outWidth / i, options.outHeight / i);
  202. BitmapFactory.Options options2 = new BitmapFactory.Options();
  203. options2.inPreferredConfig = Bitmap.Config.RGB_565;
  204. options2.inSampleSize = min;
  205. bitmap = BitmapFactory.decodeFile(str, options2);
  206. if (bitmap == null) {
  207. return null;
  208. }
  209. try {
  210. int min2 = Math.min(bitmap.getWidth(), bitmap.getHeight());
  211. float f = ((float) i) / ((float) min2);
  212. Matrix matrix = new Matrix();
  213. matrix.postScale(f, f);
  214. return Bitmap.createBitmap(bitmap, (bitmap.getWidth() - min2) / 2, (bitmap.getHeight() - min2) / 2, min2, min2, matrix, true);
  215. } catch (OutOfMemoryError e) {
  216. e = e;
  217. e.printStackTrace();
  218. return bitmap;
  219. }
  220. }
  221. }
  222. return null;
  223. } catch (OutOfMemoryError e2) {
  224. e = e2;
  225. bitmap = null;
  226. e.printStackTrace();
  227. return bitmap;
  228. }
  229. }
  230. }