├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── dictionaries
│ └── wangtao.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── libs
│ └── gson-2.2.4.jar
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── home
│ │ └── labellinkdemo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── home
│ │ │ └── labellinkdemo
│ │ │ ├── MyApplication.java
│ │ │ ├── ScreenUtils.java
│ │ │ ├── ToastUtils.java
│ │ │ ├── activity
│ │ │ ├── LabelLinkFlowLayoutActivity.java
│ │ │ ├── LabelLinkRecyclerActivity.java
│ │ │ └── MainActivity.java
│ │ │ ├── adapter
│ │ │ └── LinkLabelAdapter.java
│ │ │ └── bean
│ │ │ └── LinkLabelBean.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── circle.xml
│ │ ├── circle_bule.xml
│ │ ├── circle_fen.xml
│ │ ├── circle_ret_orange.xml
│ │ ├── dialog_label.xml
│ │ ├── dialog_label_text.xml
│ │ ├── dialog_label_text_tv.xml
│ │ ├── dialog_label_tv.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── red_sold_round_gay.xml
│ │ └── red_sold_round_sel.xml
│ │ ├── layout
│ │ ├── activity_label_link_flow_layout.xml
│ │ ├── activity_label_link_recycler.xml
│ │ ├── activity_main.xml
│ │ ├── adapter_activity_label_content.xml
│ │ ├── adapter_activity_label_title.xml
│ │ └── dialog_view_textview.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── home
│ └── labellinkdemo
│ └── 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/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.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 |
--------------------------------------------------------------------------------
/.idea/dictionaries/wangtao.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
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 |
--------------------------------------------------------------------------------
/.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 | ### 项目介绍
2 | ##### 是一款标签选择的demo.有固定的逻辑.适合大部分项目的应用场景
3 | ### 同步简书地址:
4 | #### https://www.jianshu.com/p/d6c4b7c873d3
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.home.labellinkdemo"
7 | minSdkVersion 15
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | implementation 'com.android.support:appcompat-v7:25.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28 | //黄油刀
29 | implementation 'com.jakewharton:butterknife:8.8.1'
30 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
31 | //noinspection GradleCompatible
32 | implementation 'com.android.support:design:25.1.0'
33 | implementation files('libs/gson-2.2.4.jar')
34 | //flowLayout 布局展示
35 | implementation 'com.hyman:flowlayout-lib:1.1.2'
36 | }
37 |
--------------------------------------------------------------------------------
/app/libs/gson-2.2.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/app/libs/gson-2.2.4.jar
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/home/labellinkdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.home.labellinkdemo;
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 | * Instrumented 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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.home.labellinkdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/home/labellinkdemo/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.home.labellinkdemo;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | public class MyApplication extends Application {
7 |
8 | public static Context sInstance;
9 |
10 | @Override
11 | public void onCreate() {
12 | super.onCreate();
13 | sInstance = getApplicationContext();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/home/labellinkdemo/ScreenUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 JustWayward Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.home.labellinkdemo;
17 |
18 | import android.annotation.SuppressLint;
19 | import android.content.Context;
20 | import android.content.res.Configuration;
21 | import android.os.Build;
22 | import android.util.DisplayMetrics;
23 | import android.util.TypedValue;
24 | import android.view.Display;
25 | import android.view.WindowManager;
26 |
27 | import java.lang.reflect.Method;
28 |
29 | /**
30 | * 屏幕亮度工具类
31 | *
32 | * @author yuyh.
33 | * @date 16/4/10.
34 | */
35 | public class ScreenUtils {
36 |
37 | public enum EScreenDensity {
38 | XXHDPI, //超高分辨率 1080×1920
39 | XHDPI, //超高分辨率 720×1280
40 | HDPI, //高分辨率 480×800
41 | MDPI, //中分辨率 320×480
42 | }
43 |
44 | public static EScreenDensity getDisply(Context context) {
45 | EScreenDensity eScreenDensity;
46 | //初始化屏幕密度
47 | DisplayMetrics dm = context.getApplicationContext().getResources().getDisplayMetrics();
48 | int densityDpi = dm.densityDpi;
49 |
50 | if (densityDpi <= 160) {
51 | eScreenDensity = EScreenDensity.MDPI;
52 | } else if (densityDpi <= 240) {
53 | eScreenDensity = EScreenDensity.HDPI;
54 | } else if (densityDpi < 400) {
55 | eScreenDensity = EScreenDensity.XHDPI;
56 | } else {
57 | eScreenDensity = EScreenDensity.XXHDPI;
58 | }
59 | return eScreenDensity;
60 | }
61 |
62 | /**
63 | * 获取屏幕宽度
64 | *
65 | * @return
66 | */
67 | public static int getScreenWidth() {
68 | return MyApplication.sInstance.getResources().getDisplayMetrics().widthPixels;
69 | }
70 |
71 | /**
72 | * 获取屏幕高度
73 | *
74 | * @return
75 | */
76 | public static int getScreenHeight() {
77 | String model = Build.MODEL;
78 | if (model.equals("MIX 2")) {
79 | return getDpi(MyApplication.sInstance);
80 | } else {
81 | return MyApplication.sInstance.getResources().getDisplayMetrics().heightPixels;
82 | }
83 | }
84 |
85 | public static int getDpi(Context context) {
86 | int dpi = 0;
87 | @SuppressLint("WrongConstant") WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
88 | Display display = windowManager.getDefaultDisplay();
89 | DisplayMetrics displayMetrics = new DisplayMetrics();
90 | @SuppressWarnings("rawtypes")
91 | Class c;
92 | try {
93 | c = Class.forName("android.view.Display");
94 | @SuppressWarnings("unchecked")
95 | Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
96 | method.invoke(display, displayMetrics);
97 | dpi = displayMetrics.heightPixels;
98 | } catch (Exception e) {
99 | e.printStackTrace();
100 | }
101 | return dpi;
102 | }
103 |
104 | /**
105 | * 将dp转换成px
106 | *
107 | * @param dp
108 | * @return
109 | */
110 | public static float dpToPx(float dp) {
111 | return dp * MyApplication.sInstance.getResources().getDisplayMetrics().density;
112 | }
113 |
114 | public static int dpToPxInt(float dp) {
115 | return (int) (dpToPx(dp) + 0.5f);
116 | }
117 |
118 | /**
119 | * 将px转换成dp
120 | *
121 | * @param px
122 | * @return
123 | */
124 | public static float pxToDp(float px) {
125 | return px / MyApplication.sInstance.getResources().getDisplayMetrics().density;
126 | }
127 |
128 | public static int pxToDpInt(float px) {
129 | return (int) (pxToDp(px) + 0.5f);
130 | }
131 |
132 | /**
133 | * 将px值转换为sp值
134 | *
135 | * @param pxValue
136 | * @return
137 | */
138 | public static float pxToSp(float pxValue) {
139 | return pxValue / MyApplication.sInstance.getResources().getDisplayMetrics().scaledDensity;
140 | }
141 |
142 | /**
143 | * 将sp值转换为px值
144 | *
145 | * @param spValue
146 | * @return
147 | */
148 | public static float spToPx(float spValue) {
149 | return spValue * MyApplication.sInstance.getResources().getDisplayMetrics().scaledDensity;
150 | }
151 |
152 | public static int getStatusBarHeight(Context context) {
153 | int result = 0;
154 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
155 | if (resourceId > 0) {
156 | result = context.getResources().getDimensionPixelSize(resourceId);
157 | }
158 | return result;
159 | }
160 |
161 | public static int getActionBarSize(Context context) {
162 | TypedValue tv = new TypedValue();
163 | if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
164 | int actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
165 | return actionBarHeight;
166 | }
167 | return 0;
168 | }
169 |
170 | /**
171 | * 当前是否是横屏
172 | *
173 | * @param context context
174 | * @return boolean
175 | */
176 | public static final boolean isLandscape(Context context) {
177 | return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
178 | }
179 |
180 | /**
181 | * 当前是否是竖屏
182 | *
183 | * @param context context
184 | * @return boolean
185 | */
186 | public static final boolean isPortrait(Context context) {
187 | return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/app/src/main/java/com/home/labellinkdemo/ToastUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 JustWayward Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.home.labellinkdemo;
17 |
18 | import android.content.Context;
19 | import android.text.TextUtils;
20 | import android.widget.Toast;
21 |
22 | /**
23 | * Toast工具类,解决多个Toast同时出现的问题
24 | *
25 | * @author yuyh.
26 | * @date 16/4/9.
27 | */
28 | public class ToastUtils {
29 |
30 | private static Toast mToast;
31 | private static Context context = MyApplication.sInstance;
32 |
33 | public static void showSingleToast(String text) {
34 | if (!TextUtils.isEmpty(text)) {
35 | getSingleToast(text, Toast.LENGTH_SHORT).show();
36 | }
37 | }
38 |
39 | public static Toast getSingleToast(String text, int duration) {
40 | if (mToast == null && !TextUtils.isEmpty(text)) {
41 | mToast = Toast.makeText(context, text, duration);
42 | } else {
43 | if (!TextUtils.isEmpty(text)) {
44 | mToast.setText(text);
45 | }
46 | }
47 | return mToast;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/home/labellinkdemo/activity/LabelLinkFlowLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package com.home.labellinkdemo.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 | import android.widget.LinearLayout;
10 | import android.widget.TextView;
11 |
12 | import com.google.gson.Gson;
13 | import com.home.labellinkdemo.R;
14 | import com.home.labellinkdemo.ScreenUtils;
15 | import com.home.labellinkdemo.ToastUtils;
16 | import com.zhy.view.flowlayout.FlowLayout;
17 | import com.zhy.view.flowlayout.TagAdapter;
18 | import com.zhy.view.flowlayout.TagFlowLayout;
19 |
20 | import java.util.ArrayList;
21 | import java.util.HashMap;
22 | import java.util.List;
23 | import java.util.Set;
24 |
25 | import butterknife.BindView;
26 | import butterknife.ButterKnife;
27 |
28 | public class LabelLinkFlowLayoutActivity extends AppCompatActivity {
29 |
30 | @BindView(R.id.tabLayout_man)
31 | TagFlowLayout tabLayoutMan;
32 |
33 | private Object[] strAll = new Object[]{"开始", "男人", "穿越", "军事", "悬疑", "还有谁", "仙侠", "奇幻", "竞技",
34 | "开始1", "神雕侠侣", "现言", "LOL", "婚恋", "穿越", "红尘", "灵异", "女人", "开始2",
35 | "恐怖", "蜜语", "言情", "吃鸡", "校园", "妹子", "荒岛", "其他"};
36 |
37 | private HashMap> stringHashMap = new HashMap<>();
38 | private List list = new ArrayList<>();
39 | private Gson gson = new Gson();
40 | private List list1 = new ArrayList<>();
41 | private List list2 = new ArrayList<>();
42 | private List list3 = new ArrayList<>();
43 |
44 |
45 | @Override
46 | protected void onCreate(Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | setContentView(R.layout.activity_label_link_flow_layout);
49 | ButterKnife.bind(this);
50 |
51 | tabLayoutMan.setAdapter(new TagAdapter(strAll) {
52 | @Override
53 | public View getView(FlowLayout flowLayout, int i, Object s) {
54 | if (String.valueOf(s).contains("开始")) {
55 | View inflat = LayoutInflater.from(getApplicationContext()).inflate(R.layout.adapter_activity_label_title, null);
56 | ImageView adapterIv = (ImageView) inflat.findViewById(R.id.adapter_iv);
57 | TextView adapterTitle = (TextView) inflat.findViewById(R.id.adater_title);
58 | if (String.valueOf(s).equals("开始")) {
59 | adapterIv.setImageResource(R.drawable.circle);
60 | adapterTitle.setText("以下推荐男生选择");
61 | } else if (String.valueOf(s).equals("开始1")) {
62 | adapterIv.setImageResource(R.drawable.circle_fen);
63 | adapterTitle.setText("以下推荐女生选择");
64 | } else if (String.valueOf(s).equals("开始2")) {
65 | adapterIv.setImageResource(R.drawable.circle_bule);
66 | adapterTitle.setText("以下推荐二次元选择");
67 | }
68 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
69 | layoutParams.width = ScreenUtils.getScreenWidth();
70 | inflat.setLayoutParams(layoutParams);
71 | return inflat;
72 | } else {
73 | TextView tv = (TextView) LayoutInflater.from(getApplicationContext()).inflate(R.layout.dialog_view_textview,
74 | tabLayoutMan, false);
75 | tv.setText(String.valueOf(s));
76 | return tv;
77 | }
78 | }
79 | });
80 |
81 | tabLayoutMan.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
82 | @Override
83 | public void onSelected(Set set) {
84 | stringHashMap.clear();
85 | list.clear();
86 | list1.clear();
87 | list2.clear();
88 | list3.clear();
89 | for (Integer entry : set) {
90 | if (!String.valueOf(strAll[entry]).contains("开始")) {
91 | list.add(String.valueOf(strAll[entry]));
92 | }
93 | if (entry > 0 && entry < 9) {
94 | if (!String.valueOf(strAll[entry]).contains("开始")) {
95 | list1.add(String.valueOf(strAll[entry]));
96 | }
97 | } else if (entry > 9 && entry < 18) {
98 | if (!String.valueOf(strAll[entry]).contains("开始")) {
99 | list2.add(String.valueOf(strAll[entry]));
100 | }
101 | } else {
102 | if (!String.valueOf(strAll[entry]).contains("开始")) {
103 | list3.add(String.valueOf(strAll[entry]));
104 | }
105 | }
106 | }
107 | if (list1.size() > 0) {
108 | stringHashMap.put("1", list1);
109 | }
110 | if (list2.size() > 0) {
111 | stringHashMap.put("2", list2);
112 | }
113 | if (list3.size() > 0) {
114 | stringHashMap.put("3", list3);
115 | }
116 | String json = gson.toJson(stringHashMap);
117 | ToastUtils.showSingleToast("数据: " + json);
118 | }
119 | });
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/home/labellinkdemo/activity/LabelLinkRecyclerActivity.java:
--------------------------------------------------------------------------------
1 | package com.home.labellinkdemo.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.GridLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | import com.google.gson.Gson;
11 | import com.home.labellinkdemo.R;
12 | import com.home.labellinkdemo.ToastUtils;
13 | import com.home.labellinkdemo.adapter.LinkLabelAdapter;
14 | import com.home.labellinkdemo.bean.LinkLabelBean;
15 |
16 | import java.util.ArrayList;
17 | import java.util.HashMap;
18 | import java.util.List;
19 | import java.util.Map;
20 |
21 | import butterknife.BindView;
22 | import butterknife.ButterKnife;
23 | import butterknife.OnClick;
24 |
25 | public class LabelLinkRecyclerActivity extends AppCompatActivity {
26 |
27 | @BindView(R.id.recyclerview)
28 | RecyclerView recyclerView;
29 | @BindView(R.id.email_sign_in_button)
30 | Button btn;
31 |
32 | private List list = new ArrayList<>();
33 | private List list1 = new ArrayList<>();
34 | private List list2 = new ArrayList<>();
35 | private List list3 = new ArrayList<>();
36 | private Gson gson = new Gson();
37 |
38 | private String[] str = new String[]{"标题1", "帅哥", "校园", "军事", "悬疑", "科幻", "露露", "奇幻", "韦恩", "标题2",
39 | "古言", "抢女", "总裁", "网红", "穿越", "美女", "灵异", "色魔", "标题3",
40 | "恐怖", "红魔", "言情", "科幻", "诺克萨斯", "人妖", "荒岛", "其他"};
41 | private Map> hashMap = new HashMap<>();
42 | private LinkLabelBean linkLabelBean;
43 |
44 | @Override
45 | public void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_label_link_recycler);
48 | ButterKnife.bind(this);
49 | initData();
50 | initView();
51 | }
52 |
53 | private void initData() {
54 | for (int i = 0; i < str.length; i++) {
55 | linkLabelBean = new LinkLabelBean();
56 | linkLabelBean.setStr(str[i]);
57 | list.add(linkLabelBean);
58 | }
59 | }
60 |
61 |
62 | private void initView() {
63 | final GridLayoutManager mLayoutManager = new GridLayoutManager(getApplicationContext(), 4);
64 | mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
65 | @Override
66 | public int getSpanSize(int position) {
67 | int type = recyclerView.getAdapter().getItemViewType(position);//获得返回值
68 | if (type == 99) {
69 | return mLayoutManager.getSpanCount();
70 | } else {
71 | return 1;
72 | }
73 | }
74 | });
75 | recyclerView.setLayoutManager(mLayoutManager);
76 | LinkLabelAdapter linkLabelAdapter = new LinkLabelAdapter(getApplicationContext(), list);
77 | recyclerView.setAdapter(linkLabelAdapter);
78 | }
79 |
80 | @OnClick({R.id.email_sign_in_button})
81 | public void onClick(View view) {
82 | switch (view.getId()) {
83 | case R.id.email_sign_in_button:
84 | //这边其实可以优化 但是时间不够就不再做优化。
85 | boolean zhishao = false;
86 | for (int i = 0; i < list.size(); i++) {
87 | if (list.get(i).isSelect()) {
88 | zhishao = true;
89 | }
90 | }
91 | if (!zhishao) {
92 | ToastUtils.showSingleToast("至少选择一个标签。");
93 | return;
94 | }
95 | hashMap.clear();
96 | list1.clear();
97 | list2.clear();
98 | list3.clear();
99 | for (int i = 0; i < list.size(); i++) {
100 | if (list.get(i).isSelect()) {
101 | if (i > 0 && i <= 8) {
102 | list1.add(list.get(i).getStr());
103 | } else if (i > 8 && i <= 17) {
104 | list2.add(list.get(i).getStr());
105 | } else {
106 | list3.add(list.get(i).getStr());
107 | }
108 | }
109 | }
110 | if (list1.size() > 0) {
111 | hashMap.put("1", list1);
112 | }
113 | if (list2.size() > 0) {
114 | hashMap.put("2", list2);
115 | }
116 | if (list3.size() > 0) {
117 | hashMap.put("3", list3);
118 | }
119 | String s = gson.toJson(hashMap);
120 | ToastUtils.showSingleToast("选中数据--" + s);
121 | break;
122 | }
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/app/src/main/java/com/home/labellinkdemo/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.home.labellinkdemo.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.home.labellinkdemo.R;
10 |
11 | import butterknife.BindView;
12 | import butterknife.ButterKnife;
13 | import butterknife.OnClick;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | @BindView(R.id.bt_gridview)
18 | Button btGridview;
19 | @BindView(R.id.bt_flowLayout)
20 | Button btFlowLayout;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 | ButterKnife.bind(this);
27 | }
28 |
29 | @OnClick({R.id.bt_gridview, R.id.bt_flowLayout})
30 | public void onClick(View view) {
31 | switch (view.getId()) {
32 | case R.id.bt_gridview:
33 | startActivity(new Intent(getApplicationContext(), LabelLinkRecyclerActivity.class));
34 | break;
35 | case R.id.bt_flowLayout:
36 | startActivity(new Intent(getApplicationContext(), LabelLinkFlowLayoutActivity.class));
37 | break;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/home/labellinkdemo/adapter/LinkLabelAdapter.java:
--------------------------------------------------------------------------------
1 | package com.home.labellinkdemo.adapter;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 | import android.widget.LinearLayout;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import com.home.labellinkdemo.R;
15 | import com.home.labellinkdemo.ToastUtils;
16 | import com.home.labellinkdemo.bean.LinkLabelBean;
17 |
18 | import java.util.List;
19 |
20 | /**
21 | * Created by wangtao on 2018/4/18.
22 | */
23 |
24 | public class LinkLabelAdapter extends RecyclerView.Adapter {
25 |
26 | private Context context;
27 | private final int TITLE = 99;
28 | private final int CONTENT = 100;
29 | private int Zeng = 0;
30 | private List list;
31 |
32 | public LinkLabelAdapter(Context context, List list) {
33 | this.context = context;
34 | this.list = list;
35 | }
36 |
37 |
38 | @Override
39 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
40 | RecyclerView.ViewHolder holder = null;
41 | if (viewType == TITLE) {
42 | holder = new TitleHolder(LayoutInflater.from(context).inflate(R.layout.adapter_activity_label_title, null));
43 | } else {
44 | holder = new LabelHolder(LayoutInflater.from(context).inflate(R.layout.adapter_activity_label_content, null));
45 | }
46 | return holder;
47 | }
48 |
49 | @Override
50 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
51 | if (getItemViewType(position) == TITLE) {
52 | ((TitleHolder) holder).setData(position);
53 | } else {
54 | ((LabelHolder) holder).setData(position);
55 | }
56 | }
57 |
58 | @Override
59 | public int getItemCount() {
60 | return list.size();
61 | }
62 |
63 | @Override
64 | public int getItemViewType(int position) {
65 | if (list.get(position).getStr().contains("标题")) {
66 | return TITLE;
67 | } else {
68 | return CONTENT;
69 | }
70 | }
71 |
72 | class TitleHolder extends RecyclerView.ViewHolder {
73 |
74 | private final TextView adapterTitle;
75 | private final ImageView adapterTitleIv;
76 |
77 | public TitleHolder(View inflate) {
78 | super(inflate);
79 | adapterTitle = (TextView) inflate.findViewById(R.id.adater_title);
80 | adapterTitleIv = (ImageView) inflate.findViewById(R.id.adapter_iv);
81 | }
82 |
83 | @SuppressLint("WrongConstant")
84 | public void setData(int position) {
85 | switch (list.get(position).getStr()) {
86 | case "标题1":
87 | adapterTitleIv.setImageResource(R.drawable.circle);
88 | adapterTitle.setText("以下推荐男生选择");
89 | break;
90 | case "标题2":
91 | adapterTitleIv.setImageResource(R.drawable.circle_fen);
92 | adapterTitle.setText("以下推荐女生选择");
93 | break;
94 | case "标题3":
95 | adapterTitleIv.setImageResource(R.drawable.circle_bule);
96 | adapterTitle.setText("以下推荐二次元选择");
97 | break;
98 | default:
99 | adapterTitleIv.setVisibility(View.GONE);
100 | adapterTitle.setVisibility(View.GONE);
101 | break;
102 | }
103 | }
104 | }
105 |
106 | private class LabelHolder extends RecyclerView.ViewHolder {
107 | private TextView textView;
108 | private final LinearLayout llContent;
109 |
110 | public LabelHolder(View inflate) {
111 | super(inflate);
112 | textView = (TextView) inflate.findViewById(R.id.textViewContent);
113 | llContent = (LinearLayout) inflate.findViewById(R.id.llContent);
114 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
115 | layoutParams.leftMargin = 50;
116 | llContent.setLayoutParams(layoutParams);
117 | }
118 |
119 | public void setData(final int position) {
120 | textView.setText(list.get(position).getStr());
121 | textView.setOnClickListener(new View.OnClickListener() {
122 | @Override
123 | public void onClick(View v) {
124 | if (list.get(position).isSelect()) {
125 | Zeng--;
126 | }
127 | if (Zeng < 4) {
128 | if (textView.isSelected()) {
129 | textView.setSelected(false);
130 | list.get(position).setSelect(false);
131 | } else {
132 | ++Zeng;
133 | textView.setSelected(true);
134 | list.get(position).setSelect(true);
135 | }
136 | } else {
137 | ToastUtils.showSingleToast("最多只能选择4个标签");
138 | }
139 | }
140 | });
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/app/src/main/java/com/home/labellinkdemo/bean/LinkLabelBean.java:
--------------------------------------------------------------------------------
1 | package com.home.labellinkdemo.bean;
2 |
3 | /**
4 | * Created by wangtao on 2018/4/18.
5 | */
6 |
7 | public class LinkLabelBean {
8 |
9 | private boolean select;
10 |
11 | private String str;
12 |
13 | public String getStr() {
14 | return str == null ? "" : str;
15 | }
16 |
17 | public void setStr(String str) {
18 | this.str = str;
19 | }
20 |
21 | public boolean isSelect() {
22 | return select;
23 | }
24 |
25 | public void setSelect(boolean select) {
26 | this.select = select;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
14 |
17 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_bule.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
14 |
17 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_fen.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
14 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_ret_orange.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dialog_label.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dialog_label_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dialog_label_text_tv.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dialog_label_tv.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/red_sold_round_gay.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/red_sold_round_sel.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_label_link_flow_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_label_link_recycler.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
26 |
27 |
31 |
32 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
19 |
20 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/adapter_activity_label_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/adapter_activity_label_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_view_textview.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LabelLinkDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/home/labellinkdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.home.labellinkdemo;
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() {
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 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.4'
11 | classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | maven {url "https://jitpack.io" }
21 | google()
22 | jcenter()
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangtao2855/LabelLinkDemo/620efa7f8c1765b3f36aeada3f2732583d1b113c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Sep 04 13:21:39 CST 2018
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-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------