itemLongClickListener;
29 | private long minClickIntervaltime = 100; //ITEM点击的最小间隔
30 | private long mLastClickTime;//上次点击时间
31 |
32 | /**
33 | * 获取布局ID
34 | *
35 | * @return 布局Id, ex:R.layout.listitem_***
36 | */
37 | public abstract int getItemLayoutId(int viewType);
38 |
39 | /**
40 | * 获取布局ID
41 | *
42 | * @return 布局Id, ex:R.layout.listitem_***
43 | */
44 | public View getItemLayout(ViewGroup parent, int viewType) {
45 | return LayoutInflater.from(parent.getContext()).inflate(getItemLayoutId(viewType), parent, false);
46 | }
47 |
48 | /**
49 | * 客户自己定义的GridLayoutManager的item需要跨的行数
50 | *
51 | * @return GridLayoutManager 0为占满,其他为占的具体行数,最多为占满
52 | */
53 | public int getGridItemSpanCount(int position, int viewType) {
54 | return 1;
55 | }
56 |
57 | /**
58 | * 客户自己定义的StaggeredLayoutManager的item是否需要占满
59 | *
60 | * @return true为占满, false为1行
61 | */
62 | public boolean getIsStaggeredItemFullSpan(int position, int viewType) {
63 | return false;
64 | }
65 |
66 | /**
67 | * 设置Item点击的最小间隔
68 | *
69 | * @param minClickIntervaltime millionSeconds
70 | */
71 | public void setItemMinClickIntervalTime(long minClickIntervaltime) {
72 | this.minClickIntervaltime = minClickIntervaltime;
73 | }
74 |
75 | /**
76 | * 设置显示数据,替代getView,在此函数中进行赋值操作
77 | *
78 | * ex:
79 | * TextView tvNumb = getView(view, R.id.tv);
80 | * tvNumb.setText(String.valueOf(position + 1));
81 | */
82 | public abstract void setUpData(CommonHolder holder, int position, int viewType, T data);
83 |
84 | public void setOnItemClickListener(OnItemClickListener li) {
85 | itemClickListener = li;
86 | }
87 |
88 | public void setOnItemLongClickListener(OnItemLongClickListener li) {
89 | itemLongClickListener = li;
90 | }
91 |
92 | /**
93 | * 追加条目数据
94 | */
95 | public void addDatas(List datas) {
96 | if (datas != null) {
97 | listData.addAll(datas);
98 | }
99 | notifyDataSetChanged();
100 | }
101 |
102 | /**
103 | * 将数据替换为传入的数据集
104 | */
105 | public void setDatas(List datas) {
106 | listData.clear();
107 | if (datas != null) {
108 | listData.addAll(datas);
109 | }
110 | notifyDataSetChanged();
111 | }
112 |
113 | /**
114 | * 清空数据集
115 | */
116 | public void clearDatas() {
117 | listData.clear();
118 | notifyDataSetChanged();
119 | }
120 |
121 | /**
122 | * 获取数据集
123 | */
124 | public ArrayList getDatas() {
125 | return listData;
126 | }
127 |
128 | public T getItem(int position) {
129 | return listData.get(position);
130 | }
131 |
132 |
133 | @Override
134 | public int getItemCount() {
135 | return listData.size();
136 | }
137 |
138 | @Override
139 | public CommonHolder onCreateViewHolder(ViewGroup parent, final int viewType) {
140 | View v = getItemLayout(parent, viewType);
141 | return new CommonHolder((RecyclerView) parent, v);
142 | }
143 |
144 | @Override
145 | public void onBindViewHolder(final CommonHolder viewHolder, final int position) {
146 | final T data = listData.get(position);
147 | if (itemClickListener != null) {
148 | viewHolder.itemView.setOnClickListener(v -> {
149 | long curTime = System.currentTimeMillis();
150 | if (curTime - mLastClickTime > minClickIntervaltime) {
151 | mLastClickTime = curTime;
152 | itemClickListener.onItemClick(viewHolder.itemView, position, data);
153 | }
154 | });
155 | }
156 |
157 | if (itemLongClickListener != null) {
158 | viewHolder.itemView.setOnLongClickListener(v -> {
159 | long curTime = System.currentTimeMillis();
160 | if (curTime - mLastClickTime > minClickIntervaltime) {
161 | mLastClickTime = curTime;
162 | return itemLongClickListener.onItemLongClick(viewHolder.itemView, position, data);
163 | }
164 | return false;
165 | });
166 | }
167 |
168 | setUpData(viewHolder, position, getItemViewType(position), data);
169 | }
170 |
171 | /**
172 | * @return 返回
173 | */
174 | protected E getView(CommonHolder holder, int id) {
175 | SparseArray spHolder = holder.spHolder;
176 | View childView = spHolder.get(id);
177 | if (null == childView) {
178 | childView = holder.itemView.findViewById(id);
179 | spHolder.put(id, childView);
180 | }
181 | return (E) childView;
182 | }
183 |
184 | /**
185 | * @return 返回
186 | *
187 | * @deprecated use {@link #getView(CommonHolder, int)}
188 | */
189 | protected E get(CommonHolder holder, int id) {
190 | return getView(holder, id);
191 | }
192 |
193 | public static class CommonHolder extends RecyclerView.ViewHolder {
194 | public SparseArray spHolder = new SparseArray<>();
195 | public RecyclerView viewParent;
196 |
197 | public CommonHolder(RecyclerView viewParent, View itemView) {
198 | super(itemView);
199 | this.viewParent = viewParent;
200 | }
201 | }
202 |
203 | public interface OnItemClickListener {
204 | void onItemClick(View covertView, int position, T data);
205 | }
206 |
207 | public interface OnItemLongClickListener {
208 | boolean onItemLongClick(View covertView, int position, T data);
209 | }
210 | }
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/CommonHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview;
11 |
12 | import androidx.recyclerview.widget.RecyclerView;
13 | import android.util.SparseArray;
14 | import android.view.View;
15 |
16 | public class CommonHolder extends RecyclerView.ViewHolder {
17 | public SparseArray spHolder = new SparseArray<>();
18 | public RecyclerView viewParent;
19 |
20 | public CommonHolder(RecyclerView viewParent, View itemView) {
21 | super(itemView);
22 | this.viewParent = viewParent;
23 | }
24 | }
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/PullScrollView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview;
11 |
12 | import android.content.Context;
13 | import com.google.android.material.appbar.AppBarLayout;
14 | import androidx.coordinatorlayout.widget.CoordinatorLayout;
15 | import android.util.AttributeSet;
16 | import android.view.MotionEvent;
17 | import android.view.View;
18 | import android.view.ViewGroup;
19 | import android.view.ViewParent;
20 | import android.widget.LinearLayout;
21 | import android.widget.ScrollView;
22 |
23 | import com.zcolin.gui.pullrecyclerview.hfooter.DefRefreshHeader;
24 | import com.zcolin.gui.pullrecyclerview.hfooter.IRefreshHeader;
25 |
26 |
27 | /**
28 | * 下拉刷新的ScrollView
29 | *
30 | */
31 | public class PullScrollView extends ScrollView {
32 | private RefreshListener mRefreshListener;
33 |
34 | private IRefreshHeader refreshHeader;
35 | private boolean isRefreshEnabled = true; //设置下拉刷新是否可用
36 | private float dragRate = 2; //下拉刷新滑动阻力系数,越大需要手指下拉的距离越大才能刷新
37 |
38 | private boolean isRefreshing; //是否正在刷新
39 | private float mLastY = -1; //上次触摸的的Y值
40 | private int topY;
41 | private float sumOffSet;
42 | private boolean isAdded;
43 |
44 | private AppBarStateChangeListener.State appbarState = AppBarStateChangeListener.State.EXPANDED;
45 |
46 | public PullScrollView(Context context) {
47 | this(context, null);
48 | }
49 |
50 | public PullScrollView(Context context, AttributeSet attrs) {
51 | this(context, attrs, 0);
52 | }
53 |
54 | public PullScrollView(Context context, AttributeSet attrs, int defStyle) {
55 | super(context, attrs, defStyle);
56 | init();
57 | }
58 |
59 | private void init() {
60 | if (isRefreshEnabled) {
61 | refreshHeader = new DefRefreshHeader(getContext());
62 | }
63 | }
64 |
65 | private void setLayout() {
66 | if (!isAdded) {
67 | isAdded = true;
68 |
69 | ViewGroup group = (ViewGroup) getParent();
70 | LinearLayout container = new LinearLayout(getContext());
71 | container.setOrientation(LinearLayout.VERTICAL);
72 | int index = group.indexOfChild(this);
73 | group.removeView(this);
74 | group.addView(container, index, getLayoutParams());
75 | container.addView(refreshHeader.getHeaderView(),
76 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
77 | ViewGroup.LayoutParams.WRAP_CONTENT));
78 | container.addView(this,
79 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
80 | ViewGroup.LayoutParams.MATCH_PARENT));
81 | }
82 | }
83 |
84 | public View getRefreshHeaderView() {
85 | return refreshHeader.getHeaderView();
86 | }
87 |
88 | /**
89 | * 设置下拉刷新上拉加载回调
90 | */
91 | public void setRefreshListener(RefreshListener listener) {
92 | mRefreshListener = listener;
93 | }
94 |
95 | /**
96 | * 设置自定义的header
97 | */
98 | public PullScrollView setRefreshHeader(IRefreshHeader refreshHeader) {
99 | this.refreshHeader = refreshHeader;
100 | return this;
101 | }
102 |
103 | /**
104 | * 下拉刷新是否可用
105 | */
106 | public PullScrollView setIsRefreshEnabled(boolean enabled) {
107 | isRefreshEnabled = enabled;
108 | return this;
109 | }
110 |
111 | /**
112 | * 下拉刷新滑动阻力系数,越大需要手指下拉的距离越大才能刷新
113 | */
114 | public PullScrollView setDragRate(int dragRate) {
115 | this.dragRate = dragRate;
116 | return this;
117 | }
118 |
119 | /**
120 | * 设置下拉刷新的进度条风格
121 | */
122 | public PullScrollView setRefreshProgressStyle(String style) {
123 | if (refreshHeader != null && refreshHeader instanceof DefRefreshHeader) {
124 | ((DefRefreshHeader) refreshHeader).setProgressStyle(style);
125 | }
126 | return this;
127 | }
128 |
129 | /**
130 | * 设置加载更多的进度条风格
131 | */
132 | public PullScrollView setRefreshHeaderText(String str1, String str2, String str3, String str4) {
133 | if (refreshHeader != null && refreshHeader instanceof DefRefreshHeader) {
134 | ((DefRefreshHeader) refreshHeader).setInfoText(str1, str2, str3, str4);
135 | }
136 | return this;
137 | }
138 |
139 | /**
140 | * 设置下拉刷新的箭头图标
141 | */
142 | public PullScrollView setArrowImage(int resId) {
143 | if (refreshHeader != null && refreshHeader instanceof DefRefreshHeader) {
144 | ((DefRefreshHeader) refreshHeader).setArrowImageView(resId);
145 | }
146 | return this;
147 | }
148 |
149 |
150 | /**
151 | * 手动调用直接刷新,无下拉效果
152 | */
153 | public void refresh() {
154 | if (mRefreshListener != null) {
155 | isRefreshing = true;
156 | mRefreshListener.onRefresh();
157 | }
158 | }
159 |
160 | /**
161 | * 手动调用下拉刷新,有下拉效果
162 | */
163 | public void refreshWithPull() {
164 | setRefreshing(true);
165 | refresh();
166 | }
167 |
168 | /**
169 | * 下拉刷新和到底加载完成
170 | */
171 | public void setRefreshCompleted() {
172 | if (isRefreshing) {
173 | isRefreshing = false;
174 | refreshHeader.onComplete();
175 | }
176 | }
177 |
178 | /**
179 | * 手动调用加载状态,此函数不会调用 {@link RefreshListener#onRefresh()}加载数据
180 | * 如果需要加载数据和状态显示调用 {@link #refreshWithPull()}
181 | */
182 | public void setRefreshing(final boolean refreshing) {
183 | if (refreshing && isRefreshEnabled) {
184 | isRefreshing = true;
185 | refreshHeader.onRefreshing();
186 |
187 | int offSet = refreshHeader.getHeaderView().getMeasuredHeight();
188 | refreshHeader.onMove(offSet, offSet);
189 | }
190 | }
191 |
192 |
193 | @Override
194 | public boolean onTouchEvent(MotionEvent ev) {
195 | if (mLastY == -1) {
196 | mLastY = ev.getRawY();
197 | }
198 |
199 | switch (ev.getAction()) {
200 | case MotionEvent.ACTION_DOWN:
201 | mLastY = ev.getRawY();
202 | sumOffSet = 0;
203 | break;
204 | case MotionEvent.ACTION_MOVE:
205 | final float deltaY = (ev.getRawY() - mLastY) / dragRate;
206 | mLastY = ev.getRawY();
207 | sumOffSet += deltaY;
208 | if (isOnTop() && isRefreshEnabled && appbarState == AppBarStateChangeListener.State.EXPANDED) {
209 | refreshHeader.onMove(deltaY, sumOffSet);
210 | if (refreshHeader.getVisibleHeight() > 0 && !isRefreshing) {
211 | return false;
212 | }
213 | }
214 | break;
215 | default:
216 | mLastY = -1; // reset
217 | if (isOnTop() && isRefreshEnabled && appbarState == AppBarStateChangeListener.State.EXPANDED) {
218 | if (refreshHeader.onRelease()) {
219 | if (mRefreshListener != null) {
220 | isRefreshing = true;
221 | mRefreshListener.onRefresh();
222 | }
223 | }
224 | }
225 | break;
226 | }
227 | return super.onTouchEvent(ev);
228 | }
229 |
230 | @Override
231 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
232 | super.onScrollChanged(l, t, oldl, oldt);
233 | topY = t;
234 | }
235 |
236 | /**
237 | * 如果在HeaderView已经被添加到布局中,说明已经到顶部
238 | */
239 | private boolean isOnTop() {
240 | return topY == 0;
241 | }
242 |
243 | @Override
244 | protected void onAttachedToWindow() {
245 | super.onAttachedToWindow();
246 |
247 | //解决和AppBarLayout冲突的问题
248 | ViewParent p = getParent();
249 | while (p != null) {
250 | if (p instanceof CoordinatorLayout) {
251 | break;
252 | }
253 | p = p.getParent();
254 | }
255 |
256 | if (p != null) {
257 | AppBarLayout appBarLayout = null;
258 | CoordinatorLayout coordinatorLayout = (CoordinatorLayout) p;
259 | final int childCount = coordinatorLayout.getChildCount();
260 | for (int i = childCount - 1; i >= 0; i--) {
261 | final View child = coordinatorLayout.getChildAt(i);
262 | if (child instanceof AppBarLayout) {
263 | appBarLayout = (AppBarLayout) child;
264 | break;
265 | }
266 | }
267 |
268 | if (appBarLayout != null) {
269 | appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
270 | @Override
271 | public void onStateChanged(AppBarLayout appBarLayout, State state) {
272 | appbarState = state;
273 | }
274 | });
275 | }
276 | }
277 | setLayout();
278 | }
279 |
280 | public interface RefreshListener {
281 | void onRefresh();
282 | }
283 | }
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/RecycleViewDivider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview;
11 |
12 | import android.content.Context;
13 | import android.content.res.TypedArray;
14 | import android.graphics.Canvas;
15 | import android.graphics.Paint;
16 | import android.graphics.Rect;
17 | import android.graphics.drawable.Drawable;
18 | import androidx.core.content.ContextCompat;
19 | import androidx.recyclerview.widget.LinearLayoutManager;
20 | import androidx.recyclerview.widget.RecyclerView;
21 | import android.view.View;
22 |
23 | public class RecycleViewDivider extends RecyclerView.ItemDecoration {
24 |
25 | private Paint mPaint;
26 | private Drawable mDivider;
27 | private int mDividerHeight = 2;//分割线高度,默认为1px
28 | private int mOrientation;//列表的方向:LinearLayoutManager.VERTICAL或LinearLayoutManager.HORIZONTAL
29 | private static final int[] ATTRS = new int[]{android.R.attr.listDivider};
30 |
31 | /**
32 | * 默认分割线:高度为2px,颜色为灰色
33 | *
34 | * @param orientation 列表方向
35 | */
36 | public RecycleViewDivider(Context context, int orientation) {
37 | if (orientation != LinearLayoutManager.VERTICAL && orientation != LinearLayoutManager.HORIZONTAL) {
38 | throw new IllegalArgumentException("请输入正确的参数!");
39 | }
40 | mOrientation = orientation;
41 |
42 | final TypedArray a = context.obtainStyledAttributes(ATTRS);
43 | mDivider = a.getDrawable(0);
44 | a.recycle();
45 | }
46 |
47 | /**
48 | * 自定义分割线
49 | *
50 | * @param orientation 列表方向
51 | * @param drawableId 分割线图片
52 | */
53 | public RecycleViewDivider(Context context, int orientation, int drawableId) {
54 | this(context, orientation);
55 | mDivider = ContextCompat.getDrawable(context, drawableId);
56 | mDividerHeight = mDivider.getIntrinsicHeight();
57 | }
58 |
59 | /**
60 | * 自定义分割线
61 | *
62 | * @param orientation 列表方向
63 | * @param dividerHeight 分割线高度
64 | * @param dividerColor 分割线颜色
65 | */
66 | public RecycleViewDivider(Context context, int orientation, int dividerHeight, int dividerColor) {
67 | this(context, orientation);
68 | mDividerHeight = dividerHeight;
69 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
70 | mPaint.setColor(dividerColor);
71 | mPaint.setStyle(Paint.Style.FILL);
72 | }
73 |
74 |
75 | //获取分割线尺寸
76 | @Override
77 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
78 | super.getItemOffsets(outRect, view, parent, state);
79 | outRect.set(0, 0, 0, mDividerHeight);
80 | }
81 |
82 | //绘制分割线
83 | @Override
84 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
85 | super.onDraw(c, parent, state);
86 | if (mOrientation == LinearLayoutManager.VERTICAL) {
87 | drawVertical(c, parent);
88 | } else {
89 | drawHorizontal(c, parent);
90 | }
91 | }
92 |
93 | //绘制横向 item 分割线
94 | private void drawHorizontal(Canvas canvas, RecyclerView parent) {
95 | final int left = parent.getPaddingLeft();
96 | final int right = parent.getMeasuredWidth() - parent.getPaddingRight();
97 | final int childSize = parent.getChildCount();
98 |
99 | for (int i = 0; i < childSize; i++) {
100 | final View child = parent.getChildAt(i);
101 | //所有header和footer都不画线
102 | if (child.getTag() != null && child.getTag() instanceof String) {
103 | String tag = ((String) child.getTag());
104 | if ("reservedView".equals(tag)) {
105 | continue;
106 | }
107 | }
108 |
109 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
110 | final int top = child.getBottom() + layoutParams.bottomMargin;
111 | final int bottom = top + mDividerHeight;
112 | if (mDivider != null) {
113 | mDivider.setBounds(left, top, right, bottom);
114 | mDivider.draw(canvas);
115 | }
116 | if (mPaint != null) {
117 | canvas.drawRect(left, top, right, bottom, mPaint);
118 | }
119 | }
120 | }
121 |
122 | //绘制纵向 item 分割线
123 |
124 | private void drawVertical(Canvas canvas, RecyclerView parent) {
125 | final int top = parent.getPaddingTop();
126 | final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom();
127 | final int childSize = parent.getChildCount();
128 | for (int i = 0; i < childSize; i++) {
129 | final View child = parent.getChildAt(i);
130 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
131 | final int left = child.getRight() + layoutParams.rightMargin;
132 | final int right = left + mDividerHeight;
133 | if (mDivider != null) {
134 | mDivider.setBounds(left, top, right, bottom);
135 | mDivider.draw(canvas);
136 | }
137 | if (mPaint != null) {
138 | canvas.drawRect(left, top, right, bottom, mPaint);
139 | }
140 | }
141 | }
142 | }
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/hfooter/DefLoadMoreFooter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.hfooter;
11 |
12 | import android.content.Context;
13 | import androidx.recyclerview.widget.RecyclerView;
14 | import android.util.AttributeSet;
15 | import android.view.Gravity;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.widget.LinearLayout;
19 | import android.widget.ProgressBar;
20 | import android.widget.TextView;
21 |
22 | import com.zcolin.gui.pullrecyclerview.progressindicator.AVLoadingIndicatorView;
23 | import com.zcolin.gui.pullrecyclerview.progressindicator.ProgressStyle;
24 | import com.zcolin.gui.pullrecyclerview.progressindicator.SimpleViewSwitcher;
25 |
26 |
27 | /**
28 | * 默认的加载更多FooterView,如需要简单的变换,可以直接在{@link com.zcolin.gui.pullrecyclerview.PullRecyclerView}中设置
29 | * 复杂的需要继承此类重写或者实现{@link ILoadMoreFooter} 接口
30 | */
31 | public class DefLoadMoreFooter extends LinearLayout implements ILoadMoreFooter {
32 |
33 | public static String STR_LOADING = "正在加载";
34 | public static String STR_LOAD_COMPLETE = "正在加载";
35 | public static String STR_NOMORE = "已加载全部";
36 |
37 | private SimpleViewSwitcher mProgressBar;
38 | private TextView mText;
39 | private boolean isShowNoMore = true;
40 | private int mMeasuredHeight;
41 |
42 | public DefLoadMoreFooter(Context context) {
43 | this(context, null);
44 | }
45 |
46 | public DefLoadMoreFooter(Context context, AttributeSet attrs) {
47 | super(context, attrs);
48 | initView();
49 | }
50 |
51 | public void initView() {
52 | setGravity(Gravity.CENTER);
53 | setPadding(0, 25, 0, 25);
54 | setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
55 | ViewGroup.LayoutParams.WRAP_CONTENT));
56 | setProgressStyle(ProgressStyle.BallSpinFadeLoaderIndicator);
57 |
58 | mText = new TextView(getContext());
59 | mText.setText(STR_LOADING);
60 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
61 | ViewGroup.LayoutParams.WRAP_CONTENT);
62 | layoutParams.setMargins(20, 0, 0, 0);
63 | addView(mText, layoutParams);
64 |
65 | onReset();//初始为隐藏状态
66 |
67 | measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
68 | mMeasuredHeight = getMeasuredHeight();
69 | }
70 |
71 |
72 | public void setProgressStyle(String style) {
73 | if (mProgressBar == null) {
74 | mProgressBar = new SimpleViewSwitcher(getContext());
75 | mProgressBar.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
76 | ViewGroup.LayoutParams.WRAP_CONTENT));
77 | addView(mProgressBar);
78 | }
79 |
80 | if (ProgressStyle.SysProgress.equals(style)) {
81 | mProgressBar.setView(new ProgressBar(getContext(), null, android.R.attr.progressBarStyle));
82 | } else {
83 | AVLoadingIndicatorView progressView = new AVLoadingIndicatorView(this.getContext());
84 | progressView.setIndicatorColor(0xffB5B5B5);
85 | progressView.setIndicator(style);
86 | mProgressBar.setView(progressView);
87 | }
88 | }
89 |
90 | @Override
91 | public void setIsShowNoMore(boolean isShow) {
92 | isShowNoMore = isShow;
93 | }
94 |
95 | @Override
96 | public void onReset() {
97 | onComplete();
98 | }
99 |
100 | @Override
101 | public void onLoading() {
102 | mProgressBar.setVisibility(View.VISIBLE);
103 | mText.setText(STR_LOADING);
104 | this.getLayoutParams().height = mMeasuredHeight;//动态设置高度,否则在列表中会占位高度
105 | this.setVisibility(View.VISIBLE);
106 | }
107 |
108 | @Override
109 | public void onComplete() {
110 | mText.setText(STR_LOAD_COMPLETE);
111 | this.getLayoutParams().height = mMeasuredHeight;
112 | this.setVisibility(View.INVISIBLE);
113 | }
114 |
115 | @Override
116 | public void onNoMore() {
117 | mText.setText(STR_NOMORE);
118 | mProgressBar.setVisibility(View.GONE);
119 | this.setVisibility(isShowNoMore ? View.VISIBLE : View.GONE);
120 | this.getLayoutParams().height = isShowNoMore ? mMeasuredHeight : 5;
121 | }
122 |
123 | @Override
124 | public View getFootView() {
125 | return this;
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/hfooter/DefRefreshHeader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.hfooter;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.content.Context;
14 | import android.content.SharedPreferences;
15 | import android.os.Handler;
16 | import android.util.AttributeSet;
17 | import android.view.Gravity;
18 | import android.view.LayoutInflater;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 | import android.view.animation.Animation;
22 | import android.view.animation.RotateAnimation;
23 | import android.widget.ImageView;
24 | import android.widget.LinearLayout;
25 | import android.widget.ProgressBar;
26 | import android.widget.TextView;
27 |
28 | import com.zcolin.gui.pullrecyclerview.R;
29 | import com.zcolin.gui.pullrecyclerview.progressindicator.AVLoadingIndicatorView;
30 | import com.zcolin.gui.pullrecyclerview.progressindicator.ProgressStyle;
31 | import com.zcolin.gui.pullrecyclerview.progressindicator.SimpleViewSwitcher;
32 |
33 | /**
34 | * 默认的下拉更多HeaderView,如需要简单的变换,可以直接在{@link com.zcolin.gui.pullrecyclerview.PullRecyclerView}中设置
35 | * 复杂的需要继承此类重写或者实现{@link IRefreshHeader} 接口
36 | */
37 | public class DefRefreshHeader extends LinearLayout implements IRefreshHeader {
38 | private static final int ROTATE_ANIM_DURATION = 180;
39 |
40 | private int mState;
41 |
42 | private String strInfo1 = "下拉刷新";
43 | private String strInfo2 = "释放立即刷新";
44 | private String strInfo3 = "正在刷新";
45 | private String strInfo4 = "刷新完成";
46 |
47 | private LinearLayout mContainer;
48 | private ImageView mArrowImageView;
49 | private SimpleViewSwitcher mProgressBar;
50 | private TextView mStatusTextView;
51 | private TextView mHeaderTimeView;
52 |
53 | private Animation mRotateUpAnim;
54 | private Animation mRotateDownAnim;
55 |
56 | public int mMeasuredHeight;
57 |
58 | public DefRefreshHeader(Context context) {
59 | this(context, null);
60 | }
61 |
62 | public DefRefreshHeader(Context context, AttributeSet attrs) {
63 | super(context, attrs);
64 | initView();
65 | }
66 |
67 | private void initView() {
68 | // 初始情况,设置下拉刷新view高度为0
69 | LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
70 | lp.setMargins(0, 0, 0, 0);
71 | this.setLayoutParams(lp);
72 | this.setPadding(0, 0, 0, 0);
73 |
74 | mContainer = (LinearLayout) LayoutInflater.from(getContext())
75 | .inflate(R.layout.gui_pullrecyclerview_header, null);
76 | addView(mContainer, new LayoutParams(LayoutParams.MATCH_PARENT, 0));
77 | setGravity(Gravity.BOTTOM);
78 |
79 | mArrowImageView = findViewById(R.id.listview_header_arrow);
80 | mStatusTextView = findViewById(R.id.refresh_status_textview);
81 |
82 | mProgressBar = findViewById(R.id.listview_header_progressbar);
83 | setProgressStyle(ProgressStyle.BallSpinFadeLoaderIndicator);
84 |
85 | mRotateUpAnim = new RotateAnimation(0.0f,
86 | -180.0f,
87 | Animation.RELATIVE_TO_SELF,
88 | 0.5f,
89 | Animation.RELATIVE_TO_SELF,
90 | 0.5f);
91 | mRotateUpAnim.setDuration(ROTATE_ANIM_DURATION);
92 | mRotateUpAnim.setFillAfter(true);
93 |
94 | mRotateDownAnim = new RotateAnimation(-180.0f,
95 | 0.0f,
96 | Animation.RELATIVE_TO_SELF,
97 | 0.5f,
98 | Animation.RELATIVE_TO_SELF,
99 | 0.5f);
100 | mRotateDownAnim.setDuration(ROTATE_ANIM_DURATION);
101 | mRotateDownAnim.setFillAfter(true);
102 |
103 | mHeaderTimeView = findViewById(R.id.last_refresh_time);
104 | measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
105 | mMeasuredHeight = getMeasuredHeight();
106 | }
107 |
108 | /**
109 | * 设置加载进度框样式
110 | *
111 | * @param style {@link ProgressStyle}
112 | */
113 | public void setProgressStyle(String style) {
114 | if (ProgressStyle.SysProgress.equals(style)) {
115 | mProgressBar.setView(new ProgressBar(getContext(), null, android.R.attr.progressBarStyle));
116 | } else {
117 | AVLoadingIndicatorView progressView = new AVLoadingIndicatorView(this.getContext());
118 | progressView.setIndicatorColor(0xffB5B5B5);
119 | progressView.setIndicator(style);
120 | mProgressBar.setView(progressView);
121 | }
122 | }
123 |
124 | /**
125 | * 设置控件的不同状态的文字
126 | *
127 | * @param str1 下拉时显示的文字, 如‘下拉刷新’
128 | * @param str2 拉到可以刷新的距离显示 如‘释放立即刷新’
129 | * @param str3 刷新中的文字 如‘正在刷新’
130 | * @param str4 刷新完成的文字 如‘刷新完成’
131 | */
132 | public void setInfoText(String str1, String str2, String str3, String str4) {
133 | strInfo1 = str1;
134 | strInfo2 = str2;
135 | strInfo3 = str3;
136 | strInfo4 = str4;
137 | }
138 |
139 | /**
140 | * 设置下拉箭头的图标
141 | */
142 | public void setArrowImageView(int resid) {
143 | mArrowImageView.setImageResource(resid);
144 | }
145 |
146 |
147 | @Override
148 | public void onReset() {
149 | mArrowImageView.setVisibility(View.VISIBLE);
150 | mProgressBar.setVisibility(View.INVISIBLE);
151 |
152 | if (mState == STATE_PREPARED) {
153 | mArrowImageView.startAnimation(mRotateDownAnim);
154 | }
155 | if (mState == STATE_REFRESHING) {
156 | mArrowImageView.clearAnimation();
157 | }
158 | mStatusTextView.setText(strInfo1);
159 | mState = STATE_NORMAL;
160 | }
161 |
162 | @Override
163 | public void onPrepare() {
164 | mArrowImageView.setVisibility(View.VISIBLE);
165 | mProgressBar.setVisibility(View.INVISIBLE);
166 |
167 | if (mState != STATE_PREPARED) {
168 | mArrowImageView.clearAnimation();
169 | mArrowImageView.startAnimation(mRotateUpAnim);
170 | mStatusTextView.setText(strInfo2);
171 | }
172 | mState = STATE_PREPARED;
173 | }
174 |
175 | @Override
176 | public void onMove(float offSet, float sumOffSet) {
177 | if (getVisibleHeight() > 0 || offSet > 0) {
178 | setVisibleHeight((int) offSet + getVisibleHeight());
179 | if (mState <= STATE_PREPARED) { // 未处于刷新状态,更新箭头
180 | if (getVisibleHeight() > mMeasuredHeight) {
181 | onPrepare();
182 | } else {
183 | onReset();
184 | }
185 | }
186 | }
187 | }
188 |
189 | @Override
190 | public boolean onRelease() {
191 | int height = getVisibleHeight();
192 | if (height > mMeasuredHeight && mState < STATE_REFRESHING) {
193 | onRefreshing();
194 | }
195 |
196 | // refreshing and header isn't shown fully. do nothing.
197 | if (mState == STATE_REFRESHING && height <= mMeasuredHeight) {
198 | //return;
199 | }
200 |
201 | int destHeight = 0; // default: scroll back to dismiss header.
202 | // is refreshing, just scroll back to show all the header.
203 | if (mState == STATE_REFRESHING) {
204 | destHeight = mMeasuredHeight;
205 | }
206 | smoothScrollTo(destHeight);
207 | return mState == STATE_REFRESHING;
208 | }
209 |
210 | @Override
211 | public void onRefreshing() {
212 | mArrowImageView.clearAnimation();
213 | mArrowImageView.setVisibility(View.INVISIBLE);
214 | mProgressBar.setVisibility(View.VISIBLE);
215 | mStatusTextView.setText(strInfo3);
216 | mState = STATE_REFRESHING;
217 | }
218 |
219 | @Override
220 | public void onComplete() {
221 | mArrowImageView.setVisibility(View.INVISIBLE);
222 | mProgressBar.setVisibility(View.INVISIBLE);
223 |
224 | SharedPreferences pre = getContext().getApplicationContext()
225 | .getSharedPreferences("pullrecyclerview", Context.MODE_PRIVATE);
226 | mHeaderTimeView.setText(friendlyTime(pre.getLong("refresh_time", 0)));
227 | new Handler().postDelayed(() -> reset(), 200);
228 | mStatusTextView.setText(strInfo4);
229 |
230 | //当前刷新时间存入到本地
231 | long timestamp = System.currentTimeMillis();
232 | pre.edit().putLong("refresh_time", timestamp).apply();
233 | mState = STATE_COMPLETE;
234 | }
235 |
236 | /**
237 | * 回归初始状态,刷新完成时调用
238 | */
239 | private void reset() {
240 | smoothScrollTo(0);
241 | new Handler().postDelayed(() -> onReset(), 500);
242 | }
243 |
244 | /**
245 | * 平滑的显示Header偏移
246 | */
247 | private void smoothScrollTo(int destHeight) {
248 | ValueAnimator animator = ValueAnimator.ofInt(getVisibleHeight(), destHeight);
249 | animator.setDuration(300).start();
250 | animator.addUpdateListener(animation -> setVisibleHeight((int) animation.getAnimatedValue()));
251 | animator.start();
252 | }
253 |
254 |
255 | /**
256 | * 设置下拉Header需要显示的高度
257 | */
258 | private void setVisibleHeight(int height) {
259 | if (height < 0) {
260 | height = 0;
261 | }
262 | LayoutParams lp = (LayoutParams) mContainer.getLayoutParams();
263 | lp.height = height;
264 | mContainer.setLayoutParams(lp);
265 | }
266 |
267 |
268 | @Override
269 | public int getVisibleHeight() {
270 | LayoutParams lp = (LayoutParams) mContainer.getLayoutParams();
271 | return lp.height;
272 | }
273 |
274 | @Override
275 | public View getHeaderView() {
276 | return this;
277 | }
278 |
279 | private String friendlyTime(long timestamp) {
280 | if (timestamp == 0) {
281 | return "";
282 | }
283 |
284 | int ct = (int) ((System.currentTimeMillis() - timestamp) / 1000);
285 | if (ct >= 0 && ct < 60) {
286 | return "刚刚";
287 | }
288 | if (ct >= 60 && ct < 3600) {
289 | return Math.max(ct / 60, 1) + "分钟前";
290 | }
291 | if (ct >= 3600 && ct < 86400) {
292 | return ct / 3600 + "小时前";
293 | }
294 | if (ct >= 86400 && ct < 2592000) { //86400 * 30
295 | int day = ct / 86400;
296 | return day + "天前";
297 | }
298 | if (ct >= 2592000 && ct < 31104000) { //86400 * 30
299 | return ct / 2592000 + "月前";
300 | }
301 | return ct / 31104000 + "年前";
302 | }
303 | }
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/hfooter/ILoadMoreFooter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.hfooter;
11 |
12 | import android.view.View;
13 |
14 | /**
15 | * 加载更多FooterView需要实现的接口
16 | */
17 | public interface ILoadMoreFooter {
18 |
19 | /**
20 | * 状态回调,回复初始设置
21 | */
22 | void onReset();
23 |
24 | /**
25 | * 状态回调,加载中
26 | */
27 | void onLoading();
28 |
29 | /**
30 | * 状态回调,加载完成
31 | */
32 | void onComplete();
33 |
34 | /**
35 | * 状态回调,已全部加载完成
36 | */
37 | void onNoMore();
38 |
39 | /**
40 | * 是否显示没有更多
41 | */
42 | void setIsShowNoMore(boolean isShow);
43 |
44 | /**
45 | * 加载更多的View
46 | */
47 | View getFootView();
48 | }
49 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/hfooter/IRefreshHeader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.hfooter;
11 |
12 | import android.view.View;
13 |
14 | /**
15 | * 下拉HeadrView需要实现的接口
16 | */
17 | public interface IRefreshHeader {
18 |
19 | /**
20 | * 手势状态
21 | */
22 | int STATE_NORMAL = 0;
23 | int STATE_PREPARED = 1;
24 | int STATE_REFRESHING = 2;
25 | int STATE_COMPLETE = 3;
26 |
27 | void onReset();
28 |
29 | /**
30 | * 处于可以刷新的状态,已经过了指定距离
31 | */
32 | void onPrepare();
33 |
34 | /**
35 | * 正在刷新
36 | */
37 | void onRefreshing();
38 |
39 | /**
40 | * 下拉移动
41 | */
42 | void onMove(float offSet, float sumOffSet);
43 |
44 | /**
45 | * 下拉松开
46 | */
47 | boolean onRelease();
48 |
49 | /**
50 | * 下拉刷新完成
51 | */
52 | void onComplete();
53 |
54 | /**
55 | * 获取HeaderView
56 | */
57 | View getHeaderView();
58 |
59 | /**
60 | * 获取Header的显示高度
61 | */
62 | int getVisibleHeight();
63 | }
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/ProgressStyle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator;
11 |
12 | /**
13 | * Created by Jack on 2015/10/19.
14 | */
15 | public class ProgressStyle {
16 | public static final String SysProgress = "SysProgress";
17 | public static final String BallBeatIndicator = "BallBeatIndicator";
18 | public static final String BallClipRotateIndicator = "BallClipRotateIndicator";
19 | public static final String BallClipRotateMultipleIndicator = "BallClipRotateMultipleIndicator";
20 | public static final String BallClipRotatePulseIndicator = "BallClipRotatePulseIndicator";
21 | public static final String BallGridBeatIndicator = "BallGridBeatIndicator";
22 | public static final String BallGridPulseIndicator = "BallGridPulseIndicator";
23 | public static final String BallPulseIndicator = "BallPulseIndicator";
24 | public static final String BallPulseRiseIndicator = "BallPulseRiseIndicator";
25 | public static final String BallPulseSyncIndicator = "BallPulseSyncIndicator";
26 | public static final String BallRotateIndicator = "BallRotateIndicator";
27 | public static final String BallScaleIndicator = "BallScaleIndicator";
28 | public static final String BallScaleMultipleIndicator = "BallScaleMultipleIndicator";
29 | public static final String BallScaleRippleIndicator = "BallScaleRippleIndicator";
30 | public static final String BallScaleRippleMultipleIndicator = "BallScaleRippleMultipleIndicator";
31 | public static final String BallSpinFadeLoaderIndicator = "BallSpinFadeLoaderIndicator";
32 | public static final String BallTrianglePathIndicator = "BallTrianglePathIndicator";
33 | public static final String BallZigZagDeflectIndicator = "BallZigZagDeflectIndicator";
34 | public static final String BallZigZagIndicator = "BallZigZagIndicator";
35 | public static final String CubeTransitionIndicator = "CubeTransitionIndicator";
36 | public static final String LineScaleIndicator = "LineScaleIndicator";
37 | public static final String LineScalePartyIndicator = "LineScalePartyIndicator";
38 | public static final String LineScalePulseOutIndicator = "LineScalePulseOutIndicator";
39 | public static final String LineScalePulseOutRapidIndicator = "LineScalePulseOutRapidIndicator";
40 | public static final String LineSpinFadeLoaderIndicator = "LineSpinFadeLoaderIndicator";
41 | public static final String PacmanIndicator = "PacmanIndicator";
42 | public static final String SemiCircleSpinIndicator = "SemiCircleSpinIndicator";
43 | public static final String SquareSpinIndicator = "SquareSpinIndicator";
44 | public static final String TriangleSkewSpinIndicator = "TriangleSkewSpinIndicator";
45 | }
46 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/SimpleViewSwitcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator;
11 |
12 | import android.content.Context;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 |
17 | /**
18 | * Created by Jack on 2015/10/19.
19 | */
20 | public class SimpleViewSwitcher extends ViewGroup {
21 |
22 | public SimpleViewSwitcher(Context context) {
23 | super(context);
24 | }
25 |
26 | public SimpleViewSwitcher(Context context, AttributeSet attrs) {
27 | this(context, attrs, 0);
28 | }
29 |
30 | public SimpleViewSwitcher(Context context, AttributeSet attrs, int defStyle) {
31 | super(context, attrs, defStyle);
32 | }
33 |
34 | @Override
35 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
36 | int childCount = this.getChildCount();
37 | int maxHeight = 0;
38 | int maxWidth = 0;
39 | for (int i = 0; i < childCount; i++) {
40 | View child = this.getChildAt(i);
41 | this.measureChild(child, widthMeasureSpec, heightMeasureSpec);
42 | int cw = child.getMeasuredWidth();
43 | // int ch = child.getMeasuredHeight();
44 | maxWidth = child.getMeasuredWidth();
45 | maxHeight = child.getMeasuredHeight();
46 | }
47 | setMeasuredDimension(maxWidth, maxHeight);
48 | }
49 |
50 | @Override
51 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
52 | final int count = getChildCount();
53 | for (int i = 0; i < count; i++) {
54 | final View child = getChildAt(i);
55 | if (child.getVisibility() != View.GONE) {
56 | child.layout(0, 0, r - l, b - t);
57 |
58 | }
59 | }
60 | }
61 |
62 | public void setView(View view) {
63 | if (this.getChildCount() != 0) {
64 | this.removeViewAt(0);
65 | }
66 | this.addView(view, 0);
67 | }
68 |
69 | }
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallBeatIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 |
16 | import java.util.ArrayList;
17 |
18 | /**
19 | * Created by Jack on 2015/10/19.
20 | */
21 | public class BallBeatIndicator extends Indicator {
22 |
23 | public static final float SCALE = 1.0f;
24 |
25 | public static final int ALPHA = 255;
26 |
27 | private float[] scaleFloats = new float[]{SCALE, SCALE, SCALE};
28 |
29 | int[] alphas = new int[]{ALPHA, ALPHA, ALPHA,};
30 |
31 | @Override
32 | public void draw(Canvas canvas, Paint paint) {
33 | float circleSpacing = 4;
34 | float radius = (getWidth() - circleSpacing * 2) / 6;
35 | float x = getWidth() / 2 - (radius * 2 + circleSpacing);
36 | float y = getHeight() / 2;
37 | for (int i = 0; i < 3; i++) {
38 | canvas.save();
39 | float translateX = x + (radius * 2) * i + circleSpacing * i;
40 | canvas.translate(translateX, y);
41 | canvas.scale(scaleFloats[i], scaleFloats[i]);
42 | paint.setAlpha(alphas[i]);
43 | canvas.drawCircle(0, 0, radius, paint);
44 | canvas.restore();
45 | }
46 | }
47 |
48 | @Override
49 | public ArrayList onCreateAnimators() {
50 | ArrayList animators = new ArrayList<>();
51 | int[] delays = new int[]{350, 0, 350};
52 | for (int i = 0; i < 3; i++) {
53 | final int index = i;
54 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.75f, 1);
55 | scaleAnim.setDuration(700);
56 | scaleAnim.setRepeatCount(-1);
57 | scaleAnim.setStartDelay(delays[i]);
58 | addUpdateListener(scaleAnim, animation -> {
59 | scaleFloats[index] = (float) animation.getAnimatedValue();
60 | postInvalidate();
61 | });
62 |
63 | ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 51, 255);
64 | alphaAnim.setDuration(700);
65 | alphaAnim.setRepeatCount(-1);
66 | alphaAnim.setStartDelay(delays[i]);
67 | addUpdateListener(alphaAnim, animation -> {
68 | alphas[index] = (int) animation.getAnimatedValue();
69 | postInvalidate();
70 | });
71 | animators.add(scaleAnim);
72 | animators.add(alphaAnim);
73 | }
74 | return animators;
75 | }
76 |
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallClipRotateIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.graphics.RectF;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/16.
21 | */
22 | public class BallClipRotateIndicator extends Indicator {
23 |
24 | float scaleFloat = 1, degrees;
25 |
26 | @Override
27 | public void draw(Canvas canvas, Paint paint) {
28 | paint.setStyle(Paint.Style.STROKE);
29 | paint.setStrokeWidth(3);
30 |
31 | float circleSpacing = 12;
32 | float x = (getWidth()) / 2;
33 | float y = (getHeight()) / 2;
34 | canvas.translate(x, y);
35 | canvas.scale(scaleFloat, scaleFloat);
36 | canvas.rotate(degrees);
37 | RectF rectF = new RectF(-x + circleSpacing, -y + circleSpacing, 0 + x - circleSpacing, 0 + y - circleSpacing);
38 | canvas.drawArc(rectF, -45, 270, false, paint);
39 | }
40 |
41 | @Override
42 | public ArrayList onCreateAnimators() {
43 | ArrayList animators = new ArrayList<>();
44 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.6f, 0.5f, 1);
45 | scaleAnim.setDuration(750);
46 | scaleAnim.setRepeatCount(-1);
47 | addUpdateListener(scaleAnim, animation -> {
48 | scaleFloat = (float) animation.getAnimatedValue();
49 | postInvalidate();
50 | });
51 | ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360);
52 | rotateAnim.setDuration(750);
53 | rotateAnim.setRepeatCount(-1);
54 | addUpdateListener(rotateAnim, animation -> {
55 | degrees = (float) animation.getAnimatedValue();
56 | postInvalidate();
57 | });
58 | animators.add(scaleAnim);
59 | animators.add(rotateAnim);
60 | return animators;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallClipRotateMultipleIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.graphics.RectF;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/17.
21 | */
22 | public class BallClipRotateMultipleIndicator extends Indicator {
23 |
24 | float scaleFloat = 1, degrees;
25 |
26 |
27 | @Override
28 | public void draw(Canvas canvas, Paint paint) {
29 | paint.setStrokeWidth(3);
30 | paint.setStyle(Paint.Style.STROKE);
31 |
32 | float circleSpacing = 12;
33 | float x = getWidth() / 2;
34 | float y = getHeight() / 2;
35 |
36 | canvas.save();
37 |
38 | canvas.translate(x, y);
39 | canvas.scale(scaleFloat, scaleFloat);
40 | canvas.rotate(degrees);
41 |
42 | //draw two big arc
43 | float[] bStartAngles = new float[]{135, -45};
44 | for (int i = 0; i < 2; i++) {
45 | RectF rectF = new RectF(-x + circleSpacing, -y + circleSpacing, x - circleSpacing, y - circleSpacing);
46 | canvas.drawArc(rectF, bStartAngles[i], 90, false, paint);
47 | }
48 |
49 | canvas.restore();
50 | canvas.translate(x, y);
51 | canvas.scale(scaleFloat, scaleFloat);
52 | canvas.rotate(-degrees);
53 | //draw two small arc
54 | float[] sStartAngles = new float[]{225, 45};
55 | for (int i = 0; i < 2; i++) {
56 | RectF rectF = new RectF(-x / 1.8f + circleSpacing, -y / 1.8f + circleSpacing, x / 1.8f - circleSpacing, y / 1.8f - circleSpacing);
57 | canvas.drawArc(rectF, sStartAngles[i], 90, false, paint);
58 | }
59 | }
60 |
61 | @Override
62 | public ArrayList onCreateAnimators() {
63 | ArrayList animators = new ArrayList<>();
64 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.6f, 1);
65 | scaleAnim.setDuration(1000);
66 | scaleAnim.setRepeatCount(-1);
67 | addUpdateListener(scaleAnim, animation -> {
68 | scaleFloat = (float) animation.getAnimatedValue();
69 | postInvalidate();
70 | });
71 |
72 | ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360);
73 | rotateAnim.setDuration(1000);
74 | rotateAnim.setRepeatCount(-1);
75 | addUpdateListener(rotateAnim, animation -> {
76 | degrees = (float) animation.getAnimatedValue();
77 | postInvalidate();
78 | });
79 | animators.add(scaleAnim);
80 | animators.add(rotateAnim);
81 | return animators;
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallClipRotatePulseIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.graphics.RectF;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/16.
21 | */
22 | public class BallClipRotatePulseIndicator extends Indicator {
23 |
24 | float scaleFloat1, scaleFloat2, degrees;
25 |
26 |
27 | @Override
28 | public void draw(Canvas canvas, Paint paint) {
29 | float circleSpacing = 12;
30 | float x = getWidth() / 2;
31 | float y = getHeight() / 2;
32 |
33 | //draw fill circle
34 | canvas.save();
35 | canvas.translate(x, y);
36 | canvas.scale(scaleFloat1, scaleFloat1);
37 | paint.setStyle(Paint.Style.FILL);
38 | canvas.drawCircle(0, 0, x / 2.5f, paint);
39 |
40 | canvas.restore();
41 |
42 | canvas.translate(x, y);
43 | canvas.scale(scaleFloat2, scaleFloat2);
44 | canvas.rotate(degrees);
45 |
46 | paint.setStrokeWidth(3);
47 | paint.setStyle(Paint.Style.STROKE);
48 |
49 | //draw two arc
50 | float[] startAngles = new float[]{225, 45};
51 | for (int i = 0; i < 2; i++) {
52 | RectF rectF = new RectF(-x + circleSpacing, -y + circleSpacing, x - circleSpacing, y - circleSpacing);
53 | canvas.drawArc(rectF, startAngles[i], 90, false, paint);
54 | }
55 | }
56 |
57 | @Override
58 | public ArrayList onCreateAnimators() {
59 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.3f, 1);
60 | scaleAnim.setDuration(1000);
61 | scaleAnim.setRepeatCount(-1);
62 | addUpdateListener(scaleAnim, animation -> {
63 | scaleFloat1 = (float) animation.getAnimatedValue();
64 | postInvalidate();
65 | });
66 |
67 | ValueAnimator scaleAnim2 = ValueAnimator.ofFloat(1, 0.6f, 1);
68 | scaleAnim2.setDuration(1000);
69 | scaleAnim2.setRepeatCount(-1);
70 | addUpdateListener(scaleAnim2, animation -> {
71 | scaleFloat2 = (float) animation.getAnimatedValue();
72 | postInvalidate();
73 | });
74 |
75 | ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360);
76 | rotateAnim.setDuration(1000);
77 | rotateAnim.setRepeatCount(-1);
78 | addUpdateListener(rotateAnim, animation -> {
79 | degrees = (float) animation.getAnimatedValue();
80 | postInvalidate();
81 | });
82 | ArrayList animators = new ArrayList<>();
83 | animators.add(scaleAnim);
84 | animators.add(scaleAnim2);
85 | animators.add(rotateAnim);
86 | return animators;
87 | }
88 |
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallGridBeatIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 |
16 | import java.util.ArrayList;
17 |
18 | /**
19 | * Created by Jack on 2015/10/20.
20 | */
21 | public class BallGridBeatIndicator extends Indicator {
22 |
23 | public static final int ALPHA = 255;
24 |
25 | int[] alphas = new int[]{ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA};
26 |
27 | @Override
28 | public void draw(Canvas canvas, Paint paint) {
29 | float circleSpacing = 4;
30 | float radius = (getWidth() - circleSpacing * 4) / 6;
31 | float x = getWidth() / 2 - (radius * 2 + circleSpacing);
32 | float y = getWidth() / 2 - (radius * 2 + circleSpacing);
33 |
34 | for (int i = 0; i < 3; i++) {
35 | for (int j = 0; j < 3; j++) {
36 | canvas.save();
37 | float translateX = x + (radius * 2) * j + circleSpacing * j;
38 | float translateY = y + (radius * 2) * i + circleSpacing * i;
39 | canvas.translate(translateX, translateY);
40 | paint.setAlpha(alphas[3 * i + j]);
41 | canvas.drawCircle(0, 0, radius, paint);
42 | canvas.restore();
43 | }
44 | }
45 | }
46 |
47 | @Override
48 | public ArrayList onCreateAnimators() {
49 | ArrayList animators = new ArrayList<>();
50 |
51 | int[] durations = {960, 930, 1190, 1130, 1340, 940, 1200, 820, 1190};
52 | int[] delays = {360, 400, 680, 410, 710, -150, -120, 10, 320};
53 |
54 | for (int i = 0; i < 9; i++) {
55 | final int index = i;
56 | ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 168, 255);
57 | alphaAnim.setDuration(durations[i]);
58 | alphaAnim.setRepeatCount(-1);
59 | alphaAnim.setStartDelay(delays[i]);
60 | addUpdateListener(alphaAnim, animation -> {
61 | alphas[index] = (int) animation.getAnimatedValue();
62 | postInvalidate();
63 | });
64 | animators.add(alphaAnim);
65 | }
66 | return animators;
67 | }
68 |
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallGridPulseIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 |
16 | import java.util.ArrayList;
17 |
18 | /**
19 | * Created by Jack on 2015/10/16.
20 | */
21 | public class BallGridPulseIndicator extends Indicator {
22 |
23 | public static final int ALPHA = 255;
24 |
25 | public static final float SCALE = 1.0f;
26 |
27 | int[] alphas = new int[]{ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA};
28 |
29 | float[] scaleFloats = new float[]{SCALE, SCALE, SCALE, SCALE, SCALE, SCALE, SCALE, SCALE, SCALE};
30 |
31 |
32 | @Override
33 | public void draw(Canvas canvas, Paint paint) {
34 | float circleSpacing = 4;
35 | float radius = (getWidth() - circleSpacing * 4) / 6;
36 | float x = getWidth() / 2 - (radius * 2 + circleSpacing);
37 | float y = getWidth() / 2 - (radius * 2 + circleSpacing);
38 |
39 | for (int i = 0; i < 3; i++) {
40 | for (int j = 0; j < 3; j++) {
41 | canvas.save();
42 | float translateX = x + (radius * 2) * j + circleSpacing * j;
43 | float translateY = y + (radius * 2) * i + circleSpacing * i;
44 | canvas.translate(translateX, translateY);
45 | canvas.scale(scaleFloats[3 * i + j], scaleFloats[3 * i + j]);
46 | paint.setAlpha(alphas[3 * i + j]);
47 | canvas.drawCircle(0, 0, radius, paint);
48 | canvas.restore();
49 | }
50 | }
51 | }
52 |
53 | @Override
54 | public ArrayList onCreateAnimators() {
55 | ArrayList animators = new ArrayList<>();
56 | int[] durations = {720, 1020, 1280, 1420, 1450, 1180, 870, 1450, 1060};
57 | int[] delays = {-60, 250, -170, 480, 310, 30, 460, 780, 450};
58 |
59 | for (int i = 0; i < 9; i++) {
60 | final int index = i;
61 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.5f, 1);
62 | scaleAnim.setDuration(durations[i]);
63 | scaleAnim.setRepeatCount(-1);
64 | scaleAnim.setStartDelay(delays[i]);
65 | addUpdateListener(scaleAnim, animation -> {
66 | scaleFloats[index] = (float) animation.getAnimatedValue();
67 | postInvalidate();
68 | });
69 |
70 | ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 210, 122, 255);
71 | alphaAnim.setDuration(durations[i]);
72 | alphaAnim.setRepeatCount(-1);
73 | alphaAnim.setStartDelay(delays[i]);
74 | addUpdateListener(alphaAnim, animation -> {
75 | alphas[index] = (int) animation.getAnimatedValue();
76 | postInvalidate();
77 | });
78 | animators.add(scaleAnim);
79 | animators.add(alphaAnim);
80 | }
81 | return animators;
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallPulseIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 |
16 | import java.util.ArrayList;
17 |
18 | /**
19 | * Created by Jack on 2015/10/16.
20 | */
21 | public class BallPulseIndicator extends Indicator {
22 |
23 | public static final float SCALE = 1.0f;
24 |
25 | //scale x ,y
26 | private float[] scaleFloats = new float[]{SCALE, SCALE, SCALE};
27 |
28 |
29 | @Override
30 | public void draw(Canvas canvas, Paint paint) {
31 | float circleSpacing = 4;
32 | float radius = (Math.min(getWidth(), getHeight()) - circleSpacing * 2) / 6;
33 | float x = getWidth() / 2 - (radius * 2 + circleSpacing);
34 | float y = getHeight() / 2;
35 | for (int i = 0; i < 3; i++) {
36 | canvas.save();
37 | float translateX = x + (radius * 2) * i + circleSpacing * i;
38 | canvas.translate(translateX, y);
39 | canvas.scale(scaleFloats[i], scaleFloats[i]);
40 | canvas.drawCircle(0, 0, radius, paint);
41 | canvas.restore();
42 | }
43 | }
44 |
45 | @Override
46 | public ArrayList onCreateAnimators() {
47 | ArrayList animators = new ArrayList<>();
48 | int[] delays = new int[]{120, 240, 360};
49 | for (int i = 0; i < 3; i++) {
50 | final int index = i;
51 |
52 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.3f, 1);
53 |
54 | scaleAnim.setDuration(750);
55 | scaleAnim.setRepeatCount(-1);
56 | scaleAnim.setStartDelay(delays[i]);
57 |
58 | addUpdateListener(scaleAnim, animation -> {
59 | scaleFloats[index] = (float) animation.getAnimatedValue();
60 | postInvalidate();
61 | });
62 | animators.add(scaleAnim);
63 | }
64 | return animators;
65 | }
66 |
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallPulseRiseIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Camera;
14 | import android.graphics.Canvas;
15 | import android.graphics.Matrix;
16 | import android.graphics.Paint;
17 | import android.view.animation.LinearInterpolator;
18 |
19 | import java.util.ArrayList;
20 |
21 | /**
22 | * Created by Jack on 2015/10/17.
23 | */
24 | public class BallPulseRiseIndicator extends Indicator {
25 |
26 | private Camera mCamera;
27 | private Matrix mMatrix;
28 |
29 | private float degress;
30 |
31 | public BallPulseRiseIndicator() {
32 | mCamera = new Camera();
33 | mMatrix = new Matrix();
34 | }
35 |
36 | @Override
37 | public void draw(Canvas canvas, Paint paint) {
38 |
39 | mMatrix.reset();
40 | mCamera.save();
41 | mCamera.rotateX(degress);
42 | mCamera.getMatrix(mMatrix);
43 | mCamera.restore();
44 |
45 | mMatrix.preTranslate(-centerX(), -centerY());
46 | mMatrix.postTranslate(centerX(), centerY());
47 | canvas.concat(mMatrix);
48 |
49 | float radius = getWidth() / 10;
50 | canvas.drawCircle(getWidth() / 4, radius * 2, radius, paint);
51 | canvas.drawCircle(getWidth() * 3 / 4, radius * 2, radius, paint);
52 |
53 | canvas.drawCircle(radius, getHeight() - 2 * radius, radius, paint);
54 | canvas.drawCircle(getWidth() / 2, getHeight() - 2 * radius, radius, paint);
55 | canvas.drawCircle(getWidth() - radius, getHeight() - 2 * radius, radius, paint);
56 | }
57 |
58 | @Override
59 | public ArrayList onCreateAnimators() {
60 | ArrayList animators = new ArrayList<>();
61 | ValueAnimator animator = ValueAnimator.ofFloat(0, 360);
62 | addUpdateListener(animator, animation -> {
63 | degress = (float) animation.getAnimatedValue();
64 | postInvalidate();
65 | });
66 | animator.setInterpolator(new LinearInterpolator());
67 | animator.setRepeatCount(-1);
68 | animator.setDuration(1500);
69 | animators.add(animator);
70 | return animators;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallPulseSyncIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 |
16 | import java.util.ArrayList;
17 |
18 | /**
19 | * Created by Jack on 2015/10/19.
20 | */
21 | public class BallPulseSyncIndicator extends Indicator {
22 |
23 | float[] translateYFloats = new float[3];
24 |
25 | @Override
26 | public void draw(Canvas canvas, Paint paint) {
27 | float circleSpacing = 4;
28 | float radius = (getWidth() - circleSpacing * 2) / 6;
29 | float x = getWidth() / 2 - (radius * 2 + circleSpacing);
30 | for (int i = 0; i < 3; i++) {
31 | canvas.save();
32 | float translateX = x + (radius * 2) * i + circleSpacing * i;
33 | canvas.translate(translateX, translateYFloats[i]);
34 | canvas.drawCircle(0, 0, radius, paint);
35 | canvas.restore();
36 | }
37 | }
38 |
39 | @Override
40 | public ArrayList onCreateAnimators() {
41 | ArrayList animators = new ArrayList<>();
42 | float circleSpacing = 4;
43 | float radius = (getWidth() - circleSpacing * 2) / 6;
44 | int[] delays = new int[]{70, 140, 210};
45 | for (int i = 0; i < 3; i++) {
46 | final int index = i;
47 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(getHeight() / 2, getHeight() / 2 - radius * 2, getHeight() / 2);
48 | scaleAnim.setDuration(600);
49 | scaleAnim.setRepeatCount(-1);
50 | scaleAnim.setStartDelay(delays[i]);
51 | addUpdateListener(scaleAnim, animation -> {
52 | translateYFloats[index] = (float) animation.getAnimatedValue();
53 | postInvalidate();
54 | });
55 | animators.add(scaleAnim);
56 | }
57 | return animators;
58 | }
59 |
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallRotateIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Matrix;
15 | import android.graphics.Paint;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/17.
21 | */
22 | public class BallRotateIndicator extends Indicator {
23 |
24 | float scaleFloat = 0.5f;
25 |
26 | float degress;
27 |
28 | private Matrix mMatrix;
29 |
30 | public BallRotateIndicator() {
31 | mMatrix = new Matrix();
32 | }
33 |
34 | @Override
35 | public void draw(Canvas canvas, Paint paint) {
36 | float radius = getWidth() / 10;
37 | float x = getWidth() / 2;
38 | float y = getHeight() / 2;
39 |
40 | /*mMatrix.preTranslate(-centerX(), -centerY());
41 | mMatrix.preRotate(degress,centerX(),centerY());
42 | mMatrix.postTranslate(centerX(), centerY());
43 | canvas.concat(mMatrix);*/
44 |
45 | canvas.rotate(degress, centerX(), centerY());
46 |
47 | canvas.save();
48 | canvas.translate(x - radius * 2 - radius, y);
49 | canvas.scale(scaleFloat, scaleFloat);
50 | canvas.drawCircle(0, 0, radius, paint);
51 | canvas.restore();
52 |
53 | canvas.save();
54 | canvas.translate(x, y);
55 | canvas.scale(scaleFloat, scaleFloat);
56 | canvas.drawCircle(0, 0, radius, paint);
57 | canvas.restore();
58 |
59 | canvas.save();
60 | canvas.translate(x + radius * 2 + radius, y);
61 | canvas.scale(scaleFloat, scaleFloat);
62 | canvas.drawCircle(0, 0, radius, paint);
63 | canvas.restore();
64 | }
65 |
66 | @Override
67 | public ArrayList onCreateAnimators() {
68 | ArrayList animators = new ArrayList<>();
69 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(0.5f, 1, 0.5f);
70 | scaleAnim.setDuration(1000);
71 | scaleAnim.setRepeatCount(-1);
72 | addUpdateListener(scaleAnim, animation -> {
73 | scaleFloat = (float) animation.getAnimatedValue();
74 | postInvalidate();
75 | });
76 |
77 | ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360);
78 | addUpdateListener(rotateAnim, animation -> {
79 | degress = (float) animation.getAnimatedValue();
80 | postInvalidate();
81 | });
82 | rotateAnim.setDuration(1000);
83 | rotateAnim.setRepeatCount(-1);
84 |
85 | animators.add(scaleAnim);
86 | animators.add(rotateAnim);
87 | return animators;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallScaleIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.view.animation.LinearInterpolator;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/19.
21 | */
22 | public class BallScaleIndicator extends Indicator {
23 |
24 | float scale = 1;
25 | int alpha = 255;
26 |
27 | @Override
28 | public void draw(Canvas canvas, Paint paint) {
29 | float circleSpacing = 4;
30 | paint.setAlpha(alpha);
31 | canvas.scale(scale, scale, getWidth() / 2, getHeight() / 2);
32 | paint.setAlpha(alpha);
33 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2 - circleSpacing, paint);
34 | }
35 |
36 | @Override
37 | public ArrayList onCreateAnimators() {
38 | ArrayList animators = new ArrayList<>();
39 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(0, 1);
40 | scaleAnim.setInterpolator(new LinearInterpolator());
41 | scaleAnim.setDuration(1000);
42 | scaleAnim.setRepeatCount(-1);
43 | addUpdateListener(scaleAnim, animation -> {
44 | scale = (float) animation.getAnimatedValue();
45 | postInvalidate();
46 | });
47 |
48 | ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 0);
49 | alphaAnim.setInterpolator(new LinearInterpolator());
50 | alphaAnim.setDuration(1000);
51 | alphaAnim.setRepeatCount(-1);
52 | addUpdateListener(alphaAnim, animation -> {
53 | alpha = (int) animation.getAnimatedValue();
54 | postInvalidate();
55 | });
56 | animators.add(scaleAnim);
57 | animators.add(alphaAnim);
58 | return animators;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallScaleMultipleIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.view.animation.LinearInterpolator;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/19.
21 | */
22 | public class BallScaleMultipleIndicator extends Indicator {
23 |
24 | float[] scaleFloats = new float[]{1, 1, 1};
25 | int[] alphaInts = new int[]{255, 255, 255};
26 |
27 | @Override
28 | public void draw(Canvas canvas, Paint paint) {
29 | float circleSpacing = 4;
30 | for (int i = 0; i < 3; i++) {
31 | paint.setAlpha(alphaInts[i]);
32 | canvas.scale(scaleFloats[i], scaleFloats[i], getWidth() / 2, getHeight() / 2);
33 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2 - circleSpacing, paint);
34 | }
35 | }
36 |
37 | @Override
38 | public ArrayList onCreateAnimators() {
39 | ArrayList animators = new ArrayList<>();
40 | long[] delays = new long[]{0, 200, 400};
41 | for (int i = 0; i < 3; i++) {
42 | final int index = i;
43 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(0, 1);
44 | scaleAnim.setInterpolator(new LinearInterpolator());
45 | scaleAnim.setDuration(1000);
46 | scaleAnim.setRepeatCount(-1);
47 | addUpdateListener(scaleAnim, animation -> {
48 | scaleFloats[index] = (float) animation.getAnimatedValue();
49 | postInvalidate();
50 | });
51 | scaleAnim.setStartDelay(delays[i]);
52 |
53 | ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 0);
54 | alphaAnim.setInterpolator(new LinearInterpolator());
55 | alphaAnim.setDuration(1000);
56 | alphaAnim.setRepeatCount(-1);
57 | addUpdateListener(alphaAnim, animation -> {
58 | alphaInts[index] = (int) animation.getAnimatedValue();
59 | postInvalidate();
60 | });
61 | scaleAnim.setStartDelay(delays[i]);
62 |
63 | animators.add(scaleAnim);
64 | animators.add(alphaAnim);
65 | }
66 | return animators;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallScaleRippleIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.view.animation.LinearInterpolator;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/19.
21 | */
22 | public class BallScaleRippleIndicator extends BallScaleIndicator {
23 |
24 |
25 | @Override
26 | public void draw(Canvas canvas, Paint paint) {
27 | paint.setStyle(Paint.Style.STROKE);
28 | paint.setStrokeWidth(3);
29 | super.draw(canvas, paint);
30 | }
31 |
32 | @Override
33 | public ArrayList onCreateAnimators() {
34 | ArrayList animators = new ArrayList<>();
35 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(0, 1);
36 | scaleAnim.setInterpolator(new LinearInterpolator());
37 | scaleAnim.setDuration(1000);
38 | scaleAnim.setRepeatCount(-1);
39 | addUpdateListener(scaleAnim, animation -> {
40 | scale = (float) animation.getAnimatedValue();
41 | postInvalidate();
42 | });
43 |
44 | ValueAnimator alphaAnim = ValueAnimator.ofInt(0, 255);
45 | alphaAnim.setInterpolator(new LinearInterpolator());
46 | alphaAnim.setDuration(1000);
47 | alphaAnim.setRepeatCount(-1);
48 | addUpdateListener(alphaAnim, animation -> {
49 | alpha = (int) animation.getAnimatedValue();
50 | postInvalidate();
51 | });
52 |
53 | animators.add(scaleAnim);
54 | animators.add(alphaAnim);
55 | return animators;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallScaleRippleMultipleIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.view.animation.LinearInterpolator;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/19.
21 | */
22 | public class BallScaleRippleMultipleIndicator extends BallScaleMultipleIndicator {
23 |
24 |
25 | @Override
26 | public void draw(Canvas canvas, Paint paint) {
27 | paint.setStyle(Paint.Style.STROKE);
28 | paint.setStrokeWidth(3);
29 | super.draw(canvas, paint);
30 | }
31 |
32 | @Override
33 | public ArrayList onCreateAnimators() {
34 | ArrayList animators = new ArrayList<>();
35 | long[] delays = new long[]{0, 200, 400};
36 | for (int i = 0; i < 3; i++) {
37 | final int index = i;
38 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(0, 1);
39 | scaleAnim.setInterpolator(new LinearInterpolator());
40 | scaleAnim.setDuration(1000);
41 | scaleAnim.setRepeatCount(-1);
42 | addUpdateListener(scaleAnim, animation -> {
43 | scaleFloats[index] = (float) animation.getAnimatedValue();
44 | postInvalidate();
45 | });
46 | scaleAnim.setStartDelay(delays[i]);
47 |
48 | ValueAnimator alphaAnim = ValueAnimator.ofInt(0, 255);
49 | scaleAnim.setInterpolator(new LinearInterpolator());
50 | alphaAnim.setDuration(1000);
51 | alphaAnim.setRepeatCount(-1);
52 | addUpdateListener(alphaAnim, animation -> {
53 | alphaInts[index] = (int) animation.getAnimatedValue();
54 | postInvalidate();
55 | });
56 | scaleAnim.setStartDelay(delays[i]);
57 |
58 | animators.add(scaleAnim);
59 | animators.add(alphaAnim);
60 | }
61 | return animators;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallSpinFadeLoaderIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 |
16 | import java.util.ArrayList;
17 |
18 | /**
19 | * Created by Jack on 2015/10/20.
20 | */
21 | public class BallSpinFadeLoaderIndicator extends Indicator {
22 |
23 | public static final float SCALE = 1.0f;
24 |
25 | public static final int ALPHA = 255;
26 |
27 | float[] scaleFloats = new float[]{SCALE, SCALE, SCALE, SCALE, SCALE, SCALE, SCALE, SCALE};
28 |
29 | int[] alphas = new int[]{ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA};
30 |
31 |
32 | @Override
33 | public void draw(Canvas canvas, Paint paint) {
34 | float radius = getWidth() / 10;
35 | for (int i = 0; i < 8; i++) {
36 | canvas.save();
37 | Point point = circleAt(getWidth(), getHeight(), getWidth() / 2 - radius, i * (Math.PI / 4));
38 | canvas.translate(point.x, point.y);
39 | canvas.scale(scaleFloats[i], scaleFloats[i]);
40 | paint.setAlpha(alphas[i]);
41 | canvas.drawCircle(0, 0, radius, paint);
42 | canvas.restore();
43 | }
44 | }
45 |
46 | @Override
47 | public ArrayList onCreateAnimators() {
48 | ArrayList animators = new ArrayList<>();
49 | int[] delays = {0, 120, 240, 360, 480, 600, 720, 780, 840};
50 | for (int i = 0; i < 8; i++) {
51 | final int index = i;
52 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.4f, 1);
53 | scaleAnim.setDuration(1000);
54 | scaleAnim.setRepeatCount(-1);
55 | scaleAnim.setStartDelay(delays[i]);
56 | addUpdateListener(scaleAnim, animation -> {
57 | scaleFloats[index] = (float) animation.getAnimatedValue();
58 | postInvalidate();
59 | });
60 |
61 | ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 77, 255);
62 | alphaAnim.setDuration(1000);
63 | alphaAnim.setRepeatCount(-1);
64 | alphaAnim.setStartDelay(delays[i]);
65 | addUpdateListener(alphaAnim, animation -> {
66 | alphas[index] = (int) animation.getAnimatedValue();
67 | postInvalidate();
68 | });
69 | animators.add(scaleAnim);
70 | animators.add(alphaAnim);
71 | }
72 | return animators;
73 | }
74 |
75 | /**
76 | * 圆O的圆心为(a,b),半径为R,点A与到X轴的为角α.
77 | * 则点A的坐标为(a+R*cosα,b+R*sinα)
78 | */
79 | Point circleAt(int width, int height, float radius, double angle) {
80 | float x = (float) (width / 2 + radius * (Math.cos(angle)));
81 | float y = (float) (height / 2 + radius * (Math.sin(angle)));
82 | return new Point(x, y);
83 | }
84 |
85 | final class Point {
86 | public float x;
87 | public float y;
88 |
89 | public Point(float x, float y) {
90 | this.x = x;
91 | this.y = y;
92 | }
93 | }
94 |
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallTrianglePathIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.view.animation.LinearInterpolator;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/19.
21 | */
22 | public class BallTrianglePathIndicator extends Indicator {
23 |
24 | float[] translateX = new float[3], translateY = new float[3];
25 |
26 | @Override
27 | public void draw(Canvas canvas, Paint paint) {
28 | paint.setStrokeWidth(3);
29 | paint.setStyle(Paint.Style.STROKE);
30 | for (int i = 0; i < 3; i++) {
31 | canvas.save();
32 | canvas.translate(translateX[i], translateY[i]);
33 | canvas.drawCircle(0, 0, getWidth() / 10, paint);
34 | canvas.restore();
35 | }
36 | }
37 |
38 | @Override
39 | public ArrayList onCreateAnimators() {
40 | ArrayList animators = new ArrayList<>();
41 | float startX = getWidth() / 5;
42 | float startY = getWidth() / 5;
43 | for (int i = 0; i < 3; i++) {
44 | final int index = i;
45 | ValueAnimator translateXAnim = ValueAnimator.ofFloat(getWidth() / 2, getWidth() - startX, startX, getWidth() / 2);
46 | if (i == 1) {
47 | translateXAnim = ValueAnimator.ofFloat(getWidth() - startX, startX, getWidth() / 2, getWidth() - startX);
48 | } else if (i == 2) {
49 | translateXAnim = ValueAnimator.ofFloat(startX, getWidth() / 2, getWidth() - startX, startX);
50 | }
51 | ValueAnimator translateYAnim = ValueAnimator.ofFloat(startY, getHeight() - startY, getHeight() - startY, startY);
52 | if (i == 1) {
53 | translateYAnim = ValueAnimator.ofFloat(getHeight() - startY, getHeight() - startY, startY, getHeight() - startY);
54 | } else if (i == 2) {
55 | translateYAnim = ValueAnimator.ofFloat(getHeight() - startY, startY, getHeight() - startY, getHeight() - startY);
56 | }
57 |
58 | translateXAnim.setDuration(2000);
59 | translateXAnim.setInterpolator(new LinearInterpolator());
60 | translateXAnim.setRepeatCount(-1);
61 | addUpdateListener(translateXAnim, animation -> {
62 | translateX[index] = (float) animation.getAnimatedValue();
63 | postInvalidate();
64 | });
65 |
66 | translateYAnim.setDuration(2000);
67 | translateYAnim.setInterpolator(new LinearInterpolator());
68 | translateYAnim.setRepeatCount(-1);
69 | addUpdateListener(translateYAnim, animation -> {
70 | translateY[index] = (float) animation.getAnimatedValue();
71 | postInvalidate();
72 | });
73 |
74 | animators.add(translateXAnim);
75 | animators.add(translateYAnim);
76 | }
77 | return animators;
78 | }
79 |
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallZigZagDeflectIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 |
13 | import android.animation.ValueAnimator;
14 | import android.view.animation.LinearInterpolator;
15 |
16 | import java.util.ArrayList;
17 |
18 | /**
19 | * Created by Jack on 2015/10/19.
20 | */
21 | public class BallZigZagDeflectIndicator extends BallZigZagIndicator {
22 |
23 |
24 | @Override
25 | public ArrayList onCreateAnimators() {
26 | ArrayList animators = new ArrayList<>();
27 | float startX = getWidth() / 6;
28 | float startY = getWidth() / 6;
29 | for (int i = 0; i < 2; i++) {
30 | final int index = i;
31 | ValueAnimator translateXAnim = ValueAnimator.ofFloat(startX, getWidth() - startX, startX, getWidth() - startX, startX);
32 | if (i == 1) {
33 | translateXAnim = ValueAnimator.ofFloat(getWidth() - startX, startX, getWidth() - startX, startX, getWidth() - startX);
34 | }
35 | ValueAnimator translateYAnim = ValueAnimator.ofFloat(startY, startY, getHeight() - startY, getHeight() - startY, startY);
36 | if (i == 1) {
37 | translateYAnim = ValueAnimator.ofFloat(getHeight() - startY, getHeight() - startY, startY, startY, getHeight() - startY);
38 | }
39 |
40 | translateXAnim.setDuration(2000);
41 | translateXAnim.setInterpolator(new LinearInterpolator());
42 | translateXAnim.setRepeatCount(-1);
43 | addUpdateListener(translateXAnim, animation -> {
44 | translateX[index] = (float) animation.getAnimatedValue();
45 | postInvalidate();
46 | });
47 |
48 | translateYAnim.setDuration(2000);
49 | translateYAnim.setInterpolator(new LinearInterpolator());
50 | translateYAnim.setRepeatCount(-1);
51 | addUpdateListener(translateYAnim, animation -> {
52 | translateY[index] = (float) animation.getAnimatedValue();
53 | postInvalidate();
54 | });
55 |
56 | animators.add(translateXAnim);
57 | animators.add(translateYAnim);
58 | }
59 | return animators;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/BallZigZagIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.view.animation.LinearInterpolator;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/19.
21 | */
22 | public class BallZigZagIndicator extends Indicator {
23 |
24 | float[] translateX = new float[2], translateY = new float[2];
25 |
26 |
27 | @Override
28 | public void draw(Canvas canvas, Paint paint) {
29 | for (int i = 0; i < 2; i++) {
30 | canvas.save();
31 | canvas.translate(translateX[i], translateY[i]);
32 | canvas.drawCircle(0, 0, getWidth() / 10, paint);
33 | canvas.restore();
34 | }
35 | }
36 |
37 | @Override
38 | public ArrayList onCreateAnimators() {
39 | ArrayList animators = new ArrayList<>();
40 | float startX = getWidth() / 6;
41 | float startY = getWidth() / 6;
42 | for (int i = 0; i < 2; i++) {
43 | final int index = i;
44 | ValueAnimator translateXAnim = ValueAnimator.ofFloat(startX, getWidth() - startX, getWidth() / 2, startX);
45 | if (i == 1) {
46 | translateXAnim = ValueAnimator.ofFloat(getWidth() - startX, startX, getWidth() / 2, getWidth() - startX);
47 | }
48 | ValueAnimator translateYAnim = ValueAnimator.ofFloat(startY, startY, getHeight() / 2, startY);
49 | if (i == 1) {
50 | translateYAnim = ValueAnimator.ofFloat(getHeight() - startY, getHeight() - startY, getHeight() / 2, getHeight() - startY);
51 | }
52 |
53 | translateXAnim.setDuration(1000);
54 | translateXAnim.setInterpolator(new LinearInterpolator());
55 | translateXAnim.setRepeatCount(-1);
56 | addUpdateListener(translateXAnim, animation -> {
57 | translateX[index] = (float) animation.getAnimatedValue();
58 | postInvalidate();
59 | });
60 |
61 | translateYAnim.setDuration(1000);
62 | translateYAnim.setInterpolator(new LinearInterpolator());
63 | translateYAnim.setRepeatCount(-1);
64 | addUpdateListener(translateYAnim, animation -> {
65 | translateY[index] = (float) animation.getAnimatedValue();
66 | postInvalidate();
67 | });
68 | animators.add(translateXAnim);
69 | animators.add(translateYAnim);
70 | }
71 | return animators;
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/CubeTransitionIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.graphics.RectF;
16 | import android.view.animation.LinearInterpolator;
17 |
18 | import java.util.ArrayList;
19 |
20 | /**
21 | * Created by Jack on 2015/10/18.
22 | */
23 | public class CubeTransitionIndicator extends Indicator {
24 |
25 | float[] translateX = new float[2], translateY = new float[2];
26 | float degrees, scaleFloat = 1.0f;
27 |
28 | @Override
29 | public void draw(Canvas canvas, Paint paint) {
30 | float rWidth = getWidth() / 5;
31 | float rHeight = getHeight() / 5;
32 | for (int i = 0; i < 2; i++) {
33 | canvas.save();
34 | canvas.translate(translateX[i], translateY[i]);
35 | canvas.rotate(degrees);
36 | canvas.scale(scaleFloat, scaleFloat);
37 | RectF rectF = new RectF(-rWidth / 2, -rHeight / 2, rWidth / 2, rHeight / 2);
38 | canvas.drawRect(rectF, paint);
39 | canvas.restore();
40 | }
41 | }
42 |
43 | @Override
44 | public ArrayList onCreateAnimators() {
45 | ArrayList animators = new ArrayList<>();
46 | float startX = getWidth() / 5;
47 | float startY = getHeight() / 5;
48 | for (int i = 0; i < 2; i++) {
49 | final int index = i;
50 | translateX[index] = startX;
51 | ValueAnimator translationXAnim = ValueAnimator.ofFloat(startX, getWidth() - startX, getWidth() - startX, startX, startX);
52 | if (i == 1) {
53 | translationXAnim = ValueAnimator.ofFloat(getWidth() - startX, startX, startX, getWidth() - startX, getWidth() - startX);
54 | }
55 | translationXAnim.setInterpolator(new LinearInterpolator());
56 | translationXAnim.setDuration(1600);
57 | translationXAnim.setRepeatCount(-1);
58 | translationXAnim.addUpdateListener(animation -> {
59 | translateX[index] = (float) animation.getAnimatedValue();
60 | postInvalidate();
61 | });
62 | translateY[index] = startY;
63 | ValueAnimator translationYAnim = ValueAnimator.ofFloat(startY, startY, getHeight() - startY, getHeight() - startY, startY);
64 | if (i == 1) {
65 | translationYAnim = ValueAnimator.ofFloat(getHeight() - startY, getHeight() - startY, startY, startY, getHeight() - startY);
66 | }
67 | translationYAnim.setDuration(1600);
68 | translationYAnim.setInterpolator(new LinearInterpolator());
69 | translationYAnim.setRepeatCount(-1);
70 | addUpdateListener(translationYAnim, animation -> {
71 | translateY[index] = (float) animation.getAnimatedValue();
72 | postInvalidate();
73 | });
74 |
75 | animators.add(translationXAnim);
76 | animators.add(translationYAnim);
77 | }
78 |
79 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.5f, 1, 0.5f, 1);
80 | scaleAnim.setDuration(1600);
81 | scaleAnim.setInterpolator(new LinearInterpolator());
82 | scaleAnim.setRepeatCount(-1);
83 | addUpdateListener(scaleAnim, animation -> {
84 | scaleFloat = (float) animation.getAnimatedValue();
85 | postInvalidate();
86 | });
87 |
88 | ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360, 1.5f * 360, 2 * 360);
89 | rotateAnim.setDuration(1600);
90 | rotateAnim.setInterpolator(new LinearInterpolator());
91 | rotateAnim.setRepeatCount(-1);
92 | addUpdateListener(rotateAnim, animation -> {
93 | degrees = (float) animation.getAnimatedValue();
94 | postInvalidate();
95 | });
96 |
97 | animators.add(scaleAnim);
98 | animators.add(rotateAnim);
99 | return animators;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/Indicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Color;
15 | import android.graphics.ColorFilter;
16 | import android.graphics.Paint;
17 | import android.graphics.PixelFormat;
18 | import android.graphics.Rect;
19 | import android.graphics.drawable.Animatable;
20 | import android.graphics.drawable.Drawable;
21 |
22 | import java.util.ArrayList;
23 | import java.util.HashMap;
24 |
25 | /**
26 | * Created by Jack Wang on 2016/8/5.
27 | */
28 |
29 | public abstract class Indicator extends Drawable implements Animatable {
30 |
31 | private HashMap mUpdateListeners = new HashMap<>();
32 |
33 | private ArrayList mAnimators;
34 | private int alpha = 255;
35 | private static final Rect ZERO_BOUNDS_RECT = new Rect();
36 | protected Rect drawBounds = ZERO_BOUNDS_RECT;
37 |
38 | private boolean mHasAnimators;
39 |
40 | private Paint mPaint = new Paint();
41 |
42 | public Indicator() {
43 | mPaint.setColor(Color.WHITE);
44 | mPaint.setStyle(Paint.Style.FILL);
45 | mPaint.setAntiAlias(true);
46 | }
47 |
48 | public int getColor() {
49 | return mPaint.getColor();
50 | }
51 |
52 | public void setColor(int color) {
53 | mPaint.setColor(color);
54 | }
55 |
56 | @Override
57 | public void setAlpha(int alpha) {
58 | this.alpha = alpha;
59 | }
60 |
61 | @Override
62 | public int getAlpha() {
63 | return alpha;
64 | }
65 |
66 | @Override
67 | public int getOpacity() {
68 | return PixelFormat.OPAQUE;
69 | }
70 |
71 | @Override
72 | public void setColorFilter(ColorFilter colorFilter) {
73 |
74 | }
75 |
76 | @Override
77 | public void draw(Canvas canvas) {
78 | draw(canvas, mPaint);
79 | }
80 |
81 | public abstract void draw(Canvas canvas, Paint paint);
82 |
83 | public abstract ArrayList onCreateAnimators();
84 |
85 | @Override
86 | public void start() {
87 | ensureAnimators();
88 |
89 | if (mAnimators == null) {
90 | return;
91 | }
92 |
93 | // If the animators has not ended, do nothing.
94 | if (isStarted()) {
95 | return;
96 | }
97 | startAnimators();
98 | invalidateSelf();
99 | }
100 |
101 | private void startAnimators() {
102 | for (int i = 0; i < mAnimators.size(); i++) {
103 | ValueAnimator animator = mAnimators.get(i);
104 |
105 | //when the animator restart , add the updateListener again because they
106 | // was removed by animator stop .
107 | ValueAnimator.AnimatorUpdateListener updateListener = mUpdateListeners.get(animator);
108 | if (updateListener != null) {
109 | animator.addUpdateListener(updateListener);
110 | }
111 |
112 | animator.start();
113 | }
114 | }
115 |
116 | private void stopAnimators() {
117 | if (mAnimators != null) {
118 | for (ValueAnimator animator : mAnimators) {
119 | if (animator != null && animator.isStarted()) {
120 | animator.removeAllUpdateListeners();
121 | animator.end();
122 | }
123 | }
124 | }
125 | }
126 |
127 | private void ensureAnimators() {
128 | if (!mHasAnimators) {
129 | mAnimators = onCreateAnimators();
130 | mHasAnimators = true;
131 | }
132 | }
133 |
134 | @Override
135 | public void stop() {
136 | stopAnimators();
137 | }
138 |
139 | private boolean isStarted() {
140 | for (ValueAnimator animator : mAnimators) {
141 | return animator.isStarted();
142 | }
143 | return false;
144 | }
145 |
146 | @Override
147 | public boolean isRunning() {
148 | for (ValueAnimator animator : mAnimators) {
149 | return animator.isRunning();
150 | }
151 | return false;
152 | }
153 |
154 | /**
155 | * Your should use this to add AnimatorUpdateListener when
156 | * create animator , otherwise , animator doesn't work when
157 | * the animation restart .
158 | */
159 | public void addUpdateListener(ValueAnimator animator, ValueAnimator.AnimatorUpdateListener updateListener) {
160 | mUpdateListeners.put(animator, updateListener);
161 | }
162 |
163 | @Override
164 | protected void onBoundsChange(Rect bounds) {
165 | super.onBoundsChange(bounds);
166 | setDrawBounds(bounds);
167 | }
168 |
169 | public void setDrawBounds(Rect drawBounds) {
170 | setDrawBounds(drawBounds.left, drawBounds.top, drawBounds.right, drawBounds.bottom);
171 | }
172 |
173 | public void setDrawBounds(int left, int top, int right, int bottom) {
174 | this.drawBounds = new Rect(left, top, right, bottom);
175 | }
176 |
177 | public void postInvalidate() {
178 | invalidateSelf();
179 | }
180 |
181 | public Rect getDrawBounds() {
182 | return drawBounds;
183 | }
184 |
185 | public int getWidth() {
186 | return drawBounds.width();
187 | }
188 |
189 | public int getHeight() {
190 | return drawBounds.height();
191 | }
192 |
193 | public int centerX() {
194 | return drawBounds.centerX();
195 | }
196 |
197 | public int centerY() {
198 | return drawBounds.centerY();
199 | }
200 |
201 | public float exactCenterX() {
202 | return drawBounds.exactCenterX();
203 | }
204 |
205 | public float exactCenterY() {
206 | return drawBounds.exactCenterY();
207 | }
208 |
209 | }
210 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/LineScaleIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.graphics.RectF;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/19.
21 | */
22 | public class LineScaleIndicator extends Indicator {
23 |
24 | public static final float SCALE = 1.0f;
25 |
26 | float[] scaleYFloats = new float[]{SCALE, SCALE, SCALE, SCALE, SCALE,};
27 |
28 | @Override
29 | public void draw(Canvas canvas, Paint paint) {
30 | float translateX = getWidth() / 11;
31 | float translateY = getHeight() / 2;
32 | for (int i = 0; i < 5; i++) {
33 | canvas.save();
34 | canvas.translate((2 + i * 2) * translateX - translateX / 2, translateY);
35 | canvas.scale(SCALE, scaleYFloats[i]);
36 | RectF rectF = new RectF(-translateX / 2, -getHeight() / 2.5f, translateX / 2, getHeight() / 2.5f);
37 | canvas.drawRoundRect(rectF, 5, 5, paint);
38 | canvas.restore();
39 | }
40 | }
41 |
42 | @Override
43 | public ArrayList onCreateAnimators() {
44 | ArrayList animators = new ArrayList<>();
45 | long[] delays = new long[]{100, 200, 300, 400, 500};
46 | for (int i = 0; i < 5; i++) {
47 | final int index = i;
48 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.4f, 1);
49 | scaleAnim.setDuration(1000);
50 | scaleAnim.setRepeatCount(-1);
51 | scaleAnim.setStartDelay(delays[i]);
52 | addUpdateListener(scaleAnim, animation -> {
53 | scaleYFloats[index] = (float) animation.getAnimatedValue();
54 | postInvalidate();
55 | });
56 | animators.add(scaleAnim);
57 | }
58 | return animators;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/LineScalePartyIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.graphics.RectF;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/19.
21 | */
22 | public class LineScalePartyIndicator extends Indicator {
23 |
24 | public static final float SCALE = 1.0f;
25 |
26 | float[] scaleFloats = new float[]{SCALE, SCALE, SCALE, SCALE, SCALE,};
27 |
28 | @Override
29 | public void draw(Canvas canvas, Paint paint) {
30 | float translateX = getWidth() / 9;
31 | float translateY = getHeight() / 2;
32 | for (int i = 0; i < 4; i++) {
33 | canvas.save();
34 | canvas.translate((2 + i * 2) * translateX - translateX / 2, translateY);
35 | canvas.scale(scaleFloats[i], scaleFloats[i]);
36 | RectF rectF = new RectF(-translateX / 2, -getHeight() / 2.5f, translateX / 2, getHeight() / 2.5f);
37 | canvas.drawRoundRect(rectF, 5, 5, paint);
38 | canvas.restore();
39 | }
40 | }
41 |
42 |
43 | @Override
44 | public ArrayList onCreateAnimators() {
45 | ArrayList animators = new ArrayList<>();
46 | long[] durations = new long[]{1260, 430, 1010, 730};
47 | long[] delays = new long[]{770, 290, 280, 740};
48 | for (int i = 0; i < 4; i++) {
49 | final int index = i;
50 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.4f, 1);
51 | scaleAnim.setDuration(durations[i]);
52 | scaleAnim.setRepeatCount(-1);
53 | scaleAnim.setStartDelay(delays[i]);
54 | addUpdateListener(scaleAnim, animation -> {
55 | scaleFloats[index] = (float) animation.getAnimatedValue();
56 | postInvalidate();
57 | });
58 | animators.add(scaleAnim);
59 | }
60 | return animators;
61 | }
62 |
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/LineScalePulseOutIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 |
13 | import android.animation.ValueAnimator;
14 |
15 | import java.util.ArrayList;
16 |
17 | /**
18 | * Created by Jack on 2015/10/19.
19 | */
20 | public class LineScalePulseOutIndicator extends LineScaleIndicator {
21 |
22 | @Override
23 | public ArrayList onCreateAnimators() {
24 | ArrayList animators = new ArrayList<>();
25 | long[] delays = new long[]{500, 250, 0, 250, 500};
26 | for (int i = 0; i < 5; i++) {
27 | final int index = i;
28 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.3f, 1);
29 | scaleAnim.setDuration(900);
30 | scaleAnim.setRepeatCount(-1);
31 | scaleAnim.setStartDelay(delays[i]);
32 | addUpdateListener(scaleAnim, animation -> {
33 | scaleYFloats[index] = (float) animation.getAnimatedValue();
34 | postInvalidate();
35 | });
36 | animators.add(scaleAnim);
37 | }
38 | return animators;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/LineScalePulseOutRapidIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 |
13 | import android.animation.ValueAnimator;
14 |
15 | import java.util.ArrayList;
16 |
17 | /**
18 | * Created by Jack on 2015/10/19.
19 | */
20 | public class LineScalePulseOutRapidIndicator extends LineScaleIndicator {
21 |
22 | @Override
23 | public ArrayList onCreateAnimators() {
24 | ArrayList animators = new ArrayList<>();
25 | long[] delays = new long[]{400, 200, 0, 200, 400};
26 | for (int i = 0; i < 5; i++) {
27 | final int index = i;
28 | ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.4f, 1);
29 | scaleAnim.setDuration(1000);
30 | scaleAnim.setRepeatCount(-1);
31 | scaleAnim.setStartDelay(delays[i]);
32 | addUpdateListener(scaleAnim, animation -> {
33 | scaleYFloats[index] = (float) animation.getAnimatedValue();
34 | postInvalidate();
35 | });
36 | animators.add(scaleAnim);
37 | }
38 | return animators;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/LineSpinFadeLoaderIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.graphics.Canvas;
13 | import android.graphics.Paint;
14 | import android.graphics.RectF;
15 |
16 | /**
17 | * Created by Jack on 2015/10/24.
18 | * Email:81813780@qq.com
19 | */
20 | public class LineSpinFadeLoaderIndicator extends BallSpinFadeLoaderIndicator {
21 |
22 |
23 | @Override
24 | public void draw(Canvas canvas, Paint paint) {
25 | float radius = getWidth() / 10;
26 | for (int i = 0; i < 8; i++) {
27 | canvas.save();
28 | Point point = circleAt(getWidth(), getHeight(), getWidth() / 2.5f - radius, i * (Math.PI / 4));
29 | canvas.translate(point.x, point.y);
30 | canvas.scale(scaleFloats[i], scaleFloats[i]);
31 | canvas.rotate(i * 45);
32 | paint.setAlpha(alphas[i]);
33 | RectF rectF = new RectF(-radius, -radius / 1.5f, 1.5f * radius, radius / 1.5f);
34 | canvas.drawRoundRect(rectF, 5, 5, paint);
35 | canvas.restore();
36 | }
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/PacmanIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.graphics.RectF;
16 | import android.view.animation.LinearInterpolator;
17 |
18 | import java.util.ArrayList;
19 |
20 | /**
21 | * Created by Jack on 2015/10/16.
22 | */
23 | public class PacmanIndicator extends Indicator {
24 |
25 | private float translateX;
26 |
27 | private int alpha;
28 |
29 | private float degrees1, degrees2;
30 |
31 | @Override
32 | public void draw(Canvas canvas, Paint paint) {
33 | drawPacman(canvas, paint);
34 | drawCircle(canvas, paint);
35 | }
36 |
37 | private void drawPacman(Canvas canvas, Paint paint) {
38 | float x = getWidth() / 2;
39 | float y = getHeight() / 2;
40 |
41 | canvas.save();
42 |
43 | canvas.translate(x, y);
44 | canvas.rotate(degrees1);
45 | paint.setAlpha(255);
46 | RectF rectF1 = new RectF(-x / 1.7f, -y / 1.7f, x / 1.7f, y / 1.7f);
47 | canvas.drawArc(rectF1, 0, 270, true, paint);
48 |
49 | canvas.restore();
50 |
51 | canvas.save();
52 | canvas.translate(x, y);
53 | canvas.rotate(degrees2);
54 | paint.setAlpha(255);
55 | RectF rectF2 = new RectF(-x / 1.7f, -y / 1.7f, x / 1.7f, y / 1.7f);
56 | canvas.drawArc(rectF2, 90, 270, true, paint);
57 | canvas.restore();
58 | }
59 |
60 |
61 | private void drawCircle(Canvas canvas, Paint paint) {
62 | float radius = getWidth() / 11;
63 | paint.setAlpha(alpha);
64 | canvas.drawCircle(translateX, getHeight() / 2, radius, paint);
65 | }
66 |
67 | @Override
68 | public ArrayList onCreateAnimators() {
69 | ArrayList animators = new ArrayList<>();
70 | float startT = getWidth() / 11;
71 | ValueAnimator translationAnim = ValueAnimator.ofFloat(getWidth() - startT, getWidth() / 2);
72 | translationAnim.setDuration(650);
73 | translationAnim.setInterpolator(new LinearInterpolator());
74 | translationAnim.setRepeatCount(-1);
75 | addUpdateListener(translationAnim, animation -> {
76 | translateX = (float) animation.getAnimatedValue();
77 | postInvalidate();
78 | });
79 |
80 | ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 122);
81 | alphaAnim.setDuration(650);
82 | alphaAnim.setRepeatCount(-1);
83 | addUpdateListener(alphaAnim, animation -> {
84 | alpha = (int) animation.getAnimatedValue();
85 | postInvalidate();
86 | });
87 |
88 | ValueAnimator rotateAnim1 = ValueAnimator.ofFloat(0, 45, 0);
89 | rotateAnim1.setDuration(650);
90 | rotateAnim1.setRepeatCount(-1);
91 | addUpdateListener(rotateAnim1, animation -> {
92 | degrees1 = (float) animation.getAnimatedValue();
93 | postInvalidate();
94 | });
95 |
96 | ValueAnimator rotateAnim2 = ValueAnimator.ofFloat(0, -45, 0);
97 | rotateAnim2.setDuration(650);
98 | rotateAnim2.setRepeatCount(-1);
99 | addUpdateListener(rotateAnim2, animation -> {
100 | degrees2 = (float) animation.getAnimatedValue();
101 | postInvalidate();
102 | });
103 |
104 | animators.add(translationAnim);
105 | animators.add(alphaAnim);
106 | animators.add(rotateAnim1);
107 | animators.add(rotateAnim2);
108 | return animators;
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/SemiCircleSpinIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Canvas;
14 | import android.graphics.Paint;
15 | import android.graphics.RectF;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by Jack on 2015/10/20.
21 | */
22 | public class SemiCircleSpinIndicator extends Indicator {
23 |
24 | private float degress;
25 |
26 | @Override
27 | public void draw(Canvas canvas, Paint paint) {
28 | canvas.rotate(degress, centerX(), centerY());
29 | RectF rectF = new RectF(0, 0, getWidth(), getHeight());
30 | canvas.drawArc(rectF, -60, 120, false, paint);
31 | }
32 |
33 | @Override
34 | public ArrayList onCreateAnimators() {
35 | ArrayList animators = new ArrayList<>();
36 | ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360);
37 | addUpdateListener(rotateAnim, animation -> {
38 | degress = (float) animation.getAnimatedValue();
39 | postInvalidate();
40 | });
41 | rotateAnim.setDuration(600);
42 | rotateAnim.setRepeatCount(-1);
43 | animators.add(rotateAnim);
44 | return animators;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/SquareSpinIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Camera;
14 | import android.graphics.Canvas;
15 | import android.graphics.Matrix;
16 | import android.graphics.Paint;
17 | import android.graphics.RectF;
18 | import android.view.animation.LinearInterpolator;
19 |
20 | import java.util.ArrayList;
21 |
22 | /**
23 | * Created by Jack on 2015/10/16.
24 | */
25 | public class SquareSpinIndicator extends Indicator {
26 |
27 | private float rotateX;
28 | private float rotateY;
29 |
30 | private Camera mCamera;
31 | private Matrix mMatrix;
32 |
33 | public SquareSpinIndicator() {
34 | mCamera = new Camera();
35 | mMatrix = new Matrix();
36 | }
37 |
38 | @Override
39 | public void draw(Canvas canvas, Paint paint) {
40 |
41 | mMatrix.reset();
42 | mCamera.save();
43 | mCamera.rotateX(rotateX);
44 | mCamera.rotateY(rotateY);
45 | mCamera.getMatrix(mMatrix);
46 | mCamera.restore();
47 |
48 | mMatrix.preTranslate(-centerX(), -centerY());
49 | mMatrix.postTranslate(centerX(), centerY());
50 | canvas.concat(mMatrix);
51 |
52 | canvas.drawRect(new RectF(getWidth() / 5, getHeight() / 5, getWidth() * 4 / 5, getHeight() * 4 / 5), paint);
53 | }
54 |
55 | @Override
56 | public ArrayList onCreateAnimators() {
57 | ArrayList animators = new ArrayList<>();
58 | ValueAnimator animator = ValueAnimator.ofFloat(0, 180, 180, 0, 0);
59 | addUpdateListener(animator, animation -> {
60 | rotateX = (float) animation.getAnimatedValue();
61 | postInvalidate();
62 | });
63 | animator.setInterpolator(new LinearInterpolator());
64 | animator.setRepeatCount(-1);
65 | animator.setDuration(2500);
66 |
67 | ValueAnimator animator1 = ValueAnimator.ofFloat(0, 0, 180, 180, 0);
68 | addUpdateListener(animator1, animation -> {
69 | rotateY = (float) animation.getAnimatedValue();
70 | postInvalidate();
71 | });
72 | animator1.setInterpolator(new LinearInterpolator());
73 | animator1.setRepeatCount(-1);
74 | animator1.setDuration(2500);
75 |
76 | animators.add(animator);
77 | animators.add(animator1);
78 | return animators;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/java/com/zcolin/gui/pullrecyclerview/progressindicator/indicators/TriangleSkewSpinIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 | package com.zcolin.gui.pullrecyclerview.progressindicator.indicators;
11 |
12 | import android.animation.ValueAnimator;
13 | import android.graphics.Camera;
14 | import android.graphics.Canvas;
15 | import android.graphics.Matrix;
16 | import android.graphics.Paint;
17 | import android.graphics.Path;
18 | import android.view.animation.LinearInterpolator;
19 |
20 | import java.util.ArrayList;
21 |
22 | /**
23 | * Created by Jack on 2015/10/20.
24 | */
25 | public class TriangleSkewSpinIndicator extends Indicator {
26 |
27 | private float rotateX;
28 | private float rotateY;
29 |
30 | private Camera mCamera;
31 | private Matrix mMatrix;
32 |
33 | public TriangleSkewSpinIndicator() {
34 | mCamera = new Camera();
35 | mMatrix = new Matrix();
36 | }
37 |
38 | @Override
39 | public void draw(Canvas canvas, Paint paint) {
40 |
41 |
42 | mMatrix.reset();
43 | mCamera.save();
44 | mCamera.rotateX(rotateX);
45 | mCamera.rotateY(rotateY);
46 | mCamera.getMatrix(mMatrix);
47 | mCamera.restore();
48 |
49 | mMatrix.preTranslate(-centerX(), -centerY());
50 | mMatrix.postTranslate(centerX(), centerY());
51 | canvas.concat(mMatrix);
52 |
53 | Path path = new Path();
54 | path.moveTo(getWidth() / 5, getHeight() * 4 / 5);
55 | path.lineTo(getWidth() * 4 / 5, getHeight() * 4 / 5);
56 | path.lineTo(getWidth() / 2, getHeight() / 5);
57 | path.close();
58 | canvas.drawPath(path, paint);
59 | }
60 |
61 | @Override
62 | public ArrayList onCreateAnimators() {
63 | ArrayList animators = new ArrayList<>();
64 | ValueAnimator animator = ValueAnimator.ofFloat(0, 180, 180, 0, 0);
65 | addUpdateListener(animator, animation -> {
66 | rotateX = (float) animation.getAnimatedValue();
67 | postInvalidate();
68 | });
69 | animator.setInterpolator(new LinearInterpolator());
70 | animator.setRepeatCount(-1);
71 | animator.setDuration(2500);
72 |
73 | ValueAnimator animator1 = ValueAnimator.ofFloat(0, 0, 180, 180, 0);
74 | addUpdateListener(animator1, animation -> {
75 | rotateY = (float) animation.getAnimatedValue();
76 | postInvalidate();
77 | });
78 | animator1.setInterpolator(new LinearInterpolator());
79 | animator1.setRepeatCount(-1);
80 | animator1.setDuration(2500);
81 |
82 | animators.add(animator);
83 | animators.add(animator1);
84 | return animators;
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/res/drawable-xhdpi/gui_ic_pullrecyclerview_loading_rotate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcolin/PullRecyclerView/ec3a31489769d8c0f3935a928f4aef03fc5eab16/libPullRecyclerView/src/main/res/drawable-xhdpi/gui_ic_pullrecyclerview_loading_rotate.png
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/res/drawable-xhdpi/gui_ic_pullrecyclerview_pulltorefresh_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcolin/PullRecyclerView/ec3a31489769d8c0f3935a928f4aef03fc5eab16/libPullRecyclerView/src/main/res/drawable-xhdpi/gui_ic_pullrecyclerview_pulltorefresh_arrow.png
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/res/layout/gui_pullrecyclerview_footer.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
23 |
24 |
31 |
32 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/res/layout/gui_pullrecyclerview_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
22 |
23 |
31 |
32 |
37 |
38 |
43 |
44 |
49 |
50 |
55 |
56 |
57 |
58 |
67 |
68 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/res/values/gui_zrecycler_view_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/res/values/gui_zrecycler_view_ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/libPullRecyclerView/src/main/res/values/gui_zrecycler_view_style.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
20 |
21 |
28 |
29 |
36 |
37 |
--------------------------------------------------------------------------------
/screenshot/1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcolin/PullRecyclerView/ec3a31489769d8c0f3935a928f4aef03fc5eab16/screenshot/1.gif
--------------------------------------------------------------------------------
/screenshot/2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcolin/PullRecyclerView/ec3a31489769d8c0f3935a928f4aef03fc5eab16/screenshot/2.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * *********************************************************
3 | * author colin
4 | * company telchina
5 | * email wanglin2046@126.com
6 | * date 18-1-9 下午3:05
7 | * ********************************************************
8 | */
9 |
10 |
11 |
12 |
13 |
14 | include ':app', ':libPullRecyclerView'
--------------------------------------------------------------------------------