99import android .view .MotionEvent ;
1010import android .view .VelocityTracker ;
1111import android .view .View ;
12- import android .view .ViewGroup ;
1312import android .widget .FrameLayout ;
1413
1514import com .android .systemui .R ;
16- import com .android .systemui .statusbar .policy .BatteryController ;
17- import com .android .systemui .statusbar .policy .BluetoothController ;
18- import com .android .systemui .statusbar .policy .LocationController ;
19- import com .android .systemui .statusbar .policy .NetworkController ;
2015
2116public class PanelView extends FrameLayout {
2217 public static final boolean DEBUG = PanelBar .DEBUG ;
@@ -70,12 +65,16 @@ public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime)
7065 }
7166 };
7267
73- private final Runnable mStopAnimator = new Runnable () { public void run () {
74- if (mTimeAnimator .isStarted ()) {
75- mTimeAnimator .end ();
76- mRubberbanding = false ;
68+ private final Runnable mStopAnimator = new Runnable () {
69+ @ Override
70+ public void run () {
71+ if (mTimeAnimator .isStarted ()) {
72+ mTimeAnimator .end ();
73+ mRubberbanding = false ;
74+ mClosing = false ;
75+ }
7776 }
78- }} ;
77+ };
7978
8079 private float mVel , mAccel ;
8180 private int mFullHeight = 0 ;
@@ -90,20 +89,22 @@ private void animationTick(long dtms) {
9089 mTimeAnimator .setTimeListener (mAnimationCallback );
9190
9291 mTimeAnimator .start ();
93-
94- mRubberbanding = STRETCH_PAST_CONTENTS && mExpandedHeight > getFullHeight ();
92+
93+ mRubberbanding = STRETCH_PAST_CONTENTS // is it enabled at all?
94+ && mExpandedHeight > getFullHeight () // are we past the end?
95+ && mVel >= -mFlingGestureMinDistPx ; // was this not possibly a "close" gesture?
9596 if (mRubberbanding ) {
9697 mClosing = true ;
9798 } else if (mVel == 0 ) {
98- // if the panel is less than halfway open, close it
99+ // if the panel is less than halfway open, close it
99100 mClosing = (mFinalTouchY / getFullHeight ()) < 0.5f ;
100101 } else {
101102 mClosing = mExpandedHeight > 0 && mVel < 0 ;
102103 }
103104 } else if (dtms > 0 ) {
104105 final float dt = dtms * 0.001f ; // ms -> s
105- LOG ("tick: v=%.2fpx/s dt=%.4fs" , mVel , dt );
106- LOG ("tick: before: h=%d" , (int ) mExpandedHeight );
106+ if ( DEBUG ) LOG ("tick: v=%.2fpx/s dt=%.4fs" , mVel , dt );
107+ if ( DEBUG ) LOG ("tick: before: h=%d" , (int ) mExpandedHeight );
107108
108109 final float fh = getFullHeight ();
109110 boolean braking = false ;
@@ -136,12 +137,12 @@ private void animationTick(long dtms) {
136137 }
137138
138139 float h = mExpandedHeight + mVel * dt ;
139-
140+
140141 if (mRubberbanding && h < fh ) {
141142 h = fh ;
142143 }
143144
144- LOG ("tick: new h=%d closing=%s" , (int ) h , mClosing ?"true" :"false" );
145+ if ( DEBUG ) LOG ("tick: new h=%d closing=%s" , (int ) h , mClosing ?"true" :"false" );
145146
146147 setExpandedHeightInternal (h );
147148
@@ -205,14 +206,14 @@ protected void onFinishInflate() {
205206 loadDimens ();
206207
207208 mHandleView = findViewById (R .id .handle );
208- LOG ("handle view: " + mHandleView );
209+ if ( DEBUG ) LOG ("handle view: " + mHandleView );
209210 if (mHandleView != null ) {
210211 mHandleView .setOnTouchListener (new View .OnTouchListener () {
211212 @ Override
212213 public boolean onTouch (View v , MotionEvent event ) {
213214 final float y = event .getY ();
214215 final float rawY = event .getRawY ();
215- LOG ("handle.onTouch: a=%s y=%.1f rawY=%.1f off=%.1f" ,
216+ if ( DEBUG ) LOG ("handle.onTouch: a=%s y=%.1f rawY=%.1f off=%.1f" ,
216217 MotionEvent .actionToString (event .getAction ()),
217218 y , rawY , mTouchOffset );
218219 PanelView .this .getLocationOnScreen (mAbsPos );
@@ -224,6 +225,7 @@ public boolean onTouch(View v, MotionEvent event) {
224225 mInitialTouchY = y ;
225226 mVelocityTracker = VelocityTracker .obtain ();
226227 trackMovement (event );
228+ mTimeAnimator .cancel (); // end any outstanding animations
227229 mBar .onTrackingStarted (PanelView .this );
228230 mTouchOffset = (rawY - mAbsPos [1 ]) - PanelView .this .getExpandedHeight ();
229231 break ;
@@ -263,7 +265,7 @@ public boolean onTouch(View v, MotionEvent event) {
263265
264266 // if you've barely moved your finger, we treat the velocity as 0
265267 // preventing spurious flings due to touch screen jitter
266- final float deltaY = ( float ) Math .abs (mFinalTouchY - mInitialTouchY );
268+ final float deltaY = Math .abs (mFinalTouchY - mInitialTouchY );
267269 if (deltaY < mFlingGestureMinDistPx
268270 || vel < mFlingGestureMinDistPx ) {
269271 vel = 0 ;
@@ -273,7 +275,7 @@ public boolean onTouch(View v, MotionEvent event) {
273275 vel = -vel ;
274276 }
275277
276- LOG ("gesture: dy=%f vraw=(%f,%f) vnorm=(%f,%f) vlinear=%f" ,
278+ if ( DEBUG ) LOG ("gesture: dy=%f vraw=(%f,%f) vnorm=(%f,%f) vlinear=%f" ,
277279 deltaY ,
278280 mVelocityTracker .getXVelocity (),
279281 mVelocityTracker .getYVelocity (),
@@ -312,7 +314,7 @@ public String getName() {
312314
313315 @ Override
314316 protected void onViewAdded (View child ) {
315- LOG ("onViewAdded: " + child );
317+ if ( DEBUG ) LOG ("onViewAdded: " + child );
316318 }
317319
318320 public View getHandle () {
@@ -324,15 +326,15 @@ public View getHandle() {
324326 protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
325327 super .onMeasure (widthMeasureSpec , heightMeasureSpec );
326328
327- LOG ("onMeasure(%d, %d) -> (%d, %d)" ,
329+ if ( DEBUG ) LOG ("onMeasure(%d, %d) -> (%d, %d)" ,
328330 widthMeasureSpec , heightMeasureSpec , getMeasuredWidth (), getMeasuredHeight ());
329331
330332 // Did one of our children change size?
331333 int newHeight = getMeasuredHeight ();
332334 if (newHeight != mFullHeight ) {
333335 mFullHeight = newHeight ;
334336 // If the user isn't actively poking us, let's rubberband to the content
335- if (!mTracking && !mRubberbanding && !mTimeAnimator .isStarted ()
337+ if (!mTracking && !mRubberbanding && !mTimeAnimator .isStarted ()
336338 && mExpandedHeight > 0 && mExpandedHeight != mFullHeight ) {
337339 mExpandedHeight = mFullHeight ;
338340 }
@@ -351,7 +353,7 @@ public void setExpandedHeight(float height) {
351353
352354 @ Override
353355 protected void onLayout (boolean changed , int left , int top , int right , int bottom ) {
354- LOG ("onLayout: changed=%s, bottom=%d eh=%d fh=%d" , changed ?"T" :"f" , bottom , (int )mExpandedHeight , ( int ) mFullHeight );
356+ if ( DEBUG ) LOG ("onLayout: changed=%s, bottom=%d eh=%d fh=%d" , changed ?"T" :"f" , bottom , (int )mExpandedHeight , mFullHeight );
355357 super .onLayout (changed , left , top , right , bottom );
356358 }
357359
@@ -365,7 +367,7 @@ public void setExpandedHeightInternal(float h) {
365367 if (!(STRETCH_PAST_CONTENTS && (mTracking || mRubberbanding )) && h > fh ) h = fh ;
366368 mExpandedHeight = h ;
367369
368- LOG ("setExpansion: height=%.1f fh=%.1f tracking=%s rubber=%s" , h , fh , mTracking ?"T" :"f" , mRubberbanding ?"T" :"f" );
370+ if ( DEBUG ) LOG ("setExpansion: height=%.1f fh=%.1f tracking=%s rubber=%s" , h , fh , mTracking ?"T" :"f" , mRubberbanding ?"T" :"f" );
369371
370372 requestLayout ();
371373// FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
@@ -377,9 +379,9 @@ public void setExpandedHeightInternal(float h) {
377379
378380 private float getFullHeight () {
379381 if (mFullHeight <= 0 ) {
380- LOG ("Forcing measure() since fullHeight=" + mFullHeight );
381- measure (MeasureSpec .makeMeasureSpec (LayoutParams .WRAP_CONTENT , MeasureSpec .EXACTLY ),
382- MeasureSpec .makeMeasureSpec (LayoutParams .WRAP_CONTENT , MeasureSpec .EXACTLY ));
382+ if ( DEBUG ) LOG ("Forcing measure() since fullHeight=" + mFullHeight );
383+ measure (MeasureSpec .makeMeasureSpec (android . view . ViewGroup . LayoutParams .WRAP_CONTENT , MeasureSpec .EXACTLY ),
384+ MeasureSpec .makeMeasureSpec (android . view . ViewGroup . LayoutParams .WRAP_CONTENT , MeasureSpec .EXACTLY ));
383385 }
384386 return mFullHeight ;
385387 }
@@ -397,11 +399,15 @@ public float getExpandedFraction() {
397399 }
398400
399401 public boolean isFullyExpanded () {
400- return mExpandedHeight = = getFullHeight ();
402+ return mExpandedHeight > = getFullHeight ();
401403 }
402404
403405 public boolean isFullyCollapsed () {
404- return mExpandedHeight == 0 ;
406+ return mExpandedHeight <= 0 ;
407+ }
408+
409+ public boolean isCollapsing () {
410+ return mClosing ;
405411 }
406412
407413 public void setBar (PanelBar panelBar ) {
@@ -411,17 +417,19 @@ public void setBar(PanelBar panelBar) {
411417 public void collapse () {
412418 // TODO: abort animation or ongoing touch
413419 if (!isFullyCollapsed ()) {
420+ // collapse() should never be a rubberband, even if an animation is already running
421+ mRubberbanding = false ;
414422 fling (-mSelfCollapseVelocityPx , /*always=*/ true );
415423 }
416424 }
417425
418426 public void expand () {
419427 if (isFullyCollapsed ()) {
420428 mBar .startOpeningPanel (this );
421- LOG ("expand: calling fling(%s, true)" , mSelfExpandVelocityPx );
429+ if ( DEBUG ) LOG ("expand: calling fling(%s, true)" , mSelfExpandVelocityPx );
422430 fling (mSelfExpandVelocityPx , /*always=*/ true );
423431 } else if (DEBUG ) {
424- LOG ("skipping expansion: is expanded" );
432+ if ( DEBUG ) LOG ("skipping expansion: is expanded" );
425433 }
426434 }
427435}
0 commit comments