OSDN Git Service

Changed NavigationView.refresh() in onResume() of the activity to try
[android-x86/packages-apps-CMFileManager.git] / src / com / cyanogenmod / filemanager / activities / NavigationActivity.java
old mode 100644 (file)
new mode 100755 (executable)
index 5754f27..93a18a3
 
 package com.cyanogenmod.filemanager.activities;
 
-import android.app.ActionBar;
 import android.app.Activity;
 import android.app.AlertDialog;
+import android.app.Dialog;
 import android.app.SearchManager;
 import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.res.Configuration;
-import android.content.res.Resources;
 import android.content.res.XmlResourceParser;
 import android.database.Cursor;
 import android.graphics.Color;
@@ -39,7 +39,6 @@ import android.os.Bundle;
 import android.os.Environment;
 import android.os.Handler;
 import android.os.Parcelable;
-import android.os.storage.StorageManager;
 import android.os.storage.StorageVolume;
 import android.support.v4.app.ActionBarDrawerToggle;
 import android.support.v4.widget.DrawerLayout;
@@ -47,12 +46,11 @@ import android.text.TextUtils;
 import android.util.Log;
 import android.view.Gravity;
 import android.view.KeyEvent;
-import android.view.Menu;
-import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
+import android.view.inputmethod.InputMethodManager;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.ImageButton;
@@ -61,20 +59,17 @@ import android.widget.LinearLayout;
 import android.widget.ListPopupWindow;
 import android.widget.ListView;
 import android.widget.PopupWindow;
-import android.widget.ScrollView;
 import android.widget.SearchView;
 import android.widget.TextView;
 import android.widget.Toast;
-
 import android.widget.Toolbar;
 import android.widget.ArrayAdapter;
+
 import com.android.internal.util.XmlUtils;
 import com.cyanogenmod.filemanager.FileManagerApplication;
 import com.cyanogenmod.filemanager.R;
 import com.cyanogenmod.filemanager.activities.preferences.SettingsPreferences;
-import com.cyanogenmod.filemanager.adapters.HighlightedSimpleMenuListAdapter;
 import com.cyanogenmod.filemanager.adapters.MenuSettingsAdapter;
-import com.cyanogenmod.filemanager.adapters.SimpleMenuListAdapter;
 import com.cyanogenmod.filemanager.console.Console;
 import com.cyanogenmod.filemanager.console.ConsoleAllocException;
 import com.cyanogenmod.filemanager.console.ConsoleBuilder;
@@ -204,6 +199,7 @@ public class NavigationActivity extends Activity
     private Toolbar mToolBar;
     private SearchView mSearchView;
     private NavigationCustomTitleView mCustomTitleView;
+    private InputMethodManager mImm;
 
     private final BroadcastReceiver mNotificationReceiver = new BroadcastReceiver() {
         @Override
@@ -319,18 +315,17 @@ public class NavigationActivity extends Activity
 
                 } else if (intent.getAction().compareTo(Intent.ACTION_TIME_CHANGED) == 0 ||
                            intent.getAction().compareTo(Intent.ACTION_DATE_CHANGED) == 0 ||
-                           intent.getAction().compareTo(Intent.ACTION_TIMEZONE_CHANGED) == 0) {
+                           intent.getAction().compareTo(Intent.ACTION_TIMEZONE_CHANGED) == 0 ||
+                           intent.getAction().compareTo(Intent.ACTION_LOCALE_CHANGED) == 0) {
                     // Refresh the data
                     synchronized (FileHelper.DATETIME_SYNC) {
                         FileHelper.sReloadDateTimeFormats = true;
                         NavigationActivity.this.getCurrentNavigationView().refresh();
                     }
                 } else if (intent.getAction().compareTo(
-                        FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED) == 0) {
-                    onRequestBookmarksRefresh();
-                    removeUnmountedHistory();
-                    removeUnmountedSelection();
-                } else if(intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED)) {
+                        FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED) == 0 ||
+                            intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED) ||
+                            intent.getAction().equals(Intent.ACTION_MEDIA_UNMOUNTED)) {
                     onRequestBookmarksRefresh();
                     removeUnmountedHistory();
                     removeUnmountedSelection();
@@ -474,8 +469,12 @@ public class NavigationActivity extends Activity
     private boolean mExitFlag = false;
     private long mExitBackTimeout = -1;
 
+    private Dialog mActiveDialog = null;
+
     private int mOrientation;
 
+    private boolean mNeedsEasyMode = false;
+
     /**
      * @hide
      */
@@ -506,10 +505,21 @@ public class NavigationActivity extends Activity
         filter.addAction(Intent.ACTION_DATE_CHANGED);
         filter.addAction(Intent.ACTION_TIME_CHANGED);
         filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
+        filter.addAction(Intent.ACTION_LOCALE_CHANGED);
         filter.addAction(FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED);
-        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
         registerReceiver(this.mNotificationReceiver, filter);
 
+        // This filter needs the file data scheme, so it must be defined separately.
+        IntentFilter newFilter = new IntentFilter();
+        newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
+        newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
+        newFilter.addDataScheme(ContentResolver.SCHEME_FILE);
+        registerReceiver(mNotificationReceiver, newFilter);
+
+        //the input manager service
+        mImm = (InputMethodManager) this.getSystemService(
+                Context.INPUT_METHOD_SERVICE);
+
         // Set the theme before setContentView
         Theme theme = ThemeManager.getCurrentTheme(this);
         theme.setBaseThemeNoActionBar(this);
@@ -631,6 +641,7 @@ public class NavigationActivity extends Activity
         if (curDir != null) {
             VirtualMountPointConsole vc = VirtualMountPointConsole.getVirtualConsoleForPath(
                     mNavigationViews[mCurrentNavigationView].getCurrentDir());
+            getCurrentNavigationView().refresh(true);
             if (vc != null && !vc.isMounted()) {
                 onRequestBookmarksRefresh();
                 removeUnmountedHistory();
@@ -680,6 +691,16 @@ public class NavigationActivity extends Activity
         if (mDrawerToggle.onOptionsItemSelected(item)) {
           return true;
         }
+
+        if (mNeedsEasyMode) {
+            if (item.getItemId() == android.R.id.home) {
+                if (mHistory.size() == 0 && !isEasyModeVisible()) {
+                    performShowEasyMode();
+                } else {
+                    back();
+                }
+            }
+        }
         return super.onOptionsItemSelected(item);
     }
 
@@ -692,6 +713,10 @@ public class NavigationActivity extends Activity
             Log.d(TAG, "NavigationActivity.onDestroy"); //$NON-NLS-1$
         }
 
+        if (mActiveDialog != null && mActiveDialog.isShowing()) {
+            mActiveDialog.dismiss();
+        }
+
         // Unregister the receiver
         try {
             unregisterReceiver(this.mNotificationReceiver);
@@ -699,6 +724,7 @@ public class NavigationActivity extends Activity
             /**NON BLOCK**/
         }
 
+        recycle();
         //All destroy. Continue
         super.onDestroy();
     }
@@ -881,14 +907,36 @@ public class NavigationActivity extends Activity
 
             /** Called when a drawer has settled in a completely open state. */
             public void onDrawerOpened(View drawerView) {
+                onDrawerLayoutOpened(drawerView);
                 super.onDrawerOpened(drawerView);
             }
         };
+        getActionBar().setDisplayHomeAsUpEnabled(true);
 
         // Set the drawer toggle as the DrawerListener
         mDrawerLayout.setDrawerListener(mDrawerToggle);
     }
 
+    /***
+     * Method that do something when the DrawerLayout opened.
+     */
+    private void onDrawerLayoutOpened(View drawerView){
+        if (mSearchView != null && mSearchView.getVisibility() == View.VISIBLE) {
+            closeSearch();
+            hideSoftInput(drawerView);
+        }
+    }
+
+    /**
+     * Method that hide the software when the software showing.
+     *
+     * */
+    private void hideSoftInput(View view){
+        if (mImm != null) {
+            mImm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+        }
+    }
+
     /**
      * Method that adds a history entry to the history list in the drawer
      */
@@ -961,6 +1009,7 @@ public class NavigationActivity extends Activity
     private void performShowEasyMode() {
         mEasyModeListView.setVisibility(View.VISIBLE);
         getCurrentNavigationView().setVisibility(View.GONE);
+        performShowBackArrow(false);
     }
 
     /**
@@ -971,6 +1020,16 @@ public class NavigationActivity extends Activity
         getCurrentNavigationView().setVisibility(View.VISIBLE);
     }
 
+    private void performShowBackArrow(boolean showBackArrow) {
+        if (mNeedsEasyMode) {
+            mDrawerToggle.setDrawerIndicatorEnabled(!showBackArrow);
+        }
+    }
+
+    private boolean isEasyModeVisible() {
+        return mEasyModeListView.getVisibility() != View.GONE;
+    }
+
     /**
      * Method takes a bookmark as argument and adds it to the bookmark list in
      * the drawer
@@ -1002,7 +1061,7 @@ public class NavigationActivity extends Activity
         Drawable action = null;
         String actionCd = null;
         if (bookmark.mType.compareTo(BOOKMARK_TYPE.HOME) == 0) {
-            action = iconholder.getDrawable("ic_config_drawable"); //$NON-NLS-1$
+            action = iconholder.getDrawable("ic_edit_home_bookmark_drawable"); //$NON-NLS-1$
             actionCd = getApplicationContext().getString(
                     R.string.bookmarks_button_config_cd);
         }
@@ -1077,6 +1136,7 @@ public class NavigationActivity extends Activity
                         } else {
                             performHideEasyMode();
                         }
+                        performShowBackArrow(!mDrawerToggle.isDrawerIndicatorEnabled());
                         getCurrentNavigationView().open(fso);
                         mDrawerLayout.closeDrawer(Gravity.START);
                     }
@@ -1301,7 +1361,7 @@ public class NavigationActivity extends Activity
         try {
             // Recovery sdcards from storage manager
             StorageVolume[] volumes = StorageHelper
-                    .getStorageVolumes(getApplication());
+                    .getStorageVolumes(getApplication(), true);
             for (StorageVolume volume: volumes) {
                 if (volume != null) {
                     String mountedState = volume.getState();
@@ -1452,7 +1512,9 @@ public class NavigationActivity extends Activity
         intent.putExtra(SearchManager.QUERY, "*"); // Use wild-card '*'
 
         if (position == 0) {
+            // the user has selected all items, they want to see their folders so let's do that.
             performHideEasyMode();
+            performShowBackArrow(true);
             return;
 
         } else {
@@ -1541,14 +1603,25 @@ public class NavigationActivity extends Activity
         // Check if request navigation to directory (use as default), and
         // ensure chrooted and absolute path
         String navigateTo = intent.getStringExtra(EXTRA_NAVIGATE_TO);
+        String intentAction = intent.getAction();
         if (navigateTo != null && navigateTo.length() > 0) {
             initialDir = navigateTo;
+        } else if (intentAction != null && intentAction.equals(Intent.ACTION_VIEW)) {
+            Uri data = intent.getData();
+            if (data != null && (FileHelper.FILE_URI_SCHEME.equals(data.getScheme())
+                    || FileHelper.FOLDER_URI_SCHEME.equals(data.getScheme())
+                    || FileHelper.DIRECTORY_URI_SCHEME.equals(data.getScheme()))) {
+                File path = new File(data.getPath());
+                if (path.isDirectory()) {
+                    initialDir = path.getAbsolutePath();
+                }
+            }
         }
 
         // Add to history
         final boolean addToHistory = intent.getBooleanExtra(EXTRA_ADD_TO_HISTORY, true);
 
-        // We cannot navigate to a secure console if is unmount, go to root in that case
+        // We cannot navigate to a secure console if it is unmounted. So go to root in that case
         VirtualConsole vc = VirtualMountPointConsole.getVirtualConsoleForPath(initialDir);
         if (vc != null && vc instanceof SecureConsole && !((SecureConsole) vc).isMounted()) {
             initialDir = FileHelper.ROOT_DIRECTORY;
@@ -1558,9 +1631,17 @@ public class NavigationActivity extends Activity
             // Initial directory is the first external sdcard (sdcard, emmc, usb, ...)
             if (!StorageHelper.isPathInStorageVolume(initialDir)) {
                 StorageVolume[] volumes =
-                        StorageHelper.getStorageVolumes(this);
+                        StorageHelper.getStorageVolumes(this, false);
                 if (volumes != null && volumes.length > 0) {
                     initialDir = volumes[0].getPath();
+                    int count = volumes.length;
+                    for (int i = 0; i < count; i++) {
+                        StorageVolume volume = volumes[i];
+                        if (Environment.MEDIA_MOUNTED.equalsIgnoreCase(volume.getState())) {
+                            initialDir = volume.getPath();
+                            break;
+                        }
+                    }
                     //Ensure that initial directory is an absolute directory
                     initialDir = FileHelper.getAbsPath(initialDir);
                 } else {
@@ -1622,15 +1703,18 @@ public class NavigationActivity extends Activity
         }
 
         boolean needsEasyMode = false;
-        for (Bookmark bookmark :mSdBookmarks) {
-            if (bookmark.mPath.equalsIgnoreCase(initialDir)) {
-                needsEasyMode = true;
-                break;
+        if (mSdBookmarks != null ) {
+            for (Bookmark bookmark :mSdBookmarks) {
+                if (bookmark.mPath.equalsIgnoreCase(initialDir)) {
+                    needsEasyMode = true;
+                    break;
+                }
             }
         }
 
-        needsEasyMode = needsEasyMode
-                && getResources().getBoolean(R.bool.cmcc_show_easy_mode);
+        mNeedsEasyMode = getResources().getBoolean(R.bool.cmcc_show_easy_mode);
+
+        needsEasyMode = needsEasyMode && mNeedsEasyMode;
         if (needsEasyMode) {
             performShowEasyMode();
         } else {
@@ -1708,16 +1792,29 @@ public class NavigationActivity extends Activity
             }
             return true;
         }
-        if (keyCode == KeyEvent.KEYCODE_BACK) {
+        return super.onKeyUp(keyCode, event);
+    }
+
+    @Override
+    public void onBackPressed() {
+        if (mDrawerLayout.isDrawerOpen(Gravity.START)) {
+            mDrawerLayout.closeDrawer(Gravity.START);
+            return;
+        }
+
+        boolean upToParent = mHistory.size() > 0;
+
+        if (mNeedsEasyMode && !isEasyModeVisible() && !upToParent) {
+            performShowEasyMode();
+            return;
+        } else {
             if (checkBackAction()) {
-                performHideEasyMode();
-                return true;
+                return;
             }
-
-            // An exit event has occurred, force the destroy the consoles
-            exit();
         }
-        return super.onKeyUp(keyCode, event);
+
+        // An exit event has occurred, force the destroy the consoles
+        exit();
     }
 
     /**
@@ -1929,6 +2026,11 @@ public class NavigationActivity extends Activity
         // Ignored
     }
 
+    @Override
+    public void onCancel(){
+        // nop
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -2095,7 +2197,11 @@ public class NavigationActivity extends Activity
             //Communicate the user that the next time the application will be closed
             this.mExitBackTimeout = System.currentTimeMillis();
             DialogHelper.showToast(this, R.string.msgs_push_again_to_exit, Toast.LENGTH_SHORT);
-            return true;
+            if (mNeedsEasyMode) {
+                return isEasyModeVisible();
+            } else {
+                return true;
+            }
         }
 
         //Back action not applied
@@ -2436,6 +2542,10 @@ public class NavigationActivity extends Activity
      * @hide
      */
     void exit() {
+        finish();
+    }
+
+    private void recycle() {
         // Recycle the navigation views
         int cc = this.mNavigationViews.length;
         for (int i = 0; i < cc; i++) {
@@ -2451,7 +2561,6 @@ public class NavigationActivity extends Activity
         } catch (Throwable ex) {
             /**NON BLOCK**/
         }
-        finish();
     }
 
     /**
@@ -2705,4 +2814,7 @@ public class NavigationActivity extends Activity
         theme.setImageDrawable(this, (ButtonItem) v, "ab_delete_drawable"); //$NON-NLS-1$
     }
 
+    public void updateActiveDialog(Dialog dialog) {
+        mActiveDialog = dialog;
+    }
 }