Merge "Make search behave correctly"
diff --git a/src/com/android/contacts/activities/DialtactsActivity.java b/src/com/android/contacts/activities/DialtactsActivity.java
index 022a724..01212f5 100644
--- a/src/com/android/contacts/activities/DialtactsActivity.java
+++ b/src/com/android/contacts/activities/DialtactsActivity.java
@@ -255,7 +255,11 @@
new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
- // Ignore.
+ View view = getCurrentFocus();
+ if (view != null) {
+ hideInputMethod(view);
+ view.clearFocus();
+ }
return true;
}
@@ -274,16 +278,12 @@
* the search UI and let users go back to usual Phone UI.
*
* This does _not_ handle back button.
- *
- * TODO: need "up" button instead of close button
*/
private final OnCloseListener mPhoneSearchCloseListener =
new OnCloseListener() {
@Override
public boolean onClose() {
- if (TextUtils.isEmpty(mSearchView.getQuery())) {
- exitSearchUi();
- } else {
+ if (!TextUtils.isEmpty(mSearchView.getQuery())) {
mSearchView.setQuery(null, true);
}
return true;
@@ -645,13 +645,20 @@
// Instantiate or reset SearchView in ActionBar.
if (mSearchView == null) {
- // TODO: layout is not what we want. Need "up" button instead of "close" button, etc.
final View searchViewLayout =
getLayoutInflater().inflate(R.layout.custom_action_bar, null);
mSearchView = (SearchView) searchViewLayout.findViewById(R.id.search_view);
- mSearchView.setQueryHint(getString(R.string.hint_findContacts));
mSearchView.setOnQueryTextListener(mPhoneSearchQueryTextListener);
mSearchView.setOnCloseListener(mPhoneSearchCloseListener);
+ // Since we're using a custom layout for showing SearchView instead of letting the
+ // search menu icon do that job, we need to manually configure the View so it looks
+ // "shown via search menu".
+ // - it should be iconified by default
+ // - it should not be iconified at this time
+ // See also comments for onActionViewExpanded()/onActionViewCollapsed()
+ mSearchView.setIconifiedByDefault(true);
+ mSearchView.setQueryHint(getString(R.string.hint_findContacts));
+ mSearchView.setIconified(false);
mSearchView.requestFocus();
// Show soft keyboard when SearchView has a focus. Need to delay the request in order
// to let InputMethodManager handle it correctly.
@@ -690,6 +697,9 @@
transaction.commit();
mViewPager.setVisibility(View.GONE);
+ // We need to call this and onActionViewCollapsed() manually, since we are using a custom
+ // layout instead of asking the search menu item to take care of SearchView.
+ mSearchView.onActionViewExpanded();
mInSearchUi = true;
}
@@ -732,6 +742,8 @@
// Request to update option menu.
invalidateOptionsMenu();
+ // See comments in onActionViewExpanded()
+ mSearchView.onActionViewCollapsed();
mInSearchUi = false;
}