├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── beauney
│ │ └── scanning
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── beauney
│ │ │ └── scanning
│ │ │ ├── BaseActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── ScanningImageDemoActivity.java
│ │ │ ├── ScanningLayoutDemoActivity.java
│ │ │ ├── ScanningRoundDemoActivity.java
│ │ │ ├── ScanningViewDemoActivity.java
│ │ │ └── utils
│ │ │ ├── AnimatorUtil.java
│ │ │ └── ScreenCapture.java
│ └── res
│ │ ├── drawable-hdpi
│ │ ├── ad_progress_bar.png
│ │ ├── icon_choose_sel.png
│ │ ├── language_cn_sel.png
│ │ ├── language_en_sel.png
│ │ ├── temp_demand_3.jpg
│ │ ├── temp_demand_4.jpg
│ │ ├── temp_demand_5.jpg
│ │ └── window_background.jpg
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ad_progress_bar_bg.xml
│ │ ├── ad_progress_selector.xml
│ │ ├── ad_text_bg_shape.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── language_cn_nor.xml
│ │ ├── language_cn_selector.xml
│ │ ├── language_en_nor.xml
│ │ └── language_en_selector.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_scanning_image_demo.xml
│ │ ├── activity_scanning_layout_demo.xml
│ │ ├── activity_scanning_round_demo.xml
│ │ └── activity_scanning_view_demo.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
│ └── beauney
│ └── scanning
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── beauney
│ │ └── scanning
│ │ └── library
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── beauney
│ │ │ └── scanning
│ │ │ └── library
│ │ │ ├── ScanningImageView.java
│ │ │ ├── ScanningLinearLayout.java
│ │ │ ├── ScanningRoundView.java
│ │ │ ├── ScanningView.java
│ │ │ └── utils
│ │ │ └── DisplayUtil.java
│ └── res
│ │ ├── drawable-hdpi
│ │ ├── layount_light.png
│ │ ├── round_light.png
│ │ └── scanning_view_light.9.png
│ │ └── values
│ │ └── attrs.xml
│ └── test
│ └── java
│ └── com
│ └── beauney
│ └── scanning
│ └── library
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | /.idea
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ScanningView
2 | Android TV开发与手机开发最大的不同点就是焦点,TV常用的操作方式是遥控器,所以给用户一个醒目美观的焦点是至关重要的。很多产品经理在设计焦点的时候都会选择扫光的效果,比如小牧电视的控件选中效果。今天就给大家介绍一款自定义的扫光效果控件。
3 | # 效果展示
4 |
5 | 
6 | 
7 | 
8 | 
9 |
10 | # 使用步骤
11 | 1. 引入library
12 |
13 | ```implementation 'com.beauney.scanning:scanning-view:1.0.1'```
14 |
15 | 2. xml中使用控件
16 |
17 | ```
18 |
25 |
26 |
30 |
31 |
36 |
37 | ```
38 |
39 | 3. 代码中调用start()、stop()方法
40 |
41 | ```
42 | RelativeLayout container = findViewById(R.id.container);
43 |
44 | for (int i = 0; i < container.getChildCount(); i++) {
45 | container.getChildAt(i).setOnFocusChangeListener(new View.OnFocusChangeListener() {
46 | @Override
47 | public void onFocusChange(View view, boolean b) {
48 | ScanningView scanningView = view.findViewWithTag("scanning_view");
49 | if (b) {
50 | AnimatorUtil.scaleBigAnimator(view);
51 | scanningView.start();
52 | } else {
53 | AnimatorUtil.scaleSmallAnimator(view);
54 | scanningView.stop();
55 | }
56 | }
57 | });
58 | }
59 | ```
60 |
61 | 更多使用方法,请参考文章:[Android TV控件获得焦点的扫光效果](https://blog.csdn.net/zeng280091932/article/details/108880904)
62 |
63 | # Android架构师全套视频获取:
64 |
65 | 1、百度网盘:链接:https://pan.baidu.com/s/1GBHi4SgodTzuBa5haeD2_Q
66 |
67 | 提取码:eh4b
68 |
69 |
70 | 2、直接私信或+V:zengxiaotao1987 +Q:280091932索取
71 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.beauney.scanning"
9 | minSdkVersion 19
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | lintOptions { // 新增
25 | abortOnError false
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 | implementation 'com.beauney.scanning:scanning-view:1.0.1'
32 |
33 | // implementation project(':library')
34 | // debugImplementation project(':library')
35 | // releaseImplementation project(':library')
36 |
37 | implementation 'androidx.appcompat:appcompat:1.2.0'
38 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
39 | testImplementation 'junit:junit:4.12'
40 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
41 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
42 | }
43 |
--------------------------------------------------------------------------------
/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/beauney/scanning/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.beauney.scanning", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
28 |
31 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beauney/scanning/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.widget.Toast;
6 |
7 | import androidx.appcompat.app.AppCompatActivity;
8 |
9 | /**
10 | * @author zengjiantao
11 | * @since 2020-09-28
12 | */
13 | public abstract class BaseActivity extends AppCompatActivity {
14 |
15 | /**
16 | * 通过Class跳转界面
17 | **/
18 | protected void startActivity(Class> cls) {
19 | startActivity(cls, null);
20 | }
21 |
22 | /**
23 | * 含有Bundle通过Class跳转界面
24 | **/
25 | protected void startActivity(Class> cls, Bundle bundle) {
26 | Intent intent = new Intent();
27 | intent.setClass(this, cls);
28 | if (bundle != null) {
29 | intent.putExtras(bundle);
30 | }
31 | startActivity(intent);
32 | }
33 |
34 | /**
35 | * 短暂显示Toast提示(来自String)
36 | **/
37 | protected void showShortToast(String text) {
38 | Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
39 | }
40 |
41 | /**
42 | * 短暂显示Toast提示(id)
43 | **/
44 | protected void showShortToast(int resId) {
45 | Toast.makeText(this, resId, Toast.LENGTH_SHORT).show();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beauney/scanning/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | public class MainActivity extends BaseActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 | }
15 |
16 | public void scanningViewDemo(View view) {
17 | startActivity(ScanningViewDemoActivity.class);
18 | }
19 |
20 | public void RoundScanningViewDemo(View view) {
21 | startActivity(ScanningRoundDemoActivity.class);
22 | }
23 |
24 | public void imageScanningDemo(View view) {
25 | startActivity(ScanningImageDemoActivity.class);
26 | }
27 |
28 | public void scanningLayoutDemo(View view) {
29 | startActivity(ScanningLayoutDemoActivity.class);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beauney/scanning/ScanningImageDemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.ImageView;
6 |
7 | import com.beauney.scanning.library.ScanningImageView;
8 | import com.beauney.scanning.utils.ScreenCapture;
9 |
10 | import androidx.annotation.Nullable;
11 |
12 | /**
13 | * @author zengjiantao
14 | * @since 2020-09-28
15 | */
16 | public class ScanningImageDemoActivity extends BaseActivity {
17 |
18 | private ScanningImageView mScanningImageView;
19 | private ImageView mIconImg;
20 |
21 | @Override
22 | protected void onCreate(@Nullable Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_scanning_image_demo);
25 | mScanningImageView = findViewById(R.id.scanning_view);
26 | mIconImg = findViewById(R.id.icon_img);
27 | }
28 |
29 | public void startScanning(View view) {
30 | if (mScanningImageView.getSrcBitmap() == null) {
31 | mScanningImageView.setSrcBitmap(ScreenCapture.captureWidget(mIconImg));
32 | }
33 | mScanningImageView.start();
34 | }
35 |
36 | public void stopScanning(View view) {
37 | mScanningImageView.stop();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beauney/scanning/ScanningLayoutDemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 |
6 | import com.beauney.scanning.library.ScanningLinearLayout;
7 |
8 | import androidx.annotation.Nullable;
9 |
10 | /**
11 | * @author zengjiantao
12 | * @since 2020-09-28
13 | */
14 | public class ScanningLayoutDemoActivity extends BaseActivity {
15 | private ScanningLinearLayout mScanningLayout;
16 |
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_scanning_layout_demo);
21 |
22 | mScanningLayout = findViewById(R.id.scanning_container);
23 | }
24 |
25 | public void startScanning(View view) {
26 | mScanningLayout.start();
27 | }
28 |
29 | public void stopScanning(View view) {
30 | mScanningLayout.stop();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beauney/scanning/ScanningRoundDemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 |
6 | import com.beauney.scanning.library.ScanningRoundView;
7 |
8 | import androidx.annotation.Nullable;
9 |
10 | /**
11 | * @author zengjiantao
12 | * @since 2020-09-28
13 | */
14 | public class ScanningRoundDemoActivity extends BaseActivity {
15 | private ScanningRoundView mScanningRoundView;
16 |
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_scanning_round_demo);
21 | mScanningRoundView = findViewById(R.id.scanning_round_view);
22 | }
23 |
24 | public void startScanning(View view) {
25 | mScanningRoundView.start();
26 | }
27 |
28 | public void stopScanning(View view) {
29 | mScanningRoundView.stop();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beauney/scanning/ScanningViewDemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.RelativeLayout;
6 |
7 | import com.beauney.scanning.library.ScanningView;
8 | import com.beauney.scanning.utils.AnimatorUtil;
9 |
10 | import androidx.annotation.Nullable;
11 |
12 | /**
13 | * @author zengjiantao
14 | * @since 2020-09-28
15 | */
16 | public class ScanningViewDemoActivity extends BaseActivity {
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_scanning_view_demo);
21 | RelativeLayout container = findViewById(R.id.container);
22 |
23 | for (int i = 0; i < container.getChildCount(); i++) {
24 | container.getChildAt(i).setOnFocusChangeListener(new View.OnFocusChangeListener() {
25 | @Override
26 | public void onFocusChange(View view, boolean b) {
27 | ScanningView scanningView = view.findViewWithTag("scanning_view");
28 | if (b) {
29 | AnimatorUtil.scaleBigAnimator(view);
30 | scanningView.start();
31 | } else {
32 | AnimatorUtil.scaleSmallAnimator(view);
33 | scanningView.stop();
34 | }
35 | }
36 | });
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beauney/scanning/utils/AnimatorUtil.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning.utils;
2 |
3 | import android.view.View;
4 | import android.view.animation.AccelerateDecelerateInterpolator;
5 | import android.view.animation.AnticipateOvershootInterpolator;
6 |
7 | /**
8 | * @author zengjiantao
9 | * @since 2020-09-28
10 | */
11 | public class AnimatorUtil {
12 |
13 | private static final long SCALE_DURATION = 400L;
14 |
15 | private static final float DEFAULT_SCALE = 1.05f;
16 |
17 | /**
18 | * 放大效果动画
19 | *
20 | * @param view 目标控件
21 | */
22 | public static void scaleBigAnimator(View view) {
23 | scaleBigAnimator(view, DEFAULT_SCALE);
24 | }
25 |
26 | /**
27 | * 放大效果动画
28 | *
29 | * @param view 目标控件
30 | * @param scale 放大比例
31 | */
32 | public static void scaleBigAnimator(View view, float scale) {
33 | view.animate().cancel();
34 | view.animate()
35 | .scaleX(scale)
36 | .scaleY(scale)
37 | .setInterpolator(new AnticipateOvershootInterpolator())
38 | .setDuration(SCALE_DURATION)
39 | .start();
40 | }
41 |
42 | /**
43 | * 缩小效果动画
44 | *
45 | * @param view 目标控件
46 | */
47 | public static void scaleSmallAnimator(View view) {
48 | view.animate().cancel();
49 | view.animate()
50 | .scaleX(1f)
51 | .scaleY(1f)
52 | .setInterpolator(new AccelerateDecelerateInterpolator())
53 | .setDuration(SCALE_DURATION)
54 | .start();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beauney/scanning/utils/ScreenCapture.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | */
4 | package com.beauney.scanning.utils;
5 |
6 | import android.app.Activity;
7 | import android.graphics.Bitmap;
8 | import android.media.ThumbnailUtils;
9 | import android.view.View;
10 |
11 | /**
12 | * 截屏工具类
13 | *
14 | * @author zengjiantao
15 | * @date 2017-1-24
16 | */
17 | public class ScreenCapture {
18 |
19 | /**
20 | * 截取全屏截图
21 | *
22 | * @param activity
23 | * @return
24 | */
25 | public static Bitmap captureFullScreen(Activity activity) {
26 | View view = activity.getWindow().getDecorView();
27 | view.setDrawingCacheEnabled(true);
28 | view.buildDrawingCache();
29 | Bitmap bitmap = view.getDrawingCache();
30 | int width = activity.getWindowManager().getDefaultDisplay().getWidth();
31 | int height = activity.getWindowManager().getDefaultDisplay()
32 | .getHeight();
33 |
34 | Bitmap screenBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height);
35 | view.destroyDrawingCache();
36 | return screenBitmap;
37 | }
38 |
39 | /**
40 | * 截取指定控件截图
41 | *
42 | * @param view
43 | * @return
44 | */
45 | public static Bitmap captureWidget(View view) {
46 | if (view == null) {
47 | return null;
48 | }
49 | view.setDrawingCacheEnabled(true);
50 | view.buildDrawingCache();
51 | Bitmap bitmap = view.getDrawingCache();
52 | int width = view.getMeasuredWidth();
53 | int height = view.getMeasuredHeight();
54 |
55 | if (width <= 0 || height <= 0 || bitmap == null) {
56 | return null;
57 | }
58 | Bitmap screenBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height);
59 | view.destroyDrawingCache();
60 | return screenBitmap;
61 | }
62 |
63 | /**
64 | * 截取自定区域的屏幕内容
65 | *
66 | * @param activity
67 | * @param x
68 | * @param y
69 | * @param width
70 | * @param height
71 | * @return
72 | */
73 | public static Bitmap captureSpecifiedScreen(Activity activity, int x,
74 | int y, int width, int height) {
75 | View view = activity.getWindow().getDecorView();
76 | view.setDrawingCacheEnabled(true);
77 | view.buildDrawingCache();
78 | Bitmap bitmap = view.getDrawingCache();
79 | Bitmap screenBitmap = Bitmap.createBitmap(bitmap, x, y, width, height);
80 | view.destroyDrawingCache();
81 | return screenBitmap;
82 | }
83 |
84 | /**
85 | * 生成缩略图
86 | *
87 | * @param source
88 | * @param width
89 | * @param height
90 | * @return
91 | */
92 | public static Bitmap extractThumbnail(Bitmap source, int width, int height) {
93 | return ThumbnailUtils.extractThumbnail(source, width, height,
94 | ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ad_progress_bar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/drawable-hdpi/ad_progress_bar.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/icon_choose_sel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/drawable-hdpi/icon_choose_sel.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/language_cn_sel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/drawable-hdpi/language_cn_sel.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/language_en_sel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/drawable-hdpi/language_en_sel.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/temp_demand_3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/drawable-hdpi/temp_demand_3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/temp_demand_4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/drawable-hdpi/temp_demand_4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/temp_demand_5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/drawable-hdpi/temp_demand_5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/window_background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/drawable-hdpi/window_background.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ad_progress_bar_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ad_progress_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
6 |
7 | -
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ad_text_bg_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
--------------------------------------------------------------------------------
/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/drawable/language_cn_nor.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
10 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/language_cn_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/language_en_nor.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
10 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/language_en_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
27 |
28 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scanning_image_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
21 |
22 |
29 |
30 |
36 |
37 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scanning_layout_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
21 |
22 |
31 |
32 |
44 |
45 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scanning_round_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
21 |
22 |
29 |
30 |
35 |
36 |
48 |
49 |
60 |
61 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scanning_view_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
21 |
22 |
27 |
28 |
29 |
36 |
37 |
41 |
42 |
47 |
48 |
49 |
56 |
57 |
61 |
62 |
68 |
69 |
--------------------------------------------------------------------------------
/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/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ScanningView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/test/java/com/beauney/scanning/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/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 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.6.3'
12 | classpath 'com.novoda:bintray-release:0.9.2'
13 |
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | google()
23 | jcenter()
24 | }
25 | tasks.withType(Javadoc) { //兼容中文
26 | options.addStringOption('Xdoclint:none', '-quiet')
27 | options.addStringOption('encoding', 'UTF-8')
28 | options {
29 | encoding "UTF-8"
30 | charSet 'UTF-8'
31 | links "http://docs.oracle.com/javase/7/docs/api"
32 | }
33 | }
34 | }
35 |
36 | task clean(type: Delete) {
37 | delete rootProject.buildDir
38 | }
39 |
40 | tasks.withType(JavaCompile) {
41 | options.encoding = "UTF-8"
42 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 28 10:55:58 CST 2020
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-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | android {
5 | compileSdkVersion 29
6 | buildToolsVersion "29.0.3"
7 |
8 | defaultConfig {
9 | minSdkVersion 19
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | consumerProguardFiles 'consumer-rules.pro'
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | lintOptions { // 新增
26 | abortOnError false
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(dir: 'libs', include: ['*.jar'])
32 |
33 | implementation 'androidx.appcompat:appcompat:1.2.0'
34 | testImplementation 'junit:junit:4.12'
35 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
37 | }
38 |
39 | publish {
40 | userOrg = 'zengxiaotao1987'//bintray.com用户名
41 | groupId = 'com.beauney.scanning'//jcenter上的路径
42 | artifactId = 'scanning-view'//项目名称
43 | publishVersion = '1.0.1'//版本号
44 | desc = 'This is a custom widget of Android smart TV platform, which is used to display the sweeping effect when the widget gets focus.'//描述,不重要
45 | website = 'https://github.com/zeng280091932/ScanningView'//网站,不重要;尽量模拟github上的地址,例如我这样的;当然你有地址最好了
46 | }
47 |
--------------------------------------------------------------------------------
/library/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/library/consumer-rules.pro
--------------------------------------------------------------------------------
/library/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 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/beauney/scanning/library/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning.library;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.beauney.scanning.library.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/library/src/main/java/com/beauney/scanning/library/ScanningImageView.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning.library;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
8 | import android.graphics.Bitmap;
9 | import android.graphics.Canvas;
10 | import android.graphics.Color;
11 | import android.graphics.LinearGradient;
12 | import android.graphics.Paint;
13 | import android.graphics.PorterDuff;
14 | import android.graphics.PorterDuffXfermode;
15 | import android.util.AttributeSet;
16 | import android.view.View;
17 | import android.view.animation.AccelerateDecelerateInterpolator;
18 |
19 |
20 | /**
21 | * 扫光ImageView
22 | *
23 | * @author zengjiantao
24 | * @since 2018/10/9
25 | */
26 | public class ScanningImageView extends View {
27 |
28 | private static final long ANIMATOR_DURATION = 1000L;
29 |
30 | private int mLightColor = Color.WHITE;
31 |
32 | private Bitmap mSrcBitmap;
33 |
34 | private Bitmap mLightBitmap;
35 |
36 | private Paint mScanPaint;
37 |
38 | private Paint mLightPaint;
39 |
40 | private PorterDuffXfermode mPorterDuffXfermode;
41 |
42 | private float mLeft;
43 |
44 | private float mStart;
45 |
46 | private float mEnd;
47 |
48 | private ValueAnimator mAnimator;
49 |
50 | private Animator.AnimatorListener mAnimatorListener;
51 |
52 | public ScanningImageView(Context context) {
53 | super(context);
54 | init();
55 | }
56 |
57 | public ScanningImageView(Context context, AttributeSet attrs) {
58 | this(context, attrs, 0);
59 | }
60 |
61 | public ScanningImageView(Context context, AttributeSet attrs, int defStyleAttr) {
62 | super(context, attrs, defStyleAttr);
63 | init();
64 |
65 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ScanningImageView);
66 | mLightColor = typedArray.getColor(R.styleable.ScanningImageView_lightColor, Color.WHITE);
67 | typedArray.recycle();
68 | }
69 |
70 | private void createLightBitmap() {
71 | LinearGradient linearGradient = new LinearGradient(0, 0, getWidth(), getHeight(), new int[]{Color.TRANSPARENT, mLightColor, Color.TRANSPARENT}, new float[]{0.3f, 0.5f, 0.7f}, LinearGradient.TileMode.CLAMP);
72 | mLightPaint.setShader(linearGradient);
73 |
74 | mLightBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
75 | Canvas canvas = new Canvas(mLightBitmap);
76 | //绘制圆角矩形
77 | canvas.drawRect(0, 0, getWidth(), getHeight(), mLightPaint);
78 | }
79 |
80 | private void init() {
81 | //初始化画笔 设置抗锯齿和防抖动
82 | mScanPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
83 | mScanPaint.setDither(true);
84 | mScanPaint.setFilterBitmap(true);//加快显示速度,本设置项依赖于dither和xfermode的设置
85 |
86 | mLightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
87 | mLightPaint.setDither(true);
88 | mLightPaint.setStyle(Paint.Style.FILL);
89 | mLightPaint.setColor(Color.WHITE);
90 | mLightPaint.setFilterBitmap(true);
91 |
92 | mPorterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP);
93 | }
94 |
95 | @Override
96 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
97 | super.onSizeChanged(w, h, oldw, oldh);
98 | createLightBitmap();
99 | mLeft = mStart = -w;
100 | mEnd = w;
101 | }
102 |
103 | @Override
104 | protected void onDraw(Canvas canvas) {
105 | super.onDraw(canvas);
106 |
107 | int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), mScanPaint, Canvas.ALL_SAVE_FLAG);
108 | canvas.drawBitmap(mLightBitmap, mLeft, 0, mScanPaint);
109 | if (mSrcBitmap != null) {
110 | mScanPaint.setXfermode(mPorterDuffXfermode);
111 | canvas.drawBitmap(mSrcBitmap, 0, 0, mScanPaint);
112 | mScanPaint.setXfermode(null);
113 | }
114 | canvas.restoreToCount(sc);
115 | }
116 |
117 | private void initAnimator() {
118 | //初始化动画
119 | mAnimator = ValueAnimator.ofFloat(mStart, mEnd);
120 | mAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
121 | mAnimator.setDuration(ANIMATOR_DURATION);
122 | mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
123 | @Override
124 | public void onAnimationUpdate(ValueAnimator animation) {
125 | mLeft = (float) animation.getAnimatedValue();
126 | postInvalidate();
127 | }
128 | });
129 | mAnimator.addListener(new AnimatorListenerAdapter() {
130 | @Override
131 | public void onAnimationEnd(Animator animation) {
132 | setVisibility(GONE);
133 | if (mAnimatorListener != null) {
134 | mAnimatorListener.onAnimationEnd(animation);
135 | }
136 | }
137 |
138 | @Override
139 | public void onAnimationStart(Animator animation) {
140 | setVisibility(VISIBLE);
141 | if (mAnimatorListener != null) {
142 | mAnimatorListener.onAnimationStart(animation);
143 | }
144 | }
145 |
146 | @Override
147 | public void onAnimationCancel(Animator animation) {
148 | setVisibility(GONE);
149 | if (mAnimatorListener != null) {
150 | mAnimatorListener.onAnimationCancel(animation);
151 | }
152 | }
153 | });
154 | }
155 |
156 | public void start() {
157 | if (mSrcBitmap == null) {
158 | return;
159 | }
160 | post(new Runnable() {
161 | @Override
162 | public void run() {
163 | if (mAnimator == null) {
164 | initAnimator();
165 | } else if (mAnimator.isRunning()) {
166 | mAnimator.cancel();
167 | }
168 | mAnimator.start();
169 | }
170 | });
171 | }
172 |
173 | public void stop() {
174 | if (mAnimator != null && mAnimator.isRunning()) {
175 | mAnimator.cancel();
176 | }
177 | mLeft = mStart;
178 | postInvalidate();
179 | }
180 |
181 | public void setSrcBitmap(Bitmap srcBitmap) {
182 | this.mSrcBitmap = srcBitmap;
183 | }
184 |
185 | public Bitmap getSrcBitmap() {
186 | return mSrcBitmap;
187 | }
188 |
189 | public void setAnimatorListener(Animator.AnimatorListener animatorListener) {
190 | this.mAnimatorListener = animatorListener;
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/library/src/main/java/com/beauney/scanning/library/ScanningLinearLayout.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning.library;
2 |
3 | import android.animation.Keyframe;
4 | import android.animation.PropertyValuesHolder;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
8 | import android.graphics.Bitmap;
9 | import android.graphics.BitmapFactory;
10 | import android.graphics.Canvas;
11 | import android.graphics.Color;
12 | import android.graphics.Paint;
13 | import android.graphics.PorterDuff;
14 | import android.graphics.PorterDuffXfermode;
15 | import android.graphics.RectF;
16 | import android.util.AttributeSet;
17 | import android.view.View;
18 | import android.view.animation.AccelerateDecelerateInterpolator;
19 | import android.widget.LinearLayout;
20 |
21 | import com.beauney.scanning.library.utils.DisplayUtil;
22 |
23 | import androidx.annotation.Nullable;
24 |
25 | /**
26 | * 带扫描发光效果的线性布局
27 | *
28 | * @author zengjiantao
29 | * @since 2018/9/17
30 | */
31 | public class ScanningLinearLayout extends LinearLayout {
32 | private static final long ANIMATOR_DURATION = 2400L;
33 | private static final int DEFAULT_RADIUS_DP = 7;
34 |
35 | private Bitmap mBitmap;
36 |
37 | private Bitmap mRounderBitmap;
38 |
39 | private Paint mScanPaint;
40 |
41 | private Paint mRounderPaint;
42 |
43 | private float mLeft;
44 |
45 | private float mStart;
46 |
47 | private float mEnd;
48 |
49 | private ValueAnimator mAnimator;
50 |
51 | private PorterDuffXfermode mPorterDuffXfermode;
52 |
53 | private int mLightImage;
54 |
55 | private int mRadius;
56 |
57 | public ScanningLinearLayout(Context context) {
58 | super(context);
59 | init();
60 | }
61 |
62 | public ScanningLinearLayout(Context context, @Nullable AttributeSet attrs) {
63 | this(context, attrs, 0);
64 | }
65 |
66 | public ScanningLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
67 | super(context, attrs, defStyleAttr);
68 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ScanningLinearLayout);
69 | mLightImage = typedArray.getResourceId(R.styleable.ScanningLinearLayout_layoutLightImage, R.drawable.layount_light);
70 | mRadius = typedArray.getDimensionPixelOffset(R.styleable.ScanningLinearLayout_layoutRadius, DEFAULT_RADIUS_DP);
71 | typedArray.recycle();
72 | init();
73 | }
74 |
75 | private void createRounderBitmap() {
76 | mRounderBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
77 | Canvas canvas = new Canvas(mRounderBitmap);
78 | //绘制圆角矩形
79 | canvas.drawRoundRect(new RectF(0, 0, getWidth(), getHeight()), DisplayUtil.dip2px(getContext(), mRadius), DisplayUtil.dip2px(getContext(), mRadius), mRounderPaint);
80 | }
81 |
82 | private void init() {
83 | //初始化光图片
84 | mBitmap = BitmapFactory.decodeResource(getResources(), mLightImage);
85 | mLeft = mStart = -mBitmap.getWidth();
86 |
87 | //初始化画笔 设置抗锯齿和防抖动
88 | mScanPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
89 | mScanPaint.setDither(true);
90 | mScanPaint.setFilterBitmap(true);//加快显示速度,本设置项依赖于dither和xfermode的设置
91 |
92 |
93 | mRounderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
94 | mRounderPaint.setDither(true);
95 | mRounderPaint.setStyle(Paint.Style.FILL);
96 | mRounderPaint.setColor(Color.WHITE);
97 | mRounderPaint.setFilterBitmap(true);
98 |
99 | mPorterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
100 | }
101 |
102 | @Override
103 | protected void onDetachedFromWindow() {
104 | super.onDetachedFromWindow();
105 | if (mAnimator != null && mAnimator.isRunning()) {
106 | mAnimator.cancel();
107 | }
108 | }
109 |
110 | @Override
111 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
112 | super.onSizeChanged(w, h, oldw, oldh);
113 | createRounderBitmap();
114 | mEnd = w;
115 | }
116 |
117 | @Override
118 | protected void dispatchDraw(Canvas canvas) {
119 | super.dispatchDraw(canvas);
120 |
121 | int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), mScanPaint, Canvas.ALL_SAVE_FLAG);
122 | canvas.drawBitmap(mBitmap, mLeft, 0, mScanPaint);
123 | mScanPaint.setXfermode(mPorterDuffXfermode);
124 | canvas.drawBitmap(mRounderBitmap, 0, 0, mScanPaint);
125 | mScanPaint.setXfermode(null);
126 | canvas.restoreToCount(sc);
127 | }
128 |
129 | private void initAnimator() {
130 | PropertyValuesHolder pvhLeft = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_X,
131 | Keyframe.ofFloat(0f, mStart),
132 | Keyframe.ofFloat(.83f, mStart),
133 | Keyframe.ofFloat(1f, mEnd)
134 | );
135 | //初始化动画
136 | mAnimator = ValueAnimator.ofPropertyValuesHolder(pvhLeft);
137 | mAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
138 | mAnimator.setDuration(ANIMATOR_DURATION);
139 | // mAnimator.setStartDelay(ANIMATOR_DELAY);
140 | mAnimator.setRepeatCount(ValueAnimator.INFINITE);
141 | mAnimator.setRepeatMode(ValueAnimator.RESTART);
142 | mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
143 | @Override
144 | public void onAnimationUpdate(ValueAnimator animation) {
145 | mLeft = (float) animation.getAnimatedValue();
146 | postInvalidate();
147 | }
148 | });
149 | }
150 |
151 | public void start() {
152 | post(new Runnable() {
153 | @Override
154 | public void run() {
155 | if (mAnimator == null) {
156 | initAnimator();
157 | } else if (mAnimator.isRunning()) {
158 | mAnimator.cancel();
159 | }
160 | mAnimator.start();
161 | }
162 | });
163 | }
164 |
165 | public void stop() {
166 | if (mAnimator != null && mAnimator.isRunning()) {
167 | mAnimator.cancel();
168 | }
169 | mLeft = mStart;
170 | postInvalidate();
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/library/src/main/java/com/beauney/scanning/library/ScanningRoundView.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning.library;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Paint;
11 | import android.graphics.PorterDuff;
12 | import android.graphics.PorterDuffXfermode;
13 | import android.graphics.RectF;
14 | import android.util.AttributeSet;
15 | import android.view.View;
16 | import android.view.animation.AccelerateDecelerateInterpolator;
17 |
18 | import com.beauney.scanning.library.utils.DisplayUtil;
19 |
20 | import androidx.annotation.Nullable;
21 |
22 |
23 | /**
24 | * 开机广告的扫光效果
25 | *
26 | * @author zengjiantao
27 | * @since 2018/9/17
28 | */
29 | public class ScanningRoundView extends View {
30 | private static final long ANIMATOR_DURATION = 1000L;
31 | private static final int DEFAULT_RADIUS_DP = 7;
32 |
33 | private Bitmap mBitmap;
34 |
35 | private Bitmap mRounderBitmap;
36 |
37 | private Paint mScanPaint;
38 |
39 | private Paint mRounderPaint;
40 |
41 | private float mLeft;
42 |
43 | private float mStart;
44 |
45 | private float mEnd;
46 |
47 | private ValueAnimator mAnimator;
48 |
49 | private PorterDuffXfermode mPorterDuffXfermode;
50 |
51 | private int mLightImage;
52 |
53 | private int mRadius;
54 |
55 | public ScanningRoundView(Context context) {
56 | super(context);
57 | init();
58 | }
59 |
60 | public ScanningRoundView(Context context, @Nullable AttributeSet attrs) {
61 | this(context, attrs, 0);
62 | }
63 |
64 | public ScanningRoundView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
65 | super(context, attrs, defStyleAttr);
66 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ScanningRoundView);
67 | mLightImage = typedArray.getResourceId(R.styleable.ScanningRoundView_roundLightImage, R.drawable.round_light);
68 | mRadius = typedArray.getDimensionPixelOffset(R.styleable.ScanningRoundView_roundRadius, DEFAULT_RADIUS_DP);
69 | typedArray.recycle();
70 | init();
71 | }
72 |
73 | private void createRounderBitmap() {
74 | mRounderBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
75 | Canvas canvas = new Canvas(mRounderBitmap);
76 | //绘制圆角矩形
77 | canvas.drawRoundRect(new RectF(0, 0, getWidth(), getHeight()), DisplayUtil.dip2px(getContext(), mRadius), DisplayUtil.dip2px(getContext(), mRadius), mRounderPaint);
78 | }
79 |
80 | private void init() {
81 | //初始化光图片
82 | mBitmap = BitmapFactory.decodeResource(getResources(), mLightImage);
83 | mLeft = mStart = -mBitmap.getWidth();
84 |
85 | //初始化画笔 设置抗锯齿和防抖动
86 | mScanPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
87 | mScanPaint.setDither(true);
88 | mScanPaint.setFilterBitmap(true);//加快显示速度,本设置项依赖于dither和xfermode的设置
89 |
90 |
91 | mRounderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
92 | mRounderPaint.setDither(true);
93 | mRounderPaint.setStyle(Paint.Style.FILL);
94 | mRounderPaint.setColor(Color.WHITE);
95 | mRounderPaint.setFilterBitmap(true);
96 |
97 | mPorterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
98 | }
99 |
100 | @Override
101 | protected void onDetachedFromWindow() {
102 | super.onDetachedFromWindow();
103 | if (mAnimator != null && mAnimator.isRunning()) {
104 | mAnimator.cancel();
105 | }
106 | }
107 |
108 | @Override
109 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
110 | super.onSizeChanged(w, h, oldw, oldh);
111 | createRounderBitmap();
112 | mEnd = w;
113 | }
114 |
115 | @Override
116 | protected void onDraw(Canvas canvas) {
117 | super.onDraw(canvas);
118 |
119 | int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), mScanPaint, Canvas.ALL_SAVE_FLAG);
120 | canvas.drawBitmap(mBitmap, mLeft, 0, mScanPaint);
121 | mScanPaint.setXfermode(mPorterDuffXfermode);
122 | canvas.drawBitmap(mRounderBitmap, 0, 0, mScanPaint);
123 | mScanPaint.setXfermode(null);
124 | canvas.restoreToCount(sc);
125 | }
126 |
127 | private void initAnimator() {
128 | //初始化动画
129 | mAnimator = ValueAnimator.ofFloat(mStart, mEnd);
130 | mAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
131 | mAnimator.setDuration(ANIMATOR_DURATION);
132 | mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
133 | @Override
134 | public void onAnimationUpdate(ValueAnimator animation) {
135 | mLeft = (float) animation.getAnimatedValue();
136 | postInvalidate();
137 | }
138 | });
139 | }
140 |
141 | public void start() {
142 | post(new Runnable() {
143 | @Override
144 | public void run() {
145 | if (mAnimator == null) {
146 | initAnimator();
147 | } else if (mAnimator.isRunning()) {
148 | mAnimator.cancel();
149 | }
150 | mAnimator.start();
151 | }
152 | });
153 | }
154 |
155 | public void stop() {
156 | if (mAnimator != null && mAnimator.isRunning()) {
157 | mAnimator.cancel();
158 | }
159 | mLeft = mStart;
160 | postInvalidate();
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/library/src/main/java/com/beauney/scanning/library/ScanningView.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning.library;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Paint;
11 | import android.graphics.Rect;
12 | import android.graphics.RectF;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.animation.AccelerateDecelerateInterpolator;
16 |
17 | import androidx.annotation.NonNull;
18 | import androidx.annotation.Nullable;
19 |
20 |
21 | /**
22 | * 扫光控件,从左上角向右下角扫光
23 | *
24 | * @author zengjiantao
25 | * @since 2018/9/14
26 | */
27 | public class ScanningView extends View {
28 | private static final long ANIMATOR_DURATION = 400L;
29 |
30 | private Paint mScanPaint;
31 |
32 | private Bitmap mBitmap;
33 |
34 | private Rect mSrcRect;
35 |
36 | private RectF mDestRest;
37 |
38 | private float mDistance;
39 |
40 | private double mDegrees;
41 |
42 | private ValueAnimator mAnimator;
43 |
44 | private float mStartY;
45 |
46 | private float mTranslateY;
47 |
48 | private int mLightImage;
49 |
50 | public ScanningView(@NonNull Context context) {
51 | super(context);
52 | init();
53 | }
54 |
55 | public ScanningView(@NonNull Context context, @Nullable AttributeSet attrs) {
56 | this(context, attrs, 0);
57 | }
58 |
59 | public ScanningView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
60 | super(context, attrs, defStyleAttr);
61 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ScanningView);
62 | mLightImage = typedArray.getResourceId(R.styleable.ScanningView_lightImage, R.drawable.scanning_view_light);
63 | typedArray.recycle();
64 | init();
65 | }
66 |
67 | @Override
68 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
69 | super.onSizeChanged(w, h, oldw, oldh);
70 | //计算出控件的对角线夹角角度
71 | double radians = Math.atan((double) h / (double) w);
72 | mDegrees = Math.toDegrees(radians);
73 | //计算出光要移动的距离
74 | mDistance = (float) (Math.sin(radians) * w * 2);
75 |
76 | //设置光初始绘画位置
77 | int lightWidth = w > h ? w : h;
78 | mDestRest.set(-lightWidth, 0, lightWidth * 2, mBitmap.getHeight());
79 | }
80 |
81 | @Override
82 | protected void onDraw(Canvas canvas) {
83 | super.onDraw(canvas);
84 |
85 | canvas.save();
86 | canvas.rotate((float) -mDegrees);
87 | canvas.translate(-getWidth() / 2, mTranslateY);
88 | canvas.drawBitmap(mBitmap, mSrcRect, mDestRest, mScanPaint);
89 | canvas.restore();
90 | }
91 |
92 | @Override
93 | protected void onDetachedFromWindow() {
94 | super.onDetachedFromWindow();
95 | if (mAnimator != null && mAnimator.isRunning()) {
96 | mAnimator.cancel();
97 | }
98 | }
99 |
100 | private void init() {
101 | //初始化光图片
102 | mBitmap = BitmapFactory.decodeResource(getResources(), mLightImage);
103 | mSrcRect = new Rect(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
104 | mDestRest = new RectF();
105 | mTranslateY = mStartY = -mBitmap.getHeight();
106 |
107 | //初始化画笔 设置抗锯齿和防抖动
108 | mScanPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
109 | mScanPaint.setDither(true);
110 | }
111 |
112 | private void initAnimator() {
113 | //初始化动画
114 | mAnimator = ValueAnimator.ofFloat(mStartY, mDistance);
115 | mAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
116 | mAnimator.setDuration(ANIMATOR_DURATION);
117 | mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
118 | @Override
119 | public void onAnimationUpdate(ValueAnimator animation) {
120 | mTranslateY = (float) animation.getAnimatedValue();
121 | postInvalidate();
122 | }
123 | });
124 | }
125 |
126 | public void start() {
127 | post(new Runnable() {
128 | @Override
129 | public void run() {
130 | if (mAnimator == null) {
131 | initAnimator();
132 | } else if (mAnimator.isRunning()) {
133 | mAnimator.cancel();
134 | }
135 | mAnimator.start();
136 | }
137 | });
138 | }
139 |
140 | public void stop() {
141 | if (mAnimator != null && mAnimator.isRunning()) {
142 | mAnimator.cancel();
143 | }
144 | mTranslateY = mStartY;
145 | postInvalidate();
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/library/src/main/java/com/beauney/scanning/library/utils/DisplayUtil.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning.library.utils;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * 屏幕显示工具类
7 | *
8 | * @author zengjiantao
9 | * @since 2020-09-28
10 | */
11 | public class DisplayUtil {
12 | /**
13 | * 将dip或dp值转换为px值,保证尺寸大小不变
14 | *
15 | * @param context 上下文
16 | * @param dipValue (DisplayMetrics类中属性density)
17 | * @return px值
18 | */
19 | public static int dip2px(Context context, float dipValue) {
20 | final float scale = context.getResources().getDisplayMetrics().density;
21 | return (int) (dipValue * scale + 0.5f);
22 | }
23 |
24 | /**
25 | * 将px值转换为sp值,保证文字大小不变
26 | *
27 | * @param context 上下文
28 | * @param pxValue (DisplayMetrics类中属性scaledDensity)
29 | * @return sp值
30 | */
31 | public static int px2sp(Context context, float pxValue) {
32 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
33 | return (int) (pxValue / fontScale + 0.5f);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/layount_light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/library/src/main/res/drawable-hdpi/layount_light.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/round_light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/library/src/main/res/drawable-hdpi/round_light.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/scanning_view_light.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeng280091932/ScanningView/964d25b0be2aaf90ad84b6b68d1f2e5f05daabf9/library/src/main/res/drawable-hdpi/scanning_view_light.9.png
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/library/src/test/java/com/beauney/scanning/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.beauney.scanning.library;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name='ScanningView'
2 | include ':app'
3 | include ':library'
4 |
--------------------------------------------------------------------------------