Use new search pattern in People app
- Magnifying glass should go inside the EditText field
- "Done" button on keyboard should hide the keyboard
- When going to a search result (contact card),
the "up" button should return to the search results
and not relaunch PeopleActivity
Bug: 5081198
Change-Id: I32e103c39c40da26bfd12f1fa8cef000f33ee1c9
diff --git a/src/com/android/contacts/activities/ActionBarAdapter.java b/src/com/android/contacts/activities/ActionBarAdapter.java
index 6d28235..5a32d74 100644
--- a/src/com/android/contacts/activities/ActionBarAdapter.java
+++ b/src/com/android/contacts/activities/ActionBarAdapter.java
@@ -31,6 +31,7 @@
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.inputmethod.InputMethodManager;
import android.widget.SearchView;
import android.widget.SearchView.OnCloseListener;
import android.widget.SearchView.OnQueryTextListener;
@@ -112,6 +113,12 @@
}
LayoutParams layoutParams = new LayoutParams(searchViewWidth, LayoutParams.WRAP_CONTENT);
mSearchView = (SearchView) customSearchView.findViewById(R.id.search_view);
+ // Since the {@link SearchView} in this app is "click-to-expand", set the below mode on the
+ // {@link SearchView} so that the magnifying glass icon appears inside the editable text
+ // field. (In the "click-to-expand" search pattern, the user must explicitly expand the
+ // search field and already knows a search is being conducted, so the icon is redundant
+ // and can go away once the user starts typing.)
+ mSearchView.setIconifiedByDefault(true);
mSearchView.setQueryHint(mContext.getString(R.string.hint_findContacts));
mSearchView.setOnQueryTextListener(this);
mSearchView.setOnCloseListener(this);
@@ -265,6 +272,9 @@
private void update() {
if (mSearchMode) {
setFocusOnSearchView();
+ // Since we have the {@link SearchView} in a custom action bar, we must manually handle
+ // expanding the {@link SearchView} when a search is initiated.
+ mSearchView.onActionViewExpanded();
if (mActionBar.getNavigationMode() != ActionBar.NAVIGATION_MODE_STANDARD) {
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
@@ -287,6 +297,9 @@
mTabListener.mIgnoreTabSelected = false;
}
mActionBar.setTitle(null);
+ // Since we have the {@link SearchView} in a custom action bar, we must manually handle
+ // collapsing the {@link SearchView} when search mode is exited.
+ mSearchView.onActionViewCollapsed();
if (mListener != null) {
mListener.onAction(Action.STOP_SEARCH_MODE);
mListener.onSelectedTabChanged();
@@ -317,6 +330,16 @@
@Override
public boolean onQueryTextSubmit(String query) {
+ // When the search is "committed" by the user, then hide the keyboard so the user can
+ // more easily browse the list of results.
+ if (mSearchView != null) {
+ InputMethodManager imm = (InputMethodManager) mContext.getSystemService(
+ Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
+ }
+ mSearchView.clearFocus();
+ }
return true;
}
diff --git a/src/com/android/contacts/activities/ContactDetailActivity.java b/src/com/android/contacts/activities/ContactDetailActivity.java
index c4330f9..797971c 100644
--- a/src/com/android/contacts/activities/ContactDetailActivity.java
+++ b/src/com/android/contacts/activities/ContactDetailActivity.java
@@ -66,6 +66,13 @@
public class ContactDetailActivity extends ContactsActivity {
private static final String TAG = "ContactDetailActivity";
+ /**
+ * Intent key for a boolean that specifies whether the "up" afforance in this activity should
+ * behave as default (return user back to {@link PeopleActivity}) or whether the activity should
+ * instead be finished.
+ */
+ public static final String INTENT_KEY_IGNORE_DEFAULT_UP_BEHAVIOR = "ignoreDefaultUpBehavior";
+
private static final String KEY_DETAIL_FRAGMENT_TAG = "detailFragTag";
private static final String KEY_UPDATES_FRAGMENT_TAG = "updatesFragTag";
@@ -73,6 +80,7 @@
private ContactLoader.Result mContactData;
private Uri mLookupUri;
+ private boolean mIgnoreDefaultUpBehavior;
private ContactLoaderFragment mLoaderFragment;
private ContactDetailFragment mDetailFragment;
@@ -115,6 +123,9 @@
return;
}
+ mIgnoreDefaultUpBehavior = getIntent().getBooleanExtra(
+ INTENT_KEY_IGNORE_DEFAULT_UP_BEHAVIOR, false);
+
setContentView(R.layout.contact_detail_activity);
mRootView = (ViewGroup) findViewById(R.id.contact_detail_view);
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@@ -530,6 +541,10 @@
switch (item.getItemId()) {
case android.R.id.home:
+ if (mIgnoreDefaultUpBehavior) {
+ finish();
+ return true;
+ }
Intent intent = new Intent(this, PeopleActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 6a0d7ad..5ad8ab5 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -960,7 +960,15 @@
if (PhoneCapabilityTester.isUsingTwoPanes(PeopleActivity.this)) {
setupContactDetailFragment(contactLookupUri);
} else {
- startActivity(new Intent(Intent.ACTION_VIEW, contactLookupUri));
+ Intent intent = new Intent(Intent.ACTION_VIEW, contactLookupUri);
+ // In search mode, the "up" affordance in the contact detail page should return the
+ // user to the search results, so suppress the normal behavior which would re-launch
+ // {@link PeopleActivity} when the "up" affordance is clicked.
+ if (mActionBarAdapter.isSearchMode()) {
+ intent.putExtra(ContactDetailActivity.INTENT_KEY_IGNORE_DEFAULT_UP_BEHAVIOR,
+ true);
+ }
+ startActivity(intent);
}
}