Click on transparent QC region to dismiss QC

Also: in order to make this work better for both landscape and
portrait, I replaced the transparent margin with a transparent
view.

Change-Id: Iba12f924fde2224bd51b4a6d0bcae16b97b23dda
diff --git a/res/layout/quickcontact_activity.xml b/res/layout/quickcontact_activity.xml
index 8f78811..13b8d9b 100644
--- a/res/layout/quickcontact_activity.xml
+++ b/res/layout/quickcontact_activity.xml
@@ -24,10 +24,14 @@
     android:focusableInTouchMode="true"
     android:descendantFocusability="afterDescendants" >
 
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/quickcontact_starting_empty_height"
+        android:id="@+id/transparent_view" />
+
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginTop="@dimen/quickcontact_starting_empty_height"
         android:background="@color/card_margin_color"
         android:id="@+id/toolbar_parent">
 
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 7773598..b186038 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -143,6 +143,7 @@
     private boolean mHasAlreadyBeenOpened;
 
     private ImageView mPhotoView;
+    private View mTransparentView;
     private ExpandingEntryCardView mCommunicationCard;
     private ExpandingEntryCardView mRecentCard;
     private MultiShrinkScroller mScroller;
@@ -344,6 +345,15 @@
         mRecentCard.setTitle(getResources().getString(R.string.recent_card_title));
 
         mPhotoView = (ImageView) findViewById(R.id.photo);
+        mTransparentView = findViewById(R.id.transparent_view);
+        if (mScroller != null) {
+            mTransparentView.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    mScroller.scrollOffBottom();
+                }
+            });
+        }
 
         final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
         setActionBar(toolbar);
diff --git a/src/com/android/contacts/widget/MultiShrinkScroller.java b/src/com/android/contacts/widget/MultiShrinkScroller.java
index 03d68ee..b38f5cf 100644
--- a/src/com/android/contacts/widget/MultiShrinkScroller.java
+++ b/src/com/android/contacts/widget/MultiShrinkScroller.java
@@ -64,6 +64,7 @@
     private View mToolbar;
     private ImageView mPhotoView;
     private View mPhotoViewContainer;
+    private View mTransparentView;
     private MultiShrinkScrollerListener mListener;
     private int mHeaderTintColor;
     private int mMaximumHeaderHeight;
@@ -170,6 +171,7 @@
         mScrollViewChild = findViewById(R.id.card_container);
         mToolbar = findViewById(R.id.toolbar_parent);
         mPhotoViewContainer = findViewById(R.id.toolbar_parent);
+        mTransparentView = findViewById(R.id.transparent_view);
         mListener = listener;
 
         mPhotoView = (ImageView) findViewById(R.id.photo);
@@ -439,7 +441,7 @@
     public int getScroll() {
         final LinearLayout.LayoutParams toolbarLayoutParams
                 = (LayoutParams) mToolbar.getLayoutParams();
-        return mTransparentStartHeight - toolbarLayoutParams.topMargin
+        return mTransparentStartHeight - getTransparentViewHeight()
                 + mIntermediateHeaderHeight - toolbarLayoutParams.height + mScrollView.getScrollY();
     }
 
@@ -451,7 +453,7 @@
     public int getScroll_ignoreOversizedHeader() {
         final LinearLayout.LayoutParams toolbarLayoutParams
                 = (LayoutParams) mToolbar.getLayoutParams();
-        return mTransparentStartHeight - toolbarLayoutParams.topMargin
+        return mTransparentStartHeight - getTransparentViewHeight()
                 + Math.max(mIntermediateHeaderHeight - toolbarLayoutParams.height, 0)
                 + mScrollView.getScrollY();
     }
@@ -460,9 +462,7 @@
      * Amount of transparent space above the header/toolbar.
      */
     public int getScrollNeededToBeFullScreen() {
-        final LinearLayout.LayoutParams toolbarLayoutParams
-                = (LayoutParams) mToolbar.getLayoutParams();
-        return toolbarLayoutParams.topMargin;
+        return getTransparentViewHeight();
     }
 
     /**
@@ -544,15 +544,24 @@
                 + Math.max(0, mScrollViewChild.getHeight() - getHeight() + mMinimumHeaderHeight);
     }
 
+    private int getTransparentViewHeight() {
+        return mTransparentView.getLayoutParams().height;
+    }
+
+    private void setTransparentViewHeight(int height) {
+        mTransparentView.getLayoutParams().height = height;
+        mTransparentView.setLayoutParams(mTransparentView.getLayoutParams());
+    }
+
     private void scrollUp(int delta) {
-        LinearLayout.LayoutParams toolbarLayoutParams = (LayoutParams) mToolbar.getLayoutParams();
-        if (toolbarLayoutParams.topMargin != 0) {
-            final int originalValue = toolbarLayoutParams.topMargin;
-            toolbarLayoutParams.topMargin -= delta;
-            toolbarLayoutParams.topMargin = Math.max(toolbarLayoutParams.topMargin, 0);
-            mToolbar.setLayoutParams(toolbarLayoutParams);
-            delta -= originalValue - toolbarLayoutParams.topMargin;
+        if (getTransparentViewHeight() != 0) {
+            final int originalValue = getTransparentViewHeight();
+            setTransparentViewHeight(getTransparentViewHeight() - delta);
+            setTransparentViewHeight(Math.max(0, getTransparentViewHeight()));
+            delta -= originalValue - getTransparentViewHeight();
         }
+        final LinearLayout.LayoutParams toolbarLayoutParams
+                = (LayoutParams) mToolbar.getLayoutParams();
         if (toolbarLayoutParams.height != mMinimumHeaderHeight) {
             final int originalValue = toolbarLayoutParams.height;
             toolbarLayoutParams.height -= delta;
@@ -564,12 +573,13 @@
     }
 
     private void scrollDown(int delta) {
-        LinearLayout.LayoutParams toolbarLayoutParams = (LayoutParams) mToolbar.getLayoutParams();
         if (mScrollView.getScrollY() > 0) {
             final int originalValue = mScrollView.getScrollY();
             mScrollView.scrollBy(0, delta);
             delta -= mScrollView.getScrollY() - originalValue;
         }
+        final LinearLayout.LayoutParams toolbarLayoutParams
+                = (LayoutParams) mToolbar.getLayoutParams();
         if (toolbarLayoutParams.height < mIntermediateHeaderHeight) {
             final int originalValue = toolbarLayoutParams.height;
             toolbarLayoutParams.height -= delta;
@@ -578,8 +588,7 @@
             mToolbar.setLayoutParams(toolbarLayoutParams);
             delta -= originalValue - toolbarLayoutParams.height;
         }
-        toolbarLayoutParams.topMargin -= delta;
-        mToolbar.setLayoutParams(toolbarLayoutParams);
+        setTransparentViewHeight(getTransparentViewHeight() - delta);
 
         if (getScrollUntilOffBottom() <= 0) {
             post(new Runnable() {