├── .gitignore
├── .travis.yml
├── LICENCE
├── README.md
├── build.gradle
├── demo
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── daimajia
│ │ └── numberprogressbar
│ │ └── example
│ │ └── MainActivity.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── layout
│ └── activity_main.xml
│ ├── menu
│ └── main.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── gradle-mvn-push.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── daimajia
│ │ └── numberprogressbar
│ │ ├── NumberProgressBar.java
│ │ └── OnProgressBarListener.java
│ └── res
│ └── values
│ ├── attrs.xml
│ └── styles.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 | .DS_Store
11 |
12 | # generated files
13 | bin/
14 | gen/
15 |
16 | # Local configuration file (sdk path, etc)
17 | local.properties
18 |
19 | # Eclipse project files
20 | .classpath
21 | .project
22 | .settings/
23 |
24 | # Proguard folder generated by Eclipse
25 | proguard/
26 |
27 | #Android Studio
28 | build/
29 |
30 | # Intellij project files
31 | *.iml
32 | *.ipr
33 | *.iws
34 | .idea/
35 |
36 | #gradle
37 | .gradle/
38 |
39 | #vscode
40 | .vscode/
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | android:
3 | components:
4 | - tools
5 | - platform-tools
6 | - build-tools-25.0.2
7 | - android-25
8 | - extra-android-support
9 | - extra
10 | - extra-android-m2repository
11 | script:
12 | - ./gradlew clean assembleDebug
13 | - ./gradlew clean assembleRelease
--------------------------------------------------------------------------------
/LICENCE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Daimajia
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Android NumberProgressBar [](https://travis-ci.org/daimajia/NumberProgressBar)
2 |
3 | [](https://insight.io/github.com/daimajia/NumberProgressBar)
4 | -----
5 |
6 | The NumberProgressBar is a bar, slim and sexy (every man wants! ).
7 |
8 | I decided to do this because I was really tired of android original progress bar. So, I made some change, added more color style for this.
9 |
10 | And also you can contribute more color style, or new idea to me.
11 |
12 | BTW. My friends also made some other platform's NumberProgressBar:
13 |
14 | - [Web-Front](https://github.com/kalasoo/NumberProgressBar) by [kalasoo](https://github.com/kalasoo/NumberProgressBar)
15 | - [iOS](https://github.com/Ming-Zhe/NumberProgressBar) by [Ming-Zhe](https://github.com/Ming-Zhe/NumberProgressBar)
16 | - [Windows Phone](https://github.com/s2003zy/NumberProgressBar) by [s2003zy](https://github.com/s2003zy)
17 |
18 | ---
19 |
20 | ### Demo
21 |
22 | 
23 |
24 |
25 | [Download Demo](https://github.com/daimajia/NumberProgressBar/releases/download/v1.0/NumberProgressBar-Demo-v1.0.apk)
26 |
27 |
28 | ### Usage
29 | ----
30 |
31 | #### Gradle
32 |
33 | ```groovy
34 | dependencies {
35 | compile 'com.daimajia.numberprogressbar:library:1.4@aar'
36 | }
37 | ```
38 |
39 | #### Maven
40 |
41 | ```xml
42 |
43 | com.daimajia.numberprogressbar
44 | library
45 | 1.4
46 | apklib
47 |
48 | ```
49 |
50 | Use it in your own code:
51 |
52 | ```java
53 |
58 | ```
59 |
60 | I made some predesign style. You can use them via `style` property.
61 |
62 |
63 | 
64 |
65 | Use the preset style just like below:
66 |
67 | ```java
68 |
72 | ```
73 |
74 | In the above picture, the style is :
75 |
76 | `NumberProgressBar_Default`
77 | `NumberProgressBar_Passing_Green`
78 | `NumberProgressBar_Relax_Blue`
79 | `NumberProgressBar_Grace_Yellow`
80 | `NumberProgressBar_Warning_Red`
81 | `NumberProgressBar_Funny_Orange`
82 | `NumberProgressBar_Beauty_Red`
83 | `NumberProgressBar_Twinkle_Night`
84 |
85 | You can get more beautiful color from [kular](https://kuler.adobe.com), and you can also contribute your color style to NumberProgressBar!
86 |
87 | ### Build
88 |
89 | run `./gradlew assembleDebug` (Mac/Linux)
90 |
91 | or
92 |
93 | run `gradlew.bat assembleDebug` (Windows)
94 |
95 | ### Attributes
96 |
97 | There are several attributes you can set:
98 |
99 | 
100 |
101 | The **reached area** and **unreached area**:
102 |
103 | * color
104 | * height
105 |
106 | The **text area**:
107 |
108 | * color
109 | * text size
110 | * visibility
111 | * distance between **reached area** and **unreached area**
112 |
113 | The **bar**:
114 |
115 | * max progress
116 | * current progress
117 |
118 | for example, the default style:
119 |
120 | ```java
121 |
139 | ```
140 |
141 | ### About me:
142 |
143 | A student in China mainland, I like Google, like Android, like open source, like doing something interesting. :)
144 |
145 | If you have some new idea or internship opportunity, please [email me](mailto:daimajia@gmail.com) !
146 |
--------------------------------------------------------------------------------
/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 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.3'
9 | }
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | jcenter()
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/demo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/demo/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 9
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled true
16 | consumerProguardFiles 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.android.support:appcompat-v7:25.1.1'
24 | compile project(':library')
25 | }
26 |
--------------------------------------------------------------------------------
/demo/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
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 | #}
--------------------------------------------------------------------------------
/demo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.daimajia.numberprogressbar.example;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.ActionBarActivity;
5 | import android.view.Menu;
6 | import android.view.MenuItem;
7 | import android.widget.Toast;
8 |
9 | import com.daimajia.numberprogressbar.NumberProgressBar;
10 | import com.daimajia.numberprogressbar.OnProgressBarListener;
11 |
12 | import java.util.Timer;
13 | import java.util.TimerTask;
14 |
15 |
16 | public class MainActivity extends ActionBarActivity implements OnProgressBarListener {
17 | private Timer timer;
18 |
19 | private NumberProgressBar bnp;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_main);
25 |
26 | bnp = (NumberProgressBar)findViewById(R.id.numberbar1);
27 | bnp.setOnProgressBarListener(this);
28 | timer = new Timer();
29 | timer.schedule(new TimerTask() {
30 | @Override
31 | public void run() {
32 | runOnUiThread(new Runnable() {
33 | @Override
34 | public void run() {
35 | bnp.incrementProgressBy(1);
36 | }
37 | });
38 | }
39 | }, 1000, 100);
40 | }
41 |
42 | @Override
43 | public boolean onCreateOptionsMenu(Menu menu) {
44 | // Inflate the menu; this adds items to the action bar if it is present.
45 | getMenuInflater().inflate(R.menu.main, menu);
46 | return true;
47 | }
48 |
49 | @Override
50 | public boolean onOptionsItemSelected(MenuItem item) {
51 | // Handle action bar item clicks here. The action bar will
52 | // automatically handle clicks on the Home/Up button, so long
53 | // as you specify a parent activity in AndroidManifest.xml.
54 | int id = item.getItemId();
55 | if (id == R.id.action_settings) {
56 | return true;
57 | }
58 | return super.onOptionsItemSelected(item);
59 | }
60 |
61 | @Override
62 | protected void onDestroy() {
63 | super.onDestroy();
64 | timer.cancel();
65 | }
66 |
67 | @Override
68 | public void onProgressChange(int current, int max) {
69 | if(current == max) {
70 | Toast.makeText(getApplicationContext(), getString(R.string.finish), Toast.LENGTH_SHORT).show();
71 | bnp.setProgress(0);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/NumberProgressBar/c63171bd053adcf287659e16440bd6efd834a795/demo/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/NumberProgressBar/c63171bd053adcf287659e16440bd6efd834a795/demo/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/NumberProgressBar/c63171bd053adcf287659e16440bd6efd834a795/demo/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/NumberProgressBar/c63171bd053adcf287659e16440bd6efd834a795/demo/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
22 |
23 |
31 |
32 |
38 |
39 |
46 |
47 |
48 |
55 |
56 |
57 |
64 |
65 |
72 |
73 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/demo/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/demo/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Example
5 | Hello world!
6 | Settings
7 | ProgressBar is finished.
8 |
9 |
10 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Settings specified in this file will override any Gradle settings
4 | # configured through the IDE.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
10 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | VERSION_NAME=1.4
16 | VERSION_CODE=5
17 | GROUP=com.daimajia.numberprogressbar
18 | POM_DESCRIPTION=A more beautiful progressbar in Android
19 | POM_URL=https://github.com/daimajia/NumberProgressBar
20 | POM_SCM_URL=https://github.com/chrisbanes/ActionBar-PullToRefresh
21 | POM_SCM_CONNECTION=scm:https://github.com/daimajia/NumberProgressBar.git
22 | POM_SCM_DEV_CONNECTION=scm:https://github.com/daimajia/NumberProgressBar.git
23 | POM_LICENCE_NAME=MIT
24 | POM_LICENCE_URL=http://opensource.org/licenses/MIT
25 | POM_LICENCE_DIST=repo
26 | POM_DEVELOPER_ID=daimajia
27 | POM_DEVELOPER_NAME=daimajia
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/NumberProgressBar/c63171bd053adcf287659e16440bd6efd834a795/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Feb 16 20:38:04 CST 2017
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.14.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 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 9
9 | targetSdkVersion 25
10 | versionCode 5
11 | versionName "1.4"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | consumerProguardFiles 'proguard-rules.pro'
17 | }
18 | }
19 | return true
20 | }
21 |
22 | apply from: './gradle-mvn-push.gradle'
--------------------------------------------------------------------------------
/library/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 | }
41 |
42 | afterEvaluate { project ->
43 | uploadArchives {
44 | repositories {
45 | mavenDeployer {
46 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
47 |
48 | pom.groupId = GROUP
49 | pom.artifactId = POM_ARTIFACT_ID
50 | pom.version = VERSION_NAME
51 |
52 | repository(url: getReleaseRepositoryUrl()) {
53 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
54 | }
55 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
56 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
57 | }
58 |
59 | pom.project {
60 | name POM_NAME
61 | packaging POM_PACKAGING
62 | description POM_DESCRIPTION
63 | url POM_URL
64 |
65 | scm {
66 | url POM_SCM_URL
67 | connection POM_SCM_CONNECTION
68 | developerConnection POM_SCM_DEV_CONNECTION
69 | }
70 |
71 | licenses {
72 | license {
73 | name POM_LICENCE_NAME
74 | url POM_LICENCE_URL
75 | distribution POM_LICENCE_DIST
76 | }
77 | }
78 |
79 | developers {
80 | developer {
81 | id POM_DEVELOPER_ID
82 | name POM_DEVELOPER_NAME
83 | }
84 | }
85 | }
86 | }
87 | }
88 | }
89 |
90 | signing {
91 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
92 | sign configurations.archives
93 | }
94 |
95 | task apklib(type: Zip){
96 | appendix = extension = 'apklib'
97 |
98 | from 'AndroidManifest.xml'
99 | into('res') {
100 | from 'res'
101 | }
102 | into('src') {
103 | from 'src'
104 | }
105 | }
106 |
107 | task jar(type: Jar) {
108 | from android.sourceSets.main.java.srcDirs
109 | }
110 |
111 | task androidJavadocs(type: Javadoc) {
112 | source = android.sourceSets.main.java.srcDirs
113 | classpath += project.files(android.getBootClasspath() .join(File.pathSeparator))
114 | }
115 |
116 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
117 | classifier = 'javadoc'
118 | from androidJavadocs.destinationDir
119 | }
120 |
121 | task androidSourcesJar(type: Jar) {
122 | classifier = 'sources'
123 | from android.sourceSets.main.java.srcDirs
124 | }
125 |
126 | artifacts {
127 | archives androidSourcesJar
128 | archives androidJavadocsJar
129 | archives apklib
130 | archives jar
131 | }
132 | }
--------------------------------------------------------------------------------
/library/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Settings specified in this file will override any Gradle settings
4 | # configured through the IDE.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
10 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | POM_NAME=NumberProgressBar Library
16 | POM_ARTIFACT_ID=library
17 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
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 | -keep class com.daimajia.numberprogressbar.** { *; }
19 | -keep interface com.daimajia.numberprogressbar.** { *; }
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/java/com/daimajia/numberprogressbar/NumberProgressBar.java:
--------------------------------------------------------------------------------
1 | package com.daimajia.numberprogressbar;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.RectF;
9 | import android.os.Bundle;
10 | import android.os.Parcelable;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 |
14 | import static com.daimajia.numberprogressbar.NumberProgressBar.ProgressTextVisibility.Invisible;
15 | import static com.daimajia.numberprogressbar.NumberProgressBar.ProgressTextVisibility.Visible;
16 |
17 | /**
18 | * Created by daimajia on 14-4-30.
19 | */
20 | public class NumberProgressBar extends View {
21 |
22 | private int mMaxProgress = 100;
23 |
24 | /**
25 | * Current progress, can not exceed the max progress.
26 | */
27 | private int mCurrentProgress = 0;
28 |
29 | /**
30 | * The progress area bar color.
31 | */
32 | private int mReachedBarColor;
33 |
34 | /**
35 | * The bar unreached area color.
36 | */
37 | private int mUnreachedBarColor;
38 |
39 | /**
40 | * The progress text color.
41 | */
42 | private int mTextColor;
43 |
44 | /**
45 | * The progress text size.
46 | */
47 | private float mTextSize;
48 |
49 | /**
50 | * The height of the reached area.
51 | */
52 | private float mReachedBarHeight;
53 |
54 | /**
55 | * The height of the unreached area.
56 | */
57 | private float mUnreachedBarHeight;
58 |
59 | /**
60 | * The suffix of the number.
61 | */
62 | private String mSuffix = "%";
63 |
64 | /**
65 | * The prefix.
66 | */
67 | private String mPrefix = "";
68 |
69 |
70 | private final int default_text_color = Color.rgb(66, 145, 241);
71 | private final int default_reached_color = Color.rgb(66, 145, 241);
72 | private final int default_unreached_color = Color.rgb(204, 204, 204);
73 | private final float default_progress_text_offset;
74 | private final float default_text_size;
75 | private final float default_reached_bar_height;
76 | private final float default_unreached_bar_height;
77 |
78 | /**
79 | * For save and restore instance of progressbar.
80 | */
81 | private static final String INSTANCE_STATE = "saved_instance";
82 | private static final String INSTANCE_TEXT_COLOR = "text_color";
83 | private static final String INSTANCE_TEXT_SIZE = "text_size";
84 | private static final String INSTANCE_REACHED_BAR_HEIGHT = "reached_bar_height";
85 | private static final String INSTANCE_REACHED_BAR_COLOR = "reached_bar_color";
86 | private static final String INSTANCE_UNREACHED_BAR_HEIGHT = "unreached_bar_height";
87 | private static final String INSTANCE_UNREACHED_BAR_COLOR = "unreached_bar_color";
88 | private static final String INSTANCE_MAX = "max";
89 | private static final String INSTANCE_PROGRESS = "progress";
90 | private static final String INSTANCE_SUFFIX = "suffix";
91 | private static final String INSTANCE_PREFIX = "prefix";
92 | private static final String INSTANCE_TEXT_VISIBILITY = "text_visibility";
93 |
94 | private static final int PROGRESS_TEXT_VISIBLE = 0;
95 |
96 |
97 | /**
98 | * The width of the text that to be drawn.
99 | */
100 | private float mDrawTextWidth;
101 |
102 | /**
103 | * The drawn text start.
104 | */
105 | private float mDrawTextStart;
106 |
107 | /**
108 | * The drawn text end.
109 | */
110 | private float mDrawTextEnd;
111 |
112 | /**
113 | * The text that to be drawn in onDraw().
114 | */
115 | private String mCurrentDrawText;
116 |
117 | /**
118 | * The Paint of the reached area.
119 | */
120 | private Paint mReachedBarPaint;
121 | /**
122 | * The Paint of the unreached area.
123 | */
124 | private Paint mUnreachedBarPaint;
125 | /**
126 | * The Paint of the progress text.
127 | */
128 | private Paint mTextPaint;
129 |
130 | /**
131 | * Unreached bar area to draw rect.
132 | */
133 | private RectF mUnreachedRectF = new RectF(0, 0, 0, 0);
134 | /**
135 | * Reached bar area rect.
136 | */
137 | private RectF mReachedRectF = new RectF(0, 0, 0, 0);
138 |
139 | /**
140 | * The progress text offset.
141 | */
142 | private float mOffset;
143 |
144 | /**
145 | * Determine if need to draw unreached area.
146 | */
147 | private boolean mDrawUnreachedBar = true;
148 |
149 | private boolean mDrawReachedBar = true;
150 |
151 | private boolean mIfDrawText = true;
152 |
153 | /**
154 | * Listener
155 | */
156 | private OnProgressBarListener mListener;
157 |
158 | public enum ProgressTextVisibility {
159 | Visible, Invisible
160 | }
161 |
162 | public NumberProgressBar(Context context) {
163 | this(context, null);
164 | }
165 |
166 | public NumberProgressBar(Context context, AttributeSet attrs) {
167 | this(context, attrs, 0);
168 | }
169 |
170 | public NumberProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
171 | super(context, attrs, defStyleAttr);
172 |
173 | default_reached_bar_height = dp2px(1.5f);
174 | default_unreached_bar_height = dp2px(1.0f);
175 | default_text_size = sp2px(10);
176 | default_progress_text_offset = dp2px(3.0f);
177 |
178 | //load styled attributes.
179 | final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.NumberProgressBar,
180 | defStyleAttr, 0);
181 |
182 | mReachedBarColor = attributes.getColor(R.styleable.NumberProgressBar_progress_reached_color, default_reached_color);
183 | mUnreachedBarColor = attributes.getColor(R.styleable.NumberProgressBar_progress_unreached_color, default_unreached_color);
184 | mTextColor = attributes.getColor(R.styleable.NumberProgressBar_progress_text_color, default_text_color);
185 | mTextSize = attributes.getDimension(R.styleable.NumberProgressBar_progress_text_size, default_text_size);
186 |
187 | mReachedBarHeight = attributes.getDimension(R.styleable.NumberProgressBar_progress_reached_bar_height, default_reached_bar_height);
188 | mUnreachedBarHeight = attributes.getDimension(R.styleable.NumberProgressBar_progress_unreached_bar_height, default_unreached_bar_height);
189 | mOffset = attributes.getDimension(R.styleable.NumberProgressBar_progress_text_offset, default_progress_text_offset);
190 |
191 | int textVisible = attributes.getInt(R.styleable.NumberProgressBar_progress_text_visibility, PROGRESS_TEXT_VISIBLE);
192 | if (textVisible != PROGRESS_TEXT_VISIBLE) {
193 | mIfDrawText = false;
194 | }
195 |
196 | setProgress(attributes.getInt(R.styleable.NumberProgressBar_progress_current, 0));
197 | setMax(attributes.getInt(R.styleable.NumberProgressBar_progress_max, 100));
198 |
199 | attributes.recycle();
200 | initializePainters();
201 | }
202 |
203 | @Override
204 | protected int getSuggestedMinimumWidth() {
205 | return (int) mTextSize;
206 | }
207 |
208 | @Override
209 | protected int getSuggestedMinimumHeight() {
210 | return Math.max((int) mTextSize, Math.max((int) mReachedBarHeight, (int) mUnreachedBarHeight));
211 | }
212 |
213 | @Override
214 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
215 | setMeasuredDimension(measure(widthMeasureSpec, true), measure(heightMeasureSpec, false));
216 | }
217 |
218 | private int measure(int measureSpec, boolean isWidth) {
219 | int result;
220 | int mode = MeasureSpec.getMode(measureSpec);
221 | int size = MeasureSpec.getSize(measureSpec);
222 | int padding = isWidth ? getPaddingLeft() + getPaddingRight() : getPaddingTop() + getPaddingBottom();
223 | if (mode == MeasureSpec.EXACTLY) {
224 | result = size;
225 | } else {
226 | result = isWidth ? getSuggestedMinimumWidth() : getSuggestedMinimumHeight();
227 | result += padding;
228 | if (mode == MeasureSpec.AT_MOST) {
229 | if (isWidth) {
230 | result = Math.max(result, size);
231 | } else {
232 | result = Math.min(result, size);
233 | }
234 | }
235 | }
236 | return result;
237 | }
238 |
239 | @Override
240 | protected void onDraw(Canvas canvas) {
241 | if (mIfDrawText) {
242 | calculateDrawRectF();
243 | } else {
244 | calculateDrawRectFWithoutProgressText();
245 | }
246 |
247 | if (mDrawReachedBar) {
248 | canvas.drawRect(mReachedRectF, mReachedBarPaint);
249 | }
250 |
251 | if (mDrawUnreachedBar) {
252 | canvas.drawRect(mUnreachedRectF, mUnreachedBarPaint);
253 | }
254 |
255 | if (mIfDrawText)
256 | canvas.drawText(mCurrentDrawText, mDrawTextStart, mDrawTextEnd, mTextPaint);
257 | }
258 |
259 | private void initializePainters() {
260 | mReachedBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
261 | mReachedBarPaint.setColor(mReachedBarColor);
262 |
263 | mUnreachedBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
264 | mUnreachedBarPaint.setColor(mUnreachedBarColor);
265 |
266 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
267 | mTextPaint.setColor(mTextColor);
268 | mTextPaint.setTextSize(mTextSize);
269 | }
270 |
271 |
272 | private void calculateDrawRectFWithoutProgressText() {
273 | mReachedRectF.left = getPaddingLeft();
274 | mReachedRectF.top = getHeight() / 2.0f - mReachedBarHeight / 2.0f;
275 | mReachedRectF.right = (getWidth() - getPaddingLeft() - getPaddingRight()) / (getMax() * 1.0f) * getProgress() + getPaddingLeft();
276 | mReachedRectF.bottom = getHeight() / 2.0f + mReachedBarHeight / 2.0f;
277 |
278 | mUnreachedRectF.left = mReachedRectF.right;
279 | mUnreachedRectF.right = getWidth() - getPaddingRight();
280 | mUnreachedRectF.top = getHeight() / 2.0f + -mUnreachedBarHeight / 2.0f;
281 | mUnreachedRectF.bottom = getHeight() / 2.0f + mUnreachedBarHeight / 2.0f;
282 | }
283 |
284 | private void calculateDrawRectF() {
285 |
286 | mCurrentDrawText = String.format("%d", getProgress() * 100 / getMax());
287 | mCurrentDrawText = mPrefix + mCurrentDrawText + mSuffix;
288 | mDrawTextWidth = mTextPaint.measureText(mCurrentDrawText);
289 |
290 | if (getProgress() == 0) {
291 | mDrawReachedBar = false;
292 | mDrawTextStart = getPaddingLeft();
293 | } else {
294 | mDrawReachedBar = true;
295 | mReachedRectF.left = getPaddingLeft();
296 | mReachedRectF.top = getHeight() / 2.0f - mReachedBarHeight / 2.0f;
297 | mReachedRectF.right = (getWidth() - getPaddingLeft() - getPaddingRight()) / (getMax() * 1.0f) * getProgress() - mOffset + getPaddingLeft();
298 | mReachedRectF.bottom = getHeight() / 2.0f + mReachedBarHeight / 2.0f;
299 | mDrawTextStart = (mReachedRectF.right + mOffset);
300 | }
301 |
302 | mDrawTextEnd = (int) ((getHeight() / 2.0f) - ((mTextPaint.descent() + mTextPaint.ascent()) / 2.0f));
303 |
304 | if ((mDrawTextStart + mDrawTextWidth) >= getWidth() - getPaddingRight()) {
305 | mDrawTextStart = getWidth() - getPaddingRight() - mDrawTextWidth;
306 | mReachedRectF.right = mDrawTextStart - mOffset;
307 | }
308 |
309 | float unreachedBarStart = mDrawTextStart + mDrawTextWidth + mOffset;
310 | if (unreachedBarStart >= getWidth() - getPaddingRight()) {
311 | mDrawUnreachedBar = false;
312 | } else {
313 | mDrawUnreachedBar = true;
314 | mUnreachedRectF.left = unreachedBarStart;
315 | mUnreachedRectF.right = getWidth() - getPaddingRight();
316 | mUnreachedRectF.top = getHeight() / 2.0f + -mUnreachedBarHeight / 2.0f;
317 | mUnreachedRectF.bottom = getHeight() / 2.0f + mUnreachedBarHeight / 2.0f;
318 | }
319 | }
320 |
321 | /**
322 | * Get progress text color.
323 | *
324 | * @return progress text color.
325 | */
326 | public int getTextColor() {
327 | return mTextColor;
328 | }
329 |
330 | /**
331 | * Get progress text size.
332 | *
333 | * @return progress text size.
334 | */
335 | public float getProgressTextSize() {
336 | return mTextSize;
337 | }
338 |
339 | public int getUnreachedBarColor() {
340 | return mUnreachedBarColor;
341 | }
342 |
343 | public int getReachedBarColor() {
344 | return mReachedBarColor;
345 | }
346 |
347 | public int getProgress() {
348 | return mCurrentProgress;
349 | }
350 |
351 | public int getMax() {
352 | return mMaxProgress;
353 | }
354 |
355 | public float getReachedBarHeight() {
356 | return mReachedBarHeight;
357 | }
358 |
359 | public float getUnreachedBarHeight() {
360 | return mUnreachedBarHeight;
361 | }
362 |
363 | public void setProgressTextSize(float textSize) {
364 | this.mTextSize = textSize;
365 | mTextPaint.setTextSize(mTextSize);
366 | invalidate();
367 | }
368 |
369 | public void setProgressTextColor(int textColor) {
370 | this.mTextColor = textColor;
371 | mTextPaint.setColor(mTextColor);
372 | invalidate();
373 | }
374 |
375 | public void setUnreachedBarColor(int barColor) {
376 | this.mUnreachedBarColor = barColor;
377 | mUnreachedBarPaint.setColor(mUnreachedBarColor);
378 | invalidate();
379 | }
380 |
381 | public void setReachedBarColor(int progressColor) {
382 | this.mReachedBarColor = progressColor;
383 | mReachedBarPaint.setColor(mReachedBarColor);
384 | invalidate();
385 | }
386 |
387 | public void setReachedBarHeight(float height) {
388 | mReachedBarHeight = height;
389 | }
390 |
391 | public void setUnreachedBarHeight(float height) {
392 | mUnreachedBarHeight = height;
393 | }
394 |
395 | public void setMax(int maxProgress) {
396 | if (maxProgress > 0) {
397 | this.mMaxProgress = maxProgress;
398 | invalidate();
399 | }
400 | }
401 |
402 | public void setSuffix(String suffix) {
403 | if (suffix == null) {
404 | mSuffix = "";
405 | } else {
406 | mSuffix = suffix;
407 | }
408 | }
409 |
410 | public String getSuffix() {
411 | return mSuffix;
412 | }
413 |
414 | public void setPrefix(String prefix) {
415 | if (prefix == null)
416 | mPrefix = "";
417 | else {
418 | mPrefix = prefix;
419 | }
420 | }
421 |
422 | public String getPrefix() {
423 | return mPrefix;
424 | }
425 |
426 | public void incrementProgressBy(int by) {
427 | if (by > 0) {
428 | setProgress(getProgress() + by);
429 | }
430 |
431 | if(mListener != null){
432 | mListener.onProgressChange(getProgress(), getMax());
433 | }
434 | }
435 |
436 | public void setProgress(int progress) {
437 | if (progress <= getMax() && progress >= 0) {
438 | this.mCurrentProgress = progress;
439 | invalidate();
440 | }
441 | }
442 |
443 | @Override
444 | protected Parcelable onSaveInstanceState() {
445 | final Bundle bundle = new Bundle();
446 | bundle.putParcelable(INSTANCE_STATE, super.onSaveInstanceState());
447 | bundle.putInt(INSTANCE_TEXT_COLOR, getTextColor());
448 | bundle.putFloat(INSTANCE_TEXT_SIZE, getProgressTextSize());
449 | bundle.putFloat(INSTANCE_REACHED_BAR_HEIGHT, getReachedBarHeight());
450 | bundle.putFloat(INSTANCE_UNREACHED_BAR_HEIGHT, getUnreachedBarHeight());
451 | bundle.putInt(INSTANCE_REACHED_BAR_COLOR, getReachedBarColor());
452 | bundle.putInt(INSTANCE_UNREACHED_BAR_COLOR, getUnreachedBarColor());
453 | bundle.putInt(INSTANCE_MAX, getMax());
454 | bundle.putInt(INSTANCE_PROGRESS, getProgress());
455 | bundle.putString(INSTANCE_SUFFIX, getSuffix());
456 | bundle.putString(INSTANCE_PREFIX, getPrefix());
457 | bundle.putBoolean(INSTANCE_TEXT_VISIBILITY, getProgressTextVisibility());
458 | return bundle;
459 | }
460 |
461 | @Override
462 | protected void onRestoreInstanceState(Parcelable state) {
463 | if (state instanceof Bundle) {
464 | final Bundle bundle = (Bundle) state;
465 | mTextColor = bundle.getInt(INSTANCE_TEXT_COLOR);
466 | mTextSize = bundle.getFloat(INSTANCE_TEXT_SIZE);
467 | mReachedBarHeight = bundle.getFloat(INSTANCE_REACHED_BAR_HEIGHT);
468 | mUnreachedBarHeight = bundle.getFloat(INSTANCE_UNREACHED_BAR_HEIGHT);
469 | mReachedBarColor = bundle.getInt(INSTANCE_REACHED_BAR_COLOR);
470 | mUnreachedBarColor = bundle.getInt(INSTANCE_UNREACHED_BAR_COLOR);
471 | initializePainters();
472 | setMax(bundle.getInt(INSTANCE_MAX));
473 | setProgress(bundle.getInt(INSTANCE_PROGRESS));
474 | setPrefix(bundle.getString(INSTANCE_PREFIX));
475 | setSuffix(bundle.getString(INSTANCE_SUFFIX));
476 | setProgressTextVisibility(bundle.getBoolean(INSTANCE_TEXT_VISIBILITY) ? Visible : Invisible);
477 | super.onRestoreInstanceState(bundle.getParcelable(INSTANCE_STATE));
478 | return;
479 | }
480 | super.onRestoreInstanceState(state);
481 | }
482 |
483 | public float dp2px(float dp) {
484 | final float scale = getResources().getDisplayMetrics().density;
485 | return dp * scale + 0.5f;
486 | }
487 |
488 | public float sp2px(float sp) {
489 | final float scale = getResources().getDisplayMetrics().scaledDensity;
490 | return sp * scale;
491 | }
492 |
493 | public void setProgressTextVisibility(ProgressTextVisibility visibility) {
494 | mIfDrawText = visibility == Visible;
495 | invalidate();
496 | }
497 |
498 | public boolean getProgressTextVisibility() {
499 | return mIfDrawText;
500 | }
501 |
502 | public void setOnProgressBarListener(OnProgressBarListener listener){
503 | mListener = listener;
504 | }
505 | }
506 |
--------------------------------------------------------------------------------
/library/src/main/java/com/daimajia/numberprogressbar/OnProgressBarListener.java:
--------------------------------------------------------------------------------
1 | package com.daimajia.numberprogressbar;
2 |
3 | /**
4 | * Created by lelexxx on 15-4-23.
5 | */
6 | public interface OnProgressBarListener {
7 |
8 | void onProgressChange(int current, int max);
9 | }
10 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/library/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
36 |
37 |
52 |
53 |
68 |
69 |
84 |
85 |
100 |
101 |
116 |
117 |
132 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'library', 'demo'
2 |
--------------------------------------------------------------------------------