├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.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
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── base_view.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── cheek
│ │ │ │ └── android
│ │ │ │ └── example
│ │ │ │ ├── BaseFragment.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ └── test
│ │ └── java
│ │ └── com
│ │ └── chaek
│ │ └── example
│ │ └── ExampleUnitTest.java
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ └── java
│ │ └── com
│ │ └── chaek
│ │ └── android
│ │ └── widget
│ │ └── CaterpillarIndicator.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── img
└── 1.gif
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------
/img/1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shallcheek/CaterpillarIndicator/HEAD/img/1.gif
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CaterpillarIndicator
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shallcheek/CaterpillarIndicator/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shallcheek/CaterpillarIndicator/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shallcheek/CaterpillarIndicator/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shallcheek/CaterpillarIndicator/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shallcheek/CaterpillarIndicator/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | /app/build/
11 | /.idea/
12 | /gradle/
13 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/chaek/example/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.chaek.example;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cheek/android/example/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.cheek.android.example;
2 |
3 | import android.os.Bundle;
4 | import androidx.annotation.Nullable;
5 | import androidx.fragment.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | /**
11 | * Created by W on 2017/2/3.
12 | */
13 |
14 | public class BaseFragment extends Fragment {
15 | @Nullable
16 | @Override
17 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
18 | return View.inflate(getContext(), R.layout.base_view, null);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/base_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/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 E:\androidsdk\android-sdk_r24.4.1-windows\android-sdk-windows/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 |
--------------------------------------------------------------------------------
/library/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 E:\androidsdk\android-sdk_r24.4.1-windows\android-sdk-windows/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 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Fri Feb 03 09:52:52 CST 2017
16 | android.enableJetifier=true
17 | android.useAndroidX=true
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android-extensions'
3 | apply plugin: 'kotlin-android'
4 |
5 | android {
6 | compileSdkVersion 29
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 29
10 | versionCode 1
11 | versionName "1.3.0"
12 | }
13 |
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | lintOptions {
21 | abortOnError false
22 | }
23 | }
24 |
25 |
26 | dependencies {
27 | implementation fileTree(include: ['*.jar'], dir: 'libs')
28 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
29 | implementation "androidx.core:core-ktx:1.1.0"
30 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
31 | }
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CaterpillarIndicator
2 | 类似毛毛虫爬动的ViewPage指示器,参考新浪微博滑动效果实现
3 |
4 | ## Gradle
5 | ```java
6 | dependencies{
7 | implementation 'com.chaek.android:caterpillarindicator:1.3.0'
8 | }
9 | ```
10 |
11 | ## XML
12 | ```xml
13 |
28 |
29 | ```
30 | ## Demo
31 |
32 |
33 | 
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android-extensions'
3 | apply plugin: 'kotlin-android'
4 |
5 | android {
6 | compileSdkVersion 29
7 | defaultConfig {
8 | applicationId "com.chaek.android"
9 | minSdkVersion 15
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | lintOptions {
22 | abortOnError false
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(include: ['*.jar'], dir: 'libs')
28 |
29 | implementation 'androidx.appcompat:appcompat:1.1.0'
30 | implementation 'com.chaek.android:caterpillarindicator:1.3.0'
31 |
32 | testImplementation 'junit:junit:4.12'
33 | // implementation project(path: ':library')
34 | implementation "androidx.core:core-ktx:1.1.0"
35 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
36 |
37 | }
38 | repositories {
39 | mavenCentral()
40 | }
41 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CaterpillarIndicator
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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
30 |
31 |
36 |
37 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cheek/android/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.cheek.android.example;
2 |
3 | import androidx.fragment.app.Fragment;
4 | import androidx.fragment.app.FragmentManager;
5 | import androidx.fragment.app.FragmentStatePagerAdapter;
6 | import androidx.viewpager.widget.ViewPager;
7 | import androidx.appcompat.app.AppCompatActivity;
8 | import android.os.Bundle;
9 | import android.view.View;
10 | import android.widget.RelativeLayout;
11 |
12 | import com.chaek.android.widget.CaterpillarIndicator;
13 |
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | public class MainActivity extends AppCompatActivity {
18 | private RelativeLayout activityMain;
19 | private CaterpillarIndicator titleBar;
20 | private ViewPager viewpage;
21 |
22 | private List fragmentList = new ArrayList<>();
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_main);
28 |
29 |
30 | titleBar = (CaterpillarIndicator) findViewById(R.id.title_bar);
31 | viewpage = (ViewPager) findViewById(R.id.viewpage);
32 |
33 | fragmentList.add(new BaseFragment());
34 | fragmentList.add(new BaseFragment());
35 | fragmentList.add(new BaseFragment());
36 | fragmentList.add(new BaseFragment());
37 | BaseFragmentAdapter adapter = new BaseFragmentAdapter(getSupportFragmentManager());
38 | viewpage.setAdapter(adapter);
39 | viewpage.setOnClickListener(new View.OnClickListener() {
40 | @Override
41 | public void onClick(View v) {
42 | // titleBar.setTextColorSelected(getResources().getColor(R.color.colorPrimary));
43 | }
44 | });
45 | List titleInfos = new ArrayList<>();
46 | titleInfos.add(new CaterpillarIndicator.TitleInfo("热门"));
47 | titleInfos.add(new CaterpillarIndicator.TitleInfo("榜单"));
48 | titleInfos.add(new CaterpillarIndicator.TitleInfo("视频"));
49 | titleInfos.add(new CaterpillarIndicator.TitleInfo("头条"));
50 | titleBar.init(0, titleInfos, viewpage);
51 |
52 | // titleBar.setFooterLineHeight(3);
53 | // titleBar.setItemLineWidth(40);
54 | //
55 | // titleBar.setTextSizeSelected(18);
56 |
57 | }
58 |
59 | private class BaseFragmentAdapter extends FragmentStatePagerAdapter {
60 |
61 | public BaseFragmentAdapter(FragmentManager fm) {
62 | super(fm);
63 | }
64 |
65 | @Override
66 | public Fragment getItem(int position) {
67 | return fragmentList.get(position);
68 | }
69 |
70 | @Override
71 | public int getCount() {
72 | return fragmentList != null ? fragmentList.size() : 0;
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/library/src/main/java/com/chaek/android/widget/CaterpillarIndicator.kt:
--------------------------------------------------------------------------------
1 | package com.chaek.android.widget
2 |
3 | import android.animation.Animator
4 | import android.animation.AnimatorListenerAdapter
5 | import android.animation.ValueAnimator
6 | import android.content.Context
7 | import android.content.res.Resources
8 | import android.graphics.Canvas
9 | import android.graphics.Paint
10 | import android.graphics.RectF
11 | import android.graphics.Typeface
12 | import android.util.AttributeSet
13 | import android.util.TypedValue
14 | import android.view.Gravity
15 | import android.view.View
16 | import android.view.ViewGroup
17 | import android.widget.LinearLayout
18 | import android.widget.TextView
19 | import androidx.annotation.ArrayRes
20 | import androidx.core.view.ViewCompat
21 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator
22 | import androidx.viewpager.widget.ViewPager
23 | import androidx.viewpager.widget.ViewPager.OnPageChangeListener
24 | import com.chaek.android.caterpillarindicator.R
25 | import java.util.*
26 | import kotlin.math.abs
27 | import kotlin.math.roundToInt
28 |
29 | open class CaterpillarIndicator @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs), View.OnClickListener, OnPageChangeListener {
30 | private var isRoundRectangleLine = true
31 | private var isCaterpillar = true
32 | private var mFootLineColor: Int
33 | private var mTextSizeNormal: Int
34 | private var mTextSizeSelected: Int
35 | private var mTextColorNormal: Int
36 | private var mTextColorSelected: Int
37 | private var mFooterLineHeight: Int
38 | private var mItemLineWidth: Int
39 | /**
40 | * item count
41 | */
42 | private var mItemCount = 0
43 | private var textCenterFlag: Int
44 | private var textFont: Int
45 | private var mCurrentScroll = 0
46 | private var mSelectedTab = 0
47 | private var linePaddingBottom = 0
48 | private var isClickEvent = false
49 | private var mTitles: List? = null
50 | private var mViewPager: ViewPager? = null
51 | /**
52 | * line paint
53 | */
54 | private var mPaintFooterLine: Paint? = null
55 | /**
56 | * line RectF
57 | */
58 | private var drawLineRect: RectF? = null
59 | private var startLeft = 0
60 | private var targetLeft = 0
61 | private var startRight = 0
62 | private var targetRight = 0
63 | private var indicatorLeft = 0
64 | private var indicatorRight = 0
65 | private var animator: ValueAnimator? = null
66 | /**
67 | * set foot line height
68 | *
69 | * @param mFooterLineHeight foot line height (int)
70 | */
71 | fun setFooterLineHeight(mFooterLineHeight: Int) {
72 | this.mFooterLineHeight = dip2px(mFooterLineHeight.toFloat())
73 | invalidate()
74 | }
75 |
76 | fun setLinePaddingBottom(paddingBottom: Int) {
77 | linePaddingBottom = paddingBottom
78 | invalidate()
79 | }
80 |
81 | fun setTextCenterFlag(centerFlag: Int) {
82 | textCenterFlag = centerFlag
83 | invalidate()
84 | }
85 |
86 | /**
87 | * item width
88 | *
89 | * @param mItemLineWidth item width(dp)
90 | */
91 | fun setItemLineWidth(mItemLineWidth: Int) {
92 | this.mItemLineWidth = dip2px(mItemLineWidth.toFloat())
93 | invalidate()
94 | }
95 |
96 | fun setCaterpillar(caterpillar: Boolean) {
97 | isCaterpillar = caterpillar
98 | invalidate()
99 | }
100 |
101 | /**
102 | * is round line
103 | *
104 | * @param roundRectangleLine true (yes) false (no )
105 | */
106 | fun setRoundRectangleLine(roundRectangleLine: Boolean) {
107 | isRoundRectangleLine = roundRectangleLine
108 | }
109 |
110 | private fun initDraw() {
111 | mPaintFooterLine = Paint()
112 | mPaintFooterLine!!.isAntiAlias = true
113 | mPaintFooterLine!!.style = Paint.Style.FILL
114 | drawLineRect = RectF(0f, 0f, 0f, 0f)
115 | }
116 |
117 | fun setFootLineColor(mFootLineColor: Int) {
118 | this.mFootLineColor = mFootLineColor
119 | invalidate()
120 | }
121 |
122 | /**
123 | * set text normal size(dp)
124 | *
125 | * @param mTextSizeNormal normal text size
126 | */
127 | fun setTextSizeNormal(mTextSizeNormal: Int) {
128 | this.mTextSizeNormal = dip2px(mTextSizeNormal.toFloat())
129 | updateItemText()
130 | }
131 |
132 | fun setTextSizeSelected(mTextSizeSelected: Int) {
133 | this.mTextSizeSelected = dip2px(mTextSizeSelected.toFloat())
134 | updateItemText()
135 | }
136 |
137 | fun setTextColorNormal(mTextColorNormal: Int) {
138 | this.mTextColorNormal = mTextColorNormal
139 | updateItemText()
140 | }
141 |
142 | fun setTextColorSelected(mTextColorSelected: Int) {
143 | this.mTextColorSelected = mTextColorSelected
144 | updateItemText()
145 | }
146 |
147 | private fun updateItemText() {
148 | for (i in 0 until childCount) {
149 | val v = getChildAt(i)
150 | if (v is TextView) {
151 | if (v.isSelected) {
152 | v.setTextColor(mTextColorSelected)
153 | v.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSizeSelected.toFloat())
154 | } else {
155 | v.setTextColor(mTextColorNormal)
156 | v.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSizeNormal.toFloat())
157 | }
158 | }
159 | }
160 | }
161 |
162 | private fun dip2px(dpValue: Float): Int {
163 | val scale = Resources.getSystem().displayMetrics.density
164 | return (dpValue * scale + 0.5f).toInt()
165 | }
166 |
167 | fun lerp(startValue: Int, endValue: Int, fraction: Float): Int {
168 | return startValue + (fraction * (endValue - startValue).toFloat()).roundToInt()
169 | }
170 |
171 | override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
172 | val a = width.toFloat() / mViewPager!!.width.toFloat()
173 | onScrolledPositionOffset(((width + mViewPager!!.pageMargin) * position + positionOffsetPixels * a).toInt())
174 | }
175 |
176 | override fun onPageSelected(position: Int) {
177 | onSwitched(position)
178 | }
179 |
180 | override fun onPageScrollStateChanged(state: Int) {}
181 |
182 | @Synchronized
183 | fun onSwitched(position: Int) {
184 | if (mSelectedTab == position) {
185 | return
186 | }
187 | restTextStatus(mSelectedTab, position)
188 | if (isClickEvent) {
189 | updatePositionAnimate(mSelectedTab, position)
190 | }
191 | mSelectedTab = position
192 | }
193 |
194 | /**
195 | * @param startPosition 上一个position
196 | * @param newPosition 结束的position
197 | */
198 | private fun updatePositionAnimate(startPosition: Int, newPosition: Int) {
199 | if (animator != null && animator!!.isRunning) {
200 | animator!!.cancel()
201 | }
202 | val cursorWidth = width / mItemCount
203 | mItemLineWidth = if (mItemLineWidth > cursorWidth) cursorWidth else mItemLineWidth
204 | startLeft = cursorWidth * startPosition + (cursorWidth - mItemLineWidth) / 2
205 | startRight = startLeft + mItemLineWidth
206 | targetLeft = cursorWidth * newPosition + (cursorWidth - mItemLineWidth) / 2
207 | targetRight = targetLeft + mItemLineWidth
208 | animator = ValueAnimator.ofFloat(0.0f, 1.0f)
209 | animator?.interpolator = FastOutSlowInInterpolator()
210 | animator?.duration = 300
211 | animator?.addUpdateListener { animation ->
212 | val fraction = animation.animatedFraction
213 | setIndicatorPosition(lerp(startLeft, targetLeft, fraction), lerp(startRight, targetRight, fraction))
214 | }
215 | animator?.addListener(object : AnimatorListenerAdapter() {
216 | override fun onAnimationEnd(animator: Animator) {
217 | isClickEvent = false
218 | }
219 | })
220 | animator?.start()
221 | }
222 |
223 | private fun setIndicatorPosition(left: Int, right: Int) {
224 | indicatorLeft = left
225 | indicatorRight = right
226 | ViewCompat.postInvalidateOnAnimation(this)
227 | }
228 |
229 | private fun onScrolledPositionOffset(offset: Int) {
230 | if (isClickEvent) {
231 | return
232 | }
233 | mCurrentScroll = offset
234 | val scrollX: Float
235 | val cursorWidth: Int
236 | if (mItemCount != 0) {
237 | cursorWidth = width / mItemCount
238 | scrollX = (mCurrentScroll - mSelectedTab * width) / mItemCount.toFloat()
239 | } else {
240 | cursorWidth = width
241 | scrollX = mCurrentScroll.toFloat()
242 | }
243 | mItemLineWidth = if (mItemLineWidth > cursorWidth) cursorWidth else mItemLineWidth
244 | val mItemLeft: Int
245 | val mItemRight: Int
246 | if (mItemLineWidth < cursorWidth) {
247 | mItemLeft = (cursorWidth - mItemLineWidth) / 2
248 | mItemRight = cursorWidth - mItemLeft
249 | } else {
250 | mItemLeft = 0
251 | mItemRight = cursorWidth
252 | }
253 | var leftX = 0
254 | var rightX = 0
255 | val isHalf = abs(scrollX) < cursorWidth / 2
256 | if (isCaterpillar) {
257 | if (scrollX < 0) {
258 | if (isHalf) {
259 | leftX = (mSelectedTab * cursorWidth + scrollX * 2 + mItemLeft).toInt()
260 | rightX = mSelectedTab * cursorWidth + mItemRight
261 | } else { //点击
262 | leftX = (mSelectedTab - 1) * cursorWidth + mItemLeft
263 | rightX = (mSelectedTab * cursorWidth + mItemRight + (scrollX + cursorWidth / 2) * 2).toInt()
264 | }
265 | } else if (scrollX > 0) {
266 | if (isHalf) {
267 | leftX = mSelectedTab * cursorWidth + mItemLeft
268 | rightX = (mSelectedTab * cursorWidth + mItemRight + scrollX * 2).toInt()
269 | } else {
270 | leftX = (mSelectedTab * cursorWidth + mItemLeft + (scrollX - cursorWidth / 2) * 2).toInt()
271 | rightX = (mSelectedTab + 1) * cursorWidth + mItemRight
272 | }
273 | } else {
274 | leftX = mSelectedTab * cursorWidth + mItemLeft
275 | rightX = mSelectedTab * cursorWidth + mItemRight
276 | }
277 | } else {
278 | leftX = (mSelectedTab * cursorWidth + scrollX + mItemLeft).toInt()
279 | rightX = (mSelectedTab * cursorWidth + scrollX + mItemRight).toInt()
280 | }
281 |
282 | setIndicatorPosition(leftX, rightX)
283 | }
284 |
285 |
286 | override fun onDraw(canvas: Canvas) {
287 | super.onDraw(canvas)
288 | mPaintFooterLine!!.color = mFootLineColor
289 | val bottomY = height - paddingBottom - linePaddingBottom.toFloat()
290 | //set foot line height
291 | val topY = bottomY - mFooterLineHeight
292 | drawLineRect!!.left = indicatorLeft.toFloat()
293 | drawLineRect!!.right = indicatorRight.toFloat()
294 | drawLineRect!!.bottom = bottomY
295 | drawLineRect!!.top = topY
296 | val roundXY = if (isRoundRectangleLine) mFooterLineHeight / 2 else 0
297 | canvas.drawRoundRect(drawLineRect!!, roundXY.toFloat(), roundXY.toFloat(), mPaintFooterLine!!)
298 | }
299 |
300 | /**
301 | * init indication
302 | *
303 | * @param startPosition init select pos
304 | * @param tabs title list
305 | * @param mViewPager ViewPage
306 | */
307 | fun init(startPosition: Int, tabs: List, mViewPager: ViewPager) {
308 | removeAllViews()
309 | mSelectedTab = startPosition
310 | this.mViewPager = mViewPager
311 | this.mViewPager!!.addOnPageChangeListener(this)
312 | mTitles = tabs
313 | mItemCount = tabs.size
314 | weightSum = mItemCount.toFloat()
315 | if (mSelectedTab > tabs.size) {
316 | mSelectedTab = tabs.size
317 | }
318 | for (i in 0 until mItemCount) {
319 | add(tabs[i].name, i)
320 | }
321 | mViewPager.currentItem = mSelectedTab
322 | invalidate()
323 | requestLayout()
324 | }
325 |
326 | fun initTitle(mViewPager: ViewPager, list: List) {
327 | val len = list.size
328 | val tabs: MutableList = ArrayList()
329 | if (len > 0) {
330 | for (aList in list) {
331 | tabs.add(TitleInfo(aList))
332 | }
333 | }
334 | init(0, tabs, mViewPager)
335 | }
336 |
337 | fun initTitle(mViewPager: ViewPager, vararg list: String?) {
338 | val len = list.size
339 | val tabs: MutableList = ArrayList()
340 | if (len > 0) {
341 | for (aList in list) {
342 | tabs.add(TitleInfo(aList))
343 | }
344 | }
345 | init(mViewPager.currentItem, tabs, mViewPager)
346 | }
347 |
348 | fun initTitle(mViewPager: ViewPager, @ArrayRes titleList: Int) {
349 | val list = resources.getStringArray(titleList)
350 | val len = list.size
351 | val tabs: MutableList = ArrayList()
352 | if (len > 0) {
353 | for (aList in list) {
354 | tabs.add(TitleInfo(aList))
355 | }
356 | }
357 | init(mViewPager.currentItem, tabs, mViewPager)
358 | }
359 |
360 | fun initTitle(mViewPager: ViewPager, vararg list: Int) {
361 | val len = list.size
362 | val tabs: MutableList = ArrayList()
363 | if (len > 0) {
364 | for (aList in list) {
365 | tabs.add(TitleInfo(context.getString(aList)))
366 | }
367 | }
368 | init(mViewPager.currentItem, tabs, mViewPager)
369 | }
370 |
371 | private fun add(label: String?, position: Int) {
372 | val text = TextView(context)
373 | val params = LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1f)
374 | text.gravity = Gravity.CENTER
375 | text.layoutParams = params
376 | if (textCenterFlag == LINE_CENTER) {
377 | text.setPadding(0, 0, 0, linePaddingBottom)
378 | }
379 | if (textFont == FONT_BOLD) {
380 | text.typeface = Typeface.DEFAULT_BOLD
381 | }
382 | text.text = label
383 | setTabTextSize(text, position == mSelectedTab)
384 | text.id = BASE_ID + position
385 | text.setOnClickListener(this)
386 | addView(text)
387 | }
388 |
389 | override fun onClick(v: View) {
390 | val position = v.id - BASE_ID
391 | isClickEvent = true
392 | updatePositionAnimate(mSelectedTab, position)
393 | setCurrentTab(position)
394 | mViewPager!!.currentItem = position
395 | }
396 |
397 | /**
398 | * get title list size
399 | *
400 | * @return list size
401 | */
402 | private val titleCount: Int
403 | get() = if (mTitles != null) mTitles!!.size else 0
404 |
405 | private fun restTextStatus(oldPosition: Int, newPosition: Int) {
406 | if (oldPosition == newPosition) {
407 | return
408 | }
409 | for (i in 0 until childCount) {
410 | val v = getChildAt(i)
411 | if (v is TextView) {
412 | setTabTextSize(v, i == newPosition)
413 | v.isSelected = i == newPosition
414 | }
415 | }
416 | }
417 |
418 | @Synchronized
419 | fun setCurrentTab(index: Int) {
420 | if (index < 0 || index >= titleCount) {
421 | return
422 | }
423 | restTextStatus(mSelectedTab, index)
424 | mSelectedTab = index
425 | }
426 |
427 | /**
428 | * set select textView textSize&textColor state
429 | *
430 | * @param tab TextView
431 | * @param selected is Select
432 | */
433 | private fun setTabTextSize(tab: View, selected: Boolean) {
434 | if (tab is TextView) {
435 | tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, if (selected) mTextSizeSelected.toFloat() else mTextSizeNormal.toFloat())
436 | tab.setTextColor(if (selected) mTextColorSelected else mTextColorNormal)
437 | tab.typeface = if (textFont == FONT_NORMAL || textFont == FONT_SELECT_BOLD && !selected) Typeface.DEFAULT else Typeface.DEFAULT_BOLD
438 | }
439 | }
440 |
441 | override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
442 | super.onLayout(changed, l, t, r, b)
443 | if (mCurrentScroll == 0 && mSelectedTab != 0) {
444 | mCurrentScroll = (width + mViewPager!!.pageMargin) * mSelectedTab
445 | }
446 | }
447 |
448 | /**
449 | * title
450 | */
451 | class TitleInfo(var name: String?)
452 |
453 | companion object {
454 | private const val TAG = "CaterpillarIndicator"
455 | private const val BASE_ID = 0xffff00
456 | private const val FOOTER_COLOR = -0x3bbb
457 | private const val ITEM_TEXT_COLOR_NORMAL = -0x666667
458 | private const val ITEM_TEXT_COLOR_SELECT = -0x3bbb
459 | private const val TEXT_CENTER = 0
460 | private const val LINE_CENTER = 1
461 |
462 | private const val FONT_NORMAL = 0
463 | private const val FONT_SELECT_BOLD = 1
464 | private const val FONT_BOLD = 2
465 | }
466 |
467 | init {
468 | isFocusable = true
469 | val a = context.obtainStyledAttributes(attrs, R.styleable.CaterpillarIndicator)
470 | mFootLineColor = a.getColor(R.styleable.CaterpillarIndicator_slide_footer_color, FOOTER_COLOR)
471 | mTextSizeNormal = a.getDimensionPixelSize(R.styleable.CaterpillarIndicator_slide_text_size_normal, dip2px(12f))
472 | mTextSizeSelected = a.getDimensionPixelSize(R.styleable.CaterpillarIndicator_slide_text_size_selected, dip2px(mTextSizeNormal.toFloat()))
473 | mFooterLineHeight = a.getDimensionPixelOffset(R.styleable.CaterpillarIndicator_slide_footer_line_height, dip2px(3f))
474 | mTextColorSelected = a.getColor(R.styleable.CaterpillarIndicator_slide_text_color_selected, ITEM_TEXT_COLOR_SELECT)
475 | mTextColorNormal = a.getColor(R.styleable.CaterpillarIndicator_slide_text_color_normal, ITEM_TEXT_COLOR_NORMAL)
476 | isCaterpillar = a.getBoolean(R.styleable.CaterpillarIndicator_slide_caterpillar, true)
477 | isRoundRectangleLine = a.getBoolean(R.styleable.CaterpillarIndicator_slide_round, true)
478 | mItemLineWidth = a.getDimension(R.styleable.CaterpillarIndicator_slide_item_width, dip2px(24f).toFloat()).toInt()
479 | linePaddingBottom = a.getDimension(R.styleable.CaterpillarIndicator_slide_padding_bottom, 0f).toInt()
480 | textCenterFlag = a.getInt(R.styleable.CaterpillarIndicator_slide_text_center_flag, TEXT_CENTER)
481 | textFont = a.getInt(R.styleable.CaterpillarIndicator_slide_text_font, FONT_NORMAL)
482 | setWillNotDraw(false)
483 | initDraw()
484 | a.recycle()
485 | }
486 | }
--------------------------------------------------------------------------------