Skip to content

Commit b42b842

Browse files
committed
Remove the handle headroom if the challenge is open.
This change also moves to an absolute-distance model of tracking the panel instead of a delta model; this allows us to make the decision about the handle size in only one place (when first detecting the gesture) instead of requiring us to mix it into the arithmetic everywhere. Also fixes the drag-too-slowly-and-the-panel-doesn't-move problem. Change-Id: I9bdbadd968134ad5ad67eaef9539536fb5cfe1a1 Proto-Id: I0c2f484da89f063995384c263aa9f5f03339ed7c
1 parent 1bfcc82 commit b42b842

File tree

1 file changed

+46
-26
lines changed

1 file changed

+46
-26
lines changed

policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
8282
private VelocityTracker mVelocityTracker;
8383
private int mMinVelocity;
8484
private int mMaxVelocity;
85-
private float mLastTouchY;
85+
private float mGestureStartY; // where did you touch the screen to start this gesture?
86+
private int mGestureStartChallengeBottom; // where was the challenge at that time?
8687
private int mDragHandleSize; // handle hitrect extension into the challenge view
8788
private int mDragHandleHeadroom; // extend the handle's hitrect this far above the line
8889
private int mDragHandleEdgeSlop;
@@ -469,7 +470,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
469470
final int action = ev.getActionMasked();
470471
switch (action) {
471472
case MotionEvent.ACTION_DOWN:
472-
mLastTouchY = ev.getY();
473+
mGestureStartY = ev.getY();
473474
break;
474475

475476
case MotionEvent.ACTION_CANCEL:
@@ -484,11 +485,12 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
484485
final float y = ev.getY(i);
485486

486487
if (!mIsBouncing &&
487-
(isInDragHandle(x, y) || crossedDragHandle(x, y, mLastTouchY) ||
488+
(isInDragHandle(x, y) || crossedDragHandle(x, y, mGestureStartY) ||
488489
(isInChallengeView(x, y) && mScrollState == SCROLL_STATE_SETTLING)) &&
489490
mActivePointerId == INVALID_POINTER) {
490491
mActivePointerId = ev.getPointerId(i);
491-
mLastTouchY = y;
492+
mGestureStartY = ev.getY();
493+
mGestureStartChallengeBottom = getChallengeBottom();
492494
mDragging = true;
493495
} else if (isInChallengeView(x, y)) {
494496
mBlockDrag = true;
@@ -547,10 +549,12 @@ public boolean onTouchEvent(MotionEvent ev) {
547549
final float x = ev.getX(i);
548550
final float y = ev.getY(i);
549551

550-
if ((isInDragHandle(x, y) || crossedDragHandle(x, y, mLastTouchY) ||
552+
if ((isInDragHandle(x, y) || crossedDragHandle(x, y, mGestureStartY) ||
551553
(isInChallengeView(x, y) && mScrollState == SCROLL_STATE_SETTLING))
552554
&& mActivePointerId == INVALID_POINTER) {
555+
mGestureStartY = y;
553556
mActivePointerId = ev.getPointerId(i);
557+
mGestureStartChallengeBottom = getChallengeBottom();
554558
mDragging = true;
555559
break;
556560
}
@@ -570,20 +574,25 @@ public boolean onTouchEvent(MotionEvent ev) {
570574
showChallenge(0);
571575
return true;
572576
}
573-
final float y = Math.max(ev.getY(index),
574-
getChallengeOpenedTop() - mDragHandleHeadroom);
575-
final float delta = y - mLastTouchY;
576-
final int idelta = (int) delta;
577-
// Don't lose the rounded component
578-
mLastTouchY = y + delta - idelta;
579-
580-
moveChallengeBy(idelta);
577+
final float y = ev.getY(index);
578+
final float pos = Math.min(y - mGestureStartY,
579+
getChallengeOpenedTop());
580+
581+
moveChallengeTo(mGestureStartChallengeBottom + (int) pos);
581582
}
582583
break;
583584
}
584585
return true;
585586
}
586587

588+
/**
589+
* We only want to add additional vertical space to the drag handle when the panel is fully
590+
* closed.
591+
*/
592+
private int getDragHandleHeadroom() {
593+
return isChallengeShowing() ? 0 : mDragHandleHeadroom;
594+
}
595+
587596
private boolean isInChallengeView(float x, float y) {
588597
if (mChallengeView == null) return false;
589598

@@ -595,16 +604,16 @@ private boolean isInDragHandle(float x, float y) {
595604
if (mChallengeView == null) return false;
596605

597606
return x >= mDragHandleEdgeSlop &&
598-
y >= mChallengeView.getTop() - mDragHandleHeadroom &&
607+
y >= mChallengeView.getTop() - getDragHandleHeadroom() &&
599608
x < getWidth() - mDragHandleEdgeSlop &&
600609
y < mChallengeView.getTop() + mDragHandleSize;
601610
}
602611

603-
private boolean crossedDragHandle(float x, float y, float lastY) {
612+
private boolean crossedDragHandle(float x, float y, float initialY) {
604613
final int challengeTop = mChallengeView.getTop();
605614
return x >= 0 &&
606615
x < getWidth() &&
607-
lastY < (challengeTop - mDragHandleHeadroom) &&
616+
initialY < (challengeTop - getDragHandleHeadroom()) &&
608617
y > challengeTop + mDragHandleSize;
609618
}
610619

@@ -734,7 +743,7 @@ public void draw(Canvas c) {
734743
debugPaint.setColor(0x40FF00CC);
735744
// show the isInDragHandle() rect
736745
c.drawRect(mDragHandleEdgeSlop,
737-
mChallengeView.getTop() - mDragHandleHeadroom,
746+
mChallengeView.getTop() - getDragHandleHeadroom(),
738747
getWidth() - mDragHandleEdgeSlop,
739748
mChallengeView.getTop() + mDragHandleSize,
740749
debugPaint);
@@ -790,8 +799,7 @@ private boolean moveChallengeTo(int bottom) {
790799
return false;
791800
}
792801

793-
final int bottomMargin = ((LayoutParams) mChallengeView.getLayoutParams()).bottomMargin;
794-
final int layoutBottom = getHeight() - getPaddingBottom() - bottomMargin;
802+
final int layoutBottom = getLayoutBottom();
795803
final int challengeHeight = mChallengeView.getHeight();
796804

797805
bottom = Math.max(layoutBottom,
@@ -814,20 +822,32 @@ private boolean moveChallengeTo(int bottom) {
814822
return true;
815823
}
816824

825+
/**
826+
* The bottom edge of this SlidingChallengeLayout's coordinate system; will coincide with
827+
* the bottom edge of mChallengeView when the challenge is fully opened.
828+
*/
829+
private int getLayoutBottom() {
830+
final int bottomMargin = (mChallengeView == null)
831+
? 0
832+
: ((LayoutParams) mChallengeView.getLayoutParams()).bottomMargin;
833+
final int layoutBottom = getHeight() - getPaddingBottom() - bottomMargin;
834+
return layoutBottom;
835+
}
836+
837+
/**
838+
* The bottom edge of mChallengeView; essentially, where the sliding challenge 'is'.
839+
*/
817840
private int getChallengeBottom() {
818841
if (mChallengeView == null) return 0;
819842

820843
return mChallengeView.getBottom();
821844
}
822845

846+
/**
847+
* The top edge of the challenge if it were fully opened.
848+
*/
823849
private int getChallengeOpenedTop() {
824-
final int paddedBottom = getHeight() - getPaddingBottom();
825-
if (mChallengeView == null) return paddedBottom;
826-
827-
final int bottomMargin = ((LayoutParams) mChallengeView.getLayoutParams()).bottomMargin;
828-
final int layoutBottom = paddedBottom - bottomMargin;
829-
830-
return layoutBottom - mChallengeView.getHeight();
850+
return getLayoutBottom() - ((mChallengeView == null) ? 0 : mChallengeView.getHeight());
831851
}
832852

833853
private void moveChallengeBy(int delta) {

0 commit comments

Comments
 (0)