Skip to content

Commit

Permalink
支持单行显示
Browse files Browse the repository at this point in the history
  • Loading branch information
teach committed Sep 20, 2019
1 parent caa67e7 commit d1e2456
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 252 deletions.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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")
}
125 changes: 36 additions & 89 deletions app/src/main/java/com/donkingliang/labelsviewdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> label = new ArrayList<>();
Expand Down Expand Up @@ -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<TestBean>() {
@Override
Expand All @@ -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
Expand Down
Loading

0 comments on commit d1e2456

Please sign in to comment.