├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── font
│ │ │ └── lobster.otf
│ │ ├── drawable-hdpi
│ │ │ └── ic_options.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_options.png
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_options.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_options.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── drawable
│ │ │ └── bg_layout.xml
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ └── strings.xml
│ │ └── layout
│ │ │ ├── activity_main.xml
│ │ │ └── layout_options.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── hlabexamples
│ │ └── animatedpulltorefresh
│ │ ├── ListAdapter.kt
│ │ └── MainActivity.kt
├── proguard-rules.pro
└── build.gradle
├── _config.yml
├── AnimatedPullToRefreshLib
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ └── values
│ │ │ ├── dimen.xml
│ │ │ ├── strings.xml
│ │ │ └── attrs.xml
│ │ └── java
│ │ └── com
│ │ └── hlab
│ │ └── animatedpulltorefresh
│ │ ├── enums
│ │ ├── HeaderState.java
│ │ ├── HeaderAnimSpeed.java
│ │ ├── HeaderLoopAnim.java
│ │ └── HeaderTextAnim.java
│ │ ├── AnimationListener.java
│ │ ├── herlper
│ │ ├── Constants.java
│ │ ├── ViewHelper.java
│ │ └── AnimationHelper.java
│ │ ├── CharacterAnimatorHeaderView.java
│ │ └── AnimatedPullToRefreshLayout.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-leap-day
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':AnimatedPullToRefreshLib'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/font/lobster.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/font/lobster.otf
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_options.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/drawable-hdpi/ic_options.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_options.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/drawable-mdpi/ic_options.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_options.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/drawable-xhdpi/ic_options.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_options.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/drawable-xxhdpi/ic_options.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarinTrivedi/AnimatedPullToRefresh-master/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .DS_Store
3 | .externalNativeBuild
4 | /.gradle
5 | /.idea
6 | /local.properties
7 | /build
8 | /captures
9 | /app/build
10 | /AnimatedPullToRefreshLib/build
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Sep 01 19:24:17 IST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #f9f9f9
8 | #5c5c5c
9 |
10 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/res/values/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 10sp
4 | 10dp
5 | 10dp
6 | 5dp
7 | 5dp
8 |
9 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Swipe to refresh
3 | Release to refresh
4 | Refreshing ...
5 | Refreshing complete
6 | last update:
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/java/com/hlab/animatedpulltorefresh/enums/HeaderState.java:
--------------------------------------------------------------------------------
1 | package com.hlab.animatedpulltorefresh.enums;
2 |
3 | public enum HeaderState {
4 | HEADER_STATE_DEFAULT(-1),
5 | HEADER_STATE_NORMAL(0),
6 | HEADER_STATE_READY(1),
7 | HEADER_STATE_REFRESHING(2),
8 | HEADER_STATE_COMPLETE(3);
9 |
10 | int state;
11 |
12 | HeaderState(int i) {
13 | state = i;
14 | }
15 |
16 | public int getState() {
17 | return state;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/java/com/hlab/animatedpulltorefresh/AnimationListener.java:
--------------------------------------------------------------------------------
1 | package com.hlab.animatedpulltorefresh;
2 |
3 | import android.view.animation.Animation;
4 |
5 | /**
6 | * Created in Android_animated_pull_to_refresh_control-master on 22/03/17.
7 | */
8 |
9 | class AnimationListener implements Animation.AnimationListener {
10 | @Override
11 | public void onAnimationStart(Animation animation) {
12 | }
13 |
14 | @Override
15 | public void onAnimationEnd(Animation animation) {
16 | }
17 |
18 | @Override
19 | public void onAnimationRepeat(Animation animation) {
20 | }
21 | }
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/java/com/hlab/animatedpulltorefresh/enums/HeaderAnimSpeed.java:
--------------------------------------------------------------------------------
1 | package com.hlab.animatedpulltorefresh.enums;
2 |
3 | /**
4 | * Created in Android_animated_pull_to_refresh_control-master on 22/03/17.
5 | */
6 |
7 | public enum HeaderAnimSpeed {
8 | FAST(0), SLOW(1);
9 |
10 | private int speed;
11 |
12 | HeaderAnimSpeed(int type) {
13 | speed = type;
14 | }
15 |
16 | public int getSpeed() {
17 | return speed;
18 | }
19 |
20 | public static HeaderAnimSpeed fromId(int id) {
21 | for (HeaderAnimSpeed f : values()) {
22 | if (f.speed == id) return f;
23 | }
24 | throw new IllegalArgumentException();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/java/com/hlab/animatedpulltorefresh/enums/HeaderLoopAnim.java:
--------------------------------------------------------------------------------
1 | package com.hlab.animatedpulltorefresh.enums;
2 |
3 | /**
4 | * Created in Android_animated_pull_to_refresh_control-master on 22/03/17.
5 | */
6 |
7 | public enum HeaderLoopAnim {
8 | ZOOM(0), FADE(1);
9 |
10 | private int animType;
11 |
12 | HeaderLoopAnim(int type) {
13 | animType = type;
14 | }
15 |
16 | public int getAnimType() {
17 | return animType;
18 | }
19 |
20 | public static HeaderLoopAnim fromId(int id) {
21 | for (HeaderLoopAnim f : values()) {
22 | if (f.animType == id) return f;
23 | }
24 | throw new IllegalArgumentException();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/java/com/hlab/animatedpulltorefresh/enums/HeaderTextAnim.java:
--------------------------------------------------------------------------------
1 | package com.hlab.animatedpulltorefresh.enums;
2 |
3 | /**
4 | * Created in Android_animated_pull_to_refresh_control-master on 22/03/17.
5 | */
6 |
7 | public enum HeaderTextAnim {
8 | ROTATE_CW(0), ROTATE_ACW(1), FADE(2), ZOOM(3);
9 |
10 | private int animType;
11 |
12 | HeaderTextAnim(int type) {
13 | animType = type;
14 | }
15 |
16 | public int getAnimType() {
17 | return animType;
18 | }
19 |
20 | public static HeaderTextAnim fromId(int id) {
21 | for (HeaderTextAnim f : values()) {
22 | if (f.animType == id) return f;
23 | }
24 | throw new IllegalArgumentException();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AnimatedPullToRefresh
3 | LOADING
4 |
5 |
6 | - Fast
7 | - Slow
8 |
9 |
10 |
11 | - Rotate Clockwise
12 | - Rotate Anti-clockwise
13 | - Fade
14 | - Zoom
15 |
16 |
17 |
18 | - Zoom
19 | - Fade
20 |
21 |
22 |
23 | - 1
24 | - 2
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/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 /Volumes/DATA/Android-Setup/android-sdk-mac_86/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/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 /Volumes/DATA/Android-Setup/android-sdk-mac_86/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/java/com/hlab/animatedpulltorefresh/herlper/Constants.java:
--------------------------------------------------------------------------------
1 | package com.hlab.animatedpulltorefresh.herlper;
2 |
3 | public class Constants {
4 |
5 | // time out for no movements during swipe action
6 | public static final int RETURN_DURATION = 200;
7 |
8 | // time out for showing refresh complete
9 | public static final int REFRESH_COMPLETE_DURATION = 200;
10 |
11 | // Duration of the animation from the top of the content view to parent top
12 | public static final int RETURN_TO_TOP_DURATION = 200;
13 |
14 | // Duration of the animation from the top of the content view to the height of header
15 | public static final int RETURN_TO_HEADER_DURATION = 200;
16 |
17 | // maximum swipe distance( percent of parent container)
18 | public static final float MAX_SWIPE_DISTANCE_FACTOR = .3f;
19 |
20 | // swipe distance to trigger refreshing
21 | public static final int SWIPE_REFRESH_TRIGGER_DISTANCE = 100;
22 |
23 | // swipe resistance factor
24 | public static final float RESISTANCE_FACTOR = .4f;
25 | }
26 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'com.github.dcendents.android-maven'
4 |
5 | group='com.github.hlab'
6 | android {
7 | compileSdkVersion 29
8 |
9 | defaultConfig {
10 | minSdkVersion 21
11 | targetSdkVersion 29
12 | versionCode 2
13 | versionName "1.0.2"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | android {
23 | lintOptions {
24 | abortOnError false
25 | }
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 | implementation 'androidx.appcompat:appcompat:1.2.0'
32 | implementation "androidx.core:core-ktx:+"
33 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
34 | }
35 |
36 |
37 | ext {
38 | PUBLISH_GROUP_ID = 'com.hlab.animatedPullToRefresh'
39 | PUBLISH_ARTIFACT_ID = 'animated-pull-to-refresh-layout'
40 | PUBLISH_VERSION = '1.0.2'
41 | }
42 | repositories {
43 | mavenCentral()
44 | }
45 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion 29
6 |
7 | defaultConfig {
8 | applicationId "com.hlabexamples.AnimatedPullToRefresh"
9 | minSdkVersion 21
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | dataBinding{
21 | enabled = true
22 | }
23 | android {
24 | lintOptions {
25 | abortOnError false
26 | }
27 | }
28 | compileOptions {
29 | sourceCompatibility JavaVersion.VERSION_1_8
30 | targetCompatibility JavaVersion.VERSION_1_8
31 | }
32 | }
33 |
34 | dependencies {
35 | implementation fileTree(include: ['*.jar'], dir: 'libs')
36 | implementation 'com.google.android.material:material:1.2.0'
37 | implementation 'com.github.HarinTrivedi:FABRevealMenu-master:2.0.0'
38 | implementation project(':AnimatedPullToRefreshLib')
39 | implementation "androidx.core:core-ktx:+"
40 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
41 | }
42 | repositories {
43 | mavenCentral()
44 | }
45 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/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 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hlabexamples/animatedpulltorefresh/ListAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.hlabexamples.animatedpulltorefresh
2 |
3 | import android.content.Context
4 | import android.graphics.Color
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import android.widget.TextView
9 | import androidx.recyclerview.widget.RecyclerView
10 | import java.util.*
11 |
12 | /**
13 | * Created in Android_animated_pull_to_refresh_control-master on 23/03/17.
14 | */
15 | class ItemListAdapter(private val context: Context) : RecyclerView.Adapter() {
16 | private var items: MutableList = ArrayList()
17 | private var inflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
18 |
19 | init {
20 | for (i in 0..19) {
21 | items.add("List Item " + (i + 1))
22 | }
23 | }
24 |
25 | override fun getItemCount(): Int {
26 | return items.size
27 | }
28 |
29 | class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
30 | var tv: TextView? = itemView.findViewById(android.R.id.text1) as TextView
31 | }
32 |
33 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
34 | return ItemViewHolder(inflater.inflate(android.R.layout.simple_list_item_1, parent, false))
35 | }
36 |
37 | override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
38 | holder.tv?.setTextColor(Color.BLACK)
39 | holder.tv?.text = items.get(position)
40 | }
41 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
22 |
23 |
27 |
28 |
29 |
30 |
39 |
40 |
44 |
45 |
51 |
52 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/java/com/hlab/animatedpulltorefresh/herlper/ViewHelper.java:
--------------------------------------------------------------------------------
1 | package com.hlab.animatedpulltorefresh.herlper;
2 |
3 | import android.content.Context;
4 | import android.graphics.Typeface;
5 | import android.view.Gravity;
6 | import android.widget.LinearLayout;
7 | import android.widget.TextView;
8 |
9 | import com.hlab.animatedpulltorefresh.R;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Helper class to manage views inside Header
16 | */
17 |
18 | public class ViewHelper {
19 |
20 | private Context context;
21 | private LinearLayout.LayoutParams tvParams, containerParams;
22 |
23 | // View Attributes
24 | private int headerTextSize;
25 | private int headerTextColor;
26 | private int headerPaddingTop;
27 | private int headerPaddingBottom;
28 | private Typeface mTitleTypeface;
29 |
30 | public ViewHelper(Context context) {
31 | this.context = context;
32 |
33 | containerParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
34 | tvParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
35 | tvParams.setMargins(context.getResources().getDimensionPixelSize(R.dimen.headerPaddingLeft),
36 | context.getResources().getDimensionPixelSize(R.dimen.headerPaddingTop),
37 | context.getResources().getDimensionPixelSize(R.dimen.headerPaddingRight),
38 | 0);
39 | }
40 |
41 | /**
42 | * Generates parent container layout
43 | */
44 | public LinearLayout generateContainerLayout() {
45 | LinearLayout container = new LinearLayout(context);
46 | container.setLayoutParams(containerParams);
47 | container.setGravity(Gravity.CENTER);
48 | container.setOrientation(LinearLayout.HORIZONTAL);
49 | return container;
50 | }
51 |
52 | /**
53 | * Generates character view
54 | */
55 | private TextView generateCharacterTextView(char c) {
56 | TextView textView = new TextView(context);
57 | textView.setText(String.valueOf(c));
58 | textView.setTextColor(headerTextColor);
59 | textView.setLayoutParams(tvParams);
60 | textView.setTextSize(headerTextSize);
61 | if (mTitleTypeface != null)
62 | textView.setTypeface(mTitleTypeface);
63 | return textView;
64 | }
65 |
66 | /**
67 | * Start adding views in parent
68 | */
69 | public List generateCharacterViewList(String text) {
70 | if (text == null)
71 | text = "";
72 | List characterViewList = new ArrayList<>();
73 |
74 | for (char c : text.toCharArray()) {
75 | characterViewList.add(generateCharacterTextView(c));
76 | }
77 | return characterViewList;
78 | }
79 |
80 | public int getHeaderTextSize() {
81 | return headerTextSize;
82 | }
83 |
84 | public void setHeaderTextSize(int headerTextSize) {
85 | this.headerTextSize = headerTextSize;
86 | }
87 |
88 | public int getHeaderTextColor() {
89 | return headerTextColor;
90 | }
91 |
92 | public void setHeaderTextColor(int headerTextColor) {
93 | this.headerTextColor = headerTextColor;
94 | }
95 |
96 | public int getHeaderPaddingTop() {
97 | return headerPaddingTop;
98 | }
99 |
100 | public void setHeaderPaddingTop(int headerPaddingTop) {
101 | tvParams.topMargin = headerPaddingTop;
102 | this.headerPaddingTop = headerPaddingTop;
103 | }
104 |
105 | public int getHeaderPaddingBottom() {
106 | return headerPaddingBottom;
107 | }
108 |
109 | public void setHeaderPaddingBottom(int headerPaddingBottom) {
110 | // tvParams.bottomMargin = headerPaddingBottom;
111 | this.headerPaddingBottom = headerPaddingBottom;
112 | }
113 |
114 | public void setHeaderTextTypeface(Typeface mTitleTypeface) {
115 | this.mTitleTypeface = mTitleTypeface;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AnimatedPullToRefresh
2 | ***
3 | An simple general purpose UI library to add pull to refresh functionality with cool header text animation, which provides different customizations which allows to change header text, animation, color animation etc. Choose combination of your choice and rock your app screen.
4 | ***
5 |
6 | ## Feature
7 | * Easy integration
8 | * Easy customisation
9 | * Allows to customise text color, background color, animations etc of your choice.
10 | ***
11 |
12 | ## Demo
13 | * Simple demo 1
14 |
15 | 
16 |
17 | * Simple demo 2
18 |
19 | 
20 |
21 | * Custom fonts
22 |
23 | 
24 |
25 | * Customize animation
26 |
27 | 
28 |
29 | * Customize animation iteration
30 |
31 | 
32 |
33 |
34 | ***
35 | ## How to integrate
36 |
37 | Add it in your root build.gradle at the end of repositories:
38 |
39 | ````
40 | allprojects {
41 | repositories {
42 | ...
43 | maven { url 'https://jitpack.io' }
44 | }
45 | }
46 | ````
47 | Step 2. Add the dependency
48 |
49 | ````
50 | dependencies {
51 | implementation 'com.github.HarinTrivedi:AnimatedPullToRefresh-master:1.0.4'
52 | }
53 | ````
54 |
55 | ***
56 | ## How to use
57 | _**1. Inside layout xml**_
58 |
59 | Add namespace in layout like:
60 |
61 | xmlns:app="http://schemas.android.com/apk/res-auto"
62 |
63 | Use AnimatedPullToRefresh in xml layout like:
64 |
65 | // new font support
79 |
80 |
81 |
82 |
83 |
84 | **Attributes**
85 |
86 | * headerText : Text to display in header
87 | * animationSpeed : Slow / Fast
88 | * headerBackgroundColor : Background color of the header view
89 | * headerLoopAnimation : zoom / fade
90 | * headerTextAnimation : rotateCW(clockwise) / rotateACW(anti-clockwise) / fade / zoom
91 | * headerTextColor : Color of the text inside the header
92 | * headerTextFontPath : Custom font path from assets
93 |
94 | * headerTextColorAnimationEnabled : To enable / disable color changing animation of text
95 | * headerTextAnimIteration : No of iteration to perform on single character animation (default 1)
96 | * headerLoopAnimIteration : No of iteration to perform on whole text animation (default11)
97 | * headerTextFontFamily: Custom font family from font resource // New feature
98 |
99 | _**2. Inside Activity/Fragment**_
100 |
101 | ````
102 | ... implements AnimatedPullToRefreshLayout.OnRefreshListener {
103 | ...
104 | AnimatedPullToRefreshLayout mPullToRefreshLayout = (AnimatedPullToRefreshLayout) findViewById(R.id.pullToRefreshLayout);
105 | // Provide array of colors to add color animation of your choice
106 | mPullToRefreshLayout.setColorAnimationArray(new int[]{Color.CYAN, Color.RED, Color.YELLOW, Color.MAGENTA});
107 | // Set refresh listener
108 | mPullToRefreshLayout.setOnRefreshListener(this);
109 | ...
110 | }
111 |
112 | ````
113 |
114 | ## More is coming, Enjoy and post issues/suggestion if you love to use this 👍
115 |
116 | ***
117 |
118 | ## LICENSE
119 | ````
120 | Copyright 2020 Harry's Lab
121 |
122 | Licensed under the Apache License, Version 2.0 (the "License");
123 | you may not use this file except in compliance with the License.
124 | You may obtain a copy of the License at
125 |
126 | http://www.apache.org/licenses/LICENSE-2.0
127 |
128 | Unless required by applicable law or agreed to in writing, software
129 | distributed under the License is distributed on an "AS IS" BASIS,
130 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131 | See the License for the specific language governing permissions and
132 | limitations under the License.
133 | ````
134 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hlabexamples/animatedpulltorefresh/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.hlabexamples.animatedpulltorefresh
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.os.Handler
6 | import android.view.LayoutInflater
7 | import android.view.View
8 | import android.view.inputmethod.InputMethodManager
9 | import androidx.appcompat.app.AppCompatActivity
10 | import androidx.core.content.ContextCompat
11 | import androidx.databinding.DataBindingUtil
12 | import androidx.recyclerview.widget.LinearLayoutManager
13 | import androidx.recyclerview.widget.RecyclerView
14 | import com.google.android.material.floatingactionbutton.FloatingActionButton
15 | import com.hlab.animatedpulltorefresh.AnimatedPullToRefreshLayout
16 | import com.hlab.animatedpulltorefresh.AnimatedPullToRefreshLayout.OnRefreshListener
17 | import com.hlab.animatedpulltorefresh.enums.HeaderAnimSpeed
18 | import com.hlab.animatedpulltorefresh.enums.HeaderLoopAnim
19 | import com.hlab.animatedpulltorefresh.enums.HeaderTextAnim
20 | import com.hlab.fabrevealmenu.view.FABRevealMenu
21 | import com.hlabexamples.animatedpulltorefresh.databinding.LayoutOptionsBinding
22 |
23 | class MainActivity : AppCompatActivity(), OnRefreshListener {
24 | private lateinit var fabMenu: FABRevealMenu
25 | private lateinit var mPullToRefreshLayout: AnimatedPullToRefreshLayout
26 | private lateinit var menuBinding: LayoutOptionsBinding
27 |
28 | override fun onCreate(savedInstanceState: Bundle?) {
29 | super.onCreate(savedInstanceState)
30 | setContentView(R.layout.activity_main)
31 | val recyclerView = findViewById(R.id.recyclerView)
32 | recyclerView.layoutManager = LinearLayoutManager(this)
33 | recyclerView.adapter = ItemListAdapter(this)
34 | mPullToRefreshLayout = findViewById(R.id.pullToRefreshLayout)
35 | mPullToRefreshLayout.setColorAnimationArray(intArrayOf(Color.CYAN, Color.RED, Color.YELLOW, Color.MAGENTA))
36 | mPullToRefreshLayout.setOnRefreshListener(this)
37 |
38 | /*
39 | For FABRevealMenu checkout here:
40 | https://github.com/HarinTrivedi/FABRevealMenu-master
41 | */
42 | val fab = findViewById(R.id.fab)
43 | fabMenu = findViewById(R.id.fabMenu)
44 | fabMenu.bindAnchorView(fab)
45 | fabMenu.customView = addCustomView()
46 | }
47 |
48 | private fun addCustomView(): View {
49 | menuBinding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.layout_options, findViewById(R.id.parent), false)
50 | menuBinding.btnApply.setOnClickListener {
51 | configurePullToRefreshView()
52 | hideKeyboard()
53 | fabMenu.closeMenu()
54 | }
55 | return menuBinding.root
56 | }
57 |
58 | override fun onRefresh() {
59 | //todo: do something here when it starts to refresh
60 | Handler().postDelayed({ mPullToRefreshLayout.refreshComplete() }, 6000)
61 | }
62 |
63 | private fun configurePullToRefreshView() {
64 | mPullToRefreshLayout.setHeaderTextAnimIteration(menuBinding.spTextAnimIt.selectedItemPosition + 1)
65 | mPullToRefreshLayout.setHeaderLoopAnimIteration(menuBinding.spLoopAnimIt.selectedItemPosition + 1)
66 | when (menuBinding.spSpeed.selectedItemPosition) {
67 | 0 -> mPullToRefreshLayout.setAnimationSpeed(HeaderAnimSpeed.FAST)
68 | 1 -> mPullToRefreshLayout.setAnimationSpeed(HeaderAnimSpeed.SLOW)
69 | }
70 | when (menuBinding.spTextAnim.selectedItemPosition) {
71 | 0 -> mPullToRefreshLayout.setHeaderTextAnim(HeaderTextAnim.ROTATE_CW)
72 | 1 -> mPullToRefreshLayout.setHeaderTextAnim(HeaderTextAnim.ROTATE_ACW)
73 | 2 -> mPullToRefreshLayout.setHeaderTextAnim(HeaderTextAnim.FADE)
74 | 3 -> mPullToRefreshLayout.setHeaderTextAnim(HeaderTextAnim.ZOOM)
75 | }
76 | when (menuBinding.spLoopAnim.selectedItemPosition) {
77 | 0 -> mPullToRefreshLayout.setHeaderLoopAnim(HeaderLoopAnim.ZOOM)
78 | 1 -> mPullToRefreshLayout.setHeaderLoopAnim(HeaderLoopAnim.FADE)
79 | }
80 | mPullToRefreshLayout.setColorAnimEnable(menuBinding.swEnable.isChecked)
81 | if (menuBinding.rbLight.isChecked) {
82 | mPullToRefreshLayout.setHeaderBackgroundColor(ContextCompat.getColor(this, R.color.colorWhite))
83 | mPullToRefreshLayout.setHeaderTextColor(ContextCompat.getColor(this, R.color.colorLabelDark))
84 | } else if (menuBinding.rbDark.isChecked) {
85 | mPullToRefreshLayout.setHeaderBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimaryDark))
86 | mPullToRefreshLayout.setHeaderTextColor(ContextCompat.getColor(this, R.color.colorLabelLight))
87 | }
88 | mPullToRefreshLayout.setHeaderText(menuBinding.edtLabel.text.toString())
89 | }
90 |
91 | override fun onBackPressed() {
92 | if (fabMenu.isShowing) {
93 | fabMenu.closeMenu()
94 | } else {
95 | super.onBackPressed()
96 | }
97 | }
98 |
99 | private fun hideKeyboard() {
100 | val view = this.currentFocus
101 | if (view != null) {
102 | val imm = (getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager)
103 | imm.hideSoftInputFromWindow(view.windowToken, 0)
104 | }
105 | }
106 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_options.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
18 |
19 |
22 |
23 |
29 |
30 |
31 |
32 |
37 |
38 |
42 |
43 |
50 |
51 |
57 |
58 |
59 |
64 |
65 |
71 |
72 |
77 |
78 |
84 |
85 |
90 |
91 |
97 |
98 |
103 |
104 |
110 |
111 |
116 |
117 |
123 |
124 |
132 |
133 |
142 |
143 |
144 |
145 |
146 |
147 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/java/com/hlab/animatedpulltorefresh/CharacterAnimatorHeaderView.java:
--------------------------------------------------------------------------------
1 | package com.hlab.animatedpulltorefresh;
2 |
3 | import android.content.Context;
4 | import android.graphics.Typeface;
5 | import android.os.Handler;
6 | import android.util.AttributeSet;
7 | import android.view.Gravity;
8 | import android.widget.LinearLayout;
9 | import android.widget.TextView;
10 |
11 | import androidx.annotation.Nullable;
12 |
13 | import com.hlab.animatedpulltorefresh.enums.HeaderAnimSpeed;
14 | import com.hlab.animatedpulltorefresh.enums.HeaderLoopAnim;
15 | import com.hlab.animatedpulltorefresh.enums.HeaderState;
16 | import com.hlab.animatedpulltorefresh.enums.HeaderTextAnim;
17 | import com.hlab.animatedpulltorefresh.herlper.AnimationHelper;
18 | import com.hlab.animatedpulltorefresh.herlper.ViewHelper;
19 |
20 | import java.util.List;
21 |
22 | /**
23 | * Header view to manipulate characters views with provided customization on it
24 | */
25 | class CharacterAnimatorHeaderView extends LinearLayout implements AnimatedPullToRefreshLayout.AnimatedPullToRefreshHeaderLayout {
26 |
27 | private List characterViewList;
28 | private ViewHelper viewHelper;
29 | private AnimationHelper animationHelper;
30 |
31 | private boolean isInitialized = false;
32 | private int currentIndex = -1;
33 | private Handler mLoopHandler;
34 | private Runnable mLoopRunnable;
35 |
36 | private String headerText;
37 | private int headerBackgroundColor;
38 |
39 | public CharacterAnimatorHeaderView(Context context, @Nullable AttributeSet attrs) {
40 | super(context, attrs);
41 | }
42 |
43 | public CharacterAnimatorHeaderView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
44 | super(context, attrs, defStyleAttr);
45 | }
46 |
47 | public CharacterAnimatorHeaderView(Context context) {
48 | super(context);
49 | setWillNotDraw(false);
50 |
51 | viewHelper = new ViewHelper(context);
52 | animationHelper = new AnimationHelper();
53 | }
54 |
55 | /**
56 | * Initialize view
57 | */
58 | public void initView() {
59 | isInitialized = true;
60 | removeAllViews();
61 | setOrientation(VERTICAL);
62 | setGravity(Gravity.BOTTOM);
63 | setBackgroundColor(headerBackgroundColor);
64 |
65 | LinearLayout mContainer = viewHelper.generateContainerLayout();
66 | addView(mContainer);
67 |
68 | characterViewList = viewHelper.generateCharacterViewList(headerText);
69 | for (TextView textView : characterViewList) {
70 | mContainer.addView(textView);
71 | }
72 |
73 | setupAnimation();
74 | }
75 |
76 | /**
77 | * Initialization animations
78 | */
79 | public void setupAnimation() {
80 | mLoopHandler = new Handler();
81 | mLoopRunnable = new Runnable() {
82 | @Override
83 | public void run() {
84 | currentIndex++;
85 | if (currentIndex >= characterViewList.size()) {
86 | currentIndex = -1;
87 | if (!animationHelper.shouldContinueTextIteration())
88 | playTextAnimation();
89 | else
90 | mLoopHandler.postDelayed(mLoopRunnable, 20);
91 | } else {
92 | if (!animationHelper.shouldContinueLoopIteration())
93 | playLoopAnimation();
94 | else
95 | mLoopHandler.postDelayed(mLoopRunnable, 20);
96 | }
97 | }
98 | };
99 | }
100 |
101 | /**
102 | * Start main animation
103 | */
104 | private void playLoopAnimation() {
105 | long wait = animationHelper.applyTextAnimation(characterViewList.get(currentIndex));
106 | mLoopHandler.postDelayed(mLoopRunnable, wait);
107 | }
108 |
109 | /**
110 | * Start character animation
111 | */
112 | private void playTextAnimation() {
113 | long wait = animationHelper.applyLoopAnimation(characterViewList);
114 | mLoopHandler.postDelayed(mLoopRunnable, wait);
115 | }
116 |
117 | @Override
118 | public void onStateChange(HeaderState headerState, HeaderState lastHeaderState) {
119 | if (headerState == lastHeaderState) {
120 | return;
121 | }
122 |
123 | switch (headerState) {
124 | case HEADER_STATE_NORMAL:
125 | // if (lastStateCode == AnimatedPullToRefreshLayout.HeaderState.HEADER_STATE_READY) {
126 | // }
127 | // if (lastStateCode == AnimatedPullToRefreshLayout.HeaderState.HEADER_STATE_REFRESHING) {
128 | // }
129 | break;
130 | case HEADER_STATE_READY:
131 | break;
132 | case HEADER_STATE_REFRESHING:
133 | mLoopHandler.post(mLoopRunnable);
134 | break;
135 | case HEADER_STATE_COMPLETE:
136 | mLoopHandler.removeCallbacks(mLoopRunnable);
137 | break;
138 | }
139 | }
140 |
141 | /**
142 | * Set color animation array
143 | */
144 | public void setColorAnimationArray(int[] colorAnimationArray) {
145 | animationHelper.setColorAnimationArray(colorAnimationArray);
146 | }
147 |
148 | /**
149 | * Set header text
150 | */
151 | public void setHeaderText(String headerText) {
152 | this.headerText = headerText;
153 | }
154 |
155 | /**
156 | * Set header background color
157 | */
158 | public void setHeaderBackgroundColor(int headerBackgroundColor) {
159 | this.headerBackgroundColor = headerBackgroundColor;
160 | setBackgroundColor(headerBackgroundColor);
161 | }
162 |
163 | /**
164 | * Set header character size
165 | */
166 | public void setHeaderTextSize(int headerTextSize) {
167 | viewHelper.setHeaderTextSize(headerTextSize);
168 | if (isInitialized)
169 | initView();
170 | }
171 |
172 | /**
173 | * Set header character color
174 | */
175 | public void setHeaderTextColor(int headerTextColor) {
176 | viewHelper.setHeaderTextColor(headerTextColor);
177 | animationHelper.setOriginalColor(headerTextColor);
178 | if (isInitialized)
179 | initView();
180 | }
181 |
182 | private void setHeaderPaddingTop(int headerPaddingTop) {
183 | viewHelper.setHeaderPaddingTop(headerPaddingTop);
184 | }
185 |
186 | private void setHeaderPaddingBottom(int headerPaddingBottom) {
187 | viewHelper.setHeaderPaddingBottom(headerPaddingBottom);
188 | }
189 |
190 | /**
191 | * Set character animation
192 | */
193 | public void setHeaderTextAnim(HeaderTextAnim headerTextAnim) {
194 | animationHelper.setHeaderTextAnim(headerTextAnim);
195 | }
196 |
197 | /**
198 | * Set loop animation
199 | */
200 | public void setHeaderLoopAnim(HeaderLoopAnim headerLoopAnim) {
201 | animationHelper.setHeaderLoopAnim(headerLoopAnim);
202 | }
203 |
204 | /**
205 | * Set character animation iteration count
206 | */
207 | public void setHeaderTextAnimIteration(int headerTextAnimIteration) {
208 | animationHelper.setHeaderTextAnimIteration(headerTextAnimIteration);
209 | }
210 |
211 | /**
212 | * Set loop animation iteration count
213 | */
214 | public void setHeaderLoopAnimIteration(int headerLoopAnimIteration) {
215 | animationHelper.setHeaderLoopAnimIteration(headerLoopAnimIteration);
216 | }
217 |
218 | /**
219 | * Enable / Disable color animation
220 | */
221 | public void setColorAnimEnable(boolean colorAnimEnable) {
222 | animationHelper.setColorAnimEnable(colorAnimEnable);
223 | }
224 |
225 | /**
226 | * Set animation speed
227 | */
228 | public void setAnimationSpeed(HeaderAnimSpeed animationSpeed) {
229 | animationHelper.setAnimationSpeed(animationSpeed);
230 | }
231 |
232 | /**
233 | * Set custom font typeface
234 | */
235 | public void setHeaderTextTypeface(Typeface mTitleTypeface) {
236 | if (mTitleTypeface != null) {
237 | viewHelper.setHeaderTextTypeface(mTitleTypeface);
238 | if (isInitialized)
239 | initView();
240 | }
241 | }
242 | }
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/java/com/hlab/animatedpulltorefresh/herlper/AnimationHelper.java:
--------------------------------------------------------------------------------
1 | package com.hlab.animatedpulltorefresh.herlper;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ArgbEvaluator;
6 | import android.animation.ValueAnimator;
7 | import android.graphics.Color;
8 | import android.view.animation.AlphaAnimation;
9 | import android.view.animation.Animation;
10 | import android.view.animation.AnimationSet;
11 | import android.view.animation.Interpolator;
12 | import android.view.animation.RotateAnimation;
13 | import android.view.animation.ScaleAnimation;
14 | import android.widget.TextView;
15 |
16 | import androidx.interpolator.view.animation.LinearOutSlowInInterpolator;
17 |
18 | import com.hlab.animatedpulltorefresh.enums.HeaderAnimSpeed;
19 | import com.hlab.animatedpulltorefresh.enums.HeaderLoopAnim;
20 | import com.hlab.animatedpulltorefresh.enums.HeaderTextAnim;
21 |
22 | import java.util.List;
23 |
24 | /**
25 | * Helper class to handle animations
26 | */
27 | public class AnimationHelper {
28 |
29 | private long CHARACTER_ANIM_DURATION = 50;
30 | private Interpolator interpolator;
31 | private int originalColor = Color.BLACK;
32 |
33 | //colors to animate on each character
34 | private int[] colorAnimationArray;
35 | private int colorIndex = 0;
36 | //no of text animation iteration
37 | private int currentTextIteration = 0;
38 | //no of loop animation iteration
39 | private int currentLoopIteration = 0;
40 |
41 | private float SCALE_AMOUNT = 1.2f;
42 | private float FADE_MOUNT = 0.5f;
43 | private float ROTATION_ANGLE = 20.0f;
44 |
45 | // Animation attributes
46 | private HeaderTextAnim headerTextAnim = HeaderTextAnim.ROTATE_CW;
47 | private HeaderLoopAnim headerLoopAnim = HeaderLoopAnim.ZOOM;
48 | private HeaderAnimSpeed headerAnimSpeed = HeaderAnimSpeed.FAST;
49 | private int headerTextAnimIteration = 1;
50 | private int headerLoopAnimIteration = 1;
51 | private boolean isColorAnimEnable = true;
52 |
53 | public AnimationHelper() {
54 | interpolator = new LinearOutSlowInInterpolator();
55 | colorAnimationArray = new int[]{Color.CYAN};
56 | }
57 |
58 | /**
59 | * Start animations on characters
60 | */
61 | public long applyTextAnimation(final TextView target) {
62 |
63 | final long duration = (long) (CHARACTER_ANIM_DURATION * 2.1f);
64 |
65 | if (isColorAnimEnable && colorAnimationArray != null) {
66 | final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), originalColor, colorAnimationArray[colorIndex]);
67 | colorAnimation.setDuration(duration);
68 | colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
69 | @Override
70 | public void onAnimationUpdate(ValueAnimator animator) {
71 | target.setTextColor((Integer) animator.getAnimatedValue());
72 | }
73 | });
74 | colorAnimation.addListener(new AnimatorListenerAdapter() {
75 | @Override
76 | public void onAnimationEnd(Animator animation) {
77 | super.onAnimationEnd(animation);
78 | target.setTextColor(originalColor);
79 | }
80 | });
81 | colorAnimation.start();
82 |
83 | // loop though color array
84 | colorIndex = (colorIndex + 1) % colorAnimationArray.length;
85 | }
86 |
87 | AnimationSet set = new AnimationSet(true);
88 | if (headerTextAnim == HeaderTextAnim.ROTATE_CW) {
89 | ROTATION_ANGLE = 20.0f;
90 | addTextRotateAnimations(set);
91 | } else if (headerTextAnim == HeaderTextAnim.ROTATE_ACW) {
92 | ROTATION_ANGLE = -20.0f;
93 | addTextRotateAnimations(set);
94 | } else if (headerTextAnim == HeaderTextAnim.FADE) {
95 | addTextFadeAnimations(set);
96 | } else if (headerTextAnim == HeaderTextAnim.ZOOM) {
97 | addTextZoomAnimations(set);
98 | }
99 | target.startAnimation(set);
100 |
101 | // text anim iteration
102 | currentTextIteration = (currentTextIteration + 1) % headerTextAnimIteration;
103 |
104 | return duration + CHARACTER_ANIM_DURATION;
105 | }
106 |
107 | // Rotation
108 | private void addTextRotateAnimations(AnimationSet set) {
109 | RotateAnimation mRotateUpAnim = new RotateAnimation(0.0f, ROTATION_ANGLE, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
110 | mRotateUpAnim.setDuration(CHARACTER_ANIM_DURATION);
111 | set.addAnimation(mRotateUpAnim);
112 | RotateAnimation mRotateDownAnim = new RotateAnimation(ROTATION_ANGLE, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
113 | mRotateDownAnim.setDuration(CHARACTER_ANIM_DURATION);
114 | mRotateDownAnim.setStartOffset(CHARACTER_ANIM_DURATION + 20);
115 | mRotateDownAnim.setFillAfter(true);
116 | set.addAnimation(mRotateDownAnim);
117 | set.setInterpolator(interpolator);
118 | }
119 |
120 | // Fade
121 | private void addTextFadeAnimations(AnimationSet set) {
122 | AlphaAnimation mFadeInAnim = new AlphaAnimation(1, FADE_MOUNT);
123 | mFadeInAnim.setDuration(CHARACTER_ANIM_DURATION);
124 | set.addAnimation(mFadeInAnim);
125 | AlphaAnimation mFadeOutAnim = new AlphaAnimation(FADE_MOUNT, 1);
126 | mFadeOutAnim.setDuration(CHARACTER_ANIM_DURATION);
127 | mFadeOutAnim.setStartOffset(CHARACTER_ANIM_DURATION + 20);
128 | mFadeOutAnim.setFillAfter(true);
129 | set.addAnimation(mFadeOutAnim);
130 | set.setInterpolator(interpolator);
131 | }
132 |
133 | // Zoom
134 | private void addTextZoomAnimations(AnimationSet set) {
135 | ScaleAnimation mScaleAnim = new ScaleAnimation(1, SCALE_AMOUNT, 1f, SCALE_AMOUNT, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
136 | mScaleAnim.setDuration(CHARACTER_ANIM_DURATION);
137 | set.addAnimation(mScaleAnim);
138 | ScaleAnimation mScaleDownAnim = new ScaleAnimation(1, SCALE_AMOUNT, 1f, SCALE_AMOUNT, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
139 | mScaleDownAnim.setDuration(CHARACTER_ANIM_DURATION);
140 | mScaleDownAnim.setStartOffset(CHARACTER_ANIM_DURATION + 20);
141 | mScaleDownAnim.setFillAfter(true);
142 | set.addAnimation(mScaleDownAnim);
143 | set.setInterpolator(interpolator);
144 | }
145 |
146 | /**
147 | * Start Loop animation on given list of characters
148 | */
149 | public long applyLoopAnimation(List targetList) {
150 | long duration = (long) (CHARACTER_ANIM_DURATION * 5f);
151 | for (final TextView target : targetList) {
152 | AnimationSet set = new AnimationSet(true);
153 | if (headerLoopAnim == HeaderLoopAnim.ZOOM) {
154 | addLoopScaleAnimations(duration, set);
155 | } else if (headerLoopAnim == HeaderLoopAnim.FADE) {
156 | addLoopFadeAnimations(duration, set);
157 | }
158 | target.startAnimation(set);
159 | }
160 |
161 | // loop anim iteration
162 | currentLoopIteration = (currentLoopIteration + 1) % headerLoopAnimIteration;
163 | return (long) ((duration * 2.1f) + 300);
164 | }
165 |
166 | // add scale in loop
167 | private void addLoopScaleAnimations(long duration, AnimationSet set) {
168 | ScaleAnimation mScaleAnim = new ScaleAnimation(1, SCALE_AMOUNT, 1f, SCALE_AMOUNT, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
169 | mScaleAnim.setDuration(duration);
170 | set.addAnimation(mScaleAnim);
171 | ScaleAnimation mScaleDownAnim = new ScaleAnimation(SCALE_AMOUNT, 1, SCALE_AMOUNT, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
172 | mScaleDownAnim.setDuration(duration);
173 | mScaleDownAnim.setStartOffset(duration + 50);
174 | set.addAnimation(mScaleDownAnim);
175 | set.setInterpolator(interpolator);
176 | }
177 |
178 | // add fade in loop
179 | private void addLoopFadeAnimations(long duration, AnimationSet set) {
180 | AlphaAnimation mFadeInAnim = new AlphaAnimation(1, FADE_MOUNT);
181 | mFadeInAnim.setDuration(duration);
182 | set.addAnimation(mFadeInAnim);
183 | AlphaAnimation mFadeOutAnim = new AlphaAnimation(FADE_MOUNT, 1);
184 | mFadeOutAnim.setDuration(duration);
185 | mFadeOutAnim.setStartOffset(duration + 50);
186 | set.addAnimation(mFadeOutAnim);
187 | set.setInterpolator(interpolator);
188 | }
189 |
190 | public boolean shouldContinueTextIteration() {
191 | return currentTextIteration != 0;
192 | }
193 |
194 | public boolean shouldContinueLoopIteration() {
195 | return currentLoopIteration != 0;
196 | }
197 |
198 | public void setColorAnimationArray(int[] colorAnimationArray) {
199 | this.colorAnimationArray = colorAnimationArray;
200 | }
201 |
202 | public void setOriginalColor(int originalColor) {
203 | this.originalColor = originalColor;
204 | }
205 |
206 | public HeaderTextAnim getHeaderTextAnim() {
207 | return headerTextAnim;
208 | }
209 |
210 | public void setHeaderTextAnim(HeaderTextAnim headerTextAnim) {
211 | this.headerTextAnim = headerTextAnim;
212 | }
213 |
214 | public HeaderLoopAnim getHeaderLoopAnim() {
215 | return headerLoopAnim;
216 | }
217 |
218 | public void setHeaderLoopAnim(HeaderLoopAnim headerLoopAnim) {
219 | this.headerLoopAnim = headerLoopAnim;
220 | }
221 |
222 | public int getHeaderTextAnimIteration() {
223 | return headerTextAnimIteration;
224 | }
225 |
226 | public void setHeaderTextAnimIteration(int headerTextAnimIteration) {
227 | this.headerTextAnimIteration = headerTextAnimIteration;
228 | }
229 |
230 | public int getHeaderLoopAnimIteration() {
231 | return headerLoopAnimIteration;
232 | }
233 |
234 | public void setHeaderLoopAnimIteration(int headerLoopAnimIteration) {
235 | this.headerLoopAnimIteration = headerLoopAnimIteration;
236 | }
237 |
238 | public boolean isColorAnimEnable() {
239 | return isColorAnimEnable;
240 | }
241 |
242 | public void setColorAnimEnable(boolean colorAnimEnable) {
243 | isColorAnimEnable = colorAnimEnable;
244 | }
245 |
246 | public void setAnimationSpeed(HeaderAnimSpeed animationSpeed) {
247 | headerAnimSpeed = animationSpeed;
248 | if (animationSpeed == HeaderAnimSpeed.FAST)
249 | CHARACTER_ANIM_DURATION = 50;
250 | else if (animationSpeed == HeaderAnimSpeed.SLOW)
251 | CHARACTER_ANIM_DURATION = 100;
252 | }
253 | }
254 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2017 Harry's Lab
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/AnimatedPullToRefreshLib/src/main/java/com/hlab/animatedpulltorefresh/AnimatedPullToRefreshLayout.java:
--------------------------------------------------------------------------------
1 | package com.hlab.animatedpulltorefresh;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Rect;
7 | import android.graphics.Typeface;
8 | import android.os.Build;
9 | import android.util.AttributeSet;
10 | import android.util.DisplayMetrics;
11 | import android.view.MotionEvent;
12 | import android.view.View;
13 | import android.view.ViewConfiguration;
14 | import android.view.ViewGroup;
15 | import android.view.animation.Animation;
16 | import android.view.animation.Transformation;
17 |
18 | import androidx.core.content.res.ResourcesCompat;
19 | import androidx.core.view.ViewCompat;
20 |
21 | import com.hlab.animatedpulltorefresh.enums.HeaderAnimSpeed;
22 | import com.hlab.animatedpulltorefresh.enums.HeaderLoopAnim;
23 | import com.hlab.animatedpulltorefresh.enums.HeaderState;
24 | import com.hlab.animatedpulltorefresh.enums.HeaderTextAnim;
25 |
26 | import static com.hlab.animatedpulltorefresh.herlper.Constants.MAX_SWIPE_DISTANCE_FACTOR;
27 | import static com.hlab.animatedpulltorefresh.herlper.Constants.REFRESH_COMPLETE_DURATION;
28 | import static com.hlab.animatedpulltorefresh.herlper.Constants.RESISTANCE_FACTOR;
29 | import static com.hlab.animatedpulltorefresh.herlper.Constants.RETURN_DURATION;
30 | import static com.hlab.animatedpulltorefresh.herlper.Constants.RETURN_TO_HEADER_DURATION;
31 | import static com.hlab.animatedpulltorefresh.herlper.Constants.RETURN_TO_TOP_DURATION;
32 | import static com.hlab.animatedpulltorefresh.herlper.Constants.SWIPE_REFRESH_TRIGGER_DISTANCE;
33 |
34 | /**
35 | * AnimatedPullToRefreshLayout
36 | * View to add pull to refresh functionality on any child view
37 | * Also adds character header animator view with multiple customizations
38 | */
39 | public class AnimatedPullToRefreshLayout extends ViewGroup {
40 |
41 | private final Animation mAnimateStayComplete = new Animation() {
42 | @Override
43 | public void applyTransformation(float interpolatedTime, Transformation t) {
44 | }
45 | };
46 | private HeaderState currentHeaderState = HeaderState.HEADER_STATE_NORMAL;
47 | private HeaderState lastHeaderState = HeaderState.HEADER_STATE_DEFAULT;
48 | private int mTargetOriginalTop;
49 | private int mFrom;
50 | private int mTouchSlop;
51 | private int mDistanceToTriggerSync = -1;
52 | private int mCurrentTargetOffsetTop = 0;
53 | private float mPrevY;
54 | private int mTriggerOffset = 0;
55 | private boolean mInReturningAnimation;
56 | private final AnimationListener mReturningAnimationListener = new AnimationListener() {
57 | @Override
58 | public void onAnimationEnd(Animation animation) {
59 | // Once the target content has returned to its start position, reset
60 | // the target offset to 0
61 | // mCurrentTargetOffsetTop = 0;
62 | mInReturningAnimation = false;
63 | }
64 | };
65 | private boolean mRefreshing = false;
66 | private boolean isHorizontalScroll;
67 | private boolean mCheckValidMotionFlag = true;
68 | private OnRefreshListener mListener;
69 | private MotionEvent mDownEvent;
70 | private RefreshCheckHandler mRefreshCheckHandler;
71 | private ScrollUpHandler mScrollUpHandler;
72 | private View mHeadview;
73 | private View mTarget = null;
74 | private final Runnable mStayRefreshCompletePosition = new Runnable() {
75 | @Override
76 | public void run() {
77 | animateStayComplete(mStayCompleteListener);
78 | }
79 | };
80 | private final Animation mAnimateToStartPosition = new Animation() {
81 | @Override
82 | public void applyTransformation(float interpolatedTime, Transformation t) {
83 | int targetTop = mTargetOriginalTop;
84 | if (mFrom != mTargetOriginalTop) {
85 | targetTop = (mFrom + (int) ((mTargetOriginalTop - mFrom) * interpolatedTime));
86 | }
87 | int offset = targetTop - mTarget.getTop();
88 | final int currentTop = mTarget.getTop();
89 | if (offset + currentTop < 0) {
90 | offset = 0 - currentTop;
91 | }
92 | setTargetOffsetTop(offset, true);
93 | }
94 | };
95 | private final Runnable mReturnToStartPosition = new Runnable() {
96 | @Override
97 | public void run() {
98 | mInReturningAnimation = true;
99 | animateOffsetToStartPosition(mTarget.getTop(), mReturningAnimationListener);
100 | }
101 | };
102 | private final AnimationListener mStayCompleteListener = new AnimationListener() {
103 | @Override
104 | public void onAnimationEnd(Animation animation) {
105 | mReturnToStartPosition.run();
106 | mRefreshing = false;
107 | }
108 | };
109 | // Cancel the refresh gesture and animate everything back to its original state.
110 | private final Runnable mCancel = new Runnable() {
111 | @Override
112 | public void run() {
113 | mInReturningAnimation = true;
114 | // Timeout fired since the user last moved their finger; animate the
115 | // trigger to 0 and put the target back at its original position
116 | animateOffsetToStartPosition(mTarget.getTop(), mReturningAnimationListener);
117 | }
118 | };
119 | private final Animation mAnimateToTriggerPosition = new Animation() {
120 | @Override
121 | public void applyTransformation(float interpolatedTime, Transformation t) {
122 | int targetTop = mDistanceToTriggerSync;
123 | if (mFrom > mDistanceToTriggerSync) {
124 | targetTop = (mFrom + (int) ((mDistanceToTriggerSync - mFrom) * interpolatedTime));
125 | }
126 | int offset = targetTop - mTarget.getTop();
127 | final int currentTop = mTarget.getTop();
128 | if (offset + currentTop < 0) {
129 | offset = 0 - currentTop;
130 | }
131 | setTargetOffsetTop(offset, true);
132 | }
133 | };
134 | private final Runnable mReturnToTrigerPosition = new Runnable() {
135 | @Override
136 | public void run() {
137 | mInReturningAnimation = true;
138 | animateOffsetToTrigerPosition(mTarget.getTop(), mReturningAnimationListener);
139 | }
140 | };
141 | private CharacterAnimatorHeaderView headerView;
142 |
143 | public AnimatedPullToRefreshLayout(Context context) {
144 | this(context, null);
145 | }
146 |
147 | public AnimatedPullToRefreshLayout(Context context, AttributeSet attrs) {
148 | this(context, attrs, 0);
149 | }
150 |
151 | public AnimatedPullToRefreshLayout(Context context, AttributeSet attrs, int defStyle) {
152 | super(context, attrs, defStyle);
153 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
154 | setWillNotDraw(false);
155 |
156 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedPullToRefreshLayout);
157 | if (a != null) {
158 | String headerText = a.getString(R.styleable.AnimatedPullToRefreshLayout_headerText);
159 | int headerTextSize = a.getDimensionPixelSize(R.styleable.AnimatedPullToRefreshLayout_headerTextSize, (int) getResources().getDimension(R.dimen.headerTextSize));
160 | int headerTextColor = a.getColor(R.styleable.AnimatedPullToRefreshLayout_headerTextColor, getColor(android.R.color.darker_gray));
161 | int headerBackgroundColor = a.getColor(R.styleable.AnimatedPullToRefreshLayout_headerBackgroundColor, getColor(android.R.color.transparent));
162 | HeaderAnimSpeed headerAnimSpeed = HeaderAnimSpeed.fromId(a.getInt(R.styleable.AnimatedPullToRefreshLayout_animationSpeed, HeaderAnimSpeed.FAST.getSpeed()));
163 | HeaderTextAnim headerTextAnim = HeaderTextAnim.fromId(a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerTextAnimation, HeaderTextAnim.ROTATE_CW.getAnimType()));
164 | HeaderLoopAnim headerLoopAnim = HeaderLoopAnim.fromId(a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerLoopAnimation, HeaderLoopAnim.ZOOM.getAnimType()));
165 | int headerTextAnimIteration = a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerTextAnimIteration, HeaderTextAnim.ROTATE_CW.getAnimType());
166 | int headerLoopAnimIteration = a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerLoopAnimIteration, HeaderLoopAnim.ZOOM.getAnimType());
167 | boolean isColorAnimEnabled = a.getBoolean(R.styleable.AnimatedPullToRefreshLayout_headerTextColorAnimationEnabled, true);
168 | Typeface mTitleTypeface = null;
169 | //Font
170 | if (a.hasValue(R.styleable.AnimatedPullToRefreshLayout_headerTextFontFamily)) {
171 | int fontId = a.getResourceId(R.styleable.AnimatedPullToRefreshLayout_headerTextFontFamily, -1);
172 | if (fontId != -1)
173 | mTitleTypeface = ResourcesCompat.getFont(context, fontId);
174 | }
175 |
176 | a.recycle();
177 |
178 | if (isInEditMode())
179 | return;
180 |
181 | // adding header layout : important
182 | headerView = new CharacterAnimatorHeaderView(getContext());
183 | headerView.setHeaderText(headerText);
184 | headerView.setHeaderTextSize(headerTextSize);
185 | headerView.setHeaderTextColor(headerTextColor);
186 | headerView.setHeaderBackgroundColor(headerBackgroundColor);
187 | headerView.setHeaderTextAnim(headerTextAnim);
188 | headerView.setHeaderLoopAnim(headerLoopAnim);
189 | headerView.setHeaderTextAnimIteration(headerTextAnimIteration);
190 | headerView.setHeaderLoopAnimIteration(headerLoopAnimIteration);
191 | headerView.setColorAnimEnable(isColorAnimEnabled);
192 | headerView.setAnimationSpeed(headerAnimSpeed);
193 | headerView.setHeaderTextTypeface(mTitleTypeface);
194 |
195 | setHeaderView(headerView);
196 | }
197 |
198 | }
199 |
200 | private void animateStayComplete(AnimationListener listener) {
201 | mAnimateStayComplete.reset();
202 | mAnimateStayComplete.setDuration(REFRESH_COMPLETE_DURATION);
203 | mAnimateStayComplete.setAnimationListener(listener);
204 | mTarget.startAnimation(mAnimateStayComplete);
205 | }
206 |
207 | private void animateOffsetToTrigerPosition(int from, AnimationListener listener) {
208 | mFrom = from;
209 | mAnimateToTriggerPosition.reset();
210 | mAnimateToTriggerPosition.setDuration(RETURN_TO_HEADER_DURATION);
211 | mAnimateToTriggerPosition.setAnimationListener(listener);
212 | mTarget.startAnimation(mAnimateToTriggerPosition);
213 | }
214 |
215 | private void animateOffsetToStartPosition(int from, AnimationListener listener) {
216 | mFrom = from;
217 | mAnimateToStartPosition.reset();
218 | mAnimateToStartPosition.setDuration(RETURN_TO_TOP_DURATION);
219 | mAnimateToStartPosition.setAnimationListener(listener);
220 | mTarget.startAnimation(mAnimateToStartPosition);
221 | }
222 |
223 | /**
224 | * Whether it is possible for the view of this layout to scroll up.
225 | */
226 | private boolean canViewScrollUp(View view, MotionEvent event) {
227 | boolean ret;
228 |
229 | event.offsetLocation(view.getScrollX() - view.getLeft(), view.getScrollY() - view.getTop());
230 | if (mScrollUpHandler != null) {
231 | boolean canViewScrollUp = mScrollUpHandler.canScrollUp(view);
232 | if (canViewScrollUp)
233 | return true;
234 | }
235 |
236 | ret = ViewCompat.canScrollVertically(view, -1) || canChildrenScrollUp(view, event);
237 | return ret;
238 | }
239 |
240 | /**
241 | * Whether it is possible for the child view of this layout to scroll up.
242 | */
243 | private boolean canChildrenScrollUp(View view, MotionEvent event) {
244 | if (view instanceof ViewGroup) {
245 | final ViewGroup viewgroup = (ViewGroup) view;
246 | int count = viewgroup.getChildCount();
247 | for (int i = 0; i < count; ++i) {
248 | View child = viewgroup.getChildAt(i);
249 | Rect bounds = new Rect();
250 | child.getHitRect(bounds);
251 | if (bounds.contains((int) event.getX(), (int) event.getY())) {
252 | return canViewScrollUp(child, event);
253 | }
254 | }
255 | }
256 |
257 | return false;
258 | }
259 |
260 | private void setHeaderView(View headerView) {
261 | if (mHeadview != null) {
262 | if (mHeadview == headerView)
263 | return;
264 | removeView(mHeadview);
265 | }
266 | mHeadview = headerView;
267 |
268 | addView(mHeadview, new MarginLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
269 |
270 | this.headerView.initView();
271 | }
272 |
273 | @Override
274 | public void onAttachedToWindow() {
275 | super.onAttachedToWindow();
276 | removeCallbacks(mCancel);
277 | removeCallbacks(mReturnToStartPosition);
278 | }
279 |
280 | @Override
281 | public void onDetachedFromWindow() {
282 | super.onDetachedFromWindow();
283 | removeCallbacks(mReturnToStartPosition);
284 | removeCallbacks(mCancel);
285 | }
286 |
287 | /**
288 | * Set the listener to be notified when a refresh is executed via the swipe gesture.
289 | */
290 | public void setOnRefreshListener(OnRefreshListener listener) {
291 | mListener = listener;
292 | }
293 |
294 | private void setRefreshState(HeaderState state) {
295 | currentHeaderState = state;
296 | ((AnimatedPullToRefreshHeaderLayout) mHeadview).onStateChange(currentHeaderState, lastHeaderState);
297 | lastHeaderState = state;
298 | }
299 |
300 | private void updateHeadViewState(boolean changeHeightOnly) {
301 | if (changeHeightOnly) {
302 | setRefreshState(currentHeaderState);
303 | } else {
304 | if (mTarget.getTop() > mDistanceToTriggerSync) {
305 | setRefreshState(HeaderState.HEADER_STATE_READY);
306 | } else {
307 | setRefreshState(HeaderState.HEADER_STATE_NORMAL);
308 | }
309 | }
310 | }
311 |
312 | public void refreshComplete() {
313 | setRefreshing(false);
314 | }
315 |
316 | /**
317 | * Whether the RefreshView is actively showing refresh progress.
318 | */
319 | public boolean isRefreshing() {
320 | return mRefreshing;
321 | }
322 |
323 | /**
324 | * Notify the widget that refresh state has changed. Do not call this when
325 | * refresh is executed by a swipe gesture.
326 | */
327 | protected void setRefreshing(boolean refreshing) {
328 | if (mRefreshing != refreshing) {
329 | ensureTarget();
330 | mRefreshing = refreshing;
331 | if (mRefreshing) {
332 | // if (refreshMode == REFRESH_MODE_PULL) {
333 | mReturnToTrigerPosition.run();
334 | // }
335 |
336 | } else {
337 | // keep refreshing state for refresh complete
338 | // if (refreshMode == REFRESH_MODE_PULL) {
339 | mRefreshing = true;
340 | removeCallbacks(mReturnToStartPosition);
341 | removeCallbacks(mCancel);
342 | mStayRefreshCompletePosition.run();
343 | // }
344 | setRefreshState(HeaderState.HEADER_STATE_COMPLETE);
345 | }
346 | }
347 | }
348 |
349 | private View getContentView() {
350 | return getChildAt(0) == mHeadview ? getChildAt(1) : getChildAt(0);
351 | }
352 |
353 | private void ensureTarget() {
354 | if (mTarget == null) {
355 | if (getChildCount() > 2 && !isInEditMode()) {
356 | throw new IllegalStateException(
357 | "AnimatedPullToRefresh can host ONLY one direct child");
358 | }
359 | mTarget = getContentView();
360 | mTargetOriginalTop = mTarget.getTop();
361 |
362 | }
363 | if (mDistanceToTriggerSync == -1) {
364 | if (getParent() != null && ((View) getParent()).getHeight() > 0) {
365 | final DisplayMetrics metrics = getResources().getDisplayMetrics();
366 | mTriggerOffset = (int) (SWIPE_REFRESH_TRIGGER_DISTANCE * metrics.density);
367 | mDistanceToTriggerSync = (int) Math.min(
368 | ((View) getParent()).getHeight() * MAX_SWIPE_DISTANCE_FACTOR,
369 | mTriggerOffset + mTargetOriginalTop);
370 | }
371 | }
372 | }
373 |
374 | @Override
375 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
376 | if (getChildCount() == 0) {
377 | return;
378 | }
379 | MarginLayoutParams lp = (MarginLayoutParams) mHeadview.getLayoutParams();
380 | final int headViewLeft = getPaddingLeft() + lp.leftMargin;
381 | final int headViewTop = mCurrentTargetOffsetTop - mHeadview.getMeasuredHeight() + getPaddingTop() + lp.topMargin;
382 | final int headViewRight = headViewLeft + mHeadview.getMeasuredWidth();
383 | final int headViewBottom = headViewTop + mHeadview.getMeasuredHeight();
384 | mHeadview.layout(headViewLeft, headViewTop, headViewRight, headViewBottom);
385 | final View content = getContentView();
386 | lp = (MarginLayoutParams) content.getLayoutParams();
387 | final int childLeft = getPaddingLeft() + lp.leftMargin;
388 | final int childTop = mCurrentTargetOffsetTop + getPaddingTop() + lp.topMargin;
389 | final int childRight = childLeft + content.getMeasuredWidth();
390 | final int childBottom = childTop + content.getMeasuredHeight();
391 | content.layout(childLeft, childTop, childRight, childBottom);
392 | }
393 |
394 | @Override
395 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
396 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
397 |
398 | if (getChildCount() > 2 && !isInEditMode()) {
399 | throw new IllegalStateException("AnimatedPullToRefresh can host one child content view.");
400 | }
401 |
402 | measureChildWithMargins(mHeadview, widthMeasureSpec, 0, heightMeasureSpec, 0);
403 |
404 | final View content = getContentView();
405 | if (getChildCount() > 0) {
406 | MarginLayoutParams lp = (MarginLayoutParams) content.getLayoutParams();
407 | content.measure(
408 | MeasureSpec.makeMeasureSpec(getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY),
409 | MeasureSpec.makeMeasureSpec(getMeasuredHeight() - getPaddingTop() - getPaddingBottom() - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY));
410 | }
411 | }
412 |
413 | @Override
414 | protected boolean checkLayoutParams(LayoutParams p) {
415 | return p instanceof MarginLayoutParams;
416 | }
417 |
418 | @Override
419 | protected LayoutParams generateDefaultLayoutParams() {
420 | return new MarginLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
421 | }
422 |
423 | @Override
424 | protected LayoutParams generateLayoutParams(LayoutParams p) {
425 | return new MarginLayoutParams(p);
426 | }
427 |
428 | @Override
429 | public LayoutParams generateLayoutParams(AttributeSet attrs) {
430 | return new MarginLayoutParams(getContext(), attrs);
431 | }
432 |
433 | @Override
434 | public void addView(View child, int index, LayoutParams params) {
435 | if (getChildCount() > 1 && !isInEditMode()) {
436 | throw new IllegalStateException("AnimatedPullToRefresh can host ONLY one child content view");
437 | }
438 | super.addView(child, index, params);
439 | }
440 |
441 | private boolean checkCanDoRefresh() {
442 | return mRefreshCheckHandler == null || mRefreshCheckHandler.canRefresh();
443 | }
444 |
445 | @Override
446 | public boolean dispatchTouchEvent(MotionEvent event) {
447 | boolean ret = super.dispatchTouchEvent(event);
448 | if (event.getAction() == MotionEvent.ACTION_DOWN)
449 | ret = true;
450 | return ret;
451 | }
452 |
453 | @Override
454 | public boolean onInterceptTouchEvent(MotionEvent ev) {
455 | ensureTarget();
456 | boolean handled = false;
457 | float curY = ev.getY();
458 |
459 | if (!isEnabled()) {
460 | return false;
461 | }
462 |
463 | // record the first event:
464 | if (ev.getAction() == MotionEvent.ACTION_DOWN) {
465 | mDownEvent = MotionEvent.obtain(ev);
466 | mPrevY = mDownEvent.getY();
467 | mCheckValidMotionFlag = true;
468 | } else if (ev.getAction() == MotionEvent.ACTION_MOVE) {
469 | if (mDownEvent != null) {
470 | float yDiff = Math.abs(curY - mDownEvent.getY());
471 |
472 | float xDiff = Math.abs(ev.getX() - mDownEvent.getX());
473 | if (isHorizontalScroll) {
474 | mPrevY = curY;
475 | return false;
476 | } else if (xDiff <= mTouchSlop) {
477 | return false;
478 | }
479 |
480 | if (yDiff < mTouchSlop) {
481 | mPrevY = curY;
482 | return false;
483 | }
484 | }
485 | } else if (ev.getAction() == MotionEvent.ACTION_UP) {
486 | if (mDownEvent != null) {
487 |
488 | float yDiff = Math.abs(curY - mDownEvent.getY());
489 | if (isHorizontalScroll) {
490 | isHorizontalScroll = false;
491 | mPrevY = ev.getY();
492 | return false;
493 | } else if (yDiff < mTouchSlop) {
494 | mPrevY = curY;
495 | return false;
496 | }
497 | }
498 | }
499 |
500 | MotionEvent event = MotionEvent.obtain(ev);
501 | if (!mInReturningAnimation && !canViewScrollUp(mTarget, event)) {
502 | handled = onTouchEvent(ev);
503 | } else {
504 | mPrevY = ev.getY();
505 | }
506 |
507 | return handled || super.onInterceptTouchEvent(ev);
508 | }
509 |
510 | @Override
511 | public void requestDisallowInterceptTouchEvent(boolean b) {
512 | }
513 |
514 | @SuppressLint("ClickableViewAccessibility")
515 | @Override
516 | public boolean onTouchEvent(MotionEvent event) {
517 | if (!isEnabled()) {
518 | return false;
519 | }
520 |
521 | final int action = event.getAction();
522 | boolean handled = false;
523 | int curTargetTop = mTarget.getTop();
524 | mCurrentTargetOffsetTop = curTargetTop - mTargetOriginalTop;
525 | switch (action) {
526 |
527 | case MotionEvent.ACTION_MOVE:
528 | if (mDownEvent != null && !mInReturningAnimation) {
529 | final float eventY = event.getY();
530 | float yDiff = eventY - mDownEvent.getY();
531 | boolean isScrollUp = eventY - mPrevY > 0;
532 |
533 | // if yDiff is large enough to be counted as one move event
534 | if (mCheckValidMotionFlag && (yDiff > mTouchSlop || yDiff < -mTouchSlop)) {
535 | mCheckValidMotionFlag = false;
536 | } else {
537 | if (isRefreshing()) {
538 | mPrevY = event.getY();
539 | handled = false;
540 | break;
541 | }
542 | }
543 |
544 | // curTargetTop is bigger than trigger
545 | if (curTargetTop >= mDistanceToTriggerSync) {
546 | // User movement passed distance; trigger a refresh
547 | removeCallbacks(mCancel);
548 | }
549 | // curTargetTop is not bigger than trigger
550 | else {
551 | // Just track the user's movement
552 | if (!isScrollUp && (curTargetTop < mTargetOriginalTop + 1)) {
553 | removeCallbacks(mCancel);
554 | mPrevY = event.getY();
555 | handled = false;
556 | // clear the progressBar
557 | break;
558 | } else {
559 | updatePositionTimeout(true);
560 | }
561 | }
562 |
563 | handled = true;
564 | if (curTargetTop >= mTargetOriginalTop && !isRefreshing())
565 | setTargetOffsetTop((int) ((eventY - mPrevY) * RESISTANCE_FACTOR), false);
566 | else
567 | setTargetOffsetTop((int) ((eventY - mPrevY)), true);
568 | mPrevY = event.getY();
569 | }
570 |
571 | break;
572 | case MotionEvent.ACTION_UP:
573 | if (mRefreshing)
574 | break;
575 | if (mCurrentTargetOffsetTop >= mTriggerOffset/* && refreshMode == REFRESH_MODE_PULL*/) {
576 | startRefresh();
577 | handled = true;
578 | } else {
579 | updatePositionTimeout(false);
580 | handled = true;
581 | }
582 | break;
583 | case MotionEvent.ACTION_CANCEL:
584 | if (mDownEvent != null) {
585 | mDownEvent.recycle();
586 | mDownEvent = null;
587 | }
588 | break;
589 | }
590 | return handled;
591 | }
592 |
593 | private void startRefresh() {
594 | if (!checkCanDoRefresh()) {
595 | updatePositionTimeout(false);
596 | return;
597 | }
598 | removeCallbacks(mCancel);
599 | setRefreshState(HeaderState.HEADER_STATE_REFRESHING);
600 | setRefreshing(true);
601 | if (mListener != null)
602 | mListener.onRefresh();
603 | }
604 |
605 | private void updateContentOffsetTop(int targetTop, boolean changeHeightOnly) {
606 | final int currentTop = mTarget.getTop();
607 | if (targetTop < mTargetOriginalTop) {
608 | targetTop = mTargetOriginalTop;
609 | }
610 | setTargetOffsetTop(targetTop - currentTop, changeHeightOnly);
611 | }
612 |
613 | private void setTargetOffsetTop(int offset, boolean changeHeightOnly) {
614 | if (offset == 0)
615 | return;
616 | // check whether the mTarget total top offset is going to be smaller than 0
617 | if (mCurrentTargetOffsetTop + offset >= 0) {
618 | mTarget.offsetTopAndBottom(offset);
619 | mHeadview.offsetTopAndBottom(offset);
620 | mCurrentTargetOffsetTop += offset;
621 |
622 | mHeadview.getLayoutParams().height = (int) (mHeadview.getMeasuredHeight() + offset * 0.8f);
623 | mHeadview.requestLayout();
624 |
625 | invalidate();
626 | } else {
627 | updateContentOffsetTop(mTargetOriginalTop, changeHeightOnly);
628 | }
629 | updateHeadViewState(changeHeightOnly);
630 | }
631 |
632 | private void updatePositionTimeout(boolean isDelayed) {
633 | removeCallbacks(mCancel);
634 | postDelayed(mCancel, isDelayed ? RETURN_DURATION : 0);
635 | }
636 |
637 | @SuppressWarnings("deprecation")
638 | private int getColor(int colorResId) {
639 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
640 | getResources().getColor(colorResId, getContext().getTheme());
641 | else
642 | getResources().getColor(colorResId);
643 | return colorResId;
644 | }
645 |
646 | public void setColorAnimationArray(int[] colorAnimationArray) {
647 | headerView.setColorAnimationArray(colorAnimationArray);
648 | }
649 |
650 | // setters
651 | public void setHeaderText(String headerText) {
652 | if (headerView != null) {
653 | headerView.setHeaderText(headerText);
654 | headerView.initView();
655 | }
656 | }
657 |
658 | public void setHeaderTextSize(int headerTextSize) {
659 | if (headerView != null) {
660 | headerView.setHeaderTextSize(headerTextSize);
661 | headerView.invalidate();
662 | }
663 | }
664 |
665 | public void setHeaderTextColor(int headerTextColor) {
666 | if (headerView != null) {
667 | headerView.setHeaderTextColor(headerTextColor);
668 | headerView.invalidate();
669 | }
670 | }
671 |
672 | public void setHeaderBackgroundColor(int headerBackgroundColor) {
673 | if (headerView != null) {
674 | headerView.setHeaderBackgroundColor(headerBackgroundColor);
675 | headerView.invalidate();
676 | }
677 | }
678 |
679 | public void setHeaderTextAnim(HeaderTextAnim headerTextAnim) {
680 | if (headerView != null) {
681 | headerView.setHeaderTextAnim(headerTextAnim);
682 | headerView.invalidate();
683 | }
684 | }
685 |
686 | public void setHeaderLoopAnim(HeaderLoopAnim headerLoopAnim) {
687 | if (headerView != null) {
688 | headerView.setHeaderLoopAnim(headerLoopAnim);
689 | headerView.invalidate();
690 | }
691 | }
692 |
693 | public void setHeaderTextAnimIteration(int headerTextAnimIteration) {
694 | if (headerView != null) {
695 | headerView.setHeaderTextAnimIteration(headerTextAnimIteration);
696 | headerView.invalidate();
697 | }
698 | }
699 |
700 | public void setHeaderLoopAnimIteration(int headerLoopAnimIteration) {
701 | if (headerView != null) {
702 | headerView.setHeaderLoopAnimIteration(headerLoopAnimIteration);
703 | headerView.invalidate();
704 | }
705 | }
706 |
707 | // public void setHeaderPaddingTop(int headerPaddingTop) {
708 | // if (headerView != null) {
709 | // headerView.setHeaderPaddingTop(headerPaddingTop);
710 | // headerView.invalidate();
711 | // }
712 | // }
713 | //
714 | // public void setHeaderPaddingBottom(int headerPaddingBottom) {
715 | // if (headerView != null) {
716 | // headerView.setHeaderPaddingBottom(headerPaddingBottom);
717 | // headerView.invalidate();
718 | // }
719 | // }
720 |
721 | public void setColorAnimEnable(boolean colorAnimEnable) {
722 | if (headerView != null) {
723 | headerView.setColorAnimEnable(colorAnimEnable);
724 | headerView.invalidate();
725 | }
726 | }
727 |
728 | public void setAnimationSpeed(HeaderAnimSpeed animationSpeed) {
729 | if (headerView != null) {
730 | headerView.setAnimationSpeed(animationSpeed);
731 | headerView.invalidate();
732 | }
733 | }
734 |
735 | public void setHeaderTextTypeface(Typeface mTitleTypeface) {
736 | if (headerView != null) {
737 | headerView.setHeaderTextTypeface(mTitleTypeface);
738 | headerView.invalidate();
739 | }
740 | }
741 |
742 | /**
743 | * Classes that wish to be notified when the swipe gesture correctly
744 | * triggers a refresh should implement this interface.
745 | */
746 | public interface OnRefreshListener {
747 | void onRefresh();
748 | }
749 |
750 | /**
751 | * Classes that checking whether refresh can be triggered
752 | */
753 | interface RefreshCheckHandler {
754 | boolean canRefresh();
755 | }
756 |
757 | interface ScrollUpHandler {
758 | boolean canScrollUp(View view);
759 | }
760 |
761 | /**
762 | * Classes that must be implemented by for custom header view
763 | */
764 | interface AnimatedPullToRefreshHeaderLayout {
765 | void onStateChange(HeaderState currentHeaderState, HeaderState lastHeaderState);
766 | }
767 | }
768 |
--------------------------------------------------------------------------------