本文主要介绍PullToRefresh框架中的两个接口和一个基类,这些是下拉刷新框架的基础和核心;
一、IPullToRefresh接口:
IPullToRefresh主要定义了View下拉刷新过程中需要实现的一些基本方法;这些方法主要用来控制列表的一些状态;这些方法包括,下面主要介绍一下这个接口中的核心方法;
用我渣渣的英语水平大概翻译了几个核心方法,大牛直接无视吧........
public interface IPullToRefresh<T extends View> {
T:泛型用法,用来表示要能引用刷新的View,比如:ListView、Gridiew、ScrollView等;
/**
*
* 当前的Mode为Mode.BOTH的时候,通过这个方法可以获取view的真实状态;
*
* Get the mode that this view is currently in. This is only really useful
* when using <code>Mode.BOTH</code>.
*
* @return Mode that the view is currently in
*/
public Mode getCurrentMode();
/**
*
* Returns whether the Touch Events are filtered or not. If true is
* returned, then the View will only use touch events where the difference
* in the Y-axis is greater than the difference in the X-axis. This means
* that the View will not interfere when it is used in a horizontal
* scrolling View (such as a ViewPager).
*
* @return boolean - true if the View is filtering Touch Events
*/
public boolean getFilterTouchEvents();
/**
* Returns a proxy object which allows you to call methods on all of the
* LoadingLayouts (the Views which show when Pulling/Refreshing).
* <p />
* You should not keep the result of this method any longer than you need
* it.
* 代理模式的应用;返回下拉、上拉布局的代理对象,用来控制相应上拉、下拉布局的显示状态;
* @return Object which will proxy any calls you make on it, to all of the
* LoadingLayouts.
*/
public ILoadingLayout getLoadingLayoutProxy();
/**
* Returns a proxy object which allows you to call methods on the
* LoadingLayouts (the Views which show when Pulling/Refreshing). The actual
* LoadingLayout(s) which will be affected, are chosen by the parameters you
* give.
* <p />
* You should not keep the result of this method any longer than you need
* it.
* 代理模式的应用;返回下拉、上拉布局的代理对象;
* 通过设置参数,可以影响这些布局的显示状态;
*
* @param includeStart - Whether to include the Start/Header Views
* @param includeEnd - Whether to include the End/Footer Views
* @return Object which will proxy any calls you make on it, to the
* LoadingLayouts included.
*/
public ILoadingLayout getLoadingLayoutProxy(boolean includeStart, boolean includeEnd);
/**
* Get the mode that this view has been set to. If this returns
* <code>Mode.BOTH</code>, you can use <code>getCurrentMode()</code> to
* check which mode the view is currently in
* 返回当前View当前所处的状态,如果这个方法返回为Mode.BOTH,你可以通过getCurrentMode()方法
* 进一步检查当前View所处的状态
*
* @return Mode that the view has been set to
*/
public Mode getMode();
/**
* Get the Wrapped Refreshable View. Anything returned here has already been
* added to the content view.
*
* 获取包装好的Refreshable View,无论当前返回的是什么View,该View都已经被添加到了
* LinearLayout中(后面看代码会明白)
*
* @return The View which is currently wrapped
*/
public T getRefreshableView();
/**
* Get whether the 'Refreshing' View should be automatically shown when
* refreshing. Returns true by default.
*
* 返回一个布尔值来表示正在刷新的View在刷新时是否正在被展示,默认返回true;
*
* @return - true if the Refreshing View will be show
*/
public boolean getShowViewWhileRefreshing();
/**
* @return - The state that the View is currently in.
*
* 返回View的当前State(enum,后续会讲到)
*
*/
public State getState();
/**
* Whether Pull-to-Refresh is enabled
*
* 返回一个布尔值来表示pull-to-refresh动作是否结束;
*
* @return enabled
*/
public boolean isPullToRefreshEnabled();
/**
* Gets whether Overscroll support is enabled. This is different to
* Android's standard Overscroll support (the edge-glow) which is available
* from GINGERBREAD onwards
*
*
*
* @return true - if both PullToRefresh-OverScroll and Android's inbuilt
* OverScroll are enabled
*/
public boolean isPullToRefreshOverScrollEnabled();
/**
* Returns whether the Widget is currently in the Refreshing mState
*
* 返回一个布尔值来表示正在刷新的状态是否结束;
*
* @return true if the Widget is currently refreshing
*/
public boolean isRefreshing();
/**
* Returns whether the widget has enabled scrolling on the Refreshable View
* while refreshing.
*
* @return true if the widget has enabled scrolling while refreshing
*/
public boolean isScrollingWhileRefreshingEnabled();
/**
* Mark the current Refresh as complete. Will Reset the UI and hide the
* Refreshing View
*
* 标记当前刷新完成,即将重置UI,隐藏正在刷新的view;
*
*/
public void onRefreshComplete();
/**
* Set the Touch Events to be filtered or not. If set to true, then the View
* will only use touch events where the difference in the Y-axis is greater
* than the difference in the X-axis. This means that the View will not
* interfere when it is used in a horizontal scrolling View (such as a
* ViewPager), but will restrict which types of finger scrolls will trigger
* the View.
*
* @param filterEvents - true if you want to filter Touch Events. Default is
* true.
*/
public void setFilterTouchEvents(boolean filterEvents);
/**
* Set the mode of Pull-to-Refresh that this view will use.
*
* 设置Pull-to-Refresh的mode
*
* @param mode - Mode to set the View to
*/
public void setMode(Mode mode);
/**
* Set OnPullEventListener for the Widget
*
* @param listener - Listener to be used when the Widget has a pull event to
* propogate.
*/
public void setOnPullEventListener(OnPullEventListener<T> listener);
/**
* Set OnRefreshListener for the Widget
*
* @param listener - Listener to be used when the Widget is set to Refresh
*/
public void setOnRefreshListener(OnRefreshListener<T> listener);
/**
* Set OnRefreshListener for the Widget
*
* @param listener - Listener to be used when the Widget is set to Refresh
*/
public void setOnRefreshListener(OnRefreshListener2<T> listener);
/**
* Sets whether Overscroll support is enabled. This is different to
* Android's standard Overscroll support (the edge-glow). This setting only
* takes effect when running on device with Android v2.3 or greater.
*
* 设置是否启用Overscroll support,这个不同于android标准的Overscroll support
* 这个设置仅仅是当框架运行在2.3及更高版本才起作用;
*
* @param enabled - true if you want Overscroll enabled
*/
public void setPullToRefreshOverScrollEnabled(boolean enabled);
/**
* Sets the Widget to be in the refresh state. The UI will be updated to
* show the 'Refreshing' view, and be scrolled to show such.
*
* 设置控件正在刷新时的状态;这个时候将展示正在刷新的UI;
*
*/
public void setRefreshing();
/**
* Sets the Widget to be in the refresh state. The UI will be updated to
* show the 'Refreshing' view.
*
* 通过参数来设置是否要显示正在刷新的UI;
*
* @param doScroll - true if you want to force a scroll to the Refreshing
* view.
*/
public void setRefreshing(boolean doScroll);
/**
* Sets the Animation Interpolator that is used for animated scrolling.
* Defaults to a DecelerateInterpolator
*
* @param interpolator - Interpolator to use
*/
public void setScrollAnimationInterpolator(Interpolator interpolator);
/**
* By default the Widget disables scrolling on the Refreshable View while
* refreshing. This method can change this behaviour.
*
* @param scrollingWhileRefreshingEnabled - true if you want to enable
* scrolling while refreshing
*/
public void setScrollingWhileRefreshingEnabled(boolean scrollingWhileRefreshingEnabled);
/**
* A mutator to enable/disable whether the 'Refreshing' View should be
* automatically shown when refreshing.
*
* @param showView
*/
public void setShowViewWhileRefreshing(boolean showView);
}
二、ILoadingLayout接口:
这个接口主要用于控制上拉、下拉显示的Layout的一些状态,包括一些需要更新的文案、视图等;
public interface ILoadingLayout {
/**
*
* Set the Last Updated Text. This displayed under the main label when
* Pulling
*
* 设置最新更新的文案;上拉、下拉view的时候显示在主标签上;
*
* @param label - Label to set
*/
public void setLastUpdatedLabel(CharSequence label);
/**
*
* Set the drawable used in the loading layout. This is the same as calling
* <code>setLoadingDrawable(drawable, Mode.BOTH)</code>
*
* 设置正在加载时候的drawable;等价于调用setLoadingDrawable(drawable, Mode.BOTH)
*
* @param drawable - Drawable to display
*/
public void setLoadingDrawable(Drawable drawable);
/**
*
* Set Text to show when the Widget is being Pulled
* <code>setPullLabel(releaseLabel, Mode.BOTH)</code>
*
* 设置正在被拉动时显示的文案;
*
* @param pullLabel - CharSequence to display
*/
public void setPullLabel(CharSequence pullLabel);
/**
*
* Set Text to show when the Widget is refreshing
* <code>setRefreshingLabel(releaseLabel, Mode.BOTH)</code>
*
* 设置正在刷新时显示文案;
*
* @param refreshingLabel - CharSequence to display
*/
public void setRefreshingLabel(CharSequence refreshingLabel);
/**
*
* Set Text to show when the Widget is being pulled, and will refresh when
* released. This is the same as calling
* <code>setReleaseLabel(releaseLabel, Mode.BOTH)</code>
*
* 当上拉、下拉结束,松手时,设置文案;
*
* @param releaseLabel - CharSequence to display
*/
public void setReleaseLabel(CharSequence releaseLabel);
/**
*
* Set's the Sets the typeface and style in which the text should be
* displayed.
*
* 设置文案展示时候typeface和style
*
* Please see
* {@link android.widget.TextView#setTypeface(Typeface)
* TextView#setTypeface(Typeface)}.
*/
public void setTextTypeface(Typeface tf);
}
三、PullToRefreshBase抽象类:
public abstract class PullToRefreshBase<T extends View> extends LinearLayout implements IPullToRefresh<T>
这个类是一个抽象类,继承自LinearLayout,实现了IPullToRefresh接口;首先,它是对需要上拉、下拉View(比如:ListView、GridView等)的一个Wrapper,里面实现了对上拉、下拉View的初始化操作,并且监听了上拉、下拉期间一系列的操作事件,及回调方法,它是IPullToRefresh的直接实现,是框架的核心中的核心;这里只做简单介绍,后面的文章会分两个篇幅来介绍这个类;