Adds extra padding to top entry if no title

Bug: 16679107
Change-Id: Id5bff96d419acd27b179f7f2913b08b61afe09c5
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 6439c1d..0a5403b 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -144,6 +144,8 @@
     <dimen name="expanding_entry_card_title_text_size">16sp</dimen>
     <!-- Padding for the title text for a ExpandingEntryCardView -->
     <dimen name="expanding_entry_card_title_padding">16dp</dimen>
+    <!-- Extra top padding if the title is set to null -->
+    <dimen name="expanding_entry_card_null_title_top_extra_padding">2dp</dimen>
 
     <!-- Height of the separator between entries in an ExpandingEntryCardView -->
     <dimen name="expanding_entry_card_item_separator_height">1dp</dimen>
diff --git a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
index 9891a8f..7501bb8 100644
--- a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
+++ b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
@@ -353,6 +353,15 @@
     }
 
     private void addEntry(View entry) {
+        // If no title and the first entry in the group, add extra padding
+        if (TextUtils.isEmpty(mTitleTextView.getText()) &&
+                mEntriesViewGroup.getChildCount() == 0) {
+            entry.setPadding(entry.getPaddingLeft(),
+                    entry.getPaddingTop() + getResources().getDimensionPixelSize(
+                            R.dimen.expanding_entry_card_null_title_top_extra_padding),
+                    entry.getPaddingRight(),
+                    entry.getPaddingBottom());
+        }
         mEntriesViewGroup.addView(entry);
     }
 
@@ -786,13 +795,30 @@
         if (mTitleTextView == null) {
             Log.e(TAG, "mTitleTextView is null");
         }
-        if (title == null) {
-            mTitleTextView.setVisibility(View.GONE);
-            findViewById(R.id.title_separator).setVisibility(View.GONE);
-        }
         mTitleTextView.setText(title);
-        mTitleTextView.setVisibility(View.VISIBLE);
-        findViewById(R.id.title_separator).setVisibility(View.VISIBLE);
+        mTitleTextView.setVisibility(TextUtils.isEmpty(title) ? View.GONE : View.VISIBLE);
+        findViewById(R.id.title_separator).setVisibility(TextUtils.isEmpty(title) ?
+                View.GONE : View.VISIBLE);
+        // If the title is set after children have been added, reset the top entry's padding to
+        // the default. Else if the title is cleared after children have been added, set
+        // the extra top padding
+        if (!TextUtils.isEmpty(title) && mEntriesViewGroup.getChildCount() > 0) {
+            View firstEntry = mEntriesViewGroup.getChildAt(0);
+            firstEntry.setPadding(firstEntry.getPaddingLeft(),
+                    getResources().getDimensionPixelSize(
+                            R.dimen.expanding_entry_card_item_padding_top),
+                    firstEntry.getPaddingRight(),
+                    firstEntry.getPaddingBottom());
+        } else if (!TextUtils.isEmpty(title) && mEntriesViewGroup.getChildCount() > 0) {
+            View firstEntry = mEntriesViewGroup.getChildAt(0);
+            firstEntry.setPadding(firstEntry.getPaddingLeft(),
+                    getResources().getDimensionPixelSize(
+                            R.dimen.expanding_entry_card_item_padding_top) +
+                            getResources().getDimensionPixelSize(
+                                    R.dimen.expanding_entry_card_null_title_top_extra_padding),
+                    firstEntry.getPaddingRight(),
+                    firstEntry.getPaddingBottom());
+        }
     }
 
     public boolean shouldShow() {