2 * Copyright (C) 2012 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.cyanogenmod.filemanager.activities;
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.app.Dialog;
22 import android.app.SearchManager;
23 import android.content.BroadcastReceiver;
24 import android.content.ContentResolver;
25 import android.content.Context;
26 import android.content.DialogInterface;
27 import android.content.Intent;
28 import android.content.IntentFilter;
29 import android.content.res.Configuration;
30 import android.content.res.XmlResourceParser;
31 import android.database.Cursor;
32 import android.graphics.Color;
33 import android.graphics.drawable.Drawable;
34 import android.net.Uri;
35 import android.nfc.NfcAdapter;
36 import android.nfc.NfcEvent;
37 import android.os.AsyncTask;
38 import android.os.Bundle;
39 import android.os.Environment;
40 import android.os.Handler;
41 import android.os.Parcelable;
42 import android.os.storage.StorageVolume;
43 import android.support.v4.app.ActionBarDrawerToggle;
44 import android.support.v4.widget.DrawerLayout;
45 import android.text.TextUtils;
46 import android.util.Log;
47 import android.view.Gravity;
48 import android.view.KeyEvent;
49 import android.view.MenuItem;
50 import android.view.View;
51 import android.view.View.OnClickListener;
52 import android.view.ViewGroup;
53 import android.widget.AdapterView;
54 import android.widget.AdapterView.OnItemClickListener;
55 import android.widget.ImageButton;
56 import android.widget.ImageView;
57 import android.widget.LinearLayout;
58 import android.widget.ListPopupWindow;
59 import android.widget.ListView;
60 import android.widget.PopupWindow;
61 import android.widget.SearchView;
62 import android.widget.TextView;
63 import android.widget.Toast;
64 import android.widget.Toolbar;
65 import android.widget.ArrayAdapter;
67 import com.android.internal.util.XmlUtils;
68 import com.cyanogenmod.filemanager.FileManagerApplication;
69 import com.cyanogenmod.filemanager.R;
70 import com.cyanogenmod.filemanager.activities.preferences.SettingsPreferences;
71 import com.cyanogenmod.filemanager.adapters.MenuSettingsAdapter;
72 import com.cyanogenmod.filemanager.console.Console;
73 import com.cyanogenmod.filemanager.console.ConsoleAllocException;
74 import com.cyanogenmod.filemanager.console.ConsoleBuilder;
75 import com.cyanogenmod.filemanager.console.InsufficientPermissionsException;
76 import com.cyanogenmod.filemanager.console.NoSuchFileOrDirectory;
77 import com.cyanogenmod.filemanager.console.VirtualConsole;
78 import com.cyanogenmod.filemanager.console.VirtualMountPointConsole;
79 import com.cyanogenmod.filemanager.console.secure.SecureConsole;
80 import com.cyanogenmod.filemanager.listeners.OnHistoryListener;
81 import com.cyanogenmod.filemanager.listeners.OnRequestRefreshListener;
82 import com.cyanogenmod.filemanager.model.Bookmark;
83 import com.cyanogenmod.filemanager.model.DiskUsage;
84 import com.cyanogenmod.filemanager.model.FileSystemObject;
85 import com.cyanogenmod.filemanager.model.History;
86 import com.cyanogenmod.filemanager.model.MountPoint;
87 import com.cyanogenmod.filemanager.model.Bookmark.BOOKMARK_TYPE;
88 import com.cyanogenmod.filemanager.parcelables.HistoryNavigable;
89 import com.cyanogenmod.filemanager.parcelables.NavigationViewInfoParcelable;
90 import com.cyanogenmod.filemanager.parcelables.SearchInfoParcelable;
91 import com.cyanogenmod.filemanager.preferences.AccessMode;
92 import com.cyanogenmod.filemanager.preferences.Bookmarks;
93 import com.cyanogenmod.filemanager.preferences.FileManagerSettings;
94 import com.cyanogenmod.filemanager.preferences.NavigationLayoutMode;
95 import com.cyanogenmod.filemanager.preferences.ObjectIdentifier;
96 import com.cyanogenmod.filemanager.preferences.Preferences;
97 import com.cyanogenmod.filemanager.ui.IconHolder;
98 import com.cyanogenmod.filemanager.ui.ThemeManager;
99 import com.cyanogenmod.filemanager.ui.ThemeManager.Theme;
100 import com.cyanogenmod.filemanager.ui.dialogs.ActionsDialog;
101 import com.cyanogenmod.filemanager.ui.dialogs.FilesystemInfoDialog;
102 import com.cyanogenmod.filemanager.ui.dialogs.InitialDirectoryDialog;
103 import com.cyanogenmod.filemanager.ui.dialogs.FilesystemInfoDialog.OnMountListener;
104 import com.cyanogenmod.filemanager.ui.widgets.Breadcrumb;
105 import com.cyanogenmod.filemanager.ui.widgets.ButtonItem;
106 import com.cyanogenmod.filemanager.ui.widgets.NavigationCustomTitleView;
107 import com.cyanogenmod.filemanager.ui.widgets.NavigationView;
108 import com.cyanogenmod.filemanager.ui.widgets.NavigationView.OnNavigationRequestMenuListener;
109 import com.cyanogenmod.filemanager.ui.widgets.NavigationView.OnNavigationSelectionChangedListener;
110 import com.cyanogenmod.filemanager.ui.widgets.SelectionView;
111 import com.cyanogenmod.filemanager.util.AndroidHelper;
112 import com.cyanogenmod.filemanager.util.BookmarksHelper;
113 import com.cyanogenmod.filemanager.util.CommandHelper;
114 import com.cyanogenmod.filemanager.util.DialogHelper;
115 import com.cyanogenmod.filemanager.util.ExceptionUtil;
116 import com.cyanogenmod.filemanager.util.ExceptionUtil.OnRelaunchCommandResult;
117 import com.cyanogenmod.filemanager.util.FileHelper;
118 import com.cyanogenmod.filemanager.util.MimeTypeHelper.MimeTypeCategory;
119 import com.cyanogenmod.filemanager.util.StorageHelper;
122 import java.io.FileNotFoundException;
123 import java.util.ArrayList;
124 import java.util.Arrays;
125 import java.util.HashMap;
126 import java.util.List;
127 import java.util.Locale;
128 import java.util.Map;
130 import static com.cyanogenmod.filemanager.util.MimeTypeHelper.MimeTypeCategory.*;
133 * The main navigation activity. This activity is the center of the application.
134 * From this the user can navigate, search, make actions.<br/>
135 * This activity is singleTop, so when it is displayed no other activities exists in
137 * This cause an issue with the saved instance of this class, because if another activity
138 * is displayed, and the process is killed, NavigationActivity is started and the saved
139 * instance gets corrupted.<br/>
140 * For this reason the methods {link {@link Activity#onSaveInstanceState(Bundle)} and
141 * {@link Activity#onRestoreInstanceState(Bundle)} are not implemented, and every time
142 * the app is killed, is restarted from his initial state.
144 public class NavigationActivity extends Activity
145 implements OnHistoryListener, OnRequestRefreshListener,
146 OnNavigationRequestMenuListener, OnNavigationSelectionChangedListener {
148 private static final String TAG = "NavigationActivity"; //$NON-NLS-1$
150 private static boolean DEBUG = false;
152 // Bookmark list XML tags
153 private static final String TAG_BOOKMARKS = "Bookmarks"; //$NON-NLS-1$
154 private static final String TAG_BOOKMARK = "bookmark"; //$NON-NLS-1$
156 private static final String STR_USB = "usb"; // $NON-NLS-1$
159 * Intent code for request a search.
161 public static final int INTENT_REQUEST_SEARCH = 10001;
164 * Intent code for request a search.
166 public static final int INTENT_REQUEST_SETTINGS = 20001;
169 * Constant for extra information about selected search entry.
171 public static final String EXTRA_SEARCH_ENTRY_SELECTION =
172 "extra_search_entry_selection"; //$NON-NLS-1$
175 * Constant for extra information about last search data.
177 public static final String EXTRA_SEARCH_LAST_SEARCH_DATA =
178 "extra_search_last_search_data"; //$NON-NLS-1$
181 * Constant for extra information for request a navigation to the passed path.
183 public static final String EXTRA_NAVIGATE_TO =
184 "extra_navigate_to"; //$NON-NLS-1$
187 * Constant for extra information for request to add navigation to the history
189 public static final String EXTRA_ADD_TO_HISTORY =
190 "extra_add_to_history"; //$NON-NLS-1$
192 // The timeout needed to reset the exit status for back button
193 // After this time user need to tap 2 times the back button to
194 // exit, and the toast is shown again after the first tap.
195 private static final int RELEASE_EXIT_CHECK_TIMEOUT = 3500;
198 private Toolbar mToolBar;
199 private SearchView mSearchView;
200 private NavigationCustomTitleView mCustomTitleView;
202 private final BroadcastReceiver mNotificationReceiver = new BroadcastReceiver() {
204 public void onReceive(Context context, Intent intent) {
205 if (intent != null) {
206 if (intent.getAction().compareTo(FileManagerSettings.INTENT_SETTING_CHANGED) == 0) {
207 // The settings has changed
208 String key = intent.getStringExtra(FileManagerSettings.EXTRA_SETTING_CHANGED_KEY);
210 // Disk usage warning level
211 if (key.compareTo(FileManagerSettings.
212 SETTINGS_DISK_USAGE_WARNING_LEVEL.getId()) == 0) {
214 // Set the free disk space warning level of the breadcrumb widget
215 Breadcrumb breadcrumb = getCurrentNavigationView().getBreadcrumb();
216 String fds = Preferences.getSharedPreferences().getString(
217 FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.getId(),
218 (String)FileManagerSettings.
219 SETTINGS_DISK_USAGE_WARNING_LEVEL.getDefaultValue());
220 breadcrumb.setFreeDiskSpaceWarningLevel(Integer.parseInt(fds));
221 breadcrumb.updateMountPointInfo();
225 // Case sensitive sort
226 if (key.compareTo(FileManagerSettings.
227 SETTINGS_CASE_SENSITIVE_SORT.getId()) == 0) {
228 getCurrentNavigationView().refresh();
233 if (key.compareTo(FileManagerSettings.
234 SETTINGS_DISPLAY_THUMBS.getId()) == 0) {
235 // Clean the icon cache applying the current theme
241 if (key.compareTo(FileManagerSettings.
242 SETTINGS_USE_FLINGER.getId()) == 0) {
244 Preferences.getSharedPreferences().getBoolean(
245 FileManagerSettings.SETTINGS_USE_FLINGER.getId(),
246 ((Boolean)FileManagerSettings.
247 SETTINGS_USE_FLINGER.
248 getDefaultValue()).booleanValue());
249 getCurrentNavigationView().setUseFlinger(useFlinger);
254 if (key.compareTo(FileManagerSettings.
255 SETTINGS_ACCESS_MODE.getId()) == 0) {
256 // Is it necessary to create or exit of the ChRooted?
258 FileManagerApplication.
259 getAccessMode().compareTo(AccessMode.SAFE) == 0;
260 if (chRooted != NavigationActivity.this.mChRooted) {
270 if (key.compareTo(FileManagerSettings.
271 SETTINGS_RESTRICT_SECONDARY_USERS_ACCESS.getId()) == 0) {
272 if (AndroidHelper.isSecondaryUser(context)) {
274 Preferences.savePreference(
275 FileManagerSettings.SETTINGS_ACCESS_MODE,
276 AccessMode.SAFE, true);
277 } catch (Throwable ex) {
278 Log.w(TAG, "can't save console preference", ex); //$NON-NLS-1$
280 ConsoleBuilder.changeToNonPrivilegedConsole(context);
285 // Filetime format mode
286 if (key.compareTo(FileManagerSettings.
287 SETTINGS_FILETIME_FORMAT_MODE.getId()) == 0) {
289 synchronized (FileHelper.DATETIME_SYNC) {
290 FileHelper.sReloadDateTimeFormats = true;
291 NavigationActivity.this.getCurrentNavigationView().refresh();
296 } else if (intent.getAction().compareTo(
297 FileManagerSettings.INTENT_FILE_CHANGED) == 0) {
298 // Retrieve the file that was changed
300 intent.getStringExtra(FileManagerSettings.EXTRA_FILE_CHANGED_KEY);
302 FileSystemObject fso = CommandHelper.getFileInfo(context, file, null);
304 getCurrentNavigationView().refresh(fso);
306 } catch (Exception e) {
307 ExceptionUtil.translateException(context, e, true, false);
310 } else if (intent.getAction().compareTo(
311 FileManagerSettings.INTENT_THEME_CHANGED) == 0) {
314 } else if (intent.getAction().compareTo(Intent.ACTION_TIME_CHANGED) == 0 ||
315 intent.getAction().compareTo(Intent.ACTION_DATE_CHANGED) == 0 ||
316 intent.getAction().compareTo(Intent.ACTION_TIMEZONE_CHANGED) == 0) {
318 synchronized (FileHelper.DATETIME_SYNC) {
319 FileHelper.sReloadDateTimeFormats = true;
320 NavigationActivity.this.getCurrentNavigationView().refresh();
322 } else if (intent.getAction().compareTo(
323 FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED) == 0 ||
324 intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED) ||
325 intent.getAction().equals(Intent.ACTION_MEDIA_UNMOUNTED)) {
326 onRequestBookmarksRefresh();
327 removeUnmountedHistory();
328 removeUnmountedSelection();
334 private OnClickListener mOnClickDrawerTabListener = new OnClickListener() {
336 public void onClick(View v) {
338 case R.id.drawer_bookmarks_tab:
339 if (!mBookmarksTab.isSelected()) {
340 mBookmarksTab.setSelected(true);
341 mHistoryTab.setSelected(false);
342 mBookmarksTab.setTextAppearance(
343 NavigationActivity.this, R.style.primary_text_appearance);
344 mHistoryTab.setTextAppearance(
345 NavigationActivity.this, R.style.secondary_text_appearance);
346 mHistoryLayout.setVisibility(View.GONE);
347 mBookmarksLayout.setVisibility(View.VISIBLE);
351 Preferences.savePreference(FileManagerSettings.USER_PREF_LAST_DRAWER_TAB,
352 Integer.valueOf(0), true);
353 } catch (Exception ex) {
354 Log.e(TAG, "Can't save last drawer tab", ex); //$NON-NLS-1$
357 mClearHistory.setVisibility(View.GONE);
360 case R.id.drawer_history_tab:
361 if (!mHistoryTab.isSelected()) {
362 mHistoryTab.setSelected(true);
363 mBookmarksTab.setSelected(false);
364 mHistoryTab.setTextAppearance(
365 NavigationActivity.this, R.style.primary_text_appearance);
366 mBookmarksTab.setTextAppearance(
367 NavigationActivity.this, R.style.secondary_text_appearance);
368 mBookmarksLayout.setVisibility(View.GONE);
369 mHistoryLayout.setVisibility(View.VISIBLE);
373 Preferences.savePreference(FileManagerSettings.USER_PREF_LAST_DRAWER_TAB,
374 Integer.valueOf(1), true);
375 } catch (Exception ex) {
376 Log.e(TAG, "Can't save last drawer tab", ex); //$NON-NLS-1$
379 mClearHistory.setVisibility(mHistory.size() > 0 ? View.VISIBLE : View.GONE);
388 private OnClickListener mOnClickDrawerActionBarListener = new OnClickListener() {
390 public void onClick(View v) {
392 case R.id.ab_settings:
393 mDrawerLayout.closeDrawer(Gravity.START);
396 case R.id.ab_clear_history:
398 mClearHistory.setVisibility(View.GONE);
406 static String MIME_TYPE_LOCALIZED_NAMES[];
410 static Map<MimeTypeCategory, Drawable> EASY_MODE_ICONS = new
411 HashMap<MimeTypeCategory, Drawable>();
416 NavigationView[] mNavigationViews;
420 ListView mEasyModeListView;
421 private List<History> mHistory;
423 private static final List<MimeTypeCategory> EASY_MODE_LIST = new ArrayList<MimeTypeCategory>() {
434 private ArrayAdapter<MimeTypeCategory> mEasyModeAdapter;
435 private View.OnClickListener mEasyModeItemClickListener = new View.OnClickListener() {
437 public void onClick(View view) {
438 Integer position = (Integer) view.getTag();
443 private int mCurrentNavigationView;
445 private ViewGroup mActionBar;
446 private SelectionView mSelectionBar;
448 private DrawerLayout mDrawerLayout;
449 private ViewGroup mDrawer;
450 private ActionBarDrawerToggle mDrawerToggle;
451 private LinearLayout mDrawerHistory;
452 private TextView mDrawerHistoryEmpty;
454 private TextView mBookmarksTab;
455 private TextView mHistoryTab;
456 private View mBookmarksLayout;
457 private View mHistoryLayout;
459 private ButtonItem mSettings;
460 private ButtonItem mClearHistory;
462 private List<Bookmark> mBookmarks;
463 private List<Bookmark> mSdBookmarks;
464 private LinearLayout mDrawerBookmarks;
466 private boolean mExitFlag = false;
467 private long mExitBackTimeout = -1;
469 private Dialog mActiveDialog = null;
471 private int mOrientation;
483 private AsyncTask<Void, Void, Boolean> mBookmarksTask;
489 protected void onCreate(Bundle state) {
492 Log.d(TAG, "NavigationActivity.onCreate"); //$NON-NLS-1$
495 // Register the broadcast receiver
496 IntentFilter filter = new IntentFilter();
497 filter.addAction(FileManagerSettings.INTENT_SETTING_CHANGED);
498 filter.addAction(FileManagerSettings.INTENT_FILE_CHANGED);
499 filter.addAction(FileManagerSettings.INTENT_THEME_CHANGED);
500 filter.addAction(Intent.ACTION_DATE_CHANGED);
501 filter.addAction(Intent.ACTION_TIME_CHANGED);
502 filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
503 filter.addAction(FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED);
504 registerReceiver(this.mNotificationReceiver, filter);
506 // This filter needs the file data scheme, so it must be defined separately.
507 IntentFilter newFilter = new IntentFilter();
508 newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
509 newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
510 newFilter.addDataScheme(ContentResolver.SCHEME_FILE);
511 registerReceiver(mNotificationReceiver, newFilter);
513 // Set the theme before setContentView
514 Theme theme = ThemeManager.getCurrentTheme(this);
515 theme.setBaseThemeNoActionBar(this);
517 //Set the main layout of the activity
518 setContentView(R.layout.navigation);
520 //Initialize nfc adapter
521 NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
522 if (mNfcAdapter != null) {
523 mNfcAdapter.setBeamPushUrisCallback(new NfcAdapter.CreateBeamUrisCallback() {
525 public Uri[] createBeamUris(NfcEvent event) {
526 List<FileSystemObject> selectedFiles =
527 getCurrentNavigationView().getSelectedFiles();
528 if (selectedFiles.size() > 0) {
529 List<Uri> fileUri = new ArrayList<Uri>();
530 for (FileSystemObject f : selectedFiles) {
531 //Beam ignores folders and system files
532 if (!FileHelper.isDirectory(f) && !FileHelper.isSystemFile(f)) {
533 fileUri.add(Uri.fromFile(new File(f.getFullPath())));
536 if (fileUri.size() > 0) {
537 return fileUri.toArray(new Uri[fileUri.size()]);
545 //Initialize activity
549 initNavigationViews();
551 // As we're using a Toolbar, we should retrieve it and set it
552 // to be our ActionBar
553 mToolBar = (Toolbar) findViewById(R.id.material_toolbar);
554 setActionBar(mToolBar);
556 //Initialize action bars
557 initTitleActionBar();
558 initStatusActionBar();
561 // Initialize navigation drawer
565 // Adjust layout (only when start on landscape mode)
566 int orientation = getResources().getConfiguration().orientation;
567 if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
570 this.mOrientation = orientation;
575 // Show welcome message
578 this.mHandler = new Handler();
579 this.mHandler.post(new Runnable() {
582 // Initialize console
585 //Initialize navigation
586 int cc = NavigationActivity.this.mNavigationViews.length;
587 for (int i = 0; i < cc; i++) {
588 initNavigation(i, false, getIntent());
591 //Check the intent action
592 checkIntent(getIntent());
596 MIME_TYPE_LOCALIZED_NAMES = MimeTypeCategory.getFriendlyLocalizedNames(NavigationActivity
599 EASY_MODE_ICONS.put(MimeTypeCategory.NONE, getResources().getDrawable(R.drawable
601 EASY_MODE_ICONS.put(MimeTypeCategory.IMAGE, getResources().getDrawable(R.drawable
603 EASY_MODE_ICONS.put(MimeTypeCategory.VIDEO, getResources().getDrawable(R.drawable
605 EASY_MODE_ICONS.put(MimeTypeCategory.AUDIO, getResources().getDrawable(R.drawable
607 EASY_MODE_ICONS.put(MimeTypeCategory.DOCUMENT, getResources().getDrawable(R.drawable
609 EASY_MODE_ICONS.put(MimeTypeCategory.APP, getResources().getDrawable(R.drawable
610 .ic_em_application));
613 super.onCreate(state);
617 protected void onResume() {
620 if (mSearchView.getVisibility() == View.VISIBLE) {
624 // Check restrictions
625 if (!FileManagerApplication.checkRestrictSecondaryUsersAccess(this, mChRooted)) {
629 // Check that the current dir is mounted (for virtual filesystems)
630 String curDir = mNavigationViews[mCurrentNavigationView].getCurrentDir();
631 if (curDir != null) {
632 VirtualMountPointConsole vc = VirtualMountPointConsole.getVirtualConsoleForPath(
633 mNavigationViews[mCurrentNavigationView].getCurrentDir());
634 if (vc != null && !vc.isMounted()) {
635 onRequestBookmarksRefresh();
636 removeUnmountedHistory();
637 removeUnmountedSelection();
639 Intent intent = new Intent();
640 intent.putExtra(EXTRA_ADD_TO_HISTORY, false);
641 initNavigation(NavigationActivity.this.mCurrentNavigationView, false, intent);
647 protected void onPostCreate(Bundle savedInstanceState) {
648 super.onPostCreate(savedInstanceState);
649 // Sync the toggle state after onRestoreInstanceState has occurred.
650 mDrawerToggle.syncState();
657 protected void onNewIntent(Intent intent) {
658 //Initialize navigation
659 initNavigation(this.mCurrentNavigationView, true, intent);
661 //Check the intent action
669 public void onConfigurationChanged(Configuration newConfig) {
670 super.onConfigurationChanged(newConfig);
672 mDrawerToggle.onConfigurationChanged(newConfig);
679 public boolean onOptionsItemSelected(MenuItem item) {
680 if (mDrawerToggle.onOptionsItemSelected(item)) {
683 return super.onOptionsItemSelected(item);
690 protected void onDestroy() {
692 Log.d(TAG, "NavigationActivity.onDestroy"); //$NON-NLS-1$
695 if (mActiveDialog != null && mActiveDialog.isShowing()) {
696 mActiveDialog.dismiss();
699 // Unregister the receiver
701 unregisterReceiver(this.mNotificationReceiver);
702 } catch (Throwable ex) {
706 //All destroy. Continue
711 * Method that returns the current navigation view.
713 * @return NavigationView The current navigation view
715 public NavigationView getCurrentNavigationView() {
716 return getNavigationView(this.mCurrentNavigationView);
720 * Method that returns the current navigation view.
722 * @param viewId The view to return
723 * @return NavigationView The current navigation view
725 public NavigationView getNavigationView(int viewId) {
726 if (this.mNavigationViews == null) return null;
727 return this.mNavigationViews[viewId];
731 * Method that initializes the activity.
733 private void init() {
734 this.mHistory = new ArrayList<History>();
735 this.mChRooted = FileManagerApplication.getAccessMode().compareTo(AccessMode.SAFE) == 0;
739 * Method that displays a welcome message the first time the user
740 * access the application
742 private void showWelcomeMsg() {
743 boolean firstUse = Preferences.getSharedPreferences().getBoolean(
744 FileManagerSettings.SETTINGS_FIRST_USE.getId(),
745 ((Boolean)FileManagerSettings.SETTINGS_FIRST_USE.getDefaultValue()).booleanValue());
747 //Display the welcome message?
748 if (firstUse && FileManagerApplication.hasShellCommands()) {
749 // open navigation drawer to show user that it exists
750 mDrawerLayout.openDrawer(Gravity.START);
752 AlertDialog dialog = DialogHelper.createAlertDialog(this,
753 R.mipmap.ic_launcher_filemanager, R.string.welcome_title,
754 getString(R.string.welcome_msg), false);
755 DialogHelper.delegateDialogShow(this, dialog);
757 // Don't display again this dialog
759 Preferences.savePreference(
760 FileManagerSettings.SETTINGS_FIRST_USE, Boolean.FALSE, true);
761 } catch (Exception e) {/**NON BLOCK**/}
766 * Method that initializes the titlebar of the activity.
768 private void initTitleActionBar() {
769 //Inflate the view and associate breadcrumb
770 View titleLayout = getLayoutInflater().inflate(
771 R.layout.navigation_view_customtitle, null, false);
772 NavigationCustomTitleView title =
773 (NavigationCustomTitleView)titleLayout.findViewById(R.id.navigation_title_flipper);
774 title.setOnHistoryListener(this);
775 Breadcrumb breadcrumb = (Breadcrumb)title.findViewById(R.id.breadcrumb_view);
776 int cc = this.mNavigationViews.length;
777 for (int i = 0; i < cc; i++) {
778 this.mNavigationViews[i].setBreadcrumb(breadcrumb);
779 this.mNavigationViews[i].setOnHistoryListener(this);
780 this.mNavigationViews[i].setOnNavigationSelectionChangedListener(this);
781 this.mNavigationViews[i].setOnNavigationOnRequestMenuListener(this);
782 this.mNavigationViews[i].setCustomTitle(title);
785 // Set the free disk space warning level of the breadcrumb widget
786 String fds = Preferences.getSharedPreferences().getString(
787 FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.getId(),
788 (String)FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.getDefaultValue());
789 breadcrumb.setFreeDiskSpaceWarningLevel(Integer.parseInt(fds));
791 //Configure the action bar options
792 getActionBar().setBackgroundDrawable(
793 getResources().getDrawable(R.drawable.bg_material_titlebar));
794 mToolBar.addView(titleLayout);
798 * Method that initializes the statusbar of the activity.
800 private void initStatusActionBar() {
801 //Performs a width calculation of buttons. Buttons exceeds the width
802 //of the action bar should be hidden
803 //This application not use android ActionBar because the application
804 //make uses of the title and bottom areas, and wants to force to show
805 //the overflow button (without care of physical buttons)
806 this.mActionBar = (ViewGroup)findViewById(R.id.navigation_actionbar);
807 this.mActionBar.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
809 public void onLayoutChange(
810 View v, int left, int top, int right, int bottom, int oldLeft,
811 int oldTop, int oldRight, int oldBottom) {
812 //Get the width of the action bar
813 int w = v.getMeasuredWidth();
815 //Wake through children calculation his dimensions
816 int bw = (int)getResources().getDimension(R.dimen.default_buttom_width);
818 final ViewGroup abView = ((ViewGroup)v);
819 int cc = abView.getChildCount();
820 for (int i = 0; i < cc; i++) {
821 View child = abView.getChildAt(i);
822 child.setVisibility(cw + bw > w ? View.INVISIBLE : View.VISIBLE);
828 // Have overflow menu? Actually no. There is only a search action, so just hide
830 View overflow = findViewById(R.id.ab_overflow);
831 overflow.setVisibility(View.GONE);
833 // Show the status bar
834 View statusBar = findViewById(R.id.navigation_statusbar_portrait_holder);
835 statusBar.setVisibility(View.VISIBLE);
839 * Method that initializes the selectionbar of the activity.
841 private void initSelectionBar() {
842 this.mSelectionBar = (SelectionView)findViewById(R.id.navigation_selectionbar);
846 * Method that initializes the navigation drawer of the activity.
848 private void initDrawer() {
849 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
850 //Set our status bar color
851 mDrawerLayout.setStatusBarBackgroundColor(R.color.material_palette_blue_primary_dark);
852 mDrawer = (ViewGroup) findViewById(R.id.drawer);
853 mDrawerBookmarks = (LinearLayout) findViewById(R.id.bookmarks_list);
854 mDrawerHistory = (LinearLayout) findViewById(R.id.history_list);
855 mDrawerHistoryEmpty = (TextView) findViewById(R.id.history_empty);
857 mBookmarksLayout = findViewById(R.id.drawer_bookmarks);
858 mHistoryLayout = findViewById(R.id.drawer_history);
859 mBookmarksTab = (TextView) findViewById(R.id.drawer_bookmarks_tab);
860 mHistoryTab = (TextView) findViewById(R.id.drawer_history_tab);
861 mBookmarksTab.setOnClickListener(mOnClickDrawerTabListener);
862 mHistoryTab.setOnClickListener(mOnClickDrawerTabListener);
864 mSettings = (ButtonItem) findViewById(R.id.ab_settings);
865 mSettings.setOnClickListener(mOnClickDrawerActionBarListener);
866 mClearHistory = (ButtonItem) findViewById(R.id.ab_clear_history);
867 mClearHistory.setOnClickListener(mOnClickDrawerActionBarListener);
869 // Restore the last tab pressed
870 Integer lastTab = Preferences.getSharedPreferences().getInt(
871 FileManagerSettings.USER_PREF_LAST_DRAWER_TAB.getId(),
872 (Integer) FileManagerSettings.USER_PREF_LAST_DRAWER_TAB
874 mOnClickDrawerTabListener.onClick(lastTab == 0 ? mBookmarksTab : mHistoryTab);
876 // Set the navigation drawer "hamburger" icon
877 mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
878 R.drawable.ic_material_light_navigation_drawer,
879 R.string.drawer_open, R.string.drawer_close) {
881 /** Called when a drawer has settled in a completely closed state. */
882 public void onDrawerClosed(View view) {
883 super.onDrawerClosed(view);
886 /** Called when a drawer has settled in a completely open state. */
887 public void onDrawerOpened(View drawerView) {
888 super.onDrawerOpened(drawerView);
891 getActionBar().setDisplayHomeAsUpEnabled(true);
893 // Set the drawer toggle as the DrawerListener
894 mDrawerLayout.setDrawerListener(mDrawerToggle);
898 * Method that adds a history entry to the history list in the drawer
900 private void addHistoryToDrawer(int index, HistoryNavigable navigable) {
901 // hide empty message
902 mDrawerHistoryEmpty.setVisibility(View.GONE);
904 Theme theme = ThemeManager.getCurrentTheme(this);
905 IconHolder iconholder = new IconHolder(this, false);
907 // inflate single bookmark layout item and fill it
908 LinearLayout view = (LinearLayout) getLayoutInflater().inflate(
909 R.layout.history_item, null);
911 ImageView iconView = (ImageView) view
912 .findViewById(R.id.history_item_icon);
913 TextView name = (TextView) view.findViewById(R.id.history_item_name);
914 TextView directory = (TextView) view
915 .findViewById(R.id.history_item_directory);
917 Drawable icon = iconholder.getDrawable("ic_fso_folder_drawable"); //$NON-NLS-1$
918 if (navigable instanceof SearchInfoParcelable) {
919 icon = iconholder.getDrawable("ic_history_search_drawable"); //$NON-NLS-1$
921 iconView.setImageDrawable(icon);
923 String title = navigable.getTitle();
924 if (title == null || title.trim().length() == 0) {
925 title = getString(R.string.root_directory_name);
929 directory.setText(navigable.getDescription());
931 theme.setTextColor(this, name, "text_color");
932 theme.setTextColor(this, directory, "text_color");
935 view.setOnClickListener(new OnClickListener() {
937 public void onClick(View v) {
938 final int index = mDrawerHistory.indexOfChild(v);
939 final int count = mDrawerHistory.getChildCount();
940 final History history = mHistory.get(count - index - 1);
942 navigateToHistory(history);
943 mDrawerLayout.closeDrawer(Gravity.START);
947 // add as first child
948 mDrawerHistory.addView(view, 0);
950 // Show clear button if history tab is selected
951 mClearHistory.setVisibility(mHistoryTab.isSelected() ? View.VISIBLE : View.GONE);
955 * Method takes a bookmark as argument and adds it to mBookmarks and the
958 public void addBookmark(Bookmark bookmark) {
959 mBookmarks.add(bookmark);
960 addBookmarkToDrawer(bookmark);
964 * Show the easy mode view
966 private void performShowEasyMode() {
967 mEasyModeListView.setVisibility(View.VISIBLE);
968 getCurrentNavigationView().setVisibility(View.GONE);
972 * Hide the easy mode view
974 private void performHideEasyMode() {
975 mEasyModeListView.setVisibility(View.GONE);
976 getCurrentNavigationView().setVisibility(View.VISIBLE);
980 * Method takes a bookmark as argument and adds it to the bookmark list in
983 private void addBookmarkToDrawer(Bookmark bookmark) {
984 Theme theme = ThemeManager.getCurrentTheme(this);
985 IconHolder iconholder = new IconHolder(this, false);
987 // inflate single bookmark layout item and fill it
988 LinearLayout view = (LinearLayout) getLayoutInflater().inflate(
989 R.layout.bookmarks_item, null);
991 ImageView icon = (ImageView) view
992 .findViewById(R.id.bookmarks_item_icon);
993 TextView name = (TextView) view.findViewById(R.id.bookmarks_item_name);
994 TextView path = (TextView) view.findViewById(R.id.bookmarks_item_path);
995 ImageButton actionButton = (ImageButton) view
996 .findViewById(R.id.bookmarks_item_action);
998 name.setText(bookmark.mName);
999 path.setText(bookmark.mPath);
1001 theme.setTextColor(this, name, "text_color");
1002 theme.setTextColor(this, path, "text_color");
1004 icon.setImageDrawable(iconholder.getDrawable(BookmarksHelper
1005 .getIcon(bookmark)));
1007 Drawable action = null;
1008 String actionCd = null;
1009 if (bookmark.mType.compareTo(BOOKMARK_TYPE.HOME) == 0) {
1010 action = iconholder.getDrawable("ic_edit_home_bookmark_drawable"); //$NON-NLS-1$
1011 actionCd = getApplicationContext().getString(
1012 R.string.bookmarks_button_config_cd);
1014 else if (bookmark.mType.compareTo(BOOKMARK_TYPE.USER_DEFINED) == 0) {
1015 action = iconholder.getDrawable("ic_close_drawable"); //$NON-NLS-1$
1016 actionCd = getApplicationContext().getString(
1017 R.string.bookmarks_button_remove_bookmark_cd);
1020 actionButton.setImageDrawable(action);
1021 actionButton.setVisibility(action != null ? View.VISIBLE : View.GONE);
1022 actionButton.setOnClickListener(new OnClickListener() {
1024 public void onClick(View view) {
1025 final View v = (View) view.getParent();
1026 final int index = mDrawerBookmarks.indexOfChild(v);
1027 final Bookmark bookmark = mBookmarks.get(index);
1030 if (bookmark.mType.compareTo(BOOKMARK_TYPE.HOME) == 0) {
1031 // Show a dialog for configure initial directory
1032 InitialDirectoryDialog dialog = new InitialDirectoryDialog(
1033 NavigationActivity.this);
1034 dialog.setOnValueChangedListener(new InitialDirectoryDialog.OnValueChangedListener() {
1036 public void onValueChanged(String newInitialDir) {
1037 bookmark.mPath = newInitialDir;
1039 // reset drawer bookmarks list
1048 if (bookmark.mType.compareTo(BOOKMARK_TYPE.USER_DEFINED) == 0) {
1049 boolean result = Bookmarks.removeBookmark(
1050 getApplicationContext(), bookmark);
1051 if (!result) { // Show warning
1052 DialogHelper.showToast(getApplicationContext(),
1053 R.string.msgs_operation_failure,
1054 Toast.LENGTH_SHORT);
1057 mBookmarks.remove(bookmark);
1058 mDrawerBookmarks.removeView(v);
1063 actionButton.setContentDescription(actionCd);
1065 // handle item click
1066 view.setOnClickListener(new OnClickListener() {
1068 public void onClick(View v) {
1069 final int index = mDrawerBookmarks.indexOfChild(v);
1070 final Bookmark bookmark = mBookmarks.get(index);
1072 boolean showEasyMode = (mSdBookmarks.contains(bookmark)) &&
1073 getResources().getBoolean(R.bool.cmcc_show_easy_mode);
1075 // try to navigate to the bookmark path
1077 FileSystemObject fso = CommandHelper.getFileInfo(
1078 getApplicationContext(), bookmark.mPath, null);
1081 performShowEasyMode();
1083 performHideEasyMode();
1085 getCurrentNavigationView().open(fso);
1086 mDrawerLayout.closeDrawer(Gravity.START);
1089 // The bookmark does not exist, delete the user-defined
1092 Bookmarks.removeBookmark(getApplicationContext(),
1095 // reset bookmarks list to default
1098 catch (Exception ex) {
1102 catch (Exception e) { // Capture the exception
1104 .translateException(NavigationActivity.this, e);
1105 if (e instanceof NoSuchFileOrDirectory
1106 || e instanceof FileNotFoundException) {
1107 // The bookmark does not exist, delete the user-defined
1110 Bookmarks.removeBookmark(getApplicationContext(),
1113 // reset bookmarks list to default
1116 catch (Exception ex) {
1124 mDrawerBookmarks.addView(view);
1128 * Method that initializes the bookmarks.
1130 private synchronized void initBookmarks() {
1131 if (mBookmarksTask != null &&
1132 !mBookmarksTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
1136 // Retrieve the loading view
1137 final View waiting = findViewById(R.id.bookmarks_loading);
1139 // Load bookmarks in background
1140 mBookmarksTask = new AsyncTask<Void, Void, Boolean>() {
1144 protected Boolean doInBackground(Void... params) {
1146 mBookmarks = loadBookmarks();
1147 return Boolean.TRUE;
1150 catch (Exception e) {
1152 return Boolean.FALSE;
1157 protected void onPreExecute() {
1158 waiting.setVisibility(View.VISIBLE);
1159 mDrawerBookmarks.removeAllViews();
1163 protected void onPostExecute(Boolean result) {
1164 waiting.setVisibility(View.GONE);
1165 if (result.booleanValue()) {
1166 for (Bookmark bookmark : mBookmarks) {
1167 addBookmarkToDrawer(bookmark);
1171 if (this.mCause != null) {
1172 ExceptionUtil.translateException(
1173 NavigationActivity.this, this.mCause);
1176 mBookmarksTask = null;
1180 protected void onCancelled() {
1181 waiting.setVisibility(View.GONE);
1182 mBookmarksTask = null;
1185 mBookmarksTask.execute();
1189 * Method that loads all kind of bookmarks and join in an array to be used
1190 * in the listview adapter.
1192 * @return List<Bookmark>
1195 List<Bookmark> loadBookmarks() {
1196 // Bookmarks = HOME + FILESYSTEM + SD STORAGES + USER DEFINED
1197 // In ChRooted mode = SD STORAGES + USER DEFINED (from SD STORAGES)
1198 List<Bookmark> bookmarks = new ArrayList<Bookmark>();
1199 if (!this.mChRooted) {
1200 bookmarks.add(loadHomeBookmarks());
1201 bookmarks.addAll(loadFilesystemBookmarks());
1203 mSdBookmarks = loadSdStorageBookmarks();
1204 bookmarks.addAll(mSdBookmarks);
1205 bookmarks.addAll(loadVirtualBookmarks());
1206 bookmarks.addAll(loadUserBookmarks());
1211 * Method that loads the home bookmark from the user preference.
1213 * @return Bookmark The bookmark loaded
1215 private Bookmark loadHomeBookmarks() {
1216 String initialDir = Preferences.getSharedPreferences().getString(
1217 FileManagerSettings.SETTINGS_INITIAL_DIR.getId(),
1218 (String) FileManagerSettings.SETTINGS_INITIAL_DIR
1219 .getDefaultValue());
1220 return new Bookmark(BOOKMARK_TYPE.HOME,
1221 getString(R.string.bookmarks_home), initialDir);
1225 * Method that loads the filesystem bookmarks from the internal xml file.
1226 * (defined by this application)
1228 * @return List<Bookmark> The bookmarks loaded
1230 private List<Bookmark> loadFilesystemBookmarks() {
1232 // Initialize the bookmarks
1233 List<Bookmark> bookmarks = new ArrayList<Bookmark>();
1235 // Read the command list xml file
1236 XmlResourceParser parser = getResources().getXml(
1237 R.xml.filesystem_bookmarks);
1240 // Find the root element
1241 XmlUtils.beginDocument(parser, TAG_BOOKMARKS);
1243 XmlUtils.nextElement(parser);
1244 String element = parser.getName();
1245 if (element == null) {
1249 if (TAG_BOOKMARK.equals(element)) {
1250 CharSequence name = null;
1251 CharSequence directory = null;
1254 name = getString(parser.getAttributeResourceValue(
1255 R.styleable.Bookmark_name, 0));
1257 catch (Exception e) {
1261 directory = getString(parser
1262 .getAttributeResourceValue(
1263 R.styleable.Bookmark_directory, 0));
1265 catch (Exception e) {
1268 if (directory == null) {
1270 .getAttributeValue(R.styleable.Bookmark_directory);
1272 if (name != null && directory != null) {
1273 bookmarks.add(new Bookmark(
1274 BOOKMARK_TYPE.FILESYSTEM, name.toString(),
1275 directory.toString()));
1280 // Return the bookmarks
1288 catch (Throwable ex) {
1289 Log.e(TAG, "Load filesystem bookmarks failed", ex); //$NON-NLS-1$
1293 return new ArrayList<Bookmark>();
1297 * Method that loads the secure digital card storage bookmarks from the
1300 * @return List<Bookmark> The bookmarks loaded
1302 private List<Bookmark> loadSdStorageBookmarks() {
1303 // Initialize the bookmarks
1304 List<Bookmark> bookmarks = new ArrayList<Bookmark>();
1307 // Recovery sdcards from storage manager
1308 StorageVolume[] volumes = StorageHelper
1309 .getStorageVolumes(getApplication(), true);
1310 for (StorageVolume volume: volumes) {
1311 if (volume != null) {
1312 String mountedState = volume.getState();
1313 String path = volume.getPath();
1314 if (!Environment.MEDIA_MOUNTED.equalsIgnoreCase(mountedState) &&
1315 !Environment.MEDIA_MOUNTED_READ_ONLY.equalsIgnoreCase(mountedState)) {
1316 Log.w(TAG, "Ignoring '" + path + "' with state of '"+ mountedState + "'");
1319 if (!TextUtils.isEmpty(path)) {
1320 String lowerPath = path.toLowerCase(Locale.ROOT);
1322 if (lowerPath.contains(STR_USB)) {
1323 bookmark = new Bookmark(BOOKMARK_TYPE.USB, StorageHelper
1324 .getStorageVolumeDescription(getApplication(), volume), path);
1326 bookmark = new Bookmark(BOOKMARK_TYPE.SDCARD, StorageHelper
1327 .getStorageVolumeDescription(getApplication(), volume), path);
1329 bookmarks.add(bookmark);
1334 // Return the bookmarks
1337 catch (Throwable ex) {
1338 Log.e(TAG, "Load filesystem bookmarks failed", ex); //$NON-NLS-1$
1342 return new ArrayList<Bookmark>();
1346 * Method that loads all virtual mount points.
1348 * @return List<Bookmark> The bookmarks loaded
1350 private List<Bookmark> loadVirtualBookmarks() {
1351 // Initialize the bookmarks
1352 List<Bookmark> bookmarks = new ArrayList<Bookmark>();
1353 List<MountPoint> mps = VirtualMountPointConsole.getVirtualMountPoints();
1354 for (MountPoint mp : mps) {
1355 BOOKMARK_TYPE type = null;
1357 if (mp.isSecure()) {
1358 type = BOOKMARK_TYPE.SECURE;
1359 name = getString(R.string.bookmarks_secure);
1360 } else if (mp.isRemote()) {
1361 type = BOOKMARK_TYPE.REMOTE;
1362 name = getString(R.string.bookmarks_remote);
1366 bookmarks.add(new Bookmark(type, name, mp.getMountPoint()));
1372 * Method that loads the user bookmarks (added by the user).
1374 * @return List<Bookmark> The bookmarks loaded
1376 private List<Bookmark> loadUserBookmarks() {
1377 List<Bookmark> bookmarks = new ArrayList<Bookmark>();
1378 Cursor cursor = Bookmarks.getAllBookmarks(this.getContentResolver());
1380 if (cursor != null && cursor.moveToFirst()) {
1382 Bookmark bm = new Bookmark(cursor);
1384 && !StorageHelper.isPathInStorageVolume(bm.mPath)) {
1389 while (cursor.moveToNext());
1394 if (cursor != null) {
1398 catch (Exception e) {
1403 // Remove bookmarks from virtual storage if the filesystem is not mount
1404 int c = bookmarks.size() - 1;
1405 for (int i = c; i >= 0; i--) {
1406 VirtualMountPointConsole vc =
1407 VirtualMountPointConsole.getVirtualConsoleForPath(bookmarks.get(i).mPath);
1408 if (vc != null && !vc.isMounted()) {
1409 bookmarks.remove(i);
1417 * Method that initializes the navigation views of the activity
1419 private void initNavigationViews() {
1420 //Get the navigation views (wishlist: multiple view; for now only one view)
1421 this.mNavigationViews = new NavigationView[1];
1422 this.mCurrentNavigationView = 0;
1424 this.mNavigationViews[0] = (NavigationView)findViewById(R.id.navigation_view);
1425 this.mNavigationViews[0].setId(0);
1426 this.mEasyModeListView = (ListView) findViewById(R.id.lv_easy_mode);
1427 mEasyModeAdapter = new ArrayAdapter<MimeTypeCategory>(this, R.layout
1428 .navigation_view_simple_item) {
1430 public View getView(int position, View convertView, ViewGroup parent) {
1431 convertView = (convertView == null) ?getLayoutInflater().inflate(R.layout
1432 .navigation_view_simple_item, parent, false) : convertView;
1433 MimeTypeCategory item = getItem(position);
1434 String typeTitle = MIME_TYPE_LOCALIZED_NAMES[item.ordinal()];
1435 TextView typeTitleTV = (TextView) convertView
1436 .findViewById(R.id.navigation_view_item_name);
1437 ImageView typeIconIV = (ImageView) convertView
1438 .findViewById(R.id.navigation_view_item_icon);
1439 View checkBoxView = convertView.findViewById(R.id.navigation_view_item_check);
1440 checkBoxView.setVisibility(View.GONE);
1441 typeTitleTV.setText(typeTitle);
1442 typeIconIV.setImageDrawable(EASY_MODE_ICONS.get(item));
1443 convertView.setOnClickListener(mEasyModeItemClickListener);
1444 convertView.setTag(position);
1448 mEasyModeAdapter.addAll(EASY_MODE_LIST);
1449 mEasyModeListView.setAdapter(mEasyModeAdapter);
1452 private void onClicked(int position) {
1453 Intent intent = new Intent(this, SearchActivity.class);
1454 intent.setAction(Intent.ACTION_SEARCH);
1455 intent.putExtra(SearchActivity.EXTRA_SEARCH_DIRECTORY,
1456 getCurrentNavigationView().getCurrentDir());
1457 intent.putExtra(SearchManager.QUERY, "*"); // Use wild-card '*'
1459 if (position == 0) {
1460 performHideEasyMode();
1464 ArrayList<MimeTypeCategory> searchCategories = new ArrayList<MimeTypeCategory>();
1465 MimeTypeCategory selectedCategory = EASY_MODE_LIST.get(position);
1466 searchCategories.add(selectedCategory);
1467 // a one off case where we implicitly want to also search for TEXT mimetypes when the
1468 // DOCUMENTS category is selected
1469 if (selectedCategory == MimeTypeCategory.DOCUMENT) {
1470 searchCategories.add(MimeTypeCategory.TEXT);
1472 intent.putExtra(SearchActivity.EXTRA_SEARCH_MIMETYPE, searchCategories);
1475 startActivity(intent);
1479 * Method that initialize the console
1482 void initConsole() {
1483 //Create the default console (from the preferences)
1485 Console console = ConsoleBuilder.getConsole(NavigationActivity.this);
1486 if (console == null) {
1487 throw new ConsoleAllocException("console == null"); //$NON-NLS-1$
1489 } catch (Throwable ex) {
1490 if (!NavigationActivity.this.mChRooted) {
1491 //Show exception and exit
1492 Log.e(TAG, getString(R.string.msgs_cant_create_console), ex);
1493 // We don't have any console
1494 // Show exception and exit
1495 DialogHelper.showToast(
1496 NavigationActivity.this,
1497 R.string.msgs_cant_create_console, Toast.LENGTH_LONG);
1502 // We are in a trouble (something is not allowing creating the console)
1503 // Ask the user to return to prompt or root access mode mode with a
1504 // non-privileged console, prior to make crash the application
1511 * Method that initializes the navigation.
1513 * @param viewId The navigation view identifier where apply the navigation
1514 * @param restore Initialize from a restore info
1515 * @param intent The current intent
1518 void initNavigation(final int viewId, final boolean restore, final Intent intent) {
1519 final NavigationView navigationView = getNavigationView(viewId);
1520 this.mHandler.post(new Runnable() {
1523 //Is necessary navigate?
1525 applyInitialDir(navigationView, intent);
1532 * Method that applies the user-defined initial directory
1534 * @param navigationView The navigation view
1535 * @param intent The current intent
1538 void applyInitialDir(final NavigationView navigationView, final Intent intent) {
1539 //Load the user-defined initial directory
1541 Preferences.getSharedPreferences().getString(
1542 FileManagerSettings.SETTINGS_INITIAL_DIR.getId(),
1543 (String)FileManagerSettings.
1544 SETTINGS_INITIAL_DIR.getDefaultValue());
1546 // Check if request navigation to directory (use as default), and
1547 // ensure chrooted and absolute path
1548 String navigateTo = intent.getStringExtra(EXTRA_NAVIGATE_TO);
1549 String intentAction = intent.getAction();
1550 if (navigateTo != null && navigateTo.length() > 0) {
1551 initialDir = navigateTo;
1552 } else if (intentAction != null && intentAction.equals(Intent.ACTION_VIEW)) {
1553 Uri data = intent.getData();
1554 if (data != null && (FileHelper.FILE_URI_SCHEME.equals(data.getScheme())
1555 || FileHelper.FOLDER_URI_SCHEME.equals(data.getScheme())
1556 || FileHelper.DIRECTORY_URI_SCHEME.equals(data.getScheme()))) {
1557 File path = new File(data.getPath());
1558 if (path.isDirectory()) {
1559 initialDir = path.getAbsolutePath();
1565 final boolean addToHistory = intent.getBooleanExtra(EXTRA_ADD_TO_HISTORY, true);
1567 // We cannot navigate to a secure console if it is unmounted. So go to root in that case
1568 VirtualConsole vc = VirtualMountPointConsole.getVirtualConsoleForPath(initialDir);
1569 if (vc != null && vc instanceof SecureConsole && !((SecureConsole) vc).isMounted()) {
1570 initialDir = FileHelper.ROOT_DIRECTORY;
1573 if (this.mChRooted) {
1574 // Initial directory is the first external sdcard (sdcard, emmc, usb, ...)
1575 if (!StorageHelper.isPathInStorageVolume(initialDir)) {
1576 StorageVolume[] volumes =
1577 StorageHelper.getStorageVolumes(this, false);
1578 if (volumes != null && volumes.length > 0) {
1579 initialDir = volumes[0].getPath();
1580 //Ensure that initial directory is an absolute directory
1581 initialDir = FileHelper.getAbsPath(initialDir);
1583 // Show exception and exit
1584 DialogHelper.showToast(
1586 R.string.msgs_cant_create_console, Toast.LENGTH_LONG);
1592 //Ensure that initial directory is an absolute directory
1593 final String userInitialDir = initialDir;
1594 initialDir = FileHelper.getAbsPath(initialDir);
1595 final String absInitialDir = initialDir;
1596 File f = new File(initialDir);
1597 boolean exists = f.exists();
1599 // Fix for /data/media/0. Libcore doesn't detect it correctly.
1601 exists = CommandHelper.getFileInfo(this, initialDir, false, null) != null;
1602 } catch (InsufficientPermissionsException ipex) {
1603 ExceptionUtil.translateException(
1604 this, ipex, false, true, new OnRelaunchCommandResult() {
1606 public void onSuccess() {
1607 navigationView.changeCurrentDir(absInitialDir, addToHistory);
1610 public void onFailed(Throwable cause) {
1611 showInitialInvalidDirectoryMsg(userInitialDir);
1612 navigationView.changeCurrentDir(FileHelper.ROOT_DIRECTORY,
1616 public void onCancelled() {
1617 showInitialInvalidDirectoryMsg(userInitialDir);
1618 navigationView.changeCurrentDir(FileHelper.ROOT_DIRECTORY,
1623 // Asynchronous mode
1625 } catch (Exception ex) {
1626 // We are not interested in other exceptions
1627 ExceptionUtil.translateException(this, ex, true, false);
1630 // Check again the initial directory
1632 showInitialInvalidDirectoryMsg(userInitialDir);
1633 initialDir = FileHelper.ROOT_DIRECTORY;
1636 // Weird, but we have a valid initial directory
1640 boolean needsEasyMode = false;
1641 if (mSdBookmarks != null ) {
1642 for (Bookmark bookmark :mSdBookmarks) {
1643 if (bookmark.mPath.equalsIgnoreCase(initialDir)) {
1644 needsEasyMode = true;
1650 needsEasyMode = needsEasyMode
1651 && getResources().getBoolean(R.bool.cmcc_show_easy_mode);
1652 if (needsEasyMode) {
1653 performShowEasyMode();
1655 performHideEasyMode();
1657 // Change the current directory to the user-defined initial directory
1658 navigationView.changeCurrentDir(initialDir, addToHistory);
1662 * Displays a message reporting invalid directory
1664 * @param initialDir The initial directory
1667 void showInitialInvalidDirectoryMsg(String initialDir) {
1668 // Change to root directory
1669 DialogHelper.showToast(
1672 R.string.msgs_settings_invalid_initial_directory,
1674 Toast.LENGTH_SHORT);
1678 * Method that verifies the intent passed to the activity, and checks
1679 * if a request is made like Search.
1681 * @param intent The intent to check
1684 void checkIntent(Intent intent) {
1686 if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
1687 Intent searchIntent = new Intent(this, SearchActivity.class);
1688 searchIntent.setAction(Intent.ACTION_SEARCH);
1689 //- SearchActivity.EXTRA_SEARCH_DIRECTORY
1690 searchIntent.putExtra(
1691 SearchActivity.EXTRA_SEARCH_DIRECTORY,
1692 getCurrentNavigationView().getCurrentDir());
1693 //- SearchManager.APP_DATA
1694 if (intent.getBundleExtra(SearchManager.APP_DATA) != null) {
1695 Bundle bundle = new Bundle();
1696 bundle.putAll(intent.getBundleExtra(SearchManager.APP_DATA));
1697 searchIntent.putExtra(SearchManager.APP_DATA, bundle);
1699 //-- SearchManager.QUERY
1700 String query = intent.getStringExtra(SearchManager.QUERY);
1701 if (query != null) {
1702 searchIntent.putExtra(SearchManager.QUERY, query);
1704 //- android.speech.RecognizerIntent.EXTRA_RESULTS
1705 ArrayList<String> extraResults =
1706 intent.getStringArrayListExtra(android.speech.RecognizerIntent.EXTRA_RESULTS);
1707 if (extraResults != null) {
1708 searchIntent.putStringArrayListExtra(
1709 android.speech.RecognizerIntent.EXTRA_RESULTS, extraResults);
1711 startActivityForResult(searchIntent, INTENT_REQUEST_SEARCH);
1720 public boolean onKeyUp(int keyCode, KeyEvent event) {
1721 if (keyCode == KeyEvent.KEYCODE_MENU) {
1722 if (mDrawerLayout.isDrawerOpen(mDrawer)) {
1723 mDrawerLayout.closeDrawer(Gravity.START);
1725 mDrawerLayout.openDrawer(Gravity.START);
1729 return super.onKeyUp(keyCode, event);
1733 public void onBackPressed() {
1734 if (checkBackAction()) {
1735 performHideEasyMode();
1739 // An exit event has occurred, force the destroy the consoles
1744 * Method invoked when an action item is clicked.
1746 * @param view The button pushed
1748 public void onActionBarItemClick(View view) {
1749 switch (view.getId()) {
1750 //######################
1751 //Navigation Custom Title
1752 //######################
1753 case R.id.ab_configuration:
1754 //Show navigation view configuration toolbar
1755 getCurrentNavigationView().getCustomTitle().showConfigurationView();
1758 //Hide navigation view configuration toolbar
1759 getCurrentNavigationView().getCustomTitle().hideConfigurationView();
1762 //######################
1763 //Breadcrumb Actions
1764 //######################
1765 case R.id.ab_filesystem_info:
1766 //Show information of the filesystem
1767 MountPoint mp = getCurrentNavigationView().getBreadcrumb().getMountPointInfo();
1768 DiskUsage du = getCurrentNavigationView().getBreadcrumb().getDiskUsageInfo();
1769 showMountPointInfo(mp, du);
1772 //######################
1773 //Navigation view options
1774 //######################
1775 case R.id.ab_sort_mode:
1776 showSettingsPopUp(view,
1778 new FileManagerSettings[]{
1779 FileManagerSettings.SETTINGS_SORT_MODE}));
1781 case R.id.ab_layout_mode:
1782 showSettingsPopUp(view,
1784 new FileManagerSettings[]{
1785 FileManagerSettings.SETTINGS_LAYOUT_MODE}));
1787 case R.id.ab_view_options:
1788 // If we are in ChRooted mode, then don't show non-secure items
1789 if (this.mChRooted) {
1790 showSettingsPopUp(view,
1791 Arrays.asList(new FileManagerSettings[]{
1792 FileManagerSettings.SETTINGS_SHOW_DIRS_FIRST}));
1794 showSettingsPopUp(view,
1795 Arrays.asList(new FileManagerSettings[]{
1796 FileManagerSettings.SETTINGS_SHOW_DIRS_FIRST,
1797 FileManagerSettings.SETTINGS_SHOW_HIDDEN,
1798 FileManagerSettings.SETTINGS_SHOW_SYSTEM,
1799 FileManagerSettings.SETTINGS_SHOW_SYMLINKS}));
1804 //######################
1806 //######################
1807 case R.id.ab_selection_done:
1808 //Show information of the filesystem
1809 getCurrentNavigationView().onDeselectAll();
1812 //######################
1813 //Action Bar buttons
1814 //######################
1815 case R.id.ab_actions:
1816 openActionsDialog(getCurrentNavigationView().getCurrentDir(),
1820 case R.id.ab_search:
1834 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1835 if (requestCode == INTENT_REQUEST_SETTINGS) {
1836 // reset bookmarks list to default as the user could changed the
1837 // root mode which changes the system bookmarks
1843 switch (requestCode) {
1844 case INTENT_REQUEST_SEARCH:
1845 if (resultCode == RESULT_OK) {
1847 Bundle bundle = data.getExtras();
1848 if (bundle != null) {
1849 FileSystemObject fso = (FileSystemObject) bundle.getSerializable(
1850 EXTRA_SEARCH_ENTRY_SELECTION);
1851 SearchInfoParcelable searchInfo =
1852 bundle.getParcelable(EXTRA_SEARCH_LAST_SEARCH_DATA);
1854 //Goto to new directory
1855 getCurrentNavigationView().open(fso, searchInfo);
1856 performHideEasyMode();
1859 } else if (resultCode == RESULT_CANCELED) {
1860 SearchInfoParcelable searchInfo =
1861 data.getParcelableExtra(EXTRA_SEARCH_LAST_SEARCH_DATA);
1862 if (searchInfo != null && searchInfo.isSuccessNavigation()) {
1863 //Navigate to previous history
1866 // I don't know is the search view was changed, so try to do a refresh
1867 // of the navigation view
1868 getCurrentNavigationView().refresh(true);
1871 // reset bookmarks list to default as the user could have set a
1872 // new bookmark in the search activity
1886 public void onNewHistory(HistoryNavigable navigable) {
1887 addHistoryToDrawer(this.mHistory.size(), navigable);
1888 //Recollect information about current status
1889 History history = new History(this.mHistory.size(), navigable);
1890 this.mHistory.add(history);
1897 public void onCheckHistory() {
1904 public void onRequestRefresh(Object o, boolean clearSelection) {
1905 if (o instanceof FileSystemObject) {
1906 // Refresh only the item
1907 this.getCurrentNavigationView().refresh((FileSystemObject)o);
1908 } else if (o == null) {
1910 getCurrentNavigationView().refresh();
1912 if (clearSelection) {
1913 this.getCurrentNavigationView().onDeselectAll();
1921 public void onRequestBookmarksRefresh() {
1929 public void onRequestRemove(Object o, boolean clearSelection) {
1930 if (o instanceof FileSystemObject) {
1932 this.getCurrentNavigationView().removeItem((FileSystemObject)o);
1934 //Remove from history
1935 removeFromHistory((FileSystemObject)o);
1937 onRequestRefresh(null, clearSelection);
1939 if (clearSelection) {
1940 this.getCurrentNavigationView().onDeselectAll();
1948 public void onNavigateTo(Object o) {
1953 public void onCancel(){
1961 public void onSelectionChanged(NavigationView navView, List<FileSystemObject> selectedItems) {
1962 this.mSelectionBar.setSelection(selectedItems);
1969 public void onRequestMenu(NavigationView navView, FileSystemObject item) {
1970 // Show the actions dialog
1971 openActionsDialog(item, false);
1975 * Method that shows a popup with a menu associated a {@link FileManagerSettings}.
1977 * @param anchor The action button that was pressed
1978 * @param settings The array of settings associated with the action button
1980 private void showSettingsPopUp(View anchor, List<FileManagerSettings> settings) {
1981 //Create the adapter
1982 final MenuSettingsAdapter adapter = new MenuSettingsAdapter(this, settings);
1984 //Create a show the popup menu
1985 final ListPopupWindow popup = DialogHelper.createListPopupWindow(this, adapter, anchor);
1986 popup.setOnItemClickListener(new OnItemClickListener() {
1988 public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
1989 FileManagerSettings setting =
1990 ((MenuSettingsAdapter)parent.getAdapter()).getSetting(position);
1991 final int value = ((MenuSettingsAdapter)parent.getAdapter()).getId(position);
1994 if (setting.compareTo(FileManagerSettings.SETTINGS_LAYOUT_MODE) == 0) {
1995 //Need to change the layout
1996 getCurrentNavigationView().changeViewMode(
1997 NavigationLayoutMode.fromId(value));
2000 if (setting.getDefaultValue() instanceof Enum<?>) {
2002 Preferences.savePreference(setting, new ObjectIdentifier() {
2004 public int getId() {
2011 Preferences.getSharedPreferences().
2014 ((Boolean)setting.getDefaultValue()).booleanValue());
2015 Preferences.savePreference(setting, Boolean.valueOf(!newval), false);
2017 getCurrentNavigationView().refresh();
2019 } catch (Exception e) {
2020 Log.e(TAG, "Error applying navigation option", e); //$NON-NLS-1$
2021 NavigationActivity.this.mHandler.post(new Runnable() {
2024 DialogHelper.showToast(
2025 NavigationActivity.this,
2026 R.string.msgs_settings_save_failure, Toast.LENGTH_SHORT);
2032 getCurrentNavigationView().getCustomTitle().restoreView();
2037 popup.setOnDismissListener(new PopupWindow.OnDismissListener() {
2039 public void onDismiss() {
2047 * Method that show the information of a filesystem mount point.
2049 * @param mp The mount point info
2050 * @param du The disk usage of the mount point
2052 private void showMountPointInfo(MountPoint mp, DiskUsage du) {
2053 //Has mount point info?
2055 //There is no information
2057 DialogHelper.createWarningDialog(
2059 R.string.filesystem_info_warning_title,
2060 R.string.filesystem_info_warning_msg);
2061 DialogHelper.delegateDialogShow(this, alert);
2065 //Show a the filesystem info dialog
2066 FilesystemInfoDialog dialog = new FilesystemInfoDialog(this, mp, du);
2067 dialog.setOnMountListener(new OnMountListener() {
2069 public void onRemount(MountPoint mountPoint) {
2070 //Update the statistics of breadcrumb, only if mount point is the same
2071 Breadcrumb breadcrumb = getCurrentNavigationView().getBreadcrumb();
2072 if (breadcrumb.getMountPointInfo().compareTo(mountPoint) == 0) {
2073 breadcrumb.updateMountPointInfo();
2075 if (mountPoint.isSecure()) {
2076 // Secure mountpoints only can be unmount, so we need to move the navigation
2077 // to a secure storage (do not add to history)
2078 Intent intent = new Intent();
2079 intent.putExtra(EXTRA_ADD_TO_HISTORY, false);
2080 initNavigation(NavigationActivity.this.mCurrentNavigationView, false, intent);
2088 * Method that checks the action that must be realized when the
2089 * back button is pushed.
2091 * @return boolean Indicates if the action must be intercepted
2093 private boolean checkBackAction() {
2094 // We need a basic structure to check this
2095 if (getCurrentNavigationView() == null) return false;
2097 if (mSearchView.getVisibility() == View.VISIBLE) {
2101 //Check if the configuration view is showing. In this case back
2102 //action must be "close configuration"
2103 if (getCurrentNavigationView().getCustomTitle().isConfigurationViewShowing()) {
2104 getCurrentNavigationView().getCustomTitle().restoreView();
2108 //Do back operation over the navigation history
2109 boolean flag = this.mExitFlag;
2111 this.mExitFlag = !back();
2113 // Retrieve if the exit status timeout has expired
2114 long now = System.currentTimeMillis();
2115 boolean timeout = (this.mExitBackTimeout == -1 ||
2116 (now - this.mExitBackTimeout) > RELEASE_EXIT_CHECK_TIMEOUT);
2118 //Check if there no history and if the user was advised in the last back action
2119 if (this.mExitFlag && (this.mExitFlag != flag || timeout)) {
2120 //Communicate the user that the next time the application will be closed
2121 this.mExitBackTimeout = System.currentTimeMillis();
2122 DialogHelper.showToast(this, R.string.msgs_push_again_to_exit, Toast.LENGTH_SHORT);
2126 //Back action not applied
2127 return !this.mExitFlag;
2131 public void startActivity(Intent intent) {
2132 // check if search intent
2133 if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
2134 intent.putExtra(SearchActivity.EXTRA_SEARCH_DIRECTORY,
2135 getCurrentNavigationView().getCurrentDir());
2138 super.startActivity(intent);
2142 * Method that returns the history size.
2144 private void clearHistory() {
2145 this.mHistory.clear();
2146 mDrawerHistory.removeAllViews();
2147 mDrawerHistoryEmpty.setVisibility(View.VISIBLE);
2151 * Method that navigates to the passed history reference.
2153 * @param history The history reference
2154 * @return boolean A problem occurs while navigate
2156 public synchronized boolean navigateToHistory(History history) {
2159 History realHistory = this.mHistory.get(history.getPosition());
2161 //Navigate to item. Check what kind of history is
2162 if (realHistory.getItem() instanceof NavigationViewInfoParcelable) {
2164 NavigationViewInfoParcelable info =
2165 (NavigationViewInfoParcelable)realHistory.getItem();
2166 int viewId = info.getId();
2167 NavigationView view = getNavigationView(viewId);
2168 // Selected items must not be restored from on history navigation
2169 info.setSelectedFiles(view.getSelectedFiles());
2170 if (!view.onRestoreState(info)) {
2174 } else if (realHistory.getItem() instanceof SearchInfoParcelable) {
2175 //Search (open search with the search results)
2176 SearchInfoParcelable info = (SearchInfoParcelable)realHistory.getItem();
2177 Intent searchIntent = new Intent(this, SearchActivity.class);
2178 searchIntent.setAction(SearchActivity.ACTION_RESTORE);
2179 searchIntent.putExtra(SearchActivity.EXTRA_SEARCH_RESTORE, (Parcelable)info);
2180 startActivityForResult(searchIntent, INTENT_REQUEST_SEARCH);
2182 //The type is unknown
2183 throw new IllegalArgumentException("Unknown history type"); //$NON-NLS-1$
2186 //Remove the old history
2187 int cc = realHistory.getPosition();
2188 for (int i = this.mHistory.size() - 1; i >= cc; i--) {
2189 this.mHistory.remove(i);
2190 mDrawerHistory.removeViewAt(0);
2193 if (mDrawerHistory.getChildCount() == 0) {
2194 mDrawerHistoryEmpty.setVisibility(View.VISIBLE);
2198 boolean clearHistory = mHistoryTab.isSelected() && mHistory.size() > 0;
2199 mClearHistory.setVisibility(clearHistory ? View.VISIBLE : View.GONE);
2202 } catch (Throwable ex) {
2203 if (history != null) {
2205 String.format("Failed to navigate to history %d: %s", //$NON-NLS-1$
2206 Integer.valueOf(history.getPosition()),
2207 history.getItem().getTitle()), ex);
2210 String.format("Failed to navigate to history: null", ex)); //$NON-NLS-1$
2212 this.mHandler.post(new Runnable() {
2215 DialogHelper.showToast(
2216 NavigationActivity.this,
2217 R.string.msgs_history_unknown, Toast.LENGTH_LONG);
2221 //Not change directory
2227 * Method that request a back action over the navigation history.
2229 * @return boolean If a back action was applied
2231 public boolean back() {
2232 // Check that has valid history
2233 while (this.mHistory.size() > 0) {
2234 History h = this.mHistory.get(this.mHistory.size() - 1);
2235 if (h.getItem() instanceof NavigationViewInfoParcelable) {
2236 // Verify that the path exists
2237 String path = ((NavigationViewInfoParcelable)h.getItem()).getCurrentDir();
2240 FileSystemObject info = CommandHelper.getFileInfo(this, path, null);
2244 this.mHistory.remove(this.mHistory.size() - 1);
2245 } catch (Exception e) {
2246 ExceptionUtil.translateException(this, e, true, false);
2247 this.mHistory.remove(this.mHistory.size() - 1);
2254 //Navigate to history
2255 if (this.mHistory.size() > 0) {
2256 return navigateToHistory(this.mHistory.get(this.mHistory.size() - 1));
2260 mClearHistory.setVisibility(View.GONE);
2265 * Method that opens the actions dialog
2267 * @param item The path or the {@link FileSystemObject}
2268 * @param global If the menu to display is the one with global actions
2270 private void openActionsDialog(Object item, boolean global) {
2271 // Resolve the full path
2272 String path = String.valueOf(item);
2273 if (item instanceof FileSystemObject) {
2274 path = ((FileSystemObject)item).getFullPath();
2277 // Prior to show the dialog, refresh the item reference
2278 FileSystemObject fso = null;
2280 fso = CommandHelper.getFileInfo(this, path, false, null);
2282 throw new NoSuchFileOrDirectory(path);
2285 } catch (Exception e) {
2287 ExceptionUtil.translateException(this, e);
2289 // Remove the object
2290 if (e instanceof FileNotFoundException || e instanceof NoSuchFileOrDirectory) {
2291 // If have a FileSystemObject reference then there is no need to search
2292 // the path (less resources used)
2293 if (item instanceof FileSystemObject) {
2294 getCurrentNavigationView().removeItem((FileSystemObject)item);
2296 getCurrentNavigationView().removeItem((String)item);
2303 ActionsDialog dialog = new ActionsDialog(this, this, fso, global, false);
2304 dialog.setOnRequestRefreshListener(this);
2305 dialog.setOnSelectionListener(getCurrentNavigationView());
2310 * Method that opens the search view.
2315 mSearchView.setVisibility(View.VISIBLE);
2316 mSearchView.onActionViewExpanded();
2317 mCustomTitleView.setVisibility(View.GONE);
2320 void closeSearch() {
2321 mSearchView.setVisibility(View.GONE);
2322 mSearchView.onActionViewCollapsed();
2323 mCustomTitleView.setVisibility(View.VISIBLE);
2327 * Method that opens the settings activity.
2331 void openSettings() {
2332 Intent settingsIntent = new Intent(NavigationActivity.this,
2333 SettingsPreferences.class);
2334 startActivityForResult(settingsIntent, INTENT_REQUEST_SETTINGS);
2338 * Method that remove the {@link FileSystemObject} from the history
2340 private void removeFromHistory(FileSystemObject fso) {
2341 if (this.mHistory != null) {
2342 int cc = this.mHistory.size() - 1;
2343 for (int i = cc; i >= 0 ; i--) {
2344 History history = this.mHistory.get(i);
2345 if (history.getItem() instanceof NavigationViewInfoParcelable) {
2346 String p0 = fso.getFullPath();
2347 String p1 = ((NavigationViewInfoParcelable) history.getItem()).getCurrentDir();
2348 if (p0.compareTo(p1) == 0) {
2349 this.mHistory.remove(i);
2350 mDrawerHistory.removeViewAt(mDrawerHistory.getChildCount() - i - 1);
2351 mDrawerHistoryEmpty.setVisibility(
2352 mDrawerHistory.getChildCount() == 0 ? View.VISIBLE : View.GONE);
2353 updateHistoryPositions();
2361 * Update the history positions after one of the history is removed from drawer
2363 private void updateHistoryPositions() {
2364 int cc = this.mHistory.size() - 1;
2365 for (int i = 0; i <= cc ; i++) {
2366 History history = this.mHistory.get(i);
2367 history.setPosition(i + 1);
2372 * Method that ask the user to change the access mode prior to crash.
2376 //Show a dialog asking the user
2377 AlertDialog dialog =
2378 DialogHelper.createYesNoDialog(
2380 R.string.msgs_change_to_prompt_access_mode_title,
2381 R.string.msgs_change_to_prompt_access_mode_msg,
2382 new DialogInterface.OnClickListener() {
2384 public void onClick(DialogInterface alertDialog, int which) {
2385 if (which == DialogInterface.BUTTON_NEGATIVE) {
2386 // We don't have any console
2387 // Show exception and exit
2388 DialogHelper.showToast(
2389 NavigationActivity.this,
2390 R.string.msgs_cant_create_console, Toast.LENGTH_LONG);
2395 // Ok. Now try to change to prompt mode. Any crash
2396 // here is a fatal error. We won't have any console to operate.
2399 ConsoleBuilder.changeToNonPrivilegedConsole(NavigationActivity.this);
2402 Preferences.savePreference(
2403 FileManagerSettings.SETTINGS_ACCESS_MODE,
2404 AccessMode.PROMPT, true);
2406 } catch (Exception e) {
2407 // Displays an exception and exit
2408 Log.e(TAG, getString(R.string.msgs_cant_create_console), e);
2409 DialogHelper.showToast(
2410 NavigationActivity.this,
2411 R.string.msgs_cant_create_console, Toast.LENGTH_LONG);
2416 DialogHelper.delegateDialogShow(this, dialog);
2420 * Method that creates a ChRooted environment, protecting the user to break anything in
2424 void createChRooted() {
2425 // If we are in a ChRooted mode, then do nothing
2426 if (this.mChRooted) return;
2427 this.mChRooted = true;
2429 int cc = this.mNavigationViews.length;
2430 for (int i = 0; i < cc; i++) {
2431 this.mNavigationViews[i].createChRooted();
2434 // Remove the selection
2435 cc = this.mNavigationViews.length;
2436 for (int i = 0; i < cc; i++) {
2437 getCurrentNavigationView().onDeselectAll();
2440 // Remove the history (don't allow to access to previous data)
2445 * Method that exits from a ChRooted
2448 void exitChRooted() {
2449 // If we aren't in a ChRooted mode, then do nothing
2450 if (!this.mChRooted) return;
2451 this.mChRooted = false;
2453 int cc = this.mNavigationViews.length;
2454 for (int i = 0; i < cc; i++) {
2455 this.mNavigationViews[i].exitChRooted();
2460 * Method called when a controlled exit is required
2464 // Recycle the navigation views
2465 int cc = this.mNavigationViews.length;
2466 for (int i = 0; i < cc; i++) {
2467 this.mNavigationViews[i].recycle();
2470 FileManagerApplication.destroyBackgroundConsole();
2471 } catch (Throwable ex) {
2475 ConsoleBuilder.destroyConsole();
2476 } catch (Throwable ex) {
2483 * Method that reconfigures the layout for better fit in portrait and landscape modes
2485 private void onLayoutChanged() {
2486 Theme theme = ThemeManager.getCurrentTheme(this);
2487 boolean drawerOpen = mDrawerLayout.isDrawerOpen(Gravity.START);
2489 // Apply only when the orientation was changed
2490 int orientation = getResources().getConfiguration().orientation;
2491 if (this.mOrientation == orientation) return;
2492 this.mOrientation = orientation;
2494 // imitate a closed drawer while layout is rebuilt to avoid NullPointerException
2496 mDrawerLayout.closeDrawer(Gravity.START);
2499 if (this.mOrientation == Configuration.ORIENTATION_LANDSCAPE) {
2501 ViewGroup statusBar = (ViewGroup)findViewById(R.id.navigation_statusbar);
2502 if (statusBar.getParent() != null) {
2503 ViewGroup parent = (ViewGroup) statusBar.getParent();
2504 parent.removeView(statusBar);
2507 // Calculate the action button size (all the buttons must fit in the title bar)
2508 int bw = (int)getResources().getDimension(R.dimen.default_buttom_width);
2509 int abw = this.mActionBar.getChildCount() * bw;
2511 int cc = statusBar.getChildCount();
2512 for (int i = 0; i < cc; i++) {
2513 View child = statusBar.getChildAt(i);
2514 if (child instanceof ButtonItem) {
2518 // Currently there isn't overflow menu
2519 int w = abw + rbw - bw;
2521 // Add to the new location
2522 ViewGroup newParent = (ViewGroup)findViewById(R.id.navigation_title_landscape_holder);
2523 LinearLayout.LayoutParams params =
2524 new LinearLayout.LayoutParams(
2526 ViewGroup.LayoutParams.MATCH_PARENT);
2527 statusBar.setLayoutParams(params);
2528 newParent.addView(statusBar);
2531 theme.setBackgroundDrawable(this, statusBar, "titlebar_drawable"); //$NON-NLS-1$
2534 View holder = findViewById(R.id.navigation_statusbar_portrait_holder);
2535 holder.setVisibility(View.GONE);
2539 ViewGroup statusBar = (ViewGroup)findViewById(R.id.navigation_statusbar);
2540 if (statusBar.getParent() != null) {
2541 ViewGroup parent = (ViewGroup) statusBar.getParent();
2542 parent.removeView(statusBar);
2545 // Add to the new location
2546 ViewGroup newParent = (ViewGroup)findViewById(
2547 R.id.navigation_statusbar_portrait_holder);
2548 LinearLayout.LayoutParams params =
2549 new LinearLayout.LayoutParams(
2550 ViewGroup.LayoutParams.MATCH_PARENT,
2551 ViewGroup.LayoutParams.MATCH_PARENT);
2552 statusBar.setLayoutParams(params);
2553 newParent.addView(statusBar);
2556 theme.setBackgroundDrawable(this, statusBar, "statusbar_drawable"); //$NON-NLS-1$
2559 newParent.setVisibility(View.VISIBLE);
2562 // if drawer was open, imitate reopening
2564 mDrawerToggle.onDrawerOpened(mDrawer);
2569 * Method that removes all the history items that refers to virtual unmounted filesystems
2571 private void removeUnmountedHistory() {
2572 int cc = mHistory.size() - 1;
2573 for (int i = cc; i >= 0; i--) {
2574 History history = mHistory.get(i);
2575 if (history.getItem() instanceof NavigationViewInfoParcelable) {
2576 NavigationViewInfoParcelable navigableInfo =
2577 ((NavigationViewInfoParcelable) history.getItem());
2578 VirtualMountPointConsole vc =
2579 VirtualMountPointConsole.getVirtualConsoleForPath(
2580 navigableInfo.getCurrentDir());
2581 if (vc != null && !vc.isMounted()) {
2583 mDrawerHistory.removeViewAt(mDrawerHistory.getChildCount() - i - 1);
2587 mDrawerHistoryEmpty.setVisibility(
2588 mDrawerHistory.getChildCount() == 0 ? View.VISIBLE : View.GONE);
2589 updateHistoryPositions();
2593 * Method that removes all the selection items that refers to virtual unmounted filesystems
2595 private void removeUnmountedSelection() {
2596 for (NavigationView view : mNavigationViews) {
2597 view.removeUnmountedSelection();
2599 mSelectionBar.setSelection(getNavigationView(mCurrentNavigationView).getSelectedFiles());
2603 * Method that applies the current theme to the activity
2607 int orientation = getResources().getConfiguration().orientation;
2608 Theme theme = ThemeManager.getCurrentTheme(this);
2609 theme.setBaseThemeNoActionBar(this);
2612 // imitate a closed drawer while layout is rebuilt to avoid NullPointerException
2613 boolean drawerOpen = mDrawerLayout.isDrawerOpen(Gravity.START);
2615 mDrawerLayout.closeDrawer(Gravity.START);
2619 View v = findViewById(R.id.navigation_layout);
2620 theme.setBackgroundDrawable(this, v, "background_drawable"); //$NON-NLS-1$
2623 theme.setTitlebarDrawable(this, getActionBar(), "titlebar_drawable"); //$NON-NLS-1$
2625 // Hackery to theme search view
2626 mSearchView = (SearchView) findViewById(R.id.navigation_search_bar);
2627 int searchPlateId = mSearchView.getContext().getResources()
2628 .getIdentifier("android:id/search_plate", null, null);
2629 View searchPlate = mSearchView.findViewById(searchPlateId);
2630 if (searchPlate != null) {
2631 int searchTextId = searchPlate.getContext().getResources()
2632 .getIdentifier("android:id/search_src_text", null, null);
2633 TextView searchText = (TextView) searchPlate.findViewById(searchTextId);
2634 if (searchText != null) {
2635 searchText.setTextColor(Color.WHITE);
2636 searchText.setHintTextColor(Color.WHITE);
2639 int magId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
2640 ImageView magImage = (ImageView) mSearchView.findViewById(magId);
2641 if (magImage != null) {
2642 magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
2646 SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2647 mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
2648 mSearchView.setIconifiedByDefault(false);
2650 mCustomTitleView = (NavigationCustomTitleView) findViewById(R.id.navigation_title_flipper);
2651 mCustomTitleView.setVisibility(View.VISIBLE);
2654 v = findViewById(R.id.navigation_statusbar);
2655 if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
2656 theme.setBackgroundDrawable(this, v, "titlebar_drawable"); //$NON-NLS-1$
2658 theme.setBackgroundDrawable(this, v, "statusbar_drawable"); //$NON-NLS-1$
2660 v = findViewById(R.id.ab_overflow);
2661 theme.setImageDrawable(this, (ImageView)v, "ab_overflow_drawable"); //$NON-NLS-1$
2662 v = findViewById(R.id.ab_actions);
2663 theme.setImageDrawable(this, (ImageView)v, "ab_actions_drawable"); //$NON-NLS-1$
2664 v = findViewById(R.id.ab_search);
2665 theme.setImageDrawable(this, (ImageView)v, "ab_search_drawable"); //$NON-NLS-1$
2668 v = findViewById(R.id.ab_configuration);
2669 theme.setImageDrawable(this, (ImageView)v, "expander_open_drawable"); //$NON-NLS-1$
2670 v = findViewById(R.id.ab_close);
2671 theme.setImageDrawable(this, (ImageView)v, "expander_close_drawable"); //$NON-NLS-1$
2672 v = findViewById(R.id.ab_sort_mode);
2673 theme.setImageDrawable(this, (ImageView)v, "ab_sort_mode_drawable"); //$NON-NLS-1$
2674 v = findViewById(R.id.ab_layout_mode);
2675 theme.setImageDrawable(this, (ImageView)v, "ab_layout_mode_drawable"); //$NON-NLS-1$
2676 v = findViewById(R.id.ab_view_options);
2677 theme.setImageDrawable(this, (ImageView)v, "ab_view_options_drawable"); //$NON-NLS-1$
2680 v = findViewById(R.id.navigation_selectionbar);
2681 theme.setBackgroundDrawable(this, v, "selectionbar_drawable"); //$NON-NLS-1$
2682 v = findViewById(R.id.ab_selection_done);
2683 theme.setImageDrawable(this, (ImageView)v, "ab_selection_done_drawable"); //$NON-NLS-1$
2684 v = findViewById(R.id.navigation_status_selection_label);
2685 theme.setTextColor(this, (TextView)v, "text_color"); //$NON-NLS-1$
2687 // - Navigation drawer
2688 v = findViewById(R.id.history_empty);
2689 theme.setTextColor(this, (TextView)v, "text_color"); //$NON-NLS-1$
2691 for (int i=0; i<mDrawerHistory.getChildCount(); i++) {
2692 View item = mDrawerHistory.getChildAt(i);
2694 v = item.findViewById(R.id.history_item_name);
2695 theme.setTextColor(this, (TextView)v, "text_color"); //$NON-NLS-1$
2696 v = item.findViewById(R.id.history_item_directory);
2697 theme.setTextColor(this, (TextView)v, "text_color"); //$NON-NLS-1$
2701 int cc = this.mNavigationViews.length;
2702 for (int i = 0; i < cc; i++) {
2703 getNavigationView(i).applyTheme();
2706 // if drawer was open, imitate reopening
2708 mDrawerToggle.onDrawerOpened(mDrawer);
2713 * Method that applies the current theme to the tab host
2715 private void applyTabTheme() {
2717 Theme theme = ThemeManager.getCurrentTheme(this);
2719 View v = findViewById(R.id.drawer);
2720 theme.setBackgroundDrawable(this, v, "background_drawable"); //$NON-NLS-1$
2722 v = findViewById(R.id.drawer_bookmarks_tab);
2723 theme.setTextColor(this, (TextView)v, "text_color"); //$NON-NLS-1$
2724 v = findViewById(R.id.drawer_history_tab);
2725 theme.setTextColor(this, (TextView)v, "text_color"); //$NON-NLS-1$
2727 v = findViewById(R.id.ab_settings);
2728 theme.setImageDrawable(this, (ButtonItem) v, "ab_settings_drawable"); //$NON-NLS-1$
2729 v = findViewById(R.id.ab_clear_history);
2730 theme.setImageDrawable(this, (ButtonItem) v, "ab_delete_drawable"); //$NON-NLS-1$
2733 public void updateActiveDialog(Dialog dialog) {
2734 mActiveDialog = dialog;