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 6770acf..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;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.nfc.NfcAdapter;
 import android.nfc.NfcEvent;
 import android.os.AsyncTask;
 import android.os.Bundle;
+import android.os.Environment;
 import android.os.Handler;
 import android.os.Parcelable;
 import android.os.storage.StorageVolume;
+import android.support.v4.app.ActionBarDrawerToggle;
+import android.support.v4.widget.DrawerLayout;
+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;
 import android.widget.ImageView;
 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;
@@ -96,10 +102,8 @@ import com.cyanogenmod.filemanager.ui.dialogs.ActionsDialog;
 import com.cyanogenmod.filemanager.ui.dialogs.FilesystemInfoDialog;
 import com.cyanogenmod.filemanager.ui.dialogs.InitialDirectoryDialog;
 import com.cyanogenmod.filemanager.ui.dialogs.FilesystemInfoDialog.OnMountListener;
-import com.cyanogenmod.filemanager.ui.widgets.ActionBarDrawerToggle;
 import com.cyanogenmod.filemanager.ui.widgets.Breadcrumb;
 import com.cyanogenmod.filemanager.ui.widgets.ButtonItem;
-import com.cyanogenmod.filemanager.ui.widgets.DrawerLayout;
 import com.cyanogenmod.filemanager.ui.widgets.NavigationCustomTitleView;
 import com.cyanogenmod.filemanager.ui.widgets.NavigationView;
 import com.cyanogenmod.filemanager.ui.widgets.NavigationView.OnNavigationRequestMenuListener;
@@ -112,14 +116,19 @@ import com.cyanogenmod.filemanager.util.DialogHelper;
 import com.cyanogenmod.filemanager.util.ExceptionUtil;
 import com.cyanogenmod.filemanager.util.ExceptionUtil.OnRelaunchCommandResult;
 import com.cyanogenmod.filemanager.util.FileHelper;
+import com.cyanogenmod.filemanager.util.MimeTypeHelper.MimeTypeCategory;
 import com.cyanogenmod.filemanager.util.StorageHelper;
 
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
+
+import static com.cyanogenmod.filemanager.util.MimeTypeHelper.MimeTypeCategory.*;
 
 /**
  * The main navigation activity. This activity is the center of the application.
@@ -145,6 +154,8 @@ public class NavigationActivity extends Activity
     private static final String TAG_BOOKMARKS = "Bookmarks"; //$NON-NLS-1$
     private static final String TAG_BOOKMARK = "bookmark"; //$NON-NLS-1$
 
+    private static final String STR_USB = "usb"; // $NON-NLS-1$
+
     /**
      * Intent code for request a search.
      */
@@ -184,6 +195,12 @@ public class NavigationActivity extends Activity
     // exit, and the toast is shown again after the first tap.
     private static final int RELEASE_EXIT_CHECK_TIMEOUT = 3500;
 
+
+    private Toolbar mToolBar;
+    private SearchView mSearchView;
+    private NavigationCustomTitleView mCustomTitleView;
+    private InputMethodManager mImm;
+
     private final BroadcastReceiver mNotificationReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
@@ -298,14 +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) {
+                        FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED) == 0 ||
+                            intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED) ||
+                            intent.getAction().equals(Intent.ACTION_MEDIA_UNMOUNTED)) {
                     onRequestBookmarksRefresh();
                     removeUnmountedHistory();
                     removeUnmountedSelection();
@@ -373,7 +393,7 @@ public class NavigationActivity extends Activity
         public void onClick(View v) {
             switch (v.getId()) {
                 case R.id.ab_settings:
-                    mDrawerLayout.closeDrawer(mDrawer);
+                    mDrawerLayout.closeDrawer(Gravity.START);
                     openSettings();
                     break;
                 case R.id.ab_clear_history:
@@ -386,12 +406,43 @@ public class NavigationActivity extends Activity
         }
     };
 
+    static String MIME_TYPE_LOCALIZED_NAMES[];
+    /**
+     * @hide
+     */
+    static Map<MimeTypeCategory, Drawable> EASY_MODE_ICONS = new
+            HashMap<MimeTypeCategory, Drawable>();
+
     /**
      * @hide
      */
     NavigationView[] mNavigationViews;
+    /**
+     * @hide
+     */
+    ListView mEasyModeListView;
     private List<History> mHistory;
 
+    private static final List<MimeTypeCategory> EASY_MODE_LIST = new ArrayList<MimeTypeCategory>() {
+        {
+            add(NONE);
+            add(IMAGE);
+            add(VIDEO);
+            add(AUDIO);
+            add(DOCUMENT);
+            add(APP);
+        }
+    };
+
+    private ArrayAdapter<MimeTypeCategory> mEasyModeAdapter;
+    private View.OnClickListener mEasyModeItemClickListener = new View.OnClickListener() {
+        @Override
+        public void onClick(View view) {
+            Integer position = (Integer) view.getTag();
+            onClicked(position);
+        }
+    };
+
     private int mCurrentNavigationView;
 
     private ViewGroup mActionBar;
@@ -412,15 +463,18 @@ public class NavigationActivity extends Activity
     private ButtonItem mClearHistory;
 
     private List<Bookmark> mBookmarks;
+    private List<Bookmark> mSdBookmarks;
     private LinearLayout mDrawerBookmarks;
 
     private boolean mExitFlag = false;
     private long mExitBackTimeout = -1;
 
-    private View mOptionsAnchorView;
+    private Dialog mActiveDialog = null;
 
     private int mOrientation;
 
+    private boolean mNeedsEasyMode = false;
+
     /**
      * @hide
      */
@@ -451,12 +505,24 @@ 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);
         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.setBaseTheme(this, false);
+        theme.setBaseThemeNoActionBar(this);
 
         //Set the main layout of the activity
         setContentView(R.layout.navigation);
@@ -492,6 +558,11 @@ public class NavigationActivity extends Activity
         //Navigation views
         initNavigationViews();
 
+        // As we're using a Toolbar, we should retrieve it and set it
+        // to be our ActionBar
+        mToolBar = (Toolbar) findViewById(R.id.material_toolbar);
+        setActionBar(mToolBar);
+
         //Initialize action bars
         initTitleActionBar();
         initStatusActionBar();
@@ -532,6 +603,22 @@ public class NavigationActivity extends Activity
             }
         });
 
+        MIME_TYPE_LOCALIZED_NAMES = MimeTypeCategory.getFriendlyLocalizedNames(NavigationActivity
+            .this);
+
+        EASY_MODE_ICONS.put(MimeTypeCategory.NONE, getResources().getDrawable(R.drawable
+                .ic_em_all));
+        EASY_MODE_ICONS.put(MimeTypeCategory.IMAGE, getResources().getDrawable(R.drawable
+                .ic_em_image));
+        EASY_MODE_ICONS.put(MimeTypeCategory.VIDEO, getResources().getDrawable(R.drawable
+                .ic_em_video));
+        EASY_MODE_ICONS.put(MimeTypeCategory.AUDIO, getResources().getDrawable(R.drawable
+                .ic_em_music));
+        EASY_MODE_ICONS.put(MimeTypeCategory.DOCUMENT, getResources().getDrawable(R.drawable
+                .ic_em_document));
+        EASY_MODE_ICONS.put(MimeTypeCategory.APP, getResources().getDrawable(R.drawable
+                .ic_em_application));
+
         //Save state
         super.onCreate(state);
     }
@@ -540,6 +627,10 @@ public class NavigationActivity extends Activity
     protected void onResume() {
         super.onResume();
 
+        if (mSearchView.getVisibility() == View.VISIBLE) {
+            closeSearch();
+        }
+
         // Check restrictions
         if (!FileManagerApplication.checkRestrictSecondaryUsersAccess(this, mChRooted)) {
             return;
@@ -550,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();
@@ -595,11 +687,36 @@ public class NavigationActivity extends Activity
      * {@inheritDoc}
      */
     @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        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);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     protected void onDestroy() {
         if (DEBUG) {
             Log.d(TAG, "NavigationActivity.onDestroy"); //$NON-NLS-1$
         }
 
+        if (mActiveDialog != null && mActiveDialog.isShowing()) {
+            mActiveDialog.dismiss();
+        }
+
         // Unregister the receiver
         try {
             unregisterReceiver(this.mNotificationReceiver);
@@ -607,6 +724,7 @@ public class NavigationActivity extends Activity
             /**NON BLOCK**/
         }
 
+        recycle();
         //All destroy. Continue
         super.onDestroy();
     }
@@ -649,12 +767,12 @@ public class NavigationActivity extends Activity
                 ((Boolean)FileManagerSettings.SETTINGS_FIRST_USE.getDefaultValue()).booleanValue());
 
         //Display the welcome message?
-        if (firstUse && FileManagerApplication.isDeviceRooted()) {
+        if (firstUse && FileManagerApplication.hasShellCommands()) {
             // open navigation drawer to show user that it exists
-            mDrawerLayout.openDrawer(mDrawer);
+            mDrawerLayout.openDrawer(Gravity.START);
 
             AlertDialog dialog = DialogHelper.createAlertDialog(this,
-                    R.drawable.ic_launcher, R.string.welcome_title,
+                    R.mipmap.ic_launcher_filemanager, R.string.welcome_title,
                     getString(R.string.welcome_msg), false);
             DialogHelper.delegateDialogShow(this, dialog);
 
@@ -670,8 +788,6 @@ public class NavigationActivity extends Activity
      * Method that initializes the titlebar of the activity.
      */
     private void initTitleActionBar() {
-        getActionBar().setTitle(R.string.app_name);
-
         //Inflate the view and associate breadcrumb
         View titleLayout = getLayoutInflater().inflate(
                 R.layout.navigation_view_customtitle, null, false);
@@ -696,10 +812,8 @@ public class NavigationActivity extends Activity
 
         //Configure the action bar options
         getActionBar().setBackgroundDrawable(
-                getResources().getDrawable(R.drawable.bg_holo_titlebar));
-        getActionBar().setDisplayOptions(
-                ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
-        getActionBar().setCustomView(titleLayout);
+                getResources().getDrawable(R.drawable.bg_material_titlebar));
+        mToolBar.addView(titleLayout);
     }
 
     /**
@@ -755,6 +869,8 @@ public class NavigationActivity extends Activity
      */
     private void initDrawer() {
         mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
+        //Set our status bar color
+        mDrawerLayout.setStatusBarBackgroundColor(R.color.material_palette_blue_primary_dark);
         mDrawer = (ViewGroup) findViewById(R.id.drawer);
         mDrawerBookmarks = (LinearLayout) findViewById(R.id.bookmarks_list);
         mDrawerHistory = (LinearLayout) findViewById(R.id.history_list);
@@ -781,44 +897,44 @@ public class NavigationActivity extends Activity
 
         // Set the navigation drawer "hamburger" icon
         mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
-                R.drawable.ic_holo_light_navigation_drawer,
+                R.drawable.ic_material_light_navigation_drawer,
                 R.string.drawer_open, R.string.drawer_close) {
 
             /** Called when a drawer has settled in a completely closed state. */
             public void onDrawerClosed(View view) {
                 super.onDrawerClosed(view);
-                getActionBar().setDisplayOptions(
-                        ActionBar.DISPLAY_SHOW_CUSTOM
-                                | ActionBar.DISPLAY_SHOW_HOME);
-                getActionBar().setDisplayHomeAsUpEnabled(true);
-                getActionBar().setHomeButtonEnabled(true);
             }
 
             /** Called when a drawer has settled in a completely open state. */
             public void onDrawerOpened(View drawerView) {
+                onDrawerLayoutOpened(drawerView);
                 super.onDrawerOpened(drawerView);
-                getActionBar().setDisplayOptions(
-                        ActionBar.DISPLAY_SHOW_TITLE
-                                | ActionBar.DISPLAY_SHOW_HOME);
-                getActionBar().setDisplayHomeAsUpEnabled(true);
-                getActionBar().setHomeButtonEnabled(true);
-
-                // change ActionBar title text color
-                Theme theme = ThemeManager
-                        .getCurrentTheme(NavigationActivity.this);
-                // get ActionBar title TextView id
-                int titleId = Resources.getSystem().getIdentifier(
-                        "action_bar_title", "id", "android");
-                TextView v = (TextView) findViewById(titleId);
-                theme.setTextColor(NavigationActivity.this, v, "text_color"); //$NON-NLS-1$
             }
         };
+        getActionBar().setDisplayHomeAsUpEnabled(true);
 
         // Set the drawer toggle as the DrawerListener
         mDrawerLayout.setDrawerListener(mDrawerToggle);
+    }
 
-        getActionBar().setDisplayHomeAsUpEnabled(true);
-        getActionBar().setHomeButtonEnabled(true);
+    /***
+     * 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);
+        }
     }
 
     /**
@@ -867,7 +983,7 @@ public class NavigationActivity extends Activity
                 final History history = mHistory.get(count - index - 1);
 
                 navigateToHistory(history);
-                mDrawerLayout.closeDrawer(mDrawer);
+                mDrawerLayout.closeDrawer(Gravity.START);
             }
         });
 
@@ -875,7 +991,7 @@ public class NavigationActivity extends Activity
         mDrawerHistory.addView(view, 0);
 
         // Show clear button if history tab is selected
-        mClearHistory.setVisibility(mHistoryTab.getVisibility());
+        mClearHistory.setVisibility(mHistoryTab.isSelected() ? View.VISIBLE : View.GONE);
     }
 
     /**
@@ -888,6 +1004,33 @@ public class NavigationActivity extends Activity
     }
 
     /**
+     * Show the easy mode view
+     */
+    private void performShowEasyMode() {
+        mEasyModeListView.setVisibility(View.VISIBLE);
+        getCurrentNavigationView().setVisibility(View.GONE);
+        performShowBackArrow(false);
+    }
+
+    /**
+     * Hide the easy mode view
+     */
+    private void performHideEasyMode() {
+        mEasyModeListView.setVisibility(View.GONE);
+        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
      */
@@ -918,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);
         }
@@ -980,13 +1123,22 @@ public class NavigationActivity extends Activity
                 final int index = mDrawerBookmarks.indexOfChild(v);
                 final Bookmark bookmark = mBookmarks.get(index);
 
+                boolean showEasyMode = (mSdBookmarks.contains(bookmark)) &&
+                        getResources().getBoolean(R.bool.cmcc_show_easy_mode);
+
                 // try to navigate to the bookmark path
                 try {
                     FileSystemObject fso = CommandHelper.getFileInfo(
                             getApplicationContext(), bookmark.mPath, null);
                     if (fso != null) {
+                        if (showEasyMode) {
+                            performShowEasyMode();
+                        } else {
+                            performHideEasyMode();
+                        }
+                        performShowBackArrow(!mDrawerToggle.isDrawerIndicatorEnabled());
                         getCurrentNavigationView().open(fso);
-                        mDrawerLayout.closeDrawer(mDrawer);
+                        mDrawerLayout.closeDrawer(Gravity.START);
                     }
                     else {
                         // The bookmark does not exist, delete the user-defined
@@ -1103,7 +1255,8 @@ public class NavigationActivity extends Activity
             bookmarks.add(loadHomeBookmarks());
             bookmarks.addAll(loadFilesystemBookmarks());
         }
-        bookmarks.addAll(loadSdStorageBookmarks());
+        mSdBookmarks = loadSdStorageBookmarks();
+        bookmarks.addAll(mSdBookmarks);
         bookmarks.addAll(loadVirtualBookmarks());
         bookmarks.addAll(loadUserBookmarks());
         return bookmarks;
@@ -1208,20 +1361,28 @@ public class NavigationActivity extends Activity
         try {
             // Recovery sdcards from storage manager
             StorageVolume[] volumes = StorageHelper
-                    .getStorageVolumes(getApplication());
-            int cc = volumes.length;
-            for (int i = 0; i < cc; i++) {
-                if (volumes[i].getPath().toLowerCase(Locale.ROOT)
-                        .indexOf("usb") != -1) { //$NON-NLS-1$
-                    bookmarks.add(new Bookmark(BOOKMARK_TYPE.USB, StorageHelper
-                            .getStorageVolumeDescription(getApplication(),
-                                    volumes[i]), volumes[i].getPath()));
-                }
-                else {
-                    bookmarks.add(new Bookmark(BOOKMARK_TYPE.SDCARD,
-                            StorageHelper.getStorageVolumeDescription(
-                                    getApplication(), volumes[i]), volumes[i]
-                                    .getPath()));
+                    .getStorageVolumes(getApplication(), true);
+            for (StorageVolume volume: volumes) {
+                if (volume != null) {
+                    String mountedState = volume.getState();
+                    String path = volume.getPath();
+                    if (!Environment.MEDIA_MOUNTED.equalsIgnoreCase(mountedState) &&
+                            !Environment.MEDIA_MOUNTED_READ_ONLY.equalsIgnoreCase(mountedState)) {
+                        Log.w(TAG, "Ignoring '" + path + "' with state of '"+ mountedState + "'");
+                        continue;
+                    }
+                    if (!TextUtils.isEmpty(path)) {
+                        String lowerPath = path.toLowerCase(Locale.ROOT);
+                        Bookmark bookmark;
+                        if (lowerPath.contains(STR_USB)) {
+                            bookmark = new Bookmark(BOOKMARK_TYPE.USB, StorageHelper
+                                    .getStorageVolumeDescription(getApplication(), volume), path);
+                        } else {
+                            bookmark = new Bookmark(BOOKMARK_TYPE.SDCARD, StorageHelper
+                                    .getStorageVolumeDescription(getApplication(), volume), path);
+                        }
+                        bookmarks.add(bookmark);
+                    }
                 }
             }
 
@@ -1317,6 +1478,58 @@ public class NavigationActivity extends Activity
         //- 0
         this.mNavigationViews[0] = (NavigationView)findViewById(R.id.navigation_view);
         this.mNavigationViews[0].setId(0);
+        this.mEasyModeListView = (ListView) findViewById(R.id.lv_easy_mode);
+        mEasyModeAdapter = new ArrayAdapter<MimeTypeCategory>(this, R.layout
+                .navigation_view_simple_item) {
+            @Override
+            public View getView(int position, View convertView, ViewGroup parent) {
+                convertView = (convertView == null) ?getLayoutInflater().inflate(R.layout
+                        .navigation_view_simple_item, parent, false) : convertView;
+                MimeTypeCategory item = getItem(position);
+                String typeTitle = MIME_TYPE_LOCALIZED_NAMES[item.ordinal()];
+                TextView typeTitleTV = (TextView) convertView
+                        .findViewById(R.id.navigation_view_item_name);
+                ImageView typeIconIV = (ImageView) convertView
+                        .findViewById(R.id.navigation_view_item_icon);
+                View checkBoxView = convertView.findViewById(R.id.navigation_view_item_check);
+                checkBoxView.setVisibility(View.GONE);
+                typeTitleTV.setText(typeTitle);
+                typeIconIV.setImageDrawable(EASY_MODE_ICONS.get(item));
+                convertView.setOnClickListener(mEasyModeItemClickListener);
+                convertView.setTag(position);
+                return convertView;
+            }
+        };
+        mEasyModeAdapter.addAll(EASY_MODE_LIST);
+        mEasyModeListView.setAdapter(mEasyModeAdapter);
+    }
+
+    private void onClicked(int position) {
+        Intent intent = new Intent(this, SearchActivity.class);
+        intent.setAction(Intent.ACTION_SEARCH);
+        intent.putExtra(SearchActivity.EXTRA_SEARCH_DIRECTORY,
+                getCurrentNavigationView().getCurrentDir());
+        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 {
+            ArrayList<MimeTypeCategory> searchCategories = new ArrayList<MimeTypeCategory>();
+            MimeTypeCategory selectedCategory = EASY_MODE_LIST.get(position);
+            searchCategories.add(selectedCategory);
+            // a one off case where we implicitly want to also search for TEXT mimetypes when the
+            // DOCUMENTS category is selected
+            if (selectedCategory == MimeTypeCategory.DOCUMENT) {
+                searchCategories.add(MimeTypeCategory.TEXT);
+            }
+            intent.putExtra(SearchActivity.EXTRA_SEARCH_MIMETYPE, searchCategories);
+        }
+
+        startActivity(intent);
     }
 
     /**
@@ -1390,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;
@@ -1407,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 {
@@ -1470,6 +1702,24 @@ public class NavigationActivity extends Activity
             }
         }
 
+        boolean needsEasyMode = false;
+        if (mSdBookmarks != null ) {
+            for (Bookmark bookmark :mSdBookmarks) {
+                if (bookmark.mPath.equalsIgnoreCase(initialDir)) {
+                    needsEasyMode = true;
+                    break;
+                }
+            }
+        }
+
+        mNeedsEasyMode = getResources().getBoolean(R.bool.cmcc_show_easy_mode);
+
+        needsEasyMode = needsEasyMode && mNeedsEasyMode;
+        if (needsEasyMode) {
+            performShowEasyMode();
+        } else {
+            performHideEasyMode();
+        }
         // Change the current directory to the user-defined initial directory
         navigationView.changeCurrentDir(initialDir, addToHistory);
     }
@@ -1535,18 +1785,36 @@ public class NavigationActivity extends Activity
     @Override
     public boolean onKeyUp(int keyCode, KeyEvent event) {
         if (keyCode == KeyEvent.KEYCODE_MENU) {
-            showOverflowPopUp(this.mOptionsAnchorView);
+            if (mDrawerLayout.isDrawerOpen(mDrawer)) {
+                mDrawerLayout.closeDrawer(Gravity.START);
+            } else {
+                mDrawerLayout.openDrawer(Gravity.START);
+            }
             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()) {
-                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();
     }
 
     /**
@@ -1562,8 +1830,6 @@ public class NavigationActivity extends Activity
             case R.id.ab_configuration:
                 //Show navigation view configuration toolbar
                 getCurrentNavigationView().getCustomTitle().showConfigurationView();
-                getActionBar().setDisplayHomeAsUpEnabled(true);
-                getActionBar().setHomeButtonEnabled(true);
                 break;
             case R.id.ab_close:
                 //Hide navigation view configuration toolbar
@@ -1629,11 +1895,8 @@ public class NavigationActivity extends Activity
                 break;
 
             case R.id.ab_search:
-                openSearch();
-                break;
 
-            case R.id.ab_overflow:
-                showOverflowPopUp(view);
+                openSearch();
                 break;
 
             default:
@@ -1667,6 +1930,7 @@ public class NavigationActivity extends Activity
                             if (fso != null) {
                                 //Goto to new directory
                                 getCurrentNavigationView().open(fso, searchInfo);
+                                performHideEasyMode();
                             }
                         }
                     } else if (resultCode == RESULT_CANCELED) {
@@ -1762,6 +2026,11 @@ public class NavigationActivity extends Activity
         // Ignored
     }
 
+    @Override
+    public void onCancel(){
+        // nop
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -1852,56 +2121,6 @@ public class NavigationActivity extends Activity
     }
 
     /**
-     * Method that shows a popup with the activity main menu.
-     *
-     * @param anchor The action button that was pressed
-     */
-    private void showOverflowPopUp(View anchor) {
-        SimpleMenuListAdapter adapter =
-                new HighlightedSimpleMenuListAdapter(this, R.menu.navigation);
-        Menu menu = adapter.getMenu();
-        int cc = this.mActionBar.getChildCount();
-        for (int i = 0, j = this.mActionBar.getChildCount() - 1; i < cc; i++, j--) {
-            View child = this.mActionBar.getChildAt(i);
-            boolean visible = child.getVisibility() == View.VISIBLE;
-            if (visible) {
-                menu.removeItem(menu.getItem(j).getItemId());
-            }
-        }
-
-        final ListPopupWindow popup = DialogHelper.createListPopupWindow(this, adapter, anchor);
-        popup.setOnItemClickListener(new OnItemClickListener() {
-            @Override
-            public void onItemClick(
-                    final AdapterView<?> parent, final View v, final int position, final long id) {
-
-                final int itemId = (int)id;
-                NavigationActivity.this.mHandler.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        popup.dismiss();
-                        switch (itemId) {
-                            case R.id.mnu_settings:
-                                //Settings
-                                openSettings();
-                                break;
-
-                            case R.id.mnu_search:
-                                //Search
-                                openSearch();
-                                popup.dismiss();
-                                break;
-                            default:
-                                break;
-                        }
-                    }
-                });
-            }
-        });
-        popup.show();
-    }
-
-    /**
      * Method that show the information of a filesystem mount point.
      *
      * @param mp The mount point info
@@ -1952,6 +2171,10 @@ public class NavigationActivity extends Activity
         // We need a basic structure to check this
         if (getCurrentNavigationView() == null) return false;
 
+        if (mSearchView.getVisibility() == View.VISIBLE) {
+            closeSearch();
+        }
+
         //Check if the configuration view is showing. In this case back
         //action must be "close configuration"
         if (getCurrentNavigationView().getCustomTitle().isConfigurationViewShowing()) {
@@ -1974,24 +2197,26 @@ 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
         return !this.mExitFlag;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
-    public boolean onSearchRequested() {
-        Bundle bundle = new Bundle();
-        bundle.putString(
-                SearchActivity.EXTRA_SEARCH_DIRECTORY,
-                getCurrentNavigationView().getCurrentDir());
-        startSearch(Preferences.getLastSearch(), true, bundle, false);
-        return true;
+    public void startActivity(Intent intent) {
+        // check if search intent
+        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
+            intent.putExtra(SearchActivity.EXTRA_SEARCH_DIRECTORY,
+                    getCurrentNavigationView().getCurrentDir());
+        }
+
+        super.startActivity(intent);
     }
 
     /**
@@ -2051,6 +2276,8 @@ public class NavigationActivity extends Activity
             }
 
             //Navigate
+            boolean clearHistory = mHistoryTab.isSelected() && mHistory.size() > 0;
+            mClearHistory.setVisibility(clearHistory ? View.VISIBLE : View.GONE);
             return true;
 
         } catch (Throwable ex) {
@@ -2105,13 +2332,13 @@ public class NavigationActivity extends Activity
             }
         }
 
-        //Extract a history from the
+        //Navigate to history
         if (this.mHistory.size() > 0) {
-            //Navigate to history
             return navigateToHistory(this.mHistory.get(this.mHistory.size() - 1));
         }
 
         //Nothing to apply
+        mClearHistory.setVisibility(View.GONE);
         return false;
     }
 
@@ -2161,12 +2388,20 @@ public class NavigationActivity extends Activity
     }
 
     /**
-     * Method that opens the search activity.
+     * Method that opens the search view.
      *
      * @hide
      */
     void openSearch() {
-        onSearchRequested();
+        mSearchView.setVisibility(View.VISIBLE);
+        mSearchView.onActionViewExpanded();
+        mCustomTitleView.setVisibility(View.GONE);
+    }
+
+    void closeSearch() {
+        mSearchView.setVisibility(View.GONE);
+        mSearchView.onActionViewCollapsed();
+        mCustomTitleView.setVisibility(View.VISIBLE);
     }
 
     /**
@@ -2307,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++) {
@@ -2322,7 +2561,6 @@ public class NavigationActivity extends Activity
         } catch (Throwable ex) {
             /**NON BLOCK**/
         }
-        finish();
     }
 
     /**
@@ -2330,7 +2568,7 @@ public class NavigationActivity extends Activity
      */
     private void onLayoutChanged() {
         Theme theme = ThemeManager.getCurrentTheme(this);
-        boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawer);
+        boolean drawerOpen = mDrawerLayout.isDrawerOpen(Gravity.START);
 
         // Apply only when the orientation was changed
         int orientation = getResources().getConfiguration().orientation;
@@ -2339,7 +2577,7 @@ public class NavigationActivity extends Activity
 
         // imitate a closed drawer while layout is rebuilt to avoid NullPointerException
         if (drawerOpen) {
-            mDrawerToggle.onDrawerClosed(mDrawer);
+            mDrawerLayout.closeDrawer(Gravity.START);
         }
 
         if (this.mOrientation == Configuration.ORIENTATION_LANDSCAPE) {
@@ -2452,13 +2690,13 @@ public class NavigationActivity extends Activity
     void applyTheme() {
         int orientation = getResources().getConfiguration().orientation;
         Theme theme = ThemeManager.getCurrentTheme(this);
-        theme.setBaseTheme(this, false);
+        theme.setBaseThemeNoActionBar(this);
         applyTabTheme();
 
         // imitate a closed drawer while layout is rebuilt to avoid NullPointerException
-        boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawer);
+        boolean drawerOpen = mDrawerLayout.isDrawerOpen(Gravity.START);
         if (drawerOpen) {
-            mDrawerToggle.onDrawerClosed(mDrawer);
+            mDrawerLayout.closeDrawer(Gravity.START);
         }
 
         //- Layout
@@ -2468,6 +2706,34 @@ public class NavigationActivity extends Activity
         //- ActionBar
         theme.setTitlebarDrawable(this, getActionBar(), "titlebar_drawable"); //$NON-NLS-1$
 
+        // Hackery to theme search view
+        mSearchView = (SearchView) findViewById(R.id.navigation_search_bar);
+        int searchPlateId = mSearchView.getContext().getResources()
+                .getIdentifier("android:id/search_plate", null, null);
+        View searchPlate = mSearchView.findViewById(searchPlateId);
+        if (searchPlate != null) {
+            int searchTextId = searchPlate.getContext().getResources()
+                    .getIdentifier("android:id/search_src_text", null, null);
+            TextView searchText = (TextView) searchPlate.findViewById(searchTextId);
+            if (searchText != null) {
+                searchText.setTextColor(Color.WHITE);
+                searchText.setHintTextColor(Color.WHITE);
+            }
+
+            int magId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
+            ImageView magImage = (ImageView) mSearchView.findViewById(magId);
+            if (magImage != null) {
+                magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
+            }
+        }
+
+        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
+        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
+        mSearchView.setIconifiedByDefault(false);
+
+        mCustomTitleView = (NavigationCustomTitleView) findViewById(R.id.navigation_title_flipper);
+        mCustomTitleView.setVisibility(View.VISIBLE);
+
         //- StatusBar
         v = findViewById(R.id.navigation_statusbar);
         if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
@@ -2505,7 +2771,6 @@ public class NavigationActivity extends Activity
         // - Navigation drawer
         v = findViewById(R.id.history_empty);
         theme.setTextColor(this, (TextView)v, "text_color"); //$NON-NLS-1$
-        mDrawerToggle.setDrawerImageResource(theme.getResourceId(this, "drawer_icon"));
 
         for (int i=0; i<mDrawerHistory.getChildCount(); i++) {
             View item = mDrawerHistory.getChildAt(i);
@@ -2549,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;
+    }
 }