├── .gitignore
├── .idea
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wanjian
│ │ └── scrollscreenshots
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── wanjian
│ │ │ └── scrollscreenshots
│ │ │ ├── AutoScreenShotsAct.java
│ │ │ ├── DrawListViewAct.java
│ │ │ ├── DrawScrollViewAct.java
│ │ │ ├── MainActivity.java
│ │ │ └── ScrollAct.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_auto_scroll.xml
│ │ ├── activity_auto_scroll_demo.xml
│ │ ├── activity_draw_listview.xml
│ │ ├── activity_draw_scrollview.xml
│ │ ├── activity_main.xml
│ │ └── item.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_round.png
│ │ └── labuladuo.jpeg
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── wanjian
│ └── scrollscreenshots
│ └── ExampleUnitTest.java
├── auto_cap_demo.gif
├── auto_cap_demo.mp4
├── auto_scroll.gif
├── auto_scroll.mp4
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── listview_capture.jpg
├── miui_screen_cap.gif
├── scrollview_capture.jpg
└── 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 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 wanjian
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 跟miui一样的自动滚动截屏
2 |
3 | > 很久之前写过一篇完全不同于其他长截屏方案的的博客,不过很仓促,现在重新整理一下 [android长截屏beta1](http://blog.csdn.net/qingchunweiliang/article/details/52248643)
4 |
5 |
6 | #### miui自动滚动长截屏效果
7 |
8 | 
9 |
10 |
11 |
12 | #### 画
13 |
14 | * 给滚动控件外面嵌套一个`FrameLayout`(`LinearLayout`等也可以)
15 | * 手动调用`FrameLayout`的`draw`方法把`view`画到`bitmap`上
16 |
17 | ```java
18 | Bitmap bitmap = Bitmap.createBitmap(container.getWidth(), container.getHeight(), Bitmap.Config.ARGB_8888);
19 | Canvas canvas = new Canvas(bitmap);
20 | container.draw(canvas);
21 |
22 | ```
23 | > 具体参考 `DrawScrollViewAct` `DrawListViewAct`
24 |
25 |
26 | #### 滚
27 |
28 | * 通过不断改变motionEvent的y值并手动调用view的`dispatchTouchEvent`方法实现`view`滚动
29 |
30 | ```java
31 |
32 | private void autoScroll() {
33 | final int delay = 16;
34 | final MotionEvent motionEvent = MotionEvent.obtain(SystemClock.uptimeMillis()
35 | , SystemClock.uptimeMillis()
36 | , MotionEvent.ACTION_DOWN
37 | , listView.getWidth() / 2
38 | , listView.getHeight() / 2
39 | , 0);
40 | listView.dispatchTouchEvent(motionEvent);//先分发 MotionEvent.ACTION_DOWN 事件
41 |
42 | listView.postDelayed(new Runnable() {
43 | @Override
44 | public void run() {
45 | motionEvent.setAction(MotionEvent.ACTION_MOVE); //延时分发 MotionEvent.ACTION_MOVE 事件
46 | //改变y坐标,越大滚动越快,但太大可能会导致掉帧
47 | motionEvent.setLocation((int) motionEvent.getX(), (int) motionEvent.getY() - 10);
48 | listView.dispatchTouchEvent(motionEvent);
49 | listView.postDelayed(this, delay);
50 | }
51 | }, delay);
52 | }
53 |
54 |
55 | ```
56 |
57 | > 参考 ScrollAct
58 |
59 | 自动滚动效果
60 | 
61 |
62 | #### 截屏
63 |
64 |
65 | * 每自动滚动完一屏幕调用`view.draw()`把`view`画到`bitmap`上,最后拼接bitmap
66 |
67 | > 参考 `AutoScreenShotsAct`
68 |
69 |
70 | #### 为什么要嵌套一层view
71 |
72 | listview不嵌套时,不管是否滚动,都能得到正确的结果
73 |
74 | 
75 |
76 |
77 | 但scrollview滚动后即使顶部的已经看不到了,但调用scrollview的draw时还是会把scrollview不可见的地方画进去
78 | 
79 |
80 | 为了通用起间,我们给view外面嵌套了一层view
81 |
82 | #### 代码实现
83 |
84 | 关键逻辑如下,但有些细节还需要具体对待
85 |
86 | ```java
87 |
88 | private void autoScroll() {
89 | final int delay = 16;//延时16毫秒分发滑动事件
90 | final int step = 10;//每次滑动距离5像素,可以根据需要调整(若卡顿的话实际滚动距离可能小于5)
91 | final MotionEvent motionEvent = MotionEvent.obtain(SystemClock.uptimeMillis()
92 | , SystemClock.uptimeMillis()
93 | , MotionEvent.ACTION_DOWN
94 | , listView.getWidth() / 2
95 | , listView.getHeight() / 2
96 | , 0);
97 | //先分发 MotionEvent.ACTION_DOWN 事件,我们指定为按下位置是listview的中间位置,当然其他位置也可以
98 | listView.dispatchTouchEvent(motionEvent);
99 | /*
100 | 注意:
101 | 查看Listview源码可知 滑动距离大于ViewConfiguration.get(view.getContext()).getScaledTouchSlop()时listview才开始滚动
102 | private boolean startScrollIfNeeded(int x, int y, MotionEvent vtev) {
103 | // Check if we have moved far enough that it looks more like a
104 | // scroll than a tap
105 | final int deltaY = y - mMotionY;
106 | final int distance = Math.abs(deltaY);
107 | final boolean overscroll = mScrollY != 0;
108 | if ((overscroll || distance > mTouchSlop) && (getNestedScrollAxes() & SCROLL_AXIS_VERTICAL) == 0) {
109 | ...
110 | return true;
111 | }
112 | return false;
113 | }
114 | */
115 | motionEvent.setAction(MotionEvent.ACTION_MOVE);
116 | motionEvent.setLocation(motionEvent.getX(), motionEvent.getY() - (ViewConfiguration.get(listView.getContext()).getScaledTouchSlop()));
117 | listView.dispatchTouchEvent(motionEvent);
118 |
119 | final int startScrollY = (int) motionEvent.getY();
120 |
121 | listView.postDelayed(new Runnable() {
122 | @Override
123 | public void run() {
124 | if (isScreenShots == false) {//注意:我们无法通过滚动距离来判断是否滚动到了最后,所以需要通过其他方式停止滚动
125 | drawRemainAndAssemble(startScrollY, (int) motionEvent.getY());
126 | return;
127 | }
128 | //滚动刚好一整屏时画到bitmap上
129 | drawIfNeeded(startScrollY, (int) motionEvent.getY());
130 |
131 | motionEvent.setAction(MotionEvent.ACTION_MOVE); //延时分发 MotionEvent.ACTION_MOVE 事件
132 | /*
133 | 改变motionEvent的y坐标,nextStep越大滚动越快,但太大可能会导致掉帧,导致实际滚动距离小于我们滑动的距离
134 |
135 | 因为我们是根据(curScrollY - startScrollY) % container.getHeight() == 0来判定是否刚好滚动了一屏幕的,
136 | 所以快要滚动到刚好一屏幕位置时,修改nextStep的值,使下次滚动后刚好是一屏幕的距离。
137 | 当然nextStep也可以一直是1,这时就不需要凑整了,但这样会导致滚动的特别慢
138 | */
139 | int nextStep;
140 | int gap = (startScrollY - (int) motionEvent.getY() + step) % container.getHeight();
141 | if (gap > 0 && gap < step) {
142 | nextStep = step - gap;
143 | } else {
144 | nextStep = step;
145 | }
146 |
147 | motionEvent.setLocation((int) motionEvent.getX(), (int) motionEvent.getY() - nextStep);
148 | listView.dispatchTouchEvent(motionEvent);
149 |
150 | listView.postDelayed(this, delay);
151 | }
152 | }, delay);
153 | }
154 |
155 | private void drawRemainAndAssemble(int startScrollY, int curScrollY) {
156 | //最后的可能不足一屏幕,需要单独处理
157 | if ((curScrollY - startScrollY) % container.getHeight() != 0) {
158 | Bitmap film = Bitmap.createBitmap(container.getWidth(), container.getHeight(), Bitmap.Config.RGB_565);
159 | Canvas canvas = new Canvas();
160 | canvas.setBitmap(film);
161 | container.draw(canvas);
162 |
163 | int part = (startScrollY - curScrollY) / container.getHeight();
164 | int remainHeight = startScrollY - curScrollY - container.getHeight() * part;
165 | Bitmap remainBmp = Bitmap.createBitmap(film, 0, container.getHeight() - remainHeight, container.getWidth(), remainHeight);
166 | bitmaps.add(remainBmp);
167 | }
168 |
169 | assembleBmp();
170 |
171 | }
172 |
173 | private void assembleBmp() {
174 | int h = 0;
175 | for (Bitmap bitmap : bitmaps) {
176 | h += bitmap.getHeight();
177 | }
178 | //如果你需要透明度或者对图片质量要求很高的话请使用Config.ARGB_8888
179 | Bitmap bitmap = Bitmap.createBitmap(container.getWidth(), h, Bitmap.Config.RGB_565);
180 | Canvas canvas = new Canvas(bitmap);
181 | for (Bitmap b : bitmaps) {
182 | canvas.drawBitmap(b, 0, 0, null);
183 | canvas.translate(0, b.getHeight());
184 | }
185 | ViewGroup.LayoutParams params = img.getLayoutParams();
186 | params.width = bitmap.getWidth() * 2;
187 | params.height = bitmap.getHeight() * 2;
188 | img.requestLayout();
189 | img.setImageBitmap(bitmap);
190 | }
191 |
192 | private void drawIfNeeded(int startScrollY, int curScrollY) {
193 |
194 | if ((curScrollY - startScrollY) % container.getHeight() == 0) {
195 | //正好滚动满一屏
196 |
197 | //为了更通用,我们是把ListView的父布局(和ListView宽高相同)画到了bitmap上
198 | Bitmap film = Bitmap.createBitmap(container.getWidth(), container.getHeight(), Bitmap.Config.RGB_565);
199 | Canvas canvas = new Canvas();
200 | canvas.setBitmap(film);
201 | container.draw(canvas);
202 | bitmaps.add(film);
203 | }
204 | }
205 |
206 |
207 | ```
208 | #### 最终效果
209 |
210 | 左边是自动滚动的Listview,右边是停止截屏后的bitmap,可以看到完全没有拼接痕迹
211 |
212 |
213 | 
214 |
215 |
216 |
217 |
218 | ```txt
219 | MIT License
220 |
221 | Copyright (c) 2018 wanjian
222 |
223 | Permission is hereby granted, free of charge, to any person obtaining a copy
224 | of this software and associated documentation files (the "Software"), to deal
225 | in the Software without restriction, including without limitation the rights
226 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
227 | copies of the Software, and to permit persons to whom the Software is
228 | furnished to do so, subject to the following conditions:
229 |
230 | The above copyright notice and this permission notice shall be included in all
231 | copies or substantial portions of the Software.
232 |
233 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
234 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
235 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
236 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
237 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
238 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
239 | SOFTWARE.
240 |
241 |
242 | ```
243 |
244 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.wanjian.scrollscreenshots"
7 | minSdkVersion 14
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:26.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
28 | }
29 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/wanjian/scrollscreenshots/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.scrollscreenshots;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.wanjian.scrollscreenshots", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wanjian/scrollscreenshots/AutoScreenShotsAct.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.scrollscreenshots;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.os.Bundle;
7 | import android.os.SystemClock;
8 | import android.support.annotation.Nullable;
9 | import android.view.LayoutInflater;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.view.ViewConfiguration;
13 | import android.view.ViewGroup;
14 | import android.widget.BaseAdapter;
15 | import android.widget.ImageView;
16 | import android.widget.ListView;
17 | import android.widget.TextView;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * Created by wanjian on 2018/1/3.
24 | */
25 |
26 | public class AutoScreenShotsAct extends Activity {
27 | private ListView listView;
28 |
29 | private ImageView img;
30 |
31 | private ViewGroup container;
32 |
33 | private List bitmaps = new ArrayList<>();
34 |
35 | private boolean isScreenShots = false;
36 |
37 | @Override
38 | protected void onCreate(@Nullable Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_auto_scroll_demo);
41 | listView = findViewById(R.id.listview);
42 | img = findViewById(R.id.img);
43 | container = findViewById(R.id.container);
44 |
45 | setAdapter();
46 |
47 | findViewById(R.id.start).setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | bitmaps.clear();
51 | img.setImageBitmap(null);
52 | isScreenShots = true;
53 | autoScroll();
54 | }
55 | });
56 | findViewById(R.id.stop).setOnClickListener(new View.OnClickListener() {
57 | @Override
58 | public void onClick(View v) {
59 | isScreenShots = false;
60 |
61 | }
62 | });
63 | }
64 |
65 | private void autoScroll() {
66 | final int delay = 16;//延时16毫秒分发滑动事件
67 | final int step = 10;//每次滑动距离5像素,可以根据需要调整(若卡顿的话实际滚动距离可能小于5)
68 | final MotionEvent motionEvent = MotionEvent.obtain(SystemClock.uptimeMillis()
69 | , SystemClock.uptimeMillis()
70 | , MotionEvent.ACTION_DOWN
71 | , listView.getWidth() / 2
72 | , listView.getHeight() / 2
73 | , 0);
74 | //先分发 MotionEvent.ACTION_DOWN 事件,我们指定为按下位置是listview的中间位置,当然其他位置也可以
75 | listView.dispatchTouchEvent(motionEvent);
76 | /*
77 | 注意:
78 | 查看Listview源码可知 滑动距离大于ViewConfiguration.get(view.getContext()).getScaledTouchSlop()时listview才开始滚动
79 | private boolean startScrollIfNeeded(int x, int y, MotionEvent vtev) {
80 | // Check if we have moved far enough that it looks more like a
81 | // scroll than a tap
82 | final int deltaY = y - mMotionY;
83 | final int distance = Math.abs(deltaY);
84 | final boolean overscroll = mScrollY != 0;
85 | if ((overscroll || distance > mTouchSlop) && (getNestedScrollAxes() & SCROLL_AXIS_VERTICAL) == 0) {
86 | ...
87 | return true;
88 | }
89 | return false;
90 | }
91 | */
92 | motionEvent.setAction(MotionEvent.ACTION_MOVE);
93 | motionEvent.setLocation(motionEvent.getX(), motionEvent.getY() - (ViewConfiguration.get(listView.getContext()).getScaledTouchSlop()));
94 | listView.dispatchTouchEvent(motionEvent);
95 |
96 | final int startScrollY = (int) motionEvent.getY();
97 |
98 | listView.postDelayed(new Runnable() {
99 | @Override
100 | public void run() {
101 | if (isScreenShots == false) {//注意:我们无法通过滚动距离来判断是否滚动到了最后,所以需要通过其他方式停止滚动
102 | drawRemainAndAssemble(startScrollY, (int) motionEvent.getY());
103 | return;
104 | }
105 | //滚动刚好一整屏时画到bitmap上
106 | drawIfNeeded(startScrollY, (int) motionEvent.getY());
107 |
108 | motionEvent.setAction(MotionEvent.ACTION_MOVE); //延时分发 MotionEvent.ACTION_MOVE 事件
109 | /*
110 | 改变motionEvent的y坐标,nextStep越大滚动越快,但太大可能会导致掉帧,导致实际滚动距离小于我们滑动的距离
111 |
112 | 因为我们是根据(curScrollY - startScrollY) % container.getHeight() == 0来判定是否刚好滚动了一屏幕的,
113 | 所以快要滚动到刚好一屏幕位置时,修改nextStep的值,使下次滚动后刚好是一屏幕的距离。
114 | 当然nextStep也可以一直是1,这时就不需要凑整了,但这样会导致滚动的特别慢
115 | */
116 | int nextStep;
117 | int gap = (startScrollY - (int) motionEvent.getY() + step) % container.getHeight();
118 | if (gap > 0 && gap < step) {
119 | nextStep = step - gap;
120 | } else {
121 | nextStep = step;
122 | }
123 |
124 | motionEvent.setLocation((int) motionEvent.getX(), (int) motionEvent.getY() - nextStep);
125 | listView.dispatchTouchEvent(motionEvent);
126 |
127 | listView.postDelayed(this, delay);
128 | }
129 | }, delay);
130 | }
131 |
132 | private void drawRemainAndAssemble(int startScrollY, int curScrollY) {
133 | //最后的可能不足一屏幕,需要单独处理
134 | if ((curScrollY - startScrollY) % container.getHeight() != 0) {
135 | Bitmap film = Bitmap.createBitmap(container.getWidth(), container.getHeight(), Bitmap.Config.RGB_565);
136 | Canvas canvas = new Canvas();
137 | canvas.setBitmap(film);
138 | container.draw(canvas);
139 |
140 | int part = (startScrollY - curScrollY) / container.getHeight();
141 | int remainHeight = startScrollY - curScrollY - container.getHeight() * part;
142 | Bitmap remainBmp = Bitmap.createBitmap(film, 0, container.getHeight() - remainHeight, container.getWidth(), remainHeight);
143 | bitmaps.add(remainBmp);
144 | }
145 |
146 | assembleBmp();
147 |
148 | }
149 |
150 | private void assembleBmp() {
151 | int h = 0;
152 | for (Bitmap bitmap : bitmaps) {
153 | h += bitmap.getHeight();
154 | }
155 | Bitmap bitmap = Bitmap.createBitmap(container.getWidth(), h, Bitmap.Config.RGB_565);
156 | Canvas canvas = new Canvas(bitmap);
157 | for (Bitmap b : bitmaps) {
158 | canvas.drawBitmap(b, 0, 0, null);
159 | canvas.translate(0, b.getHeight());
160 | }
161 | ViewGroup.LayoutParams params = img.getLayoutParams();
162 | params.width = bitmap.getWidth() * 2;
163 | params.height = bitmap.getHeight() * 2;
164 | img.requestLayout();
165 | img.setImageBitmap(bitmap);
166 | }
167 |
168 | private void drawIfNeeded(int startScrollY, int curScrollY) {
169 |
170 | if ((curScrollY - startScrollY) % container.getHeight() == 0) {
171 | //正好滚动满一屏
172 |
173 | //为了更通用,我们是把ListView的父布局(和ListView宽高相同)画到了bitmap上
174 | Bitmap film = Bitmap.createBitmap(container.getWidth(), container.getHeight(), Bitmap.Config.RGB_565);
175 | Canvas canvas = new Canvas();
176 | canvas.setBitmap(film);
177 | container.draw(canvas);
178 | bitmaps.add(film);
179 | }
180 | }
181 |
182 | private void setAdapter() {
183 |
184 | listView.setAdapter(new BaseAdapter() {
185 | @Override
186 | public int getCount() {
187 | return 100;
188 | }
189 |
190 | @Override
191 | public Object getItem(int position) {
192 | return null;
193 | }
194 |
195 | @Override
196 | public long getItemId(int position) {
197 | return 0;
198 | }
199 |
200 | @Override
201 | public View getView(int position, View convertView, ViewGroup parent) {
202 | if (convertView == null) {
203 | convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item, listView, false);
204 | convertView.setTag(R.id.index, convertView.findViewById(R.id.index));
205 | }
206 | ((TextView) convertView.getTag(R.id.index)).setText(position + "");
207 | return convertView;
208 | }
209 | });
210 |
211 | }
212 | }
213 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wanjian/scrollscreenshots/DrawListViewAct.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.scrollscreenshots;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.os.Bundle;
7 | import android.support.annotation.Nullable;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.BaseAdapter;
12 | import android.widget.ImageView;
13 | import android.widget.ListView;
14 | import android.widget.TextView;
15 |
16 | /**
17 | * Created by wanjian on 2018/1/3.
18 | */
19 |
20 | public class DrawListViewAct extends Activity {
21 |
22 | private ListView listView;
23 | private ViewGroup container;
24 |
25 | private ImageView img1;
26 | private ImageView img2;
27 | private ImageView img3;
28 |
29 | @Override
30 | protected void onCreate(@Nullable Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_draw_listview);
33 | listView = findViewById(R.id.listview);
34 | container = findViewById(R.id.container);
35 | img1 = findViewById(R.id.img1);
36 | img2 = findViewById(R.id.img2);
37 | img3 = findViewById(R.id.img3);
38 |
39 | setAdapter();
40 |
41 | img1.setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View v) {
44 | drawListView(img1);
45 | }
46 | });
47 | img2.setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | drawListView(img2);
51 | }
52 | });
53 | img3.setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View v) {
56 | drawListViewContainer(img3);
57 | }
58 | });
59 |
60 | }
61 |
62 | private void drawListViewContainer(ImageView imageView) {
63 | Bitmap bitmap = Bitmap.createBitmap(container.getWidth(), container.getHeight(), Bitmap.Config.ARGB_8888);
64 | Canvas canvas = new Canvas(bitmap);
65 | container.draw(canvas);
66 | imageView.setImageBitmap(bitmap);
67 | }
68 |
69 | private void drawListView(ImageView imageView) {
70 | Bitmap bitmap = Bitmap.createBitmap(listView.getWidth(), listView.getHeight(), Bitmap.Config.ARGB_8888);
71 | Canvas canvas = new Canvas(bitmap);
72 | listView.draw(canvas);
73 | imageView.setImageBitmap(bitmap);
74 | }
75 |
76 | private void setAdapter() {
77 |
78 | listView.setAdapter(new BaseAdapter() {
79 | @Override
80 | public int getCount() {
81 | return 30;
82 | }
83 |
84 | @Override
85 | public Object getItem(int position) {
86 | return null;
87 | }
88 |
89 | @Override
90 | public long getItemId(int position) {
91 | return 0;
92 | }
93 |
94 | @Override
95 | public View getView(int position, View convertView, ViewGroup parent) {
96 | if (convertView == null) {
97 | convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item, listView, false);
98 | convertView.setTag(R.id.index, convertView.findViewById(R.id.index));
99 | }
100 | ((TextView) convertView.getTag(R.id.index)).setText(position + "");
101 | return convertView;
102 | }
103 | });
104 |
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wanjian/scrollscreenshots/DrawScrollViewAct.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.scrollscreenshots;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.os.Bundle;
7 | import android.support.annotation.Nullable;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ImageView;
12 | import android.widget.ScrollView;
13 | import android.widget.TextView;
14 |
15 | /**
16 | * Created by wanjian on 2018/1/3.
17 | */
18 |
19 | public class DrawScrollViewAct extends Activity {
20 |
21 | private ScrollView scrollView;
22 | private ViewGroup container;
23 |
24 | private ImageView img1;
25 | private ImageView img2;
26 | private ImageView img3;
27 |
28 | @Override
29 | protected void onCreate(@Nullable Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_draw_scrollview);
32 | scrollView = findViewById(R.id.scrollView);
33 | container = findViewById(R.id.container);
34 | img1 = findViewById(R.id.img1);
35 | img2 = findViewById(R.id.img2);
36 | img3 = findViewById(R.id.img3);
37 |
38 | ViewGroup itemContainer = findViewById(R.id.itemContainer);
39 | for (int i = 0; i < 20; i++) {
40 | View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item, itemContainer, false);
41 | ((TextView) view.findViewById(R.id.index)).setText("" + i);
42 | itemContainer.addView(view);
43 | }
44 |
45 | img1.setOnClickListener(new View.OnClickListener() {
46 | @Override
47 | public void onClick(View v) {
48 | drawScrollView(img1);
49 | }
50 | });
51 | img2.setOnClickListener(new View.OnClickListener() {
52 | @Override
53 | public void onClick(View v) {
54 | drawScrollView(img2);
55 | }
56 | });
57 | img3.setOnClickListener(new View.OnClickListener() {
58 | @Override
59 | public void onClick(View v) {
60 | drawScrollViewContainer(img3);
61 | }
62 | });
63 |
64 | }
65 |
66 | private void drawScrollViewContainer(ImageView imageView) {
67 | Bitmap bitmap = Bitmap.createBitmap(container.getWidth(), container.getHeight(), Bitmap.Config.ARGB_8888);
68 | Canvas canvas = new Canvas(bitmap);
69 | container.draw(canvas);
70 | imageView.setImageBitmap(bitmap);
71 | }
72 |
73 | private void drawScrollView(ImageView imageView) {
74 | Bitmap bitmap = Bitmap.createBitmap(scrollView.getWidth(), scrollView.getHeight(), Bitmap.Config.ARGB_8888);
75 | Canvas canvas = new Canvas(bitmap);
76 | scrollView.draw(canvas);
77 | imageView.setImageBitmap(bitmap);
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wanjian/scrollscreenshots/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.scrollscreenshots;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 |
15 | findViewById(R.id.draw1).setOnClickListener(new View.OnClickListener() {
16 | @Override
17 | public void onClick(View v) {
18 | startActivity(new Intent(getApplicationContext(), DrawListViewAct.class));
19 | }
20 | });
21 | findViewById(R.id.draw2).setOnClickListener(new View.OnClickListener() {
22 | @Override
23 | public void onClick(View v) {
24 | startActivity(new Intent(getApplicationContext(), DrawScrollViewAct.class));
25 | }
26 | });
27 | findViewById(R.id.scroll).setOnClickListener(new View.OnClickListener() {
28 | @Override
29 | public void onClick(View v) {
30 | startActivity(new Intent(getApplicationContext(), ScrollAct.class));
31 | }
32 | });
33 | findViewById(R.id.demo).setOnClickListener(new View.OnClickListener() {
34 | @Override
35 | public void onClick(View v) {
36 | startActivity(new Intent(getApplicationContext(), AutoScreenShotsAct.class));
37 | }
38 | });
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wanjian/scrollscreenshots/ScrollAct.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.scrollscreenshots;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.os.SystemClock;
6 | import android.support.annotation.Nullable;
7 | import android.view.LayoutInflater;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.BaseAdapter;
12 | import android.widget.ListView;
13 | import android.widget.TextView;
14 |
15 | /**
16 | * Created by wanjian on 2018/1/3.
17 | */
18 |
19 | public class ScrollAct extends Activity {
20 |
21 | private ListView listView;
22 |
23 | @Override
24 | protected void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_auto_scroll);
27 | listView = findViewById(R.id.listview);
28 |
29 | setAdapter();
30 |
31 | findViewById(R.id.start).setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View v) {
34 | autoScroll();
35 | }
36 | });
37 | }
38 |
39 | private void autoScroll() {
40 | final int delay = 16;
41 | final MotionEvent motionEvent = MotionEvent.obtain(SystemClock.uptimeMillis()
42 | , SystemClock.uptimeMillis()
43 | , MotionEvent.ACTION_DOWN
44 | , listView.getWidth() / 2
45 | , listView.getHeight() / 2
46 | , 0);
47 | listView.dispatchTouchEvent(motionEvent);//先分发 MotionEvent.ACTION_DOWN 事件
48 |
49 | listView.postDelayed(new Runnable() {
50 | @Override
51 | public void run() {
52 | motionEvent.setAction(MotionEvent.ACTION_MOVE); //延时分发 MotionEvent.ACTION_MOVE 事件
53 | //改变y坐标,越大滚动越快,但太大可能会导致掉帧
54 | motionEvent.setLocation((int) motionEvent.getX(), (int) motionEvent.getY() - 10);
55 | listView.dispatchTouchEvent(motionEvent);
56 | listView.postDelayed(this, delay);
57 | }
58 | }, delay);
59 | }
60 |
61 | private void setAdapter() {
62 |
63 | listView.setAdapter(new BaseAdapter() {
64 | @Override
65 | public int getCount() {
66 | return 100;
67 | }
68 |
69 | @Override
70 | public Object getItem(int position) {
71 | return null;
72 | }
73 |
74 | @Override
75 | public long getItemId(int position) {
76 | return 0;
77 | }
78 |
79 | @Override
80 | public View getView(int position, View convertView, ViewGroup parent) {
81 | if (convertView == null) {
82 | convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item, listView, false);
83 | convertView.setTag(R.id.index, convertView.findViewById(R.id.index));
84 | }
85 | ((TextView) convertView.getTag(R.id.index)).setText(position + "");
86 | return convertView;
87 | }
88 | });
89 |
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_auto_scroll.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_auto_scroll_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
17 |
22 |
23 |
24 |
25 |
26 |
27 |
32 |
33 |
34 |
42 |
43 |
48 |
49 |
55 |
56 |
57 |
64 |
65 |
68 |
69 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_draw_listview.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
16 |
17 |
22 |
23 |
24 |
25 |
26 |
32 |
33 |
38 |
39 |
44 |
45 |
51 |
52 |
53 |
59 |
60 |
65 |
66 |
72 |
73 |
74 |
80 |
81 |
86 |
87 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_draw_scrollview.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
16 |
17 |
22 |
23 |
28 |
29 |
30 |
31 |
32 |
33 |
39 |
40 |
45 |
46 |
51 |
52 |
58 |
59 |
60 |
66 |
67 |
72 |
73 |
79 |
80 |
81 |
87 |
88 |
93 |
94 |
100 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
22 |
23 |
28 |
29 |
30 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
17 |
18 |
23 |
24 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/labuladuo.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/app/src/main/res/mipmap-xxhdpi/labuladuo.jpeg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Scroll screen shots
3 | 自动滚动截屏\n基本原理\n1.画\n2.滚\n实现跟miui一样的自动滚动长截屏效果
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/wanjian/scrollscreenshots/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wanjian.scrollscreenshots;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/auto_cap_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/auto_cap_demo.gif
--------------------------------------------------------------------------------
/auto_cap_demo.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/auto_cap_demo.mp4
--------------------------------------------------------------------------------
/auto_scroll.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/auto_scroll.gif
--------------------------------------------------------------------------------
/auto_scroll.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/auto_scroll.mp4
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.1'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jan 03 09:47:37 CST 2018
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 |
--------------------------------------------------------------------------------
/listview_capture.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/listview_capture.jpg
--------------------------------------------------------------------------------
/miui_screen_cap.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/miui_screen_cap.gif
--------------------------------------------------------------------------------
/scrollview_capture.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android-notes/auto-scroll-capture/3a6bbd23b11611db3195c73b8a2ed9b7779590aa/scrollview_capture.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------