2020import android .content .Context ;
2121import android .content .res .TypedArray ;
2222import android .graphics .Canvas ;
23+ import android .graphics .Paint ;
2324import android .graphics .drawable .Drawable ;
2425import android .util .AttributeSet ;
2526import android .util .FloatProperty ;
4142 */
4243public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout {
4344 private static final String TAG = "SlidingChallengeLayout" ;
45+ private static final boolean DEBUG = false ;
4446
4547 // Drawn to show the drag handle in closed state; crossfades to the challenge view
4648 // when challenge is fully visible
@@ -81,7 +83,8 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
8183 private int mMinVelocity ;
8284 private int mMaxVelocity ;
8385 private float mLastTouchY ;
84- private int mDragHandleSize ;
86+ private int mDragHandleSize ; // handle hitrect extension into the challenge view
87+ private int mDragHandleHeadroom ; // extend the handle's hitrect this far above the line
8588 private int mDragHandleEdgeSlop ;
8689 float mHandleAlpha ;
8790 float mFrameAlpha ;
@@ -226,6 +229,10 @@ public void setDragDrawables(Drawable handle, Drawable icon) {
226229 final int defaultSize = (int ) (DRAG_HANDLE_DEFAULT_SIZE * density + 0.5f );
227230 mDragHandleSize = Math .max (handle != null ? handle .getIntrinsicHeight () : defaultSize ,
228231 icon != null ? icon .getIntrinsicHeight () : defaultSize );
232+
233+ // top half of the lock icon, plus another 25% to be sure
234+ mDragHandleHeadroom = (icon != null ) ? (int )(icon .getIntrinsicHeight () * 0.75f ) : 0 ;
235+
229236 mHandleDrawable = handle ;
230237 mDragIconDrawable = icon ;
231238 }
@@ -563,7 +570,8 @@ public boolean onTouchEvent(MotionEvent ev) {
563570 showChallenge (0 );
564571 return true ;
565572 }
566- final float y = Math .max (ev .getY (index ), getChallengeOpenedTop ());
573+ final float y = Math .max (ev .getY (index ),
574+ getChallengeOpenedTop () - mDragHandleHeadroom );
567575 final float delta = y - mLastTouchY ;
568576 final int idelta = (int ) delta ;
569577 // Don't lose the rounded component
@@ -587,14 +595,16 @@ private boolean isInDragHandle(float x, float y) {
587595 if (mChallengeView == null ) return false ;
588596
589597 return x >= mDragHandleEdgeSlop &&
590- y >= mChallengeView .getTop () &&
598+ y >= mChallengeView .getTop () - mDragHandleHeadroom &&
591599 x < getWidth () - mDragHandleEdgeSlop &&
592600 y < mChallengeView .getTop () + mDragHandleSize ;
593601 }
594602
595603 private boolean crossedDragHandle (float x , float y , float lastY ) {
596604 final int challengeTop = mChallengeView .getTop ();
597- return x >= 0 && x < getWidth () && lastY < challengeTop &&
605+ return x >= 0 &&
606+ x < getWidth () &&
607+ lastY < (challengeTop - mDragHandleHeadroom ) &&
598608 y > challengeTop + mDragHandleSize ;
599609 }
600610
@@ -717,6 +727,19 @@ public void computeScroll() {
717727 @ Override
718728 public void draw (Canvas c ) {
719729 super .draw (c );
730+
731+ final Paint debugPaint ;
732+ if (DEBUG ) {
733+ debugPaint = new Paint ();
734+ debugPaint .setColor (0x40FF00CC );
735+ // show the isInDragHandle() rect
736+ c .drawRect (mDragHandleEdgeSlop ,
737+ mChallengeView .getTop () - mDragHandleHeadroom ,
738+ getWidth () - mDragHandleEdgeSlop ,
739+ mChallengeView .getTop () + mDragHandleSize ,
740+ debugPaint );
741+ }
742+
720743 if (mChallengeView != null && mHandleAlpha > 0 && mHandleDrawable != null ) {
721744 final int top = mChallengeView .getTop ();
722745 final int handleHeight = mHandleDrawable .getIntrinsicHeight ();
@@ -726,6 +749,14 @@ public void draw(Canvas c) {
726749 mHandleDrawable .setAlpha ((int ) (mHandleAlpha * 0xFF ));
727750 mHandleDrawable .draw (c );
728751
752+ if (DEBUG ) {
753+ // now show the actual drag handle
754+ debugPaint .setStyle (Paint .Style .STROKE );
755+ debugPaint .setStrokeWidth (1 );
756+ debugPaint .setColor (0xFF80FF00 );
757+ c .drawRect (challengeLeft , top , challengeRight , top + handleHeight , debugPaint );
758+ }
759+
729760 if (mDragIconDrawable != null ) {
730761 final int iconWidth = mDragIconDrawable .getIntrinsicWidth ();
731762 final int iconHeight = mDragIconDrawable .getIntrinsicHeight ();
@@ -735,6 +766,12 @@ public void draw(Canvas c) {
735766 iconTop + iconHeight );
736767 mDragIconDrawable .setAlpha ((int ) (mHandleAlpha * 0xFF ));
737768 mDragIconDrawable .draw (c );
769+
770+ if (DEBUG ) {
771+ debugPaint .setColor (0xFF00FF00 );
772+ c .drawRect (iconLeft , iconTop , iconLeft + iconWidth ,
773+ iconTop + iconHeight , debugPaint );
774+ }
738775 }
739776 }
740777 }
0 commit comments