├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── CountdownView ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── xinshiwi │ │ └── power │ │ └── progressview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── xinshiwi │ │ │ └── power │ │ │ └── progressview │ │ │ ├── MainActivity.java │ │ │ ├── OnFinishListener.java │ │ │ ├── ProgressView.java │ │ │ └── SplashActivity.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ └── activity_splash.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 │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── xinshiwi │ └── power │ └── progressview │ └── ExampleUnitTest.java ├── README.md ├── ScreenShots ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── xinshiwi │ │ └── power │ │ └── screenshotsdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── xinshiwi │ │ │ └── power │ │ │ └── screenshotsdemo │ │ │ ├── MainActivity.java │ │ │ ├── RvActivity.java │ │ │ ├── RvAdapter.java │ │ │ ├── ShootUtils.java │ │ │ └── SvActivity.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_rv.xml │ │ ├── activity_sv.xml │ │ ├── item_rv.xml │ │ └── pop_photo.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 │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── xinshiwi │ └── power │ └── screenshotsdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mvpdemo ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── xinyang │ │ └── mvpdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── xinyang │ │ │ └── mvpdemo │ │ │ ├── LoginActivity.java │ │ │ ├── model │ │ │ ├── ILoginBiz.java │ │ │ ├── LoginBiz.java │ │ │ ├── OnLoginListener.java │ │ │ └── UserInfoBean.java │ │ │ ├── presenter │ │ │ └── UserLoginPresenter.java │ │ │ └── view │ │ │ └── ILoginView.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_login.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 │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── xinyang │ └── mvpdemo │ └── ExampleUnitTest.java └── 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/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CountdownView/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /CountdownView/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion '26.0.2' 6 | 7 | defaultConfig { 8 | applicationId "com.xinshiwi.power.progressview" 9 | minSdkVersion 21 10 | targetSdkVersion 26 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(dir: 'libs', include: ['*.jar']) 27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 28 | exclude group: 'com.android.support', module: 'support-annotations' 29 | }) 30 | compile 'com.android.support:appcompat-v7:26.+' 31 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 32 | testCompile 'junit:junit:4.12' 33 | } 34 | -------------------------------------------------------------------------------- /CountdownView/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\develop\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /CountdownView/src/androidTest/java/com/xinshiwi/power/progressview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.progressview; 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 | * Instrumentation 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.xinshiwi.power.progressview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CountdownView/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /CountdownView/src/main/java/com/xinshiwi/power/progressview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.progressview; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class MainActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_main); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CountdownView/src/main/java/com/xinshiwi/power/progressview/OnFinishListener.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.progressview; 2 | 3 | /** 4 | * 进度完成监听接口 5 | * Created by xinyang on 2017/12/15. 6 | */ 7 | 8 | public interface OnFinishListener { 9 | 10 | /** 11 | * 结束时回调 12 | */ 13 | void onFinish(); 14 | } 15 | -------------------------------------------------------------------------------- /CountdownView/src/main/java/com/xinshiwi/power/progressview/ProgressView.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.progressview; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.graphics.RectF; 8 | import android.support.annotation.Nullable; 9 | import android.util.AttributeSet; 10 | import android.view.View; 11 | 12 | /** 13 | * 圆形倒计时进度条 14 | * 15 | * @author xinyang 16 | */ 17 | 18 | public class ProgressView extends View { 19 | 20 | 21 | private RectF mRectF; 22 | private Paint mPaint; 23 | /** 24 | * 画笔颜色 25 | */ 26 | private int paintColor; 27 | /** 28 | * 进度条圆弧宽度 29 | */ 30 | private int mStrokeWidth = 8; 31 | /** 32 | * 最大进度 33 | */ 34 | private float mMaxProgress = 100; 35 | /** 36 | * 当前进度 37 | */ 38 | private float mProgress = 0; 39 | 40 | 41 | public ProgressView(Context context) { 42 | this(context, null); 43 | } 44 | 45 | public ProgressView(Context context, @Nullable AttributeSet attrs) { 46 | this(context, attrs, 0); 47 | } 48 | 49 | public ProgressView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 50 | super(context, attrs, defStyleAttr); 51 | 52 | mRectF = new RectF(); 53 | mPaint = new Paint(); 54 | } 55 | 56 | @Override 57 | protected void onDraw(Canvas canvas) { 58 | super.onDraw(canvas); 59 | int width = this.getWidth(); 60 | int height = this.getHeight(); 61 | 62 | if (width != height) { 63 | int min = Math.min(width, height); 64 | width = min; 65 | height = min; 66 | } 67 | 68 | //位置 69 | mRectF.left = mStrokeWidth / 2; 70 | mRectF.top = mStrokeWidth / 2; 71 | mRectF.right = width - mStrokeWidth / 2; 72 | mRectF.bottom = height - mStrokeWidth / 2; 73 | 74 | //设置画布为透明 75 | canvas.drawColor(Color.TRANSPARENT); 76 | 77 | //画个半透明的圆当背景 78 | mPaint.setColor(Color.parseColor("#33000000")); 79 | mPaint.setStyle(Paint.Style.FILL); 80 | canvas.drawOval(mRectF, mPaint); 81 | 82 | 83 | //设置画笔 84 | mPaint.setAntiAlias(true); 85 | mPaint.setColor(paintColor); 86 | mPaint.setStyle(Paint.Style.STROKE); 87 | mPaint.setStrokeWidth(mStrokeWidth); 88 | 89 | 90 | canvas.drawArc(mRectF, -90, -(mProgress / mMaxProgress) * 360, false, mPaint); 91 | } 92 | 93 | /** 94 | * 设置画笔颜色 95 | * 96 | * @param color 97 | */ 98 | public void setPaintColor(String color) { 99 | paintColor = Color.parseColor(color); 100 | } 101 | 102 | /** 103 | * 设置到最大进度的时间 104 | * 105 | * @param time 倒计时时间 毫秒值 106 | */ 107 | public void startDownTime(final long time, final OnFinishListener listener) { 108 | mMaxProgress = 100; 109 | new Thread(new Runnable() { 110 | @Override 111 | public void run() { 112 | for (int i = (int) mMaxProgress; i >= 0; i--) { 113 | try { 114 | Thread.sleep((long) (time / mMaxProgress)); 115 | //当倒计时结束时通知 116 | if (i == 0 && listener != null) { 117 | post(new Runnable() { 118 | @Override 119 | public void run() { 120 | listener.onFinish(); 121 | } 122 | }); 123 | } 124 | } catch (InterruptedException e) { 125 | e.printStackTrace(); 126 | } 127 | mProgress = (float) i; 128 | ProgressView.this.postInvalidate(); 129 | } 130 | } 131 | }).start(); 132 | } 133 | 134 | 135 | } 136 | -------------------------------------------------------------------------------- /CountdownView/src/main/java/com/xinshiwi/power/progressview/SplashActivity.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.progressview; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.RelativeLayout; 8 | 9 | public class SplashActivity extends AppCompatActivity { 10 | 11 | private ProgressView mProgressView; 12 | private RelativeLayout mRlEnter; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_splash); 18 | 19 | initView(); 20 | } 21 | 22 | private void initView() { 23 | mRlEnter = (RelativeLayout) findViewById(R.id.rl_enter); 24 | mProgressView = (ProgressView) findViewById(R.id.progress); 25 | 26 | //跳过的点击事件 27 | mRlEnter.setOnClickListener(new View.OnClickListener() { 28 | @Override 29 | public void onClick(View view) { 30 | enterMain(); 31 | } 32 | }); 33 | 34 | //设置进度条颜色 35 | mProgressView.setPaintColor("#ff0000"); 36 | //开始倒计时 37 | mProgressView.startDownTime(3500, new OnFinishListener() { 38 | @Override 39 | public void onFinish() { 40 | enterMain(); 41 | } 42 | }); 43 | } 44 | 45 | private void enterMain(){ 46 | startActivity(new Intent(this,MainActivity.class)); 47 | finish(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /CountdownView/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /CountdownView/src/main/res/layout/activity_splash.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 18 | 19 | 24 | 25 | 32 | 33 | 34 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /CountdownView/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinyang123123/AndroidDemo/9ee5a96f74658f4220e31f175b74c23cd8e1a614/CountdownView/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /CountdownView/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinyang123123/AndroidDemo/9ee5a96f74658f4220e31f175b74c23cd8e1a614/CountdownView/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /CountdownView/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinyang123123/AndroidDemo/9ee5a96f74658f4220e31f175b74c23cd8e1a614/CountdownView/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /CountdownView/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinyang123123/AndroidDemo/9ee5a96f74658f4220e31f175b74c23cd8e1a614/CountdownView/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /CountdownView/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinyang123123/AndroidDemo/9ee5a96f74658f4220e31f175b74c23cd8e1a614/CountdownView/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CountdownView/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinyang123123/AndroidDemo/9ee5a96f74658f4220e31f175b74c23cd8e1a614/CountdownView/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /CountdownView/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinyang123123/AndroidDemo/9ee5a96f74658f4220e31f175b74c23cd8e1a614/CountdownView/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CountdownView/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinyang123123/AndroidDemo/9ee5a96f74658f4220e31f175b74c23cd8e1a614/CountdownView/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /CountdownView/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinyang123123/AndroidDemo/9ee5a96f74658f4220e31f175b74c23cd8e1a614/CountdownView/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CountdownView/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xinyang123123/AndroidDemo/9ee5a96f74658f4220e31f175b74c23cd8e1a614/CountdownView/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /CountdownView/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /CountdownView/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ProgressView 3 | 4 | -------------------------------------------------------------------------------- /CountdownView/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /CountdownView/src/test/java/com/xinshiwi/power/progressview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.progressview; 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 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidDemo 2 | 平日里写的一些小demo 3 | 4 | 5 | 6 | - [Android闪屏页圆形倒计时进度条实现](https://juejin.im/post/5a329793518825214c7f1170) 7 | - [Android 普通View截图 RecyclerView截图 ScrollView截图](https://juejin.im/post/5a37d8436fb9a04522079d33) 8 | -------------------------------------------------------------------------------- /ScreenShots/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /ScreenShots/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion '26.0.2' 6 | 7 | defaultConfig { 8 | applicationId "com.xinshiwi.power.screenshotsdemo" 9 | minSdkVersion 21 10 | targetSdkVersion 26 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(include: ['*.jar'], dir: 'libs') 27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 28 | exclude group: 'com.android.support', module: 'support-annotations' 29 | }) 30 | compile 'com.android.support:appcompat-v7:26.+' 31 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 32 | compile 'com.android.support:design:26.0.0-alpha1' 33 | compile 'com.github.chrisbanes:PhotoView:2.1.3' 34 | testCompile 'junit:junit:4.12' 35 | } 36 | -------------------------------------------------------------------------------- /ScreenShots/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\develop\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /ScreenShots/src/androidTest/java/com/xinshiwi/power/screenshotsdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.screenshotsdemo; 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 | * Instrumentation 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.xinshiwi.power.screenshotsdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ScreenShots/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /ScreenShots/src/main/java/com/xinshiwi/power/screenshotsdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.screenshotsdemo; 2 | 3 | import android.content.Intent; 4 | import android.graphics.Bitmap; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.Gravity; 8 | import android.view.View; 9 | import android.widget.PopupWindow; 10 | 11 | import com.github.chrisbanes.photoview.PhotoView; 12 | 13 | public class MainActivity extends AppCompatActivity { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | 20 | initView(); 21 | } 22 | 23 | private void initView() { 24 | findViewById(R.id.btn).setOnClickListener(mClickListener); 25 | findViewById(R.id.btn_scroll).setOnClickListener(mClickListener); 26 | findViewById(R.id.btn_rv).setOnClickListener(mClickListener); 27 | } 28 | 29 | View.OnClickListener mClickListener = new View.OnClickListener() { 30 | @Override 31 | public void onClick(View view) { 32 | switch (view.getId()) { 33 | case R.id.btn: 34 | Bitmap bitmap = ShootUtils.shotView(getWindow().getDecorView()); 35 | if (bitmap != null){ 36 | showPhoto(bitmap); 37 | } 38 | break; 39 | case R.id.btn_scroll: 40 | startActivity(new Intent(MainActivity.this, SvActivity.class)); 41 | break; 42 | case R.id.btn_rv: 43 | startActivity(new Intent(MainActivity.this, RvActivity.class)); 44 | break; 45 | } 46 | } 47 | }; 48 | 49 | private void showPhoto(Bitmap bitmap) { 50 | View view = View.inflate(this, R.layout.pop_photo, null); 51 | PhotoView pv = view.findViewById(R.id.pv); 52 | pv.setImageBitmap(bitmap); 53 | PopupWindow window = new PopupWindow(this); 54 | window.setContentView(view); 55 | window.setFocusable(true); 56 | window.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, 0, 0); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ScreenShots/src/main/java/com/xinshiwi/power/screenshotsdemo/RvActivity.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.screenshotsdemo; 2 | 3 | import android.graphics.Bitmap; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.Gravity; 9 | import android.view.View; 10 | import android.widget.Button; 11 | import android.widget.PopupWindow; 12 | 13 | import com.github.chrisbanes.photoview.PhotoView; 14 | 15 | import java.util.ArrayList; 16 | 17 | public class RvActivity extends AppCompatActivity { 18 | 19 | private Button mBtn; 20 | private RecyclerView mRv; 21 | private ArrayList mList; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_rv); 27 | 28 | initView(); 29 | initData(); 30 | } 31 | 32 | private void initView() { 33 | mBtn = (Button) findViewById(R.id.btn); 34 | mRv = (RecyclerView) findViewById(R.id.rv); 35 | mBtn.setOnClickListener(new View.OnClickListener() { 36 | @Override 37 | public void onClick(View v) { 38 | Bitmap bitmap = ShootUtils.shotRecyclerView(mRv); 39 | if (bitmap != null) { 40 | showPhoto(bitmap); 41 | } 42 | } 43 | }); 44 | } 45 | 46 | private void showPhoto(Bitmap bitmap) { 47 | View view = View.inflate(this, R.layout.pop_photo, null); 48 | PhotoView pv = view.findViewById(R.id.pv); 49 | pv.setImageBitmap(bitmap); 50 | PopupWindow window = new PopupWindow(this); 51 | window.setContentView(view); 52 | window.setFocusable(true); 53 | window.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, 0, 0); 54 | } 55 | 56 | private void initData() { 57 | mList = new ArrayList<>(); 58 | for (int i = 0; i < 50; i++) { 59 | mList.add("我是item" + i); 60 | } 61 | initRv(); 62 | } 63 | 64 | private void initRv() { 65 | RvAdapter adapter = new RvAdapter(mList, this); 66 | mRv.setLayoutManager(new LinearLayoutManager(this)); 67 | mRv.setAdapter(adapter); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /ScreenShots/src/main/java/com/xinshiwi/power/screenshotsdemo/RvAdapter.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.screenshotsdemo; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import java.util.ArrayList; 11 | 12 | /** 13 | * Created by xinyang on 2017/12/18. 14 | */ 15 | 16 | public class RvAdapter extends RecyclerView.Adapter { 17 | 18 | private ArrayList mList; 19 | private Context mContext; 20 | 21 | public RvAdapter(ArrayList list, Context context) { 22 | mList = list; 23 | mContext = context; 24 | } 25 | 26 | @Override 27 | public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 28 | // View view = View.inflate(mContext, R.layout.item_rv, null); 29 | View view = LayoutInflater.from(mContext).inflate(R.layout.item_rv, parent, false); 30 | return new MyViewHolder(view); 31 | } 32 | 33 | @Override 34 | public void onBindViewHolder(MyViewHolder holder, int position) { 35 | holder.tv.setText(mList.get(position)); 36 | } 37 | 38 | @Override 39 | public int getItemCount() { 40 | return mList == null ? 0 : mList.size(); 41 | } 42 | 43 | static class MyViewHolder extends RecyclerView.ViewHolder { 44 | 45 | public TextView tv; 46 | 47 | public MyViewHolder(View itemView) { 48 | super(itemView); 49 | tv = itemView.findViewById(R.id.tv); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /ScreenShots/src/main/java/com/xinshiwi/power/screenshotsdemo/ShootUtils.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.screenshotsdemo; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.Canvas; 5 | import android.graphics.Paint; 6 | import android.graphics.drawable.ColorDrawable; 7 | import android.graphics.drawable.Drawable; 8 | import android.support.v4.util.LruCache; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.View; 11 | import android.widget.ScrollView; 12 | 13 | 14 | /** 15 | * 截图工具类 16 | * 17 | * @author xinyang 18 | * @date 2017/12/11 19 | */ 20 | 21 | public class ShootUtils { 22 | 23 | 24 | /** 25 | * recyclerView 滚动截图 26 | * 27 | * @param view recyclerView 28 | */ 29 | public static Bitmap shotRecyclerView(RecyclerView view) { 30 | //获取设置的adapter 31 | RecyclerView.Adapter adapter = view.getAdapter(); 32 | if (adapter == null) { 33 | return null; 34 | } 35 | //创建保存截图的bitmap 36 | Bitmap bigBitmap = null; 37 | //获取item的数量 38 | int size = adapter.getItemCount(); 39 | //recycler的完整高度 用于创建bitmap时使用 40 | int height = 0; 41 | //获取最大可用内存 42 | final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); 43 | 44 | // 使用1/8的缓存 45 | final int cacheSize = maxMemory / 8; 46 | //把每个item的绘图缓存存储在LruCache中 47 | LruCache bitmapCache = new LruCache<>(cacheSize); 48 | for (int i = 0; i < size; i++) { 49 | //手动调用创建和绑定ViewHolder方法, 50 | RecyclerView.ViewHolder holder = adapter.createViewHolder(view, adapter.getItemViewType(i)); 51 | adapter.onBindViewHolder(holder, i); 52 | //测量 53 | holder.itemView.measure( 54 | View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY), 55 | View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); 56 | //布局 57 | holder.itemView.layout(0, 0, holder.itemView.getMeasuredWidth(), 58 | holder.itemView.getMeasuredHeight()); 59 | //开启绘图缓存 60 | holder.itemView.setDrawingCacheEnabled(true); 61 | holder.itemView.buildDrawingCache(); 62 | Bitmap drawingCache = holder.itemView.getDrawingCache(); 63 | if (drawingCache != null) { 64 | bitmapCache.put(String.valueOf(i), drawingCache); 65 | } 66 | //获取itemView的实际高度并累加 67 | height += holder.itemView.getMeasuredHeight(); 68 | } 69 | //根据计算出的recyclerView高度创建bitmap 70 | bigBitmap = Bitmap.createBitmap(view.getMeasuredWidth(), height, Bitmap.Config.RGB_565); 71 | //创建一个canvas画板 72 | Canvas canvas = new Canvas(bigBitmap); 73 | //获取recyclerView的背景颜色 74 | Drawable background = view.getBackground(); 75 | //画出recyclerView的背景色 这里只用了color一种 有需要也可以自己扩展 76 | if (background instanceof ColorDrawable) { 77 | ColorDrawable colorDrawable = (ColorDrawable) background; 78 | int color = colorDrawable.getColor(); 79 | canvas.drawColor(color); 80 | } 81 | //当前bitmap的高度 82 | int top = 0; 83 | //画笔 84 | Paint paint = new Paint(); 85 | for (int i = 0; i < size; i++) { 86 | Bitmap bitmap = bitmapCache.get(String.valueOf(i)); 87 | canvas.drawBitmap(bitmap, 0f, top, paint); 88 | top += bitmap.getHeight(); 89 | //如果有在第二次截图时崩溃等状况,注掉下面方法就好,原因我还没想明白。。。 90 | bitmap.recycle(); 91 | } 92 | return bigBitmap; 93 | } 94 | 95 | 96 | /** 97 | * 普通View截图 98 | * 99 | * @param view view对象 100 | * @return 101 | */ 102 | public static Bitmap shotView(View view) { 103 | //开启绘图缓存 104 | view.setDrawingCacheEnabled(true); 105 | view.buildDrawingCache(); 106 | //获取绘图缓存 107 | Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache(), 0, 0, view.getMeasuredWidth(), 108 | view.getMeasuredHeight()); 109 | //清理绘图缓存,释放资源 110 | view.destroyDrawingCache(); 111 | return bitmap; 112 | } 113 | 114 | /** 115 | * ScrollView截图 116 | */ 117 | public static Bitmap shotScrollView(ScrollView view) { 118 | int height = 0; 119 | //理论上scrollView只会有一个子View啦 120 | for (int i = 0; i < view.getChildCount(); i++) { 121 | height += view.getChildAt(i).getHeight(); 122 | } 123 | //创建保存缓存的bitmap 124 | Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), height, Bitmap.Config.RGB_565); 125 | //可以简单的把Canvas理解为一个画板 而bitmap就是块画布 126 | Canvas canvas = new Canvas(bitmap); 127 | //获取ScrollView的背景颜色 128 | Drawable background = view.getBackground(); 129 | //画出ScrollView的背景色 这里只用了color一种 有需要也可以自己扩展 也可以自己直接指定一种背景色 130 | if (background instanceof ColorDrawable) { 131 | ColorDrawable colorDrawable = (ColorDrawable) background; 132 | int color = colorDrawable.getColor(); 133 | canvas.drawColor(color); 134 | } 135 | //把view的内容都画到指定的画板Canvas上 136 | view.draw(canvas); 137 | return bitmap; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /ScreenShots/src/main/java/com/xinshiwi/power/screenshotsdemo/SvActivity.java: -------------------------------------------------------------------------------- 1 | package com.xinshiwi.power.screenshotsdemo; 2 | 3 | import android.graphics.Bitmap; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.Gravity; 7 | import android.view.View; 8 | import android.widget.PopupWindow; 9 | import android.widget.ScrollView; 10 | 11 | import com.github.chrisbanes.photoview.PhotoView; 12 | 13 | public class SvActivity extends AppCompatActivity { 14 | 15 | private ScrollView mSv; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_sv); 21 | 22 | initView(); 23 | } 24 | 25 | private void initView(){ 26 | mSv = (ScrollView) findViewById(R.id.sv); 27 | findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() { 28 | @Override 29 | public void onClick(View v) { 30 | Bitmap bitmap = ShootUtils.shotScrollView(mSv); 31 | if (bitmap != null){ 32 | showPhoto(bitmap); 33 | } 34 | } 35 | }); 36 | } 37 | 38 | private void showPhoto(Bitmap bitmap) { 39 | View view = View.inflate(this, R.layout.pop_photo, null); 40 | PhotoView pv = view.findViewById(R.id.pv); 41 | pv.setImageBitmap(bitmap); 42 | PopupWindow window = new PopupWindow(this); 43 | window.setContentView(view); 44 | window.setFocusable(true); 45 | window.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, 0, 0); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ScreenShots/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 |