在629行到744行的代码是绘制图形,747行onTouchEvent()里面主要是调用了882行的justify()方法,用于调整画面,
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- WheelAdapter adapter = getAdapter();
- if (adapter == null) {
- return true;
- }
- if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {
- justify();
- }
- return true;
- }
- /**
- * Justifies wheel
- */
- private void justify() {
- if (adapter == null) {
- return;
- }
- lastScrollY = 0;
- int offset = scrollingOffset;
- int itemHeight = getItemHeight();
- boolean needToIncrease = offset > 0 ? currentItem < adapter.getItemsCount() : currentItem > 0;
- if ((isCyclic || needToIncrease) && Math.abs((float) offset) > (float) itemHeight / 2) {
- if (offset < 0)
- offset += itemHeight + MIN_DELTA_FOR_SCROLLING;
- else
- offset -= itemHeight + MIN_DELTA_FOR_SCROLLING;
- }
- if (Math.abs(offset) > MIN_DELTA_FOR_SCROLLING) {
- scroller.startScroll(0, 0, 0, offset, SCROLLING_DURATION);
- setNextMessage(MESSAGE_JUSTIFY);
- } else {
- finishScrolling();
- }
- }
