├── .gitignore ├── .idea ├── caches │ ├── build_file_checksums.ser │ └── gradle_models.ser ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── AndroidRubberIndicator.iml ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── library.iml ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── me │ │ └── liangfei │ │ └── indicator │ │ ├── CircleView.java │ │ └── RubberIndicator.java │ └── res │ ├── drawable │ └── indicator_background.xml │ ├── layout │ └── rubber_indicator.xml │ └── values │ ├── attrs_rubberindicator.xml │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── sample.iml └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── me │ │ └── liangfei │ │ └── rubberindicator │ │ └── MainActivity.java │ └── res │ ├── drawable │ └── indicator_background.xml │ ├── layout │ └── activity_main.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liangfeidotme/AndroidRubberIndicator/32c6bae8ccb5d7acb34ff572f9a9a2b9fca8c494/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/caches/gradle_models.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liangfeidotme/AndroidRubberIndicator/32c6bae8ccb5d7acb34ff572f9a9a2b9fca8c494/.idea/caches/gradle_models.ser -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AndroidRubberIndicator.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 liangfei 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RubberIndicator 2 | 3 | [![Join the chat at https://gitter.im/LyndonChin/AndroidRubberIndicator](https://badges.gitter.im/LyndonChin/AndroidRubberIndicator.svg)](https://gitter.im/LyndonChin/AndroidRubberIndicator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | 6 | 7 | A rubber indicator for ViewPager 8 | 9 | 10 | 11 | * Designed by [Valentyn Khenkin](https://dribbble.com/shots/2090803-Rubber-Indicator?list=searches&tag=indicator&offset=7) 12 | * [Here](http://codepen.io/machycek/full/eNvyjb/) is the CSS version 13 | 14 | ## Usage 15 | 16 | The attributes for `RubberIndicator` are not yet finished. 17 | A toy example is provided in [sample](sample/src/main/java/com/liangfeizc/rubberindicator/MainActivity.java). 18 | 19 | ## Introduction 20 | 21 | APIs offered by **RubberIndicator**. 22 | 23 | |APIs | Usage| 24 | |---|---| 25 | |setCount(int count)|Set the count of indicators| 26 | |setCount(int count, int focusPos)|Set the count and specify the focusing indicator| 27 | |setFocusPosition(int pos)|Set focusing indicator| 28 | |getFocusPosition()|Get focusing indicator| 29 | |moveToLeft()|Move the focusing indicator to left| 30 | |moveToRight()|Move the focusing indicator to right| 31 | 32 | In addition to the APIs listed in the table, **RubberIndicator** also provides a callback listener - **OnMoveListener** for the user should be notified when the moving animator finished. 33 | 34 | ```java 35 | public interface OnMoveListener { 36 | void onMovedToLeft(); 37 | void onMovedToRight(); 38 | } 39 | ``` 40 | 41 | ## Me 42 | 43 | * [weibo](http://weibo.com/liangfeizc) 44 | * [twitter](https://twitter.com/JpRyouhi) 45 | 46 | ## License 47 | 48 | MIT 49 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.4.0' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | google() 19 | jcenter() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /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: -Xmx10248m -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 | #Sat Jul 04 08:26:51 CST 2015 16 | android.enableJetifier=true 17 | android.useAndroidX=true 18 | systemProp.http.proxyHost=127.0.0.1 19 | systemProp.http.proxyPort=1080 20 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liangfeidotme/AndroidRubberIndicator/32c6bae8ccb5d7acb34ff572f9a9a2b9fca8c494/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 26 00:48:42 CST 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-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | defaultConfig { 7 | minSdkVersion 15 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | } 12 | buildTypes { 13 | release { 14 | minifyEnabled false 15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 16 | } 17 | } 18 | } 19 | 20 | dependencies { 21 | implementation fileTree(dir: 'libs', include: ['*.jar']) 22 | implementation 'androidx.appcompat:appcompat:1.0.0' 23 | } 24 | -------------------------------------------------------------------------------- /library/library.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 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 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /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 /Users/rufi/Library/Android/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 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /library/src/main/java/me/liangfei/indicator/CircleView.java: -------------------------------------------------------------------------------- 1 | package me.liangfei.indicator; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.Paint; 8 | import android.graphics.PointF; 9 | import android.util.AttributeSet; 10 | import android.view.View; 11 | 12 | /** 13 | * Created by liangfeizc on 6/26/15. 14 | */ 15 | class CircleView extends View { 16 | private static final int DEFAULT_COLOR = Color.BLACK; 17 | 18 | private int mColor; 19 | private float mRadius; 20 | private float mCenterX; 21 | private float mCenterY; 22 | 23 | private Paint mPaint; 24 | 25 | public CircleView(Context context) { 26 | this(context, null); 27 | } 28 | 29 | public CircleView(Context context, AttributeSet attrs) { 30 | this(context, attrs, 0); 31 | } 32 | 33 | public CircleView(Context context, AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleView); 36 | try { 37 | mColor = a.getColor(R.styleable.CircleView_cv_color, DEFAULT_COLOR); 38 | } finally { 39 | a.recycle(); 40 | } 41 | init(); 42 | } 43 | 44 | private void init() { 45 | mPaint = new Paint(); 46 | mPaint.setAntiAlias(true); 47 | mPaint.setColor(mColor); 48 | mPaint.setStrokeWidth(1); 49 | mPaint.setStyle(Paint.Style.FILL_AND_STROKE); 50 | } 51 | 52 | @Override 53 | protected void onDraw(Canvas canvas) { 54 | super.onDraw(canvas); 55 | canvas.drawCircle(mCenterX, mCenterY, mRadius - 5, mPaint); 56 | } 57 | 58 | @Override 59 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 60 | super.onLayout(changed, left, top, right, bottom); 61 | mCenterX = (right - left) / 2; 62 | mCenterY = (bottom - top) / 2; 63 | 64 | mRadius = Math.min(mCenterX, mCenterY); 65 | } 66 | 67 | public void setColor(final int colorValue) { 68 | mPaint.setColor(colorValue); 69 | invalidate(); 70 | } 71 | 72 | public PointF getCenter() { 73 | return new PointF(getX() + getWidth() / 2, getY() + getHeight() / 2); 74 | } 75 | 76 | public void setCenter(final PointF center) { 77 | setCenter(center.x, center.y); 78 | } 79 | 80 | public void setCenter(float cx, float cy) { 81 | setX(cx - getWidth() / 2); 82 | setY(cy - getHeight() / 2); 83 | } 84 | 85 | public void setRadius(final float radius) { 86 | mRadius = radius; 87 | invalidate(); 88 | } 89 | 90 | public float getRadius() { 91 | return mRadius; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /library/src/main/java/me/liangfei/indicator/RubberIndicator.java: -------------------------------------------------------------------------------- 1 | package me.liangfei.indicator; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorSet; 5 | import android.animation.ObjectAnimator; 6 | import android.animation.PropertyValuesHolder; 7 | import android.animation.ValueAnimator; 8 | import android.annotation.TargetApi; 9 | import android.content.Context; 10 | import android.content.res.TypedArray; 11 | import android.graphics.Path; 12 | import android.graphics.PathMeasure; 13 | import android.graphics.PointF; 14 | import android.graphics.drawable.GradientDrawable; 15 | import android.os.Build; 16 | import android.util.AttributeSet; 17 | import android.view.Gravity; 18 | import android.view.View; 19 | import android.view.ViewGroup; 20 | import android.view.animation.AccelerateDecelerateInterpolator; 21 | import android.widget.LinearLayout; 22 | import android.widget.RelativeLayout; 23 | 24 | import java.util.ArrayList; 25 | import java.util.LinkedList; 26 | import java.util.List; 27 | 28 | /** 29 | * Created by liangfeizc on 6/28/15. 30 | */ 31 | public class RubberIndicator extends RelativeLayout { 32 | private static final String TAG = "RubberIndicator"; 33 | 34 | private static final int DEFAULT_SMALL_CIRCLE_COLOR = 0xFFDF8D81; 35 | private static final int DEFAULT_LARGE_CIRCLE_COLOR = 0xFFAF3854; 36 | private static final int DEFAULT_OUTER_CIRCLE_COLOR = 0xFF533456; 37 | 38 | private static final int SMALL_CIRCLE_RADIUS = 20; 39 | private static final int LARGE_CIRCLE_RADIUS = 25; 40 | private static final int OUTER_CIRCLE_RADIUS = 50; 41 | 42 | private static final int BEZIER_CURVE_ANCHOR_DISTANCE = 30; 43 | 44 | private static final int CIRCLE_TYPE_SMALL = 0x00; 45 | private static final int CIRCLE_TYPE_LARGE = 0x01; 46 | private static final int CIRCLE_TYPE_OUTER = 0x02; 47 | 48 | /** 49 | * colors 50 | */ 51 | private int mSmallCircleColor; 52 | private int mLargeCircleColor; 53 | private int mOuterCircleColor; 54 | 55 | /** 56 | * coordinate values 57 | */ 58 | private int mSmallCircleRadius; 59 | private int mLargeCircleRadius; 60 | private int mOuterCircleRadius; 61 | 62 | /** 63 | * views 64 | */ 65 | private LinearLayout mContainer; 66 | private CircleView mLargeCircle; 67 | private CircleView mSmallCircle; 68 | private CircleView mOuterCircle; 69 | private List mCircleViews; 70 | 71 | /** 72 | * animations 73 | */ 74 | private AnimatorSet mAnim; 75 | private PropertyValuesHolder mPvhScaleX; 76 | private PropertyValuesHolder mPvhScaleY; 77 | private PropertyValuesHolder mPvhScale; 78 | private PropertyValuesHolder mPvhRotation; 79 | 80 | private LinkedList mPendingAnimations; 81 | 82 | /** 83 | * Movement Path 84 | */ 85 | private Path mSmallCirclePath; 86 | 87 | /** 88 | * Indicator movement listener 89 | */ 90 | private OnMoveListener mOnMoveListener; 91 | 92 | /** 93 | * Helper values 94 | */ 95 | private int mFocusPosition = -1; 96 | private int mBezierCurveAnchorDistance = dp2px(BEZIER_CURVE_ANCHOR_DISTANCE); 97 | 98 | public RubberIndicator(Context context) { 99 | super(context); 100 | init(null, 0); 101 | } 102 | 103 | public RubberIndicator(Context context, AttributeSet attrs) { 104 | super(context, attrs); 105 | init(attrs, 0); 106 | } 107 | 108 | public RubberIndicator(Context context, AttributeSet attrs, int defStyleAttr) { 109 | super(context, attrs, defStyleAttr); 110 | init(attrs, defStyleAttr); 111 | } 112 | 113 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 114 | public RubberIndicator(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 115 | super(context, attrs, defStyleAttr, defStyleRes); 116 | init(attrs, defStyleAttr); 117 | } 118 | 119 | private void init(AttributeSet attrs, int defStyle) { 120 | /** Get XML attributes */ 121 | final TypedArray styledAttributes = getContext().obtainStyledAttributes(attrs, R.styleable.RubberIndicator, defStyle, 0); 122 | mSmallCircleColor = styledAttributes.getColor(R.styleable.RubberIndicator_smallCircleColor, DEFAULT_SMALL_CIRCLE_COLOR); 123 | mLargeCircleColor = styledAttributes.getColor(R.styleable.RubberIndicator_largeCircleColor, DEFAULT_LARGE_CIRCLE_COLOR); 124 | mOuterCircleColor = styledAttributes.getColor(R.styleable.RubberIndicator_outerCircleColor, DEFAULT_OUTER_CIRCLE_COLOR); 125 | styledAttributes.recycle(); 126 | 127 | /** Initialize views */ 128 | View rootView = inflate(getContext(), R.layout.rubber_indicator, this); 129 | mContainer = (LinearLayout) rootView.findViewById(R.id.container); 130 | mOuterCircle = (CircleView) rootView.findViewById(R.id.outer_circle); 131 | 132 | // Apply outer color to outerCircle and background shape 133 | View containerWrapper = rootView.findViewById(R.id.container_wrapper); 134 | mOuterCircle.setColor(mOuterCircleColor); 135 | GradientDrawable shape = (GradientDrawable) containerWrapper.getBackground(); 136 | shape.setColor(mOuterCircleColor); 137 | 138 | /** values */ 139 | mSmallCircleRadius = dp2px(SMALL_CIRCLE_RADIUS); 140 | mLargeCircleRadius = dp2px(LARGE_CIRCLE_RADIUS); 141 | mOuterCircleRadius = dp2px(OUTER_CIRCLE_RADIUS); 142 | 143 | /** animators */ 144 | mPvhScaleX = PropertyValuesHolder.ofFloat("scaleX", 1, 0.8f, 1); 145 | mPvhScaleY = PropertyValuesHolder.ofFloat("scaleY", 1, 0.8f, 1); 146 | mPvhScale = PropertyValuesHolder.ofFloat("scaleY", 1, 0.5f, 1); 147 | mPvhRotation = PropertyValuesHolder.ofFloat("rotation", 0); 148 | 149 | mSmallCirclePath = new Path(); 150 | 151 | mPendingAnimations = new LinkedList<>(); 152 | 153 | /** circle view list */ 154 | mCircleViews = new ArrayList<>(); 155 | } 156 | 157 | @Override 158 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 159 | super.onLayout(changed, l, t, r, b); 160 | 161 | // Prevent crash if the count as not been set 162 | if(mLargeCircle != null){ 163 | mOuterCircle.setCenter(mLargeCircle.getCenter()); 164 | } 165 | } 166 | 167 | public void setCount(int count) { 168 | if (mFocusPosition == -1) { 169 | mFocusPosition = 0; 170 | } 171 | setCount(count, mFocusPosition); 172 | } 173 | 174 | /** 175 | * This method must be called before {@link #setCount(int)}, otherwise the focus position will 176 | * be set to the default value - zero. 177 | * @param pos the focus position 178 | */ 179 | public void setFocusPosition(final int pos) { 180 | mFocusPosition = pos; 181 | } 182 | 183 | public void setCount(int count, int focusPos) { 184 | if (count < 2) { 185 | throw new IllegalArgumentException("count must be greater than 2"); 186 | } 187 | 188 | if (focusPos >= count) { 189 | throw new IllegalArgumentException("focus position must be less than count"); 190 | } 191 | 192 | /* Check if the number on indicator has changed since the last setCount to prevent duplicate */ 193 | if(mCircleViews.size() != count) { 194 | mContainer.removeAllViews(); 195 | mCircleViews.clear(); 196 | 197 | int i = 0; 198 | for (; i < focusPos; i++) { 199 | addSmallCircle(); 200 | } 201 | 202 | addLargeCircle(); 203 | 204 | for (i = focusPos + 1; i < count; i++) { 205 | addSmallCircle(); 206 | } 207 | } 208 | 209 | mFocusPosition = focusPos; 210 | } 211 | 212 | public int getFocusPosition() { 213 | return mFocusPosition; 214 | } 215 | 216 | public void moveToLeft() { 217 | if (mAnim != null && mAnim.isRunning()){ 218 | mPendingAnimations.add(false); 219 | return; 220 | } 221 | move(false); 222 | } 223 | 224 | public void moveToRight() { 225 | if (mAnim != null && mAnim.isRunning()){ 226 | mPendingAnimations.add(true); 227 | return; 228 | } 229 | move(true); 230 | } 231 | 232 | public void setOnMoveListener(final OnMoveListener moveListener) { 233 | mOnMoveListener = moveListener; 234 | } 235 | 236 | private void addSmallCircle() { 237 | CircleView smallCircle = createCircleView(CIRCLE_TYPE_SMALL); 238 | mCircleViews.add(smallCircle); 239 | mContainer.addView(smallCircle); 240 | } 241 | 242 | private void addLargeCircle() { 243 | mLargeCircle = createCircleView(CIRCLE_TYPE_LARGE); 244 | mCircleViews.add(mLargeCircle); 245 | mContainer.addView(mLargeCircle); 246 | } 247 | 248 | private CircleView createCircleView(int type) { 249 | CircleView circleView = new CircleView(getContext()); 250 | 251 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( 252 | ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 253 | params.weight = 1; 254 | params.gravity = Gravity.CENTER_VERTICAL; 255 | 256 | switch (type) { 257 | case CIRCLE_TYPE_SMALL: 258 | params.height = params.width = mSmallCircleRadius << 1; 259 | circleView.setColor(mSmallCircleColor); 260 | break; 261 | case CIRCLE_TYPE_LARGE: 262 | params.height = params.width = mLargeCircleRadius << 1; 263 | circleView.setColor(mLargeCircleColor); 264 | break; 265 | case CIRCLE_TYPE_OUTER: 266 | params.height = params.width = mOuterCircleRadius << 1; 267 | circleView.setColor(mOuterCircleColor); 268 | break; 269 | } 270 | 271 | circleView.setLayoutParams(params); 272 | 273 | return circleView; 274 | } 275 | 276 | private int getNextPosition(boolean toRight) { 277 | int nextPos = mFocusPosition + (toRight ? 1 : -1); 278 | if (nextPos < 0 || nextPos >= mCircleViews.size()) return -1; 279 | return nextPos; 280 | } 281 | 282 | private void swapCircles(int currentPos, int nextPos) { 283 | CircleView circleView = mCircleViews.get(currentPos); 284 | mCircleViews.set(currentPos, mCircleViews.get(nextPos)); 285 | mCircleViews.set(nextPos, circleView); 286 | } 287 | 288 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 289 | private void move(final boolean toRight) { 290 | final int nextPos = getNextPosition(toRight); 291 | if (nextPos == -1) return; 292 | 293 | mSmallCircle = mCircleViews.get(nextPos); 294 | 295 | // Calculate the new x coordinate for circles. 296 | float smallCircleX = toRight ? mLargeCircle.getX() 297 | : mLargeCircle.getX() + mLargeCircle.getWidth() - mSmallCircle.getWidth(); 298 | float largeCircleX = toRight ? 299 | mSmallCircle.getX() + mSmallCircle.getWidth() - mLargeCircle.getWidth() : mSmallCircle.getX(); 300 | float outerCircleX = mOuterCircle.getX() + largeCircleX - mLargeCircle.getX(); 301 | 302 | // animations for large circle and outer circle. 303 | PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", mLargeCircle.getX(), largeCircleX); 304 | ObjectAnimator largeCircleAnim = ObjectAnimator.ofPropertyValuesHolder( 305 | mLargeCircle, pvhX, mPvhScaleX, mPvhScaleY); 306 | 307 | pvhX = PropertyValuesHolder.ofFloat("x", mOuterCircle.getX(), outerCircleX); 308 | ObjectAnimator outerCircleAnim = ObjectAnimator.ofPropertyValuesHolder( 309 | mOuterCircle, pvhX, mPvhScaleX, mPvhScaleY); 310 | 311 | // Animations for small circle 312 | PointF smallCircleCenter = mSmallCircle.getCenter(); 313 | PointF smallCircleEndCenter = new PointF( 314 | smallCircleCenter.x - (mSmallCircle.getX() - smallCircleX), smallCircleCenter.y); 315 | 316 | // Create motion anim for small circle. 317 | mSmallCirclePath.reset(); 318 | mSmallCirclePath.moveTo(smallCircleCenter.x, smallCircleCenter.y); 319 | mSmallCirclePath.quadTo(smallCircleCenter.x, smallCircleCenter.y, 320 | (smallCircleCenter.x + smallCircleEndCenter.x) / 2, 321 | (smallCircleCenter.y + smallCircleEndCenter.y) / 2 + mBezierCurveAnchorDistance); 322 | mSmallCirclePath.lineTo(smallCircleEndCenter.x, smallCircleEndCenter.y); 323 | 324 | ValueAnimator smallCircleAnim; 325 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 326 | smallCircleAnim = ObjectAnimator.ofObject(mSmallCircle, "center", null, mSmallCirclePath); 327 | 328 | } else { 329 | final PathMeasure pathMeasure = new PathMeasure(mSmallCirclePath, false); 330 | final float[] point = new float[2]; 331 | smallCircleAnim = ValueAnimator.ofFloat(0.0f, 1.0f); 332 | smallCircleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 333 | @Override 334 | public void onAnimationUpdate(ValueAnimator animation) { 335 | pathMeasure.getPosTan( 336 | pathMeasure.getLength() * animation.getAnimatedFraction(), point, null); 337 | mSmallCircle.setCenter(new PointF(point[0], point[1])); 338 | } 339 | }); 340 | } 341 | 342 | mPvhRotation.setFloatValues(0, toRight ? -30f : 30f, 0, toRight ? 30f : -30f, 0); 343 | ObjectAnimator otherAnim = ObjectAnimator.ofPropertyValuesHolder(mSmallCircle, mPvhRotation, mPvhScale); 344 | 345 | mAnim = new AnimatorSet(); 346 | mAnim.play(smallCircleAnim) 347 | .with(otherAnim).with(largeCircleAnim).with(outerCircleAnim); 348 | mAnim.setInterpolator(new AccelerateDecelerateInterpolator()); 349 | mAnim.setDuration(500); 350 | mAnim.addListener(new Animator.AnimatorListener() { 351 | @Override 352 | public void onAnimationStart(Animator animation) { } 353 | 354 | @Override 355 | public void onAnimationEnd(Animator animation) { 356 | swapCircles(mFocusPosition, nextPos); 357 | mFocusPosition = nextPos; 358 | 359 | if (mOnMoveListener != null) { 360 | if (toRight) { 361 | mOnMoveListener.onMovedToRight(); 362 | } else { 363 | mOnMoveListener.onMovedToLeft(); 364 | } 365 | } 366 | 367 | if(!mPendingAnimations.isEmpty()){ 368 | move(mPendingAnimations.removeFirst()); 369 | } 370 | } 371 | 372 | @Override 373 | public void onAnimationCancel(Animator animation) { } 374 | 375 | @Override 376 | public void onAnimationRepeat(Animator animation) { } 377 | }); 378 | 379 | mAnim.start(); 380 | } 381 | 382 | private int dp2px(int dpValue) { 383 | return (int) getContext().getResources().getDisplayMetrics().density * dpValue; 384 | } 385 | 386 | public interface OnMoveListener { 387 | void onMovedToLeft(); 388 | void onMovedToRight(); 389 | } 390 | } 391 | -------------------------------------------------------------------------------- /library/src/main/res/drawable/indicator_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | -------------------------------------------------------------------------------- /library/src/main/res/layout/rubber_indicator.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 23 | 24 | 31 | 32 | -------------------------------------------------------------------------------- /library/src/main/res/values/attrs_rubberindicator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /library/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFDF8D81 4 | #FFAF3854 5 | #FF533456 6 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /library/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | defaultConfig { 7 | applicationId "me.liangfei.rubberindicator.sample" 8 | minSdkVersion 15 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'androidx.appcompat:appcompat:1.0.2' 24 | implementation project(':library') 25 | } 26 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/rufi/Library/Android/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 | -------------------------------------------------------------------------------- /sample/sample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 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 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /sample/src/main/java/me/liangfei/rubberindicator/MainActivity.java: -------------------------------------------------------------------------------- 1 | package me.liangfei.rubberindicator; 2 | 3 | import android.os.Bundle; 4 | import androidx.core.view.GestureDetectorCompat; 5 | import androidx.appcompat.app.AppCompatActivity; 6 | import android.util.Log; 7 | import android.view.GestureDetector; 8 | import android.view.Menu; 9 | import android.view.MenuItem; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | import android.widget.TextView; 13 | 14 | import me.liangfei.indicator.RubberIndicator; 15 | 16 | public class MainActivity extends AppCompatActivity 17 | implements RubberIndicator.OnMoveListener { 18 | 19 | private static final int SWIPE_MIN_DISTANCE = 120; 20 | private static final int SWIPE_MAX_OFF_PATH = 250; 21 | private static final int SWIPE_THRESHOLD_VELOCITY = 200; 22 | 23 | private static final String KEY_INDICATOR_POSITION = "indicator_position"; 24 | private static final String KEY_INDICATOR_ITEM_NUM = "indicator_item_num"; 25 | 26 | // set the number of indicator items to 5 27 | private int indicatorItemNum = 7; 28 | 29 | private TextView mTextView; 30 | private RubberIndicator mRubberIndicator; 31 | private GestureDetectorCompat mDetector; 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_main); 37 | 38 | // set gesture detector 39 | mDetector = new GestureDetectorCompat(this, new MyGestureListener()); 40 | 41 | mRubberIndicator = (RubberIndicator) findViewById(R.id.rubber); 42 | mTextView = (TextView) findViewById(R.id.focus_position); 43 | 44 | // check to see if savedInstanceState is null 45 | if (savedInstanceState != null) { 46 | mRubberIndicator.setCount(savedInstanceState.getInt(KEY_INDICATOR_ITEM_NUM), savedInstanceState.getInt(KEY_INDICATOR_POSITION)); 47 | } else { 48 | mRubberIndicator.setCount(indicatorItemNum, 3); 49 | } 50 | 51 | //mRubberIndicator.setCount(5, 2); 52 | mRubberIndicator.setOnMoveListener(this); 53 | updateFocusPosition(); 54 | } 55 | 56 | @Override 57 | protected void onSaveInstanceState(Bundle outState) { 58 | outState.putInt(KEY_INDICATOR_POSITION, mRubberIndicator.getFocusPosition()); 59 | outState.putInt(KEY_INDICATOR_ITEM_NUM, mRubberIndicator.getChildCount()); 60 | super.onSaveInstanceState(outState); 61 | } 62 | 63 | @Override 64 | public boolean onCreateOptionsMenu(Menu menu) { 65 | // Inflate the menu; this adds items to the action bar if it is present. 66 | getMenuInflater().inflate(R.menu.menu_main, menu); 67 | return true; 68 | } 69 | 70 | @Override 71 | public boolean onOptionsItemSelected(MenuItem item) { 72 | return super.onOptionsItemSelected(item); 73 | } 74 | 75 | @Override 76 | public boolean onTouchEvent(MotionEvent event) { 77 | mDetector.onTouchEvent(event); 78 | return super.onTouchEvent(event); 79 | } 80 | 81 | public void moveToRight(View view) { 82 | mRubberIndicator.moveToRight(); 83 | } 84 | 85 | public void moveToLeft(View view) { 86 | mRubberIndicator.moveToLeft(); 87 | } 88 | 89 | @Override 90 | public void onMovedToLeft() { 91 | updateFocusPosition(); 92 | } 93 | 94 | @Override 95 | public void onMovedToRight() { 96 | updateFocusPosition(); 97 | } 98 | 99 | private void updateFocusPosition() { 100 | mTextView.setText("Focusing on " + mRubberIndicator.getFocusPosition()); 101 | } 102 | 103 | class MyGestureListener extends GestureDetector.SimpleOnGestureListener { 104 | private static final String TAG = "Gestures"; 105 | 106 | @Override 107 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 108 | try { 109 | if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) 110 | return false; 111 | // right to left swipe 112 | if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 113 | Log.d(TAG, "swipe left"); 114 | moveToLeft(null); 115 | } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 116 | Log.d(TAG, "swipe right"); 117 | moveToRight(null); 118 | } 119 | } catch (Exception e) { 120 | // nothing 121 | } 122 | return false; 123 | } 124 | 125 | @Override 126 | public boolean onDown(MotionEvent e) { 127 | return true; 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/indicator_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | 12 | 21 | 22 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liangfeidotme/AndroidRubberIndicator/32c6bae8ccb5d7acb34ff572f9a9a2b9fca8c494/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liangfeidotme/AndroidRubberIndicator/32c6bae8ccb5d7acb34ff572f9a9a2b9fca8c494/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liangfeidotme/AndroidRubberIndicator/32c6bae8ccb5d7acb34ff572f9a9a2b9fca8c494/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liangfeidotme/AndroidRubberIndicator/32c6bae8ccb5d7acb34ff572f9a9a2b9fca8c494/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5dp 4 | 5dp 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RubberIndicator 3 | 4 | About 5 | 6 | ==> 7 | <== 8 | Swipe the screen 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':library' 2 | --------------------------------------------------------------------------------