Highlight search texts in search result

PeopleActivity does it.

Change-Id: I2d4523ace783c2b622e0d0e0cd17fb61d1155c0a
diff --git a/src/com/android/contacts/activities/DialtactsActivity.java b/src/com/android/contacts/activities/DialtactsActivity.java
index d1b0c23..c912c2e 100644
--- a/src/com/android/contacts/activities/DialtactsActivity.java
+++ b/src/com/android/contacts/activities/DialtactsActivity.java
@@ -96,19 +96,10 @@
     private StrequentContactListFragment mStrequentFragment;
 
     /**
-     * The index of the tab that has last been manually selected (the user clicked on a tab).
-     * This value does not keep track of programmatically set Tabs (e.g. Call Log after a Call)
-     */
-    private int mLastManuallySelectedTab;
-
-    /**
      * Fragment for searching phone numbers. Unlike the other Fragments, this doesn't correspond
      * to tab but is shown by a search action.
      */
     private PhoneNumberPickerFragment mPhoneNumberPickerFragment;
-
-    private SearchView mSearchView;
-
     /**
      * True when this Activity is in its search UI (with a {@link SearchView} and
      * {@link PhoneNumberPickerFragment}).
@@ -116,6 +107,14 @@
     private boolean mInSearchUi;
 
     /**
+     * The index of the tab that has last been manually selected (the user clicked on a tab).
+     * This value does not keep track of programmatically set Tabs (e.g. Call Log after a Call)
+     */
+    private int mLastManuallySelectedTab;
+
+    private SearchView mSearchView;
+
+    /**
      * Listener used when one of phone numbers in search UI is selected. This will initiate a
      * phone call using the phone number.
      */
@@ -203,6 +202,7 @@
                 .findFragmentById(R.id.phone_number_picker_fragment);
         mPhoneNumberPickerFragment.setOnPhoneNumberPickerActionListener(
                 mPhoneNumberPickerActionListener);
+        mPhoneNumberPickerFragment.setHighlightSearchPrefix(true);
 
         // Hide all tabs (the current tab will later be reshown once a tab is selected)
         final FragmentTransaction transaction = fragmentManager.beginTransaction();
diff --git a/src/com/android/contacts/list/PhoneNumberListAdapter.java b/src/com/android/contacts/list/PhoneNumberListAdapter.java
index c159ac8..fee1064 100644
--- a/src/com/android/contacts/list/PhoneNumberListAdapter.java
+++ b/src/com/android/contacts/list/PhoneNumberListAdapter.java
@@ -60,6 +60,7 @@
     private CharSequence mUnknownNameText;
     private int mDisplayNameColumnIndex;
     private int mAlternativeDisplayNameColumnIndex;
+    private boolean mHighlightSearchPrefix;
 
     public PhoneNumberListAdapter(Context context) {
         super(context);
@@ -157,6 +158,9 @@
     protected void bindView(View itemView, int partition, Cursor cursor, int position) {
         ContactListItemView view = (ContactListItemView)itemView;
 
+        view.setHighlightedPrefix(mHighlightSearchPrefix && isSearchMode() ?
+                getUpperCaseQueryString() : null);
+
         // Look at elements before and after this position, checking if contact IDs are same.
         // If they have one same contact ID, it means they can be grouped.
         //
@@ -245,4 +249,8 @@
     protected void unbindPhoto(final ContactListItemView view) {
         view.removePhotoView(true, false);
     }
+
+    public void setHighlightSearchPrefix(boolean highlight) {
+        mHighlightSearchPrefix = highlight;
+    }
 }
diff --git a/src/com/android/contacts/list/PhoneNumberPickerFragment.java b/src/com/android/contacts/list/PhoneNumberPickerFragment.java
index a38f734..b40f80a 100644
--- a/src/com/android/contacts/list/PhoneNumberPickerFragment.java
+++ b/src/com/android/contacts/list/PhoneNumberPickerFragment.java
@@ -111,4 +111,13 @@
     public void onPickerResult(Intent data) {
         mListener.onPickPhoneNumberAction(data.getData());
     }
+
+    public void setHighlightSearchPrefix(boolean highlight) {
+        if (!isLegacyCompatibilityMode()) {
+            PhoneNumberListAdapter adapter = (PhoneNumberListAdapter)getAdapter();
+            adapter.setHighlightSearchPrefix(highlight);
+        } else {
+            // Not supported.
+        }
+    }
 }