├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── demo.gif
│ │ │ │ ├── gray_progress.png
│ │ │ │ └── simple_bitmap.png
│ │ │ ├── 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
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_select_idiom_progress.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── colors.xml
│ │ │ └── layout
│ │ │ │ ├── activity_test_bitmap.xml
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── test
│ │ │ └── progress
│ │ │ ├── TestBitmapActivity.java
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── test
│ │ │ └── progress
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── test
│ │ └── progress
│ │ └── ExampleInstrumentedTest.java
├── libs
│ └── SelectColorDialog-debug.aar
├── proguard-rules.pro
└── build.gradle
├── MyProgress
├── .gitignore
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── progress_attr.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── progress
│ │ │ └── MyProgress.java
│ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── progress
│ │ │ └── ExampleInstrumentedTest.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── progress
│ │ └── ExampleUnitTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── aar
└── MyProgress-release.aar
├── .gitignore
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/MyProgress/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':MyProgress'
2 |
--------------------------------------------------------------------------------
/aar/MyProgress-release.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/aar/MyProgress-release.aar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/drawable/demo.gif
--------------------------------------------------------------------------------
/app/libs/SelectColorDialog-debug.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/libs/SelectColorDialog-debug.aar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/gray_progress.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/drawable/gray_progress.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/simple_bitmap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/drawable/simple_bitmap.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_select_idiom_progress.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhongruiAndroid/Progress/HEAD/app/src/main/res/drawable-xxhdpi/ic_select_idiom_progress.png
--------------------------------------------------------------------------------
/MyProgress/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .DS_Store
5 | build/
6 | /captures
7 | .externalNativeBuild
8 | !build.gradle
9 | .idea/
10 | gradle/
11 | gradle.properties
12 | *.apk
13 | .svn
14 | help.gradle
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Progress
3 |
4 |
5 | Hello blank fragment
6 |
7 |
--------------------------------------------------------------------------------
/MyProgress/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 30
5 |
6 | defaultConfig {
7 | minSdkVersion 15
8 | targetSdkVersion 30
9 | versionCode 1
10 | versionName "1.0"
11 |
12 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
13 |
14 | }
15 |
16 | }
17 | dependencies {
18 | implementation 'androidx.appcompat:appcompat:1.0.0'
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/test/progress/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.test.progress;
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 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_test_bitmap.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
17 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/test/progress/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.test.progress;
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.test.progress", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/MyProgress/src/androidTest/java/com/github/progress/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.progress;
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.github.progress.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
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 |
--------------------------------------------------------------------------------
/MyProgress/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
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 |
--------------------------------------------------------------------------------
/MyProgress/src/test/java/com/github/progress/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.progress;
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 | @Test
18 | public void sdf() throws Exception {
19 | float a=50;
20 | int b=30;
21 | int c=130;
22 | System.out.println(b*a/c);
23 | }
24 | @Test
25 | public void d() throws Exception {
26 | System.out.println(0%360);
27 | System.out.println(1%360);
28 | System.out.println(360%360);
29 | System.out.println(367%360);
30 | }
31 | @Test
32 | public void dd() throws Exception {
33 | float a=0.9f;
34 | int b= (int) a;
35 | int c= (int) 1.2f;
36 | int d= (int) 1.5f;
37 | System.out.println(b);
38 | System.out.println(c);
39 | System.out.println(d);
40 | }
41 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.test.progress"
7 | minSdkVersion 19
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 |
20 | repositories {
21 | flatDir {
22 | dirs 'libs'
23 | }
24 | }
25 | packagingOptions {
26 | // exclude 'META-INF/proguard/androidx-annotations.pro'
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
32 |
33 | implementation 'androidx.appcompat:appcompat:1.0.0'
34 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
35 | testImplementation 'junit:junit:4.12'
36 | implementation project(':MyProgress')
37 | implementation(name: 'SelectColorDialog-debug', ext: 'aar')
38 | api "com.github.skydoves:colorpickerview:2.0.2"
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/test/progress/TestBitmapActivity.java:
--------------------------------------------------------------------------------
1 | package com.test.progress;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.BitmapShader;
6 | import android.graphics.Shader;
7 | import android.os.Bundle;
8 |
9 | import com.github.progress.MyProgress;
10 |
11 | import androidx.appcompat.app.AppCompatActivity;
12 |
13 | public class TestBitmapActivity extends AppCompatActivity {
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_test_bitmap);
19 |
20 | MyProgress myProgress=findViewById(R.id.myProgress);
21 |
22 |
23 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.simple_bitmap);
24 | Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight() - 11);
25 | Shader shader=new BitmapShader(newBitmap,Shader.TileMode.REPEAT,Shader.TileMode.REPEAT);
26 | myProgress.setProgressShader(shader);
27 |
28 |
29 | Bitmap bitmapBG = BitmapFactory.decodeResource(getResources(), R.drawable.gray_progress);
30 | Bitmap newBitmapBG = Bitmap.createBitmap(bitmapBG, 0, 0, bitmapBG.getWidth(), bitmapBG.getHeight() - 9);
31 | Shader shaderBG=new BitmapShader(newBitmapBG,Shader.TileMode.REPEAT,Shader.TileMode.REPEAT);
32 | myProgress.setBgShader(shaderBG);
33 |
34 | myProgress.setMaxProgress(200).setNowProgress(100).setRadius(80).complete();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/MyProgress/src/main/res/values/progress_attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #18B4ED
4 | #18B4ED
5 | #18B4ED
6 | #87ceeb
7 |
8 | #4ed3fd
9 |
10 |
11 | #3a92e9
12 | #419BF3
13 | #f6f6f6
14 | #000000
15 | #333333
16 | #444444
17 | #666666
18 | #999999
19 | #eaeaea
20 | #d7d7d7
21 | #f2f2f2
22 | #616161
23 | #f2f2f2
24 | #FFF1EFEF
25 | #d4d4d4
26 | #DDDDDD
27 | #2DDB97
28 | #FF20D18C
29 | #34e8a6
30 | #22ddb0
31 | #E6F9F7
32 | #50000000
33 |
34 |
35 | #06C1AE
36 | #419BF3
37 | #FFC820
38 | #eaa304
39 | #4ed3fd
40 | #fc353a
41 | #FFE4E0E0
42 | #E2419BF3
43 | #333333
44 | #2ACBE0
45 | #ff712b
46 | #FFF2EB
47 | #419BF3
48 | #FFC8C8C8
49 |
50 |
51 | #848484
52 | #848484
53 | #56abe4
54 | #70000000
55 | #BF58C2F7
56 | #ffffff
57 | #86FFFFFF
58 | #616161
59 | #000000
60 | #00000000
61 | #70000000
62 | #90000000
63 | #a0000000
64 | #b0000000
65 | #e5e5e5
66 | #B2B2B2
67 | #C0C5CA
68 | #BEC2C7
69 | #B2B2B2
70 | #DFE4EA
71 | #cccccc
72 | #E2E2E2
73 | #E2E2E2
74 | #41A5D6
75 | #18B4ED
76 |
77 | #20000000
78 | #FFCECBCB
79 |
80 | #dfdfdf
81 | #c2c1c1
82 | #f2f2f2
83 | #D1D1D1
84 |
85 | #66000000
86 |
87 |
88 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Progress
2 | 
3 |
4 |
5 | | 属性 | 类型 | 说明 |
6 | |----------------|-----------|-----------------------------------------------------------------------|
7 | | viewWidth | dimension | 进度条宽度(不设置则默认为layout_width) |
8 | | viewHeight | dimension | 进度条高度(不设置则默认为layout_height) |
9 | | bgColor | color | 进度条背景颜色 |
10 | | borderColor | color | 进度条边框颜色 |
11 | | borderWidth | dimension | 进度条边框宽度 |
12 | | progressColor | color | 进度条颜色 |
13 | | nowProgress | float | 进度条当前进度(默认为30) |
14 | | maxProgress | float | 进度条最大值(默认为100) |
15 | | angle | integer | 进度条旋转角度 |
16 | | radius | dimension | 进度条圆角大小(默认为viewHeight的一半,最大值不会超过viewHeight的一半) |
17 | | useAnimation | boolean | 是否使用动画(默认为true) |
18 | | duration | integer | 动画执行时间(默认为1200毫秒) |
19 | | allInterval | dimension | 进度条与边框的距离 |
20 | | leftInterval | dimension | 进度条与左边框的距离 |
21 | | topInterval | dimension | 进度条与顶部边框的距离 |
22 | | rightInterval | dimension | 进度条与右边框的距离 |
23 | | bottomInterval | dimension | 进度条与底部边框的距离 |
24 |
25 |
26 |
27 |
28 | ```xml
29 |
38 | ```
39 |
40 | #### 设置进度条颜色渐变
41 | ```java
42 | //进度条边框颜色渐变
43 | Shader borderShader;
44 | //进度条背景颜色渐变
45 | Shader bgShader;
46 | //进度条颜色渐变
47 | Shader progressShader;
48 | //进度条动画插入器,建议在setProgress方法之前设置(默认为DecelerateInterpolator)
49 | TimeInterpolator interpolator
50 |
51 | //为进度条设置线性颜色渐变,起始坐标为view左上角,结束坐标为view右下角(注意view圆点坐标在view中心)
52 | LinearGradient linearGradient = new LinearGradient(
53 | -myProgress.getViewWidth() / 2,
54 | -myProgress.getViewHeight() / 2,
55 | myProgress.getViewWidth() / 2,
56 | myProgress.getViewHeight() / 2,
57 | ContextCompat.getColor(MainActivity.this, R.color.green),
58 | ContextCompat.getColor(MainActivity.this, R.color.blue),
59 | Shader.TileMode.MIRROR);
60 |
61 | myProgress.setNowProgress(30).setMaxProgress(100).setProgressShader(linearGradient).complete();
62 | ```
63 | ### 注意:代码设置属性之后调用complete()才能生效
64 | #### 进度监听
65 | ```java
66 | MyProgress myProgress = (MyProgress) findViewById(R.id.myProgress);
67 | myProgress.setOnProgressInter(new MyProgress.OnProgressInter() {
68 | @Override
69 | public void progress(float scaleProgress, float progress, float max) {
70 | //scaleProgress:动画执行时的进度
71 | //progress:设置的进度
72 | //max:进度条最大值
73 | }
74 | });
75 | ```
76 |
77 |
78 |
79 | ### 如果本库对您有帮助,还希望支付宝扫一扫下面二维码,你我同时免费获取奖励金(非常感谢 Y(^-^)Y)
80 | 
81 |
82 |
83 | | 最新版本号 | [  ](https://bintray.com/zhongrui/mylibrary/MyProgress/_latestVersion) |
84 | |--------|----|
85 |
86 |
87 | ```gradle
88 | compile 'com.github:MyProgress:版本号看上面'
89 | ```
90 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/test/progress/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.test.progress;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.LinearGradient;
6 | import android.graphics.Shader;
7 | import android.os.Bundle;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import androidx.appcompat.widget.AppCompatCheckBox;
12 | import androidx.core.content.ContextCompat;
13 | import android.view.View;
14 | import android.view.View.OnClickListener;
15 | import android.widget.Button;
16 | import android.widget.CheckBox;
17 | import android.widget.CompoundButton;
18 | import android.widget.SeekBar;
19 | import android.widget.TextView;
20 |
21 | import com.github.progress.MyProgress;
22 | import com.github.selectcolordialog.SelectColorDialog;
23 | import com.github.selectcolordialog.SelectColorListener;
24 |
25 | public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener, OnClickListener, CompoundButton.OnCheckedChangeListener {
26 | MyProgress mp;
27 | SeekBar sb_angle;
28 | SeekBar sb_round;
29 | SeekBar sb_left;
30 | SeekBar sb_top;
31 | SeekBar sb_right;
32 | SeekBar sb_bottom;
33 | Context context;
34 |
35 | Button btLookBitmapProgress;
36 |
37 | private SeekBar sbProgress;
38 | private SeekBar sbProgressSecond;
39 | private SeekBar sbBorderWidth;
40 | private TextView tvBgColor;
41 | private TextView tvBorderColor;
42 | private TextView tvProgressColor;
43 | private CheckBox cbShowAnim;
44 | private SelectColorDialog selectColorDialog;
45 |
46 |
47 | private AppCompatCheckBox cbTopLeftNoRadius;
48 | private AppCompatCheckBox cbTopRightNoRadius;
49 | private AppCompatCheckBox cbBottomRightNoRadius;
50 | private AppCompatCheckBox cbBottomLeftNoRadius;
51 |
52 | private AppCompatCheckBox cbTopLeftNoRadius2;
53 | private AppCompatCheckBox cbTopRightNoRadius2;
54 | private AppCompatCheckBox cbBottomRightNoRadius2;
55 | private AppCompatCheckBox cbBottomLeftNoRadius2;
56 |
57 | @Override
58 | protected void onCreate(Bundle savedInstanceState) {
59 | super.onCreate(savedInstanceState);
60 | setContentView(R.layout.activity_main);
61 | context = this;
62 | initView();
63 |
64 | btLookBitmapProgress = findViewById(R.id.btLookBitmapProgress);
65 | btLookBitmapProgress.setOnClickListener(new OnClickListener() {
66 | @Override
67 | public void onClick(View v) {
68 | startActivity(new Intent(MainActivity.this, TestBitmapActivity.class));
69 | }
70 | });
71 | sb_angle = (SeekBar) findViewById(R.id.sb_angle);
72 | sb_round = (SeekBar) findViewById(R.id.sb_round);
73 | sb_left = (SeekBar) findViewById(R.id.sb_left);
74 | sb_top = (SeekBar) findViewById(R.id.sb_top);
75 | sb_right = (SeekBar) findViewById(R.id.sb_right);
76 | sb_bottom = (SeekBar) findViewById(R.id.sb_bottom);
77 |
78 | mp = (MyProgress) findViewById(R.id.mp);
79 | mp.setUseAnimation(cbShowAnim.isClickable());
80 | LinearGradient linearGradient = new LinearGradient(-mp.getViewWidth() / 2, -mp.getViewHeight() / 2, mp.getViewWidth() / 2, mp.getViewHeight() / 2,
81 | ContextCompat.getColor(MainActivity.this, R.color.green),
82 | ContextCompat.getColor(MainActivity.this, R.color.blue),
83 | Shader.TileMode.MIRROR);
84 | mp.setNowProgress(sbProgress.getProgress()).setNowProgressSecond(sbProgressSecond.getProgress()).setMaxProgress(100).setProgressShader(linearGradient).setRadius(mp.getViewHeight() / 2).complete();
85 | mp.setBgColor(ContextCompat.getColor(context, R.color.white));
86 | mp.setOnProgressInter(new MyProgress.OnProgressInter() {
87 | @Override
88 | public void progress(float animProgress, float progress, float max) {
89 | // Log.i("======", animProgress + "==" + progress + "===" + max);
90 | }
91 | });
92 | mp.setOnProgressInterSecond(new MyProgress.OnProgressInter() {
93 | @Override
94 | public void progress(float animProgress, float progress, float max) {
95 |
96 | }
97 | });
98 |
99 | sb_round.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
100 | @Override
101 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
102 |
103 | mp.setRadius(mp.getViewHeight() / 2 * progress / 100).complete();
104 | }
105 |
106 | @Override
107 | public void onStartTrackingTouch(SeekBar seekBar) {
108 |
109 | }
110 |
111 | @Override
112 | public void onStopTrackingTouch(SeekBar seekBar) {
113 |
114 | }
115 | });
116 |
117 |
118 | sb_angle.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
119 | @Override
120 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
121 | mp.setAngle(progress * 360 / 100).complete();
122 | }
123 |
124 | @Override
125 | public void onStartTrackingTouch(SeekBar seekBar) {
126 | }
127 |
128 | @Override
129 | public void onStopTrackingTouch(SeekBar seekBar) {
130 | }
131 | });
132 |
133 | sb_left.setOnSeekBarChangeListener(getL(0));
134 | sb_top.setOnSeekBarChangeListener(getL(1));
135 | sb_right.setOnSeekBarChangeListener(getL(2));
136 | sb_bottom.setOnSeekBarChangeListener(getL(3));
137 |
138 | }
139 |
140 | @NonNull
141 | private SeekBar.OnSeekBarChangeListener getL(final int flag) {
142 | return new SeekBar.OnSeekBarChangeListener() {
143 | @Override
144 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
145 | switch (flag) {
146 | case 0:
147 | mp.setLeftInterval(progress * dip2px(context, 10) / 100).complete();
148 | break;
149 | case 1:
150 | mp.setTopInterval(progress * dip2px(context, 10) / 100).complete();
151 | break;
152 | case 2:
153 | mp.setRightInterval(progress * dip2px(context, 10) / 100).complete();
154 | break;
155 | case 3:
156 | mp.setBottomInterval(progress * dip2px(context, 10) / 100).complete();
157 | break;
158 | }
159 | }
160 |
161 | @Override
162 | public void onStartTrackingTouch(SeekBar seekBar) {
163 | }
164 |
165 | @Override
166 | public void onStopTrackingTouch(SeekBar seekBar) {
167 | }
168 | };
169 | }
170 |
171 | public int dip2px(Context context, float dipValue) {
172 | float scale = context.getResources().getDisplayMetrics().density;
173 | return (int) (dipValue * scale + 0.5F);
174 | }
175 |
176 | private void initView() {
177 | sbProgress = (SeekBar) findViewById(R.id.sbProgress);
178 | sbProgress.setOnSeekBarChangeListener(this);
179 |
180 | sbProgressSecond = (SeekBar) findViewById(R.id.sbProgressSecond);
181 | sbProgressSecond.setOnSeekBarChangeListener(this);
182 |
183 |
184 | cbShowAnim = findViewById(R.id.cbShowAnim);
185 | cbShowAnim.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
186 | @Override
187 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
188 | mp.setUseAnimation(isChecked);
189 | }
190 | });
191 |
192 | sbBorderWidth = (SeekBar) findViewById(R.id.sbBorderWidth);
193 | sbBorderWidth.setOnSeekBarChangeListener(this);
194 |
195 | tvBgColor = findViewById(R.id.tvBgColor);
196 | tvBgColor.setOnClickListener(this);
197 |
198 | tvBorderColor = findViewById(R.id.tvBorderColor);
199 | tvBorderColor.setOnClickListener(this);
200 |
201 | tvProgressColor = findViewById(R.id.tvProgressColor);
202 | tvProgressColor.setOnClickListener(this);
203 |
204 | cbTopLeftNoRadius = findViewById(R.id.cbTopLeftNoRadius);
205 | cbTopLeftNoRadius.setOnCheckedChangeListener(this);
206 |
207 | cbTopRightNoRadius = findViewById(R.id.cbTopRightNoRadius);
208 | cbTopRightNoRadius.setOnCheckedChangeListener(this);
209 |
210 | cbBottomRightNoRadius = findViewById(R.id.cbBottomRightNoRadius);
211 | cbBottomRightNoRadius.setOnCheckedChangeListener(this);
212 |
213 | cbBottomLeftNoRadius = findViewById(R.id.cbBottomLeftNoRadius);
214 | cbBottomLeftNoRadius.setOnCheckedChangeListener(this);
215 |
216 |
217 |
218 | cbTopLeftNoRadius2 = findViewById(R.id.cbTopLeftNoRadius2);
219 | cbTopLeftNoRadius2.setOnCheckedChangeListener(this);
220 |
221 | cbTopRightNoRadius2 = findViewById(R.id.cbTopRightNoRadius2);
222 | cbTopRightNoRadius2.setOnCheckedChangeListener(this);
223 |
224 | cbBottomRightNoRadius2 = findViewById(R.id.cbBottomRightNoRadius2);
225 | cbBottomRightNoRadius2.setOnCheckedChangeListener(this);
226 |
227 | cbBottomLeftNoRadius2 = findViewById(R.id.cbBottomLeftNoRadius2);
228 | cbBottomLeftNoRadius2.setOnCheckedChangeListener(this);
229 |
230 | }
231 |
232 | @Override
233 | public void onClick(View v) {
234 | switch (v.getId()) {
235 | case R.id.tvProgressColor:
236 | selectColorDialog = new SelectColorDialog(this);
237 | selectColorDialog.setListener(new SelectColorListener() {
238 | @Override
239 | public void selectColor(int color) {
240 | mp.setProgressColor(color).complete();
241 | tvProgressColor.setBackgroundColor(color);
242 | }
243 | });
244 | selectColorDialog.show();
245 | break;
246 | case R.id.tvBgColor:
247 | selectColorDialog = new SelectColorDialog(this);
248 | selectColorDialog.setListener(new SelectColorListener() {
249 | @Override
250 | public void selectColor(int color) {
251 | mp.setBgColor(color).complete();
252 | tvBgColor.setBackgroundColor(color);
253 | }
254 | });
255 | selectColorDialog.show();
256 | break;
257 | case R.id.tvBorderColor:
258 | selectColorDialog = new SelectColorDialog(this);
259 | selectColorDialog.setListener(new SelectColorListener() {
260 | @Override
261 | public void selectColor(int color) {
262 | mp.setBorderColor(color).complete();
263 | tvBorderColor.setBackgroundColor(color);
264 | }
265 | });
266 | selectColorDialog.show();
267 | break;
268 | }
269 | }
270 |
271 | @Override
272 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
273 | switch (seekBar.getId()) {
274 | case R.id.sbProgress:
275 | mp.setNowProgress(progress).complete();
276 | break;
277 | case R.id.sbProgressSecond:
278 | mp.setNowProgressSecond(progress).complete();
279 | break;
280 | case R.id.sbBorderWidth:
281 | mp.setBorderWidth(progress / 3).complete();
282 | break;
283 | }
284 | }
285 |
286 | @Override
287 | public void onStartTrackingTouch(SeekBar seekBar) {
288 |
289 | }
290 |
291 | @Override
292 | public void onStopTrackingTouch(SeekBar seekBar) {
293 |
294 | }
295 |
296 | @Override
297 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
298 | switch (buttonView.getId()){
299 | case R.id.cbTopLeftNoRadius:
300 | mp.setNoTopLeftRadius(isChecked).complete();
301 | break;
302 | case R.id.cbTopRightNoRadius:
303 | mp.setNoTopRightRadius(isChecked).complete();
304 | break;
305 | case R.id.cbBottomRightNoRadius:
306 | mp.setNoBottomRightRadius(isChecked).complete();
307 | break;
308 | case R.id.cbBottomLeftNoRadius:
309 | mp.setNoBottomLeftRadius(isChecked).complete();
310 | break;
311 | case R.id.cbTopLeftNoRadius2:
312 | mp.setNoTopLeftRadiusSecond(isChecked).complete();
313 | break;
314 | case R.id.cbTopRightNoRadius2:
315 | mp.setNoTopRightRadiusSecond(isChecked).complete();
316 | break;
317 | case R.id.cbBottomRightNoRadius2:
318 | mp.setNoBottomRightRadiusSecond(isChecked).complete();
319 | break;
320 | case R.id.cbBottomLeftNoRadius2:
321 | mp.setNoBottomLeftRadiusSecond(isChecked).complete();
322 | break;
323 | }
324 | }
325 | }
326 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
26 |
27 |
31 |
32 |
37 |
38 |
45 |
46 |
54 |
55 |
63 |
64 |
72 |
79 |
80 |
81 |
87 |
88 |
92 |
93 |
99 |
100 |
106 |
107 |
113 |
119 |
120 |
126 |
127 |
132 |
133 |
139 |
140 |
141 |
147 |
148 |
153 |
154 |
160 |
161 |
162 |
168 |
169 |
174 |
175 |
181 |
182 |
183 |
189 |
190 |
195 |
196 |
202 |
203 |
204 |
210 |
211 |
216 |
217 |
223 |
224 |
225 |
231 |
232 |
237 |
238 |
244 |
245 |
246 |
252 |
253 |
258 |
259 |
265 |
266 |
267 |
273 |
279 |
286 |
293 |
300 |
307 |
308 |
314 |
320 |
327 |
334 |
341 |
348 |
349 |
355 |
356 |
357 |
358 |
359 |
--------------------------------------------------------------------------------
/MyProgress/src/main/java/com/github/progress/MyProgress.java:
--------------------------------------------------------------------------------
1 | package com.github.progress;
2 |
3 | import android.animation.TimeInterpolator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Paint;
10 | import android.graphics.Path;
11 | import android.graphics.PorterDuff;
12 | import android.graphics.PorterDuffXfermode;
13 | import android.graphics.RectF;
14 | import android.graphics.Shader;
15 | import android.os.Build;
16 | import android.util.AttributeSet;
17 | import android.view.View;
18 | import android.view.animation.DecelerateInterpolator;
19 |
20 | import androidx.annotation.ColorInt;
21 | import androidx.annotation.Nullable;
22 | import androidx.annotation.RequiresApi;
23 |
24 |
25 | /**
26 | * Created by Administrator on 2018/6/21.
27 | */
28 |
29 | public class MyProgress extends View {
30 | private OnProgressInter onProgressInter;
31 | private OnProgressInter onProgressInterSecond;
32 | private RectF borderRectF;
33 | private RectF progressRectF;
34 | private ValueAnimator valueAnimator;
35 | private ValueAnimator valueAnimatorSecond;
36 |
37 | public interface OnProgressInter {
38 | void progress(float animProgress, float progress, float maxProgress);
39 | }
40 |
41 | public OnProgressInter getOnProgressInter() {
42 | return onProgressInter;
43 | }
44 |
45 | public void setOnProgressInter(OnProgressInter onProgressInter) {
46 | this.onProgressInter = onProgressInter;
47 | }
48 |
49 | public OnProgressInter getOnProgressInterSecond() {
50 | return onProgressInterSecond;
51 | }
52 |
53 | public void setOnProgressInterSecond(OnProgressInter onProgressInterSecond) {
54 | this.onProgressInterSecond = onProgressInterSecond;
55 | }
56 |
57 | private void setProgressToInter(float scaleProgress, float progress, float max) {
58 | if (onProgressInter != null) {
59 | onProgressInter.progress(scaleProgress, progress, max);
60 | }
61 | }
62 |
63 | private void setProgressToInterSecond(float scaleProgress, float progress, float max) {
64 | if (onProgressInterSecond != null) {
65 | onProgressInterSecond.progress(scaleProgress, progress, max);
66 | }
67 | }
68 |
69 | private float viewWidth;
70 | private float viewHeight;
71 | private float radius;
72 | private int bgColor;
73 | private int borderColor;
74 | private float borderWidth = 4;
75 | private int progressColor;
76 | private int progressColorSecond;
77 | private int allInterval = 0;
78 | private int leftInterval;
79 | private int topInterval;
80 | private int rightInterval;
81 | private int bottomInterval;
82 | private boolean useAnimation = true;
83 | private float nowProgress = 0;
84 | //用于动画计算
85 | private float scaleProgress = nowProgress;
86 |
87 | private float nowProgressSecond = 0;
88 | //用于动画计算
89 | private float scaleProgressSecond = nowProgressSecond;
90 |
91 |
92 | private float maxProgress = 100;
93 | private int angle = 0;
94 | private int rotateAngle = 0;
95 | private int duration = 1200;
96 |
97 |
98 | private boolean noTopLeftRadius;
99 | private boolean noTopRightRadius;
100 | private boolean noBottomLeftRadius;
101 | private boolean noBottomRightRadius;
102 |
103 |
104 | private boolean noTopLeftRadiusSecond;
105 | private boolean noTopRightRadiusSecond;
106 | private boolean noBottomLeftRadiusSecond;
107 | private boolean noBottomRightRadiusSecond;
108 |
109 |
110 | private Shader borderShader;
111 | private Shader bgShader;
112 | private Shader progressShader;
113 | private Shader progressShaderSecond;
114 |
115 |
116 | private final String def_borderColor = "#239936";
117 | private final String def_bgColor = "#00000000";
118 | private final String def_progressColor = def_borderColor;
119 |
120 | private TimeInterpolator interpolator = new DecelerateInterpolator();
121 |
122 | private Paint helperPaint;
123 | /*progress*/
124 | private Paint progressPaint;
125 | private Path progressPath;
126 |
127 |
128 | /*progressSecond*/
129 | private Paint progressPaintSecond;
130 | private Path progressPathSecond;
131 |
132 |
133 | /*bg*/
134 | private Paint bgPaint;
135 | private Path bgPath;
136 |
137 | /*border*/
138 | private Paint borderPaint;
139 | private Path borderPath;
140 |
141 | public MyProgress(Context context) {
142 | super(context);
143 | init(null);
144 | }
145 |
146 | public MyProgress(Context context, @Nullable AttributeSet attrs) {
147 | super(context, attrs);
148 | init(attrs);
149 | }
150 |
151 | public MyProgress(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
152 | super(context, attrs, defStyleAttr);
153 | init(attrs);
154 | }
155 |
156 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
157 | public MyProgress(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
158 | super(context, attrs, defStyleAttr, defStyleRes);
159 | init(attrs);
160 | }
161 |
162 | private void init(AttributeSet attrs) {
163 | bgColor = Color.parseColor(def_bgColor);
164 | borderColor = Color.parseColor(def_borderColor);
165 | progressColor = Color.parseColor(def_progressColor);
166 |
167 | if (attrs == null) {
168 | return;
169 | }
170 |
171 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.MyProgress);
172 |
173 | viewWidth = typedArray.getDimension(R.styleable.MyProgress_viewWidth, 0);
174 | viewHeight = typedArray.getDimension(R.styleable.MyProgress_viewHeight, 0);
175 | bgColor = typedArray.getColor(R.styleable.MyProgress_bgColor, Color.parseColor(def_bgColor));
176 | borderColor = typedArray.getColor(R.styleable.MyProgress_borderColor, Color.parseColor(def_borderColor));
177 | borderWidth = typedArray.getDimension(R.styleable.MyProgress_borderWidth, 4);
178 | progressColor = typedArray.getColor(R.styleable.MyProgress_progressColor, borderColor);
179 | allInterval = (int) typedArray.getDimension(R.styleable.MyProgress_allInterval, 0);
180 | leftInterval = (int) typedArray.getDimension(R.styleable.MyProgress_leftInterval, 0);
181 | topInterval = (int) typedArray.getDimension(R.styleable.MyProgress_topInterval, 0);
182 | rightInterval = (int) typedArray.getDimension(R.styleable.MyProgress_rightInterval, 0);
183 | bottomInterval = (int) typedArray.getDimension(R.styleable.MyProgress_bottomInterval, 0);
184 | useAnimation = typedArray.getBoolean(R.styleable.MyProgress_useAnimation, true);
185 | radius = typedArray.getDimension(R.styleable.MyProgress_radius, 0);
186 | maxProgress = typedArray.getFloat(R.styleable.MyProgress_maxProgress, 100);
187 | nowProgress = typedArray.getFloat(R.styleable.MyProgress_nowProgress, 0);
188 | angle = typedArray.getInt(R.styleable.MyProgress_angle, 0);
189 | setAngle(angle);
190 | duration = typedArray.getInt(R.styleable.MyProgress_duration, 1200);
191 |
192 | noTopLeftRadius = typedArray.getBoolean(R.styleable.MyProgress_noTopLeftRadius, false);
193 | noTopRightRadius = typedArray.getBoolean(R.styleable.MyProgress_noTopRightRadius, false);
194 | noBottomLeftRadius = typedArray.getBoolean(R.styleable.MyProgress_noBottomLeftRadius, false);
195 | noBottomRightRadius = typedArray.getBoolean(R.styleable.MyProgress_noBottomRightRadius, false);
196 |
197 | nowProgressSecond = typedArray.getDimension(R.styleable.MyProgress_nowProgressSecond, 0);
198 | progressColorSecond = typedArray.getColor(R.styleable.MyProgress_progressColorSecond, Color.parseColor("#4ed3fd"));
199 |
200 |
201 | noTopLeftRadiusSecond = typedArray.getBoolean(R.styleable.MyProgress_noTopLeftRadiusSecond, false);
202 | noTopRightRadiusSecond = typedArray.getBoolean(R.styleable.MyProgress_noTopRightRadiusSecond, false);
203 | noBottomLeftRadiusSecond = typedArray.getBoolean(R.styleable.MyProgress_noBottomLeftRadiusSecond, false);
204 | noBottomRightRadiusSecond = typedArray.getBoolean(R.styleable.MyProgress_noBottomRightRadiusSecond, false);
205 |
206 | if (maxProgress <= 0) {
207 | this.maxProgress = 0;
208 | }
209 | if (nowProgress > maxProgress) {
210 | this.nowProgress = maxProgress;
211 | } else if (nowProgress < 0) {
212 | this.nowProgress = 0;
213 | }
214 |
215 | scaleProgress = nowProgress;
216 | typedArray.recycle();
217 |
218 |
219 | initPaint();
220 |
221 |
222 | initPath();
223 |
224 |
225 | }
226 |
227 | private void initPath() {
228 | progressPath = new Path();
229 | progressPathSecond = new Path();
230 | borderPath = new Path();
231 | bgPath = new Path();
232 | }
233 |
234 | private boolean isHorizontal(int angle) {
235 | if (angle % 180 == 0) {
236 | return true;
237 | } else {
238 | return false;
239 | }
240 | }
241 |
242 | private boolean isVertical(int angle) {
243 | if (isHorizontal(angle)) {
244 | return false;
245 | } else {
246 | if (angle % 90 == 0) {
247 | return true;
248 | } else {
249 | return false;
250 | }
251 | }
252 | }
253 |
254 | @Override
255 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
256 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
257 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
258 |
259 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
260 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
261 |
262 |
263 | int mWidth = 400;
264 | int mHeight = 30;
265 | if (viewWidth + 0 > mWidth) {
266 | mWidth = (int) (viewWidth + 0);
267 | }
268 | if (viewHeight + 0 > mHeight) {
269 | mHeight = (int) (viewHeight + 0);
270 | }
271 | setMeasuredDimension(
272 | widthMode == MeasureSpec.EXACTLY ? widthSize : Math.min(mWidth, widthSize),
273 | heightMode == MeasureSpec.EXACTLY ? heightSize : Math.min(mHeight, heightSize));
274 | }
275 |
276 |
277 | private void updateBGPath() {
278 | if (bgPath != null) {
279 | bgPath.reset();
280 | }
281 | bgPath.addRoundRect(getBorderRectF(), getRectFRadius(true), Path.Direction.CW);
282 | }
283 |
284 | private void initPaint() {
285 | borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
286 | borderPaint.setStyle(Paint.Style.STROKE);
287 | borderPaint.setColor(borderColor);
288 | borderPaint.setStrokeWidth(borderWidth * 2f);
289 |
290 | bgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
291 | bgPaint.setStyle(Paint.Style.FILL);
292 | bgPaint.setColor(bgColor);
293 |
294 |
295 | progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
296 | progressPaint.setStyle(Paint.Style.FILL);
297 | progressPaint.setColor(progressColor);
298 |
299 | progressPaintSecond = new Paint(Paint.ANTI_ALIAS_FLAG);
300 | progressPaintSecond.setStyle(Paint.Style.FILL);
301 | progressPaintSecond.setColor(progressColorSecond);
302 |
303 |
304 | helperPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
305 | helperPaint.setStyle(Paint.Style.FILL);
306 | helperPaint.setColor(Color.WHITE);
307 | }
308 |
309 | @Override
310 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
311 | if (viewWidth == 0 && viewHeight == 0) {
312 | if (isHorizontal(angle)) {
313 | viewWidth = getWidth();
314 | viewHeight = getHeight();
315 | } else if (isVertical(angle)) {
316 | viewWidth = getHeight();
317 | viewHeight = getWidth();
318 | } else {
319 | viewWidth = 300;
320 | viewHeight = 20;
321 | }
322 | } else if (viewHeight == 0) {
323 | viewHeight = getHeight();
324 | } else if (viewWidth == 0) {
325 | viewWidth = getWidth();
326 | }
327 |
328 |
329 | updateBGPath();
330 | updateBorderPath();
331 | updateProgressPath();
332 | updateProgressPathSecond();
333 | }
334 |
335 |
336 | private void updateProgressPath() {
337 | progressPath.reset();
338 | progressPath.addRoundRect(getProgressRectF(scaleProgress), getRectFRadius(false), Path.Direction.CW);
339 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
340 | progressPath.op(bgPath, Path.Op.INTERSECT);
341 | }
342 | }
343 |
344 | private void updateProgressPathSecond() {
345 | progressPathSecond.reset();
346 | progressPathSecond.addRoundRect(getProgressRectF(scaleProgressSecond), getRectFRadiusSecond(false), Path.Direction.CW);
347 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
348 | progressPathSecond.op(bgPath, Path.Op.INTERSECT);
349 | }
350 | }
351 |
352 | private void updateBorderPath() {
353 | borderPath.reset();
354 | borderPath.addRoundRect(getBorderRectF(), getRectFRadius(true), Path.Direction.CW);
355 | }
356 |
357 | @Override
358 | protected void onDraw(Canvas canvas) {
359 |
360 | canvas.translate(getWidth() / 2f, getHeight() / 2f);
361 | if (rotateAngle > 0) {
362 | canvas.rotate(rotateAngle);
363 | }
364 |
365 | if (borderWidth > 0) {
366 | int count = canvas.saveLayer(-viewWidth / 2f, -viewHeight / 2f, viewWidth / 2f, viewHeight / 2f, null, Canvas.ALL_SAVE_FLAG);
367 | canvas.drawPath(borderPath, borderPaint);
368 |
369 | bgPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
370 | canvas.drawPath(bgPath, bgPaint);
371 | bgPaint.setXfermode(null);
372 | canvas.restoreToCount(count);
373 | } else {
374 | canvas.drawPath(bgPath, bgPaint);
375 | }
376 | canvas.drawPath(progressPathSecond, progressPaintSecond);
377 |
378 | canvas.drawPath(progressPath, progressPaint);
379 |
380 |
381 | }
382 |
383 |
384 | private float getScaleAngle() {
385 | return angle % 360;
386 | }
387 |
388 | private RectF getBorderRectF() {
389 | if (borderRectF == null) {
390 | borderRectF = new RectF(-viewWidth / 2f + borderWidth, -viewHeight / 2f + borderWidth, viewWidth / 2f - borderWidth, viewHeight / 2f - borderWidth);
391 | } else {
392 | borderRectF.set(-viewWidth / 2f + borderWidth, -viewHeight / 2f + borderWidth, viewWidth / 2f - borderWidth, viewHeight / 2f - borderWidth);
393 | }
394 | return borderRectF;
395 | }
396 |
397 |
398 | private RectF getProgressRectF(float scaleProgress) {
399 | float leftOffset = leftInterval;
400 | float topOffset = topInterval;
401 | float rightOffset = rightInterval;
402 | float bottomOffset = bottomInterval;
403 | if (allInterval > 0) {
404 | leftOffset = allInterval;
405 | topOffset = allInterval;
406 | rightOffset = allInterval;
407 | bottomOffset = allInterval;
408 | }
409 | float progressWidth = viewWidth - leftOffset - rightOffset - getBorderWidth() * 2f;
410 |
411 | float tempBorderW = borderWidth;
412 | if (maxProgress <= 0) {
413 | if (progressRectF == null) {
414 | progressRectF = new RectF(
415 | -viewWidth / 2f + leftOffset + tempBorderW,
416 | -viewHeight / 2f + topOffset + tempBorderW,
417 | viewWidth / 2f - leftOffset - tempBorderW,
418 | viewHeight / 2f - bottomOffset - tempBorderW);
419 | } else {
420 | progressRectF.set(
421 | -viewWidth / 2f + leftOffset + tempBorderW,
422 | -viewHeight / 2f + topOffset + tempBorderW,
423 | viewWidth / 2f - leftOffset - tempBorderW,
424 | viewHeight / 2f - bottomOffset - tempBorderW);
425 | }
426 | } else {
427 | if (progressRectF == null) {
428 | progressRectF = new RectF(
429 | -viewWidth / 2f + leftOffset + tempBorderW,
430 | -viewHeight / 2f + topOffset + tempBorderW,
431 | (progressWidth * scaleProgress / maxProgress - viewWidth / 2f + leftOffset) + tempBorderW,
432 | viewHeight / 2f - bottomOffset - tempBorderW);
433 | } else {
434 |
435 | progressRectF.set(
436 | -viewWidth / 2f + leftOffset + tempBorderW,
437 | -viewHeight / 2f + topOffset + tempBorderW,
438 | (progressWidth * scaleProgress / maxProgress - viewWidth / 2f + leftOffset) + tempBorderW,
439 | viewHeight / 2f - bottomOffset - tempBorderW);
440 | }
441 | }
442 | return progressRectF;
443 | }
444 |
445 | private float[] getRectFRadius(boolean isBGRadius) {
446 | if (isBGRadius) {
447 | return new float[]{getRadius(), getRadius(), getRadius(), getRadius(), getRadius(), getRadius(), getRadius(), getRadius()};
448 | }
449 | float scale = getProgressRectF(scaleProgress).height() * 1f / getBorderRectF().height();
450 | float tempRadius = getRadius() * scale;
451 | return new float[]{
452 | noTopLeftRadius ? 0 : tempRadius, noTopLeftRadius ? 0 : tempRadius,
453 | noTopRightRadius ? 0 : tempRadius, noTopRightRadius ? 0 : tempRadius,
454 | noBottomRightRadius ? 0 : tempRadius, noBottomRightRadius ? 0 : tempRadius,
455 | noBottomLeftRadius ? 0 : tempRadius, noBottomLeftRadius ? 0 : tempRadius
456 | };
457 | }
458 |
459 | private float[] getRectFRadiusSecond(boolean isBGRadius) {
460 | if (isBGRadius) {
461 | return new float[]{getRadius(), getRadius(), getRadius(), getRadius(), getRadius(), getRadius(), getRadius(), getRadius()};
462 | }
463 | float scale = getProgressRectF(scaleProgressSecond).height() * 1f / getBorderRectF().height();
464 | float tempRadius = getRadius() * scale;
465 | return new float[]{
466 | noTopLeftRadiusSecond ? 0 : tempRadius, noTopLeftRadiusSecond ? 0 : tempRadius,
467 | noTopRightRadiusSecond ? 0 : tempRadius, noTopRightRadiusSecond ? 0 : tempRadius,
468 | noBottomRightRadiusSecond ? 0 : tempRadius, noBottomRightRadiusSecond ? 0 : tempRadius,
469 | noBottomLeftRadiusSecond ? 0 : tempRadius, noBottomLeftRadiusSecond ? 0 : tempRadius
470 | };
471 | }
472 |
473 | private void needInvalidate() {
474 | post(new Runnable() {
475 | @Override
476 | public void run() {
477 | invalidate();
478 | }
479 | });
480 | }
481 |
482 | public int getBorderColor() {
483 | return borderColor;
484 | }
485 |
486 | public MyProgress setBorderColor(@ColorInt int borderColor) {
487 | if (this.borderColor == borderColor) {
488 | return this;
489 | }
490 | this.borderColor = borderColor;
491 | borderPaint.setColor(borderColor);
492 | return this;
493 | }
494 |
495 | public float getBorderWidth() {
496 | return borderWidth;
497 | }
498 |
499 | public MyProgress setBorderWidth(float borderWidth) {
500 | if (this.borderWidth == borderWidth) {
501 | return this;
502 | }
503 | this.borderWidth = borderWidth;
504 | borderPaint.setStrokeWidth(borderWidth * 2f);
505 |
506 | updateBGPath();
507 | updateBorderPath();
508 | updateProgressPath();
509 | updateProgressPathSecond();
510 | return this;
511 | }
512 |
513 | public int getProgressColor() {
514 | return progressColor;
515 | }
516 |
517 | public MyProgress setProgressColor(int progressColor) {
518 | if (this.progressColor == progressColor) {
519 | return this;
520 | }
521 | this.progressColor = progressColor;
522 | this.progressShader = null;
523 | progressPaint.setColor(progressColor);
524 | progressPaint.setShader(null);
525 | return this;
526 | }
527 |
528 | public int getAllInterval() {
529 | return allInterval;
530 | }
531 |
532 | public MyProgress setAllInterval(int allInterval) {
533 | if (allInterval == this.allInterval) {
534 | return this;
535 | }
536 | this.allInterval = allInterval;
537 | updateProgressPath();
538 | updateProgressPathSecond();
539 | return this;
540 | }
541 |
542 | public int getLeftInterval() {
543 | return leftInterval;
544 | }
545 |
546 | public MyProgress setLeftInterval(int leftInterval) {
547 | if (leftInterval == this.leftInterval) {
548 | return this;
549 | }
550 | this.leftInterval = leftInterval;
551 | updateProgressPath();
552 | updateProgressPathSecond();
553 | return this;
554 | }
555 |
556 | public int getTopInterval() {
557 | return topInterval;
558 | }
559 |
560 | public MyProgress setTopInterval(int topInterval) {
561 | if (topInterval == this.topInterval) {
562 | return this;
563 | }
564 | this.topInterval = topInterval;
565 | updateProgressPath();
566 | updateProgressPathSecond();
567 | return this;
568 | }
569 |
570 | public int getRightInterval() {
571 | return rightInterval;
572 | }
573 |
574 | public MyProgress setRightInterval(int rightInterval) {
575 | if (rightInterval == this.rightInterval) {
576 | return this;
577 | }
578 | this.rightInterval = rightInterval;
579 | updateProgressPath();
580 | updateProgressPathSecond();
581 | return this;
582 | }
583 |
584 | public int getBottomInterval() {
585 | return bottomInterval;
586 | }
587 |
588 | public MyProgress setBottomInterval(int bottomInterval) {
589 | if (bottomInterval == this.bottomInterval) {
590 | return this;
591 | }
592 | this.bottomInterval = bottomInterval;
593 | updateProgressPath();
594 | updateProgressPathSecond();
595 | return this;
596 | }
597 |
598 | public boolean isUseAnimation() {
599 | return useAnimation;
600 | }
601 |
602 | public MyProgress setUseAnimation(boolean useAnimation) {
603 | this.useAnimation = useAnimation;
604 | return this;
605 | }
606 |
607 | public float getMaxProgress() {
608 | return maxProgress;
609 | }
610 |
611 | public void complete() {
612 | needInvalidate();
613 | }
614 |
615 | public MyProgress setMaxProgress(float maxProgress) {
616 | if (maxProgress <= 0) {
617 | this.maxProgress = 0;
618 | } else {
619 | this.maxProgress = maxProgress;
620 | }
621 | return this;
622 | }
623 |
624 | public float getNowProgress() {
625 | return nowProgress;
626 | }
627 |
628 | public MyProgress setNowProgress(float progress) {
629 | return setNowProgress(progress, useAnimation);
630 | }
631 |
632 | public MyProgress setNowProgress(float progress, boolean useAnimation) {
633 | float beforeProgress = this.scaleProgress;
634 | if (progress > maxProgress) {
635 | this.nowProgress = maxProgress;
636 | } else if (progress < 0) {
637 | this.nowProgress = 0;
638 | } else {
639 | this.nowProgress = progress;
640 | }
641 | if (useAnimation) {
642 | valueAnimator = ValueAnimator.ofFloat(beforeProgress, this.nowProgress);
643 | valueAnimator.removeAllUpdateListeners();
644 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
645 | @Override
646 | public void onAnimationUpdate(ValueAnimator animation) {
647 | MyProgress.this.scaleProgress = (float) animation.getAnimatedValue();
648 | updateProgressPath();
649 | invalidate();
650 | setProgressToInter(MyProgress.this.scaleProgress, MyProgress.this.nowProgress, MyProgress.this.maxProgress);
651 | }
652 | });
653 | valueAnimator.setInterpolator(interpolator);
654 | valueAnimator.setDuration(duration);
655 | valueAnimator.start();
656 | } else {
657 | MyProgress.this.scaleProgress = this.nowProgress;
658 | updateProgressPath();
659 | invalidate();
660 | setProgressToInter(MyProgress.this.scaleProgress, this.nowProgress, this.maxProgress);
661 | }
662 | return this;
663 | }
664 |
665 | public int getAngle() {
666 | return angle;
667 | }
668 |
669 | public MyProgress setAngle(int angle) {
670 | this.angle = angle;
671 | if (this.angle < 0) {
672 | setRotateAngle(angle % 360 + 360);
673 | } else {
674 | setRotateAngle(angle % 360);
675 | }
676 | return this;
677 | }
678 |
679 | private void setRotateAngle(int rotateAngle) {
680 | this.rotateAngle = rotateAngle;
681 | }
682 |
683 | public int getDuration() {
684 | return duration;
685 | }
686 |
687 | public MyProgress setDuration(int duration) {
688 | this.duration = duration;
689 | return this;
690 | }
691 |
692 | public float getViewWidth() {
693 | return viewWidth;
694 | }
695 |
696 | public MyProgress setViewWidth(float viewWidth) {
697 | if (viewWidth == this.viewWidth) {
698 | return this;
699 | }
700 | this.viewWidth = viewWidth;
701 | updateBGPath();
702 | updateBorderPath();
703 | updateProgressPath();
704 | updateProgressPathSecond();
705 | return this;
706 | }
707 |
708 | public float getViewHeight() {
709 | return viewHeight;
710 | }
711 |
712 | public MyProgress setViewHeight(float viewHeight) {
713 | if (viewHeight == this.viewHeight) {
714 | return this;
715 | }
716 | this.viewHeight = viewHeight;
717 | updateBGPath();
718 | updateBorderPath();
719 | updateProgressPath();
720 | updateProgressPathSecond();
721 | return this;
722 | }
723 |
724 | public int getBgColor() {
725 | return bgColor;
726 | }
727 |
728 | public MyProgress setBgColor(int bgColor) {
729 | if (this.bgColor == bgColor) {
730 | return this;
731 | }
732 | this.bgColor = bgColor;
733 | bgPaint.setColor(bgColor);
734 | return this;
735 | }
736 |
737 | public float getRadius() {
738 | return radius;
739 | }
740 |
741 | public MyProgress setRadius(float radius) {
742 | if (radius == this.radius) {
743 | return this;
744 | }
745 | this.radius = radius;
746 | updateBGPath();
747 | updateBorderPath();
748 | updateProgressPath();
749 | updateProgressPathSecond();
750 | return this;
751 | }
752 |
753 | public float getNowProgressSecond() {
754 | return nowProgressSecond;
755 | }
756 |
757 | public MyProgress setNowProgressSecond(float nowProgressSecond) {
758 | return setNowProgressSecond(nowProgressSecond, useAnimation);
759 | }
760 |
761 | public MyProgress setNowProgressSecondByProgress(float nowProgressSecond) {
762 | return setNowProgressSecond(getNowProgress() + nowProgressSecond, useAnimation);
763 | }
764 |
765 | public MyProgress setNowProgressSecond(float nowProgressSecond, boolean useAnimation) {
766 | float beforeProgress = this.scaleProgressSecond;
767 | if (nowProgressSecond > maxProgress) {
768 | this.nowProgressSecond = maxProgress;
769 | } else if (nowProgressSecond < 0) {
770 | this.nowProgressSecond = 0;
771 | } else {
772 | this.nowProgressSecond = nowProgressSecond;
773 | }
774 | if (useAnimation) {
775 | valueAnimatorSecond = ValueAnimator.ofFloat(beforeProgress, this.nowProgressSecond);
776 | valueAnimatorSecond.removeAllUpdateListeners();
777 | valueAnimatorSecond.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
778 | @Override
779 | public void onAnimationUpdate(ValueAnimator animation) {
780 | MyProgress.this.scaleProgressSecond = (float) animation.getAnimatedValue();
781 | updateProgressPathSecond();
782 | invalidate();
783 | setProgressToInterSecond(MyProgress.this.scaleProgressSecond, MyProgress.this.nowProgressSecond, MyProgress.this.maxProgress);
784 | }
785 | });
786 | valueAnimatorSecond.setInterpolator(interpolator);
787 | valueAnimatorSecond.setDuration(duration);
788 | valueAnimatorSecond.start();
789 | } else {
790 | MyProgress.this.scaleProgressSecond = this.nowProgressSecond;
791 | updateProgressPathSecond();
792 | invalidate();
793 | setProgressToInterSecond(MyProgress.this.scaleProgressSecond, this.nowProgressSecond, this.maxProgress);
794 | }
795 | return this;
796 |
797 | }
798 |
799 | public int getProgressColorSecond() {
800 | return progressColorSecond;
801 | }
802 |
803 | public MyProgress setProgressColorSecond(int progressColorSecond) {
804 | if (this.progressColorSecond == progressColorSecond) {
805 | return this;
806 | }
807 | this.progressShaderSecond = null;
808 | progressPaintSecond.setColor(progressColorSecond);
809 | progressPaintSecond.setShader(null);
810 |
811 | this.progressColorSecond = progressColorSecond;
812 | return this;
813 | }
814 |
815 |
816 | public TimeInterpolator getInterpolator() {
817 | return interpolator;
818 | }
819 |
820 | public MyProgress setInterpolator(TimeInterpolator interpolator) {
821 | this.interpolator = interpolator;
822 | return this;
823 | }
824 |
825 | public Shader getBorderShader() {
826 | return borderShader;
827 | }
828 |
829 | public MyProgress setBorderShader(Shader borderShader) {
830 | this.borderShader = borderShader;
831 | if (borderShader != null) {
832 | borderPaint.setShader(borderShader);
833 | } else {
834 | borderPaint.setShader(null);
835 | }
836 | return this;
837 | }
838 |
839 | public Shader getBgShader() {
840 | return bgShader;
841 | }
842 |
843 | public MyProgress setBgShader(Shader bgShader) {
844 | if (bgShader == this.bgShader) {
845 | return this;
846 | }
847 | this.bgShader = bgShader;
848 | if (this.bgColor == Color.parseColor(def_bgColor)) {
849 | /*防止bgPaint设置透明色导致背景shader无效*/
850 | this.bgColor = Color.WHITE;
851 | }
852 | bgPaint.setShader(bgShader);
853 | return this;
854 | }
855 |
856 | public Shader getProgressShader() {
857 | return progressShader;
858 | }
859 |
860 | public MyProgress setProgressShader(Shader progressShader) {
861 | if (progressShader == this.progressShader) {
862 | return this;
863 | }
864 | this.progressShader = progressShader;
865 | progressPaint.setShader(progressShader);
866 | return this;
867 | }
868 |
869 | public Shader getProgressShaderSecond() {
870 | return progressShaderSecond;
871 | }
872 |
873 | public MyProgress setProgressShaderSecond(Shader progressShaderSecond) {
874 | if (progressShaderSecond == this.progressShaderSecond) {
875 | return this;
876 | }
877 | this.progressShaderSecond = progressShaderSecond;
878 | progressPaintSecond.setShader(progressShaderSecond);
879 | return this;
880 | }
881 |
882 | public boolean isNoTopLeftRadius() {
883 | return noTopLeftRadius;
884 | }
885 |
886 | public MyProgress setNoTopLeftRadius(boolean noTopLeftRadius) {
887 | this.noTopLeftRadius = noTopLeftRadius;
888 | updateProgressPath();
889 | return this;
890 | }
891 |
892 | public boolean isNoTopRightRadius() {
893 | return noTopRightRadius;
894 | }
895 |
896 | public MyProgress setNoTopRightRadius(boolean noTopRightRadius) {
897 | this.noTopRightRadius = noTopRightRadius;
898 | updateProgressPath();
899 | return this;
900 | }
901 |
902 | public boolean isNoBottomLeftRadius() {
903 | return noBottomLeftRadius;
904 | }
905 |
906 | public MyProgress setNoBottomLeftRadius(boolean noBottomLeftRadius) {
907 | this.noBottomLeftRadius = noBottomLeftRadius;
908 | updateProgressPath();
909 | return this;
910 | }
911 |
912 | public boolean isNoBottomRightRadius() {
913 | return noBottomRightRadius;
914 | }
915 |
916 | public MyProgress setNoBottomRightRadius(boolean noBottomRightRadius) {
917 | this.noBottomRightRadius = noBottomRightRadius;
918 | updateProgressPath();
919 | return this;
920 | }
921 |
922 | public boolean isNoTopLeftRadiusSecond() {
923 | return noTopLeftRadiusSecond;
924 | }
925 |
926 | public MyProgress setNoTopLeftRadiusSecond(boolean noTopLeftRadiusSecond) {
927 | this.noTopLeftRadiusSecond = noTopLeftRadiusSecond;
928 | updateProgressPathSecond();
929 | return this;
930 | }
931 |
932 | public boolean isNoTopRightRadiusSecond() {
933 | return noTopRightRadiusSecond;
934 | }
935 |
936 | public MyProgress setNoTopRightRadiusSecond(boolean noTopRightRadiusSecond) {
937 | this.noTopRightRadiusSecond = noTopRightRadiusSecond;
938 | updateProgressPathSecond();
939 | return this;
940 | }
941 |
942 | public boolean isNoBottomLeftRadiusSecond() {
943 | return noBottomLeftRadiusSecond;
944 | }
945 |
946 | public MyProgress setNoBottomLeftRadiusSecond(boolean noBottomLeftRadiusSecond) {
947 | this.noBottomLeftRadiusSecond = noBottomLeftRadiusSecond;
948 | updateProgressPathSecond();
949 | return this;
950 | }
951 |
952 | public boolean isNoBottomRightRadiusSecond() {
953 | return noBottomRightRadiusSecond;
954 | }
955 |
956 | public MyProgress setNoBottomRightRadiusSecond(boolean noBottomRightRadiusSecond) {
957 | this.noBottomRightRadiusSecond = noBottomRightRadiusSecond;
958 | updateProgressPathSecond();
959 | return this;
960 | }
961 | }
962 |
--------------------------------------------------------------------------------