From f28af0e34d6c13ea056e7c1194d4f8da79b772aa Mon Sep 17 00:00:00 2001 From: matthew Date: Mon, 29 Aug 2016 11:10:16 +0800 Subject: [PATCH] BUGFIX: When finger toggle switcher outside of switche view rectangle and release, the SlideListener are not trigger. --- .../com/leaking/slideswitch/SlideSwitch.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/SlideSwitch/src/com/leaking/slideswitch/SlideSwitch.java b/SlideSwitch/src/com/leaking/slideswitch/SlideSwitch.java index bb51baf..7246583 100644 --- a/SlideSwitch/src/com/leaking/slideswitch/SlideSwitch.java +++ b/SlideSwitch/src/com/leaking/slideswitch/SlideSwitch.java @@ -174,7 +174,7 @@ protected void onDraw(Canvas canvas) { canvas.drawRoundRect(frontCircleRect, radius, radius, paint); } } - + @Override public boolean onTouchEvent(MotionEvent event) { if (slideable == false) @@ -196,22 +196,27 @@ public boolean onTouchEvent(MotionEvent event) { invalidateView(); } break; - case MotionEvent.ACTION_UP: - int wholeX = (int) (event.getRawX() - eventStartX); - frontRect_left_begin = frontRect_left; - boolean toRight; - toRight = (frontRect_left_begin > max_left / 2 ? true : false); - if (Math.abs(wholeX) < 3) { - toRight = !toRight; - } - moveToDest(toRight); - break; + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: + stopToggle(event); + break; default: break; } return true; } + private void stopToggle(MotionEvent event) { + int wholeX = (int) (event.getRawX() - eventStartX); + frontRect_left_begin = frontRect_left; + boolean toRight; + toRight = (frontRect_left_begin > max_left / 2); + if (Math.abs(wholeX) < 3) { + toRight = !toRight; + } + moveToDest(toRight); +} + /** * draw again */