Fix empty screen on Android L and tweak UI

Screenshots: https://drive.google.com/open?id=0BwSNbQ_IWQd2Mm1pMkU1QWE1bFU

Bug: 25850722
Bug: 25849077

Change-Id: Iec5624d5b5a9e5f365533df7976e79d0afa3d118
diff --git a/res/layout-land/contacts_unavailable_fragment_content.xml b/res/layout-land/contacts_unavailable_fragment_content.xml
index 05e4919..4f26db6 100644
--- a/res/layout-land/contacts_unavailable_fragment_content.xml
+++ b/res/layout-land/contacts_unavailable_fragment_content.xml
@@ -23,22 +23,15 @@
 
     <LinearLayout
         android:orientation="vertical"
-        android:layout_marginLeft="44dip"
-        android:layout_marginRight="44dip"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"/>
-
-    <LinearLayout
-        android:orientation="vertical"
-        android:layout_marginLeft="48dip"
-        android:layout_marginRight="48dip"
+        android:layout_marginLeft="40dp"
+        android:layout_marginRight="40dp"
         android:layout_width="wrap_content"
         android:layout_height="match_parent">
         <ImageView
             android:id="@+id/empty_image"
             android:layout_height="128dp"
             android:layout_width="128dp"
-            android:layout_marginTop="56dip"
+            android:layout_marginTop="60dp"
             android:alpha="0.38"
             android:gravity="center_horizontal"/>
 
@@ -46,48 +39,51 @@
             android:id="@+id/message"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_marginTop="6dip"
-            android:textAppearance="?android:attr/textAppearanceLarge"
+            android:layout_marginTop="4dp"
+            android:textAppearance="?android:attr/textAppearanceMedium"
             android:textColor="?android:attr/textColorSecondary"
+            android:layout_gravity="center_horizontal"
             android:textIsSelectable="false"/>
 
-    </LinearLayout>
-
-    <LinearLayout
-        android:orientation="vertical"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent">
-
-        <Button
-            android:id="@+id/add_account_button"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginTop="72dip"
-            android:layout_marginBottom="20dip"
-            android:textColor="@android:color/white"
-            android:text="@string/contacts_unavailable_add_account" />
-
-        <Button
-            android:id="@+id/import_contacts_button"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginBottom="15dip"
-            android:textColor="@android:color/white"
-            android:text="@string/contacts_unavailable_import_contacts" />
-
         <ProgressBar
             android:id="@+id/progress"
-            android:layout_width="wrap_content"
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
+            style="?android:attr/progressBarStyleHorizontal"
+            android:indeterminate="true"
             android:layout_gravity="center_horizontal"
-            android:layout_marginBottom="15dip" />
+            android:layout_marginTop="12dp" />
     </LinearLayout>
 
+    <!-- This buttons_container is landscape exclusive because we want the two buttons to be of
+         the same width (wrapping the longer content) and the layout width to be 208dp. -->
     <LinearLayout
+        android:id="@+id/buttons_container"
         android:orientation="vertical"
-        android:layout_marginLeft="44dip"
-        android:layout_marginRight="44dip"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"/>
+        android:layout_width="208dp"
+        android:layout_height="match_parent">
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_gravity="center_horizontal">
+
+            <Button
+                android:id="@+id/add_account_button"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="85dp"
+                android:layout_marginBottom="10dp"
+                android:textColor="@android:color/white"
+                android:text="@string/contacts_unavailable_add_account" />
+
+            <Button
+                android:id="@+id/import_contacts_button"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:textColor="@android:color/white"
+                android:text="@string/contacts_unavailable_import_contacts" />
+        </LinearLayout>
+    </LinearLayout>
 
 </LinearLayout>
diff --git a/res/layout/contacts_unavailable_fragment_content.xml b/res/layout/contacts_unavailable_fragment_content.xml
index 32636b4..9482273 100644
--- a/res/layout/contacts_unavailable_fragment_content.xml
+++ b/res/layout/contacts_unavailable_fragment_content.xml
@@ -25,32 +25,44 @@
         android:id="@+id/empty_image"
         android:layout_height="128dp"
         android:layout_width="128dp"
-        android:layout_marginTop="56dip"
+        android:layout_marginTop="56dp"
         android:alpha="0.38"
         android:gravity="center_horizontal" />
 
-    <TextView
-        android:id="@+id/message"
+    <LinearLayout
+        android:orientation="vertical"
         android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="6dip"
-        android:textAppearance="?android:attr/textAppearanceLarge"
-        android:textColor="?android:attr/textColorSecondary"/>
+        android:layout_height="wrap_content">
+
+        <TextView
+            android:id="@+id/message"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="4dp"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textColor="?android:attr/textColorSecondary"/>
+
+        <ProgressBar
+            android:id="@+id/progress"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            style="?android:attr/progressBarStyleHorizontal"
+            android:indeterminate="true"
+            android:layout_gravity="center_horizontal"
+            android:layout_marginTop="12dp" />
+    </LinearLayout>
 
     <LinearLayout
         android:orientation="vertical"
-        android:layout_marginLeft="48dip"
-        android:layout_marginRight="48dip"
-
         android:layout_width="wrap_content"
-        android:layout_height="match_parent">
+        android:layout_height="wrap_content">
 
         <Button
             android:id="@+id/add_account_button"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginTop="24dip"
-            android:layout_marginBottom="15dip"
+            android:layout_marginTop="50dp"
+            android:layout_marginBottom="10dp"
             android:textColor="@android:color/white"
             android:text="@string/contacts_unavailable_add_account" />
 
@@ -58,15 +70,7 @@
             android:id="@+id/import_contacts_button"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginBottom="15dip"
             android:textColor="@android:color/white"
             android:text="@string/contacts_unavailable_import_contacts" />
-
-        <ProgressBar
-            android:id="@+id/progress"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center_horizontal"
-            android:layout_marginBottom="15dip" />
     </LinearLayout>
 </LinearLayout>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 607c86b..321c39b 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -264,6 +264,8 @@
          We have to be more careful in landscape. -->
     <dimen name="people_activity_landscape_tabs_text_size">8dp</dimen>
 
+    <dimen name="update_contact_list_top_margin">120dp</dimen>
+
     <dimen name="expanding_entry_card_item_icon_height">24dp</dimen>
     <dimen name="expanding_entry_card_item_icon_width">24dp</dimen>
 
diff --git a/src/com/android/contacts/list/ContactsUnavailableFragment.java b/src/com/android/contacts/list/ContactsUnavailableFragment.java
index 2b9e184..fec3553 100644
--- a/src/com/android/contacts/list/ContactsUnavailableFragment.java
+++ b/src/com/android/contacts/list/ContactsUnavailableFragment.java
@@ -17,9 +17,9 @@
 
 import android.app.Fragment;
 import android.content.Context;
+import android.content.res.Configuration;
 import android.graphics.PorterDuff;
 import android.os.Bundle;
-import android.provider.ContactsContract.ProviderStatus;
 import android.support.v4.content.ContextCompat;
 import android.view.Gravity;
 import android.view.LayoutInflater;
@@ -47,6 +47,7 @@
     private Button mAddAccountButton;
     private Button mImportContactsButton;
     private ProgressBar mProgress;
+    private View mButtonsContainer;
     private int mNoContactsMsgResId = -1;
     private int mLastTab = -1;
 
@@ -70,13 +71,17 @@
         mAddAccountButton = (Button) mView.findViewById(R.id.add_account_button);
         mAddAccountButton.setOnClickListener(this);
         mAddAccountButton.getBackground().setColorFilter(ContextCompat.getColor(getContext(), R
-                .color.primary_color), PorterDuff.Mode.MULTIPLY);
+                .color.primary_color), PorterDuff.Mode.SRC_ATOP);
         mImportContactsButton = (Button) mView.findViewById(R.id.import_contacts_button);
         mImportContactsButton.setOnClickListener(this);
         mImportContactsButton.getBackground().setColorFilter(ContextCompat.getColor(getContext(),
-                R.color.primary_color), PorterDuff.Mode.MULTIPLY);
+                R.color.primary_color), PorterDuff.Mode.SRC_ATOP);
         mProgress = (ProgressBar) mView.findViewById(R.id.progress);
 
+        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
+            mButtonsContainer = mView.findViewById(R.id.buttons_container);
+        }
+
         if (mProviderStatus != null) {
             updateStatus(mProviderStatus);
         }
@@ -99,7 +104,7 @@
             updateViewsForEmptyStatus();
         } else if (providerStatus == ProviderStatusCompat.STATUS_BUSY) {
             updateViewsForBusyStatus(R.string.upgrade_in_progress);
-        } else if (providerStatus == ProviderStatusCompat.STATUS_CHANGING_LOCALE){
+        } else if (providerStatus == ProviderStatusCompat.STATUS_CHANGING_LOCALE) {
             updateViewsForBusyStatus(R.string.locale_change_in_progress);
         }
     }
@@ -110,8 +115,7 @@
     private void updateViewsForEmptyStatus() {
         setTabInfo(mNoContactsMsgResId, mLastTab);
         if (mLastTab == TabState.ALL) {
-            mAddAccountButton.setVisibility(View.VISIBLE);
-            mImportContactsButton.setVisibility(View.VISIBLE);
+            updateButtonVisibilty(View.VISIBLE);
         }
         mProgress.setVisibility(View.GONE);
     }
@@ -125,9 +129,18 @@
         mMessageView.setText(resId);
         mMessageView.setGravity(Gravity.CENTER_HORIZONTAL);
         mMessageView.setVisibility(View.VISIBLE);
-        mAddAccountButton.setVisibility(View.GONE);
-        mImportContactsButton.setVisibility(View.GONE);
+        updateButtonVisibilty(View.GONE);
         mProgress.setVisibility(View.VISIBLE);
+        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
+            final ViewGroup.MarginLayoutParams lp =
+                    (ViewGroup.MarginLayoutParams) mMessageView.getLayoutParams();
+            final int marginTop =
+                    (int) getResources().getDimension(R.dimen.update_contact_list_top_margin);
+            lp.setMargins(0, marginTop, 0, 0);
+            mImageView.setVisibility(View.GONE);
+        } else {
+            mImageView.setVisibility(View.INVISIBLE);
+        }
     }
 
     @Override
@@ -144,6 +157,7 @@
                 break;
         }
     }
+
     /**
      * Set the message to be shown if no data is available for the selected tab
      *
@@ -160,13 +174,11 @@
                 mMessageView.setVisibility(View.VISIBLE);
                 if (callerTab == TabState.FAVORITES) {
                     mImageView.setImageResource(R.drawable.ic_star_black_128dp);
-                    mAddAccountButton.setVisibility(View.GONE);
-                    mImportContactsButton.setVisibility(View.GONE);
                     mProgress.setVisibility(View.GONE);
+                    updateButtonVisibilty(View.GONE);
                 } else if (callerTab == TabState.ALL) {
                     mImageView.setImageResource(R.drawable.ic_person_black_128dp);
-                    mAddAccountButton.setVisibility(View.VISIBLE);
-                    mImportContactsButton.setVisibility(View.VISIBLE);
+                    updateButtonVisibilty(View.VISIBLE);
                 }
             } else {
                 mMessageView.setVisibility(View.GONE);
@@ -174,6 +186,17 @@
         }
     }
 
+    private void updateButtonVisibilty(int visibility) {
+        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
+            mAddAccountButton.setVisibility(visibility);
+            mImportContactsButton.setVisibility(visibility);
+            mButtonsContainer.setVisibility(visibility);
+        } else {
+            mAddAccountButton.setVisibility(visibility);
+            mImportContactsButton.setVisibility(visibility);
+        }
+    }
+
     @Override
     public Context getContext() {
         return getActivity();