Skip to content

Commit 1bfcc82

Browse files
committed
Expand top of touchable area of challenge drag handle.
Change-Id: I8d471041205cd929e899903daae61d5ac948597c Proto-Id: I5f44a135451c1cd86bbe4fb8ebd1af7609715ce3
1 parent 6f35209 commit 1bfcc82

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.content.Context;
2121
import android.content.res.TypedArray;
2222
import android.graphics.Canvas;
23+
import android.graphics.Paint;
2324
import android.graphics.drawable.Drawable;
2425
import android.util.AttributeSet;
2526
import android.util.FloatProperty;
@@ -41,6 +42,7 @@
4142
*/
4243
public 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

Comments
 (0)