├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── xyz
│ │ └── sangcomz
│ │ └── indicatordecoratorsample
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── ic_launcher-web.png
│ ├── java
│ │ └── xyz
│ │ │ └── sangcomz
│ │ │ └── indicatordecoratorsample
│ │ │ ├── ListAdapter.kt
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_background.xml
│ │ ├── drawable
│ │ ├── ic_grade_gray_24dp.xml
│ │ ├── ic_grade_red_24dp.xml
│ │ └── ic_launcher_foreground.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── item.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── xyz
│ └── sangcomz
│ └── indicatordecoratorsample
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
├── release.gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── indicatordecorator
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── xyz
│ │ └── sangcomz
│ │ └── indicatordecorator
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ └── java
│ │ └── xyz
│ │ └── sangcomz
│ │ └── indicatordecorator
│ │ ├── IndicatorItemDecoration.kt
│ │ ├── ext
│ │ └── IntExt.kt
│ │ └── shape
│ │ ├── CircleIndicator.kt
│ │ ├── DrawableIndicator.kt
│ │ ├── IndicatorShape.kt
│ │ └── SquareIndicator.kt
│ └── test
│ └── java
│ └── xyz
│ └── sangcomz
│ └── indicatordecorator
│ └── ExampleUnitTest.kt
├── pic
├── banner.png
└── sample.gif
├── release.sh
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # IndicatorDecorator
3 | Indicator decorator is an indicator that can be used in ViewPager2 and RecyclerView.
4 |
5 | ## What's New in 0.2.0? :tada:
6 | - version update
7 |
8 | ## How to Use
9 |
10 | ### Gradle
11 | ```groovy
12 | dependencies {
13 | implementation 'xyz.sangcomz:indicatordecorator:0.2.0'
14 | }
15 | ```
16 | ### Usage
17 | ```java
18 | viewPager1.addItemDecoration(IndicatorItemDecoration().apply {
19 | indicatorShape = CircleIndicator().apply {
20 | colorActive = ContextCompat.getColor(this@MainActivity, R.color.colorPrimaryDark)
21 | }
22 | })
23 | ```
24 |
25 | #### attribute
26 |
27 | | Attribute Name | Description | Default Value |
28 | |:--------------------------:|-------------------------------------------|:-------------------:|
29 | | topOffset | Top Offset with Page Item | 4DP |
30 | | bottomOffset | Bottom Offset in View | 4DP |
31 | | indicatorItemPadding | Padding between indicators | 8DP |
32 | | indicatorShape | Indicator shape | CircleIndicator |
33 | | isOverlap | Can overlap | false |
34 | | isShowBackground |Background visibility | false |
35 | | backgroundColor | Background Color | WHITE |
36 | | backgroundCornerRadius | Background Corner Radius | 8DP |
37 | | backgroundSideOffset | Background side offset | 16DP |
38 | |backgroundTopAndBottomOffset| Background top and bottom offset | 4DP |
39 |
40 | #### Support Indicator Shape
41 |
42 | - CircleIndicator
43 | - DrawableIndicator
44 | - SquareIndicator
45 |
46 | It can be created by extend IndicatorShape. (It's better if you make a PR)
47 |
48 | ## Result Screen
49 |
50 | | Project Name | Result Screen |
51 | |:---------:|---|
52 | | Sample |
|
53 |
54 | # Contribute
55 | Welcome any contributions.
56 |
57 | # Inspired by
58 | * [bleeding182/recyclerviewItemDecorations](https://github.com/bleeding182/recyclerviewItemDecorations), I was inspired by his code.
59 |
60 | # License
61 |
62 | Copyright 2019 Jeong Seokwon
63 |
64 | Licensed under the Apache License, Version 2.0 (the "License");
65 | you may not use this file except in compliance with the License.
66 | You may obtain a copy of the License at
67 |
68 | http://www.apache.org/licenses/LICENSE-2.0
69 |
70 | Unless required by applicable law or agreed to in writing, software
71 | distributed under the License is distributed on an "AS IS" BASIS,
72 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
73 | See the License for the specific language governing permissions and
74 | limitations under the License.
75 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 29
9 | defaultConfig {
10 | applicationId "xyz.sangcomz.indicatordecoratorsample"
11 | minSdkVersion 21
12 | targetSdkVersion 29
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: 'libs', include: ['*.jar'])
27 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
28 | implementation 'androidx.appcompat:appcompat:1.2.0'
29 | implementation 'androidx.core:core-ktx:1.3.1'
30 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
31 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
32 | implementation 'androidx.viewpager2:viewpager2:1.0.0'
33 | implementation "org.jetbrains.anko:anko:0.10.8"
34 |
35 | testImplementation 'junit:junit:4.13'
36 | androidTestImplementation 'androidx.test:runner:1.3.0'
37 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
38 | implementation project(path: ':indicatordecorator')
39 | }
40 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/xyz/sangcomz/indicatordecoratorsample/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecoratorsample
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("xyz.sangcomz.indicatordecoratorsample", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/main/java/xyz/sangcomz/indicatordecoratorsample/ListAdapter.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecoratorsample
2 |
3 | import android.view.LayoutInflater
4 | import android.view.View
5 | import android.view.ViewGroup
6 | import androidx.appcompat.widget.AppCompatTextView
7 | import androidx.core.content.ContextCompat
8 | import androidx.recyclerview.widget.RecyclerView
9 |
10 | class ListAdapter(private val list: List>) :
11 | RecyclerView.Adapter() {
12 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
13 | return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item, parent, false))
14 | }
15 |
16 | override fun getItemCount() = list.size
17 |
18 | override fun onBindViewHolder(holder: ViewHolder, position: Int) {
19 | holder.setData(list[position])
20 | }
21 |
22 | class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
23 | private val container = itemView
24 | private val textView = itemView.findViewById(R.id.textView)
25 |
26 | fun setData(data: Pair) {
27 | container.setBackgroundColor(ContextCompat.getColor(container.context, data.first))
28 | textView.text = data.second
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/app/src/main/java/xyz/sangcomz/indicatordecoratorsample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecoratorsample
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import androidx.core.content.ContextCompat
6 | import androidx.recyclerview.widget.PagerSnapHelper
7 | import kotlinx.android.synthetic.main.activity_main.*
8 | import xyz.sangcomz.indicatordecorator.IndicatorItemDecoration
9 | import xyz.sangcomz.indicatordecorator.shape.CircleIndicator
10 | import xyz.sangcomz.indicatordecorator.shape.DrawableIndicator
11 | import xyz.sangcomz.indicatordecorator.shape.SquareIndicator
12 |
13 | class MainActivity : AppCompatActivity() {
14 |
15 | private val adapter1: ListAdapter = ListAdapter(
16 | listOf(
17 | R.color.page1 to "DrawableIndicator\npage 1",
18 | R.color.page2 to "DrawableIndicator\npage 2",
19 | R.color.page3 to "DrawableIndicator\npage 3",
20 | R.color.page4 to "DrawableIndicator\npage 4",
21 | R.color.page5 to "DrawableIndicator\npage 5",
22 | R.color.page6 to "DrawableIndicator\npage 6",
23 | R.color.page7 to "DrawableIndicator\npage 7",
24 | R.color.page8 to "DrawableIndicator\npage 8"
25 | )
26 | )
27 |
28 | private val adapter2: ListAdapter = ListAdapter(
29 | listOf(
30 | R.color.page8 to "SquareIndicator\npage 1",
31 | R.color.page7 to "SquareIndicator\npage 2",
32 | R.color.page6 to "SquareIndicator\npage 3",
33 | R.color.page5 to "SquareIndicator\npage 4",
34 | R.color.page4 to "SquareIndicator\npage 5",
35 | R.color.page3 to "SquareIndicator\npage 6",
36 | R.color.page2 to "SquareIndicator\npage 7",
37 | R.color.page1 to "SquareIndicator\npage 8"
38 | )
39 | )
40 |
41 | private val adapter3: ListAdapter = ListAdapter(
42 | listOf(
43 | R.color.page4 to "CircleIndicator\npage 1",
44 | R.color.page5 to "CircleIndicator\npage 2",
45 | R.color.page6 to "CircleIndicator\npage 3",
46 | R.color.page7 to "CircleIndicator\npage 4",
47 | R.color.page8 to "CircleIndicator\npage 5",
48 | R.color.page1 to "CircleIndicator\npage 6",
49 | R.color.page2 to "CircleIndicator\npage 7",
50 | R.color.page3 to "CircleIndicator\npage 8"
51 | )
52 | )
53 |
54 | override fun onCreate(savedInstanceState: Bundle?) {
55 | super.onCreate(savedInstanceState)
56 | setContentView(R.layout.activity_main)
57 |
58 | recyclerView.adapter = adapter1
59 | PagerSnapHelper().attachToRecyclerView(recyclerView)
60 | recyclerView.addItemDecoration(IndicatorItemDecoration().apply {
61 | indicatorShape = DrawableIndicator(
62 | ContextCompat.getDrawable(
63 | this@MainActivity,
64 | R.drawable.ic_grade_red_24dp
65 | )!!,
66 | ContextCompat.getDrawable(this@MainActivity, R.drawable.ic_grade_gray_24dp)!!
67 | )
68 | })
69 |
70 | viewPager2.adapter = adapter2
71 | viewPager2.addItemDecoration(IndicatorItemDecoration().apply {
72 | indicatorShape = SquareIndicator().apply {
73 | colorActive = ContextCompat.getColor(this@MainActivity, R.color.colorPrimaryDark)
74 | }
75 | })
76 |
77 | viewPager1.adapter = adapter3
78 | viewPager1.addItemDecoration(IndicatorItemDecoration().apply {
79 | indicatorShape = CircleIndicator().apply {
80 | isOverlap = true
81 | colorActive = ContextCompat.getColor(this@MainActivity, R.color.colorPrimaryDark)
82 | isShowBackground = true
83 | }
84 | })
85 |
86 |
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
7 |
9 |
10 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_grade_gray_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_grade_red_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
6 |
8 |
12 |
15 |
19 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
28 |
29 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #00DDFF
4 | #2196F3
5 | #FF00D4
6 | #2196F3
7 | #C51BD8
8 | #1B3AD8
9 | #1BD8B2
10 | #3ED81B
11 | #B5D81B
12 | #D85D1B
13 | #D81B1B
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | IndicatorDecorator Sample
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/xyz/sangcomz/indicatordecoratorsample/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecoratorsample
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.4.10'
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:4.0.1'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 |
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/release.gradle:
--------------------------------------------------------------------------------
1 | /**
2 | * Use For Upload
3 | */
4 | version = gradle.versionName
5 |
6 | def siteUrl = 'https://github.com/sangcomz/IndicatorDecorator' // Homepage URL of the library
7 | def gitUrl = 'https://github.com/sangcomz/IndicatorDecorator.git' // Git repository URL
8 | group = "xyz.sangcomz" // Maven Group ID for the artifact
9 |
10 |
11 | install {
12 | repositories.mavenInstaller {
13 | // This generates POM.xml with proper parameters
14 | pom {
15 | project {
16 | packaging 'aar'
17 |
18 | // Add your description here
19 | name 'IndicatorDecorator'
20 | description = 'Indicator decorator is an indicator that can be used in ViewPager2 and RecyclerView.'
21 | url siteUrl
22 |
23 | // Set your license
24 | licenses {
25 | license {
26 | name 'The Apache Software License, Version 2.0'
27 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
28 | }
29 | }
30 | developers {
31 | developer {
32 | id 'sangcomz'
33 | name 'Jeong Seokwon'
34 | email 'sangcomz@naver.com'
35 | }
36 | }
37 | scm {
38 | connection gitUrl
39 | developerConnection gitUrl
40 | url siteUrl
41 |
42 | }
43 | }
44 | }
45 | }
46 | }
47 |
48 | task sourcesJar(type: Jar) {
49 | from android.sourceSets.main.java.srcDirs
50 | classifier = 'sources'
51 | }
52 |
53 | afterEvaluate {
54 | javadoc.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
55 | }
56 |
57 | task javadoc(type: Javadoc) {
58 | source = android.sourceSets.main.java.srcDirs
59 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
60 | }
61 |
62 |
63 | task javadocJar(type: Jar, dependsOn: javadoc) {
64 | classifier = 'javadoc'
65 | from javadoc.destinationDir
66 |
67 | }
68 | artifacts {
69 | archives javadocJar
70 | archives sourcesJar
71 | }
72 |
73 | if (project.rootProject.file('local.properties').isFile()) {
74 | Properties properties = new Properties()
75 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
76 |
77 | bintray {
78 | user = properties.getProperty("bintray.user", '')
79 | key = properties.getProperty("bintray.apikey", '')
80 | publish = true
81 | configurations = ['archives']
82 | pkg {
83 | repo = "maven"
84 | // it is the name that appears in bintray when logged
85 | name = "IndicatorDecorator"
86 | websiteUrl = siteUrl
87 | vcsUrl = gitUrl
88 | licenses = ["Apache-2.0"]
89 | publish = true
90 | }
91 | }
92 |
93 |
94 | github {
95 | owner = 'sangcomz'
96 | repo = 'IndicatorDecorator'
97 | token = properties.getProperty("github_access_tokens", ' ')
98 | tagName = version
99 | targetCommitish = 'master'
100 | body = """## Release Note
101 | * [Feature] Indicators to overlap. Use`isOverlap` (#2)
102 | 8 [Feature] Indicator background setting method added (#4)
103 | """
104 | name = version
105 | }
106 | }
107 |
108 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 19 22:57:45 KST 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.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/indicatordecorator/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/indicatordecorator/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | buildscript {
6 | repositories {
7 | jcenter()
8 | mavenCentral()
9 | }
10 |
11 | dependencies {
12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
13 | classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3"
14 | classpath 'co.riiid:gradle-github-plugin:0.4.2'
15 | }
16 | }
17 |
18 | android {
19 | compileSdkVersion gradle.compileSdk
20 | defaultConfig {
21 | minSdkVersion gradle.minSdk
22 | targetSdkVersion gradle.targetSdk
23 | versionCode gradle.versionCode
24 | versionName gradle.versionName
25 |
26 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
27 | consumerProguardFiles 'consumer-rules.pro'
28 | }
29 | }
30 |
31 | apply plugin: 'com.github.dcendents.android-maven'
32 | apply plugin: "com.jfrog.bintray"
33 | apply plugin: 'co.riiid.gradle'
34 |
35 | apply from: '../gradle/release.gradle'
36 |
37 | dependencies {
38 | implementation fileTree(dir: 'libs', include: ['*.jar'])
39 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
40 | implementation 'androidx.appcompat:appcompat:1.2.0'
41 | implementation 'androidx.core:core-ktx:1.3.1'
42 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
43 | testImplementation 'junit:junit:4.13'
44 | androidTestImplementation 'androidx.test:runner:1.3.0'
45 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
46 | }
47 |
48 | tasks.withType(Javadoc).all {
49 | enabled = false
50 | }
--------------------------------------------------------------------------------
/indicatordecorator/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/indicatordecorator/consumer-rules.pro
--------------------------------------------------------------------------------
/indicatordecorator/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/indicatordecorator/src/androidTest/java/xyz/sangcomz/indicatordecorator/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecorator
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("xyz.sangcomz.indicatordecorator.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/indicatordecorator/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/indicatordecorator/src/main/java/xyz/sangcomz/indicatordecorator/IndicatorItemDecoration.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecorator
2 |
3 | import android.graphics.*
4 | import android.view.View
5 | import androidx.recyclerview.widget.LinearLayoutManager
6 | import androidx.recyclerview.widget.RecyclerView
7 | import xyz.sangcomz.indicatordecorator.ext.toDP
8 | import xyz.sangcomz.indicatordecorator.shape.CircleIndicator
9 | import xyz.sangcomz.indicatordecorator.shape.IndicatorShape
10 | import kotlin.math.max
11 |
12 | /**
13 | * inspired by https://github.com/bleeding182/recyclerviewItemDecorations
14 | */
15 | class IndicatorItemDecoration : RecyclerView.ItemDecoration() {
16 | /**
17 | * Top Offset with Page Item
18 | */
19 | var topOffset = 4.toDP().toInt()
20 | /**
21 | * Bottom Offset in View
22 | */
23 | var bottomOffset = 4.toDP().toInt()
24 | /**
25 | * Padding between indicators.
26 | */
27 | var indicatorItemPadding = 8.toDP()
28 | /**
29 | * Indicator shape
30 | */
31 | var isOverlap: Boolean = false
32 |
33 | private val backgroundPaint = Paint()
34 | /**
35 | * Background visibility
36 | */
37 | var isShowBackground = false
38 | /**
39 | * Background Color
40 | */
41 | var backgroundColor = Color.WHITE
42 | /**
43 | * Background Corner Radius
44 | */
45 | var backgroundCornerRadius = 8.toDP()
46 | /**
47 | * Background side offset
48 | */
49 | var backgroundSideOffset = 16.toDP().toInt()
50 | /**
51 | * Background top And bottom offset
52 | */
53 | var backgroundTopAndBottomOffset = 4.toDP().toInt()
54 |
55 | /**
56 | * Indicator shape
57 | * By default it has a circle of radius 4.
58 | */
59 | var indicatorShape: IndicatorShape = CircleIndicator().apply { radius = 4.toDP() }
60 |
61 | override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
62 | super.onDrawOver(c, parent, state)
63 |
64 | val adapter = parent.adapter ?: return
65 | val layoutManager: LinearLayoutManager =
66 | parent.layoutManager as? LinearLayoutManager ?: return
67 |
68 | val itemCount = adapter.itemCount
69 |
70 | val totalLength = indicatorShape.getIndicatorWidth() * itemCount
71 |
72 | val paddingBetweenItems = max(0, itemCount - 1) * indicatorItemPadding
73 | val indicatorTotalWidth = totalLength + paddingBetweenItems
74 | val indicatorStartX = (parent.width - indicatorTotalWidth) / 2f
75 |
76 | val indicatorPosY =
77 | if (isOverlap) parent.height - indicatorShape.getIndicatorHeight() - bottomOffset
78 | else parent.height - (indicatorShape.getIndicatorHeight() / 2) - bottomOffset
79 |
80 | if (isShowBackground)
81 | drawBackground(
82 | c,
83 | indicatorTotalWidth,
84 | indicatorStartX,
85 | parent.height.toFloat() - bottomOffset
86 | )
87 |
88 | drawInactiveIndicators(c, indicatorStartX, indicatorPosY, itemCount)
89 |
90 | val activePosition = layoutManager.findFirstVisibleItemPosition()
91 | if (activePosition == RecyclerView.NO_POSITION) return
92 | layoutManager.findViewByPosition(activePosition)?.run {
93 | drawSelectedIndicators(
94 | c,
95 | activePosition + if (width / 2f > width + left) 1 else 0,
96 | indicatorStartX,
97 | indicatorPosY
98 | )
99 | }
100 | }
101 |
102 | private fun drawBackground(
103 | c: Canvas,
104 | totalWidth: Float,
105 | startX: Float,
106 | bottomY: Float
107 | ) {
108 | val rectF = RectF()
109 |
110 | backgroundPaint.color = backgroundColor
111 | rectF.set(
112 | startX + indicatorShape.getIndicatorWidth() / 2 - indicatorShape.drawStartPosition - backgroundSideOffset,
113 | bottomY - indicatorShape.getIndicatorHeight() - indicatorShape.drawStartPosition - backgroundTopAndBottomOffset,
114 | startX + totalWidth + indicatorShape.getIndicatorWidth() / 2 - indicatorShape.drawStartPosition + backgroundSideOffset,
115 | bottomY - indicatorShape.drawStartPosition + backgroundTopAndBottomOffset
116 | )
117 | c.drawRoundRect(rectF, backgroundCornerRadius, backgroundCornerRadius, backgroundPaint)
118 | }
119 |
120 | private fun drawInactiveIndicators(
121 | c: Canvas,
122 | indicatorStartX: Float,
123 | indicatorPosY: Float,
124 | itemCount: Int
125 | ) {
126 | val itemWidth = indicatorShape.getIndicatorWidth() + indicatorItemPadding
127 |
128 | var start = indicatorStartX
129 | for (i in 0 until itemCount) {
130 | indicatorShape.inactiveIndicatorDraw(
131 | c, start + indicatorShape.getIndicatorWidth() / 2,
132 | indicatorPosY
133 | )
134 | start += itemWidth
135 | }
136 | }
137 |
138 | private fun drawSelectedIndicators(
139 | c: Canvas,
140 | selectedPosition: Int,
141 | indicatorStartX: Float,
142 | indicatorPosY: Float
143 | ) {
144 | val itemWidth = indicatorShape.getIndicatorWidth() + indicatorItemPadding
145 | val start = indicatorStartX + itemWidth * selectedPosition
146 |
147 | indicatorShape.activeIndicatorDraw(
148 | c,
149 | start + indicatorShape.getIndicatorWidth() / 2,
150 | indicatorPosY
151 | )
152 | }
153 |
154 |
155 | override fun getItemOffsets(
156 | outRect: Rect,
157 | view: View,
158 | parent: RecyclerView,
159 | state: RecyclerView.State
160 | ) {
161 | super.getItemOffsets(outRect, view, parent, state)
162 | if (!isOverlap)
163 | outRect.bottom = getTotalHeight().toInt()
164 | }
165 |
166 | private fun getTotalHeight() = topOffset + bottomOffset + indicatorShape.getIndicatorHeight()
167 |
168 | }
--------------------------------------------------------------------------------
/indicatordecorator/src/main/java/xyz/sangcomz/indicatordecorator/ext/IntExt.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecorator.ext
2 |
3 | import android.content.res.Resources
4 |
5 | fun Int.toDP()= Resources.getSystem().displayMetrics.density * this
--------------------------------------------------------------------------------
/indicatordecorator/src/main/java/xyz/sangcomz/indicatordecorator/shape/CircleIndicator.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecorator.shape
2 |
3 | import android.graphics.Canvas
4 | import android.graphics.Color
5 | import android.graphics.Paint
6 | import xyz.sangcomz.indicatordecorator.ext.toDP
7 |
8 | class CircleIndicator : IndicatorShape {
9 | private val paint = Paint().apply { isAntiAlias = true }
10 | override val drawStartPosition: Float
11 | get() = radius
12 | var colorActive: Int = Color.CYAN
13 | var colorInactive: Int = Color.GRAY
14 | var radius: Float = 4.toDP()
15 |
16 | override var scaleFactor: Float = 1.2f
17 |
18 | override fun getIndicatorWidth() = radius * 2
19 | override fun getIndicatorHeight() = radius * 2
20 | override fun inactiveIndicatorDraw(c: Canvas, x: Float, y: Float) {
21 | paint.color = colorInactive
22 | c.drawCircle(x, y, radius, paint)
23 | }
24 |
25 | override fun activeIndicatorDraw(c: Canvas, x: Float, y: Float) {
26 | paint.color = colorActive
27 | c.drawCircle(x, y, radius * scaleFactor, paint)
28 | }
29 | }
--------------------------------------------------------------------------------
/indicatordecorator/src/main/java/xyz/sangcomz/indicatordecorator/shape/DrawableIndicator.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecorator.shape
2 |
3 | import android.graphics.Canvas
4 | import android.graphics.drawable.Drawable
5 |
6 |
7 | class DrawableIndicator(
8 | drawableActive: Drawable,
9 | drawableInActive: Drawable
10 | ) : IndicatorShape {
11 | override val drawStartPosition = 0f
12 | override var scaleFactor: Float = 1.2f
13 |
14 | var width: Float = drawableActive.intrinsicWidth.toFloat()
15 | var height: Float = drawableActive.intrinsicHeight.toFloat()
16 | var drawableActive = drawableActive
17 | var drawableInActive = drawableInActive
18 |
19 |
20 | override fun inactiveIndicatorDraw(c: Canvas, x: Float, y: Float) {
21 | drawableInActive.setBounds(
22 | x.toInt(),
23 | (y - height / 2).toInt(),
24 | (x + width).toInt(),
25 | (y + height / 2).toInt()
26 | )
27 | drawableInActive.draw(c)
28 | }
29 |
30 | override fun activeIndicatorDraw(c: Canvas, x: Float, y: Float) {
31 | val widthScale = ((width * scaleFactor) - width) / 2
32 | val heightScale = ((height * scaleFactor) - height) / 2
33 | drawableActive.setBounds(
34 | (x - widthScale).toInt(),
35 | (y - height / 2 - heightScale).toInt(),
36 | (x + width + widthScale).toInt(),
37 | (y + height / 2 + heightScale).toInt()
38 | )
39 | drawableActive.draw(c)
40 | }
41 |
42 | override fun getIndicatorWidth() = width
43 |
44 | override fun getIndicatorHeight() = height
45 | }
--------------------------------------------------------------------------------
/indicatordecorator/src/main/java/xyz/sangcomz/indicatordecorator/shape/IndicatorShape.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecorator.shape
2 |
3 | import android.graphics.Canvas
4 |
5 | interface IndicatorShape {
6 | /**
7 | * Factor associated with the selected indicator scale value
8 | */
9 | var scaleFactor: Float
10 |
11 | /**
12 | * The starting coordinate that is actually drawn
13 | * For example, when drawing a square, draw a circle from the x coordinate to the width and a circle the radius of both sides of the x coordinate.
14 | */
15 | val drawStartPosition: Float
16 | /**
17 | * To draw inactive indicator
18 | */
19 | fun inactiveIndicatorDraw(c: Canvas, x: Float, y: Float)
20 |
21 | /**
22 | * To draw active indicator
23 | */
24 | fun activeIndicatorDraw(c: Canvas, x: Float, y: Float)
25 |
26 | /**
27 | * get indicator width
28 | */
29 | fun getIndicatorWidth(): Float
30 |
31 | /**
32 | * get indicator height
33 | */
34 | fun getIndicatorHeight(): Float
35 | }
--------------------------------------------------------------------------------
/indicatordecorator/src/main/java/xyz/sangcomz/indicatordecorator/shape/SquareIndicator.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecorator.shape
2 |
3 | import android.graphics.Canvas
4 | import android.graphics.Color
5 | import android.graphics.Paint
6 | import xyz.sangcomz.indicatordecorator.ext.toDP
7 |
8 | class SquareIndicator : IndicatorShape {
9 | override val drawStartPosition = 0f
10 |
11 | private val paint = Paint().apply { isAntiAlias = true }
12 |
13 | var colorActive: Int = Color.BLACK
14 | var colorInactive: Int = Color.GRAY
15 | var width = 8.toDP()
16 |
17 |
18 | override var scaleFactor = 1.2f
19 | override fun inactiveIndicatorDraw(c: Canvas, x: Float, y: Float) {
20 | paint.color = colorInactive
21 | c.drawRect(x, y - width / 2, x + width, y + width / 2, paint)
22 | }
23 |
24 | override fun activeIndicatorDraw(c: Canvas, x: Float, y: Float) {
25 | paint.color = colorActive
26 | val scale = ((width * scaleFactor) - width) / 2
27 | c.drawRect(
28 | x - scale,
29 | y - (width * scaleFactor) / 2,
30 | x + width + scale,
31 | y + (width * scaleFactor) / 2,
32 | paint
33 | )
34 | }
35 |
36 | override fun getIndicatorWidth() = width
37 | override fun getIndicatorHeight() = width
38 | }
--------------------------------------------------------------------------------
/indicatordecorator/src/test/java/xyz/sangcomz/indicatordecorator/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package xyz.sangcomz.indicatordecorator
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/pic/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/pic/banner.png
--------------------------------------------------------------------------------
/pic/sample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangcomz/IndicatorDecorator/d5fee05dbb1b01ba80d1c421c766d1e75ad25894/pic/sample.gif
--------------------------------------------------------------------------------
/release.sh:
--------------------------------------------------------------------------------
1 | ./gradlew clean bintrayUpload githubRelease
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':indicatordecorator'
2 | rootProject.name = 'IndicatorDecorator'
3 |
4 | gradle.ext.versionCode = 4
5 | gradle.ext.versionName = '0.2.0'
6 |
7 | gradle.ext.set('minSdk', 21)
8 | gradle.ext.set('targetSdk', 29)
9 | gradle.ext.set('compileSdk', 29)
10 |
--------------------------------------------------------------------------------