Fix scroll offset calculation for collapsed header

When originally writing the logic that handled flinging and EdgeEffect
it was impossible for contacts viewed inside the Contacts app
to have a collapsed contact photo without the contact photo
touching the top of the window. Now that we have added click-to-expand
and click-to-collapse to the contact photo, we need to handle one
more case.

Bug: 17405547
Change-Id: I0fbad31b96ae7cf182708e9386b5327dfda8a226
diff --git a/src/com/android/contacts/widget/MultiShrinkScroller.java b/src/com/android/contacts/widget/MultiShrinkScroller.java
index f5bd2a2..15dca5c 100644
--- a/src/com/android/contacts/widget/MultiShrinkScroller.java
+++ b/src/com/android/contacts/widget/MultiShrinkScroller.java
@@ -881,10 +881,17 @@
     /**
      * Returns the minimum size that we want to compress the header to, given that we don't want to
      * allow the the ScrollView to scroll unless there is new content off of the edge of ScrollView.
+     * This value is never smaller than the current header height.
      */
     private int getFullyCompressedHeaderHeight() {
-        return Math.min(Math.max(mToolbar.getLayoutParams().height - getOverflowingChildViewSize(),
-                        mMinimumHeaderHeight), getMaximumScrollableHeaderHeight());
+        final int minimumScrollableHeaderHeight =
+                Math.min(Math.max(mToolbar.getLayoutParams().height - getOverflowingChildViewSize(),
+                mMinimumHeaderHeight), getMaximumScrollableHeaderHeight());
+        // It is possible that the current header height is smaller than the minimum height
+        // that can be obtained by scrolling since tapping on the contact photo collapses it.
+        // In this case, just return the current height or the minimum height.
+        return Math.max(Math.min(minimumScrollableHeaderHeight, mToolbar.getLayoutParams().height),
+                mMinimumHeaderHeight);
     }
 
     /**