• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/FileManager


Commit MetaInfo

Révision2d8f1f6a97383b1431d180da74dc3e049ad959c8 (tree)
l'heure2011-06-29 14:37:58
AuteurJoe Berria <nexesdevelopment@gmai...>
CommiterJoe Berria

Message de Log

fixed problem with slow loading thumbnails.

Change Summary

Modification

--- a/src/com/nexes/manager/tablet/DirContentActivity.java
+++ b/src/com/nexes/manager/tablet/DirContentActivity.java
@@ -81,6 +81,7 @@ public class DirContentActivity extends Fragment implements OnItemClickListener,
8181 private FileManager mFileMang;
8282 private EventHandler mHandler;
8383 private MultiSelectHandler mMultiSelect;
84+ private ThumbnailCreator mThumbnail;
8485 private static OnBookMarkAddListener mBookmarkList;
8586
8687 private LinearLayout mPathView, mMultiSelectView;
@@ -467,6 +468,9 @@ public class DirContentActivity extends Fragment implements OnItemClickListener,
467468 }
468469
469470 if(file.isDirectory() && !mActionModeSelected ) {
471+ if (mThumbnail != null)
472+ mThumbnail = null;
473+
470474 addBackButton(name, true);
471475
472476 } else if (!file.isDirectory() && !mActionModeSelected ) {
@@ -616,6 +620,9 @@ public class DirContentActivity extends Fragment implements OnItemClickListener,
616620 if(mActionModeSelected || mMultiSelectOn)
617621 return;
618622
623+ if (mThumbnail != null)
624+ mThumbnail = null;
625+
619626 mData = mFileMang.setHomeDir(name);
620627 mDelegate.notifyDataSetChanged();
621628
@@ -870,20 +877,20 @@ public class DirContentActivity extends Fragment implements OnItemClickListener,
870877 private final int GB = MG * KB;
871878
872879 private DataViewHolder mHolder;
873- private ThumbnailCreator mThumbnail;
874880 private String mName;
875881
876882 public DataAdapter(Context context, int layout, ArrayList<String> data) {
877883 super(context, layout, data);
878- mThumbnail = new ThumbnailCreator(72, 72);
879-
880884 }
881885
882886 @Override
883887 public View getView(int position, View view, ViewGroup parent) {
884888 String ext;
885889 File file = null;
886- String current = mFileMang.getCurrentDir();
890+ String current = mFileMang.getCurrentDir();
891+
892+ if (mThumbnail == null)
893+ mThumbnail = new ThumbnailCreator(72, 72);
887894
888895 mName = mData.get(position);
889896 file = new File(current + "/" + mName);
@@ -973,15 +980,16 @@ public class DirContentActivity extends Fragment implements OnItemClickListener,
973980 if (thumb == null) {
974981 final Handler handle = new Handler(new Handler.Callback() {
975982 public boolean handleMessage(Message msg) {
976- mHolder.mIcon.setImageDrawable((BitmapDrawable)msg.obj);
977- mHolder.mIcon.setScaleType(ScaleType.CENTER);
978983 notifyDataSetChanged();
979984
980985 return true;
981986 }
982987 });
988+
989+ mThumbnail.createNewThumbnail(mData, mFileMang.getCurrentDir(), handle);
983990
984- mThumbnail.createNewThumbnail(file.getPath(), handle);
991+ if (!mThumbnail.isAlive())
992+ mThumbnail.start();
985993
986994 } else {
987995 mHolder.mIcon.setImageDrawable(thumb);
--- a/src/com/nexes/manager/tablet/ThumbnailCreator.java
+++ b/src/com/nexes/manager/tablet/ThumbnailCreator.java
@@ -24,18 +24,22 @@ import android.graphics.drawable.BitmapDrawable;
2424 import android.os.Handler;
2525 import android.os.Message;
2626 import android.view.Gravity;
27-import android.util.Log;
2827
2928 import java.lang.ref.SoftReference;
3029 import java.util.HashMap;
30+import java.util.ArrayList;
3131 import java.io.File;
3232
33-public class ThumbnailCreator {
34-
33+public class ThumbnailCreator extends Thread {
3534 private int mWidth;
3635 private int mHeight;
3736 private SoftReference<Bitmap> mThumb;
3837 private static HashMap<String, BitmapDrawable> mCacheMap = null;
38+
39+ //test vars
40+ private ArrayList<String> files;
41+ private String dir;
42+ private Handler handler;
3943
4044 public ThumbnailCreator(int width, int height) {
4145 mHeight = height;
@@ -49,51 +53,72 @@ public class ThumbnailCreator {
4953 return mCacheMap.get(name);
5054 }
5155
52- /*
53- * This needs to be done properly.
54- */
55- public void createNewThumbnail(final String imageName, final Handler handler) {
56- Thread thread = new Thread() {
56+ @Override
57+ public void run() {
58+ int len = files.size();
59+
60+ for (int i = 0; i < len; i++) {
61+ final File file = new File(dir + "/" + files.get(i));
5762
58- public void run() {
59- File file = new File(imageName);
63+ if (isImageFile(file.getName())) {
6064 long len_kb = file.length() / 1024;
61-
65+
6266 BitmapFactory.Options options = new BitmapFactory.Options();
6367 options.outWidth = mWidth;
6468 options.outHeight = mHeight;
6569
66- if (len_kb > 400 && len_kb < 1600) {
70+ if (len_kb > 500 && len_kb < 2000) {
6771 options.inSampleSize = 16;
68- mThumb = new SoftReference<Bitmap>(BitmapFactory.decodeFile(imageName, options));
72+ options.inPurgeable = true;
73+ options.inPreferQualityOverSpeed = false;
74+ mThumb = new SoftReference<Bitmap>(BitmapFactory.decodeFile(file.getPath(), options));
6975
70- } else if (len_kb >= 1600) {
76+ } else if (len_kb >= 2000) {
7177 options.inSampleSize = 32;
72- mThumb = new SoftReference<Bitmap>(BitmapFactory.decodeFile(imageName, options));
78+ options.inPurgeable = true;
79+ options.inPreferQualityOverSpeed = false;
80+ mThumb = new SoftReference<Bitmap>(BitmapFactory.decodeFile(file.getPath(), options));
7381
74- } else if (len_kb <= 400) {
82+ } else if (len_kb <= 500) {
83+ options.inPurgeable = true;
7584 mThumb = new SoftReference<Bitmap>(Bitmap.createScaledBitmap(
76- BitmapFactory.decodeFile(imageName),
85+ BitmapFactory.decodeFile(file.getPath()),
7786 mWidth,
7887 mHeight,
7988 false));
8089 }
8190
82- BitmapDrawable d = new BitmapDrawable(mThumb.get());
91+ final BitmapDrawable d = new BitmapDrawable(mThumb.get());
92+
8393 d.setGravity(Gravity.CENTER);
84- mCacheMap.put(imageName, d);
94+ mCacheMap.put(file.getPath(), d);
8595
8696 handler.post(new Runnable() {
8797 @Override
8898 public void run() {
8999 Message msg = handler.obtainMessage();
90- msg.obj = (BitmapDrawable)mCacheMap.get((imageName));
100+ msg.obj = (BitmapDrawable)d;
91101 msg.sendToTarget();
92102 }
93103 });
94104 }
95- };
96- thread.start();
97-
105+ }
106+ }
107+
108+ public void createNewThumbnail(ArrayList<String> files, String dir, Handler handler) {
109+ this.files = files;
110+ this.dir = dir;
111+ this.handler = handler;
112+ }
113+
114+ private boolean isImageFile(String file) {
115+ String ext = file.substring(file.lastIndexOf(".") + 1);
116+
117+ if (ext.equalsIgnoreCase("png") || ext.equalsIgnoreCase("jpg") ||
118+ ext.equalsIgnoreCase("jpeg")|| ext.equalsIgnoreCase("gif") ||
119+ ext.equalsIgnoreCase("tiff")|| ext.equalsIgnoreCase("tif"))
120+ return true;
121+
122+ return false;
98123 }
99124 }