Fix cosmetic glitch in the Call log with SIP addresses

When there's no "label" field to display (like "Home" or "Work"), we were
setting the visibility of that TextView to GONE.  But that's a bad idea,
since we still need it as a RelativeLayout anchor for the "number" field
next to it.  This was causing SIP addresses to move all the way to the
left edge of the screen, where they collide with the "expand" icon.

(I sanity-checked the other RelativeLayout positioning in
recent_calls_list_item_layout.xml, and the only other time we use
visibility=GONE is when that whole bottom row is missing, so we won't have
this same issue there.)

Now the "label" field is INVISIBLE (not GONE) when there's no label to
show.

Also, when there's no label to show we don't need any extra margin
*between* the label and the number.  So in that case, add some negative
left margin to the number view in order to undo the right margin added by
the label view.

TESTED: all combinations of { groups , non-groups } and { real phone
  numbers , SIP addresses } and the label and/or number are now all
  correctly aligned.

Bug: 3062630

Change-Id: I760356ded7b510b08c0791b942507f25ab3a4a4a
diff --git a/res/layout-finger/recent_calls_list_group_item.xml b/res/layout-finger/recent_calls_list_group_item.xml
index 2d3e7af..79e7bb9 100644
--- a/res/layout-finger/recent_calls_list_group_item.xml
+++ b/res/layout-finger/recent_calls_list_group_item.xml
@@ -60,6 +60,7 @@
         android:layout_alignParentLeft="true"
         android:layout_alignParentBottom="true"
         android:layout_marginLeft="36dip"
+        android:layout_marginRight="5dip"
         android:layout_alignBaseline="@id/date"
 
         android:singleLine="true"
@@ -71,7 +72,6 @@
     <TextView android:id="@+id/number"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginLeft="5dip"
         android:layout_toRightOf="@id/label"
         android:layout_toLeftOf="@id/date"
         android:layout_alignBaseline="@id/label"
diff --git a/res/layout-finger/recent_calls_list_item_layout.xml b/res/layout-finger/recent_calls_list_item_layout.xml
index 7463669..faaa893 100644
--- a/res/layout-finger/recent_calls_list_item_layout.xml
+++ b/res/layout-finger/recent_calls_list_item_layout.xml
@@ -52,6 +52,7 @@
         android:layout_alignParentLeft="true"
         android:layout_alignParentBottom="true"
         android:layout_marginLeft="36dip"
+        android:layout_marginRight="5dip"
         android:layout_alignBaseline="@id/date"
 
         android:singleLine="true"
@@ -63,7 +64,6 @@
     <TextView android:id="@+id/number"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginLeft="5dip"
         android:layout_toRightOf="@id/label"
         android:layout_toLeftOf="@id/date"
         android:layout_alignBaseline="@id/label"
diff --git a/src/com/android/contacts/RecentCallsListActivity.java b/src/com/android/contacts/RecentCallsListActivity.java
index 8e7b4bc..145ff69 100644
--- a/src/com/android/contacts/RecentCallsListActivity.java
+++ b/src/com/android/contacts/RecentCallsListActivity.java
@@ -686,8 +686,33 @@
                 if (!TextUtils.isEmpty(numberLabel)) {
                     views.labelView.setText(numberLabel);
                     views.labelView.setVisibility(View.VISIBLE);
+
+                    // Zero out the numberView's left margin (see below)
+                    ViewGroup.MarginLayoutParams numberLP =
+                            (ViewGroup.MarginLayoutParams) views.numberView.getLayoutParams();
+                    numberLP.leftMargin = 0;
+                    views.numberView.setLayoutParams(numberLP);
                 } else {
-                    views.labelView.setVisibility(View.GONE);
+                    // There's nothing to display in views.labelView, so hide it.
+                    // We can't set it to View.GONE, since it's the anchor for
+                    // numberView in the RelativeLayout, so make it INVISIBLE.
+                    //   Also, we need to manually *subtract* some left margin from
+                    // numberView to compensate for the right margin built in to
+                    // labelView (otherwise the number will be indented by a very
+                    // slight amount).
+                    //   TODO: a cleaner fix would be to contain both the label and
+                    // number inside a LinearLayout, and then set labelView *and*
+                    // its padding to GONE when there's no label to display.
+                    views.labelView.setText(null);
+                    views.labelView.setVisibility(View.INVISIBLE);
+
+                    ViewGroup.MarginLayoutParams labelLP =
+                            (ViewGroup.MarginLayoutParams) views.labelView.getLayoutParams();
+                    ViewGroup.MarginLayoutParams numberLP =
+                            (ViewGroup.MarginLayoutParams) views.numberView.getLayoutParams();
+                    // Equivalent to setting android:layout_marginLeft in XML
+                    numberLP.leftMargin = -labelLP.rightMargin;
+                    views.numberView.setLayoutParams(numberLP);
                 }
             } else {
                 if (number.equals(CallerInfo.UNKNOWN_NUMBER)) {