├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── Sample
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── shape_line.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── layout_tab_0.xml
│ │ │ │ ├── item_selector.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── rock
│ │ │ │ └── android
│ │ │ │ └── tagselectorview
│ │ │ │ ├── MyDataBean.java
│ │ │ │ ├── CustomAdapter.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── rock
│ │ │ └── android
│ │ │ └── tagselectorview
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── rock
│ │ └── android
│ │ └── tagselectorview
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── tagselector
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── attrs.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── arrow_top.png
│ │ │ │ ├── arrow_bottom.png
│ │ │ │ ├── select_item.png
│ │ │ │ └── horizontal_line.xml
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable
│ │ │ │ ├── shape_transparent.xml
│ │ │ │ ├── vertical_line.xml
│ │ │ │ └── selector_item_select.xml
│ │ │ ├── anim
│ │ │ │ ├── ts_content_in.xml
│ │ │ │ └── ts_content_out.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── item_tag_selector.xml
│ │ │ │ └── layout_tag_selector_view.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── rock
│ │ │ └── android
│ │ │ └── tagselector
│ │ │ ├── interfaces
│ │ │ ├── SelectorAdapter.java
│ │ │ ├── ITagSelector.java
│ │ │ └── ITagSelectorTabView.java
│ │ │ ├── Utils.java
│ │ │ ├── model
│ │ │ ├── DataBean.java
│ │ │ └── Tags.java
│ │ │ ├── LogUtil.java
│ │ │ └── views
│ │ │ ├── CheckableLinearLayout.java
│ │ │ ├── BaseSelectorAdapter.java
│ │ │ ├── SimpleSingleSelectListView.java
│ │ │ ├── TagSelectorTabTabView.java
│ │ │ └── TagSelectView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── rock
│ │ │ └── android
│ │ │ └── tagselector
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── rock
│ │ └── android
│ │ └── tagselector
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gif
├── gif2.gif
└── sample.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | TagSelectorView
--------------------------------------------------------------------------------
/Sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tagselector/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':Sample', ':tagselector'
2 |
--------------------------------------------------------------------------------
/gif/gif2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/gif/gif2.gif
--------------------------------------------------------------------------------
/gif/sample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/gif/sample.gif
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TagSelectorView
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/tagselector/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TagSelector
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/Sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/Sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/Sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/Sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/Sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/Sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/tagselector/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/tagselector/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/tagselector/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/tagselector/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/tagselector/src/main/res/drawable-xhdpi/arrow_top.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/tagselector/src/main/res/drawable-xhdpi/arrow_top.png
--------------------------------------------------------------------------------
/tagselector/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/tagselector/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/tagselector/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/tagselector/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/tagselector/src/main/res/drawable-xhdpi/arrow_bottom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/tagselector/src/main/res/drawable-xhdpi/arrow_bottom.png
--------------------------------------------------------------------------------
/tagselector/src/main/res/drawable-xhdpi/select_item.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/tagselector/src/main/res/drawable-xhdpi/select_item.png
--------------------------------------------------------------------------------
/tagselector/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rock610/TagSelectorView/HEAD/tagselector/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/drawable/shape_transparent.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/tagselector/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/drawable/vertical_line.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/Sample/src/main/res/drawable-xhdpi/shape_line.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/drawable-xhdpi/horizontal_line.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Apr 06 10:55:42 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 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/anim/ts_content_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/anim/ts_content_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #dedede
8 |
9 | #333333
10 |
11 |
--------------------------------------------------------------------------------
/Sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/drawable/selector_item_select.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/tagselector/src/test/java/com/rock/android/tagselector/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/Sample/src/test/java/com/rock/android/tagselectorview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselectorview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/Sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/tagselector/src/androidTest/java/com/rock/android/tagselector/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/Sample/src/androidTest/java/com/rock/android/tagselectorview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselectorview;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/tagselector/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Sample/src/main/java/com/rock/android/tagselectorview/MyDataBean.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselectorview;
2 |
3 | import com.rock.android.tagselector.model.DataBean;
4 |
5 | /**
6 | * Created by rock on 16/7/4.
7 | */
8 | public class MyDataBean extends DataBean {
9 |
10 | int id;
11 |
12 | public MyDataBean(String name) {
13 | super(name);
14 | }
15 |
16 | public MyDataBean(String name, int id) {
17 | super(name);
18 | this.id = id;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/interfaces/SelectorAdapter.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector.interfaces;
2 |
3 | import com.rock.android.tagselector.model.DataBean;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by rock on 16/7/5.
9 | */
10 | public interface SelectorAdapter {
11 |
12 | void setData(List extends DataBean> list);
13 |
14 | List extends DataBean> getData();
15 |
16 | void notifyDataSetChanged();
17 |
18 | int getItemHeight();
19 | }
20 |
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/Utils.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector;
2 |
3 | import android.content.Context;
4 | import android.util.TypedValue;
5 |
6 | /**
7 | * Created by rock on 16/7/4.
8 | */
9 | public class Utils {
10 |
11 | public static int dp2px(Context context, int dp) {
12 |
13 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
14 | context.getApplicationContext().getResources().getDisplayMetrics());
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/model/DataBean.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector.model;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by rock on 16/7/4.
7 | *
8 | * 模拟后台来的数据
9 | */
10 | public class DataBean implements Serializable{
11 |
12 |
13 | private static final long serialVersionUID = 4602009937739085873L;
14 |
15 | public DataBean(String name) {
16 | this.name = name;
17 | }
18 |
19 | public DataBean() {
20 | }
21 |
22 | public String name;
23 | }
24 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/Sample/src/main/res/layout/layout_tab_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
--------------------------------------------------------------------------------
/Sample/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 /Users/rock/Documents/ROCK/android-sdk-macosx/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 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/tagselector/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 /Users/rock/Documents/ROCK/android-sdk-macosx/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 |
--------------------------------------------------------------------------------
/Sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion '25.0.0'
6 |
7 | defaultConfig {
8 | applicationId "com.rock.android.tagselectorview"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.2.1'
26 | compile project(':tagselector')
27 | }
28 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/Sample/src/main/res/layout/item_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
20 |
21 |
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/LogUtil.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * Created by rock on 16/7/12.
7 | */
8 | public class LogUtil {
9 |
10 | public static final boolean DEBUG = false;
11 |
12 | public static void e(String tag,Object o){
13 | if(DEBUG){
14 | Log.e(tag,String.valueOf(o));
15 | }
16 | }
17 |
18 | public static void d(String tag,Object o){
19 | if(DEBUG){
20 | Log.d(tag,String.valueOf(o));
21 | }
22 | }
23 |
24 | public static void print(String tag,Object o){
25 | if(DEBUG){
26 | System.out.println(tag+"---"+o);
27 | }
28 | }
29 |
30 | public static void print(Object o){
31 | if(DEBUG){
32 | System.out.println(o);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/interfaces/ITagSelector.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector.interfaces;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by rock on 16/7/4.
7 | */
8 | public interface ITagSelector {
9 |
10 | interface OnItemClickListener{
11 | void onItemClick(int position);
12 | }
13 |
14 | void setData(List list);
15 |
16 | void refresh();
17 |
18 | List getData();
19 |
20 | String getCheckedName();
21 |
22 | void setOnItemClickListener(OnItemClickListener listener);
23 |
24 | T getDataByPosition(int position);
25 |
26 | int selectedPosition();
27 |
28 | /**
29 | * item的高度,默认以itemHeight*itemCount 为动画行驶的高度
30 | * */
31 | int itemHeight();
32 | /**
33 | * 自定义动画行驶的高度
34 | * */
35 | int getAnimHeight();
36 |
37 | int getCount();
38 |
39 | void show();
40 |
41 | void hide();
42 |
43 | void setTabView(ITagSelectorTabView view);
44 |
45 |
46 | void setListAdapter(SelectorAdapter adapter);
47 | }
48 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/layout/item_tag_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
26 |
27 |
--------------------------------------------------------------------------------
/Sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
23 |
24 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/tagselector/src/main/res/layout/layout_tag_selector_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
22 |
23 |
28 |
29 |
30 |
31 |
38 |
39 |
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/interfaces/ITagSelectorTabView.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector.interfaces;
2 |
3 | import android.view.View;
4 | import android.widget.FrameLayout;
5 | import android.widget.TextView;
6 |
7 | import com.rock.android.tagselector.model.Tags;
8 |
9 | /**
10 | * Created by rock on 16/7/4.
11 | */
12 | public interface ITagSelectorTabView {
13 |
14 | interface OnStatusChangedListener {
15 | void willDismiss(ITagSelectorTabView view);
16 | void dismissed(ITagSelectorTabView view);
17 | void willOpen(ITagSelectorTabView view);
18 | void opened(ITagSelectorTabView view);
19 | }
20 |
21 | interface OnViewClickListener{
22 | void onViewClick();
23 | }
24 |
25 | void setTag(String tag);
26 |
27 | void close();
28 |
29 | void close(boolean withAnim);
30 |
31 | void open();
32 |
33 | void toggle();
34 |
35 | void setup(Tags tags, FrameLayout selectorParent, FrameLayout wrapper);
36 |
37 | void setup(Tags tags, FrameLayout selectorParent, FrameLayout wrapper,ITagSelector selectorView);
38 |
39 | TextView getTextView();
40 |
41 | boolean isOpening();
42 |
43 | boolean isChangeTagAfterClicked();
44 |
45 | void setOnViewClickListener(OnViewClickListener onViewClickListener);
46 |
47 | void setOnStatusChangedListener(OnStatusChangedListener onStatusChangedListener);
48 |
49 | View getContentView();
50 |
51 | ITagSelector getTagSelectorView();
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/tagselector/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 | ext {
5 | bintrayRepo = 'maven'
6 | bintrayName = 'tagselector'
7 |
8 | publishedGroupId = 'com.rock.android'
9 | libraryName = 'TagSelectorView'
10 | artifact = 'tagselector'
11 |
12 | libraryDescription = 'A tag selector with animation on Android'
13 |
14 | siteUrl = 'https://github.com/Rock610/TagSelectorView'
15 | gitUrl = 'https://github.com/Rock610/TagSelectorView.git'
16 |
17 | libraryVersion = '1.2.2.3'
18 |
19 | developerId = 'Rock610'
20 | developerName = 'Rock610'
21 | developerEmail = 'wang1ran@163.com'
22 |
23 | licenseName = 'GPL3.0'
24 | licenseUrl = 'https://www.gnu.org/licenses/gpl-3.0.html'
25 | allLicenses = ["GPL3.0"]
26 | }
27 |
28 | android {
29 | compileSdkVersion 23
30 | buildToolsVersion '25.0.0'
31 |
32 | defaultConfig {
33 | minSdkVersion 14
34 | targetSdkVersion 23
35 | versionCode 1
36 | versionName "1.0"
37 | }
38 | buildTypes {
39 | release {
40 | minifyEnabled false
41 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
42 | }
43 | }
44 | }
45 |
46 | dependencies {
47 | compile fileTree(dir: 'libs', include: ['*.jar'])
48 | testCompile 'junit:junit:4.12'
49 | compile 'com.android.support:appcompat-v7:23.2.1'
50 | }
51 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
52 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
--------------------------------------------------------------------------------
/Sample/src/main/java/com/rock/android/tagselectorview/CustomAdapter.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselectorview;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.TextView;
9 |
10 | import com.rock.android.tagselector.interfaces.SelectorAdapter;
11 | import com.rock.android.tagselector.model.DataBean;
12 |
13 | import java.util.List;
14 |
15 | /**
16 | * Created by rock on 16/7/5.
17 | */
18 | public class CustomAdapter extends BaseAdapter implements SelectorAdapter{
19 |
20 | private List dataBeen;
21 | private Context ctx;
22 |
23 | public CustomAdapter(List dataBeen, Context ctx) {
24 | this.dataBeen = dataBeen;
25 | this.ctx = ctx;
26 | }
27 |
28 | @Override
29 | public int getCount() {
30 | return dataBeen.size();
31 | }
32 |
33 | @Override
34 | public Object getItem(int position) {
35 | return dataBeen.get(position);
36 | }
37 |
38 | @Override
39 | public long getItemId(int position) {
40 | return position;
41 | }
42 |
43 | @Override
44 | public View getView(int position, View convertView, ViewGroup parent) {
45 | convertView = LayoutInflater.from(ctx).inflate(R.layout.item_selector,parent,false);
46 | TextView tv = (TextView) convertView.findViewById(R.id.textView);
47 | tv.setText(dataBeen.get(position).name);
48 |
49 | return convertView;
50 | }
51 |
52 | @Override
53 | public void setData(List extends DataBean> list) {
54 | dataBeen = (List) list;
55 | }
56 |
57 | @Override
58 | public List getData() {
59 | return dataBeen;
60 | }
61 |
62 | @Override
63 | public int getItemHeight() {
64 | return 40;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/views/CheckableLinearLayout.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector.views;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.Checkable;
8 | import android.widget.CompoundButton;
9 | import android.widget.LinearLayout;
10 |
11 | public class CheckableLinearLayout extends LinearLayout implements Checkable {
12 | private CompoundButton _checkbox;
13 |
14 | public CheckableLinearLayout(Context context, AttributeSet attrs) {
15 | super(context, attrs);
16 | }
17 |
18 | @Override
19 | protected void onFinishInflate() {
20 | super.onFinishInflate();
21 | // find checked text view
22 | int childCount = getChildCount();
23 | for (int i = 0; i < childCount; ++i) {
24 | View v = getChildAt(i);
25 |
26 | if (v instanceof CompoundButton) {
27 | _checkbox = (CompoundButton)v;
28 | return;
29 | }
30 | if(v instanceof ViewGroup){
31 | ViewGroup viewGroup = (ViewGroup) v;
32 | for (int i1 = 0; i1 < viewGroup.getChildCount(); i1++) {
33 | View child = viewGroup.getChildAt(i1);
34 | if (child instanceof CompoundButton) {
35 | _checkbox = (CompoundButton)child;
36 | return;
37 | }
38 | }
39 | }
40 |
41 | }
42 | }
43 |
44 | @Override
45 | public boolean isChecked() {
46 | return _checkbox != null && _checkbox.isChecked();
47 | }
48 |
49 | @Override
50 | public void setChecked(boolean checked) {
51 | if (_checkbox != null) {
52 | _checkbox.setChecked(checked);
53 | }
54 | }
55 |
56 | @Override
57 | public void toggle() {
58 | if (_checkbox != null) {
59 | _checkbox.toggle();
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/model/Tags.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector.model;
2 |
3 | import com.rock.android.tagselector.interfaces.ITagSelector;
4 |
5 | import java.io.Serializable;
6 | import java.util.List;
7 |
8 | /**
9 | * Created by rock on 16/7/4.
10 | */
11 | public class Tags implements Serializable{
12 |
13 | private static final long serialVersionUID = -1371154113061363482L;
14 | public List extends DataBean> tags;
15 |
16 | public String defaultTag;
17 |
18 | public boolean isSelectFirst;
19 |
20 | public boolean isChangeAfterClicked;
21 |
22 | public int layoutRes;
23 |
24 | public int textViewId;
25 |
26 | public ITagSelector selector;
27 |
28 | public Tags(List extends DataBean> tags, String defaultTag, boolean isSelectFirst, boolean isChangeAfterClicked) {
29 | this.tags = tags;
30 | this.defaultTag = defaultTag;
31 | this.isSelectFirst = isSelectFirst;
32 | this.isChangeAfterClicked = isChangeAfterClicked;
33 | }
34 |
35 | public Tags() {
36 | }
37 |
38 | public Tags setSelector(ITagSelector selector) {
39 | this.selector = selector;
40 | return this;
41 | }
42 |
43 | public Tags setTags(List extends DataBean> tags) {
44 | this.tags = tags;
45 | return this;
46 | }
47 |
48 | public Tags setDefaultTag(String defaultTag) {
49 | this.defaultTag = defaultTag;
50 | return this;
51 | }
52 |
53 | public Tags setSelectFirst(boolean selectFirst) {
54 | isSelectFirst = selectFirst;
55 | return this;
56 | }
57 |
58 | public Tags setChangeAfterClicked(boolean changeAfterClicked) {
59 | isChangeAfterClicked = changeAfterClicked;
60 | return this;
61 | }
62 |
63 | public Tags setLayoutRes(int layoutRes) {
64 | this.layoutRes = layoutRes;
65 | return this;
66 | }
67 |
68 | public Tags setTextViewId(int textViewId) {
69 | this.textViewId = textViewId;
70 | return this;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/views/BaseSelectorAdapter.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector.views;
2 |
3 | import android.app.Activity;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.RadioButton;
9 | import android.widget.TextView;
10 |
11 | import com.rock.android.tagselector.R;
12 |
13 | import java.util.List;
14 |
15 | /**
16 | * Created by rock on 16/7/4.
17 | */
18 | public class BaseSelectorAdapter extends BaseAdapter{
19 |
20 | protected List mList;
21 | protected Activity mContext;
22 |
23 | public BaseSelectorAdapter(List mList, Activity mContext) {
24 | this.mList = mList;
25 | this.mContext = mContext;
26 | }
27 |
28 | public BaseSelectorAdapter(Activity mContext) {
29 | this(null,mContext);
30 | }
31 |
32 | @Override
33 | public int getCount() {
34 | return mList == null ? 0: mList.size();
35 | }
36 |
37 | public void addAll(List list){
38 | if(mList == null){
39 | mList = list;
40 | }else{
41 | mList.addAll(list);
42 | }
43 |
44 | notifyDataSetChanged();
45 | }
46 |
47 | public void clear(){
48 | if(mList == null) return;
49 |
50 | mList.clear();
51 | notifyDataSetChanged();
52 | }
53 |
54 | @Override
55 | public Object getItem(int position) {
56 | return mList == null ? null:mList.get(position);
57 | }
58 |
59 | @Override
60 | public long getItemId(int position) {
61 | return position;
62 | }
63 |
64 | @Override
65 | public View getView(int position, View convertView, ViewGroup parent) {
66 |
67 | ViewHolder holder;
68 | if(convertView == null){
69 | convertView = LayoutInflater.from(mContext).inflate(R.layout.item_tag_selector,parent,false);
70 | holder = new ViewHolder();
71 | holder.text = (TextView) convertView.findViewById(R.id.tagNameTv);
72 | holder.radioButton = (RadioButton) convertView.findViewById(R.id.selectRB);
73 | convertView.setTag(holder);
74 | }else{
75 | holder = (ViewHolder) convertView.getTag();
76 | }
77 | bindData(holder,position,convertView,parent);
78 |
79 | return convertView;
80 | }
81 |
82 | protected void bindData(ViewHolder holder,int position, View convertView, ViewGroup parent){
83 |
84 | }
85 |
86 | public class ViewHolder{
87 | TextView text;
88 | RadioButton radioButton;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.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.7
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TagSelectorView
2 | TagSelectorView
3 |
4 | A tag selector with animation
5 |
6 | # [已更新v2.0](https://github.com/Rock610/TagSelectorView/tree/v2.0)
7 | # 注意2.0与1.0并不兼容,2.0之前最后版本号为 1.2.2.3
8 |
9 | [](https://bintray.com/rock610/maven/tagselector/_latestVersion)
10 | [](http://www.jianshu.com/users/55ddc6ee39e8/latest_articles)
11 |
12 |
13 | be free to contact me by the blog above or email _wang1ran@163.com_
14 |
15 |
16 | 
17 |
18 |
19 | #Setup
20 |
21 | ```
22 | repositories {
23 | jcenter()
24 | }
25 |
26 | dependencies {
27 | compile 'com.rock.android:tagselector:xxx'//version code
28 | }
29 | ```
30 |
31 | #Usage
32 |
33 | - in xml
34 | ```
35 |
39 | ```
40 |
41 | - in your activity
42 | ```
43 | TagSelectView tagSelectView = (TagSelectView) findViewById(R.id.tagSelectView);
44 |
45 | List dataList = new ArrayList<>();
46 |
47 | int count = 2;
48 | List dataBeanList = new ArrayList<>();
49 | for (int i = 0; i < count; i++) {
50 | dataBeanList.add(new MyDataBean("item A" + i));
51 | }
52 |
53 | dataList.add(new Tags().
54 | setDefaultTag(dataBeanList.get(0).name)
55 | .setTags(dataBeanList)
56 | .setChangeAfterClicked(true)
57 | .setSelectFirst(false);
58 | tagSelectView.attach(dataList);
59 | ```
60 | data source must extend the DataBean
61 | - to insert a data to any tab
62 | ```
63 | ITagSelectorTabView tagSelectorView = tagSelectView.getTabView(0).getTagSelectorView();
64 | tagSelectorView.getData().add(0, new MyDataBean("im new"));
65 | tagSelectorView.refresh();
66 | ```
67 |
68 | - get the selected tag
69 | ```
70 | tagSelectView.setOnTagSelectedListener(new TagSelectView.OnTagSelectedListener() {
71 | @Override
72 | public void onTagSelected(int selectorListPosition, int tabPosition) {
73 | DataBean dataBean = dataList.get(tabPosition).tags.get(selectorListPosition);
74 | MyDataBean d = (MyDataBean) dataBean;
75 | //do something like request the network
76 |
77 | }
78 | });
79 |
80 | ```
81 |
82 | - listening the tab
83 | ```
84 | tagSelectView.setOnTagViewStatusChangedListener(new TagSelectView.OnTagViewStatusChangedListener() {
85 | @Override
86 | public void onOpened(ITagSelectorTabView openedView) {
87 |
88 | }
89 |
90 | @Override
91 | public void onClosed(ITagSelectorTabView closedView) {
92 |
93 | }
94 | });
95 |
96 | ```
97 |
98 | #License
99 | [https://www.gnu.org/licenses/licenses.html](https://www.gnu.org/licenses/licenses.html)
100 |
101 |
102 |
--------------------------------------------------------------------------------
/Sample/src/main/java/com/rock/android/tagselectorview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselectorview;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.FrameLayout;
8 | import android.widget.TextView;
9 |
10 | import com.rock.android.tagselector.LogUtil;
11 | import com.rock.android.tagselector.interfaces.ITagSelector;
12 | import com.rock.android.tagselector.interfaces.ITagSelectorTabView;
13 | import com.rock.android.tagselector.model.DataBean;
14 | import com.rock.android.tagselector.model.Tags;
15 | import com.rock.android.tagselector.views.TagSelectView;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | public class MainActivity extends AppCompatActivity {
21 |
22 |
23 | private TagSelectView tagSelectView;
24 | private List dataList;
25 | private ITagSelector tagSelectorView;
26 | private TextView firstTabTv;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_main);
32 | tagSelectView = (TagSelectView) findViewById(R.id.tagSelectView);
33 |
34 | tagSelectView.setOnTagViewStatusChangedListener(new TagSelectView.OnTagViewStatusChangedListener() {
35 | @Override
36 | public void onOpened(ITagSelectorTabView openedView) {
37 | TextView textView = openedView.getTextView();
38 | if(textView == firstTabTv){
39 | textView.setTextColor(Color.YELLOW);
40 | }else{
41 | textView.setTextColor(Color.BLUE);
42 | }
43 | }
44 |
45 | @Override
46 | public void onClosed(ITagSelectorTabView closedView) {
47 | TextView textView = closedView.getTextView();
48 | if(textView == firstTabTv){
49 | textView.setTextColor(Color.CYAN);
50 | }else{
51 | textView.setTextColor(Color.BLACK);
52 | }
53 |
54 | }
55 | });
56 |
57 | tagSelectView.setOnTagSelectedListener(new TagSelectView.OnTagSelectedListener() {
58 | @Override
59 | public void onTagSelected(int selectorListPosition, int tabPosition) {
60 | LogUtil.e("onTagSelected", "selected==" + selectorListPosition + "===tab===" + tabPosition);
61 |
62 | DataBean dataBean = dataList.get(tabPosition).tags.get(selectorListPosition);
63 | MyDataBean d = (MyDataBean) dataBean;
64 | LogUtil.e("onTagSelected", "data name===" + d.name);
65 |
66 | DataBean dataBean1 = (DataBean) tagSelectView.getTabView(tabPosition).getTagSelectorView().getData().get(selectorListPosition);
67 | LogUtil.e("onTagSelected", "data1 name===" + dataBean1.name);
68 | //do something like request the network
69 |
70 | }
71 | });
72 | initData();
73 |
74 | }
75 |
76 | private void initData() {
77 | dataList = new ArrayList<>();
78 |
79 | int count = 2;
80 | List dataBeanList = new ArrayList<>();
81 | for (int i = 0; i < count; i++) {
82 | dataBeanList.add(new MyDataBean("item A" + i));
83 | }
84 |
85 | dataList.add(new Tags().
86 | setDefaultTag(dataBeanList.get(0).name)
87 | .setTags(dataBeanList)
88 | .setChangeAfterClicked(true)
89 | .setSelectFirst(false)
90 | .setLayoutRes(R.layout.layout_tab_0)
91 | .setTextViewId(R.id.theTextView));
92 |
93 |
94 |
95 | List dataBeanList1 = new ArrayList<>();
96 | for (int i = 0; i < count; i++) {
97 | dataBeanList1.add(new MyDataBean("item B" + i));
98 | }
99 |
100 | dataList.add(new Tags(dataBeanList1, dataBeanList1.get(0).name, false, true));
101 |
102 |
103 | int countc = 10;
104 | List dataBeanList2 = new ArrayList<>();
105 | for (int i = 0; i < countc; i++) {
106 | dataBeanList2.add(new MyDataBean("item C" + i));
107 | }
108 |
109 | dataList.add(new Tags(dataBeanList2, dataBeanList2.get(0).name, false, true));
110 |
111 | tagSelectView.attach(dataList);
112 | tagSelectView.setWrapperHeight(FrameLayout.LayoutParams.MATCH_PARENT);
113 |
114 | //pass a custom adapter to a selector
115 | tagSelectorView = tagSelectView.getTabView(0).getTagSelectorView();
116 | tagSelectorView.setListAdapter(new CustomAdapter(dataBeanList, this));
117 |
118 |
119 | firstTabTv = (TextView) findViewById(R.id.theTextView);
120 |
121 | }
122 |
123 | public void onClickAddData(View v){
124 | //insert a data
125 | tagSelectView.getTabView(1).getTagSelectorView().getData().add(0, new MyDataBean("im new"));
126 | tagSelectView.getTabView(1).getTagSelectorView().refresh();
127 |
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/views/SimpleSingleSelectListView.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector.views;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Color;
6 | import android.support.annotation.NonNull;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.AdapterView;
11 | import android.widget.ListAdapter;
12 | import android.widget.ListView;
13 |
14 | import com.rock.android.tagselector.R;
15 | import com.rock.android.tagselector.interfaces.ITagSelector;
16 | import com.rock.android.tagselector.interfaces.ITagSelectorTabView;
17 | import com.rock.android.tagselector.interfaces.SelectorAdapter;
18 | import com.rock.android.tagselector.model.DataBean;
19 |
20 | import java.util.List;
21 |
22 | /**
23 | * Created by rock on 16/7/4.
24 | */
25 | public class SimpleSingleSelectListView extends ListView implements ITagSelector {
26 |
27 | // private List mListData;
28 | private SelectorAdapter mAdapter;
29 |
30 | private ITagSelectorTabView tabView;
31 |
32 | private ITagSelector.OnItemClickListener onItemClickListener;
33 |
34 | @Override
35 | public void setOnItemClickListener(ITagSelector.OnItemClickListener onItemClickListener) {
36 | this.onItemClickListener = onItemClickListener;
37 | }
38 |
39 | public SimpleSingleSelectListView(Context context) {
40 | super(context);
41 | init();
42 | }
43 |
44 | public SimpleSingleSelectListView(Context context, AttributeSet attrs) {
45 | super(context, attrs);
46 | init();
47 | }
48 |
49 | public SimpleSingleSelectListView(Context context, AttributeSet attrs, int defStyleAttr) {
50 | super(context, attrs, defStyleAttr);
51 | init();
52 | }
53 |
54 | private void init() {
55 | if (isInEditMode()) return;
56 |
57 | setBackgroundColor(Color.WHITE);
58 | setChoiceMode(CHOICE_MODE_SINGLE);
59 | setDividerHeight(1);
60 | setDivider(getResources().getDrawable(R.drawable.horizontal_line));
61 | mAdapter = new SimpleAdapter((Activity) getContext());
62 | setAdapter((SimpleAdapter) mAdapter);
63 |
64 | setOnItemClickListener(new AdapterView.OnItemClickListener() {
65 | @Override
66 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
67 | if(tabView.isChangeTagAfterClicked()){
68 | tabView.setTag(mAdapter.getData().get(position).name);
69 | }
70 |
71 | if(onItemClickListener != null){
72 | onItemClickListener.onItemClick(position);
73 | }
74 | }
75 | });
76 |
77 | setVisibility(View.GONE);
78 | }
79 |
80 | @Override
81 | public void setData(@NonNull List list) {
82 |
83 | setItemChecked(INVALID_POSITION,true);
84 | mAdapter.setData(list);
85 | mAdapter.notifyDataSetChanged();
86 |
87 | }
88 |
89 | @Override
90 | public void refresh() {
91 | mAdapter.notifyDataSetChanged();
92 | }
93 |
94 | @Override
95 | public List getData() {
96 | return (List) mAdapter.getData();
97 | }
98 |
99 | @Override
100 | public String getCheckedName() {
101 |
102 | if (getCheckedItemPosition() != INVALID_POSITION) {
103 | return mAdapter.getData().get(getCheckedItemPosition()).name;
104 | }
105 | return "";
106 | }
107 |
108 | @Override
109 | public DataBean getDataByPosition(int position) {
110 | return mAdapter.getData().get(position);
111 | }
112 |
113 | @Override
114 | public int selectedPosition() {
115 | return getCheckedItemPosition();
116 | }
117 |
118 | @Override
119 | public int itemHeight() {
120 | return mAdapter.getItemHeight();
121 | }
122 |
123 | @Override
124 | public int getAnimHeight() {
125 | return 250;
126 | }
127 |
128 | @Override
129 | public void show() {
130 | setVisibility(View.VISIBLE);
131 | }
132 |
133 | @Override
134 | public void hide() {
135 | setVisibility(View.GONE);
136 | }
137 |
138 | @Override
139 | public void setTabView(ITagSelectorTabView view) {
140 | tabView = view;
141 | }
142 |
143 | /**
144 | * to set a custom Adapter to the listView,
145 | *
146 | * you must implement SelectorAdapter and extends ListAdapter
147 | *
148 | * */
149 | @Override
150 | public void setListAdapter(SelectorAdapter adapter) {
151 | setAdapter((ListAdapter) adapter);
152 | mAdapter = adapter;
153 | }
154 |
155 | class SimpleAdapter extends BaseSelectorAdapter implements SelectorAdapter{
156 |
157 | public SimpleAdapter(List mList, Activity mContext) {
158 | super(mList, mContext);
159 | }
160 |
161 | public SimpleAdapter(Activity mContext) {
162 | super(mContext);
163 | }
164 |
165 | @Override
166 | protected void bindData(ViewHolder holder, int position, View convertView, ViewGroup parent) {
167 | super.bindData(holder, position, convertView, parent);
168 |
169 | holder.text.setText(mList.get(position).name);
170 | }
171 |
172 | @Override
173 | public void setData(List extends DataBean> list) {
174 | if(mList == null){
175 | mList = (List) list;
176 | }else{
177 | mList.clear();
178 | mList.addAll(list);
179 | }
180 | }
181 |
182 | @Override
183 | public List getData() {
184 | return mList;
185 | }
186 |
187 | @Override
188 | public int getItemHeight() {
189 | return 50;
190 | }
191 | }
192 |
193 | }
194 |
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/views/TagSelectorTabTabView.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector.views;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.Gravity;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.view.animation.Animation;
10 | import android.view.animation.AnimationUtils;
11 | import android.widget.FrameLayout;
12 | import android.widget.RelativeLayout;
13 | import android.widget.TextView;
14 |
15 | import com.rock.android.tagselector.LogUtil;
16 | import com.rock.android.tagselector.R;
17 | import com.rock.android.tagselector.interfaces.ITagSelector;
18 | import com.rock.android.tagselector.interfaces.ITagSelectorTabView;
19 | import com.rock.android.tagselector.model.Tags;
20 |
21 | /**
22 | * Created by rock on 16/7/4.
23 | */
24 | public class TagSelectorTabTabView extends RelativeLayout implements ITagSelectorTabView {
25 |
26 | protected TextView mTextView;
27 | protected FrameLayout mWrapper;
28 | protected FrameLayout selectorParent;
29 |
30 | protected boolean isOpening;
31 |
32 | protected Tags mTags;
33 |
34 | private OnStatusChangedListener onStatusChangedListener;
35 | private OnViewClickListener onViewClickListener;
36 |
37 | private View contentView;
38 | private ITagSelector selectorView;
39 |
40 | @Override
41 | public void setOnViewClickListener(OnViewClickListener onViewClickListener) {
42 | this.onViewClickListener = onViewClickListener;
43 | }
44 |
45 | @Override
46 | public void setOnStatusChangedListener(OnStatusChangedListener onStatusChangedListener) {
47 | this.onStatusChangedListener = onStatusChangedListener;
48 | }
49 |
50 | @Override
51 | public View getContentView() {
52 | return contentView;
53 | }
54 |
55 | @Override
56 | public ITagSelector getTagSelectorView() {
57 | return selectorView;
58 | }
59 |
60 | public TagSelectorTabTabView(Context context) {
61 | super(context);
62 | init();
63 | }
64 |
65 | public TagSelectorTabTabView(Context context, AttributeSet attrs) {
66 | super(context, attrs);
67 | init();
68 | }
69 |
70 | public TagSelectorTabTabView(Context context, AttributeSet attrs, int defStyleAttr) {
71 | super(context, attrs, defStyleAttr);
72 | init();
73 | }
74 |
75 | private void init() {
76 |
77 |
78 | setOnClickListener(new OnClickListener() {
79 | @Override
80 | public void onClick(View v) {
81 | LogUtil.e(getTagText(), "clicked");
82 | toggle();
83 |
84 | if (onViewClickListener != null) {
85 | onViewClickListener.onViewClick();
86 | }
87 |
88 | }
89 | });
90 | }
91 |
92 | private String getTagText() {
93 | return mTextView.getText().toString();
94 | }
95 |
96 | @Override
97 | public void setTag(String tag) {
98 | mTextView.setText(tag);
99 | }
100 |
101 | @Override
102 | public void close() {
103 | close(true);
104 | }
105 |
106 | @Override
107 | public void close(boolean withAnim) {
108 | if (onStatusChangedListener != null) {
109 | onStatusChangedListener.willDismiss(this);
110 | }
111 |
112 | mWrapper.clearAnimation();
113 |
114 | if (!isOpening) return;
115 |
116 | if (!withAnim) {
117 | afterClose();
118 | return;
119 | }
120 |
121 | Animation ta = AnimationUtils.loadAnimation(getContext(), R.anim.ts_content_out);
122 | mWrapper.startAnimation(ta);
123 |
124 | //代替动画监听,因为有时会不响应listener
125 | postDelayed(new Runnable() {
126 | @Override
127 | public void run() {
128 | afterClose();
129 | }
130 | }, ta.getDuration());
131 | }
132 |
133 | private void afterClose() {
134 | isOpening = false;
135 | selectorView.hide();
136 | if (selectorParent != null && selectorParent.getVisibility() != View.GONE) {
137 | selectorParent.setVisibility(View.GONE);
138 | }
139 | if (onStatusChangedListener != null) {
140 | onStatusChangedListener.dismissed(TagSelectorTabTabView.this);
141 | }
142 | }
143 |
144 | @Override
145 | public void open() {
146 |
147 | if (onStatusChangedListener != null) {
148 | onStatusChangedListener.willOpen(this);
149 | }
150 | mWrapper.clearAnimation();
151 | if (isOpening) return;
152 |
153 | if (selectorParent != null && selectorParent.getVisibility() != View.VISIBLE) {
154 | selectorParent.setVisibility(View.VISIBLE);
155 | }
156 | Animation ta = AnimationUtils.loadAnimation(getContext(), R.anim.ts_content_in);
157 | mWrapper.startAnimation(ta);
158 | selectorView.show();
159 | isOpening = true;
160 | if (onStatusChangedListener != null) {
161 | onStatusChangedListener.opened(this);
162 | }
163 | }
164 |
165 | @Override
166 | public void toggle() {
167 | if (isOpening) {
168 | close();
169 | } else {
170 | open();
171 | }
172 | }
173 |
174 | @Override
175 | public void setup(Tags tags, FrameLayout selectorParent, FrameLayout wrapper) {
176 | setup(tags,selectorParent,wrapper,null);
177 | }
178 |
179 | @Override
180 | public void setup(Tags tags, FrameLayout selectorParent, FrameLayout wrapper,ITagSelector selectorView){
181 |
182 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
183 | try {
184 | View view = newTagView(tags.layoutRes, tags.textViewId);
185 | contentView = view;
186 | addView(view, params);
187 | } catch (Exception e) {
188 | e.printStackTrace();
189 | }
190 |
191 | mWrapper = wrapper;
192 | this.selectorParent = selectorParent;
193 | mTags = tags;
194 | if(selectorView != null){
195 | this.selectorView = selectorView;
196 | wrapper.addView((View) selectorView);
197 | }else{
198 | setDefaultSelector(wrapper);
199 | }
200 |
201 | this.selectorView.setTabView(this);
202 | this.selectorView.setData(tags.tags);
203 | setTag(tags.defaultTag);
204 |
205 | }
206 |
207 | private void setDefaultSelector(FrameLayout wrapper){
208 | selectorView = new SimpleSingleSelectListView(getContext());
209 |
210 | FrameLayout.LayoutParams paramsList = new FrameLayout.LayoutParams(
211 | ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
212 | wrapper.addView((View) selectorView, paramsList);
213 |
214 | }
215 |
216 | @Override
217 | public TextView getTextView() {
218 | return mTextView;
219 | }
220 |
221 | @Override
222 | public boolean isOpening() {
223 | return isOpening;
224 | }
225 |
226 | @Override
227 | public boolean isChangeTagAfterClicked() {
228 | return mTags.isChangeAfterClicked;
229 | }
230 |
231 | /**
232 | * 包装一个内部view,这里直接以TextView为例
233 | * 必须给mTextView赋值
234 | */
235 | protected View newTagView (int res,int textViewid) throws Exception {
236 | if(res != 0){
237 | View view = LayoutInflater.from(getContext()).inflate(res,null);
238 | if(view == null){
239 | throw new RuntimeException("can not inflate view by id==="+res);
240 | }
241 | if(textViewid != 0){
242 | mTextView = (TextView) view.findViewById(textViewid);
243 | }
244 |
245 | if(mTextView == null){
246 | throw new RuntimeException("can not find TextView by id==="+textViewid);
247 | }
248 | return view;
249 | }
250 |
251 | RelativeLayout layout = new RelativeLayout(getContext());
252 | RelativeLayout.LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
253 | params.addRule(RelativeLayout.CENTER_IN_PARENT);
254 | TextView tv = new TextView(getContext());
255 | mTextView = tv;
256 | tv.setCompoundDrawablesWithIntrinsicBounds(0,0, R.drawable.arrow_bottom,0);
257 | tv.setGravity(Gravity.CENTER);
258 |
259 | layout.addView(tv,params);
260 | return layout;
261 | }
262 | }
263 |
--------------------------------------------------------------------------------
/tagselector/src/main/java/com/rock/android/tagselector/views/TagSelectView.java:
--------------------------------------------------------------------------------
1 | package com.rock.android.tagselector.views;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.drawable.Drawable;
6 | import android.util.AttributeSet;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.FrameLayout;
11 | import android.widget.LinearLayout;
12 |
13 | import com.rock.android.tagselector.R;
14 | import com.rock.android.tagselector.Utils;
15 | import com.rock.android.tagselector.interfaces.ITagSelector;
16 | import com.rock.android.tagselector.interfaces.ITagSelectorTabView;
17 | import com.rock.android.tagselector.model.Tags;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * Created by rock on 16/7/4.
24 | */
25 | public class TagSelectView extends FrameLayout {
26 |
27 | public static final int DEFAULT_WRAPPER_HEIGHT = 250;//默认wrapper高度
28 | private LinearLayout mTabWrapperLayout;
29 | private FrameLayout listContentLayout;
30 | private FrameLayout wrapperLayout;
31 | private List mTabSelectViews = new ArrayList<>();
32 |
33 | private ITagSelectorTabView lastOpenedTab;
34 |
35 | private OnTagViewStatusChangedListener onTagViewStatusChangedListener;
36 |
37 | private OnTagSelectedListener onTagSelectedListener;
38 |
39 | protected int tabHeight;
40 |
41 | protected int bottomLineColor;
42 |
43 | protected Drawable dividerDrawable;
44 |
45 | protected int wrapperHeight;
46 |
47 | protected int tabTextColor;
48 | private View bottomLine;
49 |
50 | public TagSelectView setOnTagSelectedListener(OnTagSelectedListener onTagSelectedListener) {
51 | this.onTagSelectedListener = onTagSelectedListener;
52 | return this;
53 | }
54 |
55 | public TagSelectView setOnTagViewStatusChangedListener(OnTagViewStatusChangedListener onTagViewStatusChangedListener) {
56 | this.onTagViewStatusChangedListener = onTagViewStatusChangedListener;
57 | return this;
58 | }
59 |
60 | public interface OnTagSelectedListener{
61 | void onTagSelected(int selectorListPosition,int tabPosition);
62 | }
63 |
64 | public interface OnTagViewStatusChangedListener{
65 | void onOpened(ITagSelectorTabView openedView);
66 |
67 | void onClosed(ITagSelectorTabView closedView);
68 | }
69 |
70 | public TagSelectView(Context context) {
71 | super(context);
72 | init(null);
73 | }
74 |
75 | public TagSelectView(Context context, AttributeSet attrs) {
76 | super(context, attrs);
77 | init(attrs);
78 | }
79 |
80 | public TagSelectView(Context context, AttributeSet attrs, int defStyleAttr) {
81 | super(context, attrs, defStyleAttr);
82 | init(attrs);
83 | }
84 |
85 | private void init(AttributeSet attrs) {
86 |
87 | if(attrs != null){
88 | TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs,R.styleable.TagSelectView,0,0);
89 | tabHeight = a.getDimensionPixelSize(R.styleable.TagSelectView_tabHeight,0);
90 | bottomLineColor = a.getColor(R.styleable.TagSelectView_tabBottomLineColor,getResources().getColor(R.color.lineColor));
91 | dividerDrawable = a.getDrawable(R.styleable.TagSelectView_tabDivider);
92 | wrapperHeight = a.getDimensionPixelSize(R.styleable.TagSelectView_wrapperHeight, Utils.dp2px(getContext(),DEFAULT_WRAPPER_HEIGHT));
93 | tabTextColor = a.getColor(R.styleable.TagSelectView_selectorTabTextColor,getResources().getColor(R.color.defaultTabTextColor));
94 | a.recycle();
95 | }
96 |
97 | LayoutInflater.from(getContext()).inflate(R.layout.layout_tag_selector_view, this);
98 |
99 | bottomLine = findViewById(R.id.bottomLine);
100 | FrameLayout.LayoutParams paramsLine = (LayoutParams) bottomLine.getLayoutParams();
101 | paramsLine.topMargin = tabHeight;
102 |
103 | setBottomLineColor(bottomLineColor);
104 |
105 |
106 | mTabWrapperLayout = (LinearLayout) findViewById(R.id.tabViewWrapperLayout);
107 |
108 | setDividerDrawable(dividerDrawable);
109 | mTabWrapperLayout.getLayoutParams().height = tabHeight;
110 |
111 | listContentLayout = (FrameLayout) findViewById(R.id.listContentLayout);
112 | setTabHeight(tabHeight);
113 |
114 | wrapperLayout = (FrameLayout) findViewById(R.id.wrapperLayout);
115 | setWrapperHeight(wrapperHeight);
116 |
117 | listContentLayout.setOnClickListener(new OnClickListener() {
118 | @Override
119 | public void onClick(View v) {
120 | if(lastOpenedTab != null){
121 | lastOpenedTab.close();
122 | }
123 | }
124 | });
125 |
126 | listContentLayout.setVisibility(View.GONE);
127 |
128 | }
129 |
130 | public TagSelectView setTabHeight(int tabHeight) {
131 | this.tabHeight = tabHeight;
132 | FrameLayout.LayoutParams params = (LayoutParams) listContentLayout.getLayoutParams();
133 | params.topMargin = tabHeight;
134 | return this;
135 | }
136 |
137 | public TagSelectView setBottomLineColor(int bottomLineColor) {
138 | this.bottomLineColor = bottomLineColor;
139 | bottomLine.setBackgroundColor(bottomLineColor);
140 | return this;
141 | }
142 |
143 | public TagSelectView setDividerDrawable(Drawable dividerDrawable) {
144 | this.dividerDrawable = dividerDrawable;
145 | mTabWrapperLayout.setDividerDrawable(dividerDrawable);
146 | return this;
147 | }
148 |
149 | public TagSelectView setWrapperHeight(int wrapperHeight) {
150 | this.wrapperHeight = wrapperHeight;
151 | wrapperLayout.getLayoutParams().height = wrapperHeight;
152 | return this;
153 | }
154 |
155 | public TagSelectView setTabTextColor(int tabTextColor) {
156 | this.tabTextColor = tabTextColor;
157 | for (ITagSelectorTabView mTabSelectView : mTabSelectViews) {
158 | mTabSelectView.getTextView().setTextColor(tabTextColor);
159 | }
160 | return this;
161 | }
162 |
163 | public void attach(List tagsList) {
164 | if (tagsList == null) return;
165 |
166 | LinearLayout.LayoutParams tabParams =
167 | new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1);
168 |
169 | for (int i = 0; i < tagsList.size(); i++) {
170 | Tags tags = tagsList.get(i);
171 | mTabWrapperLayout.addView((View) newTabView(i,tags), tabParams);
172 | }
173 | }
174 |
175 | protected ITagSelectorTabView newTabView(final int tabPosition, Tags tags) {
176 | final ITagSelectorTabView tabView = new TagSelectorTabTabView(getContext());
177 | if(tags.selector != null){
178 | tabView.setup(tags, listContentLayout, wrapperLayout,tags.selector);
179 | }else{
180 | tabView.setup(tags, listContentLayout, wrapperLayout);
181 | }
182 | tabView.getTextView().setTextColor(tabTextColor);
183 |
184 | tabView.setOnStatusChangedListener(new ITagSelectorTabView.OnStatusChangedListener() {
185 | @Override
186 | public void willDismiss(ITagSelectorTabView view) {
187 | }
188 |
189 | @Override
190 | public void dismissed(ITagSelectorTabView view) {
191 | if(onTagViewStatusChangedListener != null){
192 | onTagViewStatusChangedListener.onClosed(view);
193 | }
194 |
195 | view.getTextView().setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.arrow_bottom,0);
196 | }
197 |
198 | @Override
199 | public void willOpen(ITagSelectorTabView view) {
200 |
201 | if(lastOpenedTab != null && lastOpenedTab != view){
202 | lastOpenedTab.close(false);
203 | }
204 |
205 | }
206 |
207 | @Override
208 | public void opened(ITagSelectorTabView view) {
209 | lastOpenedTab = view;
210 | if(onTagViewStatusChangedListener != null){
211 | onTagViewStatusChangedListener.onOpened(view);
212 | }
213 |
214 | view.getTextView().setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.arrow_top,0);
215 | }
216 | });
217 |
218 | tabView.getTagSelectorView().setOnItemClickListener(new ITagSelector.OnItemClickListener() {
219 | @Override
220 | public void onItemClick(int position) {
221 |
222 | tabView.close();
223 | if(onTagSelectedListener != null){
224 | onTagSelectedListener.onTagSelected(position,tabPosition);
225 | }
226 | }
227 | });
228 |
229 | mTabSelectViews.add(tabView);
230 |
231 | return tabView;
232 | }
233 |
234 | public ITagSelectorTabView getTabView(int position) {
235 | return mTabSelectViews.get(position);
236 | }
237 |
238 | public void dismissAll(){
239 | if(lastOpenedTab != null){
240 | lastOpenedTab.close();
241 | }
242 | }
243 |
244 | public boolean isShowing(){
245 | return lastOpenedTab != null && lastOpenedTab.isOpening();
246 | }
247 |
248 | }
249 |
--------------------------------------------------------------------------------