Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions SlideSwitch/src/com/leaking/slideswitch/SlideSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected void onDraw(Canvas canvas) {
canvas.drawRoundRect(frontCircleRect, radius, radius, paint);
}
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (slideable == false)
Expand All @@ -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
*/
Expand Down