├── .gitignore ├── LICENSE ├── README.md ├── art ├── app_icon.zip ├── app_icon_base.png ├── app_icon_base.sh └── app_icon_base.svg ├── build.gradle ├── gradle-mvn-push.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── me │ │ └── zhanghai │ │ └── android │ │ └── materialprogressbar │ │ ├── AnimationScaleIndeterminateCircularProgressDrawable.java │ │ ├── Animators.java │ │ ├── BaseDrawable.java │ │ ├── BaseIndeterminateProgressDrawable.java │ │ ├── BasePaintDrawable.java │ │ ├── BaseProgressDrawable.java │ │ ├── BaseProgressLayerDrawable.java │ │ ├── BaseSingleCircularProgressDrawable.java │ │ ├── BaseSingleHorizontalProgressDrawable.java │ │ ├── CircularProgressBackgroundDrawable.java │ │ ├── CircularProgressDrawable.java │ │ ├── HorizontalProgressBackgroundDrawable.java │ │ ├── HorizontalProgressDrawable.java │ │ ├── IndeterminateCircularProgressDrawable.java │ │ ├── IndeterminateHorizontalProgressDrawable.java │ │ ├── Interpolators.java │ │ ├── IntrinsicPaddingDrawable.java │ │ ├── MaterialProgressBar.java │ │ ├── MaterialProgressDrawable.java │ │ ├── ShowBackgroundDrawable.java │ │ ├── SingleCircularProgressDrawable.java │ │ ├── SingleHorizontalProgressDrawable.java │ │ ├── StaticIndeterminateCircularProgressDrawable.java │ │ ├── TintableDrawable.java │ │ └── internal │ │ ├── AnimationScaleListDrawableCompat.java │ │ ├── DrawableCompat.java │ │ ├── DrawableContainerCompat.java │ │ ├── ObjectAnimatorCompat.java │ │ ├── ObjectAnimatorCompatBase.java │ │ ├── ObjectAnimatorCompatLollipop.java │ │ ├── ThemeUtils.java │ │ └── ValueAnimatorCompat.java │ └── res │ └── values │ ├── attrs.xml │ └── styles.xml ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── me │ │ └── zhanghai │ │ └── android │ │ └── materialprogressbar │ │ └── sample │ │ ├── AboutActivity.java │ │ ├── Animators.java │ │ ├── AppUtils.java │ │ ├── DeterminateCircularSampleActivity.java │ │ └── MainActivity.java │ ├── launcher_icon-web.png │ └── res │ ├── layout │ ├── about_activity.xml │ ├── determinate_circular_sample_activity.xml │ └── main_activity.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── launcher_icon.png │ ├── mipmap-mdpi │ └── launcher_icon.png │ ├── mipmap-xhdpi │ └── launcher_icon.png │ ├── mipmap-xxhdpi │ └── launcher_icon.png │ ├── mipmap-xxxhdpi │ └── launcher_icon.png │ ├── values-sw600dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── screenshot ├── android_4_4_4.png ├── android_4_4_4_raw.png ├── android_5_0_1_samsung.png ├── android_5_0_1_samsung_raw.png ├── android_5_1_1.png ├── android_5_1_1_raw.png ├── android_6_0_1.png └── android_6_0_1_raw.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle/ 2 | /.idea/ 3 | /build/ 4 | /captures/ 5 | /local.properties 6 | .DS_Store 7 | *.iml 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2015 Hai Zhang 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MaterialProgressBar 2 | 3 | ![Icon](sample/src/main/launcher_icon-web.png) 4 | 5 | Material Design `ProgressBar` with consistent appearance on Android 4.0+. 6 | 7 | ## Why MaterialProgressBar? 8 | 9 | - Consistent appearance on Android 4.0+. 10 | - Correct tinting across platforms. 11 | - Able to remove the intrinsic padding of framework `ProgressBar`. 12 | - Able to hide the progress background of framework horizontal `ProgressBar`. 13 | - Able to show a determinate circular progress. 14 | - Used as a drop-in replacement for framework `ProgressBar`. 15 | 16 | ## Preview 17 | 18 | Google Play 19 | 20 | [Sample APK](//github.com/zhanghai/MaterialProgressBar/releases/download/v1.6.1/sample-release.apk) 21 | 22 | Android 4.4.4 23 | 24 | ![Android 4.4.4](screenshot/android_4_4_4.png) 25 | 26 | Samsung Android 5.0.1 (native implementation fails to tint) 27 | 28 | ![Samsung Android 5.0.1](screenshot/android_5_0_1_samsung.png) 29 | 30 | Android 6.0.1 31 | 32 | ![Android 6.0.1](screenshot/android_6_0_1.png) 33 | 34 | ## Integration 35 | 36 | Gradle: 37 | 38 | ```gradle 39 | implementation 'me.zhanghai.android.materialprogressbar:library:1.6.1' 40 | ``` 41 | 42 | ## Usage 43 | 44 | You can either simply use the [`MaterialProgressBar`](library/src/main/java/me/zhanghai/android/materialprogressbar/MaterialProgressBar.java) widget, or set drawables from this library on a regular `ProgressBar`. 45 | 46 | ### Using Widget 47 | 48 | Simply replace your `ProgressBar` with `MaterialProgressBar`, and remember to apply corresponding style and attribute for correct behavior. 49 | 50 | For example, to create an indeterminate horizontal `MaterialProgressBar`: 51 | 52 | ```xml 53 | 59 | ``` 60 | 61 | In order to make your `ProgressBar` take the correct and consistent size on all versions, you will always need to use one of the styles from this library. The trick inside it is `android:minWidth`, `android:maxWidth` (and height) that controls the drawable size. 62 | 63 | - `Widget.MaterialProgressBar.ProgressBar` 64 | - `Widget.MaterialProgressBar.ProgressBar.Horizontal` 65 | - And more size and no-padding variants in [styles.xml](library/src/main/res/values/styles.xml) 66 | 67 | Available custom attributes: 68 | 69 | - `app:mpb_progressStyle`: Style of progress drawable: `circular` or `horizontal`. Defaults to `circular`. 70 | - `app:mpb_setBothDrawables`: Whether both determinate and indeterminate drawables should be set on this progress bar. Defaults to `false` (for performance). Should be set to `true` if you want to use both of the backported determinate and indeterminate drawables. 71 | - `app:mpb_useIntrinsicPadding`: Whether progress drawable should use its intrinsic padding. Defaults to `true`. 72 | - `app:mpb_showProgressBackground`: Whether progress drawable should show a progress background. Defaults to `true` for horizontal progress drawable, `false` otherwise. 73 | - `app:mpb_determinateCircularProgressStyle`: Style of determinate circular progress drawable: normal or dynamic. Defaults to `normal`. 74 | 75 | 8 tint-related attributes such as `app:mpb_progressTint` and `app:mpb_progressTintMode` are also supported so that they can control the tinting of progress drawables. The default tint color is `?colorControlActivated`, and the default tint mode is `src_in`. 76 | 77 | For a detailed example, you can refer to the [sample app's layout](//github.com/zhanghai/MaterialProgressBar/blob/master/sample/src/main/res/layout/main_activity.xml), where you can find examples such as removing progress padding or background. 78 | 79 | ### Using Drawable 80 | 81 | Three Material Design drawables are backported to Android 4.0 (API 14), so you can create one and set it directly on your `ProgressBar`. 82 | 83 | - [`HorizontalProgressDrawable`](library/src/main/java/me/zhanghai/android/materialprogressbar/HorizontalProgressDrawable.java) 84 | - [`IndeterminateHorizontalProgressDrawable`](library/src/main/java/me/zhanghai/android/materialprogressbar/IndeterminateHorizontalProgressDrawable.java) 85 | - [`CircularProgressDrawable`](library/src/main/java/me/zhanghai/android/materialprogressbar/CircularProgressDrawable.java) 86 | - [`IndeterminateCircularProgressDrawable`](library/src/main/java/me/zhanghai/android/materialprogressbar/IndeterminateCircularProgressDrawable.java) 87 | 88 | For example, to set a `IndeterminateHorizontalProgressDrawable` on a `ProgressBar`. 89 | 90 | ```java 91 | progressBar.setIndeterminateDrawable(new IndeterminateHorizontalProgressDrawable(this)); 92 | ``` 93 | 94 | You will also need to set a style from this library as in the section above. 95 | 96 | For example, to define an indeterminate horizontal `ProgressBar`. 97 | 98 | ```xml 99 | 105 | ``` 106 | 107 | Don't forget to create and set the drawable as above. 108 | 109 | You can also customize the behavior of these drawables by calling `setShowBackground()` and `setUseIntrinsicPadding()`. Tint-related methods `setTint()`, `setTintList()` and `setTintMode()` are also backported so that you can use them directly, but remember to take these drawables as their actual type or `TintableDrawable` because VM won't be able to find these methods on `Drawable` for legacy platforms. 110 | 111 | If you want to support API level < 18, you'll need to workaround a canvas limitation as in [here](https://github.com/zhanghai/MaterialProgressBar/blob/0eee874b6fbd109eda2be01b7887647e589dcd9d/library/src/main/java/me/zhanghai/android/materialprogressbar/MaterialProgressBar.java#L122); Using `MaterialProgressBar` does this automatically. 112 | 113 | For a detailed example, you can refer to the `onCreate()` method of the old sample's [`MainActivity`](//github.com/zhanghai/MaterialProgressBar/blob/7529ea854a04207fcbf768aa574110e49c511867/sample/src/main/java/me/zhanghai/android/materialprogressbar/sample/MainActivity.java) and its layout [main_activity.xml](//github.com/zhanghai/MaterialProgressBar/blob/7529ea854a04207fcbf768aa574110e49c511867/sample/src/main/res/layout/main_activity.xml). 114 | 115 | ## ProGuard 116 | 117 | The AAR of this library has already included a ProGuard configuration file to make `ObjectAnimator` work properly. 118 | 119 | ## Older versions 120 | 121 | Neither Support v4 nor AppCompat v7 backported animation API to versions prior to ICS, and the [NineOldAndroids](https://github.com/JakeWharton/NineOldAndroids/) library has already been deprecated since people should all be using `minSdkVersion="14"` now, so versions older than ICS are not supported. 122 | 123 | ## License 124 | 125 | Copyright 2015 Hai Zhang 126 | 127 | Licensed under the Apache License, Version 2.0 (the "License"); 128 | you may not use this file except in compliance with the License. 129 | You may obtain a copy of the License at 130 | 131 | http://www.apache.org/licenses/LICENSE-2.0 132 | 133 | Unless required by applicable law or agreed to in writing, software 134 | distributed under the License is distributed on an "AS IS" BASIS, 135 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136 | See the License for the specific language governing permissions and 137 | limitations under the License. 138 | -------------------------------------------------------------------------------- /art/app_icon.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanghai/MaterialProgressBar/2b39099237bb265b6a20357470e6cecf6e3112b2/art/app_icon.zip -------------------------------------------------------------------------------- /art/app_icon_base.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanghai/MaterialProgressBar/2b39099237bb265b6a20357470e6cecf6e3112b2/art/app_icon_base.png -------------------------------------------------------------------------------- /art/app_icon_base.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | inkscape --export-png="./app_icon.png" --export-width="512" --export-height="512" app_icon.svg 3 | -------------------------------------------------------------------------------- /art/app_icon_base.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.3.1' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | version = VERSION_NAME 18 | group = GROUP 19 | repositories { 20 | jcenter() 21 | google() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /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 | 20 | def isReleaseBuild() { 21 | return VERSION_NAME.contains("SNAPSHOT") == false 22 | } 23 | 24 | def getReleaseRepositoryUrl() { 25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL 26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 27 | } 28 | 29 | def getSnapshotRepositoryUrl() { 30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL 31 | : "https://oss.sonatype.org/content/repositories/snapshots/" 32 | } 33 | 34 | def getRepositoryUsername() { 35 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" 36 | } 37 | 38 | def getRepositoryPassword() { 39 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : 40 | System.console() != null ? System.console().readLine("\nNexus password: ") : "" 41 | } 42 | 43 | afterEvaluate { project -> 44 | uploadArchives { 45 | repositories { 46 | mavenDeployer { 47 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 48 | 49 | pom.groupId = GROUP 50 | pom.artifactId = POM_ARTIFACT_ID 51 | pom.version = VERSION_NAME 52 | 53 | repository(url: getReleaseRepositoryUrl()) { 54 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 55 | } 56 | snapshotRepository(url: getSnapshotRepositoryUrl()) { 57 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 58 | } 59 | 60 | pom.project { 61 | name POM_NAME 62 | packaging POM_PACKAGING 63 | description POM_DESCRIPTION 64 | url POM_URL 65 | 66 | scm { 67 | url POM_SCM_URL 68 | connection POM_SCM_CONNECTION 69 | developerConnection POM_SCM_DEV_CONNECTION 70 | } 71 | 72 | licenses { 73 | license { 74 | name POM_LICENCE_NAME 75 | url POM_LICENCE_URL 76 | distribution POM_LICENCE_DIST 77 | } 78 | } 79 | 80 | developers { 81 | developer { 82 | id POM_DEVELOPER_ID 83 | name POM_DEVELOPER_NAME 84 | } 85 | } 86 | } 87 | } 88 | } 89 | } 90 | 91 | signing { 92 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 93 | sign configurations.archives 94 | } 95 | 96 | gradle.taskGraph.whenReady { taskGraph -> 97 | if (taskGraph.allTasks.any { it instanceof Sign }) { 98 | allprojects { 99 | ext."signing.password" = System.console() != null ? System.console().readLine("\nPGP private key password: ") : "" 100 | } 101 | } 102 | } 103 | 104 | task androidJavadocs(type: Javadoc) { 105 | source = android.sourceSets.main.java.srcDirs 106 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 107 | classpath += configurations.compile 108 | } 109 | 110 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 111 | classifier = 'javadoc' 112 | from androidJavadocs.destinationDir 113 | } 114 | 115 | task androidSourcesJar(type: Jar) { 116 | classifier = 'sources' 117 | from android.sourceSets.main.java.sourceFiles 118 | } 119 | 120 | artifacts { 121 | archives androidSourcesJar 122 | archives androidJavadocsJar 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useAndroidX=true 21 | android.enableJetifier=true 22 | 23 | VERSION_NAME=1.6.1 24 | VERSION_CODE=19 25 | GROUP=me.zhanghai.android.materialprogressbar 26 | 27 | POM_DESCRIPTION=A Material Design ProgressBar with consistent appearance 28 | POM_URL=https://github.com/zhanghai/MaterialProgressBar 29 | POM_SCM_URL=https://github.com/zhanghai/MaterialProgressBar 30 | POM_SCM_CONNECTION=scm:git@github.com:zhanghai/MaterialProgressBar.git 31 | POM_SCM_DEV_CONNECTION=scm:git@github.com:zhanghai/MaterialProgressBar.git 32 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 33 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 34 | POM_LICENCE_DIST=repo 35 | POM_DEVELOPER_ID=zhanghai 36 | POM_DEVELOPER_NAME=Zhang Hai 37 | 38 | ANDROID_MIN_SDK_VERSION=14 39 | ANDROID_COMPILE_SDK_VERSION=28 40 | ANDROID_BUILD_TOOLS_VERSION=28.0.3 41 | ANDROID_TARGET_SDK_VERSION=28 42 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanghai/MaterialProgressBar/2b39099237bb265b6a20357470e6cecf6e3112b2/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Feb 24 16:53:08 PST 2019 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.10.1-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 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /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/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | 5 | compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION) 6 | buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION 7 | 8 | defaultConfig { 9 | minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK_VERSION) 10 | targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION) 11 | versionCode Integer.parseInt(project.VERSION_CODE) 12 | versionName project.VERSION_NAME 13 | consumerProguardFiles 'proguard-rules.pro' 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | implementation 'androidx.appcompat:appcompat:1.0.2' 26 | implementation 'androidx.annotation:annotation:1.0.1' 27 | } 28 | 29 | apply from: '../gradle-mvn-push.gradle' 30 | 31 | // HACK: We are referencing our dependencies in JavaDoc. This hack fixes the classpath for the 32 | // androidJavadocs task. 33 | afterEvaluate { 34 | androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile 35 | .classpath 36 | } 37 | -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=MaterialProgressBar Library 2 | POM_ARTIFACT_ID=library 3 | POM_PACKAGING=aar 4 | -------------------------------------------------------------------------------- /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 /opt/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | -keep class me.zhanghai.android.materialprogressbar.** { *; } 20 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/AnimationScaleIndeterminateCircularProgressDrawable.java: -------------------------------------------------------------------------------- 1 | package me.zhanghai.android.materialprogressbar; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | 6 | import androidx.annotation.NonNull; 7 | import me.zhanghai.android.materialprogressbar.internal.AnimationScaleListDrawableCompat; 8 | 9 | public class AnimationScaleIndeterminateCircularProgressDrawable 10 | extends AnimationScaleListDrawableCompat implements MaterialProgressDrawable, 11 | IntrinsicPaddingDrawable, TintableDrawable { 12 | 13 | public AnimationScaleIndeterminateCircularProgressDrawable(@NonNull Context context) { 14 | super(new Drawable[] { 15 | new StaticIndeterminateCircularProgressDrawable(context), 16 | new IndeterminateCircularProgressDrawable(context) 17 | }); 18 | } 19 | 20 | @Override 21 | public boolean getUseIntrinsicPadding() { 22 | return getIntrinsicPaddingDrawable().getUseIntrinsicPadding(); 23 | } 24 | 25 | @Override 26 | public void setUseIntrinsicPadding(boolean useIntrinsicPadding) { 27 | getIntrinsicPaddingDrawable().setUseIntrinsicPadding(useIntrinsicPadding); 28 | } 29 | 30 | @NonNull 31 | private IntrinsicPaddingDrawable getIntrinsicPaddingDrawable() { 32 | return (IntrinsicPaddingDrawable) getCurrent(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/Animators.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.animation.Animator; 9 | import android.animation.AnimatorSet; 10 | import android.animation.ObjectAnimator; 11 | import android.animation.ValueAnimator; 12 | import android.annotation.SuppressLint; 13 | import android.graphics.Path; 14 | 15 | import androidx.annotation.NonNull; 16 | import me.zhanghai.android.materialprogressbar.internal.ObjectAnimatorCompat; 17 | 18 | /** 19 | * Animators backported for Drawables in this library. 20 | */ 21 | class Animators { 22 | 23 | private Animators() {} 24 | 25 | // M -522.59998,0 26 | // c 48.89972,0 166.02656,0 301.21729,0 27 | // c 197.58128,0 420.9827,0 420.9827,0 28 | private static final Path PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X; 29 | static { 30 | PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X = new Path(); 31 | PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X.moveTo(-522.59998f, 0); 32 | PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X.rCubicTo(48.89972f, 0, 166.02656f, 33 | 0, 301.21729f, 0); 34 | PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X.rCubicTo(197.58128f, 0, 420.9827f, 35 | 0, 420.9827f, 0); 36 | } 37 | 38 | // M 0 0.1 39 | // L 1 0.826849212646 40 | // L 2 0.1 41 | private static final Path PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X; 42 | static { 43 | PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X = new Path(); 44 | PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X.moveTo(0, 0.1f); 45 | PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X.lineTo(1, 0.826849212646f); 46 | PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X.lineTo(2, 0.1f); 47 | } 48 | 49 | // M -197.60001,0 50 | // c 14.28182,0 85.07782,0 135.54689,0 51 | // c 54.26191,0 90.42461,0 168.24331,0 52 | // c 144.72154,0 316.40982,0 316.40982,0 53 | private static final Path PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X; 54 | static { 55 | PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X = new Path(); 56 | PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X.moveTo(-197.60001f, 0); 57 | PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X.rCubicTo(14.28182f, 0, 85.07782f, 0, 58 | 135.54689f, 0); 59 | PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X.rCubicTo(54.26191f, 0, 90.42461f, 0, 60 | 168.24331f, 0); 61 | PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X.rCubicTo(144.72154f, 0, 316.40982f, 0, 62 | 316.40982f, 0); 63 | } 64 | 65 | // M 0.0,0.1 66 | // L 1.0,0.571379510698 67 | // L 2.0,0.909950256348 68 | // L 3.0,0.1 69 | private static final Path PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X; 70 | static { 71 | PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X = new Path(); 72 | PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X.moveTo(0, 0.1f); 73 | PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X.lineTo(1, 0.571379510698f); 74 | PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X.lineTo(2, 0.909950256348f); 75 | PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X.lineTo(3, 0.1f); 76 | } 77 | 78 | /** 79 | * Create a backported Animator for 80 | * {@code @android:anim/progress_indeterminate_horizontal_rect1}. 81 | * 82 | * @param target The object whose properties are to be animated. 83 | * @return An Animator object that is set up to behave the same as the its native counterpart. 84 | */ 85 | @NonNull 86 | public static Animator createIndeterminateHorizontalRect1(@NonNull Object target) { 87 | 88 | ObjectAnimator translateXAnimator = ObjectAnimatorCompat.ofFloat(target, "translateX", null, 89 | PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X); 90 | translateXAnimator.setDuration(2000); 91 | translateXAnimator.setInterpolator( 92 | Interpolators.INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X.INSTANCE); 93 | translateXAnimator.setRepeatCount(ValueAnimator.INFINITE); 94 | 95 | ObjectAnimator scaleXAnimator = ObjectAnimatorCompat.ofFloat(target, null, "scaleX", 96 | PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X); 97 | scaleXAnimator.setDuration(2000); 98 | scaleXAnimator.setInterpolator( 99 | Interpolators.INDETERMINATE_HORIZONTAL_RECT1_SCALE_X.INSTANCE); 100 | scaleXAnimator.setRepeatCount(ValueAnimator.INFINITE); 101 | 102 | AnimatorSet animatorSet = new AnimatorSet(); 103 | animatorSet.playTogether(translateXAnimator, scaleXAnimator); 104 | return animatorSet; 105 | } 106 | 107 | /** 108 | * Create a backported Animator for 109 | * {@code @android:anim/progress_indeterminate_horizontal_rect2}. 110 | * 111 | * @param target The object whose properties are to be animated. 112 | * @return An Animator object that is set up to behave the same as the its native counterpart. 113 | */ 114 | @NonNull 115 | public static Animator createIndeterminateHorizontalRect2(@NonNull Object target) { 116 | 117 | ObjectAnimator translateXAnimator = ObjectAnimatorCompat.ofFloat(target, "translateX", null, 118 | PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X); 119 | translateXAnimator.setDuration(2000); 120 | translateXAnimator.setInterpolator( 121 | Interpolators.INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X.INSTANCE); 122 | translateXAnimator.setRepeatCount(ValueAnimator.INFINITE); 123 | 124 | ObjectAnimator scaleXAnimator = ObjectAnimatorCompat.ofFloat(target, null, "scaleX", 125 | PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X); 126 | scaleXAnimator.setDuration(2000); 127 | scaleXAnimator.setInterpolator( 128 | Interpolators.INDETERMINATE_HORIZONTAL_RECT2_SCALE_X.INSTANCE); 129 | scaleXAnimator.setRepeatCount(ValueAnimator.INFINITE); 130 | 131 | AnimatorSet animatorSet = new AnimatorSet(); 132 | animatorSet.playTogether(translateXAnimator, scaleXAnimator); 133 | return animatorSet; 134 | } 135 | 136 | /** 137 | * Create a backported Animator for {@code @android:anim/progress_indeterminate_material}. 138 | * 139 | * @param target The object whose properties are to be animated. 140 | * @return An Animator object that is set up to behave the same as the its native counterpart. 141 | */ 142 | @NonNull 143 | public static Animator createIndeterminate(@NonNull Object target) { 144 | 145 | @SuppressLint("ObjectAnimatorBinding") 146 | ObjectAnimator trimPathStartAnimator = ObjectAnimator.ofFloat(target, "trimPathStart", 0, 147 | 0.75f); 148 | trimPathStartAnimator.setDuration(1333); 149 | trimPathStartAnimator.setInterpolator(Interpolators.TRIM_PATH_START.INSTANCE); 150 | trimPathStartAnimator.setRepeatCount(ValueAnimator.INFINITE); 151 | 152 | @SuppressLint("ObjectAnimatorBinding") 153 | ObjectAnimator trimPathEndAnimator = ObjectAnimator.ofFloat(target, "trimPathEnd", 0, 154 | 0.75f); 155 | trimPathEndAnimator.setDuration(1333); 156 | trimPathEndAnimator.setInterpolator(Interpolators.TRIM_PATH_END.INSTANCE); 157 | trimPathEndAnimator.setRepeatCount(ValueAnimator.INFINITE); 158 | 159 | @SuppressLint("ObjectAnimatorBinding") 160 | ObjectAnimator trimPathOffsetAnimator = ObjectAnimator.ofFloat(target, "trimPathOffset", 0, 161 | 0.25f); 162 | trimPathOffsetAnimator.setDuration(1333); 163 | trimPathOffsetAnimator.setInterpolator(Interpolators.LINEAR.INSTANCE); 164 | trimPathOffsetAnimator.setRepeatCount(ValueAnimator.INFINITE); 165 | 166 | AnimatorSet animatorSet = new AnimatorSet(); 167 | animatorSet.playTogether(trimPathStartAnimator, trimPathEndAnimator, 168 | trimPathOffsetAnimator); 169 | return animatorSet; 170 | } 171 | 172 | /** 173 | * Create a backported Animator for 174 | * {@code @android:anim/progress_indeterminate_rotation_material}. 175 | * 176 | * @param target The object whose properties are to be animated. 177 | * @return An Animator object that is set up to behave the same as the its native counterpart. 178 | */ 179 | @NonNull 180 | public static Animator createIndeterminateRotation(@NonNull Object target) { 181 | @SuppressLint("ObjectAnimatorBinding") 182 | ObjectAnimator rotationAnimator = ObjectAnimator.ofFloat(target, "rotation", 0, 720); 183 | rotationAnimator.setDuration(6665); 184 | rotationAnimator.setInterpolator(Interpolators.LINEAR.INSTANCE); 185 | rotationAnimator.setRepeatCount(ValueAnimator.INFINITE); 186 | return rotationAnimator; 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/BaseDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.content.res.ColorStateList; 9 | import android.graphics.Canvas; 10 | import android.graphics.Color; 11 | import android.graphics.ColorFilter; 12 | import android.graphics.PixelFormat; 13 | import android.graphics.PorterDuff; 14 | import android.graphics.PorterDuffColorFilter; 15 | import android.graphics.Rect; 16 | import android.graphics.drawable.Drawable; 17 | 18 | import androidx.annotation.ColorInt; 19 | import androidx.annotation.IntRange; 20 | import androidx.annotation.NonNull; 21 | import androidx.annotation.Nullable; 22 | 23 | abstract class BaseDrawable extends Drawable implements TintableDrawable { 24 | 25 | @IntRange(from = 0, to = 255) 26 | protected int mAlpha = 255; 27 | @Nullable 28 | protected ColorFilter mColorFilter; 29 | @Nullable 30 | protected ColorStateList mTintList; 31 | @NonNull 32 | protected PorterDuff.Mode mTintMode = PorterDuff.Mode.SRC_IN; 33 | @Nullable 34 | protected PorterDuffColorFilter mTintFilter; 35 | 36 | @NonNull 37 | private final DummyConstantState mConstantState = new DummyConstantState(); 38 | 39 | @IntRange(from = 0, to = 255) 40 | @Override 41 | public int getAlpha() { 42 | return mAlpha; 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public void setAlpha(@IntRange(from = 0, to = 255) int alpha) { 50 | if (mAlpha != alpha) { 51 | mAlpha = alpha; 52 | invalidateSelf(); 53 | } 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Nullable 60 | @Override 61 | public ColorFilter getColorFilter() { 62 | return mColorFilter; 63 | } 64 | 65 | /** 66 | * {@inheritDoc} 67 | */ 68 | @Override 69 | public void setColorFilter(@Nullable ColorFilter colorFilter) { 70 | mColorFilter = colorFilter; 71 | invalidateSelf(); 72 | } 73 | 74 | /** 75 | * {@inheritDoc} 76 | */ 77 | @Override 78 | public void setTint(@ColorInt int tintColor) { 79 | setTintList(ColorStateList.valueOf(tintColor)); 80 | } 81 | 82 | /** 83 | * {@inheritDoc} 84 | */ 85 | @Override 86 | public void setTintList(@Nullable ColorStateList tint) { 87 | mTintList = tint; 88 | if (updateTintFilter()) { 89 | invalidateSelf(); 90 | } 91 | } 92 | 93 | /** 94 | * {@inheritDoc} 95 | */ 96 | @Override 97 | public void setTintMode(@NonNull PorterDuff.Mode tintMode) { 98 | mTintMode = tintMode; 99 | if (updateTintFilter()) { 100 | invalidateSelf(); 101 | } 102 | } 103 | 104 | @Override 105 | public boolean isStateful() { 106 | return mTintList != null && mTintList.isStateful(); 107 | } 108 | 109 | @Override 110 | protected boolean onStateChange(@NonNull int[] state) { 111 | return updateTintFilter(); 112 | } 113 | 114 | private boolean updateTintFilter() { 115 | 116 | if (mTintList == null || mTintMode == null) { 117 | boolean hadTintFilter = mTintFilter != null; 118 | mTintFilter = null; 119 | return hadTintFilter; 120 | } 121 | 122 | int tintColor = mTintList.getColorForState(getState(), Color.TRANSPARENT); 123 | // They made PorterDuffColorFilter.setColor() and setMode() @hide. 124 | mTintFilter = new PorterDuffColorFilter(tintColor, mTintMode); 125 | return true; 126 | } 127 | 128 | /** 129 | * {@inheritDoc} 130 | */ 131 | @Override 132 | public int getOpacity() { 133 | // Be safe. 134 | return PixelFormat.TRANSLUCENT; 135 | } 136 | 137 | /** 138 | * {@inheritDoc} 139 | */ 140 | @Override 141 | public void draw(@NonNull Canvas canvas) { 142 | 143 | Rect bounds = getBounds(); 144 | if (bounds.width() == 0 || bounds.height() == 0) { 145 | return; 146 | } 147 | 148 | int saveCount = canvas.save(); 149 | canvas.translate(bounds.left, bounds.top); 150 | onDraw(canvas, bounds.width(), bounds.height()); 151 | canvas.restoreToCount(saveCount); 152 | } 153 | 154 | @Nullable 155 | protected ColorFilter getColorFilterForDrawing() { 156 | return mColorFilter != null ? mColorFilter : mTintFilter; 157 | } 158 | 159 | protected abstract void onDraw(@NonNull Canvas canvas, int width, int height); 160 | 161 | // Workaround LayerDrawable.ChildDrawable which calls getConstantState().newDrawable() 162 | // without checking for null. 163 | // We are never inflated from XML so the protocol of ConstantState does not apply to us. In 164 | // order to make LayerDrawable happy, we return ourselves from DummyConstantState.newDrawable(). 165 | 166 | @NonNull 167 | @Override 168 | public ConstantState getConstantState() { 169 | return mConstantState; 170 | } 171 | 172 | private class DummyConstantState extends ConstantState { 173 | 174 | @Override 175 | public int getChangingConfigurations() { 176 | return 0; 177 | } 178 | 179 | @NonNull 180 | @Override 181 | public Drawable newDrawable() { 182 | return BaseDrawable.this; 183 | } 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/BaseIndeterminateProgressDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.animation.Animator; 9 | import android.annotation.SuppressLint; 10 | import android.content.Context; 11 | import android.graphics.Canvas; 12 | import android.graphics.Color; 13 | import android.graphics.drawable.Animatable; 14 | 15 | import androidx.annotation.NonNull; 16 | import me.zhanghai.android.materialprogressbar.internal.ThemeUtils; 17 | 18 | abstract class BaseIndeterminateProgressDrawable extends BaseProgressDrawable 19 | implements Animatable { 20 | 21 | @NonNull 22 | protected Animator[] mAnimators; 23 | 24 | @SuppressLint("NewApi") 25 | public BaseIndeterminateProgressDrawable(@NonNull Context context) { 26 | int controlActivatedColor = ThemeUtils.getColorFromAttrRes(R.attr.colorControlActivated, 27 | Color.BLACK, context); 28 | // setTint() has been overridden for compatibility; DrawableCompat won't work because 29 | // wrapped Drawable won't be Animatable. 30 | setTint(controlActivatedColor); 31 | } 32 | 33 | /** 34 | * {@inheritDoc} 35 | */ 36 | @Override 37 | public void draw(@NonNull Canvas canvas) { 38 | super.draw(canvas); 39 | 40 | if (isStarted()) { 41 | invalidateSelf(); 42 | } 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public void start() { 50 | 51 | if (isStarted()) { 52 | return; 53 | } 54 | 55 | for (Animator animator : mAnimators) { 56 | animator.start(); 57 | } 58 | invalidateSelf(); 59 | } 60 | 61 | private boolean isStarted() { 62 | for (Animator animator : mAnimators) { 63 | if (animator.isStarted()) { 64 | return true; 65 | } 66 | } 67 | return false; 68 | } 69 | 70 | /** 71 | * {@inheritDoc} 72 | */ 73 | @Override 74 | public void stop() { 75 | for (Animator animator : mAnimators) { 76 | animator.end(); 77 | } 78 | } 79 | 80 | /** 81 | * {@inheritDoc} 82 | */ 83 | @Override 84 | public boolean isRunning() { 85 | for (Animator animator : mAnimators) { 86 | if (animator.isRunning()) { 87 | return true; 88 | } 89 | } 90 | return false; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/BasePaintDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.graphics.Canvas; 9 | import android.graphics.Color; 10 | import android.graphics.Paint; 11 | 12 | import androidx.annotation.NonNull; 13 | import androidx.annotation.Nullable; 14 | 15 | abstract class BasePaintDrawable extends BaseDrawable { 16 | 17 | @Nullable 18 | private Paint mPaint; 19 | 20 | @Override 21 | protected final void onDraw(@NonNull Canvas canvas, int width, int height) { 22 | 23 | if (mPaint == null) { 24 | mPaint = new Paint(); 25 | mPaint.setAntiAlias(true); 26 | mPaint.setColor(Color.BLACK); 27 | onPreparePaint(mPaint); 28 | } 29 | mPaint.setAlpha(mAlpha); 30 | mPaint.setColorFilter(getColorFilterForDrawing()); 31 | 32 | onDraw(canvas, width, height, mPaint); 33 | } 34 | 35 | protected abstract void onPreparePaint(@NonNull Paint paint); 36 | 37 | protected abstract void onDraw(@NonNull Canvas canvas, int width, int height, 38 | @NonNull Paint paint); 39 | } 40 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/BaseProgressDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | abstract class BaseProgressDrawable extends BasePaintDrawable implements IntrinsicPaddingDrawable { 9 | 10 | protected boolean mUseIntrinsicPadding = true; 11 | 12 | /** 13 | * {@inheritDoc} 14 | */ 15 | @Override 16 | public boolean getUseIntrinsicPadding() { 17 | return mUseIntrinsicPadding; 18 | } 19 | 20 | /** 21 | * {@inheritDoc} 22 | */ 23 | @Override 24 | public void setUseIntrinsicPadding(boolean useIntrinsicPadding) { 25 | if (mUseIntrinsicPadding != useIntrinsicPadding) { 26 | mUseIntrinsicPadding = useIntrinsicPadding; 27 | invalidateSelf(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/BaseProgressLayerDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.annotation.SuppressLint; 9 | import android.content.Context; 10 | import android.content.res.ColorStateList; 11 | import android.graphics.Color; 12 | import android.graphics.PorterDuff; 13 | import android.graphics.drawable.Drawable; 14 | import android.graphics.drawable.LayerDrawable; 15 | import android.util.Log; 16 | 17 | import androidx.annotation.ColorInt; 18 | import androidx.annotation.FloatRange; 19 | import androidx.annotation.NonNull; 20 | import androidx.annotation.Nullable; 21 | import androidx.core.graphics.ColorUtils; 22 | import me.zhanghai.android.materialprogressbar.internal.ThemeUtils; 23 | 24 | class BaseProgressLayerDrawable< 25 | ProgressDrawableType extends IntrinsicPaddingDrawable & ShowBackgroundDrawable 26 | & TintableDrawable, BackgroundDrawableType extends IntrinsicPaddingDrawable 27 | & ShowBackgroundDrawable & TintableDrawable> 28 | extends LayerDrawable implements IntrinsicPaddingDrawable, MaterialProgressDrawable, 29 | ShowBackgroundDrawable, TintableDrawable { 30 | 31 | @FloatRange(from = 0, to = 1) 32 | private float mBackgroundAlpha; 33 | 34 | @NonNull 35 | private final BackgroundDrawableType mBackgroundDrawable; 36 | @NonNull 37 | private final ProgressDrawableType mSecondaryProgressDrawable; 38 | @NonNull 39 | private final ProgressDrawableType mProgressDrawable; 40 | 41 | public BaseProgressLayerDrawable(@NonNull Drawable[] layers, @NonNull Context context) { 42 | super(layers); 43 | 44 | mBackgroundAlpha = ThemeUtils.getFloatFromAttrRes(android.R.attr.disabledAlpha, 0, context); 45 | 46 | setId(0, android.R.id.background); 47 | //noinspection unchecked 48 | mBackgroundDrawable = (BackgroundDrawableType) getDrawable(0); 49 | setId(1, android.R.id.secondaryProgress); 50 | //noinspection unchecked 51 | mSecondaryProgressDrawable = (ProgressDrawableType) getDrawable(1); 52 | setId(2, android.R.id.progress); 53 | //noinspection unchecked 54 | mProgressDrawable = (ProgressDrawableType) getDrawable(2); 55 | 56 | int controlActivatedColor = ThemeUtils.getColorFromAttrRes(R.attr.colorControlActivated, 57 | Color.BLACK, context); 58 | setTint(controlActivatedColor); 59 | } 60 | 61 | /** 62 | * {@inheritDoc} 63 | */ 64 | @Override 65 | public boolean getShowBackground() { 66 | return mBackgroundDrawable.getShowBackground(); 67 | } 68 | 69 | /** 70 | * {@inheritDoc} 71 | */ 72 | @Override 73 | public void setShowBackground(boolean show) { 74 | if (mBackgroundDrawable.getShowBackground() != show) { 75 | mBackgroundDrawable.setShowBackground(show); 76 | mSecondaryProgressDrawable.setShowBackground(!show); 77 | } 78 | } 79 | 80 | /** 81 | * {@inheritDoc} 82 | */ 83 | @Override 84 | public boolean getUseIntrinsicPadding() { 85 | return mBackgroundDrawable.getUseIntrinsicPadding(); 86 | } 87 | 88 | /** 89 | * {@inheritDoc} 90 | */ 91 | @Override 92 | public void setUseIntrinsicPadding(boolean useIntrinsicPadding) { 93 | mBackgroundDrawable.setUseIntrinsicPadding(useIntrinsicPadding); 94 | mSecondaryProgressDrawable.setUseIntrinsicPadding(useIntrinsicPadding); 95 | mProgressDrawable.setUseIntrinsicPadding(useIntrinsicPadding); 96 | } 97 | 98 | /** 99 | * {@inheritDoc} 100 | */ 101 | @Override 102 | @SuppressLint("NewApi") 103 | public void setTint(@ColorInt int tintColor) { 104 | // Modulate alpha of tintColor against mBackgroundAlpha. 105 | int backgroundTintColor = ColorUtils.setAlphaComponent(tintColor, Math.round(Color.alpha( 106 | tintColor) * mBackgroundAlpha)); 107 | mBackgroundDrawable.setTint(backgroundTintColor); 108 | mSecondaryProgressDrawable.setTint(backgroundTintColor); 109 | mProgressDrawable.setTint(tintColor); 110 | } 111 | 112 | /** 113 | * {@inheritDoc} 114 | */ 115 | @Override 116 | @SuppressLint("NewApi") 117 | public void setTintList(@Nullable ColorStateList tint) { 118 | ColorStateList backgroundTint; 119 | if (tint != null) { 120 | if (!tint.isOpaque()) { 121 | Log.w(getClass().getSimpleName(), "setTintList() called with a non-opaque" + 122 | " ColorStateList, its original alpha will be discarded"); 123 | } 124 | backgroundTint = tint.withAlpha(Math.round(mBackgroundAlpha * 255)); 125 | } else { 126 | backgroundTint = null; 127 | } 128 | mBackgroundDrawable.setTintList(backgroundTint); 129 | mSecondaryProgressDrawable.setTintList(backgroundTint); 130 | mProgressDrawable.setTintList(tint); 131 | } 132 | 133 | /** 134 | * {@inheritDoc} 135 | */ 136 | @Override 137 | @SuppressLint("NewApi") 138 | public void setTintMode(@NonNull PorterDuff.Mode tintMode) { 139 | mBackgroundDrawable.setTintMode(tintMode); 140 | mSecondaryProgressDrawable.setTintMode(tintMode); 141 | mProgressDrawable.setTintMode(tintMode); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/BaseSingleCircularProgressDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.graphics.Canvas; 9 | import android.graphics.Paint; 10 | import android.graphics.RectF; 11 | 12 | import androidx.annotation.NonNull; 13 | 14 | abstract class BaseSingleCircularProgressDrawable extends BaseProgressDrawable { 15 | 16 | private static final RectF RECT_BOUND = new RectF(-21, -21, 21, 21); 17 | private static final RectF RECT_PADDED_BOUND = new RectF(-24, -24, 24, 24); 18 | private static final RectF RECT_PROGRESS = new RectF(-19, -19, 19, 19); 19 | 20 | @Override 21 | protected void onPreparePaint(@NonNull Paint paint) { 22 | paint.setStyle(Paint.Style.STROKE); 23 | paint.setStrokeWidth(4); 24 | } 25 | 26 | @Override 27 | protected void onDraw(@NonNull Canvas canvas, int width, int height, @NonNull Paint paint) { 28 | 29 | if (mUseIntrinsicPadding) { 30 | canvas.scale(width / RECT_PADDED_BOUND.width(), height / RECT_PADDED_BOUND.height()); 31 | canvas.translate(RECT_PADDED_BOUND.width() / 2, RECT_PADDED_BOUND.height() / 2); 32 | } else { 33 | canvas.scale(width / RECT_BOUND.width(), height / RECT_BOUND.height()); 34 | canvas.translate(RECT_BOUND.width() / 2, RECT_BOUND.height() / 2); 35 | } 36 | 37 | onDrawRing(canvas, paint); 38 | } 39 | 40 | protected abstract void onDrawRing(@NonNull Canvas canvas, @NonNull Paint paint); 41 | 42 | protected void drawRing(@NonNull Canvas canvas, @NonNull Paint paint, float startAngle, 43 | float sweepAngle) { 44 | // startAngle starts at 3 o'clock on a watch. 45 | canvas.drawArc(RECT_PROGRESS, -90 + startAngle, sweepAngle, false, paint); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/BaseSingleHorizontalProgressDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.content.Context; 9 | import android.graphics.Canvas; 10 | import android.graphics.Paint; 11 | import android.graphics.RectF; 12 | 13 | import androidx.annotation.Dimension; 14 | import androidx.annotation.NonNull; 15 | import androidx.annotation.Px; 16 | 17 | class BaseSingleHorizontalProgressDrawable extends BaseProgressDrawable { 18 | 19 | @Dimension(unit = Dimension.DP) 20 | private static final int PROGRESS_INTRINSIC_HEIGHT_DP = 4; 21 | @Dimension(unit = Dimension.DP) 22 | private static final int PADDED_INTRINSIC_HEIGHT_DP = 16; 23 | protected static final RectF RECT_BOUND = new RectF(-180, -1, 180, 1); 24 | private static final RectF RECT_PADDED_BOUND = new RectF(-180, -4, 180, 4); 25 | 26 | @Px 27 | private final int mProgressIntrinsicHeight; 28 | @Px 29 | private final int mPaddedIntrinsicHeight; 30 | 31 | public BaseSingleHorizontalProgressDrawable(@NonNull Context context) { 32 | float density = context.getResources().getDisplayMetrics().density; 33 | mProgressIntrinsicHeight = Math.round(PROGRESS_INTRINSIC_HEIGHT_DP * density); 34 | mPaddedIntrinsicHeight = Math.round(PADDED_INTRINSIC_HEIGHT_DP * density); 35 | } 36 | 37 | @Override 38 | @Px 39 | public int getIntrinsicHeight() { 40 | return mUseIntrinsicPadding ? mPaddedIntrinsicHeight : mProgressIntrinsicHeight; 41 | } 42 | 43 | @Override 44 | protected void onPreparePaint(Paint paint) { 45 | paint.setStyle(Paint.Style.FILL); 46 | } 47 | 48 | @Override 49 | protected void onDraw(Canvas canvas, int width, int height, Paint paint) { 50 | 51 | if (mUseIntrinsicPadding) { 52 | canvas.scale(width / RECT_PADDED_BOUND.width(), height / RECT_PADDED_BOUND.height()); 53 | canvas.translate(RECT_PADDED_BOUND.width() / 2, RECT_PADDED_BOUND.height() / 2); 54 | } else { 55 | canvas.scale(width / RECT_BOUND.width(), height / RECT_BOUND.height()); 56 | canvas.translate(RECT_BOUND.width() / 2, RECT_BOUND.height() / 2); 57 | } 58 | 59 | onDrawRect(canvas, paint); 60 | } 61 | 62 | protected void onDrawRect(Canvas canvas, Paint paint) { 63 | canvas.drawRect(RECT_BOUND, paint); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/CircularProgressBackgroundDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.graphics.Canvas; 9 | import android.graphics.Paint; 10 | 11 | import androidx.annotation.NonNull; 12 | 13 | class CircularProgressBackgroundDrawable extends BaseSingleCircularProgressDrawable 14 | implements ShowBackgroundDrawable { 15 | 16 | private boolean mShow = true; 17 | 18 | @Override 19 | public boolean getShowBackground() { 20 | return mShow; 21 | } 22 | 23 | @Override 24 | public void setShowBackground(boolean show) { 25 | if (mShow != show) { 26 | mShow = show; 27 | invalidateSelf(); 28 | } 29 | } 30 | 31 | @Override 32 | public void draw(@NonNull Canvas canvas) { 33 | if (mShow) { 34 | super.draw(canvas); 35 | } 36 | } 37 | 38 | @Override 39 | protected void onDrawRing(@NonNull Canvas canvas, @NonNull Paint paint) { 40 | drawRing(canvas, paint, 0, 360); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/CircularProgressDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.content.Context; 9 | import android.graphics.drawable.Drawable; 10 | 11 | import androidx.annotation.NonNull; 12 | 13 | /** 14 | * A new {@code Drawable} for determinate circular {@code ProgressBar}. 15 | */ 16 | public class CircularProgressDrawable extends BaseProgressLayerDrawable< 17 | SingleCircularProgressDrawable, CircularProgressBackgroundDrawable> { 18 | 19 | /** 20 | * Create a new {@code CircularProgressDrawable}. 21 | * 22 | * @param context the {@code Context} for retrieving style information. 23 | */ 24 | public CircularProgressDrawable(int style, @NonNull Context context) { 25 | super(new Drawable[] { 26 | new CircularProgressBackgroundDrawable(), 27 | new SingleCircularProgressDrawable(style), 28 | new SingleCircularProgressDrawable(style), 29 | }, context); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/HorizontalProgressBackgroundDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.content.Context; 9 | import android.graphics.Canvas; 10 | 11 | import androidx.annotation.NonNull; 12 | 13 | class HorizontalProgressBackgroundDrawable extends BaseSingleHorizontalProgressDrawable 14 | implements ShowBackgroundDrawable { 15 | 16 | private boolean mShow = true; 17 | 18 | public HorizontalProgressBackgroundDrawable(@NonNull Context context) { 19 | super(context); 20 | } 21 | 22 | @Override 23 | public boolean getShowBackground() { 24 | return mShow; 25 | } 26 | 27 | @Override 28 | public void setShowBackground(boolean show) { 29 | if (mShow != show) { 30 | mShow = show; 31 | invalidateSelf(); 32 | } 33 | } 34 | 35 | @Override 36 | public void draw(@NonNull Canvas canvas) { 37 | if (mShow) { 38 | super.draw(canvas); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/HorizontalProgressDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.content.Context; 9 | import android.graphics.drawable.Drawable; 10 | 11 | import androidx.annotation.NonNull; 12 | 13 | /** 14 | * A backported {@code Drawable} for determinate horizontal {@code ProgressBar}. 15 | */ 16 | public class HorizontalProgressDrawable extends BaseProgressLayerDrawable< 17 | SingleHorizontalProgressDrawable, HorizontalProgressBackgroundDrawable> { 18 | 19 | /** 20 | * Create a new {@code HorizontalProgressDrawable}. 21 | * 22 | * @param context the {@code Context} for retrieving style information. 23 | */ 24 | public HorizontalProgressDrawable(@NonNull Context context) { 25 | super(new Drawable[] { 26 | new HorizontalProgressBackgroundDrawable(context), 27 | new SingleHorizontalProgressDrawable(context), 28 | new SingleHorizontalProgressDrawable(context) 29 | }, context); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/IndeterminateCircularProgressDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.animation.Animator; 9 | import android.content.Context; 10 | import android.graphics.Canvas; 11 | import android.graphics.Paint; 12 | import android.graphics.RectF; 13 | 14 | import androidx.annotation.Dimension; 15 | import androidx.annotation.Keep; 16 | import androidx.annotation.NonNull; 17 | import androidx.annotation.Px; 18 | 19 | /** 20 | * A backported {@code Drawable} for indeterminate circular {@code ProgressBar}. 21 | */ 22 | public class IndeterminateCircularProgressDrawable extends BaseIndeterminateProgressDrawable 23 | implements MaterialProgressDrawable { 24 | 25 | @Dimension(unit = Dimension.DP) 26 | private static final int PROGRESS_INTRINSIC_SIZE_DP = 42; 27 | @Dimension(unit = Dimension.DP) 28 | private static final int PADDED_INTRINSIC_SIZE_DP = 48; 29 | private static final RectF RECT_BOUND = new RectF(-21, -21, 21, 21); 30 | private static final RectF RECT_PADDED_BOUND = new RectF(-24, -24, 24, 24); 31 | private static final RectF RECT_PROGRESS = new RectF(-19, -19, 19, 19); 32 | 33 | @Px 34 | private final int mProgressIntrinsicSize; 35 | @Px 36 | private final int mPaddedIntrinsicSize; 37 | 38 | @NonNull 39 | private final RingPathTransform mRingPathTransform = new RingPathTransform(); 40 | @NonNull 41 | private final RingRotation mRingRotation = new RingRotation(); 42 | 43 | /** 44 | * Create a new {@code IndeterminateCircularProgressDrawable}. 45 | * 46 | * @param context the {@code Context} for retrieving style information. 47 | */ 48 | public IndeterminateCircularProgressDrawable(@NonNull Context context) { 49 | super(context); 50 | 51 | float density = context.getResources().getDisplayMetrics().density; 52 | mProgressIntrinsicSize = Math.round(PROGRESS_INTRINSIC_SIZE_DP * density); 53 | mPaddedIntrinsicSize = Math.round(PADDED_INTRINSIC_SIZE_DP * density); 54 | 55 | mAnimators = new Animator[] { 56 | Animators.createIndeterminate(mRingPathTransform), 57 | Animators.createIndeterminateRotation(mRingRotation) 58 | }; 59 | } 60 | 61 | @Px 62 | private int getIntrinsicSize() { 63 | return mUseIntrinsicPadding ? mPaddedIntrinsicSize : mProgressIntrinsicSize; 64 | } 65 | 66 | /** 67 | * {@inheritDoc} 68 | */ 69 | @Override 70 | @Px 71 | public int getIntrinsicWidth() { 72 | return getIntrinsicSize(); 73 | } 74 | 75 | /** 76 | * {@inheritDoc} 77 | */ 78 | @Override 79 | @Px 80 | public int getIntrinsicHeight() { 81 | return getIntrinsicSize(); 82 | } 83 | 84 | @Override 85 | protected void onPreparePaint(@NonNull Paint paint) { 86 | paint.setStyle(Paint.Style.STROKE); 87 | paint.setStrokeWidth(4); 88 | paint.setStrokeCap(Paint.Cap.SQUARE); 89 | paint.setStrokeJoin(Paint.Join.MITER); 90 | } 91 | 92 | @Override 93 | protected void onDraw(@NonNull Canvas canvas, int width, int height, @NonNull Paint paint) { 94 | 95 | if (mUseIntrinsicPadding) { 96 | canvas.scale(width / RECT_PADDED_BOUND.width(), height / RECT_PADDED_BOUND.height()); 97 | canvas.translate(RECT_PADDED_BOUND.width() / 2, RECT_PADDED_BOUND.height() / 2); 98 | } else { 99 | canvas.scale(width / RECT_BOUND.width(), height / RECT_BOUND.height()); 100 | canvas.translate(RECT_BOUND.width() / 2, RECT_BOUND.height() / 2); 101 | } 102 | 103 | drawRing(canvas, paint); 104 | } 105 | 106 | private void drawRing(@NonNull Canvas canvas, @NonNull Paint paint) { 107 | 108 | int saveCount = canvas.save(); 109 | canvas.rotate(mRingRotation.mRotation); 110 | 111 | // startAngle starts at 3 o'clock on a watch. 112 | float startAngle = -90 + 360 * (mRingPathTransform.mTrimPathOffset 113 | + mRingPathTransform.mTrimPathStart); 114 | float sweepAngle = 360 * (mRingPathTransform.mTrimPathEnd 115 | - mRingPathTransform.mTrimPathStart); 116 | canvas.drawArc(RECT_PROGRESS, startAngle, sweepAngle, false, paint); 117 | 118 | canvas.restoreToCount(saveCount); 119 | } 120 | 121 | private static class RingPathTransform { 122 | 123 | public float mTrimPathStart; 124 | public float mTrimPathEnd; 125 | public float mTrimPathOffset; 126 | 127 | @Keep 128 | @SuppressWarnings("unused") 129 | public void setTrimPathStart(float trimPathStart) { 130 | mTrimPathStart = trimPathStart; 131 | } 132 | 133 | @Keep 134 | @SuppressWarnings("unused") 135 | public void setTrimPathEnd(float trimPathEnd) { 136 | mTrimPathEnd = trimPathEnd; 137 | } 138 | 139 | @Keep 140 | @SuppressWarnings("unused") 141 | public void setTrimPathOffset(float trimPathOffset) { 142 | mTrimPathOffset = trimPathOffset; 143 | } 144 | } 145 | 146 | private static class RingRotation { 147 | 148 | private float mRotation; 149 | 150 | @Keep 151 | @SuppressWarnings("unused") 152 | public void setRotation(float rotation) { 153 | mRotation = rotation; 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/IndeterminateHorizontalProgressDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.animation.Animator; 9 | import android.content.Context; 10 | import android.graphics.Canvas; 11 | import android.graphics.Paint; 12 | import android.graphics.RectF; 13 | 14 | import androidx.annotation.Dimension; 15 | import androidx.annotation.FloatRange; 16 | import androidx.annotation.Keep; 17 | import androidx.annotation.NonNull; 18 | import androidx.annotation.Px; 19 | import me.zhanghai.android.materialprogressbar.internal.ThemeUtils; 20 | 21 | /** 22 | * A backported {@code Drawable} for indeterminate horizontal {@code ProgressBar}. 23 | */ 24 | public class IndeterminateHorizontalProgressDrawable extends BaseIndeterminateProgressDrawable 25 | implements MaterialProgressDrawable, ShowBackgroundDrawable { 26 | 27 | @Dimension(unit = Dimension.DP) 28 | private static final int PROGRESS_INTRINSIC_HEIGHT_DP = 4; 29 | @Dimension(unit = Dimension.DP) 30 | private static final int PADDED_INTRINSIC_HEIGHT_DP = 16; 31 | private static final RectF RECT_BOUND = new RectF(-180, -1, 180, 1); 32 | private static final RectF RECT_PADDED_BOUND = new RectF(-180, -4, 180, 4); 33 | private static final RectF RECT_PROGRESS = new RectF(-144, -1, 144, 1); 34 | private static final RectTransformX RECT_1_TRANSFORM_X = new RectTransformX(-522.6f, 0.1f); 35 | private static final RectTransformX RECT_2_TRANSFORM_X = new RectTransformX(-197.6f, 0.1f); 36 | 37 | @Px 38 | private final int mProgressIntrinsicHeight; 39 | @Px 40 | private final int mPaddedIntrinsicHeight; 41 | @FloatRange(from = 0, to = 1) 42 | private float mBackgroundAlpha; 43 | 44 | private boolean mShowBackground = true; 45 | 46 | @NonNull 47 | private final RectTransformX mRect1TransformX = new RectTransformX(RECT_1_TRANSFORM_X); 48 | @NonNull 49 | private final RectTransformX mRect2TransformX = new RectTransformX(RECT_2_TRANSFORM_X); 50 | 51 | /** 52 | * Create a new {@code IndeterminateHorizontalProgressDrawable}. 53 | * 54 | * @param context the {@code Context} for retrieving style information. 55 | */ 56 | public IndeterminateHorizontalProgressDrawable(@NonNull Context context) { 57 | super(context); 58 | 59 | float density = context.getResources().getDisplayMetrics().density; 60 | mProgressIntrinsicHeight = Math.round(PROGRESS_INTRINSIC_HEIGHT_DP * density); 61 | mPaddedIntrinsicHeight = Math.round(PADDED_INTRINSIC_HEIGHT_DP * density); 62 | 63 | mBackgroundAlpha = ThemeUtils.getFloatFromAttrRes(android.R.attr.disabledAlpha, 0, context); 64 | 65 | mAnimators = new Animator[] { 66 | Animators.createIndeterminateHorizontalRect1(mRect1TransformX), 67 | Animators.createIndeterminateHorizontalRect2(mRect2TransformX) 68 | }; 69 | } 70 | 71 | /** 72 | * {@inheritDoc} 73 | */ 74 | @Override 75 | public boolean getShowBackground() { 76 | return mShowBackground; 77 | } 78 | 79 | /** 80 | * {@inheritDoc} 81 | */ 82 | @Override 83 | public void setShowBackground(boolean show) { 84 | if (mShowBackground != show) { 85 | mShowBackground = show; 86 | invalidateSelf(); 87 | } 88 | } 89 | 90 | /** 91 | * {@inheritDoc} 92 | */ 93 | @Override 94 | @Px 95 | public int getIntrinsicHeight() { 96 | return mUseIntrinsicPadding ? mPaddedIntrinsicHeight : mProgressIntrinsicHeight; 97 | } 98 | 99 | @Override 100 | protected void onPreparePaint(Paint paint) { 101 | paint.setStyle(Paint.Style.FILL); 102 | } 103 | 104 | @Override 105 | protected void onDraw(Canvas canvas, int width, int height, Paint paint) { 106 | 107 | if (mUseIntrinsicPadding) { 108 | canvas.scale(width / RECT_PADDED_BOUND.width(), height / RECT_PADDED_BOUND.height()); 109 | canvas.translate(RECT_PADDED_BOUND.width() / 2, RECT_PADDED_BOUND.height() / 2); 110 | } else { 111 | canvas.scale(width / RECT_BOUND.width(), height / RECT_BOUND.height()); 112 | canvas.translate(RECT_BOUND.width() / 2, RECT_BOUND.height() / 2); 113 | } 114 | 115 | if (mShowBackground) { 116 | paint.setAlpha(Math.round(mAlpha * mBackgroundAlpha)); 117 | drawBackgroundRect(canvas, paint); 118 | paint.setAlpha(mAlpha); 119 | } 120 | drawProgressRect(canvas, mRect2TransformX, paint); 121 | drawProgressRect(canvas, mRect1TransformX, paint); 122 | } 123 | 124 | private static void drawBackgroundRect(Canvas canvas, Paint paint) { 125 | canvas.drawRect(RECT_BOUND, paint); 126 | } 127 | 128 | private static void drawProgressRect(Canvas canvas, RectTransformX transformX, Paint paint) { 129 | 130 | int saveCount = canvas.save(); 131 | canvas.translate(transformX.mTranslateX, 0); 132 | canvas.scale(transformX.mScaleX, 1); 133 | 134 | canvas.drawRect(RECT_PROGRESS, paint); 135 | 136 | canvas.restoreToCount(saveCount); 137 | } 138 | 139 | private static class RectTransformX { 140 | 141 | public float mTranslateX; 142 | public float mScaleX; 143 | 144 | public RectTransformX(float translateX, float scaleX) { 145 | mTranslateX = translateX; 146 | mScaleX = scaleX; 147 | } 148 | 149 | public RectTransformX(RectTransformX that) { 150 | mTranslateX = that.mTranslateX; 151 | mScaleX = that.mScaleX; 152 | } 153 | 154 | @Keep 155 | @SuppressWarnings("unused") 156 | public void setTranslateX(float translateX) { 157 | mTranslateX = translateX; 158 | } 159 | 160 | @Keep 161 | @SuppressWarnings("unused") 162 | public void setScaleX(float scaleX) { 163 | mScaleX = scaleX; 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/Interpolators.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.graphics.Path; 9 | import android.view.animation.Interpolator; 10 | import android.view.animation.LinearInterpolator; 11 | 12 | import androidx.core.view.animation.PathInterpolatorCompat; 13 | 14 | /** 15 | * Interpolators backported for Animators in this library. 16 | */ 17 | class Interpolators { 18 | 19 | /** 20 | * Backported Interpolator for 21 | * {@code @android:interpolator/progress_indeterminate_horizontal_rect1_translatex}. 22 | */ 23 | public static class INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X { 24 | // M 0.0,0.0 25 | // L 0.2 0 26 | // C 0.3958333333336,0.0 0.474845090492,0.206797621729 0.5916666666664,0.417082932942 27 | // C 0.7151610251224,0.639379624869 0.81625,0.974556908664 1.0,1.0 28 | private static final Path PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X; 29 | static { 30 | PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X = new Path(); 31 | PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X.moveTo(0, 0); 32 | PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X.lineTo(0.2f, 0); 33 | PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X.cubicTo(0.3958333333336f, 0, 34 | 0.474845090492f, 0.206797621729f, 0.5916666666664f, 0.417082932942f); 35 | PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X.cubicTo(0.7151610251224f, 36 | 0.639379624869f, 0.81625f, 0.974556908664f, 1, 1); 37 | } 38 | public static final Interpolator INSTANCE = 39 | PathInterpolatorCompat.create(PATH_INDETERMINATE_HORIZONTAL_RECT1_TRANSLATE_X); 40 | } 41 | 42 | /** 43 | * Backported Interpolator for 44 | * {@code @android:interpolator/progress_indeterminate_horizontal_rect1_scalex}. 45 | */ 46 | public static class INDETERMINATE_HORIZONTAL_RECT1_SCALE_X { 47 | // M 0 0 48 | // L 0.3665 0 49 | // C 0.47252618112021,0.062409910275 0.61541608570164,0.5 0.68325,0.5 50 | // C 0.75475061236836,0.5 0.75725829093844,0.814510098964 1.0,1.0 51 | private static final Path PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X; 52 | static { 53 | PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X = new Path(); 54 | PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X.moveTo(0, 0); 55 | PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X.lineTo(0.3665f, 0); 56 | PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X.cubicTo(0.47252618112021f, 0.062409910275f, 57 | 0.61541608570164f, 0.5f, 0.68325f, 0.5f); 58 | PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X.cubicTo(0.75475061236836f, 0.5f, 59 | 0.75725829093844f, 0.814510098964f, 1, 1); 60 | } 61 | public static final Interpolator INSTANCE = 62 | PathInterpolatorCompat.create(PATH_INDETERMINATE_HORIZONTAL_RECT1_SCALE_X); 63 | } 64 | 65 | /** 66 | * Backported Interpolator for 67 | * {@code @android:interpolator/progress_indeterminate_horizontal_rect2_translatex}. 68 | */ 69 | public static class INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X { 70 | // M 0.0,0.0 71 | // C 0.0375,0.0 0.128764607715,0.0895380946618 0.25,0.218553507947 72 | // C 0.322410320025,0.295610602487 0.436666666667,0.417591408114 73 | // 0.483333333333,0.489826169306 74 | // C 0.69,0.80972296795 0.793333333333,0.950016125212 1.0,1.0 75 | private static final Path PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X; 76 | static { 77 | PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X = new Path(); 78 | PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X.moveTo(0, 0); 79 | PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X.cubicTo(0.0375f, 0, 0.128764607715f, 80 | 0.0895380946618f, 0.25f, 0.218553507947f); 81 | PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X.cubicTo(0.322410320025f, 0.295610602487f, 82 | 0.436666666667f, 0.417591408114f, 0.483333333333f, 0.489826169306f); 83 | PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X.cubicTo(0.69f, 0.80972296795f, 84 | 0.793333333333f, 0.950016125212f, 1, 1); 85 | } 86 | public static final Interpolator INSTANCE = 87 | PathInterpolatorCompat.create(PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X); 88 | } 89 | 90 | /** 91 | * Backported Interpolator for 92 | * {@code @android:interpolator/progress_indeterminate_horizontal_rect2_scalex}. 93 | */ 94 | public static class INDETERMINATE_HORIZONTAL_RECT2_SCALE_X { 95 | // M 0,0 96 | // C 0.06834272400867,0.01992566661414 0.19220331656133,0.15855429260523 0.33333333333333, 97 | // 0.34926160892842 98 | // C 0.38410433133433,0.41477913453861 0.54945792615267,0.68136029463551 0.66666666666667, 99 | // 0.68279962777002 100 | // C 0.752586273196,0.68179620963216 0.737253971954,0.878896194318 1,1 101 | private static final Path PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X; 102 | static { 103 | PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X = new Path(); 104 | PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X.moveTo(0, 0); 105 | PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X.cubicTo(0.06834272400867f, 0.01992566661414f, 106 | 0.19220331656133f, 0.15855429260523f, 0.33333333333333f, 0.34926160892842f); 107 | PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X.cubicTo(0.38410433133433f, 0.41477913453861f, 108 | 0.54945792615267f, 0.68136029463551f, 0.66666666666667f, 0.68279962777002f); 109 | PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X.cubicTo(0.752586273196f, 0.68179620963216f, 110 | 0.737253971954f, 0.878896194318f, 1, 1); 111 | } 112 | public static final Interpolator INSTANCE = 113 | PathInterpolatorCompat.create(PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X); 114 | } 115 | 116 | /** 117 | * Backported Interpolator for {@code @android:interpolator/trim_start_interpolator}. 118 | */ 119 | public static class TRIM_PATH_START { 120 | // L 0.5,0 121 | // C 0.7,0 0.6,1 1,1 122 | private static final Path PATH_TRIM_PATH_START; 123 | static { 124 | PATH_TRIM_PATH_START = new Path(); 125 | PATH_TRIM_PATH_START.lineTo(0.5f, 0); 126 | PATH_TRIM_PATH_START.cubicTo(0.7f, 0, 0.6f, 1, 1, 1); 127 | } 128 | public static final Interpolator INSTANCE = 129 | PathInterpolatorCompat.create(PATH_TRIM_PATH_START); 130 | } 131 | 132 | /** 133 | * Backported Interpolator for {@code @android:interpolator/trim_end_interpolator}. 134 | */ 135 | public static class TRIM_PATH_END { 136 | // C 0.2,0 0.1,1 0.5,1 137 | // L 1,1 138 | private static final Path PATH_TRIM_PATH_END; 139 | static { 140 | PATH_TRIM_PATH_END = new Path(); 141 | PATH_TRIM_PATH_END.cubicTo(0.2f, 0, 0.1f, 1, 0.5f, 1); 142 | PATH_TRIM_PATH_END.lineTo(1, 1); 143 | } 144 | public static final Interpolator INSTANCE = PathInterpolatorCompat.create(PATH_TRIM_PATH_END); 145 | } 146 | 147 | /** 148 | * Lazy-initialized singleton Interpolator for {@code @android:interpolator/linear}. 149 | */ 150 | public static class LINEAR { 151 | public static final Interpolator INSTANCE = new LinearInterpolator(); 152 | } 153 | 154 | private Interpolators() {} 155 | } 156 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/IntrinsicPaddingDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | /** 9 | * A {@code Drawable} that has an intrinsic padding. 10 | */ 11 | public interface IntrinsicPaddingDrawable { 12 | 13 | /** 14 | * Get whether this drawable is using an intrinsic padding. The default is {@code true}. 15 | * 16 | * @return Whether this drawable is using an intrinsic padding. 17 | */ 18 | boolean getUseIntrinsicPadding(); 19 | 20 | /** 21 | * Set whether this drawable should use an intrinsic padding. The default is {@code true}. 22 | * 23 | * @param useIntrinsicPadding Whether this drawable should use its intrinsic padding. 24 | */ 25 | void setUseIntrinsicPadding(boolean useIntrinsicPadding); 26 | } 27 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/MaterialProgressDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | interface MaterialProgressDrawable {} 9 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/ShowBackgroundDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | /** 9 | * A {@code Drawable} that has a background. 10 | */ 11 | public interface ShowBackgroundDrawable { 12 | 13 | /** 14 | * Get whether this drawable is showing a background. The default is {@code true}. 15 | * 16 | * @return Whether this drawable is showing a background. 17 | */ 18 | boolean getShowBackground(); 19 | 20 | /** 21 | * Set whether this drawable should show a background. The default is {@code true}. 22 | * 23 | * @param show Whether background should be shown. 24 | */ 25 | void setShowBackground(boolean show); 26 | } 27 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/SingleCircularProgressDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.graphics.Canvas; 9 | import android.graphics.Paint; 10 | import android.graphics.drawable.Drawable; 11 | 12 | import androidx.annotation.IntRange; 13 | import androidx.annotation.NonNull; 14 | 15 | class SingleCircularProgressDrawable extends BaseSingleCircularProgressDrawable 16 | implements ShowBackgroundDrawable { 17 | 18 | /** 19 | * Value from {@link Drawable#getLevel()} 20 | */ 21 | private static final int LEVEL_MAX = 10000; 22 | 23 | private static final float START_ANGLE_MAX_NORMAL = 0; 24 | private static final float START_ANGLE_MAX_DYNAMIC = 360; 25 | private static final float SWEEP_ANGLE_MAX = 360; 26 | 27 | private final float mStartAngleMax; 28 | 29 | private boolean mShowBackground; 30 | 31 | SingleCircularProgressDrawable(int style) { 32 | switch (style) { 33 | case MaterialProgressBar.DETERMINATE_CIRCULAR_PROGRESS_STYLE_NORMAL: 34 | mStartAngleMax = START_ANGLE_MAX_NORMAL; 35 | break; 36 | case MaterialProgressBar.DETERMINATE_CIRCULAR_PROGRESS_STYLE_DYNAMIC: 37 | mStartAngleMax = START_ANGLE_MAX_DYNAMIC; 38 | break; 39 | default: 40 | throw new IllegalArgumentException("Invalid value for style"); 41 | } 42 | } 43 | 44 | @Override 45 | protected boolean onLevelChange(@IntRange(from = 0, to = LEVEL_MAX) int level) { 46 | invalidateSelf(); 47 | return true; 48 | } 49 | 50 | @Override 51 | public boolean getShowBackground() { 52 | return mShowBackground; 53 | } 54 | 55 | @Override 56 | public void setShowBackground(boolean show) { 57 | if (mShowBackground != show) { 58 | mShowBackground = show; 59 | invalidateSelf(); 60 | } 61 | } 62 | 63 | @Override 64 | protected void onDrawRing(@NonNull Canvas canvas, @NonNull Paint paint) { 65 | 66 | int level = getLevel(); 67 | if (level == 0) { 68 | return; 69 | } 70 | 71 | float ratio = (float) level / LEVEL_MAX; 72 | float startAngle = ratio * mStartAngleMax; 73 | float sweepAngle = ratio * SWEEP_ANGLE_MAX; 74 | 75 | drawRing(canvas, paint, startAngle, sweepAngle); 76 | if (mShowBackground) { 77 | // Draw twice to emulate the background for secondary progress. 78 | drawRing(canvas, paint, startAngle, sweepAngle); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/SingleHorizontalProgressDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.content.Context; 9 | import android.graphics.Canvas; 10 | import android.graphics.Paint; 11 | import android.graphics.drawable.Drawable; 12 | 13 | import androidx.annotation.IntRange; 14 | import androidx.annotation.NonNull; 15 | 16 | class SingleHorizontalProgressDrawable extends BaseSingleHorizontalProgressDrawable 17 | implements ShowBackgroundDrawable { 18 | 19 | /** 20 | * Value from {@link Drawable#getLevel()} 21 | */ 22 | private static final int LEVEL_MAX = 10000; 23 | 24 | private boolean mShowBackground; 25 | 26 | public SingleHorizontalProgressDrawable(@NonNull Context context) { 27 | super(context); 28 | } 29 | 30 | @Override 31 | protected boolean onLevelChange(@IntRange(from = 0, to = LEVEL_MAX) int level) { 32 | invalidateSelf(); 33 | return true; 34 | } 35 | 36 | @Override 37 | public boolean getShowBackground() { 38 | return mShowBackground; 39 | } 40 | 41 | @Override 42 | public void setShowBackground(boolean show) { 43 | if (mShowBackground != show) { 44 | mShowBackground = show; 45 | invalidateSelf(); 46 | } 47 | } 48 | 49 | @Override 50 | protected void onDrawRect(@NonNull Canvas canvas, @NonNull Paint paint) { 51 | 52 | int level = getLevel(); 53 | if (level == 0) { 54 | return; 55 | } 56 | 57 | int saveCount = canvas.save(); 58 | canvas.scale((float) level / LEVEL_MAX, 1, RECT_BOUND.left, 0); 59 | 60 | super.onDrawRect(canvas, paint); 61 | if (mShowBackground) { 62 | // Draw twice to emulate the background for secondary progress. 63 | super.onDrawRect(canvas, paint); 64 | } 65 | 66 | canvas.restoreToCount(saveCount); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/StaticIndeterminateCircularProgressDrawable.java: -------------------------------------------------------------------------------- 1 | package me.zhanghai.android.materialprogressbar; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Matrix; 7 | import android.graphics.Paint; 8 | import android.graphics.Path; 9 | import android.graphics.RectF; 10 | 11 | import androidx.annotation.Dimension; 12 | import androidx.annotation.NonNull; 13 | import androidx.annotation.Px; 14 | import me.zhanghai.android.materialprogressbar.internal.ThemeUtils; 15 | 16 | public class StaticIndeterminateCircularProgressDrawable extends BaseProgressDrawable { 17 | 18 | /** 19 | * Backported {@code Path} for {@code @android:drawable/progress_static_material}. 20 | */ 21 | private static final Path PATH_PROGRESS; 22 | static { 23 | // M17.65,6.35 24 | // C16.2,4.9 14.21,4.0 12.0,4.0 25 | // c-4.42,0.0 -7.99,3.58 -7.99,8.0 26 | // s3.57,8.0 7.99,8.0 27 | // c3.73,0.0 6.84,-2.55 7.73,-6.0 28 | // l-2.08,0.0 29 | // c-0.82,2.33 -3.04,4.0 -5.65,4.0 -3.31,0.0 -6.0,-2.69 -6.0,-6.0 30 | // s2.69,-6.0 6.0,-6.0 31 | // c1.66,0.0 3.1,0.69 4.22,1.78 32 | // L13.0,11.0 33 | // l7.0,0.0 34 | // L20.0,4.0 35 | // l-2.35,2.35 36 | // z 37 | // 38 | // M 17.65,6.35 39 | // C 16.2,4.9 14.21,4 12,4 40 | // C 7.58,4 4.01,7.58 4.01,12 41 | // c 0,4.42 3.57,8 7.99,8 42 | // c 3.73,0 6.84,-2.55 7.73,-6 43 | // H 17.65 44 | // C 16.83,16.33 14.61,18 12,18 45 | // C 8.69,18 6,15.31 6,12 46 | // C 6,8.69 8.69,6 12,6 47 | // c 1.66,0 3.1,0.69 4.22,1.78 48 | // L 13,11 49 | // h 7 50 | // V 4 51 | // Z 52 | PATH_PROGRESS = new Path(); 53 | PATH_PROGRESS.moveTo(17.65f, 6.35f); 54 | PATH_PROGRESS.cubicTo(16.2f, 4.9f, 14.21f, 4f, 12f, 4f); 55 | PATH_PROGRESS.cubicTo(7.58f, 4f, 4.01f, 7.58f, 4.01f, 12f); 56 | PATH_PROGRESS.rCubicTo(0f, 4.42f, 3.57f, 8f, 7.99f, 8f); 57 | PATH_PROGRESS.rCubicTo(3.73f, 0f, 6.84f, -2.55f, 7.73f, -6f); 58 | PATH_PROGRESS.rLineTo(-2.08f, 0f); 59 | PATH_PROGRESS.cubicTo(16.83f, 16.33f, 14.61f, 18f, 12f, 18f); 60 | PATH_PROGRESS.cubicTo(8.69f, 18f, 6f, 15.31f, 6f, 12f); 61 | PATH_PROGRESS.cubicTo(6f, 8.69f, 8.69f, 6f, 12f, 6f); 62 | PATH_PROGRESS.rCubicTo(1.66f, 0f, 3.1f, 0.69f, 4.22f, 1.78f); 63 | PATH_PROGRESS.lineTo(13f, 11f); 64 | PATH_PROGRESS.rLineTo(7f, 0f); 65 | PATH_PROGRESS.lineTo(20f, 4f); 66 | PATH_PROGRESS.close(); 67 | } 68 | 69 | @Dimension(unit = Dimension.DP) 70 | private static final int PROGRESS_INTRINSIC_SIZE_DP = 42; 71 | @Dimension(unit = Dimension.DP) 72 | private static final int PADDED_INTRINSIC_SIZE_DP = 48; 73 | // To keep the same ratio as indeterminate circular progress drawable. 74 | private static final RectF RECT_PROGRESS_BOUND = new RectF(3, 3, 21, 21); 75 | private static final RectF RECT_PADDED_BOUND = new RectF(0, 0, 24, 24); 76 | 77 | @Px 78 | private final int mProgressIntrinsicSize; 79 | @Px 80 | private final int mPaddedIntrinsicSize; 81 | 82 | @NonNull 83 | private final Path mPath = new Path(); 84 | @NonNull 85 | private final Matrix mMatrix = new Matrix(); 86 | 87 | /** 88 | * Create a new {@code StaticIndeterminateCircularProgressDrawable}. 89 | * 90 | * @param context the {@code Context} for retrieving style information. 91 | */ 92 | public StaticIndeterminateCircularProgressDrawable(@NonNull Context context) { 93 | 94 | float density = context.getResources().getDisplayMetrics().density; 95 | mProgressIntrinsicSize = Math.round(PROGRESS_INTRINSIC_SIZE_DP * density); 96 | mPaddedIntrinsicSize = Math.round(PADDED_INTRINSIC_SIZE_DP * density); 97 | 98 | int controlActivatedColor = ThemeUtils.getColorFromAttrRes(R.attr.colorControlActivated, 99 | Color.BLACK, context); 100 | // setTint() has been overridden for compatibility. 101 | setTint(controlActivatedColor); 102 | } 103 | 104 | @Px 105 | private int getIntrinsicSize() { 106 | return mUseIntrinsicPadding ? mPaddedIntrinsicSize : mProgressIntrinsicSize; 107 | } 108 | 109 | /** 110 | * {@inheritDoc} 111 | */ 112 | @Override 113 | @Px 114 | public int getIntrinsicWidth() { 115 | return getIntrinsicSize(); 116 | } 117 | 118 | /** 119 | * {@inheritDoc} 120 | */ 121 | @Override 122 | @Px 123 | public int getIntrinsicHeight() { 124 | return getIntrinsicSize(); 125 | } 126 | 127 | @Override 128 | protected void onPreparePaint(@NonNull Paint paint) { 129 | paint.setStyle(Paint.Style.FILL); 130 | } 131 | 132 | @Override 133 | protected void onDraw(@NonNull Canvas canvas, int width, int height, @NonNull Paint paint) { 134 | // Drawing the transformed path makes rendering much less blurry than using canvas transform 135 | // directly. See https://stackoverflow.com/a/16091390 . 136 | RectF bound = mUseIntrinsicPadding ? RECT_PADDED_BOUND : RECT_PROGRESS_BOUND; 137 | mMatrix.setScale(width / bound.width(), height / bound.height()); 138 | mMatrix.preTranslate(-bound.left, -bound.top); 139 | PATH_PROGRESS.transform(mMatrix, mPath); 140 | canvas.drawPath(mPath, paint); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/TintableDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar; 7 | 8 | import android.content.res.ColorStateList; 9 | import android.graphics.ColorFilter; 10 | import android.graphics.PorterDuff; 11 | import android.graphics.drawable.Drawable; 12 | 13 | import androidx.annotation.ColorInt; 14 | import androidx.annotation.NonNull; 15 | import androidx.annotation.Nullable; 16 | import androidx.core.graphics.drawable.TintAwareDrawable; 17 | 18 | /** 19 | * A {@code Drawable} that is tintable. 20 | */ 21 | public interface TintableDrawable extends TintAwareDrawable { 22 | 23 | /** 24 | * Specifies tint color for this drawable. 25 | *

26 | * A Drawable's drawing content will be blended together with its tint 27 | * before it is drawn to the screen. This functions similarly to 28 | * {@link Drawable#setColorFilter(int, PorterDuff.Mode)}. 29 | *

30 | *

31 | * To clear the tint, pass {@code null} to 32 | * {@link #setTintList(ColorStateList)}. 33 | *

34 | *

Note: Setting a color filter via 35 | * {@link Drawable#setColorFilter(ColorFilter)} or 36 | * {@link Drawable#setColorFilter(int, PorterDuff.Mode)} overrides tint. 37 | *

38 | * 39 | * @param tintColor Color to use for tinting this drawable 40 | * @see #setTintList(ColorStateList) 41 | * @see #setTintMode(PorterDuff.Mode) 42 | */ 43 | void setTint(@ColorInt int tintColor); 44 | 45 | /** 46 | * Specifies tint color for this drawable as a color state list. 47 | *

48 | * A Drawable's drawing content will be blended together with its tint 49 | * before it is drawn to the screen. This functions similarly to 50 | * {@link Drawable#setColorFilter(int, PorterDuff.Mode)}. 51 | *

52 | *

Note: Setting a color filter via 53 | * {@link Drawable#setColorFilter(ColorFilter)} or 54 | * {@link Drawable#setColorFilter(int, PorterDuff.Mode)} overrides tint. 55 | *

56 | * 57 | * @param tint Color state list to use for tinting this drawable, or 58 | * {@code null} to clear the tint 59 | * @see #setTint(int) 60 | * @see #setTintMode(PorterDuff.Mode) 61 | */ 62 | void setTintList(@Nullable ColorStateList tint); 63 | 64 | /** 65 | * Specifies a tint blending mode for this drawable. 66 | *

67 | * Defines how this drawable's tint color should be blended into the drawable 68 | * before it is drawn to screen. Default tint mode is {@link PorterDuff.Mode#SRC_IN}. 69 | *

70 | *

Note: Setting a color filter via 71 | * {@link Drawable#setColorFilter(ColorFilter)} or 72 | * {@link Drawable#setColorFilter(int, PorterDuff.Mode)} overrides tint. 73 | *

74 | * 75 | * @param tintMode A Porter-Duff blending mode 76 | * @see #setTint(int) 77 | * @see #setTintList(ColorStateList) 78 | */ 79 | void setTintMode(@NonNull PorterDuff.Mode tintMode); 80 | } 81 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/internal/AnimationScaleListDrawableCompat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 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 | package me.zhanghai.android.materialprogressbar.internal; 18 | 19 | import android.content.res.Resources; 20 | import android.graphics.drawable.Animatable; 21 | import android.graphics.drawable.Drawable; 22 | import android.os.Build; 23 | 24 | import androidx.annotation.NonNull; 25 | import androidx.annotation.Nullable; 26 | import androidx.annotation.RequiresApi; 27 | 28 | /* 29 | * @see com.android.internal.graphics.drawable.AnimationScaleListDrawable 30 | */ 31 | public class AnimationScaleListDrawableCompat extends DrawableContainerCompat 32 | implements Animatable { 33 | private static final String TAG = "AnimationScaleListDrawableCompat"; 34 | private AnimationScaleListState mAnimationScaleListState; 35 | private boolean mMutated; 36 | 37 | public AnimationScaleListDrawableCompat(@NonNull Drawable[] drawables) { 38 | setConstantState(new AnimationScaleListState(null, this, null)); 39 | for (Drawable drawable : drawables) { 40 | mAnimationScaleListState.addDrawable(drawable); 41 | } 42 | onStateChange(getState()); 43 | } 44 | 45 | private AnimationScaleListDrawableCompat(@Nullable AnimationScaleListState state, 46 | @Nullable Resources res) { 47 | // Every scale list drawable has its own constant state. 48 | final AnimationScaleListState newState = new AnimationScaleListState(state, this, res); 49 | setConstantState(newState); 50 | onStateChange(getState()); 51 | } 52 | 53 | /** 54 | * Set the current drawable according to the animation scale. If scale is 0, then pick the 55 | * static drawable, otherwise, pick the animatable drawable. 56 | */ 57 | @Override 58 | protected boolean onStateChange(int[] stateSet) { 59 | final boolean changed = super.onStateChange(stateSet); 60 | int idx = mAnimationScaleListState.getCurrentDrawableIndexBasedOnScale(); 61 | return selectDrawable(idx) || changed; 62 | } 63 | 64 | 65 | @Override 66 | public Drawable mutate() { 67 | if (!mMutated && super.mutate() == this) { 68 | mAnimationScaleListState.mutate(); 69 | mMutated = true; 70 | } 71 | return this; 72 | } 73 | 74 | @Override 75 | public void clearMutated() { 76 | super.clearMutated(); 77 | mMutated = false; 78 | } 79 | 80 | @Override 81 | public void start() { 82 | Drawable dr = getCurrent(); 83 | if (dr != null && dr instanceof Animatable) { 84 | ((Animatable) dr).start(); 85 | } 86 | } 87 | 88 | @Override 89 | public void stop() { 90 | Drawable dr = getCurrent(); 91 | if (dr != null && dr instanceof Animatable) { 92 | ((Animatable) dr).stop(); 93 | } 94 | } 95 | 96 | @Override 97 | public boolean isRunning() { 98 | boolean result = false; 99 | Drawable dr = getCurrent(); 100 | if (dr != null && dr instanceof Animatable) { 101 | result = ((Animatable) dr).isRunning(); 102 | } 103 | return result; 104 | } 105 | 106 | static class AnimationScaleListState extends DrawableContainerState { 107 | int[] mThemeAttrs = null; 108 | // The index of the last static drawable. 109 | int mStaticDrawableIndex = -1; 110 | // The index of the last animatable drawable. 111 | int mAnimatableDrawableIndex = -1; 112 | 113 | AnimationScaleListState(AnimationScaleListState orig, 114 | AnimationScaleListDrawableCompat owner, Resources res) { 115 | super(orig, owner, res); 116 | 117 | if (orig != null) { 118 | // Perform a shallow copy and rely on mutate() to deep-copy. 119 | mThemeAttrs = orig.mThemeAttrs; 120 | 121 | mStaticDrawableIndex = orig.mStaticDrawableIndex; 122 | mAnimatableDrawableIndex = orig.mAnimatableDrawableIndex; 123 | } 124 | 125 | } 126 | 127 | void mutate() { 128 | mThemeAttrs = mThemeAttrs != null ? mThemeAttrs.clone() : null; 129 | } 130 | 131 | /** 132 | * Add the drawable into the container. 133 | * This class only keep track one animatable drawable, and one static. If there are multiple 134 | * defined in the XML, then pick the last one. 135 | */ 136 | int addDrawable(Drawable drawable) { 137 | final int pos = addChild(drawable); 138 | if (drawable instanceof Animatable) { 139 | mAnimatableDrawableIndex = pos; 140 | } else { 141 | mStaticDrawableIndex = pos; 142 | } 143 | return pos; 144 | } 145 | 146 | @Override 147 | public Drawable newDrawable() { 148 | return new AnimationScaleListDrawableCompat(this, null); 149 | } 150 | 151 | @Override 152 | public Drawable newDrawable(Resources res) { 153 | return new AnimationScaleListDrawableCompat(this, res); 154 | } 155 | 156 | @Override 157 | @RequiresApi(Build.VERSION_CODES.LOLLIPOP) 158 | public boolean canApplyTheme() { 159 | return mThemeAttrs != null || super.canApplyTheme(); 160 | } 161 | 162 | public int getCurrentDrawableIndexBasedOnScale() { 163 | if (!ValueAnimatorCompat.areAnimatorsEnabled()) { 164 | return mStaticDrawableIndex; 165 | } 166 | return mAnimatableDrawableIndex; 167 | } 168 | } 169 | 170 | @Override 171 | @RequiresApi(Build.VERSION_CODES.LOLLIPOP) 172 | public void applyTheme(@NonNull Resources.Theme theme) { 173 | super.applyTheme(theme); 174 | 175 | onStateChange(getState()); 176 | } 177 | 178 | @Override 179 | protected void setConstantState(@NonNull DrawableContainerState state) { 180 | super.setConstantState(state); 181 | 182 | if (state instanceof AnimationScaleListState) { 183 | mAnimationScaleListState = (AnimationScaleListState) state; 184 | } 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/internal/DrawableCompat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar.internal; 7 | 8 | import android.graphics.PorterDuff; 9 | 10 | import androidx.annotation.Nullable; 11 | 12 | public class DrawableCompat { 13 | 14 | /** 15 | * Parses a {@link android.graphics.PorterDuff.Mode} from a tintMode attribute's enum value. 16 | */ 17 | public static @Nullable PorterDuff.Mode parseTintMode(int value, 18 | @Nullable PorterDuff.Mode defaultMode) { 19 | switch (value) { 20 | case 3: return PorterDuff.Mode.SRC_OVER; 21 | case 5: return PorterDuff.Mode.SRC_IN; 22 | case 9: return PorterDuff.Mode.SRC_ATOP; 23 | case 14: return PorterDuff.Mode.MULTIPLY; 24 | case 15: return PorterDuff.Mode.SCREEN; 25 | case 16: return PorterDuff.Mode.ADD; 26 | default: return defaultMode; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/internal/ObjectAnimatorCompat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar.internal; 7 | 8 | import android.animation.ObjectAnimator; 9 | import android.graphics.Path; 10 | import android.os.Build; 11 | import android.util.Property; 12 | 13 | import androidx.annotation.NonNull; 14 | import androidx.annotation.Nullable; 15 | 16 | /** 17 | * Helper for accessing features in {@link ObjectAnimator} introduced after API level 11 (for 18 | * {@link android.animation.PropertyValuesHolder}) in a backward compatible fashion. 19 | */ 20 | public class ObjectAnimatorCompat { 21 | 22 | private ObjectAnimatorCompat() {} 23 | 24 | /** 25 | * Constructs and returns an ObjectAnimator that animates between color values. A single 26 | * value implies that that value is the one being animated to. Two values imply starting 27 | * and ending values. More than two values imply a starting value, values to animate through 28 | * along the way, and an ending value (these values will be distributed evenly across 29 | * the duration of the animation). 30 | * 31 | * @param target The object whose property is to be animated. This object should have a public 32 | * method on it called {@code setName()}, where {@code name} is the value of the 33 | * {@code propertyName} parameter. 34 | * @param propertyName The name of the property being animated. 35 | * @param values A set of values that the animation will animate between over time. 36 | * @return An ObjectAnimator object that is set up to animate between the given values. 37 | */ 38 | @NonNull 39 | public static ObjectAnimator ofArgb(@Nullable Object target, @NonNull String propertyName, 40 | int... values) { 41 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 42 | return ObjectAnimatorCompatLollipop.ofArgb(target, propertyName, values); 43 | } else { 44 | return ObjectAnimatorCompatBase.ofArgb(target, propertyName, values); 45 | } 46 | } 47 | 48 | /** 49 | * Constructs and returns an ObjectAnimator that animates between color values. A single 50 | * value implies that that value is the one being animated to. Two values imply starting 51 | * and ending values. More than two values imply a starting value, values to animate through 52 | * along the way, and an ending value (these values will be distributed evenly across 53 | * the duration of the animation). 54 | * 55 | * @param target The object whose property is to be animated. 56 | * @param property The property being animated. 57 | * @param values A set of values that the animation will animate between over time. 58 | * @return An ObjectAnimator object that is set up to animate between the given values. 59 | */ 60 | @NonNull 61 | public static ObjectAnimator ofArgb(@Nullable T target, 62 | @NonNull Property property, int... values) { 63 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 64 | return ObjectAnimatorCompatLollipop.ofArgb(target, property, values); 65 | } else { 66 | return ObjectAnimatorCompatBase.ofArgb(target, property, values); 67 | } 68 | } 69 | 70 | /** 71 | * Constructs and returns an ObjectAnimator that animates coordinates along a {@code Path} using 72 | * two properties. A {@code Path} animation moves in two dimensions, animating coordinates 73 | * {@code (x, y)} together to follow the line. In this variation, the coordinates are floats 74 | * that are set to separate properties designated by {@code xPropertyName} and 75 | * {@code yPropertyName}. 76 | * 77 | * @param target The object whose properties are to be animated. This object should have public 78 | * methods on it called {@code setNameX()} and {@code setNameY}, where 79 | * {@code nameX} and {@code nameY} are the value of the {@code xPropertyName} and 80 | * {@code yPropertyName} parameters, respectively. 81 | * @param xPropertyName The name of the property for the x coordinate being animated. 82 | * @param yPropertyName The name of the property for the y coordinate being animated. 83 | * @param path The {@code Path} to animate values along. 84 | * @return An ObjectAnimator object that is set up to animate along {@code path}. 85 | */ 86 | @NonNull 87 | public static ObjectAnimator ofFloat(@Nullable Object target, @NonNull String xPropertyName, 88 | @NonNull String yPropertyName, @NonNull Path path) { 89 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 90 | return ObjectAnimatorCompatLollipop.ofFloat(target, xPropertyName, yPropertyName, path); 91 | } else { 92 | return ObjectAnimatorCompatBase.ofFloat(target, xPropertyName, yPropertyName, path); 93 | } 94 | } 95 | 96 | /** 97 | * Constructs and returns an ObjectAnimator that animates coordinates along a {@code Path} using 98 | * two properties. A {@code Path} animation moves in two dimensions, animating coordinates 99 | * {@code (x, y)} together to follow the line. In this variation, the coordinates are floats 100 | * that are set to separate properties, {@code xProperty} and {@code yProperty}. 101 | * 102 | * @param target The object whose properties are to be animated. 103 | * @param xProperty The property for the x coordinate being animated. 104 | * @param yProperty The property for the y coordinate being animated. 105 | * @param path The {@code Path} to animate values along. 106 | * @return An ObjectAnimator object that is set up to animate along {@code path}. 107 | */ 108 | @NonNull 109 | public static ObjectAnimator ofFloat(@Nullable T target, 110 | @NonNull Property xProperty, 111 | @NonNull Property yProperty, 112 | @NonNull Path path) { 113 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 114 | return ObjectAnimatorCompatLollipop.ofFloat(target, xProperty, yProperty, path); 115 | } else { 116 | return ObjectAnimatorCompatBase.ofFloat(target, xProperty, yProperty, path); 117 | } 118 | } 119 | 120 | /** 121 | * Constructs and returns an ObjectAnimator that animates coordinates along a {@code Path} using 122 | * two properties. A {@code Path} animation moves in two dimensions, animating coordinates 123 | * {@code (x, y)} together to follow the line. In this variation, the coordinates are integers 124 | * that are set to separate properties designated by {@code xPropertyName} and 125 | * {@code yPropertyName}. 126 | * 127 | * @param target The object whose properties are to be animated. This object should have public 128 | * methods on it called {@code setNameX()} and {@code setNameY}, where 129 | * {@code nameX} and {@code nameY} are the value of {@code xPropertyName} and 130 | * {@code yPropertyName} parameters, respectively. 131 | * @param xPropertyName The name of the property for the x coordinate being animated. 132 | * @param yPropertyName The name of the property for the y coordinate being animated. 133 | * @param path The {@code Path} to animate values along. 134 | * @return An ObjectAnimator object that is set up to animate along {@code path}. 135 | */ 136 | @NonNull 137 | public static ObjectAnimator ofInt(@Nullable Object target, @NonNull String xPropertyName, 138 | @NonNull String yPropertyName, @NonNull Path path) { 139 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 140 | return ObjectAnimatorCompatLollipop.ofInt(target, xPropertyName, yPropertyName, path); 141 | } else { 142 | return ObjectAnimatorCompatBase.ofInt(target, xPropertyName, yPropertyName, path); 143 | } 144 | } 145 | 146 | /** 147 | * Constructs and returns an ObjectAnimator that animates coordinates along a {@code Path} using 148 | * two properties. A {@code Path} animation moves in two dimensions, animating coordinates 149 | * {@code (x, y)} together to follow the line. In this variation, the coordinates are integers 150 | * that are set to separate properties, {@code xProperty} and {@code yProperty}. 151 | * 152 | * @param target The object whose properties are to be animated. 153 | * @param xProperty The property for the x coordinate being animated. 154 | * @param yProperty The property for the y coordinate being animated. 155 | * @param path The {@code Path} to animate values along. 156 | * @return An ObjectAnimator object that is set up to animate along {@code path}. 157 | */ 158 | @NonNull 159 | public static ObjectAnimator ofInt(@Nullable T target, 160 | @NonNull Property xProperty, 161 | @NonNull Property yProperty, 162 | @NonNull Path path) { 163 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 164 | return ObjectAnimatorCompatLollipop.ofInt(target, xProperty, yProperty, path); 165 | } else { 166 | return ObjectAnimatorCompatBase.ofInt(target, xProperty, yProperty, path); 167 | } 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/internal/ObjectAnimatorCompatBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar.internal; 7 | 8 | import android.animation.ArgbEvaluator; 9 | import android.animation.ObjectAnimator; 10 | import android.animation.PropertyValuesHolder; 11 | import android.graphics.Path; 12 | import android.graphics.PathMeasure; 13 | import android.util.Property; 14 | 15 | import androidx.annotation.NonNull; 16 | import androidx.annotation.Nullable; 17 | import androidx.annotation.Size; 18 | 19 | class ObjectAnimatorCompatBase { 20 | 21 | // As per android.support.v4.view.animation.FastOutLinearInInterpolator. 22 | private static final int NUM_POINTS = 201; 23 | 24 | private ObjectAnimatorCompatBase() {} 25 | 26 | @NonNull 27 | public static ObjectAnimator ofArgb(@Nullable Object target, @NonNull String propertyName, 28 | int... values) { 29 | ObjectAnimator animator = ObjectAnimator.ofInt(target, propertyName, values); 30 | animator.setEvaluator(new ArgbEvaluator()); 31 | return animator; 32 | } 33 | 34 | @NonNull 35 | public static ObjectAnimator ofArgb(@Nullable T target, 36 | @NonNull Property property, int... values) { 37 | ObjectAnimator animator = ObjectAnimator.ofInt(target, property, values); 38 | animator.setEvaluator(new ArgbEvaluator()); 39 | return animator; 40 | } 41 | 42 | @NonNull 43 | public static ObjectAnimator ofFloat(@Nullable Object target, @NonNull String xPropertyName, 44 | @NonNull String yPropertyName, @NonNull Path path) { 45 | 46 | float[] xValues = new float[NUM_POINTS]; 47 | float[] yValues = new float[NUM_POINTS]; 48 | calculateXYValues(path, xValues, yValues); 49 | 50 | PropertyValuesHolder xPvh = PropertyValuesHolder.ofFloat(xPropertyName, xValues); 51 | PropertyValuesHolder yPvh = PropertyValuesHolder.ofFloat(yPropertyName, yValues); 52 | 53 | return ObjectAnimator.ofPropertyValuesHolder(target, xPvh, yPvh); 54 | } 55 | 56 | @NonNull 57 | public static ObjectAnimator ofFloat(@Nullable T target, 58 | @NonNull Property xProperty, 59 | @NonNull Property yProperty, 60 | @NonNull Path path) { 61 | 62 | float[] xValues = new float[NUM_POINTS]; 63 | float[] yValues = new float[NUM_POINTS]; 64 | calculateXYValues(path, xValues, yValues); 65 | 66 | PropertyValuesHolder xPvh = PropertyValuesHolder.ofFloat(xProperty, xValues); 67 | PropertyValuesHolder yPvh = PropertyValuesHolder.ofFloat(yProperty, yValues); 68 | 69 | return ObjectAnimator.ofPropertyValuesHolder(target, xPvh, yPvh); 70 | } 71 | 72 | @NonNull 73 | public static ObjectAnimator ofInt(@Nullable Object target, @NonNull String xPropertyName, 74 | @NonNull String yPropertyName, @NonNull Path path) { 75 | 76 | int[] xValues = new int[NUM_POINTS]; 77 | int[] yValues = new int[NUM_POINTS]; 78 | calculateXYValues(path, xValues, yValues); 79 | 80 | PropertyValuesHolder xPvh = PropertyValuesHolder.ofInt(xPropertyName, xValues); 81 | PropertyValuesHolder yPvh = PropertyValuesHolder.ofInt(yPropertyName, yValues); 82 | 83 | return ObjectAnimator.ofPropertyValuesHolder(target, xPvh, yPvh); 84 | } 85 | 86 | @NonNull 87 | public static ObjectAnimator ofInt(@Nullable T target, 88 | @NonNull Property xProperty, 89 | @NonNull Property yProperty, 90 | @NonNull Path path) { 91 | 92 | int[] xValues = new int[NUM_POINTS]; 93 | int[] yValues = new int[NUM_POINTS]; 94 | calculateXYValues(path, xValues, yValues); 95 | 96 | PropertyValuesHolder xPvh = PropertyValuesHolder.ofInt(xProperty, xValues); 97 | PropertyValuesHolder yPvh = PropertyValuesHolder.ofInt(yProperty, yValues); 98 | 99 | return ObjectAnimator.ofPropertyValuesHolder(target, xPvh, yPvh); 100 | } 101 | 102 | private static void calculateXYValues(@NonNull Path path, 103 | @NonNull @Size(NUM_POINTS) float[] xValues, 104 | @NonNull @Size(NUM_POINTS) float[] yValues) { 105 | 106 | PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */); 107 | float pathLength = pathMeasure.getLength(); 108 | 109 | float[] position = new float[2]; 110 | for (int i = 0; i < NUM_POINTS; ++i) { 111 | float distance = (i * pathLength) / (NUM_POINTS - 1); 112 | pathMeasure.getPosTan(distance, position, null /* tangent */); 113 | xValues[i] = position[0]; 114 | yValues[i] = position[1]; 115 | } 116 | } 117 | 118 | private static void calculateXYValues(@NonNull Path path, 119 | @NonNull @Size(NUM_POINTS) int[] xValues, 120 | @NonNull @Size(NUM_POINTS) int[] yValues) { 121 | 122 | PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */); 123 | float pathLength = pathMeasure.getLength(); 124 | 125 | float[] position = new float[2]; 126 | for (int i = 0; i < NUM_POINTS; ++i) { 127 | float distance = (i * pathLength) / (NUM_POINTS - 1); 128 | pathMeasure.getPosTan(distance, position, null /* tangent */); 129 | xValues[i] = Math.round(position[0]); 130 | yValues[i] = Math.round(position[1]); 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/internal/ObjectAnimatorCompatLollipop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar.internal; 7 | 8 | import android.animation.ObjectAnimator; 9 | import android.annotation.TargetApi; 10 | import android.graphics.Path; 11 | import android.os.Build; 12 | import android.util.Property; 13 | 14 | import androidx.annotation.NonNull; 15 | import androidx.annotation.Nullable; 16 | 17 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 18 | class ObjectAnimatorCompatLollipop { 19 | 20 | private ObjectAnimatorCompatLollipop() {} 21 | 22 | @NonNull 23 | public static ObjectAnimator ofArgb(@Nullable Object target, @NonNull String propertyName, 24 | int... values) { 25 | return ObjectAnimator.ofArgb(target, propertyName, values); 26 | } 27 | 28 | @NonNull 29 | public static ObjectAnimator ofArgb(@Nullable T target, 30 | @NonNull Property property, int... values) { 31 | return ObjectAnimator.ofArgb(target, property, values); 32 | } 33 | 34 | @NonNull 35 | public static ObjectAnimator ofFloat(@Nullable Object target, @NonNull String xPropertyName, 36 | @NonNull String yPropertyName, @NonNull Path path) { 37 | return ObjectAnimator.ofFloat(target, xPropertyName, yPropertyName, path); 38 | } 39 | 40 | @NonNull 41 | public static ObjectAnimator ofFloat(@Nullable T target, 42 | @NonNull Property xProperty, 43 | @NonNull Property yProperty, 44 | @NonNull Path path) { 45 | return ObjectAnimator.ofFloat(target, xProperty, yProperty, path); 46 | } 47 | 48 | @NonNull 49 | public static ObjectAnimator ofInt(@Nullable Object target, @NonNull String xPropertyName, 50 | @NonNull String yPropertyName, @NonNull Path path) { 51 | return ObjectAnimator.ofInt(target, xPropertyName, yPropertyName, path); 52 | } 53 | 54 | @NonNull 55 | public static ObjectAnimator ofInt(@Nullable T target, 56 | @NonNull Property xProperty, 57 | @NonNull Property yProperty, 58 | @NonNull Path path) { 59 | return ObjectAnimator.ofInt(target, xProperty, yProperty, path); 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/internal/ThemeUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar.internal; 7 | 8 | import android.content.Context; 9 | import android.content.res.TypedArray; 10 | 11 | import androidx.annotation.AttrRes; 12 | import androidx.annotation.ColorInt; 13 | import androidx.annotation.NonNull; 14 | 15 | public class ThemeUtils { 16 | 17 | private ThemeUtils() {} 18 | 19 | @ColorInt 20 | public static int getColorFromAttrRes(@AttrRes int attrRes, @ColorInt int defaultValue, 21 | @NonNull Context context) { 22 | TypedArray a = context.obtainStyledAttributes(new int[] { attrRes }); 23 | try { 24 | return a.getColor(0, defaultValue); 25 | } finally { 26 | a.recycle(); 27 | } 28 | } 29 | 30 | public static float getFloatFromAttrRes(@AttrRes int attrRes, float defaultValue, 31 | @NonNull Context context) { 32 | TypedArray a = context.obtainStyledAttributes(new int[] { attrRes }); 33 | try { 34 | return a.getFloat(0, defaultValue); 35 | } finally { 36 | a.recycle(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /library/src/main/java/me/zhanghai/android/materialprogressbar/internal/ValueAnimatorCompat.java: -------------------------------------------------------------------------------- 1 | package me.zhanghai.android.materialprogressbar.internal; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.annotation.SuppressLint; 5 | import android.os.Build; 6 | 7 | import java.lang.reflect.Field; 8 | import java.lang.reflect.Method; 9 | 10 | import androidx.annotation.NonNull; 11 | import androidx.annotation.Nullable; 12 | 13 | public class ValueAnimatorCompat { 14 | 15 | @NonNull 16 | private static final Object sValueAnimatorGetDurationScaleMethodLock = new Object(); 17 | private static boolean sValueAnimatorGetDurationScaleMethodInitialized; 18 | @Nullable 19 | private static Method sValueAnimatorGetDurationScaleMethod; 20 | 21 | @NonNull 22 | private static final Object sValueAnimatorSDurationScaleFieldLock = new Object(); 23 | private static boolean sValueAnimatorSDurationScaleFieldInitialized; 24 | @Nullable 25 | private static Field sValueAnimatorSDurationScaleField; 26 | 27 | 28 | private ValueAnimatorCompat() {} 29 | 30 | public static boolean areAnimatorsEnabled() { 31 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 32 | return ValueAnimator.areAnimatorsEnabled(); 33 | } 34 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 35 | Method valueAnimatorGetDurationScaleMethod = getValueAnimatorGetDurationScaleMethod(); 36 | if (valueAnimatorGetDurationScaleMethod != null) { 37 | try { 38 | float durationScale = (float) valueAnimatorGetDurationScaleMethod.invoke(null); 39 | return durationScale != 0; 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | } 45 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 46 | Field valueAnimatorSDurationScaleField = getValueAnimatorSDurationScaleField(); 47 | if (valueAnimatorSDurationScaleField != null) { 48 | try { 49 | float durationScale = (float) valueAnimatorSDurationScaleField.get(null); 50 | return durationScale != 0; 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | } 56 | return true; 57 | } 58 | 59 | @Nullable 60 | @SuppressLint("PrivateApi") 61 | private static Method getValueAnimatorGetDurationScaleMethod() { 62 | synchronized (sValueAnimatorGetDurationScaleMethodLock) { 63 | if (!sValueAnimatorGetDurationScaleMethodInitialized) { 64 | try { 65 | //noinspection JavaReflectionMemberAccess 66 | sValueAnimatorGetDurationScaleMethod = ValueAnimator.class.getDeclaredMethod( 67 | "getDurationScale"); 68 | sValueAnimatorGetDurationScaleMethod.setAccessible(true); 69 | } catch (Exception e) { 70 | e.printStackTrace(); 71 | } 72 | sValueAnimatorGetDurationScaleMethodInitialized = true; 73 | } 74 | return sValueAnimatorGetDurationScaleMethod; 75 | } 76 | } 77 | 78 | @Nullable 79 | private static Field getValueAnimatorSDurationScaleField() { 80 | synchronized (sValueAnimatorSDurationScaleFieldLock) { 81 | if (!sValueAnimatorSDurationScaleFieldInitialized) { 82 | try { 83 | //noinspection JavaReflectionMemberAccess 84 | sValueAnimatorSDurationScaleField = ValueAnimator.class.getDeclaredField( 85 | "sDurationScale"); 86 | sValueAnimatorSDurationScaleField.setAccessible(true); 87 | } catch (Exception e) { 88 | e.printStackTrace(); 89 | } 90 | sValueAnimatorSDurationScaleFieldInitialized = true; 91 | } 92 | return sValueAnimatorSDurationScaleField; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /library/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 20 | 21 | 25 | 26 | 35 | 36 | 42 | 43 | 49 | 50 | 56 | 57 | 63 | 64 | 70 | 71 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | 5 | compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION) 6 | buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION 7 | 8 | defaultConfig { 9 | applicationId "me.zhanghai.android.materialprogressbar.sample" 10 | minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK_VERSION) 11 | targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION) 12 | versionCode Integer.parseInt(project.VERSION_CODE) 13 | versionName project.VERSION_NAME 14 | } 15 | 16 | signingConfigs { 17 | release { 18 | storeFile file('../../github.jks') 19 | storePassword System.console() != null ? System.console().readLine("\nKeystore password: ") : "" 20 | keyAlias 'materialprogressbar' 21 | keyPassword System.console() != null ? System.console().readLine("\nKey password: ") : "" 22 | } 23 | } 24 | 25 | buildTypes { 26 | release { 27 | minifyEnabled true 28 | shrinkResources true 29 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 30 | signingConfig signingConfigs.release 31 | } 32 | } 33 | } 34 | 35 | dependencies { 36 | implementation fileTree(dir: 'libs', include: ['*.jar']) 37 | implementation 'androidx.appcompat:appcompat:1.0.2' 38 | implementation 'com.jakewharton:butterknife:9.0.0-rc1' 39 | annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1' 40 | implementation project(':library') 41 | } 42 | -------------------------------------------------------------------------------- /sample/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 /opt/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 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 11 | 12 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 37 | 38 | 39 | 43 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /sample/src/main/java/me/zhanghai/android/materialprogressbar/sample/AboutActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar.sample; 7 | 8 | import android.os.Bundle; 9 | import android.text.method.LinkMovementMethod; 10 | import android.view.MenuItem; 11 | import android.widget.TextView; 12 | 13 | import androidx.appcompat.app.AppCompatActivity; 14 | import butterknife.BindView; 15 | import butterknife.ButterKnife; 16 | 17 | public class AboutActivity extends AppCompatActivity { 18 | 19 | @BindView(R.id.version) 20 | TextView mVersionText; 21 | @BindView(R.id.github) 22 | TextView mGithubText; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | 28 | setContentView(R.layout.about_activity); 29 | ButterKnife.bind(this); 30 | 31 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 32 | 33 | String version = getString(R.string.about_version_format, BuildConfig.VERSION_NAME); 34 | mVersionText.setText(version); 35 | mGithubText.setMovementMethod(LinkMovementMethod.getInstance()); 36 | } 37 | 38 | @Override 39 | public boolean onOptionsItemSelected(MenuItem item) { 40 | switch (item.getItemId()) { 41 | case android.R.id.home: 42 | AppUtils.navigateUp(this); 43 | return true; 44 | default: 45 | return super.onOptionsItemSelected(item); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sample/src/main/java/me/zhanghai/android/materialprogressbar/sample/Animators.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar.sample; 7 | 8 | import android.animation.ValueAnimator; 9 | import android.view.animation.LinearInterpolator; 10 | import android.widget.ProgressBar; 11 | 12 | class Animators { 13 | 14 | private Animators() {} 15 | 16 | public static ValueAnimator makeDeterminateCircularPrimaryProgressAnimator( 17 | final ProgressBar[] progressBars) { 18 | ValueAnimator animator = ValueAnimator.ofInt(0, 150); 19 | animator.setDuration(6000); 20 | animator.setInterpolator(new LinearInterpolator()); 21 | animator.setRepeatCount(ValueAnimator.INFINITE); 22 | animator.addUpdateListener( 23 | new ValueAnimator.AnimatorUpdateListener() { 24 | @Override 25 | public void onAnimationUpdate(ValueAnimator animator) { 26 | int value = (int) animator.getAnimatedValue(); 27 | for (ProgressBar progressBar : progressBars) { 28 | progressBar.setProgress(value); 29 | } 30 | } 31 | }); 32 | return animator; 33 | } 34 | 35 | public static ValueAnimator makeDeterminateCircularPrimaryAndSecondaryProgressAnimator( 36 | final ProgressBar[] progressBars) { 37 | ValueAnimator animator = makeDeterminateCircularPrimaryProgressAnimator(progressBars); 38 | animator.addUpdateListener( 39 | new ValueAnimator.AnimatorUpdateListener() { 40 | @Override 41 | public void onAnimationUpdate(ValueAnimator animator) { 42 | int value = Math.round(1.25f * (int) animator.getAnimatedValue()); 43 | for (ProgressBar progressBar : progressBars) { 44 | progressBar.setSecondaryProgress(value); 45 | } 46 | } 47 | }); 48 | return animator; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /sample/src/main/java/me/zhanghai/android/materialprogressbar/sample/AppUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar.sample; 7 | 8 | import android.app.Activity; 9 | import android.content.Intent; 10 | import android.os.Bundle; 11 | 12 | import androidx.core.app.NavUtils; 13 | import androidx.core.app.TaskStackBuilder; 14 | 15 | public class AppUtils { 16 | 17 | private AppUtils() {} 18 | 19 | // From http://developer.android.com/training/implementing-navigation/ancestral.html#NavigateUp . 20 | public static void navigateUp(Activity activity, Bundle extras) { 21 | Intent upIntent = NavUtils.getParentActivityIntent(activity); 22 | if (upIntent != null) { 23 | if (extras != null) { 24 | upIntent.putExtras(extras); 25 | } 26 | if (NavUtils.shouldUpRecreateTask(activity, upIntent)) { 27 | // This activity is NOT part of this app's task, so create a new task 28 | // when navigating up, with a synthesized back stack. 29 | TaskStackBuilder.create(activity) 30 | // Add all of this activity's parents to the back stack. 31 | .addNextIntentWithParentStack(upIntent) 32 | // Navigate up to the closest parent. 33 | .startActivities(); 34 | } else { 35 | // This activity is part of this app's task, so simply 36 | // navigate up to the logical parent activity. 37 | // According to http://stackoverflow.com/a/14792752/2420519 38 | //NavUtils.navigateUpTo(activity, upIntent); 39 | upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 40 | activity.startActivity(upIntent); 41 | } 42 | } 43 | activity.finish(); 44 | } 45 | 46 | public static void navigateUp(Activity activity) { 47 | navigateUp(activity, null); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sample/src/main/java/me/zhanghai/android/materialprogressbar/sample/DeterminateCircularSampleActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar.sample; 7 | 8 | import android.animation.ValueAnimator; 9 | import android.os.Bundle; 10 | import android.view.MenuItem; 11 | import android.widget.ProgressBar; 12 | 13 | import androidx.appcompat.app.AppCompatActivity; 14 | import butterknife.BindViews; 15 | import butterknife.ButterKnife; 16 | 17 | public class DeterminateCircularSampleActivity extends AppCompatActivity { 18 | 19 | @BindViews({ 20 | R.id.normal_progress, 21 | R.id.tinted_normal_progress, 22 | R.id.dynamic_progress, 23 | R.id.tinted_dynamic_progress 24 | }) 25 | ProgressBar[] mPrimaryProgressBars; 26 | @BindViews({ 27 | R.id.normal_secondary_progress, 28 | R.id.normal_background_progress, 29 | R.id.tinted_normal_secondary_progress, 30 | R.id.tinted_normal_background_progress, 31 | R.id.dynamic_secondary_progress, 32 | R.id.dynamic_background_progress, 33 | R.id.tinted_dynamic_secondary_progress, 34 | R.id.tinted_dynamic_background_progress 35 | }) 36 | ProgressBar[] mPrimaryAndSecondaryProgressBars; 37 | 38 | private ValueAnimator mPrimaryProgressAnimator; 39 | private ValueAnimator mPrimaryAndSecondaryProgressAnimator; 40 | 41 | @Override 42 | protected void onCreate(Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | 45 | setContentView(R.layout.determinate_circular_sample_activity); 46 | ButterKnife.bind(this); 47 | 48 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 49 | 50 | mPrimaryProgressAnimator = 51 | Animators.makeDeterminateCircularPrimaryProgressAnimator(mPrimaryProgressBars); 52 | mPrimaryAndSecondaryProgressAnimator = 53 | Animators.makeDeterminateCircularPrimaryAndSecondaryProgressAnimator( 54 | mPrimaryAndSecondaryProgressBars); 55 | } 56 | 57 | @Override 58 | public void onAttachedToWindow() { 59 | super.onAttachedToWindow(); 60 | 61 | mPrimaryProgressAnimator.start(); 62 | mPrimaryAndSecondaryProgressAnimator.start(); 63 | } 64 | 65 | @Override 66 | public void onDetachedFromWindow() { 67 | super.onDetachedFromWindow(); 68 | 69 | mPrimaryProgressAnimator.end(); 70 | mPrimaryAndSecondaryProgressAnimator.end(); 71 | } 72 | 73 | @Override 74 | public boolean onOptionsItemSelected(MenuItem item) { 75 | switch (item.getItemId()) { 76 | case android.R.id.home: 77 | AppUtils.navigateUp(this); 78 | return true; 79 | default: 80 | return super.onOptionsItemSelected(item); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /sample/src/main/java/me/zhanghai/android/materialprogressbar/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Zhang Hai 3 | * All Rights Reserved. 4 | */ 5 | 6 | package me.zhanghai.android.materialprogressbar.sample; 7 | 8 | import android.animation.ValueAnimator; 9 | import android.content.Intent; 10 | import android.os.Bundle; 11 | import android.view.Menu; 12 | import android.view.MenuItem; 13 | import android.widget.ProgressBar; 14 | 15 | import androidx.appcompat.app.AppCompatActivity; 16 | import butterknife.BindViews; 17 | import butterknife.ButterKnife; 18 | 19 | public class MainActivity extends AppCompatActivity { 20 | 21 | @BindViews({ 22 | R.id.determinate_circular_large_progress, 23 | R.id.determinate_circular_progress, 24 | R.id.determinate_circular_small_progress 25 | }) 26 | ProgressBar[] mDeterminateCircularProgressBars; 27 | 28 | private ValueAnimator mDeterminateCircularProgressAnimator; 29 | 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | 34 | setContentView(R.layout.main_activity); 35 | ButterKnife.bind(this); 36 | 37 | mDeterminateCircularProgressAnimator = 38 | Animators.makeDeterminateCircularPrimaryProgressAnimator( 39 | mDeterminateCircularProgressBars); 40 | } 41 | 42 | @Override 43 | public void onAttachedToWindow() { 44 | super.onAttachedToWindow(); 45 | 46 | mDeterminateCircularProgressAnimator.start(); 47 | } 48 | 49 | @Override 50 | public void onDetachedFromWindow() { 51 | super.onDetachedFromWindow(); 52 | 53 | mDeterminateCircularProgressAnimator.end(); 54 | } 55 | 56 | @Override 57 | public boolean onCreateOptionsMenu(Menu menu) { 58 | getMenuInflater().inflate(R.menu.menu_main, menu); 59 | return true; 60 | } 61 | 62 | @Override 63 | public boolean onOptionsItemSelected(MenuItem item) { 64 | switch (item.getItemId()) { 65 | case R.id.action_about: 66 | startActivity(new Intent(this, AboutActivity.class)); 67 | return true; 68 | case R.id.action_determinate_circular_sample: 69 | startActivity(new Intent(this, DeterminateCircularSampleActivity.class)); 70 | return true; 71 | default: 72 | return super.onOptionsItemSelected(item); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /sample/src/main/launcher_icon-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanghai/MaterialProgressBar/2b39099237bb265b6a20357470e6cecf6e3112b2/sample/src/main/launcher_icon-web.png -------------------------------------------------------------------------------- /sample/src/main/res/layout/about_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 15 | 16 | 25 | 26 | 31 | 32 | 39 | 40 | 47 | 48 | 55 | 56 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/determinate_circular_sample_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 15 | 16 | 24 | 25 | 31 | 32 | 35 | 36 | 43 | 44 | 51 | 52 | 60 | 61 | 62 | 69 | 70 | 73 | 74 | 82 | 83 | 92 | 93 | 104 | 105 | 106 | 113 | 114 | 117 | 118 | 126 | 127 | 135 | 136 | 145 | 146 | 147 | 154 | 155 | 158 | 159 | 168 | 169 | 179 | 180 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/main_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 15 | 16 | 24 | 25 | 26 | 27 | 32 | 33 | 38 | 39 | 45 | 46 | 51 | 52 | 59 | 60 | 65 | 66 | 76 | 77 | 78 | 79 | 84 | 85 | 90 | 91 | 96 | 97 | 102 | 103 | 109 | 110 | 115 | 116 | 123 | 124 | 125 | 126 | 131 | 132 | 137 | 138 | 143 | 144 | 149 | 150 | 153 | 154 | 161 | 162 | 169 | 170 | 177 | 178 | 179 | 180 | 181 | 186 | 187 | 192 | 193 | 196 | 197 | 203 | 204 | 210 | 211 | 217 | 218 | 219 | 224 | 225 | 228 | 229 | 235 | 236 | 242 | 243 | 249 | 250 | 251 | 252 | 253 | 258 | 259 | 266 | 267 | 273 | 274 | 280 | 281 | 282 | 292 | 293 | 294 | 301 | 302 | 308 | 309 | 315 | 316 | 317 | 326 | 327 | 328 | 329 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 13 | 14 | 19 | 20 | 25 | 26 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/launcher_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanghai/MaterialProgressBar/2b39099237bb265b6a20357470e6cecf6e3112b2/sample/src/main/res/mipmap-hdpi/launcher_icon.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/launcher_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanghai/MaterialProgressBar/2b39099237bb265b6a20357470e6cecf6e3112b2/sample/src/main/res/mipmap-mdpi/launcher_icon.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/launcher_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanghai/MaterialProgressBar/2b39099237bb265b6a20357470e6cecf6e3112b2/sample/src/main/res/mipmap-xhdpi/launcher_icon.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/launcher_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanghai/MaterialProgressBar/2b39099237bb265b6a20357470e6cecf6e3112b2/sample/src/main/res/mipmap-xxhdpi/launcher_icon.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/launcher_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanghai/MaterialProgressBar/2b39099237bb265b6a20357470e6cecf6e3112b2/sample/src/main/res/mipmap-xxxhdpi/launcher_icon.png -------------------------------------------------------------------------------- /sample/src/main/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 24dp 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | #f44336 10 | #42f44336 11 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 16dp 10 | 16dp 11 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | MaterialProgressBar Sample 11 | 12 | Framework Implementation 13 | Library Implementation 14 | Library Implementation (Tinted) 15 | Determinate Horizontal ProgressBar 16 | Indeterminate Horizontal ProgressBar 17 | Determinate Circular ProgressBar 18 | Indeterminate Circular ProgressBar 19 | ProgressBar on Toolbar 20 | Horizontal 21 | Indeterminate Horizontal 22 | (Not Available) 23 | 24 | About 25 | @string/determinate_circular_title 26 | 27 | Determinate Circular Sample 28 | Normal Style 29 | Normal Style (Tinted) 30 | Dynamic Style 31 | Dynamic Style (Tinted) 32 | 33 | About 34 | MaterialProgressBar 35 | Version %1$s 36 | Zhang Hai 2015–2016 37 | View on GitHub 38 | 39 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 |