Fix scrolling in blocked numbers list.

+ Add elements as header, so they scroll with the list.
+ Shuffle around some layouts to make this work correctly.
+ Replace default ListView divider with custom drawable, to achieve
the desired effect of removing the divider on the first list item.
+ Override BlockedNumberAdapter to never report itself as empty.
Otherwise, the header will disappear.
+ Tweak some padding.

Bug: 25134186
Change-Id: I07711437fea2d3042d3987983667ab5316d51fcc
diff --git a/res/drawable/blocked_number_item_background.xml b/res/drawable/blocked_number_item_background.xml
new file mode 100644
index 0000000..acfea20
--- /dev/null
+++ b/res/drawable/blocked_number_item_background.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <solid android:color="@color/divider_line_color" />
+        </shape>
+    </item>
+    <item android:bottom="1dp">
+        <shape android:shape="rectangle">
+            <solid android:color="@android:color/white" />
+        </shape>
+    </item>
+</layer-list>
diff --git a/res/layout/blocked_number_fragment.xml b/res/layout/blocked_number_fragment.xml
index e41d6bc..b98b58f 100644
--- a/res/layout/blocked_number_fragment.xml
+++ b/res/layout/blocked_number_fragment.xml
@@ -14,7 +14,6 @@
      limitations under the License.
 -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:card_view="http://schemas.android.com/apk/res-auto"
     android:id="@+id/blocked_number_fragment"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
@@ -22,67 +21,18 @@
     android:paddingTop="?android:attr/actionBarSize"
     android:background="@color/blocked_number_background">
 
-    <android.support.v7.widget.CardView
-        android:id="@+id/hide_blocked_calls_setting"
+    <ListView android:id="@id/android:list"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginBottom="8dp"
-        card_view:cardCornerRadius="0dp">
+        android:divider="@null"
+        android:headerDividersEnabled="false" />
 
-        <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="horizontal"
-            android:gravity="center_vertical"
-            android:padding="16dp"
-            android:paddingEnd="8dp">
-
-            <TextView
-                android:layout_width="0dp"
-                android:layout_height="wrap_content"
-                android:layout_weight="1"
-                android:text="@string/blocked_call_settings_hide_setting"
-                style="@style/BlockedNumbersDescriptionTextStyle" />
-
-            <Switch android:id="@+id/hide_blocked_calls_switch"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_marginLeft="40dp" />
-
-        </LinearLayout>
-
-    </android.support.v7.widget.CardView>
-
-    <android.support.v7.widget.CardView
+    <TextView android:id="@android:id/empty"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        card_view:cardCornerRadius="0dp">
-
-        <LinearLayout
-            android:orientation="vertical"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:background="@color/background_dialer_white">
-
-            <include layout="@layout/blocked_number_header" />
-
-            <ListView android:id="@id/android:list"
-                android:layout_width="match_parent"
-                android:layout_height="0dp"
-                android:layout_weight="1"
-                android:drawSelectorOnTop="false"
-                android:headerDividersEnabled="false" />
-
-            <TextView android:id="@android:id/empty"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:paddingStart="@dimen/blocked_number_horizontal_margin"
-                android:paddingTop="@dimen/blocked_number_top_margin"
-                android:paddingBottom="@dimen/blocked_number_bottom_margin"
-                android:text="@string/listNoBlockedNumbers" />
-
-        </LinearLayout>
-
-    </android.support.v7.widget.CardView>
+        android:layout_height="match_parent"
+        android:paddingStart="@dimen/blocked_number_horizontal_margin"
+        android:paddingTop="@dimen/blocked_number_top_margin"
+        android:paddingBottom="@dimen/blocked_number_bottom_margin"
+        android:text="@string/listNoBlockedNumbers" />
 
 </LinearLayout>
diff --git a/res/layout/blocked_number_header.xml b/res/layout/blocked_number_header.xml
index e16efbc..3fcdf39 100644
--- a/res/layout/blocked_number_header.xml
+++ b/res/layout/blocked_number_header.xml
@@ -13,63 +13,114 @@
      See the License for the specific language governing permissions and
      limitations under the License.
 -->
-<merge xmlns:android="http://schemas.android.com/apk/res/android">
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:card_view="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical">
 
-    <TextView android:id="@+id/textView"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/blockList"
-        android:textColor="@color/blocked_number_header_color"
-        android:padding="@dimen/blocked_number_container_padding"
-        style="@android:style/TextAppearance.Material.Subhead" />
-
-    <RelativeLayout android:id="@+id/import_settings"
+    <android.support.v7.widget.CardView
+        android:id="@+id/hide_blocked_calls_setting"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:visibility="gone">
+        android:layout_marginBottom="8dp"
+        card_view:cardCornerRadius="0dp">
 
-        <TextView android:id="@+id/import_description"
+        <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:text="@string/blocked_call_settings_import_description"
-            android:textSize="@dimen/blocked_number_settings_description_text_size"
-            android:paddingStart="@dimen/blocked_number_container_padding"
-            android:paddingEnd="@dimen/blocked_number_container_padding"
-            style="@style/BlockedNumbersDescriptionTextStyle" />
+            android:orientation="horizontal"
+            android:gravity="center_vertical"
+            android:padding="16dp"
+            android:paddingEnd="8dp"
+            android:background="@android:color/white">
 
-        <Button android:id="@+id/import_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@id/import_description"
-            android:layout_alignParentEnd="true"
-            android:layout_marginEnd="@dimen/blocked_number_container_padding"
-            android:text="@string/blocked_call_settings_import_button"
-            style="@style/DialerFlatButtonStyle" />
+            <TextView
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:text="@string/blocked_call_settings_hide_setting"
+                style="@style/BlockedNumbersDescriptionTextStyle" />
 
-        <Button android:id="@+id/view_numbers_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@id/import_description"
-            android:layout_toLeftOf="@id/import_button"
-            android:text="@string/blocked_call_settings_view_numbers_button"
-            style="@style/DialerFlatButtonStyle" />
+            <Switch android:id="@+id/hide_blocked_calls_switch"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="40dp" />
 
-        <View
-            android:layout_width="match_parent"
-            android:layout_height="1dp"
-            android:layout_below="@id/import_button"
-            android:background="@color/divider_line_color"
-            android:layout_marginTop="8dp"
-            android:layout_marginBottom="8dp" />
+        </LinearLayout>
 
-    </RelativeLayout>
+    </android.support.v7.widget.CardView>
 
-    <Button android:id="@+id/add_number_button"
-        android:layout_width="wrap_content"
+    <android.support.v7.widget.CardView
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_gravity="end"
-        android:layout_marginEnd="@dimen/blocked_number_container_padding"
-        android:layout_marginTop="8dp"
-        android:text="@string/blockNumber" />
+        card_view:cardCornerRadius="0dp">
 
-</merge>
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical"
+            android:background="@android:color/white">
+
+            <TextView android:id="@+id/textView"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/blockList"
+                android:textColor="@color/blocked_number_header_color"
+                android:padding="@dimen/blocked_number_container_padding"
+                style="@android:style/TextAppearance.Material.Subhead" />
+
+            <RelativeLayout android:id="@+id/import_settings"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:visibility="gone">
+
+                <TextView android:id="@+id/import_description"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:text="@string/blocked_call_settings_import_description"
+                    android:textSize="@dimen/blocked_number_settings_description_text_size"
+                    android:paddingStart="@dimen/blocked_number_container_padding"
+                    android:paddingEnd="@dimen/blocked_number_container_padding"
+                    style="@style/BlockedNumbersDescriptionTextStyle" />
+
+                <Button android:id="@+id/import_button"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/import_description"
+                    android:layout_alignParentEnd="true"
+                    android:layout_marginEnd="@dimen/blocked_number_container_padding"
+                    android:text="@string/blocked_call_settings_import_button"
+                    style="@style/DialerFlatButtonStyle" />
+
+                <Button android:id="@+id/view_numbers_button"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/import_description"
+                    android:layout_toLeftOf="@id/import_button"
+                    android:text="@string/blocked_call_settings_view_numbers_button"
+                    style="@style/DialerFlatButtonStyle" />
+
+                <View
+                    android:layout_width="match_parent"
+                    android:layout_height="1dp"
+                    android:layout_below="@id/import_button"
+                    android:background="@color/divider_line_color"
+                    android:layout_marginTop="8dp"
+                    android:layout_marginBottom="8dp" />
+
+            </RelativeLayout>
+
+            <Button android:id="@+id/add_number_button"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_gravity="end"
+                android:layout_marginEnd="@dimen/blocked_number_container_padding"
+                android:layout_marginBottom="8dp"
+                android:text="@string/blockNumber" />
+
+        </LinearLayout>
+
+    </android.support.v7.widget.CardView>
+
+</LinearLayout>
diff --git a/res/layout/blocked_number_item.xml b/res/layout/blocked_number_item.xml
index 6c87533..79ca42e 100644
--- a/res/layout/blocked_number_item.xml
+++ b/res/layout/blocked_number_item.xml
@@ -25,7 +25,7 @@
     android:gravity="center_vertical"
     android:orientation="horizontal"
     android:focusable="true"
-    android:background="@color/background_dialer_white">
+    android:background="@drawable/blocked_number_item_background">
 
     <QuickContactBadge
         android:id="@+id/quick_contact_photo"
diff --git a/res/layout/view_numbers_to_import_fragment.xml b/res/layout/view_numbers_to_import_fragment.xml
index fae708b..c79e69a 100644
--- a/res/layout/view_numbers_to_import_fragment.xml
+++ b/res/layout/view_numbers_to_import_fragment.xml
@@ -25,6 +25,7 @@
         android:layout_width="match_parent"
         android:layout_height="0dp"
         android:layout_weight="1"
+        android:divider="@null"
         android:headerDividersEnabled="false" />
 
     <RelativeLayout
diff --git a/src/com/android/dialer/filterednumber/BlockedNumberAdapter.java b/src/com/android/dialer/filterednumber/BlockedNumberAdapter.java
index 6cd99c6..7777aeb 100644
--- a/src/com/android/dialer/filterednumber/BlockedNumberAdapter.java
+++ b/src/com/android/dialer/filterednumber/BlockedNumberAdapter.java
@@ -64,7 +64,7 @@
                         normalizedNumber,
                         number,
                         countryIso,
-                        null,
+                        number,
                         R.id.blocked_number_fragment,
                         getFragmentManager(),
                         null /* callback */);
@@ -73,4 +73,10 @@
 
         updateView(view, number, countryIso);
     }
+
+    @Override
+    public boolean isEmpty() {
+        // Always return false, so that the header with blocking-related options always shows.
+        return false;
+    }
 }
diff --git a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java
index 2f7b2f1..c478b83 100644
--- a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java
+++ b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java
@@ -57,6 +57,10 @@
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
+        LayoutInflater inflater =
+                (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        getListView().addHeaderView(inflater.inflate(R.layout.blocked_number_header, null));
+
         if (mAdapter == null) {
             mAdapter = BlockedNumberAdapter.newBlockedNumberAdapter(
                     getContext(), getActivity().getFragmentManager());