├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── android
│ │ └── yzl
│ │ └── pulllefttorefreshlayout
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── android
│ │ │ └── yzl
│ │ │ └── pulllefttorefreshlayout
│ │ │ ├── HorizontalScrollViewActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── RecyclerViewActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_horizontal.xml
│ │ ├── activity_main.xml
│ │ ├── activity_recycler.xml
│ │ └── item_pull_left.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
│ └── test
│ └── java
│ └── com
│ └── android
│ └── yzl
│ └── pulllefttorefreshlayout
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── image
└── UI.gif
├── lib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── android
│ │ └── yzl
│ │ └── lib
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── android
│ │ │ └── yzl
│ │ │ └── lib
│ │ │ ├── AnimView.java
│ │ │ ├── OnScrollListener.java
│ │ │ └── PullLeftToRefreshLayout.java
│ └── res
│ │ ├── drawable-xxhdpi
│ │ └── arrow.png
│ │ ├── layout
│ │ └── item_load_more.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
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── android
│ └── yzl
│ └── lib
│ └── ExampleUnitTest.java
├── projectFilesBackup
└── .idea
│ └── workspace.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | PullLeftToRefreshLayout
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.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 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PullLeftToRefreshLayout
2 | 带有贝塞尔曲线效果的横向刷新布局,支持多种view,如RecyclerView,HorizontalScrollView等。
3 | 
4 | #XML布局
5 | ```
6 |
13 |
14 |
18 |
19 |
20 | ```
21 | #自定义属性
22 | ```
23 | app:footerBgColor="@color/yellow"
24 | ```
25 | 可以改变刷新区域的背景颜色
26 | #监听事件
27 | ###刷新监听:当左拉距离达到刷新距离,且动画结束时调用。
28 | ```
29 | PullLeftToRefreshLayout refreshLayout = (PullLeftToRefreshLayout) findViewById(R.id.plrl);
30 | refreshLayout.setOnRefreshListener(new PullLeftToRefreshLayout.OnRefreshListener() {
31 | @Override
32 | public void onRefresh() {
33 | Toast.makeText(RecyclerViewActivity.this, "刷新数据成功", Toast.LENGTH_SHORT).show();
34 | }
35 | });
36 | ```
37 | ###滑动监听:当需要与其他可滑动控件(如ListView)嵌套使用时调用。
38 | ```
39 | refreshLayout.setOnScrollListener(new OnScrollListener() {
40 | @Override
41 | public void onScrollChange(boolean scroll) {
42 | mListView.requestDisallowInterceptTouchEvent(scroll);
43 | }
44 | });
45 | ```
46 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.android.yzl.pulllefttorefreshlayout"
9 | minSdkVersion 15
10 | targetSdkVersion 23
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 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | compile 'com.android.support:recyclerview-v7:23.0.0'
27 | compile 'com.tbruyelle.rxpermissions:rxpermissions:0.7.0@aar'
28 | compile project(':lib')
29 | }
30 |
--------------------------------------------------------------------------------
/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 D:\dev\andorid_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/androidTest/java/com/android/yzl/pulllefttorefreshlayout/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.android.yzl.pulllefttorefreshlayout;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/yzl/pulllefttorefreshlayout/HorizontalScrollViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.android.yzl.pulllefttorefreshlayout;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.widget.Toast;
7 |
8 | import com.android.yzl.lib.PullLeftToRefreshLayout;
9 |
10 | /**
11 | * Created by yzl on 2016/6/6.
12 | */
13 | public class HorizontalScrollViewActivity extends AppCompatActivity {
14 |
15 | @Override
16 | protected void onCreate(@Nullable Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_horizontal);
19 | PullLeftToRefreshLayout plrl = (PullLeftToRefreshLayout) findViewById(R.id.plrl);
20 | plrl.setOnRefreshListener(new PullLeftToRefreshLayout.OnRefreshListener() {
21 | @Override
22 | public void onRefresh() {
23 | Toast.makeText(HorizontalScrollViewActivity.this, "刷新数据成功", Toast.LENGTH_SHORT).show();
24 | }
25 | });
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/yzl/pulllefttorefreshlayout/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.android.yzl.pulllefttorefreshlayout;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.support.v7.widget.LinearLayoutManager;
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.Toast;
12 |
13 | import com.android.yzl.lib.PullLeftToRefreshLayout;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 |
22 | }
23 |
24 | public void clickH(View v){
25 | startActivity(new Intent(this, HorizontalScrollViewActivity.class));
26 | }
27 |
28 | public void clickR(View v){
29 | startActivity(new Intent(this, RecyclerViewActivity.class));
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/yzl/pulllefttorefreshlayout/RecyclerViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.android.yzl.pulllefttorefreshlayout;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.Toast;
11 |
12 | import com.android.yzl.lib.PullLeftToRefreshLayout;
13 |
14 | /**
15 | * Created by yzl on 2016/6/6.
16 | */
17 | public class RecyclerViewActivity extends AppCompatActivity {
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_recycler);
23 |
24 | RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
25 | rv.setAdapter(new PullAdapter());
26 | rv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
27 |
28 | PullLeftToRefreshLayout plrl = (PullLeftToRefreshLayout) findViewById(R.id.plrl);
29 | plrl.setOnRefreshListener(new PullLeftToRefreshLayout.OnRefreshListener() {
30 | @Override
31 | public void onRefresh() {
32 | Toast.makeText(RecyclerViewActivity.this, "刷新数据成功", Toast.LENGTH_SHORT).show();
33 | }
34 | });
35 | }
36 |
37 | public class PullAdapter extends RecyclerView.Adapter{
38 |
39 | @Override
40 | public PullrHolder onCreateViewHolder(ViewGroup parent, int viewType) {
41 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_pull_left, parent, false);
42 | return new PullrHolder(view);
43 | }
44 |
45 | @Override
46 | public void onBindViewHolder(PullrHolder holder, int position) {
47 |
48 | }
49 |
50 | @Override
51 | public int getItemCount() {
52 | return 10;
53 | }
54 |
55 | public class PullrHolder extends RecyclerView.ViewHolder{
56 |
57 | public PullrHolder(View itemView) {
58 | super(itemView);
59 | }
60 | }
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_horizontal.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
18 |
19 |
27 |
28 |
36 |
37 |
45 |
46 |
54 |
55 |
63 |
64 |
72 |
73 |
81 |
82 |
90 |
91 |
99 |
100 |
108 |
109 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_recycler.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_pull_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/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 | #ffffff
7 | #efef66#
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PullLeftToRefreshLayout
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/android/yzl/pulllefttorefreshlayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.android.yzl.pulllefttorefreshlayout;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/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.0'
9 |
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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 26 20:06:09 CST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/image/UI.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/image/UI.gif
--------------------------------------------------------------------------------
/lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 23
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(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.4.0'
25 | }
26 |
--------------------------------------------------------------------------------
/lib/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 D:\dev\andorid_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 |
--------------------------------------------------------------------------------
/lib/src/androidTest/java/com/android/yzl/lib/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.android.yzl.lib;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/android/yzl/lib/AnimView.java:
--------------------------------------------------------------------------------
1 | package com.android.yzl.lib;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Path;
7 | import android.util.AttributeSet;
8 | import android.util.TypedValue;
9 | import android.view.View;
10 |
11 | /**
12 | * Created by yzl on 2016/6/2.
13 | */
14 | public class AnimView extends View {
15 |
16 | boolean isBezierBackDone = false;
17 |
18 | private int mWidth;
19 | private int mHeight;
20 | private int PULL_WIDTH;
21 | private int PULL_DELTA;
22 |
23 | private long mStart;
24 | private long mStop;
25 | private int mBezierDeta;
26 |
27 | private long bezierBackDur;
28 |
29 | private Paint mBackPaint;
30 | private Path mPath;
31 |
32 | private AnimatorStatus mAniStatus = AnimatorStatus.PULL_LEFT;
33 |
34 | enum AnimatorStatus{
35 | PULL_LEFT,
36 | DRAG_LEFT,
37 | RELEASE,
38 | }
39 |
40 | public AnimView(Context context) {
41 | this(context, null, 0);
42 | }
43 |
44 | public AnimView(Context context, AttributeSet attrs) {
45 | this(context, attrs, 0);
46 | }
47 |
48 | public AnimView(Context context, AttributeSet attrs, int defStyleAttr) {
49 | super(context, attrs, defStyleAttr);
50 | init(context);
51 | }
52 |
53 | private void init(Context context){
54 | PULL_WIDTH = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, context.getResources().getDisplayMetrics());
55 | PULL_DELTA = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 80, context.getResources().getDisplayMetrics());
56 |
57 | mPath = new Path();
58 | mBackPaint = new Paint();
59 | mBackPaint.setAntiAlias(true);
60 | mBackPaint.setStyle(Paint.Style.FILL);
61 | }
62 |
63 | @Override
64 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
65 | int width = MeasureSpec.getSize(widthMeasureSpec);
66 | if (width > PULL_DELTA + PULL_WIDTH) {
67 | widthMeasureSpec = MeasureSpec.makeMeasureSpec(PULL_DELTA + PULL_WIDTH, MeasureSpec.getMode(widthMeasureSpec));
68 | }
69 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
70 | }
71 |
72 | @Override
73 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
74 | super.onLayout(changed, left, top, right, bottom);
75 | if (changed) {
76 | mWidth = getWidth();
77 | mHeight = getHeight();
78 |
79 | if (mWidth < PULL_WIDTH) {
80 | mAniStatus = AnimatorStatus.PULL_LEFT;
81 | }
82 |
83 |
84 | switch (mAniStatus) {
85 | case PULL_LEFT:
86 | if (mWidth >= PULL_WIDTH) {
87 | mAniStatus = AnimatorStatus.DRAG_LEFT;
88 | }
89 | break;
90 | }
91 |
92 | }
93 | }
94 |
95 |
96 |
97 | @Override
98 | protected void onDraw(Canvas canvas) {
99 | super.onDraw(canvas);
100 | switch (mAniStatus){
101 | case PULL_LEFT:
102 | canvas.drawRect(0, 0, mWidth, mHeight, mBackPaint);
103 | break;
104 | case DRAG_LEFT:
105 | drawDrag(canvas);
106 | break;
107 | case RELEASE:
108 | drawBack(canvas, getBezierDelta());
109 | break;
110 | }
111 | }
112 |
113 | private void drawDrag(Canvas canvas) {
114 | canvas.drawRect(mWidth - PULL_WIDTH, 0, mWidth, mHeight, mBackPaint);
115 |
116 | mPath.reset();
117 | mPath.moveTo(mWidth - PULL_WIDTH, 0);
118 | mPath.quadTo(0, mHeight / 2, mWidth - PULL_WIDTH, mHeight);
119 | canvas.drawPath(mPath, mBackPaint);
120 | }
121 |
122 | private void drawBack(Canvas canvas, int delta){
123 | mPath.reset();
124 | mPath.moveTo(mWidth, 0);
125 | mPath.lineTo(mWidth - PULL_WIDTH, 0);
126 | mPath.quadTo(delta, mHeight / 2, mWidth - PULL_WIDTH, mHeight);
127 | mPath.lineTo(mWidth, mHeight);
128 | canvas.drawPath(mPath, mBackPaint);
129 |
130 | invalidate();
131 |
132 | if(bezierBackRatio == 1){
133 | isBezierBackDone = true;
134 | }
135 |
136 | if(isBezierBackDone && mWidth <= PULL_WIDTH){
137 | drawFooterBack(canvas);
138 | }
139 | }
140 |
141 | private void drawFooterBack(Canvas canvas){
142 | canvas.drawRect(0, 0, mWidth, mHeight, mBackPaint);
143 | }
144 |
145 | public void releaseDrag(){
146 | mAniStatus = AnimatorStatus.RELEASE;
147 | mStart = System.currentTimeMillis();
148 | mStop = mStart + bezierBackDur;
149 | mBezierDeta = mWidth - PULL_WIDTH;
150 | isBezierBackDone = false;
151 | requestLayout();
152 | }
153 |
154 | public void setBezierBackDur(long bezierBackDur) {
155 | this.bezierBackDur = bezierBackDur;
156 | }
157 |
158 | private float bezierBackRatio;
159 |
160 | private int getBezierDelta() {
161 | bezierBackRatio = getBezierBackRatio();
162 | return (int) (mBezierDeta * bezierBackRatio);
163 | }
164 |
165 | private float getBezierBackRatio() {
166 | if (System.currentTimeMillis() >= mStop) {
167 | return 1;
168 | }
169 | float ratio = (System.currentTimeMillis() - mStart) / (float) bezierBackDur;
170 | return Math.min(1, ratio);
171 | }
172 |
173 | public void setBgColor(int color){
174 | mBackPaint.setColor(color);
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/android/yzl/lib/OnScrollListener.java:
--------------------------------------------------------------------------------
1 | package com.android.yzl.lib;
2 |
3 | /**
4 | * Created by yzl on 2016/6/3.
5 | */
6 | public interface OnScrollListener {
7 |
8 | void onScrollChange(boolean scroll);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/android/yzl/lib/PullLeftToRefreshLayout.java:
--------------------------------------------------------------------------------
1 | package com.android.yzl.lib;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Color;
8 | import android.support.annotation.NonNull;
9 | import android.support.v4.view.ViewCompat;
10 | import android.util.AttributeSet;
11 | import android.util.TypedValue;
12 | import android.view.Gravity;
13 | import android.view.LayoutInflater;
14 | import android.view.MotionEvent;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.view.animation.Animation;
18 | import android.view.animation.DecelerateInterpolator;
19 | import android.view.animation.Interpolator;
20 | import android.view.animation.LinearInterpolator;
21 | import android.view.animation.RotateAnimation;
22 | import android.widget.FrameLayout;
23 | import android.widget.ImageView;
24 | import android.widget.TextView;
25 |
26 | /**
27 | * Created by yzl on 2016/6/6.
28 | */
29 | public class PullLeftToRefreshLayout extends FrameLayout {
30 |
31 | private static final Interpolator ANIMATION_INTERPOLATOR = new LinearInterpolator();
32 | private static final long BACK_ANIM_DUR = 500;
33 | private static final long BEZIER_BACK_DUR = 350;
34 | private static final int ROTATION_ANIM_DUR = 200;
35 |
36 | /**
37 | * MoreView移动的最大距离
38 | */
39 | private static float MORE_VIEW_MOVE_DIMEN;
40 | private static final int ROTATION_ANGLE = 180;
41 |
42 | private static String SCAN_MORE;
43 | private static String RELEASE_SCAN_MORE;
44 |
45 | private float mTouchStartX;
46 | private float mTouchCurX;
47 |
48 | private float mPullWidth;
49 | private float mFooterWidth;
50 |
51 | /**
52 | * 目的是为了将moreView隐藏以便滑动
53 | */
54 | private int moreViewMarginRight;
55 | private int footerViewBgColor;
56 |
57 | private boolean isRefresh = false;
58 | private boolean scrollState = false;
59 |
60 | private View mChildView;
61 | private AnimView footerView;
62 | private View moreView;
63 | private TextView moreText;
64 | private ImageView arrowIv;
65 |
66 | private ValueAnimator mBackAnimator;
67 | private RotateAnimation mArrowRotateAnim;
68 | private RotateAnimation mArrowRotateBackAnim;
69 |
70 | OnScrollListener onScrollListener;
71 | OnRefreshListener onRefreshListener;
72 |
73 | private DecelerateInterpolator interpolator = new DecelerateInterpolator(10);
74 |
75 | public PullLeftToRefreshLayout(Context context) {
76 | this(context, null, 0);
77 | }
78 |
79 | public PullLeftToRefreshLayout(Context context, AttributeSet attrs) {
80 | this(context, attrs, 0);
81 | }
82 |
83 | public PullLeftToRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
84 | super(context, attrs, defStyleAttr);
85 | init(context, attrs);
86 | }
87 |
88 | private void init(Context context, AttributeSet attrs) {
89 | mPullWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, context.getResources().getDisplayMetrics());
90 | MORE_VIEW_MOVE_DIMEN = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, context.getResources().getDisplayMetrics());
91 | mFooterWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, context.getResources().getDisplayMetrics());
92 | moreViewMarginRight = -getResources().getDimensionPixelSize(R.dimen.dp_26);
93 | SCAN_MORE = getResources().getString(R.string.scan_more);
94 | RELEASE_SCAN_MORE = getResources().getString(R.string.release_scan_more);
95 |
96 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PullLeftToRefreshLayout);
97 | footerViewBgColor = ta.getColor(R.styleable.PullLeftToRefreshLayout_footerBgColor, Color.rgb(243, 242, 242));
98 | ta.recycle();
99 |
100 | this.post(new Runnable() {
101 | @Override
102 | public void run() {
103 | mChildView = getChildAt(0);
104 | addFooterView();
105 | addMoreView();
106 | initBackAnim();
107 | initRotateAnim();
108 | }
109 | });
110 | }
111 |
112 | private void addFooterView() {
113 | LayoutParams params = new LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
114 | params.gravity = Gravity.RIGHT;
115 |
116 | footerView = new AnimView(getContext());
117 | footerView.setLayoutParams(params);
118 | footerView.setBgColor(footerViewBgColor);
119 | footerView.setBezierBackDur(BEZIER_BACK_DUR);
120 | addViewInternal(footerView);
121 | }
122 |
123 | private void addMoreView() {
124 | LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
125 | params.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
126 | params.setMargins(0, 0, moreViewMarginRight, 0);
127 |
128 | moreView = LayoutInflater.from(getContext()).inflate(R.layout.item_load_more, this, false);
129 | moreView.setLayoutParams(params);
130 | moreText = (TextView) moreView.findViewById(R.id.tvMoreText);
131 | arrowIv = (ImageView) moreView.findViewById(R.id.ivRefreshArrow);
132 |
133 | addViewInternal(moreView);
134 | }
135 |
136 | private void initRotateAnim() {
137 | int pivotType = Animation.RELATIVE_TO_SELF;
138 | float pivotValue = 0.5f;
139 | mArrowRotateAnim = new RotateAnimation(0, ROTATION_ANGLE, pivotType, pivotValue, pivotType, pivotValue);
140 | mArrowRotateAnim.setInterpolator(ANIMATION_INTERPOLATOR);
141 | mArrowRotateAnim.setDuration(ROTATION_ANIM_DUR);
142 | mArrowRotateAnim.setFillAfter(true);
143 |
144 | mArrowRotateBackAnim = new RotateAnimation(ROTATION_ANGLE, 0, pivotType, pivotValue, pivotType, pivotValue);
145 | mArrowRotateBackAnim.setInterpolator(ANIMATION_INTERPOLATOR);
146 | mArrowRotateBackAnim.setDuration(ROTATION_ANIM_DUR);
147 | mArrowRotateBackAnim.setFillAfter(true);
148 | }
149 |
150 | private void initBackAnim() {
151 | if (mChildView == null) {
152 | return;
153 | }
154 | mBackAnimator = ValueAnimator.ofFloat(mPullWidth, 0);
155 | mBackAnimator.addListener(new AnimListener());
156 | mBackAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
157 | @Override
158 | public void onAnimationUpdate(ValueAnimator animation) {
159 | float val = (float) animation.getAnimatedValue();
160 | if (val <= mFooterWidth) {
161 | val = interpolator.getInterpolation(val / mFooterWidth) * val;
162 | footerView.getLayoutParams().width = (int) val;
163 | footerView.requestLayout();
164 | }
165 |
166 | if (mChildView != null) {
167 | mChildView.setTranslationX(-val);
168 | }
169 |
170 | moveMoreView(val, true);
171 | }
172 | });
173 | mBackAnimator.setDuration(BACK_ANIM_DUR);
174 | }
175 |
176 | private void addViewInternal(@NonNull View child) {
177 | super.addView(child);
178 | }
179 |
180 | @Override
181 | public void addView(View child) {
182 | if (getChildCount() >= 1) {
183 | throw new RuntimeException("you can only attach one child");
184 | }
185 |
186 | mChildView = child;
187 | super.addView(child);
188 | }
189 |
190 |
191 | @Override
192 | public boolean onInterceptTouchEvent(MotionEvent ev) {
193 | if (isRefresh) {
194 | return true;
195 | }
196 |
197 | switch (ev.getAction()) {
198 | case MotionEvent.ACTION_DOWN:
199 | mTouchStartX = ev.getX();
200 | mTouchCurX = mTouchStartX;
201 | setScrollState(false);
202 | break;
203 | case MotionEvent.ACTION_MOVE:
204 | float curX = ev.getX();
205 | float dx = curX - mTouchStartX;
206 |
207 | if (dx < -10 && !canScrollRight()) {//点击事件要传回子类
208 | setScrollState(true);
209 | return true;
210 | }
211 | }
212 | return super.onInterceptTouchEvent(ev);
213 | }
214 |
215 | @Override
216 | public boolean onTouchEvent(MotionEvent event) {
217 | if (isRefresh) {
218 | return super.onTouchEvent(event);
219 | }
220 |
221 | switch (event.getAction()) {
222 | case MotionEvent.ACTION_MOVE:
223 | mTouchCurX = event.getX();
224 | float dx = mTouchStartX - mTouchCurX;
225 | dx = Math.min(mPullWidth * 2, dx);
226 | dx = Math.max(0, dx);
227 |
228 | if (mChildView == null || dx <= 0) {
229 | return true;
230 | }
231 |
232 | float unit = dx / 2;
233 | float offsetx = interpolator.getInterpolation(unit / mPullWidth) * unit;
234 | mChildView.setTranslationX(-offsetx);
235 | footerView.getLayoutParams().width = (int) offsetx;
236 | footerView.requestLayout();
237 |
238 | moveMoreView(offsetx, false);
239 |
240 | return true;
241 | case MotionEvent.ACTION_UP:
242 | case MotionEvent.ACTION_CANCEL:
243 | if (mChildView == null) {
244 | return true;
245 | }
246 |
247 | float childDx = Math.abs(mChildView.getTranslationX());
248 | if (childDx >= mFooterWidth) {
249 | mBackAnimator.setFloatValues(childDx, 0);
250 | mBackAnimator.start();
251 | footerView.releaseDrag();
252 |
253 | if (reachReleasePoint()) {
254 | isRefresh = true;
255 | }
256 | } else {
257 | mBackAnimator.setFloatValues(childDx, 0);
258 | mBackAnimator.start();
259 | }
260 |
261 | setScrollState(false);
262 |
263 | return true;
264 | }
265 |
266 | return super.onTouchEvent(event);
267 | }
268 |
269 | /**
270 | * direction Negative to check scrolling left, positive to check scrolling right
271 | *
272 | * @return
273 | */
274 | private boolean canScrollRight() {
275 | if (mChildView == null) {
276 | return false;
277 | }
278 |
279 | return ViewCompat.canScrollHorizontally(mChildView, 1);
280 | }
281 |
282 | private void moveMoreView(float offsetx, boolean release) {
283 | float dx = offsetx / 2;
284 | if (dx <= MORE_VIEW_MOVE_DIMEN) {
285 | moreView.setTranslationX(-dx);
286 | if (!release && switchMoreText(SCAN_MORE)) {
287 | arrowIv.clearAnimation();
288 | arrowIv.startAnimation(mArrowRotateBackAnim);
289 | }
290 | } else {
291 | if (switchMoreText(RELEASE_SCAN_MORE)) {
292 | arrowIv.clearAnimation();
293 | arrowIv.startAnimation(mArrowRotateAnim);
294 | }
295 | }
296 | }
297 |
298 | private boolean switchMoreText(String text) {
299 | if (text.equals(moreText.getText().toString())) {
300 | return false;
301 | }
302 | moreText.setText(text);
303 | return true;
304 | }
305 |
306 | private boolean reachReleasePoint() {
307 | return RELEASE_SCAN_MORE.equals(moreText.getText().toString());
308 | }
309 |
310 | private class AnimListener implements Animator.AnimatorListener {
311 |
312 | @Override
313 | public void onAnimationStart(Animator animator) {
314 | }
315 |
316 | @Override
317 | public void onAnimationEnd(Animator animator) {
318 | if (onRefreshListener != null && isRefresh) {
319 | onRefreshListener.onRefresh();
320 | }
321 | moreText.setText(SCAN_MORE);
322 | arrowIv.clearAnimation();
323 | isRefresh = false;
324 | }
325 |
326 | @Override
327 | public void onAnimationCancel(Animator animator) {
328 | }
329 |
330 | @Override
331 | public void onAnimationRepeat(Animator animator) {
332 | }
333 | }
334 |
335 | private void setScrollState(boolean scrollState) {
336 | if (this.scrollState == scrollState) {
337 | return;
338 | }
339 | this.scrollState = scrollState;
340 | if (onScrollListener != null) {
341 | onScrollListener.onScrollChange(scrollState);
342 | }
343 | }
344 |
345 | public void setOnScrollListener(OnScrollListener onScrollListener) {
346 | this.onScrollListener = onScrollListener;
347 | }
348 |
349 | public void setOnRefreshListener(OnRefreshListener onRefreshListener) {
350 | this.onRefreshListener = onRefreshListener;
351 | }
352 |
353 | public interface OnRefreshListener {
354 | void onRefresh();
355 | }
356 |
357 | }
358 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-xxhdpi/arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/lib/src/main/res/drawable-xxhdpi/arrow.png
--------------------------------------------------------------------------------
/lib/src/main/res/layout/item_load_more.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
23 |
24 |
--------------------------------------------------------------------------------
/lib/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/lib/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/lib/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/lib/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/lib/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yzl520/PullLeftToRefreshLayout/d8a4fa2c18ff65a03555d9aa3ff91d427b3c1eb4/lib/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #a8a7a7
7 |
8 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 6dp
6 | 12dp
7 | 26dp
8 |
9 | 10sp
10 |
11 |
12 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | lib
3 | 查看更多
4 | 释放查看
5 |
6 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/lib/src/test/java/com/android/yzl/lib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.android.yzl.lib;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':lib'
2 |
--------------------------------------------------------------------------------