├── .gitignore
├── LICENSE
├── PullScrollView
├── .gitignore
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── ic_launcher-web.png
│ ├── java
│ └── com
│ │ └── markmao
│ │ └── pullscrollview
│ │ └── ui
│ │ ├── MainActivity.java
│ │ ├── PulldownViewActivity.java
│ │ ├── StretchViewActivity.java
│ │ └── widget
│ │ ├── PullScrollView.java
│ │ └── StretchScrollView.java
│ └── res
│ ├── drawable-hdpi
│ ├── add.png
│ ├── arrow_up.png
│ ├── avatar_default.png
│ ├── button_bg_normal.9.png
│ ├── button_bg_pressed.9.png
│ ├── card_avatar_bar.9.png
│ ├── card_whole.9.png
│ ├── ic_launcher.png
│ └── scrollview_header.jpg
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── drawable
│ └── selector_btn.xml
│ ├── layout
│ ├── act_main.xml
│ ├── act_pull_down.xml
│ └── act_stretch.xml
│ ├── values-v11
│ └── styles.xml
│ ├── values-v14
│ └── styles.xml
│ └── values
│ ├── attrs.xml
│ ├── color.xml
│ ├── strings.xml
│ └── styles.xml
├── README.md
├── Screenshots
├── 0.png
├── 1.png
└── 2.png
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Eclipse project files
19 | .classpath
20 | .project
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Intellij project files
26 | *.iml
27 | *.ipr
28 | *.iws
29 | .idea/
30 | /.gradle/
31 |
32 | /build
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction, and
10 | distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright
13 | owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all other entities
16 | that control, are controlled by, or are under common control with that entity.
17 | For the purposes of this definition, "control" means (i) the power, direct or
18 | indirect, to cause the direction or management of such entity, whether by
19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20 | outstanding shares, or (iii) beneficial ownership of such entity.
21 |
22 | "You" (or "Your") shall mean an individual or Legal Entity exercising
23 | permissions granted by this License.
24 |
25 | "Source" form shall mean the preferred form for making modifications, including
26 | but not limited to software source code, documentation source, and configuration
27 | files.
28 |
29 | "Object" form shall mean any form resulting from mechanical transformation or
30 | translation of a Source form, including but not limited to compiled object code,
31 | generated documentation, and conversions to other media types.
32 |
33 | "Work" shall mean the work of authorship, whether in Source or Object form, made
34 | available under the License, as indicated by a copyright notice that is included
35 | in or attached to the work (an example is provided in the Appendix below).
36 |
37 | "Derivative Works" shall mean any work, whether in Source or Object form, that
38 | is based on (or derived from) the Work and for which the editorial revisions,
39 | annotations, elaborations, or other modifications represent, as a whole, an
40 | original work of authorship. For the purposes of this License, Derivative Works
41 | shall not include works that remain separable from, or merely link (or bind by
42 | name) to the interfaces of, the Work and Derivative Works thereof.
43 |
44 | "Contribution" shall mean any work of authorship, including the original version
45 | of the Work and any modifications or additions to that Work or Derivative Works
46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work
47 | by the copyright owner or by an individual or Legal Entity authorized to submit
48 | on behalf of the copyright owner. For the purposes of this definition,
49 | "submitted" means any form of electronic, verbal, or written communication sent
50 | to the Licensor or its representatives, including but not limited to
51 | communication on electronic mailing lists, source code control systems, and
52 | issue tracking systems that are managed by, or on behalf of, the Licensor for
53 | the purpose of discussing and improving the Work, but excluding communication
54 | that is conspicuously marked or otherwise designated in writing by the copyright
55 | owner as "Not a Contribution."
56 |
57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58 | of whom a Contribution has been received by Licensor and subsequently
59 | incorporated within the Work.
60 |
61 | 2. Grant of Copyright License.
62 |
63 | Subject to the terms and conditions of this License, each Contributor hereby
64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65 | irrevocable copyright license to reproduce, prepare Derivative Works of,
66 | publicly display, publicly perform, sublicense, and distribute the Work and such
67 | Derivative Works in Source or Object form.
68 |
69 | 3. Grant of Patent License.
70 |
71 | Subject to the terms and conditions of this License, each Contributor hereby
72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73 | irrevocable (except as stated in this section) patent license to make, have
74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75 | such license applies only to those patent claims licensable by such Contributor
76 | that are necessarily infringed by their Contribution(s) alone or by combination
77 | of their Contribution(s) with the Work to which such Contribution(s) was
78 | submitted. If You institute patent litigation against any entity (including a
79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80 | Contribution incorporated within the Work constitutes direct or contributory
81 | patent infringement, then any patent licenses granted to You under this License
82 | for that Work shall terminate as of the date such litigation is filed.
83 |
84 | 4. Redistribution.
85 |
86 | You may reproduce and distribute copies of the Work or Derivative Works thereof
87 | in any medium, with or without modifications, and in Source or Object form,
88 | provided that You meet the following conditions:
89 |
90 | You must give any other recipients of the Work or Derivative Works a copy of
91 | this License; and
92 | You must cause any modified files to carry prominent notices stating that You
93 | changed the files; and
94 | You must retain, in the Source form of any Derivative Works that You distribute,
95 | all copyright, patent, trademark, and attribution notices from the Source form
96 | of the Work, excluding those notices that do not pertain to any part of the
97 | Derivative Works; and
98 | If the Work includes a "NOTICE" text file as part of its distribution, then any
99 | Derivative Works that You distribute must include a readable copy of the
100 | attribution notices contained within such NOTICE file, excluding those notices
101 | that do not pertain to any part of the Derivative Works, in at least one of the
102 | following places: within a NOTICE text file distributed as part of the
103 | Derivative Works; within the Source form or documentation, if provided along
104 | with the Derivative Works; or, within a display generated by the Derivative
105 | Works, if and wherever such third-party notices normally appear. The contents of
106 | the NOTICE file are for informational purposes only and do not modify the
107 | License. You may add Your own attribution notices within Derivative Works that
108 | You distribute, alongside or as an addendum to the NOTICE text from the Work,
109 | provided that such additional attribution notices cannot be construed as
110 | modifying the License.
111 | You may add Your own copyright statement to Your modifications and may provide
112 | additional or different license terms and conditions for use, reproduction, or
113 | distribution of Your modifications, or for any such Derivative Works as a whole,
114 | provided Your use, reproduction, and distribution of the Work otherwise complies
115 | with the conditions stated in this License.
116 |
117 | 5. Submission of Contributions.
118 |
119 | Unless You explicitly state otherwise, any Contribution intentionally submitted
120 | for inclusion in the Work by You to the Licensor shall be under the terms and
121 | conditions of this License, without any additional terms or conditions.
122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of
123 | any separate license agreement you may have executed with Licensor regarding
124 | such Contributions.
125 |
126 | 6. Trademarks.
127 |
128 | This License does not grant permission to use the trade names, trademarks,
129 | service marks, or product names of the Licensor, except as required for
130 | reasonable and customary use in describing the origin of the Work and
131 | reproducing the content of the NOTICE file.
132 |
133 | 7. Disclaimer of Warranty.
134 |
135 | Unless required by applicable law or agreed to in writing, Licensor provides the
136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138 | including, without limitation, any warranties or conditions of TITLE,
139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140 | solely responsible for determining the appropriateness of using or
141 | redistributing the Work and assume any risks associated with Your exercise of
142 | permissions under this License.
143 |
144 | 8. Limitation of Liability.
145 |
146 | In no event and under no legal theory, whether in tort (including negligence),
147 | contract, or otherwise, unless required by applicable law (such as deliberate
148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be
149 | liable to You for damages, including any direct, indirect, special, incidental,
150 | or consequential damages of any character arising as a result of this License or
151 | out of the use or inability to use the Work (including but not limited to
152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153 | any and all other commercial damages or losses), even if such Contributor has
154 | been advised of the possibility of such damages.
155 |
156 | 9. Accepting Warranty or Additional Liability.
157 |
158 | While redistributing the Work or Derivative Works thereof, You may choose to
159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160 | other liability obligations and/or rights consistent with this License. However,
161 | in accepting such obligations, You may act only on Your own behalf and on Your
162 | sole responsibility, not on behalf of any other Contributor, and only if You
163 | agree to indemnify, defend, and hold each Contributor harmless for any liability
164 | incurred by, or claims asserted against, such Contributor by reason of your
165 | accepting any such warranty or additional liability.
166 |
167 | END OF TERMS AND CONDITIONS
168 |
169 | APPENDIX: How to apply the Apache License to your work
170 |
171 | To apply the Apache License to your work, attach the following boilerplate
172 | notice, with the fields enclosed by brackets "[]" replaced with your own
173 | identifying information. (Don't include the brackets!) The text should be
174 | enclosed in the appropriate comment syntax for the file format. We also
175 | recommend that a file or class name and description of purpose be included on
176 | the same "printed page" as the copyright notice for easier identification within
177 | third-party archives.
178 |
179 | Copyright [yyyy] [name of copyright owner]
180 |
181 | Licensed under the Apache License, Version 2.0 (the "License");
182 | you may not use this file except in compliance with the License.
183 | You may obtain a copy of the License at
184 |
185 | http://www.apache.org/licenses/LICENSE-2.0
186 |
187 | Unless required by applicable law or agreed to in writing, software
188 | distributed under the License is distributed on an "AS IS" BASIS,
189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190 | See the License for the specific language governing permissions and
191 | limitations under the License.
192 |
--------------------------------------------------------------------------------
/PullScrollView/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/PullScrollView/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 18
5 | buildToolsVersion "19.1"
6 | compileOptions.encoding = "UTF-8"
7 |
8 | defaultConfig {
9 | minSdkVersion 10
10 | targetSdkVersion 19
11 | }
12 | }
13 | dependencies {
14 | compile 'com.android.support:appcompat-v7:19.+'
15 | }
16 |
17 |
18 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
24 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/java/com/markmao/pullscrollview/ui/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.markmao.pullscrollview.ui;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | import com.markmao.pullscrollview.R;
9 |
10 | /**
11 | * Demo
12 | *
13 | * @author markmjw
14 | * @date 2014-04-30
15 | */
16 | public class MainActivity extends Activity {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.act_main);
22 |
23 | findViewById(R.id.pulldown_scrollview_btn).setOnClickListener(new View.OnClickListener() {
24 | @Override
25 | public void onClick(View v) {
26 | Intent intent = new Intent(MainActivity.this, PulldownViewActivity.class);
27 | startActivity(intent);
28 | }
29 | });
30 |
31 | findViewById(R.id.stretch_scrollview_btn).setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View v) {
34 | Intent intent = new Intent(MainActivity.this, StretchViewActivity.class);
35 | startActivity(intent);
36 | }
37 | });
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/java/com/markmao/pullscrollview/ui/PulldownViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.markmao.pullscrollview.ui;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.view.Gravity;
7 | import android.view.View;
8 | import android.widget.ImageView;
9 | import android.widget.TableLayout;
10 | import android.widget.TableRow;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import com.markmao.pullscrollview.R;
15 | import com.markmao.pullscrollview.ui.widget.PullScrollView;
16 |
17 | /**
18 | * Pull down ScrollView demo.
19 | *
20 | * @author markmjw
21 | * @date 2014-04-30
22 | */
23 | public class PulldownViewActivity extends Activity implements PullScrollView.OnTurnListener {
24 | private PullScrollView mScrollView;
25 | private ImageView mHeadImg;
26 |
27 | private TableLayout mMainLayout;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.act_pull_down);
33 |
34 | initView();
35 |
36 | showTable();
37 | }
38 |
39 | protected void initView() {
40 | mScrollView = (PullScrollView) findViewById(R.id.scroll_view);
41 | mHeadImg = (ImageView) findViewById(R.id.background_img);
42 |
43 | mMainLayout = (TableLayout) findViewById(R.id.table_layout);
44 |
45 | mScrollView.setHeader(mHeadImg);
46 | mScrollView.setOnTurnListener(this);
47 | }
48 |
49 | public void showTable() {
50 | TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(
51 | TableRow.LayoutParams.MATCH_PARENT,
52 | TableRow.LayoutParams.WRAP_CONTENT);
53 | layoutParams.gravity = Gravity.CENTER;
54 | layoutParams.leftMargin = 30;
55 | layoutParams.bottomMargin = 10;
56 | layoutParams.topMargin = 10;
57 |
58 | for (int i = 0; i < 30; i++) {
59 | TableRow tableRow = new TableRow(this);
60 | TextView textView = new TextView(this);
61 | textView.setText("Test pull down scroll view " + i);
62 | textView.setTextSize(20);
63 | textView.setPadding(15, 15, 15, 15);
64 |
65 | tableRow.addView(textView, layoutParams);
66 | if (i % 2 != 0) {
67 | tableRow.setBackgroundColor(Color.LTGRAY);
68 | } else {
69 | tableRow.setBackgroundColor(Color.WHITE);
70 | }
71 |
72 | final int n = i;
73 | tableRow.setOnClickListener(new View.OnClickListener() {
74 | @Override
75 | public void onClick(View v) {
76 | Toast.makeText(PulldownViewActivity.this, "Click item " + n, Toast.LENGTH_SHORT).show();
77 | }
78 | });
79 |
80 | mMainLayout.addView(tableRow);
81 | }
82 | }
83 |
84 | @Override
85 | public void onTurn() {
86 |
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/java/com/markmao/pullscrollview/ui/StretchViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.markmao.pullscrollview.ui;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.view.Gravity;
7 | import android.view.View;
8 | import android.widget.TableLayout;
9 | import android.widget.TableRow;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import com.markmao.pullscrollview.R;
14 |
15 | /**
16 | * Stretch ScrollView demo.
17 | *
18 | * @author markmjw
19 | * @date 2014-04-30
20 | */
21 | public class StretchViewActivity extends Activity {
22 | private TableLayout mMainLayout;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.act_stretch);
28 |
29 | mMainLayout = (TableLayout) findViewById(R.id.table_layout);
30 | showTable();
31 | }
32 |
33 | public void showTable() {
34 | TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(
35 | TableRow.LayoutParams.MATCH_PARENT,
36 | TableRow.LayoutParams.WRAP_CONTENT);
37 | layoutParams.gravity = Gravity.CENTER;
38 | layoutParams.leftMargin = 30;
39 | layoutParams.bottomMargin = 10;
40 | layoutParams.topMargin = 10;
41 |
42 | for (int i = 0; i < 40; i++) {
43 | TableRow tableRow = new TableRow(this);
44 | TextView textView = new TextView(this);
45 | textView.setText("Test stretch scroll view " + i);
46 | textView.setTextSize(20);
47 | textView.setPadding(15, 15, 15, 15);
48 |
49 | tableRow.addView(textView, layoutParams);
50 | if (i % 2 != 0) {
51 | tableRow.setBackgroundColor(Color.LTGRAY);
52 | } else {
53 | tableRow.setBackgroundColor(Color.WHITE);
54 | }
55 |
56 | final int n = i;
57 | tableRow.setOnClickListener(new View.OnClickListener() {
58 | @Override
59 | public void onClick(View v) {
60 | Toast.makeText(StretchViewActivity.this, "Click item " + n, Toast.LENGTH_SHORT).show();
61 | }
62 | });
63 |
64 | mMainLayout.addView(tableRow);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/java/com/markmao/pullscrollview/ui/widget/PullScrollView.java:
--------------------------------------------------------------------------------
1 | package com.markmao.pullscrollview.ui.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.PointF;
6 | import android.graphics.Rect;
7 | import android.util.AttributeSet;
8 | import android.util.Log;
9 | import android.view.MotionEvent;
10 | import android.view.View;
11 | import android.view.animation.TranslateAnimation;
12 | import android.widget.ScrollView;
13 |
14 | import com.markmao.pullscrollview.R;
15 |
16 | /**
17 | * 自定义ScrollView
18 | *
19 | * @author markmjw
20 | * @date 2013-09-13
21 | */
22 | public class PullScrollView extends ScrollView {
23 | private static final String LOG_TAG = "PullScrollView";
24 | /** 阻尼系数,越小阻力就越大. */
25 | private static final float SCROLL_RATIO = 0.5f;
26 |
27 | /** 滑动至翻转的距离. */
28 | private static final int TURN_DISTANCE = 100;
29 |
30 | /** 头部view. */
31 | private View mHeader;
32 |
33 | /** 头部view高度. */
34 | private int mHeaderHeight;
35 |
36 | /** 头部view显示高度. */
37 | private int mHeaderVisibleHeight;
38 |
39 | /** ScrollView的content view. */
40 | private View mContentView;
41 |
42 | /** ScrollView的content view矩形. */
43 | private Rect mContentRect = new Rect();
44 |
45 | /** 首次点击的Y坐标. */
46 | private PointF mStartPoint = new PointF();
47 |
48 | /** 是否开始移动. */
49 | private boolean isMoving = false;
50 |
51 | /** 是否移动到顶部位置. */
52 | private boolean isTop = false;
53 |
54 | /** 头部图片初始顶部和底部. */
55 | private int mInitTop, mInitBottom;
56 |
57 | /** 头部图片拖动时顶部和底部. */
58 | private int mCurrentTop, mCurrentBottom;
59 |
60 | /** 状态变化时的监听器. */
61 | private OnTurnListener mOnTurnListener;
62 |
63 | private enum State {
64 | /**顶部*/
65 | UP,
66 | /**底部*/
67 | DOWN,
68 | /**正常*/
69 | NORMAL
70 | }
71 |
72 | /** 状态. */
73 | private State mState = State.NORMAL;
74 |
75 | public PullScrollView(Context context) {
76 | super(context);
77 | init(context, null);
78 | }
79 |
80 | public PullScrollView(Context context, AttributeSet attrs) {
81 | super(context, attrs);
82 | init(context, attrs);
83 | }
84 |
85 | public PullScrollView(Context context, AttributeSet attrs, int defStyle) {
86 | super(context, attrs, defStyle);
87 | init(context, attrs);
88 | }
89 |
90 | private void init(Context context, AttributeSet attrs) {
91 | // set scroll mode
92 | setOverScrollMode(OVER_SCROLL_NEVER);
93 |
94 | if (null != attrs) {
95 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PullScrollView);
96 |
97 | if (ta != null) {
98 | mHeaderHeight = (int) ta.getDimension(R.styleable.PullScrollView_headerHeight, -1);
99 | mHeaderVisibleHeight = (int) ta.getDimension(R.styleable
100 | .PullScrollView_headerVisibleHeight, -1);
101 | ta.recycle();
102 | }
103 | }
104 | }
105 |
106 | /**
107 | * 设置Header
108 | *
109 | * @param view
110 | */
111 | public void setHeader(View view) {
112 | mHeader = view;
113 | }
114 |
115 | /**
116 | * 设置状态改变时的监听器
117 | *
118 | * @param turnListener
119 | */
120 | public void setOnTurnListener(OnTurnListener turnListener) {
121 | mOnTurnListener = turnListener;
122 | }
123 |
124 | @Override
125 | protected void onFinishInflate() {
126 | if (getChildCount() > 0) {
127 | mContentView = getChildAt(0);
128 | }
129 | }
130 |
131 | @Override
132 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
133 | super.onScrollChanged(l, t, oldl, oldt);
134 |
135 | if (getScrollY() == 0) {
136 | isTop = true;
137 | }
138 | }
139 |
140 | @Override
141 | public boolean onInterceptTouchEvent(MotionEvent ev) {
142 | onTouchEvent(ev);
143 | return super.onInterceptTouchEvent(ev);
144 | }
145 |
146 |
147 | // @Override
148 | // public boolean onInterceptTouchEvent(MotionEvent ev) {
149 | // return onTouchEvent(ev) || super.onInterceptTouchEvent(ev);
150 | // }
151 |
152 | @Override
153 | public boolean onTouchEvent(MotionEvent ev) {
154 | if (mContentView != null) {
155 | int action = ev.getAction();
156 | switch (action) {
157 | case MotionEvent.ACTION_DOWN:
158 | mStartPoint.set(ev.getX(), ev.getY());
159 | mCurrentTop = mInitTop = mHeader.getTop();
160 | mCurrentBottom = mInitBottom = mHeader.getBottom();
161 | return super.onTouchEvent(ev);
162 | case MotionEvent.ACTION_MOVE:
163 | float deltaY = Math.abs(ev.getY() - mStartPoint.y);
164 | if (deltaY > 10 && deltaY > Math.abs(ev.getX() - mStartPoint.x)) {
165 | mHeader.clearAnimation();
166 | mContentView.clearAnimation();
167 | doActionMove(ev);
168 | }
169 | break;
170 | case MotionEvent.ACTION_UP:
171 | // 回滚动画
172 | if (isNeedAnimation()) {
173 | rollBackAnimation();
174 | }
175 |
176 | if (getScrollY() == 0) {
177 | mState = State.NORMAL;
178 | }
179 |
180 | isMoving = false;
181 | break;
182 | default:
183 | break;
184 |
185 | }
186 | }
187 |
188 | // 禁止控件本身的滑动.
189 | boolean isHandle = isMoving;
190 | if (!isMoving) {
191 | try {
192 | isHandle = super.onTouchEvent(ev);
193 | } catch (Exception e) {
194 | Log.w(LOG_TAG, e);
195 | }
196 | }
197 | return isHandle;
198 | }
199 |
200 | /**
201 | * 执行移动动画
202 | *
203 | * @param event
204 | */
205 | private void doActionMove(MotionEvent event) {
206 | // 当滚动到顶部时,将状态设置为正常,避免先向上拖动再向下拖动到顶端后首次触摸不响应的问题
207 | if (getScrollY() == 0) {
208 | mState = State.NORMAL;
209 |
210 | // 滑动经过顶部初始位置时,修正Touch down的坐标为当前Touch点的坐标
211 | if (isTop) {
212 | isTop = false;
213 | mStartPoint.y = event.getY();
214 | }
215 | }
216 |
217 | float deltaY = event.getY() - mStartPoint.y;
218 |
219 | // 对于首次Touch操作要判断方位:UP OR DOWN
220 | if (deltaY < 0 && mState == State.NORMAL) {
221 | mState = State.UP;
222 | } else if (deltaY > 0 && mState == State.NORMAL) {
223 | mState = State.DOWN;
224 | }
225 |
226 | if (mState == State.UP) {
227 | deltaY = deltaY < 0 ? deltaY : 0;
228 |
229 | isMoving = false;
230 |
231 | } else if (mState == State.DOWN) {
232 | if (getScrollY() <= deltaY) {
233 | isMoving = true;
234 | }
235 | deltaY = deltaY < 0 ? 0 : (deltaY > mHeaderHeight ? mHeaderHeight : deltaY);
236 | }
237 |
238 | if (isMoving) {
239 | // 初始化content view矩形
240 | if (mContentRect.isEmpty()) {
241 | // 保存正常的布局位置
242 | mContentRect.set(mContentView.getLeft(), mContentView.getTop(), mContentView.getRight(),
243 | mContentView.getBottom());
244 | }
245 |
246 | // 计算header移动距离(手势移动的距离*阻尼系数*0.5)
247 | float headerMoveHeight = deltaY * 0.5f * SCROLL_RATIO;
248 | mCurrentTop = (int) (mInitTop + headerMoveHeight);
249 | mCurrentBottom = (int) (mInitBottom + headerMoveHeight);
250 |
251 | // 计算content移动距离(手势移动的距离*阻尼系数)
252 | float contentMoveHeight = deltaY * SCROLL_RATIO;
253 |
254 | // 修正content移动的距离,避免超过header的底边缘
255 | int headerBottom = mCurrentBottom - mHeaderVisibleHeight;
256 | int top = (int) (mContentRect.top + contentMoveHeight);
257 | int bottom = (int) (mContentRect.bottom + contentMoveHeight);
258 |
259 | if (top <= headerBottom) {
260 | // 移动content view
261 | mContentView.layout(mContentRect.left, top, mContentRect.right, bottom);
262 |
263 | // 移动header view
264 | mHeader.layout(mHeader.getLeft(), mCurrentTop, mHeader.getRight(), mCurrentBottom);
265 | }
266 | }
267 | }
268 |
269 | private void rollBackAnimation() {
270 | TranslateAnimation tranAnim = new TranslateAnimation(0, 0,
271 | Math.abs(mInitTop - mCurrentTop), 0);
272 | tranAnim.setDuration(200);
273 | mHeader.startAnimation(tranAnim);
274 |
275 | mHeader.layout(mHeader.getLeft(), mInitTop, mHeader.getRight(), mInitBottom);
276 |
277 | // 开启移动动画
278 | TranslateAnimation innerAnim = new TranslateAnimation(0, 0, mContentView.getTop(), mContentRect.top);
279 | innerAnim.setDuration(200);
280 | mContentView.startAnimation(innerAnim);
281 | mContentView.layout(mContentRect.left, mContentRect.top, mContentRect.right, mContentRect.bottom);
282 |
283 | mContentRect.setEmpty();
284 |
285 | // 回调监听器
286 | if (mCurrentTop > mInitTop + TURN_DISTANCE && mOnTurnListener != null){
287 | mOnTurnListener.onTurn();
288 | }
289 | }
290 |
291 | /**
292 | * 是否需要开启动画
293 | */
294 | private boolean isNeedAnimation() {
295 | return !mContentRect.isEmpty() && isMoving;
296 | }
297 |
298 | /**
299 | * 翻转事件监听器
300 | *
301 | * @author markmjw
302 | */
303 | public interface OnTurnListener {
304 | /**
305 | * 翻转回调方法
306 | */
307 | public void onTurn();
308 | }
309 | }
310 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/java/com/markmao/pullscrollview/ui/widget/StretchScrollView.java:
--------------------------------------------------------------------------------
1 | package com.markmao.pullscrollview.ui.widget;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.os.Message;
6 | import android.util.AttributeSet;
7 | import android.view.MotionEvent;
8 | import android.view.View;
9 | import android.widget.ScrollView;
10 |
11 | /**
12 | * A ScrollView which can scroll to (0,0) when pull down or up.
13 | *
14 | * @author markmjw
15 | * @date 2014-04-30
16 | */
17 | public class StretchScrollView extends ScrollView {
18 | private static final int MSG_REST_POSITION = 0x01;
19 |
20 | /** The max scroll height. */
21 | private static final int MAX_SCROLL_HEIGHT = 400;
22 | /** Damping, the smaller the greater the resistance */
23 | private static final float SCROLL_RATIO = 0.4f;
24 |
25 | private View mChildRootView;
26 |
27 | private float mTouchY;
28 | private boolean mTouchStop = false;
29 |
30 | private int mScrollY = 0;
31 | private int mScrollDy = 0;
32 |
33 | private Handler mHandler = new Handler() {
34 | @Override
35 | public void handleMessage(Message msg) {
36 | if (MSG_REST_POSITION == msg.what) {
37 | if (mScrollY != 0 && mTouchStop) {
38 | mScrollY -= mScrollDy;
39 |
40 | if ((mScrollDy < 0 && mScrollY > 0) || (mScrollDy > 0 && mScrollY < 0)) {
41 | mScrollY = 0;
42 | }
43 |
44 | mChildRootView.scrollTo(0, mScrollY);
45 | // continue scroll after 20ms
46 | sendEmptyMessageDelayed(MSG_REST_POSITION, 20);
47 | }
48 | }
49 | }
50 | };
51 |
52 | public StretchScrollView(Context context) {
53 | super(context);
54 |
55 | init();
56 | }
57 |
58 | public StretchScrollView(Context context, AttributeSet attrs) {
59 | super(context, attrs);
60 |
61 | init();
62 | }
63 |
64 | public StretchScrollView(Context context, AttributeSet attrs, int defStyle) {
65 | super(context, attrs, defStyle);
66 |
67 | init();
68 | }
69 |
70 | private void init() {
71 | // set scroll mode
72 | setOverScrollMode(OVER_SCROLL_NEVER);
73 | }
74 |
75 | @Override
76 | protected void onFinishInflate() {
77 | if (getChildCount() > 0) {
78 | // when finished inflating from layout xml, get the first child view
79 | mChildRootView = getChildAt(0);
80 | }
81 | }
82 |
83 | @Override
84 | public boolean onInterceptTouchEvent(MotionEvent ev) {
85 | if (ev.getAction() == MotionEvent.ACTION_DOWN) {
86 | mTouchY = ev.getY();
87 | }
88 | return super.onInterceptTouchEvent(ev);
89 | }
90 |
91 | @Override
92 | public boolean onTouchEvent(MotionEvent ev) {
93 | if (null != mChildRootView) {
94 | doTouchEvent(ev);
95 | }
96 | return super.onTouchEvent(ev);
97 | }
98 |
99 | private void doTouchEvent(MotionEvent ev) {
100 | int action = ev.getAction();
101 |
102 | switch (action) {
103 | case MotionEvent.ACTION_UP:
104 | mScrollY = mChildRootView.getScrollY();
105 | if (mScrollY != 0) {
106 | mTouchStop = true;
107 | mScrollDy = (int) (mScrollY / 10.0f);
108 | mHandler.sendEmptyMessage(MSG_REST_POSITION);
109 | }
110 | break;
111 |
112 | case MotionEvent.ACTION_MOVE:
113 | float nowY = ev.getY();
114 | int deltaY = (int) (mTouchY - nowY);
115 | mTouchY = nowY;
116 | if (isNeedMove()) {
117 | int offset = mChildRootView.getScrollY();
118 | if (offset < MAX_SCROLL_HEIGHT && offset > -MAX_SCROLL_HEIGHT) {
119 | mChildRootView.scrollBy(0, (int) (deltaY * SCROLL_RATIO));
120 | mTouchStop = false;
121 | }
122 | }
123 | break;
124 |
125 | default:
126 | break;
127 | }
128 | }
129 |
130 | private boolean isNeedMove() {
131 | int viewHeight = mChildRootView.getMeasuredHeight();
132 | int scrollHeight = getHeight();
133 | int offset = viewHeight - scrollHeight;
134 | int scrollY = getScrollY();
135 |
136 | return scrollY == 0 || scrollY == offset;
137 | }
138 | }
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-hdpi/add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-hdpi/add.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-hdpi/arrow_up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-hdpi/arrow_up.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-hdpi/avatar_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-hdpi/avatar_default.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-hdpi/button_bg_normal.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-hdpi/button_bg_normal.9.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-hdpi/button_bg_pressed.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-hdpi/button_bg_pressed.9.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-hdpi/card_avatar_bar.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-hdpi/card_avatar_bar.9.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-hdpi/card_whole.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-hdpi/card_whole.9.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-hdpi/scrollview_header.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-hdpi/scrollview_header.jpg
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/PullScrollView/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/drawable/selector_btn.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/layout/act_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
13 |
14 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/layout/act_pull_down.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
25 |
26 |
31 |
32 |
39 |
40 |
45 |
46 |
64 |
65 |
76 |
77 |
89 |
90 |
91 |
100 |
101 |
116 |
117 |
125 |
126 |
132 |
133 |
139 |
140 |
141 |
154 |
155 |
156 |
157 |
164 |
165 |
175 |
176 |
184 |
185 |
186 |
187 |
188 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/layout/act_stretch.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/values/color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #ffffff
5 | #00000000
6 |
7 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PullScrollView
5 | Settings
6 | PulldownScrollView
7 | StretchScrollView
8 | 加关注
9 | 职位:产品经理
10 | 书单:25本
11 | 西北老狼michael
12 | 谁能像优乐美一样把我捧在手心,我就能让他的儿子长的更帅女儿长的更漂亮
13 | TA推荐的好书
14 |
15 |
16 |
--------------------------------------------------------------------------------
/PullScrollView/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | PullScrollView
2 | ===========
3 |
4 | *注:本项目使用Android Studio开发*
5 |
6 |
7 | ## **本例包含ScrollView的两种实现:** ##
8 | >1.仿照新浪微博Android客户端个人中心的ScrollView,下拉背景伸缩回弹效果。
9 | >2.ScrollView仿IOS回弹效果。
10 |
11 | ## **使用示例** ##
12 |
13 | ```java
14 | 1、
15 | mScrollView = (PullScrollView) findViewById(R.id.scroll_view);
16 | mHeadImg = (ImageView) findViewById(R.id.background_img);
17 | mScrollView.setOnTurnListener(this);
18 | mScrollView.init(mHeadImg);
19 | 2、
20 | 获取头部View进行修改示例:
21 | TextView tvHello = (TextView)mHeadImg.findViewById(R.id.tv_hello);
22 | tvHello.setText("world");
23 | ```
24 |
25 | ##Screenshots
26 | 
27 |
28 | 
29 |
30 | 
31 |
32 | License
33 | =======
34 |
35 | Copyright (C) 2014 MarkMjw
36 |
37 | Licensed under the Apache License, Version 2.0 (the "License");
38 | you may not use this file except in compliance with the License.
39 | You may obtain a copy of the License at
40 |
41 | http://www.apache.org/licenses/LICENSE-2.0
42 |
43 | Unless required by applicable law or agreed to in writing, software
44 | distributed under the License is distributed on an "AS IS" BASIS,
45 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46 | See the License for the specific language governing permissions and
47 | limitations under the License.
48 |
--------------------------------------------------------------------------------
/Screenshots/0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/Screenshots/0.png
--------------------------------------------------------------------------------
/Screenshots/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/Screenshots/1.png
--------------------------------------------------------------------------------
/Screenshots/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/Screenshots/2.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | repositories {
4 | mavenCentral()
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.2.3'
9 | }
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | mavenCentral()
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkMjw/PullScrollView/0dbcbd2f4f17b4953f30a74d9481e1315e49e47e/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Mar 01 23:12:52 GMT+08:00 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':PullScrollView'
2 |
--------------------------------------------------------------------------------