Bring account view up to spec (E2)

* Use elevation instead of divider for list header
* Change icon size and margin programmatically.

Bug 30358448

Change-Id: Ib707c116c23ee39d43c265a5c26184d6944bedc0
diff --git a/res/drawable/account_header_background.xml b/res/drawable/account_header_background.xml
deleted file mode 100644
index af72c6d..0000000
--- a/res/drawable/account_header_background.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<!--
-  ~ Copyright (C) 2016 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/list_item_account_header_border_color" />
-        </shape>
-    </item>
-    <item android:bottom="1dp">
-        <shape android:shape="rectangle">
-            <solid android:color="@color/background_primary" />
-        </shape>
-    </item>
-</layer-list>
\ No newline at end of file
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 8089a2e..0d1b6ea 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -60,9 +60,6 @@
     <!-- Background color of pinned header items. -->
     <color name="list_item_pinned_header_color">@color/background_primary</color>
 
-    <!-- 8% black. -->
-    <color name="list_item_account_header_border_color">#15000000</color>
-
     <!-- Color of the mime-type icons inside the editor. 50% black. -->
     <color name="editor_icon_color">#7f7f7f</color>
 
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index a3b097f..a30b045 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -292,4 +292,7 @@
 
     <!-- Minimum height for group name EditText -->
     <dimen name="group_name_edit_text_min_height">48dp</dimen>
+
+    <!-- Elevation of contact list header -->
+    <dimen name="contact_list_header_elevation">2dp</dimen>
 </resources>
diff --git a/src/com/android/contacts/list/MultiSelectContactsListFragment.java b/src/com/android/contacts/list/MultiSelectContactsListFragment.java
index 2612cf2..937d4c2 100644
--- a/src/com/android/contacts/list/MultiSelectContactsListFragment.java
+++ b/src/com/android/contacts/list/MultiSelectContactsListFragment.java
@@ -30,12 +30,13 @@
 
 import android.content.Context;
 import android.database.Cursor;
-import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.provider.ContactsContract;
+import android.support.v4.view.ViewCompat;
 import android.util.Log;
 import android.view.View;
+import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityEvent;
 import android.widget.AbsListView;
 import android.widget.ImageView;
@@ -291,11 +292,10 @@
             return;
         }
         if (firstVisibleItem == 0) {
-            accountFilterContainer.setBackground(
-                    new ColorDrawable(getResources().getColor(R.color.background_primary)));
+            ViewCompat.setElevation(accountFilterContainer, 0);
         } else {
-            accountFilterContainer.setBackground(
-                    getResources().getDrawable(R.drawable.account_header_background));
+            ViewCompat.setElevation(accountFilterContainer,
+                    getResources().getDimension(R.dimen.contact_list_header_elevation));
         }
     }
 
@@ -343,10 +343,49 @@
         final Drawable icon = accountType != null ? accountType.getDisplayIcon(context) : null;
         final ImageView accountFilterHeaderIcon = (ImageView) accountFilterContainer
                 .findViewById(R.id.account_filter_icon);
+
+        // If it's a writable Google account, we set icon size as 24dp; otherwise, we set it as
+        // 20dp. And we need to change margin accordingly. This is because the Google icon looks
+        // smaller when the icons are of the same size.
+        if (accountType instanceof GoogleAccountType) {
+            accountFilterHeaderIcon.getLayoutParams().height = getResources()
+                    .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_size);
+            accountFilterHeaderIcon.getLayoutParams().width =
+                    accountFilterHeaderIcon.getLayoutParams().height;
+
+            setMargins(accountFilterHeaderIcon,
+                    getResources().getDimensionPixelOffset(
+                            R.dimen.contact_browser_list_header_icon_left_margin),
+                    getResources().getDimensionPixelOffset(
+                            R.dimen.contact_browser_list_header_icon_right_margin));
+        } else {
+            accountFilterHeaderIcon.getLayoutParams().height = getResources()
+                    .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_size_alt);
+            accountFilterHeaderIcon.getLayoutParams().width =
+                    accountFilterHeaderIcon.getLayoutParams().height;
+
+            setMargins(accountFilterHeaderIcon,
+                    getResources().getDimensionPixelOffset(
+                            R.dimen.contact_browser_list_header_icon_left_margin_alt),
+                    getResources().getDimensionPixelOffset(
+                            R.dimen.contact_browser_list_header_icon_right_margin_alt));
+        }
+        accountFilterHeaderIcon.requestLayout();
+
         accountFilterHeaderIcon.setVisibility(View.VISIBLE);
         accountFilterHeaderIcon.setImageDrawable(icon);
     }
 
+    private void setMargins(View v, int l, int r) {
+        if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
+            ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
+            p.setMarginStart(l);
+            p.setMarginEnd(r);
+            v.setLayoutParams(p);
+            v.requestLayout();
+        }
+    }
+
     private void bindListHeaderCommon(View listView, View accountFilterContainer) {
         // Show header and remove top padding of the list
         accountFilterContainer.setVisibility(View.VISIBLE);