Merge "Fix for search view/IME issues"
diff --git a/res/layout/custom_action_bar.xml b/res/layout/custom_action_bar.xml
index 2357756..f749586 100644
--- a/res/layout/custom_action_bar.xml
+++ b/res/layout/custom_action_bar.xml
@@ -14,11 +14,20 @@
limitations under the License.
-->
+<!-- Dimensions are set at runtime in ActionBarAdapter -->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
+ android:layout_width="0dip"
+ android:layout_height="0dip" >
+ <!-- To prevent the search view from getting the initial focus. -->
+ <View
+ android:focusable="true"
+ android:focusableInTouchMode="true"
+ android:layout_width="1px"
+ android:layout_height="1px" >
+ <requestFocus />
+ </View>
<SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
diff --git a/res/menu-sw580dp-w720dp/actions.xml b/res/menu-sw580dp-w720dp/actions.xml
index 081065c..d87b091 100644
--- a/res/menu-sw580dp-w720dp/actions.xml
+++ b/res/menu-sw580dp-w720dp/actions.xml
@@ -15,11 +15,6 @@
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
- android:id="@+id/menu_search"
- android:showAsAction="always"
- android:actionViewClass="android.widget.SearchView" />
-
- <item
android:id="@+id/menu_add_contact"
android:icon="@drawable/ic_menu_add_contact_holo_light"
android:title="@string/menu_new_contact_action_bar"
diff --git a/res/menu-sw580dp/actions.xml b/res/menu-sw580dp/actions.xml
index 1d955c1..fea883e 100644
--- a/res/menu-sw580dp/actions.xml
+++ b/res/menu-sw580dp/actions.xml
@@ -15,11 +15,6 @@
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
- android:id="@+id/menu_search"
- android:showAsAction="always"
- android:actionViewClass="android.widget.SearchView" />
-
- <item
android:id="@+id/menu_add_contact"
android:icon="@drawable/ic_menu_add_contact_holo_light"
android:title="@string/menu_new_contact_action_bar"
diff --git a/res/values-sw580dp/dimens.xml b/res/values-sw580dp/dimens.xml
index 0c1e5fb..bcaf1d2 100644
--- a/res/values-sw580dp/dimens.xml
+++ b/res/values-sw580dp/dimens.xml
@@ -33,4 +33,5 @@
<dimen name="list_section_height">37dip</dimen>
<dimen name="directory_header_height">56dip</dimen>
<dimen name="detail_tab_carousel_height">256dip</dimen>
+ <dimen name="search_view_width">400dip</dimen>
</resources>
diff --git a/res/values-sw580dp/donottranslate_config.xml b/res/values-sw580dp/donottranslate_config.xml
index fcb7da9..5ca1af6 100644
--- a/res/values-sw580dp/donottranslate_config.xml
+++ b/res/values-sw580dp/donottranslate_config.xml
@@ -19,4 +19,5 @@
<resources>
<bool name="config_use_two_panes">true</bool>
+ <bool name="always_show_search_view">true</bool>
</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index a0c4845..948d357 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -148,7 +148,7 @@
<!-- Spacing on the left the search field in the action bar -->
<dimen name="action_bar_search_spacing">12dip</dimen>
- <!-- Size of the shortcut icon. 0dip means: use the system default -->
+ <!-- Size of the shortcut icon. 0dip means: use the system default -->
<dimen name="shortcut_icon_size">0dip</dimen>
<!-- Height of list sections (A, B, C) that show the first character of the contacts -->
@@ -181,4 +181,7 @@
<dimen name="dialpad_digits_margin_top">1dip</dimen>
<!-- Just used in landscape mode -->
<dimen name="dialpad_digits_margin_bottom">50dip</dimen>
+
+ <!-- Width of search view in action bar. Use 0dip for MATCH_PARENT -->
+ <dimen name="search_view_width">0dip</dimen>
</resources>
diff --git a/res/values/donottranslate_config.xml b/res/values/donottranslate_config.xml
index e310953..c778212 100644
--- a/res/values/donottranslate_config.xml
+++ b/res/values/donottranslate_config.xml
@@ -103,4 +103,8 @@
<!-- If true, Contacts uses two panes: List and Detail. If false, Details are
shown in their own screens. This flag must be in sync with the layout definitions. -->
<bool name="config_use_two_panes">false</bool>
+
+ <!-- If true, search view on action bar will always be visible. If false, it'll only be
+ visible in search mode. -->
+ <bool name="always_show_search_view">false</bool>
</resources>
diff --git a/src/com/android/contacts/activities/ActionBarAdapter.java b/src/com/android/contacts/activities/ActionBarAdapter.java
index 073f665..e0f8aef 100644
--- a/src/com/android/contacts/activities/ActionBarAdapter.java
+++ b/src/com/android/contacts/activities/ActionBarAdapter.java
@@ -58,27 +58,24 @@
private SearchView mSearchView;
private final Context mContext;
+ private final boolean mAlwaysShowSearchView;
private Listener mListener;
private ContactListFilterController mFilterController;
private ActionBar mActionBar;
- private View mCustomSearchView;
- private LayoutParams mLayoutParams;
- private boolean mIsSearchInOverflowMenu;
public ActionBarAdapter(Context context, Listener listener) {
mContext = context;
mListener = listener;
mSearchLabelText = mContext.getString(R.string.search_label);
+ mAlwaysShowSearchView = mContext.getResources().getBoolean(R.bool.always_show_search_view);
}
- public void onCreate(Bundle savedState, ContactsRequest request, ActionBar actionBar,
- boolean searchInOverflowMenu) {
+ public void onCreate(Bundle savedState, ContactsRequest request, ActionBar actionBar) {
mActionBar = actionBar;
mQueryString = null;
- mIsSearchInOverflowMenu = searchInOverflowMenu;
if (savedState != null) {
mSearchMode = savedState.getBoolean(EXTRA_KEY_SEARCH_MODE);
@@ -88,18 +85,23 @@
mQueryString = request.getQueryString();
}
- if (mSearchView != null) {
- mSearchView.setQuery(mQueryString, false);
+ // Set up search view.
+ View customSearchView = LayoutInflater.from(mContext).inflate(R.layout.custom_action_bar,
+ null);
+ int searchViewWidth = mContext.getResources().getDimensionPixelSize(
+ R.dimen.search_view_width);
+ if (searchViewWidth == 0) {
+ searchViewWidth = LayoutParams.MATCH_PARENT;
}
-
- update();
- }
-
- public void setSearchView(SearchView searchView) {
- mSearchView = searchView;
+ LayoutParams layoutParams = new LayoutParams(searchViewWidth, LayoutParams.WRAP_CONTENT);
+ mSearchView = (SearchView) customSearchView.findViewById(R.id.search_view);
+ mSearchView.setQueryHint(mContext.getString(R.string.hint_findContacts));
mSearchView.setOnQueryTextListener(this);
mSearchView.setOnCloseListener(this);
mSearchView.setQuery(mQueryString, false);
+ mActionBar.setCustomView(customSearchView, layoutParams);
+
+ update();
}
public void setListener(Listener listener) {
@@ -111,10 +113,6 @@
mFilterController.addListener(this);
}
- public boolean isSearchInOverflowMenu() {
- return mIsSearchInOverflowMenu;
- }
-
public boolean isSearchMode() {
return mSearchMode;
}
@@ -127,7 +125,7 @@
return;
}
if (mSearchMode) {
- mSearchView.requestFocus();
+ setFocusOnSearchView();
} else {
mSearchView.setQuery(null, false);
}
@@ -147,31 +145,20 @@
public void update() {
if (mSearchMode) {
- // If the search icon was in the overflow menu, then inflate a custom view containing
- // a search view for the action bar (and hide the tabs).
- if (mIsSearchInOverflowMenu) {
- if (mCustomSearchView == null) {
- mCustomSearchView = LayoutInflater.from(mContext).inflate(
- R.layout.custom_action_bar, null);
- mLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,
- LayoutParams.WRAP_CONTENT);
- SearchView searchView = (SearchView) mCustomSearchView.
- findViewById(R.id.search_view);
- searchView.setQueryHint(mContext.getString(R.string.hint_findContacts));
- setSearchView(searchView);
- }
- mActionBar.setDisplayShowCustomEnabled(true);
- mActionBar.setCustomView(mCustomSearchView, mLayoutParams);
- mSearchView.requestFocus();
- } else {
+ mActionBar.setDisplayShowCustomEnabled(true);
+ if (mAlwaysShowSearchView) {
+ // Tablet -- change the app title for the search mode
mActionBar.setTitle(mSearchLabelText);
+ } else {
+ // Phone -- search view gets focus
+ setFocusOnSearchView();
}
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
if (mListener != null) {
mListener.onAction(Action.START_SEARCH_MODE);
}
} else {
- mActionBar.setDisplayShowCustomEnabled(false);
+ mActionBar.setDisplayShowCustomEnabled(mAlwaysShowSearchView);
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mActionBar.setTitle(null);
if (mListener != null) {
@@ -236,4 +223,9 @@
@Override
public void onContactListFilterCustomizationRequest() {
}
+
+ private void setFocusOnSearchView() {
+ mSearchView.requestFocus();
+ mSearchView.setIconified(false); // Workaround for the "IME not popping up" issue.
+ }
}
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index d5bdd61..ad66956 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -303,7 +303,7 @@
setTitle(mRequest.getActivityTitle());
ActionBar actionBar = getActionBar();
mActionBarAdapter = new ActionBarAdapter(this, this);
- mActionBarAdapter.onCreate(savedState, mRequest, getActionBar(), !mContentPaneDisplayed);
+ mActionBarAdapter.onCreate(savedState, mRequest, getActionBar());
mActionBarAdapter.setContactListFilterController(mContactListFilterController);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
@@ -935,16 +935,6 @@
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.actions, menu);
- MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
- if (searchMenuItem != null && searchMenuItem.getActionView() instanceof SearchView) {
- SearchView searchView = (SearchView) searchMenuItem.getActionView();
- searchView.setQueryHint(getString(R.string.hint_findContacts));
- searchView.setIconifiedByDefault(false);
-
- if (mActionBarAdapter != null) {
- mActionBarAdapter.setSearchView(searchView);
- }
- }
// On narrow screens we specify a NEW group button in the {@link ActionBar}, so that
// it can be in the overflow menu. On wide screens, we use a custom view because we need
@@ -1009,10 +999,8 @@
if (mActionBarAdapter.isSearchMode()) {
addContactMenu.setVisible(false);
addGroupMenu.setVisible(false);
- // If search is normally in the overflow menu, when we are in search
- // mode, hide this option.
- if (mActionBarAdapter.isSearchInOverflowMenu()) {
- searchMenu.setVisible(false);
+ if (searchMenu != null) {
+ searchMenu.setVisible(false); // Don't show the search menu in search mode.
}
} else {
switch (mSelectedTab) {