diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index a29c688..5230380 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.3" + compileSdkVersion 26 defaultConfig { applicationId "com.donkingliang.labelsviewdemo" - minSdkVersion 9 - targetSdkVersion 25 + minSdkVersion 14 + targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -20,12 +19,12 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + implementation fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.3.1' - testCompile 'junit:junit:4.12' + implementation 'com.android.support:appcompat-v7:26.1.0' + testImplementation 'junit:junit:4.12' - compile project(":labels") + implementation project(":labels") } diff --git a/app/src/main/java/com/donkingliang/labelsviewdemo/MainActivity.java b/app/src/main/java/com/donkingliang/labelsviewdemo/MainActivity.java index b8ca985..270dfa3 100644 --- a/app/src/main/java/com/donkingliang/labelsviewdemo/MainActivity.java +++ b/app/src/main/java/com/donkingliang/labelsviewdemo/MainActivity.java @@ -14,16 +14,32 @@ import static com.donkingliang.labelsviewdemo.R.id.labels; -public class MainActivity extends AppCompatActivity implements View.OnClickListener { +public class MainActivity extends AppCompatActivity implements LabelsView.OnLabelClickListener { + private LabelsView btnLabels; private LabelsView labelsView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - - labelsView = (LabelsView) findViewById(labels); + btnLabels = findViewById(R.id.btnLabels); + labelsView = findViewById(labels); + + // 按钮组 + ArrayList btns = new ArrayList<>(); + btns.add("不可选中"); + btns.add("单选(可反选)"); + btns.add("单选(不可反选)"); + btns.add("多选"); + btns.add("多选(最多5个)"); + btns.add("多选(最少1个)"); + btns.add("多选(1,2必选)"); + btns.add("指示器模式"); + btns.add("取消选中"); + btns.add("点击"); + btnLabels.setLabels(btns); + btnLabels.setOnLabelClickListener(this); //测试的数据 // ArrayList label = new ArrayList<>(); @@ -54,66 +70,6 @@ protected void onCreate(Bundle savedInstanceState) { testList.add(new TestBean("PHP", 10)); testList.add(new TestBean("Python", 11)); testList.add(new TestBean("Swift", 12)); - testList.add(new TestBean("Android", 1)); - testList.add(new TestBean("IOS", 2)); - testList.add(new TestBean("前端", 3)); - testList.add(new TestBean("后台", 4)); - testList.add(new TestBean("微信开发", 5)); - testList.add(new TestBean("游戏开发", 6)); - testList.add(new TestBean("Java", 7)); - testList.add(new TestBean("JavaScript", 8)); - testList.add(new TestBean("C++", 9)); - testList.add(new TestBean("PHP", 10)); - testList.add(new TestBean("Python", 11)); - testList.add(new TestBean("Swift", 12)); - testList.add(new TestBean("Android", 1)); - testList.add(new TestBean("IOS", 2)); - testList.add(new TestBean("前端", 3)); - testList.add(new TestBean("后台", 4)); - testList.add(new TestBean("微信开发", 5)); - testList.add(new TestBean("游戏开发", 6)); - testList.add(new TestBean("Java", 7)); - testList.add(new TestBean("JavaScript", 8)); - testList.add(new TestBean("C++", 9)); - testList.add(new TestBean("PHP", 10)); - testList.add(new TestBean("Python", 11)); - testList.add(new TestBean("Swift", 12)); - testList.add(new TestBean("Android", 1)); - testList.add(new TestBean("IOS", 2)); - testList.add(new TestBean("前端", 3)); - testList.add(new TestBean("后台", 4)); - testList.add(new TestBean("微信开发", 5)); - testList.add(new TestBean("游戏开发", 6)); - testList.add(new TestBean("Java", 7)); - testList.add(new TestBean("JavaScript", 8)); - testList.add(new TestBean("C++", 9)); - testList.add(new TestBean("PHP", 10)); - testList.add(new TestBean("Python", 11)); - testList.add(new TestBean("Swift", 12)); - testList.add(new TestBean("Android", 1)); - testList.add(new TestBean("IOS", 2)); - testList.add(new TestBean("前端", 3)); - testList.add(new TestBean("后台", 4)); - testList.add(new TestBean("微信开发", 5)); - testList.add(new TestBean("游戏开发", 6)); - testList.add(new TestBean("Java", 7)); - testList.add(new TestBean("JavaScript", 8)); - testList.add(new TestBean("C++", 9)); - testList.add(new TestBean("PHP", 10)); - testList.add(new TestBean("Python", 11)); - testList.add(new TestBean("Swift", 12)); - testList.add(new TestBean("Android", 1)); - testList.add(new TestBean("IOS", 2)); - testList.add(new TestBean("前端", 3)); - testList.add(new TestBean("后台", 4)); - testList.add(new TestBean("微信开发", 5)); - testList.add(new TestBean("游戏开发", 6)); - testList.add(new TestBean("Java", 7)); - testList.add(new TestBean("JavaScript", 8)); - testList.add(new TestBean("C++", 9)); - testList.add(new TestBean("PHP", 10)); - testList.add(new TestBean("Python", 11)); - testList.add(new TestBean("Swift", 12)); labelsView.setLabels(testList, new LabelsView.LabelTextProvider() { @Override @@ -126,75 +82,66 @@ public CharSequence getLabelText(TextView label, int position, TestBean data) { // labelsView.setMaxLines(1); labelsView.clearAllSelect(); - - findViewById(R.id.btn_none).setOnClickListener(this); - findViewById(R.id.btn_single).setOnClickListener(this); - findViewById(R.id.btn_multi).setOnClickListener(this); - findViewById(R.id.btn_multi_5).setOnClickListener(this); - findViewById(R.id.btn_un_select).setOnClickListener(this); - findViewById(R.id.btn_click).setOnClickListener(this); - findViewById(R.id.btn_single_irrevocably).setOnClickListener(this); - findViewById(R.id.btn_multi_compulsory).setOnClickListener(this); - findViewById(R.id.btn_multi_1).setOnClickListener(this); - findViewById(R.id.btn_indicator).setOnClickListener(this); } @Override - public void onClick(View v) { + public void onLabelClick(TextView label, Object data, int position) { labelsView.setOnLabelClickListener(null); - switch (v.getId()) { - case R.id.btn_none: + labelsView.clearCompulsorys(); + switch (position) { + case 0: labelsView.setSelectType(LabelsView.SelectType.NONE); break; - case R.id.btn_single: + case 1: labelsView.setSelectType(LabelsView.SelectType.SINGLE); break; - case R.id.btn_single_irrevocably: + case 2: labelsView.setSelectType(LabelsView.SelectType.SINGLE_IRREVOCABLY); break; - case R.id.btn_multi: + case 3: labelsView.setSelectType(LabelsView.SelectType.MULTI); labelsView.setMaxSelect(0); labelsView.setMinSelect(0); break; - case R.id.btn_multi_5: + case 4: labelsView.setSelectType(LabelsView.SelectType.MULTI); labelsView.setMaxSelect(5); labelsView.setMinSelect(0); break; - case R.id.btn_multi_1: + case 5: labelsView.setSelectType(LabelsView.SelectType.MULTI); labelsView.setMaxSelect(0); labelsView.setMinSelect(1); break; - case R.id.btn_multi_compulsory: + case 6: labelsView.setSelectType(LabelsView.SelectType.MULTI); labelsView.setMaxSelect(0); labelsView.setMinSelect(0); labelsView.setCompulsorys(0, 1); break; - case R.id.btn_indicator: - + case 7: labelsView.setIndicator(!labelsView.isIndicator()); if (labelsView.isIndicator()) { - ((TextView) v).setText("取消指示器模式"); + btnLabels.getLabels().set(position, "取消指示器模式"); + label.setText("取消指示器模式"); } else { - ((TextView) v).setText("指示器模式"); + btnLabels.getLabels().set(position, "指示器模式"); + label.setText("指示器模式"); } break; - case R.id.btn_un_select: + case 8: labelsView.clearAllSelect(); break; - case R.id.btn_click: + case 9: labelsView.setSelectType(LabelsView.SelectType.NONE); labelsView.setOnLabelClickListener(new LabelsView.OnLabelClickListener() { @Override diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index c87295c..47a4c9f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,126 +6,45 @@ android:background="#cccccc" android:orientation="vertical"> - - -