├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── wildscrolllibrary ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── ids.xml │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ └── attrs_wildscroll.xml │ │ ├── drawable │ │ │ ├── fastscroll_background_popup.xml │ │ │ └── fastscroll_popup_circle.xml │ │ └── layout │ │ │ └── popup_section.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── appspell │ │ └── wildscroll │ │ ├── adapter │ │ ├── SectionFastScroll.kt │ │ └── SectionFastScrollAdapter.kt │ │ ├── sections │ │ ├── popup │ │ │ ├── SectionPopup.kt │ │ │ ├── SectionCirclePopup.kt │ │ │ └── SectionLetterPopup.kt │ │ ├── Sections.kt │ │ ├── fastscroll │ │ │ └── FastScroll.kt │ │ └── SectionBarView.kt │ │ ├── coroutines │ │ └── Android.kt │ │ └── view │ │ └── WildScrollRecyclerView.kt ├── proguard-rules.pro ├── .gitignore └── build.gradle ├── app ├── src │ └── main │ │ ├── res │ │ ├── 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 │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ ├── styles.xml │ │ │ └── colors.xml │ │ ├── drawable-mdpi │ │ │ ├── background_circle.xml │ │ │ └── background_popup.xml │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── drawable │ │ │ ├── ic_circle.xml │ │ │ ├── ic_android.xml │ │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ │ ├── fragment_simple.xml │ │ │ ├── fragment_custom_programmatically.xml │ │ │ ├── fragment_sections.xml │ │ │ ├── activity_main.xml │ │ │ ├── fragment_custom.xml │ │ │ ├── item_sections_section.xml │ │ │ ├── item_sample_list.xml │ │ │ ├── item_sections_item.xml │ │ │ └── item_second_sample_list.xml │ │ └── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ └── com │ │ │ └── appspell │ │ │ └── wildscroll │ │ │ ├── data │ │ │ ├── Company.kt │ │ │ └── DataSource.kt │ │ │ ├── fragments │ │ │ ├── SimpleFragment.kt │ │ │ ├── CustomLayoutFragment.kt │ │ │ ├── SectionsFragment.kt │ │ │ └── CustomProgrammaticallyFragment.kt │ │ │ ├── adapter │ │ │ ├── SimpleAdapter.kt │ │ │ ├── SimpleSecondAdapter.kt │ │ │ └── SectionsAdapter.kt │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml ├── proguard-rules.pro ├── .gitignore └── build.gradle ├── .idea ├── vcs.xml ├── modules.xml ├── runConfigurations.xml └── misc.xml ├── gradle.properties ├── .gitignore ├── LICENSE ├── gradlew.bat ├── gradlew └── README.md /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':wildscrolllibrary' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appspell/Wild-Scroll/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | WildScrollLibrary 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appspell/Wild-Scroll/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appspell/Wild-Scroll/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appspell/Wild-Scroll/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appspell/Wild-Scroll/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appspell/Wild-Scroll/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appspell/Wild-Scroll/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appspell/Wild-Scroll/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appspell/Wild-Scroll/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appspell/Wild-Scroll/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appspell/Wild-Scroll/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/java/com/appspell/wildscroll/adapter/SectionFastScroll.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.adapter 2 | 3 | interface SectionFastScroll { 4 | fun getSectionName(position: Int): String 5 | } -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/appspell/wildscroll/data/Company.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.data 2 | 3 | data class Company(val company: String, 4 | val phrase: String, 5 | val street: String, 6 | val avatar: String) -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8dp 4 | 12sp 5 | 16sp 6 | 42sp 7 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/res/drawable/fastscroll_background_popup.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/background_circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jan 02 15:11:03 MSK 2018 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-4.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/res/drawable/fastscroll_popup_circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Wild Scroll 3 | Simple 4 | Layout 5 | Programmatically 6 | Sections 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/background_popup.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_circle.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #00000000 4 | #85000000 5 | #d9000000 6 | #07000000 7 | #1c757575 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 24sp 4 | 16dp 5 | 6 | 3dp 7 | 8 | 10sp 9 | 13sp 10 | 8dp 11 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #2196F3 4 | #2196F3 5 | #0D47A1 6 | #E3F2FD 7 | #00BCD4 8 | #006064 9 | #E0F7FA 10 | #d8000000 11 | #82000000 12 | #10000000 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_simple.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_custom_programmatically.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/res/layout/popup_section.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | -------------------------------------------------------------------------------- /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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/java/com/appspell/wildscroll/adapter/SectionFastScrollAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.adapter 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.support.v7.widget.RecyclerView.ViewHolder 5 | import com.appspell.wildscroll.sections.SectionInfo 6 | 7 | abstract class SectionFastScrollAdapter : RecyclerView.Adapter(), SectionFastScroll { 8 | 9 | var sections: Map = emptyMap() 10 | set(value) { 11 | field = value 12 | value.values.forEach { section -> 13 | notifyItemChanged(section.position) 14 | } 15 | } 16 | 17 | open fun isSection(position: Int): Boolean = sections.containsKey(position) 18 | 19 | fun getSectionInfo(position: Int) = sections[position] 20 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /wildscrolllibrary/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/res/drawable/ic_android.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 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 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | 43 | # Keystore files 44 | *.jks 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json 56 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 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 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | 43 | # Keystore files 44 | *.jks 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json -------------------------------------------------------------------------------- /wildscrolllibrary/.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 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 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | 43 | # Keystore files 44 | *.jks 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/java/com/appspell/wildscroll/sections/popup/SectionPopup.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.sections.popup 2 | 3 | import android.graphics.Canvas 4 | import android.graphics.Rect 5 | import com.appspell.wildscroll.sections.Sections 6 | 7 | interface SectionPopup { 8 | fun show(section: String, x: Int, y: Int, parentWidth: Int, parentHeight: Int, sections: Sections) 9 | fun dismiss() 10 | fun draw(canvas: Canvas) 11 | fun getRect(): Rect 12 | 13 | var onDismissListener: (() -> Unit)? 14 | var width: Int 15 | var height: Int 16 | } 17 | 18 | class StubSectionPopup : SectionPopup { 19 | override fun show(section: String, x: Int, y: Int, parentWidth: Int, parentHeight: Int, sections: Sections) {} 20 | override fun dismiss() {} 21 | override fun draw(canvas: Canvas) {} 22 | override fun getRect(): Rect = Rect(0, 0, 0, 0) 23 | 24 | override var onDismissListener: (() -> Unit)? = null 25 | override var width: Int = 0 26 | override var height: Int = 0 27 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Alexey 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 | -------------------------------------------------------------------------------- /app/src/main/java/com/appspell/wildscroll/data/DataSource.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.data 2 | 3 | import android.content.res.Resources 4 | import com.appspell.wildscroll.R 5 | import com.google.gson.GsonBuilder 6 | import com.google.gson.reflect.TypeToken 7 | 8 | 9 | class DataSource(private val resources: Resources) { 10 | val companies: List 11 | get() { 12 | val json = resources.openRawResource(R.raw.mockdata).bufferedReader().use { it.readText() } 13 | 14 | val listType = object : TypeToken>() {}.type 15 | val list = GsonBuilder().create().fromJson>(json, listType) 16 | // 17 | // val alp = "QWERTYUIOOPLKJHGFDSAZXVBNM1234567890" 18 | // for(i in 0..100000) { 19 | // var name = "" 20 | // for (n in 0..20) { 21 | // name += alp[Random().nextInt(alp.length)] 22 | // } 23 | // 24 | // list.add(Company(name, name[0].toUpperCase().toString())) 25 | // } 26 | return list.sortedBy { it.company } //TODO do it in background 27 | } 28 | 29 | } 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/appspell/wildscroll/fragments/SimpleFragment.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.fragments 2 | 3 | import android.os.Bundle 4 | import android.support.v4.app.Fragment 5 | import android.support.v7.widget.LinearLayoutManager 6 | import android.support.v7.widget.RecyclerView 7 | import android.view.LayoutInflater 8 | import android.view.View 9 | import android.view.ViewGroup 10 | import com.appspell.wildscroll.R 11 | import com.appspell.wildscroll.R.layout 12 | import com.appspell.wildscroll.adapter.SampleAdapter 13 | import com.appspell.wildscroll.data.DataSource 14 | 15 | class SimpleFragment : Fragment() { 16 | 17 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = 18 | inflater.inflate(layout.fragment_simple, container, false) 19 | 20 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 21 | val recyclerView = view.findViewById(R.id.list) 22 | with(recyclerView) { 23 | layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) 24 | adapter = SampleAdapter() 25 | (adapter as SampleAdapter).items = DataSource(resources).companies 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /app/src/main/java/com/appspell/wildscroll/fragments/CustomLayoutFragment.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.fragments 2 | 3 | import android.os.Bundle 4 | import android.support.v4.app.Fragment 5 | import android.support.v7.widget.LinearLayoutManager 6 | import android.support.v7.widget.RecyclerView 7 | import android.view.LayoutInflater 8 | import android.view.View 9 | import android.view.ViewGroup 10 | import com.appspell.wildscroll.R 11 | import com.appspell.wildscroll.R.layout 12 | import com.appspell.wildscroll.adapter.SampleAdapter 13 | import com.appspell.wildscroll.data.DataSource 14 | 15 | class CustomLayoutFragment : Fragment() { 16 | 17 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = 18 | inflater.inflate(layout.fragment_custom, container, false) 19 | 20 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 21 | val recyclerView = view.findViewById(R.id.list) 22 | with(recyclerView) { 23 | layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) 24 | adapter = SampleAdapter() 25 | (adapter as SampleAdapter).items = DataSource(resources).companies 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /app/src/main/java/com/appspell/wildscroll/fragments/SectionsFragment.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.fragments 2 | 3 | import android.os.Bundle 4 | import android.support.v4.app.Fragment 5 | import android.support.v7.widget.LinearLayoutManager 6 | import android.support.v7.widget.RecyclerView 7 | import android.view.LayoutInflater 8 | import android.view.View 9 | import android.view.ViewGroup 10 | import com.appspell.wildscroll.R 11 | import com.appspell.wildscroll.R.layout 12 | import com.appspell.wildscroll.adapter.SectionsAdapter 13 | import com.appspell.wildscroll.data.DataSource 14 | 15 | class SectionsFragment : Fragment() { 16 | 17 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = 18 | inflater.inflate(layout.fragment_sections, container, false) 19 | 20 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 21 | val recyclerView = view.findViewById(R.id.list) 22 | with(recyclerView) { 23 | layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) 24 | adapter = SectionsAdapter() 25 | (adapter as SectionsAdapter).items = DataSource(resources).companies //TODO need to duplicate section items 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/java/com/appspell/wildscroll/coroutines/Android.kt: -------------------------------------------------------------------------------- 1 | package com.eatigo.common.coroutines 2 | 3 | import android.os.Handler 4 | import android.os.Looper 5 | import kotlin.coroutines.experimental.AbstractCoroutineContextElement 6 | import kotlin.coroutines.experimental.Continuation 7 | import kotlin.coroutines.experimental.ContinuationInterceptor 8 | 9 | object Android : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor { 10 | override fun interceptContinuation(continuation: Continuation): Continuation = AndroidContinuation(continuation) 11 | } 12 | 13 | private class AndroidContinuation(val cont: Continuation) : Continuation by cont { 14 | override fun resume(value: T) { 15 | when (Looper.myLooper() == Looper.getMainLooper()) { 16 | true -> cont.resume(value) 17 | false -> Handler(Looper.getMainLooper()).post { cont.resume(value) } 18 | } 19 | } 20 | 21 | override fun resumeWithException(exception: Throwable) { 22 | when (Looper.myLooper() == Looper.getMainLooper()) { 23 | true -> cont.resumeWithException(exception) 24 | false -> Handler(Looper.getMainLooper()).post { cont.resumeWithException(exception) } 25 | } 26 | } 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_sections.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 19 | 20 | 21 | 30 | 31 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/res/values/attrs_wildscroll.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/java/com/appspell/wildscroll/sections/popup/SectionCirclePopup.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.sections.popup 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.Context 5 | import android.graphics.PorterDuff 6 | import android.support.annotation.ColorRes 7 | import android.support.annotation.DimenRes 8 | import android.support.v4.content.res.ResourcesCompat 9 | import appspell.com.wildscroll.R 10 | 11 | 12 | @SuppressLint("ResourceType") 13 | class SectionCirclePopup( 14 | context: Context, 15 | @ColorRes 16 | sectionTextColorRes: Int = R.color.fastscroll_highlight_text, 17 | @DimenRes 18 | sectionTextSizeDimen: Int = R.dimen.fastscroll_popup_section_text_size, 19 | @ColorRes 20 | backgroundColorRes: Int = R.color.fastscroll_popup_background, 21 | @DimenRes 22 | paddingRes: Int = R.dimen.fastscroll_popup_padding) 23 | : SectionLetterPopup(context = context, 24 | textColorRes = sectionTextColorRes, 25 | textSizeDimen = sectionTextSizeDimen, 26 | backgroundResource = R.drawable.fastscroll_popup_circle, 27 | paddingRes = paddingRes) { 28 | 29 | override var backgroundColorRes: Int = backgroundColorRes 30 | set(value) { 31 | field = value 32 | val color = ResourcesCompat.getColor(context.resources, value, context.theme) 33 | background?.mutate()?.setColorFilter(color, PorterDuff.Mode.SRC_IN) 34 | } 35 | 36 | init { 37 | this.backgroundColorRes = backgroundColorRes 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /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 27 9 | buildToolsVersion "27.0.2" 10 | defaultConfig { 11 | applicationId "com.appspell.wildscroll" 12 | minSdkVersion 15 13 | targetSdkVersion 27 14 | versionCode 1 15 | versionName "1.0" 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | vectorDrawables.useSupportLibrary = true 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(include: ['*.jar'], dir: 'libs') 29 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 30 | implementation 'com.android.support:appcompat-v7:27.0.2' 31 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 32 | implementation 'com.android.support:recyclerview-v7:27.0.2' 33 | implementation 'com.android.support:cardview-v7:27.0.2' 34 | implementation 'com.google.code.gson:gson:2.8.2' 35 | testImplementation 'junit:junit:4.12' 36 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 37 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 38 | implementation project(':wildscrolllibrary') 39 | implementation 'com.android.support:design:27.0.2' 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_custom.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/appspell/wildscroll/adapter/SimpleAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.adapter 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import android.widget.TextView 8 | import com.appspell.wildscroll.R 9 | import com.appspell.wildscroll.data.Company 10 | 11 | class SampleAdapter : RecyclerView.Adapter(), SectionFastScroll { 12 | var items = emptyList() 13 | set(value) { 14 | field = value 15 | notifyDataSetChanged() 16 | } 17 | 18 | override fun getItemCount() = items.size 19 | 20 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListViewHolder? { 21 | val view = LayoutInflater.from(parent.context).inflate(R.layout.item_sample_list, parent, false) 22 | return ListViewHolder(view) 23 | } 24 | 25 | override fun onBindViewHolder(holder: ListViewHolder, position: Int) { 26 | holder.bind(items[position]) 27 | } 28 | 29 | override fun getSectionName(position: Int): String = items[position].company 30 | } 31 | 32 | class ListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 33 | private val company: TextView = itemView.findViewById(R.id.company) 34 | private val phrase: TextView = itemView.findViewById(R.id.phrase) 35 | private val street: TextView = itemView.findViewById(R.id.street) 36 | 37 | fun bind(item: Company) { 38 | company.text = item.company 39 | phrase.text = item.phrase 40 | street.text = item.street 41 | } 42 | } -------------------------------------------------------------------------------- /app/src/main/java/com/appspell/wildscroll/adapter/SimpleSecondAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.adapter 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import android.widget.TextView 8 | import com.appspell.wildscroll.R 9 | import com.appspell.wildscroll.data.Company 10 | 11 | class SampleSecondAdapter : RecyclerView.Adapter(), SectionFastScroll { 12 | var items = emptyList() 13 | set(value) { 14 | field = value 15 | notifyDataSetChanged() 16 | } 17 | 18 | override fun getItemCount() = items.size 19 | 20 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SecondListViewHolder? { 21 | val view = LayoutInflater.from(parent.context).inflate(R.layout.item_second_sample_list, parent, false) 22 | return SecondListViewHolder(view) 23 | } 24 | 25 | override fun onBindViewHolder(holder: SecondListViewHolder, position: Int) { 26 | holder.bind(items[position]) 27 | } 28 | 29 | override fun getSectionName(position: Int): String = items[position].company 30 | } 31 | 32 | class SecondListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 33 | private val company: TextView = itemView.findViewById(R.id.company) 34 | private val phrase: TextView = itemView.findViewById(R.id.phrase) 35 | private val street: TextView = itemView.findViewById(R.id.street) 36 | 37 | fun bind(item: Company) { 38 | company.text = item.company 39 | phrase.text = item.phrase 40 | street.text = item.street 41 | } 42 | } -------------------------------------------------------------------------------- /wildscrolllibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'bintray-release' 5 | 6 | buildscript { 7 | repositories { 8 | jcenter() 9 | } 10 | dependencies { 11 | classpath 'com.novoda:bintray-release:0.8.0' 12 | } 13 | } 14 | 15 | android { 16 | compileSdkVersion 27 17 | buildToolsVersion "27.0.2" 18 | defaultConfig { 19 | minSdkVersion 15 20 | targetSdkVersion 27 21 | versionCode 1 22 | versionName "0.90" 23 | } 24 | 25 | buildTypes { 26 | release { 27 | minifyEnabled false 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | } 32 | 33 | kotlin { 34 | experimental { 35 | coroutines "enable" 36 | } 37 | } 38 | 39 | dependencies { 40 | implementation 'com.android.support:appcompat-v7:27.0.2' 41 | implementation "com.android.support:recyclerview-v7:27.0.2" 42 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 43 | 44 | //coroutines 45 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.19.2" 46 | } 47 | repositories { 48 | mavenCentral() 49 | jcenter() 50 | } 51 | 52 | publish { 53 | userOrg = 'appspell' 54 | groupId = 'com.appspell.wild-scroll' 55 | artifactId = 'wild-scroll' 56 | publishVersion = android.defaultConfig.versionName 57 | desc = 'Android RecyclerView Fast Scroller' 58 | website = 'https://github.com/appspell/Wild-Scroll' 59 | } 60 | 61 | tasks.withType(Javadoc).all { 62 | enabled = false 63 | } -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_sections_section.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 27 | 28 | 42 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/appspell/wildscroll/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll 2 | 3 | import android.content.Context 4 | import android.os.Bundle 5 | import android.support.design.widget.TabLayout 6 | import android.support.v4.app.Fragment 7 | import android.support.v4.app.FragmentManager 8 | import android.support.v4.app.FragmentStatePagerAdapter 9 | import android.support.v4.view.ViewPager 10 | import android.support.v7.app.AppCompatActivity 11 | import com.appspell.wildscroll.fragments.CustomLayoutFragment 12 | import com.appspell.wildscroll.fragments.CustomProgrammaticallyFragment 13 | import com.appspell.wildscroll.fragments.SimpleFragment 14 | 15 | class SampleActivity : AppCompatActivity() { 16 | 17 | override fun onCreate(savedInstanceState: Bundle?) { 18 | super.onCreate(savedInstanceState) 19 | setContentView(R.layout.activity_main) 20 | 21 | val viewPager = findViewById(R.id.pager) 22 | viewPager.adapter = PagerAdapter(supportFragmentManager, this) 23 | 24 | val tabLayout = findViewById(R.id.tabLayout) 25 | tabLayout.setupWithViewPager(viewPager) 26 | } 27 | } 28 | 29 | internal class PagerAdapter(fm: FragmentManager, private val context: Context) : FragmentStatePagerAdapter(fm) { 30 | 31 | override fun getItem(position: Int): Fragment? = 32 | when (position) { 33 | 0 -> SimpleFragment() 34 | 1 -> CustomLayoutFragment() 35 | 2 -> CustomProgrammaticallyFragment() 36 | // 3 -> SectionsFragment() 37 | else -> null 38 | } 39 | 40 | override fun getPageTitle(position: Int): CharSequence? = 41 | when (position) { 42 | 0 -> context.getString(R.string.tab_simple) 43 | 1 -> context.getString(R.string.tab_custom_layout) 44 | 2 -> context.getString(R.string.tab_custom_programmatically) 45 | // 3 -> context.getString(R.string.tab_sections) 46 | else -> null 47 | } 48 | 49 | override fun getCount(): Int { 50 | return 3 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/appspell/wildscroll/fragments/CustomProgrammaticallyFragment.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.fragments 2 | 3 | import android.graphics.Typeface 4 | import android.os.Bundle 5 | import android.support.v4.app.Fragment 6 | import android.support.v7.widget.LinearLayoutManager 7 | import android.view.LayoutInflater 8 | import android.view.View 9 | import android.view.ViewGroup 10 | import com.appspell.wildscroll.R 11 | import com.appspell.wildscroll.R.layout 12 | import com.appspell.wildscroll.adapter.SampleSecondAdapter 13 | import com.appspell.wildscroll.data.DataSource 14 | import com.appspell.wildscroll.sections.Gravity.LEFT 15 | import com.appspell.wildscroll.sections.popup.SectionLetterPopup 16 | import com.appspell.wildscroll.view.WildScrollRecyclerView 17 | 18 | class CustomProgrammaticallyFragment : Fragment() { 19 | 20 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = 21 | inflater.inflate(layout.fragment_custom_programmatically, container, false) 22 | 23 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 24 | val recyclerView = view.findViewById(R.id.list) 25 | with(recyclerView) { 26 | layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) 27 | adapter = SampleSecondAdapter() 28 | (adapter as SampleSecondAdapter).items = DataSource(resources).companies 29 | 30 | textColor = R.color.colorSecondaryDark 31 | textSize = R.dimen.textRegular 32 | textTypeFace = Typeface.SANS_SERIF 33 | 34 | highlightColor = R.color.colorSecondary 35 | highlightTextSize = R.dimen.fastscroll_section_highlight_text_size 36 | highlightTextFace = Typeface.DEFAULT_BOLD 37 | 38 | sectionBarPaddingLeft = R.dimen.padding 39 | sectionBarPaddingRight = R.dimen.padding 40 | sectionBarCollapseDigital = false 41 | sectionBarGravity = LEFT 42 | 43 | sectionPopup = SectionLetterPopup(context, 44 | textColorRes = R.color.colorSecondaryLight, 45 | textSizeDimen = R.dimen.textPopup, 46 | textTypeFace = Typeface.DEFAULT_BOLD, 47 | backgroundResource = R.drawable.background_popup, 48 | paddingRes = R.dimen.padding) 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_sample_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 28 | 29 | 45 | 46 | 58 | 59 | 72 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_sections_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 16 | 17 | 34 | 35 | 51 | 52 | 64 | 65 | 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/appspell/wildscroll/adapter/SectionsAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.adapter 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import android.widget.TextView 8 | import com.appspell.wildscroll.R 9 | import com.appspell.wildscroll.data.Company 10 | import com.appspell.wildscroll.sections.SectionInfo 11 | 12 | class SectionsAdapter : SectionFastScrollAdapter(), SectionFastScroll { 13 | companion object { 14 | 15 | const val SECTION = 10 16 | const val ITEM = 20 17 | } 18 | 19 | var items = emptyList() 20 | set(value) { 21 | field = value 22 | notifyDataSetChanged() 23 | } 24 | 25 | override fun getItemCount(): Int = items.count() 26 | 27 | override fun getItemViewType(position: Int): Int = 28 | if (isSection(position)) { 29 | SECTION 30 | } else { 31 | ITEM 32 | } 33 | 34 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder? = 35 | when (viewType) { 36 | SECTION -> { 37 | val view = LayoutInflater.from(parent.context).inflate(R.layout.item_sections_section, parent, false) 38 | SectionsSectionViewHolder(view) 39 | } 40 | ITEM -> { 41 | val view = LayoutInflater.from(parent.context).inflate(R.layout.item_sections_item, parent, false) 42 | SectionsItemViewHolder(view) 43 | } 44 | else -> null 45 | } 46 | 47 | override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { 48 | when (getItemViewType(position)) { 49 | SECTION -> { 50 | holder as SectionsSectionViewHolder 51 | holder.bind(getSectionInfo(position)!!) 52 | } 53 | ITEM -> { 54 | holder as SectionsItemViewHolder 55 | holder.bind(items[position]) 56 | } 57 | else -> throw Exception("Cannot find binding for ${getItemViewType(position)}") 58 | } 59 | 60 | } 61 | 62 | override fun getSectionName(position: Int): String = items[position].company 63 | } 64 | 65 | 66 | class SectionsSectionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 67 | private val section = itemView.findViewById(R.id.section) 68 | 69 | fun bind(sectionInfo: SectionInfo) { 70 | section.text = sectionInfo.shortName.toString() 71 | } 72 | } 73 | 74 | class SectionsItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 75 | private val section = itemView.findViewById(R.id.section) 76 | 77 | private val company = itemView.findViewById(R.id.company) 78 | private val phrase = itemView.findViewById(R.id.phrase) 79 | private val street = itemView.findViewById(R.id.street) 80 | 81 | fun bind(item: Company) { 82 | section.text = item.company 83 | company.text = item.company 84 | phrase.text = item.phrase 85 | street.text = item.street 86 | } 87 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/item_second_sample_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 17 | 18 | 25 | 26 | 30 | 31 | 42 | 43 | 61 | 62 | 75 | 76 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/java/com/appspell/wildscroll/sections/Sections.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.sections 2 | 3 | import android.support.v4.util.ArrayMap 4 | import android.support.v7.widget.RecyclerView 5 | import android.text.TextUtils 6 | import com.appspell.wildscroll.adapter.SectionFastScroll 7 | import com.appspell.wildscroll.adapter.SectionFastScrollAdapter 8 | import com.eatigo.common.coroutines.Android 9 | import kotlinx.coroutines.experimental.CommonPool 10 | import kotlinx.coroutines.experimental.Deferred 11 | import kotlinx.coroutines.experimental.Job 12 | import kotlinx.coroutines.experimental.async 13 | import kotlinx.coroutines.experimental.launch 14 | import java.util.TreeMap 15 | 16 | interface OnSectionChangedListener { 17 | fun onSectionChanged() 18 | } 19 | 20 | enum class Gravity { 21 | LEFT, RIGHT //TODO top and bottom 22 | } 23 | 24 | data class SectionInfo(val name: String, 25 | val shortName: Char, 26 | val position: Int, 27 | val count: Int) 28 | 29 | class Sections { 30 | companion object { 31 | const val UNSELECTED = -1 32 | 33 | private const val SECTION_SHORT_NAME_EMPTY = '-' 34 | private const val SECTION_SHORT_NAME_DIGITAL = '#' 35 | } 36 | 37 | var left = 0f 38 | var top = 0f 39 | var width = 0f 40 | var height = 0f 41 | 42 | var gravity = Gravity.RIGHT 43 | var collapseDigital = true 44 | 45 | var paddingLeft = 0f 46 | var paddingRight = 0f 47 | 48 | var sections: ArrayMap = ArrayMap() 49 | 50 | var selected = UNSELECTED //TODO redraw section bar after set new value 51 | 52 | private var job: Job? = null 53 | 54 | fun getCount() = sections.size 55 | 56 | fun changeSize(w: Int, h: Int, highlightTextSize: Float) { 57 | val sectionCount = sections.size 58 | 59 | when (gravity) { 60 | Gravity.LEFT -> { 61 | width = highlightTextSize + paddingLeft + paddingRight 62 | height = h / sectionCount.toFloat() 63 | left = 0f 64 | } 65 | Gravity.RIGHT -> { 66 | width = highlightTextSize + paddingLeft + paddingRight 67 | height = h / sectionCount.toFloat() 68 | left = w - width 69 | } 70 | //TODO top / bottom 71 | } 72 | } 73 | 74 | fun contains(x: Float, y: Float): Boolean { 75 | return x >= left && 76 | x <= left + width && 77 | y >= top && 78 | y <= height * sections.size 79 | } 80 | 81 | fun getSectionInfoByIndex(index: Int): SectionInfo? { 82 | val key = getSectionByIndex(index) 83 | return sections[key] 84 | } 85 | 86 | fun createShortName(name: String): Char = 87 | when { 88 | name.isEmpty() -> SECTION_SHORT_NAME_EMPTY 89 | collapseDigital && TextUtils.isDigitsOnly(name[0].toString()) -> SECTION_SHORT_NAME_DIGITAL 90 | else -> name[0].toUpperCase() 91 | } 92 | 93 | fun refresh(adapter: RecyclerView.Adapter<*>?, listener: OnSectionChangedListener) { //TODO move it to separate class 94 | job?.cancel() 95 | job = launch(Android) { 96 | sections = fetchSections(adapter).await() 97 | // prepareSectionsAdapter(adapter) 98 | listener.onSectionChanged() 99 | } 100 | } 101 | 102 | private suspend fun prepareSectionsAdapter(adapter: RecyclerView.Adapter<*>?) { 103 | if (adapter !is SectionFastScrollAdapter<*>) return 104 | adapter.sections = prepareSectionInformationForAdapter().await() 105 | } 106 | 107 | private fun prepareSectionInformationForAdapter(): Deferred> { 108 | return async(CommonPool) { 109 | val map = TreeMap() 110 | sections.values.forEach { sectionInfo -> map.put(sectionInfo.position, sectionInfo) } 111 | return@async map 112 | } 113 | } 114 | 115 | private fun fetchSections(adapter: RecyclerView.Adapter<*>?): Deferred> { 116 | return async(CommonPool) { 117 | val map = ArrayMap() 118 | 119 | if (adapter == null) { 120 | return@async map 121 | } 122 | if (adapter.itemCount <= 1 || adapter !is SectionFastScroll) { 123 | return@async map 124 | } 125 | 126 | if (adapter.itemCount > 0) { 127 | for (position in 0 until adapter.itemCount) { 128 | 129 | val name = adapter.getSectionName(position) 130 | 131 | val shortName = createShortName(name) 132 | 133 | val sectionInfo = 134 | if (map.containsKey(shortName)) map[shortName]!!.copy(count = map[shortName]!!.count + 1) 135 | else SectionInfo(name, shortName, position, 1) 136 | 137 | map[shortName] = sectionInfo 138 | } 139 | } 140 | return@async map 141 | } 142 | } 143 | 144 | protected fun getSectionByIndex(index: Int): Char = sections.keyAt(index) 145 | } 146 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/java/com/appspell/wildscroll/sections/popup/SectionLetterPopup.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.sections.popup 2 | 3 | import android.content.Context 4 | import android.graphics.Canvas 5 | import android.graphics.Paint 6 | import android.graphics.Paint.Align.CENTER 7 | import android.graphics.PorterDuff 8 | import android.graphics.Rect 9 | import android.graphics.Typeface 10 | import android.graphics.drawable.Drawable 11 | import android.support.annotation.ColorRes 12 | import android.support.annotation.DimenRes 13 | import android.support.annotation.DrawableRes 14 | import android.support.v4.content.res.ResourcesCompat 15 | import appspell.com.wildscroll.R 16 | import com.appspell.wildscroll.sections.Sections 17 | 18 | 19 | open class SectionLetterPopup( 20 | protected var context: Context, 21 | @ColorRes 22 | textColorRes: Int = R.color.fastscroll_highlight_text, 23 | @DimenRes 24 | textSizeDimen: Int = R.dimen.fastscroll_popup_section_text_size, 25 | var textTypeFace: Typeface = Typeface.DEFAULT, 26 | @DrawableRes 27 | backgroundResource: Int = R.drawable.fastscroll_background_popup, 28 | @DimenRes 29 | paddingRes: Int = R.dimen.fastscroll_popup_padding 30 | ) : SectionPopup { 31 | 32 | var sectionTextSizeDimen: Int = textSizeDimen 33 | set(value) { 34 | field = value 35 | textPaint.textSize = context.resources.getDimension(value) 36 | } 37 | 38 | var sectionTextColorRes: Int = textColorRes 39 | set(value) { 40 | field = value 41 | textPaint.color = ResourcesCompat.getColor(context.resources, value, context.theme) 42 | } 43 | 44 | var paddingRes: Int = paddingRes 45 | set(value) { 46 | field = value 47 | padding = context.resources.getDimension(value) 48 | measure(padding!!) 49 | } 50 | 51 | var padding: Float? = null 52 | set(value) { 53 | field = value 54 | measure(value!!) 55 | } 56 | 57 | var sectionTextColor: Int? = null 58 | set(value) { 59 | textPaint.color = value!! 60 | } 61 | 62 | var sectionTextSize: Float? = null 63 | set(value) { 64 | textPaint.textSize = value!! 65 | measure(padding) 66 | } 67 | 68 | var backgroundResource: Int = backgroundResource 69 | set(value) { 70 | field = value 71 | background = ResourcesCompat.getDrawable(context.resources, value, context.theme)!! 72 | } 73 | 74 | var backgroundDrawable: Drawable? = null 75 | set(value) { 76 | background = value 77 | } 78 | 79 | open var backgroundColorRes: Int = 0 80 | set(value) { 81 | field = value 82 | val color = ResourcesCompat.getColor(context.resources, value, context.theme) 83 | background?.mutate()?.setColorFilter(color, PorterDuff.Mode.SRC_IN) 84 | } 85 | 86 | var backgroundColor: Int? = null 87 | set(value) { 88 | background?.mutate()?.setColorFilter(value!!, PorterDuff.Mode.SRC_IN) 89 | } 90 | 91 | var isShowing = false 92 | 93 | protected var x = 0 94 | protected var y = 0 95 | protected var sectionName: String = "" 96 | protected var background: Drawable? = null 97 | protected var textPaint: Paint = Paint() 98 | 99 | override var width: Int = 0 100 | override var height: Int = 0 101 | 102 | override var onDismissListener: (() -> Unit)? = null 103 | 104 | init { 105 | val resources = context.resources 106 | val theme = context.theme 107 | 108 | background = ResourcesCompat.getDrawable(resources, backgroundResource, theme)!! 109 | 110 | textPaint.run { 111 | color = ResourcesCompat.getColor(resources, textColorRes, theme) 112 | textSize = resources.getDimension(textSizeDimen) 113 | typeface = textTypeFace 114 | isAntiAlias = true 115 | textAlign = CENTER 116 | } 117 | 118 | val padding = context.resources.getDimension(paddingRes) 119 | measure(padding) 120 | } 121 | 122 | private fun measure(padding: Float?) { 123 | val padding = padding ?: 0f 124 | width = (textPaint.textSize + padding).toInt() 125 | height = width 126 | } 127 | 128 | override fun show(section: String, x: Int, y: Int, parentWidth: Int, parentHeight: Int, sections: Sections) { 129 | sectionName = section 130 | this.x = x 131 | this.y = y 132 | 133 | isShowing = true 134 | 135 | when (sections.gravity) { 136 | com.appspell.wildscroll.sections.Gravity.LEFT -> { 137 | this.x = sections.width.toInt() + sections.width.toInt() 138 | this.y = y - height / 2 139 | } 140 | com.appspell.wildscroll.sections.Gravity.RIGHT -> { 141 | this.x = (sections.left - width).toInt() - sections.width.toInt() 142 | this.y = y - height / 2 143 | } 144 | //TODO top / bottom 145 | } 146 | 147 | //corrections 148 | if (this.x < 0) this.x = 0 149 | else if (this.x > parentWidth - width) this.x = parentWidth - width 150 | if (this.y < 0) this.y = 0 151 | else if (this.y > parentHeight - height) this.y = parentHeight - height 152 | } 153 | 154 | override fun draw(canvas: Canvas) { 155 | if (!isShowing) return 156 | drawBackground(canvas) 157 | drawText(canvas) 158 | } 159 | 160 | override fun dismiss() { 161 | isShowing = false 162 | onDismissListener?.invoke() 163 | } 164 | 165 | override fun getRect() = Rect(x, y, x + width, y + height) 166 | 167 | protected open fun drawBackground(canvas: Canvas) { 168 | background?.setBounds(x, y, x + width, y + height) 169 | background?.draw(canvas) 170 | } 171 | 172 | protected open fun drawText(canvas: Canvas) { 173 | val offset = ((textPaint.descent() + textPaint.ascent()) / 2f) 174 | canvas.drawText(sectionName, 175 | x + width / 2f, 176 | y + height / 2f - offset, 177 | textPaint) 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DEPRECATED 2 | 3 | 4 | # wild-scroll 5 | Android RecyclerView Fast Scroller + Section bar 6 | 7 | ![alt tag](https://i.imgur.com/sSCEVRf.gif) 8 | ![alt tag](https://i.imgur.com/TNhTMZD.gif) 9 | ![alt tag](https://i.imgur.com/26QFKMu.gif) 10 | 11 | Download 12 | -------- 13 | 14 | Grab via Maven: 15 | ```xml 16 | 17 | com.appspell.wild-scroll 18 | wild-scroll 19 | 0.90 20 | pom 21 | 22 | ``` 23 | or Gradle: 24 | ```groovy 25 | implementation 'com.appspell.wild-scroll:wild-scroll:0.90' 26 | ``` 27 | 28 | 29 | Minimal working example 30 | ----------------------- 31 | 32 | In your [layout](/app/src/main/res/layout/fragment_simple.xml) file: 33 | ```xml 34 | 39 | ``` 40 | 41 | In your [code](/app/src/main/java/com/appspell/wildscroll/fragments/SimpleFragment.kt) (Actvity/Fragment): 42 | ```Kotlin 43 | val recyclerView = view.findViewById(R.id.list) 44 | with(recyclerView) { 45 | layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) 46 | adapter = SampleAdapter() 47 | (adapter as SampleAdapter).items = DataSource(resources).companies 48 | } 49 | ``` 50 | 51 | One important thing that your need to implement `SectionFastScroll` for your [`RecyclerView.Adapter`](/app/src/main/java/com/appspell/wildscroll/adapter/SimpleAdapter.kt) 52 | ```Kotlin 53 | class SampleAdapter : RecyclerView.Adapter(), SectionFastScroll { 54 | override fun getSectionName(position: Int): String = items[position].section 55 | } 56 | ``` 57 | 58 | 59 | Set all available attributes in [XML](/app/src/main/res/layout/fragment_custom.xml) 60 | ----------------------------------- 61 | 62 | ```xml 63 | 83 | ``` 84 | 85 | 86 | Configure in [code](/app/src/main/java/com/appspell/wildscroll/fragments/CustomProgrammaticallyFragment.kt) 87 | ----------------- 88 | 89 | ```Kotlin 90 | val recyclerView = view.findViewById(R.id.list) 91 | with(recyclerView) { 92 | layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) 93 | adapter = SampleSecondAdapter() 94 | (adapter as SampleSecondAdapter).items = DataSource(resources).companies 95 | 96 | textColor = R.color.colorSecondaryDark 97 | textSize = R.dimen.textRegular 98 | textTypeFace = Typeface.SANS_SERIF 99 | 100 | highlightColor = R.color.colorSecondary 101 | highlightTextSize = R.dimen.fastscroll_section_highlight_text_size 102 | highlightTextFace = Typeface.DEFAULT_BOLD 103 | 104 | sectionBarPaddingLeft = R.dimen.padding 105 | sectionBarPaddingRight = R.dimen.padding 106 | sectionBarCollapseDigital = false 107 | sectionBarGravity = LEFT 108 | 109 | sectionPopup = SectionLetterPopup(context, 110 | textColorRes = R.color.colorSecondaryLight, 111 | textSizeDimen = R.dimen.textPopup, 112 | textTypeFace = Typeface.DEFAULT_BOLD, 113 | backgroundResource = R.drawable.background_popup, 114 | paddingRes = R.dimen.padding) 115 | } 116 | ``` 117 | 118 | 119 | Section popups 120 | -------------- 121 | 122 | You can set your custom popup or use one of included into the library ones. 123 | 124 | [`SectionLetterPopup`](/wildscrolllibrary/src/main/java/com/appspell/wildscroll/sections/popup/SectionLetterPopup.kt) - This popup shows section name and can use custom background (`backgroundResource`). 125 | 126 | [`SectionCirclePopup`](/wildscrolllibrary/src/main/java/com/appspell/wildscroll/sections/popup/SectionLetterPopup.kt) - Extends `SectionLetterPopup` but use predefined round background. 127 | 128 | [`StubSectionPopup`](/wildscrolllibrary/src/main/java/com/appspell/wildscroll/sections/popup/SectionPopup.kt) - It's just a stub. This popup can't be rendered. 129 | 130 | If you want to implement your own section popup you should use interface [`com.appspell.wildscroll.sections.popup.SectionPopup`](/wildscrolllibrary/src/main/java/com/appspell/wildscroll/sections/popup/SectionPopup.kt). 131 | 132 | 133 | XML attributes 134 | -------------- 135 | 136 | 137 | Section bar 138 | 139 | `wildScroll_sectionBarEnable` - show or hide section bar 140 | 141 | `wildScroll_sectionBarGravity` - section bar positon. (currently available: left and right) 142 | 143 | `wildScroll_textColor` - section text color 144 | 145 | `wildScroll_textSize` - section text size 146 | 147 | `wildScroll_highlightColor` - color for selected section 148 | 149 | `wildScroll_highlightTextSize` - text size for selected section 150 | 151 | `wildScroll_sectionBarBackgroundColor` - background color for section bar 152 | 153 | `wildScroll_sectionBarPaddingLeft` - left padding for section bar 154 | 155 | `wildScroll_sectionBarPaddingRight` - right padding for section bar 156 | 157 | `wildScroll_sectionBarCollapseDigital` - merge all of numeric sections into one (1..10 -> #) 158 | 159 | 160 | Popup 161 | 162 | `wildScroll_popupEnable` - show or hide section popup 163 | 164 | `wildScroll_popupBackgroundDrawable` - popup background 165 | 166 | `wildScroll_popupBackgroundColor` - color for preselected background drawable (like *tint*) 167 | 168 | `wildScroll_popupPadding` - paddings for popup 169 | 170 | `wildScroll_popupTextColor` - section text color 171 | 172 | `wildScroll_popupTextSize` - section text size 173 | -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/java/com/appspell/wildscroll/sections/fastscroll/FastScroll.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.sections.fastscroll 2 | 3 | import android.support.v7.widget.GridLayoutManager 4 | import android.support.v7.widget.LinearLayoutManager 5 | import android.support.v7.widget.LinearSmoothScroller 6 | import android.support.v7.widget.RecyclerView 7 | import android.support.v7.widget.RecyclerView.HORIZONTAL 8 | import android.support.v7.widget.RecyclerView.OnScrollListener 9 | import android.support.v7.widget.StaggeredGridLayoutManager 10 | import android.view.MotionEvent 11 | import appspell.com.wildscroll.R 12 | import com.appspell.wildscroll.adapter.SectionFastScroll 13 | import com.appspell.wildscroll.sections.SectionBarView 14 | import com.appspell.wildscroll.sections.Sections 15 | 16 | 17 | class FastScroll(private val sectionBar: SectionBarView) { 18 | 19 | private val sections 20 | get() = sectionBar.sections 21 | 22 | private val recyclerView 23 | get() = sectionBar.recyclerView 24 | 25 | private var isScrolling = false 26 | 27 | private var lastPositionX = 0f 28 | private var lastPositionY = 0f 29 | private val minScrollSensitivity: Float 30 | 31 | private val scroller: OnScrollListener = object : OnScrollListener() { 32 | override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) { 33 | super.onScrolled(recyclerView, dx, dy) 34 | if (isScrolling) { 35 | return 36 | } 37 | selectSectionByFirstVisibleItem() 38 | } 39 | } 40 | 41 | init { 42 | recyclerView.addOnScrollListener(scroller) 43 | minScrollSensitivity = recyclerView.resources.getDimension(R.dimen.fastscroll_minimum_scrolling_sensitivity) 44 | } 45 | 46 | fun onTouchEvent(ev: MotionEvent): Boolean { 47 | when (ev.action) { 48 | MotionEvent.ACTION_DOWN -> { 49 | recyclerView.parent.requestDisallowInterceptTouchEvent(false) 50 | lastPositionX = ev.x 51 | lastPositionY = ev.y 52 | isScrolling = false 53 | } 54 | MotionEvent.ACTION_UP -> { 55 | recyclerView.parent.requestDisallowInterceptTouchEvent(false) 56 | sectionBar.dismissPopup() 57 | 58 | if (!isScrolling && sections.contains(ev.x, ev.y)) { 59 | val sectionIndex = getSectionIndex(ev.y) 60 | val sectionInfo = sections.getSectionInfoByIndex(sectionIndex) 61 | 62 | scrollToPosition(sectionInfo!!.position) //TODO smooth scroll 63 | 64 | sections.selected = sectionIndex 65 | sectionBar.invalidateSectionBar() 66 | 67 | return true 68 | } 69 | } 70 | MotionEvent.ACTION_MOVE -> { 71 | recyclerView.parent.requestDisallowInterceptTouchEvent(true) 72 | 73 | val dif = when (isHorizontalScroll()) { 74 | true -> Math.abs(lastPositionX - ev.x) > minScrollSensitivity 75 | false -> Math.abs(lastPositionY - ev.y) > minScrollSensitivity 76 | } 77 | 78 | if (dif && sections.contains(ev.x, ev.y)) { 79 | val sectionIndex = getSectionIndex(ev.y) 80 | val sectionInfo = sections.getSectionInfoByIndex(sectionIndex)!! 81 | 82 | val dY = ev.y - sections.height * sectionIndex 83 | val sectionProgress = dY / sections.height 84 | val dPosition = sectionInfo.count * sectionProgress 85 | val position = Math.round(sectionInfo.position + dPosition) 86 | 87 | scrollToPosition(position) 88 | 89 | sections.selected = sectionIndex 90 | sectionBar.invalidateSectionBar() 91 | 92 | sectionBar.showPopup(sectionInfo, ev.x.toInt(), ev.y.toInt()) 93 | 94 | isScrolling = true 95 | return true 96 | } 97 | } 98 | MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_OUTSIDE -> { 99 | recyclerView.parent.requestDisallowInterceptTouchEvent(false) 100 | sectionBar.dismissPopup() 101 | return true 102 | } 103 | } 104 | return false 105 | } 106 | 107 | fun onInterceptTouchEvent(ev: MotionEvent): Boolean { 108 | return sections.contains(ev.x, ev.y) 109 | } 110 | 111 | fun selectSectionByFirstVisibleItem() { 112 | val layoutManager = recyclerView.layoutManager 113 | 114 | val firstItemPosition = when (layoutManager) { 115 | is LinearLayoutManager -> layoutManager.findFirstVisibleItemPosition() 116 | is StaggeredGridLayoutManager -> layoutManager.findFirstVisibleItemPositions(null)[0] 117 | else -> RecyclerView.NO_POSITION 118 | } 119 | 120 | sections.selected = getSectionIndexByAdapterItemPosition(firstItemPosition) 121 | } 122 | 123 | private fun getSectionIndex(pos: Float): Int = 124 | when (isHorizontalScroll()) { 125 | true -> Math.floor((pos * sections.getCount() / sectionBar.width).toDouble()).toInt() 126 | false -> Math.floor((pos * sections.getCount() / sectionBar.height).toDouble()).toInt() 127 | } 128 | 129 | private fun getSectionIndexByAdapterItemPosition(itemPosition: Int): Int { 130 | if (recyclerView.adapter !is SectionFastScroll || itemPosition == RecyclerView.NO_POSITION) return Sections.UNSELECTED 131 | val sectionName = (recyclerView.adapter as SectionFastScroll).getSectionName(itemPosition) 132 | val sectionKey = sections.createShortName(sectionName) 133 | return sections.sections.indexOfKey(sectionKey) 134 | } 135 | 136 | private fun scrollToPosition(itemPosition: Int) { 137 | recyclerView.stopScroll() 138 | when (recyclerView.layoutManager) { 139 | is LinearLayoutManager -> 140 | (recyclerView.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(itemPosition, 0) 141 | else -> 142 | recyclerView.layoutManager.scrollToPosition(itemPosition) 143 | } 144 | } 145 | 146 | private fun smoothScrollToPosition(itemPosition: Int) { 147 | recyclerView.stopScroll() 148 | smoothScroller.targetPosition = itemPosition 149 | if (!smoothScroller.isRunning) { 150 | recyclerView.layoutManager.startSmoothScroll(smoothScroller) 151 | } 152 | } 153 | 154 | private fun isHorizontalScroll(): Boolean = 155 | when (recyclerView.layoutManager) { 156 | is LinearLayoutManager -> 157 | (recyclerView.layoutManager as LinearLayoutManager).orientation == HORIZONTAL 158 | is GridLayoutManager -> 159 | (recyclerView.layoutManager as GridLayoutManager).orientation == HORIZONTAL 160 | is StaggeredGridLayoutManager -> 161 | (recyclerView.layoutManager as StaggeredGridLayoutManager).orientation == HORIZONTAL 162 | else -> 163 | false 164 | } 165 | 166 | private val smoothScroller = object : LinearSmoothScroller(recyclerView.context) { 167 | override fun getVerticalSnapPreference(): Int { 168 | return LinearSmoothScroller.SNAP_TO_START 169 | } 170 | } 171 | } -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/java/com/appspell/wildscroll/sections/SectionBarView.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.sections 2 | 3 | import android.graphics.Canvas 4 | import android.graphics.Paint 5 | import android.graphics.Paint.Align 6 | import android.graphics.Rect 7 | import android.graphics.Typeface 8 | import android.support.annotation.ColorInt 9 | import android.support.v7.widget.RecyclerView 10 | import android.view.MotionEvent 11 | import com.appspell.wildscroll.sections.Gravity.LEFT 12 | import com.appspell.wildscroll.sections.Gravity.RIGHT 13 | import com.appspell.wildscroll.sections.fastscroll.FastScroll 14 | import com.appspell.wildscroll.sections.popup.SectionCirclePopup 15 | import com.appspell.wildscroll.sections.popup.SectionPopup 16 | import com.appspell.wildscroll.view.WildScrollRecyclerView 17 | 18 | class SectionBarView(val recyclerView: WildScrollRecyclerView) { 19 | 20 | @ColorInt 21 | var textColor: Int = 0 22 | set(value) { 23 | field = value 24 | textPaint.color = value 25 | } 26 | 27 | @ColorInt 28 | var highlightColor: Int = 0 29 | set(value) { 30 | field = value 31 | highlightTextPaint.color = value 32 | } 33 | 34 | @ColorInt 35 | var sectionBarBackgroundColor: Int = 0 36 | set(value) { 37 | field = value 38 | sectionsPaint.color = value 39 | } 40 | 41 | var sectionBarPaddingLeft: Float = 0f 42 | set(value) { 43 | field = value 44 | sections.paddingLeft = value 45 | onSizeChanged(recyclerView.width, recyclerView.height) 46 | } 47 | 48 | var sectionBarPaddingRight: Float = 0f 49 | set(value) { 50 | field = value 51 | sections.paddingRight = value 52 | onSizeChanged(recyclerView.width, recyclerView.height) 53 | } 54 | 55 | var textSize: Float = 0f 56 | set(value) { 57 | field = value 58 | textPaint.textSize = value 59 | onSizeChanged(recyclerView.width, recyclerView.height) 60 | } 61 | 62 | var highlightTextSize: Float = 0f 63 | set(value) { 64 | field = value 65 | highlightTextPaint.textSize = value 66 | onSizeChanged(recyclerView.width, recyclerView.height) 67 | } 68 | 69 | var textTypeFace: Typeface = Typeface.DEFAULT 70 | set(value) { 71 | field = value 72 | textPaint.typeface = value 73 | } 74 | 75 | var highlightTextFace: Typeface = Typeface.DEFAULT 76 | set(value) { 77 | field = value 78 | highlightTextPaint.typeface = value 79 | } 80 | 81 | var sectionBarCollapseDigital: Boolean = true 82 | set(value) { 83 | field = value 84 | sections.collapseDigital = value 85 | } 86 | 87 | var sectionBarGravity: Gravity = Gravity.RIGHT 88 | set(value) { 89 | field = value 90 | sections.gravity = value 91 | onSizeChanged(recyclerView.width, recyclerView.height) 92 | } 93 | 94 | var sectionPopup: SectionPopup = SectionCirclePopup(context) 95 | set(value) { 96 | field = value 97 | field.onDismissListener = { invalidateSectionPopup() } 98 | } 99 | 100 | var sectionBarEnable: Boolean = true 101 | 102 | var popupEnable: Boolean = true 103 | 104 | val width: Int 105 | get() = sectionsRect.right - sectionsRect.left 106 | 107 | val height: Int 108 | get() = sectionsRect.bottom - sectionsRect.top 109 | 110 | var sections: Sections = Sections() 111 | 112 | private val fastScroll = FastScroll(this) 113 | 114 | private val textPaint = Paint() 115 | private val highlightTextPaint = Paint() 116 | private val sectionsPaint = Paint() 117 | private val sectionsRect = Rect() 118 | 119 | private val context 120 | get() = recyclerView.context 121 | private val resources 122 | get() = context.resources 123 | 124 | init { 125 | with(textPaint) { 126 | isAntiAlias = true 127 | textAlign = Align.CENTER 128 | } 129 | 130 | with(highlightTextPaint) { 131 | isAntiAlias = true 132 | textAlign = Align.CENTER 133 | } 134 | } 135 | 136 | fun draw(canvas: Canvas) { 137 | if (sectionBarEnable == false || sections.getCount() == 0) { 138 | return 139 | } 140 | 141 | canvas.drawRect(sectionsRect, sectionsPaint) 142 | 143 | when (sections.gravity) { 144 | //TODO draw top and bottom 145 | Gravity.LEFT, Gravity.RIGHT -> { 146 | val posX = (sections.left + sections.width / 2f) 147 | 148 | sections.sections.entries.forEachIndexed { index, section -> 149 | val top = sections.top + (index + 1) * sections.height - sections.height / 2f 150 | 151 | //TODO implement gravity top or bottom (horizontal) 152 | when (sections.selected == index) { 153 | true -> canvas.drawText(section.key.toString(), posX, top + highlightTextPaint.textSize / 2f, highlightTextPaint) 154 | false -> canvas.drawText(section.key.toString(), posX, top + textPaint.textSize / 2f, textPaint) 155 | } 156 | } 157 | } 158 | } 159 | 160 | if (popupEnable) { 161 | sectionPopup.draw(canvas) 162 | } 163 | } 164 | 165 | fun onTouchEvent(ev: MotionEvent): Boolean { 166 | return fastScroll.onTouchEvent(ev) 167 | } 168 | 169 | fun onInterceptTouchEvent(ev: MotionEvent): Boolean = sectionBarEnable && fastScroll.onInterceptTouchEvent(ev) 170 | 171 | fun onSizeChanged(width: Int, height: Int) { 172 | if (width == 0 && height == 0) return 173 | 174 | val maxTextSize = Math.max(textPaint.textSize, highlightTextPaint.textSize) 175 | sections.changeSize(width, height, maxTextSize) 176 | 177 | when (sections.gravity) { 178 | //TODO top and bottom 179 | LEFT, RIGHT -> { 180 | if (textPaint.textSize > sections.width) { 181 | textPaint.textSize = sections.width 182 | } 183 | 184 | if (highlightTextPaint.textSize > sections.width) { 185 | highlightTextPaint.textSize = sections.width 186 | } 187 | 188 | with(sectionsRect) { 189 | left = sections.left.toInt() 190 | right = (sections.left + sections.width).toInt() 191 | top = 0 192 | bottom = height 193 | } 194 | } 195 | } 196 | } 197 | 198 | fun invalidateSectionBar() { 199 | fastScroll.selectSectionByFirstVisibleItem() 200 | recyclerView.invalidate(sectionsRect) 201 | } 202 | 203 | private fun invalidateSectionPopup() { 204 | recyclerView.invalidate(sectionPopup.getRect()) 205 | } 206 | 207 | fun showPopup(section: SectionInfo, x: Int, y: Int) { 208 | if (popupEnable == false) { 209 | return 210 | } 211 | 212 | val sectionName = section.shortName.toString() 213 | sectionPopup.show(sectionName, x, y, recyclerView.width, recyclerView.height, sections) 214 | } 215 | 216 | fun dismissPopup() { 217 | sectionPopup.dismiss() 218 | } 219 | 220 | fun invalidateLayout(adapter: RecyclerView.Adapter<*>?) { 221 | sections.refresh(adapter, object : OnSectionChangedListener { //TODO check memory leaks here 222 | override fun onSectionChanged() { 223 | onSizeChanged(recyclerView.width, recyclerView.height) 224 | invalidateSectionBar() 225 | } 226 | }) 227 | } 228 | } -------------------------------------------------------------------------------- /wildscrolllibrary/src/main/java/com/appspell/wildscroll/view/WildScrollRecyclerView.kt: -------------------------------------------------------------------------------- 1 | package com.appspell.wildscroll.view 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.Context 5 | import android.graphics.Canvas 6 | import android.graphics.Typeface 7 | import android.support.annotation.ColorRes 8 | import android.support.annotation.DimenRes 9 | import android.support.annotation.DrawableRes 10 | import android.support.v4.content.res.ResourcesCompat 11 | import android.support.v7.widget.RecyclerView 12 | import android.util.AttributeSet 13 | import android.view.MotionEvent 14 | import appspell.com.wildscroll.R 15 | import com.appspell.wildscroll.sections.Gravity 16 | import com.appspell.wildscroll.sections.SectionBarView 17 | import com.appspell.wildscroll.sections.popup.SectionCirclePopup 18 | import com.appspell.wildscroll.sections.popup.SectionLetterPopup 19 | import com.appspell.wildscroll.sections.popup.SectionPopup 20 | 21 | class WildScrollRecyclerView @JvmOverloads constructor( 22 | context: Context, 23 | attrs: AttributeSet? = null, 24 | defStyle: Int = 0 25 | ) : RecyclerView(context, attrs, defStyle) { 26 | 27 | private val sectionBar = SectionBarView(this) 28 | 29 | //Section regular text 30 | @ColorRes 31 | var textColor: Int = R.color.fastscroll_default_text 32 | set(value) { 33 | sectionBar.textColor = ResourcesCompat.getColor(resources, value, context.theme) 34 | } 35 | @DimenRes 36 | var textSize: Int = R.dimen.fastscroll_section_text_size 37 | set(value) { 38 | sectionBar.textSize = resources.getDimension(value) 39 | } 40 | var textTypeFace: Typeface = Typeface.DEFAULT 41 | set(value) { 42 | sectionBar.textTypeFace = value 43 | } 44 | 45 | //Section highlighted text 46 | @ColorRes 47 | var highlightColor: Int = R.color.fastscroll_highlight_text 48 | set(value) { 49 | sectionBar.highlightColor = ResourcesCompat.getColor(resources, value, context.theme) 50 | } 51 | @DimenRes 52 | var highlightTextSize: Int = R.dimen.fastscroll_section_highlight_text_size 53 | set(value) { 54 | sectionBar.highlightTextSize = resources.getDimension(value) 55 | } 56 | var highlightTextFace: Typeface = Typeface.DEFAULT 57 | set(value) { 58 | sectionBar.highlightTextFace = value 59 | } 60 | 61 | //Section bar settings 62 | @ColorRes 63 | var sectionBarBackgroundColor: Int = R.color.fastscroll_section_background 64 | set(value) { 65 | sectionBar.sectionBarBackgroundColor = ResourcesCompat.getColor(resources, value, context.theme) 66 | } 67 | @DimenRes 68 | var sectionBarPaddingLeft: Int = R.dimen.fastscroll_section_padding 69 | set(value) { 70 | sectionBar.sectionBarPaddingLeft = resources.getDimension(value) 71 | } 72 | @DimenRes 73 | var sectionBarPaddingRight: Int = R.dimen.fastscroll_section_padding 74 | set(value) { 75 | sectionBar.sectionBarPaddingRight = resources.getDimension(value) 76 | } 77 | var sectionBarCollapseDigital: Boolean = true 78 | set(value) { 79 | sectionBar.sectionBarCollapseDigital = value 80 | } 81 | var sectionBarGravity: Gravity = Gravity.RIGHT 82 | set(value) { 83 | sectionBar.sectionBarGravity = value 84 | } 85 | var sectionBarEnable: Boolean = true 86 | set(value) { 87 | sectionBar.sectionBarEnable = value 88 | } 89 | 90 | //Popup section 91 | var popupEnable: Boolean = true 92 | set(value) { 93 | sectionBar.popupEnable = value 94 | } 95 | @DrawableRes 96 | var popupBackground: Int = R.drawable.fastscroll_background_popup 97 | set(value) { 98 | if (sectionBar.sectionPopup !is SectionLetterPopup) { 99 | sectionBar.sectionPopup = SectionLetterPopup(context, backgroundResource = value) 100 | } else { 101 | (sectionBar.sectionPopup as SectionLetterPopup).backgroundResource = value 102 | } 103 | } 104 | @ColorRes 105 | var popupBackgroundColor: Int = R.color.fastscroll_popup_background 106 | set(value) { 107 | if (sectionBar.sectionPopup is SectionCirclePopup) { 108 | (sectionBar.sectionPopup as SectionCirclePopup).backgroundColorRes = value 109 | } else { 110 | sectionBar.sectionPopup = SectionCirclePopup(context, backgroundColorRes = value) 111 | } 112 | } 113 | @ColorRes 114 | var popupTextColor: Int = R.color.fastscroll_highlight_text 115 | set(value) { 116 | if (sectionBar.sectionPopup is SectionCirclePopup) { 117 | (sectionBar.sectionPopup as SectionCirclePopup).sectionTextColorRes = value 118 | } else { 119 | sectionBar.sectionPopup = SectionCirclePopup(context, sectionTextColorRes = value) 120 | } 121 | } 122 | @DimenRes 123 | var popupTextSize: Int = R.dimen.fastscroll_popup_section_text_size 124 | set(value) { 125 | if (sectionBar.sectionPopup is SectionLetterPopup) { 126 | (sectionBar.sectionPopup as SectionLetterPopup).sectionTextSizeDimen = value 127 | } else { 128 | sectionBar.sectionPopup = SectionCirclePopup(context, sectionTextSizeDimen = value) 129 | } 130 | } 131 | @DimenRes 132 | var popupPadding: Int = R.dimen.fastscroll_popup_padding 133 | set(value) { 134 | if (sectionBar.sectionPopup is SectionLetterPopup) { 135 | (sectionBar.sectionPopup as SectionLetterPopup).paddingRes = value 136 | } else { 137 | sectionBar.sectionPopup = SectionCirclePopup(context, paddingRes = value) 138 | } 139 | } 140 | var sectionPopup: SectionPopup = SectionCirclePopup(context) 141 | set(value) { 142 | sectionBar.sectionPopup = value 143 | } 144 | 145 | init { 146 | textTypeFace = Typeface.DEFAULT 147 | highlightTextFace = Typeface.DEFAULT 148 | 149 | sectionPopup = SectionCirclePopup(context, sectionTextColorRes = popupTextColor, sectionTextSizeDimen = popupTextSize, backgroundColorRes = popupBackgroundColor) 150 | 151 | attrs?.let { 152 | val typedArray = context.obtainStyledAttributes(it, R.styleable.WildScroll, defStyle, 0) 153 | try { 154 | // Section Bar Text 155 | sectionBar.textColor = typedArray.getColor(R.styleable.WildScroll_wildScroll_textColor, ResourcesCompat.getColor(resources, R.color.fastscroll_default_text, context.theme)) 156 | sectionBar.textSize = typedArray.getDimension(R.styleable.WildScroll_wildScroll_textSize, resources.getDimension(R.dimen.fastscroll_section_text_size)) 157 | sectionBar.highlightColor = typedArray.getColor(R.styleable.WildScroll_wildScroll_highlightColor, ResourcesCompat.getColor(resources, R.color.fastscroll_highlight_text, context.theme)) 158 | sectionBar.highlightTextSize = typedArray.getDimension(R.styleable.WildScroll_wildScroll_highlightTextSize, resources.getDimension(R.dimen.fastscroll_section_highlight_text_size)) 159 | 160 | // Section Bar main settings 161 | sectionBar.sectionBarBackgroundColor = typedArray.getColor(R.styleable.WildScroll_wildScroll_sectionBarBackgroundColor, ResourcesCompat.getColor(resources, R.color.fastscroll_transparent, context.theme)) 162 | sectionBar.sectionBarPaddingLeft = typedArray.getDimension(R.styleable.WildScroll_wildScroll_sectionBarPaddingLeft, resources.getDimension(R.dimen.fastscroll_section_padding)) 163 | sectionBar.sectionBarPaddingRight = typedArray.getDimension(R.styleable.WildScroll_wildScroll_sectionBarPaddingRight, resources.getDimension(R.dimen.fastscroll_section_padding)) 164 | sectionBarCollapseDigital = typedArray.getBoolean(R.styleable.WildScroll_wildScroll_sectionBarCollapseDigital, true) 165 | sectionBarGravity = Gravity.values()[typedArray.getInt(R.styleable.WildScroll_wildScroll_sectionBarGravity, Gravity.RIGHT.ordinal)] 166 | sectionBarEnable = typedArray.getBoolean(R.styleable.WildScroll_wildScroll_sectionBarEnable, true) 167 | 168 | // Section popup 169 | if (typedArray.hasValue(R.styleable.WildScroll_wildScroll_popupEnable)) { 170 | popupEnable = typedArray.getBoolean(R.styleable.WildScroll_wildScroll_popupEnable, true) 171 | } 172 | if (typedArray.hasValue(R.styleable.WildScroll_wildScroll_popupPadding)) { 173 | if (sectionBar.sectionPopup is SectionLetterPopup) { 174 | (sectionBar.sectionPopup as SectionLetterPopup).padding = typedArray.getDimension(R.styleable.WildScroll_wildScroll_popupPadding, resources.getDimension(R.dimen.fastscroll_popup_padding)) 175 | } 176 | } 177 | if (typedArray.hasValue(R.styleable.WildScroll_wildScroll_popupBackgroundDrawable)) { 178 | if (sectionBar.sectionPopup is SectionLetterPopup) { 179 | (sectionBar.sectionPopup as SectionLetterPopup).backgroundDrawable = typedArray.getDrawable(R.styleable.WildScroll_wildScroll_popupBackgroundDrawable) 180 | } 181 | } 182 | if (typedArray.hasValue(R.styleable.WildScroll_wildScroll_popupBackgroundColor)) { 183 | if (sectionBar.sectionPopup is SectionCirclePopup) { 184 | (sectionBar.sectionPopup as SectionCirclePopup).backgroundColor = typedArray.getColor(R.styleable.WildScroll_wildScroll_popupBackgroundColor, ResourcesCompat.getColor(resources, R.color.fastscroll_popup_background, context.theme)) 185 | } 186 | } 187 | if (typedArray.hasValue(R.styleable.WildScroll_wildScroll_popupTextColor)) { 188 | if (sectionBar.sectionPopup is SectionLetterPopup) { 189 | (sectionBar.sectionPopup as SectionLetterPopup).sectionTextColor = typedArray.getColor(R.styleable.WildScroll_wildScroll_popupTextColor, ResourcesCompat.getColor(resources, R.color.fastscroll_highlight_text, context.theme)) 190 | } 191 | } 192 | if (typedArray.hasValue(R.styleable.WildScroll_wildScroll_popupTextSize)) { 193 | if (sectionBar.sectionPopup is SectionLetterPopup) { 194 | (sectionBar.sectionPopup as SectionLetterPopup).sectionTextSize = typedArray.getDimension(R.styleable.WildScroll_wildScroll_popupTextSize, resources.getDimension(R.dimen.fastscroll_popup_section_text_size)) 195 | } 196 | } 197 | } finally { 198 | typedArray.recycle() 199 | } 200 | } 201 | } 202 | 203 | override fun onSizeChanged(width: Int, height: Int, oldw: Int, oldh: Int) { 204 | super.onSizeChanged(width, height, oldw, oldh) 205 | sectionBar.onSizeChanged(width, height) 206 | } 207 | 208 | override fun draw(canvas: Canvas?) { 209 | super.draw(canvas) 210 | sectionBar.draw(canvas!!) 211 | } 212 | 213 | @SuppressLint("ClickableViewAccessibility") 214 | override fun onTouchEvent(ev: MotionEvent): Boolean { 215 | if (sectionBar.onTouchEvent(ev)) { 216 | return true 217 | } 218 | return super.onTouchEvent(ev) 219 | } 220 | 221 | override fun onInterceptTouchEvent(ev: MotionEvent): Boolean = 222 | if (sectionBar.onInterceptTouchEvent(ev)) true 223 | else super.onInterceptTouchEvent(ev) 224 | 225 | override fun setAdapter(adapter: Adapter<*>?) { 226 | adapter?.registerAdapterDataObserver(dataObserver) 227 | super.setAdapter(adapter) 228 | } 229 | 230 | fun release() { 231 | adapter?.unregisterAdapterDataObserver(dataObserver) 232 | } 233 | 234 | private val dataObserver = object : AdapterDataObserver() { 235 | override fun onChanged() { 236 | sectionBar.invalidateLayout(adapter) 237 | super.onChanged() 238 | } 239 | } 240 | } 241 | --------------------------------------------------------------------------------