From e9d06f5cf2f2f6859d85ed0efef280f05be47304 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Thu, 19 Apr 2012 01:09:26 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E8=BF=9B=E4=B8=80=E6=AD=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../micode/fileexplorer/FileViewInteractionHub.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/net/micode/fileexplorer/FileViewInteractionHub.java b/src/net/micode/fileexplorer/FileViewInteractionHub.java index 8073715..e05cada 100644 --- a/src/net/micode/fileexplorer/FileViewInteractionHub.java +++ b/src/net/micode/fileexplorer/FileViewInteractionHub.java @@ -381,6 +381,10 @@ public boolean onOperationUpLevel() { return true; } + /* + *在这里控制了按返回键回到上一级菜单的动作 + *下一步修改为真正的后退动作 + */ if (!mRoot.equals(mCurrentPath)) { mCurrentPath = new File(mCurrentPath).getParent(); refreshFileList(); @@ -1054,7 +1058,11 @@ private void viewFile(FileInfo lFileInfo) { Log.e(LOG_TAG, "fail to view file: " + e.toString()); } } - + + /* + *在这里控制了按返回键回到上一级菜单的动作 + *下一步修改为真正的后退动作 + */ public boolean onBackPressed() { if (mDropdownNavigation.getVisibility() == View.VISIBLE) { mDropdownNavigation.setVisibility(View.GONE); From 9aa864e947394244218f11fef473ec171e2dd15d Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Thu, 19 Apr 2012 21:34:40 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=8C=89=E8=BF=94=E5=9B=9E=E9=94=AE?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E6=98=AF=E7=9C=9F=E6=AD=A3=E7=9A=84=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E4=B8=8A=E4=B8=80=E4=B8=AA=E8=AE=BF=E9=97=AE=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E8=80=8C=E5=B9=B6=E9=9D=9E=E4=B8=8A?= =?UTF-8?q?=E4=B8=80=E7=BA=A7=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../micode/fileexplorer/FileViewActivity.java | 3 +- .../fileexplorer/FileViewInteractionHub.java | 53 +++++++++++++------ 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/net/micode/fileexplorer/FileViewActivity.java b/src/net/micode/fileexplorer/FileViewActivity.java index 2678bb5..e1a1867 100644 --- a/src/net/micode/fileexplorer/FileViewActivity.java +++ b/src/net/micode/fileexplorer/FileViewActivity.java @@ -435,8 +435,7 @@ public boolean setPath(String location) { if (!location.startsWith(mFileViewInteractionHub.getRootPath())) { return false; } - mFileViewInteractionHub.setCurrentPath(location); - mFileViewInteractionHub.refreshFileList(); + mFileViewInteractionHub.jump2Folder(location); return true; } diff --git a/src/net/micode/fileexplorer/FileViewInteractionHub.java b/src/net/micode/fileexplorer/FileViewInteractionHub.java index e05cada..909342a 100644 --- a/src/net/micode/fileexplorer/FileViewInteractionHub.java +++ b/src/net/micode/fileexplorer/FileViewInteractionHub.java @@ -21,6 +21,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.Stack; import android.R.drawable; import android.app.AlertDialog; @@ -86,6 +87,8 @@ public class FileViewInteractionHub implements IOperationProgressListener { private ImageView mNavigationBarUpDownArrow; private Context mContext; + + private Stack mFolderHistroyStack; public enum Mode { View, Pick @@ -98,6 +101,7 @@ public FileViewInteractionHub(IFileInteractionListener fileViewListener) { mFileOperationHelper = new FileOperationHelper(this); mFileSortHelper = new FileSortHelper(); mContext = mFileViewListener.getContext(); + mFolderHistroyStack = new Stack(); } private void showProgress(String msg) { @@ -231,7 +235,7 @@ public void onClick(View v) { onOperationButtonCancel(); break; case R.id.path_pane_up_level: - onOperationUpLevel(); + onOperationUpLevel(false); ActionMode mode = ((FileExplorerTabActivity) mContext).getActionMode(); if (mode != null) { mode.finish(); @@ -311,6 +315,26 @@ public void onOperationSelectAll() { } mFileViewListener.onDataChanged(); } + + public void jump2Folder(String path) { + if(mCurrentPath != path){//判断是否应该将当前路径添加到历史堆栈中 + mFolderHistroyStack.add(mCurrentPath.isEmpty() ? mRoot : mCurrentPath); + } + mCurrentPath = path; + refreshFileList(); + } + + /* + *返回上一个文件夹 + *当存在上一个浏览过的文件夹时返回true,当已经是最初浏览的文件夹时返回false + *(用以判断是否该退出) + */ + private boolean folderReturn(){ + if(mFolderHistroyStack.empty())return false; + mCurrentPath = mFolderHistroyStack.pop(); + refreshFileList(); + return true; + } private OnClickListener navigationClick = new OnClickListener() { @@ -322,12 +346,7 @@ public void onClick(View v) { if (mFileViewListener.onNavigation(path)) return; - if(path.isEmpty()){ - mCurrentPath = mRoot; - } else{ - mCurrentPath = path; - } - refreshFileList(); + jump2Folder(path.isEmpty() ? mRoot : path); } }; @@ -374,7 +393,7 @@ protected void onNavigationBarClick() { } } - public boolean onOperationUpLevel() { + public boolean onOperationUpLevel(boolean isreturn) { showDropdownNavigation(false); if (mFileViewListener.onOperation(GlobalConsts.OPERATION_UP_LEVEL)) { @@ -385,12 +404,15 @@ public boolean onOperationUpLevel() { *在这里控制了按返回键回到上一级菜单的动作 *下一步修改为真正的后退动作 */ - if (!mRoot.equals(mCurrentPath)) { - mCurrentPath = new File(mCurrentPath).getParent(); - refreshFileList(); - return true; + if (isreturn) {//真正的后退动作 + return folderReturn(); + } else {//返回上一级文件夹 + if (!mRoot.equals(mCurrentPath)) { + jump2Folder(new File(mCurrentPath).getParent()); + return true; + } } - + return false; } @@ -981,12 +1003,11 @@ public void onListItemClick(AdapterView parent, View view, int position, long return; } - mCurrentPath = getAbsoluteName(mCurrentPath, lFileInfo.fileName); + jump2Folder(getAbsoluteName(mCurrentPath, lFileInfo.fileName)); ActionMode actionMode = ((FileExplorerTabActivity) mContext).getActionMode(); if (actionMode != null) { actionMode.finish(); } - refreshFileList(); } public void setRootPath(String path) { @@ -1068,7 +1089,7 @@ public boolean onBackPressed() { mDropdownNavigation.setVisibility(View.GONE); } else if (isInSelection()) { clearSelection(); - } else if (!onOperationUpLevel()) { + } else if (!onOperationUpLevel(true)) { return false; } return true; From 863f8cc44e0a03702781c6d9eda7e597981edbe1 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Sat, 21 Apr 2012 17:25:36 +0800 Subject: [PATCH 3/5] Remove useless comments & Format code. --- .../micode/fileexplorer/FileViewActivity.java | 129 +++-- .../fileexplorer/FileViewInteractionHub.java | 499 ++++++++++-------- 2 files changed, 362 insertions(+), 266 deletions(-) diff --git a/src/net/micode/fileexplorer/FileViewActivity.java b/src/net/micode/fileexplorer/FileViewActivity.java index e1a1867..b9c55af 100644 --- a/src/net/micode/fileexplorer/FileViewActivity.java +++ b/src/net/micode/fileexplorer/FileViewActivity.java @@ -87,7 +87,8 @@ public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Log.v(LOG_TAG, "received broadcast:" + intent.toString()); - if (action.equals(Intent.ACTION_MEDIA_MOUNTED) || action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) { + if (action.equals(Intent.ACTION_MEDIA_MOUNTED) + || action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) { runOnUiThread(new Runnable() { @Override public void run() { @@ -101,18 +102,22 @@ public void run() { private boolean mBackspaceExit; @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { mActivity = getActivity(); // getWindow().setFormat(android.graphics.PixelFormat.RGBA_8888); - mRootView = inflater.inflate(R.layout.file_explorer_list, container, false); - ActivitiesManager.getInstance().registerActivity(ActivitiesManager.ACTIVITY_FILE_VIEW, mActivity); + mRootView = inflater.inflate(R.layout.file_explorer_list, container, + false); + ActivitiesManager.getInstance().registerActivity( + ActivitiesManager.ACTIVITY_FILE_VIEW, mActivity); mFileCagetoryHelper = new FileCategoryHelper(mActivity); mFileViewInteractionHub = new FileViewInteractionHub(this); Intent intent = mActivity.getIntent(); String action = intent.getAction(); if (!TextUtils.isEmpty(action) - && (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT))) { + && (action.equals(Intent.ACTION_PICK) || action + .equals(Intent.ACTION_GET_CONTENT))) { mFileViewInteractionHub.setMode(Mode.Pick); boolean pickFolder = intent.getBooleanExtra(PICK_FOLDER, false); @@ -122,26 +127,35 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mFileCagetoryHelper.setCustomCategory(exts); } } else { - mFileCagetoryHelper.setCustomCategory(new String[]{} /*folder only*/); - mRootView.findViewById(R.id.pick_operation_bar).setVisibility(View.VISIBLE); - - mRootView.findViewById(R.id.button_pick_confirm).setOnClickListener(new OnClickListener() { - public void onClick(View v) { - try { - Intent intent = Intent.parseUri(mFileViewInteractionHub.getCurrentPath(), 0); - mActivity.setResult(Activity.RESULT_OK, intent); - mActivity.finish(); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - } - }); - - mRootView.findViewById(R.id.button_pick_cancel).setOnClickListener(new OnClickListener() { - public void onClick(View v) { - mActivity.finish(); - } - }); + mFileCagetoryHelper.setCustomCategory(new String[] {} /* + * folder + * only + */); + mRootView.findViewById(R.id.pick_operation_bar).setVisibility( + View.VISIBLE); + + mRootView.findViewById(R.id.button_pick_confirm) + .setOnClickListener(new OnClickListener() { + public void onClick(View v) { + try { + Intent intent = Intent.parseUri( + mFileViewInteractionHub + .getCurrentPath(), 0); + mActivity.setResult(Activity.RESULT_OK, + intent); + mActivity.finish(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + } + }); + + mRootView.findViewById(R.id.button_pick_cancel) + .setOnClickListener(new OnClickListener() { + public void onClick(View v) { + mActivity.finish(); + } + }); } } else { mFileViewInteractionHub.setMode(Mode.View); @@ -149,10 +163,11 @@ public void onClick(View v) { mFileListView = (ListView) mRootView.findViewById(R.id.file_path_list); mFileIconHelper = new FileIconHelper(mActivity); - mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, mFileNameList, mFileViewInteractionHub, - mFileIconHelper); + mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, + mFileNameList, mFileViewInteractionHub, mFileIconHelper); - boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD, !FileExplorerPreferenceActivity.isReadRoot(mActivity)); + boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD, + !FileExplorerPreferenceActivity.isReadRoot(mActivity)); Log.i(LOG_TAG, "baseSd = " + baseSd); String rootDir = intent.getStringExtra(ROOT_DIRECTORY); @@ -165,7 +180,8 @@ public void onClick(View v) { } mFileViewInteractionHub.setRootPath(rootDir); - String currentDir = FileExplorerPreferenceActivity.getPrimaryFolder(mActivity); + String currentDir = FileExplorerPreferenceActivity + .getPrimaryFolder(mActivity); Uri uri = intent.getData(); if (uri != null) { if (baseSd && this.sdDir.startsWith(uri.getPath())) { @@ -178,8 +194,9 @@ public void onClick(View v) { Log.i(LOG_TAG, "CurrentDir = " + currentDir); mBackspaceExit = (uri != null) - && (TextUtils.isEmpty(action) - || (!action.equals(Intent.ACTION_PICK) && !action.equals(Intent.ACTION_GET_CONTENT))); + && (TextUtils.isEmpty(action) || (!action + .equals(Intent.ACTION_PICK) && !action + .equals(Intent.ACTION_GET_CONTENT))); mFileListView.setAdapter(mAdapter); mFileViewInteractionHub.refreshFileList(); @@ -215,7 +232,8 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { @Override public boolean onBack() { - if (mBackspaceExit || !Util.isSDCardReady() || mFileViewInteractionHub == null) { + if (mBackspaceExit || !Util.isSDCardReady() + || mFileViewInteractionHub == null) { return false; } return mFileViewInteractionHub.onBackPressed(); @@ -224,6 +242,7 @@ public boolean onBack() { private class PathScrollPositionItem { String path; int pos; + PathScrollPositionItem(String s, int p) { path = s; pos = p; @@ -233,18 +252,23 @@ private class PathScrollPositionItem { // execute before change, return the memorized scroll position private int computeScrollPosition(String path) { int pos = 0; - if(mPreviousPath!=null) { + if (mPreviousPath != null) { if (path.startsWith(mPreviousPath)) { - int firstVisiblePosition = mFileListView.getFirstVisiblePosition(); + int firstVisiblePosition = mFileListView + .getFirstVisiblePosition(); if (mScrollPositionList.size() != 0 - && mPreviousPath.equals(mScrollPositionList.get(mScrollPositionList.size() - 1).path)) { + && mPreviousPath.equals(mScrollPositionList + .get(mScrollPositionList.size() - 1).path)) { mScrollPositionList.get(mScrollPositionList.size() - 1).pos = firstVisiblePosition; - Log.i(LOG_TAG, "computeScrollPosition: update item: " + mPreviousPath + " " + firstVisiblePosition + Log.i(LOG_TAG, "computeScrollPosition: update item: " + + mPreviousPath + " " + firstVisiblePosition + " stack count:" + mScrollPositionList.size()); pos = firstVisiblePosition; } else { - mScrollPositionList.add(new PathScrollPositionItem(mPreviousPath, firstVisiblePosition)); - Log.i(LOG_TAG, "computeScrollPosition: add item: " + mPreviousPath + " " + firstVisiblePosition + mScrollPositionList.add(new PathScrollPositionItem( + mPreviousPath, firstVisiblePosition)); + Log.i(LOG_TAG, "computeScrollPosition: add item: " + + mPreviousPath + " " + firstVisiblePosition + " stack count:" + mScrollPositionList.size()); } } else { @@ -260,16 +284,19 @@ private int computeScrollPosition(String path) { pos = mScrollPositionList.get(i - 1).pos; } - for (int j = mScrollPositionList.size() - 1; j >= i-1 && j>=0; j--) { + for (int j = mScrollPositionList.size() - 1; j >= i - 1 + && j >= 0; j--) { mScrollPositionList.remove(j); } } } - Log.i(LOG_TAG, "computeScrollPosition: result pos: " + path + " " + pos + " stack count:" + mScrollPositionList.size()); + Log.i(LOG_TAG, "computeScrollPosition: result pos: " + path + " " + pos + + " stack count:" + mScrollPositionList.size()); mPreviousPath = path; return pos; } + public boolean onRefreshFileList(String path, FileSortHelper sort) { File file = new File(path); if (!file.exists() || !file.isDirectory()) { @@ -285,13 +312,16 @@ public boolean onRefreshFileList(String path, FileSortHelper sort) { for (File child : listFiles) { // do not show selected file if in move state - if (mFileViewInteractionHub.isMoveState() && mFileViewInteractionHub.isFileSelected(child.getPath())) + if (mFileViewInteractionHub.isMoveState() + && mFileViewInteractionHub.isFileSelected(child.getPath())) continue; String absolutePath = child.getAbsolutePath(); - if (Util.isNormalFile(absolutePath) && Util.shouldShowFile(absolutePath)) { + if (Util.isNormalFile(absolutePath) + && Util.shouldShowFile(absolutePath)) { FileInfo lFileInfo = Util.GetFileInfo(child, - mFileCagetoryHelper.getFilter(), Settings.instance().getShowDotAndHiddenFiles()); + mFileCagetoryHelper.getFilter(), Settings.instance() + .getShowDotAndHiddenFiles()); if (lFileInfo != null) { fileList.add(lFileInfo); } @@ -318,7 +348,7 @@ private void updateUI() { navigationBar.setVisibility(sdCardReady ? View.VISIBLE : View.GONE); mFileListView.setVisibility(sdCardReady ? View.VISIBLE : View.GONE); - if(sdCardReady) { + if (sdCardReady) { mFileViewInteractionHub.refreshFileList(); } } @@ -354,7 +384,8 @@ public void run() { @Override public void onPick(FileInfo f) { try { - Intent intent = Intent.parseUri(Uri.fromFile(new File(f.filePath)).toString(), 0); + Intent intent = Intent.parseUri(Uri.fromFile(new File(f.filePath)) + .toString(), 0); mActivity.setResult(Activity.RESULT_OK, intent); mActivity.finish(); return; @@ -373,11 +404,13 @@ public boolean onOperation(int id) { return false; } - //支持显示真实路径 + // 支持显示真实路径 @Override public String getDisplayPath(String path) { - if (path.startsWith(this.sdDir) && !FileExplorerPreferenceActivity.showRealPath(mActivity)) { - return getString(R.string.sd_folder) + path.substring(this.sdDir.length()); + if (path.startsWith(this.sdDir) + && !FileExplorerPreferenceActivity.showRealPath(mActivity)) { + return getString(R.string.sd_folder) + + path.substring(this.sdDir.length()); } else { return path; } diff --git a/src/net/micode/fileexplorer/FileViewInteractionHub.java b/src/net/micode/fileexplorer/FileViewInteractionHub.java index 909342a..7b1a04c 100644 --- a/src/net/micode/fileexplorer/FileViewInteractionHub.java +++ b/src/net/micode/fileexplorer/FileViewInteractionHub.java @@ -87,7 +87,7 @@ public class FileViewInteractionHub implements IOperationProgressListener { private ImageView mNavigationBarUpDownArrow; private Context mContext; - + private Stack mFolderHistroyStack; public enum Mode { @@ -172,7 +172,8 @@ public boolean isInSelection() { } public boolean isMoveState() { - return mFileOperationHelper.isMoveState() || mFileOperationHelper.canPaste(); + return mFileOperationHelper.isMoveState() + || mFileOperationHelper.canPaste(); } private void setup() { @@ -183,25 +184,30 @@ private void setup() { private void setupNaivgationBar() { mNavigationBar = mFileViewListener.getViewById(R.id.navigation_bar); - mNavigationBarText = (TextView) mFileViewListener.getViewById(R.id.current_path_view); - mNavigationBarUpDownArrow = (ImageView) mFileViewListener.getViewById(R.id.path_pane_arrow); + mNavigationBarText = (TextView) mFileViewListener + .getViewById(R.id.current_path_view); + mNavigationBarUpDownArrow = (ImageView) mFileViewListener + .getViewById(R.id.path_pane_arrow); View clickable = mFileViewListener.getViewById(R.id.current_path_pane); clickable.setOnClickListener(buttonClick); - mDropdownNavigation = mFileViewListener.getViewById(R.id.dropdown_navigation); + mDropdownNavigation = mFileViewListener + .getViewById(R.id.dropdown_navigation); setupClick(mNavigationBar, R.id.path_pane_up_level); } // buttons private void setupOperationPane() { - mConfirmOperationBar = mFileViewListener.getViewById(R.id.moving_operation_bar); + mConfirmOperationBar = mFileViewListener + .getViewById(R.id.moving_operation_bar); setupClick(mConfirmOperationBar, R.id.button_moving_confirm); setupClick(mConfirmOperationBar, R.id.button_moving_cancel); } private void setupClick(View v, int id) { - View button = (v != null ? v.findViewById(id) : mFileViewListener.getViewById(id)); + View button = (v != null ? v.findViewById(id) : mFileViewListener + .getViewById(id)); if (button != null) button.setOnClickListener(buttonClick); } @@ -210,37 +216,38 @@ private void setupClick(View v, int id) { @Override public void onClick(View v) { switch (v.getId()) { - case R.id.button_operation_copy: - onOperationCopy(); - break; - case R.id.button_operation_move: - onOperationMove(); - break; - case R.id.button_operation_send: - onOperationSend(); - break; - case R.id.button_operation_delete: - onOperationDelete(); - break; - case R.id.button_operation_cancel: - onOperationSelectAllOrCancel(); - break; - case R.id.current_path_pane: - onNavigationBarClick(); - break; - case R.id.button_moving_confirm: - onOperationButtonConfirm(); - break; - case R.id.button_moving_cancel: - onOperationButtonCancel(); - break; - case R.id.path_pane_up_level: - onOperationUpLevel(false); - ActionMode mode = ((FileExplorerTabActivity) mContext).getActionMode(); - if (mode != null) { - mode.finish(); - } - break; + case R.id.button_operation_copy: + onOperationCopy(); + break; + case R.id.button_operation_move: + onOperationMove(); + break; + case R.id.button_operation_send: + onOperationSend(); + break; + case R.id.button_operation_delete: + onOperationDelete(); + break; + case R.id.button_operation_cancel: + onOperationSelectAllOrCancel(); + break; + case R.id.current_path_pane: + onNavigationBarClick(); + break; + case R.id.button_moving_confirm: + onOperationButtonConfirm(); + break; + case R.id.button_moving_cancel: + onOperationButtonCancel(); + break; + case R.id.path_pane_up_level: + onOperationUpLevel(false); + ActionMode mode = ((FileExplorerTabActivity) mContext) + .getActionMode(); + if (mode != null) { + mode.finish(); + } + break; } } @@ -261,7 +268,8 @@ private void onOperationFavorite() { } private void onOperationSetting() { - Intent intent = new Intent(mContext, FileExplorerPreferenceActivity.class); + Intent intent = new Intent(mContext, + FileExplorerPreferenceActivity.class); if (intent != null) { try { mContext.startActivity(intent); @@ -272,7 +280,8 @@ private void onOperationSetting() { } private void onOperationFavorite(String path) { - FavoriteDatabaseHelper databaseHelper = FavoriteDatabaseHelper.getInstance(); + FavoriteDatabaseHelper databaseHelper = FavoriteDatabaseHelper + .getInstance(); if (databaseHelper != null) { int stringId = 0; if (databaseHelper.isFavorite(path)) { @@ -288,7 +297,8 @@ private void onOperationFavorite(String path) { } private void onOperationShowSysFiles() { - Settings.instance().setShowDotAndHiddenFiles(!Settings.instance().getShowDotAndHiddenFiles()); + Settings.instance().setShowDotAndHiddenFiles( + !Settings.instance().getShowDotAndHiddenFiles()); refreshFileList(); } @@ -309,28 +319,30 @@ public void onOperationSelectAll() { FileExplorerTabActivity fileExplorerTabActivity = (FileExplorerTabActivity) mContext; ActionMode mode = fileExplorerTabActivity.getActionMode(); if (mode == null) { - mode = fileExplorerTabActivity.startActionMode(new ModeCallback(mContext, this)); + mode = fileExplorerTabActivity.startActionMode(new ModeCallback( + mContext, this)); fileExplorerTabActivity.setActionMode(mode); - Util.updateActionModeTitle(mode, mContext, getSelectedFileList().size()); + Util.updateActionModeTitle(mode, mContext, getSelectedFileList() + .size()); } mFileViewListener.onDataChanged(); } - + public void jump2Folder(String path) { - if(mCurrentPath != path){//判断是否应该将当前路径添加到历史堆栈中 - mFolderHistroyStack.add(mCurrentPath.isEmpty() ? mRoot : mCurrentPath); + if (mCurrentPath != path) {// 判断是否应该将当前路径添加到历史堆栈中 + mFolderHistroyStack.add(mCurrentPath.isEmpty() ? mRoot + : mCurrentPath); } mCurrentPath = path; refreshFileList(); } - + /* - *返回上一个文件夹 - *当存在上一个浏览过的文件夹时返回true,当已经是最初浏览的文件夹时返回false - *(用以判断是否该退出) + * 返回上一个文件夹当存在上一个浏览过的文件夹时返回true,当已经是最初浏览的文件夹时返回false(用以判断是否该退出) */ - private boolean folderReturn(){ - if(mFolderHistroyStack.empty())return false; + private boolean folderReturn() { + if (mFolderHistroyStack.empty()) + return false; mCurrentPath = mFolderHistroyStack.pop(); refreshFileList(); return true; @@ -355,35 +367,41 @@ protected void onNavigationBarClick() { if (mDropdownNavigation.getVisibility() == View.VISIBLE) { showDropdownNavigation(false); } else { - LinearLayout list = (LinearLayout) mDropdownNavigation.findViewById(R.id.dropdown_navigation_list); + LinearLayout list = (LinearLayout) mDropdownNavigation + .findViewById(R.id.dropdown_navigation_list); list.removeAllViews(); int pos = 0; String displayPath = mFileViewListener.getDisplayPath(mCurrentPath); boolean root = true; int left = 0; - while (pos != -1 && !displayPath.equals("/")) {//如果当前位置在根文件夹则不显示导航条 + while (pos != -1 && !displayPath.equals("/")) {// 如果当前位置在根文件夹则不显示导航条 int end = displayPath.indexOf("/", pos); if (end == -1) break; - View listItem = LayoutInflater.from(mContext).inflate(R.layout.dropdown_item, - null); + View listItem = LayoutInflater.from(mContext).inflate( + R.layout.dropdown_item, null); View listContent = listItem.findViewById(R.id.list_item); listContent.setPadding(left, 0, 0, 0); left += 20; - ImageView img = (ImageView) listItem.findViewById(R.id.item_icon); + ImageView img = (ImageView) listItem + .findViewById(R.id.item_icon); - img.setImageResource(root ? R.drawable.dropdown_icon_root : R.drawable.dropdown_icon_folder); + img.setImageResource(root ? R.drawable.dropdown_icon_root + : R.drawable.dropdown_icon_folder); root = false; - TextView text = (TextView) listItem.findViewById(R.id.path_name); + TextView text = (TextView) listItem + .findViewById(R.id.path_name); String substring = displayPath.substring(pos, end); - if(substring.isEmpty())substring = "/"; + if (substring.isEmpty()) + substring = "/"; text.setText(substring); listItem.setOnClickListener(navigationClick); - listItem.setTag(mFileViewListener.getRealPath(displayPath.substring(0, end))); + listItem.setTag(mFileViewListener.getRealPath(displayPath + .substring(0, end))); pos = end + 1; list.addView(listItem); } @@ -400,26 +418,24 @@ public boolean onOperationUpLevel(boolean isreturn) { return true; } - /* - *在这里控制了按返回键回到上一级菜单的动作 - *下一步修改为真正的后退动作 - */ - if (isreturn) {//真正的后退动作 + if (isreturn) {// 真正的后退动作 return folderReturn(); - } else {//返回上一级文件夹 + } else {// 返回上一级文件夹 if (!mRoot.equals(mCurrentPath)) { jump2Folder(new File(mCurrentPath).getParent()); return true; } } - + return false; } public void onOperationCreateFolder() { - TextInputDialog dialog = new TextInputDialog(mContext, mContext.getString( - R.string.operation_create_folder), mContext.getString(R.string.operation_create_folder_message), - mContext.getString(R.string.new_folder_name), new OnFinishListener() { + TextInputDialog dialog = new TextInputDialog(mContext, + mContext.getString(R.string.operation_create_folder), + mContext.getString(R.string.operation_create_folder_message), + mContext.getString(R.string.new_folder_name), + new OnFinishListener() { @Override public boolean onFinish(String text) { return doCreateFolder(text); @@ -434,10 +450,13 @@ private boolean doCreateFolder(String text) { return false; if (mFileOperationHelper.CreateFolder(mCurrentPath, text)) { - mFileViewListener.addSingleFile(Util.GetFileInfo(Util.makePath(mCurrentPath, text))); + mFileViewListener.addSingleFile(Util.GetFileInfo(Util.makePath( + mCurrentPath, text))); mFileListView.setSelection(mFileListView.getCount() - 1); } else { - new AlertDialog.Builder(mContext).setMessage(mContext.getString(R.string.fail_to_create_folder)) + new AlertDialog.Builder(mContext) + .setMessage( + mContext.getString(R.string.fail_to_create_folder)) .setPositiveButton(R.string.confirm, null).create().show(); return false; } @@ -465,7 +484,8 @@ public void onOperationCopy(ArrayList files) { clearSelection(); showConfirmOperationBar(true); - View confirmButton = mConfirmOperationBar.findViewById(R.id.button_moving_confirm); + View confirmButton = mConfirmOperationBar + .findViewById(R.id.button_moving_confirm); confirmButton.setEnabled(false); // refresh to hide selected files refreshFileList(); @@ -479,8 +499,8 @@ public void onOperationCopyPath() { } private void copy(CharSequence text) { - ClipboardManager cm = (ClipboardManager) mContext.getSystemService( - Context.CLIPBOARD_SERVICE); + ClipboardManager cm = (ClipboardManager) mContext + .getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(text); } @@ -494,7 +514,8 @@ public void onOperationMove() { mFileOperationHelper.StartMove(getSelectedFileList()); clearSelection(); showConfirmOperationBar(true); - View confirmButton = mConfirmOperationBar.findViewById(R.id.button_moving_confirm); + View confirmButton = mConfirmOperationBar + .findViewById(R.id.button_moving_confirm); confirmButton.setEnabled(false); // refresh to hide selected files refreshFileList(); @@ -516,13 +537,15 @@ private void updateConfirmButtons() { if (mConfirmOperationBar.getVisibility() == View.GONE) return; - Button confirmButton = (Button) mConfirmOperationBar.findViewById(R.id.button_moving_confirm); + Button confirmButton = (Button) mConfirmOperationBar + .findViewById(R.id.button_moving_confirm); int text = R.string.operation_paste; if (isSelectingFiles()) { confirmButton.setEnabled(mCheckedFileNameList.size() != 0); text = R.string.operation_send; } else if (isMoveState()) { - confirmButton.setEnabled(mFileOperationHelper.canMove(mCurrentPath)); + confirmButton + .setEnabled(mFileOperationHelper.canMove(mCurrentPath)); } confirmButton.setText(text); @@ -530,20 +553,24 @@ private void updateConfirmButtons() { private void updateNavigationPane() { View upLevel = mFileViewListener.getViewById(R.id.path_pane_up_level); - upLevel.setVisibility(mRoot.equals(mCurrentPath) ? View.INVISIBLE : View.VISIBLE); + upLevel.setVisibility(mRoot.equals(mCurrentPath) ? View.INVISIBLE + : View.VISIBLE); View arrow = mFileViewListener.getViewById(R.id.path_pane_arrow); - arrow.setVisibility(mRoot.equals(mCurrentPath) ? View.GONE : View.VISIBLE); + arrow.setVisibility(mRoot.equals(mCurrentPath) ? View.GONE + : View.VISIBLE); - mNavigationBarText.setText(mFileViewListener.getDisplayPath(mCurrentPath)); + mNavigationBarText.setText(mFileViewListener + .getDisplayPath(mCurrentPath)); } public void onOperationSend() { ArrayList selectedFileList = getSelectedFileList(); for (FileInfo f : selectedFileList) { if (f.IsDir) { - AlertDialog dialog = new AlertDialog.Builder(mContext).setMessage( - R.string.error_info_cant_send_folder).setPositiveButton(R.string.confirm, null).create(); + AlertDialog dialog = new AlertDialog.Builder(mContext) + .setMessage(R.string.error_info_cant_send_folder) + .setPositiveButton(R.string.confirm, null).create(); dialog.show(); return; } @@ -571,8 +598,10 @@ public void onOperationRename() { final FileInfo f = getSelectedFileList().get(0); clearSelection(); - TextInputDialog dialog = new TextInputDialog(mContext, mContext.getString(R.string.operation_rename), - mContext.getString(R.string.operation_rename_message), f.fileName, new OnFinishListener() { + TextInputDialog dialog = new TextInputDialog(mContext, + mContext.getString(R.string.operation_rename), + mContext.getString(R.string.operation_rename_message), + f.fileName, new OnFinishListener() { @Override public boolean onFinish(String text) { return doRename(f, text); @@ -591,7 +620,8 @@ private boolean doRename(final FileInfo f, String text) { f.fileName = text; mFileViewListener.onDataChanged(); } else { - new AlertDialog.Builder(mContext).setMessage(mContext.getString(R.string.fail_to_rename)) + new AlertDialog.Builder(mContext) + .setMessage(mContext.getString(R.string.fail_to_rename)) .setPositiveButton(R.string.confirm, null).create().show(); return false; } @@ -606,9 +636,12 @@ private void notifyFileSystemChanged(String path) { final Intent intent; if (f.isDirectory()) { intent = new Intent(Intent.ACTION_MEDIA_MOUNTED); - intent.setClassName("com.android.providers.media", "com.android.providers.media.MediaScannerReceiver"); - intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory())); - Log.v(LOG_TAG, "directory changed, send broadcast:" + intent.toString()); + intent.setClassName("com.android.providers.media", + "com.android.providers.media.MediaScannerReceiver"); + intent.setData(Uri.fromFile(Environment + .getExternalStorageDirectory())); + Log.v(LOG_TAG, + "directory changed, send broadcast:" + intent.toString()); } else { intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setData(Uri.fromFile(new File(path))); @@ -632,22 +665,30 @@ public void onOperationDelete(int position) { } private void doOperationDelete(final ArrayList selectedFileList) { - final ArrayList selectedFiles = new ArrayList(selectedFileList); + final ArrayList selectedFiles = new ArrayList( + selectedFileList); Dialog dialog = new AlertDialog.Builder(mContext) - .setMessage(mContext.getString(R.string.operation_delete_confirm_message)) - .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - if (mFileOperationHelper.Delete(selectedFiles)) { - showProgress(mContext.getString(R.string.operation_deleting)); - } - clearSelection(); - } - }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - clearSelection(); - } - }).create(); + .setMessage( + mContext.getString(R.string.operation_delete_confirm_message)) + .setPositiveButton(R.string.confirm, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, + int whichButton) { + if (mFileOperationHelper.Delete(selectedFiles)) { + showProgress(mContext + .getString(R.string.operation_deleting)); + } + clearSelection(); + } + }) + .setNegativeButton(R.string.cancel, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int which) { + clearSelection(); + } + }).create(); dialog.show(); } @@ -659,8 +700,8 @@ public void onOperationInfo() { if (file == null) return; - InformationDialog dialog = new InformationDialog(mContext, file, mFileViewListener - .getFileIconHelper()); + InformationDialog dialog = new InformationDialog(mContext, file, + mFileViewListener.getFileIconHelper()); dialog.show(); clearSelection(); } @@ -698,7 +739,8 @@ public void onOperationButtonCancel() { // context menu private OnCreateContextMenuListener mListViewContextMenuListener = new OnCreateContextMenuListener() { @Override - public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { + public void onCreateContextMenu(ContextMenu menu, View v, + ContextMenuInfo menuInfo) { if (isInSelection() || isMoveState()) return; @@ -706,7 +748,8 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuIn AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; - FavoriteDatabaseHelper databaseHelper = FavoriteDatabaseHelper.getInstance(); + FavoriteDatabaseHelper databaseHelper = FavoriteDatabaseHelper + .getInstance(); FileInfo file = mFileViewListener.getItem(info.position); if (databaseHelper != null && file != null) { int stringId = databaseHelper.isFavorite(file.filePath) ? R.string.operation_unfavorite @@ -714,11 +757,14 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuIn addMenuItem(menu, GlobalConsts.MENU_FAVORITE, 0, stringId); } - addMenuItem(menu, GlobalConsts.MENU_COPY, 0, R.string.operation_copy); - addMenuItem(menu, GlobalConsts.MENU_COPY_PATH, 0, R.string.operation_copy_path); + addMenuItem(menu, GlobalConsts.MENU_COPY, 0, + R.string.operation_copy); + addMenuItem(menu, GlobalConsts.MENU_COPY_PATH, 0, + R.string.operation_copy_path); // addMenuItem(menu, GlobalConsts.MENU_PASTE, 0, // R.string.operation_paste); - addMenuItem(menu, GlobalConsts.MENU_MOVE, 0, R.string.operation_move); + addMenuItem(menu, GlobalConsts.MENU_MOVE, 0, + R.string.operation_move); addMenuItem(menu, MENU_SEND, 0, R.string.operation_send); addMenuItem(menu, MENU_RENAME, 0, R.string.operation_rename); addMenuItem(menu, MENU_DELETE, 0, R.string.operation_delete); @@ -738,12 +784,15 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuIn private int mListViewContextMenuSelectedItem; private void setupFileListView() { - mFileListView = (ListView) mFileViewListener.getViewById(R.id.file_path_list); + mFileListView = (ListView) mFileViewListener + .getViewById(R.id.file_path_list); mFileListView.setLongClickable(true); - mFileListView.setOnCreateContextMenuListener(mListViewContextMenuListener); + mFileListView + .setOnCreateContextMenuListener(mListViewContextMenuListener); mFileListView.setOnItemClickListener(new OnItemClickListener() { @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { + public void onItemClick(AdapterView parent, View view, + int position, long id) { onListItemClick(parent, view, position, id); } }); @@ -783,8 +832,10 @@ public void onItemClick(AdapterView parent, View view, int position, long id) @Override public boolean onMenuItemClick(MenuItem item) { - AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); - mListViewContextMenuSelectedItem = info != null ? info.position : -1; + AdapterContextMenuInfo info = (AdapterContextMenuInfo) item + .getMenuInfo(); + mListViewContextMenuSelectedItem = info != null ? info.position + : -1; int itemId = item.getItemId(); if (mFileViewListener.onOperation(itemId)) { @@ -794,74 +845,74 @@ public boolean onMenuItemClick(MenuItem item) { addContextMenuSelectedItem(); switch (itemId) { - case MENU_SEARCH: - onOperationSearch(); - break; - case GlobalConsts.MENU_NEW_FOLDER: - onOperationCreateFolder(); - break; - case MENU_REFRESH: - onOperationReferesh(); - break; - case MENU_SELECTALL: - onOperationSelectAllOrCancel(); - break; - case GlobalConsts.MENU_SHOWHIDE: - onOperationShowSysFiles(); - break; - case GlobalConsts.MENU_FAVORITE: - onOperationFavorite(); - break; - case MENU_SETTING: - onOperationSetting(); - break; - case MENU_EXIT: - ((FileExplorerTabActivity) mContext).finish(); - break; - // sort - case MENU_SORT_NAME: - item.setChecked(true); - onSortChanged(SortMethod.name); - break; - case MENU_SORT_SIZE: - item.setChecked(true); - onSortChanged(SortMethod.size); - break; - case MENU_SORT_DATE: - item.setChecked(true); - onSortChanged(SortMethod.date); - break; - case MENU_SORT_TYPE: - item.setChecked(true); - onSortChanged(SortMethod.type); - break; - - case GlobalConsts.MENU_COPY: - onOperationCopy(); - break; - case GlobalConsts.MENU_COPY_PATH: - onOperationCopyPath(); - break; - case GlobalConsts.MENU_PASTE: - onOperationPaste(); - break; - case GlobalConsts.MENU_MOVE: - onOperationMove(); - break; - case MENU_SEND: - onOperationSend(); - break; - case MENU_RENAME: - onOperationRename(); - break; - case MENU_DELETE: - onOperationDelete(); - break; - case MENU_INFO: - onOperationInfo(); - break; - default: - return false; + case MENU_SEARCH: + onOperationSearch(); + break; + case GlobalConsts.MENU_NEW_FOLDER: + onOperationCreateFolder(); + break; + case MENU_REFRESH: + onOperationReferesh(); + break; + case MENU_SELECTALL: + onOperationSelectAllOrCancel(); + break; + case GlobalConsts.MENU_SHOWHIDE: + onOperationShowSysFiles(); + break; + case GlobalConsts.MENU_FAVORITE: + onOperationFavorite(); + break; + case MENU_SETTING: + onOperationSetting(); + break; + case MENU_EXIT: + ((FileExplorerTabActivity) mContext).finish(); + break; + // sort + case MENU_SORT_NAME: + item.setChecked(true); + onSortChanged(SortMethod.name); + break; + case MENU_SORT_SIZE: + item.setChecked(true); + onSortChanged(SortMethod.size); + break; + case MENU_SORT_DATE: + item.setChecked(true); + onSortChanged(SortMethod.date); + break; + case MENU_SORT_TYPE: + item.setChecked(true); + onSortChanged(SortMethod.type); + break; + + case GlobalConsts.MENU_COPY: + onOperationCopy(); + break; + case GlobalConsts.MENU_COPY_PATH: + onOperationCopyPath(); + break; + case GlobalConsts.MENU_PASTE: + onOperationPaste(); + break; + case GlobalConsts.MENU_MOVE: + onOperationMove(); + break; + case MENU_SEND: + onOperationSend(); + break; + case MENU_RENAME: + onOperationRename(); + break; + case MENU_DELETE: + onOperationDelete(); + break; + case MENU_INFO: + onOperationInfo(); + break; + default: + return false; } mListViewContextMenuSelectedItem = -1; @@ -888,8 +939,8 @@ public boolean onCreateOptionsMenu(Menu menu) { addMenuItem(menu, MENU_SELECTALL, 0, R.string.operation_selectall, R.drawable.ic_menu_select_all); - SubMenu sortMenu = menu.addSubMenu(0, MENU_SORT, 1, R.string.menu_item_sort).setIcon( - R.drawable.ic_menu_sort); + SubMenu sortMenu = menu.addSubMenu(0, MENU_SORT, 1, + R.string.menu_item_sort).setIcon(R.drawable.ic_menu_sort); addMenuItem(sortMenu, MENU_SORT_NAME, 0, R.string.menu_item_sort_name); addMenuItem(sortMenu, MENU_SORT_SIZE, 1, R.string.menu_item_sort_size); addMenuItem(sortMenu, MENU_SORT_DATE, 2, R.string.menu_item_sort_date); @@ -899,16 +950,18 @@ public boolean onCreateOptionsMenu(Menu menu) { // addMenuItem(menu, GlobalConsts.MENU_PASTE, 2, // R.string.operation_paste); - addMenuItem(menu, GlobalConsts.MENU_NEW_FOLDER, 3, R.string.operation_create_folder, - R.drawable.ic_menu_new_folder); - addMenuItem(menu, GlobalConsts.MENU_FAVORITE, 4, R.string.operation_favorite, - R.drawable.ic_menu_delete_favorite); - addMenuItem(menu, GlobalConsts.MENU_SHOWHIDE, 5, R.string.operation_show_sys, - R.drawable.ic_menu_show_sys); + addMenuItem(menu, GlobalConsts.MENU_NEW_FOLDER, 3, + R.string.operation_create_folder, R.drawable.ic_menu_new_folder); + addMenuItem(menu, GlobalConsts.MENU_FAVORITE, 4, + R.string.operation_favorite, R.drawable.ic_menu_delete_favorite); + addMenuItem(menu, GlobalConsts.MENU_SHOWHIDE, 5, + R.string.operation_show_sys, R.drawable.ic_menu_show_sys); addMenuItem(menu, MENU_REFRESH, 6, R.string.operation_refresh, R.drawable.ic_menu_refresh); - addMenuItem(menu, MENU_SETTING, 7, R.string.menu_setting, drawable.ic_menu_preferences); - addMenuItem(menu, MENU_EXIT, 8, R.string.menu_exit, drawable.ic_menu_close_clear_cancel); + addMenuItem(menu, MENU_SETTING, 7, R.string.menu_setting, + drawable.ic_menu_preferences); + addMenuItem(menu, MENU_EXIT, 8, R.string.menu_exit, + drawable.ic_menu_close_clear_cancel); return true; } @@ -916,9 +969,11 @@ private void addMenuItem(Menu menu, int itemId, int order, int string) { addMenuItem(menu, itemId, order, string, -1); } - private void addMenuItem(Menu menu, int itemId, int order, int string, int iconRes) { + private void addMenuItem(Menu menu, int itemId, int order, int string, + int iconRes) { if (!mFileViewListener.shouldHideMenu(itemId)) { - MenuItem item = menu.add(0, itemId, order, string).setOnMenuItemClickListener(menuItemClick); + MenuItem item = menu.add(0, itemId, order, string) + .setOnMenuItemClickListener(menuItemClick); if (iconRes > 0) { item.setIcon(iconRes); } @@ -932,7 +987,8 @@ public boolean onPrepareOptionsMenu(Menu menu) { private void updateMenuItems(Menu menu) { menu.findItem(MENU_SELECTALL).setTitle( - isSelectedAll() ? R.string.operation_cancel_selectall : R.string.operation_selectall); + isSelectedAll() ? R.string.operation_cancel_selectall + : R.string.operation_selectall); menu.findItem(MENU_SELECTALL).setEnabled(mCurrentMode != Mode.Pick); MenuItem menuItem = menu.findItem(GlobalConsts.MENU_SHOWHIDE); @@ -941,7 +997,8 @@ private void updateMenuItems(Menu menu) { : R.string.operation_show_sys); } - FavoriteDatabaseHelper databaseHelper = FavoriteDatabaseHelper.getInstance(); + FavoriteDatabaseHelper databaseHelper = FavoriteDatabaseHelper + .getInstance(); if (databaseHelper != null) { MenuItem item = menu.findItem(GlobalConsts.MENU_FAVORITE); if (item != null) { @@ -964,7 +1021,8 @@ public Mode getMode() { return mCurrentMode; } - public void onListItemClick(AdapterView parent, View view, int position, long id) { + public void onListItemClick(AdapterView parent, View view, int position, + long id) { FileInfo lFileInfo = mFileViewListener.getItem(position); showDropdownNavigation(false); @@ -975,8 +1033,10 @@ public void onListItemClick(AdapterView parent, View view, int position, long if (isInSelection()) { boolean selected = lFileInfo.Selected; - ActionMode actionMode = ((FileExplorerTabActivity) mContext).getActionMode(); - ImageView checkBox = (ImageView) view.findViewById(R.id.file_checkbox); + ActionMode actionMode = ((FileExplorerTabActivity) mContext) + .getActionMode(); + ImageView checkBox = (ImageView) view + .findViewById(R.id.file_checkbox); if (selected) { mCheckedFileNameList.remove(lFileInfo); checkBox.setImageResource(R.drawable.btn_check_off_holo_light); @@ -985,12 +1045,15 @@ public void onListItemClick(AdapterView parent, View view, int position, long checkBox.setImageResource(R.drawable.btn_check_on_holo_light); } if (actionMode != null) { - if (mCheckedFileNameList.size() == 0) actionMode.finish(); - else actionMode.invalidate(); + if (mCheckedFileNameList.size() == 0) + actionMode.finish(); + else + actionMode.invalidate(); } lFileInfo.Selected = !selected; - Util.updateActionModeTitle(actionMode, mContext, mCheckedFileNameList.size()); + Util.updateActionModeTitle(actionMode, mContext, + mCheckedFileNameList.size()); return; } @@ -1004,7 +1067,8 @@ public void onListItemClick(AdapterView parent, View view, int position, long } jump2Folder(getAbsoluteName(mCurrentPath, lFileInfo.fileName)); - ActionMode actionMode = ((FileExplorerTabActivity) mContext).getActionMode(); + ActionMode actionMode = ((FileExplorerTabActivity) mContext) + .getActionMode(); if (actionMode != null) { actionMode.finish(); } @@ -1028,7 +1092,8 @@ public void setCurrentPath(String path) { } private String getAbsoluteName(String path, String name) { - return path.equals(GlobalConsts.ROOT_PATH) ? path + name : path + File.separator + name; + return path.equals(GlobalConsts.ROOT_PATH) ? path + name : path + + File.separator + name; } // check or uncheck @@ -1036,7 +1101,7 @@ public boolean onCheckItem(FileInfo f, View v) { if (isMoveState()) return false; - if(isSelectingFiles() && f.IsDir) + if (isSelectingFiles() && f.IsDir) return false; if (f.Selected) { @@ -1052,9 +1117,11 @@ private boolean isSelectingFiles() { } public boolean isSelectedAll() { - return mFileViewListener.getItemCount() != 0 && mCheckedFileNameList.size() == mFileViewListener.getItemCount(); + return mFileViewListener.getItemCount() != 0 + && mCheckedFileNameList.size() == mFileViewListener + .getItemCount(); } - + public boolean isSelected() { return mCheckedFileNameList.size() != 0; } @@ -1079,11 +1146,7 @@ private void viewFile(FileInfo lFileInfo) { Log.e(LOG_TAG, "fail to view file: " + e.toString()); } } - - /* - *在这里控制了按返回键回到上一级菜单的动作 - *下一步修改为真正的后退动作 - */ + public boolean onBackPressed() { if (mDropdownNavigation.getVisibility() == View.VISIBLE) { mDropdownNavigation.setVisibility(View.GONE); @@ -1109,9 +1172,9 @@ public void moveFileFrom(ArrayList files) { private void showDropdownNavigation(boolean show) { mDropdownNavigation.setVisibility(show ? View.VISIBLE : View.GONE); - mNavigationBarUpDownArrow - .setImageResource(mDropdownNavigation.getVisibility() == View.VISIBLE ? R.drawable.arrow_up - : R.drawable.arrow_down); + mNavigationBarUpDownArrow.setImageResource(mDropdownNavigation + .getVisibility() == View.VISIBLE ? R.drawable.arrow_up + : R.drawable.arrow_down); } @Override From e3bf1f04f09632a243e478f4d9e622e167e22710 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Mon, 4 Jun 2012 23:12:33 +0800 Subject: [PATCH 4/5] =?UTF-8?q?Fix=20some=20bugs=20due=20to=20not=20applyi?= =?UTF-8?q?ng=20setting=20changes=20immediately.=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=94=B1=E4=BA=8E=E6=B2=A1=E6=9C=89=E5=9C=A8=E6=94=B9=E5=8F=98?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=90=8E=E5=8F=8A=E6=97=B6=E5=8F=98=E6=9B=B4?= =?UTF-8?q?mRoot=E7=9A=84=E5=80=BC=E8=80=8C=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E6=96=87=E4=BB=B6=E5=A4=B9=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E5=8F=8A=E8=B7=B3=E8=BD=AC=E9=94=99=E8=AF=AF=E3=80=82=20?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E6=89=80=E6=9C=89=E7=9A=84=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E9=87=8D=E5=90=AF=E7=A8=8B=E5=BA=8F=E5=90=8E?= =?UTF-8?q?=E6=89=8D=E4=BC=9A=E7=94=9F=E6=95=88=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileExplorerPreferenceActivity.java | 76 +++++++++++++------ .../micode/fileexplorer/FileViewActivity.java | 6 +- .../fileexplorer/FileViewInteractionHub.java | 16 ++-- 3 files changed, 68 insertions(+), 30 deletions(-) diff --git a/src/net/micode/fileexplorer/FileExplorerPreferenceActivity.java b/src/net/micode/fileexplorer/FileExplorerPreferenceActivity.java index e2a3215..e7070a3 100644 --- a/src/net/micode/fileexplorer/FileExplorerPreferenceActivity.java +++ b/src/net/micode/fileexplorer/FileExplorerPreferenceActivity.java @@ -25,22 +25,25 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; +import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.PreferenceActivity; import android.preference.PreferenceManager; import android.text.TextUtils; /** - * + * * @author ShunLi */ -public class FileExplorerPreferenceActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener { +public class FileExplorerPreferenceActivity extends PreferenceActivity + implements OnSharedPreferenceChangeListener { private static final String PRIMARY_FOLDER = "pref_key_primary_folder"; private static final String READ_ROOT = "pref_key_read_root"; private static final String SHOW_REAL_PATH = "pref_key_show_real_path"; private static final String SYSTEM_SEPARATOR = File.separator; private EditTextPreference mEditTextPreference; + private CheckBoxPreference mCheckBoxPreferenceShowRealPath; @Override protected void onCreate(Bundle savedInstanceState) { @@ -48,6 +51,9 @@ protected void onCreate(Bundle savedInstanceState) { addPreferencesFromResource(R.xml.preferences); mEditTextPreference = (EditTextPreference) findPreference(PRIMARY_FOLDER); + mCheckBoxPreferenceShowRealPath = (CheckBoxPreference) findPreference(SHOW_REAL_PATH); + mCheckBoxPreferenceShowRealPath.setEnabled(getPreferenceScreen() + .getSharedPreferences().getBoolean(READ_ROOT, false)); } @Override @@ -55,11 +61,12 @@ protected void onResume() { super.onResume(); // Setup the initial values - SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences(); + SharedPreferences sharedPreferences = getPreferenceScreen() + .getSharedPreferences(); mEditTextPreference.setSummary(this.getString( - R.string.pref_primary_folder_summary, - sharedPreferences.getString(PRIMARY_FOLDER, GlobalConsts.ROOT_PATH))); + R.string.pref_primary_folder_summary, sharedPreferences + .getString(PRIMARY_FOLDER, GlobalConsts.ROOT_PATH))); // Set up a listener whenever a key changes sharedPreferences.registerOnSharedPreferenceChangeListener(this); @@ -70,30 +77,48 @@ protected void onPause() { super.onPause(); // Unregister the listener whenever a key changes - getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); + getPreferenceScreen().getSharedPreferences() + .unregisterOnSharedPreferenceChangeListener(this); } @Override - public void onSharedPreferenceChanged(SharedPreferences sharedpreferences, String key) { + public void onSharedPreferenceChanged(SharedPreferences sharedpreferences, + String key) { if (PRIMARY_FOLDER.equals(key)) { - mEditTextPreference.setSummary(this.getString( - R.string.pref_primary_folder_summary, - sharedpreferences.getString(PRIMARY_FOLDER, GlobalConsts.ROOT_PATH))); + mEditTextPreference + .setSummary(this.getString( + R.string.pref_primary_folder_summary, + sharedpreferences.getString(PRIMARY_FOLDER, + GlobalConsts.ROOT_PATH))); + } else if (READ_ROOT.equals(key)) { + // sharedpreferences.getBoolean(READ_ROOT, false) + mCheckBoxPreferenceShowRealPath.setEnabled(sharedpreferences + .getBoolean(READ_ROOT, false)); } } public static String getPrimaryFolder(Context context) { - SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); - String primaryFolder = settings.getString(PRIMARY_FOLDER, context.getString(R.string.default_primary_folder, GlobalConsts.ROOT_PATH)); - - if (TextUtils.isEmpty(primaryFolder)) { // setting primary folder = empty("") + SharedPreferences settings = PreferenceManager + .getDefaultSharedPreferences(context); + String primaryFolder = settings.getString(PRIMARY_FOLDER, context + .getString(R.string.default_primary_folder, + GlobalConsts.ROOT_PATH)); + + if (TextUtils.isEmpty(primaryFolder)) { // setting primary folder = + // empty("") primaryFolder = GlobalConsts.ROOT_PATH; } - // it's remove the end char of the home folder setting when it with the '/' at the end. - // if has the backslash at end of the home folder, it's has minor bug at "UpLevel" function. + // it's remove the end char of the home folder setting when it with the + // '/' at the end. + // if has the backslash at end of the home folder, it's has minor bug at + // "UpLevel" function. int length = primaryFolder.length(); - if (length > 1 && SYSTEM_SEPARATOR.equals(primaryFolder.substring(length - 1))) { // length = 1, ROOT_PATH + if (length > 1 + && SYSTEM_SEPARATOR.equals(primaryFolder.substring(length - 1))) { // length + // = + // 1, + // ROOT_PATH return primaryFolder.substring(0, length - 1); } else { return primaryFolder; @@ -101,17 +126,22 @@ public static String getPrimaryFolder(Context context) { } public static boolean isReadRoot(Context context) { - SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences settings = PreferenceManager + .getDefaultSharedPreferences(context); boolean isReadRootFromSetting = settings.getBoolean(READ_ROOT, false); - boolean isReadRootWhenSettingPrimaryFolderWithoutSdCardPrefix = !getPrimaryFolder(context).startsWith(Util.getSdDirectory()); + boolean isReadRootWhenSettingPrimaryFolderWithoutSdCardPrefix = !getPrimaryFolder( + context).startsWith(Util.getSdDirectory()); - return isReadRootFromSetting || isReadRootWhenSettingPrimaryFolderWithoutSdCardPrefix; + return isReadRootFromSetting + || isReadRootWhenSettingPrimaryFolderWithoutSdCardPrefix; } - + public static boolean showRealPath(Context context) { - SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); - return settings.getBoolean(SHOW_REAL_PATH, false); + SharedPreferences settings = PreferenceManager + .getDefaultSharedPreferences(context); + return settings.getBoolean(SHOW_REAL_PATH, false) + && isReadRoot(context); } } diff --git a/src/net/micode/fileexplorer/FileViewActivity.java b/src/net/micode/fileexplorer/FileViewActivity.java index b9c55af..cb48a4f 100644 --- a/src/net/micode/fileexplorer/FileViewActivity.java +++ b/src/net/micode/fileexplorer/FileViewActivity.java @@ -100,6 +100,7 @@ public void run() { }; private boolean mBackspaceExit; + private boolean mShowRealPath; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -166,6 +167,8 @@ public void onClick(View v) { mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, mFileNameList, mFileViewInteractionHub, mFileIconHelper); + mShowRealPath = FileExplorerPreferenceActivity.showRealPath(mActivity); + boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD, !FileExplorerPreferenceActivity.isReadRoot(mActivity)); Log.i(LOG_TAG, "baseSd = " + baseSd); @@ -407,8 +410,7 @@ public boolean onOperation(int id) { // 支持显示真实路径 @Override public String getDisplayPath(String path) { - if (path.startsWith(this.sdDir) - && !FileExplorerPreferenceActivity.showRealPath(mActivity)) { + if (path.startsWith(this.sdDir) && !mShowRealPath) { return getString(R.string.sd_folder) + path.substring(this.sdDir.length()); } else { diff --git a/src/net/micode/fileexplorer/FileViewInteractionHub.java b/src/net/micode/fileexplorer/FileViewInteractionHub.java index 7b1a04c..38d17ba 100644 --- a/src/net/micode/fileexplorer/FileViewInteractionHub.java +++ b/src/net/micode/fileexplorer/FileViewInteractionHub.java @@ -339,13 +339,19 @@ public void jump2Folder(String path) { /* * 返回上一个文件夹当存在上一个浏览过的文件夹时返回true,当已经是最初浏览的文件夹时返回false(用以判断是否该退出) + * 新增加了判断是否属于合法路径的判断,用以在变更设置时(是否浏览root目录等)自动过滤掉不该显示的目录 */ private boolean folderReturn() { - if (mFolderHistroyStack.empty()) - return false; - mCurrentPath = mFolderHistroyStack.pop(); - refreshFileList(); - return true; + String path = null; + while (!mFolderHistroyStack.empty()) { + path = mFolderHistroyStack.pop(); + if (path.startsWith(mRoot)) { + mCurrentPath = path; + refreshFileList(); + return true; + } + } + return false; } private OnClickListener navigationClick = new OnClickListener() { From ff65cb86f734dafc378b3bea93cc9f31ed16ec2f Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Mon, 4 Jun 2012 23:43:33 +0800 Subject: [PATCH 5/5] Fixed can't copy empty directory. --- src/net/micode/fileexplorer/FileOperationHelper.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/net/micode/fileexplorer/FileOperationHelper.java b/src/net/micode/fileexplorer/FileOperationHelper.java index 287e2fb..c40126a 100644 --- a/src/net/micode/fileexplorer/FileOperationHelper.java +++ b/src/net/micode/fileexplorer/FileOperationHelper.java @@ -264,6 +264,8 @@ private void CopyFile(FileInfo f, String dest) { destFile = new File(destPath); } + destFile.mkdirs();// 修复不能复制空文件夹的bug + for (File child : file.listFiles(mFilter)) { if (!child.isHidden() && Util.isNormalFile(child.getAbsolutePath())) { CopyFile(Util.GetFileInfo(child, mFilter, Settings.instance().getShowDotAndHiddenFiles()), destPath);