/** * 重置刷新 */ public void resetRefresh() { releaseMoveToRefreshHeight(0); postDelayed(new Runnable() { @Override public void run() { changeRefreshState(PULL_REFRESH_STATE, 0); } }, 500); }
/** * 刷新完成 */ public void refreshComplete() { mPullRefreshLayout.refreshComplete(); }
public PullRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); removeAllViews(); setOrientation(HORIZONTAL); setGravity(Gravity.BOTTOM); init(context); }
public boolean releaseAction() { boolean isRefresh = false; int visibleHeight = getVisibleHeight(); int destHeight = 1; if (visibleHeight == 1) { isRefresh = false; } if (visibleHeight > mRefreshHeight && mRefreshState < REFRESHING_STATE) { changeRefreshState(REFRESHING_STATE, MAX_PROGRESS); isRefresh = true; } if (mRefreshState == REFRESHING_STATE) { destHeight = mRefreshHeight; } else if (mRefreshState == PULL_REFRESH_STATE) { mRefreshView.setIsDrawArrow(true); mRefreshView.setProgress(0); } releaseMoveToRefreshHeight(destHeight); return isRefresh; }
private void startRefreshAnimator(BaseViewHolder holder) { RefreshView refreshView = (RefreshView) holder.itemView.findViewById(R.id.load_more); if (refreshView != null) { refreshView.setIndicatorId(mLoadingIndicator); if (mLoadingIndicator == LoadMoreType.APAY) { refreshView.setIsDrawArrow(false); refreshView.setProgress(100); } refreshView.startAnimator(); } }
/** * 移动过程中不断改变高度和状态 * * @param delta */ public void onMove(float delta) { if (getVisibleHeight() > 0 || delta > 0) { setVisibleHeight((int) (delta + getVisibleHeight())); if (mRefreshState <= RELEASE_REFRESH_STATE) { changeRefreshState(getVisibleHeight() >= mRefreshHeight ? RELEASE_REFRESH_STATE : PULL_REFRESH_STATE, getVisibleHeight() * MAX_PROGRESS / mRefreshHeight); } } }
/** * 刷新完成 */ public void refreshComplete() { changeRefreshState(REFRESHED_STATE, MAX_PROGRESS); resetRefresh(); }
/** * @param y */ private void changePosition(int y) { selectorPosition = y / (mHeight / mDatas.size()); if (selectorPosition >= mDatas.size()) { selectorPosition = mDatas.size() - 1; } else if (selectorPosition <= 0) { selectorPosition = 0; } if (mOnTouchListener != null) { mOnTouchListener.onTouchListener(mDatas.get(selectorPosition), false); } invalidate(); }
/** * 获取可见的高度 * * @return */ public int getVisibleHeight() { LayoutParams lp = getRefreshLayoutParams(); return lp.height; }
@Override public void run() { changeRefreshState(PULL_REFRESH_STATE, 0); } }, 500);
/** * @param position */ public void setSelectorPosition(int position) { selectorPosition = position; invalidate(); }
public LetterNavigationView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); }
public RefreshView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); }
private void init(Context context) { mPullRefreshLayout = new PullRefreshLayout(context); }
public void setIndicatorColor(int color) { mIndicatorColor = color; mPaint.setColor(mIndicatorColor); this.invalidate(); }
@Override public void onAnimationUpdate(ValueAnimator animation) { setVisibleHeight((int) animation.getAnimatedValue()); } });
public RefreshRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context); }
private void init(Context context) { this.mContext = context; mPullRefreshStr = PULL_REFRESH_STR; mReleaseRefreshStr = RELEASE_REFRESH_STR; mRefreshingStr = REFRESHING_STR; mRefreshedStr = REFRESHED_STR; mRefreshState = PULL_REFRESH_STATE; mRefreshHeight = ScreenUtils.dip2px(mContext, 54); addRefreshLayout(); }
public void setIndicatorId(@LoadMoreType int indicatorId) { mIndicatorId = indicatorId; applyIndicator(); }
/** * 设置可见的高度 * * @param height */ public void setVisibleHeight(int height) { if (height <= 0) height = 0; LayoutParams lp = getRefreshLayoutParams(); lp.height = height; mRefreshLayout.setLayoutParams(lp); }