├── .gitignore
├── .idea
├── codeStyles
│ └── Project.xml
├── compiler.xml
├── encodings.xml
├── gradle.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── .travis.yml
├── CHANGELOG.md
├── LICENSE.txt
├── README.md
├── art
├── demo.gif
└── demo.png
├── build.gradle
├── demo
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── liulishuo
│ │ └── magicprogress
│ │ └── demo
│ │ ├── activity
│ │ └── MainActivity.java
│ │ └── widget
│ │ └── AnimTextView.java
│ └── res
│ ├── drawable
│ └── demo_btn_bg.xml
│ ├── layout
│ └── activity_main.xml
│ ├── menu
│ └── menu_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle.properties
├── gradle
├── bintray.gradle
├── mavenlocal.gradle
├── mvn-push.gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── LICENSE
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── liulishuo
│ │ └── magicprogresswidget
│ │ ├── MagicProgressBar.java
│ │ └── MagicProgressCircle.java
│ └── res
│ └── values
│ ├── attrs.xml
│ └── colors.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .DS_Store
5 | /build
6 | /captures
7 |
8 | /.idea/workspace.xml
9 | /.idea/libraries
10 | /.idea/misc.xml
11 | /.idea/checkstyle-idea.xml
12 | /.idea/caches
13 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.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 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | android:
4 | components:
5 | - platform-tools
6 | - build-tools-27.0.3
7 | - android-27
8 | - extra
9 |
10 | after_script:
11 | - cat ./demo/build/outputs/lint-results.xml
12 | - cat ./library/build/outputs/lint-results.xml
13 |
14 | sudo: false
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 | ---
3 |
4 | ## Version 1.1.1
5 |
6 | _2018-08-08_
7 |
8 | - Fix the circle close arc become lucency when set percent >=1 directly
9 |
10 | ## Version 1.1.0
11 |
12 | _2018-08-07_
13 |
14 | - Add `foot_over_head` for support close MagicProgressCircle foot above head
15 |
16 | ## Version 1.0.9
17 |
18 | _2016-04-21_
19 |
20 | - `MagicProgressBar`与`MagicProgressCircle`添加Smooth-Progress-Duration功能: `setSmoothPercent(percent:float, durationMillis:long):void`,可以在指定时间范围内平滑的滚动到指定的百分比
21 |
22 | ## Version 1.0.8
23 |
24 | - `MagicProgressBar`与`MagicProgressCircle`添加Smooth-Progress功能: `setSmoothPercent(percent:float):void`
25 |
26 | ## Version 1.0.7
27 |
28 | - 修复`MagicProgressBar`在进度操作左侧的左半球时,在进度条下面多画了左侧球体的右半球部分
29 |
30 | ## Version 1.0.6
31 |
32 | - 添加代码中动态调整参数的接口
33 | - `MagicProgressBar`支持配置进度条右侧是圆弧还是平面
34 |
35 | ## Version 1.0.2
36 |
37 | - library删除对v7的引用
38 |
39 | ## Version 1.0.1
40 |
41 | - 规范包名
42 | - 添加上传maven gradle脚本
43 |
44 | ## Version 1.0.0
45 |
46 | - initial release
47 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright (c) 2015 LingoChamp Inc.
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MagicProgressWidget
2 |
3 | [![Download][bintray_svg]][bintray_link]
4 | [![Build Status][build_status_svg]][build_status_link]
5 |
6 | > 渐变的圆形进度条与轻量横向进度条
7 |
8 | ## I. 最终效果
9 |
10 | ![demo gif][demo_gif]
11 |
12 | ## II. 如何使用
13 |
14 | `build.gradle`中配置:
15 |
16 | ```
17 | implementation 'com.liulishuo.magicprogresswidget:library:1.1.1'
18 | ```
19 |
20 | > 建议参考github中的demo
21 |
22 | ```
23 |
32 |
33 |
40 | ```
41 |
42 | #### 1. Magic Progress Circle
43 |
44 | - 支持平滑过渡: `setSmoothPercent(percent:float):void`
45 | - 支持指定时间的平滑过渡: `setSmoothPercent(percent:float, durationMillis:long):void`
46 |
47 | | 参数 | 含义 | 默认值 |
48 | | :--- | :--- | :--- |
49 | | mpc_percent | 填充的百分比[0, 1] | 0 |
50 | | mpc_stroke_width | 描边宽度 | 18dp |
51 | | mpc_start_color | 渐变颜色起点颜色(percent=0) | #FF00FFED |
52 | | mpc_end_color | 渐变颜色终点颜色(percent=1) | #FFED00FF |
53 | | mpc_default_color | 未填充部分的描边的颜色 | #1AFFFFFF |
54 | | mpc_foot_over_head | 结尾的圆弧是否覆盖开始的圆弧 | false |
55 |
56 | #### 2. Magic Progress Bar
57 |
58 | > 相比系统的ProgressBar更加轻量,如果你的ProgressBar要求不是很复杂,推荐使用
59 |
60 | - 支持平滑过渡: `setSmoothPercent(percent:float):void`
61 | - 支持指定时间的平滑过渡: `setSmoothPercent(percent:float, durationMillis:long):void`
62 |
63 | | 参数 | 含义 | 默认值 |
64 | | :--- | :--- | :--- |
65 | | mpb_percent | 填充的百分比[0, 1] | 0 |
66 | | mpb_fill_color | 填充进度的颜色 | 0 |
67 | | mpb_background_color | 进度背景的颜色 | 0 |
68 | | mpb_flat | 填充的进度条右侧是否是平面(不是平面就是圆弧) | false |
69 |
70 | ## III. LICENSE
71 |
72 | ```
73 | Copyright (c) 2015 LingoChamp Inc.
74 |
75 | Licensed under the Apache License, Version 2.0 (the "License");
76 | you may not use this file except in compliance with the License.
77 | You may obtain a copy of the License at
78 |
79 | http://www.apache.org/licenses/LICENSE-2.0
80 |
81 | Unless required by applicable law or agreed to in writing, software
82 | distributed under the License is distributed on an "AS IS" BASIS,
83 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
84 | See the License for the specific language governing permissions and
85 | limitations under the License.
86 | ```
87 |
88 | [demo_gif]: https://github.com/lingochamp/MagicProgressWidget/raw/master/art/demo.gif
89 | [bintray_svg]: https://api.bintray.com/packages/jacksgong/maven/MagicProgressWidget/images/download.svg
90 | [bintray_link]: https://bintray.com/jacksgong/maven/MagicProgressWidget/_latestVersion
91 | [build_status_svg]: https://travis-ci.org/lingochamp/MagicProgressWidget.svg?branch=master
92 | [build_status_link]: https://travis-ci.org/lingochamp/MagicProgressWidget
93 |
--------------------------------------------------------------------------------
/art/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingochamp/MagicProgressWidget/ba88d7ee0bea89faea96a1199ce27ed9a2734e33/art/demo.gif
--------------------------------------------------------------------------------
/art/demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingochamp/MagicProgressWidget/ba88d7ee0bea89faea96a1199ce27ed9a2734e33/art/demo.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | google()
4 | jcenter()
5 | }
6 | dependencies {
7 | classpath 'com.android.tools.build:gradle:3.3.0-alpha04'
8 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
9 | }
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | jcenter()
15 | google()
16 | }
17 | }
18 |
19 | subprojects {
20 | group = GROUP
21 | version = VERSION_NAME
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/demo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/demo/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion COMPILE_SDK_VERSION as int
5 | buildToolsVersion BUILD_TOOLS_VERSION as String
6 |
7 | defaultConfig {
8 | applicationId "com.liulishuo.magicprogress.demo"
9 | minSdkVersion 14
10 | targetSdkVersion TARGET_SDK_VERSION as int
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | }
22 |
23 | dependencies {
24 | implementation project(':library')
25 | implementation 'com.android.support:recyclerview-v7:27.1.1'
26 | implementation 'com.android.support:appcompat-v7:27.1.1'
27 | }
28 |
--------------------------------------------------------------------------------
/demo/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 /Users/Jacksgong/Develop/sdk/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 |
--------------------------------------------------------------------------------
/demo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/liulishuo/magicprogress/demo/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.liulishuo.magicprogress.demo.activity;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorSet;
5 | import android.animation.ObjectAnimator;
6 | import android.content.Intent;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 | import android.view.animation.AccelerateInterpolator;
14 |
15 | import com.liulishuo.magicprogress.demo.R;
16 | import com.liulishuo.magicprogress.demo.widget.AnimTextView;
17 | import com.liulishuo.magicprogresswidget.MagicProgressBar;
18 | import com.liulishuo.magicprogresswidget.MagicProgressCircle;
19 |
20 | import java.util.Random;
21 |
22 | import cn.dreamtobe.percentsmoothhandler.ISmoothTarget;
23 |
24 | /**
25 | * Created by Jacksgong on 12/10/15.
26 | */
27 | public class MainActivity extends AppCompatActivity {
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_main);
33 | assignViews();
34 |
35 | anim();
36 | }
37 |
38 | private boolean isAnimActive;
39 | private final Random random = new Random();
40 |
41 | private void anim() {
42 | final int ceil = 26;
43 | final int progress = random.nextInt(ceil);
44 |
45 | AnimatorSet set = new AnimatorSet();
46 | set.playTogether(
47 | ObjectAnimator.ofFloat(demoMpc, "percent", 0, progress / 100f),
48 | ObjectAnimator.ofInt(demoTv, "progress", 0, progress),
49 | ObjectAnimator.ofFloat(demo1Mpb, "percent", 0, random.nextInt(ceil) / 100f),
50 | ObjectAnimator.ofFloat(demo2Mpb, "percent", 0, random.nextInt(ceil) / 100f),
51 | ObjectAnimator.ofFloat(demo3Mpb, "percent", 0, random.nextInt(ceil) / 100f),
52 | ObjectAnimator.ofFloat(demo4Mpb, "percent", 0, random.nextInt(ceil) / 100f)
53 | );
54 | set.setDuration(600);
55 | set.addListener(new Animator.AnimatorListener() {
56 | @Override
57 | public void onAnimationStart(Animator animation) {
58 | isAnimActive = true;
59 | }
60 |
61 | @Override
62 | public void onAnimationEnd(Animator animation) {
63 | isAnimActive = false;
64 | }
65 |
66 | @Override
67 | public void onAnimationCancel(Animator animation) {
68 |
69 | }
70 |
71 | @Override
72 | public void onAnimationRepeat(Animator animation) {
73 |
74 | }
75 | });
76 | set.setInterpolator(new AccelerateInterpolator());
77 | set.start();
78 | }
79 |
80 |
81 | public void onReRandomPercent(final View view) {
82 | if (isAnimActive) {
83 | return;
84 | }
85 | anim();
86 | }
87 |
88 | public void onClickIncreaseSmoothly(final View view) {
89 | if (isAnimActive) {
90 | return;
91 | }
92 |
93 | float mpcPercent = getIncreasedPercent(demoMpc);
94 | demoMpc.setSmoothPercent(mpcPercent);
95 | demoTv.setSmoothPercent(mpcPercent);
96 | // Just for demo smoothly process to the target percent in 3000ms duration.
97 | demo1Mpb.setSmoothPercent(getIncreasedPercent(demo1Mpb), 3000);
98 | demo2Mpb.setSmoothPercent(getIncreasedPercent(demo2Mpb));
99 | demo3Mpb.setSmoothPercent(getIncreasedPercent(demo3Mpb));
100 | demo4Mpb.setSmoothPercent(getIncreasedPercent(demo4Mpb));
101 | }
102 |
103 | private float getIncreasedPercent(ISmoothTarget target) {
104 | float increasedPercent = target.getPercent() + 0.1f;
105 |
106 | return Math.min(1, increasedPercent);
107 | }
108 |
109 | @Override
110 | public boolean onCreateOptionsMenu(Menu menu) {
111 | getMenuInflater().inflate(R.menu.menu_main, menu);
112 | return super.onCreateOptionsMenu(menu);
113 | }
114 |
115 | @Override
116 | public boolean onOptionsItemSelected(MenuItem item) {
117 | switch (item.getItemId()) {
118 | case R.id.menu_github:
119 | openGitHub();
120 | return true;
121 | default:
122 | return super.onOptionsItemSelected(item);
123 | }
124 | }
125 |
126 | private void openGitHub() {
127 | Uri uri = Uri.parse(getString(R.string.app_github_url));
128 | Intent intent = new Intent(Intent.ACTION_VIEW, uri);
129 | startActivity(intent);
130 | }
131 |
132 | private MagicProgressCircle demoMpc;
133 | private AnimTextView demoTv;
134 | private MagicProgressBar demo1Mpb;
135 | private MagicProgressBar demo2Mpb;
136 | private MagicProgressBar demo3Mpb;
137 | private MagicProgressBar demo4Mpb;
138 |
139 | private void assignViews() {
140 | demoMpc = (MagicProgressCircle) findViewById(R.id.demo_mpc);
141 | demoTv = (AnimTextView) findViewById(R.id.demo_tv);
142 | demo1Mpb = (MagicProgressBar) findViewById(R.id.demo_1_mpb);
143 | demo2Mpb = (MagicProgressBar) findViewById(R.id.demo_2_mpb);
144 | demo3Mpb = (MagicProgressBar) findViewById(R.id.demo_3_mpb);
145 | demo4Mpb = (MagicProgressBar) findViewById(R.id.demo_4_mpb);
146 | }
147 |
148 | }
149 |
150 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/liulishuo/magicprogress/demo/widget/AnimTextView.java:
--------------------------------------------------------------------------------
1 | package com.liulishuo.magicprogress.demo.widget;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import java.lang.ref.WeakReference;
7 |
8 | import cn.dreamtobe.percentsmoothhandler.ISmoothTarget;
9 | import cn.dreamtobe.percentsmoothhandler.SmoothHandler;
10 |
11 | /**
12 | * Created by Jacksgong on 12/11/15.
13 | */
14 | public class AnimTextView extends android.support.v7.widget.AppCompatTextView implements ISmoothTarget {
15 | private SmoothHandler smoothHandler;
16 |
17 | public AnimTextView(Context context) {
18 | super(context);
19 | }
20 |
21 | public AnimTextView(Context context, AttributeSet attrs) {
22 | super(context, attrs);
23 | }
24 |
25 | public AnimTextView(Context context, AttributeSet attrs, int defStyleAttr) {
26 | super(context, attrs, defStyleAttr);
27 | }
28 |
29 | private int progress;
30 | private int max = 100;
31 |
32 | public void setProgress(final int progress) {
33 | if (smoothHandler != null) {
34 | smoothHandler.commitPercent(progress / (float) getMax());
35 | }
36 |
37 | this.progress = progress;
38 | setText(String.valueOf(progress));
39 | }
40 |
41 | public int getProgress() {
42 | return this.progress;
43 | }
44 |
45 | public int getMax() {
46 | return max;
47 | }
48 |
49 | public void setMax(int max) {
50 | this.max = max;
51 | }
52 |
53 | @Override
54 | public float getPercent() {
55 | return getProgress() / (float) getMax();
56 | }
57 |
58 | @Override
59 | public void setPercent(float percent) {
60 | setProgress((int) Math.ceil(percent * getMax()));
61 | }
62 |
63 | @Override
64 | public void setSmoothPercent(float percent) {
65 | getSmoothHandler().loopSmooth(percent);
66 | }
67 |
68 | @Override
69 | public void setSmoothPercent(float percent, long durationMillis) {
70 | getSmoothHandler().loopSmooth(percent, durationMillis);
71 | }
72 |
73 | private SmoothHandler getSmoothHandler() {
74 | if (smoothHandler == null) {
75 | smoothHandler = new SmoothHandler(new WeakReference(this));
76 | }
77 | return smoothHandler;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/demo_btn_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
20 |
21 |
29 |
30 |
31 |
32 |
40 |
41 |
47 |
48 |
53 |
54 |
59 |
60 |
66 |
67 |
73 |
74 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/demo/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingochamp/MagicProgressWidget/ba88d7ee0bea89faea96a1199ce27ed9a2734e33/demo/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingochamp/MagicProgressWidget/ba88d7ee0bea89faea96a1199ce27ed9a2734e33/demo/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingochamp/MagicProgressWidget/ba88d7ee0bea89faea96a1199ce27ed9a2734e33/demo/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingochamp/MagicProgressWidget/ba88d7ee0bea89faea96a1199ce27ed9a2734e33/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingochamp/MagicProgressWidget/ba88d7ee0bea89faea96a1199ce27ed9a2734e33/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | @color/black_thin
4 | @color/black
5 | #FF4081
6 |
7 | #FFFFFFFF
8 | #FF000000
9 | #0D0D0E
10 |
11 | #777777
12 | #666666
13 |
14 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MagicProgressWidget
3 | GitHub
4 | https://github.com/lingochamp/MagicProgressWidget
5 | re-random percent
6 | increase progress smoothly
7 |
8 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
19 |
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP=com.liulishuo.magicprogresswidget
2 |
3 | VERSION_NAME=1.1.1
4 | BUILD_TOOLS_VERSION=27.0.3
5 | COMPILE_SDK_VERSION=27
6 | TARGET_SDK_VERSION=27
7 |
8 | POM_URL=https://github.com/lingochamp/MagicProgressWidget
9 | ISSUE_URL=https://github.com/lingochamp/MagicProgressWidget/issues
10 | POM_SCM_URL=https://github.com/lingochamp/MagicProgressWidget
11 | POM_SCM_CONNECTION=scm:git:git://github.com/lingochamp/MagicProgressWidget.git
12 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/lingochamp/MagicProgressWidget.git
13 |
14 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
15 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
16 | POM_LICENCE_DIST=repo
17 |
18 | POM_DEVELOPER_ID=lingochamp
19 | POM_DEVELOPER_NAME=LingoChamp Inc.
20 |
21 | org.gradle.parallel=true
22 |
--------------------------------------------------------------------------------
/gradle/bintray.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 LingoChamp Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | apply plugin: 'com.jfrog.bintray'
19 |
20 | afterEvaluate { project ->
21 | task sourcesJar(type: Jar) {
22 | from android.sourceSets.main.java.srcDirs
23 | classifier = 'sources'
24 | }
25 |
26 | task javadoc(type: Javadoc) {
27 | failOnError false
28 | source = android.sourceSets.main.java.srcDirs
29 | options {
30 | charSet = 'UTF-8'
31 | links "http://docs.oracle.com/javase/7/docs/api/"
32 | linksOffline "http://d.android.com/reference", System.getenv("ANDROID_HOME") + "/docs/reference"
33 | }
34 | classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
35 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
36 | }
37 |
38 | task javadocJar(type: Jar, dependsOn: javadoc) {
39 | classifier = 'javadoc'
40 | from javadoc.destinationDir
41 | }
42 |
43 | artifacts {
44 | archives javadocJar
45 | archives sourcesJar
46 | }
47 | }
48 |
49 |
50 | def getBintrayUser() {
51 | return hasProperty('BINTRAY_USER') ? BINTRAY_USER : ""
52 | }
53 |
54 | def getBintrayGPGPassword() {
55 | return hasProperty('BINTRAY_GPG_PASSWORD') ? BINTRAY_GPG_PASSWORD : ""
56 | }
57 |
58 | def getBintrayApiKey() {
59 | return hasProperty('BINTRAY_API_KEY') ? BINTRAY_API_KEY : ""
60 | }
61 |
62 | def getSonatypeUsername() {
63 | return hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : ""
64 | }
65 |
66 | def getSonatypePassword() {
67 | return hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : ""
68 | }
69 | version = VERSION_NAME
70 |
71 | bintray {
72 | user = getBintrayUser()
73 | key = getBintrayApiKey()
74 |
75 | // publish = true //[Default: false] Whether version should be auto published after an upload
76 | // override = false //[Default: false] Whether to override version artifacts already published
77 |
78 | configurations = ['archives']
79 | pkg {
80 | repo = "maven"
81 | name = POM_NAME
82 | desc = POM_DESCRIPTION
83 | websiteUrl = POM_URL
84 | issueTrackerUrl = ISSUE_URL
85 | vcsUrl = POM_SCM_URL
86 | licenses = ["Apache-2.0"]
87 | publish = true
88 | publicDownloadNumbers = true
89 |
90 | githubRepo = POM_URL
91 | githubReleaseNotesFile = 'README.md'
92 |
93 | version {
94 | gpg {
95 | sign = true //Determines whether to GPG sign the files. The default is false
96 | passphrase = getBintrayGPGPassword()
97 | }
98 |
99 | mavenCentralSync {
100 | sync = true
101 | user = getSonatypeUsername()
102 | password = getSonatypePassword()
103 | close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
104 | }
105 | }
106 | }
107 | }
--------------------------------------------------------------------------------
/gradle/mavenlocal.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 LingoChamp Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'maven-publish'
18 |
19 | task sourceJar(type: Jar) {
20 | from android.sourceSets.main.java.srcDirs
21 | classifier "source"
22 | }
23 |
24 | publishing {
25 | publications {
26 | magicProgressWidget(MavenPublication) {
27 | groupId GROUP
28 | artifactId POM_ARTIFACT_ID
29 | version VERSION_NAME
30 | artifact(sourceJar)
31 | artifact("$buildDir/outputs/aar/${project.name}-release.aar")
32 |
33 | pom.withXml {
34 | def dependenciesNode = asNode().appendNode('dependencies')
35 | configurations.compile.allDependencies.each {
36 | if (it.group != null
37 | && (it.name != null || "unspecified" == it.name)
38 | && it.version != null) {
39 | def dependencyNode = dependenciesNode.appendNode('dependency')
40 | dependencyNode.appendNode('groupId', it.group)
41 | dependencyNode.appendNode('artifactId', it.name)
42 | dependencyNode.appendNode('version', it.version)
43 | }
44 | }
45 | }
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/gradle/mvn-push.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'maven'
18 | apply plugin: 'signing'
19 | apply from: '../gradle/mavenlocal.gradle'
20 | apply from: '../gradle/bintray.gradle'
21 |
22 | version = VERSION_NAME
23 | group = GROUP
24 |
25 | def isReleaseBuild() {
26 | return VERSION_NAME.contains("SNAPSHOT") == false
27 | }
28 |
29 | def getReleaseRepositoryUrl() {
30 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL :
31 | "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
32 | }
33 |
34 | def getSnapshotRepositoryUrl() {
35 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL :
36 | "https://oss.sonatype.org/content/repositories/snapshots/"
37 | }
38 |
39 | def getRepositoryUsername() {
40 | return hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : ""
41 | }
42 |
43 | def getRepositoryPassword() {
44 | return hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : ""
45 | }
46 |
47 | afterEvaluate { project ->
48 | uploadArchives {
49 | repositories {
50 | mavenDeployer {
51 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
52 |
53 | pom.groupId = GROUP
54 | pom.artifactId = POM_ARTIFACT_ID
55 | pom.version = VERSION_NAME
56 |
57 | repository(url: getReleaseRepositoryUrl()) {
58 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
59 | }
60 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
61 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
62 | }
63 |
64 | pom.project {
65 | name POM_NAME
66 | packaging POM_PACKAGING
67 | description POM_DESCRIPTION
68 | url POM_URL
69 |
70 | scm {
71 | url POM_SCM_URL
72 | connection POM_SCM_CONNECTION
73 | developerConnection POM_SCM_DEV_CONNECTION
74 | }
75 |
76 | licenses {
77 | license {
78 | name POM_LICENCE_NAME
79 | url POM_LICENCE_URL
80 | distribution POM_LICENCE_DIST
81 | }
82 | }
83 |
84 | developers {
85 | developer {
86 | id POM_DEVELOPER_ID
87 | name POM_DEVELOPER_NAME
88 | }
89 | }
90 | }
91 | }
92 | }
93 | }
94 |
95 | signing {
96 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
97 | sign configurations.archives
98 | }
99 |
100 | if (project.getPlugins().hasPlugin('com.android.application') ||
101 | project.getPlugins().hasPlugin('com.android.library')) {
102 | task install(type: Upload, dependsOn: assemble) {
103 | repositories.mavenInstaller {
104 | configuration = configurations.archives
105 |
106 | pom.groupId = GROUP
107 | pom.artifactId = POM_ARTIFACT_ID
108 | pom.version = VERSION_NAME
109 |
110 | pom.project {
111 | name POM_NAME
112 | packaging POM_PACKAGING
113 | description POM_DESCRIPTION
114 | url POM_URL
115 |
116 | scm {
117 | url POM_SCM_URL
118 | connection POM_SCM_CONNECTION
119 | developerConnection POM_SCM_DEV_CONNECTION
120 | }
121 |
122 | licenses {
123 | license {
124 | name POM_LICENCE_NAME
125 | url POM_LICENCE_URL
126 | distribution POM_LICENCE_DIST
127 | }
128 | }
129 |
130 | developers {
131 | developer {
132 | id POM_DEVELOPER_ID
133 | name POM_DEVELOPER_NAME
134 | }
135 | }
136 | }
137 | }
138 | }
139 |
140 | task androidJavadocs(type: Javadoc) {
141 | source = android.sourceSets.main.java.source
142 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
143 | }
144 |
145 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
146 | classifier = 'javadoc'
147 | from androidJavadocs.destinationDir
148 | }
149 |
150 | task androidSourcesJar(type: Jar) {
151 | classifier = 'sources'
152 | from android.sourceSets.main.java.source
153 | }
154 | } else {
155 | install {
156 | repositories.mavenInstaller {
157 | pom.groupId = GROUP
158 | pom.artifactId = POM_ARTIFACT_ID
159 | pom.version = VERSION_NAME
160 |
161 | pom.project {
162 | name POM_NAME
163 | packaging POM_PACKAGING
164 | description POM_DESCRIPTION
165 | url POM_URL
166 |
167 | scm {
168 | url POM_SCM_URL
169 | connection POM_SCM_CONNECTION
170 | developerConnection POM_SCM_DEV_CONNECTION
171 | }
172 |
173 | licenses {
174 | license {
175 | name POM_LICENCE_NAME
176 | url POM_LICENCE_URL
177 | distribution POM_LICENCE_DIST
178 | }
179 | }
180 |
181 | developers {
182 | developer {
183 | id POM_DEVELOPER_ID
184 | name POM_DEVELOPER_NAME
185 | }
186 | }
187 | }
188 | }
189 | }
190 |
191 | task sourcesJar(type: Jar, dependsOn: classes) {
192 | classifier = 'sources'
193 | from sourceSets.main.allSource
194 | }
195 |
196 | task javadocJar(type: Jar, dependsOn: javadoc) {
197 | classifier = 'javadoc'
198 | from javadoc.destinationDir
199 | }
200 | }
201 |
202 | if (JavaVersion.current().isJava8Compatible()) {
203 | allprojects {
204 | tasks.withType(Javadoc) {
205 | options.addStringOption('Xdoclint:none', '-quiet')
206 | }
207 | }
208 | }
209 |
210 | artifacts {
211 | if (project.getPlugins().hasPlugin('com.android.application') ||
212 | project.getPlugins().hasPlugin('com.android.library')) {
213 | archives androidSourcesJar
214 | archives androidJavadocsJar
215 | } else {
216 | archives sourcesJar
217 | archives javadocJar
218 | }
219 | }
220 | }
221 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lingochamp/MagicProgressWidget/ba88d7ee0bea89faea96a1199ce27ed9a2734e33/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Aug 07 20:00:52 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015 LingoChamp Inc.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion COMPILE_SDK_VERSION as int
5 | buildToolsVersion BUILD_TOOLS_VERSION as String
6 |
7 | defaultConfig {
8 | minSdkVersion 3
9 | versionName VERSION_NAME as String
10 | }
11 | buildTypes {
12 | release {
13 | minifyEnabled false
14 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
15 | }
16 | }
17 |
18 | }
19 |
20 | dependencies {
21 | api 'cn.dreamtobe.percentsmoothhandler:library:0.1.1'
22 | }
23 |
24 | apply from: rootProject.file('gradle/mvn-push.gradle')
25 |
--------------------------------------------------------------------------------
/library/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_ARTIFACT_ID=library
2 | POM_NAME=MagicProgressWidget
3 | POM_DESCRIPTION=A magic progress widget library for Android
4 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/library/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 /Users/Jacksgong/Develop/sdk/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 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/java/com/liulishuo/magicprogresswidget/MagicProgressBar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 LingoChamp Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.liulishuo.magicprogresswidget;
17 |
18 | import android.annotation.TargetApi;
19 | import android.content.Context;
20 | import android.content.res.TypedArray;
21 | import android.graphics.Canvas;
22 | import android.graphics.Paint;
23 | import android.graphics.RectF;
24 | import android.os.Build;
25 | import android.util.AttributeSet;
26 | import android.view.View;
27 |
28 | import java.lang.ref.WeakReference;
29 |
30 | import cn.dreamtobe.percentsmoothhandler.ISmoothTarget;
31 | import cn.dreamtobe.percentsmoothhandler.SmoothHandler;
32 |
33 |
34 | /**
35 | * Created by Jacksgong on 12/8/15.
36 | *
37 | * 轻量的ProgressBar
38 | */
39 | public class MagicProgressBar extends View implements ISmoothTarget {
40 |
41 | // ColorInt
42 | private int fillColor;
43 |
44 | // ColorInt
45 | private int backgroundColor;
46 |
47 | private Paint fillPaint;
48 | private Paint backgroundPaint;
49 |
50 | private float percent;
51 | private boolean isFlat;
52 |
53 | private SmoothHandler smoothHandler;
54 |
55 | public MagicProgressBar(Context context) {
56 | super(context);
57 | init(context, null);
58 | }
59 |
60 | public MagicProgressBar(Context context, AttributeSet attrs) {
61 | super(context, attrs);
62 | init(context, attrs);
63 | }
64 |
65 | public MagicProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
66 | super(context, attrs, defStyleAttr);
67 | init(context, attrs);
68 | }
69 |
70 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
71 | public MagicProgressBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
72 | super(context, attrs, defStyleAttr, defStyleRes);
73 | init(context, attrs);
74 | }
75 |
76 | private void init(final Context context, AttributeSet attrs) {
77 | if (context == null || attrs == null) {
78 | return;
79 | }
80 |
81 |
82 | TypedArray typedArray = null;
83 | try {
84 | typedArray = context.obtainStyledAttributes(attrs, R.styleable.MagicProgressBar);
85 | percent = typedArray.getFloat(R.styleable.MagicProgressBar_mpb_percent, 0);
86 | fillColor = typedArray.getColor(R.styleable.MagicProgressBar_mpb_fill_color, 0);
87 | backgroundColor = typedArray.getColor(R.styleable.MagicProgressBar_mpb_background_color, 0);
88 | isFlat = typedArray.getBoolean(R.styleable.MagicProgressBar_mpb_flat, false);
89 | } finally {
90 | if (typedArray != null) {
91 | typedArray.recycle();
92 | }
93 | }
94 |
95 | fillPaint = new Paint();
96 | fillPaint.setColor(fillColor);
97 | fillPaint.setAntiAlias(true);
98 |
99 | backgroundPaint = new Paint();
100 | backgroundPaint.setColor(backgroundColor);
101 | backgroundPaint.setAntiAlias(true);
102 |
103 | }
104 |
105 | /**
106 | * @param fillColor ColorInt
107 | */
108 | public void setFillColor(final int fillColor) {
109 | if (this.fillColor != fillColor) {
110 | this.fillColor = fillColor;
111 | this.fillPaint.setColor(fillColor);
112 | invalidate();
113 | }
114 |
115 | }
116 |
117 | /**
118 | * @param backgroundColor ColorInt
119 | */
120 | public void setBackgroundColor(final int backgroundColor) {
121 | if (this.backgroundColor != backgroundColor) {
122 | this.backgroundColor = backgroundColor;
123 | this.backgroundPaint.setColor(backgroundColor);
124 | invalidate();
125 | }
126 | }
127 |
128 | public int getFillColor() {
129 | return this.fillColor;
130 | }
131 |
132 | public int getBackgroundColor() {
133 | return this.backgroundColor;
134 | }
135 |
136 | public float getPercent() {
137 | return this.percent;
138 | }
139 |
140 | /**
141 | * @param percent FloatRange(from = 0.0, to = 1.0)
142 | */
143 | public void setPercent(float percent) {
144 | percent = Math.min(1, percent);
145 | percent = Math.max(0, percent);
146 |
147 | if (smoothHandler != null) {
148 | smoothHandler.commitPercent(percent);
149 | }
150 |
151 | if (this.percent != percent) {
152 | this.percent = percent;
153 | invalidate();
154 | }
155 |
156 | }
157 |
158 | @Override
159 | public void setSmoothPercent(float percent) {
160 | getSmoothHandler().loopSmooth(percent);
161 | }
162 |
163 | @Override
164 | public void setSmoothPercent(float percent, long durationMillis) {
165 | getSmoothHandler().loopSmooth(percent, durationMillis);
166 | }
167 |
168 | private SmoothHandler getSmoothHandler() {
169 | if (smoothHandler == null) {
170 | smoothHandler = new SmoothHandler(new WeakReference(this));
171 | }
172 | return smoothHandler;
173 | }
174 |
175 | /**
176 | * @param flat Whether the right side of progress is round or flat
177 | */
178 | public void setFlat(final boolean flat) {
179 | if (this.isFlat != flat) {
180 | this.isFlat = flat;
181 |
182 | invalidate();
183 | }
184 | }
185 |
186 | private final RectF rectF = new RectF();
187 | // private final Path regionPath = new Path();
188 | // private final Path fillPath = new Path();
189 |
190 | @Override
191 | protected void onDraw(Canvas canvas) {
192 | super.onDraw(canvas);
193 |
194 | float drawPercent = percent;
195 |
196 | canvas.save();
197 |
198 |
199 | final int height = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
200 | final int width = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
201 |
202 | float fillWidth = drawPercent * width;
203 | final float radius = height / 2.0f;
204 |
205 |
206 | rectF.left = 0;
207 | rectF.top = 0;
208 | rectF.right = width;
209 | rectF.bottom = height;
210 |
211 | // regionPath.reset();
212 | // regionPath.addRoundRect(rectF, radius, radius, Path.Direction.CW);
213 | // regionPath.close();
214 | // draw background
215 | if (backgroundColor != 0) {
216 | canvas.drawRoundRect(rectF, radius, radius, backgroundPaint);
217 | // canvas.drawPath(regionPath, backgroundPaint);
218 | }
219 |
220 |
221 | // draw fill
222 | try {
223 |
224 |
225 | if (fillColor != 0 && fillWidth > 0) {
226 | //有锯齿, 无奈放弃
227 | // fillPath.reset();
228 | // rectF.right = fillWidth;
229 | // fillPath.addRect(rectF, Path.Direction.CW);
230 | // fillPath.close();
231 | // canvas.clipPath(regionPath);
232 | // canvas.drawPath(fillPath, fillPaint);
233 | if (fillWidth == width) {
234 | rectF.right = fillWidth;
235 | canvas.drawRoundRect(rectF, radius, radius, fillPaint);
236 | return;
237 | }
238 |
239 | if (isFlat) {
240 |
241 | // draw left semicircle
242 | canvas.save();
243 | rectF.right = fillWidth > radius ? radius : fillWidth;
244 | canvas.clipRect(rectF);
245 | rectF.right = radius * 2;
246 | canvas.drawRoundRect(rectF, radius, radius, fillPaint);
247 | canvas.restore();
248 |
249 | if (fillWidth <= radius) {
250 | return;
251 | }
252 |
253 | float leftAreaWidth = width - radius;
254 | // draw center
255 | float centerX = fillWidth > leftAreaWidth ? leftAreaWidth : fillWidth;
256 | rectF.left = radius;
257 | rectF.right = centerX;
258 | canvas.drawRect(rectF, fillPaint);
259 | if (fillWidth <= leftAreaWidth) {
260 | return;
261 | }
262 |
263 | // draw right semicircle
264 | rectF.left = leftAreaWidth - radius;
265 |
266 | rectF.right = fillWidth;
267 | canvas.clipRect(rectF);
268 |
269 | rectF.right = width;
270 | canvas.drawArc(rectF, -90, 180, true, fillPaint);
271 |
272 | } else {
273 |
274 | if (fillWidth <= radius * 2) {
275 | rectF.right = fillWidth;
276 | canvas.clipRect(rectF);
277 | rectF.right = radius * 2;
278 | canvas.drawRoundRect(rectF, radius, radius, fillPaint);
279 | } else {
280 | rectF.right = fillWidth;
281 | canvas.drawRoundRect(rectF, radius, radius, fillPaint);
282 | }
283 | }
284 |
285 | }
286 | } finally {
287 | canvas.restore();
288 | }
289 | }
290 |
291 | }
292 |
--------------------------------------------------------------------------------
/library/src/main/java/com/liulishuo/magicprogresswidget/MagicProgressCircle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 LingoChamp Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.liulishuo.magicprogresswidget;
17 |
18 | import android.annotation.SuppressLint;
19 | import android.annotation.TargetApi;
20 | import android.content.Context;
21 | import android.content.res.TypedArray;
22 | import android.graphics.Canvas;
23 | import android.graphics.Paint;
24 | import android.graphics.RectF;
25 | import android.graphics.SweepGradient;
26 | import android.os.Build;
27 | import android.util.AttributeSet;
28 | import android.view.View;
29 |
30 | import java.lang.ref.WeakReference;
31 |
32 | import cn.dreamtobe.percentsmoothhandler.ISmoothTarget;
33 | import cn.dreamtobe.percentsmoothhandler.SmoothHandler;
34 |
35 |
36 | /**
37 | * Created by Jacksgong on 12/8/15.
38 | */
39 | public class MagicProgressCircle extends View implements ISmoothTarget {
40 |
41 | // ColorInt
42 | private int startColor;
43 | // ColorInt
44 | private int endColor;
45 | // ColorInt
46 | private int defaultColor;
47 |
48 | private int percentEndColor;
49 |
50 | private int strokeWidth;
51 | private float percent;
52 |
53 | // 用于渐变
54 | private Paint paint;
55 |
56 | private SmoothHandler smoothHandler;
57 |
58 | private boolean isFootOverHead;
59 |
60 | public MagicProgressCircle(Context context) {
61 | super(context);
62 | init(context, null);
63 | }
64 |
65 | public MagicProgressCircle(Context context, AttributeSet attrs) {
66 | super(context, attrs);
67 | init(context, attrs);
68 | }
69 |
70 | public MagicProgressCircle(Context context, AttributeSet attrs, int defStyleAttr) {
71 | super(context, attrs, defStyleAttr);
72 | init(context, attrs);
73 | }
74 |
75 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
76 | public MagicProgressCircle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
77 | super(context, attrs, defStyleAttr, defStyleRes);
78 | init(context, attrs);
79 | }
80 |
81 |
82 | private void init(final Context context, final AttributeSet attrs) {
83 | float defaultPercent = -1;
84 | if (isInEditMode()) {
85 | defaultPercent = 0.6f;
86 | }
87 |
88 | do {
89 | final int strokeWdithDefaultValue = (int) (18 * getResources().getDisplayMetrics().density + 0.5f);
90 | if (context == null || attrs == null) {
91 | strokeWidth = strokeWdithDefaultValue;
92 | percent = defaultPercent;
93 | startColor = getResources().getColor(R.color.mpc_start_color);
94 | endColor = getResources().getColor(R.color.mpc_end_color);
95 | defaultColor = getResources().getColor(R.color.mpc_default_color);
96 | break;
97 | }
98 |
99 | TypedArray typedArray = null;
100 | try {
101 | typedArray = context.obtainStyledAttributes(attrs, R.styleable.MagicProgressCircle);
102 | percent = typedArray.getFloat(R.styleable.MagicProgressCircle_mpc_percent, defaultPercent);
103 | strokeWidth = (int) typedArray.getDimension(R.styleable.MagicProgressCircle_mpc_stroke_width, strokeWdithDefaultValue);
104 | startColor = typedArray.getColor(R.styleable.MagicProgressCircle_mpc_start_color, getResources().getColor(R.color.mpc_start_color));
105 | endColor = typedArray.getColor(R.styleable.MagicProgressCircle_mpc_end_color, getResources().getColor(R.color.mpc_end_color));
106 | defaultColor = typedArray.getColor(R.styleable.MagicProgressCircle_mpc_default_color, getResources().getColor(R.color.mpc_default_color));
107 | isFootOverHead = typedArray.getBoolean(R.styleable.MagicProgressCircle_mpc_foot_over_head, false);
108 | } finally {
109 | if (typedArray != null) {
110 | typedArray.recycle();
111 | }
112 | }
113 |
114 |
115 | } while (false);
116 |
117 | paint = new Paint();
118 | paint.setAntiAlias(true);
119 | paint.setStrokeWidth(strokeWidth);
120 | paint.setStyle(Paint.Style.STROKE);
121 | paint.setStrokeJoin(Paint.Join.ROUND);
122 | paint.setStrokeCap(Paint.Cap.ROUND);
123 |
124 | startPaint = new Paint();
125 | startPaint.setColor(startColor);
126 | startPaint.setAntiAlias(true);
127 | startPaint.setStyle(Paint.Style.FILL);
128 |
129 |
130 | endPaint = new Paint();
131 | endPaint.setAntiAlias(true);
132 | endPaint.setStyle(Paint.Style.FILL);
133 |
134 | refreshDelta();
135 |
136 |
137 | customColors = new int[]{startColor, percentEndColor, defaultColor, defaultColor};
138 | fullColors = new int[]{startColor, endColor};
139 | emptyColors = new int[]{defaultColor, defaultColor};
140 |
141 | customPositions = new float[4];
142 | customPositions[0] = 0;
143 | customPositions[3] = 1;
144 |
145 | extremePositions = new float[]{0, 1};
146 | }
147 |
148 | private void refreshDelta() {
149 | int endR = (endColor & 0xFF0000) >> 16;
150 | int endG = (endColor & 0xFF00) >> 8;
151 | int endB = (endColor & 0xFF);
152 |
153 | this.startR = (startColor & 0xFF0000) >> 16;
154 | this.startG = (startColor & 0xFF00) >> 8;
155 | this.startB = (startColor & 0xFF);
156 |
157 | deltaR = endR - startR;
158 | deltaG = endG - startG;
159 | deltaB = endB - startB;
160 | }
161 |
162 | /**
163 | * @param percent FloatRange(from = 0.0, to = 1.0)
164 | */
165 | public void setPercent(float percent) {
166 | percent = Math.min(1, percent);
167 | percent = Math.max(0, percent);
168 |
169 | if (smoothHandler != null) {
170 | smoothHandler.commitPercent(percent);
171 | }
172 |
173 | if (this.percent != percent) {
174 | this.percent = percent;
175 | invalidate();
176 | }
177 |
178 | }
179 |
180 | @Override
181 | public void setSmoothPercent(float percent) {
182 | getSmoothHandler().loopSmooth(percent);
183 | }
184 |
185 | @Override
186 | public void setSmoothPercent(float percent, long durationMillis) {
187 | getSmoothHandler().loopSmooth(percent, durationMillis);
188 | }
189 |
190 | private SmoothHandler getSmoothHandler() {
191 | if (smoothHandler == null) {
192 | smoothHandler = new SmoothHandler(new WeakReference(this));
193 | }
194 | return smoothHandler;
195 | }
196 |
197 | public float getPercent() {
198 | return this.percent;
199 | }
200 |
201 | /**
202 | * @param color ColorInt
203 | */
204 | public void setStartColor(final int color) {
205 | if (this.startColor != color) {
206 | this.startColor = color;
207 | // delta变化
208 | refreshDelta();
209 |
210 | // 渐变前部分
211 | customColors[0] = color;
212 | // 前半圆
213 | startPaint.setColor(color);
214 | // 全满时 渐变起点
215 | fullColors[0] = color;
216 |
217 | invalidate();
218 | }
219 | }
220 |
221 | public int getStartColor() {
222 | return this.startColor;
223 | }
224 |
225 | /**
226 | * @param color ColorInt
227 | */
228 | public void setEndColor(final int color) {
229 | if (this.endColor != color) {
230 | this.endColor = color;
231 | // delta变化
232 | refreshDelta();
233 |
234 | // 渐变后部分 动态计算#draw
235 | // 后半圆 需要动态计算#draw,在某些情况下没有
236 |
237 | // 全满时 渐变结束
238 | fullColors[1] = color;
239 |
240 |
241 | invalidate();
242 | }
243 | }
244 |
245 | public int getEndColor() {
246 | return this.endColor;
247 | }
248 |
249 | /**
250 | * @param color ColorInt
251 | */
252 | public void setDefaultColor(final int color) {
253 | if (this.defaultColor != color) {
254 | this.defaultColor = color;
255 |
256 | // 渐变后半部分
257 | customColors[2] = color;
258 | customColors[3] = color;
259 |
260 | // percent = 0
261 | emptyColors[0] = color;
262 | emptyColors[1] = color;
263 |
264 | invalidate();
265 | }
266 | }
267 |
268 | public int getDefaultColor() {
269 | return this.defaultColor;
270 | }
271 |
272 | /**
273 | * @param width px
274 | */
275 | public void setStrokeWidth(final int width) {
276 | if (this.strokeWidth != width) {
277 | this.strokeWidth = width;
278 | // 画描边的描边变化
279 | paint.setStrokeWidth(width);
280 |
281 | // 会影响measure
282 | requestLayout();
283 | }
284 | }
285 |
286 | public int getStrokeWidth() {
287 | return this.strokeWidth;
288 | }
289 |
290 | /**
291 | * @param footOverHead Boolean
292 | */
293 | public void setFootOverHead(boolean footOverHead) {
294 | if (this.isFootOverHead != footOverHead) {
295 | this.isFootOverHead = footOverHead;
296 | invalidate();
297 | }
298 | }
299 |
300 | public boolean isFootOverHead() {
301 | return isFootOverHead;
302 | }
303 |
304 | private int deltaR, deltaB, deltaG;
305 | private int startR, startB, startG;
306 |
307 | private void calculatePercentEndColor(final float percent) {
308 | percentEndColor = ((int) (deltaR * percent + startR) << 16) +
309 | ((int) (deltaG * percent + startG) << 8) +
310 | ((int) (deltaB * percent + startB)) + 0xFF000000;
311 | }
312 |
313 | @Override
314 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
315 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
316 |
317 | this.rectF.left = getMeasuredWidth() / 2 - strokeWidth / 2;
318 | this.rectF.top = 0;
319 | this.rectF.right = getMeasuredWidth() / 2 + strokeWidth / 2;
320 | this.rectF.bottom = strokeWidth;
321 | }
322 |
323 | private Paint startPaint;
324 | private Paint endPaint;
325 |
326 |
327 | private final RectF rectF = new RectF();
328 |
329 | private int[] customColors;
330 | private int[] fullColors;
331 | private int[] emptyColors;
332 | private float[] customPositions;
333 | private float[] extremePositions;
334 |
335 |
336 | // 目前由于SweepGradient赋值只在构造函数,无法pre allocate & reuse instead
337 | @SuppressLint("DrawAllocation")
338 | @Override
339 | protected void onDraw(Canvas canvas) {
340 | super.onDraw(canvas);
341 |
342 | final int restore = canvas.save();
343 |
344 | final int cx = getMeasuredWidth() / 2;
345 | final int cy = getMeasuredHeight() / 2;
346 | final int radius = getMeasuredWidth() / 2 - strokeWidth / 2;
347 |
348 | float drawPercent = percent;
349 | if (drawPercent > 0.97 && drawPercent < 1) {
350 | // 设计师说这样比较好
351 | drawPercent = 0.97f;
352 | }
353 |
354 | // 画渐变圆
355 | canvas.save();
356 | canvas.rotate(-90, cx, cy);
357 | int[] colors;
358 | float[] positions;
359 | if (drawPercent < 1 && drawPercent > 0) {
360 | calculatePercentEndColor(drawPercent);
361 | customColors[1] = percentEndColor;
362 | colors = customColors;
363 | customPositions[1] = drawPercent;
364 | customPositions[2] = drawPercent;
365 | positions = customPositions;
366 | } else if (drawPercent == 1) {
367 | percentEndColor = endColor;
368 | colors = fullColors;
369 | positions = extremePositions;
370 | } else {
371 | // <= 0 || > 1?
372 | colors = emptyColors;
373 | positions = extremePositions;
374 | }
375 | final SweepGradient sweepGradient = new SweepGradient(getMeasuredWidth() / 2, getMeasuredHeight() / 2, colors, positions);
376 | paint.setShader(sweepGradient);
377 | canvas.drawCircle(cx, cy, radius, paint);
378 | canvas.restore();
379 |
380 | if (drawPercent > 0) {
381 | // 绘制结束的半圆
382 | if (drawPercent < 1 || (isFootOverHead && drawPercent == 1)) {
383 | canvas.save();
384 | endPaint.setColor(percentEndColor);
385 | canvas.rotate((int) Math.floor(360.0f * drawPercent) - 1, cx, cy);
386 | canvas.drawArc(rectF, -90f, 180f, true, endPaint);
387 | canvas.restore();
388 | }
389 | if (!isFootOverHead || drawPercent < 1) {
390 | canvas.save();
391 | // 绘制开始的半圆
392 | canvas.drawArc(rectF, 90f, 180f, true, startPaint);
393 | canvas.restore();
394 | }
395 | }
396 |
397 |
398 | canvas.restoreToCount(restore);
399 |
400 | }
401 | }
402 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FF00FFED
4 | #FFED00FF
5 |
6 | #1AFFFFFF
7 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':demo', ':library'
2 |
--------------------------------------------------------------------------------