├── recyclerviewfastscroller
├── .gitignore
├── gradle.properties
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── attrs.xml
│ │ │ ├── drawable
│ │ │ │ ├── fast_scroller_handle_rounded.xml
│ │ │ │ └── section_indicator_background_default_rounded.xml
│ │ │ └── layout
│ │ │ │ ├── section_indicator_with_title.xml
│ │ │ │ └── vertical_recycler_fast_scroller_layout.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── xyz
│ │ │ └── danoz
│ │ │ └── recyclerviewfastscroller
│ │ │ ├── calculation
│ │ │ ├── progress
│ │ │ │ ├── ScrollProgressCalculator.java
│ │ │ │ ├── TouchableScrollProgressCalculator.java
│ │ │ │ ├── VerticalScrollProgressCalculator.java
│ │ │ │ └── VerticalLinearLayoutManagerScrollProgressCalculator.java
│ │ │ ├── VerticalScrollBoundsProvider.java
│ │ │ └── position
│ │ │ │ └── VerticalScreenPositionCalculator.java
│ │ │ ├── sectionindicator
│ │ │ ├── SectionIndicator.java
│ │ │ ├── animation
│ │ │ │ └── DefaultSectionIndicatorAlphaAnimator.java
│ │ │ ├── AbsSectionIndicator.java
│ │ │ └── title
│ │ │ │ └── SectionTitleIndicator.java
│ │ │ ├── RecyclerViewScroller.java
│ │ │ ├── FastScrollerTouchListener.java
│ │ │ ├── vertical
│ │ │ └── VerticalRecyclerViewFastScroller.java
│ │ │ └── AbsRecyclerViewFastScroller.java
│ └── androidTest
│ │ └── java
│ │ └── xyz
│ │ └── danoz
│ │ └── recyclerviewfastscroller
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── gradle-maven-push.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── releases
└── recyclerviewfastscroller-0.1.0.aar
├── Application
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable-hdpi
│ │ │ └── recycler_fast_scroller_icon.png
│ │ ├── drawable-mdpi
│ │ │ └── recycler_fast_scroller_icon.png
│ │ ├── drawable-xhdpi
│ │ │ └── recycler_fast_scroller_icon.png
│ │ ├── drawable-xxhdpi
│ │ │ └── recycler_fast_scroller_icon.png
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ ├── dimens.xml
│ │ │ ├── base-strings.xml
│ │ │ ├── template-styles.xml
│ │ │ └── template-dimens.xml
│ │ ├── menu
│ │ │ └── main_options_menu.xml
│ │ ├── values-v11
│ │ │ └── template-styles.xml
│ │ ├── values-v21
│ │ │ ├── base-colors.xml
│ │ │ └── base-template-styles.xml
│ │ ├── values-sw600dp
│ │ │ ├── template-dimens.xml
│ │ │ └── template-styles.xml
│ │ └── layout
│ │ │ ├── activity_main.xml
│ │ │ ├── recycler_view_with_fast_scroller_fragment.xml
│ │ │ ├── text_row_item.xml
│ │ │ └── recycler_view_with_fast_scroller_section_title_indicator_fragment.xml
│ │ ├── java
│ │ └── xyz
│ │ │ └── danoz
│ │ │ └── recyclerviewfastscroller
│ │ │ └── sample
│ │ │ ├── data
│ │ │ ├── ColorGroupCalculator.java
│ │ │ ├── ColorData.java
│ │ │ ├── ColorDataSet.java
│ │ │ └── ColorGroup.java
│ │ │ ├── ui
│ │ │ └── example
│ │ │ │ └── ColorGroupSectionTitleIndicator.java
│ │ │ ├── fragment
│ │ │ ├── RecyclerViewWithSectionIndicatorFragment.java
│ │ │ └── RecyclerViewWithFastScrollerFragment.java
│ │ │ ├── MainActivity.java
│ │ │ └── recyclerview
│ │ │ └── ColorfulAdapter.java
│ │ └── AndroidManifest.xml
└── build.gradle
├── LICENSE
├── packaging.yaml
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/recyclerviewfastscroller/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':recyclerviewfastscroller'
2 | include 'Application'
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danoz73/RecyclerViewFastScroller/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/recyclerviewfastscroller/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=RecyclerViewFastScroller
2 | POM_ARTIFACT_ID=recyclerviewfastscroller
3 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RecyclerViewFastScroller
3 |
4 |
--------------------------------------------------------------------------------
/releases/recyclerviewfastscroller-0.1.0.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danoz73/RecyclerViewFastScroller/HEAD/releases/recyclerviewfastscroller-0.1.0.aar
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/Application/src/main/res/drawable-hdpi/recycler_fast_scroller_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danoz73/RecyclerViewFastScroller/HEAD/Application/src/main/res/drawable-hdpi/recycler_fast_scroller_icon.png
--------------------------------------------------------------------------------
/Application/src/main/res/drawable-mdpi/recycler_fast_scroller_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danoz73/RecyclerViewFastScroller/HEAD/Application/src/main/res/drawable-mdpi/recycler_fast_scroller_icon.png
--------------------------------------------------------------------------------
/Application/src/main/res/drawable-xhdpi/recycler_fast_scroller_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danoz73/RecyclerViewFastScroller/HEAD/Application/src/main/res/drawable-xhdpi/recycler_fast_scroller_icon.png
--------------------------------------------------------------------------------
/Application/src/main/res/drawable-xxhdpi/recycler_fast_scroller_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danoz73/RecyclerViewFastScroller/HEAD/Application/src/main/res/drawable-xxhdpi/recycler_fast_scroller_icon.png
--------------------------------------------------------------------------------
/Application/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFF
4 | #ffcecece
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 08 13:53:18 PDT 2014
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.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/Application/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Element
4 | Simple List
5 | List With Section Indicator
6 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/res/drawable/fast_scroller_handle_rounded.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4dp
4 | 8dp
5 | 16dp
6 | 32dp
7 | 64dp
8 |
9 | 72dp
10 |
--------------------------------------------------------------------------------
/Application/src/main/res/menu/main_options_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/androidTest/java/xyz/danoz/recyclerviewfastscroller/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/res/drawable/section_indicator_background_default_rounded.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 |
15 |
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2015 Daniel Smith
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
--------------------------------------------------------------------------------
/packaging.yaml:
--------------------------------------------------------------------------------
1 | # GOOGLE SAMPLE PACKAGING DATA
2 | #
3 | # This file is used by Google as part of our samples packaging process.
4 | # End users may safely ignore this file. It has no relevance to other systems.
5 | ---
6 | status: PUBLISHED
7 | technologies: [Android]
8 | categories: [UI]
9 | languages: [Java]
10 | solutions: [Mobile]
11 | github: googlesamples/android-RecyclerView
12 | level: INTERMEDIATE
13 | icon: RecyclerViewSample/src/main/res/drawable-xxhdpi/ic_launcher.png
14 | doc_refs:
15 | - android:preview/material/ui-widgets.html
16 | license: apache2
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 | utils/build_scripts/credentials/
5 |
6 | # files for the dex VM
7 | *.dex
8 |
9 | # Java class files
10 | *.class
11 |
12 | # generated files
13 | bin/
14 | gen/
15 | .settings/
16 | .idea/
17 | .gradle/
18 | build/
19 | caches/
20 | utils/logs/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | #.DS_Store files
26 | *.DS_Store
27 |
28 | graphics/
29 | resources/
30 | traces/
31 |
32 | *$*
33 | *.iml
34 | *.eml
35 | *.ipr
36 | *.iws
37 | out
38 | .classpath
39 | .project
40 | *.pyc
41 | classnames.txt
42 |
43 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=0.1.3
2 | VERSION_CODE=3
3 | GROUP_ID=xyz.danoz
4 |
5 | POM_DESCRIPTION=FastScroller for the Android RecyclerView widget
6 | POM_URL=https://github.com/danoz73/RecyclerViewFastScroller
7 | POM_SCM_URL=https://github.com/danoz73/RecyclerViewFastScroller
8 | POM_SCM_CONNECTION=scm:git@github.com:danoz73/RecyclerViewFastScroller.git
9 | POM_SCM_DEV_CONNECTION=scm:git@github.com:danoz73/RecyclerViewFastScroller.git
10 | POM_LICENSE_NAME=The Apache Software License, Version 2.0
11 | POM_LICENSE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
12 | POM_LICENSE_DIST=repo
13 | POM_DEVELOPER_ID=danoz73
14 | POM_DEVELOPER_NAME=Daniel Smith
--------------------------------------------------------------------------------
/Application/src/main/java/xyz/danoz/recyclerviewfastscroller/sample/data/ColorGroupCalculator.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.sample.data;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | /**
6 | * Allow for finding a color group based on a hue
7 | */
8 | class ColorGroupCalculator {
9 |
10 | @NonNull
11 | public ColorGroup getColorGroup(float hue) {
12 | for (ColorGroup group : ColorGroup.values()) {
13 | if (group.containsHue((int) hue)) {
14 | return group;
15 | }
16 | }
17 |
18 | throw new NullPointerException("Could not classify hue into Color Group!");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/calculation/progress/ScrollProgressCalculator.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.calculation.progress;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 |
5 | /**
6 | * Assists in calculating the amount of scroll progress for a {@link RecyclerView}
7 | */
8 | public interface ScrollProgressCalculator {
9 |
10 | /**
11 | * Calculates the scroll progress of a provided RecyclerView
12 | * @param recyclerView for which to calculate scroll progress
13 | * @return fraction from [0 to 1] representing the scroll progress
14 | */
15 | public float calculateScrollProgress(RecyclerView recyclerView);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/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 /Users/D/Downloads/android-sdk-macosx/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 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/calculation/VerticalScrollBoundsProvider.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.calculation;
2 |
3 | /**
4 | * {@link Please describe ScrollBoundsProvider!}
5 | */
6 | public class VerticalScrollBoundsProvider {
7 |
8 | private final float mMinimumScrollY;
9 | private final float mMaximumScrollY;
10 |
11 | public VerticalScrollBoundsProvider(float minimumScrollY, float maximumScrollY) {
12 | mMinimumScrollY = minimumScrollY;
13 | mMaximumScrollY = maximumScrollY;
14 | }
15 |
16 | public float getMinimumScrollY() {
17 | return mMinimumScrollY;
18 | }
19 |
20 | public float getMaximumScrollY() {
21 | return mMaximumScrollY;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Application/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | 72dp
20 |
--------------------------------------------------------------------------------
/Application/src/main/res/values/base-strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | RecyclerViewFastScroller
19 |
20 |
--------------------------------------------------------------------------------
/Application/src/main/java/xyz/danoz/recyclerviewfastscroller/sample/data/ColorData.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.sample.data;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | /**
6 | * Data object representing a color
7 | */
8 | public class ColorData {
9 |
10 | private final int mColorInt;
11 | private final ColorGroup mColorGroup;
12 |
13 | public ColorData(int colorInt, @NonNull ColorGroup colorGroup) {
14 | mColorInt = colorInt;
15 | mColorGroup = colorGroup;
16 | }
17 |
18 | public int getIntValue() {
19 | return mColorInt;
20 | }
21 |
22 | public ColorGroup getColorGroup() {
23 | return mColorGroup;
24 | }
25 |
26 | @Override
27 | public String toString() {
28 | return String.format("#%06X", (0xFFFFFF & mColorInt));
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Application/src/main/res/values-v11/template-styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/calculation/progress/TouchableScrollProgressCalculator.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.calculation.progress;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.MotionEvent;
5 |
6 |
7 | /**
8 | * Assists in calculating the amount of scroll progress for a {@link RecyclerView} based on a {@link MotionEvent}
9 | */
10 | public interface TouchableScrollProgressCalculator extends ScrollProgressCalculator {
11 |
12 | /**
13 | * Calculates the scroll progress of a RecyclerView based on a motion event from a scroller
14 | * @param event for which to calculate scroll progress
15 | * @return fraction from [0 to 1] representing the scroll progress
16 | */
17 | public float calculateScrollProgress(MotionEvent event);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/Application/src/main/res/values-v21/base-colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #FFF
20 | #ffcecece
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Application/src/main/res/values-sw600dp/template-dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 | @dimen/margin_huge
22 | @dimen/margin_medium
23 |
24 |
25 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/res/layout/section_indicator_with_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/res/layout/vertical_recycler_fast_scroller_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
26 |
27 |
--------------------------------------------------------------------------------
/Application/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion as Integer
5 | buildToolsVersion rootProject.ext.buildToolsVersion as String
6 |
7 | defaultConfig {
8 | applicationId "xyz.danoz.recyclerviewfastscroller.sample"
9 | minSdkVersion rootProject.ext.minSdkVersion as Integer
10 | targetSdkVersion rootProject.ext.targetSdkVersion as Integer
11 | versionCode rootProject.ext.versionCode as Integer
12 | versionName rootProject.ext.versionName as String
13 | }
14 |
15 | compileOptions {
16 | sourceCompatibility JavaVersion.VERSION_1_7
17 | targetCompatibility JavaVersion.VERSION_1_7
18 | }
19 |
20 | lintOptions {
21 | abortOnError false
22 | }
23 | }
24 |
25 | dependencies {
26 | compile "com.android.support:support-v4:22.0.0"
27 | compile "com.android.support:recyclerview-v7:21.0.2"
28 | compile project(':recyclerviewfastscroller')
29 | }
--------------------------------------------------------------------------------
/Application/src/main/res/values-sw600dp/template-styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Application/src/main/res/values/template-styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Application/src/main/res/values-v21/base-template-styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/calculation/position/VerticalScreenPositionCalculator.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.calculation.position;
2 |
3 | import xyz.danoz.recyclerviewfastscroller.calculation.VerticalScrollBoundsProvider;
4 |
5 | /**
6 | * Calculates the correct vertical Y position for a view based on scroll progress and given bounds
7 | */
8 | public class VerticalScreenPositionCalculator {
9 |
10 | private final VerticalScrollBoundsProvider mVerticalScrollBoundsProvider;
11 |
12 | public VerticalScreenPositionCalculator(VerticalScrollBoundsProvider scrollBoundsProvider) {
13 | mVerticalScrollBoundsProvider = scrollBoundsProvider;
14 | }
15 |
16 | public float getYPositionFromScrollProgress(float scrollProgress) {
17 | return Math.max(
18 | mVerticalScrollBoundsProvider.getMinimumScrollY(),
19 | Math.min(
20 | scrollProgress * mVerticalScrollBoundsProvider.getMaximumScrollY(),
21 | mVerticalScrollBoundsProvider.getMaximumScrollY()
22 | )
23 | );
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/sectionindicator/SectionIndicator.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.sectionindicator;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.widget.SectionIndexer;
5 |
6 | /**
7 | * An indicator for which section a {@link RecyclerView} is currently in. This is for RecyclerViews whose adapters
8 | * implement the {@link SectionIndexer} interface.
9 | */
10 | public interface SectionIndicator {
11 |
12 | /**
13 | * Sets the progress of the indicator
14 | * @param progress fraction from [0 to 1] representing progress scrolled through a RecyclerView
15 | */
16 | public void setProgress(float progress);
17 |
18 | /**
19 | * Allows the setting of section types in the indicator. The indicator should appropriately handle the section type
20 | * @param section the current section to which the list is scrolled
21 | */
22 | public void setSection(T section);
23 |
24 | /**
25 | * Method for animating the alpha of the indicator
26 | * @param targetAlpha alpha to animate towards
27 | */
28 | public void animateAlpha(float targetAlpha);
29 | }
30 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/sectionindicator/animation/DefaultSectionIndicatorAlphaAnimator.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.sectionindicator.animation;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.view.View;
5 |
6 | /**
7 | * Utility class for animating the popup section indicator
8 | */
9 | public class DefaultSectionIndicatorAlphaAnimator {
10 |
11 | private static final int ANIMATION_DURATION = 500;
12 |
13 | private final View mSectionIndicatorView;
14 | private float mTargetAlpha = 0;
15 |
16 | public DefaultSectionIndicatorAlphaAnimator(View sectionIndicatorView) {
17 | mSectionIndicatorView = sectionIndicatorView;
18 | mSectionIndicatorView.setAlpha(0);
19 | }
20 |
21 | public void animateTo(float target){
22 | if (target == mTargetAlpha) {
23 | return;
24 | }
25 |
26 | ObjectAnimator alphaAnimator =
27 | ObjectAnimator.ofFloat(mSectionIndicatorView, "alpha", mTargetAlpha, target);
28 | alphaAnimator.setDuration(ANIMATION_DURATION);
29 | alphaAnimator.start();
30 | mTargetAlpha = target;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Application/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
16 |
22 |
23 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Application/src/main/res/layout/recycler_view_with_fast_scroller_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/calculation/progress/VerticalScrollProgressCalculator.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.calculation.progress;
2 |
3 | import android.view.MotionEvent;
4 |
5 | import xyz.danoz.recyclerviewfastscroller.calculation.VerticalScrollBoundsProvider;
6 |
7 | /**
8 | * Basic scroll progress calculator used to calculate vertical scroll progress from a touch event
9 | */
10 | public abstract class VerticalScrollProgressCalculator implements TouchableScrollProgressCalculator {
11 |
12 | private final VerticalScrollBoundsProvider mScrollBoundsProvider;
13 |
14 | public VerticalScrollProgressCalculator(VerticalScrollBoundsProvider scrollBoundsProvider) {
15 | mScrollBoundsProvider = scrollBoundsProvider;
16 | }
17 |
18 | @Override
19 | public float calculateScrollProgress(MotionEvent event) {
20 | float y = event.getY();
21 |
22 | if (y <= mScrollBoundsProvider.getMinimumScrollY()) {
23 | return 0;
24 | } else if (y >= mScrollBoundsProvider.getMaximumScrollY()) {
25 | return 1;
26 | } else {
27 | return y / mScrollBoundsProvider.getMaximumScrollY();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Application/src/main/res/values/template-dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 | 4dp
22 | 8dp
23 | 16dp
24 | 32dp
25 | 64dp
26 |
27 |
28 |
29 | @dimen/margin_medium
30 | @dimen/margin_medium
31 |
32 |
33 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion as Integer
5 | buildToolsVersion rootProject.ext.buildToolsVersion as String
6 |
7 | defaultConfig {
8 | minSdkVersion rootProject.ext.minSdkVersion as Integer
9 | targetSdkVersion rootProject.ext.targetSdkVersion as Integer
10 | versionCode rootProject.ext.versionCode as Integer
11 | versionName rootProject.ext.versionName as String
12 | }
13 |
14 | compileOptions {
15 | sourceCompatibility JavaVersion.VERSION_1_7
16 | targetCompatibility JavaVersion.VERSION_1_7
17 | }
18 |
19 | lintOptions {
20 | abortOnError false
21 | }
22 | }
23 |
24 | dependencies {
25 | compile "com.android.support:support-v4:22.1.0"
26 | compile "com.android.support:recyclerview-v7:22.1.0"
27 | }
28 |
29 | def uploadScriptPropertyName = "recyclerviewfastscroller.uploadScript"
30 |
31 | if (project.hasProperty(uploadScriptPropertyName)
32 | && new File((String) project.property(uploadScriptPropertyName)).exists()) {
33 |
34 | apply from: project.property(uploadScriptPropertyName)
35 |
36 | afterEvaluate {
37 | androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Application/src/main/java/xyz/danoz/recyclerviewfastscroller/sample/data/ColorDataSet.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.sample.data;
2 |
3 | import android.graphics.Color;
4 |
5 | /**
6 | * Dummy dataset of N {@link ColorData} objects
7 | */
8 | public class ColorDataSet {
9 |
10 | private static final int DATA_SET_SIZE = 100;
11 | private static final float NUM_HUES = 359;
12 | private static final ColorData[] mColors = new ColorData[DATA_SET_SIZE];
13 |
14 | public ColorDataSet() {
15 | this(new ColorGroupCalculator());
16 | }
17 |
18 | private ColorDataSet(ColorGroupCalculator colorGroupCalculator) {
19 | for (int i = 0; i < mColors.length; i++) {
20 | mColors[i] = generateNewColor(i, mColors.length, colorGroupCalculator);
21 | }
22 | }
23 |
24 | private ColorData generateNewColor(int position, int numColors, ColorGroupCalculator colorGroupCalculator) {
25 | float positionBasedHue = position * (NUM_HUES / numColors);
26 | int color = Color.HSVToColor(new float[] {positionBasedHue, 1, 1});
27 | return new ColorData(color, colorGroupCalculator.getColorGroup(positionBasedHue));
28 | }
29 |
30 | public int getSize() {
31 | return mColors.length;
32 | }
33 |
34 | public ColorData get(int position) {
35 | return mColors[position];
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/Application/src/main/java/xyz/danoz/recyclerviewfastscroller/sample/ui/example/ColorGroupSectionTitleIndicator.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.sample.ui.example;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import xyz.danoz.recyclerviewfastscroller.sample.data.ColorGroup;
7 | import xyz.danoz.recyclerviewfastscroller.sectionindicator.title.SectionTitleIndicator;
8 |
9 | /**
10 | * Indicator for sections of type {@link ColorGroup}
11 | */
12 | public class ColorGroupSectionTitleIndicator extends SectionTitleIndicator {
13 |
14 | public ColorGroupSectionTitleIndicator(Context context) {
15 | super(context);
16 | }
17 |
18 | public ColorGroupSectionTitleIndicator(Context context, AttributeSet attrs) {
19 | super(context, attrs);
20 | }
21 |
22 | public ColorGroupSectionTitleIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
23 | super(context, attrs, defStyleAttr);
24 | }
25 |
26 | @Override
27 | public void setSection(ColorGroup colorGroup) {
28 | // Example of using a single character
29 | setTitleText(colorGroup.getName().charAt(0) + "");
30 |
31 | // Example of using a longer string
32 | // setTitleText(colorGroup.getName());
33 |
34 | setIndicatorTextColor(colorGroup.getAsColor());
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/Application/src/main/java/xyz/danoz/recyclerviewfastscroller/sample/data/ColorGroup.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.sample.data;
2 |
3 | import android.graphics.Color;
4 |
5 | /**
6 | * Coarse groupings of colors by hue
7 | */
8 | public enum ColorGroup {
9 | RED_UPPER (345, 360, "Red"),
10 | PINK (300, RED_UPPER.mMinimumHue, "Pink"),
11 | PURPLE (260, PINK.mMinimumHue, "Purple"),
12 | BLUE (175, PURPLE.mMinimumHue, "Blue"),
13 | GREEN (70, BLUE.mMinimumHue, "Green"),
14 | YELLOW (50, GREEN.mMinimumHue, "Yellow"),
15 | ORANGE (25, YELLOW.mMinimumHue, "Orange"),
16 | RED_LOWER (0, ORANGE.mMinimumHue, "Red"),
17 | ;
18 |
19 | private final int mMinimumHue, mMaximumHue;
20 | private final int mIntegerRepresentation;
21 | private final String mName;
22 |
23 | ColorGroup(int minimumHue, int maximumHue, String groupName) {
24 | mMinimumHue = minimumHue;
25 | mMaximumHue = maximumHue;
26 | mName = groupName;
27 | mIntegerRepresentation = Color.HSVToColor(new float[] { (maximumHue + minimumHue) / 2, 1, 1});
28 | }
29 |
30 | public String getName() {
31 | return mName;
32 | }
33 |
34 | public boolean containsHue(int hue) {
35 | return (hue >= mMinimumHue && hue < mMaximumHue);
36 | }
37 |
38 | public int getAsColor() {
39 | return mIntegerRepresentation;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Application/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
22 |
23 |
24 |
25 |
29 |
30 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/RecyclerViewScroller.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.support.v7.widget.RecyclerView.OnScrollListener;
5 |
6 | /**
7 | * To be implemented by any object that scrolls a {@link RecyclerView}
8 | */
9 | public interface RecyclerViewScroller {
10 |
11 | /**
12 | * What good is a RecyclerViewScroller without a {@link RecyclerView}?!
13 | * @param recyclerView to scroll using the scroller
14 | */
15 | public void setRecyclerView(RecyclerView recyclerView);
16 |
17 | /**
18 | * Since {@link OnScrollListener} is not implemented as an interface, RecyclerViewScrollers cannot implement this
19 | * interface, and in most cases, it makes no sense for them to extend a scroll listener. For this reason, we must
20 | * provide a listener that is intended to be fetched and set as a listener on a {@link RecyclerView}.
21 | *
22 | * This assumes that a scroller should to know when RecyclerViews are scrolled independently of scroller actions.
23 | *
24 | * @return this scroller's listener for a RecyclerView's scrolling.
25 | */
26 | public OnScrollListener getOnScrollListener();
27 |
28 | /**
29 | * Indicate to the scroller that it should scroll to a certain amount of scroll progress
30 | * @param scrollProgress the progress of the scroll expressed as a fraction from [0, 1]
31 | * @param fromTouch true if this scroll request was triggered by a touch
32 | */
33 | public void scrollTo(float scrollProgress, boolean fromTouch);
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/Application/src/main/res/layout/text_row_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
24 |
25 |
37 |
38 |
42 |
43 |
--------------------------------------------------------------------------------
/Application/src/main/res/layout/recycler_view_with_fast_scroller_section_title_indicator_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
27 |
28 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/FastScrollerTouchListener.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller;
2 |
3 | import xyz.danoz.recyclerviewfastscroller.sectionindicator.SectionIndicator;
4 |
5 | import android.support.annotation.Nullable;
6 | import android.view.MotionEvent;
7 | import android.view.View;
8 | import android.view.View.OnTouchListener;
9 |
10 | /**
11 | * Touch listener that will move a {@link AbsRecyclerViewFastScroller}'s handle to a specified offset along the scroll bar
12 | */
13 | class FastScrollerTouchListener implements OnTouchListener {
14 |
15 | private final AbsRecyclerViewFastScroller mFastScroller;
16 |
17 | /**
18 | * @param fastScroller {@link xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller} for this listener to scroll
19 | */
20 | public FastScrollerTouchListener(AbsRecyclerViewFastScroller fastScroller) {
21 | mFastScroller = fastScroller;
22 | }
23 |
24 | @Override
25 | public boolean onTouch(View v, MotionEvent event) {
26 | SectionIndicator sectionIndicator = mFastScroller.getSectionIndicator();
27 | showOrHideIndicator(sectionIndicator, event);
28 |
29 | float scrollProgress = mFastScroller.getScrollProgress(event);
30 | mFastScroller.scrollTo(scrollProgress, true);
31 | mFastScroller.moveHandleToPosition(scrollProgress);
32 | return true;
33 | }
34 |
35 | private void showOrHideIndicator(@Nullable SectionIndicator sectionIndicator, MotionEvent event) {
36 | if (sectionIndicator == null) {
37 | return;
38 | }
39 |
40 | switch (event.getActionMasked()) {
41 | case MotionEvent.ACTION_DOWN:
42 | sectionIndicator.animateAlpha(1f);
43 | return;
44 | case MotionEvent.ACTION_UP:
45 | sectionIndicator.animateAlpha(0f);
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/calculation/progress/VerticalLinearLayoutManagerScrollProgressCalculator.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.calculation.progress;
2 |
3 | import xyz.danoz.recyclerviewfastscroller.calculation.VerticalScrollBoundsProvider;
4 |
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.support.v7.widget.RecyclerView.ViewHolder;
8 | import android.view.View;
9 |
10 | /**
11 | * Calculates scroll progress for a {@link RecyclerView} with a {@link LinearLayoutManager}
12 | */
13 | public class VerticalLinearLayoutManagerScrollProgressCalculator extends VerticalScrollProgressCalculator {
14 |
15 | public VerticalLinearLayoutManagerScrollProgressCalculator(VerticalScrollBoundsProvider scrollBoundsProvider) {
16 | super(scrollBoundsProvider);
17 | }
18 |
19 | /**
20 | * @param recyclerView recycler that experiences a scroll event
21 | * @return the progress through the recycler view list content
22 | */
23 | @Override
24 | public float calculateScrollProgress(RecyclerView recyclerView) {
25 | LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
26 | int lastFullyVisiblePosition = layoutManager.findLastCompletelyVisibleItemPosition();
27 |
28 | View visibleChild = recyclerView.getChildAt(0);
29 | if (visibleChild == null) {
30 | return 0;
31 | }
32 | ViewHolder holder = recyclerView.getChildViewHolder(visibleChild);
33 | int itemHeight = holder.itemView.getHeight();
34 | int recyclerHeight = recyclerView.getHeight();
35 | int itemsInWindow = recyclerHeight / itemHeight;
36 |
37 | int numItemsInList = recyclerView.getAdapter().getItemCount();
38 | int numScrollableSectionsInList = numItemsInList - itemsInWindow;
39 | int indexOfLastFullyVisibleItemInFirstSection = numItemsInList - numScrollableSectionsInList - 1;
40 |
41 | int currentSection = lastFullyVisiblePosition - indexOfLastFullyVisibleItemInFirstSection;
42 |
43 | return (float) currentSection / numScrollableSectionsInList;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/vertical/VerticalRecyclerViewFastScroller.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.vertical;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.util.AttributeSet;
8 |
9 | import xyz.danoz.recyclerviewfastscroller.AbsRecyclerViewFastScroller;
10 | import xyz.danoz.recyclerviewfastscroller.R;
11 | import xyz.danoz.recyclerviewfastscroller.RecyclerViewScroller;
12 | import xyz.danoz.recyclerviewfastscroller.calculation.VerticalScrollBoundsProvider;
13 | import xyz.danoz.recyclerviewfastscroller.calculation.position.VerticalScreenPositionCalculator;
14 | import xyz.danoz.recyclerviewfastscroller.calculation.progress.TouchableScrollProgressCalculator;
15 | import xyz.danoz.recyclerviewfastscroller.calculation.progress.VerticalLinearLayoutManagerScrollProgressCalculator;
16 | import xyz.danoz.recyclerviewfastscroller.calculation.progress.VerticalScrollProgressCalculator;
17 |
18 | /**
19 | * Widget used to fast-scroll a vertical {@link RecyclerView}.
20 | * Currently assumes the use of a {@link LinearLayoutManager}
21 | */
22 | public class VerticalRecyclerViewFastScroller extends AbsRecyclerViewFastScroller implements RecyclerViewScroller {
23 |
24 | @Nullable private VerticalScrollProgressCalculator mScrollProgressCalculator;
25 | @Nullable private VerticalScreenPositionCalculator mScreenPositionCalculator;
26 |
27 | public VerticalRecyclerViewFastScroller(Context context) {
28 | this(context, null);
29 | }
30 |
31 | public VerticalRecyclerViewFastScroller(Context context, AttributeSet attrs) {
32 | this(context, attrs, 0);
33 | }
34 |
35 | public VerticalRecyclerViewFastScroller(Context context, AttributeSet attrs, int defStyleAttr) {
36 | super(context, attrs, defStyleAttr);
37 | }
38 |
39 | @Override
40 | protected int getLayoutResourceId() {
41 | return R.layout.vertical_recycler_fast_scroller_layout;
42 | }
43 |
44 | @Override
45 | @Nullable
46 | protected TouchableScrollProgressCalculator getScrollProgressCalculator() {
47 | return mScrollProgressCalculator;
48 | }
49 |
50 | @Override
51 | public void moveHandleToPosition(float scrollProgress) {
52 | if (mScreenPositionCalculator == null) {
53 | return;
54 | }
55 | mHandle.setY(mScreenPositionCalculator.getYPositionFromScrollProgress(scrollProgress));
56 | }
57 |
58 | protected void onCreateScrollProgressCalculator() {
59 | VerticalScrollBoundsProvider boundsProvider =
60 | new VerticalScrollBoundsProvider(mBar.getY(), mBar.getY() + mBar.getHeight() - mHandle.getHeight());
61 | mScrollProgressCalculator = new VerticalLinearLayoutManagerScrollProgressCalculator(boundsProvider);
62 | mScreenPositionCalculator = new VerticalScreenPositionCalculator(boundsProvider);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Application/src/main/java/xyz/danoz/recyclerviewfastscroller/sample/fragment/RecyclerViewWithSectionIndicatorFragment.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.sample.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import xyz.danoz.recyclerview.sample.R;
12 | import xyz.danoz.recyclerviewfastscroller.sample.data.ColorDataSet;
13 | import xyz.danoz.recyclerviewfastscroller.sample.recyclerview.ColorfulAdapter;
14 | import xyz.danoz.recyclerviewfastscroller.sectionindicator.title.SectionTitleIndicator;
15 | import xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller;
16 |
17 | /**
18 | * Adapted from sample code that demonstrates the use of {@link RecyclerView} with a {@link LinearLayoutManager}
19 | */
20 | public class RecyclerViewWithSectionIndicatorFragment extends Fragment {
21 |
22 | @Override
23 | public void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | }
26 |
27 | @Override
28 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
29 | Bundle savedInstanceState) {
30 | ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.recycler_view_with_fast_scroller_section_title_indicator_fragment, container, false);
31 |
32 | // Grab your RecyclerView, RecyclerViewFastScroller, and SectionTitleIndicator from the layout
33 | RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
34 | VerticalRecyclerViewFastScroller fastScroller =
35 | (VerticalRecyclerViewFastScroller) rootView.findViewById(R.id.fast_scroller);
36 | SectionTitleIndicator sectionTitleIndicator =
37 | (SectionTitleIndicator) rootView.findViewById(R.id.fast_scroller_section_title_indicator);
38 |
39 | RecyclerView.Adapter adapter = new ColorfulAdapter(new ColorDataSet());
40 | recyclerView.setAdapter(adapter);
41 |
42 | // Connect the recycler to the scroller (to let the scroller scroll the list)
43 | fastScroller.setRecyclerView(recyclerView);
44 |
45 | // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
46 | recyclerView.setOnScrollListener(fastScroller.getOnScrollListener());
47 |
48 | // Connect the section indicator to the scroller
49 | fastScroller.setSectionIndicator(sectionTitleIndicator);
50 |
51 | setRecyclerViewLayoutManager(recyclerView);
52 |
53 | return rootView;
54 | }
55 |
56 | /**
57 | * Set RecyclerView's LayoutManager
58 | */
59 | public void setRecyclerViewLayoutManager(RecyclerView recyclerView) {
60 | int scrollPosition = 0;
61 |
62 | // If a layout manager has already been set, get current scroll position.
63 | if (recyclerView.getLayoutManager() != null) {
64 | scrollPosition =
65 | ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
66 | }
67 |
68 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
69 |
70 | recyclerView.setLayoutManager(linearLayoutManager);
71 | recyclerView.scrollToPosition(scrollPosition);
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/Application/src/main/java/xyz/danoz/recyclerviewfastscroller/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 The Android Open Source Project
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 | package xyz.danoz.recyclerviewfastscroller.sample;
18 |
19 | import android.os.Bundle;
20 | import android.support.v4.app.Fragment;
21 | import android.support.v4.app.FragmentActivity;
22 | import android.support.v4.app.FragmentTransaction;
23 | import android.view.Menu;
24 | import android.view.MenuInflater;
25 | import android.view.MenuItem;
26 |
27 | import xyz.danoz.recyclerview.sample.R;
28 | import xyz.danoz.recyclerviewfastscroller.sample.fragment.RecyclerViewWithFastScrollerFragment;
29 | import xyz.danoz.recyclerviewfastscroller.sample.fragment.RecyclerViewWithSectionIndicatorFragment;
30 | import xyz.danoz.recyclerviewfastscroller.sectionindicator.title.SectionTitleIndicator;
31 | import xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller;
32 |
33 | /**
34 | * Simple activity for displaying an example of the {@link VerticalRecyclerViewFastScroller} as well as
35 | * {@link SectionTitleIndicator} usage paired with the fast scroller
36 | */
37 | public class MainActivity extends FragmentActivity {
38 |
39 | @Override
40 | protected void onCreate(Bundle savedInstanceState) {
41 | super.onCreate(savedInstanceState);
42 | setContentView(R.layout.activity_main);
43 |
44 | if (savedInstanceState == null) {
45 | RecyclerViewWithFastScrollerFragment fragment = new RecyclerViewWithFastScrollerFragment();
46 | replaceCurrentFragment(fragment);
47 | }
48 | }
49 |
50 | private void replaceCurrentFragment(Fragment newFragment) {
51 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
52 | transaction.replace(R.id.sample_content_fragment, newFragment);
53 | transaction.commit();
54 | }
55 |
56 | @Override
57 | public boolean onCreateOptionsMenu(Menu menu) {
58 | MenuInflater inflater = getMenuInflater();
59 | inflater.inflate(R.menu.main_options_menu, menu);
60 | return true;
61 | }
62 |
63 | @Override
64 | public boolean onOptionsItemSelected(MenuItem item) {
65 | // Handle item selection
66 | switch (item.getItemId()) {
67 | case R.id.menu_item_list_no_section_indicator:
68 | RecyclerViewWithFastScrollerFragment simpleFastScrollerFragment = new RecyclerViewWithFastScrollerFragment();
69 | replaceCurrentFragment(simpleFastScrollerFragment);
70 | return true;
71 | case R.id.menu_item_list_with_sections:
72 | RecyclerViewWithSectionIndicatorFragment sectionsFragment = new RecyclerViewWithSectionIndicatorFragment();
73 | replaceCurrentFragment(sectionsFragment);
74 | return true;
75 | default:
76 | return super.onOptionsItemSelected(item);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/Application/src/main/java/xyz/danoz/recyclerviewfastscroller/sample/fragment/RecyclerViewWithFastScrollerFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
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 | package xyz.danoz.recyclerviewfastscroller.sample.fragment;
18 |
19 | import android.os.Bundle;
20 | import android.support.v4.app.Fragment;
21 | import android.support.v7.widget.LinearLayoutManager;
22 | import android.support.v7.widget.RecyclerView;
23 | import android.view.LayoutInflater;
24 | import android.view.View;
25 | import android.view.ViewGroup;
26 |
27 | import xyz.danoz.recyclerview.sample.R;
28 | import xyz.danoz.recyclerviewfastscroller.sample.data.ColorDataSet;
29 | import xyz.danoz.recyclerviewfastscroller.sample.recyclerview.ColorfulAdapter;
30 | import xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller;
31 |
32 | /**
33 | * Adapted from sample code that demonstrates the use of {@link RecyclerView} with a {@link LinearLayoutManager}
34 | */
35 | public class RecyclerViewWithFastScrollerFragment extends Fragment {
36 |
37 | @Override
38 | public void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | }
41 |
42 | @Override
43 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
44 | Bundle savedInstanceState) {
45 | View rootView = inflater.inflate(R.layout.recycler_view_with_fast_scroller_fragment, container, false);
46 |
47 | // Grab the RecyclerView and the RecyclerViewFastScroller from the layout
48 | RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
49 | VerticalRecyclerViewFastScroller fastScroller = (VerticalRecyclerViewFastScroller) rootView.findViewById(R.id.fast_scroller);
50 |
51 | // Connect the recycler to the scroller (to let the scroller scroll the list)
52 | fastScroller.setRecyclerView(recyclerView);
53 |
54 | // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
55 | recyclerView.setOnScrollListener(fastScroller.getOnScrollListener());
56 |
57 | setRecyclerViewLayoutManager(recyclerView);
58 |
59 | RecyclerView.Adapter adapter = new ColorfulAdapter(new ColorDataSet());
60 | recyclerView.setAdapter(adapter);
61 |
62 | return rootView;
63 | }
64 |
65 | /**
66 | * Set RecyclerView's LayoutManager
67 | */
68 | public void setRecyclerViewLayoutManager(RecyclerView recyclerView) {
69 | int scrollPosition = 0;
70 |
71 | // If a layout manager has already been set, get current scroll position.
72 | if (recyclerView.getLayoutManager() != null) {
73 | scrollPosition =
74 | ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
75 | }
76 |
77 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
78 |
79 | recyclerView.setLayoutManager(linearLayoutManager);
80 | recyclerView.scrollToPosition(scrollPosition);
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/gradle-maven-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 | apply plugin: 'maven'
18 | apply plugin: 'signing'
19 |
20 | def isReleaseBuild() {
21 | return VERSION_NAME.contains("SNAPSHOT") == false
22 | }
23 |
24 | def getReleaseRepositoryUrl() {
25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
27 | }
28 |
29 | def getSnapshotRepositoryUrl() {
30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
31 | : "https://oss.sonatype.org/content/repositories/snapshots/"
32 | }
33 |
34 | afterEvaluate { project ->
35 | uploadArchives {
36 | repositories {
37 | mavenDeployer {
38 | beforeDeployment {
39 | MavenDeployment deployment -> signing.signPom(deployment)
40 | }
41 |
42 | pom.groupId = GROUP_ID
43 | pom.artifactId = POM_ARTIFACT_ID
44 | pom.version = VERSION_NAME
45 |
46 | repository(url: getReleaseRepositoryUrl()) {
47 | authentication(userName: OSSRH_USERNAME, password: OSSRH_PASSWORD)
48 | }
49 |
50 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
51 | authentication(userName: OSSRH_USERNAME, password: OSSRH_PASSWORD)
52 | }
53 |
54 | pom.project {
55 | name POM_NAME
56 | packaging POM_PACKAGING
57 | description POM_DESCRIPTION
58 | url POM_URL
59 |
60 | scm {
61 | url POM_SCM_URL
62 | connection POM_SCM_CONNECTION
63 | developerConnection POM_SCM_DEV_CONNECTION
64 | }
65 |
66 | licenses {
67 | license {
68 | name POM_LICENSE_NAME
69 | url POM_LICENSE_URL
70 | distribution POM_LICENSE_DIST
71 | }
72 | }
73 |
74 | developers {
75 | developer {
76 | id POM_DEVELOPER_ID
77 | name POM_DEVELOPER_NAME
78 | }
79 | }
80 | }
81 | }
82 | }
83 | }
84 |
85 | signing {
86 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
87 | sign configurations.archives
88 | }
89 |
90 | task androidJavadocs(type: Javadoc) {
91 | source = android.sourceSets.main.java.srcDirs
92 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
93 | }
94 |
95 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
96 | classifier = 'javadoc'
97 | from androidJavadocs.destinationDir
98 | }
99 |
100 | task androidSourcesJar(type: Jar) {
101 | classifier = 'sources'
102 | from android.sourceSets.main.java.sourceFiles
103 | }
104 |
105 | artifacts {
106 | archives androidSourcesJar
107 | archives androidJavadocsJar
108 | }
109 | }
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/sectionindicator/AbsSectionIndicator.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.sectionindicator;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.util.AttributeSet;
6 | import android.view.LayoutInflater;
7 | import android.view.ViewGroup;
8 | import android.widget.FrameLayout;
9 |
10 | import xyz.danoz.recyclerviewfastscroller.R;
11 | import xyz.danoz.recyclerviewfastscroller.calculation.VerticalScrollBoundsProvider;
12 | import xyz.danoz.recyclerviewfastscroller.calculation.position.VerticalScreenPositionCalculator;
13 | import xyz.danoz.recyclerviewfastscroller.sectionindicator.animation.DefaultSectionIndicatorAlphaAnimator;
14 |
15 | /**
16 | * Abstract base implementation of a section indicator used to indicate the section of a list upon which the user is
17 | * currently fast scrolling.
18 | */
19 | public abstract class AbsSectionIndicator extends FrameLayout implements SectionIndicator {
20 |
21 | private static final int[] STYLEABLE = R.styleable.AbsSectionIndicator;
22 |
23 | private VerticalScreenPositionCalculator mScreenPositionCalculator;
24 | private DefaultSectionIndicatorAlphaAnimator mDefaultSectionIndicatorAlphaAnimator;
25 |
26 | public AbsSectionIndicator(Context context) {
27 | this(context, null);
28 | }
29 |
30 | public AbsSectionIndicator(Context context, AttributeSet attrs) {
31 | this(context, attrs, 0);
32 | }
33 |
34 | public AbsSectionIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
35 | super(context, attrs, defStyleAttr);
36 | TypedArray attributes = getContext().getTheme().obtainStyledAttributes(attrs, STYLEABLE, 0, 0);
37 | try {
38 | int layoutId = attributes.getResourceId(R.styleable.AbsSectionIndicator_rfs_section_indicator_layout, getDefaultLayoutId());
39 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
40 | inflater.inflate(layoutId, this, true);
41 | } finally {
42 | attributes.recycle();
43 | }
44 |
45 | mDefaultSectionIndicatorAlphaAnimator = new DefaultSectionIndicatorAlphaAnimator(this);
46 | }
47 |
48 | /**
49 | * @return the default layout for a given implementation of AbsSectionIndicator
50 | */
51 | protected abstract int getDefaultLayoutId();
52 |
53 | /**
54 | * @return the default background color to be used if not provided by client in XML
55 | * @see {@link #applyCustomBackgroundColorAttribute(int)}
56 | */
57 | protected abstract int getDefaultBackgroundColor();
58 |
59 | /**
60 | * Clients can provide a custom background color for a section indicator
61 | * @param color provided in XML via the {@link R.styleable#AbsSectionIndicator_backgroundColor} parameter. If not
62 | * specified in XML, this defaults to that which is provided by {@link #getDefaultBackgroundColor()}
63 | */
64 | protected abstract void applyCustomBackgroundColorAttribute(int color);
65 |
66 | @Override
67 | public void onLayout(boolean changed, int left, int top, int right, int bottom) {
68 | super.onLayout(changed, left, top, right, bottom);
69 | if (mScreenPositionCalculator == null) {
70 | VerticalScrollBoundsProvider boundsProvider =
71 | new VerticalScrollBoundsProvider(0, ((ViewGroup) getParent()).getHeight() - getHeight());
72 | mScreenPositionCalculator = new VerticalScreenPositionCalculator(boundsProvider);
73 | }
74 | }
75 |
76 | @Override
77 | public void setProgress(float progress) {
78 | setY(mScreenPositionCalculator.getYPositionFromScrollProgress(progress));
79 | }
80 |
81 | @Override
82 | public void animateAlpha(float targetAlpha) {
83 | mDefaultSectionIndicatorAlphaAnimator.animateTo(targetAlpha);
84 | }
85 |
86 | @Override
87 | public abstract void setSection(T object);
88 | }
89 |
--------------------------------------------------------------------------------
/Application/src/main/java/xyz/danoz/recyclerviewfastscroller/sample/recyclerview/ColorfulAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
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 | package xyz.danoz.recyclerviewfastscroller.sample.recyclerview;
18 |
19 | import android.graphics.Color;
20 | import android.support.v7.widget.RecyclerView;
21 | import android.view.LayoutInflater;
22 | import android.view.View;
23 | import android.view.ViewGroup;
24 | import android.widget.SectionIndexer;
25 | import android.widget.TextView;
26 |
27 | import xyz.danoz.recyclerview.sample.R;
28 | import xyz.danoz.recyclerviewfastscroller.sample.data.ColorData;
29 | import xyz.danoz.recyclerviewfastscroller.sample.data.ColorDataSet;
30 | import xyz.danoz.recyclerviewfastscroller.sample.data.ColorGroup;
31 |
32 | /**
33 | * Provide views to RecyclerView with data from mDataSet.
34 | */
35 | public class ColorfulAdapter extends RecyclerView.Adapter implements SectionIndexer {
36 |
37 | private ColorDataSet mDataSet;
38 |
39 | /**
40 | * Provide a reference to the type of views that you are using (custom ViewHolder)
41 | */
42 | public static class ViewHolder extends RecyclerView.ViewHolder {
43 | private final TextView textView;
44 |
45 | public ViewHolder(View v) {
46 | super(v);
47 | // Define click listener for the ViewHolder's View.
48 | v.setOnClickListener(new View.OnClickListener() {
49 | @Override
50 | public void onClick(View v) {
51 | v.setBackgroundColor(Color.BLACK);
52 | }
53 | });
54 | textView = (TextView) v.findViewById(R.id.textView);
55 | }
56 |
57 | public TextView getTextView() {
58 | return textView;
59 | }
60 | }
61 |
62 | /**
63 | * Initialize the dataset of the Adapter.
64 | *
65 | * @param data String[] containing the data to populate views to be used by RecyclerView.
66 | */
67 | public ColorfulAdapter(ColorDataSet data) {
68 | mDataSet = data;
69 | }
70 |
71 | // Create new views (invoked by the layout manager)
72 | @Override
73 | public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
74 | View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.text_row_item, viewGroup, false);
75 | return new ViewHolder(v);
76 | }
77 |
78 | // Replace the contents of a view (invoked by the layout manager)
79 | @Override
80 | public void onBindViewHolder(ViewHolder viewHolder, final int position) {
81 | // Get element from your dataset at this position and replace the contents of the view
82 | // with that element
83 | ColorData color = mDataSet.get(position);
84 | viewHolder.itemView.setBackgroundColor(color.getIntValue());
85 | viewHolder.getTextView().setText(mDataSet.get(position).toString());
86 | }
87 |
88 | // Return the size of your dataset (invoked by the layout manager)
89 | @Override
90 | public int getItemCount() {
91 | return mDataSet.getSize();
92 | }
93 |
94 | @Override
95 | public Object[] getSections() {
96 | return ColorGroup.values();
97 | }
98 |
99 | @Override
100 | public int getPositionForSection(int sectionIndex) {
101 | return 0;
102 | }
103 |
104 | @Override
105 | public int getSectionForPosition(int position) {
106 | if (position >= mDataSet.getSize()) {
107 | position = mDataSet.getSize() - 1;
108 | }
109 |
110 | ColorData color = mDataSet.get(position);
111 | return color.getColorGroup().ordinal();
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/sectionindicator/title/SectionTitleIndicator.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller.sectionindicator.title;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.drawable.Drawable;
6 | import android.graphics.drawable.GradientDrawable;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 | import android.widget.TextView;
10 |
11 | import xyz.danoz.recyclerviewfastscroller.R;
12 | import xyz.danoz.recyclerviewfastscroller.sectionindicator.AbsSectionIndicator;
13 |
14 | /**
15 | * Popup view that gets shown when fast scrolling
16 | */
17 | public abstract class SectionTitleIndicator extends AbsSectionIndicator {
18 |
19 | private static final int[] STYLEABLE = R.styleable.SectionTitleIndicator;
20 | private static final int DEFAULT_TITLE_INDICATOR_LAYOUT = R.layout.section_indicator_with_title;
21 | private static final int DEFAULT_BACKGROUND_COLOR = android.R.color.darker_gray;
22 | private static final int DEFAULT_TEXT_COLOR = android.R.color.white;
23 |
24 | private final View mIndicatorBackground;
25 | private final TextView mTitleText;
26 |
27 | public SectionTitleIndicator(Context context) {
28 | this(context, null);
29 | }
30 |
31 | public SectionTitleIndicator(Context context, AttributeSet attrs) {
32 | this(context, attrs, 0);
33 | }
34 |
35 | public SectionTitleIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
36 | super(context, attrs, defStyleAttr);
37 | mIndicatorBackground = findViewById(R.id.section_title_popup);
38 | mTitleText = (TextView) findViewById(R.id.section_indicator_text);
39 |
40 | TypedArray attributes = getContext().getTheme().obtainStyledAttributes(attrs, STYLEABLE, 0, 0);
41 | try {
42 | int customBackgroundColor =
43 | attributes.getColor(R.styleable.SectionTitleIndicator_rfs_backgroundColor, getDefaultBackgroundColor());
44 | applyCustomBackgroundColorAttribute(customBackgroundColor);
45 |
46 | int customTextColor =
47 | attributes.getColor(R.styleable.SectionTitleIndicator_rfs_textColor, getDefaultBackgroundColor());
48 | applyCustomTextColorAttribute(customTextColor);
49 | } finally {
50 | attributes.recycle();
51 | }
52 | }
53 |
54 | /**
55 | * @return the default layout for a section indicator with a title. This closely resembles the section indicator
56 | * featured in Lollipop's Contact's application
57 | */
58 | @Override
59 | protected int getDefaultLayoutId() {
60 | return DEFAULT_TITLE_INDICATOR_LAYOUT;
61 | }
62 |
63 | protected int getDefaultBackgroundColor() {
64 | return DEFAULT_BACKGROUND_COLOR;
65 | }
66 |
67 | protected int getDefaultTextColor() {
68 | return DEFAULT_TEXT_COLOR;
69 | }
70 |
71 | /**
72 | * Clients can provide a custom background color for a section indicator
73 | * @param color provided in XML via the {@link R.styleable#SectionTitleIndicator_rfs_backgroundColor} parameter. If not
74 | * specified in XML, this defaults to that which is provided by {@link #getDefaultBackgroundColor()}
75 | */
76 | @Override
77 | protected void applyCustomBackgroundColorAttribute(int color) {
78 | setIndicatorBackgroundColor(color);
79 | }
80 |
81 | /**
82 | * An enhanced method for setting the background color of the indicator that has knowledge of the indicator's
83 | * layout in instances where calling {@link #setBackgroundColor(int)} won't do.
84 | * @param color to set as the indicator's background color
85 | */
86 | public void setIndicatorBackgroundColor(int color) {
87 | Drawable backgroundDrawable = mIndicatorBackground.getBackground();
88 |
89 | if (backgroundDrawable instanceof GradientDrawable) {
90 | GradientDrawable backgroundShape = (GradientDrawable) backgroundDrawable;
91 | backgroundShape.setColor(color);
92 | } else {
93 | mIndicatorBackground.setBackgroundColor(color);
94 | }
95 | }
96 |
97 | /**
98 | * Clients can provide a custom text color for a section indicator
99 | * @param color provided in XML via the {@link R.styleable#SectionTitleIndicator_rfs_textColor} parameter. If not
100 | * specified in XML, this defaults to that which is provided by {@link #getDefaultTextColor()} ()}
101 | */
102 | protected void applyCustomTextColorAttribute(int color) {
103 | setIndicatorTextColor(color);
104 | }
105 |
106 | /**
107 | * Allows user to programmatically set the text color of the indicator
108 | * @param color to set as the indicator's text color
109 | */
110 | public void setIndicatorTextColor(int color) {
111 | mTitleText.setTextColor(color);
112 | }
113 |
114 | /**
115 | * Set the text for the section title popup
116 | * @param text to display in the section title popup
117 | */
118 | public void setTitleText(String text) {
119 | mTitleText.setText(text);
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | RecyclerViewFastScroller
2 | ===================================
3 |
4 | The RecyclerViewFastScroller is a widget that can be added to a layout and connected to a RecyclerView for fast scrolling.
5 |
6 | This project is a demonstration of using the RecyclerViewFastScroller widget in a simple activity that uses the basic workings of com.example.android.recyclerview from the v21 Android samples.
7 |
8 | 
9 | 
10 |
11 | As of [`b3e2d2f`](https://github.com/danoz73/RecyclerViewFastScroller/commit/b3e2d2fa8284dea31fbc5f9f218199f2a187a657), there is now support for adding a `SectionIndicator` widget, which connects to the scroller. This adds functionality similar to Google's Lollipop Contacts application.
12 |
13 | ### Download
14 |
15 | You can grab the current version of the library from maven central
16 | ```java
17 | compile 'xyz.danoz:recyclerviewfastscroller:0.1.3'
18 | ```
19 |
20 | ### Usage
21 |
22 | Below are some simple steps to using a RecyclerViewFastScroller. Currently, there is only a single implementation (`VerticalRecyclerViewFastScroller`), so that will be used here.
23 |
24 | The best way to check everything out is to peruse the example code and run the sample Application. See how `VerticalRecyclerViewFastScroller` is utilized in the `recycler_view_frag.xml`.
25 |
26 | ##### Example Code
27 |
28 | 1) In the activity or fragment XML where your `RecyclerView` resides, include a `VerticalRecyclerViewFastScroller` object. The following example would be in a relative layout:
29 |
30 | ```java
31 | ...
32 |
37 |
38 |
44 | ...
45 | ```
46 |
47 | 2) In your fragment or activity where you setup layout programmatically, simply hook up the fast scroller to the recycler as follows:
48 |
49 | ```java
50 | ...
51 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
52 | View rootView = inflater.inflate(R.layout.recycler_view_frag, container, false);
53 | ...
54 |
55 | // Grab your RecyclerView and the RecyclerViewFastScroller from the layout
56 | RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
57 | VerticalRecyclerViewFastScroller fastScroller = (VerticalRecyclerViewFastScroller) rootView.findViewById(R.id.fast_scroller);
58 |
59 | // Connect the recycler to the scroller (to let the scroller scroll the list)
60 | fastScroller.setRecyclerView(recyclerView);
61 |
62 | // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
63 | recyclerView.setOnScrollListener(fastScroller.getOnScrollListener());
64 |
65 | ...
66 | return rootView;
67 | }
68 | ...
69 | ```
70 |
71 | ###### Optional usage
72 |
73 | There are currently a few attributes that can be used to customize the vertical fast scroller:
74 |
75 | ```java
76 |
77 |
78 |
79 |
80 | ```
81 |
82 | You can see usage of some of these in the example `recycler_view_with_fast_scroller_fragment.xml` which is the layout for the example app's single fragment.
83 |
84 | ##### SectionIndicators
85 |
86 | Refer to `RecyclerViewWithSectionIndicatorFragment` and the corresponding `recycler_view_with_fast_scroller_section_title_indicator_fragment.xml` in order to find an implementation that adds the Lollipop-Contacts-like section indicator. In addition to the above, you will need to include the indicator in your layout (example here from `recycler_view_with_fast_scroller_section_title_indicator_fragment.xml`):
87 |
88 | ```java
89 | ...
90 |
100 | ...
101 | ```
102 | and then connect it to the scroller in the fragment:
103 | ```java
104 | ...
105 | // Connect the section indicator to the scroller
106 | fastScroller.setSectionIndicator(sectionTitleIndicator);
107 | ...
108 | ```
109 |
110 | ### Contribution
111 |
112 | Feel free to submit pull requests and create issues! I will try to be vigilant about maintaining this library, but may not always be as fast as you would like ;)
113 |
--------------------------------------------------------------------------------
/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/recyclerviewfastscroller/src/main/java/xyz/danoz/recyclerviewfastscroller/AbsRecyclerViewFastScroller.java:
--------------------------------------------------------------------------------
1 | package xyz.danoz.recyclerviewfastscroller;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Color;
7 | import android.graphics.drawable.Drawable;
8 | import android.os.Build.VERSION;
9 | import android.os.Build.VERSION_CODES;
10 | import android.support.annotation.NonNull;
11 | import android.support.annotation.Nullable;
12 | import android.support.v7.widget.RecyclerView;
13 | import android.support.v7.widget.RecyclerView.OnScrollListener;
14 | import android.util.AttributeSet;
15 | import android.view.LayoutInflater;
16 | import android.view.MotionEvent;
17 | import android.view.View;
18 | import android.widget.FrameLayout;
19 | import android.widget.SectionIndexer;
20 |
21 | import xyz.danoz.recyclerviewfastscroller.calculation.progress.ScrollProgressCalculator;
22 | import xyz.danoz.recyclerviewfastscroller.calculation.progress.TouchableScrollProgressCalculator;
23 | import xyz.danoz.recyclerviewfastscroller.sectionindicator.SectionIndicator;
24 |
25 | /**
26 | * Defines a basic widget that will allow for fast scrolling a RecyclerView using the basic paradigm of
27 | * a handle and a bar.
28 | *
29 | * TODO: More specifics and better support for effectively extending this base class
30 | */
31 | public abstract class AbsRecyclerViewFastScroller extends FrameLayout implements RecyclerViewScroller {
32 |
33 | private static final int[] STYLEABLE = R.styleable.AbsRecyclerViewFastScroller;
34 | /** The long bar along which a handle travels */
35 | protected final View mBar;
36 | /** The handle that signifies the user's progress in the list */
37 | protected final View mHandle;
38 |
39 | /* TODO:
40 | * Consider making RecyclerView final and should be passed in using a custom attribute
41 | * This could allow for some type checking on the section indicator wrt the adapter of the RecyclerView
42 | */
43 | private RecyclerView mRecyclerView;
44 | private SectionIndicator mSectionIndicator;
45 |
46 | /** If I had my druthers, AbsRecyclerViewFastScroller would implement this as an interface, but Android has made
47 | * {@link OnScrollListener} an abstract class instead of an interface. Hmmm */
48 | protected OnScrollListener mOnScrollListener;
49 |
50 | public AbsRecyclerViewFastScroller(Context context) {
51 | this(context, null, 0);
52 | }
53 |
54 | public AbsRecyclerViewFastScroller(Context context, AttributeSet attrs) {
55 | this(context, attrs, 0);
56 | }
57 |
58 | public AbsRecyclerViewFastScroller(Context context, AttributeSet attrs, int defStyleAttr) {
59 | super(context, attrs, defStyleAttr);
60 |
61 | TypedArray attributes = getContext().getTheme().obtainStyledAttributes(attrs, STYLEABLE, 0, 0);
62 |
63 | try {
64 | int layoutResource = attributes.getResourceId(R.styleable.AbsRecyclerViewFastScroller_rfs_fast_scroller_layout,
65 | getLayoutResourceId());
66 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
67 | inflater.inflate(layoutResource, this, true);
68 |
69 | mBar = findViewById(R.id.scroll_bar);
70 | mHandle = findViewById(R.id.scroll_handle);
71 |
72 | Drawable barDrawable = attributes.getDrawable(R.styleable.AbsRecyclerViewFastScroller_rfs_barBackground);
73 | int barColor = attributes.getColor(R.styleable.AbsRecyclerViewFastScroller_rfs_barColor, Color.GRAY);
74 | applyCustomAttributesToView(mBar, barDrawable, barColor);
75 |
76 | Drawable handleDrawable = attributes.getDrawable(R.styleable.AbsRecyclerViewFastScroller_rfs_handleBackground);
77 | int handleColor = attributes.getColor(R.styleable.AbsRecyclerViewFastScroller_rfs_handleColor, Color.GRAY);
78 | applyCustomAttributesToView(mHandle, handleDrawable, handleColor);
79 | } finally {
80 | attributes.recycle();
81 | }
82 |
83 | setOnTouchListener(new FastScrollerTouchListener(this));
84 | }
85 |
86 | private void applyCustomAttributesToView(View view, Drawable drawable, int color) {
87 | if (drawable != null) {
88 | setViewBackground(view, drawable);
89 | } else {
90 | view.setBackgroundColor(color);
91 | }
92 | }
93 |
94 | /**
95 | * Provides the ability to programmatically set the color of the fast scroller's handle
96 | * @param color for the handle to be
97 | */
98 | public void setHandleColor(int color) {
99 | mHandle.setBackgroundColor(color);
100 | }
101 |
102 | /**
103 | * Provides the ability to programmatically set the background drawable of the fast scroller's handle
104 | * @param drawable for the handle's background
105 | */
106 | public void setHandleBackground(Drawable drawable) {
107 | setViewBackground(mHandle, drawable);
108 | }
109 |
110 | /**
111 | * Provides the ability to programmatically set the color of the fast scroller's bar
112 | * @param color for the bar to be
113 | */
114 | public void setBarColor(int color) {
115 | mBar.setBackgroundColor(color);
116 | }
117 |
118 | /**
119 | * Provides the ability to programmatically set the background drawable of the fast scroller's bar
120 | * @param drawable for the bar's background
121 | */
122 | public void setBarBackground(Drawable drawable) {
123 | setViewBackground(mBar, drawable);
124 | }
125 |
126 | @TargetApi(VERSION_CODES.JELLY_BEAN)
127 | private void setViewBackground(View view, Drawable background) {
128 | if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
129 | view.setBackground(background);
130 | } else {
131 | //noinspection deprecation
132 | view.setBackgroundDrawable(background);
133 | }
134 | }
135 |
136 | @Override
137 | public void setRecyclerView(RecyclerView recyclerView) {
138 | mRecyclerView = recyclerView;
139 | }
140 |
141 | public void setSectionIndicator(SectionIndicator sectionIndicator) {
142 | mSectionIndicator = sectionIndicator;
143 | }
144 |
145 | @Nullable
146 | public SectionIndicator getSectionIndicator() {
147 | return mSectionIndicator;
148 | }
149 |
150 | @Override
151 | public void scrollTo(float scrollProgress, boolean fromTouch) {
152 | int position = getPositionFromScrollProgress(scrollProgress);
153 | mRecyclerView.scrollToPosition(position);
154 |
155 | updateSectionIndicator(position, scrollProgress);
156 | }
157 |
158 | private void updateSectionIndicator(int position, float scrollProgress) {
159 | if (mSectionIndicator != null) {
160 | mSectionIndicator.setProgress(scrollProgress);
161 | if (mRecyclerView.getAdapter() instanceof SectionIndexer) {
162 | SectionIndexer indexer = ((SectionIndexer) mRecyclerView.getAdapter());
163 | int section = indexer.getSectionForPosition(position);
164 | Object[] sections = indexer.getSections();
165 | mSectionIndicator.setSection(sections[section]);
166 | }
167 | }
168 | }
169 |
170 | private int getPositionFromScrollProgress(float scrollProgress) {
171 | return (int) (mRecyclerView.getAdapter().getItemCount() * scrollProgress);
172 | }
173 |
174 | /**
175 | * Classes that extend AbsFastScroller must implement their own {@link OnScrollListener} to respond to scroll
176 | * events when the {@link #mRecyclerView} is scrolled NOT using the fast scroller.
177 | * @return an implementation for responding to scroll events from the {@link #mRecyclerView}
178 | */
179 | @NonNull
180 | public OnScrollListener getOnScrollListener() {
181 | if (mOnScrollListener == null) {
182 | mOnScrollListener = new OnScrollListener() {
183 | @Override
184 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
185 | float scrollProgress = 0;
186 | ScrollProgressCalculator scrollProgressCalculator = getScrollProgressCalculator();
187 | if (scrollProgressCalculator != null) {
188 | scrollProgress = scrollProgressCalculator.calculateScrollProgress(recyclerView);
189 | }
190 | moveHandleToPosition(scrollProgress);
191 | }
192 | };
193 | }
194 | return mOnScrollListener;
195 | }
196 |
197 | @Override
198 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
199 | super.onLayout(changed, left, top, right, bottom);
200 |
201 | if (getScrollProgressCalculator() == null) {
202 | onCreateScrollProgressCalculator();
203 | }
204 |
205 | // synchronize the handle position to the RecyclerView
206 | float scrollProgress = getScrollProgressCalculator().calculateScrollProgress(mRecyclerView);
207 | moveHandleToPosition(scrollProgress);
208 | }
209 |
210 | /**
211 | * Sub classes have to override this method and create the ScrollProgressCalculator instance in this method.
212 | */
213 | protected abstract void onCreateScrollProgressCalculator();
214 |
215 | /**
216 | * Takes a touch event and determines how much scroll progress this translates into
217 | * @param event touch event received by the layout
218 | * @return scroll progress, or fraction by which list is scrolled [0 to 1]
219 | */
220 | public float getScrollProgress(MotionEvent event) {
221 | ScrollProgressCalculator scrollProgressCalculator = getScrollProgressCalculator();
222 | if (scrollProgressCalculator != null) {
223 | return getScrollProgressCalculator().calculateScrollProgress(event);
224 | }
225 | return 0;
226 | }
227 |
228 | /**
229 | * Define a layout resource for your implementation of AbsFastScroller
230 | * Currently must contain a handle view (R.id.scroll_handle) and a bar (R.id.scroll_bar)
231 | * @return a resource id corresponding to the chosen layout.
232 | */
233 | protected abstract int getLayoutResourceId();
234 |
235 | /**
236 | * Define a ScrollProgressCalculator for your implementation of AbsFastScroller
237 | * @return a chosen implementation of {@link ScrollProgressCalculator}
238 | */
239 | @Nullable
240 | protected abstract TouchableScrollProgressCalculator getScrollProgressCalculator();
241 |
242 | /**
243 | * Moves the handle of the scroller by specific progress amount
244 | * @param scrollProgress fraction by which to move scroller [0 to 1]
245 | */
246 | public abstract void moveHandleToPosition(float scrollProgress);
247 |
248 | }
--------------------------------------------------------------------------------