├── .gitignore ├── LICENSE ├── README.md ├── art ├── demo.gif ├── ic_launcher.ai ├── ic_launcher.png └── ic_launcher.svg ├── build.gradle ├── demo ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jrummyapps │ │ └── fastscrollrecyclerview │ │ └── sample │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── jaredrummler │ │ │ └── fastscrollrecyclerview │ │ │ └── sample │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable │ │ └── ic_github_white_24dp.xml │ │ ├── layout │ │ ├── item.xml │ │ └── main.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── jrummyapps │ └── fastscrollrecyclerview │ └── sample │ └── ExampleUnitTest.java ├── gradle ├── gradle-mvn-push.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jaredrummler │ │ └── fastscrollrecyclerview │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── jaredrummler │ │ │ └── fastscrollrecyclerview │ │ │ ├── FastScrollBar.java │ │ │ ├── FastScrollPopup.java │ │ │ ├── FastScrollRecyclerView.java │ │ │ └── Utilities.java │ └── res │ │ ├── drawable-ldrtl │ │ └── fastscroll_popup_bg.xml │ │ ├── drawable │ │ └── fastscroll_popup_bg.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ └── dimens.xml │ └── test │ └── java │ └── com │ └── jaredrummler │ └── fastscrollrecyclerview │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | ########### Specifies intentionally untracked files to ignore ########### 2 | 3 | ### Gradle 4 | .gradle/ 5 | build/ 6 | 7 | ### IntelliJ IDEA 8 | /.idea 9 | *.iml 10 | *.iws 11 | captures/ 12 | .navigation/ 13 | local.properties 14 | bin/ 15 | gen/ 16 | out/ 17 | *.apk 18 | *.ap_ 19 | 20 | ### Android 21 | *.jks 22 | *.dex 23 | 24 | ### Java 25 | *.class 26 | hs_err_pid* 27 | 28 | ### Windows 29 | Desktop.ini 30 | Thumbs.db 31 | ehthumbs.db 32 | 33 | ### OSX 34 | .DS_Store 35 | 36 | ### Linux 37 | *~ 38 | .fuse_hidden* 39 | .directory 40 | .Trash-* 41 | 42 | ### Logs 43 | *.log 44 | 45 | ### Crashlytics 46 | com_crashlytics_export_strings.xml 47 | crashlytics.properties 48 | crashlytics-build.properties 49 | fabric.properties 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2016 Jared Rummler 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ![image](./demo/src/main/res/mipmap-mdpi/ic_launcher.png) FastScroll-RecyclerView 2 | 3 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.jaredrummler/fastscroll-recyclerview/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.jaredrummler/fastscroll-recyclerview) [![License](http://img.shields.io/:license-apache-blue.svg)](LICENSE) [![API](https://img.shields.io/badge/API-11%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=14) 4 | 5 | ![DEMO GIF](art/demo.gif "DEMO") 6 | 7 | Usage 8 | ----- 9 | 10 | Add the view to your layout: 11 | 12 | ```xml 13 | 25 | ``` 26 | 27 | Create a `RecyclerView.Adapter` that extends `FastScrollRecyclerView.SectionedAdapter`: 28 | 29 | ```java 30 | private static class RecyclerAdapter extends RecyclerView.Adapter 31 | implements FastScrollRecyclerView.SectionedAdapter { 32 | 33 | private final String[] countries; 34 | 35 | public RecyclerAdapter(String[] countries) { 36 | this.countries = countries; 37 | } 38 | 39 | ... 40 | 41 | @NonNull @Override public String getSectionName(int position) { 42 | return countries[position].substring(0, 1).toUpperCase(Locale.ENGLISH); 43 | } 44 | 45 | } 46 | ``` 47 | 48 | Download 49 | -------- 50 | 51 | Download [the latest AAR](https://repo1.maven.org/maven2/com/jaredrummler/fastscroll-recyclerview/1.0.3/fastscroll-recyclerview-1.0.3.aar) or grab via Gradle: 52 | 53 | ```groovy 54 | compile 'com.jaredrummler:fastscroll-recyclerview:1.0.3' 55 | ``` 56 | or Maven: 57 | ```xml 58 | 59 | com.jaredrummler 60 | fastscroll-recyclerview 61 | 1.0.3 62 | aar 63 | 64 | ``` 65 | 66 | Credits 67 | ------- 68 | 69 | This library is based on [Google's Launcher3](https://android.googlesource.com/platform/packages/apps/Launcher3/) fast scroller. 70 | 71 | Some of the code in this library is from [Tim Malseed's](https://github.com/timusus) project [RecyclerView-FastScroller](https://github.com/timusus/RecyclerView-FastScroll) 72 | 73 | License 74 | -------- 75 | 76 | Copyright (C) 2016 Jared Rummler 77 | 78 | Licensed under the Apache License, Version 2.0 (the "License"); 79 | you may not use this file except in compliance with the License. 80 | You may obtain a copy of the License at 81 | 82 | http://www.apache.org/licenses/LICENSE-2.0 83 | 84 | Unless required by applicable law or agreed to in writing, software 85 | distributed under the License is distributed on an "AS IS" BASIS, 86 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 87 | See the License for the specific language governing permissions and 88 | limitations under the License. 89 | -------------------------------------------------------------------------------- /art/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaredrummler/FastScroll-RecyclerView/0768a0731e7b77640f39a2138973b7b528f3a84d/art/demo.gif -------------------------------------------------------------------------------- /art/ic_launcher.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaredrummler/FastScroll-RecyclerView/0768a0731e7b77640f39a2138973b7b528f3a84d/art/ic_launcher.ai -------------------------------------------------------------------------------- /art/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaredrummler/FastScroll-RecyclerView/0768a0731e7b77640f39a2138973b7b528f3a84d/art/ic_launcher.png -------------------------------------------------------------------------------- /art/ic_launcher.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 47 | 48 | 51 | 52 | 54 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:2.2.3' 7 | } 8 | } 9 | 10 | allprojects { 11 | repositories { 12 | jcenter() 13 | } 14 | } 15 | 16 | task clean(type: Delete) { 17 | delete rootProject.buildDir 18 | } 19 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /demo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.jaredrummler.fastscrollrecyclerview.sample" 9 | minSdkVersion 14 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled true 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile 'com.android.support:appcompat-v7:25.1.1' 24 | compile project(':library') 25 | testCompile 'junit:junit:4.12' 26 | } 27 | -------------------------------------------------------------------------------- /demo/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /demo/src/androidTest/java/com/jrummyapps/fastscrollrecyclerview/sample/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Jared Rummler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.jrummyapps.fastscrollrecyclerview.sample; 19 | 20 | import android.app.Application; 21 | import android.test.ApplicationTestCase; 22 | 23 | /** 24 | * Testing Fundamentals 25 | */ 26 | public class ApplicationTest extends ApplicationTestCase { 27 | 28 | public ApplicationTest() { 29 | super(Application.class); 30 | } 31 | } -------------------------------------------------------------------------------- /demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 21 | 22 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /demo/src/main/java/com/jaredrummler/fastscrollrecyclerview/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Jared Rummler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.jaredrummler.fastscrollrecyclerview.sample; 19 | 20 | import android.content.ActivityNotFoundException; 21 | import android.content.Intent; 22 | import android.net.Uri; 23 | import android.os.Bundle; 24 | import android.support.annotation.NonNull; 25 | import android.support.v7.app.AppCompatActivity; 26 | import android.support.v7.widget.LinearLayoutManager; 27 | import android.support.v7.widget.RecyclerView; 28 | import android.view.LayoutInflater; 29 | import android.view.Menu; 30 | import android.view.MenuItem; 31 | import android.view.View; 32 | import android.view.ViewGroup; 33 | import android.widget.TextView; 34 | 35 | import com.jaredrummler.fastscrollrecyclerview.FastScrollRecyclerView; 36 | 37 | import java.util.Locale; 38 | 39 | public class MainActivity extends AppCompatActivity { 40 | 41 | @Override protected void onCreate(Bundle savedInstanceState) { 42 | super.onCreate(savedInstanceState); 43 | setContentView(R.layout.main); 44 | FastScrollRecyclerView recyclerView = (FastScrollRecyclerView) findViewById(R.id.recycler); 45 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 46 | recyclerView.setAdapter(new RecyclerAdapter(getResources().getStringArray(R.array.countries_array))); 47 | } 48 | 49 | @Override public boolean onCreateOptionsMenu(Menu menu) { 50 | getMenuInflater().inflate(R.menu.menu_main, menu); 51 | return true; 52 | } 53 | 54 | @Override public boolean onOptionsItemSelected(MenuItem item) { 55 | switch (item.getItemId()) { 56 | case R.id.action_github: 57 | try { 58 | startActivity(new Intent(Intent.ACTION_VIEW, 59 | Uri.parse("https://github.com/jaredrummler/FastScroll-RecyclerView"))); 60 | } catch (ActivityNotFoundException ignored) { 61 | } 62 | return true; 63 | default: 64 | return super.onOptionsItemSelected(item); 65 | } 66 | } 67 | 68 | private static class RecyclerAdapter extends RecyclerView.Adapter 69 | implements FastScrollRecyclerView.SectionedAdapter { 70 | 71 | private final String[] countries; 72 | 73 | public RecyclerAdapter(String[] countries) { 74 | this.countries = countries; 75 | } 76 | 77 | @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 78 | return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false)); 79 | } 80 | 81 | @Override public void onBindViewHolder(ViewHolder holder, int position) { 82 | holder.text.setText(countries[position]); 83 | } 84 | 85 | @Override public int getItemCount() { 86 | return countries.length; 87 | } 88 | 89 | @NonNull @Override public String getSectionName(int position) { 90 | return countries[position].substring(0, 1).toUpperCase(Locale.ENGLISH); 91 | } 92 | 93 | static class ViewHolder extends RecyclerView.ViewHolder { 94 | 95 | public TextView text; 96 | 97 | public ViewHolder(View itemView) { 98 | super(itemView); 99 | text = (TextView) itemView.findViewById(R.id.text); 100 | } 101 | 102 | } 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/ic_github_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 24 | 27 | 28 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/item.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | -------------------------------------------------------------------------------- /demo/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 22 | 28 | 29 | -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaredrummler/FastScroll-RecyclerView/0768a0731e7b77640f39a2138973b7b528f3a84d/demo/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaredrummler/FastScroll-RecyclerView/0768a0731e7b77640f39a2138973b7b528f3a84d/demo/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaredrummler/FastScroll-RecyclerView/0768a0731e7b77640f39a2138973b7b528f3a84d/demo/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaredrummler/FastScroll-RecyclerView/0768a0731e7b77640f39a2138973b7b528f3a84d/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaredrummler/FastScroll-RecyclerView/0768a0731e7b77640f39a2138973b7b528f3a84d/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | #41a4c4 21 | #34839C 22 | #FF4081 23 | 24 | -------------------------------------------------------------------------------- /demo/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | FastScroll RecyclerView 20 | Github 21 | 22 | 23 | Afghanistan 24 | Albania 25 | Algeria 26 | American Samoa 27 | Andorra 28 | Angola 29 | Anguilla 30 | Antarctica 31 | Antigua and Barbuda 32 | Argentina 33 | Armenia 34 | Aruba 35 | Australia 36 | Austria 37 | Azerbaijan 38 | Bahrain 39 | Bangladesh 40 | Barbados 41 | Belarus 42 | Belgium 43 | Belize 44 | Benin 45 | Bermuda 46 | Bhutan 47 | Bolivia 48 | Bosnia and Herzegovina 49 | Botswana 50 | Bouvet Island 51 | Brazil 52 | British Indian Ocean Territory 53 | British Virgin Islands 54 | Brunei 55 | Bulgaria 56 | Burkina Faso 57 | Burundi 58 | Cambodia 59 | Cameroon 60 | Canada 61 | Cape Verde 62 | Cayman Islands 63 | Central African Republic 64 | Chad 65 | Chile 66 | China 67 | Christmas Island 68 | Cocos (Keeling) Islands 69 | Colombia 70 | Comoros 71 | Congo 72 | Cook Islands 73 | Costa Rica 74 | Cote d\'Ivoire 75 | Croatia 76 | Cuba 77 | Cyprus 78 | Czech Republic 79 | Democratic Republic of the Congo 80 | Denmark 81 | Djibouti 82 | Dominica 83 | Dominican Republic 84 | East Timor 85 | Ecuador 86 | Egypt 87 | El Salvador 88 | Equatorial Guinea 89 | Eritrea 90 | Estonia 91 | Ethiopia 92 | Faeroe Islands 93 | Falkland Islands 94 | Fiji 95 | Finland 96 | Former Yugoslav Republic of Macedonia 97 | France 98 | French Guiana 99 | French Polynesia 100 | French Southern Territories 101 | Gabon 102 | Georgia 103 | Germany 104 | Ghana 105 | Gibraltar 106 | Greece 107 | Greenland 108 | Grenada 109 | Guadeloupe 110 | Guam 111 | Guatemala 112 | Guinea 113 | Guinea-Bissau 114 | Guyana 115 | Haiti 116 | Heard Island and McDonald Islands 117 | Honduras 118 | Hong Kong 119 | Hungary 120 | Iceland 121 | India 122 | Indonesia 123 | Iran 124 | Iraq 125 | Ireland 126 | Israel 127 | Italy 128 | Jamaica 129 | Japan 130 | Jordan 131 | Kazakhstan 132 | Kenya 133 | Kiribati 134 | Kuwait 135 | Kyrgyzstan 136 | Laos 137 | Latvia 138 | Lebanon 139 | Lesotho 140 | Liberia 141 | Libya 142 | Liechtenstein 143 | Lithuania 144 | Luxembourg 145 | Macau 146 | Madagascar 147 | Malawi 148 | Malaysia 149 | Maldives 150 | Mali 151 | Malta 152 | Marshall Islands 153 | Martinique 154 | Mauritania 155 | Mauritius 156 | Mayotte 157 | Mexico 158 | Micronesia 159 | Moldova 160 | Monaco 161 | Mongolia 162 | Montenegro 163 | Montserrat 164 | Morocco 165 | Mozambique 166 | Myanmar 167 | Namibia 168 | Nauru 169 | Nepal 170 | Netherlands 171 | Netherlands Antilles 172 | New Caledonia 173 | New Zealand 174 | Nicaragua 175 | Niger 176 | Nigeria 177 | Niue 178 | Norfolk Island 179 | North Korea 180 | Northern Marianas 181 | Norway 182 | Oman 183 | Pakistan 184 | Palau 185 | Panama 186 | Papua New Guinea 187 | Paraguay 188 | Peru 189 | Philippines 190 | Pitcairn Islands 191 | Poland 192 | Portugal 193 | Puerto Rico 194 | Qatar 195 | Reunion 196 | Romania 197 | Russia 198 | Rwanda 199 | Sqo Tome and Principe 200 | Saint Helena 201 | Saint Kitts and Nevis 202 | Saint Lucia 203 | Saint Pierre and Miquelon 204 | Saint Vincent and the Grenadines 205 | Samoa 206 | San Marino 207 | Saudi Arabia 208 | Senegal 209 | Serbia 210 | Seychelles 211 | Sierra Leone 212 | Singapore 213 | Slovakia 214 | Slovenia 215 | Solomon Islands 216 | Somalia 217 | South Africa 218 | South Georgia and the South Sandwich Islands 219 | South Korea 220 | South Sudan 221 | Spain 222 | Sri Lanka 223 | Sudan 224 | Suriname 225 | Svalbard and Jan Mayen 226 | Swaziland 227 | Sweden 228 | Switzerland 229 | Syria 230 | Taiwan 231 | Tajikistan 232 | Tanzania 233 | Thailand 234 | The Bahamas 235 | The Gambia 236 | Togo 237 | Tokelau 238 | Tonga 239 | Trinidad and Tobago 240 | Tunisia 241 | Turkey 242 | Turkmenistan 243 | Turks and Caicos Islands 244 | Tuvalu 245 | Virgin Islands 246 | Uganda 247 | Ukraine 248 | United Arab Emirates 249 | United Kingdom 250 | United States 251 | United States Minor Outlying Islands 252 | Uruguay 253 | Uzbekistan 254 | Vanuatu 255 | Vatican City 256 | Venezuela 257 | Vietnam 258 | Wallis and Futuna 259 | Western Sahara 260 | Yemen 261 | Yugoslavia 262 | Zambia 263 | Zimbabwe 264 | 265 | 266 | 267 | -------------------------------------------------------------------------------- /demo/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /demo/src/test/java/com/jrummyapps/fastscrollrecyclerview/sample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Jared Rummler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.jrummyapps.fastscrollrecyclerview.sample; 19 | 20 | import org.junit.Test; 21 | 22 | import static org.junit.Assert.*; 23 | 24 | /** 25 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 26 | */ 27 | public class ExampleUnitTest { 28 | 29 | @Test 30 | public void addition_isCorrect() throws Exception { 31 | assertEquals(4, 2 + 2); 32 | } 33 | } -------------------------------------------------------------------------------- /gradle/gradle-mvn-push.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Chris Banes 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | apply plugin: 'maven' 19 | apply plugin: 'signing' 20 | 21 | def isReleaseBuild() { 22 | return VERSION_NAME.contains("SNAPSHOT") == false 23 | } 24 | 25 | def getReleaseRepositoryUrl() { 26 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL 27 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 28 | } 29 | 30 | def getSnapshotRepositoryUrl() { 31 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL 32 | : "https://oss.sonatype.org/content/repositories/snapshots/" 33 | } 34 | 35 | def getRepositoryUsername() { 36 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" 37 | } 38 | 39 | def getRepositoryPassword() { 40 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" 41 | } 42 | 43 | afterEvaluate { project -> 44 | uploadArchives { 45 | repositories { 46 | mavenDeployer { 47 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 48 | 49 | pom.groupId = GROUP 50 | pom.artifactId = POM_ARTIFACT_ID 51 | pom.version = VERSION_NAME 52 | 53 | repository(url: getReleaseRepositoryUrl()) { 54 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 55 | } 56 | snapshotRepository(url: getSnapshotRepositoryUrl()) { 57 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 58 | } 59 | 60 | pom.project { 61 | name POM_NAME 62 | packaging POM_PACKAGING 63 | description POM_DESCRIPTION 64 | url POM_URL 65 | 66 | scm { 67 | url POM_SCM_URL 68 | connection POM_SCM_CONNECTION 69 | developerConnection POM_SCM_DEV_CONNECTION 70 | } 71 | 72 | licenses { 73 | license { 74 | name POM_LICENCE_NAME 75 | url POM_LICENCE_URL 76 | distribution POM_LICENCE_DIST 77 | } 78 | } 79 | 80 | developers { 81 | developer { 82 | id POM_DEVELOPER_ID 83 | name POM_DEVELOPER_NAME 84 | } 85 | } 86 | } 87 | } 88 | } 89 | } 90 | 91 | signing { 92 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 93 | sign configurations.archives 94 | } 95 | 96 | task androidJavadocs(type: Javadoc) { 97 | source = android.sourceSets.main.java.srcDirs 98 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 99 | failOnError = false 100 | } 101 | 102 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 103 | classifier = 'javadoc' 104 | from androidJavadocs.destinationDir 105 | } 106 | 107 | task androidSourcesJar(type: Jar) { 108 | classifier = 'sources' 109 | from android.sourceSets.main.java.sourceFiles 110 | } 111 | 112 | artifacts { 113 | archives androidSourcesJar 114 | archives androidJavadocsJar 115 | } 116 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaredrummler/FastScroll-RecyclerView/0768a0731e7b77640f39a2138973b7b528f3a84d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Nov 04 10:19:51 PDT 2016 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-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # 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 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 11 9 | targetSdkVersion 25 10 | consumerProguardFiles 'proguard-rules.pro' 11 | } 12 | } 13 | 14 | dependencies { 15 | testCompile 'junit:junit:4.12' 16 | compile 'com.android.support:recyclerview-v7:25.1.1' 17 | } 18 | 19 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') 20 | 21 | afterEvaluate { 22 | androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath 23 | } -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=1.0.3 2 | VERSION_CODE=4 3 | GROUP=com.jaredrummler 4 | 5 | POM_NAME=FastScroll RecyclerView 6 | POM_ARTIFACT_ID=fastscroll-recyclerview 7 | POM_PACKAGING=aar 8 | 9 | POM_DESCRIPTION=ReyclerView with fast scrolling and scroll popups 10 | POM_URL=https://github.com/jaredrummler/FastScroll-RecyclerView 11 | POM_SCM_URL=https://github.com/jaredrummler/FastScroll-RecyclerView 12 | POM_SCM_CONNECTION=scm:git@github.com:jaredrummler/FastScroll-RecyclerView.git 13 | POM_SCM_DEV_CONNECTION=scm:git@github.com:jaredrummler/FastScroll-RecyclerView.git 14 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 15 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 16 | POM_LICENCE_DIST=repo 17 | POM_DEVELOPER_ID=jaredrummler 18 | POM_DEVELOPER_NAME=Jared Rummler 19 | 20 | SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots 21 | RELEASE_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2 -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | -keep class com.jaredrummler.fastscrollrecyclerview.** { *; } -------------------------------------------------------------------------------- /library/src/androidTest/java/com/jaredrummler/fastscrollrecyclerview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Jared Rummler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.jaredrummler.fastscrollrecyclerview; 19 | 20 | import android.app.Application; 21 | import android.test.ApplicationTestCase; 22 | 23 | /** 24 | * Testing Fundamentals 25 | */ 26 | public class ApplicationTest extends ApplicationTestCase { 27 | 28 | public ApplicationTest() { 29 | super(Application.class); 30 | } 31 | } -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /library/src/main/java/com/jaredrummler/fastscrollrecyclerview/FastScrollBar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Jared Rummler 3 | * Copyright (C) 2015 The Android Open Source Project 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.jaredrummler.fastscrollrecyclerview; 20 | 21 | import android.animation.AnimatorSet; 22 | import android.animation.ArgbEvaluator; 23 | import android.animation.ObjectAnimator; 24 | import android.animation.ValueAnimator; 25 | import android.content.res.Resources; 26 | import android.content.res.TypedArray; 27 | import android.graphics.Canvas; 28 | import android.graphics.Color; 29 | import android.graphics.Paint; 30 | import android.graphics.Path; 31 | import android.graphics.Point; 32 | import android.graphics.Rect; 33 | import android.support.annotation.ColorInt; 34 | import android.util.AttributeSet; 35 | import android.view.MotionEvent; 36 | import android.view.ViewConfiguration; 37 | 38 | public class FastScrollBar { 39 | 40 | private final static int MAX_TRACK_ALPHA = 30; 41 | private final static int SCROLL_BAR_VIS_DURATION = 150; 42 | 43 | private final Rect invalidateRect = new Rect(); 44 | private final Rect tmpRect = new Rect(); 45 | 46 | /*package*/ final Point thumbOffset = new Point(-1, -1); 47 | private final Path thumbPath = new Path(); 48 | 49 | /*package*/ FastScrollRecyclerView recyclerView; 50 | private FastScrollPopup fastScrollPopup; 51 | 52 | private AnimatorSet scrollbarAnimator; 53 | 54 | private int thumbInactiveColor; 55 | private int thumbActiveColor; 56 | 57 | /*package*/ Paint thumbPaint; 58 | private int thumbMinWidth; 59 | private int thumbMaxWidth; 60 | /*package*/ int thumbWidth; 61 | /*package*/ int thumbHeight; 62 | private int thumbCurvature; 63 | 64 | private Paint trackPaint; 65 | private int trackWidth; 66 | private float lastTouchY; 67 | 68 | // The inset is the buffer around which a point will still register as a click on the scrollbar 69 | private int touchInset; 70 | 71 | private boolean isDragging; 72 | private boolean isThumbDetached; 73 | private boolean canThumbDetach; 74 | private boolean ignoreDragGesture; 75 | private boolean showThumbCurvature; 76 | 77 | // This is the offset from the top of the scrollbar when the user first starts touching. 78 | // To prevent jumping, this offset is applied as the user scrolls. 79 | private int touchOffset; 80 | 81 | public FastScrollBar(FastScrollRecyclerView rv, AttributeSet attrs) { 82 | TypedArray ta = rv.getContext().obtainStyledAttributes(attrs, R.styleable.FastScrollRecyclerView); 83 | Resources res = rv.getResources(); 84 | showThumbCurvature = ta.getBoolean(R.styleable.FastScrollRecyclerView_fastScrollThumbCurvatureEnabled, false); 85 | thumbInactiveColor = ta.getColor(R.styleable.FastScrollRecyclerView_fastScrollThumbInactiveColor, 86 | res.getColor(R.color.fastscroll_thumb_inactive_color)); 87 | thumbActiveColor = ta.getColor(R.styleable.FastScrollRecyclerView_fastScrollThumbActiveColor, 88 | res.getColor(R.color.fastscroll_thumb_active_color)); 89 | int trackColor = ta.getColor(R.styleable.FastScrollRecyclerView_fastScrollTrackColor, Color.BLACK); 90 | ta.recycle(); 91 | recyclerView = rv; 92 | fastScrollPopup = new FastScrollPopup(rv, attrs); 93 | trackPaint = new Paint(); 94 | trackPaint.setColor(trackColor); 95 | trackPaint.setAlpha(MAX_TRACK_ALPHA); 96 | thumbPaint = new Paint(); 97 | thumbPaint.setAntiAlias(true); 98 | thumbPaint.setColor(thumbInactiveColor); 99 | thumbPaint.setStyle(Paint.Style.FILL); 100 | thumbWidth = thumbMinWidth = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_min_width); 101 | thumbMaxWidth = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_max_width); 102 | thumbHeight = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_height); 103 | thumbCurvature = showThumbCurvature ? thumbMaxWidth - thumbMinWidth : 0; 104 | touchInset = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_touch_inset); 105 | if (rv.isFastScrollAlwaysEnabled()) { 106 | animateScrollbar(true); 107 | } 108 | } 109 | 110 | public void setDetachThumbOnFastScroll() { 111 | canThumbDetach = true; 112 | } 113 | 114 | public void reattachThumbToScroll() { 115 | isThumbDetached = false; 116 | } 117 | 118 | public void setThumbOffset(int x, int y) { 119 | if (thumbOffset.x == x && thumbOffset.y == y) { 120 | return; 121 | } 122 | invalidateRect 123 | .set(thumbOffset.x - thumbCurvature, thumbOffset.y, thumbOffset.x + thumbWidth, thumbOffset.y + thumbHeight); 124 | thumbOffset.set(x, y); 125 | updateThumbPath(); 126 | invalidateRect 127 | .union(thumbOffset.x - thumbCurvature, thumbOffset.y, thumbOffset.x + thumbWidth, thumbOffset.y + thumbHeight); 128 | recyclerView.invalidate(invalidateRect); 129 | } 130 | 131 | public Point getThumbOffset() { 132 | return thumbOffset; 133 | } 134 | 135 | // Setter/getter for the thumb bar width for animations 136 | public void setThumbWidth(int width) { 137 | invalidateRect 138 | .set(thumbOffset.x - thumbCurvature, thumbOffset.y, thumbOffset.x + thumbWidth, thumbOffset.y + thumbHeight); 139 | thumbWidth = width; 140 | updateThumbPath(); 141 | invalidateRect 142 | .union(thumbOffset.x - thumbCurvature, thumbOffset.y, thumbOffset.x + thumbWidth, thumbOffset.y + thumbHeight); 143 | recyclerView.invalidate(invalidateRect); 144 | } 145 | 146 | public int getThumbWidth() { 147 | return thumbWidth; 148 | } 149 | 150 | // Setter/getter for the track bar width for animations 151 | public void setTrackWidth(int width) { 152 | invalidateRect.set(thumbOffset.x - thumbCurvature, 0, thumbOffset.x + thumbWidth, recyclerView.getHeight()); 153 | trackWidth = width; 154 | updateThumbPath(); 155 | invalidateRect.union(thumbOffset.x - thumbCurvature, 0, thumbOffset.x + thumbWidth, recyclerView.getHeight()); 156 | recyclerView.invalidate(invalidateRect); 157 | } 158 | 159 | public int getTrackWidth() { 160 | return trackWidth; 161 | } 162 | 163 | public int getThumbHeight() { 164 | return thumbHeight; 165 | } 166 | 167 | public int getThumbMaxWidth() { 168 | return thumbMaxWidth; 169 | } 170 | 171 | public float getLastTouchY() { 172 | return lastTouchY; 173 | } 174 | 175 | public boolean isDraggingThumb() { 176 | return isDragging; 177 | } 178 | 179 | public boolean isThumbDetached() { 180 | return isThumbDetached; 181 | } 182 | 183 | public void setThumbActiveColor(@ColorInt int color) { 184 | thumbActiveColor = color; 185 | thumbPaint.setColor(color); 186 | recyclerView.invalidate(invalidateRect); 187 | } 188 | 189 | public void setThumbInactiveColor(@ColorInt int color) { 190 | thumbInactiveColor = color; 191 | thumbPaint.setColor(color); 192 | recyclerView.invalidate(invalidateRect); 193 | } 194 | 195 | public void setTrackColor(@ColorInt int color) { 196 | trackPaint.setColor(color); 197 | recyclerView.invalidate(invalidateRect); 198 | } 199 | 200 | public void setPopupBackgroundColor(@ColorInt int color) { 201 | fastScrollPopup.setBackgroundColor(color); 202 | } 203 | 204 | public void setPopupTextColor(@ColorInt int color) { 205 | fastScrollPopup.setTextColor(color); 206 | } 207 | 208 | public FastScrollPopup getFastScrollPopup() { 209 | return fastScrollPopup; 210 | } 211 | 212 | /** 213 | * Handles the touch event and determines whether to show the fast scroller (or updates it if 214 | * it is already showing). 215 | */ 216 | protected void handleTouchEvent(MotionEvent ev, int downX, int downY, int lastY) { 217 | ViewConfiguration config = ViewConfiguration.get(recyclerView.getContext()); 218 | 219 | int action = ev.getAction(); 220 | int y = (int) ev.getY(); 221 | switch (action) { 222 | case MotionEvent.ACTION_DOWN: 223 | if (isNearThumb(downX, downY)) { 224 | touchOffset = downY - thumbOffset.y; 225 | } 226 | break; 227 | case MotionEvent.ACTION_MOVE: 228 | // Check if we should start scrolling, but ignore this fastscroll gesture if we have 229 | // exceeded some fixed movement 230 | ignoreDragGesture |= Math.abs(y - downY) > config.getScaledPagingTouchSlop(); 231 | if (!isDragging && !ignoreDragGesture && isNearThumb(downX, lastY) && 232 | Math.abs(y - downY) > config.getScaledTouchSlop()) { 233 | recyclerView.getParent().requestDisallowInterceptTouchEvent(true); 234 | isDragging = true; 235 | if (canThumbDetach) { 236 | isThumbDetached = true; 237 | } 238 | touchOffset += (lastY - downY); 239 | fastScrollPopup.animateVisibility(true); 240 | animateScrollbar(true); 241 | } 242 | if (isDragging) { 243 | // Update the fastscroller section name at this touch position 244 | int top = recyclerView.getBackgroundPadding().top; 245 | int bottom = recyclerView.getHeight() - recyclerView.getBackgroundPadding().bottom - thumbHeight; 246 | float boundedY = (float) Math.max(top, Math.min(bottom, y - touchOffset)); 247 | String sectionName = recyclerView.scrollToPositionAtProgress((boundedY - top) / (bottom - top)); 248 | fastScrollPopup.setSectionName(sectionName); 249 | fastScrollPopup.animateVisibility(!sectionName.isEmpty()); 250 | recyclerView.invalidate(fastScrollPopup.updateFastScrollerBounds(recyclerView, lastY)); 251 | lastTouchY = boundedY; 252 | } 253 | break; 254 | case MotionEvent.ACTION_UP: 255 | case MotionEvent.ACTION_CANCEL: 256 | touchOffset = 0; 257 | lastTouchY = 0; 258 | ignoreDragGesture = false; 259 | if (isDragging) { 260 | isDragging = false; 261 | fastScrollPopup.animateVisibility(false); 262 | recyclerView.hideScrollBar(); 263 | } 264 | break; 265 | } 266 | } 267 | 268 | protected void draw(Canvas canvas) { 269 | if (thumbOffset.x < 0 || thumbOffset.y < 0) { 270 | return; 271 | } 272 | 273 | // Draw the scroll bar track and thumb 274 | if (trackPaint.getAlpha() > 0) { 275 | canvas.drawRect(thumbOffset.x, 0, thumbOffset.x + thumbWidth, recyclerView.getHeight(), trackPaint); 276 | } 277 | canvas.drawPath(thumbPath, thumbPaint); 278 | 279 | // Draw the popup 280 | fastScrollPopup.draw(canvas); 281 | } 282 | 283 | /** 284 | * Animates the width and color of the scrollbar. 285 | */ 286 | protected void animateScrollbar(boolean isScrolling) { 287 | if (scrollbarAnimator != null) { 288 | scrollbarAnimator.cancel(); 289 | } 290 | 291 | scrollbarAnimator = new AnimatorSet(); 292 | ObjectAnimator trackWidthAnim = ObjectAnimator.ofInt(this, "trackWidth", 293 | isScrolling ? thumbMaxWidth : thumbMinWidth); 294 | ObjectAnimator thumbWidthAnim = ObjectAnimator.ofInt(this, "thumbWidth", 295 | isScrolling ? thumbMaxWidth : thumbMinWidth); 296 | scrollbarAnimator.playTogether(trackWidthAnim, thumbWidthAnim); 297 | if (thumbActiveColor != thumbInactiveColor) { 298 | ValueAnimator colorAnimation = ValueAnimator 299 | .ofObject(new ArgbEvaluator(), thumbPaint.getColor(), isScrolling ? thumbActiveColor : thumbInactiveColor); 300 | colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 301 | 302 | @Override 303 | public void onAnimationUpdate(ValueAnimator animator) { 304 | thumbPaint.setColor((Integer) animator.getAnimatedValue()); 305 | recyclerView 306 | .invalidate(thumbOffset.x, thumbOffset.y, thumbOffset.x + thumbWidth, thumbOffset.y + thumbHeight); 307 | } 308 | }); 309 | scrollbarAnimator.play(colorAnimation); 310 | } 311 | scrollbarAnimator.setDuration(SCROLL_BAR_VIS_DURATION); 312 | scrollbarAnimator.start(); 313 | } 314 | 315 | /** 316 | * Updates the path for the thumb drawable. 317 | */ 318 | private void updateThumbPath() { 319 | thumbCurvature = showThumbCurvature ? thumbMaxWidth - thumbWidth : 0; 320 | thumbPath.reset(); 321 | thumbPath.moveTo(thumbOffset.x + thumbWidth, thumbOffset.y); // tr 322 | thumbPath.lineTo(thumbOffset.x + thumbWidth, thumbOffset.y + thumbHeight); // br 323 | thumbPath.lineTo(thumbOffset.x, thumbOffset.y + thumbHeight); // bl 324 | thumbPath.cubicTo(thumbOffset.x, thumbOffset.y + thumbHeight, 325 | thumbOffset.x - thumbCurvature, 326 | thumbOffset.y + thumbHeight / 2, 327 | thumbOffset.x, thumbOffset.y); // bl2tl 328 | thumbPath.close(); 329 | } 330 | 331 | /** 332 | * Returns whether the specified points are near the scroll bar bounds. 333 | */ 334 | private boolean isNearThumb(int x, int y) { 335 | tmpRect.set(thumbOffset.x, thumbOffset.y, thumbOffset.x + thumbWidth, 336 | thumbOffset.y + thumbHeight); 337 | tmpRect.inset(touchInset, touchInset); 338 | return tmpRect.contains(x, y); 339 | } 340 | 341 | } 342 | -------------------------------------------------------------------------------- /library/src/main/java/com/jaredrummler/fastscrollrecyclerview/FastScrollPopup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Jared Rummler 3 | * Copyright (C) 2015 The Android Open Source Project 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.jaredrummler.fastscrollrecyclerview; 20 | 21 | import android.animation.Animator; 22 | import android.animation.ObjectAnimator; 23 | import android.content.res.Resources; 24 | import android.content.res.TypedArray; 25 | import android.graphics.Canvas; 26 | import android.graphics.Color; 27 | import android.graphics.Paint; 28 | import android.graphics.PorterDuff; 29 | import android.graphics.Rect; 30 | import android.graphics.drawable.Drawable; 31 | import android.support.annotation.ColorInt; 32 | import android.util.AttributeSet; 33 | 34 | /** 35 | * The fast scroller popup that shows the section name the list will jump to. 36 | */ 37 | public class FastScrollPopup { 38 | 39 | private static final float FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR = 1.5f; 40 | 41 | private final Rect backgroundBounds = new Rect(); // The absolute bounds of the fast scroller bg 42 | private final Rect invalidateRect = new Rect(); 43 | private final Rect tmpRect = new Rect(); 44 | private final Rect textBounds = new Rect(); 45 | 46 | private FastScrollRecyclerView recyclerView; 47 | private Animator alphaAnimator; 48 | private Resources resources; 49 | private Drawable background; 50 | private Paint textPaint; 51 | private String sectionName; 52 | private int originalBackgroundSize; 53 | private float alpha; 54 | private boolean visible; 55 | 56 | public FastScrollPopup(FastScrollRecyclerView rv, AttributeSet attrs) { 57 | TypedArray ta = rv.getContext().obtainStyledAttributes(attrs, R.styleable.FastScrollRecyclerView); 58 | recyclerView = rv; 59 | resources = rv.getResources(); 60 | int bgColor = ta.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupBackgroundColor, Color.TRANSPARENT); 61 | int textColor = ta.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupTextColor, Color.WHITE); 62 | float textSize = ta.getDimension(R.styleable.FastScrollRecyclerView_fastScrollTextSize, resources.getDimensionPixelSize(R.dimen.fastscroll_popup_text_size)); 63 | originalBackgroundSize = (int) textSize + (int) ta.getDimension(R.styleable.FastScrollRecyclerView_fastScrollPopupPadding, resources.getDimensionPixelSize(R.dimen.fastscroll_popup_default_padding)); 64 | background = resources.getDrawable(R.drawable.fastscroll_popup_bg); 65 | if (bgColor != Color.TRANSPARENT) { 66 | background = background.mutate(); 67 | background.setColorFilter(bgColor, PorterDuff.Mode.SRC_IN); 68 | } 69 | background.setBounds(0, 0, originalBackgroundSize, originalBackgroundSize); 70 | textPaint = new Paint(); 71 | textPaint.setColor(textColor); 72 | textPaint.setAntiAlias(true); 73 | textPaint.setTextSize(textSize); 74 | ta.recycle(); 75 | } 76 | 77 | /** 78 | * Sets the section name. 79 | */ 80 | protected void setSectionName(String sectionName) { 81 | if (!sectionName.equals(this.sectionName)) { 82 | this.sectionName = sectionName; 83 | textPaint.getTextBounds(sectionName, 0, sectionName.length(), textBounds); 84 | // Update the width to use measureText since that is more accurate 85 | textBounds.right = (int) (textBounds.left + textPaint.measureText(sectionName)); 86 | } 87 | } 88 | 89 | /** 90 | * Updates the bounds for the fast scroller. 91 | * 92 | * @return the invalidation rect for this update. 93 | */ 94 | protected Rect updateFastScrollerBounds(FastScrollRecyclerView rv, int lastTouchY) { 95 | invalidateRect.set(backgroundBounds); 96 | 97 | if (isVisible()) { 98 | // Calculate the dimensions and position of the fast scroller popup 99 | int edgePadding = rv.getMaxScrollbarWidth(); 100 | int bgPadding = (originalBackgroundSize - textBounds.height()) / 2; 101 | int bgHeight = originalBackgroundSize; 102 | int bgWidth = Math.max(originalBackgroundSize, textBounds.width() + (2 * bgPadding)); 103 | if (Utilities.isRtl(resources)) { 104 | backgroundBounds.left = rv.getBackgroundPadding().left + (2 * rv.getMaxScrollbarWidth()); 105 | backgroundBounds.right = backgroundBounds.left + bgWidth; 106 | } else { 107 | backgroundBounds.right = rv.getWidth() - rv.getBackgroundPadding().right - (2 * rv.getMaxScrollbarWidth()); 108 | backgroundBounds.left = backgroundBounds.right - bgWidth; 109 | } 110 | backgroundBounds.top = lastTouchY - (int) (FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR * bgHeight); 111 | backgroundBounds.top = 112 | Math.max(edgePadding, Math.min(backgroundBounds.top, rv.getHeight() - edgePadding - bgHeight)); 113 | backgroundBounds.bottom = backgroundBounds.top + bgHeight; 114 | } else { 115 | backgroundBounds.setEmpty(); 116 | } 117 | 118 | // Combine the old and new fast scroller bounds to create the full invalidate rect 119 | invalidateRect.union(backgroundBounds); 120 | return invalidateRect; 121 | } 122 | 123 | /** 124 | * Animates the visibility of the fast scroller popup. 125 | */ 126 | public void animateVisibility(boolean visible) { 127 | if (this.visible != visible) { 128 | this.visible = visible; 129 | if (alphaAnimator != null) { 130 | alphaAnimator.cancel(); 131 | } 132 | alphaAnimator = ObjectAnimator.ofFloat(this, "alpha", visible ? 1f : 0f); 133 | alphaAnimator.setDuration(visible ? 200 : 150); 134 | alphaAnimator.start(); 135 | } 136 | } 137 | 138 | // Setter/getter for the popup alpha for animations 139 | public void setAlpha(float alpha) { 140 | this.alpha = alpha; 141 | recyclerView.invalidate(backgroundBounds); 142 | } 143 | 144 | public float getAlpha() { 145 | return alpha; 146 | } 147 | 148 | public void setBackgroundColor(@ColorInt int color) { 149 | background = background.mutate(); 150 | background.setColorFilter(color, PorterDuff.Mode.SRC_IN); 151 | } 152 | 153 | public void setTextColor(@ColorInt int color) { 154 | textPaint.setColor(color); 155 | } 156 | 157 | public int getHeight() { 158 | return originalBackgroundSize; 159 | } 160 | 161 | protected void draw(Canvas c) { 162 | if (isVisible()) { 163 | // Draw the fast scroller popup 164 | int restoreCount = c.save(Canvas.MATRIX_SAVE_FLAG); 165 | c.translate(backgroundBounds.left, backgroundBounds.top); 166 | tmpRect.set(backgroundBounds); 167 | tmpRect.offsetTo(0, 0); 168 | background.setBounds(tmpRect); 169 | background.setAlpha((int) (alpha * 255)); 170 | background.draw(c); 171 | textPaint.setAlpha((int) (alpha * 255)); 172 | c.drawText(sectionName, (backgroundBounds.width() - textBounds.width()) / 2, 173 | backgroundBounds.height() - (backgroundBounds.height() - textBounds.height()) / 2, 174 | textPaint); 175 | c.restoreToCount(restoreCount); 176 | } 177 | } 178 | 179 | public boolean isVisible() { 180 | return (alpha > 0f) && (sectionName != null); 181 | } 182 | 183 | } 184 | -------------------------------------------------------------------------------- /library/src/main/java/com/jaredrummler/fastscrollrecyclerview/FastScrollRecyclerView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Jared Rummler 3 | * Copyright (C) 2016 Tim Malseed 4 | * Copyright (C) 2015 The Android Open Source Project 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | package com.jaredrummler.fastscrollrecyclerview; 21 | 22 | import android.content.Context; 23 | import android.content.res.TypedArray; 24 | import android.graphics.Canvas; 25 | import android.graphics.Rect; 26 | import android.support.annotation.ColorInt; 27 | import android.support.annotation.NonNull; 28 | import android.support.v7.widget.GridLayoutManager; 29 | import android.support.v7.widget.LinearLayoutManager; 30 | import android.support.v7.widget.RecyclerView; 31 | import android.util.AttributeSet; 32 | import android.view.MotionEvent; 33 | import android.view.View; 34 | 35 | /** 36 | * A base {@link RecyclerView}, which does the following: 37 | * 38 | *
    39 | *
  • NOT intercept a touch unless the scrolling velocity is below a predefined threshold. 40 | *
  • Enable fast scroller. 41 | *
42 | */ 43 | public class FastScrollRecyclerView extends RecyclerView implements RecyclerView.OnItemTouchListener { 44 | 45 | private static final int SCROLL_DELTA_THRESHOLD_DP = 4; 46 | private static final int DEFAULT_HIDE_DELAY = 1000; 47 | 48 | private final ScrollPositionState scrollPositionState = new ScrollPositionState(); 49 | private final Rect backgroundPadding = new Rect(); 50 | /*package*/ FastScrollBar fastScrollBar; 51 | /*package*/ boolean fastScrollAlwaysEnabled; 52 | private float deltaThreshold; 53 | private int hideDelay; 54 | /*package*/ int lastDy; // Keeps the last known scrolling delta/velocity along y-axis. 55 | private int downX; 56 | private int downY; 57 | private int lastY; 58 | 59 | final Runnable hide = new Runnable() { 60 | 61 | @Override public void run() { 62 | if (!fastScrollBar.isDraggingThumb()) { 63 | fastScrollBar.animateScrollbar(false); 64 | } 65 | } 66 | }; 67 | 68 | public FastScrollRecyclerView(Context context) { 69 | this(context, null); 70 | } 71 | 72 | public FastScrollRecyclerView(Context context, AttributeSet attrs) { 73 | this(context, attrs, 0); 74 | } 75 | 76 | public FastScrollRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) { 77 | super(context, attrs, defStyleAttr); 78 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.FastScrollRecyclerView); 79 | fastScrollAlwaysEnabled = ta.getBoolean(R.styleable.FastScrollRecyclerView_fastScrollAlwaysEnabled, false); 80 | hideDelay = ta.getInt(R.styleable.FastScrollRecyclerView_fastScrollHideDelay, DEFAULT_HIDE_DELAY); 81 | ta.recycle(); 82 | deltaThreshold = getResources().getDisplayMetrics().density * SCROLL_DELTA_THRESHOLD_DP; 83 | fastScrollBar = new FastScrollBar(this, attrs); 84 | fastScrollBar.setDetachThumbOnFastScroll(); 85 | addOnScrollListener(new OnScrollListener() { 86 | 87 | @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 88 | if (fastScrollAlwaysEnabled) return; 89 | switch (newState) { 90 | case SCROLL_STATE_DRAGGING: 91 | removeCallbacks(hide); 92 | fastScrollBar.animateScrollbar(true); 93 | break; 94 | case SCROLL_STATE_IDLE: 95 | hideScrollBar(); 96 | break; 97 | } 98 | } 99 | 100 | @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 101 | lastDy = dy; 102 | onUpdateScrollbar(dy); 103 | } 104 | }); 105 | } 106 | 107 | public void reset() { 108 | fastScrollBar.reattachThumbToScroll(); 109 | } 110 | 111 | @Override protected void onFinishInflate() { 112 | super.onFinishInflate(); 113 | addOnItemTouchListener(this); 114 | } 115 | 116 | /** 117 | * We intercept the touch handling only to support fast scrolling when initiated from the 118 | * scroll bar. Otherwise, we fall back to the default RecyclerView touch handling. 119 | */ 120 | @Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent ev) { 121 | return handleTouchEvent(ev); 122 | } 123 | 124 | @Override public void onTouchEvent(RecyclerView rv, MotionEvent ev) { 125 | handleTouchEvent(ev); 126 | } 127 | 128 | /** 129 | * Handles the touch event and determines whether to show the fast scroller (or updates it if 130 | * it is already showing). 131 | */ 132 | private boolean handleTouchEvent(MotionEvent ev) { 133 | int action = ev.getAction(); 134 | int x = (int) ev.getX(); 135 | int y = (int) ev.getY(); 136 | switch (action) { 137 | case MotionEvent.ACTION_DOWN: 138 | // Keep track of the down positions 139 | downX = x; 140 | downY = lastY = y; 141 | if (shouldStopScroll(ev)) { 142 | stopScroll(); 143 | } 144 | fastScrollBar.handleTouchEvent(ev, downX, downY, lastY); 145 | break; 146 | case MotionEvent.ACTION_MOVE: 147 | lastY = y; 148 | fastScrollBar.handleTouchEvent(ev, downX, downY, lastY); 149 | break; 150 | case MotionEvent.ACTION_UP: 151 | case MotionEvent.ACTION_CANCEL: 152 | onFastScrollCompleted(); 153 | fastScrollBar.handleTouchEvent(ev, downX, downY, lastY); 154 | break; 155 | } 156 | return fastScrollBar.isDraggingThumb(); 157 | } 158 | 159 | @Override public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 160 | // DO NOT REMOVE, NEEDED IMPLEMENTATION FOR M BUILDS 161 | } 162 | 163 | /** 164 | * Returns whether this {@link MotionEvent} should trigger the scroll to be stopped. 165 | */ 166 | protected boolean shouldStopScroll(MotionEvent ev) { 167 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { 168 | if ((Math.abs(lastDy) < deltaThreshold && getScrollState() != RecyclerView.SCROLL_STATE_IDLE)) { 169 | // now the touch events are being passed to the {@link WidgetCell} until the 170 | // touch sequence goes over the touch slop. 171 | return true; 172 | } 173 | } 174 | return false; 175 | } 176 | 177 | public void updateBackgroundPadding(Rect padding) { 178 | backgroundPadding.set(padding); 179 | } 180 | 181 | public Rect getBackgroundPadding() { 182 | return backgroundPadding; 183 | } 184 | 185 | /** 186 | * Returns the scroll bar width when the user is scrolling. 187 | */ 188 | public int getMaxScrollbarWidth() { 189 | return fastScrollBar.getThumbMaxWidth(); 190 | } 191 | 192 | /** 193 | * Returns the available scroll height: 194 | * AvailableScrollHeight = Total height of the all items - last page height 195 | * 196 | * This assumes that all rows are the same height. 197 | */ 198 | protected int getAvailableScrollHeight(int rowCount, int rowHeight) { 199 | int visibleHeight = getHeight() - backgroundPadding.top - backgroundPadding.bottom; 200 | int scrollHeight = getPaddingTop() + rowCount * rowHeight + getPaddingBottom(); 201 | return scrollHeight - visibleHeight; 202 | } 203 | 204 | /** 205 | * Returns the available scroll bar height: 206 | * AvailableScrollBarHeight = Total height of the visible view - thumb height 207 | */ 208 | protected int getAvailableScrollBarHeight() { 209 | int visibleHeight = getHeight() - backgroundPadding.top - backgroundPadding.bottom; 210 | return visibleHeight - fastScrollBar.getThumbHeight(); 211 | } 212 | 213 | public boolean isFastScrollAlwaysEnabled() { 214 | return fastScrollAlwaysEnabled; 215 | } 216 | 217 | protected void hideScrollBar() { 218 | if (!fastScrollAlwaysEnabled) { 219 | removeCallbacks(hide); 220 | postDelayed(hide, hideDelay); 221 | } 222 | } 223 | 224 | public void setThumbActiveColor(@ColorInt int color) { 225 | fastScrollBar.setThumbActiveColor(color); 226 | } 227 | 228 | public void setTrackInactiveColor(@ColorInt int color) { 229 | fastScrollBar.setThumbInactiveColor(color); 230 | } 231 | 232 | public void setPopupBackgroundColor(@ColorInt int color) { 233 | fastScrollBar.setPopupBackgroundColor(color); 234 | } 235 | 236 | public void setPopupTextColor(@ColorInt int color) { 237 | fastScrollBar.setPopupTextColor(color); 238 | } 239 | 240 | public FastScrollBar getFastScrollBar() { 241 | return fastScrollBar; 242 | } 243 | 244 | @Override 245 | public void draw(Canvas canvas) { 246 | super.draw(canvas); 247 | 248 | // Draw the ScrollBar AFTER the ItemDecorations are drawn over 249 | onUpdateScrollbar(0); 250 | fastScrollBar.draw(canvas); 251 | } 252 | 253 | /** 254 | * Updates the scrollbar thumb offset to match the visible scroll of the recycler view. It does 255 | * this by mapping the available scroll area of the recycler view to the available space for the 256 | * scroll bar. 257 | * 258 | * @param scrollPosState 259 | * the current scroll position 260 | * @param rowCount 261 | * the number of rows, used to calculate the total scroll height (assumes that 262 | * all rows are the same height) 263 | */ 264 | protected void synchronizeScrollBarThumbOffsetToViewScroll(ScrollPositionState scrollPosState, int rowCount) { 265 | // Only show the scrollbar if there is height to be scrolled 266 | int availableScrollBarHeight = getAvailableScrollBarHeight(); 267 | int availableScrollHeight = getAvailableScrollHeight(rowCount, scrollPosState.rowHeight); 268 | if (availableScrollHeight <= 0) { 269 | fastScrollBar.setThumbOffset(-1, -1); 270 | return; 271 | } 272 | 273 | // Calculate the current scroll position, the scrollY of the recycler view accounts for the 274 | // view padding, while the scrollBarY is drawn right up to the background padding (ignoring 275 | // padding) 276 | int scrollY = getPaddingTop() + 277 | Math.round(((scrollPosState.rowIndex - scrollPosState.rowTopOffset) * scrollPosState.rowHeight)); 278 | int scrollBarY = 279 | backgroundPadding.top + (int) (((float) scrollY / availableScrollHeight) * availableScrollBarHeight); 280 | 281 | // Calculate the position and size of the scroll bar 282 | int scrollBarX; 283 | if (Utilities.isRtl(getResources())) { 284 | scrollBarX = backgroundPadding.left; 285 | } else { 286 | scrollBarX = getWidth() - backgroundPadding.right - fastScrollBar.getThumbWidth(); 287 | } 288 | fastScrollBar.setThumbOffset(scrollBarX, scrollBarY); 289 | } 290 | 291 | /** 292 | *

Maps the touch (from 0..1) to the adapter position that should be visible.

293 | * 294 | *

Override in each subclass of this base class.

295 | */ 296 | public String scrollToPositionAtProgress(float touchFraction) { 297 | int itemCount = getAdapter().getItemCount(); 298 | if (itemCount == 0) { 299 | return ""; 300 | } 301 | int spanCount = 1; 302 | int rowCount = itemCount; 303 | if (getLayoutManager() instanceof GridLayoutManager) { 304 | spanCount = ((GridLayoutManager) getLayoutManager()).getSpanCount(); 305 | rowCount = (int) Math.ceil((double) rowCount / spanCount); 306 | } 307 | 308 | // Stop the scroller if it is scrolling 309 | stopScroll(); 310 | 311 | getCurScrollState(scrollPositionState); 312 | 313 | float itemPos = itemCount * touchFraction; 314 | 315 | int availableScrollHeight = getAvailableScrollHeight(rowCount, scrollPositionState.rowHeight); 316 | 317 | //The exact position of our desired item 318 | int exactItemPos = (int) (availableScrollHeight * touchFraction); 319 | 320 | //Scroll to the desired item. The offset used here is kind of hard to explain. 321 | //If the position we wish to scroll to is, say, position 10.5, we scroll to position 10, 322 | //and then offset by 0.5 * rowHeight. This is how we achieve smooth scrolling. 323 | LinearLayoutManager layoutManager = ((LinearLayoutManager) getLayoutManager()); 324 | layoutManager.scrollToPositionWithOffset(spanCount * exactItemPos / scrollPositionState.rowHeight, 325 | -(exactItemPos % scrollPositionState.rowHeight)); 326 | 327 | if (!(getAdapter() instanceof SectionedAdapter)) { 328 | return ""; 329 | } 330 | 331 | int posInt = (int) ((touchFraction == 1) ? itemPos - 1 : itemPos); 332 | 333 | SectionedAdapter sectionedAdapter = (SectionedAdapter) getAdapter(); 334 | return sectionedAdapter.getSectionName(posInt); 335 | } 336 | 337 | /** 338 | *

Updates the bounds for the scrollbar.

339 | * 340 | *

Override in each subclass of this base class.

341 | */ 342 | public void onUpdateScrollbar(int dy) { 343 | int rowCount = getAdapter().getItemCount(); 344 | if (getLayoutManager() instanceof GridLayoutManager) { 345 | int spanCount = ((GridLayoutManager) getLayoutManager()).getSpanCount(); 346 | rowCount = (int) Math.ceil((double) rowCount / spanCount); 347 | } 348 | // Skip early if, there are no items. 349 | if (rowCount == 0) { 350 | fastScrollBar.setThumbOffset(-1, -1); 351 | return; 352 | } 353 | 354 | // Skip early if, there no child laid out in the container. 355 | getCurScrollState(scrollPositionState); 356 | if (scrollPositionState.rowIndex < 0) { 357 | fastScrollBar.setThumbOffset(-1, -1); 358 | return; 359 | } 360 | 361 | synchronizeScrollBarThumbOffsetToViewScroll(scrollPositionState, rowCount); 362 | } 363 | 364 | /** 365 | *

Override in each subclass of this base class.

366 | */ 367 | public void onFastScrollCompleted() { 368 | } 369 | 370 | /** 371 | * Returns information about the item that the recycler view is currently scrolled to. 372 | */ 373 | protected void getCurScrollState(ScrollPositionState stateOut) { 374 | stateOut.rowIndex = -1; 375 | stateOut.rowTopOffset = -1; 376 | stateOut.rowHeight = -1; 377 | 378 | // Return early if there are no items 379 | int rowCount = getAdapter().getItemCount(); 380 | if (rowCount == 0) { 381 | return; 382 | } 383 | 384 | View child = getChildAt(0); 385 | if (child == null) { 386 | return; 387 | } 388 | 389 | stateOut.rowIndex = getChildPosition(child); 390 | if (getLayoutManager() instanceof GridLayoutManager) { 391 | stateOut.rowIndex = stateOut.rowIndex / ((GridLayoutManager) getLayoutManager()).getSpanCount(); 392 | } 393 | stateOut.rowTopOffset = getLayoutManager().getDecoratedTop(child) / (float) child.getHeight(); 394 | stateOut.rowHeight = calculateRowHeight(child.getHeight()); 395 | } 396 | 397 | /** 398 | * Calculates the row height based on the average of the visible children, to handle scrolling 399 | * through children with different heights gracefully 400 | */ 401 | protected int calculateRowHeight(int fallbackHeight) { 402 | LayoutManager layoutManager = getLayoutManager(); 403 | 404 | if (layoutManager instanceof LinearLayoutManager) { 405 | final int firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition(); 406 | final int lastVisiblePosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition(); 407 | 408 | if (lastVisiblePosition > firstVisiblePosition) { 409 | final int height = getHeight(); 410 | final int paddingTop = getPaddingTop(); 411 | final int paddingBottom = getPaddingBottom(); 412 | 413 | // How many rows are visible, like 10.5f for 10 rows completely and one halfway visible 414 | float visibleRows = 0f; 415 | 416 | for (int position = firstVisiblePosition; position <= lastVisiblePosition; position++) { 417 | ViewHolder viewHolder = findViewHolderForLayoutPosition(position); 418 | if (viewHolder == null || viewHolder.itemView == null) { 419 | continue; 420 | } 421 | 422 | final View itemView = viewHolder.itemView; 423 | final int itemHeight = itemView.getHeight(); 424 | if (itemHeight == 0) { 425 | continue; 426 | } 427 | 428 | // Finds how much of the itemView is actually visible. 429 | // This allows smooth changes of the scrollbar thumb height 430 | final int visibleHeight = itemHeight 431 | - Math.max(0, paddingBottom - layoutManager.getDecoratedTop(itemView)) // How much is cut at the top 432 | - Math.max(0, paddingBottom + layoutManager.getDecoratedBottom(itemView) - height); // How much is cut at the bottom 433 | 434 | visibleRows += visibleHeight / (float) itemHeight; 435 | } 436 | 437 | return Math.round((height - (paddingTop + paddingBottom)) / visibleRows); 438 | } 439 | } 440 | 441 | return fallbackHeight; 442 | } 443 | 444 | /** 445 | * Iterface to implement in your {@link RecyclerView.Adapter} to show a popup next to the scroller 446 | */ 447 | public interface SectionedAdapter { 448 | 449 | /** 450 | * @param position 451 | * the item position 452 | * @return the section name for this item 453 | */ 454 | @NonNull String getSectionName(int position); 455 | } 456 | 457 | /** 458 | * The current scroll state of the recycler view. We use this in onUpdateScrollbar() 459 | * and scrollToPositionAtProgress() to determine the scroll position of the recycler view so 460 | * that we can calculate what the scroll bar looks like, and where to jump to from the fast 461 | * scroller. 462 | */ 463 | public static class ScrollPositionState { 464 | 465 | // The index of the first visible row 466 | public int rowIndex; 467 | // The offset of the first visible row, in percentage of the height 468 | public float rowTopOffset; 469 | // The height of a given row (they are currently all the same height) 470 | public int rowHeight; 471 | } 472 | 473 | } -------------------------------------------------------------------------------- /library/src/main/java/com/jaredrummler/fastscrollrecyclerview/Utilities.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Jared Rummler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.jaredrummler.fastscrollrecyclerview; 19 | 20 | import android.content.res.Resources; 21 | import android.os.Build; 22 | import android.view.View; 23 | 24 | final class Utilities { 25 | 26 | static boolean isRtl(Resources res) { 27 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && 28 | res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /library/src/main/res/drawable-ldrtl/fastscroll_popup_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | 21 | 24 | 28 | -------------------------------------------------------------------------------- /library/src/main/res/drawable/fastscroll_popup_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | 25 | 29 | -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /library/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | #009688 22 | #009688 23 | 24 | 25 | -------------------------------------------------------------------------------- /library/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 24dp 21 | 48dp 22 | 0dp 23 | 9dp 24 | 72dp 25 | -24dp 26 | 27 | 28 | -------------------------------------------------------------------------------- /library/src/test/java/com/jaredrummler/fastscrollrecyclerview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Jared Rummler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.jaredrummler.fastscrollrecyclerview; 19 | 20 | import org.junit.Test; 21 | 22 | import static org.junit.Assert.*; 23 | 24 | /** 25 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 26 | */ 27 | public class ExampleUnitTest { 28 | 29 | @Test 30 | public void addition_isCorrect() throws Exception { 31 | assertEquals(4, 2 + 2); 32 | } 33 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Jared Rummler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | include ':demo', ':library' 19 | --------------------------------------------------------------------------------