├── sample_zhy_progressbar ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── Screenshot2.png ├── Screenshot_.gif ├── ic_launcher-web.png ├── libs │ └── android-support-v4.jar ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── layout │ │ ├── roundbar.xml │ │ └── activity_main.xml │ ├── menu │ │ └── main.xml │ ├── values-v11 │ │ └── styles.xml │ └── values-v14 │ │ └── styles.xml ├── .classpath ├── project.properties ├── proguard-project.txt ├── .project ├── AndroidManifest.xml └── src │ └── com │ └── zhy │ └── sample │ └── progressbar │ └── MainActivity.java ├── library_zhy_progressbar ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── ic_launcher-web.png ├── libs │ └── android-support-v4.jar ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ ├── styles.xml │ │ └── attr_progress_bar.xml │ ├── menu │ │ └── main.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── drawable │ │ ├── style_01.xml │ │ ├── style_02.xml │ │ ├── style_03.xml │ │ └── style_04.xml ├── .classpath ├── AndroidManifest.xml ├── project.properties ├── proguard-project.txt ├── .project └── src │ └── com │ └── zhy │ └── view │ ├── RoundProgressBarWidthNumber.java │ └── HorizontalProgressBarWithNumber.java ├── .gitignore ├── README.md.bak ├── README.md └── LICENSE /sample_zhy_progressbar/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /library_zhy_progressbar/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/Screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/sample_zhy_progressbar/Screenshot2.png -------------------------------------------------------------------------------- /sample_zhy_progressbar/Screenshot_.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/sample_zhy_progressbar/Screenshot_.gif -------------------------------------------------------------------------------- /library_zhy_progressbar/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/library_zhy_progressbar/ic_launcher-web.png -------------------------------------------------------------------------------- /sample_zhy_progressbar/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/sample_zhy_progressbar/ic_launcher-web.png -------------------------------------------------------------------------------- /sample_zhy_progressbar/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/sample_zhy_progressbar/libs/android-support-v4.jar -------------------------------------------------------------------------------- /library_zhy_progressbar/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/library_zhy_progressbar/libs/android-support-v4.jar -------------------------------------------------------------------------------- /library_zhy_progressbar/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/library_zhy_progressbar/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /library_zhy_progressbar/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/library_zhy_progressbar/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /library_zhy_progressbar/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/library_zhy_progressbar/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/sample_zhy_progressbar/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/sample_zhy_progressbar/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/sample_zhy_progressbar/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/sample_zhy_progressbar/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /library_zhy_progressbar/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyangAndroid/Android-ProgressBarWidthNumber/HEAD/library_zhy_progressbar/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample_zhy_progressbar/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /library_zhy_progressbar/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Demo_zhy_26_progressbar 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | sample_zhy_progressbar 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/layout/roundbar.xml: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/drawable/style_01.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/drawable/style_02.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/drawable/style_03.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/drawable/style_04.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /library_zhy_progressbar/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /library_zhy_progressbar/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /library_zhy_progressbar/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | android.library=true 16 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | android.library.reference.1=../library_zhy_progressbar 16 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /library_zhy_progressbar/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | sample_zhy_progressbar 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /library_zhy_progressbar/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | library_zhy_progressbar 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /library_zhy_progressbar/res/values/attr_progress_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/src/com/zhy/sample/progressbar/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhy.sample.progressbar; 2 | 3 | import com.zhy.view.HorizontalProgressBarWithNumber; 4 | import com.zhy.view.RoundProgressBarWidthNumber; 5 | 6 | import android.os.Bundle; 7 | import android.os.Handler; 8 | import android.view.Menu; 9 | import android.app.Activity; 10 | 11 | public class MainActivity extends Activity { 12 | 13 | private RoundProgressBarWidthNumber mRoundProgressBar; 14 | 15 | private HorizontalProgressBarWithNumber mProgressBar; 16 | private static final int MSG_PROGRESS_UPDATE = 0x110; 17 | 18 | private Handler mHandler = new Handler() { 19 | public void handleMessage(android.os.Message msg) { 20 | int progress = mProgressBar.getProgress(); 21 | int roundProgress = mRoundProgressBar.getProgress(); 22 | mProgressBar.setProgress(++progress); 23 | mRoundProgressBar.setProgress(++roundProgress); 24 | if (progress >= 100) { 25 | mHandler.removeMessages(MSG_PROGRESS_UPDATE); 26 | } 27 | mHandler.sendEmptyMessageDelayed(MSG_PROGRESS_UPDATE, 100); 28 | }; 29 | }; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_main); 35 | mProgressBar = (HorizontalProgressBarWithNumber) findViewById(R.id.id_progressbar01); 36 | mRoundProgressBar = (RoundProgressBarWidthNumber) findViewById(R.id.id_progress02); 37 | mHandler.sendEmptyMessage(MSG_PROGRESS_UPDATE); 38 | 39 | } 40 | 41 | @Override 42 | public boolean onCreateOptionsMenu(Menu menu) 43 | { 44 | getMenuInflater().inflate(R.menu.main, menu); 45 | return true; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /library_zhy_progressbar/src/com/zhy/view/RoundProgressBarWidthNumber.java: -------------------------------------------------------------------------------- 1 | package com.zhy.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Paint.Cap; 7 | import android.graphics.Paint.Style; 8 | import android.graphics.RectF; 9 | import android.util.AttributeSet; 10 | 11 | import com.zhy.library.view.R; 12 | 13 | public class RoundProgressBarWidthNumber extends 14 | HorizontalProgressBarWithNumber 15 | { 16 | /** 17 | * mRadius of view 18 | */ 19 | private int mRadius = dp2px(30); 20 | private int mMaxPaintWidth; 21 | 22 | public RoundProgressBarWidthNumber(Context context) 23 | { 24 | this(context, null); 25 | } 26 | 27 | public RoundProgressBarWidthNumber(Context context, AttributeSet attrs) 28 | { 29 | super(context, attrs); 30 | 31 | mReachedProgressBarHeight = (int) (mUnReachedProgressBarHeight * 2.5f); 32 | TypedArray ta = context.obtainStyledAttributes(attrs, 33 | R.styleable.RoundProgressBarWidthNumber); 34 | mRadius = (int) ta.getDimension( 35 | R.styleable.RoundProgressBarWidthNumber_radius, mRadius); 36 | ta.recycle(); 37 | 38 | mPaint.setStyle(Style.STROKE); 39 | mPaint.setAntiAlias(true); 40 | mPaint.setDither(true); 41 | mPaint.setStrokeCap(Cap.ROUND); 42 | 43 | } 44 | 45 | /** 46 | * 这里默认在布局中padding值要么不设置,要么全部设置 47 | */ 48 | @Override 49 | protected synchronized void onMeasure(int widthMeasureSpec, 50 | int heightMeasureSpec) 51 | { 52 | 53 | mMaxPaintWidth = Math.max(mReachedProgressBarHeight, 54 | mUnReachedProgressBarHeight); 55 | int expect = mRadius * 2 + mMaxPaintWidth + getPaddingLeft() 56 | + getPaddingRight(); 57 | int width = resolveSize(expect, widthMeasureSpec); 58 | int height = resolveSize(expect, heightMeasureSpec); 59 | int realWidth = Math.min(width, height); 60 | 61 | mRadius = (realWidth - getPaddingLeft() - getPaddingRight() - mMaxPaintWidth) / 2; 62 | 63 | setMeasuredDimension(realWidth, realWidth); 64 | 65 | } 66 | 67 | @Override 68 | protected synchronized void onDraw(Canvas canvas) 69 | { 70 | 71 | String text = getProgress() + "%"; 72 | float textWidth = mPaint.measureText(text); 73 | float textHeight = (mPaint.descent() + mPaint.ascent()) / 2; 74 | 75 | canvas.save(); 76 | canvas.translate(getPaddingLeft() + mMaxPaintWidth / 2, getPaddingTop() 77 | + mMaxPaintWidth / 2); 78 | mPaint.setStyle(Style.STROKE); 79 | // draw unreaded bar 80 | mPaint.setColor(mUnReachedBarColor); 81 | mPaint.setStrokeWidth(mUnReachedProgressBarHeight); 82 | canvas.drawCircle(mRadius, mRadius, mRadius, mPaint); 83 | // draw reached bar 84 | mPaint.setColor(mReachedBarColor); 85 | mPaint.setStrokeWidth(mReachedProgressBarHeight); 86 | float sweepAngle = getProgress() * 1.0f / getMax() * 360; 87 | canvas.drawArc(new RectF(0, 0, mRadius * 2, mRadius * 2), 0, 88 | sweepAngle, false, mPaint); 89 | // draw text 90 | mPaint.setStyle(Style.FILL); 91 | canvas.drawText(text, mRadius - textWidth / 2, mRadius - textHeight, 92 | mPaint); 93 | 94 | canvas.restore(); 95 | 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /README.md.bak: -------------------------------------------------------------------------------- 1 | # Android-ViewPagerIndicator 2 | 一款仿MIUI的ViewPagerIndicator,支持Tab数量随意定义。 3 | 4 | # 效果图 5 | 6 | ## HorizontalProgressBarWithNumber 7 | ![Sample Screenshots][1] 8 | ## RoundProgressBarWidthNumber 9 | ![Sample Screenshots][2] 10 | 11 | # 用法 12 | 13 | ## 代码生成tab 14 | 15 | mIndicator.setVisibleTabCount(4);//设置可见Tab数量 16 | mIndicator.setTabItemTitles(mDatas);//设置tab标题 17 | mViewPager.setAdapter(mAdapter); 18 | mIndicator.setViewPager(mViewPager,0);//绑定ViewPager 19 | 20 | ## 直接布局中书写 21 | 布局中编写,则代码中只需要绑定ViewPager一行代码。 22 | 23 | 30 | 31 | 38 | 39 | 47 | 48 | 56 | 57 | 65 | 66 | 74 | 75 | 76 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | #关于我 88 | 89 | [我的博客地址][3] 90 | 91 | [1]: https://github.com/hongyangAndroid/Android-ViewPagerIndicator/blob/master/fixed_item.gif 92 | [2]: https://github.com/hongyangAndroid/Android-ViewPagerIndicator/blob/master/more_items.gif 93 | [3]: http://blog.csdn.net/lmj623565791 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-ProgressBarWidthNumber 2 | 通过继承ProgressBar实现的两种风格的滚动条,代码简洁易懂。 3 | 4 | # 效果图 5 | 6 | ## HorizontalProgressBarWithNumber 7 | 横向滚动条模仿了daimajia的滚动条风格。 8 | ![Sample Screenshots][1] 9 | ## RoundProgressBarWidthNumber 10 | ![Sample Screenshots][2] 11 | 12 | # 用法 13 | 14 | ### 布局文件 15 | 16 | 21 | 22 | 27 | 28 | 36 | 37 | 38 | 48 | 49 | 50 | 51 | 52 | ### Activity中 53 | package com.zhy.sample.progressbar; 54 | 55 | import com.zhy.view.HorizontalProgressBarWithNumber; 56 | import com.zhy.view.RoundProgressBarWidthNumber; 57 | 58 | import android.os.Bundle; 59 | import android.os.Handler; 60 | import android.app.Activity; 61 | 62 | public class MainActivity extends Activity { 63 | 64 | private HorizontalProgressBarWithNumber mProgressBar; 65 | private static final int MSG_PROGRESS_UPDATE = 0x110; 66 | 67 | private Handler mHandler = new Handler() { 68 | public void handleMessage(android.os.Message msg) { 69 | int progress = mProgressBar.getProgress(); 70 | mProgressBar.setProgress(++progress); 71 | if (progress >= 100) { 72 | mHandler.removeMessages(MSG_PROGRESS_UPDATE); 73 | } 74 | mHandler.sendEmptyMessageDelayed(MSG_PROGRESS_UPDATE, 100); 75 | }; 76 | }; 77 | 78 | @Override 79 | protected void onCreate(Bundle savedInstanceState) { 80 | super.onCreate(savedInstanceState); 81 | setContentView(R.layout.activity_main); 82 | mProgressBar = (HorizontalProgressBarWithNumber) findViewById(R.id.id_progressbar01); 83 | mHandler.sendEmptyMessage(MSG_PROGRESS_UPDATE); 84 | 85 | } 86 | 87 | } 88 | 89 | 90 | 91 | #关于我 92 | 93 | [我的博客地址][3] 94 | 95 | [1]: https://github.com/hongyangAndroid/Android-ProgressBarWidthNumber/blob/master/sample_zhy_progressbar/Screenshot_.gif 96 | [2]: https://github.com/hongyangAndroid/Android-ProgressBarWidthNumber/blob/master/sample_zhy_progressbar/Screenshot2.png 97 | [3]: http://blog.csdn.net/lmj623565791 98 | -------------------------------------------------------------------------------- /sample_zhy_progressbar/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | 19 | 20 | 28 | 29 | 38 | 39 | 47 | 48 | 55 | 56 | 66 | 67 | 78 | 79 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /library_zhy_progressbar/src/com/zhy/view/HorizontalProgressBarWithNumber.java: -------------------------------------------------------------------------------- 1 | package com.zhy.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Paint; 7 | import android.util.AttributeSet; 8 | import android.util.Log; 9 | import android.util.TypedValue; 10 | import android.widget.ProgressBar; 11 | 12 | import com.zhy.library.view.R; 13 | 14 | public class HorizontalProgressBarWithNumber extends ProgressBar 15 | { 16 | 17 | private static final int DEFAULT_TEXT_SIZE = 10; 18 | private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1; 19 | private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da; 20 | private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2; 21 | private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2; 22 | private static final int DEFAULT_SIZE_TEXT_OFFSET = 10; 23 | 24 | /** 25 | * painter of all drawing things 26 | */ 27 | protected Paint mPaint = new Paint(); 28 | /** 29 | * color of progress number 30 | */ 31 | protected int mTextColor = DEFAULT_TEXT_COLOR; 32 | /** 33 | * size of text (sp) 34 | */ 35 | protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE); 36 | 37 | /** 38 | * offset of draw progress 39 | */ 40 | protected int mTextOffset = dp2px(DEFAULT_SIZE_TEXT_OFFSET); 41 | 42 | /** 43 | * height of reached progress bar 44 | */ 45 | protected int mReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR); 46 | 47 | /** 48 | * color of reached bar 49 | */ 50 | protected int mReachedBarColor = DEFAULT_TEXT_COLOR; 51 | /** 52 | * color of unreached bar 53 | */ 54 | protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR; 55 | /** 56 | * height of unreached progress bar 57 | */ 58 | protected int mUnReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR); 59 | /** 60 | * view width except padding 61 | */ 62 | protected int mRealWidth; 63 | 64 | protected boolean mIfDrawText = true; 65 | 66 | protected static final int VISIBLE = 0; 67 | 68 | public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs) 69 | { 70 | this(context, attrs, 0); 71 | } 72 | 73 | public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs, 74 | int defStyle) 75 | { 76 | super(context, attrs, defStyle); 77 | obtainStyledAttributes(attrs); 78 | mPaint.setTextSize(mTextSize); 79 | mPaint.setColor(mTextColor); 80 | } 81 | 82 | @Override 83 | protected synchronized void onMeasure(int widthMeasureSpec, 84 | int heightMeasureSpec) 85 | { 86 | 87 | int width = MeasureSpec.getSize(widthMeasureSpec); 88 | int height = measureHeight(heightMeasureSpec); 89 | setMeasuredDimension(width, height); 90 | 91 | mRealWidth = getMeasuredWidth() - getPaddingRight() - getPaddingLeft(); 92 | } 93 | 94 | private int measureHeight(int measureSpec) 95 | { 96 | int result = 0; 97 | int specMode = MeasureSpec.getMode(measureSpec); 98 | int specSize = MeasureSpec.getSize(measureSpec); 99 | if (specMode == MeasureSpec.EXACTLY) 100 | { 101 | result = specSize; 102 | } else 103 | { 104 | float textHeight = (mPaint.descent() - mPaint.ascent()); 105 | result = (int) (getPaddingTop() + getPaddingBottom() + Math.max( 106 | Math.max(mReachedProgressBarHeight, 107 | mUnReachedProgressBarHeight), Math.abs(textHeight))); 108 | if (specMode == MeasureSpec.AT_MOST) 109 | { 110 | result = Math.min(result, specSize); 111 | } 112 | } 113 | return result; 114 | } 115 | 116 | /** 117 | * get the styled attributes 118 | * 119 | * @param attrs 120 | */ 121 | private void obtainStyledAttributes(AttributeSet attrs) 122 | { 123 | // init values from custom attributes 124 | final TypedArray attributes = getContext().obtainStyledAttributes( 125 | attrs, R.styleable.HorizontalProgressBarWithNumber); 126 | 127 | mTextColor = attributes 128 | .getColor( 129 | R.styleable.HorizontalProgressBarWithNumber_progress_text_color, 130 | DEFAULT_TEXT_COLOR); 131 | mTextSize = (int) attributes.getDimension( 132 | R.styleable.HorizontalProgressBarWithNumber_progress_text_size, 133 | mTextSize); 134 | 135 | mReachedBarColor = attributes 136 | .getColor( 137 | R.styleable.HorizontalProgressBarWithNumber_progress_reached_color, 138 | mTextColor); 139 | mUnReachedBarColor = attributes 140 | .getColor( 141 | R.styleable.HorizontalProgressBarWithNumber_progress_unreached_color, 142 | DEFAULT_COLOR_UNREACHED_COLOR); 143 | mReachedProgressBarHeight = (int) attributes 144 | .getDimension( 145 | R.styleable.HorizontalProgressBarWithNumber_progress_reached_bar_height, 146 | mReachedProgressBarHeight); 147 | mUnReachedProgressBarHeight = (int) attributes 148 | .getDimension( 149 | R.styleable.HorizontalProgressBarWithNumber_progress_unreached_bar_height, 150 | mUnReachedProgressBarHeight); 151 | mTextOffset = (int) attributes 152 | .getDimension( 153 | R.styleable.HorizontalProgressBarWithNumber_progress_text_offset, 154 | mTextOffset); 155 | 156 | int textVisible = attributes 157 | .getInt(R.styleable.HorizontalProgressBarWithNumber_progress_text_visibility, 158 | VISIBLE); 159 | if (textVisible != VISIBLE) 160 | { 161 | mIfDrawText = false; 162 | } 163 | attributes.recycle(); 164 | } 165 | 166 | @Override 167 | protected synchronized void onDraw(Canvas canvas) 168 | { 169 | 170 | canvas.save(); 171 | canvas.translate(getPaddingLeft(), getHeight() / 2); 172 | 173 | boolean noNeedBg = false; 174 | float radio = getProgress() * 1.0f / getMax(); 175 | float progressPosX = (int) (mRealWidth * radio); 176 | String text = getProgress() + "%"; 177 | // mPaint.getTextBounds(text, 0, text.length(), mTextBound); 178 | 179 | float textWidth = mPaint.measureText(text); 180 | float textHeight = (mPaint.descent() + mPaint.ascent()) / 2; 181 | 182 | if (progressPosX + textWidth > mRealWidth) 183 | { 184 | progressPosX = mRealWidth - textWidth; 185 | noNeedBg = true; 186 | } 187 | 188 | // draw reached bar 189 | float endX = progressPosX - mTextOffset / 2; 190 | if (endX > 0) 191 | { 192 | mPaint.setColor(mReachedBarColor); 193 | mPaint.setStrokeWidth(mReachedProgressBarHeight); 194 | canvas.drawLine(0, 0, endX, 0, mPaint); 195 | } 196 | // draw progress bar 197 | // measure text bound 198 | if (mIfDrawText) 199 | { 200 | mPaint.setColor(mTextColor); 201 | canvas.drawText(text, progressPosX, -textHeight, mPaint); 202 | } 203 | 204 | // draw unreached bar 205 | if (!noNeedBg) 206 | { 207 | float start = progressPosX + mTextOffset / 2 + textWidth; 208 | mPaint.setColor(mUnReachedBarColor); 209 | mPaint.setStrokeWidth(mUnReachedProgressBarHeight); 210 | canvas.drawLine(start, 0, mRealWidth, 0, mPaint); 211 | } 212 | 213 | canvas.restore(); 214 | 215 | } 216 | 217 | /** 218 | * dp 2 px 219 | * 220 | * @param dpVal 221 | */ 222 | protected int dp2px(int dpVal) 223 | { 224 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 225 | dpVal, getResources().getDisplayMetrics()); 226 | } 227 | 228 | /** 229 | * sp 2 px 230 | * 231 | * @param spVal 232 | * @return 233 | */ 234 | protected int sp2px(int spVal) 235 | { 236 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 237 | spVal, getResources().getDisplayMetrics()); 238 | 239 | } 240 | 241 | } 242 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------