├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── org
│ │ └── raphets
│ │ └── demorecyclerview
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── org
│ │ │ └── raphets
│ │ │ └── demorecyclerview
│ │ │ ├── DefaultItemTouchHelpCallback.java
│ │ │ ├── adapter
│ │ │ ├── BaseAdapter.java
│ │ │ ├── BaseLoadMoreAdapter.java
│ │ │ ├── BaseLoadMoreAdapter2.java
│ │ │ ├── BaseLoadMoreHeaderAdapter.java
│ │ │ └── BaseViewHolder.java
│ │ │ ├── ui
│ │ │ ├── DragSwipeActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── PullRefreshActivity.java
│ │ │ ├── PullRefreshNoTipActivity.java
│ │ │ └── SupportHeadViewActivity.java
│ │ │ └── utils
│ │ │ └── SnackbarUtil.java
│ └── res
│ │ ├── anim
│ │ ├── layoutanimation.xml
│ │ └── load_anim.xml
│ │ ├── drawable
│ │ └── jr14.jpg
│ │ ├── layout-v21
│ │ └── progress_item.xml
│ │ ├── layout
│ │ ├── activity_drag_swipe.xml
│ │ ├── activity_main.xml
│ │ ├── activity_pull_refresh.xml
│ │ ├── activity_pull_refresh_no_tip.xml
│ │ ├── headview.xml
│ │ ├── item.xml
│ │ └── progress_item.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── org
│ └── raphets
│ └── demorecyclerview
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── projectFilesBackup
└── .idea
│ └── workspace.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | DemoRecyclerView
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 对RecyclerViewAdapter进行了封装,使用起来将更简单。
2 |
3 | - 封装了OnItemClickListener,onLongItemClickListener
4 |
5 | * 封装了上拉加载OnLoadMoreListener
6 |
7 | - 封装了HeadView
8 |
9 | #######使用示例:
10 |
11 | 写一个Adapter继承BaseLoadMoreHeaderAdapter
12 | ```
13 | class MyAdapter extends BaseLoadMoreHeaderAdapter {
14 | public MyAdapter(Context mContext, RecyclerView recyclerView, List mDatas, int mLayoutId) {
15 | super(mContext, recyclerView, mDatas, mLayoutId);
16 | }
17 |
18 | @Override
19 | public void convert(Context mContext, RecyclerView.ViewHolder holder, String s) {
20 | if (holder instanceof BaseViewHolder){
21 | ((BaseViewHolder) holder).setText(R.id.tv,s);
22 | }
23 | }
24 | }
25 | ```
26 |
27 | 在Activity中为RecyclerView设置Adapter
28 |
29 | ```
30 | LinearLayoutManager layoutManager=new LinearLayoutManager(this);
31 | mAdapter=new MyAdapter(this,mRecyclerView,mDatas,R.layout.item);
32 | mRecyclerView.setLayoutManager(layoutManager);
33 | View headView= LayoutInflater.from(this).inflate(R.layout.headview,mRecyclerView,false);
34 | mAdapter.addHeadView(headView);
35 | mRecyclerView.setAdapter(mAdapter);
36 |
37 | mAdapter.setOnLoadMoreListener(new BaseLoadMoreHeaderAdapter.OnLoadMoreListener() {
38 | @Override
39 | public void onLoadMore() {
40 | loadMore();
41 | }
42 | });
43 |
44 | mAdapter.setOnItemClickListener(new BaseLoadMoreHeaderAdapter.OnItemClickListener() {
45 | @Override
46 | public void onItemClick(View view, int position) {
47 | Toast.makeText(getApplicationContext(),position+"",Toast.LENGTH_SHORT).show();
48 |
49 | }
50 | });
51 | ```
52 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.2"
6 |
7 | defaultConfig {
8 | applicationId "org.raphets.demorecyclerview"
9 | minSdkVersion 19
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:24.2.1'
26 | compile 'com.android.support:recyclerview-v7:24.2.1'
27 | compile 'com.android.support:cardview-v7:24.2.1'
28 | compile 'com.android.support:design:24.2.1'
29 | }
30 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android-SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/org/raphets/demorecyclerview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/DefaultItemTouchHelpCallback.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview;
2 |
3 | import android.support.v7.widget.GridLayoutManager;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.support.v7.widget.helper.ItemTouchHelper;
7 |
8 | /**
9 | * Created by codeest on 2016/8/24.
10 | * http://blog.csdn.net/yanzhenjie1003/article/details/51935982
11 | */
12 |
13 | public class DefaultItemTouchHelpCallback extends ItemTouchHelper.Callback {
14 |
15 | /**
16 | * Item操作的回调
17 | */
18 | private OnItemTouchCallbackListener onItemTouchCallbackListener;
19 |
20 | /**
21 | * 是否可以拖拽
22 | */
23 | private boolean isCanDrag = true;
24 | /**
25 | * 是否可以被滑动
26 | */
27 | private boolean isCanSwipe = true;
28 |
29 | public DefaultItemTouchHelpCallback(OnItemTouchCallbackListener onItemTouchCallbackListener) {
30 | this.onItemTouchCallbackListener = onItemTouchCallbackListener;
31 | }
32 |
33 | /**
34 | * 设置Item操作的回调,去更新UI和数据源
35 | *
36 | * @param onItemTouchCallbackListener
37 | */
38 | public void setOnItemTouchCallbackListener(OnItemTouchCallbackListener onItemTouchCallbackListener) {
39 | this.onItemTouchCallbackListener = onItemTouchCallbackListener;
40 | }
41 |
42 | /**
43 | * 设置是否可以被拖拽
44 | *
45 | * @param canDrag 是true,否false
46 | */
47 | public void setDragEnable(boolean canDrag) {
48 | isCanDrag = canDrag;
49 | }
50 |
51 | /**
52 | * 设置是否可以被滑动
53 | *
54 | * @param canSwipe 是true,否false
55 | */
56 | public void setSwipeEnable(boolean canSwipe) {
57 | isCanSwipe = canSwipe;
58 | }
59 |
60 | /**
61 | * 当Item被长按的时候是否可以被拖拽
62 | *
63 | * @return
64 | */
65 | @Override
66 | public boolean isLongPressDragEnabled() {
67 | return isCanDrag;
68 | }
69 |
70 | /**
71 | * Item是否可以被滑动(H:左右滑动,V:上下滑动)
72 | *
73 | * @return
74 | */
75 | @Override
76 | public boolean isItemViewSwipeEnabled() {
77 | return isCanSwipe;
78 | }
79 |
80 | /**
81 | * 当用户拖拽或者滑动Item的时候需要我们告诉系统滑动或者拖拽的方向
82 | *
83 | * @param recyclerView
84 | * @param viewHolder
85 | * @return
86 | */
87 | @Override
88 | public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
89 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
90 | if (layoutManager instanceof GridLayoutManager) {// GridLayoutManager
91 | // flag如果值是0,相当于这个功能被关闭
92 | int dragFlag = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT | ItemTouchHelper.UP | ItemTouchHelper.DOWN;
93 | int swipeFlag = 0;
94 | // create make
95 | return makeMovementFlags(dragFlag, swipeFlag);
96 | } else if (layoutManager instanceof LinearLayoutManager) {// linearLayoutManager
97 | LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
98 | int orientation = linearLayoutManager.getOrientation();
99 |
100 | int dragFlag = 0;
101 | int swipeFlag = 0;
102 |
103 | // 为了方便理解,相当于分为横着的ListView和竖着的ListView
104 | if (orientation == LinearLayoutManager.HORIZONTAL) {// 如果是横向的布局
105 | swipeFlag = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
106 | dragFlag = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
107 | } else if (orientation == LinearLayoutManager.VERTICAL) {// 如果是竖向的布局,相当于ListView
108 | dragFlag = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
109 | swipeFlag = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
110 | }
111 | return makeMovementFlags(dragFlag, swipeFlag);
112 | }
113 | return 0;
114 | }
115 |
116 | /**
117 | * 当Item被拖拽的时候被回调
118 | *
119 | * @param recyclerView recyclerView
120 | * @param srcViewHolder 拖拽的ViewHolder
121 | * @param targetViewHolder 目的地的viewHolder
122 | * @return
123 | */
124 | @Override
125 | public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder srcViewHolder, RecyclerView.ViewHolder targetViewHolder) {
126 | if (onItemTouchCallbackListener != null) {
127 | return onItemTouchCallbackListener.onMove(srcViewHolder.getAdapterPosition(), targetViewHolder.getAdapterPosition());
128 | }
129 | return false;
130 | }
131 |
132 | @Override
133 | public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
134 | if (onItemTouchCallbackListener != null) {
135 | onItemTouchCallbackListener.onSwiped(viewHolder.getAdapterPosition());
136 | }
137 | }
138 |
139 | public interface OnItemTouchCallbackListener {
140 | /**
141 | * 当某个Item被滑动删除的时候
142 | *
143 | * @param adapterPosition item的position
144 | */
145 | void onSwiped(int adapterPosition);
146 |
147 | /**
148 | * 当两个Item位置互换的时候被回调
149 | *
150 | * @param srcPosition 拖拽的item的position
151 | * @param targetPosition 目的地的Item的position
152 | * @return 开发者处理了操作应该返回true,开发者没有处理就返回false
153 | */
154 | boolean onMove(int srcPosition, int targetPosition);
155 | }
156 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/adapter/BaseAdapter.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.util.DiffUtil;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by RaphetS on 2016/9/28.
15 | * 普通的万能Adapter
16 | * 支持onItemClick
17 | * 支持onLongItemClick
18 | */
19 | public abstract class BaseAdapter extends RecyclerView.Adapter {
20 | private Context mContext;
21 | private List mDatas;
22 | private int mLayoutId;
23 | private OnItemClickListener mItemClickListener;
24 | private onLongItemClickListener mLongItemClickListener;
25 |
26 | public BaseAdapter(Context mContext, List mDatas, int mLayoutId) {
27 | this.mContext = mContext;
28 | this.mDatas = mDatas;
29 | this.mLayoutId = mLayoutId;
30 | }
31 |
32 | public void updateData(List data) {
33 | mDatas.clear();
34 | mDatas.addAll(data);
35 | notifyDataSetChanged();
36 | }
37 |
38 | public void addAll(List data) {
39 | mDatas.addAll(data);
40 | notifyDataSetChanged();
41 | }
42 |
43 |
44 | @Override
45 | public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
46 | View view = LayoutInflater.from(mContext).inflate(mLayoutId, parent, false);
47 | BaseViewHolder holder = new BaseViewHolder(view);
48 | return holder;
49 | }
50 |
51 | @Override
52 | public int getItemCount() {
53 | return mDatas.size();
54 | }
55 |
56 |
57 | @Override
58 | public void onBindViewHolder(BaseViewHolder holder, final int position) {
59 | convert(mContext, holder, mDatas.get(position));
60 | if (mItemClickListener != null) {
61 | holder.mItemView.setOnClickListener(new View.OnClickListener() {
62 | @Override
63 | public void onClick(View v) {
64 | mItemClickListener.onItemClick(v, position);
65 | }
66 | });
67 | }
68 | if (mLongItemClickListener != null) {
69 | holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
70 | @Override
71 | public boolean onLongClick(View v) {
72 | mLongItemClickListener.onLongItemClick(v, position);
73 | return true;
74 | }
75 | });
76 | }
77 | }
78 |
79 | protected abstract void convert(Context mContext, BaseViewHolder holder, T t);
80 |
81 |
82 | public interface OnItemClickListener {
83 | void onItemClick(View view, int position);
84 | }
85 |
86 | public interface onLongItemClickListener {
87 | void onLongItemClick(View view, int postion);
88 | }
89 |
90 | public void setOnItemClickListener(OnItemClickListener listener) {
91 | this.mItemClickListener = listener;
92 | }
93 |
94 | public void setonLongItemClickListener(onLongItemClickListener listener) {
95 | this.mLongItemClickListener = listener;
96 | }
97 | }
98 |
99 |
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/adapter/BaseLoadMoreAdapter.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 |
7 | import java.util.List;
8 |
9 |
10 | /**
11 | * Created by RaphetS on 2016/10/1.
12 | * 支持上拉加载
13 | * 底部没有进度条
14 | */
15 |
16 | public abstract class BaseLoadMoreAdapter extends BaseAdapter {
17 | private RecyclerView mRecyclerView;
18 | private boolean isLoading=false;
19 | private OnLoadMoreListener mOnLoadMoreListener;
20 | public BaseLoadMoreAdapter(Context mContext, RecyclerView recyclerView,List mDatas, int mLayoutId) {
21 | super(mContext, mDatas, mLayoutId);
22 | this.mRecyclerView=recyclerView;
23 | init();
24 |
25 | }
26 |
27 | private void init() {
28 | //mRecyclerView添加滑动事件监听
29 | mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
30 | @Override
31 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
32 | super.onScrolled(recyclerView, dx, dy);
33 | LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
34 | int totalItemCount = linearLayoutManager.getItemCount();
35 | int lastVisibleItemPosition = linearLayoutManager.findLastVisibleItemPosition();
36 | if (!isLoading &&dy>0&&lastVisibleItemPosition>=totalItemCount-5) {
37 | //此时是刷新状态
38 | if (mOnLoadMoreListener != null) {
39 | mOnLoadMoreListener.onLoadMore();
40 | }
41 | isLoading = true;
42 | }
43 | }
44 | });
45 | }
46 |
47 |
48 | public void setOnLoadMoreListener(OnLoadMoreListener listener){
49 | this.mOnLoadMoreListener=listener;
50 | }
51 |
52 |
53 | public interface OnLoadMoreListener{
54 | void onLoadMore();
55 | }
56 | public void setLoading(boolean b){
57 | isLoading=b;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/adapter/BaseLoadMoreAdapter2.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.Log;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import org.raphets.demorecyclerview.R;
12 |
13 | import java.util.List;
14 |
15 | /**
16 | * Created by RaphetS on 2016/10/1.
17 | * 支持上拉加载
18 | * 底部有进度条
19 | */
20 |
21 | public abstract class BaseLoadMoreAdapter2 extends RecyclerView.Adapter {
22 | private Context mContext;
23 | private boolean isLoading=false;
24 | private OnLoadMoreListener mOnLoadMoreListener;
25 | private OnItemClickListener mItemClickListener;
26 | private onLongItemClickListener mLongItemClickListener;
27 | private List mDatas;
28 | private int mLayoutId;
29 | private final static int TYPE_ITEM=101;
30 | private final static int TYPE_PROGRESS=102;
31 |
32 | public BaseLoadMoreAdapter2(Context mContext, RecyclerView recyclerView,List mDatas, int mLayoutId) {
33 | this.mContext = mContext;
34 | this.mDatas = mDatas;
35 | this.mLayoutId = mLayoutId;
36 | init(recyclerView);
37 | }
38 | private void init(RecyclerView recyclerView) {
39 | //mRecyclerView添加滑动事件监听
40 | recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
41 | @Override
42 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
43 | super.onScrolled(recyclerView, dx, dy);
44 | LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
45 | int totalItemCount = linearLayoutManager.getItemCount();
46 | int lastVisibleItemPosition = linearLayoutManager.findLastVisibleItemPosition();
47 | if (!isLoading &&dy>0&&lastVisibleItemPosition>=totalItemCount-1) {
48 | //此时是刷新状态
49 | if (mOnLoadMoreListener != null) {
50 | mOnLoadMoreListener.onLoadMore();
51 | }
52 | isLoading = true;
53 | }
54 | }
55 | });
56 | }
57 | public void updateData(List data) {
58 | mDatas.clear();
59 | mDatas.addAll(data);
60 | notifyDataSetChanged();
61 | }
62 |
63 | public void addAll(List data) {
64 | mDatas.addAll(data);
65 | notifyDataSetChanged();
66 | }
67 | @Override
68 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
69 | if (viewType==TYPE_ITEM){
70 | View itemView= LayoutInflater.from(mContext).inflate(mLayoutId,parent,false);
71 | BaseViewHolder baseViewHolder=new BaseViewHolder(itemView);
72 | return baseViewHolder;
73 | }else {
74 | View progressView=LayoutInflater.from(mContext).inflate(R.layout.progress_item,parent,false);
75 | ProgressViewHolder progressViewHolder= new ProgressViewHolder(progressView);
76 | return progressViewHolder;
77 | }
78 | }
79 |
80 | @Override
81 | public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
82 | if (holder instanceof BaseViewHolder){
83 | convert(mContext, holder, mDatas.get(position));
84 | ((BaseViewHolder) holder).mItemView.setOnClickListener(new View.OnClickListener() {
85 | @Override
86 | public void onClick(View v) {
87 | mItemClickListener.onItemClick(v,position);
88 | }
89 | });
90 | ((BaseViewHolder) holder).mItemView.setOnLongClickListener(new View.OnLongClickListener() {
91 | @Override
92 | public boolean onLongClick(View v) {
93 | mLongItemClickListener.onLongItemClick(v,position);
94 | return true;
95 | }
96 | });
97 | }
98 | }
99 |
100 | @Override
101 | public int getItemViewType(int position) {
102 | if (position==getItemCount()-1){
103 | return TYPE_PROGRESS;
104 | }else {
105 | return TYPE_ITEM;
106 | }
107 | }
108 |
109 |
110 | public abstract void convert(Context mContext, RecyclerView.ViewHolder holder, T t);
111 |
112 | @Override
113 | public int getItemCount() {
114 | return mDatas.size()+1;
115 | }
116 | public void setLoading(boolean b){
117 | isLoading=b;
118 | }
119 |
120 | public interface OnItemClickListener {
121 | void onItemClick(View view, int position);
122 | }
123 |
124 | public interface onLongItemClickListener {
125 | void onLongItemClick(View view, int postion);
126 | }
127 |
128 | public void setOnItemClickListener(OnItemClickListener listener) {
129 | this.mItemClickListener = listener;
130 | }
131 |
132 | public void setonLongItemClickListener(onLongItemClickListener listener) {
133 | this.mLongItemClickListener = listener;
134 | }
135 | public void setOnLoadMoreListener(OnLoadMoreListener listener){
136 | this.mOnLoadMoreListener=listener;
137 | }
138 |
139 | public interface OnLoadMoreListener{
140 | void onLoadMore();
141 | }
142 | public class ProgressViewHolder extends RecyclerView.ViewHolder{
143 | public ProgressViewHolder(View itemView) {
144 | super(itemView);
145 | }
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/adapter/BaseLoadMoreHeaderAdapter.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import org.raphets.demorecyclerview.R;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Created by RaphetS on 2016/10/1.
16 | * 支持上拉加载
17 | * 底部有进度条
18 | */
19 |
20 | public abstract class BaseLoadMoreHeaderAdapter extends RecyclerView.Adapter {
21 | private Context mContext;
22 | private boolean isLoading=false;
23 | private OnLoadMoreListener mOnLoadMoreListener;
24 | private OnItemClickListener mItemClickListener;
25 | private onLongItemClickListener mLongItemClickListener;
26 | private List mDatas;
27 | private int mLayoutId;
28 | private View mHeadView;
29 | private final static int TYPE_HEADVIEW=100;
30 | private final static int TYPE_ITEM=101;
31 | private final static int TYPE_PROGRESS=102;
32 |
33 | public BaseLoadMoreHeaderAdapter(Context mContext, RecyclerView recyclerView, List mDatas, int mLayoutId) {
34 | this.mContext = mContext;
35 | this.mDatas = mDatas;
36 | this.mLayoutId = mLayoutId;
37 | init(recyclerView);
38 | }
39 | private void init(RecyclerView recyclerView) {
40 | //mRecyclerView添加滑动事件监听
41 | recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
42 | @Override
43 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
44 | super.onScrolled(recyclerView, dx, dy);
45 | LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
46 | int totalItemCount = linearLayoutManager.getItemCount();
47 | int lastVisibleItemPosition = linearLayoutManager.findLastVisibleItemPosition();
48 | if (!isLoading &&dy>0&&lastVisibleItemPosition>=totalItemCount-1) {
49 | //此时是刷新状态
50 | if (mOnLoadMoreListener != null) {
51 | mOnLoadMoreListener.onLoadMore();
52 | }
53 | isLoading = true;
54 | }
55 | }
56 | });
57 | }
58 | public void updateData(List data) {
59 | mDatas.clear();
60 | mDatas.addAll(data);
61 | notifyDataSetChanged();
62 | }
63 |
64 | public void addAll(List data) {
65 | mDatas.addAll(data);
66 | notifyDataSetChanged();
67 | }
68 | public void addHeadView(View headView){
69 | mHeadView=headView;
70 | }
71 | @Override
72 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
73 | if (viewType==TYPE_ITEM){
74 | View itemView= LayoutInflater.from(mContext).inflate(mLayoutId,parent,false);
75 | BaseViewHolder baseViewHolder=new BaseViewHolder(itemView);
76 | return baseViewHolder;
77 | }else if (viewType==TYPE_HEADVIEW){
78 | HeadViewHolder headViewHolder=new HeadViewHolder(mHeadView);
79 | return headViewHolder;
80 | } else{
81 | View progressView=LayoutInflater.from(mContext).inflate(R.layout.progress_item,parent,false);
82 | ProgressViewHolder progressViewHolder= new ProgressViewHolder(progressView);
83 | return progressViewHolder;
84 | }
85 | }
86 |
87 | @Override
88 | public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
89 | if (holder instanceof BaseViewHolder){
90 | convert(mContext, holder, mDatas.get(position));
91 | ((BaseViewHolder) holder).mItemView.setOnClickListener(new View.OnClickListener() {
92 | @Override
93 | public void onClick(View v) {
94 | mItemClickListener.onItemClick(v,position-1);
95 | }
96 | });
97 | ((BaseViewHolder) holder).mItemView.setOnLongClickListener(new View.OnLongClickListener() {
98 | @Override
99 | public boolean onLongClick(View v) {
100 | mLongItemClickListener.onLongItemClick(v,position-1);
101 | return true;
102 | }
103 | });
104 | }
105 | }
106 |
107 | @Override
108 | public int getItemViewType(int position) {
109 | if (mHeadView!=null){
110 | if (position==getItemCount()-1){
111 | return TYPE_PROGRESS;
112 | }else if (position==0){
113 | return TYPE_HEADVIEW;
114 | }else {
115 | return TYPE_ITEM;
116 | }
117 | }else {
118 | if (position==getItemCount()-1){
119 | return TYPE_PROGRESS;
120 | }else {
121 | return TYPE_ITEM;
122 | }
123 | }
124 | }
125 |
126 |
127 | public abstract void convert(Context mContext, RecyclerView.ViewHolder holder, T t);
128 |
129 | @Override
130 | public int getItemCount() {
131 | return mDatas.size()+1;
132 | }
133 | public void setLoading(boolean b){
134 | isLoading=b;
135 | }
136 |
137 | public interface OnItemClickListener {
138 | void onItemClick(View view, int position);
139 | }
140 |
141 | public interface onLongItemClickListener {
142 | void onLongItemClick(View view, int postion);
143 | }
144 |
145 | public void setOnItemClickListener(OnItemClickListener listener) {
146 | this.mItemClickListener = listener;
147 | }
148 |
149 | public void setonLongItemClickListener(onLongItemClickListener listener) {
150 | this.mLongItemClickListener = listener;
151 | }
152 | public void setOnLoadMoreListener(OnLoadMoreListener listener){
153 | this.mOnLoadMoreListener=listener;
154 | }
155 |
156 | public interface OnLoadMoreListener{
157 | void onLoadMore();
158 | }
159 | public class ProgressViewHolder extends RecyclerView.ViewHolder{
160 | public ProgressViewHolder(View itemView) {
161 | super(itemView);
162 | }
163 | }
164 |
165 | public class HeadViewHolder extends RecyclerView.ViewHolder{
166 | public HeadViewHolder(View itemView) {
167 | super(itemView);
168 | }
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/adapter/BaseViewHolder.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview.adapter;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.graphics.Bitmap;
5 | import android.graphics.drawable.Drawable;
6 | import android.os.Build;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.text.SpannableStringBuilder;
9 | import android.util.SparseArray;
10 | import android.view.View;
11 | import android.view.animation.AlphaAnimation;
12 | import android.widget.Checkable;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | public class BaseViewHolder extends RecyclerView.ViewHolder {
17 | SparseArray mViews;
18 | View mItemView;
19 |
20 | public BaseViewHolder(View itemView) {
21 | super(itemView);
22 | mItemView = itemView;
23 | mViews = new SparseArray<>();
24 | }
25 |
26 |
27 | public T getView(int viewId) {
28 | View view = mViews.get(viewId);
29 | if (view == null) {
30 | view = mItemView.findViewById(viewId);
31 | mViews.put(viewId, view);
32 | }
33 | return (T) view;
34 | }
35 |
36 | public BaseViewHolder setText(int viewId, int resId) {
37 | TextView textView = getView(viewId);
38 | textView.setText(resId);
39 | return this;
40 | }
41 |
42 |
43 | public BaseViewHolder setText(int viewId, String text) {
44 | TextView textView = getView(viewId);
45 | textView.setText(text);
46 | return this;
47 | }
48 |
49 | public BaseViewHolder setText(int viewId, SpannableStringBuilder text) {
50 | TextView textView = getView(viewId);
51 | textView.setText(text);
52 | return this;
53 | }
54 |
55 | public BaseViewHolder setImageResource(int viewId, int resId) {
56 | ImageView view = getView(viewId);
57 | view.setImageResource(resId);
58 | return this;
59 | }
60 |
61 | public BaseViewHolder setImageBitmap(int viewId, Bitmap bitmap) {
62 | ImageView view = getView(viewId);
63 | view.setImageBitmap(bitmap);
64 | return this;
65 | }
66 |
67 | public BaseViewHolder setImageDrawable(int viewId, Drawable drawable) {
68 | ImageView view = getView(viewId);
69 | view.setImageDrawable(drawable);
70 | return this;
71 | }
72 |
73 | public BaseViewHolder setBackgroundColor(int viewId, int color) {
74 | View view = getView(viewId);
75 | view.setBackgroundColor(color);
76 | return this;
77 | }
78 |
79 | public BaseViewHolder setBackgroundResource(int viewId, int backgroundRes) {
80 | View view = getView(viewId);
81 | view.setBackgroundResource(backgroundRes);
82 | return this;
83 | }
84 |
85 | public BaseViewHolder setTextColor(int viewId, int textColor) {
86 | TextView view = getView(viewId);
87 | view.setTextColor(textColor);
88 | return this;
89 | }
90 |
91 |
92 | @SuppressLint("NewApi")
93 | public BaseViewHolder setAlpha(int viewId, float value) {
94 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
95 | getView(viewId).setAlpha(value);
96 | } else {
97 | // Pre-honeycomb hack to set Alpha value
98 | AlphaAnimation alpha = new AlphaAnimation(value, value);
99 | alpha.setDuration(0);
100 | alpha.setFillAfter(true);
101 | getView(viewId).startAnimation(alpha);
102 | }
103 | return this;
104 | }
105 |
106 | public BaseViewHolder setVisible(int viewId, boolean visible) {
107 | View view = getView(viewId);
108 | view.setVisibility(visible ? View.VISIBLE : View.GONE);
109 | return this;
110 | }
111 |
112 |
113 | public BaseViewHolder setTag(int viewId, Object tag) {
114 | View view = getView(viewId);
115 | view.setTag(tag);
116 | return this;
117 | }
118 |
119 | public BaseViewHolder setTag(int viewId, int key, Object tag) {
120 | View view = getView(viewId);
121 | view.setTag(key, tag);
122 | return this;
123 | }
124 |
125 | public BaseViewHolder setChecked(int viewId, boolean checked) {
126 | Checkable view = (Checkable) getView(viewId);
127 | view.setChecked(checked);
128 | return this;
129 | }
130 |
131 | /**
132 | * 关于事件监听
133 | */
134 | public BaseViewHolder setOnClickListener(int viewId, View.OnClickListener listener) {
135 |
136 | View view = getView(viewId);
137 | view.setOnClickListener(listener);
138 | return this;
139 | }
140 |
141 | public BaseViewHolder setOnTouchListener(int viewId, View.OnTouchListener listener) {
142 | View view = getView(viewId);
143 | view.setOnTouchListener(listener);
144 | return this;
145 | }
146 |
147 | public BaseViewHolder setOnLongClickListener(int viewId, View.OnLongClickListener listener) {
148 | View view = getView(viewId);
149 | view.setOnLongClickListener(listener);
150 | return this;
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/ui/DragSwipeActivity.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview.ui;
2 |
3 | import android.content.Context;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.helper.ItemTouchHelper;
9 | import android.view.View;
10 | import android.widget.Toast;
11 |
12 | import org.raphets.demorecyclerview.DefaultItemTouchHelpCallback;
13 | import org.raphets.demorecyclerview.R;
14 | import org.raphets.demorecyclerview.utils.SnackbarUtil;
15 | import org.raphets.demorecyclerview.adapter.BaseAdapter;
16 | import org.raphets.demorecyclerview.adapter.BaseViewHolder;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Collections;
20 | import java.util.List;
21 |
22 | public class DragSwipeActivity extends AppCompatActivity {
23 | private RecyclerView mRecyclerView;
24 | private List mData = new ArrayList<>();
25 | private DragSwipeAdapter mAdapter;
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_drag_swipe);
31 |
32 | mRecyclerView = (RecyclerView) findViewById(R.id.rv);
33 |
34 | init();
35 | addListener();
36 |
37 | }
38 |
39 |
40 | private void init() {
41 | for (int i = 0; i < 20; i++) {
42 | mData.add("item" + i);
43 | }
44 |
45 | mAdapter = new DragSwipeAdapter(this, mData, R.layout.item);
46 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
47 | mRecyclerView.setAdapter(mAdapter);
48 |
49 | setItemTouchHelper();
50 |
51 | SnackbarUtil.show(getWindow().getDecorView(),"支持长按拖拽、左右滑动删除的哦(⊙o⊙)哦");
52 |
53 | }
54 |
55 |
56 | private void setItemTouchHelper() {
57 | DefaultItemTouchHelpCallback mCallback= new DefaultItemTouchHelpCallback(new DefaultItemTouchHelpCallback.OnItemTouchCallbackListener() {
58 | @Override
59 | public void onSwiped(int adapterPosition) {
60 | // 滑动删除的时候,从数据库、数据源移除,并刷新UI
61 | if (mData != null) {
62 | mData.remove(adapterPosition);
63 | mAdapter.notifyItemRemoved(adapterPosition);
64 | }
65 | }
66 |
67 | @Override
68 | public boolean onMove(int srcPosition, int targetPosition) {
69 | if (mData != null) {
70 |
71 | // 更换数据源中的数据Item的位置
72 | Collections.swap(mData, srcPosition, targetPosition);
73 | // 更新UI中的Item的位置,主要是给用户看到交互效果
74 | mAdapter.notifyItemMoved(srcPosition, targetPosition);
75 | return true;
76 | }
77 | return false;
78 | }
79 | });
80 | mCallback.setDragEnable(true);
81 | mCallback.setSwipeEnable(true);
82 | ItemTouchHelper itemTouchHelper = new ItemTouchHelper(mCallback);
83 | itemTouchHelper.attachToRecyclerView(mRecyclerView);
84 | }
85 |
86 |
87 | private void addListener() {
88 | mAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
89 | @Override
90 | public void onItemClick(View view, int position) {
91 | Toast.makeText(DragSwipeActivity.this, "click" + position, Toast.LENGTH_SHORT).show();
92 | }
93 | });
94 | mAdapter.setonLongItemClickListener(new BaseAdapter.onLongItemClickListener() {
95 | @Override
96 | public void onLongItemClick(View view, int postion) {
97 | Toast.makeText(DragSwipeActivity.this, "long" + postion, Toast.LENGTH_SHORT).show();
98 |
99 | }
100 | });
101 | }
102 |
103 |
104 | class DragSwipeAdapter extends BaseAdapter {
105 | public DragSwipeAdapter(Context mContext, List mDatas, int mLayoutId) {
106 | super(mContext, mDatas, mLayoutId);
107 | }
108 |
109 | @Override
110 | protected void convert(Context mContext, BaseViewHolder holder, String s) {
111 | holder.setText(R.id.tv,s);
112 | }
113 | }
114 | }
115 |
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/ui/MainActivity.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview.ui;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import org.raphets.demorecyclerview.R;
10 |
11 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
12 | private Button btnDragSwipe;
13 | private Button btnPullRefresh;
14 | private Button btnPullRefreshNoTip;
15 | private Button btnSupportHeader;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | btnDragSwipe= (Button) findViewById(R.id.btn_first);
22 | btnPullRefresh= (Button) findViewById(R.id.btn_second);
23 | btnPullRefreshNoTip= (Button) findViewById(R.id.btn_third);
24 | btnSupportHeader= (Button) findViewById(R.id.btn_fourth);
25 | btnDragSwipe.setOnClickListener(this);
26 | btnPullRefresh.setOnClickListener(this);
27 | btnPullRefreshNoTip.setOnClickListener(this);
28 | btnSupportHeader.setOnClickListener(this);
29 | }
30 |
31 | @Override
32 | public void onClick(View v) {
33 | switch (v.getId()){
34 | case R.id.btn_first:
35 | startActivity(new Intent(MainActivity.this,DragSwipeActivity.class));
36 | break;
37 | case R.id.btn_second:
38 | startActivity(new Intent(MainActivity.this,PullRefreshActivity.class));
39 | break;
40 | case R.id.btn_third:
41 | startActivity(new Intent(MainActivity.this,PullRefreshNoTipActivity.class));
42 | break;
43 | case R.id.btn_fourth:
44 | startActivity(new Intent(MainActivity.this,SupportHeadViewActivity.class));
45 | break;
46 | default:
47 | break;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/ui/PullRefreshActivity.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview.ui;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.v4.widget.SwipeRefreshLayout;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.View;
11 | import android.widget.Toast;
12 |
13 | import org.raphets.demorecyclerview.R;
14 | import org.raphets.demorecyclerview.adapter.BaseLoadMoreAdapter2;
15 | import org.raphets.demorecyclerview.adapter.BaseViewHolder;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 | import java.util.Random;
20 |
21 | public class PullRefreshActivity extends AppCompatActivity {
22 |
23 | private SwipeRefreshLayout mRefreshLayout;
24 | private RecyclerView mRecyclerView;
25 | private MyAdapter mAdapter;
26 | private List mDatas=new ArrayList<>();
27 | private int page=0;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_pull_refresh);
33 | mRefreshLayout= (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
34 | mRecyclerView= (RecyclerView) findViewById(R.id.recyclerView);
35 |
36 | init();
37 | addListener();
38 |
39 | }
40 |
41 | private void init() {
42 | for (int i=0;i<10;i++){
43 | mDatas.add("item>>>"+i);
44 | }
45 |
46 | LinearLayoutManager layoutManager=new LinearLayoutManager(this);
47 | mAdapter=new MyAdapter(this,mRecyclerView,mDatas,R.layout.item);
48 | mRecyclerView.setLayoutManager(layoutManager);
49 | mRecyclerView.setAdapter(mAdapter);
50 |
51 | }
52 |
53 | private void addListener() {
54 | mRefreshLayout.setColorSchemeColors(Color.RED,Color.BLUE,Color.BLACK);
55 | mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
56 | @Override
57 | public void onRefresh() {
58 | refreshData();
59 | }
60 | });
61 |
62 | mAdapter.setOnLoadMoreListener(new BaseLoadMoreAdapter2.OnLoadMoreListener() {
63 | @Override
64 | public void onLoadMore() {
65 | loadMore();
66 | }
67 | });
68 |
69 | mAdapter.setOnItemClickListener(new BaseLoadMoreAdapter2.OnItemClickListener() {
70 | @Override
71 | public void onItemClick(View view, int position) {
72 | Toast.makeText(getApplicationContext(),position+"",Toast.LENGTH_SHORT).show();
73 | }
74 | });
75 | }
76 |
77 | private void refreshData() {
78 | new Thread(){
79 | @Override
80 | public void run() {
81 | super.run();
82 | try {
83 | Thread.sleep(2000);
84 | } catch (InterruptedException e) {
85 | e.printStackTrace();
86 | }
87 | final List data=new ArrayList();
88 | for (int i=0;i<10;i++){
89 | data.add("refresh--"+new Random().nextInt(10));
90 | }
91 |
92 | runOnUiThread(new Runnable() {
93 | @Override
94 | public void run() {
95 | mAdapter.updateData(data);
96 | mRefreshLayout.setRefreshing(false);
97 | }
98 | });
99 | }
100 | }.start();
101 | }
102 |
103 | private void loadMore() {
104 | page++;
105 | new Thread(){
106 | @Override
107 | public void run() {
108 | super.run();
109 | try {
110 | Thread.sleep(2000);
111 | } catch (InterruptedException e) {
112 | e.printStackTrace();
113 | }
114 |
115 | final List data = new ArrayList();
116 | for (int i = 0; i < 6; i++) {
117 | data.add("page" + page+"item"+i);
118 | }
119 | //addData()是在自定义的Adapter中自己添加的方法,用来给list添加数据
120 | runOnUiThread(new Runnable() {
121 | @Override
122 | public void run() {
123 | mAdapter.addAll(data);
124 | mAdapter.setLoading(false);
125 | }
126 | });
127 | }
128 | }.start();
129 |
130 | }
131 |
132 | class MyAdapter extends BaseLoadMoreAdapter2{
133 | public MyAdapter(Context mContext, RecyclerView recyclerView, List mDatas, int mLayoutId) {
134 | super(mContext, recyclerView, mDatas, mLayoutId);
135 | }
136 |
137 | @Override
138 | public void convert(Context mContext, RecyclerView.ViewHolder holder, String s) {
139 | if (holder instanceof BaseViewHolder){
140 | ((BaseViewHolder) holder).setText(R.id.tv,s);
141 | }
142 | }
143 | }
144 | }
145 |
146 |
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/ui/PullRefreshNoTipActivity.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview.ui;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.v4.widget.SwipeRefreshLayout;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.View;
11 | import android.widget.Toast;
12 |
13 | import org.raphets.demorecyclerview.R;
14 | import org.raphets.demorecyclerview.adapter.BaseAdapter;
15 | import org.raphets.demorecyclerview.adapter.BaseLoadMoreAdapter;
16 | import org.raphets.demorecyclerview.adapter.BaseLoadMoreAdapter2;
17 | import org.raphets.demorecyclerview.adapter.BaseViewHolder;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 | import java.util.Random;
22 |
23 | public class PullRefreshNoTipActivity extends AppCompatActivity {
24 | private SwipeRefreshLayout mRefreshLayout;
25 | private RecyclerView mRecyclerView;
26 | private MyAdapter mAdapter;
27 |
28 | private List mDatas=new ArrayList<>();
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_pull_refresh_no_tip);
34 | mRefreshLayout= (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
35 | mRecyclerView= (RecyclerView) findViewById(R.id.recyclerView);
36 |
37 | init();
38 | addListener();
39 | }
40 | private void init() {
41 | for (int i=0;i<10;i++){
42 | mDatas.add("item>>>"+i);
43 | }
44 |
45 | LinearLayoutManager layoutManager=new LinearLayoutManager(this);
46 | mAdapter=new MyAdapter(this,mRecyclerView,mDatas,R.layout.item);
47 | mRecyclerView.setLayoutManager(layoutManager);
48 | mRecyclerView.setAdapter(mAdapter);
49 |
50 | }
51 |
52 | private void addListener() {
53 | mRefreshLayout.setColorSchemeColors(Color.RED,Color.BLUE,Color.BLACK);
54 | mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
55 | @Override
56 | public void onRefresh() {
57 | refreshData();
58 | }
59 | });
60 |
61 | mAdapter.setOnLoadMoreListener(new BaseLoadMoreAdapter.OnLoadMoreListener() {
62 | @Override
63 | public void onLoadMore() {
64 | loadMore();
65 | }
66 | });
67 |
68 | mAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
69 | @Override
70 | public void onItemClick(View view, int position) {
71 | Toast.makeText(getApplicationContext(),position+"",Toast.LENGTH_SHORT).show();
72 |
73 | }
74 | });
75 | }
76 |
77 | private void refreshData() {
78 | new Thread(){
79 | @Override
80 | public void run() {
81 | super.run();
82 | try {
83 | Thread.sleep(2000);
84 | } catch (InterruptedException e) {
85 | e.printStackTrace();
86 | }
87 | final List data=new ArrayList();
88 | for (int i=0;i<10;i++){
89 | data.add("refresh--"+new Random().nextInt(10));
90 | }
91 |
92 | runOnUiThread(new Runnable() {
93 | @Override
94 | public void run() {
95 | mAdapter.updateData(data);
96 | mRefreshLayout.setRefreshing(false);
97 | }
98 | });
99 | }
100 | }.start();
101 | }
102 |
103 | private void loadMore() {
104 | new Thread(){
105 | @Override
106 | public void run() {
107 | super.run();
108 | try {
109 | Thread.sleep(500);
110 | } catch (InterruptedException e) {
111 | e.printStackTrace();
112 | }
113 |
114 | final List data = new ArrayList();
115 | for (int i = 0; i < 5; i++) {
116 | data.add("load" + new Random().nextInt(100));
117 | }
118 | //addData()是在自定义的Adapter中自己添加的方法,用来给list添加数据
119 | runOnUiThread(new Runnable() {
120 | @Override
121 | public void run() {
122 | mAdapter.addAll(data);
123 | mAdapter.setLoading(false);
124 | }
125 | });
126 | }
127 | }.start();
128 |
129 | }
130 |
131 |
132 |
133 |
134 | class MyAdapter extends BaseLoadMoreAdapter {
135 | public MyAdapter(Context mContext, RecyclerView recyclerView, List mDatas, int mLayoutId) {
136 | super(mContext, recyclerView, mDatas, mLayoutId);
137 | }
138 |
139 | @Override
140 | protected void convert(Context mContext, BaseViewHolder holder, String s) {
141 | holder.setText(R.id.tv,s);
142 | }
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/ui/SupportHeadViewActivity.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview.ui;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.v4.widget.SwipeRefreshLayout;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.widget.Toast;
13 |
14 | import org.raphets.demorecyclerview.R;
15 | import org.raphets.demorecyclerview.adapter.BaseLoadMoreAdapter2;
16 | import org.raphets.demorecyclerview.adapter.BaseLoadMoreHeaderAdapter;
17 | import org.raphets.demorecyclerview.adapter.BaseViewHolder;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 | import java.util.Random;
22 |
23 | public class SupportHeadViewActivity extends AppCompatActivity {
24 |
25 | private SwipeRefreshLayout mRefreshLayout;
26 | private RecyclerView mRecyclerView;
27 | private MyAdapter mAdapter;
28 | private List mDatas=new ArrayList<>();
29 | private int page=0;
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_pull_refresh);
35 | mRefreshLayout= (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
36 | mRecyclerView= (RecyclerView) findViewById(R.id.recyclerView);
37 |
38 | init();
39 | addListener();
40 |
41 | }
42 |
43 | private void init() {
44 | for (int i=0;i<10;i++){
45 | mDatas.add("item>>>"+i);
46 | }
47 |
48 | LinearLayoutManager layoutManager=new LinearLayoutManager(this);
49 | mAdapter=new MyAdapter(this,mRecyclerView,mDatas,R.layout.item);
50 | mRecyclerView.setLayoutManager(layoutManager);
51 | View headView= LayoutInflater.from(this).inflate(R.layout.headview,mRecyclerView,false);
52 | mAdapter.addHeadView(headView);
53 | mRecyclerView.setAdapter(mAdapter);
54 |
55 | }
56 |
57 | private void addListener() {
58 | mRefreshLayout.setColorSchemeColors(Color.RED,Color.BLUE,Color.BLACK);
59 | mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
60 | @Override
61 | public void onRefresh() {
62 | refreshData();
63 | }
64 | });
65 |
66 | mAdapter.setOnLoadMoreListener(new BaseLoadMoreHeaderAdapter.OnLoadMoreListener() {
67 | @Override
68 | public void onLoadMore() {
69 | loadMore();
70 | }
71 | });
72 |
73 | mAdapter.setOnItemClickListener(new BaseLoadMoreHeaderAdapter.OnItemClickListener() {
74 | @Override
75 | public void onItemClick(View view, int position) {
76 | Toast.makeText(getApplicationContext(),position+"",Toast.LENGTH_SHORT).show();
77 |
78 | }
79 | });
80 | }
81 |
82 | private void refreshData() {
83 | new Thread(){
84 | @Override
85 | public void run() {
86 | super.run();
87 | try {
88 | Thread.sleep(2000);
89 | } catch (InterruptedException e) {
90 | e.printStackTrace();
91 | }
92 | final List data=new ArrayList();
93 | for (int i=0;i<10;i++){
94 | data.add("refresh--"+new Random().nextInt(10));
95 | }
96 |
97 | runOnUiThread(new Runnable() {
98 | @Override
99 | public void run() {
100 | mAdapter.updateData(data);
101 | mRefreshLayout.setRefreshing(false);
102 | }
103 | });
104 | }
105 | }.start();
106 | }
107 |
108 | private void loadMore() {
109 | page++;
110 | new Thread(){
111 | @Override
112 | public void run() {
113 | super.run();
114 | try {
115 | Thread.sleep(2000);
116 | } catch (InterruptedException e) {
117 | e.printStackTrace();
118 | }
119 |
120 | final List data = new ArrayList();
121 | for (int i = 0; i < 6; i++) {
122 | data.add("page" + page+"item"+i);
123 | }
124 | //addData()是在自定义的Adapter中自己添加的方法,用来给list添加数据
125 | runOnUiThread(new Runnable() {
126 | @Override
127 | public void run() {
128 | mAdapter.addAll(data);
129 | mAdapter.setLoading(false);
130 | }
131 | });
132 | }
133 | }.start();
134 |
135 | }
136 |
137 | class MyAdapter extends BaseLoadMoreHeaderAdapter {
138 | public MyAdapter(Context mContext, RecyclerView recyclerView, List mDatas, int mLayoutId) {
139 | super(mContext, recyclerView, mDatas, mLayoutId);
140 | }
141 |
142 | @Override
143 | public void convert(Context mContext, RecyclerView.ViewHolder holder, String s) {
144 | if (holder instanceof BaseViewHolder){
145 | ((BaseViewHolder) holder).setText(R.id.tv,s);
146 | }
147 | }
148 | }
149 | }
150 |
151 |
--------------------------------------------------------------------------------
/app/src/main/java/org/raphets/demorecyclerview/utils/SnackbarUtil.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview.utils;
2 |
3 | import android.support.design.widget.Snackbar;
4 | import android.view.View;
5 |
6 | /**
7 | * Created by codeest on 16/9/3.
8 | */
9 |
10 | public class SnackbarUtil {
11 |
12 | public static void show(View view, String msg) {
13 | Snackbar.make(view, msg, Snackbar.LENGTH_LONG).show();
14 | }
15 |
16 | public static void showShort(View view, String msg) {
17 | Snackbar.make(view, msg, Snackbar.LENGTH_SHORT).show();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/layoutanimation.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/load_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/jr14.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaphetS/RecyclerView/e6b9a863d5365392fd7a4468a129667a998306c1/app/src/main/res/drawable/jr14.jpg
--------------------------------------------------------------------------------
/app/src/main/res/layout-v21/progress_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_drag_swipe.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
24 |
32 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_pull_refresh.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_pull_refresh_no_tip.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/headview.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/progress_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaphetS/RecyclerView/e6b9a863d5365392fd7a4468a129667a998306c1/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaphetS/RecyclerView/e6b9a863d5365392fd7a4468a129667a998306c1/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaphetS/RecyclerView/e6b9a863d5365392fd7a4468a129667a998306c1/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaphetS/RecyclerView/e6b9a863d5365392fd7a4468a129667a998306c1/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaphetS/RecyclerView/e6b9a863d5365392fd7a4468a129667a998306c1/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DemoRecyclerView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/org/raphets/demorecyclerview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package org.raphets.demorecyclerview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaphetS/RecyclerView/e6b9a863d5365392fd7a4468a129667a998306c1/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Sep 28 19:58:47 CST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------