├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wind
│ │ └── windlinkrecycleview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── wind
│ │ │ └── windlinkrecycleview
│ │ │ ├── CheckListener.java
│ │ │ ├── CityContract.java
│ │ │ ├── ItemHeaderDecoration.java
│ │ │ ├── MainActivity.java
│ │ │ ├── MyDividerItemDecoration.java
│ │ │ ├── Utils.java
│ │ │ ├── adapter
│ │ │ ├── CityRvAdapter.java
│ │ │ ├── ProvinceRvAdapter.java
│ │ │ └── RvAdapter.java
│ │ │ ├── listener
│ │ │ └── ItemClickListener.java
│ │ │ ├── model
│ │ │ └── CityBean.java
│ │ │ ├── presenter
│ │ │ └── CityPresenter.java
│ │ │ └── view
│ │ │ └── CityFragment.java
│ └── res
│ │ ├── drawable
│ │ ├── dividerline.xml
│ │ └── show.gif
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── fragment_city.xml
│ │ ├── item_city.xml
│ │ ├── item_province.xml
│ │ └── item_title.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── arrow_right.png
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── arrays.xml
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── wind
│ └── windlinkrecycleview
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── 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 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.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/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.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 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WindLinkRecycleView
2 | MVP框架下的RecycleView的双列表的城市选择联动与悬停,适合一切二级联动。
3 | ----
4 | 实现功能:
5 | ----
6 | 1.点击左边省份,省份背景改变,顶部显示省份悬停,下面显示省份的城市;
7 | 2.滑动右边的城市,顶部省份悬停,左边随着省份的改变而改变;
8 | 3.所有控件可点击;
9 | 4.仿官方mvpdemo的mvp框架;
10 | 5.snackbar的使用。
11 |
12 |
13 |
14 |
15 | 
16 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 | defaultConfig {
7 | applicationId "com.wind.windlinkrecycleview"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
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(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile 'com.android.support:design:25.3.1'
29 | compile 'com.android.support:recyclerview-v7:25.3.1'
30 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
31 | testCompile 'junit:junit:4.12'
32 | }
33 |
--------------------------------------------------------------------------------
/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 E:\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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/wind/windlinkrecycleview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.wind.windlinkrecycleview", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wind/windlinkrecycleview/CheckListener.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview;
2 |
3 | /**
4 | * Created by zhangcong on 2017/7/26.
5 | */
6 |
7 | public interface CheckListener {
8 | void check(int position,boolean isScroll);
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wind/windlinkrecycleview/CityContract.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview;
2 |
3 | /**
4 | * Created by zhangcong on 2017/7/24.
5 | */
6 |
7 | public interface CityContract {
8 | interface View
9 | {
10 | void setPresenter(Presenter presenter);
11 | void showSnackBar();
12 | void showCity();
13 | }
14 | interface Presenter {
15 | void start();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wind/windlinkrecycleview/ItemHeaderDecoration.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview;
2 |
3 | /**
4 | * Created by zhangcong on 2017/7/26.
5 | */
6 |
7 | import android.content.Context;
8 | import android.graphics.Canvas;
9 | import android.graphics.Paint;
10 | import android.graphics.Rect;
11 | import android.os.Build;
12 | import android.support.annotation.RequiresApi;
13 | import android.support.v7.widget.LinearLayoutManager;
14 | import android.support.v7.widget.RecyclerView;
15 | import android.text.TextUtils;
16 | import android.util.Log;
17 | import android.util.TypedValue;
18 | import android.view.LayoutInflater;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 | import android.widget.TextView;
22 |
23 |
24 |
25 | import com.wind.windlinkrecycleview.model.CityBean;
26 |
27 | import java.util.List;
28 |
29 | public class ItemHeaderDecoration extends RecyclerView.ItemDecoration {
30 | private List mDatas;
31 | private LayoutInflater mInflater;
32 | private int mTitleHeight;
33 | private CheckListener mCheckListener;
34 | private Context context;
35 |
36 | public static String currentTag = "0";
37 |
38 | public void setCheckListener(CheckListener checkListener) {
39 | mCheckListener = checkListener;
40 | }
41 |
42 | public ItemHeaderDecoration(Context context, List datas) {
43 | super();
44 | this.context=context;
45 | this.mDatas = datas;
46 | Paint paint = new Paint();
47 | mTitleHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, context.getResources().getDisplayMetrics());
48 | int titleFontSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, context.getResources().getDisplayMetrics());
49 | paint.setTextSize(titleFontSize);
50 | paint.setAntiAlias(true);
51 | mInflater = LayoutInflater.from(context);
52 | }
53 |
54 |
55 | public ItemHeaderDecoration setData(List mDatas) {
56 | this.mDatas = mDatas;
57 | return this;
58 | }
59 |
60 | public static void setCurrentTag(String currentTag) {
61 | ItemHeaderDecoration.currentTag = currentTag;
62 | }
63 |
64 | @Override
65 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
66 | super.getItemOffsets(outRect, view, parent, state);
67 | }
68 |
69 | @Override
70 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
71 | super.onDraw(c, parent, state);
72 | }
73 |
74 | @RequiresApi(api = Build.VERSION_CODES.KITKAT)
75 | @Override
76 | public void onDrawOver(Canvas c, final RecyclerView parent, RecyclerView.State state) {
77 | int pos = ((LinearLayoutManager) (parent.getLayoutManager())).findFirstVisibleItemPosition();
78 | String tag = mDatas.get(pos).getTag();
79 | Log.i("zhangcong",tag);
80 | View child = parent.findViewHolderForLayoutPosition(pos).itemView;
81 | boolean flag = false;
82 | if ((pos + 1) < mDatas.size()) {
83 | String suspensionTag = mDatas.get(pos + 1).getTag();
84 | if (null != tag && !tag.equals(suspensionTag)) {
85 | if (child.getHeight() + child.getTop() < mTitleHeight) {
86 | c.save();
87 | flag = true;
88 | c.translate(0, child.getHeight() + child.getTop() - mTitleHeight);
89 | }
90 | }
91 | }
92 |
93 | View topTitleView = mInflater.inflate(R.layout.item_title, parent, false);
94 | TextView tvTitle = (TextView) topTitleView.findViewById(R.id.tv_title);
95 | String [] province =context.getResources().getStringArray(R.array.province);
96 | tvTitle.setText(province[Integer.parseInt(tag)]);
97 | int toDrawWidthSpec;//用于测量的widthMeasureSpec
98 | int toDrawHeightSpec;//用于测量的heightMeasureSpec
99 | RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) topTitleView.getLayoutParams();
100 | if (lp == null) {
101 | lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);//这里是根据复杂布局layout的width height,new一个Lp
102 | topTitleView.setLayoutParams(lp);
103 | }
104 | topTitleView.setLayoutParams(lp);
105 | if (lp.width == ViewGroup.LayoutParams.MATCH_PARENT) {
106 | //如果是MATCH_PARENT,则用父控件能分配的最大宽度和EXACTLY构建MeasureSpec。
107 | toDrawWidthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight(), View.MeasureSpec.EXACTLY);
108 | } else if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) {
109 | //如果是WRAP_CONTENT,则用父控件能分配的最大宽度和AT_MOST构建MeasureSpec。
110 | toDrawWidthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight(), View.MeasureSpec.AT_MOST);
111 | } else {
112 | //否则则是具体的宽度数值,则用这个宽度和EXACTLY构建MeasureSpec。
113 | toDrawWidthSpec = View.MeasureSpec.makeMeasureSpec(lp.width, View.MeasureSpec.EXACTLY);
114 | }
115 | //高度同理
116 | if (lp.height == ViewGroup.LayoutParams.MATCH_PARENT) {
117 | toDrawHeightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight() - parent.getPaddingTop() - parent.getPaddingBottom(), View.MeasureSpec.EXACTLY);
118 | } else if (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
119 | toDrawHeightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight() - parent.getPaddingTop() - parent.getPaddingBottom(), View.MeasureSpec.AT_MOST);
120 | } else {
121 | toDrawHeightSpec = View.MeasureSpec.makeMeasureSpec(mTitleHeight, View.MeasureSpec.EXACTLY);
122 | }
123 | //依次调用 measure,layout,draw方法,将复杂头部显示在屏幕上。
124 | topTitleView.measure(toDrawWidthSpec, toDrawHeightSpec);
125 | topTitleView.layout(parent.getPaddingLeft(), parent.getPaddingTop(), parent.getPaddingLeft() + topTitleView.getMeasuredWidth(), parent.getPaddingTop() + topTitleView.getMeasuredHeight());
126 | topTitleView.draw(c);//Canvas默认在视图顶部,无需平移,直接绘制
127 | if (flag)
128 | c.restore();//恢复画布到之前保存的状态
129 | /*
130 | 如果左边的item的position与右边的tag不同,则将tag赋值给item的position,然后调用check方法实现左边联动
131 | */
132 | if (!TextUtils.equals(tag, currentTag)) {
133 | currentTag = tag;
134 | Log.i("zhangcong",currentTag);
135 | Integer integer = Integer.valueOf(currentTag);
136 | mCheckListener.check(integer, false);
137 | }
138 |
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wind/windlinkrecycleview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview;
2 |
3 | import android.support.design.widget.Snackbar;
4 | import android.support.v4.app.FragmentTransaction;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.os.Bundle;
7 | import android.support.v7.widget.DefaultItemAnimator;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.util.Log;
11 | import android.view.View;
12 |
13 | import com.wind.windlinkrecycleview.adapter.ProvinceRvAdapter;
14 | import com.wind.windlinkrecycleview.listener.ItemClickListener;
15 | import com.wind.windlinkrecycleview.presenter.CityPresenter;
16 | import com.wind.windlinkrecycleview.view.CityFragment;
17 |
18 | import java.util.Arrays;
19 | import java.util.List;
20 |
21 | public class MainActivity extends AppCompatActivity implements CheckListener{
22 | private RecyclerView recycleview;
23 | public ProvinceRvAdapter adapter;
24 | private CityFragment cityFragment;
25 | private LinearLayoutManager manager;
26 | private int mposition;
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_main);
31 | initView();
32 | initData();
33 | new CityPresenter(cityFragment);
34 | }
35 |
36 | @Override
37 | protected void onResume() {
38 | super.onResume();
39 |
40 |
41 | }
42 |
43 | private void initData() {
44 | String [] province=getResources().getStringArray(R.array.province);//获取省份
45 | final List list= Arrays.asList(province);
46 | /*
47 | 适配数据和设置监听事件
48 | */
49 | adapter=new ProvinceRvAdapter(this, list, new ItemClickListener() {
50 | @Override
51 | public void onItemClick(View view, int position) {
52 | Utils.showSnackBar(recycleview,list.get(position));
53 | mposition=position;
54 | startMove(position,true);
55 | Log.i(">>>>>>","position:"+position);
56 | moveToCenter(position);
57 | }
58 | });
59 | recycleview.setAdapter(adapter);
60 | addRightData();
61 |
62 | }
63 | //将当前选中的item居中
64 | public void moveToCenter(int position) {
65 | //将点击的position转换为当前屏幕上可见的item的位置以便于计算距离顶部的高度,从而进行移动居中
66 | Log.i(">>>>>>>>>",position - manager.findFirstVisibleItemPosition()+"eeeee");
67 | int itemPosition=position-manager.findFirstVisibleItemPosition();
68 | /*
69 | 当往上滑动太快,会出现itemPosition为-1的情况。做下判断
70 | */
71 | if (0{
18 | public CityRvAdapter(Context context, List list, ItemClickListener listener) {
19 | super(context, list, listener);
20 | }
21 |
22 | @Override
23 | protected RvHolder getHolder(View view, int viewType) {
24 | return new CityHolder(view,viewType,listener);
25 | }
26 |
27 | @Override
28 | public int getItemViewType(int position) {
29 | return list.get(position).isTitle() ? 0 : 1;
30 | }
31 |
32 | @Override
33 | protected int getLayoutId(int viewType) {
34 | return viewType==0 ? R.layout.item_title:R.layout.item_city;
35 | }
36 | private class CityHolder extends RvHolder
37 | {
38 | private TextView title;
39 | private TextView city;
40 |
41 | public CityHolder(View itemView, int type,ItemClickListener listener) {
42 | super(itemView,type, listener);
43 | switch (type)
44 | {
45 | case 0:
46 | title= (TextView) itemView.findViewById(R.id.tv_title);
47 | break;
48 | case 1:
49 | city= (TextView) itemView.findViewById(R.id.tv_city);
50 | break;
51 | default:
52 | break;
53 | }
54 | }
55 |
56 | @Override
57 | public void bindHolder(CityBean cityBean, int position) {
58 | int itemViewTtpe=CityRvAdapter.this.getItemViewType(position);
59 | switch (itemViewTtpe)
60 | {
61 | case 0:
62 | title.setText(list.get(position).getProvince());
63 | break;
64 | case 1:
65 | city.setText(list.get(position).getCity());
66 | break;
67 | case 2:
68 | break;
69 | }
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wind/windlinkrecycleview/adapter/ProvinceRvAdapter.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview.adapter;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.TextView;
9 |
10 | import com.wind.windlinkrecycleview.R;
11 | import com.wind.windlinkrecycleview.listener.ItemClickListener;
12 |
13 | import java.util.List;
14 |
15 | /**
16 | * Created by zhangcong on 2017/7/24.
17 | */
18 |
19 | public class ProvinceRvAdapter extends RvAdapter {
20 | private int clickPositon;
21 | public ProvinceRvAdapter(Context context, List list,ItemClickListener listener) {
22 | super(context, list,listener);
23 | }
24 | public ProvinceRvAdapter()
25 | {
26 | super();
27 | }
28 | public void setClickPositon(int position)
29 | {
30 | clickPositon=position;
31 | Log.i("SIMON","clickposition"+clickPositon);
32 | notifyDataSetChanged();//更新view,否则点击背景不换
33 | }
34 | @Override
35 | protected RvHolder getHolder(View view, int viewType) {
36 | return new ProvinceHolder(view,viewType,listener);
37 | }
38 |
39 | @Override
40 | protected int getLayoutId(int viewType) {
41 | return R.layout.item_province;
42 | }
43 | private class ProvinceHolder extends RvHolder
44 | {
45 | private TextView textView;
46 | private View view;
47 | public ProvinceHolder(View itemView, int type,ItemClickListener listener) {
48 | super(itemView,type, listener);
49 | view=itemView;
50 | textView= (TextView) view.findViewById(R.id.tv_province);
51 | }
52 |
53 | @Override
54 | public void bindHolder(String s, int position) {
55 |
56 | Log.i(">>>>>>","click"+clickPositon);
57 | if (position==clickPositon)
58 | {
59 | view.setBackgroundColor(Color.parseColor("#9EABF4"));
60 | textView.setTextColor(Color.parseColor("#ffffff"));
61 | }
62 | else {
63 | view.setBackgroundColor(Color.parseColor("#00FFFFFF"));//设置为透明的,因为白色会覆盖分割线
64 | textView.setTextColor(Color.parseColor("#1e1d1d"));
65 | }
66 | textView.setText(s);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wind/windlinkrecycleview/adapter/RvAdapter.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.wind.windlinkrecycleview.listener.ItemClickListener;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by zhangcong on 2017/7/24.
15 | * 当item有不同的布局时,抽象出来的类
16 | */
17 |
18 | public abstract class RvAdapter extends RecyclerView.Adapter {
19 | private Context context;
20 | protected List list;
21 | protected ItemClickListener listener;
22 | public RvAdapter(Context context,List list,ItemClickListener listener)
23 | {
24 | this.context=context;
25 | this.list=list;
26 | this.listener=listener;
27 | }
28 | public RvAdapter()
29 | {
30 |
31 | }
32 | /*
33 | called when RecyclerView needs a new {@link ViewHolder} of the given type to represent
34 | an item.
35 | */
36 | @Override
37 | public RvHolder onCreateViewHolder(ViewGroup parent, int viewType) {
38 | View view= LayoutInflater.from(parent.getContext()).inflate(getLayoutId(viewType),parent,false);
39 | return getHolder(view,viewType);
40 | }
41 |
42 | protected abstract RvHolder getHolder(View view, int viewType);
43 |
44 | protected abstract int getLayoutId(int viewType);
45 | /*
46 | 展示数据被回调
47 | */
48 | @Override
49 | public void onBindViewHolder(RvHolder holder, int position) {
50 | holder.bindHolder(list.get(position),position);
51 | holder.itemView.setTag(position);
52 | }
53 |
54 | @Override
55 | public int getItemViewType(int position) {
56 | return 0;
57 | }
58 |
59 | @Override
60 | public int getItemCount() {
61 | return list == null ? 0 : list.size();
62 | }
63 | public abstract class RvHolder extends RecyclerView.ViewHolder
64 | {
65 | protected ItemClickListener clickListener;
66 | public RvHolder(View itemView ,int type,ItemClickListener listener) {
67 | super(itemView);
68 | clickListener=listener;
69 | itemView.setOnClickListener(new View.OnClickListener() {
70 | @Override
71 | public void onClick(View v) {
72 | clickListener.onItemClick(v, (int) v.getTag());
73 | }
74 | });
75 | }
76 | public abstract void bindHolder(T t,int position);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wind/windlinkrecycleview/listener/ItemClickListener.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview.listener;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Created by zhangcong on 2017/7/24.
7 | */
8 |
9 | public interface ItemClickListener {
10 | void onItemClick(View view , int position);
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wind/windlinkrecycleview/model/CityBean.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview.model;
2 |
3 | /**
4 | * Created by zhangcong on 2017/7/24.
5 | */
6 |
7 | public class CityBean {
8 | public String city;
9 | public boolean isTitle;//判断是否为省份,来进行加载数据
10 | public String province;
11 | public String tag;//一个position,同时将城市与省份绑定
12 | public void setTitle(boolean title)
13 | {
14 | isTitle=title;
15 | }
16 | public void setProvince (String province)
17 | {
18 | this.province=province;
19 |
20 | }
21 | public String getProvince()
22 | {
23 | return province;
24 | }
25 | public boolean isTitle()
26 | {
27 | return isTitle;
28 | }
29 | public void setCity(String city)
30 | {
31 | this.city=city;
32 | }
33 | public String getCity()
34 | {
35 | return city;
36 | }
37 | public void setTag(String tag)
38 | {
39 | this.tag=tag;
40 | }
41 | public String getTag()
42 | {
43 | return tag;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wind/windlinkrecycleview/presenter/CityPresenter.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview.presenter;
2 |
3 | import com.wind.windlinkrecycleview.CityContract;
4 |
5 | /**
6 | * Created by zhangcong on 2017/7/24.
7 | */
8 |
9 | public class CityPresenter implements CityContract.Presenter {
10 | private CityContract.View cityView;
11 | public CityPresenter(CityContract.View cityview)
12 | {
13 | this.cityView=cityview;
14 | cityView.setPresenter(this);
15 | }
16 |
17 | @Override
18 | public void start() {
19 | showCity();
20 | }
21 |
22 | private void showCity() {
23 | cityView.showCity();
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wind/windlinkrecycleview/view/CityFragment.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview.view;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v7.widget.GridLayoutManager;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.util.Log;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 |
15 | import com.wind.windlinkrecycleview.CheckListener;
16 | import com.wind.windlinkrecycleview.CityContract;
17 | import com.wind.windlinkrecycleview.ItemHeaderDecoration;
18 | import com.wind.windlinkrecycleview.MainActivity;
19 | import com.wind.windlinkrecycleview.R;
20 | import com.wind.windlinkrecycleview.Utils;
21 | import com.wind.windlinkrecycleview.adapter.CityRvAdapter;
22 | import com.wind.windlinkrecycleview.adapter.ProvinceRvAdapter;
23 | import com.wind.windlinkrecycleview.listener.ItemClickListener;
24 | import com.wind.windlinkrecycleview.model.CityBean;
25 | import com.wind.windlinkrecycleview.presenter.CityPresenter;
26 |
27 | import java.util.ArrayList;
28 | import java.util.Arrays;
29 | import java.util.List;
30 |
31 | /**
32 | * Created by zhangcong on 2017/7/24.
33 | */
34 |
35 | public class CityFragment extends Fragment implements CityContract.View ,CheckListener{
36 | private CityContract.Presenter mpresenter;
37 | private RecyclerView recyclerView;
38 | private GridLayoutManager gridLayoutManager;
39 | private CityRvAdapter adapter;
40 | private List list=new ArrayList<>();
41 | private int moveCounts;
42 | public List citylist;
43 | public boolean move=false;
44 | private CheckListener checkListener;
45 | @Override
46 | public void onResume() {
47 | super.onResume();
48 |
49 |
50 | }
51 |
52 | @Nullable
53 | @Override
54 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
55 | View view=inflater.inflate(R.layout.fragment_city,container,false);
56 | recyclerView= (RecyclerView) view.findViewById(R.id.rv_city);
57 | recyclerView.addOnScrollListener(new RecyclerViewListener());
58 | mpresenter.start();
59 | Log.i("simonsimon","resume");
60 | return view;
61 |
62 | }
63 |
64 | @Override
65 | public void onCreate(@Nullable Bundle savedInstanceState) {
66 | super.onCreate(savedInstanceState);
67 | }
68 |
69 |
70 | @Override
71 | public void setPresenter(CityContract.Presenter presenter) {
72 | mpresenter=presenter;
73 | }
74 |
75 | @Override
76 | public void showSnackBar() {
77 | // Utils.showSnackBar(view,);
78 | }
79 | @Override
80 | public void showCity() {
81 | Log.i("simonsimon","showcity");
82 | Context context=getActivity();
83 | initData(context.getResources().getStringArray(R.array.province));
84 |
85 | gridLayoutManager=new GridLayoutManager(context,3);
86 | gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
87 | @Override
88 | public int getSpanSize(int position) {
89 | return list.get(position).isTitle ? 3 : 1 ;
90 | }
91 | });
92 | recyclerView.setLayoutManager(gridLayoutManager);
93 | adapter=new CityRvAdapter(context, list, new ItemClickListener() {
94 | @Override
95 | public void onItemClick(View view, int position) {
96 | switch (view.getId())
97 | {case R.id.root:
98 | Utils.showSnackBar(recyclerView,list.get(position).getProvince());//需要传入的是父view
99 | break;
100 | case R.id.ll_city:
101 | Utils.showSnackBar(recyclerView,list.get(position).getCity());
102 | break;
103 | }
104 |
105 | }
106 | });
107 | ItemHeaderDecoration decoration=new ItemHeaderDecoration(context,list);
108 | decoration.setData(list);
109 | recyclerView.addItemDecoration(decoration);
110 | decoration.setCheckListener(checkListener);
111 | recyclerView.setAdapter(adapter);
112 | }
113 | /*
114 | 获取左边点击,右边滑动的距离
115 | */
116 | public void setCounts(int counts)
117 | {
118 | moveCounts=counts;
119 | moveToPosition(moveCounts);
120 | Log.i("<<<<<<","count:"+moveCounts);
121 | }
122 | /*
123 | 移动到指定位置
124 | */
125 | private void moveToPosition(int moveCounts) {
126 | int firstItem=gridLayoutManager.findFirstVisibleItemPosition();//获取屏幕可见的第一个item的position
127 | int lastItem=gridLayoutManager.findLastVisibleItemPosition();//获取屏幕可见的最后一个item的position
128 | if (moveCounts();
174 | citylist.add(new String[]{"深圳","东莞","广州","韶关","汕头","肇庆","惠州"});
175 | citylist.add(new String[]{"哈尔滨","尚志","五常","海伦"});
176 | citylist.add(new String[]{"南昌","赣州","宜春","吉安"});
177 | citylist.add(new String[]{"沈阳","大连","鞍山","丹东"});
178 | citylist.add(new String[]{"呼和浩特","包头","赤峰","鄂尔多斯"});
179 | citylist.add(new String[]{"银川","石嘴山","吴忠","中卫"});
180 | citylist.add(new String[]{"太原","大同","运城","临汾"});
181 | citylist.add(new String[]{"西安","宝鸡","咸阳","延安"});
182 | citylist.add(new String[]{"拉萨","日喀则","那曲","巴青"});
183 | citylist.add(new String[]{"昆明","大理","丽江","普洱"});
184 | citylist.add(new String[]{"兰州","天水","白银","平凉"});
185 | citylist.add(new String[]{"南宁","柳州","桂林","钦州"});
186 | citylist.add(new String[]{"海口","三亚","三沙","琼海"});
187 | for (int i=0;i>>>>>",list.get(2).city.toString());
206 | Log.i(">>>>>>",citylist.size()+"");
207 | Log.i(">>>>>>",list.size()+"size");
208 | }
209 | @Override
210 | public void check(int position, boolean isScroll) {
211 | checkListener.check(position,isScroll);
212 | }
213 | public void setCheck(CheckListener listener)
214 | {
215 | this.checkListener=listener;
216 | }
217 |
218 | class RecyclerViewListener extends RecyclerView.OnScrollListener{
219 | /*
220 | 监听回调,滑动结束回调。
221 | */
222 | @Override
223 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
224 | super.onScrolled(recyclerView, dx, dy);
225 | //在这里进行第二次滚动(最后的100米!)
226 | if (move ){
227 | move = false;
228 | //获取要置顶的项在当前屏幕的位置,moveCount是记录的要置顶项在RecyclerView中的位置
229 | int n = moveCounts - gridLayoutManager.findFirstVisibleItemPosition();
230 | if ( 0 <= n && n < recyclerView.getChildCount()){
231 | //获取要置顶的项顶部离RecyclerView顶部的距离
232 | int top = recyclerView.getChildAt(n).getTop();
233 | //最后的移动
234 | recyclerView.scrollBy(0, top);
235 | }
236 | }
237 | }
238 | /*
239 | 监听回调,滑动状态改变回调
240 | */
241 | @Override
242 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
243 | super.onScrollStateChanged(recyclerView, newState);
244 |
245 | if (move&&newState==RecyclerView.SCROLL_STATE_IDLE)
246 | {
247 | move=false;
248 | int n=moveCounts-gridLayoutManager.findFirstVisibleItemPosition();
249 | if (0<=n&&n
2 |
4 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/show.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/drawable/show.gif
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
15 |
16 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_city.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_city.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_province.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
18 |
19 |
29 |
30 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/mipmap-xxxhdpi/arrow_right.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - 广东
5 | - 黑龙江
6 | - 江西
7 | - 辽宁
8 | - 内蒙古
9 | - 宁夏
10 | - 山西
11 | - 陕西
12 | - 西藏
13 | - 云南
14 | - 甘肃
15 | - 广西
16 | - 海南
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #efefef
7 | #fff
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WindLinkRecycleView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/wind/windlinkrecycleview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wind.windlinkrecycleview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/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.3.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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Simon986793021/WindLinkRecycleView/6a08c82aacf7a42b4367c2b6e56b8c181f6a51ff/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jul 24 09:43:45 CST 2017
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-3.3-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 |
--------------------------------------------------------------------------------