├── .gitignore ├── .idea └── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── .travis.yml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── chahinem │ │ └── pageindicator │ │ └── sample │ │ ├── MainActivity.kt │ │ ├── MyAdapter.kt │ │ └── MyPagerAdapter.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_main.xml │ ├── item_card.xml │ └── item_simple.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 ├── art ├── pageindicator.gif └── pageindicator.mp4 ├── build.gradle ├── dependencies.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pageindicator ├── .gitignore ├── build.gradle └── src │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── chahinem │ │ │ └── pageindicator │ │ │ ├── DotManager.kt │ │ │ ├── Dps.kt │ │ │ ├── PageChangeListener.kt │ │ │ ├── PageIndicator.kt │ │ │ ├── SavedState.kt │ │ │ └── ScrollListener.kt │ └── res │ │ ├── anim │ │ └── pi_default_interpolator.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── chahinem │ └── pageindicator │ └── DotManagerTest.kt └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # [Android] ======================== 2 | # Built application files 3 | *.apk 4 | *.ap_ 5 | 6 | # Files for the Dalvik VM 7 | *.dex 8 | 9 | # Java class files 10 | *.class 11 | 12 | # Generated files 13 | bin/ 14 | gen/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | 30 | ## Directory-based project format: 31 | .idea/ 32 | 33 | ## File-based project format: 34 | *.ipr 35 | *.iws 36 | 37 | ## Plugin-specific files: 38 | 39 | # IntelliJ 40 | out/ 41 | 42 | # mpeltonen/sbt-idea plugin 43 | .idea_modules/ 44 | 45 | # JIRA plugin 46 | atlassian-ide-plugin.xml 47 | 48 | # Crashlytics plugin (for Android Studio and IntelliJ) 49 | com_crashlytics_export_strings.xml 50 | 51 | 52 | # [Maven] ======================== 53 | target/ 54 | pom.xml.tag 55 | pom.xml.releaseBackup 56 | pom.xml.versionsBackup 57 | pom.xml.next 58 | release.properties 59 | 60 | 61 | # [Gradle-Android] ======================== 62 | 63 | # Ignore Gradle GUI config 64 | gradle-app.setting 65 | 66 | # Gradle Signing 67 | signing.properties 68 | trestle.keystore 69 | 70 | # Mobile Tools for Java (J2ME) 71 | .mtj.tmp/ 72 | 73 | # Package Files # 74 | *.jar 75 | *.war 76 | *.ear 77 | 78 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 79 | hs_err_pid* 80 | 81 | # Misc 82 | /.idea/workspace.xml 83 | .DS_Store 84 | /captures 85 | **/*.iml 86 | *.classgradle.properties 87 | 88 | 89 | # keep code style 90 | !.idea/codeStyles/ 91 | !.idea/codeStyles/** -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 1003 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: android 4 | dist: trusty 5 | 6 | android: 7 | components: 8 | - tools 9 | - platform-tools 10 | - build-tools-28.0.3 11 | - android-28 12 | - extra-google-m2repository 13 | - extra-android-m2repository 14 | licenses: 15 | - 'android-sdk-license-.+' 16 | - 'google-gdk-license-.+' 17 | 18 | before_install: 19 | - echo yes | sdkmanager "platforms;android-28" 20 | 21 | script: 22 | - ./gradlew clean build -PdisablePreDex --stacktrace --console plain 23 | 24 | jdk: 25 | - oraclejdk8 26 | 27 | branches: 28 | only: 29 | - master 30 | 31 | before_cache: 32 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 33 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 34 | cache: 35 | directories: 36 | - $HOME/.gradle/caches/ 37 | - $HOME/.gradle/wrapper/ 38 | - $HOME/.android/build-cache 39 | 40 | sudo: false -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Chahine Mouhamad 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/chahine/pageindicator.svg?branch=master)](https://travis-ci.org/chahine/pageindicator) 2 | [![](https://jitpack.io/v/chahine/pageindicator.svg)](https://jitpack.io/#chahine/pageindicator) 3 | 4 | # Page Indicator 5 | 6 | An Instagram like page indicator compatible with [RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html) and [ViewPager](https://developer.android.com/reference/android/support/v4/view/ViewPager.html). 7 | 8 | ![Preview](/art/pageindicator.gif) 9 | 10 | # Setup 11 | 12 | __Step 1.__ Add the JitPack repository to your build file 13 | ```groovy 14 | allprojects { 15 | repositories { 16 | maven { url 'https://jitpack.io' } 17 | } 18 | } 19 | ``` 20 | __Step 2.__ Add the dependency 21 | 22 | ```groovy 23 | dependencies { 24 | compile 'com.github.chahine:pageindicator:' 25 | } 26 | ``` 27 | 28 | # Usage 29 | 30 | Add the `PageIndicator` to your XML file: 31 | 32 | ```xml 33 | 38 | ``` 39 | 40 | #### RecyclerView 41 | 42 | ```kotlin 43 | pageIndicator.attachTo(recyclerView) 44 | ``` 45 | 46 | By default, attaching to a RecyclerView will end up updating the pageIndicator when the most visible item position changes and expect the RecyclerView items to have the same width. 47 | If you would like to customize this behavior, add a scroll listener to your RecyclerView and use `PageIndicator::swipeNext` and `PageIndicator::swipePrevious`; and set the pageIndicator's count 48 | 49 | #### View Pager 50 | 51 | ```kotlin 52 | pageIndicator.attachTo(viewPager) 53 | ``` 54 | 55 | #### Manual 56 | ```kotlin 57 | pageIndicator.swipePrevious() 58 | pageIndicator.swipeNext() 59 | ``` 60 | 61 | # Customization 62 | 63 | | Attribute | Note | Default | 64 | |---------------------|-------------------------------------------|-------------| 65 | | piDotSpacing | Spacing between dots | 3dp | 66 | | piDotBound | Range in which the selected dot remains | 40dp | 67 | | piSize[1-6] | Size from smallest to largest dot | .5dp - 6dp | 68 | | piAnimDuration | Duration of animation* in ms | 200 | 69 | | piAnimInterpolator | Animation interpolator* | decelerate | 70 | | piDefaultColor | Default unselected dot color | #B2B2B2 | 71 | | piSelectedColor | Selected dot color | #3897F0 | 72 | 73 | 74 | *Note: the animation duration and interpolator are shared between the scroll animation and dot scaling animation. 75 | 76 | ## License 77 | 78 | ``` 79 | MIT License 80 | 81 | Copyright (c) 2018 Chahine Mouhamad 82 | 83 | Permission is hereby granted, free of charge, to any person obtaining a copy 84 | of this software and associated documentation files (the "Software"), to deal 85 | in the Software without restriction, including without limitation the rights 86 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 87 | copies of the Software, and to permit persons to whom the Software is 88 | furnished to do so, subject to the following conditions: 89 | 90 | The above copyright notice and this permission notice shall be included in all 91 | copies or substantial portions of the Software. 92 | 93 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 94 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 95 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 96 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 97 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 98 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 99 | SOFTWARE. 100 | 101 | ``` 102 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion rootProject.compileSdkVersion 7 | 8 | defaultConfig { 9 | applicationId 'com.chahinem.pageindicator.sample' 10 | 11 | minSdkVersion rootProject.minSdkVersion 12 | targetSdkVersion rootProject.targetSdkVersion 13 | 14 | versionCode 1 15 | versionName '1.0' 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation project(':pageindicator') 23 | 24 | implementation rootProject.kotlinStdlib 25 | implementation rootProject.picasso 26 | implementation rootProject.supportLibs 27 | } 28 | -------------------------------------------------------------------------------- /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/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/chahinem/pageindicator/sample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.chahinem.pageindicator.sample 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import androidx.recyclerview.widget.LinearSnapHelper 6 | import com.chahinem.pageindicator.sample.MyAdapter.MyItem 7 | import com.squareup.picasso.Picasso.Builder 8 | import kotlinx.android.synthetic.main.activity_main.* 9 | 10 | class MainActivity : AppCompatActivity() { 11 | 12 | override fun onCreate(savedInstanceState: Bundle?) { 13 | super.onCreate(savedInstanceState) 14 | setContentView(R.layout.activity_main) 15 | 16 | val picasso = Builder(this).build() 17 | 18 | // RecyclerView 19 | val adapter = MyAdapter(picasso) 20 | list.adapter = adapter 21 | LinearSnapHelper().attachToRecyclerView(list) 22 | adapter.swapData(LIST_ITEMS) 23 | pageIndicator attachTo list 24 | pageIndicator2 attachTo list 25 | 26 | // ViewPager 27 | val myPagerAdapter = MyPagerAdapter(picasso, LIST_ITEMS) 28 | pager.adapter = myPagerAdapter 29 | pagerPageIndicator attachTo pager 30 | 31 | // Manual 32 | manualPageIndicator.count = 50 33 | leftBtn.setOnClickListener { manualPageIndicator.swipePrevious() } 34 | rightBtn.setOnClickListener { manualPageIndicator.swipeNext() } 35 | } 36 | 37 | companion object { 38 | private val LIST_ITEMS = listOf( 39 | MyItem( 40 | "Cormorant fishing at sunset", 41 | "Patryk Wojciechowicz", 42 | "https://cdn.dribbble.com/users/3178178/screenshots/6287074/cormorant_fishing_1600x1200_final_04_05_2019_4x.jpg"), 43 | MyItem( 44 | "Mountain House", 45 | "Alex Pasquarella", 46 | "https://cdn.dribbble.com/users/989466/screenshots/6100954/cabin-2-dribbble-alex-pasquarella_4x.png"), 47 | MyItem( 48 | "journey", 49 | "Febin_Raj", 50 | "https://cdn.dribbble.com/users/1803663/screenshots/6163551/nature-4_4x.png"), 51 | MyItem( 52 | "Explorer", 53 | "Uran", 54 | "https://cdn.dribbble.com/users/1355613/screenshots/6441984/landscape_4x.jpg"), 55 | MyItem( 56 | "Fishers Peak Limited Edition Print", 57 | "Brian Edward Miller ", 58 | "https://cdn.dribbble.com/users/329207/screenshots/6128300/bemocs_fisherspeak_dribbble.jpg"), 59 | MyItem( 60 | "First Man", 61 | "Lana Marandina", 62 | "https://cdn.dribbble.com/users/1461762/screenshots/6280906/first_man_lana_marandina_4x.png"), 63 | MyItem( 64 | "On The Road Again", 65 | "Brian Edward Miller", 66 | "https://cdn.dribbble.com/users/329207/screenshots/6522800/2026_nationwide_02_train_landscape_v01.00.jpg") 67 | ) 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/chahinem/pageindicator/sample/MyAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.chahinem.pageindicator.sample 2 | 3 | import android.view.LayoutInflater 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import android.widget.ImageView 7 | import android.widget.TextView 8 | import androidx.recyclerview.widget.RecyclerView 9 | import com.chahinem.pageindicator.sample.MyAdapter.MyViewHolder 10 | import com.squareup.picasso.Picasso 11 | 12 | class MyAdapter(private val picasso: Picasso) : RecyclerView.Adapter() { 13 | 14 | private val items: MutableList = mutableListOf() 15 | 16 | override fun getItemCount() = items.size 17 | 18 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = MyViewHolder( 19 | LayoutInflater 20 | .from(parent.context) 21 | .inflate(R.layout.item_card, parent, false)) 22 | 23 | override fun onBindViewHolder(holder: MyViewHolder, position: Int) { 24 | holder.bind(picasso, items[holder.adapterPosition]) 25 | } 26 | 27 | fun swapData(data: Iterable?) { 28 | items.clear() 29 | data?.let { items.addAll(data) } 30 | notifyDataSetChanged() 31 | } 32 | 33 | class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 34 | 35 | private val title: TextView = itemView.findViewById(R.id.title) 36 | private val caption: TextView = itemView.findViewById(R.id.caption) 37 | private val image: ImageView = itemView.findViewById(R.id.image) 38 | 39 | fun bind(picasso: Picasso, item: MyItem) { 40 | picasso 41 | .load(item.image) 42 | .placeholder(R.color.colorPrimaryDark) 43 | .fit() 44 | .centerCrop() 45 | .into(image) 46 | title.text = item.title 47 | caption.text = item.caption 48 | } 49 | } 50 | 51 | class MyItem(val title: String, val caption: String, val image: String) 52 | } -------------------------------------------------------------------------------- /app/src/main/java/com/chahinem/pageindicator/sample/MyPagerAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.chahinem.pageindicator.sample 2 | 3 | import android.view.LayoutInflater 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import android.widget.ImageView 7 | import android.widget.TextView 8 | import androidx.viewpager.widget.PagerAdapter 9 | import com.chahinem.pageindicator.sample.MyAdapter.MyItem 10 | import com.squareup.picasso.Picasso 11 | 12 | class MyPagerAdapter(private val picasso: Picasso, 13 | private val items: List) : PagerAdapter() { 14 | 15 | override fun getCount() = items.size 16 | 17 | override fun isViewFromObject(view: View, `object`: Any): Boolean = view == `object` 18 | 19 | override fun instantiateItem(container: ViewGroup, position: Int): Any { 20 | val view = LayoutInflater 21 | .from(container.context) 22 | .inflate(R.layout.item_card, container, false) 23 | 24 | val item = items[position] 25 | val title: TextView = view.findViewById(R.id.title) 26 | val caption: TextView = view.findViewById(R.id.caption) 27 | val image: ImageView = view.findViewById(R.id.image) 28 | 29 | picasso 30 | .load(item.image) 31 | .placeholder(R.color.colorPrimaryDark) 32 | .fit() 33 | .centerCrop() 34 | .into(image) 35 | title.text = item.title 36 | caption.text = item.caption 37 | 38 | container.addView(view) 39 | return view 40 | } 41 | 42 | override fun destroyItem(container: ViewGroup, position: Int, view: Any) { 43 | container.removeView(view as View) 44 | } 45 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 8 | 14 | 15 | 22 | 26 | 30 | 31 | 32 | 33 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 13 | 19 | 25 | 31 | 37 | 43 | 49 | 55 | 61 | 67 | 73 | 79 | 85 | 91 | 97 | 103 | 109 | 115 | 121 | 127 | 133 | 139 | 145 | 151 | 157 | 163 | 169 | 175 | 181 | 187 | 193 | 199 | 205 | 206 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 14 | 15 | 22 | 23 | 31 | 32 | 39 | 40 | 55 | 56 | 64 | 65 | 70 | 71 | 78 | 79 | 87 | 88 | 94 | 95 | 102 |