From e8ce6ee1c5ab9f4f3dd11526337c70a8867647d9 Mon Sep 17 00:00:00 2001 From: Brian Attwell Date: Fri, 27 Jun 2014 18:26:32 -0700 Subject: Expand header when card collapses If the card collapses enough to open up unused space inside MultiShrinkScroller, then expand the contact header. Change-Id: I88f3009ad90b2defcb7825cc797fd6105178efa4 --- .../contacts/widget/MultiShrinkScroller.java | 48 +++++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) (limited to 'src/com/android/contacts/widget') diff --git a/src/com/android/contacts/widget/MultiShrinkScroller.java b/src/com/android/contacts/widget/MultiShrinkScroller.java index 5c00a0a47..68195da78 100644 --- a/src/com/android/contacts/widget/MultiShrinkScroller.java +++ b/src/com/android/contacts/widget/MultiShrinkScroller.java @@ -500,6 +500,26 @@ public class MultiShrinkScroller extends LinearLayout { } } + /** + * Change the height of the header/toolbar. Do *not* use this outside animations. This was + * designed for use by {@link #prepareForShrinkingScrollChild}. + */ + @NeededForReflection + public void setToolbarHeight(int delta) { + final LinearLayout.LayoutParams toolbarLayoutParams + = (LayoutParams) mToolbar.getLayoutParams(); + toolbarLayoutParams.height = delta; + mToolbar.setLayoutParams(toolbarLayoutParams); + + updatePhotoTintAndDropShadow(); + updateHeaderTextSize(); + } + + @NeededForReflection + public int getToolbarHeight() { + return mToolbar.getLayoutParams().height; + } + /** * Set the height of the toolbar and update its tint accordingly. */ @@ -680,14 +700,17 @@ public class MultiShrinkScroller extends LinearLayout { * allow the the ScrollView to scroll unless there is new content off of the edge of ScrollView. */ private int getFullyCompressedHeaderHeight() { - final LinearLayout.LayoutParams toolbarLayoutParams - = (LayoutParams) mToolbar.getLayoutParams(); + return Math.min(Math.max(mToolbar.getLayoutParams().height - getOverflowingChildViewSize(), + mMinimumHeaderHeight), mIntermediateHeaderHeight); + } + + /** + * Returns the amount of mScrollViewChild that doesn't fit inside its parent. + */ + private int getOverflowingChildViewSize() { final int usedScrollViewSpace = mScrollViewChild.getHeight() - mLeftOverSpaceView.getHeight(); - final int leftOverSpace = -getHeight() + usedScrollViewSpace + toolbarLayoutParams.height; - return Math.min( - Math.max(toolbarLayoutParams.height - leftOverSpace, mMinimumHeaderHeight), - mIntermediateHeaderHeight); + return -getHeight() + usedScrollViewSpace + mToolbar.getLayoutParams().height; } private void scrollDown(int delta) { @@ -986,4 +1009,17 @@ public class MultiShrinkScroller extends LinearLayout { return (long)(1000 / getRefreshRate()); } } + + /** + * Expand the header if the mScrollViewChild is about to shrink by enough to create new empty + * space at the bottom of this ViewGroup. + */ + public void prepareForShrinkingScrollChild(int heightDelta) { + final int newEmptyScrollViewSpace = -getOverflowingChildViewSize() + heightDelta; + if (newEmptyScrollViewSpace > 0 && !mIsTwoPanel) { + final int newDesiredToolbarHeight = Math.min(mToolbar.getLayoutParams().height + + newEmptyScrollViewSpace, mIntermediateHeaderHeight); + ObjectAnimator.ofInt(this, "toolbarHeight", newDesiredToolbarHeight).start(); + } + } } -- cgit v1.2.3