├── sample-app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ └── layout │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── cz │ │ └── intik │ │ └── overflowpagerindicator │ │ └── MainActivity.kt ├── build.gradle └── proguard-rules.pro ├── overflow-library ├── .gitignore ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── res │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── attrs.xml │ │ │ └── drawable │ │ │ │ └── dot.xml │ │ └── java │ │ │ └── cz │ │ │ └── intik │ │ │ └── overflowindicator │ │ │ ├── Util.kt │ │ │ ├── SimpleSnapHelper.kt │ │ │ ├── OverflowDataObserver.kt │ │ │ └── OverflowPagerIndicator.kt │ └── test │ │ └── java │ │ └── cz │ │ └── intik │ │ └── overflowindicator │ │ └── SimpleSnapHelperTest.kt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── docs └── images │ ├── classic-indicators.png │ ├── overflow-pager-indicator.gif │ └── overflow-pager-indicator-small.gif ├── gradle.properties ├── LICENSE ├── gradlew.bat ├── README.md └── gradlew /sample-app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /overflow-library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample-app', ':overflow-library' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/ 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /docs/images/classic-indicators.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/docs/images/classic-indicators.png -------------------------------------------------------------------------------- /overflow-library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /docs/images/overflow-pager-indicator.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/docs/images/overflow-pager-indicator.gif -------------------------------------------------------------------------------- /docs/images/overflow-pager-indicator-small.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/docs/images/overflow-pager-indicator-small.gif -------------------------------------------------------------------------------- /sample-app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Overflow Pager Indicator - Sample app 3 | 4 | -------------------------------------------------------------------------------- /sample-app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/sample-app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample-app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/sample-app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample-app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/sample-app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample-app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/sample-app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample-app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/sample-app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample-app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/sample-app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample-app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/sample-app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample-app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/sample-app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample-app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/sample-app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample-app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intik/overflow-pager-indicator/HEAD/sample-app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /overflow-library/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #EEFFFFFF 4 | #99CCCCCC 5 | -------------------------------------------------------------------------------- /overflow-library/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12dp 4 | 2dp 5 | -------------------------------------------------------------------------------- /sample-app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /overflow-library/src/main/java/cz/intik/overflowindicator/Util.kt: -------------------------------------------------------------------------------- 1 | package cz.intik.overflowindicator 2 | 3 | import android.content.res.Resources 4 | 5 | internal object Util { 6 | fun dpToPx(dp: Double): Int = (dp * Resources.getSystem().displayMetrics.density).toInt() 7 | } 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri May 29 23:20:45 CEST 2020 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-6.4.1-all.zip 7 | -------------------------------------------------------------------------------- /overflow-library/src/main/res/drawable/dot.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample-app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /overflow-library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /sample-app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /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 | android.enableJetifier=true 13 | android.useAndroidX=true 14 | org.gradle.jvmargs=-Xmx1536m 15 | 16 | # When configured, Gradle will run in incubating parallel mode. 17 | # This option should only be used with decoupled projects. More details, visit 18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 19 | # org.gradle.parallel=true 20 | -------------------------------------------------------------------------------- /sample-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 28 7 | 8 | defaultConfig { 9 | applicationId "cz.intik.overflowpagerindicator" 10 | minSdkVersion 21 11 | targetSdkVersion 28 12 | versionCode 3 13 | versionName "3.0.1" 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | repositories { 25 | mavenCentral() 26 | } 27 | 28 | 29 | dependencies { 30 | implementation "androidx.appcompat:appcompat:1.1.0" 31 | implementation "androidx.recyclerview:recyclerview:1.1.0" 32 | 33 | implementation project(path: ':overflow-library') 34 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 35 | } -------------------------------------------------------------------------------- /overflow-library/src/main/java/cz/intik/overflowindicator/SimpleSnapHelper.kt: -------------------------------------------------------------------------------- 1 | package cz.intik.overflowindicator 2 | 3 | import androidx.recyclerview.widget.PagerSnapHelper 4 | import androidx.recyclerview.widget.RecyclerView 5 | 6 | /** 7 | * SnapHelper which allows snapping of pages, customized with notifying of [OverflowPagerIndicator] 8 | * when position is snapped 9 | * 10 | * @author Petr Introvic 11 | * created 07.10.2017. 12 | */ 13 | class SimpleSnapHelper(private val overflowPagerIndicator: OverflowPagerIndicator) : 14 | PagerSnapHelper() { 15 | 16 | override fun findTargetSnapPosition( 17 | layoutManager: RecyclerView.LayoutManager, 18 | velocityX: Int, 19 | velocityY: Int 20 | ): Int { 21 | val position = super.findTargetSnapPosition(layoutManager, velocityX, velocityY) 22 | 23 | // Notify OverflowPagerIndicator about changed page 24 | overflowPagerIndicator.onPageSelected(position) 25 | 26 | return position 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /sample-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 C:\Users\Petr\AppData\Local\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /overflow-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 C:\Users\Petr\AppData\Local\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /overflow-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 28 7 | 8 | defaultConfig { 9 | minSdkVersion 16 10 | targetSdkVersion 28 11 | versionCode 3 12 | versionName "3.0.1" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | dependencies { 27 | implementation "androidx.appcompat:appcompat:1.1.0" 28 | implementation "androidx.recyclerview:recyclerview:1.1.0" 29 | 30 | implementation "com.andkulikov:transitionseverywhere:2.1.0" 31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 32 | 33 | testImplementation "androidx.test.ext:junit:1.1.1" 34 | testImplementation "androidx.test:core:1.2.0" 35 | testImplementation "io.mockk:mockk:1.10.0" 36 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Petr Introvic 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. -------------------------------------------------------------------------------- /overflow-library/src/test/java/cz/intik/overflowindicator/SimpleSnapHelperTest.kt: -------------------------------------------------------------------------------- 1 | package cz.intik.overflowindicator 2 | 3 | import androidx.recyclerview.widget.RecyclerView 4 | import io.mockk.every 5 | import io.mockk.mockk 6 | import io.mockk.verify 7 | import org.junit.Before 8 | import org.junit.Test 9 | 10 | /* 11 | * @author Petr Introvic 12 | * created 31.5.2020 13 | */ 14 | class SimpleSnapHelperTest { 15 | 16 | private lateinit var mockedLayoutManager: RecyclerView.LayoutManager 17 | private lateinit var mockedOverflowPagerIndicator: OverflowPagerIndicator 18 | private lateinit var testedSimpleSnapHelper: SimpleSnapHelper 19 | 20 | @Before 21 | fun setup() { 22 | mockedOverflowPagerIndicator = mockk(relaxUnitFun = true) 23 | mockedLayoutManager = mockk() 24 | 25 | testedSimpleSnapHelper = SimpleSnapHelper(mockedOverflowPagerIndicator) 26 | } 27 | 28 | @Test 29 | fun `test findTargetSnapPosition calls onPageSelected`() { 30 | every { mockedLayoutManager.itemCount } returns 0 31 | 32 | testedSimpleSnapHelper.findTargetSnapPosition(mockedLayoutManager, 0, 0) 33 | 34 | verify { mockedOverflowPagerIndicator.onPageSelected(any()) } 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /overflow-library/src/main/java/cz/intik/overflowindicator/OverflowDataObserver.kt: -------------------------------------------------------------------------------- 1 | package cz.intik.overflowindicator 2 | 3 | import androidx.recyclerview.widget.RecyclerView 4 | 5 | /** 6 | * Data observer which notifies [OverflowPagerIndicator] of changed data 7 | * 8 | * @author Petr Introvic 9 | * created 03.10.2017. 10 | */ 11 | 12 | internal class OverflowDataObserver(private val overflowPagerIndicator: OverflowPagerIndicator) : 13 | RecyclerView.AdapterDataObserver() { 14 | 15 | override fun onChanged() = overflowPagerIndicator.updateIndicatorsCount() 16 | 17 | override fun onItemRangeInserted(positionStart: Int, itemCount: Int) = 18 | overflowPagerIndicator.updateIndicatorsCount() 19 | 20 | override fun onItemRangeChanged(positionStart: Int, itemCount: Int) = 21 | overflowPagerIndicator.updateIndicatorsCount() 22 | 23 | override fun onItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?) = 24 | overflowPagerIndicator.updateIndicatorsCount() 25 | 26 | override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) = 27 | overflowPagerIndicator.updateIndicatorsCount() 28 | 29 | override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) = 30 | overflowPagerIndicator.updateIndicatorsCount() 31 | } 32 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /sample-app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 20 | 21 | 26 | 27 | 28 | 32 | 33 | 37 | 38 | 45 | 46 | 47 | 51 | 52 | 56 | 57 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /sample-app/src/main/java/cz/intik/overflowpagerindicator/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package cz.intik.overflowpagerindicator 2 | 3 | import android.graphics.Color 4 | import android.os.Bundle 5 | import android.view.ViewGroup 6 | import android.widget.FrameLayout 7 | 8 | import androidx.appcompat.app.AppCompatActivity 9 | import androidx.recyclerview.widget.LinearLayoutManager 10 | import androidx.recyclerview.widget.RecyclerView 11 | import cz.intik.overflowindicator.OverflowPagerIndicator 12 | import cz.intik.overflowindicator.SimpleSnapHelper 13 | 14 | /** 15 | * @author Petr Introvic 16 | * created 03.10.2017. 17 | */ 18 | class MainActivity : AppCompatActivity() { 19 | 20 | data class Data( 21 | val recyclerViewId: Int, 22 | val indicatorViewId: Int, 23 | val itemCount: Int, 24 | val delay: Long 25 | ) 26 | 27 | private val data = listOf( 28 | Data(R.id.recyclerView, R.id.viewPagerIndicator, 20, 500L), 29 | Data(R.id.recyclerViewColors, R.id.viewPagerIndicatorColors, 9, 1_000L), 30 | Data(R.id.recyclerViewSizes, R.id.viewPagerIndicatorSizes, 5, 2_000L) 31 | ) 32 | 33 | override fun onCreate(savedInstanceState: Bundle?) { 34 | super.onCreate(savedInstanceState) 35 | setContentView(R.layout.activity_main) 36 | 37 | data.forEach(::initRecyclerWithIndicator) 38 | } 39 | 40 | private fun initRecyclerWithIndicator(data: Data) { 41 | val (recyclerViewId, indicatorViewId, itemCount, delay) = data 42 | 43 | val recyclerView = findViewById(recyclerViewId) 44 | val overflowPagerIndicator = findViewById(indicatorViewId) 45 | val adapter = Adapter() 46 | 47 | recyclerView.layoutManager = 48 | LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false) 49 | recyclerView.adapter = adapter 50 | 51 | overflowPagerIndicator.attachToRecyclerView(recyclerView) 52 | 53 | SimpleSnapHelper(overflowPagerIndicator).attachToRecyclerView(recyclerView) 54 | 55 | recyclerView.postDelayed({ adapter.updateItemCount(itemCount) }, delay) 56 | } 57 | 58 | private class Adapter : RecyclerView.Adapter() { 59 | // Some material colors for recycler view items background 60 | private val colors = 61 | mutableListOf("#2196F3", "#00BCD4", "#4CAF50", "#CDDC39", "#FFC107", "#FF5722") 62 | .apply { shuffle() } 63 | 64 | private var itemCount = 0 65 | 66 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { 67 | val view = FrameLayout(parent.context).apply { 68 | layoutParams = ViewGroup.LayoutParams( 69 | ViewGroup.LayoutParams.MATCH_PARENT, 70 | ViewGroup.LayoutParams.MATCH_PARENT 71 | ) 72 | } 73 | 74 | return object : RecyclerView.ViewHolder(view) { 75 | 76 | } 77 | } 78 | 79 | override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { 80 | val color = Color.parseColor(colors[position % colors.size]) 81 | 82 | holder.itemView.setBackgroundColor(color) 83 | } 84 | 85 | override fun getItemCount(): Int = itemCount 86 | 87 | internal fun updateItemCount(newCount: Int) { 88 | itemCount = newCount 89 | 90 | notifyDataSetChanged() 91 | } 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overflow Pager Indicator widget 2 | 3 | [![Download](https://jitpack.io/v/intik/overflow-pager-indicator.svg)](https://jitpack.io/#intik/overflow-pager-indicator) 4 | [![](https://jitci.com/gh/intik/overflow-pager-indicator/svg)](https://jitci.com/gh/intik/overflow-pager-indicator) 5 | [![license](https://img.shields.io/badge/license-MIT%20license-blue.svg)](LICENSE) 6 | 7 | Simple widget for recycler view - displaying dots indicators of currently selected page - 8 | with some fancy animation when dataset is large. 9 | 10 | **Large dataset** displays only fixed amount of dots centered around currently selected page 11 | with a nice little scaling animation of indicators on the edges. Provides fluent animation of 12 | selecting new page. 13 | 14 | **Small dataset** displays classic dot indicators line with currently selected page highlighted. 15 | 16 | RecyclerView should be configured with snapping to pages vie PagerSnapHelper subclass ~ simulates 17 | behavior of classic ViewPager 18 | 19 | ## Widget preview 20 | 21 | | :heavy_check_mark: Overflowed indicators | :x: Classic confusing indicators | 22 | | ----------------------- | ------------------------------- | 23 | | ![Widget effect animation preview](docs/images/overflow-pager-indicator.gif "Preview of widget effect of animating dots during pages swiping") | ![Classic ](docs/images/classic-indicators.png "Confusing") | 24 | 25 | _Disclaimer: Having too many pages in recycler means that user needs to swipe a lot. Different layout/ui may be more user friendly._ 26 | 27 | ## Usage 28 | 29 | ### Migration to 3.1 from 3.0 30 | 31 | `dotFillColor` and `dotStrokeColor` were renamed to `indicatorFillColor` and `indicatorStrokeColor` 32 | 33 | ### Migration to 3.0 from 2.x 34 | 35 | Make sure you have Jitpack dependency in root gradle file. 36 | 37 | Follow [this instructions](https://github.com/andkulikov/Transitions-Everywhere#migration-from-1x-guide) to update 38 | TransitionsEverywhere which migrated to Jetpack androidx.transition to prevent import crashes. 39 | 40 | ### Gradle dependency 41 | 42 | In your root gradle add dependency to Jitpack: 43 | 44 | ```gradle 45 | buildscript { 46 | repositories { 47 | ... 48 | maven { url 'https://jitpack.io' } 49 | } 50 | } 51 | ``` 52 | 53 | In you module gradle add dependency to library: 54 | 55 | ```gradle 56 | implementation 'com.github.intik:overflow-pager-indicator:3.1.0' 57 | 58 | ``` 59 | 60 | ### Layout 61 | 62 | Some layout with RecyclerView and OverflowPagerIndicator 63 | 64 | ```xml 65 | 69 | 70 | 75 | 76 | 84 | 85 | 86 | ``` 87 | 88 | ### Code 89 | 90 | Attach 91 | [OverflowPagerIndicator](overflow-library/src/main/java/cz/intik/overflowindicator/OverflowPagerIndicator.kt) 92 | (usually after LayoutManager and Adapter setup) to 93 | [RecyclerView](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView) 94 | \- for listening to dataset changes: 95 | 96 | ```kotlin 97 | viewOverflowPagerIndicator.attachToRecyclerView(recyclerView) 98 | ``` 99 | 100 | Attach 101 | [SimpleSnapHelper](overflow-library/src/main/java/cz/intik/overflowindicator/SimpleSnapHelper.kt) 102 | to recycler view which will change selected page in indicator view as items in recycler 103 | view are snapped: 104 | 105 | ```kotlin 106 | val snapHelper = SimpleSnapHelper(viewOverflowPagerIndicator) 107 | snapHelper.attachToRecyclerView(recyclerView) 108 | ``` 109 | 110 | Or use any other implementation of 111 | [PagerSnapHelper](https://developer.android.com/reference/androidx/recyclerview/widget/PagerSnapHelper "Android Developers - docs - PagerSnapHelper") 112 | or even some custom logic which will call: 113 | 114 | ```kotlin 115 | viewOverflowPagerIndicator.onPageSelected(position) 116 | ``` 117 | 118 | ### Customization 119 | 120 | You can easily change dot fill color and dot stroke color via xml attributes like this: 121 | ```xml 122 | 128 | ``` 129 | 130 | ### Changelog 131 | 132 | 3.1.0 Add customization of indicator size and margin. Unify naming of attributes to "indicatorXxx" instead of "dotXxx" 133 | 134 | 3.0.1 Remove library from Bintray, use simply Jitpack. Convert library to Kotlin and update to TransitionsEverywhere 2.0 (which uses androidx.transition.X heavily) 135 | 136 | 2.0.0 Migrate to AndroidX, add color customization options (big thanks [Javi Chaqués](https://github.com/javichaques)) 137 | 138 | 1.2.1 bugfix (thanks [Sajad Abasi](https://github.com/sajadabasi)) 139 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /overflow-library/src/main/java/cz/intik/overflowindicator/OverflowPagerIndicator.kt: -------------------------------------------------------------------------------- 1 | package cz.intik.overflowindicator 2 | 3 | import android.content.Context 4 | import android.graphics.drawable.Drawable 5 | import android.graphics.drawable.GradientDrawable 6 | import android.util.AttributeSet 7 | import android.view.View 8 | import android.widget.LinearLayout 9 | import androidx.core.content.ContextCompat 10 | import androidx.recyclerview.widget.PagerSnapHelper 11 | import androidx.recyclerview.widget.RecyclerView 12 | import androidx.transition.ChangeBounds 13 | import androidx.transition.Fade 14 | import androidx.transition.TransitionManager 15 | import androidx.transition.TransitionSet 16 | import java.util.* 17 | import kotlin.math.max 18 | 19 | /** 20 | * Pager indicator widget 21 | * 22 | * - attach to recyclerView with [.attachToRecyclerView] 23 | * - add page selecting behavior with [SimpleSnapHelper] or custom [PagerSnapHelper] 24 | * or with custom logic which calls [.onPageSelected] 25 | * 26 | * @author Petr Introvic 27 | * created 07.06.2017. 28 | */ 29 | class OverflowPagerIndicator(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) { 30 | 31 | var indicatorSize: Int = -1 32 | private set 33 | 34 | var indicatorMargin: Int = -1 35 | private set 36 | 37 | var indicatorStrokeColor: Int = -1 38 | private set 39 | 40 | var indicatorFillColor: Int = -1 41 | private set 42 | 43 | private val dataObserver: OverflowDataObserver 44 | private var indicatorCount: Int = 0 45 | private var lastSelected: Int = 0 46 | private var recyclerView: RecyclerView? = null 47 | 48 | private val indicatorDrawable: Drawable 49 | get() = GradientDrawable().apply { 50 | shape = GradientDrawable.OVAL 51 | setColor(indicatorFillColor) 52 | setStroke(Util.dpToPx(0.5), indicatorStrokeColor) 53 | } 54 | 55 | init { 56 | initAttrs(context, attrs) 57 | 58 | dataObserver = OverflowDataObserver(this) 59 | } 60 | 61 | private fun initAttrs(context: Context, attrs: AttributeSet?) { 62 | indicatorFillColor = ContextCompat.getColor(context, R.color.indicatorFill) 63 | indicatorStrokeColor = ContextCompat.getColor(context, R.color.indicatorStroke) 64 | indicatorSize = context.resources.getDimensionPixelSize(R.dimen.indicator_size) 65 | indicatorMargin = context.resources.getDimensionPixelSize(R.dimen.indicator_margin) 66 | 67 | if (attrs == null) return 68 | 69 | val attributeArray = 70 | context.obtainStyledAttributes(attrs, R.styleable.OverflowPagerIndicator) 71 | 72 | try { 73 | indicatorFillColor = attributeArray 74 | .getColor(R.styleable.OverflowPagerIndicator_indicatorFillColor, indicatorFillColor) 75 | 76 | indicatorStrokeColor = attributeArray 77 | .getColor(R.styleable.OverflowPagerIndicator_indicatorStrokeColor, indicatorStrokeColor) 78 | 79 | indicatorSize = attributeArray 80 | .getDimensionPixelSize( 81 | R.styleable.OverflowPagerIndicator_indicatorSize, indicatorSize 82 | ) 83 | 84 | indicatorMargin = attributeArray 85 | .getDimensionPixelSize( 86 | R.styleable.OverflowPagerIndicator_indicatorMargin, indicatorMargin 87 | ) 88 | } finally { 89 | attributeArray.recycle() 90 | } 91 | } 92 | 93 | override fun onDetachedFromWindow() { 94 | try { 95 | recyclerView?.adapter?.unregisterAdapterDataObserver(dataObserver) 96 | } catch (ise: IllegalStateException) { 97 | // Do nothing 98 | } 99 | 100 | super.onDetachedFromWindow() 101 | } 102 | 103 | /** 104 | * @param position Page to be selected 105 | */ 106 | fun onPageSelected(position: Int) = when { 107 | indicatorCount > MAX_INDICATORS -> updateOverflowState(position) 108 | else -> updateSimpleState(position) 109 | } 110 | 111 | /** 112 | * @param recyclerView Target recycler view 113 | */ 114 | fun attachToRecyclerView(recyclerView: RecyclerView) { 115 | this.recyclerView = recyclerView 116 | recyclerView.adapter?.registerAdapterDataObserver(dataObserver) 117 | 118 | initIndicators() 119 | } 120 | 121 | fun updateIndicatorsCount() { 122 | if (indicatorCount != recyclerView?.adapter?.itemCount) { 123 | initIndicators() 124 | } 125 | } 126 | 127 | private fun initIndicators() { 128 | lastSelected = -1 129 | indicatorCount = recyclerView?.adapter?.itemCount ?: 0 130 | createIndicators(indicatorSize, indicatorMargin) 131 | onPageSelected(0) 132 | } 133 | 134 | private fun updateSimpleState(position: Int) { 135 | if (lastSelected != -1) { 136 | animateViewScale(getChildAt(lastSelected), STATE_NORMAL) 137 | } 138 | 139 | animateViewScale(getChildAt(position), STATE_SELECTED) 140 | 141 | lastSelected = position 142 | } 143 | 144 | private fun updateOverflowState(position: Int) { 145 | if (indicatorCount == 0) return 146 | if (position < 0 || position > indicatorCount) return 147 | 148 | val transition = TransitionSet() 149 | .setOrdering(TransitionSet.ORDERING_TOGETHER) 150 | .addTransition(ChangeBounds()) 151 | .addTransition(Fade()) 152 | 153 | TransitionManager.beginDelayedTransition(this, transition) 154 | 155 | val positionStates = FloatArray(indicatorCount + 1) 156 | Arrays.fill(positionStates, STATE_GONE) 157 | 158 | val start = position - MAX_INDICATORS + 4 159 | var realStart = max(0, start) 160 | 161 | if (realStart + MAX_INDICATORS > indicatorCount) { 162 | realStart = indicatorCount - MAX_INDICATORS 163 | positionStates[indicatorCount - 1] = STATE_NORMAL 164 | positionStates[indicatorCount - 2] = STATE_NORMAL 165 | } else { 166 | if (realStart + MAX_INDICATORS - 2 < indicatorCount) { 167 | positionStates[realStart + MAX_INDICATORS - 2] = STATE_SMALL 168 | } 169 | if (realStart + MAX_INDICATORS - 1 < indicatorCount) { 170 | positionStates[realStart + MAX_INDICATORS - 1] = STATE_SMALLEST 171 | } 172 | } 173 | 174 | for (i in realStart until realStart + MAX_INDICATORS - 2) { 175 | positionStates[i] = STATE_NORMAL 176 | } 177 | 178 | if (position > 5) { 179 | positionStates[realStart] = STATE_SMALLEST 180 | positionStates[realStart + 1] = STATE_SMALL 181 | } else if (position == 5) { 182 | positionStates[realStart] = STATE_SMALL 183 | } 184 | 185 | positionStates[position] = STATE_SELECTED 186 | 187 | updateIndicators(positionStates) 188 | 189 | lastSelected = position 190 | } 191 | 192 | private fun updateIndicators(positionStates: FloatArray) { 193 | for (i in 0 until indicatorCount) { 194 | val v = getChildAt(i) 195 | 196 | when (val state = positionStates[i]) { 197 | STATE_GONE -> v.visibility = View.GONE 198 | else -> { 199 | v.visibility = View.VISIBLE 200 | animateViewScale(v, state) 201 | } 202 | } 203 | 204 | } 205 | } 206 | 207 | private fun createIndicators(indicatorSize: Int, margin: Int) { 208 | removeAllViews() 209 | 210 | if (indicatorCount <= 1) return 211 | 212 | for (i in 0 until indicatorCount) { 213 | addIndicator(indicatorCount > MAX_INDICATORS, indicatorSize, margin) 214 | } 215 | } 216 | 217 | private fun addIndicator(isOverflowState: Boolean, indicatorSize: Int, margin: Int) { 218 | val view = View(context) 219 | view.background = indicatorDrawable 220 | 221 | animateViewScale(view, if (isOverflowState) STATE_SMALLEST else STATE_NORMAL) 222 | 223 | val params = MarginLayoutParams(indicatorSize, indicatorSize).apply { 224 | leftMargin = margin 225 | rightMargin = margin 226 | } 227 | 228 | addView(view, params) 229 | } 230 | 231 | private fun animateViewScale(view: View?, scale: Float) { 232 | if (view == null) return 233 | 234 | view.animate() 235 | .scaleX(scale) 236 | .scaleY(scale) 237 | } 238 | 239 | companion object { 240 | const val MAX_INDICATORS = 9 241 | 242 | // State also represents indicator scale factor 243 | const val STATE_GONE = 0f 244 | const val STATE_SMALLEST = 0.2f 245 | const val STATE_SMALL = 0.4f 246 | const val STATE_NORMAL = 0.6f 247 | const val STATE_SELECTED = 1.0f 248 | } 249 | 250 | } 251 | --------------------------------------------------------------------------------