Polishing text style and measuring for section headers.

- Added section header text color.
- Updated section headert style.
- Fixed selection bounds measurement in ContactListItemView.
- Deleted unused methods and imports in ContactListItemView.

Bug: 13956531
Change-Id: I1dea8691bb77fae90847474414ff6143c8fea5f5
diff --git a/src/com/android/contacts/common/list/ContactListItemView.java b/src/com/android/contacts/common/list/ContactListItemView.java
index 8ae26fd..462889c 100644
--- a/src/com/android/contacts/common/list/ContactListItemView.java
+++ b/src/com/android/contacts/common/list/ContactListItemView.java
@@ -22,20 +22,17 @@
 import android.database.CharArrayBuffer;
 import android.database.Cursor;
 import android.graphics.Canvas;
-import android.graphics.Color;
 import android.graphics.Rect;
 import android.graphics.Typeface;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.provider.ContactsContract;
 import android.provider.ContactsContract.Contacts;
-import android.telephony.PhoneNumberUtils;
 import android.text.Spannable;
 import android.text.SpannableString;
 import android.text.TextUtils;
 import android.text.TextUtils.TruncateAt;
 import android.util.AttributeSet;
-import android.util.TypedValue;
 import android.view.Gravity;
 import android.view.MotionEvent;
 import android.view.View;
@@ -99,10 +96,6 @@
      */
     private int mDataViewWidthWeight = 5;
 
-    // Will be used with adjustListItemSelectionBounds().
-    private int mSelectionBoundsMarginLeft;
-    private int mSelectionBoundsMarginRight;
-
     protected static class HighlightSequence {
         private final int start;
         private final int end;
@@ -314,7 +307,7 @@
         ensurePhotoViewSize();
 
         // Width each TextView is able to use.
-        final int effectiveWidth;
+        int effectiveWidth;
         // All the other Views will honor the photo, so available width for them may be shrunk.
         if (mPhotoViewWidth > 0 || mKeepHorizontalPaddingForPhotoView) {
             effectiveWidth = specWidth - getPaddingLeft() - getPaddingRight()
@@ -323,11 +316,15 @@
             effectiveWidth = specWidth - getPaddingLeft() - getPaddingRight();
         }
 
+        if (mIsSectionHeaderEnabled) {
+            effectiveWidth -= mHeaderWidth + mGapBetweenImageAndText;
+        }
+
         // Go over all visible text views and measure actual width of each of them.
         // Also calculate their heights to get the total height for this entire view.
 
         if (isVisible(mNameTextView)) {
-            // Caculate width for name text - this parallels similar measurement in onLayout.
+            // Claculate width for name text - this parallels similar measurement in onLayout.
             int nameTextWidth = effectiveWidth;
             if (mPhotoPosition != PhotoPosition.LEFT) {
                 nameTextWidth -= mTextIndent;
@@ -467,7 +464,15 @@
             }
         }
 
-        mBoundsWithoutHeader.set(leftBound, topBound, width, bottomBound);
+        mBoundsWithoutHeader.set(leftBound, topBound, rightBound, bottomBound);
+
+        if (mIsSectionHeaderEnabled) {
+            if (isLayoutRtl) {
+                rightBound -= mGapBetweenImageAndText;
+            } else {
+                leftBound += mGapBetweenImageAndText;
+            }
+        }
 
         if (mActivatedStateSupported && isActivated()) {
             mActivatedBackgroundDrawable.setBounds(mBoundsWithoutHeader);
@@ -619,8 +624,8 @@
     public void adjustListItemSelectionBounds(Rect bounds) {
         bounds.top += mBoundsWithoutHeader.top;
         bounds.bottom = bounds.top + mBoundsWithoutHeader.height();
-        bounds.left += mSelectionBoundsMarginLeft;
-        bounds.right -= mSelectionBoundsMarginRight;
+        bounds.left = mBoundsWithoutHeader.left;
+        bounds.right = mBoundsWithoutHeader.right;
     }
 
     protected boolean isVisible(View view) {
@@ -700,7 +705,8 @@
             if (mHeaderTextView == null) {
                 mHeaderTextView = new TextView(getContext());
                 mHeaderTextView.setTextAppearance(getContext(), R.style.SectionHeaderStyle);
-                mHeaderTextView.setGravity(Gravity.CENTER);
+                mHeaderTextView.setGravity(Gravity.CENTER_VERTICAL |
+                        (ViewUtil.isViewLayoutRtl(this) ? Gravity.RIGHT : Gravity.LEFT));
                 addView(mHeaderTextView);
             }
             setMarqueeText(mHeaderTextView, title);
@@ -1383,15 +1389,6 @@
     }
 
     /**
-     * Specifies left and right margin for selection bounds. See also
-     * {@link #adjustListItemSelectionBounds(Rect)}.
-     */
-    public void setSelectionBoundsHorizontalMargin(int left, int right) {
-        mSelectionBoundsMarginLeft = left;
-        mSelectionBoundsMarginRight = right;
-    }
-
-    /**
      * Set drawable resources directly for both the background and the drawable resource
      * of the photo view
      *
diff --git a/src/com/android/contacts/common/list/ContactListPinnedHeaderView.java b/src/com/android/contacts/common/list/ContactListPinnedHeaderView.java
index 6f6e551..e0c3e1a 100644
--- a/src/com/android/contacts/common/list/ContactListPinnedHeaderView.java
+++ b/src/com/android/contacts/common/list/ContactListPinnedHeaderView.java
@@ -27,6 +27,7 @@
 import android.widget.TextView;
 
 import com.android.contacts.common.R;
+import com.android.contacts.common.util.ViewUtil;
 
 /**
  * A custom view for the pinned section header shown at the top of the contact list.
@@ -42,11 +43,12 @@
         a.recycle();
 
         setBackgroundColor(backgroundColor);
-        setTextAppearance(getContext(), R.style.DirectoryHeaderStyle);
+        setTextAppearance(getContext(), R.style.SectionHeaderStyle);
         setLayoutParams(new LayoutParams(
                 getResources().getDimensionPixelSize(R.dimen.contact_list_section_header_width),
                 LayoutParams.WRAP_CONTENT));
-        setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER);
+        setGravity(Gravity.CENTER_VERTICAL |
+                (ViewUtil.isViewLayoutRtl(this) ? Gravity.RIGHT : Gravity.LEFT));
     }
 
     /**