├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── Screenshot
├── bouncing-jelly-view-recyclerview.gif
└── bouncing-jelly-view普通情况.gif
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── aohanyao
│ │ └── bouncingjelly
│ │ ├── ListActivity.java
│ │ ├── MainActivity.java
│ │ ├── ScrollActivity.java
│ │ └── adapter
│ │ └── RecyclerAdapter.java
│ └── res
│ ├── drawable
│ ├── ic_chevron_right_black_24dp.xml
│ └── ic_settings_black_24dp.xml
│ ├── layout
│ ├── activity_list.xml
│ ├── activity_main.xml
│ ├── activity_main2.xml
│ ├── activity_main22.xml
│ ├── activity_scroll.xml
│ ├── content_list.xml
│ ├── content_main.xml
│ ├── content_main2.xml
│ ├── content_scroll.xml
│ ├── layout_list_item.xml
│ └── layout_setting_item.xml
│ ├── menu
│ └── menu_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ ├── icon_20_turn_right.png
│ └── info.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-v21
│ └── styles.xml
│ ├── 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
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── aohanyao
│ │ └── jelly
│ │ └── library
│ │ ├── BouncingJellyView.java
│ │ ├── inf
│ │ └── BouncingJellyListener.java
│ │ └── util
│ │ ├── BouncingInterpolatorType.java
│ │ ├── BouncingScreenUtils.java
│ │ └── BouncingType.java
│ └── res
│ └── values
│ ├── attr.xml
│ └── strings.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/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 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.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 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 | 1.8
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/.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 | ##BouncingJellyView
2 |
3 | ### 最新版本: [](https://jitpack.io/#aohanyao/BouncingJelly)
4 |
5 | 可以嵌套任何View,滑动到顶部或者底部,会有一个阻尼效果进行缩放整个页面,松开手指回弹。灵感来自于MIUI。
6 |
7 | ### 效果图
8 | #### 1. 普通的页面
9 | 
10 | #### 2. 嵌套RecyclerView
11 | 
12 | ### 使用
13 | 1. 添加Jitpack
14 |
15 | allprojects {
16 | repositories {
17 | ...
18 | maven { url 'https://jitpack.io' }
19 | }
20 | }
21 |
22 | 2. 在gradle中compile
23 |
24 | compile 'com.github.aohanyao:BouncingJelly:1.0.4'
25 |
26 | 3. xml
27 |
28 | 因为BouncingJellyView是继承自ScrollView,所以必须要嵌套一层ViewGroup才能使用。
29 |
30 |
31 | ```xml
32 |
33 |
38 |
39 | <任意ViewGroup>
40 | .........你的内容
41 | 任意ViewGroup>
42 |
43 |
44 |
45 | ```
46 |
47 |
48 |
49 |
50 | ### Version History
51 | ### 2018年3月6日
52 | 修复[issues/1#](https://github.com/aohanyao/BouncingJelly/issues/1#issuecomment-370310890)
53 |
54 | #### 2018年3月5日
55 | 剔除多余的包
56 |
57 | #### 2017年1月11日
58 | 1.0.0
59 |
60 | 初步完成,增加到仓库。
--------------------------------------------------------------------------------
/Screenshot/bouncing-jelly-view-recyclerview.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aohanyao/BouncingJelly/e2771db74658938fbffb3618a111a85c8c33915a/Screenshot/bouncing-jelly-view-recyclerview.gif
--------------------------------------------------------------------------------
/Screenshot/bouncing-jelly-view普通情况.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aohanyao/BouncingJelly/e2771db74658938fbffb3618a111a85c8c33915a/Screenshot/bouncing-jelly-view普通情况.gif
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | //apply plugin: 'kotlin-android'
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "26.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.aohanyao.bouncingjelly"
9 | minSdkVersion 15
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 |
22 | }
23 |
24 | dependencies {
25 | compile fileTree(include: ['*.jar'], dir: 'libs')
26 | testCompile 'junit:junit:4.12'
27 | compile 'com.android.support:appcompat-v7:24.2.1'
28 | compile 'com.android.support:design:24.2.1'
29 | compile 'com.android.support:cardview-v7:24.2.1'
30 | compile project(':library')
31 | }
32 |
--------------------------------------------------------------------------------
/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:\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 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aohanyao/bouncingjelly/ListActivity.java:
--------------------------------------------------------------------------------
1 | package com.aohanyao.bouncingjelly;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.support.v4.widget.SwipeRefreshLayout;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.LinearLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.support.v7.widget.Toolbar;
10 |
11 | import com.aohanyao.bouncingjelly.adapter.RecyclerAdapter;
12 |
13 | public class ListActivity extends AppCompatActivity {
14 |
15 | private RecyclerView rl;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_list);
21 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
22 | setSupportActionBar(toolbar);
23 | rl = (RecyclerView) findViewById(R.id.rl);
24 | initRecyclerView();
25 | }
26 |
27 | private void initRecyclerView() {
28 | RecyclerAdapter mAdapter = new RecyclerAdapter(this);
29 | LinearLayoutManager layoutManager = new LinearLayoutManager(this);
30 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
31 | rl.setLayoutManager(layoutManager);
32 | rl.setAdapter(mAdapter);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aohanyao/bouncingjelly/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.aohanyao.bouncingjelly;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 | import android.view.View;
10 |
11 | public class MainActivity extends AppCompatActivity {
12 |
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
19 | setSupportActionBar(toolbar);
20 | }
21 |
22 | public void ordinary(View view) {
23 | startActivity(new Intent(this, ScrollActivity.class));
24 | }
25 |
26 | public void list(View view) {
27 | startActivity(new Intent(this, ListActivity.class));
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aohanyao/bouncingjelly/ScrollActivity.java:
--------------------------------------------------------------------------------
1 | package com.aohanyao.bouncingjelly;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.Toolbar;
6 |
7 | public class ScrollActivity extends AppCompatActivity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_scroll);
13 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
14 | setSupportActionBar(toolbar);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aohanyao/bouncingjelly/adapter/RecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.aohanyao.bouncingjelly.adapter;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.aohanyao.bouncingjelly.R;
11 |
12 | import java.util.Random;
13 |
14 | /**
15 | *
作者:江俊超 on 2016/8/31 11:00
16 | * 邮箱:928692385@qq.com
17 | *
18 | */
19 | public class RecyclerAdapter extends RecyclerView.Adapter {
20 | private Context mContext;
21 |
22 | public RecyclerAdapter(Context mContext) {
23 | this.mContext = mContext;
24 | }
25 |
26 | @Override
27 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
28 | View view = LayoutInflater.from(mContext).inflate(R.layout.layout_list_item, null);
29 | return new ViewHolder(view);
30 | }
31 |
32 | @Override
33 | public void onBindViewHolder(ViewHolder holder, int position) {
34 | holder.setBg();
35 | }
36 |
37 | @Override
38 | public int getItemCount() {
39 | return 20;
40 | }
41 |
42 | class ViewHolder extends RecyclerView.ViewHolder {
43 | private View v_forget;
44 |
45 | public ViewHolder(View itemView) {
46 | super(itemView);
47 | v_forget= itemView.findViewById(R.id.v_forget);
48 | }
49 |
50 | public void setBg() {
51 | v_forget.setBackgroundColor(Color.parseColor(getRandColorCode()));
52 | }
53 | }
54 |
55 | /**
56 | * 获取十六进制的颜色代码.例如 "#6E36B4" , For HTML ,
57 | *
58 | * @return String
59 | */
60 | public String getRandColorCode() {
61 | String r, g, b;
62 | Random random = new Random();
63 | r = Integer.toHexString(random.nextInt(256)).toUpperCase();
64 | g = Integer.toHexString(random.nextInt(256)).toUpperCase();
65 | b = Integer.toHexString(random.nextInt(256)).toUpperCase();
66 |
67 | r = r.length() == 1 ? "0" + r : r;
68 | g = g.length() == 1 ? "0" + g : g;
69 | b = b.length() == 1 ? "0" + b : b;
70 |
71 | return "#FF"+r + g + b;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_chevron_right_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_settings_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main22.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scroll.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
16 |
17 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_scroll.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_setting_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
18 |
19 |
25 |
26 |
30 |
31 |
35 |
36 |
45 |
46 |
47 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aohanyao/BouncingJelly/e2771db74658938fbffb3618a111a85c8c33915a/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aohanyao/BouncingJelly/e2771db74658938fbffb3618a111a85c8c33915a/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/icon_20_turn_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aohanyao/BouncingJelly/e2771db74658938fbffb3618a111a85c8c33915a/app/src/main/res/mipmap-mdpi/icon_20_turn_right.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aohanyao/BouncingJelly/e2771db74658938fbffb3618a111a85c8c33915a/app/src/main/res/mipmap-mdpi/info.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aohanyao/BouncingJelly/e2771db74658938fbffb3618a111a85c8c33915a/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aohanyao/BouncingJelly/e2771db74658938fbffb3618a111a85c8c33915a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aohanyao/BouncingJelly/e2771db74658938fbffb3618a111a85c8c33915a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
13 |
--------------------------------------------------------------------------------
/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#e3e3e3
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BouncingJelly
3 | Settings
4 | ListActivity
5 | Main2Activity
6 | ScrollActivity
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
20 |
21 |
22 |
23 |
24 |
25 |
34 |
35 |
43 |
44 |
50 |
51 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 |
3 | repositories {
4 | maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
5 |
6 | jcenter()
7 | maven {
8 | url 'https://maven.google.com/'
9 | name 'Google'
10 | }
11 | }
12 | dependencies {
13 | classpath 'com.android.tools.build:gradle:3.0.1'
14 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
15 | classpath "com.github.dcendents:android-maven-gradle-plugin:2.0"
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
22 |
23 | jcenter()
24 | maven { url "https://jitpack.io" }
25 |
26 | maven {
27 | url 'https://maven.google.com/'
28 | name 'Google'
29 | }
30 | }
31 | }
32 |
33 |
34 | repositories {
35 | mavenCentral()
36 | }
37 |
--------------------------------------------------------------------------------
/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/aohanyao/BouncingJelly/e2771db74658938fbffb3618a111a85c8c33915a/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Dec 29 11:55:20 CST 2017
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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | android {
4 | compileSdkVersion 24
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 15
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | lintOptions {
18 | checkReleaseBuilds false
19 | abortOnError false
20 | }
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 |
28 | }
29 |
30 | // 打包源码jar
31 | task sourcesJar(type: Jar) {
32 | from android.sourceSets.main.java.srcDirs
33 | classifier = 'sources'
34 | }
35 | //编译groovy代码时采用 UTF-8
36 | tasks.withType(GroovyCompile) {
37 | groovyOptions.encoding = "MacRoman"
38 | }
39 |
40 | //编译JAVA文件时采用UTF-8
41 | tasks.withType(JavaCompile) {
42 | options.encoding = "UTF-8"
43 | }
44 |
45 | task javadoc(type: Javadoc) {
46 | failOnError false
47 | source = android.sourceSets.main.java.sourceFiles
48 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
49 | classpath += configurations.compile
50 | }
51 |
52 | // 打包文档jar
53 | task javadocJar(type: Jar, dependsOn: javadoc) {
54 | classifier = 'javadoc'
55 | from javadoc.destinationDir
56 | }
57 |
58 | artifacts {
59 | archives sourcesJar
60 | archives javadocJar
61 | }
62 |
63 |
64 | dependencies {
65 | implementation 'com.android.support:support-v4:24.2.1'
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/library/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:\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 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/library/src/main/java/com/aohanyao/jelly/library/BouncingJellyView.java:
--------------------------------------------------------------------------------
1 | package com.aohanyao.jelly.library;
2 |
3 | import android.animation.TimeInterpolator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.support.v4.widget.NestedScrollView;
8 | import android.util.AttributeSet;
9 | import android.util.Log;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.view.ViewConfiguration;
13 | import android.view.animation.OvershootInterpolator;
14 |
15 | import com.aohanyao.jelly.library.inf.BouncingJellyListener;
16 | import com.aohanyao.jelly.library.util.BouncingInterpolatorType;
17 | import com.aohanyao.jelly.library.util.BouncingType;
18 | import com.aohanyao.jelly.library.util.BouncingScreenUtils;
19 |
20 | /**
21 | * 作者:江俊超 on 2016/8/30 14:42
22 | * ScrollView
23 | * ver
24 | * ---------------------------------------
25 | * 2018年3月6日11:43:01
26 | * 修复:https://github.com/aohanyao/BouncingJelly/issues/1#
27 | * 产生原因是:
28 | * ①没有设置setFillViewport,导致子ViewGroup不是全部铺满的
29 | * ②在onSizeChang中错误的赋值
30 | * ---------------------------------------
31 | */
32 | public class BouncingJellyView extends NestedScrollView {
33 | private int onInterceptTouchDownY;
34 | private int dispatchTouchDowY;
35 | private float bouncingOffset = 2850f;
36 | private float offsetScale;
37 | private ValueAnimator animator;
38 | private boolean isTop = true;
39 | private String TAG = "BouncingJellyScroolView";
40 | /**
41 | * 回调
42 | */
43 | private BouncingJellyListener onBouncingJellyListener;
44 | private TimeInterpolator mTimeInterpolator;//差值器
45 | private int mBouncingDuration = 300;//回弹的时间
46 | private int mBouncingType;
47 | private View childView;
48 |
49 | private int mTouchSlop;
50 |
51 | public BouncingJellyView(Context context) {
52 | this(context, null);
53 | }
54 |
55 | public BouncingJellyView(Context context, AttributeSet attrs) {
56 | this(context, attrs, 0);
57 | }
58 |
59 | public BouncingJellyView(Context context, AttributeSet attrs, int defStyleAttr) {
60 | super(context, attrs, defStyleAttr);
61 | initAttr(attrs);
62 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
63 |
64 | }
65 |
66 | @Override
67 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
68 | super.onLayout(changed, l, t, r, b);
69 | childView = getChildAt(0);
70 | }
71 |
72 | /**
73 | * @param attrs
74 | */
75 | private void initAttr(AttributeSet attrs) {
76 | if (attrs != null) {
77 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.BouncingJellyView);
78 | //差值器
79 | mTimeInterpolator = BouncingInterpolatorType.getTimeInterpolator(typedArray.getInteger(
80 | R.styleable.BouncingJellyView_BouncingInterpolator
81 | , BouncingInterpolatorType.OVERSHOOT_INTERPOLATOR));
82 | //回弹速度
83 | mBouncingDuration = typedArray.getInteger(R.styleable.BouncingJellyView_BouncingDuration, mBouncingDuration);
84 | //果冻类型
85 | mBouncingType = typedArray.getInt(R.styleable.BouncingJellyView_BouncingType, BouncingType.BOTH);
86 | typedArray.recycle();
87 | //获取是差值 整个屏幕的三倍大小
88 | bouncingOffset = BouncingScreenUtils.getScreenHeight(getContext()) * 3;
89 | //2018年3月6日11:31:59 修复bug,设置子view铺满
90 | setFillViewport(true);
91 | }
92 | }
93 |
94 |
95 | /**
96 | * 从顶部开始滑动
97 | */
98 | public void startBouncingTo() {
99 | //设置X坐标点
100 | childView.setPivotX(getWidth() / 2);
101 | //设置Y坐标点
102 | childView.setPivotY(0);
103 | //进行缩放
104 | childView.setScaleY(1.0f + offsetScale);
105 | if (onBouncingJellyListener != null) {
106 | onBouncingJellyListener.onBouncingJellyTop(1.0f + offsetScale);
107 | }
108 | }
109 |
110 | /**
111 | * 从底部开始滑动
112 | */
113 | public void startBouncingBottom() {
114 | //设置X坐标点
115 | childView.setPivotX(getWidth() / 2);
116 | //设置Y坐标点
117 | childView.setPivotY(childView.getHeight());
118 | //开始缩放
119 | childView.setScaleY(1.0f + offsetScale);
120 | if (onBouncingJellyListener != null) {
121 | onBouncingJellyListener.onBouncingJellyBottom(1.0f + offsetScale);
122 | }
123 | }
124 |
125 |
126 | @Override
127 | public boolean dispatchTouchEvent(MotionEvent event) {
128 | switch (event.getAction()) {
129 | case MotionEvent.ACTION_DOWN:
130 | //按下坐标 用于计算缩放值
131 | dispatchTouchDowY = (int) event.getRawY();
132 | break;
133 | case MotionEvent.ACTION_MOVE:
134 | if (mBouncingType != BouncingType.NONE) {
135 | //移动的y轴
136 | int moveY = (int) event.getRawY();
137 | //dy值 判断方向
138 | int dy = moveY - dispatchTouchDowY;
139 |
140 | //y轴滚动
141 | int scrollY = getScrollY();
142 | //获得当前高度
143 | int getHeight = getHeight();
144 | //滚动范围高度
145 | int computeVerticalScrollRange = computeVerticalScrollRange();
146 |
147 | //顶部
148 | if (dy > 0 && scrollY == 0) {
149 | //判断果冻的类型
150 | if (mBouncingType == BouncingType.TOP || mBouncingType == BouncingType.BOTH) {
151 | //获取现在坐标与按下坐标的差值
152 | int abs = moveY - dispatchTouchDowY;
153 | //计算缩放值
154 | offsetScale = (Math.abs(abs) / bouncingOffset);
155 | if (offsetScale > 0.3f) {
156 | offsetScale = 0.3f;
157 | }
158 | isTop = true;
159 | startBouncingTo();
160 | return true;
161 | }
162 | } else if (scrollY == 0 && dy > 0 && offsetScale > 0) {//为顶部 并且dy为下拉 并且缩放值大于0
163 | //这一段主要是为了防止卡顿 闪屏
164 | if (mBouncingType == BouncingType.TOP || mBouncingType == BouncingType.BOTH) {
165 | //获取现在坐标与按下坐标的差值
166 | int abs = moveY - dispatchTouchDowY;
167 | //计算缩放值
168 | offsetScale = (Math.abs(abs) / bouncingOffset);
169 | if (offsetScale > 0.3f) {
170 | offsetScale = 0.3f;
171 | }
172 | if (abs <= 0) {
173 | offsetScale = 0;
174 | dispatchTouchDowY = moveY;
175 | }
176 | isTop = true;
177 | startBouncingTo();
178 | return true;
179 | }
180 | }
181 |
182 | //底部
183 | if (dy < 0 && scrollY + getHeight >= computeVerticalScrollRange) {//滚动到底部
184 | if (mBouncingType == BouncingType.BOTTOM || mBouncingType == BouncingType.BOTH) {
185 | int abs = moveY - dispatchTouchDowY;
186 | offsetScale = (Math.abs(abs) / bouncingOffset);
187 | if (offsetScale > 0.3f) {
188 | offsetScale = 0.3f;
189 | }
190 | isTop = false;
191 | startBouncingBottom();
192 | }
193 | } else if (dy > 0 && scrollY + getHeight >= computeVerticalScrollRange && offsetScale > 0) {
194 | // 防止卡顿闪屏
195 | if (mBouncingType == BouncingType.BOTTOM || mBouncingType == BouncingType.BOTH) {
196 | int abs = moveY - dispatchTouchDowY;
197 | offsetScale = (Math.abs(abs) / bouncingOffset);
198 | if (offsetScale > 0.3f) {
199 | offsetScale = 0.3f;
200 | }
201 | if (abs >= 0) {
202 | offsetScale = 0;
203 | dispatchTouchDowY = moveY;
204 | }
205 | isTop = false;
206 | startBouncingBottom();
207 | return true;
208 | }
209 | }
210 | }
211 | break;
212 | case MotionEvent.ACTION_UP:
213 | //回滚到初始点
214 | if (mBouncingType != BouncingType.NONE) {
215 | if (offsetScale > 0) {
216 | backBouncing(offsetScale, 0);
217 | return true;
218 | }
219 | }
220 | break;
221 | }
222 | return super.dispatchTouchEvent(event);
223 | }
224 |
225 | @Override
226 | public boolean onInterceptTouchEvent(MotionEvent e) {
227 | int action = e.getAction();
228 | Log.e(TAG, "onInterceptTouchEvent: " );
229 | switch (action) {
230 | case MotionEvent.ACTION_DOWN:
231 | onInterceptTouchDownY = (int) e.getX();
232 | break;
233 | case MotionEvent.ACTION_MOVE:
234 | int moveY = (int) e.getX();
235 | //判断是否达到最小滚动值
236 | int abs = Math.abs(onInterceptTouchDownY - moveY);
237 | Log.e(TAG, "onInterceptTouchEvent: 拦截事件:" + abs);
238 | if (abs > mTouchSlop) {
239 | return true;
240 | }
241 | }
242 | // 一次不接收,永久不接收
243 | return super.onInterceptTouchEvent(e);
244 | }
245 |
246 | /**
247 | * 进行回弹
248 | *
249 | * @param from
250 | * @param to
251 | */
252 | private void backBouncing(final float from, final float to) {
253 | //初始化
254 | if (animator != null && animator.isRunning()) {
255 | animator.cancel();
256 | animator = null;
257 | offsetScale = 0;
258 | startBouncingTo();
259 | }
260 | if (mTimeInterpolator == null) {
261 | mTimeInterpolator = new OvershootInterpolator();
262 | }
263 | //散发值
264 | animator = ValueAnimator.ofFloat(from, to).setDuration(mBouncingDuration);
265 | animator.setInterpolator(mTimeInterpolator);//差值器
266 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
267 | @Override
268 | public void onAnimationUpdate(ValueAnimator animation) {
269 | //获取动画阶段的值
270 | offsetScale = (float) animation.getAnimatedValue();
271 | if (isTop) {//回弹到顶部
272 | startBouncingTo();
273 | } else {//回弹到底部
274 | startBouncingBottom();
275 | }
276 | }
277 | });
278 | animator.start();
279 | }
280 |
281 |
282 | public void setOnBouncingJellyListener(BouncingJellyListener onBouncingJellyListener) {
283 | this.onBouncingJellyListener = onBouncingJellyListener;
284 | }
285 |
286 | public void setmTimeInterpolator(TimeInterpolator mTimeInterpolator) {
287 | this.mTimeInterpolator = mTimeInterpolator;
288 | }
289 |
290 | public void setmTimeInterpolatorType() {
291 |
292 | }
293 |
294 | public void setmBouncingDuration(int mBouncingDuration) {
295 | this.mBouncingDuration = mBouncingDuration;
296 | }
297 | }
298 |
--------------------------------------------------------------------------------
/library/src/main/java/com/aohanyao/jelly/library/inf/BouncingJellyListener.java:
--------------------------------------------------------------------------------
1 | package com.aohanyao.jelly.library.inf;
2 |
3 | /**
4 | * 弹跳的结果
5 | */
6 | public interface BouncingJellyListener {
7 | /**
8 | * 顶部弹跳
9 | *
10 | * @param bouncingJelly 弹跳系数
11 | */
12 | void onBouncingJellyTop(float bouncingJelly);
13 |
14 | /**
15 | * 底部弹跳
16 | *
17 | * @param bouncingJelly 弹跳系数
18 | */
19 | void onBouncingJellyBottom(float bouncingJelly);
20 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/aohanyao/jelly/library/util/BouncingInterpolatorType.java:
--------------------------------------------------------------------------------
1 | package com.aohanyao.jelly.library.util;
2 |
3 | import android.animation.TimeInterpolator;
4 | import android.view.animation.AccelerateDecelerateInterpolator;
5 | import android.view.animation.BounceInterpolator;
6 | import android.view.animation.LinearInterpolator;
7 | import android.view.animation.OvershootInterpolator;
8 |
9 | /**
10 | * 作者:江俊超 on 2016/8/31 09:36
11 | * 回弹差值器
12 | */
13 | public class BouncingInterpolatorType {
14 |
15 | public static final int OVERSHOOT_INTERPOLATOR = 1;
16 | public static final int BOUNCE_INTERPOLATOR = 2;
17 | public static final int LINEAR_INTERPOLATOR = 3;
18 | public static final int ACCELERATE_DECELERATE_INTERPOLATOR = 4;
19 |
20 | /**
21 | * get Bouncing type
22 | *
23 | * @return
24 | */
25 | public static TimeInterpolator getTimeInterpolator(int type) {
26 | TimeInterpolator mTimeInterpolator = null;
27 | switch (type) {
28 | case OVERSHOOT_INTERPOLATOR:
29 | mTimeInterpolator = new OvershootInterpolator();
30 | break;
31 | case BOUNCE_INTERPOLATOR:
32 | mTimeInterpolator = new BounceInterpolator();
33 | break;
34 | case LINEAR_INTERPOLATOR:
35 | mTimeInterpolator = new LinearInterpolator();
36 | break;
37 | case ACCELERATE_DECELERATE_INTERPOLATOR:
38 | mTimeInterpolator = new AccelerateDecelerateInterpolator();
39 | break;
40 | }
41 | return mTimeInterpolator;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/library/src/main/java/com/aohanyao/jelly/library/util/BouncingScreenUtils.java:
--------------------------------------------------------------------------------
1 | package com.aohanyao.jelly.library.util;
2 |
3 | import android.content.Context;
4 | import android.util.DisplayMetrics;
5 | import android.view.WindowManager;
6 |
7 | /**
8 | * 获得屏幕相关的辅助类
9 | *
10 | *
11 | */
12 | public class BouncingScreenUtils
13 | {
14 | /**
15 | * 获得屏幕宽度
16 | *
17 | * @param context
18 | * @return
19 | */
20 | public static int getScreenHeight(Context context)
21 | {
22 | WindowManager wm = (WindowManager) context
23 | .getSystemService(Context.WINDOW_SERVICE);
24 | DisplayMetrics outMetrics = new DisplayMetrics();
25 | wm.getDefaultDisplay().getMetrics(outMetrics);
26 | return outMetrics.heightPixels;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/aohanyao/jelly/library/util/BouncingType.java:
--------------------------------------------------------------------------------
1 | package com.aohanyao.jelly.library.util;
2 |
3 | /**
4 | * 作者:江俊超 on 2016/8/31 10:06
5 | * 可回弹的类型
6 | */
7 | public class BouncingType {
8 | /**无*/
9 | public static final int NONE = 0;
10 | /**只是顶部弹跳*/
11 | public static final int TOP = 1;
12 | /**只是底部弹跳*/
13 | public static final int BOTTOM = 2;
14 | /**顶部和底部弹跳*/
15 | public static final int BOTH = 3;
16 | }
17 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------