├── materialloadingprogressbar
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── attrs.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── lsjwzh
│ │ │ └── widget
│ │ │ └── materialloadingprogressbar
│ │ │ ├── CircleProgressBar.java
│ │ │ └── MaterialProgressDrawable.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── lsjwzh
│ │ └── widget
│ │ └── ApplicationTest.java
├── build.gradle
├── proguard-rules.pro
└── gradle.properties
├── materialloadingprogressbardemo
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ └── strings.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── lsjwzh
│ │ │ └── materialloadingprogressbardemo
│ │ │ └── MainActivity.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── lsjwzh
│ │ └── materialloadingprogressbardemo
│ │ └── ApplicationTest.java
├── build.gradle
└── proguard-rules.pro
├── screen.gif
├── screen_1.gif
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/materialloadingprogressbar/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/materialloadingprogressbardemo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/materialloadingprogressbar/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/screen.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsjwzh/MaterialLoadingProgressBar/HEAD/screen.gif
--------------------------------------------------------------------------------
/screen_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsjwzh/MaterialLoadingProgressBar/HEAD/screen_1.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':materialloadingprogressbar', ':materialloadingprogressbardemo'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsjwzh/MaterialLoadingProgressBar/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/materialloadingprogressbar/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/materialloadingprogressbardemo/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
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-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/materialloadingprogressbardemo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | MaterialLoadingProgressBarDemo
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/materialloadingprogressbardemo/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/materialloadingprogressbardemo/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # idea
29 | .idea/
30 |
31 | *.iml
32 |
33 | */*.iml
34 |
--------------------------------------------------------------------------------
/materialloadingprogressbar/src/androidTest/java/com/lsjwzh/widget/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.lsjwzh.widget;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/materialloadingprogressbardemo/src/androidTest/java/com/lsjwzh/materialloadingprogressbardemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.lsjwzh.materialloadingprogressbardemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/materialloadingprogressbar/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 9
9 | targetSdkVersion 21
10 | versionCode 12
11 | versionName "0.5.8"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.android.support:appcompat-v7:21.0.3'
24 | }
25 |
26 | //apply from: "${rootDir}/gradle-mvn-push.gradle"
27 |
28 |
--------------------------------------------------------------------------------
/materialloadingprogressbardemo/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 9
9 | targetSdkVersion 21
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile project(':materialloadingprogressbar')
24 | compile 'com.android.support:appcompat-v7:21.0.3'
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/materialloadingprogressbar/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/panwenye/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 |
--------------------------------------------------------------------------------
/materialloadingprogressbardemo/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/panwenye/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 |
--------------------------------------------------------------------------------
/materialloadingprogressbardemo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/materialloadingprogressbar/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=MaterialLoadingProgressBar Core Library
2 | POM_ARTIFACT_ID=materialloadingprogressbar
3 | POM_PACKAGING=aar
4 |
5 | #RELEASE_REPOSITORY_URL=http://nexus.mofun.so:8081/nexus/content/repositories/releases/
6 |
7 | VERSION_NAME=0.5.8-RELEASE
8 | VERSION_CODE=16
9 | GROUP=com.lsjwzh
10 |
11 | POM_DESCRIPTION=MaterialLoadingProgressBar provide a styled ProgressBar which looks like SwipeRefreshLayout's loading indicator(support-v4 v21+)
12 | POM_URL=https://github.com/lsjwzh/materialloadingprogressbar
13 | POM_SCM_URL=https://github.com/lsjwzh/materialloadingprogressbar
14 | POM_SCM_CONNECTION=scm:git:git://github.com/lsjwzh/materialloadingprogressbar.git
15 | POM_SCM_DEV_CONNECTION=scm:git:git://github.com/lsjwzh/materialloadingprogressbar.git
16 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
17 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
18 | POM_LICENCE_DIST=repo
19 | POM_DEVELOPER_ID=lsjwzh
20 | POM_DEVELOPER_NAME=lsjwzh
21 | POM_DEVELOPER_EMAIL=lsjwzh@gmail.com
22 |
--------------------------------------------------------------------------------
/materialloadingprogressbar/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/materialloadingprogressbardemo/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
20 |
26 |
27 |
36 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/materialloadingprogressbardemo/src/main/java/com/lsjwzh/materialloadingprogressbardemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.lsjwzh.materialloadingprogressbardemo;
2 |
3 | import android.os.Handler;
4 | import android.support.v7.app.ActionBarActivity;
5 | import android.os.Bundle;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.view.View;
9 |
10 | import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
11 |
12 |
13 | public class MainActivity extends ActionBarActivity {
14 | int progress = 0;
15 | private Handler handler;
16 | CircleProgressBar progress1;
17 | CircleProgressBar progress2;
18 | CircleProgressBar progressWithArrow;
19 | CircleProgressBar progressWithoutBg;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_main);
25 | progress1 = (CircleProgressBar) findViewById(R.id.progress1);
26 | progress2 = (CircleProgressBar) findViewById(R.id.progress2);
27 | progressWithArrow = (CircleProgressBar) findViewById(R.id.progressWithArrow);
28 | progressWithoutBg = (CircleProgressBar) findViewById(R.id.progressWithoutBg);
29 |
30 |
31 | // progress1.setColorSchemeResources(android.R.color.holo_blue_bright);
32 | progress2.setColorSchemeResources(android.R.color.holo_green_light,android.R.color.holo_orange_light,android.R.color.holo_red_light);
33 |
34 | progressWithArrow.setColorSchemeResources(android.R.color.holo_orange_light);
35 | progressWithoutBg.setColorSchemeResources(android.R.color.holo_red_light);
36 |
37 | handler = new Handler();
38 | for (int i = 0; i < 10; i++) {
39 | final int finalI = i;
40 | handler.postDelayed(new Runnable() {
41 | @Override
42 | public void run() {
43 | if(finalI *10>=90){
44 | progress1.setVisibility(View.VISIBLE);
45 | progress2.setVisibility(View.INVISIBLE);
46 | }else {
47 | progress2.setProgress(finalI * 10);
48 | }
49 | }
50 | },1000*(i+1));
51 | }
52 |
53 | }
54 |
55 |
56 | @Override
57 | public boolean onCreateOptionsMenu(Menu menu) {
58 | // Inflate the menu; this adds items to the action bar if it is present.
59 | getMenuInflater().inflate(R.menu.menu_main, menu);
60 | return true;
61 | }
62 |
63 | @Override
64 | public boolean onOptionsItemSelected(MenuItem item) {
65 | // Handle action bar item clicks here. The action bar will
66 | // automatically handle clicks on the Home/Up button, so long
67 | // as you specify a parent activity in AndroidManifest.xml.
68 | int id = item.getItemId();
69 |
70 | //noinspection SimplifiableIfStatement
71 | if (id == R.id.action_settings) {
72 | return true;
73 | }
74 |
75 | return super.onOptionsItemSelected(item);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](http://androidweekly.net/issues/issue-143) [](http://android-arsenal.com/details/1/1525)
2 | # MaterialLoadingProgressBar
3 | MaterialLoadingProgressBar provide a styled ProgressBar which looks like SwipeRefreshLayout's loading indicator(support-v4 v21+)
4 |
5 | 
6 | ## Usage
7 |
8 | ### how to import?
9 | add this into gradle
10 |
11 | compile('com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE')
12 |
13 |
14 | ### xml:
15 |
16 | ```
17 |
21 | ```
22 | ### options:
23 |
24 | ```
25 |
37 | ```
38 |
39 | ### java api:
40 | #### show arrow
41 | 'CircleProgressBar' will not show arrow by default.
42 | You can enable arrow drawing like this:
43 | ```
44 | circleProgressBar.setShowArrow(true);
45 | ```
46 |
47 | #### Disable circle background
48 | There is a white circle background on drawing 'CircleProgressBar' by default.
49 | If you need hide the circle background,you can add a xml item
50 |
51 | ```
52 | app:mlpb_enable_circle_background="false"
53 | ```
54 |
55 | or set it by java code
56 | ```
57 | circleProgressBar.setCircleBackgroundEnabled(false);
58 | ```
59 |
60 | ### release notes:
61 | 0.5.7: fix bugs
62 | 0.5.6: fix bugs
63 | 0.5.5: fix bug: android:visibility XML attribute does not work #6
64 |
65 | 0.5.4: fix bug: attr progress_color invalid;Restarting Progress bar does not animate #5
66 |
67 | 0.5.3: add default ring color;fix bug:NPE happens when ring color has never been setted.
68 |
69 | 0.5.2: support setColorSchemeColors.
70 |
71 | 0.5.1: fix bug: arrow be putting into incorrect position.
72 |
73 | 0.5.0: support enable/disable circle back ground.
74 |
75 | 0.4.0: fix bug:#1 :progressbar can not hide.
76 | fix bug:#2 :progressbar show full ring when running too long.
77 |
78 | 0.3.0: add showArrow option.
79 |
80 |
81 |
82 | License
83 | -------
84 |
85 | Copyright 2014 lsjwzh
86 |
87 | Licensed under the Apache License, Version 2.0 (the "License");
88 | you may not use this file except in compliance with the License.
89 | You may obtain a copy of the License at
90 |
91 | http://www.apache.org/licenses/LICENSE-2.0
92 |
93 | Unless required by applicable law or agreed to in writing, software
94 | distributed under the License is distributed on an "AS IS" BASIS,
95 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96 | See the License for the specific language governing permissions and
97 | limitations under the License.
98 |
99 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 {yyyy} {name of copyright owner}
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 |
203 |
--------------------------------------------------------------------------------
/materialloadingprogressbar/src/main/java/com/lsjwzh/widget/materialloadingprogressbar/CircleProgressBar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 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 com.lsjwzh.widget.materialloadingprogressbar;
18 |
19 | import android.content.Context;
20 | import android.content.res.Resources;
21 | import android.content.res.TypedArray;
22 | import android.graphics.Canvas;
23 | import android.graphics.Color;
24 | import android.graphics.Paint;
25 | import android.graphics.RadialGradient;
26 | import android.graphics.Shader;
27 | import android.graphics.drawable.Drawable;
28 | import android.graphics.drawable.ShapeDrawable;
29 | import android.graphics.drawable.shapes.OvalShape;
30 | import android.net.Uri;
31 | import android.support.v4.view.ViewCompat;
32 | import android.util.AttributeSet;
33 | import android.view.animation.Animation;
34 | import android.widget.ImageView;
35 |
36 | /**
37 | * Private class created to work around issues with AnimationListeners being
38 | * called before the animation is actually complete and support shadows on older
39 | * platforms.
40 | */
41 | public class CircleProgressBar extends ImageView {
42 |
43 | private static final int KEY_SHADOW_COLOR = 0x1E000000;
44 | private static final int FILL_SHADOW_COLOR = 0x3D000000;
45 | // PX
46 | private static final float X_OFFSET = 0f;
47 | private static final float Y_OFFSET = 1.75f;
48 | private static final float SHADOW_RADIUS = 3.5f;
49 | private static final int SHADOW_ELEVATION = 4;
50 |
51 |
52 | private static final int DEFAULT_CIRCLE_BG_LIGHT = 0xFFFAFAFA;
53 | private static final int DEFAULT_CIRCLE_DIAMETER = 56;
54 | private static final int STROKE_WIDTH_LARGE = 3;
55 | public static final int DEFAULT_TEXT_SIZE = 9;
56 |
57 | private Animation.AnimationListener mListener;
58 | private int mShadowRadius;
59 | private int mBackGroundColor;
60 | private int mProgressColor;
61 | private int mProgressStokeWidth;
62 | private int mArrowWidth;
63 | private int mArrowHeight;
64 | private int mProgress;
65 | private int mMax;
66 | private int mDiameter;
67 | private int mInnerRadius;
68 | private Paint mTextPaint;
69 | private int mTextColor;
70 | private int mTextSize;
71 | private boolean mIfDrawText;
72 | private boolean mShowArrow;
73 | private MaterialProgressDrawable mProgressDrawable;
74 | private ShapeDrawable mBgCircle;
75 | private boolean mCircleBackgroundEnabled;
76 | private int[] mColors = new int[]{Color.BLACK};
77 |
78 | public CircleProgressBar(Context context) {
79 | super(context);
80 | init(context, null, 0);
81 |
82 | }
83 |
84 | public CircleProgressBar(Context context, AttributeSet attrs) {
85 | super(context, attrs);
86 | init(context, attrs, 0);
87 |
88 | }
89 |
90 | public CircleProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
91 | super(context, attrs, defStyleAttr);
92 | init(context, attrs, defStyleAttr);
93 | }
94 |
95 | private void init(Context context, AttributeSet attrs, int defStyleAttr) {
96 | final TypedArray a = context.obtainStyledAttributes(
97 | attrs, R.styleable.CircleProgressBar, defStyleAttr, 0);
98 | //
99 | //
100 | //
101 | //
102 | //
103 | //
104 | //
105 | //
106 | //
107 | //
108 | //
109 | //
110 | //
111 | //
112 | //
113 | //
114 | //
115 | //
116 | //
117 | //
118 | final float density = getContext().getResources().getDisplayMetrics().density;
119 |
120 | mBackGroundColor = a.getColor(
121 | R.styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT);
122 |
123 | mProgressColor = a.getColor(
124 | R.styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT);
125 | mColors = new int[]{mProgressColor};
126 |
127 | mInnerRadius = a.getDimensionPixelOffset(
128 | R.styleable.CircleProgressBar_mlpb_inner_radius, -1);
129 |
130 | mProgressStokeWidth = a.getDimensionPixelOffset(
131 | R.styleable.CircleProgressBar_mlpb_progress_stoke_width, (int) (STROKE_WIDTH_LARGE * density));
132 | mArrowWidth = a.getDimensionPixelOffset(
133 | R.styleable.CircleProgressBar_mlpb_arrow_width, -1);
134 | mArrowHeight = a.getDimensionPixelOffset(
135 | R.styleable.CircleProgressBar_mlpb_arrow_height, -1);
136 | mTextSize = a.getDimensionPixelOffset(
137 | R.styleable.CircleProgressBar_mlpb_progress_text_size, (int) (DEFAULT_TEXT_SIZE * density));
138 | mTextColor = a.getColor(
139 | R.styleable.CircleProgressBar_mlpb_progress_text_color, Color.BLACK);
140 |
141 | mShowArrow = a.getBoolean(R.styleable.CircleProgressBar_mlpb_show_arrow, false);
142 | mCircleBackgroundEnabled = a.getBoolean(R.styleable.CircleProgressBar_mlpb_enable_circle_background, true);
143 |
144 |
145 | mProgress = a.getInt(R.styleable.CircleProgressBar_mlpb_progress, 0);
146 | mMax = a.getInt(R.styleable.CircleProgressBar_mlpb_max, 100);
147 | int textVisible = a.getInt(R.styleable.CircleProgressBar_mlpb_progress_text_visibility, 1);
148 | if (textVisible != 1) {
149 | mIfDrawText = true;
150 | }
151 |
152 | mTextPaint = new Paint();
153 | mTextPaint.setStyle(Paint.Style.FILL);
154 | mTextPaint.setColor(mTextColor);
155 | mTextPaint.setTextSize(mTextSize);
156 | mTextPaint.setAntiAlias(true);
157 | a.recycle();
158 | mProgressDrawable = new MaterialProgressDrawable(getContext(), this);
159 | super.setImageDrawable(mProgressDrawable);
160 | }
161 |
162 |
163 | private boolean elevationSupported() {
164 | return android.os.Build.VERSION.SDK_INT >= 21;
165 | }
166 |
167 | @Override
168 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
169 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
170 | if (!elevationSupported()) {
171 | setMeasuredDimension(getMeasuredWidth() + mShadowRadius * 2, getMeasuredHeight()
172 | + mShadowRadius * 2);
173 | }
174 | }
175 |
176 | @Override
177 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
178 | super.onLayout(changed, left, top, right, bottom);
179 | final float density = getContext().getResources().getDisplayMetrics().density;
180 | mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
181 | if (mDiameter <= 0) {
182 | mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
183 | }
184 | if (getBackground() == null && mCircleBackgroundEnabled) {
185 | final int shadowYOffset = (int) (density * Y_OFFSET);
186 | final int shadowXOffset = (int) (density * X_OFFSET);
187 | mShadowRadius = (int) (density * SHADOW_RADIUS);
188 |
189 | if (elevationSupported()) {
190 | mBgCircle = new ShapeDrawable(new OvalShape());
191 | ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
192 | } else {
193 | OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
194 | mBgCircle = new ShapeDrawable(oval);
195 | ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
196 | mBgCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset,
197 | KEY_SHADOW_COLOR);
198 | final int padding = (int) mShadowRadius;
199 | // set padding so the inner image sits correctly within the shadow.
200 | setPadding(padding, padding, padding, padding);
201 | }
202 | mBgCircle.getPaint().setColor(mBackGroundColor);
203 | setBackgroundDrawable(mBgCircle);
204 | }
205 | mProgressDrawable.setBackgroundColor(mBackGroundColor);
206 | mProgressDrawable.setColorSchemeColors(mColors);
207 | mProgressDrawable.setSizeParameters(mDiameter, mDiameter,
208 | mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius,
209 | mProgressStokeWidth,
210 | mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth,
211 | mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
212 | if (isShowArrow()) {
213 | mProgressDrawable.showArrowOnFirstStart(true);
214 | mProgressDrawable.setArrowScale(1f);
215 | mProgressDrawable.showArrow(true);
216 | }
217 | super.setImageDrawable(null);
218 | super.setImageDrawable(mProgressDrawable);
219 | mProgressDrawable.setAlpha(255);
220 | if(getVisibility()==VISIBLE) {
221 | mProgressDrawable.start();
222 | }
223 | }
224 |
225 | @Override
226 | protected void onDraw(Canvas canvas) {
227 | super.onDraw(canvas);
228 | if (mIfDrawText) {
229 | String text = String.format("%s%%", mProgress);
230 | int x = getWidth() / 2 - text.length() * mTextSize / 4;
231 | int y = getHeight() / 2 + mTextSize / 4;
232 | canvas.drawText(text, x, y, mTextPaint);
233 | }
234 | }
235 |
236 | @Override
237 | final public void setImageResource(int resId) {
238 |
239 | }
240 |
241 |
242 | public boolean isShowArrow() {
243 | return mShowArrow;
244 | }
245 |
246 | public void setShowArrow(boolean showArrow) {
247 | this.mShowArrow = showArrow;
248 | }
249 |
250 |
251 | @Override
252 | final public void setImageURI(Uri uri) {
253 | super.setImageURI(uri);
254 | }
255 |
256 | @Override
257 | final public void setImageDrawable(Drawable drawable) {
258 | }
259 |
260 | public void setAnimationListener(Animation.AnimationListener listener) {
261 | mListener = listener;
262 | }
263 |
264 | @Override
265 | public void onAnimationStart() {
266 | super.onAnimationStart();
267 | if (mListener != null) {
268 | mListener.onAnimationStart(getAnimation());
269 | }
270 | }
271 |
272 | @Override
273 | public void onAnimationEnd() {
274 | super.onAnimationEnd();
275 | if (mListener != null) {
276 | mListener.onAnimationEnd(getAnimation());
277 | }
278 | }
279 |
280 |
281 | /**
282 | * Set the color resources used in the progress animation from color resources.
283 | * The first color will also be the color of the bar that grows in response
284 | * to a user swipe gesture.
285 | *
286 | * @param colorResIds
287 | */
288 | public void setColorSchemeResources(int... colorResIds) {
289 | final Resources res = getResources();
290 | int[] colorRes = new int[colorResIds.length];
291 | for (int i = 0; i < colorResIds.length; i++) {
292 | colorRes[i] = res.getColor(colorResIds[i]);
293 | }
294 | setColorSchemeColors(colorRes);
295 | }
296 |
297 | /**
298 | * Set the colors used in the progress animation. The first
299 | * color will also be the color of the bar that grows in response to a user
300 | * swipe gesture.
301 | *
302 | * @param colors
303 | */
304 | public void setColorSchemeColors(int... colors) {
305 | mColors = colors;
306 | if (mProgressDrawable != null) {
307 | mProgressDrawable.setColorSchemeColors(colors);
308 | }
309 | }
310 |
311 | /**
312 | * Update the background color of the mBgCircle image view.
313 | */
314 | public void setBackgroundColor(int colorRes) {
315 | if (getBackground() instanceof ShapeDrawable) {
316 | final Resources res = getResources();
317 | ((ShapeDrawable) getBackground()).getPaint().setColor(res.getColor(colorRes));
318 | }
319 | }
320 |
321 | public boolean isShowProgressText() {
322 | return mIfDrawText;
323 | }
324 |
325 | public void setShowProgressText(boolean mIfDrawText) {
326 | this.mIfDrawText = mIfDrawText;
327 | }
328 |
329 | public int getMax() {
330 | return mMax;
331 | }
332 |
333 | public void setMax(int max) {
334 | mMax = max;
335 | }
336 |
337 | public int getProgress() {
338 | return mProgress;
339 | }
340 |
341 | public void setProgress(int progress) {
342 | if (getMax() > 0) {
343 | mProgress = progress;
344 | }
345 | }
346 |
347 |
348 | public boolean circleBackgroundEnabled() {
349 | return mCircleBackgroundEnabled;
350 | }
351 |
352 | public void setCircleBackgroundEnabled(boolean enableCircleBackground) {
353 | this.mCircleBackgroundEnabled = enableCircleBackground;
354 | }
355 |
356 | @Override
357 | public int getVisibility() {
358 | return super.getVisibility();
359 | }
360 |
361 | @Override
362 | public void setVisibility(int visibility) {
363 | super.setVisibility(visibility);
364 | if (mProgressDrawable != null) {
365 | mProgressDrawable.setVisible(visibility == VISIBLE, false);
366 | if (visibility != VISIBLE) {
367 | mProgressDrawable.stop();
368 | } else {
369 | if (mProgressDrawable.isRunning()) {
370 | mProgressDrawable.stop();
371 | }
372 | mProgressDrawable.start();
373 | }
374 | }
375 | }
376 |
377 | @Override
378 | protected void onAttachedToWindow() {
379 | super.onAttachedToWindow();
380 | if (mProgressDrawable != null) {
381 | mProgressDrawable.stop();
382 | mProgressDrawable.setVisible(getVisibility() == VISIBLE, false);
383 |
384 | requestLayout();
385 | }
386 | }
387 |
388 | @Override
389 | protected void onDetachedFromWindow() {
390 | super.onDetachedFromWindow();
391 | if (mProgressDrawable != null) {
392 | mProgressDrawable.stop();
393 | mProgressDrawable.setVisible(false, false);
394 | }
395 | }
396 |
397 |
398 | private class OvalShadow extends OvalShape {
399 | private RadialGradient mRadialGradient;
400 | private int mShadowRadius;
401 | private Paint mShadowPaint;
402 | private int mCircleDiameter;
403 |
404 | public OvalShadow(int shadowRadius, int circleDiameter) {
405 | super();
406 | mShadowPaint = new Paint();
407 | mShadowRadius = shadowRadius;
408 | mCircleDiameter = circleDiameter;
409 | mRadialGradient = new RadialGradient(mCircleDiameter / 2, mCircleDiameter / 2,
410 | mShadowRadius, new int[]{
411 | FILL_SHADOW_COLOR, Color.TRANSPARENT
412 | }, null, Shader.TileMode.CLAMP);
413 | mShadowPaint.setShader(mRadialGradient);
414 | }
415 |
416 | @Override
417 | public void draw(Canvas canvas, Paint paint) {
418 | final int viewWidth = CircleProgressBar.this.getWidth();
419 | final int viewHeight = CircleProgressBar.this.getHeight();
420 | canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2 + mShadowRadius),
421 | mShadowPaint);
422 | canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2), paint);
423 | }
424 | }
425 | }
426 |
--------------------------------------------------------------------------------
/materialloadingprogressbar/src/main/java/com/lsjwzh/widget/materialloadingprogressbar/MaterialProgressDrawable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 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 com.lsjwzh.widget.materialloadingprogressbar;
18 |
19 | import android.content.Context;
20 | import android.content.res.Resources;
21 | import android.graphics.Canvas;
22 | import android.graphics.Color;
23 | import android.graphics.ColorFilter;
24 | import android.graphics.Paint;
25 | import android.graphics.Paint.Style;
26 | import android.graphics.Path;
27 | import android.graphics.PixelFormat;
28 | import android.graphics.Rect;
29 | import android.graphics.RectF;
30 | import android.graphics.drawable.Animatable;
31 | import android.graphics.drawable.Drawable;
32 | import android.support.annotation.IntDef;
33 | import android.support.annotation.NonNull;
34 | import android.util.DisplayMetrics;
35 | import android.util.Log;
36 | import android.view.View;
37 | import android.view.animation.AccelerateDecelerateInterpolator;
38 | import android.view.animation.Animation;
39 | import android.view.animation.Interpolator;
40 | import android.view.animation.LinearInterpolator;
41 | import android.view.animation.Transformation;
42 |
43 | import java.lang.annotation.Retention;
44 | import java.lang.annotation.RetentionPolicy;
45 | import java.util.ArrayList;
46 |
47 | /**
48 | * Fancy progress indicator for Material theme.
49 | *
50 | * @hide
51 | */
52 | public class MaterialProgressDrawable extends Drawable implements Animatable {
53 | // Maps to ProgressBar.Large style
54 | public static final int LARGE = 0;
55 | // Maps to ProgressBar default style
56 | public static final int DEFAULT = 1;
57 | private static final Interpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
58 | private static final Interpolator END_CURVE_INTERPOLATOR = new EndCurveInterpolator();
59 | private static final Interpolator START_CURVE_INTERPOLATOR = new StartCurveInterpolator();
60 | private static final Interpolator EASE_INTERPOLATOR = new AccelerateDecelerateInterpolator();
61 | // Maps to ProgressBar default style
62 | private static final int CIRCLE_DIAMETER = 40;
63 | private static final float CENTER_RADIUS = 8.75f; //should add up to 10 when + stroke_width
64 | private static final float STROKE_WIDTH = 2.5f;
65 | // Maps to ProgressBar.Large style
66 | private static final int CIRCLE_DIAMETER_LARGE = 56;
67 | private static final float CENTER_RADIUS_LARGE = 12.5f;
68 | static final float STROKE_WIDTH_LARGE = 3f;
69 | /**
70 | * The duration of a single progress spin in milliseconds.
71 | */
72 | private static final int ANIMATION_DURATION = 1000 * 80 / 60;
73 | /**
74 | * The number of points in the progress "star".
75 | */
76 | private static final float NUM_POINTS = 5f;
77 | /**
78 | * Layout info for the arrowhead in dp
79 | */
80 | private static final int ARROW_WIDTH = 10;
81 | private static final int ARROW_HEIGHT = 5;
82 | private static final float ARROW_OFFSET_ANGLE = 0;
83 | /**
84 | * Layout info for the arrowhead for the large spinner in dp
85 | */
86 | static final int ARROW_WIDTH_LARGE = 12;
87 | static final int ARROW_HEIGHT_LARGE = 6;
88 | private static final float MAX_PROGRESS_ARC = .8f;
89 | private final int[] COLORS = new int[]{
90 | Color.BLACK
91 | };
92 | /**
93 | * The list of animators operating on this drawable.
94 | */
95 | private final ArrayList mAnimators = new ArrayList();
96 | /**
97 | * The indicator ring, used to manage animation state.
98 | */
99 | private final Ring mRing;
100 | private final Callback mCallback = new Callback() {
101 | @Override
102 | public void invalidateDrawable(Drawable d) {
103 | invalidateSelf();
104 | }
105 |
106 | @Override
107 | public void scheduleDrawable(Drawable d, Runnable what, long when) {
108 | scheduleSelf(what, when);
109 | }
110 |
111 | @Override
112 | public void unscheduleDrawable(Drawable d, Runnable what) {
113 | unscheduleSelf(what);
114 | }
115 | };
116 | boolean mFinishing;
117 | /**
118 | * Canvas rotation in degrees.
119 | */
120 | private float mRotation;
121 | private Resources mResources;
122 | private View mAnimExcutor;
123 | private Animation mAnimation;
124 | private float mRotationCount;
125 | private double mWidth;
126 | private double mHeight;
127 | private boolean mShowArrowOnFirstStart = false;
128 |
129 | public MaterialProgressDrawable(Context context, View animExcutor) {
130 | mAnimExcutor = animExcutor;
131 | mResources = context.getResources();
132 |
133 | mRing = new Ring(mCallback);
134 | mRing.setColors(COLORS);
135 |
136 | updateSizes(DEFAULT);
137 | setupAnimators();
138 | }
139 |
140 | public void setSizeParameters(double progressCircleWidth, double progressCircleHeight,
141 | double centerRadius, double strokeWidth, float arrowWidth, float arrowHeight) {
142 | final Ring ring = mRing;
143 | mWidth = progressCircleWidth;
144 | mHeight = progressCircleHeight ;
145 | ring.setStrokeWidth((float) strokeWidth );
146 | ring.setCenterRadius(centerRadius);
147 | ring.setColorIndex(0);
148 | ring.setArrowDimensions(arrowWidth , arrowHeight );
149 | ring.setInsets((int) mWidth, (int) mHeight);
150 | }
151 |
152 | /**
153 | * Set the overall size for the progress spinner. This updates the radius
154 | * and stroke width of the ring.
155 | *
156 | * @param size One of {@link MaterialProgressDrawable.LARGE} or
157 | * {@link MaterialProgressDrawable.DEFAULT}
158 | */
159 | public void updateSizes(@ProgressDrawableSize int size) {
160 | final DisplayMetrics metrics = mResources.getDisplayMetrics();
161 | final float screenDensity = metrics.density;
162 |
163 | if (size == LARGE) {
164 | setSizeParameters(CIRCLE_DIAMETER_LARGE*screenDensity, CIRCLE_DIAMETER_LARGE*screenDensity, CENTER_RADIUS_LARGE*screenDensity,
165 | STROKE_WIDTH_LARGE*screenDensity, ARROW_WIDTH_LARGE*screenDensity, ARROW_HEIGHT_LARGE*screenDensity);
166 | } else {
167 | setSizeParameters(CIRCLE_DIAMETER*screenDensity, CIRCLE_DIAMETER*screenDensity, CENTER_RADIUS*screenDensity, STROKE_WIDTH*screenDensity,
168 | ARROW_WIDTH*screenDensity, ARROW_HEIGHT*screenDensity);
169 | }
170 | }
171 |
172 | /**
173 | * @param show Set to true to display the arrowhead on the progress spinner.
174 | */
175 | public void showArrow(boolean show) {
176 | mRing.setShowArrow(show);
177 | }
178 |
179 | /**
180 | * @param scale Set the scale of the arrowhead for the spinner.
181 | */
182 | public void setArrowScale(float scale) {
183 | mRing.setArrowScale(scale);
184 | }
185 |
186 | /**
187 | * Set the start and end trim for the progress spinner arc.
188 | *
189 | * @param startAngle start angle
190 | * @param endAngle end angle
191 | */
192 | public void setStartEndTrim(float startAngle, float endAngle) {
193 | mRing.setStartTrim(startAngle);
194 | mRing.setEndTrim(endAngle);
195 | }
196 |
197 | /**
198 | * Set the amount of rotation to apply to the progress spinner.
199 | *
200 | * @param rotation Rotation is from [0..1]
201 | */
202 | public void setProgressRotation(float rotation) {
203 | mRing.setRotation(rotation);
204 | }
205 |
206 | /**
207 | * Update the background color of the circle image view.
208 | */
209 | public void setBackgroundColor(int color) {
210 | mRing.setBackgroundColor(color);
211 | }
212 |
213 | /**
214 | * Set the colors used in the progress animation from color resources.
215 | * The first color will also be the color of the bar that grows in response
216 | * to a user swipe gesture.
217 | *
218 | * @param colors
219 | */
220 | public void setColorSchemeColors(int... colors) {
221 | mRing.setColors(colors);
222 | mRing.setColorIndex(0);
223 | }
224 |
225 | @Override
226 | public int getIntrinsicHeight() {
227 | return (int) mHeight;
228 | }
229 |
230 | @Override
231 | public int getIntrinsicWidth() {
232 | return (int) mWidth;
233 | }
234 |
235 | @Override
236 | public void draw(Canvas c) {
237 | final Rect bounds = getBounds();
238 | final int saveCount = c.save();
239 | c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
240 | mRing.draw(c, bounds);
241 | c.restoreToCount(saveCount);
242 | }
243 |
244 | public int getAlpha() {
245 | return mRing.getAlpha();
246 | }
247 |
248 | @Override
249 | public void setAlpha(int alpha) {
250 | mRing.setAlpha(alpha);
251 | }
252 |
253 | @Override
254 | public void setColorFilter(ColorFilter colorFilter) {
255 | mRing.setColorFilter(colorFilter);
256 | }
257 |
258 | @SuppressWarnings("unused")
259 | private float getRotation() {
260 | return mRotation;
261 | }
262 |
263 | @SuppressWarnings("unused")
264 | void setRotation(float rotation) {
265 | mRotation = rotation;
266 | invalidateSelf();
267 | }
268 |
269 | @Override
270 | public int getOpacity() {
271 | return PixelFormat.TRANSLUCENT;
272 | }
273 |
274 | @Override
275 | public boolean isRunning() {
276 | return this.mAnimation.hasStarted() && !this.mAnimation.hasEnded();
277 | }
278 |
279 | @Override
280 | public void start() {
281 | mAnimation.reset();
282 | mRing.storeOriginals();
283 | mRing.setShowArrow(mShowArrowOnFirstStart);
284 |
285 | // Already showing some part of the ring
286 | if (mRing.getEndTrim() != mRing.getStartTrim()) {
287 | mFinishing = true;
288 | mAnimation.setDuration(ANIMATION_DURATION / 2);
289 | mAnimExcutor.startAnimation(mAnimation);
290 | } else {
291 | mRing.setColorIndex(0);
292 | mRing.resetOriginals();
293 | mAnimation.setDuration(ANIMATION_DURATION);
294 | mAnimExcutor.startAnimation(mAnimation);
295 | }
296 | }
297 |
298 | @Override
299 | public void stop() {
300 | mAnimExcutor.clearAnimation();
301 | setRotation(0);
302 | mRing.setShowArrow(false);
303 | mRing.setColorIndex(0);
304 | mRing.resetOriginals();
305 | }
306 |
307 | private void applyFinishTranslation(float interpolatedTime, Ring ring) {
308 | // shrink back down and complete a full rotation before
309 | // starting other circles
310 | // Rotation goes between [0..1].
311 | float targetRotation = (float) (Math.floor(ring.getStartingRotation() / MAX_PROGRESS_ARC)
312 | + 1f);
313 | final float startTrim = ring.getStartingStartTrim()
314 | + (ring.getStartingEndTrim() - ring.getStartingStartTrim()) * interpolatedTime;
315 | ring.setStartTrim(startTrim);
316 | final float rotation = ring.getStartingRotation()
317 | + ((targetRotation - ring.getStartingRotation()) * interpolatedTime);
318 | ring.setRotation(rotation);
319 | }
320 |
321 | private void setupAnimators() {
322 | final Ring ring = mRing;
323 | final Animation animation = new Animation() {
324 | @Override
325 | public void applyTransformation(float interpolatedTime, Transformation t) {
326 | if (mFinishing) {
327 | applyFinishTranslation(interpolatedTime, ring);
328 | } else {
329 | // The minProgressArc is calculated from 0 to create an
330 | // angle that
331 | // matches the stroke width.
332 | final float minProgressArc = (float) Math.toRadians(
333 | ring.getStrokeWidth() / (2 * Math.PI * ring.getCenterRadius()));
334 | final float startingEndTrim = ring.getStartingEndTrim();
335 | final float startingTrim = ring.getStartingStartTrim();
336 | final float startingRotation = ring.getStartingRotation();
337 |
338 | // Offset the minProgressArc to where the endTrim is
339 | // located.
340 | final float minArc = MAX_PROGRESS_ARC - minProgressArc;
341 | float endTrim = startingEndTrim + (minArc
342 | * START_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
343 | float startTrim = startingTrim + (MAX_PROGRESS_ARC
344 | * END_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
345 |
346 | final float sweepTrim = endTrim-startTrim;
347 | //Avoid the ring to be a full circle
348 | if(Math.abs(sweepTrim)>=1){
349 | endTrim = startTrim+0.5f;
350 | }
351 |
352 | ring.setEndTrim(endTrim);
353 |
354 | ring.setStartTrim(startTrim);
355 |
356 | final float rotation = startingRotation + (0.25f * interpolatedTime);
357 | ring.setRotation(rotation);
358 |
359 | float groupRotation = ((720.0f / NUM_POINTS) * interpolatedTime)
360 | + (720.0f * (mRotationCount / NUM_POINTS));
361 | setRotation(groupRotation);
362 |
363 | // If this view is removed by parent
364 | // clear the anim
365 | if ( mAnimExcutor.getParent() == null ) stop();
366 | }
367 | }
368 | };
369 | animation.setRepeatCount(Animation.INFINITE);
370 | animation.setRepeatMode(Animation.RESTART);
371 | animation.setInterpolator(LINEAR_INTERPOLATOR);
372 | animation.setAnimationListener(new Animation.AnimationListener() {
373 |
374 | @Override
375 | public void onAnimationStart(Animation animation) {
376 | mRotationCount = 0;
377 | }
378 |
379 | @Override
380 | public void onAnimationEnd(Animation animation) {
381 | // do nothing
382 | }
383 |
384 | @Override
385 | public void onAnimationRepeat(Animation animation) {
386 | ring.storeOriginals();
387 | ring.goToNextColor();
388 | ring.setStartTrim(ring.getEndTrim());
389 | if (mFinishing) {
390 | // finished closing the last ring from the swipe gesture; go
391 | // into progress mode
392 | mFinishing = false;
393 | animation.setDuration(ANIMATION_DURATION);
394 | ring.setShowArrow(false);
395 | } else {
396 | mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
397 | }
398 | }
399 | });
400 | mAnimation = animation;
401 | }
402 |
403 | public void showArrowOnFirstStart(boolean showArrowOnFirstStart) {
404 | this.mShowArrowOnFirstStart = showArrowOnFirstStart;
405 | }
406 |
407 | @Retention(RetentionPolicy.CLASS)
408 | @IntDef({LARGE, DEFAULT})
409 | public @interface ProgressDrawableSize {
410 | }
411 |
412 | private static class Ring {
413 | private final RectF mTempBounds = new RectF();
414 | private final Paint mPaint = new Paint();
415 | private final Paint mArrowPaint = new Paint();
416 |
417 | private final Callback mCallback;
418 | private final Paint mCirclePaint = new Paint();
419 | private float mStartTrim = 0.0f;
420 | private float mEndTrim = 0.0f;
421 | private float mRotation = 0.0f;
422 | private float mStrokeWidth = 5.0f;
423 | private float mStrokeInset = 2.5f;
424 | private int[] mColors;
425 | // mColorIndex represents the offset into the available mColors that the
426 | // progress circle should currently display. As the progress circle is
427 | // animating, the mColorIndex moves by one to the next available color.
428 | private int mColorIndex;
429 | private float mStartingStartTrim;
430 | private float mStartingEndTrim;
431 | private float mStartingRotation;
432 | private boolean mShowArrow;
433 | private Path mArrow;
434 | private float mArrowScale;
435 | private double mRingCenterRadius;
436 | private int mArrowWidth;
437 | private int mArrowHeight;
438 | private int mAlpha;
439 | private int mBackgroundColor;
440 |
441 | public Ring(Callback callback) {
442 | mCallback = callback;
443 |
444 | mPaint.setStrokeCap(Paint.Cap.SQUARE);
445 | mPaint.setAntiAlias(true);
446 | mPaint.setStyle(Style.STROKE);
447 |
448 | mArrowPaint.setStyle(Paint.Style.FILL);
449 | mArrowPaint.setAntiAlias(true);
450 | }
451 |
452 | public void setBackgroundColor(int color) {
453 | mBackgroundColor = color;
454 | }
455 |
456 | /**
457 | * Set the dimensions of the arrowhead.
458 | *
459 | * @param width Width of the hypotenuse of the arrow head
460 | * @param height Height of the arrow point
461 | */
462 | public void setArrowDimensions(float width, float height) {
463 | mArrowWidth = (int) width;
464 | mArrowHeight = (int) height;
465 | }
466 |
467 | /**
468 | * Draw the progress spinner
469 | */
470 | public void draw(Canvas c, Rect bounds) {
471 | final RectF arcBounds = mTempBounds;
472 | arcBounds.set(bounds);
473 | arcBounds.inset(mStrokeInset, mStrokeInset);
474 |
475 | final float startAngle = (mStartTrim + mRotation) * 360;
476 | final float endAngle = (mEndTrim + mRotation) * 360;
477 | float sweepAngle = endAngle - startAngle;
478 | mPaint.setColor(mColors[mColorIndex]);
479 | c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint);
480 |
481 | drawTriangle(c, startAngle, sweepAngle, bounds);
482 |
483 | if (mAlpha < 255) {
484 | mCirclePaint.setColor(mBackgroundColor);
485 | mCirclePaint.setAlpha(255 - mAlpha);
486 | c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2,
487 | mCirclePaint);
488 | }
489 | }
490 |
491 | private void drawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds) {
492 | if (mShowArrow) {
493 | if (mArrow == null) {
494 | mArrow = new android.graphics.Path();
495 | mArrow.setFillType(android.graphics.Path.FillType.EVEN_ODD);
496 | } else {
497 | mArrow.reset();
498 | }
499 |
500 | // Adjust the position of the triangle so that it is inset as
501 | // much as the arc, but also centered on the arc.
502 | float x = (float) (mRingCenterRadius * Math.cos(0) + bounds.exactCenterX());
503 | float y = (float) (mRingCenterRadius * Math.sin(0) + bounds.exactCenterY());
504 |
505 | // Update the path each time. This works around an issue in SKIA
506 | // where concatenating a rotation matrix to a scale matrix
507 | // ignored a starting negative rotation. This appears to have
508 | // been fixed as of API 21.
509 | mArrow.moveTo(0, 0);
510 | mArrow.lineTo((mArrowWidth) * mArrowScale, 0);
511 | mArrow.lineTo(((mArrowWidth) * mArrowScale / 2), (mArrowHeight
512 | * mArrowScale));
513 | mArrow.offset(x-((mArrowWidth) * mArrowScale / 2), y);
514 | mArrow.close();
515 | // draw a triangle
516 | mArrowPaint.setColor(mColors[mColorIndex]);
517 | //when sweepAngle < 0 adjust the position of the arrow
518 | c.rotate(startAngle + (sweepAngle<0?0:sweepAngle) - ARROW_OFFSET_ANGLE, bounds.exactCenterX(),
519 | bounds.exactCenterY());
520 | c.drawPath(mArrow, mArrowPaint);
521 | }
522 | }
523 |
524 | /**
525 | * Set the colors the progress spinner alternates between.
526 | *
527 | * @param colors Array of integers describing the colors. Must be non-null.
528 | */
529 | public void setColors(@NonNull int[] colors) {
530 | mColors = colors;
531 | // if colors are reset, make sure to reset the color index as well
532 | setColorIndex(0);
533 | }
534 |
535 | /**
536 | * @param index Index into the color array of the color to display in
537 | * the progress spinner.
538 | */
539 | public void setColorIndex(int index) {
540 | mColorIndex = index;
541 | }
542 |
543 | /**
544 | * Proceed to the next available ring color. This will automatically
545 | * wrap back to the beginning of colors.
546 | */
547 | public void goToNextColor() {
548 | mColorIndex = (mColorIndex + 1) % (mColors.length);
549 | }
550 |
551 | public void setColorFilter(ColorFilter filter) {
552 | mPaint.setColorFilter(filter);
553 | invalidateSelf();
554 | }
555 |
556 | /**
557 | * @return Current alpha of the progress spinner and arrowhead.
558 | */
559 | public int getAlpha() {
560 | return mAlpha;
561 | }
562 |
563 | /**
564 | * @param alpha Set the alpha of the progress spinner and associated arrowhead.
565 | */
566 | public void setAlpha(int alpha) {
567 | mAlpha = alpha;
568 | }
569 |
570 | @SuppressWarnings("unused")
571 | public float getStrokeWidth() {
572 | return mStrokeWidth;
573 | }
574 |
575 | /**
576 | * @param strokeWidth Set the stroke width of the progress spinner in pixels.
577 | */
578 | public void setStrokeWidth(float strokeWidth) {
579 | mStrokeWidth = strokeWidth;
580 | mPaint.setStrokeWidth(strokeWidth);
581 | invalidateSelf();
582 | }
583 |
584 | @SuppressWarnings("unused")
585 | public float getStartTrim() {
586 | return mStartTrim;
587 | }
588 |
589 | @SuppressWarnings("unused")
590 | public void setStartTrim(float startTrim) {
591 | mStartTrim = startTrim;
592 | invalidateSelf();
593 | }
594 |
595 | public float getStartingStartTrim() {
596 | return mStartingStartTrim;
597 | }
598 |
599 | public float getStartingEndTrim() {
600 | return mStartingEndTrim;
601 | }
602 |
603 | @SuppressWarnings("unused")
604 | public float getEndTrim() {
605 | return mEndTrim;
606 | }
607 |
608 | @SuppressWarnings("unused")
609 | public void setEndTrim(float endTrim) {
610 | mEndTrim = endTrim;
611 | invalidateSelf();
612 | }
613 |
614 | @SuppressWarnings("unused")
615 | public float getRotation() {
616 | return mRotation;
617 | }
618 |
619 | @SuppressWarnings("unused")
620 | public void setRotation(float rotation) {
621 | mRotation = rotation;
622 | invalidateSelf();
623 | }
624 |
625 | public void setInsets(int width, int height) {
626 | final float minEdge = (float) Math.min(width, height);
627 | float insets;
628 | if (mRingCenterRadius <= 0 || minEdge < 0) {
629 | insets = (float) Math.ceil(mStrokeWidth / 2.0f);
630 | } else {
631 | insets = (float) (minEdge / 2.0f - mRingCenterRadius);
632 | }
633 | mStrokeInset = insets;
634 | }
635 |
636 | @SuppressWarnings("unused")
637 | public float getInsets() {
638 | return mStrokeInset;
639 | }
640 |
641 | public double getCenterRadius() {
642 | return mRingCenterRadius;
643 | }
644 |
645 | /**
646 | * @param centerRadius Inner radius in px of the circle the progress
647 | * spinner arc traces.
648 | */
649 | public void setCenterRadius(double centerRadius) {
650 | mRingCenterRadius = centerRadius;
651 | }
652 |
653 | /**
654 | * @param show Set to true to show the arrow head on the progress spinner.
655 | */
656 | public void setShowArrow(boolean show) {
657 | if (mShowArrow != show) {
658 | mShowArrow = show;
659 | invalidateSelf();
660 | }
661 | }
662 |
663 | /**
664 | * @param scale Set the scale of the arrowhead for the spinner.
665 | */
666 | public void setArrowScale(float scale) {
667 | if (scale != mArrowScale) {
668 | mArrowScale = scale;
669 | invalidateSelf();
670 | }
671 | }
672 |
673 | /**
674 | * @return The amount the progress spinner is currently rotated, between [0..1].
675 | */
676 | public float getStartingRotation() {
677 | return mStartingRotation;
678 | }
679 |
680 | /**
681 | * If the start / end trim are offset to begin with, store them so that
682 | * animation starts from that offset.
683 | */
684 | public void storeOriginals() {
685 | mStartingStartTrim = mStartTrim;
686 | mStartingEndTrim = mEndTrim;
687 | mStartingRotation = mRotation;
688 | }
689 |
690 | /**
691 | * Reset the progress spinner to default rotation, start and end angles.
692 | */
693 | public void resetOriginals() {
694 | mStartingStartTrim = 0;
695 | mStartingEndTrim = 0;
696 | mStartingRotation = 0;
697 | setStartTrim(0);
698 | setEndTrim(0);
699 | setRotation(0);
700 | }
701 |
702 | private void invalidateSelf() {
703 | mCallback.invalidateDrawable(null);
704 | }
705 | }
706 |
707 | /**
708 | * Squishes the interpolation curve into the second half of the animation.
709 | */
710 | private static class EndCurveInterpolator extends AccelerateDecelerateInterpolator {
711 | @Override
712 | public float getInterpolation(float input) {
713 | return super.getInterpolation(Math.max(0, (input - 0.5f) * 2.0f));
714 | }
715 | }
716 |
717 | /**
718 | * Squishes the interpolation curve into the first half of the animation.
719 | */
720 | private static class StartCurveInterpolator extends AccelerateDecelerateInterpolator {
721 | @Override
722 | public float getInterpolation(float input) {
723 | return super.getInterpolation(Math.min(1, input * 2.0f));
724 | }
725 | }
726 | }
727 |
--------------------------------------------------------------------------------