diff options
author | Steve McKay <smckay@google.com> | 2015-04-30 16:12:59 -0700 |
---|---|---|
committer | Steve McKay <smckay@google.com> | 2015-05-04 16:21:09 +0000 |
commit | 69aee097a3853490c9c7afb191af4f047ab1d164 (patch) | |
tree | 83feb8f2f270e369b93c0f3fc371e0d11abadc08 | |
parent | 340b198ccbd1a05e67d586c345139617d4b84ce0 (diff) | |
download | frameworks_base-69aee097a3853490c9c7afb191af4f047ab1d164.zip frameworks_base-69aee097a3853490c9c7afb191af4f047ab1d164.tar.gz frameworks_base-69aee097a3853490c9c7afb191af4f047ab1d164.tar.bz2 |
Ensure sort menu is shown as needed.
This also hoists common code for options menu setup into BaseActivity.
Change-Id: Ie87b8188a6c142b2312c92dc0d0bd550f0b1e59f
3 files changed, 38 insertions, 42 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java index e0f10fa..cb21131 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java @@ -101,6 +101,41 @@ abstract class BaseActivity extends Activity { return showMenu; } + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + boolean shown = super.onPrepareOptionsMenu(menu); + + final RootInfo root = getCurrentRoot(); + final DocumentInfo cwd = getCurrentDirectory(); + + final MenuItem sort = menu.findItem(R.id.menu_sort); + final MenuItem sortSize = menu.findItem(R.id.menu_sort_size); + final MenuItem grid = menu.findItem(R.id.menu_grid); + final MenuItem list = menu.findItem(R.id.menu_list); + + final MenuItem advanced = menu.findItem(R.id.menu_advanced); + final MenuItem fileSize = menu.findItem(R.id.menu_file_size); + + mSearchManager.update(root); + + // Search uses backend ranking; no sorting + sort.setVisible(cwd != null && !mSearchManager.isSearching()); + + State state = getDisplayState(); + grid.setVisible(state.derivedMode != State.MODE_GRID); + list.setVisible(state.derivedMode != State.MODE_LIST); + + // Only sort by size when visible + sortSize.setVisible(state.showSize); + + advanced.setTitle(LocalPreferences.getDisplayAdvancedDevices(this) + ? R.string.menu_advanced_hide : R.string.menu_advanced_show); + fileSize.setTitle(LocalPreferences.getDisplayFileSize(this) + ? R.string.menu_file_size_hide : R.string.menu_file_size_show); + + return shown; + } + void onStackRestored(boolean restored, boolean external) {} void onRootPicked(RootInfo root) { diff --git a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java index 92c9cd1..e58c637 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java @@ -442,32 +442,16 @@ public class DocumentsActivity extends BaseActivity { public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - final FragmentManager fm = getFragmentManager(); - final RootInfo root = getCurrentRoot(); final DocumentInfo cwd = getCurrentDirectory(); final MenuItem createDir = menu.findItem(R.id.menu_create_dir); - final MenuItem sort = menu.findItem(R.id.menu_sort); - final MenuItem sortSize = menu.findItem(R.id.menu_sort_size); final MenuItem grid = menu.findItem(R.id.menu_grid); final MenuItem list = menu.findItem(R.id.menu_list); final MenuItem advanced = menu.findItem(R.id.menu_advanced); final MenuItem fileSize = menu.findItem(R.id.menu_file_size); final MenuItem settings = menu.findItem(R.id.menu_settings); - sort.setVisible(cwd != null); - grid.setVisible(mState.derivedMode != State.MODE_GRID); - list.setVisible(mState.derivedMode != State.MODE_LIST); - - mSearchManager.update(root); - - // Search uses backend ranking; no sorting - sort.setVisible(mSearchManager.isSearching()); - - // Only sort by size when visible - sortSize.setVisible(mState.showSize); - boolean fileSizeVisible = !(mState.action == ACTION_MANAGE || mState.action == ACTION_BROWSE); if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) { @@ -482,17 +466,13 @@ public class DocumentsActivity extends BaseActivity { } if (mState.action == ACTION_CREATE) { + final FragmentManager fm = getFragmentManager(); SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported()); } } else { createDir.setVisible(false); } - advanced.setTitle(LocalPreferences.getDisplayAdvancedDevices(this) - ? R.string.menu_advanced_hide : R.string.menu_advanced_show); - fileSize.setTitle(LocalPreferences.getDisplayFileSize(this) - ? R.string.menu_file_size_hide : R.string.menu_file_size_show); - advanced.setVisible(!(mState.action == ACTION_MANAGE || mState.action == ACTION_BROWSE)); fileSize.setVisible(fileSizeVisible); diff --git a/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java b/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java index cad277d..1f62973 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java @@ -185,30 +185,16 @@ public class StandaloneActivity extends BaseActivity { @Override public boolean onPrepareOptionsMenu(Menu menu) { - super.onPrepareOptionsMenu(menu); + boolean shown = super.onPrepareOptionsMenu(menu); final RootInfo root = getCurrentRoot(); final DocumentInfo cwd = getCurrentDirectory(); final MenuItem createDir = menu.findItem(R.id.menu_create_dir); - final MenuItem sort = menu.findItem(R.id.menu_sort); - final MenuItem sortSize = menu.findItem(R.id.menu_sort_size); - final MenuItem grid = menu.findItem(R.id.menu_grid); - final MenuItem list = menu.findItem(R.id.menu_list); final MenuItem advanced = menu.findItem(R.id.menu_advanced); final MenuItem fileSize = menu.findItem(R.id.menu_file_size); final MenuItem settings = menu.findItem(R.id.menu_settings); - grid.setVisible(mState.derivedMode != State.MODE_GRID); - list.setVisible(mState.derivedMode != State.MODE_LIST); - - mSearchManager.update(root); - - sort.setVisible(cwd != null && !mSearchManager.isSearching()); - - // Only sort by size when visible - sortSize.setVisible(mState.showSize); - createDir.setVisible(cwd != null && cwd.isCreateSupported() && !mSearchManager.isSearching() @@ -217,14 +203,9 @@ public class StandaloneActivity extends BaseActivity { fileSize.setVisible(cwd != null); advanced.setVisible(cwd != null); - advanced.setTitle(LocalPreferences.getDisplayAdvancedDevices(this) - ? R.string.menu_advanced_hide : R.string.menu_advanced_show); - fileSize.setTitle(LocalPreferences.getDisplayFileSize(this) - ? R.string.menu_file_size_hide : R.string.menu_file_size_show); - settings.setVisible((root.flags & Root.FLAG_HAS_SETTINGS) != 0); - return true; + return shown; } @Override |