pull_to_refresh debug

好久没有写博客了。主要是工作太忙了 + 自己开始变懒了。忏悔一下


今天研究了一下PullToRefresh[https://github.com/chrisbanes/Android-PullToRefresh]的机制,就是下拉然后自动刷新的功能,其实还是不太懂。不过先把自己已经搞清楚的写一下

1. PullToRefreshListView(PullToRefreshBase).onTouchEvent(MotionEvent) line: 330

MotionEvent.ACTION_MOVE ==> pullEvent()
2. PullToRefreshListView(PullToRefreshBase).pullEvent() line: 1193
3. PullToRefreshListView(PullToRefreshBase).setHeaderScroll(int) line: 957
4. RotateLoadingLayout(LoadingLayout).onPull(float) line: 228
5. RotateLoadingLayout.onPullImpl(float) line: 67
2-5用来显示“放开以刷新”的header,当onTouchEvent检测到MotionEvent.ACTION_UP的时候,再显示
“正在刷新”header


当检测到 MotionEvent.ACTION_DOWN之后:
1. PullToRefreshListView(PullToRefreshBase).onTouchEvent(MotionEvent)
判断此时的motion (down、up、move)进行任务分发。此时实际是在父类(PullToRefreshBase)中
2. PullToRefreshListView(PullToRefreshBase).setState(PullToRefreshBase$State, boolean...) 
从onTouchEvent获得状态,进一步分发任务:
3. PullToRefreshListView.onRefreshing(boolean) line: 77
通过super.onRefreshing, 逐步调用真正的刷新
4. PullToRefreshListView(PullToRefreshBase).onRefreshing(boolean) line: 761
判断是否需要scroll,然后用不同方式调用callRefreshListener()
5. PullToRefreshListView(PullToRefreshBase).callRefreshListener() line: 1063
2种调用方式:
a. 先调用mOnRefreshListener.onRefresh(this);
b. 如果mOnRefreshListener2非null,根据mCurrentMode == Mode.PULL_FROM_START/END调用mOnRefreshListener2.onPullUp(/down)ToRefresh(this);

你可能感兴趣的:(pull_to_refresh debug)