@@ -38,7 +38,6 @@ public class ExpandHelper implements Gefingerpoken, OnClickListener {
3838 public interface Callback {
3939 View getChildAtRawPosition (float x , float y );
4040 View getChildAtPosition (float x , float y );
41- View getPreviousChild (View currentChild );
4241 boolean canChildBeExpanded (View v );
4342 boolean setUserExpandedChild (View v , boolean userxpanded );
4443 }
@@ -142,17 +141,6 @@ public int getNaturalHeight(int maximum) {
142141 }
143142 }
144143
145- class PopState {
146- View mCurrView ;
147- View mCurrViewTopGlow ;
148- View mCurrViewBottomGlow ;
149- float mOldHeight ;
150- float mNaturalHeight ;
151- float mInitialTouchY ;
152- }
153-
154- private Stack <PopState > popStack ;
155-
156144 /**
157145 * Handle expansion gestures to expand and contract children of the callback.
158146 *
@@ -168,7 +156,6 @@ public ExpandHelper(Context context, Callback callback, int small, int large) {
168156 mLargeSize = large ;
169157 mContext = context ;
170158 mCallback = callback ;
171- popStack = new Stack <PopState >();
172159 mScaler = new ViewScaler ();
173160 mGravity = Gravity .TOP ;
174161 mScaleAnimation = ObjectAnimator .ofFloat (mScaler , "height" , 0f );
@@ -416,45 +403,40 @@ public boolean onTouchEvent(MotionEvent ev) {
416403 switch (action ) {
417404 case MotionEvent .ACTION_MOVE : {
418405 if (mPullingWithOneFinger ) {
419- float target = ev .getY () - mInitialTouchY + mOldHeight ;
420- float newHeight = clamp (target );
421- if (mHasPopped || target > mPopLimit ) {
406+ final float rawHeight = ev .getY () - mInitialTouchY + mOldHeight ;
407+ final float newHeight = clamp (rawHeight );
408+ final boolean wasClosed = (mOldHeight == mSmallSize );
409+ boolean isFinished = false ;
410+ if (rawHeight > mNaturalHeight ) {
411+ isFinished = true ;
412+ }
413+ if (rawHeight < mSmallSize ) {
414+ isFinished = true ;
415+ }
416+
417+ final float pull = Math .abs (ev .getY () - mInitialTouchY );
418+ if (mHasPopped || pull > mPopLimit ) {
422419 if (!mHasPopped ) {
423420 vibrate (mPopDuration );
424421 mHasPopped = true ;
425422 }
423+ }
424+
425+ if (mHasPopped ) {
426426 mScaler .setHeight (newHeight );
427- // glow if overscale
428- if (target > mNaturalHeight ) {
429- View previous = mCallback .getPreviousChild (mCurrView );
430- if (previous != null ) {
431- setGlow (0f );
432- pushView (previous );
433- initScale (previous );
434- mInitialTouchY = ev .getY ();
435- target = mOldHeight ;
436- newHeight = clamp (target );
437- mHasPopped = false ;
438- } else {
439- setGlow (calculateGlow (target , newHeight ));
440- }
441- } else if (target < mSmallSize && !popStack .empty ()) {
442- setGlow (0f );
443- initScale (popView ());
444- mInitialTouchY = ev .getY ();
445- setGlow (GLOW_BASE );
446- } else {
447- setGlow (calculateGlow (target , newHeight ));
448- }
427+ setGlow (GLOW_BASE );
449428 } else {
450- if (target < mSmallSize && !popStack .empty ()) {
451- setGlow (0f );
452- initScale (popView ());
453- mInitialTouchY = ev .getY ();
454- setGlow (GLOW_BASE );
455- } else {
456- setGlow (calculateGlow (4f * target , mSmallSize ));
457- }
429+ setGlow (calculateGlow (4f * pull , 0f ));
430+ }
431+
432+ final int x = (int ) ev .getX ();
433+ final int y = (int ) ev .getY ();
434+ View underPointer = findView (x , y );
435+ if (isFinished && underPointer != null && underPointer != mCurrView ) {
436+ setGlow (0f );
437+ initScale (underPointer );
438+ mInitialTouchY = ev .getY ();
439+ mHasPopped = false ;
458440 }
459441 return true ;
460442 }
@@ -516,9 +498,6 @@ private void finishScale(boolean force) {
516498 }
517499
518500 private void clearView () {
519- while (!popStack .empty ()) {
520- popStack .pop ();
521- }
522501 mCurrView = null ;
523502 mCurrViewTopGlow = null ;
524503 mCurrViewBottomGlow = null ;
@@ -539,33 +518,6 @@ private void setView(View v) {
539518 }
540519 }
541520
542- private void pushView (View v ) {
543- PopState state = new PopState ();
544- state .mCurrView = mCurrView ;
545- state .mCurrViewTopGlow = mCurrViewTopGlow ;
546- state .mCurrViewBottomGlow = mCurrViewBottomGlow ;
547- state .mOldHeight = mOldHeight ;
548- state .mNaturalHeight = mNaturalHeight ;
549- state .mInitialTouchY = mInitialTouchY ;
550- popStack .push (state );
551- }
552-
553- private View popView () {
554- if (popStack .empty ()) {
555- return null ;
556- }
557-
558- PopState state = popStack .pop ();
559- mCurrView = state .mCurrView ;
560- mCurrViewTopGlow = state .mCurrViewTopGlow ;
561- mCurrViewBottomGlow = state .mCurrViewBottomGlow ;
562- mOldHeight = state .mOldHeight ;
563- mNaturalHeight = state .mNaturalHeight ;
564- mInitialTouchY = state .mInitialTouchY ;
565-
566- return mCurrView ;
567- }
568-
569521 @ Override
570522 public void onClick (View v ) {
571523 initScale (v );
0 commit comments