packages/apps/FileManager
Revision | b39db62e9307518debf67f78d07c34e1e9fc14e8 (tree) |
---|---|
Time | 2011-07-03 00:56:20 |
Author | Joe Berria <nexesdevelopment@gmai...> |
Commiter | Joe Berria |
improved load speed of cached thumbnail icons
@@ -75,47 +75,59 @@ public class ThumbnailCreator extends Thread { | ||
75 | 75 | |
76 | 76 | final File file = new File(mDir + "/" + mFiles.get(i)); |
77 | 77 | |
78 | - if (isImageFile(file.getName())) { | |
79 | - long len_kb = file.length() / 1024; | |
80 | - | |
81 | - BitmapFactory.Options options = new BitmapFactory.Options(); | |
82 | - options.outWidth = mWidth; | |
83 | - options.outHeight = mHeight; | |
84 | - | |
85 | - if (len_kb > 500 && len_kb < 2000) { | |
86 | - options.inSampleSize = 16; | |
87 | - options.inPurgeable = true; | |
88 | - options.inPreferQualityOverSpeed = false; | |
89 | - mThumb = new SoftReference<Bitmap>(BitmapFactory.decodeFile(file.getPath(), options)); | |
90 | - | |
91 | - } else if (len_kb >= 2000) { | |
92 | - options.inSampleSize = 32; | |
93 | - options.inPurgeable = true; | |
94 | - options.inPreferQualityOverSpeed = false; | |
95 | - mThumb = new SoftReference<Bitmap>(BitmapFactory.decodeFile(file.getPath(), options)); | |
96 | - | |
97 | - } else if (len_kb <= 500) { | |
98 | - options.inPurgeable = true; | |
99 | - mThumb = new SoftReference<Bitmap>(Bitmap.createScaledBitmap( | |
100 | - BitmapFactory.decodeFile(file.getPath()), | |
101 | - mWidth, | |
102 | - mHeight, | |
103 | - false)); | |
104 | - } | |
105 | - | |
106 | - final BitmapDrawable d = new BitmapDrawable(mThumb.get()); | |
107 | - | |
108 | - d.setGravity(Gravity.CENTER); | |
109 | - mCacheMap.put(file.getPath(), d); | |
110 | - | |
78 | + //we already loaded this thumbnail, just return it. | |
79 | + if (mCacheMap.containsKey(file.getPath())) { | |
111 | 80 | mHandler.post(new Runnable() { |
112 | 81 | @Override |
113 | 82 | public void run() { |
114 | 83 | Message msg = mHandler.obtainMessage(); |
115 | - msg.obj = (BitmapDrawable)d; | |
84 | + msg.obj = mCacheMap.get(file.getPath()); | |
116 | 85 | msg.sendToTarget(); |
117 | 86 | } |
118 | 87 | }); |
88 | + | |
89 | + //we havn't loaded it yet, lets make it. | |
90 | + } else { | |
91 | + if (isImageFile(file.getName())) { | |
92 | + long len_kb = file.length() / 1024; | |
93 | + | |
94 | + BitmapFactory.Options options = new BitmapFactory.Options(); | |
95 | + options.outWidth = mWidth; | |
96 | + options.outHeight = mHeight; | |
97 | + | |
98 | + if (len_kb > 500 && len_kb < 2000) { | |
99 | + options.inSampleSize = 16; | |
100 | + options.inPurgeable = true; | |
101 | + mThumb = new SoftReference<Bitmap>(BitmapFactory.decodeFile(file.getPath(), options)); | |
102 | + | |
103 | + } else if (len_kb >= 2000) { | |
104 | + options.inSampleSize = 32; | |
105 | + options.inPurgeable = true; | |
106 | + mThumb = new SoftReference<Bitmap>(BitmapFactory.decodeFile(file.getPath(), options)); | |
107 | + | |
108 | + } else if (len_kb <= 500) { | |
109 | + options.inPurgeable = true; | |
110 | + mThumb = new SoftReference<Bitmap>(Bitmap.createScaledBitmap( | |
111 | + BitmapFactory.decodeFile(file.getPath()), | |
112 | + mWidth, | |
113 | + mHeight, | |
114 | + false)); | |
115 | + } | |
116 | + | |
117 | + final BitmapDrawable d = new BitmapDrawable(mThumb.get()); | |
118 | + | |
119 | + d.setGravity(Gravity.CENTER); | |
120 | + mCacheMap.put(file.getPath(), d); | |
121 | + | |
122 | + mHandler.post(new Runnable() { | |
123 | + @Override | |
124 | + public void run() { | |
125 | + Message msg = mHandler.obtainMessage(); | |
126 | + msg.obj = (BitmapDrawable)d; | |
127 | + msg.sendToTarget(); | |
128 | + } | |
129 | + }); | |
130 | + } | |
119 | 131 | } |
120 | 132 | } |
121 | 133 | } |