Skip to content

Commit 111c9d8

Browse files
committed
support custom suffix and prefix, fix #5
1 parent 2ce414b commit 111c9d8

File tree

11 files changed

+31
-14
lines changed

11 files changed

+31
-14
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:0.9.+'
8+
classpath 'com.android.tools.build:gradle:0.12.+'
99
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.10.+'
1010
}
1111
}

demo/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'android'
33

44
android {
55
compileSdkVersion 19
6-
buildToolsVersion "19.0.3"
6+
buildToolsVersion "19.1.0"
77

88
defaultConfig {
99
minSdkVersion 8

demo/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<application
66
android:allowBackup="true"
77
android:icon="@drawable/ic_launcher"
8-
android:label="NumberProgressBar"
98
android:theme="@style/AppTheme" >
109
<activity
1110
android:name="com.daimajia.numberprogressbar.example.MainActivity"

demo/src/main/res/layout/activity_main.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
android:layout_width="wrap_content"
1818
android:padding="20dp"
1919
custom:progress="0"
20-
custom:progress_text_visibility="invisible"
2120
style="@style/NumberProgressBar_Default"
2221
android:layout_height="wrap_content" />
2322

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'android-library'
22

33
android {
44
compileSdkVersion 19
5-
buildToolsVersion "19.0.3"
5+
buildToolsVersion "19.1.0"
66

77
defaultConfig {
88
minSdkVersion 8

library/src/main/AndroidManifest.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.daimajia.numberprogressbar">
3-
4-
<application android:allowBackup="true"
5-
android:label="@string/app_name"
6-
android:icon="@drawable/ic_launcher"
7-
>
8-
9-
</application>
10-
113
</manifest>

library/src/main/java/com/daimajia/numberprogressbar/NumberProgressBar.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ public class NumberProgressBar extends View {
5858
*/
5959
private float mUnreachedBarHeight;
6060

61+
/**
62+
* the suffix of the number.
63+
*/
64+
private String mSuffix = "%";
65+
66+
/**
67+
* the prefix.
68+
*/
69+
private String mPrefix = "";
70+
6171

6272
private final int default_text_color = Color.rgb(66, 145, 241);
6373
private final int default_reached_color = Color.rgb(66,145,241);
@@ -276,7 +286,8 @@ private void calculateDrawRectFWithoutProgressText(){
276286

277287
private void calculateDrawRectF(){
278288

279-
mCurrentDrawText = String.format("%d%%",getProgress()*100/getMax());
289+
mCurrentDrawText = String.format("%d" ,getProgress()*100/getMax());
290+
mCurrentDrawText = mPrefix + mCurrentDrawText + mSuffix;
280291
mDrawTextWidth = mTextPaint.measureText(mCurrentDrawText);
281292

282293
if(getProgress() == 0){
@@ -382,6 +393,22 @@ public void setMax(int Max) {
382393
}
383394
}
384395

396+
public void setSuffix(String suffix){
397+
if(suffix == null){
398+
mSuffix = "";
399+
}else{
400+
mSuffix = suffix;
401+
}
402+
}
403+
404+
public void setPrefix(String prefix){
405+
if(prefix == null)
406+
mPrefix = "";
407+
else{
408+
mPrefix = prefix;
409+
}
410+
}
411+
385412
public void incrementProgressBy(int by){
386413
if(by > 0){
387414
setProgress(getProgress() + by);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)