diff options
author | Diego Mondega <diegomondega@cyngn.com> | 2015-03-30 18:47:41 -0700 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2015-03-31 15:19:49 -0700 |
commit | bc92b2580833214348a648486de48ee13658a159 (patch) | |
tree | 6dce4a1109d8416a69e53aa6fb514b7b7afc5bcb | |
parent | ae2912b7b736966c25e8a993abd013130a02df04 (diff) | |
download | android_external_cyanogen_UICommon-bc92b2580833214348a648486de48ee13658a159.tar.gz android_external_cyanogen_UICommon-bc92b2580833214348a648486de48ee13658a159.tar.bz2 android_external_cyanogen_UICommon-bc92b2580833214348a648486de48ee13658a159.zip |
UiCommon : Scroll cards into visibility w/ aux views
Change-Id: I6a24e08c7cc174b28c1d0b510baa5c32030020d9
-rw-r--r-- | src/com/cyngn/uicommon/view/ExpandingCard.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/com/cyngn/uicommon/view/ExpandingCard.java b/src/com/cyngn/uicommon/view/ExpandingCard.java index bd8a479..7762dd8 100644 --- a/src/com/cyngn/uicommon/view/ExpandingCard.java +++ b/src/com/cyngn/uicommon/view/ExpandingCard.java @@ -9,6 +9,7 @@ import android.content.Context; import android.content.res.Resources; import android.util.AttributeSet; import android.view.View; +import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ListView; import com.cyngn.uicommon.R; @@ -24,6 +25,13 @@ import java.util.List; public class ExpandingCard extends FrameLayout { private static final int EXPAND_DURATION = 150; + private ListView mList; + private ViewGroup mRowContainer; + private boolean mRowContainerInitialized; + + public void setListView(ListView listView) { + mList = listView; + } public static enum AnimationType { // the bottom of the aux view is anchored and the content view slides @@ -115,6 +123,38 @@ public class ExpandingCard extends FrameLayout { animations.add(anim); animations.add(getShadowAnimation(true)); + if (mList != null && mRowContainer != null) { + // Set up the animator to animate the expansion and shadow depth. + ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f); + int scrollingNeeded = 0; + + if (mRowContainer.getTop() < 0) { + scrollingNeeded = mRowContainer.getTop(); // view at top/partially visible + } else { + int listViewHeight = mList.getHeight(); + int offset = mRowContainer.getTop() + mRowContainer.getHeight() + mAuxHeight - listViewHeight; + if (offset > 0) { + scrollingNeeded = offset; + } + } + final int finalScrollingNeeded = scrollingNeeded; + animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + + private int mCurrentScroll = 0; + + @Override + public void onAnimationUpdate(ValueAnimator animator) { + Float value = (Float) animator.getAnimatedValue(); + if (mList != null) { + int scrollBy = (int) (value * finalScrollingNeeded) - mCurrentScroll; + mList.smoothScrollBy(scrollBy, /* duration = */ 0); + mCurrentScroll += scrollBy; + } + } + }); + animations.add(animator); + } + AnimatorSet set = new AnimatorSet(); set.playTogether(animations); set.setDuration(EXPAND_DURATION); @@ -321,6 +361,7 @@ public class ExpandingCard extends FrameLayout { card.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + card.initializeRowContainer(); if (position == mSelectedPosition) { card.collapse(); mSelectedPosition = -1; @@ -357,4 +398,18 @@ public class ExpandingCard extends FrameLayout { } } } + + private void initializeRowContainer() { + if (!mRowContainerInitialized) { + ViewGroup lastView = (ViewGroup) getParent(); + while (lastView != null) { + if (lastView.getParent() instanceof ListView) { + mRowContainer = lastView; + break; + } + lastView = (ViewGroup) lastView.getParent(); + } + } + mRowContainerInitialized = true; + } } |