├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── gjiazhe │ │ └── springrecyclerview │ │ └── sample │ │ ├── HorizontalActivity.java │ │ ├── MainActivity.java │ │ ├── StaggeredGridLayoutActivity.java │ │ └── VerticalActivity.java │ └── res │ ├── layout │ ├── activity_horizontal.xml │ ├── activity_main.xml │ ├── activity_staggered_grid_layout.xml │ ├── activity_vertical.xml │ ├── item1.xml │ └── item2.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots ├── 1.gif ├── 2.gif └── 3.gif ├── settings.gradle └── springrecyclerview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java ├── android │ └── support │ │ └── v7 │ │ └── widget │ │ └── TempRecyclerView.java └── com │ └── gjiazhe │ └── springrecyclerview │ └── SpringRecyclerView.java └── res └── values ├── attrs.xml └── strings.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/* 38 | 39 | # Keystore files 40 | *.jks 41 | 42 | # Mac OS 43 | .DS_Store 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 郭佳哲 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpringRecyclerView 2 | 3 | SpringRecyclerView is a RecyclerView with spring effect when being dragged or flinged to overScroll. 4 | 5 | ListView Version : https://github.com/gjiazhe/SpringListView 6 | 7 | ## Screenshot 8 | 9 | 10 | 11 | 12 | 13 | ## Include SpringRecyclerView to Your Project 14 | 15 | With gradle: 16 | 17 | ```groovy 18 | dependencies { 19 | compile 'com.gjiazhe:SpringRecyclerView:1.0' 20 | } 21 | ``` 22 | ## Use SpringRecyclerView in Layout Files 23 | 24 | ```xml 25 | 33 | ``` 34 | 35 | ## Description of Attributes 36 | | Attributes | Format | Default | Description | 37 | | :-----------------------------: | :-----: | :-----: | :--------------------------------------: | 38 | | srv_enableSpringEffectWhenDrag | boolean | true | Whether the spring effect is enabled when we drag the recyclerView to overScroll. | 39 | | srv_enableSpringEffectWhenFling | boolean | true | Whether the spring effect is enabled when we fling the recyclerView to overScroll. | 40 | | srv_releaseBackAnimDuration | int | 300 | Duration of the rebound animation after we release the recyclerView. In millisecond. | 41 | | srv_flingBackAnimDuration | int | 300 | Duration of the rebound animation after we fling the recyclerView. In millisecond. | 42 | 43 | You can set these attributes in the layout file, or in the java code: 44 | 45 | ```java 46 | SpringRecyclerView springRecyclerView = (SpringRecyclerView)findViewById(R.id.spring_recycler_view); 47 | springRecyclerView.setEnableSpringEffectWhenDrag(true); 48 | springRecyclerView.setEnableSpringEffectWhenFling(true); 49 | springRecyclerView.setReleaseBackAnimDuration(300); 50 | springRecyclerView.setFlingBackAnimDuration(300); 51 | ``` 52 | ## License 53 | 54 | MIT License 55 | 56 | Copyright (c) 2016 郭佳哲 57 | 58 | Permission is hereby granted, free of charge, to any person obtaining a copy 59 | of this software and associated documentation files (the "Software"), to deal 60 | in the Software without restriction, including without limitation the rights 61 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 62 | copies of the Software, and to permit persons to whom the Software is 63 | furnished to do so, subject to the following conditions: 64 | 65 | The above copyright notice and this permission notice shall be included in all 66 | copies or substantial portions of the Software. 67 | 68 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 69 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 70 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 71 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 72 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 73 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 74 | SOFTWARE. 75 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.0" 6 | defaultConfig { 7 | applicationId "com.gjiazhe.springrecyclerview.sample" 8 | minSdkVersion 11 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(include: ['*.jar'], dir: 'libs') 23 | compile 'com.android.support:appcompat-v7:25.0.1' 24 | compile project(':springrecyclerview') 25 | } 26 | -------------------------------------------------------------------------------- /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 /Users/gjz/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/gjiazhe/springrecyclerview/sample/HorizontalActivity.java: -------------------------------------------------------------------------------- 1 | package com.gjiazhe.springrecyclerview.sample; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.GridLayoutManager; 6 | import android.support.v7.widget.OrientationHelper; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.TextView; 12 | 13 | import com.gjiazhe.springrecyclerview.SpringRecyclerView; 14 | 15 | public class HorizontalActivity extends AppCompatActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_horizontal); 21 | SpringRecyclerView springRecyclerView = (SpringRecyclerView) findViewById(R.id.spring_recycler_view); 22 | springRecyclerView.setLayoutManager(new GridLayoutManager(this, 5, OrientationHelper.HORIZONTAL, false)); 23 | springRecyclerView.setAdapter(new MyAdapter()); 24 | } 25 | 26 | class MyAdapter extends RecyclerView.Adapter { 27 | @Override 28 | public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 29 | LayoutInflater inflater = LayoutInflater.from(HorizontalActivity.this); 30 | View view = inflater.inflate(R.layout.item2, parent, false); 31 | return new MyViewHolder(view); 32 | } 33 | 34 | @Override 35 | public void onBindViewHolder(MyViewHolder holder, int position) { 36 | holder.textView.setText(position + 1 + ""); 37 | } 38 | 39 | @Override 40 | public int getItemCount() { 41 | return 30; 42 | } 43 | 44 | class MyViewHolder extends RecyclerView.ViewHolder { 45 | TextView textView; 46 | MyViewHolder(View itemView) { 47 | super(itemView); 48 | textView = (TextView) itemView.findViewById(R.id.text1); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/gjiazhe/springrecyclerview/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.gjiazhe.springrecyclerview.sample; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | public class MainActivity extends AppCompatActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_main); 14 | } 15 | 16 | public void openVerticalSample(View view) { 17 | startActivity(new Intent(this, VerticalActivity.class)); 18 | } 19 | 20 | public void openHorizontalSample(View view) { 21 | startActivity(new Intent(this, HorizontalActivity.class)); 22 | } 23 | 24 | public void openStaggeredGridLayoutSample(View view) { 25 | startActivity(new Intent(this, StaggeredGridLayoutActivity.class)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/gjiazhe/springrecyclerview/sample/StaggeredGridLayoutActivity.java: -------------------------------------------------------------------------------- 1 | package com.gjiazhe.springrecyclerview.sample; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.support.v7.widget.StaggeredGridLayoutManager; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.TextView; 11 | 12 | import com.gjiazhe.springrecyclerview.SpringRecyclerView; 13 | 14 | public class StaggeredGridLayoutActivity extends AppCompatActivity { 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_staggered_grid_layout); 20 | SpringRecyclerView springRecyclerView = (SpringRecyclerView) findViewById(R.id.spring_recycler_view); 21 | springRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL)); 22 | springRecyclerView.setAdapter(new MyAdapter()); 23 | } 24 | 25 | class MyAdapter extends RecyclerView.Adapter { 26 | private int[] mRandomHeight = new int[25]; 27 | 28 | MyAdapter() { 29 | for (int i=0; i { 27 | @Override 28 | public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 29 | LayoutInflater inflater = LayoutInflater.from(VerticalActivity.this); 30 | View view = inflater.inflate(R.layout.item1, parent, false); 31 | return new MyViewHolder(view); 32 | } 33 | 34 | @Override 35 | public void onBindViewHolder(MyViewHolder holder, int position) { 36 | holder.textView.setText("Item " + (position + 1)); 37 | } 38 | 39 | @Override 40 | public int getItemCount() { 41 | return 20; 42 | } 43 | 44 | class MyViewHolder extends RecyclerView.ViewHolder { 45 | TextView textView; 46 | MyViewHolder(View itemView) { 47 | super(itemView); 48 | textView = (TextView) itemView.findViewById(R.id.text1); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_horizontal.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | 25 | 26 | 37 | 38 | 42 | 43 | 54 | 55 | 59 | 60 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_staggered_grid_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_vertical.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item1.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item2.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gjiazhe/SpringRecyclerView/26054c5d41824f6d046fd5630dd2429119f58dff/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gjiazhe/SpringRecyclerView/26054c5d41824f6d046fd5630dd2429119f58dff/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gjiazhe/SpringRecyclerView/26054c5d41824f6d046fd5630dd2429119f58dff/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gjiazhe/SpringRecyclerView/26054c5d41824f6d046fd5630dd2429119f58dff/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gjiazhe/SpringRecyclerView/26054c5d41824f6d046fd5630dd2429119f58dff/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SpringRecyclerView 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.2' 9 | classpath 'com.novoda:bintray-release:0.3.4' 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gjiazhe/SpringRecyclerView/26054c5d41824f6d046fd5630dd2429119f58dff/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /screenshots/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gjiazhe/SpringRecyclerView/26054c5d41824f6d046fd5630dd2429119f58dff/screenshots/1.gif -------------------------------------------------------------------------------- /screenshots/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gjiazhe/SpringRecyclerView/26054c5d41824f6d046fd5630dd2429119f58dff/screenshots/2.gif -------------------------------------------------------------------------------- /screenshots/3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gjiazhe/SpringRecyclerView/26054c5d41824f6d046fd5630dd2429119f58dff/screenshots/3.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':springrecyclerview' 2 | -------------------------------------------------------------------------------- /springrecyclerview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /springrecyclerview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.novoda.bintray-release' 3 | 4 | android { 5 | compileSdkVersion 25 6 | buildToolsVersion "25.0.0" 7 | 8 | defaultConfig { 9 | minSdkVersion 11 10 | targetSdkVersion 25 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 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | compile 'com.android.support:appcompat-v7:25.0.1' 25 | compile 'com.android.support:recyclerview-v7:25.0.1' 26 | } 27 | 28 | publish { 29 | userOrg = 'gjiazhe' 30 | groupId = 'com.gjiazhe' 31 | artifactId = 'springrecyclerview' 32 | publishVersion = '1.0' 33 | desc = '' 34 | website = 'https://github.com/gjiazhe/SpringRecyclerView' 35 | } 36 | -------------------------------------------------------------------------------- /springrecyclerview/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/gjz/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /springrecyclerview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /springrecyclerview/src/main/java/android/support/v7/widget/TempRecyclerView.java: -------------------------------------------------------------------------------- 1 | package android.support.v7.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | /** 7 | * Change the package method absorbGlows to be protected so we could 8 | * override it in the subclass. 9 | * 10 | * Created by gjz on 17/11/2016. 11 | */ 12 | 13 | public class TempRecyclerView extends RecyclerView { 14 | 15 | protected TempRecyclerView(Context context) { 16 | this(context, null); 17 | } 18 | 19 | protected TempRecyclerView(Context context, AttributeSet attrs) { 20 | this(context, attrs, 0); 21 | } 22 | 23 | protected TempRecyclerView(Context context, AttributeSet attrs, int defStyle) { 24 | super(context, attrs, defStyle); 25 | } 26 | 27 | @Override 28 | protected void absorbGlows(int velocityX, int velocityY) {} 29 | } 30 | -------------------------------------------------------------------------------- /springrecyclerview/src/main/java/com/gjiazhe/springrecyclerview/SpringRecyclerView.java: -------------------------------------------------------------------------------- 1 | package com.gjiazhe.springrecyclerview; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.view.MotionEventCompat; 8 | import android.support.v7.widget.TempRecyclerView; 9 | import android.util.AttributeSet; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | import android.view.ViewConfiguration; 13 | import android.view.ViewParent; 14 | import android.view.animation.Animation; 15 | import android.view.animation.Interpolator; 16 | import android.view.animation.Transformation; 17 | 18 | /** 19 | * A RecyclerView With Spring Effect. 20 | * 21 | * Created by gjz on 17/11/2016. 22 | */ 23 | 24 | public class SpringRecyclerView extends TempRecyclerView { 25 | private static final int STATE_NORMAL = 0; 26 | private static final int STATE_DRAG_TOP_OR_LEFT = 1; 27 | private static final int STATE_DRAG_BOTTOM_OR_RIGHT = 2; 28 | private static final int STATE_SPRING_BACK = 3; 29 | private static final int STATE_FLING = 4; 30 | private int mState = STATE_NORMAL; 31 | 32 | private static final int DEF_RELEASE_BACK_ANIM_DURATION = 300; // ms 33 | private static final int DEF_FLING_BACK_ANIM_DURATION = 300; 34 | private int mReleaseBackAnimDuration; 35 | private int mFlingBackAnimDuration; 36 | 37 | private static final int INVALID_POINTER = -1; 38 | 39 | private final int mTouchSlop; 40 | private int mOrientation; // horizontal or vertical 41 | private float mLastMotionPos; // x-coordinate or y-coordinate of last event, base on mOrientation 42 | private float mFrom; 43 | private float mOffset; 44 | private int mActivePointerId = INVALID_POINTER; 45 | 46 | private boolean mEnableSpringEffectWhenDrag; 47 | private boolean mEnableSpringEffectWhenFling; 48 | 49 | private Animation springAnimation; 50 | private Interpolator releaseBackAnimInterpolator; 51 | private Interpolator flingBackAnimInterpolator; 52 | 53 | public SpringRecyclerView(Context context) { 54 | this(context, null); 55 | } 56 | 57 | public SpringRecyclerView(Context context, @Nullable AttributeSet attrs) { 58 | this(context, attrs, 0); 59 | } 60 | 61 | public SpringRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) { 62 | super(context, attrs, defStyle); 63 | setOverScrollMode(View.OVER_SCROLL_ALWAYS); 64 | 65 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); 66 | 67 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SpringRecyclerView); 68 | mReleaseBackAnimDuration = a.getInt(R.styleable.SpringRecyclerView_srv_releaseBackAnimDuration, DEF_RELEASE_BACK_ANIM_DURATION); 69 | mFlingBackAnimDuration = a.getInt(R.styleable.SpringRecyclerView_srv_flingBackAnimDuration, DEF_FLING_BACK_ANIM_DURATION); 70 | mEnableSpringEffectWhenDrag = a.getBoolean(R.styleable.SpringRecyclerView_srv_enableSpringEffectWhenDrag, true); 71 | mEnableSpringEffectWhenFling = a.getBoolean(R.styleable.SpringRecyclerView_srv_enableSpringEffectWhenFling, true); 72 | a.recycle(); 73 | 74 | initAnimation(); 75 | } 76 | 77 | @Override 78 | public boolean onInterceptTouchEvent(MotionEvent ev) { 79 | if (mEnableSpringEffectWhenDrag && onInterceptTouchEventInternal(ev)) { 80 | return true; 81 | } 82 | return super.onInterceptTouchEvent(ev); 83 | } 84 | 85 | private boolean onInterceptTouchEventInternal(MotionEvent ev) { 86 | final int action = MotionEventCompat.getActionMasked(ev); 87 | switch (action) { 88 | case MotionEvent.ACTION_DOWN: 89 | mLastMotionPos = mOrientation == VERTICAL ? ev.getY() : ev.getX(); 90 | mActivePointerId = ev.getPointerId(0); 91 | // If STATE_SPRING_BACK, we intercept the event and stop the animation. 92 | // If STATE_FLING, we do not intercept and allow the animation to finish. 93 | if (mState == STATE_SPRING_BACK) { 94 | if (mOffset != 0) { 95 | clearAnimation(); 96 | setState(mOffset > 0 ? STATE_DRAG_TOP_OR_LEFT : STATE_DRAG_BOTTOM_OR_RIGHT); 97 | } else { 98 | setState(STATE_NORMAL); 99 | } 100 | invalidate(); 101 | } 102 | break; 103 | case MotionEvent.ACTION_MOVE: 104 | if (mActivePointerId == INVALID_POINTER) { 105 | break; 106 | } 107 | final int pointerIndex = ev.findPointerIndex(mActivePointerId); 108 | if (pointerIndex == -1) { 109 | break; 110 | } 111 | final float pos = mOrientation == VERTICAL ? ev.getY(pointerIndex) : ev.getX(pointerIndex); 112 | final float posDiff = pos - mLastMotionPos; 113 | mLastMotionPos = pos; 114 | if (!isDragged()) { 115 | boolean canScrollUpOrLeft, canScrollDownOrRight; 116 | final int offset = mOrientation == VERTICAL ? 117 | super.computeVerticalScrollOffset() : 118 | super.computeHorizontalScrollOffset(); 119 | final int range = mOrientation == VERTICAL ? 120 | super.computeVerticalScrollRange() - super.computeVerticalScrollExtent() : 121 | super.computeHorizontalScrollRange() - super.computeHorizontalScrollExtent(); 122 | if (range == 0) { 123 | canScrollDownOrRight = canScrollUpOrLeft = false; 124 | } else { 125 | canScrollUpOrLeft = offset > 0; 126 | canScrollDownOrRight = offset < (range - 1); 127 | } 128 | if (canScrollUpOrLeft && canScrollDownOrRight) { 129 | break; 130 | } 131 | if ((Math.abs(posDiff) > mTouchSlop)) { 132 | boolean isOverScroll = false; 133 | if (!canScrollUpOrLeft && posDiff > 0) { 134 | setState(STATE_DRAG_TOP_OR_LEFT); 135 | isOverScroll = true; 136 | } else if (!canScrollDownOrRight && posDiff < 0) { 137 | setState(STATE_DRAG_BOTTOM_OR_RIGHT); 138 | isOverScroll = true; 139 | } 140 | if (isOverScroll) { 141 | // Prevent touch effect on item 142 | MotionEvent fakeCancelEvent = MotionEvent.obtain(ev); 143 | fakeCancelEvent.setAction(MotionEvent.ACTION_CANCEL); 144 | super.onTouchEvent(fakeCancelEvent); 145 | fakeCancelEvent.recycle(); 146 | super.awakenScrollBars(); 147 | 148 | final ViewParent parent = getParent(); 149 | if (parent != null) { 150 | parent.requestDisallowInterceptTouchEvent(true); 151 | } 152 | } 153 | } 154 | } 155 | break; 156 | 157 | case MotionEvent.ACTION_POINTER_UP: 158 | onSecondaryPointerUp(ev); 159 | break; 160 | 161 | case MotionEvent.ACTION_UP: 162 | case MotionEvent.ACTION_CANCEL: 163 | mActivePointerId = INVALID_POINTER; 164 | break; 165 | } 166 | return isDragged(); 167 | } 168 | 169 | @Override 170 | public boolean onTouchEvent(MotionEvent ev) { 171 | if (mEnableSpringEffectWhenDrag && onTouchEventInternal(ev)) { 172 | return true; 173 | } 174 | return super.onTouchEvent(ev); 175 | } 176 | 177 | private boolean onTouchEventInternal(MotionEvent ev) { 178 | final int action = MotionEventCompat.getActionMasked(ev); 179 | switch (action) { 180 | case MotionEvent.ACTION_DOWN: 181 | mLastMotionPos = mOrientation == VERTICAL ? ev.getY() : ev.getX(); 182 | mActivePointerId = ev.getPointerId(0); 183 | break; 184 | case MotionEvent.ACTION_MOVE: { 185 | if (mActivePointerId == INVALID_POINTER) { 186 | break; 187 | } 188 | final int pointerIndex = ev.findPointerIndex(mActivePointerId); 189 | if (pointerIndex < 0) { 190 | break; 191 | } 192 | final float pos = mOrientation == VERTICAL ? ev.getY(pointerIndex) : ev.getX(pointerIndex); 193 | final float posDiff = pos - mLastMotionPos; 194 | mLastMotionPos = pos; 195 | if (!isDragged()) { 196 | boolean canScrollUpOrLeft, canScrollDownOrRight; 197 | final int offset = mOrientation == VERTICAL ? 198 | super.computeVerticalScrollOffset() : 199 | super.computeHorizontalScrollOffset(); 200 | final int range = mOrientation == VERTICAL ? 201 | super.computeVerticalScrollRange() - super.computeVerticalScrollExtent() : 202 | super.computeHorizontalScrollRange() - super.computeHorizontalScrollExtent(); 203 | if (range == 0) { 204 | canScrollDownOrRight = canScrollUpOrLeft = false; 205 | } else { 206 | canScrollUpOrLeft = offset > 0; 207 | canScrollDownOrRight = offset < (range - 1); 208 | } 209 | if (canScrollUpOrLeft && canScrollDownOrRight) { 210 | break; 211 | } 212 | 213 | if ((Math.abs(posDiff) >= mTouchSlop)) { 214 | boolean isOverScroll = false; 215 | if (!canScrollUpOrLeft && posDiff > 0) { 216 | setState(STATE_DRAG_TOP_OR_LEFT); 217 | isOverScroll = true; 218 | } else if (!canScrollDownOrRight && posDiff < 0) { 219 | setState(STATE_DRAG_BOTTOM_OR_RIGHT); 220 | isOverScroll = true; 221 | } 222 | if (isOverScroll) { 223 | // Prevent touch effect on item 224 | MotionEvent fakeCancelEvent = MotionEvent.obtain(ev); 225 | fakeCancelEvent.setAction(MotionEvent.ACTION_CANCEL); 226 | super.onTouchEvent(fakeCancelEvent); 227 | fakeCancelEvent.recycle(); 228 | super.awakenScrollBars(); 229 | 230 | final ViewParent parent = getParent(); 231 | if (parent != null) { 232 | parent.requestDisallowInterceptTouchEvent(true); 233 | } 234 | } 235 | } 236 | } 237 | if (isDragged()) { 238 | mOffset += posDiff; 239 | // correct mOffset 240 | if ((isDraggedTopOrLeft() && mOffset <= 0) || (isDraggedBottomOrRight() && mOffset >=0)) { 241 | setState(STATE_NORMAL); 242 | mOffset = 0; 243 | // return to touch item 244 | MotionEvent fakeDownEvent = MotionEvent.obtain(ev); 245 | fakeDownEvent.setAction(MotionEvent.ACTION_DOWN); 246 | super.onTouchEvent(fakeDownEvent); 247 | fakeDownEvent.recycle(); 248 | } 249 | invalidate(); 250 | } 251 | break; 252 | } 253 | case MotionEventCompat.ACTION_POINTER_DOWN: { 254 | final int index = MotionEventCompat.getActionIndex(ev); 255 | mLastMotionPos = mOrientation == VERTICAL ? ev.getY(index) : ev.getX(index); 256 | mActivePointerId = ev.getPointerId(index); 257 | break; 258 | } 259 | 260 | case MotionEventCompat.ACTION_POINTER_UP: { 261 | onSecondaryPointerUp(ev); 262 | final int index = ev.findPointerIndex(mActivePointerId); 263 | if (index != -1) { 264 | mLastMotionPos = mOrientation == VERTICAL ? ev.getY(index) : ev.getX(index); 265 | } 266 | break; 267 | } 268 | case MotionEvent.ACTION_UP: 269 | case MotionEvent.ACTION_CANCEL: { 270 | if (mOffset != 0) { 271 | // Spring back 272 | mFrom = mOffset; 273 | startReleaseAnimation(); 274 | setState(STATE_SPRING_BACK); 275 | } 276 | mActivePointerId = INVALID_POINTER; 277 | } 278 | } 279 | return isDragged(); 280 | } 281 | 282 | @Override 283 | public void draw(Canvas canvas) { 284 | if (mState == STATE_NORMAL) { 285 | super.draw(canvas); 286 | } else { 287 | final int sc = canvas.save(); 288 | 289 | // scale the canvas 290 | if (mOrientation == VERTICAL) { 291 | final int viewHeight = getHeight(); 292 | final float scaleY = 1 + Math.abs(mOffset) / viewHeight * 0.3f; 293 | canvas.scale(1, scaleY, 0, mOffset >= 0 ? 0 : (viewHeight + getScrollY())); 294 | } else { 295 | final int viewWidth = getWidth(); 296 | final float scaleX = 1 + Math.abs(mOffset) / viewWidth * 0.3f; 297 | canvas.scale(scaleX, 1, mOffset >= 0 ? 0 : (viewWidth + getScrollX()), 0); 298 | } 299 | 300 | super.draw(canvas); 301 | canvas.restoreToCount(sc); 302 | } 303 | } 304 | 305 | @Override 306 | protected void absorbGlows(int velocityX, int velocityY) { 307 | if (mEnableSpringEffectWhenFling && mState != STATE_FLING) { 308 | final int v = mOrientation == VERTICAL ? velocityY : velocityX; 309 | mFrom = -v * (1f/60); 310 | startFlingAnimation(); 311 | setState(STATE_FLING); 312 | } 313 | } 314 | 315 | private void initAnimation() { 316 | springAnimation = new Animation() { 317 | @Override 318 | protected void applyTransformation(float interpolatedTime, Transformation t) { 319 | mOffset = mFrom * interpolatedTime; 320 | if (hasEnded()) { 321 | mOffset = 0; 322 | setState(STATE_NORMAL); 323 | } 324 | invalidate(); 325 | } 326 | }; 327 | 328 | releaseBackAnimInterpolator = new Interpolator() { 329 | @Override 330 | public float getInterpolation(float v) { 331 | return (float) Math.cos(Math.PI * v / 2); 332 | } 333 | }; 334 | 335 | flingBackAnimInterpolator = new Interpolator() { 336 | @Override 337 | public float getInterpolation(float v) { 338 | return (float) Math.sin(Math.PI * v); 339 | } 340 | }; 341 | } 342 | 343 | private void startReleaseAnimation() { 344 | springAnimation.setDuration(mReleaseBackAnimDuration); 345 | springAnimation.setInterpolator(releaseBackAnimInterpolator); 346 | startAnimation(springAnimation); 347 | } 348 | 349 | private void startFlingAnimation() { 350 | springAnimation.setDuration(mFlingBackAnimDuration); 351 | springAnimation.setInterpolator(flingBackAnimInterpolator); 352 | startAnimation(springAnimation); 353 | } 354 | 355 | private void setState(int newState) { 356 | if (mState != newState) { 357 | mState = newState; 358 | } 359 | } 360 | 361 | private boolean isDragged() { 362 | return mState == STATE_DRAG_TOP_OR_LEFT || mState == STATE_DRAG_BOTTOM_OR_RIGHT; 363 | } 364 | 365 | private boolean isDraggedTopOrLeft() { 366 | return mState == STATE_DRAG_TOP_OR_LEFT; 367 | } 368 | 369 | private boolean isDraggedBottomOrRight() { 370 | return mState == STATE_DRAG_BOTTOM_OR_RIGHT; 371 | } 372 | 373 | private void onSecondaryPointerUp(MotionEvent ev) { 374 | final int pointerIndex = ev.getActionIndex(); 375 | final int pointerId = ev.getPointerId(pointerIndex); 376 | if (pointerId == mActivePointerId) { 377 | // This was our active pointer going up. Choose a new 378 | // active pointer and adjust accordingly. 379 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; 380 | mActivePointerId = ev.getPointerId(newPointerIndex); 381 | } 382 | } 383 | 384 | @Override 385 | public void setLayoutManager(LayoutManager layout) { 386 | super.setLayoutManager(layout); 387 | if (layout != null) { 388 | mOrientation = layout.canScrollHorizontally() ? HORIZONTAL : VERTICAL; 389 | } 390 | } 391 | 392 | public void setEnableSpringEffectWhenDrag(boolean enable) { 393 | mEnableSpringEffectWhenDrag = enable; 394 | } 395 | 396 | public void setEnableSpringEffectWhenFling(boolean enable) { 397 | mEnableSpringEffectWhenFling = enable; 398 | } 399 | 400 | public void setReleaseBackAnimDuration(int duration) { 401 | mReleaseBackAnimDuration = duration; 402 | } 403 | 404 | public void setFlingBackAnimDuration(int duration) { 405 | mFlingBackAnimDuration = duration; 406 | } 407 | 408 | } 409 | -------------------------------------------------------------------------------- /springrecyclerview/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /springrecyclerview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SpringRecyclerView 3 | 4 | --------------------------------------------------------------------------------