summaryrefslogtreecommitdiffstats
path: root/packages/DocumentsUI
diff options
context:
space:
mode:
authorSteve McKay <smckay@google.com>2015-04-23 01:34:18 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-04-23 01:34:21 +0000
commit2b973ea93bb74a6b996b440cc46f02d8d545b54e (patch)
tree86436bd93695d117c75ce0b6832560c739b4a4ca /packages/DocumentsUI
parent25d4a63983430aa2461791445d2cea9829aab5be (diff)
parenta78a3694b533a4b02d3193342144dbd2f17bd8f0 (diff)
downloadframeworks_base-2b973ea93bb74a6b996b440cc46f02d8d545b54e.zip
frameworks_base-2b973ea93bb74a6b996b440cc46f02d8d545b54e.tar.gz
frameworks_base-2b973ea93bb74a6b996b440cc46f02d8d545b54e.tar.bz2
Merge "Update activities to clear search term when a root that doesn't support search is selected by the user."
Diffstat (limited to 'packages/DocumentsUI')
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java53
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java8
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java7
3 files changed, 42 insertions, 26 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
index efe71d4..e0f10fa 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
@@ -67,8 +67,10 @@ abstract class BaseActivity extends Activity {
static final String EXTRA_STATE = "state";
- private final String mTag;
RootsCache mRoots;
+ SearchManager mSearchManager;
+
+ private final String mTag;
public abstract State getDisplayState();
public abstract void onDocumentPicked(DocumentInfo doc);
@@ -86,6 +88,17 @@ abstract class BaseActivity extends Activity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mRoots = DocumentsApplication.getRootsCache(this);
+ mSearchManager = new SearchManager();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ boolean showMenu = super.onCreateOptionsMenu(menu);
+
+ getMenuInflater().inflate(R.menu.activity, menu);
+ mSearchManager.install(menu.findItem(R.id.menu_search));
+
+ return showMenu;
}
void onStackRestored(boolean restored, boolean external) {}
@@ -98,10 +111,15 @@ abstract class BaseActivity extends Activity {
state.stack.clear();
state.stackTouched = true;
- if (!mRoots.isRecentsRoot(root)) {
- new PickRootTask(root).executeOnExecutor(getCurrentExecutor());
- } else {
+ mSearchManager.update(root);
+
+ // Recents is always in memory, so we just load it directly.
+ // Otherwise we delegate loading data from disk to a task
+ // to ensure a responsive ui.
+ if (mRoots.isRecentsRoot(root)) {
onCurrentDirectoryChanged(ANIM_SIDE);
+ } else {
+ new PickRootTask(root).executeOnExecutor(getCurrentExecutor());
}
}
@@ -576,9 +594,9 @@ abstract class BaseActivity extends Activity {
final class SearchManager implements
SearchView.OnCloseListener, OnActionExpandListener, OnQueryTextListener {
- protected boolean mSearchExpanded;
- protected boolean mIgnoreNextClose;
- protected boolean mIgnoreNextCollapse;
+ private boolean mSearchExpanded;
+ private boolean mIgnoreNextClose;
+ private boolean mIgnoreNextCollapse;
private MenuItem mMenu;
private SearchView mView;
@@ -598,9 +616,10 @@ abstract class BaseActivity extends Activity {
*/
void update(RootInfo root) {
if (mMenu == null) {
- Log.d(mTag, "showMenu called before Search MenuItem installed.");
+ Log.d(mTag, "update called before Search MenuItem installed.");
return;
}
+
State state = getDisplayState();
if (state.currentSearch != null) {
mMenu.expandActionView();
@@ -609,12 +628,16 @@ abstract class BaseActivity extends Activity {
mView.clearFocus();
mView.setQuery(state.currentSearch, false);
} else {
- mIgnoreNextClose = true;
- mView.setIconified(true);
mView.clearFocus();
+ if (!mView.isIconified()) {
+ mIgnoreNextClose = true;
+ mView.setIconified(true);
+ }
- mIgnoreNextCollapse = true;
- mMenu.collapseActionView();
+ if (mMenu.isActionViewExpanded()) {
+ mIgnoreNextCollapse = true;
+ mMenu.collapseActionView();
+ }
}
showMenu(root != null
@@ -626,7 +649,11 @@ abstract class BaseActivity extends Activity {
Log.d(mTag, "showMenu called before Search MenuItem installed.");
return;
}
+
mMenu.setVisible(visible);
+ if (!visible) {
+ getDisplayState().currentSearch = null;
+ }
}
boolean isSearching() {
@@ -649,6 +676,7 @@ abstract class BaseActivity extends Activity {
onCurrentDirectoryChanged(ANIM_NONE);
return false;
}
+
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
mSearchExpanded = true;
@@ -668,6 +696,7 @@ abstract class BaseActivity extends Activity {
onCurrentDirectoryChanged(ANIM_NONE);
return true;
}
+
@Override
public boolean onQueryTextSubmit(String query) {
mSearchExpanded = true;
diff --git a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
index 9d828de..92c9cd1 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
@@ -88,7 +88,6 @@ public class DocumentsActivity extends BaseActivity {
private State mState;
- private SearchManager mSearchManager;
private ItemSelectedListener mStackListener;
private BaseAdapter mStackAdapter;
@@ -151,7 +150,6 @@ public class DocumentsActivity extends BaseActivity {
android.R.style.TextAppearance_DeviceDefault_Widget_ActionBar_Title);
}
- mSearchManager = new SearchManager();
setActionBar(mToolbar);
// Hide roots when we're managing a specific root
@@ -433,15 +431,10 @@ public class DocumentsActivity extends BaseActivity {
public boolean onCreateOptionsMenu(Menu menu) {
boolean showMenu = super.onCreateOptionsMenu(menu);
- getMenuInflater().inflate(R.menu.activity, menu);
-
// Most actions are visible when showing as dialog
if (mShowAsDialog) {
expandMenus(menu);
}
-
- this.mSearchManager.install(menu.findItem(R.id.menu_search));
-
return showMenu;
}
@@ -467,7 +460,6 @@ public class DocumentsActivity extends BaseActivity {
grid.setVisible(mState.derivedMode != State.MODE_GRID);
list.setVisible(mState.derivedMode != State.MODE_LIST);
-
mSearchManager.update(root);
// Search uses backend ranking; no sorting
diff --git a/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java b/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java
index f89b182..aad42ed 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java
@@ -63,7 +63,6 @@ public class StandaloneActivity extends BaseActivity {
private Spinner mToolbarStack;
private Toolbar mRootsToolbar;
private DirectoryContainerView mDirectoryContainer;
- private SearchManager mSearchManager;
private State mState;
private ItemSelectedListener mStackListener;
private BaseAdapter mStackAdapter;
@@ -96,7 +95,6 @@ public class StandaloneActivity extends BaseActivity {
? icicle.<State>getParcelable(EXTRA_STATE)
: buildDefaultState();
- mSearchManager = new SearchManager();
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setTitleTextAppearance(context,
android.R.style.TextAppearance_DeviceDefault_Widget_ActionBar_Title);
@@ -186,12 +184,8 @@ public class StandaloneActivity extends BaseActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
boolean showMenu = super.onCreateOptionsMenu(menu);
- getMenuInflater().inflate(R.menu.activity, menu);
expandMenus(menu);
-
- this.mSearchManager.install(menu.findItem(R.id.menu_search));
-
return showMenu;
}
@@ -215,6 +209,7 @@ public class StandaloneActivity extends BaseActivity {
list.setVisible(mState.derivedMode != State.MODE_LIST);
mSearchManager.update(root);
+
sort.setVisible(cwd != null && !mSearchManager.isSearching());
// Only sort by size when visible