├── samples
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── arrays.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_menu_myplaces.png
│ │ │ │ ├── ic_menu_emoticons.png
│ │ │ │ ├── ic_menu_friendslist.png
│ │ │ │ ├── ic_menu_start_conversation.png
│ │ │ │ ├── skin_tab_icon_contact_normal.png
│ │ │ │ ├── skin_tab_icon_plugin_normal.png
│ │ │ │ ├── skin_tab_icon_contact_selected.png
│ │ │ │ ├── skin_tab_icon_plugin_selected.png
│ │ │ │ ├── skin_tab_icon_conversation_normal.png
│ │ │ │ └── skin_tab_icon_conversation_selected.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable
│ │ │ │ └── tabbg.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_tab_indicator.xml
│ │ │ │ ├── activity_tabpage_indicator.xml
│ │ │ │ └── activity_tabpage_indicator_ex.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── kevin
│ │ │ └── tabindicator
│ │ │ └── samples
│ │ │ ├── TabFragment.java
│ │ │ ├── LauncherActivity.java
│ │ │ ├── TabIndicatorActivity.java
│ │ │ ├── TabPageIndicatorActivity.java
│ │ │ └── TabPageIndicatorExActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── kevin
│ │ │ └── tabindicator
│ │ │ └── samples
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── kevin
│ │ └── tabindicator
│ │ └── samples
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── tabindicator
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ └── update_hint.png
│ │ │ └── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── attrs.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── kevin
│ │ │ └── tabindicator
│ │ │ ├── internal
│ │ │ ├── ITabView.java
│ │ │ ├── TabPageIndicatorBase.java
│ │ │ ├── TabViewBase.java
│ │ │ └── TabIndicatorBase.java
│ │ │ ├── TabPageIndicatorEx.java
│ │ │ ├── TabIndicator.java
│ │ │ ├── TabPageIndicator.java
│ │ │ ├── TabView.java
│ │ │ ├── TabPageViewEx.java
│ │ │ └── TabPageView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── kevin
│ │ │ └── tabindicator
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── kevin
│ │ └── tabindicator
│ │ └── ApplicationTest.java
├── project.properties
├── build.gradle
├── proguard-rules.pro
└── bintrayUpload.gradle
├── settings.gradle
├── tab_indicator_sample.gif
├── tab_page_indicator_sample.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── tab_page_indicator_ex_sample.gif
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README-zh.md
├── README.md
└── gradlew
/samples/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tabindicator/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':tabindicator', ':samples'
2 |
--------------------------------------------------------------------------------
/tab_indicator_sample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/tab_indicator_sample.gif
--------------------------------------------------------------------------------
/samples/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Samples
3 |
4 |
--------------------------------------------------------------------------------
/tab_page_indicator_sample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/tab_page_indicator_sample.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/tab_page_indicator_ex_sample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/tab_page_indicator_ex_sample.gif
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/tabindicator/src/main/res/drawable/update_hint.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/tabindicator/src/main/res/drawable/update_hint.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-hdpi/ic_menu_myplaces.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-hdpi/ic_menu_myplaces.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-hdpi/ic_menu_emoticons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-hdpi/ic_menu_emoticons.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-hdpi/ic_menu_friendslist.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-hdpi/ic_menu_friendslist.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-hdpi/ic_menu_start_conversation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-hdpi/ic_menu_start_conversation.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-hdpi/skin_tab_icon_contact_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-hdpi/skin_tab_icon_contact_normal.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-hdpi/skin_tab_icon_plugin_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-hdpi/skin_tab_icon_plugin_normal.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-hdpi/skin_tab_icon_contact_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-hdpi/skin_tab_icon_contact_selected.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-hdpi/skin_tab_icon_plugin_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-hdpi/skin_tab_icon_plugin_selected.png
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-hdpi/skin_tab_icon_conversation_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-hdpi/skin_tab_icon_conversation_normal.png
--------------------------------------------------------------------------------
/tabindicator/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/samples/src/main/res/mipmap-hdpi/skin_tab_icon_conversation_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenkaiZhou/Android-TabIndicator/HEAD/samples/src/main/res/mipmap-hdpi/skin_tab_icon_conversation_selected.png
--------------------------------------------------------------------------------
/samples/src/main/res/drawable/tabbg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/tabindicator/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FF45C01A
4 | #FF555555
5 |
6 |
--------------------------------------------------------------------------------
/samples/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/samples/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/tabindicator/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 12sp
4 | 4dp
5 | 12dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
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-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
10 | /.idea
11 | /.gradle
12 | /build
13 | /local.properties
14 | /tabindicator/build
15 | /samples/build
16 | /samples/samples.iml
17 | /TabIndicator.iml
18 | /tabindicator/local.properties
--------------------------------------------------------------------------------
/tabindicator/project.properties:
--------------------------------------------------------------------------------
1 | #project
2 | project.name=TabIndicator
3 | project.groupId=com.kevin
4 | project.artifactId=tabindicator
5 | project.packaging=aar
6 | project.siteUrl=https://github.com/xuehuayous/Android-TabIndicator
7 | project.gitUrl=https://github.com/xuehuayous/Android-TabIndicator.git
8 |
9 | #javadoc
10 | javadoc.name=TabIndicator
--------------------------------------------------------------------------------
/samples/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/tabindicator/src/test/java/com/kevin/tabindicator/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator;
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 | }
--------------------------------------------------------------------------------
/samples/src/test/java/com/kevin/tabindicator/samples/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator.samples;
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 | }
--------------------------------------------------------------------------------
/samples/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/tabindicator/src/androidTest/java/com/kevin/tabindicator/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator;
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 | }
--------------------------------------------------------------------------------
/samples/src/androidTest/java/com/kevin/tabindicator/samples/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator.samples;
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 | }
--------------------------------------------------------------------------------
/tabindicator/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 8
9 | targetSdkVersion 23
10 | versionCode 2
11 | versionName "1.0.2"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.android.support:appcompat-v7:23.1.0'
23 | }
24 |
25 | apply from: "bintrayUpload.gradle"
--------------------------------------------------------------------------------
/samples/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 D:\studio-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/tabindicator/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 D:\studio-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/samples/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.kevin.tabindicator.samples"
9 | minSdkVersion 8
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(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.1.0'
26 | compile project(':tabindicator')
27 | }
28 |
--------------------------------------------------------------------------------
/tabindicator/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/samples/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tabindicator/src/main/res/values/attrs.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 |
--------------------------------------------------------------------------------
/samples/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | - "微信"
7 | - "通讯录"
8 | - "发现"
9 | - "我"
10 |
11 |
12 | - @mipmap/ic_menu_emoticons
13 | - @mipmap/ic_menu_friendslist
14 | - @mipmap/ic_menu_myplaces
15 | - @mipmap/ic_menu_start_conversation
16 |
17 |
18 |
19 | - @mipmap/skin_tab_icon_conversation_normal
20 | - @mipmap/skin_tab_icon_contact_normal
21 | - @mipmap/skin_tab_icon_plugin_normal
22 |
23 |
24 |
25 | - @mipmap/skin_tab_icon_conversation_selected
26 | - @mipmap/skin_tab_icon_contact_selected
27 | - @mipmap/skin_tab_icon_plugin_selected
28 |
29 |
30 |
--------------------------------------------------------------------------------
/samples/src/main/java/com/kevin/tabindicator/samples/TabFragment.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator.samples;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.view.Gravity;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 |
12 | public class TabFragment extends Fragment {
13 | private String mTitle = "Default";
14 |
15 | public TabFragment() {
16 | }
17 |
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
20 | Bundle savedInstanceState) {
21 | if (getArguments() != null) {
22 | mTitle = getArguments().getString("title");
23 | }
24 |
25 | TextView textView = new TextView(getActivity());
26 | textView.setTextSize(16);
27 | textView.setPadding(0,0,0,20);
28 | textView.setBackgroundColor(Color.parseColor("#ffffffff"));
29 | textView.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL);
30 | textView.setText(mTitle);
31 | return textView;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/samples/src/main/res/layout/activity_tab_indicator.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
15 |
16 |
20 |
21 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/samples/src/main/java/com/kevin/tabindicator/samples/LauncherActivity.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator.samples;
2 |
3 | import android.app.ListActivity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.ArrayAdapter;
8 | import android.widget.ListView;
9 |
10 | /**
11 | * Created by zwenkai on 2016/2/26.
12 | */
13 | public class LauncherActivity extends ListActivity{
14 |
15 | public static final String[] options = { "TabPageIndicatorEx", "TabPageIndicator", "TabIndicator"};
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setListAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, options));
21 | }
22 |
23 | @Override
24 | protected void onListItemClick(ListView l, View v, int position, long id) {
25 | Intent intent;
26 |
27 | switch (position) {
28 | default:
29 | case 0:
30 | intent = new Intent(this, TabPageIndicatorExActivity.class);
31 | break;
32 | case 1:
33 | intent = new Intent(this, TabPageIndicatorActivity.class);
34 | break;
35 | case 2:
36 | intent = new Intent(this, TabIndicatorActivity.class);
37 | break;
38 | }
39 |
40 | startActivity(intent);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/samples/src/main/res/layout/activity_tabpage_indicator.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
19 |
23 |
24 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/samples/src/main/java/com/kevin/tabindicator/samples/TabIndicatorActivity.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator.samples;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.widget.TextView;
6 |
7 | import com.kevin.tabindicator.TabIndicator;
8 | import com.kevin.tabindicator.TabPageIndicatorEx;
9 |
10 | public class TabIndicatorActivity extends AppCompatActivity {
11 |
12 | private TextView mTextView;
13 | private TabIndicator mTabIndicator;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_tab_indicator);
19 |
20 | initViews();
21 | initEvents();
22 | }
23 |
24 | /**
25 | * 初始化View
26 | */
27 | private void initViews() {
28 | mTextView = (TextView) this.findViewById(R.id.tab_indicator_act_tv);
29 | mTabIndicator = (TabIndicator) this.findViewById(R.id.tab_indicator_act_ti);
30 | mTextView.setText("Page1");
31 | mTabIndicator.setIndicateDisplay(2, true);
32 | }
33 |
34 | /**
35 | * 初始化事件
36 | */
37 | private void initEvents() {
38 | mTabIndicator.setOnTabSelectedListener(new TabPageIndicatorEx.OnTabSelectedListener() {
39 |
40 | @Override
41 | public void onTabSelected(int index) {
42 | mTextView.setText("Page"+(index+1));
43 | }
44 | });
45 | }
46 | }
--------------------------------------------------------------------------------
/samples/src/main/res/layout/activity_tabpage_indicator_ex.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
19 |
20 |
24 |
25 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/tabindicator/src/main/java/com/kevin/tabindicator/internal/ITabView.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator.internal;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * 版权所有:XXX有限公司
7 | *
8 | * ITabView
9 | *
10 | * @author zhou.wenkai ,Created on 2016-2-25 21:50:39
11 | * Major Function:底部导航条目操作接口
12 | *
13 | * 注:如果您修改了本类请填写以下内容作为记录,如非本人操作劳烦通知,谢谢!!!
14 | * @author mender,Modified Date Modify Content:
15 | */
16 | public interface ITabView {
17 | /**
18 | * 设置文字
19 | * @param id
20 | */
21 | void setText(int id);
22 |
23 | /**
24 | * 设置文字
25 | * @param text
26 | */
27 | void setText(CharSequence text);
28 |
29 | /**
30 | * 设置选中时颜色
31 | * @param selectedColor
32 | */
33 | void setSelectedColor(int selectedColor);
34 |
35 | /**
36 | * 设置未选中时颜色
37 | * @param unselectedColor
38 | */
39 | void setUnselectedColor(int unselectedColor);
40 |
41 | /**
42 | * 设置文本大小
43 | * @param textSize
44 | */
45 | void setTextSize(int textSize);
46 |
47 | /**
48 | * 设置指示点大小
49 | * @param indicatorSize
50 | */
51 | void setIndicatorSize(int indicatorSize);
52 |
53 | /**
54 | * 设置指示点图片
55 | * @param bitmap
56 | */
57 | void setIndicatorBitmap(Bitmap bitmap);
58 |
59 | /**
60 | * 设置指示点图片
61 | * @param resId
62 | */
63 | void setIndicatorBitmap(int resId);
64 |
65 | /**
66 | * 设置是否选中
67 | * @param isSelected
68 | */
69 | void setSelected(boolean isSelected);
70 | }
71 |
--------------------------------------------------------------------------------
/tabindicator/src/main/java/com/kevin/tabindicator/TabPageIndicatorEx.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.support.v4.view.ViewPager.OnPageChangeListener;
6 | import android.util.AttributeSet;
7 |
8 | import com.kevin.tabindicator.internal.TabPageIndicatorBase;
9 |
10 | /**
11 | * 版权所有:XXX有限公司
12 | *
13 | * TabPageIndicator
14 | *
15 | * @author zhou.wenkai ,Created on 2016-2-24 10:41:49
16 | * Major Function:ViewPager的底部导航指示器
17 | *
18 | * 注:如果您修改了本类请填写以下内容作为记录,如非本人操作劳烦通知,谢谢!!!
19 | * @author mender,Modified Date Modify Content:
20 | */
21 | public class TabPageIndicatorEx extends TabPageIndicatorBase implements OnPageChangeListener {
22 |
23 | /** 底部菜单图标数组 */
24 | private int[] mDrawableIds;
25 |
26 | public TabPageIndicatorEx(Context context, AttributeSet attrs) {
27 | super(context, attrs);
28 | }
29 |
30 | @Override
31 | protected void handleStyledAttributes(TypedArray a) {
32 | // 读取布局中,各个tab使用的图标
33 | int iconsResId = a.getResourceId(R.styleable.TabIndicator_tabIcons, 0);
34 | TypedArray ta = getContext().getResources().obtainTypedArray(iconsResId);
35 | int len = ta.length();
36 | mDrawableIds = new int[len];
37 | for(int i = 0; i < len; i++) {
38 | mDrawableIds[i] = ta.getResourceId(i, 0);
39 | }
40 | ta.recycle();
41 | }
42 |
43 | @Override
44 | protected TabPageViewEx createTabView() {
45 | return new TabPageViewEx(getContext());
46 | }
47 |
48 | @Override
49 | protected void setProperties(TabPageViewEx tabPageView, int index) {
50 | tabPageView.setIcon(mDrawableIds[index]);
51 | }
52 |
53 | @Override
54 | protected int getTabSize() {
55 | return mDrawableIds.length;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tabindicator/src/main/java/com/kevin/tabindicator/TabIndicator.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.util.AttributeSet;
6 |
7 | import com.kevin.tabindicator.internal.TabIndicatorBase;
8 |
9 | /**
10 | * 版权所有:XXX有限公司
11 | *
12 | * TabIndicator
13 | *
14 | * @author zhou.wenkai ,Created on 2016-2-26 22:47:35
15 | * Major Function:简单底部导航指示器
16 | *
17 | * 注:如果您修改了本类请填写以下内容作为记录,如非本人操作劳烦通知,谢谢!!!
18 | * @author mender,Modified Date Modify Content:
19 | */
20 | public class TabIndicator extends TabIndicatorBase {
21 |
22 | private int[] mSelectedDrawableIds;
23 | private int[] mUnselectedDrawableIds;
24 |
25 | public TabIndicator(Context context, AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | @Override
30 | protected void handleStyledAttributes(TypedArray a) {
31 | // 读取布局中,各个tab使用的图标
32 | int selectedIconsResId = a.getResourceId(R.styleable.TabIndicator_tabSelectedIcons, 0);
33 | TypedArray ta = getContext().getResources().obtainTypedArray(selectedIconsResId);
34 | int len = ta.length();
35 | mSelectedDrawableIds = new int[len];
36 | for(int i = 0; i < len; i++) {
37 | mSelectedDrawableIds[i] = ta.getResourceId(i, 0);
38 | }
39 |
40 | int unselectedIconsResId = a.getResourceId(R.styleable.TabIndicator_tabUnselectedIcons, 0);
41 | ta = getContext().getResources().obtainTypedArray(unselectedIconsResId);
42 | len = ta.length();
43 | mUnselectedDrawableIds = new int[len];
44 | for(int i = 0; i < len; i++) {
45 | mUnselectedDrawableIds[i] = ta.getResourceId(i, 0);
46 | }
47 |
48 | ta.recycle();
49 | }
50 |
51 | @Override
52 | protected TabView createTabView() {
53 | return new TabView(getContext());
54 | }
55 |
56 | @Override
57 | protected void setProperties(TabView tabView, int index) {
58 | tabView.setSelectedIcon(mSelectedDrawableIds[index]);
59 | tabView.setUnselectedIcon(mUnselectedDrawableIds[index]);
60 | }
61 |
62 | @Override
63 | protected int getTabSize() {
64 | return mSelectedDrawableIds.length;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/tabindicator/src/main/java/com/kevin/tabindicator/TabPageIndicator.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.support.v4.view.ViewPager.OnPageChangeListener;
6 | import android.util.AttributeSet;
7 |
8 | import com.kevin.tabindicator.internal.TabPageIndicatorBase;
9 |
10 | /**
11 | * 版权所有:XXX有限公司
12 | *
13 | * TabPageIndicator
14 | *
15 | * @author zhou.wenkai ,Created on 2016-2-27 16:04:53
16 | * Major Function:ViewPager的底部导航指示器
17 | *
18 | * 注:如果您修改了本类请填写以下内容作为记录,如非本人操作劳烦通知,谢谢!!!
19 | * @author mender,Modified Date Modify Content:
20 | */
21 | public class TabPageIndicator extends TabPageIndicatorBase implements OnPageChangeListener {
22 |
23 | /** 底部菜单图标数组 */
24 | private int[] mSelectedDrawableIds;
25 | private int[] mUnselectedDrawableIds;
26 |
27 | public TabPageIndicator(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 | }
30 |
31 | @Override
32 | protected void handleStyledAttributes(TypedArray a) {
33 | // 读取布局中,各个tab使用的图标
34 | int iconsResId = a.getResourceId(R.styleable.TabIndicator_tabSelectedIcons, 0);
35 | TypedArray ta = getContext().getResources().obtainTypedArray(iconsResId);
36 | int len = ta.length();
37 | mSelectedDrawableIds = new int[len];
38 | for(int i = 0; i < len; i++) {
39 | mSelectedDrawableIds[i] = ta.getResourceId(i, 0);
40 | }
41 |
42 | iconsResId = a.getResourceId(R.styleable.TabIndicator_tabUnselectedIcons, 0);
43 | ta = getContext().getResources().obtainTypedArray(iconsResId);
44 | len = ta.length();
45 | mUnselectedDrawableIds = new int[len];
46 | for(int i = 0; i < len; i++) {
47 | mUnselectedDrawableIds[i] = ta.getResourceId(i, 0);
48 | }
49 |
50 | ta.recycle();
51 | }
52 |
53 | @Override
54 | protected TabPageView createTabView() {
55 | return new TabPageView(getContext());
56 | }
57 |
58 | @Override
59 | protected void setProperties(TabPageView tabPageView, int index) {
60 | tabPageView.setSelectedIcon(mSelectedDrawableIds[index]);
61 | tabPageView.setUnselectedIcon(mUnselectedDrawableIds[index]);
62 | }
63 |
64 | @Override
65 | protected int getTabSize() {
66 | return mSelectedDrawableIds.length;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/tabindicator/src/main/java/com/kevin/tabindicator/TabView.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.util.AttributeSet;
8 |
9 | import com.kevin.tabindicator.internal.TabViewBase;
10 |
11 | /**
12 | * 版权所有:XXX有限公司
13 | *
14 | * TabView
15 | *
16 | * @author zhou.wenkai ,Created on 2016-2-25 23:15:39
17 | * Major Function:TabPageIndicator的每一个条目
18 | *
19 | * 注:如果您修改了本类请填写以下内容作为记录,如非本人操作劳烦通知,谢谢!!!
20 | * @author mender,Modified Date Modify Content:
21 | */
22 | public class TabView extends TabViewBase {
23 |
24 | /** 图标 */
25 | private Bitmap mSelectedIconBitmap;
26 | private Bitmap mUnselectedIconBitmap;
27 |
28 | public TabView(Context context) {
29 | super(context);
30 | }
31 |
32 | public TabView(Context context, AttributeSet attrs) {
33 | super(context, attrs);
34 | }
35 |
36 | @Override
37 | protected void onDraw(Canvas canvas) {
38 | super.onDraw(canvas);
39 | setupTargetBitmap(canvas);
40 | drawIndicator(canvas);
41 | if(null != mText) {
42 | drawTargetText(canvas);
43 | }
44 | }
45 |
46 | /**
47 | * 绘制图标图片
48 | * @param canvas
49 | */
50 | private void setupTargetBitmap(Canvas canvas) {
51 | canvas.drawBitmap(isSelected ? mSelectedIconBitmap : mUnselectedIconBitmap, null, mIconRect, null);
52 | }
53 |
54 | @Override
55 | public void setSelected(boolean selected) {
56 | this.isSelected = selected;
57 | invalidateView();
58 | }
59 |
60 | public void setSelectedIcon(int resId) {
61 | this.mSelectedIconBitmap = BitmapFactory.decodeResource(getResources(), resId);
62 | if (mIconRect != null)
63 | invalidateView();
64 | }
65 |
66 | public void setSelectedIcon(Bitmap iconBitmap) {
67 | this.mSelectedIconBitmap = iconBitmap;
68 | if (mIconRect != null)
69 | invalidateView();
70 | }
71 |
72 | public void setUnselectedIcon(int resId) {
73 | this.mUnselectedIconBitmap = BitmapFactory.decodeResource(getResources(), resId);
74 | if (mIconRect != null)
75 | invalidateView();
76 | }
77 |
78 | public void setUnselectedIcon(Bitmap iconBitmap) {
79 | this.mUnselectedIconBitmap = iconBitmap;
80 | if (mIconRect != null)
81 | invalidateView();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/tabindicator/src/main/java/com/kevin/tabindicator/internal/TabPageIndicatorBase.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator.internal;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.support.v4.view.ViewPager;
6 | import android.util.AttributeSet;
7 |
8 | import com.kevin.tabindicator.R;
9 |
10 | /**
11 | * 版权所有:XXX有限公司
12 | *
13 | * TabPageIndicatorBase
14 | *
15 | * @author zhou.wenkai ,Created on 2016-2-26 21:58:25
16 | * Major Function:ViewPager类型底部导航基类
17 | *
18 | * 注:如果您修改了本类请填写以下内容作为记录,如非本人操作劳烦通知,谢谢!!!
19 | * @author mender,Modified Date Modify Content:
20 | */
21 | public abstract class TabPageIndicatorBase extends TabIndicatorBase implements ViewPager.OnPageChangeListener {
22 |
23 | /** 是否渐变切换 */
24 | protected boolean mIsGradualChange;
25 | /** 用于ViewPager会渐变颜色 */
26 | private ViewPager mViewPager;
27 |
28 | public TabPageIndicatorBase(Context context, AttributeSet attrs) {
29 | super(context, attrs);
30 | }
31 |
32 | @Override
33 | protected void handleStyledAttributes(TypedArray a) {
34 | super.handleStyledAttributes(a);
35 | mIsGradualChange = a.getBoolean(R.styleable.TabIndicator_tabGradualChange, true);
36 | }
37 |
38 | /**
39 | * 设置是否渐变渐变切换
40 | * @param isGradualChange
41 | */
42 | public void setIsGradualChange(boolean isGradualChange) {
43 | this.mIsGradualChange = isGradualChange;
44 | }
45 |
46 | /**
47 | * 获取是否渐变切换
48 | * @return
49 | */
50 | public boolean getIsGradualChange() {
51 | return mIsGradualChange;
52 | }
53 |
54 | public void setViewPager(ViewPager viewPager) {
55 | this.mViewPager = viewPager;
56 | mViewPager.addOnPageChangeListener(this);
57 | }
58 |
59 | @Override
60 | public void onPageScrollStateChanged(int position) {
61 | }
62 |
63 | @Override
64 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
65 | if (mIsGradualChange && positionOffset > 0) {
66 | T left = mCheckedList.get(position);
67 | T right = mCheckedList.get(position + 1);
68 |
69 | left.setIconAlpha(1 - positionOffset);
70 | right.setIconAlpha(positionOffset);
71 | }
72 | }
73 |
74 | @Override
75 | public void onPageSelected(int position) {
76 | if(!mIsGradualChange) {
77 | setTabsDisplay(position);
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/samples/src/main/java/com/kevin/tabindicator/samples/TabPageIndicatorActivity.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator.samples;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 | import android.support.v4.view.ViewPager;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.Menu;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 | import android.widget.Button;
12 |
13 | import com.kevin.tabindicator.TabPageIndicator;
14 | import com.kevin.tabindicator.TabPageIndicatorEx;
15 |
16 | import java.util.ArrayList;
17 | import java.util.List;
18 |
19 | public class TabPageIndicatorActivity extends AppCompatActivity {
20 |
21 | private ViewPager mViewPager;
22 | private Button mChangeModeBtn;
23 | private TabPageIndicator mTabPageIndicator;
24 | private List mTabs = new ArrayList<>();
25 | private FragmentPagerAdapter mAdapter;
26 |
27 | private boolean isGradualChange;
28 |
29 | private String[] mTitles = new String[] { "First Fragment!",
30 | "Second Fragment!", "Third Fragment!"};
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_tabpage_indicator);
36 |
37 | initViews();
38 | initEvents();
39 | }
40 |
41 | /**
42 | * 初始化View
43 | */
44 | private void initViews() {
45 | mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
46 | mTabPageIndicator = (TabPageIndicator) findViewById(R.id.tabpage_act_tpi);
47 | mChangeModeBtn = (Button) findViewById(R.id.tabpage_act_btn_change);
48 | initTabIndicator();
49 | initViewPager();
50 | }
51 |
52 | private void initViewPager() {
53 |
54 | for (String title : mTitles) {
55 | TabFragment tabFragment = new TabFragment();
56 | Bundle args = new Bundle();
57 | args.putString("title", title);
58 | tabFragment.setArguments(args);
59 | mTabs.add(tabFragment);
60 | }
61 |
62 | mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
63 |
64 | @Override
65 | public int getCount() {
66 | return mTabs.size();
67 | }
68 |
69 | @Override
70 | public Fragment getItem(int arg0) {
71 | return mTabs.get(arg0);
72 | }
73 | };
74 | mViewPager.setAdapter(mAdapter);
75 | }
76 |
77 | /**
78 | * 初始化事件
79 | */
80 | private void initEvents() {
81 | mChangeModeBtn.setOnClickListener(new View.OnClickListener() {
82 | @Override
83 | public void onClick(View v) {
84 | mTabPageIndicator.setIsGradualChange(!isGradualChange);
85 | isGradualChange = !isGradualChange;
86 | }
87 | });
88 | mTabPageIndicator.setOnTabSelectedListener(new TabPageIndicatorEx.OnTabSelectedListener() {
89 |
90 | @Override
91 | public void onTabSelected(int index) {
92 | mViewPager.setCurrentItem(index, false);
93 | }
94 | });
95 | }
96 |
97 | private void initTabIndicator() {
98 | mTabPageIndicator.setViewPager(mViewPager);
99 | mTabPageIndicator.setIndicateDisplay(2, true);
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/samples/src/main/java/com/kevin/tabindicator/samples/TabPageIndicatorExActivity.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator.samples;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 | import android.support.v4.view.ViewPager;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.os.Bundle;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.widget.Button;
13 |
14 | import com.kevin.tabindicator.TabPageIndicatorEx;
15 |
16 | import java.util.ArrayList;
17 | import java.util.List;
18 |
19 | public class TabPageIndicatorExActivity extends AppCompatActivity {
20 |
21 | private ViewPager mViewPager;
22 | private TabPageIndicatorEx mTabPageIndicatorEx;
23 | private Button mChangeModeBtn;
24 | private List mTabs = new ArrayList<>();
25 | private FragmentPagerAdapter mAdapter;
26 |
27 | private boolean isGradualChange;
28 |
29 | private String[] mTitles = new String[] { "First Fragment!",
30 | "Second Fragment!", "Third Fragment!", "Fourth Fragment!" };
31 |
32 | @SuppressLint("NewApi")
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_tabpage_indicator_ex);
37 |
38 | initViews();
39 | initEvents();
40 | }
41 |
42 | /**
43 | * 初始化View
44 | */
45 | private void initViews() {
46 | mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
47 | mTabPageIndicatorEx = (TabPageIndicatorEx) findViewById(R.id.tabpage_act_tpi);
48 | mChangeModeBtn = (Button) findViewById(R.id.tabpage_act_btn_change);
49 |
50 | initTabIndicator();
51 | initViewPager();
52 | }
53 |
54 | private void initViewPager() {
55 |
56 | for (String title : mTitles) {
57 | TabFragment tabFragment = new TabFragment();
58 | Bundle args = new Bundle();
59 | args.putString("title", title);
60 | tabFragment.setArguments(args);
61 | mTabs.add(tabFragment);
62 | }
63 |
64 | mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
65 |
66 | @Override
67 | public int getCount() {
68 | return mTabs.size();
69 | }
70 |
71 | @Override
72 | public Fragment getItem(int arg0) {
73 | return mTabs.get(arg0);
74 | }
75 | };
76 | mViewPager.setAdapter(mAdapter);
77 | }
78 |
79 | /**
80 | * 初始化事件
81 | */
82 | private void initEvents() {
83 | mChangeModeBtn.setOnClickListener(new View.OnClickListener() {
84 | @Override
85 | public void onClick(View v) {
86 | mTabPageIndicatorEx.setIsGradualChange(!isGradualChange);
87 | isGradualChange = !isGradualChange;
88 | }
89 | });
90 | mTabPageIndicatorEx.setOnTabSelectedListener(new TabPageIndicatorEx.OnTabSelectedListener() {
91 |
92 | @Override
93 | public void onTabSelected(int index) {
94 | mViewPager.setCurrentItem(index, false);
95 | }
96 | });
97 | }
98 |
99 | private void initTabIndicator() {
100 | mTabPageIndicatorEx.setViewPager(mViewPager);
101 | mTabPageIndicatorEx.setIndicateDisplay(2, true);
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/tabindicator/src/main/java/com/kevin/tabindicator/TabPageViewEx.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Bitmap.Config;
6 | import android.graphics.BitmapFactory;
7 | import android.graphics.Canvas;
8 | import android.graphics.Paint;
9 | import android.graphics.PorterDuff;
10 | import android.graphics.PorterDuffXfermode;
11 | import android.util.AttributeSet;
12 |
13 | import com.kevin.tabindicator.internal.TabViewBase;
14 |
15 | /**
16 | * 版权所有:XXX有限公司
17 | *
18 | * TabPageViewEx
19 | *
20 | * @author zhou.wenkai ,Created on 2016-2-24 10:54:41
21 | * Major Function:TabPageIndicatorEx的每一个条目
22 | *
23 | * 注:如果您修改了本类请填写以下内容作为记录,如非本人操作劳烦通知,谢谢!!!
24 | * @author mender,Modified Date Modify Content:
25 | */
26 | public class TabPageViewEx extends TabViewBase {
27 | private Bitmap mBitmap;
28 | private Canvas mCanvas;
29 | private Paint mPaint;
30 | /** 透明度 0.0-1.0 */
31 | private float mAlpha = 0f;
32 | /** 图标 */
33 | private Bitmap mIconBitmap;
34 |
35 | public TabPageViewEx(Context context) {
36 | super(context);
37 | }
38 |
39 | public TabPageViewEx(Context context, AttributeSet attrs) {
40 | super(context, attrs);
41 | }
42 |
43 | @Override
44 | protected void onDraw(Canvas canvas) {
45 | super.onDraw(canvas);
46 | int alpha = (int) Math.ceil((255 * mAlpha));
47 | canvas.drawBitmap(mIconBitmap, null, mIconRect, null);
48 | setupTargetBitmap(alpha);
49 | if(null != mText) {
50 | drawSourceText(canvas, alpha);
51 | drawTargetText(canvas, alpha);
52 | }
53 | canvas.drawBitmap(mBitmap, 0, 0, null);
54 | drawIndicator(canvas);
55 | }
56 |
57 | private void setupTargetBitmap(int alpha) {
58 | mBitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Config.ARGB_8888);
59 | mCanvas = new Canvas(mBitmap);
60 | mPaint = new Paint();
61 | mPaint.setColor(mSelectedColor);
62 | mPaint.setAntiAlias(true);
63 | mPaint.setDither(true);
64 | mPaint.setAlpha(alpha);
65 | mCanvas.drawRect(mIconRect, mPaint);
66 | mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
67 | mPaint.setAlpha(255);
68 | mCanvas.drawBitmap(mIconBitmap, null, mIconRect, mPaint);
69 | }
70 |
71 | private void drawSourceText(Canvas canvas, int alpha) {
72 | mTextPaint.setTextSize(mTextSize);
73 | mTextPaint.setColor(mUnselectedColor);
74 | mTextPaint.setAlpha(255 - alpha);
75 | canvas.drawText(mText, mIconRect.left + mIconRect.width() / 2
76 | - mTextBound.width() / 2,
77 | mIconRect.bottom + mTextBound.height(), mTextPaint);
78 | }
79 |
80 | private void drawTargetText(Canvas canvas, int alpha) {
81 | mTextPaint.setColor(mSelectedColor);
82 | mTextPaint.setAlpha(alpha);
83 | canvas.drawText(mText, mIconRect.left + mIconRect.width() / 2
84 | - mTextBound.width() / 2,
85 | mIconRect.bottom + mTextBound.height(), mTextPaint);
86 | }
87 |
88 | @Override
89 | public void setSelected(boolean selected) {
90 | if(selected) {
91 | setIconAlpha(1.0f);
92 | } else {
93 | setIconAlpha(0f);
94 | }
95 | }
96 |
97 | public void setIcon(int resId) {
98 | this.mIconBitmap = BitmapFactory.decodeResource(getResources(), resId);
99 | if (mIconRect != null)
100 | invalidateView();
101 | }
102 |
103 | public void setIcon(Bitmap iconBitmap) {
104 | this.mIconBitmap = iconBitmap;
105 | if (mIconRect != null)
106 | invalidateView();
107 | }
108 |
109 | public void setIconAlpha(float alpha) {
110 | this.mAlpha = alpha;
111 | invalidateView();
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/tabindicator/bintrayUpload.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.github.dcendents.android-maven'
2 | apply plugin: 'com.jfrog.bintray'
3 |
4 | // load properties
5 | Properties properties = new Properties()
6 | File localPropertiesFile = project.file("local.properties");
7 | if(localPropertiesFile.exists()){
8 | properties.load(localPropertiesFile.newDataInputStream())
9 | }
10 | File projectPropertiesFile = project.file("project.properties");
11 | if(projectPropertiesFile.exists()){
12 | properties.load(projectPropertiesFile.newDataInputStream())
13 | }
14 |
15 | // read properties
16 | def projectName = properties.getProperty("project.name")
17 | def projectGroupId = properties.getProperty("project.groupId")
18 | def projectArtifactId = properties.getProperty("project.artifactId")
19 | def projectVersionName = android.defaultConfig.versionName
20 | def projectPackaging = properties.getProperty("project.packaging")
21 | def projectSiteUrl = properties.getProperty("project.siteUrl")
22 | def projectGitUrl = properties.getProperty("project.gitUrl")
23 |
24 | def developerId = properties.getProperty("developer.id")
25 | def developerName = properties.getProperty("developer.name")
26 | def developerEmail = properties.getProperty("developer.email")
27 |
28 | def bintrayUser = properties.getProperty("bintray.user")
29 | def bintrayApikey = properties.getProperty("bintray.apikey")
30 |
31 | def javadocName = properties.getProperty("javadoc.name")
32 |
33 | group = projectGroupId
34 |
35 | // This generates POM.xml with proper parameters
36 | install {
37 | repositories.mavenInstaller {
38 | pom {
39 | project {
40 | name projectName
41 | groupId projectGroupId
42 | artifactId projectArtifactId
43 | version projectVersionName
44 | packaging projectPackaging
45 | url projectSiteUrl
46 | licenses {
47 | license {
48 | name 'The Apache Software License, Version 2.0'
49 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
50 | }
51 | }
52 | developers {
53 | developer {
54 | id developerId
55 | name developerName
56 | email developerEmail
57 | }
58 | }
59 | scm {
60 | connection projectGitUrl
61 | developerConnection projectGitUrl
62 | url projectSiteUrl
63 | }
64 | }
65 | }
66 | }
67 | }
68 |
69 | // This generates sources.jar
70 | task sourcesJar(type: Jar) {
71 | from android.sourceSets.main.java.srcDirs
72 | classifier = 'sources'
73 | }
74 |
75 | task javadoc(type: Javadoc) {
76 | source = android.sourceSets.main.java.srcDirs
77 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
78 | }
79 |
80 | // This generates javadoc.jar
81 | task javadocJar(type: Jar, dependsOn: javadoc) {
82 | classifier = 'javadoc'
83 | from javadoc.destinationDir
84 | }
85 |
86 | artifacts {
87 | archives javadocJar
88 | archives sourcesJar
89 | }
90 |
91 | // javadoc configuration
92 | javadoc {
93 | options{
94 | encoding "UTF-8"
95 | charSet 'UTF-8'
96 | author true
97 | version projectVersionName
98 | links "http://docs.oracle.com/javase/7/docs/api"
99 | title javadocName
100 | }
101 | }
102 |
103 | // bintray configuration
104 | bintray {
105 | user = bintrayUser
106 | key = bintrayApikey
107 | configurations = ['archives']
108 | pkg {
109 | repo = "maven"
110 | name = projectName
111 | websiteUrl = projectSiteUrl
112 | vcsUrl = projectGitUrl
113 | licenses = ["Apache-2.0"]
114 | publish = true
115 | }
116 | }
--------------------------------------------------------------------------------
/README-zh.md:
--------------------------------------------------------------------------------
1 |
2 | # TabIndicator for Android
3 | **[English](https://github.com/xuehuayous/Android-TabIndicator)** **[中文](https://github.com/xuehuayous/Android-TabIndicator/blob/master/README-zh.md)**
4 |
5 | TabIndicator 是一个强大的底部导航控件,并且提供了许多配置方法来达到您的显示效果和需求。
6 |
7 | **简单示例**
8 | 
9 |
10 | **Page导航示例**
11 | 
12 |
13 | **增强Page导航示例**
14 | 
15 |
16 | ## 在项目中使用 TabIndicator
17 |
18 | 如果您的项目使用 Gradle 构建, 只需要在您的`build.gradle`文件添加下面一行到 `dependencies` :
19 |
20 | ```
21 | compile 'com.kevin:tabindicator:1.0.2'
22 | ```
23 |
24 | ## 简单使用 ##
25 |
26 | ### 在layout.xml 中配置LoopView ###
27 | 在Layout文件添加`com.kevin.tabindicator.TabIndicator`
28 |
29 |
39 |
40 | ### 在代码中配置 ###
41 |
42 | TabIndicator mTabIndicator = (TabIndicator) this.findViewById(R.id.tab_indicator_act_ti);
43 | mTabIndicator.setOnTabSelectedListener(new TabPageIndicatorEx.OnTabSelectedListener() {
44 |
45 | @Override
46 | public void onTabSelected(int index) {
47 | mTextView.setText("Page"+(index+1));
48 | }
49 | });
50 |
51 | ## 更多配置 ##
52 |
53 | ### XML 配置 ###
54 |
55 | 在XML中使用TabIndicator,可以有如下配置:
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | ### 在代码中配置 ###
81 |
82 | // 设置ViewPager
83 | mTabPageIndicatorEx.setViewPager(mViewPager);
84 | // 设置指定位置指示点展示与否
85 | mTabPageIndicatorEx.setIndicateDisplay(2, true);
86 | // 设置切换监听
87 | mTabPageIndicatorEx.setOnTabSelectedListener(new TabPageIndicatorEx.OnTabSelectedListener() {
88 |
89 | @Override
90 | public void onTabSelected(int index) {
91 | mViewPager.setCurrentItem(index, false);
92 | }
93 | });
94 |
95 |
96 | ## License
97 |
98 | Copyright 2015 Kevin zhou
99 |
100 | Licensed under the Apache License, Version 2.0 (the "License");
101 | you may not use this file except in compliance with the License.
102 | You may obtain a copy of the License at
103 |
104 | http://www.apache.org/licenses/LICENSE-2.0
105 |
106 | Unless required by applicable law or agreed to in writing, software
107 | distributed under the License is distributed on an "AS IS" BASIS,
108 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
109 | See the License for the specific language governing permissions and
110 | limitations under the License.
--------------------------------------------------------------------------------
/tabindicator/src/main/java/com/kevin/tabindicator/TabPageView.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Bitmap.Config;
6 | import android.graphics.BitmapFactory;
7 | import android.graphics.Canvas;
8 | import android.graphics.Paint;
9 | import android.graphics.PorterDuff;
10 | import android.graphics.PorterDuffXfermode;
11 | import android.util.AttributeSet;
12 |
13 | import com.kevin.tabindicator.internal.TabViewBase;
14 |
15 | /**
16 | * 版权所有:XXX有限公司
17 | *
18 | * TabPageView
19 | *
20 | * @author zhou.wenkai ,Created on 2016-2-27 16:09:06
21 | * Major Function:TabPageIndicator的每一个条目
22 | *
23 | * 注:如果您修改了本类请填写以下内容作为记录,如非本人操作劳烦通知,谢谢!!!
24 | * @author mender,Modified Date Modify Content:
25 | */
26 | public class TabPageView extends TabViewBase {
27 |
28 | private Paint mPaint = new Paint();
29 | /** 透明度 0.0-1.0 */
30 | private float mAlpha = 0f;
31 | /** 图标 */
32 | private Bitmap mSelectedIconBitmap;
33 | private Bitmap mUnselectedIconBitmap;
34 |
35 | public TabPageView(Context context) {
36 | super(context);
37 | }
38 |
39 | public TabPageView(Context context, AttributeSet attrs) {
40 | super(context, attrs);
41 | }
42 |
43 | @Override
44 | protected void onDraw(Canvas canvas) {
45 | super.onDraw(canvas);
46 | int alpha = (int) Math.ceil((255 * mAlpha));
47 | drawSourceBitmap(canvas, alpha);
48 | drawTargetBitmap(canvas, alpha);
49 | if(null != mText) {
50 | drawSourceText(canvas, alpha);
51 | drawTargetText(canvas, alpha);
52 | }
53 | drawIndicator(canvas);
54 | }
55 |
56 | /**
57 | * 绘制未选中图标
58 | * @param canvas
59 | * @param alpha
60 | */
61 | private void drawSourceBitmap(Canvas canvas, int alpha) {
62 | mPaint.setAntiAlias(true);
63 | mPaint.setDither(true);
64 | mPaint.setAlpha(255 - alpha);
65 | canvas.drawBitmap(mUnselectedIconBitmap, null, mIconRect, mPaint);
66 | }
67 |
68 | /**
69 | * 绘制选中图标
70 | * @param canvas
71 | * @param alpha
72 | */
73 | private void drawTargetBitmap(Canvas canvas, int alpha) {
74 | mPaint.setAntiAlias(true);
75 | mPaint.setDither(true);
76 | mPaint.setAlpha(alpha);
77 | canvas.drawBitmap(mSelectedIconBitmap, null, mIconRect, mPaint);
78 | }
79 |
80 | /**
81 | * 绘制未选中文字
82 | * @param canvas
83 | * @param alpha
84 | */
85 | private void drawSourceText(Canvas canvas, int alpha) {
86 | mTextPaint.setTextSize(mTextSize);
87 | mTextPaint.setColor(mUnselectedColor);
88 | mTextPaint.setAlpha(255 - alpha);
89 | canvas.drawText(mText, mIconRect.left + mIconRect.width() / 2
90 | - mTextBound.width() / 2,
91 | mIconRect.bottom + mTextBound.height(), mTextPaint);
92 | }
93 |
94 | /**
95 | * 绘制选中文字
96 | * @param canvas
97 | * @param alpha
98 | */
99 | private void drawTargetText(Canvas canvas, int alpha) {
100 | mTextPaint.setColor(mSelectedColor);
101 | mTextPaint.setAlpha(alpha);
102 | canvas.drawText(mText, mIconRect.left + mIconRect.width() / 2
103 | - mTextBound.width() / 2,
104 | mIconRect.bottom + mTextBound.height(), mTextPaint);
105 | }
106 |
107 |
108 | @Override
109 | public void setSelected(boolean selected) {
110 | if(selected) {
111 | setIconAlpha(1.0f);
112 | } else {
113 | setIconAlpha(0f);
114 | }
115 | }
116 |
117 | public void setSelectedIcon(int resId) {
118 | this.mSelectedIconBitmap = BitmapFactory.decodeResource(getResources(), resId);
119 | if (mIconRect != null)
120 | invalidateView();
121 | }
122 |
123 | public void setSelectedIcon(Bitmap iconBitmap) {
124 | this.mSelectedIconBitmap = iconBitmap;
125 | if (mIconRect != null)
126 | invalidateView();
127 | }
128 | public void setUnselectedIcon(int resId) {
129 | this.mUnselectedIconBitmap = BitmapFactory.decodeResource(getResources(), resId);
130 | if (mIconRect != null)
131 | invalidateView();
132 | }
133 |
134 | public void setUnselectedIcon(Bitmap iconBitmap) {
135 | this.mUnselectedIconBitmap = iconBitmap;
136 | if (mIconRect != null)
137 | invalidateView();
138 | }
139 |
140 | public void setIconAlpha(float alpha) {
141 | this.mAlpha = alpha;
142 | invalidateView();
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # TabIndicator for Android
3 | **[English](https://github.com/xuehuayous/Android-TabIndicator)** **[中文](https://github.com/xuehuayous/Android-TabIndicator/blob/master/README-zh.md)**
4 |
5 | Tab Indicator is a powerful bottom navigation widget, It provides some configuration options and good control the appearance and operational requirements.
6 |
7 | **simple example**
8 | 
9 |
10 | **Page navigation example**
11 | 
12 |
13 | **Enhanced Page navigation example**
14 | 
15 |
16 | ## Using TabIndicator in your application
17 |
18 | If you are building with Gradle, simply add the following line to the `dependencies` section of your `build.gradle` file:
19 |
20 | ```
21 | compile 'com.kevin:tabindicator:1.0.2'
22 | ```
23 |
24 | ## Simple Usage ##
25 |
26 | ### Configured as View in layout.xml ###
27 | To add the LoopView to your application, specify `com.kevin.tabindicator.TabIndicator` in your layout XML.
28 |
29 |
39 |
40 | ### Configured Programmatically ###
41 |
42 | TabIndicator mTabIndicator = (TabIndicator) this.findViewById(R.id.tab_indicator_act_ti);
43 | mTabIndicator.setOnTabSelectedListener(new TabPageIndicatorEx.OnTabSelectedListener() {
44 |
45 | @Override
46 | public void onTabSelected(int index) {
47 | mTextView.setText("Page"+(index+1));
48 | }
49 | });
50 |
51 | ## More configuration Usage ##
52 |
53 | ### XML Usage ###
54 |
55 | If you decide to use TabIndicator as a view, you can define it in your xml layout like this:
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | ### Programme Usage ###
81 |
82 | // set ViewPager
83 | mTabPageIndicatorEx.setViewPager(mViewPager);
84 | // Setting specifies the position indicator to show whether or not the point
85 | mTabPageIndicatorEx.setIndicateDisplay(2, true);
86 | // Monitor switch settings
87 | mTabPageIndicatorEx.setOnTabSelectedListener(new TabPageIndicatorEx.OnTabSelectedListener() {
88 |
89 | @Override
90 | public void onTabSelected(int index) {
91 | mViewPager.setCurrentItem(index, false);
92 | }
93 | });
94 |
95 |
96 | ## License
97 |
98 | Copyright 2015 Kevin zhou
99 |
100 | Licensed under the Apache License, Version 2.0 (the "License");
101 | you may not use this file except in compliance with the License.
102 | You may obtain a copy of the License at
103 |
104 | http://www.apache.org/licenses/LICENSE-2.0
105 |
106 | Unless required by applicable law or agreed to in writing, software
107 | distributed under the License is distributed on an "AS IS" BASIS,
108 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
109 | See the License for the specific language governing permissions and
110 | limitations under the License.
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/tabindicator/src/main/java/com/kevin/tabindicator/internal/TabViewBase.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator.internal;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Rect;
9 | import android.os.Looper;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.widget.TextView;
14 |
15 | import com.kevin.tabindicator.R;
16 |
17 | /**
18 | * 版权所有:XXX有限公司
19 | *
20 | * TabViewBase
21 | *
22 | * @author zhou.wenkai ,Created on 2016-2-25 22:20:27
23 | * Major Function:底部导航条目操作基类
24 | *
25 | * 注:如果您修改了本类请填写以下内容作为记录,如非本人操作劳烦通知,谢谢!!!
26 | * @author mender,Modified Date Modify Content:
27 | */
28 | public abstract class TabViewBase extends View implements ITabView {
29 |
30 | /** 底部文本内容 */
31 | protected String mText;
32 | /** 底部文本大小 */
33 | protected int mTextSize;
34 | /** 选中颜色 */
35 | protected int mSelectedColor;
36 | /** 未选中颜色 */
37 | protected int mUnselectedColor;
38 | /** 限制绘制icon的范围 */
39 | protected Rect mIconRect;
40 | /** 限制绘制指示点的范围 */
41 | private Rect mIndicatorRect;
42 | /** 是否显示指示点 */
43 | private boolean isIndicateDisplay;
44 | /** 指示点大小 */
45 | private int mIndicatorSize;
46 | /** 指示点图片 */
47 | private Bitmap mIndicatorBitmap;
48 |
49 | protected boolean isSelected;
50 |
51 | protected Paint mTextPaint = new Paint();
52 | protected Rect mTextBound = new Rect();
53 |
54 | public TabViewBase(Context context) {
55 | this(context, null);
56 | }
57 |
58 | public TabViewBase(Context context, AttributeSet attrs) {
59 | super(context, attrs);
60 | setIndicatorBitmap(R.drawable.update_hint);
61 | }
62 |
63 | @Override
64 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
65 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
66 |
67 | // 得到绘制icon的宽
68 | int bitmapWidth = Math.min(getMeasuredWidth() - getPaddingLeft()
69 | - getPaddingRight(), getMeasuredHeight() - getPaddingTop()
70 | - getPaddingBottom() - mTextBound.height());
71 |
72 | int left = getMeasuredWidth() / 2 - bitmapWidth / 2;
73 | int top = (getMeasuredHeight() - mTextBound.height()) / 2 - bitmapWidth / 2;
74 | // 设置icon的绘制范围
75 | mIconRect = new Rect(left, top, left + bitmapWidth, top + bitmapWidth);
76 | // 设置指示点的范围
77 | // mIndicatorRect = new Rect(left + bitmapWidth * 2/3, top, left+bitmapWidth, top + bitmapWidth /3);
78 | int indicatorRadius = mIndicatorSize / 2;
79 | int tabRealHeight = bitmapWidth + mTextBound.height();
80 | mIndicatorRect = new Rect(left + tabRealHeight* 4/5 - indicatorRadius, top, left+tabRealHeight* 4/5 + indicatorRadius, top + mIndicatorSize);
81 | }
82 |
83 | /**
84 | * 绘制文字
85 | * @param canvas
86 | */
87 | protected void drawTargetText(Canvas canvas) {
88 | mTextPaint.setColor(isSelected ? mSelectedColor : mUnselectedColor);
89 | canvas.drawText(mText, mIconRect.left + mIconRect.width() / 2
90 | - mTextBound.width() / 2,
91 | mIconRect.bottom + mTextBound.height(), mTextPaint);
92 | }
93 |
94 | /**
95 | * 绘制指示点
96 | * @param canvas
97 | */
98 | protected void drawIndicator(Canvas canvas) {
99 | if(isIndicateDisplay) {
100 | canvas.drawBitmap(mIndicatorBitmap, null, mIndicatorRect, null);
101 | }
102 | }
103 |
104 | @Override
105 | public void setText(int id) {
106 | setText(getContext().getResources().getText(id));
107 | measureText();
108 | }
109 |
110 | @Override
111 | public void setText(CharSequence text) {
112 | this.mText = (String) text;
113 | measureText();
114 | }
115 |
116 | @Override
117 | public void setSelectedColor(int selectedColor) {
118 | this.mSelectedColor = selectedColor;
119 | invalidateView();
120 | }
121 |
122 | @Override
123 | public void setUnselectedColor(int unselectedColor) {
124 | this.mUnselectedColor = unselectedColor;
125 | invalidateView();
126 | }
127 |
128 | @Override
129 | public void setTextSize(int textSize) {
130 | this.mTextSize = textSize;
131 | mTextPaint.setTextSize(mTextSize);
132 | measureText();
133 | }
134 |
135 | @Override
136 | public void setIndicatorSize(int indicatorSize) {
137 | this.mIndicatorSize = indicatorSize;
138 | }
139 |
140 | @Override
141 | public void setIndicatorBitmap(Bitmap bitmap) {
142 | this.mIndicatorBitmap = bitmap;
143 | }
144 |
145 | @Override
146 | public void setIndicatorBitmap(int resId) {
147 | this.mIndicatorBitmap = BitmapFactory.decodeResource(getResources(), resId);
148 | }
149 |
150 | @Override
151 | public abstract void setSelected(boolean selected);
152 |
153 | /**
154 | * 设置切换颜色渐变
155 | * @param alpha
156 | */
157 | protected void setIconAlpha(float alpha){}
158 |
159 | /**
160 | * 设置指示点的显示
161 | *
162 | * @param visible
163 | * 是否显示,如果false,则都不显示
164 | */
165 | public void setIndicateDisplay(boolean visible) {
166 | this.isIndicateDisplay = visible;
167 | }
168 |
169 | // 重新测量文本绘制范围
170 | private void measureText(){
171 | mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBound);
172 | }
173 |
174 | protected void invalidateView() {
175 | if (Looper.getMainLooper() == Looper.myLooper()) {
176 | invalidate();
177 | } else {
178 | postInvalidate();
179 | }
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/tabindicator/src/main/java/com/kevin/tabindicator/internal/TabIndicatorBase.java:
--------------------------------------------------------------------------------
1 | package com.kevin.tabindicator.internal;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Bitmap;
7 | import android.util.AttributeSet;
8 | import android.view.Gravity;
9 | import android.view.View;
10 | import android.widget.LinearLayout;
11 |
12 | import com.kevin.tabindicator.R;
13 |
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | /**
18 | * 版权所有:XXX有限公司
19 | *
20 | * TabIndicatorBase
21 | *
22 | * @author zhou.wenkai ,Created on 2016-2-25 21:15:04
23 | * Major Function:底部导航基类
24 | *
25 | * 注:如果您修改了本类请填写以下内容作为记录,如非本人操作劳烦通知,谢谢!!!
26 | * @author mender,Modified Date Modify Content:
27 | */
28 | public abstract class TabIndicatorBase extends LinearLayout {
29 |
30 | /** 底部菜单的文字数组 */
31 | protected CharSequence[] mLabels;
32 | /** 选中时颜色 */
33 | protected int mSelectedColor;
34 | /** 非选中时颜色 */
35 | protected int mUnselectedColor;
36 | /** 文本大小 */
37 | protected int mTextSize;
38 | /** 底部菜单padding */
39 | protected int mTabPadding;
40 | /** 指示点大小 */
41 | private int mIndicatorSize;
42 | /** 存放底部菜单 */
43 | protected List mCheckedList = new ArrayList<>();
44 | /** 回调接口,用于获取tab的选中状态 */
45 | protected OnTabSelectedListener mTabListener;
46 |
47 | public TabIndicatorBase(Context context, AttributeSet attrs) {
48 | super(context, attrs);
49 | init(context, attrs);
50 | }
51 |
52 | private void init(Context context, AttributeSet attrs) {
53 | setOrientation(LinearLayout.HORIZONTAL);
54 | setGravity(Gravity.CENTER);
55 |
56 | //Load defaults from resources
57 | final Resources res = getResources();
58 | final int defaultSelectedColor = res.getColor(R.color.default_tab_view_selected_color);
59 | final int defaultUnselectedColor = res.getColor(R.color.default_tab_view_unselected_color);
60 | final float defaultTextSize = res.getDimension(R.dimen.default_tab_view_text_size);
61 | final float defaultTabPadding = res.getDimension(R.dimen.default_tab_view_padding);
62 | final float defaultIndicatorSize = res.getDimension(R.dimen.default_tab_view_indicator_size);
63 |
64 | // Styleables from XML
65 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabIndicator);
66 |
67 | // 读取布局中,各个tab使用的文字
68 | if (a.hasValue(R.styleable.TabIndicator_tabLabels)) {
69 | mLabels = a.getTextArray(R.styleable.TabIndicator_tabLabels);
70 | }
71 |
72 | mSelectedColor = a.getColor(R.styleable.TabIndicator_tabSelectedColor, defaultSelectedColor);
73 | mUnselectedColor = a.getColor(R.styleable.TabIndicator_tabUnselectedColor, defaultUnselectedColor);
74 | mTextSize = (int) a.getDimension(R.styleable.TabIndicator_tabTextSize, defaultTextSize);
75 | mIndicatorSize = (int) a.getDimension(R.styleable.TabIndicator_TabIndicatorSize, defaultIndicatorSize);
76 | mTabPadding = (int) a.getDimension(R.styleable.TabIndicator_tabItemPadding, defaultTabPadding);
77 |
78 | handleStyledAttributes(a);
79 | a.recycle();
80 |
81 | initView();
82 | }
83 |
84 | /**
85 | * 初始化控件
86 | */
87 | private void initView() {
88 | LayoutParams params = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
89 | params.gravity = Gravity.CENTER;
90 |
91 | int size = getTabSize();
92 | for (int i = 0; i < size; i++) {
93 | final int index = i;
94 |
95 | T tabItemView = createTabView();
96 | tabItemView.setPadding(mTabPadding, mTabPadding, mTabPadding, mTabPadding);
97 | // 图标及文字
98 | if(null != mLabels) {
99 | tabItemView.setText(mLabels[index]);
100 | tabItemView.setTextSize(mTextSize);
101 | }
102 | tabItemView.setSelectedColor(mSelectedColor);
103 | tabItemView.setUnselectedColor(mUnselectedColor);
104 | tabItemView.setIndicatorSize(mIndicatorSize);
105 |
106 | setProperties(tabItemView, i);
107 |
108 | this.addView(tabItemView, params);
109 |
110 | tabItemView.setTag(index); // CheckedTextView设置索引作为tag,以便后续更改颜色、图片等
111 | mCheckedList.add(tabItemView); // 将CheckedTextView添加到list中,便于操作
112 | tabItemView.setOnClickListener(new OnClickListener() {
113 |
114 | @Override
115 | public void onClick(View v) {
116 | setTabsDisplay(index); // 设置底部图片和文字的显示
117 | if (null != mTabListener) {
118 | mTabListener.onTabSelected(index); // tab项被选中的回调事件
119 | }
120 | }
121 | });
122 |
123 | // 初始化 底部菜单选中状态,默认第一个选中
124 | if (i == 0) {
125 | tabItemView.setSelected(true);
126 | // tabItemView.setBackgroundColor(Color.rgb(240, 241, 242));
127 | } else {
128 | tabItemView.setSelected(false);
129 | // view.setBackgroundColor(Color.rgb(250, 250, 250));
130 | }
131 | }
132 | }
133 |
134 | /**
135 | * Allows Derivative classes to handle the XML Attrs without creating a
136 | * TypedArray themsevles
137 | *
138 | * @param a - TypedArray of TabIndicator Attributes
139 | */
140 | protected void handleStyledAttributes(TypedArray a) {
141 | }
142 |
143 | /**
144 | * 生成TabView
145 | * @return
146 | */
147 | protected abstract T createTabView();
148 |
149 | /**
150 | * 设置特殊属性
151 | * @param t
152 | */
153 | protected abstract void setProperties(T t, int index);
154 |
155 | /**
156 | * 获取条目个数
157 | * @return
158 | */
159 | protected abstract int getTabSize();
160 |
161 | /**
162 | * 设置底部导航中图片显示状态和字体颜色
163 | */
164 | public void setTabsDisplay(int index) {
165 | int size = mCheckedList.size();
166 | for (int i = 0; i < size; i++) {
167 | T mIconView = mCheckedList.get(i);
168 | if ((Integer) (mIconView.getTag()) == index) {
169 | mIconView.setSelected(true);
170 | // mCheckedList.get(i).setBackgroundColor(Color.rgb(240, 241, 242));
171 | } else {
172 | mIconView.setSelected(false);
173 | // mCheckedList.get(i).setBackgroundColor(Color.rgb(250, 250, 250));
174 | }
175 | }
176 | }
177 |
178 | /**
179 | * 设置指示点的显示
180 | *
181 | * @param position
182 | * 显示位置
183 | * @param visible
184 | * 是否显示,如果false,则都不显示
185 | */
186 | public void setIndicateDisplay(int position, boolean visible) {
187 | int size = mCheckedList.size();
188 | if (size <= position) {
189 | return;
190 | }
191 | T tabView = mCheckedList.get(position);
192 | tabView.setIndicateDisplay(visible);
193 | }
194 |
195 | /**
196 | * 设置指示点图片
197 | * @param bitmap
198 | */
199 | public void setIndicateBitmap(Bitmap bitmap) {
200 | for(T t : mCheckedList) {
201 | t.setIndicatorBitmap(bitmap);
202 | }
203 | }
204 |
205 | /**
206 | * 设置指示点图片
207 | * @param resId
208 | */
209 | public void setIndicateBitmap(int resId) {
210 | for(T t : mCheckedList) {
211 | t.setIndicatorBitmap(resId);
212 | }
213 | }
214 |
215 | /**
216 | * 设置定义选中tab的接口回调
217 | * @param listener
218 | */
219 | public void setOnTabSelectedListener(OnTabSelectedListener listener) {
220 | this.mTabListener = listener;
221 | }
222 |
223 | /**
224 | * 定义选中tab的接口
225 | */
226 | public interface OnTabSelectedListener {
227 | void onTabSelected(int index);
228 | }
229 |
230 | }
231 |
--------------------------------------------------------------------------------