package com.cy.hl.pull.pulllayout;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.os.CountDownTimer;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.FrameLayout;
import com.cy.hl.pull.R;
import com.cy.hl.pull.cubic.PullFreshCubicView;
import com.cy.hl.pull.cubic.PullOkImageView;
import com.cy.hl.pull.listener.IPullListener;
import com.cy.hl.pull.listener.IPullRefreshListener;
import com.cy.hl.pull.utils.NetworkStatusUtil;
/**
* 一个是cubicpage,一个是rootpage,
* cubicpage指的是下拉刷新的显示区域,后者是正常可视区域
* 小球在页面正下方,由于沉浸式,考虑到一定的偏移量
* Created by hailong on 2017/4/10 0010.
*/
public class PullLayout extends FrameLayout implements View.OnTouchListener {
private Handler mHandler = new Handler();
private PullFreshCubicView freshCubicView;//阻尼弹性小球
private View progrssView;//圆形进度条
private View okView;//加载好或者加载失败,从左到右展示的一个效果
private View cubicView;
private View contentView;
private int offset_y;//小球的竖向偏移量
private int mTouchSlop;
private float downY;
protected float mOverScrollY;
private float transY, transY1;
private float value;
private float mTotalScrollY;
private float mLastMotionY;
private boolean needAnimateDown;
private boolean needRefresh = true;
private boolean cubicOccured;//是否出现过cubic
private boolean uploaded;//是否有上拉的动作
private boolean isTouch = false;//是否有触摸
public PullLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
protected void init() {
final ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
//默认inflate上cubicview
cubicView = LayoutInflater.from(getContext()).inflate(R.layout.pull_cubic_layout, null);
addView(cubicView, 0);
//初始化cubic的相关控件
setCubicContainer(cubicView);
}
public void setCubicContainer(View cubicContainer) {
if (cubicContainer instanceof ViewGroup) {
freshCubicView = (PullFreshCubicView) cubicContainer.findViewById(R.id.beiser_view);
progrssView = cubicContainer.findViewById(R.id.pull_progress);
okView = cubicContainer.findViewById(R.id.pull_ok);
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) progrssView.getLayoutParams();
lp.topMargin = ((getResources().getDimensionPixelSize(R.dimen.pull_cubic_radis) * 2 - getResources().getDimensionPixelSize(R.dimen.pull_progress_size))) / 2;
freshCubicView.setProgressView(progrssView);
freshCubicView.setDoneIcon(okView);
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (contentView == null) {
return super.dispatchTouchEvent(ev);
}
if (!handleTouchEvent(ev)) {
return false;
}
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onTouch(View v, MotionEvent ev) {
if (contentView == null) {
return false;
}
return handleTouchEvent(ev);
}
private boolean handleTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
mHandler.removeCallbacks(freshRunnable);
downY = ev.getY(0);
mLastMotionY = downY;
valueAnimator.cancel();//停在当前位置,动画结束
mTotalScrollY = -contentView.getY();
break;
case MotionEvent.ACTION_POINTER_DOWN:
mLastMotionY = ev.getY(0);
break;
case MotionEvent.ACTION_MOVE:
isTouch = true;
int pointerIndex = ev.findPointerIndex(0);
if (pointerIndex == -1) {
pointerIndex = 0;
}
final float y = ev.getY(pointerIndex);
//如果监听到往下滑动,而且getScrollY>0,默认即可
float deltaY = mLastMotionY - y;
if (noOverScroll()) {
handleMovement(ev);
} else if (cubicOccured && deltaY > 0 && getScrollY() == 0 && contentView.getY() <= 0) {
return false;
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
isTouch = false;
if (noOverScroll()) {
if (contentView.getY() <= 0) {
resetCubicView();
needRefresh = true;
cubicOccured = false;
uploaded = false;
}
handleMoveUp();
}
break;
}
return true;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if (getChildCount() > 1) {
contentView = getChildAt(1);
if (contentView != null) {
if (contentView instanceof ViewGroup) {
setOnTouchListener(this);
}
}
}
}
private boolean handleMovement(MotionEvent ev) {
int pointerIndex = ev.findPointerIndex(0);
if (pointerIndex == -1) {
pointerIndex = 0;
}
final float y = ev.getY(pointerIndex);
//如果监听到往下滑动,而且getScrollY>0,默认即可
float deltaY = mLastMotionY - y;
mLastMotionY = y;
//表明手指往上
if (!cubicOccured && deltaY > 0) {
return false;
}
if (pullListener != null) {
if (pullListener.reachTop()) {
overScroll(deltaY);
return true;
}
}
return false;
}
//touch up事件
private void handleMoveUp() {
mHandler.removeCallbacks(freshRunnable);
//判断是否可以开始刷新
if (freshCubicView != null && (noOverScroll() || !reachBottom()) && contentView.getY() > freshCubicView.getCubicLimit()) {
mHandler.postDelayed(freshRunnable, PullFreshCubicView.Timeout);
if (freshCubicView.getProgressbar() != null) {
freshCubicView.getProgressbar().setAlpha(1f);
}
transY = contentView.getY();
transY1 = contentView.getY() - freshCubicView.getCubicLimit();
//如果正在刷新,不处理
if (transY != 0) {
ValueAnimator valueAnimator1 = new ValueAnimator();
valueAnimator1.setFloatValues(0, 1);
valueAnimator1.setDuration(400);
valueAnimator1.addUpdateListener(updateListener1);
valueAnimator1.setInterpolator(new AccelerateDecelerateInterpolator());
valueAnimator1.addListener(listener1);
valueAnimator1.start();
}
} else {
backOver();
}
mTotalScrollY = 0;
}
private void overScroll(float amount) {
dampedOverScroll(amount);
}
protected void dampedOverScroll(float amount) {
没有合适的资源?快使用搜索试试~ 我知道了~
Android完美下拉刷新(上拉加载)框架 源码实例下载

共72个文件
java:30个
xml:20个
png:10个


温馨提示
这个是四年前的时候写的,喜欢写效果的童鞋可以参考,回头发现资源需要31积分,感觉对于想要资源的朋友可能有点难过,现在先把积分调整一下,最近在研究别的技术领域,有时间我会再优化我之前发布的作品,谢谢大家的支持和指正!
资源推荐
资源详情
资源评论













收起资源包目录



















































































































共 72 条
- 1

Rocketlong
- 粉丝: 2
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 高级人工智能-5.pptx
- 【河北省】专业技术人员标准化的理论方法与实践试卷4答案.doc
- 工程报验申请表.doc
- 基于STC89C52单片机-红外智能循迹小车(同名9240).doc
- 深度强化学习各算法详解及 Pytorch 实现方法 深度强化学习各类算法介绍与 Pytorch 实现方式 深度强化学习各算法的介绍及 Pytorch 实现详解 深度强化学习不同算法介绍与 Pytorc
- 实验幼儿园儿童园内饮食记录表.doc
- 公司物流服务方案.doc
- 小学英语人称代词表格总结.doc
- 移位指令SFTPPT课件.ppt
- 计量经济学-四元线性回归模型案例分析.doc
- 计算机专业假期社会实践报告范文.docx
- 天天讲安全表格.doc
- 公司信用管理总结.doc
- 民营企业高管绩效考核研究.doc
- 教师网络远程培训心得体会四篇.doc
- 水果拼盘店创业计划书.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
前往页