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 */