2323import android .animation .ObjectAnimator ;
2424import android .content .Context ;
2525import android .util .Log ;
26+ import android .view .Gravity ;
2627import android .view .MotionEvent ;
2728import android .view .ScaleGestureDetector ;
2829import android .view .View ;
2930import android .view .ViewGroup ;
3031import android .view .View .OnClickListener ;
32+ import android .widget .ScrollView ;
33+ import android .widget .FrameLayout ;
3134
3235public class ExpandHelper implements Gefingerpoken , OnClickListener {
3336 public interface Callback {
@@ -38,7 +41,7 @@ public interface Callback {
3841 }
3942
4043 private static final String TAG = "ExpandHelper" ;
41- protected static final boolean DEBUG = false ;
44+ protected static final boolean DEBUG = true ;
4245 private static final long EXPAND_DURATION = 250 ;
4346 private static final long GLOW_DURATION = 150 ;
4447
@@ -82,8 +85,11 @@ public interface Callback {
8285 private int mLargeSize ;
8386 private float mMaximumStretch ;
8487
88+ private int mGravity ;
89+
8590 private class ViewScaler {
8691 View mView ;
92+
8793 public ViewScaler () {}
8894 public void setView (View v ) {
8995 mView = v ;
@@ -119,14 +125,23 @@ public int getNaturalHeight(int maximum) {
119125 }
120126 }
121127
128+ /**
129+ * Handle expansion gestures to expand and contract children of the callback.
130+ *
131+ * @param context application context
132+ * @param callback the container that holds the items to be manipulated
133+ * @param small the smallest allowable size for the manuipulated items.
134+ * @param large the largest allowable size for the manuipulated items.
135+ * @param scoller if non-null also manipulate the scroll position to obey the gravity.
136+ */
122137 public ExpandHelper (Context context , Callback callback , int small , int large ) {
123138 mSmallSize = small ;
124139 mMaximumStretch = mSmallSize * STRETCH_INTERVAL ;
125140 mLargeSize = large ;
126141 mContext = context ;
127142 mCallback = callback ;
128143 mScaler = new ViewScaler ();
129-
144+ mGravity = Gravity . TOP ;
130145 mScaleAnimation = ObjectAnimator .ofFloat (mScaler , "height" , 0f );
131146 mScaleAnimation .setDuration (EXPAND_DURATION );
132147
@@ -194,6 +209,7 @@ public boolean onScale(ScaleGestureDetector detector) {
194209 span *= USE_SPAN ? 1f : 0f ;
195210 float drag = detector .getFocusY () - mInitialTouchFocusY ;
196211 drag *= USE_DRAG ? 1f : 0f ;
212+ drag *= mGravity == Gravity .BOTTOM ? -1f : 1f ;
197213 float pull = Math .abs (drag ) + Math .abs (span ) + 1f ;
198214 float hand = drag * Math .abs (drag ) / pull + span * Math .abs (span ) / pull ;
199215 if (DEBUG ) Log .d (TAG , "current span handle is: " + hand );
@@ -227,6 +243,10 @@ public void setEventSource(View eventSource) {
227243 mEventSource = eventSource ;
228244 }
229245
246+ public void setGravity (int gravity ) {
247+ mGravity = gravity ;
248+ }
249+
230250 public void setGlow (float glow ) {
231251 if (!mGlowAnimationSet .isRunning () || glow == 0f ) {
232252 if (mGlowAnimationSet .isRunning ()) {
0 commit comments