package com.stay.pull.lib;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.LinearLayout;
import com.stay.pull.R;
import com.stay.pull.lib.internal.LoadingLayout;
public abstract class PullToRefreshBase<T extends View> extends LinearLayout {
final class SmoothScrollRunnable implements Runnable {
static final int ANIMATION_DURATION_MS = 190;
static final int ANIMATION_FPS = 1000 / 60;
private final Interpolator interpolator;
private final int scrollToY;
private final int scrollFromY;
private final Handler handler;
private boolean continueRunning = true;
private long startTime = -1;
private int currentY = -1;
public SmoothScrollRunnable(Handler handler, int fromY, int toY) {
this.handler = handler;
this.scrollFromY = fromY;
this.scrollToY = toY;
this.interpolator = new AccelerateDecelerateInterpolator();
}
@Override
public void run() {
/**
* Only set startTime if this is the first time we're starting, else
* actually calculate the Y delta
*/
if (startTime == -1) {
startTime = System.currentTimeMillis();
} else {
/**
* We do do all calculations in long to reduce software float
* calculations. We use 1000 as it gives us good accuracy and
* small rounding errors
*/
long normalizedTime = (1000 * (System.currentTimeMillis() - startTime)) / ANIMATION_DURATION_MS;
normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);
final int deltaY = Math.round((scrollFromY - scrollToY)
* interpolator.getInterpolation(normalizedTime / 1000f));
this.currentY = scrollFromY - deltaY;
setHeaderScroll(currentY);
}
// If we're not at the target Y, keep going...
if (continueRunning && scrollToY != currentY) {
handler.postDelayed(this, ANIMATION_FPS);
}
}
public void stop() {
this.continueRunning = false;
this.handler.removeCallbacks(this);
}
};
// ===========================================================
// Constants
// ===========================================================
static final float FRICTION = 2.0f;
static final int PULL_TO_REFRESH = 0x0;
static final int RELEASE_TO_REFRESH = 0x1;
static final int REFRESHING = 0x2;
static final int MANUAL_REFRESHING = 0x3;
public static final int MODE_PULL_DOWN_TO_REFRESH = 0x1;
public static final int MODE_PULL_UP_TO_REFRESH = 0x2;
public static final int MODE_BOTH = 0x3;
// ===========================================================
// Fields
// ===========================================================
private int touchSlop;
private float initialMotionY;
private float lastMotionX;
private float lastMotionY;
private boolean isBeingDragged = false;
private int state = PULL_TO_REFRESH;
private int mode = MODE_PULL_DOWN_TO_REFRESH;
private int currentMode;
private boolean disableScrollingWhileRefreshing = true;
T refreshableView;
private boolean isPullToRefreshEnabled = true;
private LoadingLayout headerLayout;
private LoadingLayout footerLayout;
private int headerHeight;
private final Handler handler = new Handler();
private OnRefreshListener onRefreshListener;
private SmoothScrollRunnable currentSmoothScrollRunnable;
// ===========================================================
// Constructors
// ===========================================================
public PullToRefreshBase(Context context) {
super(context);
init(context, null);
}
public PullToRefreshBase(Context context, int mode) {
super(context);
this.mode = mode;
init(context, null);
}
public PullToRefreshBase(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
// ===========================================================
// Getter & Setter
// ===========================================================
/**
* Deprecated. Use {@link #getRefreshableView()} from now on.
*
* @deprecated
* @return The Refreshable View which is currently wrapped
*/
public final T getAdapterView() {
return refreshableView;
}
/**
* Get the Wrapped Refreshable View. Anything returned here has already been
* added to the content view.
*
* @return The View which is currently wrapped
*/
public final T getRefreshableView() {
return refreshableView;
}
/**
* Whether Pull-to-Refresh is enabled
*
* @return enabled
*/
public final boolean isPullToRefreshEnabled() {
return isPullToRefreshEnabled;
}
/**
* Returns whether the widget has disabled scrolling on the Refreshable View
* while refreshing.
*
* @param true if the widget has disabled scrolling while refreshing
*/
public final boolean isDisableScrollingWhileRefreshing() {
return disableScrollingWhileRefreshing;
}
/**
* Returns whether the Widget is currently in the Refreshing state
*
* @return true if the Widget is currently refreshing
*/
public final boolean isRefreshing() {
return state == REFRESHING || state == MANUAL_REFRESHING;
}
/**
* By default the Widget disabled scrolling on the Refreshable View while
* refreshing. This method can change this behaviour.
*
* @param disableScrollingWhileRefreshing
* - true if you want to disable scrolling while refreshing
*/
public final void setDisableScrollingWhileRefreshing(boolean disableScrollingWhileRefreshing) {
this.disableScrollingWhileRefreshing = disableScrollingWhileRefreshing;
}
/**
* Mark the current Refresh as complete. Will Reset the UI and hide the
* Refreshing View
*/
public final void onRefreshComplete() {
if (state != PULL_TO_REFRESH) {
resetHeader();
}
}
/**
* Set OnRefreshListener for the Widget
*
* @param listener
* - Listener to be used when the Widget is set to Refresh
*/
public final void setOnRefreshListener(OnRefreshListener listener) {
onRefreshListener = listener;
}
/**
* A mutator to enable/disable Pull-to-Refresh for the current View
*
* @param enable
* Whether Pull-To-Refresh should be used
*/
public final void setPullToRefreshEnabled(boolean enable) {
this.isPullToRefreshEnabled = enable;
}
/**
* Set Text to show when the Widget is being pulled, and will refresh when
* released
*
* @param releaseLabel
* - String to display
*/
public void setReleaseLabel(String releaseLabel) {
if (null != headerLayout) {
headerLayout.setReleaseLabel(releaseLabel);
}
if (null != footerLayout) {
footerLayout.setReleaseLabel(releaseLabel);
}
}
/**
* Set Text to show when the Widget is being Pulled
*
* @param pullLabel
* - String to display
*/
public void setPullLabel(String pullLabel) {
if (null != headerLayout) {
headerLayout.setPullLabel(pullLabel);
}
if (null != footerLayout) {
footerLayout.setPullLabel(pullLabel);
}
}
/**
* Set Text to show when the Widget is refreshing
*
* @param refreshingLabel
* - String to display
*/
public void setRefreshingLabel(String refreshingLabel) {
if (null != headerLayout) {
headerLayout.setRefreshingLabel(refreshingLabel);
}
if (null != footerLayout) {
footerLayout.setRefreshingLabel(refreshingLabel);
}
}
public final void setRefreshing() {
this.setRefreshing(true);
}
/**
* Sets the Widget to be in the refresh state. The UI will be updated to
* show the 'Refreshing' view.
*
* @param doScroll
* - true if you want to force a scroll to the Refreshing view.
*/
public final void setRefreshing(boolean doScroll) {
if (!isRefreshing()) {
setRefreshingInternal(doScroll);
state = MANUAL_REFRESHIN
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
上拉更多 支持ListView GridView WebView.zip (90个子文件)
Te
.project 838B
project.properties 361B
proguard.cfg 1KB
src
com
stay
pull
PullToRefreshListActivity.java 4KB
lib
PullToRefreshScrollView.java 2KB
PullToRefreshBase.java 19KB
PullToRefreshExpandableListView.java 2KB
internal
EmptyViewMethodAccessor.java 665B
LoadingLayout.java 3KB
PullToRefreshWebView.java 2KB
PullToRefreshAdapterViewBase.java 6KB
PullToRefreshGridView.java 1KB
PullToRefreshListView.java 6KB
PullToRefreshWebViewActivity.java 1024B
PullToRefreshScrollViewActivity.java 1KB
PullToRefreshActivity.java 2KB
PullToRefreshGridActivity.java 2KB
PullToRefreshExpandableListActivity.java 4KB
TeActivity.java 335B
AndroidManifest.xml 1KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
pulltorefresh_down_arrow.png 48KB
pulltorefresh_up_arrow.png 667B
lv_backtotop.png 2KB
drawable-mdpi
ic_launcher.png 3KB
layout
pull_to_refresh_list.xml 864B
pull_to_refresh_scrollview.xml 616B
pull_to_refresh_grid.xml 819B
text.xml 4KB
pull_to_refresh_webview.xml 594B
pull_to_refresh_header.xml 1KB
pull_to_refresh_expandable_list.xml 813B
main.xml 2KB
values
ids.xml 142B
pull_refresh_strings.xml 378B
attrs.xml 528B
strings.xml 192B
assets
gen
com
stay
pull
R.java 9KB
.classpath 364B
bin
resources.ap_ 22KB
classes
com
stay
pull
R$layout.class 693B
R$drawable.class 522B
R$attr.class 497B
PullToRefreshGridActivity.class 3KB
PullToRefreshWebViewActivity.class 1KB
PullToRefreshScrollViewActivity$1.class 858B
lib
PullToRefreshListView$InternalListView.class 1KB
PullToRefreshListView.class 2KB
PullToRefreshWebView$1.class 962B
PullToRefreshGridView$InternalGridView.class 1KB
PullToRefreshAdapterViewBase.class 6KB
PullToRefreshWebView.class 2KB
PullToRefreshBase$SmoothScrollRunnable.class 2KB
PullToRefreshGridView.class 2KB
PullToRefreshScrollView.class 3KB
PullToRefreshScrollView$1.class 907B
internal
EmptyViewMethodAccessor.class 233B
LoadingLayout.class 3KB
PullToRefreshBase$OnRefreshListener.class 269B
PullToRefreshBase.class 12KB
PullToRefreshExpandableListView.class 2KB
PullToRefreshAdapterViewBase$1.class 1KB
PullToRefreshExpandableListView$InternalExpandableListView.class 1KB
PullToRefreshBase$OnLastItemVisibleListener.class 293B
PullToRefreshWebView$2.class 823B
PullToRefreshExpandableListActivity.class 4KB
PullToRefreshWebViewActivity$SampleWebViewClient.class 911B
PullToRefreshActivity.class 2KB
PullToRefreshListActivity$GetDataTask.class 2KB
R$id.class 1KB
PullToRefreshExpandableListActivity$GetDataTask.class 2KB
PullToRefreshScrollViewActivity.class 2KB
R.class 547B
R$string.class 620B
TeActivity.class 501B
PullToRefreshExpandableListActivity$1.class 1KB
PullToRefreshGridActivity$GetDataTask.class 2KB
PullToRefreshGridActivity$1.class 1KB
PullToRefreshListActivity.class 5KB
R$styleable.class 723B
PullToRefreshListActivity$1.class 1KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
pulltorefresh_down_arrow.png 476B
pulltorefresh_up_arrow.png 452B
lv_backtotop.png 2KB
drawable-mdpi
ic_launcher.png 2KB
classes.dex 38KB
Te.apk 41KB
共 90 条
- 1
资源评论
- LPF_FORFREE2014-11-11拿过来直接用效果不好 需要修改
SHIX
- 粉丝: 4
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功