package com.yalantis.phoenix;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.Transformation;
import android.widget.AbsListView;
import android.widget.ImageView;
import com.yalantis.phoenix.refresh_view.BaseRefreshView;
import com.yalantis.phoenix.refresh_view.SunRefreshView;
import com.yalantis.phoenix.util.Utils;
import java.security.InvalidParameterException;
public class PullToRefreshView extends ViewGroup {
private static final int DRAG_MAX_DISTANCE = 120;
private static final float DRAG_RATE = .5f;
private static final float DECELERATE_INTERPOLATION_FACTOR = 2f;
public static final int STYLE_SUN = 0;
public static final int MAX_OFFSET_ANIMATION_DURATION = 700;
private static final int INVALID_POINTER = -1;
private View mTarget;
private ImageView mRefreshView;
private Interpolator mDecelerateInterpolator;
private int mTouchSlop;
private int mTotalDragDistance;
private BaseRefreshView mBaseRefreshView;
private float mCurrentDragPercent;
private int mCurrentOffsetTop;
private boolean mRefreshing;
private int mActivePointerId;
private boolean mIsBeingDragged;
private float mInitialMotionY;
private int mFrom;
private float mFromDragPercent;
private boolean mNotify;
private OnRefreshListener mListener;
private int mTargetPaddingTop;
private int mTargetPaddingBottom;
private int mTargetPaddingRight;
private int mTargetPaddingLeft;
public PullToRefreshView(Context context) {
this(context, null);
}
public PullToRefreshView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RefreshView);
final int type = a.getInteger(R.styleable.RefreshView_type, STYLE_SUN);
a.recycle();
mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
mTotalDragDistance = Utils.convertDpToPixel(context, DRAG_MAX_DISTANCE);
mRefreshView = new ImageView(context);
setRefreshStyle(type);
addView(mRefreshView);
setWillNotDraw(false);
ViewCompat.setChildrenDrawingOrderEnabled(this, true);
}
public void setRefreshStyle(int type) {
setRefreshing(false);
switch (type) {
case STYLE_SUN:
mBaseRefreshView = new SunRefreshView(getContext(), this);
break;
default:
throw new InvalidParameterException("Type does not exist");
}
mRefreshView.setImageDrawable(mBaseRefreshView);
}
/**
* This method sets padding for the refresh (progress) view.
*/
public void setRefreshViewPadding(int left, int top, int right, int bottom) {
mRefreshView.setPadding(left, top, right, bottom);
}
public int getTotalDragDistance() {
return mTotalDragDistance;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
ensureTarget();
if (mTarget == null)
return;
widthMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth() - getPaddingRight() - getPaddingLeft(), MeasureSpec.EXACTLY);
heightMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), MeasureSpec.EXACTLY);
mTarget.measure(widthMeasureSpec, heightMeasureSpec);
mRefreshView.measure(widthMeasureSpec, heightMeasureSpec);
}
private void ensureTarget() {
if (mTarget != null)
return;
if (getChildCount() > 0) {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (child != mRefreshView) {
mTarget = child;
mTargetPaddingBottom = mTarget.getPaddingBottom();
mTargetPaddingLeft = mTarget.getPaddingLeft();
mTargetPaddingRight = mTarget.getPaddingRight();
mTargetPaddingTop = mTarget.getPaddingTop();
}
}
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (!isEnabled() || canChildScrollUp() || mRefreshing) {
return false;
}
final int action = MotionEventCompat.getActionMasked(ev);
switch (action) {
case MotionEvent.ACTION_DOWN:
setTargetOffsetTop(0, true);
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
mIsBeingDragged = false;
final float initialMotionY = getMotionEventY(ev, mActivePointerId);
if (initialMotionY == -1) {
return false;
}
mInitialMotionY = initialMotionY;
break;
case MotionEvent.ACTION_MOVE:
if (mActivePointerId == INVALID_POINTER) {
return false;
}
final float y = getMotionEventY(ev, mActivePointerId);
if (y == -1) {
return false;
}
final float yDiff = y - mInitialMotionY;
if (yDiff > mTouchSlop && !mIsBeingDragged) {
mIsBeingDragged = true;
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mIsBeingDragged = false;
mActivePointerId = INVALID_POINTER;
break;
case MotionEventCompat.ACTION_POINTER_UP:
onSecondaryPointerUp(ev);
break;
}
return mIsBeingDragged;
}
@Override
public boolean onTouchEvent(@NonNull MotionEvent ev) {
if (!mIsBeingDragged) {
return super.onTouchEvent(ev);
}
final int action = MotionEventCompat.getActionMasked(ev);
switch (action) {
case MotionEvent.ACTION_MOVE: {
final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
if (pointerIndex < 0) {
return false;
}
final float y = MotionEventCompat.getY(ev, pointerIndex);
final float yDiff = y - mInitialMotionY;
final float scrollTop = yDiff * DRAG_RATE;
mCurrentDragPercent = scrollTop / mTotalDragDistance;
if (mCurrentDragPercent < 0) {
return false;
}
float boundedDragPercent = Math.min(1f, Math.abs(mCurrentDragPercent));
float extraOS = Math.abs(scrollTop) - mTotalDragDistance;
float slingshotDist = mTotalDragDistance;
float tensionSlingshotPercent = Math.max(0,
Math.min(extraOS, slingshotDist * 2) / slingshotDist);
float tensionPercent = (float) ((tensionSlingshotPercent / 4) - Math.pow(
(tensionSlingshotPercent / 4), 2)) * 2f;
float extraMove = (slingshotDist) * tensionPercent / 2;
int targetY = (int) ((slingshotDist * boundedDragPercent) + extraMove);
mBaseRefreshView.setPercent(mCurrentDragPercent, true);
setTargetOffsetTop(targetY -
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
软件开发设计:PHP、QT、应用软件开发、系统软件开发、移动应用开发、网站开发C++、Java、python、web、C#等语言的项目开发与学习资料 硬件与设备:单片机、EDA、proteus、RTOS、包括计算机硬件、服务器、网络设备、存储设备、移动设备等 操作系统:LInux、IOS、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信是一个非常广泛的领域,它涉及到计算机科学、电子工程、数学等多个学科的知识。 云计算与大数据:数据集、包括云计算平台、大数据分析、人工智能、机器学习等,云计算是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需提供给计算机和其他设备。
资源推荐
资源详情
资源评论
收起资源包目录
基于Android平台的食堂点餐系统.zip (222个子文件)
gradlew.bat 2KB
gradlew.bat 2KB
.gitignore 118B
.gitignore 7B
.gitignore 7B
.gitignore 7B
build.gradle 2KB
build.gradle 498B
settings.gradle 35B
gradlew 5KB
gradlew 5KB
gradlew 5KB
org.apache.http.legacy.jar 296KB
volley.jar 85KB
gradle-wrapper.jar 52KB
gradle-wrapper.jar 52KB
gradle-wrapper.jar 52KB
PullToRefreshView.java 15KB
PullToRefreshView.java 15KB
FoodDetailsActivity.java 11KB
SunRefreshView.java 10KB
GerenzhongxinFragment.java 9KB
ShoppingCartFragment.java 7KB
HomeActivity.java 7KB
ShoppingcartActivity.java 7KB
ShouyeFragment.java 6KB
SearchFoodActivity.java 6KB
GoodsItem.java 6KB
LoginActivity.java 5KB
RegisterActivity.java 4KB
DividerDecoration.java 4KB
GetPostUtil.java 3KB
OtherUtils.java 3KB
PlaceAdapter.java 3KB
FoodEntity.java 3KB
SelectAdapter.java 3KB
BaseActivity.java 3KB
MyBalanceActivity.java 3KB
Logger.java 3KB
XCRoundImageView.java 2KB
SerializableSparseArray.java 2KB
OrderEntity.java 2KB
BaseRefreshView.java 2KB
BaseRefreshView.java 2KB
SearchFoodAdapter.java 2KB
WelAdapter.java 2KB
UserEntity.java 1KB
ResetPasswordActivity.java 1KB
FeedBackActivity.java 1KB
ImageUtil.java 1KB
FloatingButton.java 1KB
RemarkActivity.java 1KB
ChangeAdressActivity.java 998B
PlaceEntity.java 959B
MyListView.java 828B
NoFoodActivity.java 800B
ExampleInstrumentedTest.java 788B
SettlementActivity.java 744B
AboutUsActivity.java 681B
GerenzhongxinAdapter.java 619B
ExampleUnitTest.java 424B
Utils.java 291B
Utils.java 291B
ActionSheet.java 146B
hongshaorou.jpg 174KB
boluogulaorou.jpg 95KB
jidanbuding.jpg 74KB
school.jpg 39KB
hongshaopaigu.jpg 31KB
hongshaopaigu.jpg 31KB
tuijian.jpg 29KB
logo.png 443KB
buildings.png 44KB
buildings.png 44KB
buildings.png 36KB
buildings.png 22KB
buildings.png 22KB
buildings.png 19KB
sky.png 17KB
th_mindwarp1mb3.png 15KB
sky.png 11KB
ic_launcher.png 10KB
ic_launcher.png 8KB
sun.png 7KB
ic_exception.png 6KB
sun.png 5KB
sun.png 5KB
default_avatar.png 5KB
ic_launcher.png 5KB
cinema_icon_like_0.png 4KB
ic_launcher.png 3KB
sun.png 3KB
dot_normal.png 3KB
sky.png 3KB
sky.png 3KB
search.png 3KB
sun.png 2KB
ic_launcher.png 2KB
ck_select.png 2KB
cinema_icon_like_40.png 2KB
共 222 条
- 1
- 2
- 3
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功