├── .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 | 15 | 16 | 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 | 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 |