From b4bad67915864a3f726de70ef2cf08a3a941ea70 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 21 Aug 2014 17:13:57 -0700 Subject: Align shortcut card to top while scrolling. Bug: 16462679 Change-Id: I031909df291a25bf4894fbd34d06d163a195d94d --- src/com/android/dialer/list/ListsFragment.java | 11 +++++------ .../android/dialer/list/ShortcutCardsAdapter.java | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/com') diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index ed95dc2a4..5246b5583 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -111,12 +111,11 @@ public class ListsFragment extends AnalyticsFragment implements CallLogQueryHand private PanelSlideListener mPanelSlideListener = new PanelSlideListener() { @Override public void onPanelSlide(View panel, float slideOffset) { - // For every 1 percent that the panel is slid upwards, clip 1.5 percent from each edge - // of the shortcut card, to achieve the animated effect of the shortcut card - // rapidly shrinking and disappearing from view when the panel is slid upwards. - // slideOffset is 1 when the shortcut card is fully exposed, and 0 when completely - // hidden. - float ratioCardHidden = (1 - slideOffset) * 1.5f; + // For every 1 percent that the panel is slid upwards, clip 1 percent off the top + // edge of the shortcut card, to achieve the animated effect of the shortcut card + // being pushed out of view when the panel is slid upwards. slideOffset is 1 when + // the shortcut card is fully exposed, and 0 when completely hidden. + float ratioCardHidden = (1 - slideOffset); if (mShortcutCardsListView.getChildCount() > 0) { final SwipeableShortcutCard v = (SwipeableShortcutCard) mShortcutCardsListView.getChildAt(0); diff --git a/src/com/android/dialer/list/ShortcutCardsAdapter.java b/src/com/android/dialer/list/ShortcutCardsAdapter.java index 4bd914f25..d1ffa794a 100644 --- a/src/com/android/dialer/list/ShortcutCardsAdapter.java +++ b/src/com/android/dialer/list/ShortcutCardsAdapter.java @@ -52,6 +52,10 @@ public class ShortcutCardsAdapter extends BaseAdapter { } private static final String TAG = ShortcutCardsAdapter.class.getSimpleName(); + private static final float CLIP_CARD_BARELY_HIDDEN_RATIO = 0.001f; + private static final float CLIP_CARD_MOSTLY_HIDDEN_RATIO = 0.9f; + // Fade out 5x faster than the hidden ratio. + private static final float CLIP_CARD_OPACITY_RATIO = 5f; private final CallLogAdapter mCallLogAdapter; @@ -339,34 +343,31 @@ public class ShortcutCardsAdapter extends BaseAdapter { int width = viewToClip.getWidth(); int height = viewToClip.getHeight(); - if (ratioHidden <= 0.001f) { + if (ratioHidden <= CLIP_CARD_BARELY_HIDDEN_RATIO) { viewToClip.setTranslationZ(mPreviousTranslationZ); } else if (viewToClip.getTranslationZ() != 0){ mPreviousTranslationZ = viewToClip.getTranslationZ(); viewToClip.setTranslationZ(0); } - if (ratioHidden > 0.5f) { + if (ratioHidden > CLIP_CARD_MOSTLY_HIDDEN_RATIO) { mClipRect.set(0, 0 , 0, 0); setVisibility(View.INVISIBLE); } else { setVisibility(View.VISIBLE); - int newLeft = (int) (ratioHidden * mCardMaxHorizontalClip); - int newRight = width - newLeft; int newTop = (int) (ratioHidden * height); - int newBottom = (height - newTop); - mClipRect.set(newLeft, newTop, newRight, newBottom); + mClipRect.set(0, newTop, width, height); // Since the pane will be overlapping with the action bar, apply a vertical offset - // to visually center the clipped card in the viewable area; - int verticalOffset = -newTop / 2; - viewToClip.setTranslationY(verticalOffset); + // to top align the clipped card in the viewable area; + viewToClip.setTranslationY(-newTop); } viewToClip.setClipBounds(mClipRect); // If the view has any children, fade them out of view. final ViewGroup viewGroup = (ViewGroup) viewToClip; - setChildrenOpacity(viewGroup, Math.max(0, 1 - 4.5f * ratioHidden)); + setChildrenOpacity( + viewGroup, Math.max(0, 1 - (CLIP_CARD_OPACITY_RATIO * ratioHidden))); } private void setChildrenOpacity(ViewGroup viewGroup, float alpha) { -- cgit v1.2.3