├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── libraries │ ├── appcompat_v7_23_1_1.xml │ ├── support_annotations_23_1_1.xml │ └── support_v4_23_1_1.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── workspace.xml ├── MyApplication.iml ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── wingsofts │ │ └── circlepercentview │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── wingsofts │ │ │ └── circlepercentview │ │ │ ├── CirclePercentView.java │ │ │ ├── MainActivity.java │ │ │ └── PxUtils.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── wingsofts │ └── circlepercentview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── perview.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | # Built application files 3 | *.apk 4 | *.ap_ 5 | 6 | # Files for the Dalvik VM 7 | *.dex 8 | 9 | # Java class files 10 | *.class 11 | 12 | # Generated files 13 | bin/ 14 | gen/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | /*/build/ 20 | 21 | # Local configuration file (sdk path, etc) 22 | local.properties 23 | 24 | # Proguard folder generated by Eclipse 25 | proguard/ 26 | 27 | # Log Files 28 | *.log 29 | ======= 30 | 31 | #android 32 | *.apk 33 | *.ap_ 34 | *.dex 35 | *.class 36 | bin/ 37 | gen/ 38 | .gradle/ 39 | build/ 40 | local.properties 41 | proguard/ 42 | *.log 43 | .nacigatiom/ 44 | 45 | >>>>>>> ebd0de6d73b80bab98ae51f1f3d452c0d1572f83 46 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | CirclePercentView -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/libraries/appcompat_v7_23_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/support_annotations_23_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_v4_23_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | $USER_HOME$/.subversion 48 | 50 | 51 | 52 | 53 | 54 | 1.8 55 | 56 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 22 | 23 | 24 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 136 | 1283 | 1288 | 1647 | 1650 | 1651 | 1652 | 1662 | 1663 | 1664 | 1669 | 1670 | 1671 | 1672 | 1673 | 1674 | 1675 | 1676 | 1677 | 1678 | 1679 | 1680 | 1681 | 1682 | 1683 | 1684 | 1685 | 1686 | 1687 | 1688 | 1689 | 1690 | 1691 | 1692 | 1693 | 1694 | 1695 | 1696 | 1697 | 1698 | 1699 | 1700 | 1701 | 1704 | 1705 | 1708 | 1709 | 1710 | 1711 | 1714 | 1715 | 1718 | 1719 | 1720 | 1721 | 1724 | 1725 | 1728 | 1729 | 1732 | 1733 | 1734 | 1735 | 1738 | 1739 | 1742 | 1743 | 1746 | 1747 | 1750 | 1751 | 1752 | 1753 | 1754 | 1755 | 1756 | 1757 | 1758 | 1759 | 1760 | 1761 | 1762 | 1763 | 1764 | 1765 | 1766 | 1767 | 1768 | 1769 | 1770 | 1771 | 1772 | 1801 | 1802 | 1803 | 1831 | 1832 | 1833 | 1846 | 1847 | 1848 | 1849 | 1863 | 1864 | 1865 | 1866 | 1869 | 1870 | 1871 | 1872 | 1873 | 1887 | 1888 | 1889 | 1890 | 1891 | 1892 | 1893 | 1894 | 1895 | 1896 | 1897 | 1898 | 1912 | 1913 | 1920 | 1921 | 1922 | 1923 | 1941 | 1948 | 1949 | 1950 | 1951 | 1969 | 1976 | 1977 | 1978 | 2007 | 2008 | 2009 | 2010 | 2011 | 2019 | 2020 | 2022 | 2023 | 2024 | 2025 | 2026 | 2027 | 1450269762879 2028 | 2031 | 2032 | 2033 | 2034 | 2035 | 2036 | 2037 | 2038 | 2039 | 2040 | 2041 | 2042 | 2043 | 2044 | 2045 | 2046 | 2047 | 2048 | 2049 | 2050 | 2051 | 2052 | 2053 | 2054 | 2055 | 2056 | 2057 | 2058 | 2059 | 2060 | 2061 | 2062 | 2063 | 2064 | 2065 | 2066 | 2067 | 2068 | 2069 | 2070 | 2072 | 2073 | 2074 | 2075 | 2076 | 2077 | 2078 | 2079 | 2080 | 2081 | 2082 | 2083 | 2084 | 2085 | 2086 | 2087 | 2088 | 2089 | 2090 | 2091 | 2092 | 2093 | 2094 | 2095 | 2096 | 2097 | 2098 | 2099 | 2100 | 2101 | 2102 | 2103 | 2104 | 2105 | 2106 | 2107 | 2108 | 2109 | 2110 | 2111 | 2112 | 2113 | 2114 | 2115 | 2116 | 2117 | 2118 | 2119 | 2120 | 2121 | 2122 | 2123 | 2124 | 2125 | 2126 | 2127 | 2128 | 2129 | 2130 | 2131 | 2132 | 2133 | 2134 | 2135 | 2136 | 2137 | 2138 | 2139 | 2140 | 2141 | 2142 | 2143 | 2144 | 2145 | 2146 | 2147 | 2148 | 2149 | 2150 | 2151 | 2152 | 2153 | 2154 | 2155 | 2156 | 2157 | 2158 | 2159 | 2160 | 2161 | 2162 | 2163 | 2164 | 2165 | 2166 | 2167 | 2168 | 2169 | 2170 | 2171 | 2172 | 2173 | 2174 | 2175 | 2176 | 2177 | 2178 | 2179 | 2180 | 2181 | 2182 | 2183 | 2184 | 2185 | 2186 | 2187 | 2188 | 2189 | 2190 | 2191 | 2192 | 2193 | 2194 | 2195 | 2196 | 2197 | 2198 | 2199 | 2200 | 2201 | 2202 | 2203 | 2204 | 2205 | 2206 | 2207 | 2208 | 2209 | 2210 | 2211 | 2212 | 2213 | 2214 | 2215 | 2216 | 2217 | 2218 | 2219 | 2220 | 2221 | 2222 | 2223 | 2224 | 2225 | 2226 | 2227 | 2228 | 2229 | 2230 | 2231 | 2232 | 2233 | 2234 | 2235 | 2236 | 2237 | 2238 | 2239 | 2240 | 2241 | 2242 | 2243 | 2244 | 2245 | 2246 | 2247 | -------------------------------------------------------------------------------- /MyApplication.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CirclePercentView 2 | An Android CirclePercentView 3 | <<<<<<< HEAD 4 | ======= 5 | 6 | ###Perview 7 | ![image](https://github.com/githubwing/CirclePercentView/raw/master/perview.gif) 8 | ###How To Use 9 | add a CirclePercentView into your XML. 10 | 11 | ``` 12 | 19 | ``` 20 | you can change percent by call method setPercent() 21 | ``` 22 | mButton.setOnClickListener(new View.OnClickListener() { 23 | @Override 24 | public void onClick(View v) { 25 | int n = (int)(Math.random()*100); 26 | mCirclePercentView.setPercent(n); 27 | } 28 | }); 29 | 30 | ``` 31 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.wingsofts.circlepercentview" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/wing/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/wingsofts/circlepercentview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.wingsofts.circlepercentview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/wingsofts/circlepercentview/CirclePercentView.java: -------------------------------------------------------------------------------- 1 | package com.wingsofts.circlepercentview; 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.util.AttributeSet; 10 | import android.util.Log; 11 | import android.view.View; 12 | 13 | 14 | /**一个圆形百分比进度 View 15 | * 用于展示简易的图标 16 | * Created by Administrator on 2015/12/16. 17 | */ 18 | public class CirclePercentView extends View { 19 | 20 | //圆的半径 21 | private float mRadius; 22 | 23 | //色带的宽度 24 | private float mStripeWidth; 25 | //总体大小 26 | private int mHeight; 27 | private int mWidth; 28 | 29 | //动画位置百分比进度 30 | private int mCurPercent; 31 | 32 | //实际百分比进度 33 | private int mPercent; 34 | //圆心坐标 35 | private float x; 36 | private float y; 37 | 38 | //要画的弧度 39 | private int mEndAngle; 40 | 41 | //小圆的颜色 42 | private int mSmallColor; 43 | //大圆颜色 44 | private int mBigColor; 45 | 46 | //中心百分比文字大小 47 | private float mCenterTextSize; 48 | 49 | public CirclePercentView(Context context) { 50 | this(context, null); 51 | } 52 | 53 | public CirclePercentView(Context context, AttributeSet attrs) { 54 | this(context, attrs, 0); 55 | } 56 | 57 | public CirclePercentView(Context context, AttributeSet attrs, int defStyleAttr) { 58 | super(context, attrs, defStyleAttr); 59 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePercentView, defStyleAttr, 0); 60 | mStripeWidth = a.getDimension(R.styleable.CirclePercentView_stripeWidth, PxUtils.dpToPx(30, context)); 61 | mCurPercent = a.getInteger(R.styleable.CirclePercentView_percent, 0); 62 | mSmallColor = a.getColor(R.styleable.CirclePercentView_smallColor,0xffafb4db); 63 | mBigColor = a.getColor(R.styleable.CirclePercentView_bigColor,0xff6950a1); 64 | mCenterTextSize = a.getDimensionPixelSize(R.styleable.CirclePercentView_centerTextSize,PxUtils.spToPx(20,context)); 65 | mRadius = a.getDimensionPixelSize(R.styleable.CirclePercentView_radius,PxUtils.dpToPx(100,context)); 66 | } 67 | 68 | @Override 69 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 70 | //获取测量模式 71 | int widthMode = MeasureSpec.getMode(widthMeasureSpec); 72 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); 73 | //获取测量大小 74 | int widthSize = MeasureSpec.getSize(widthMeasureSpec); 75 | int heightSize = MeasureSpec.getSize(heightMeasureSpec); 76 | 77 | if (widthMode == MeasureSpec.EXACTLY && heightMode == MeasureSpec.EXACTLY) { 78 | mRadius = widthSize / 2; 79 | x = widthSize / 2; 80 | y = heightSize / 2; 81 | mWidth = widthSize; 82 | mHeight = heightSize; 83 | } 84 | 85 | if(widthMode == MeasureSpec.AT_MOST&&heightMode ==MeasureSpec.AT_MOST){ 86 | mWidth = (int) (mRadius*2); 87 | mHeight = (int) (mRadius*2); 88 | x = mRadius; 89 | y = mRadius; 90 | 91 | } 92 | 93 | setMeasuredDimension(mWidth,mHeight); 94 | } 95 | 96 | @Override 97 | protected void onDraw(Canvas canvas) { 98 | 99 | 100 | mEndAngle = (int) (mCurPercent * 3.6); 101 | //绘制大圆 102 | Paint bigCirclePaint = new Paint(); 103 | bigCirclePaint.setAntiAlias(true); 104 | bigCirclePaint.setColor(mBigColor); 105 | 106 | 107 | canvas.drawCircle(x, y, mRadius, bigCirclePaint); 108 | 109 | 110 | //饼状图 111 | Paint sectorPaint = new Paint(); 112 | sectorPaint.setColor(mSmallColor); 113 | sectorPaint.setAntiAlias(true); 114 | RectF rect = new RectF(0, 0, mWidth, mHeight); 115 | 116 | canvas.drawArc(rect, 270, mEndAngle, true, sectorPaint); 117 | 118 | 119 | //绘制小圆,颜色透明 120 | Paint smallCirclePaint = new Paint(); 121 | smallCirclePaint.setAntiAlias(true); 122 | smallCirclePaint.setColor(mBigColor); 123 | canvas.drawCircle(x, y, mRadius - mStripeWidth, smallCirclePaint); 124 | 125 | 126 | //绘制文本 127 | Paint textPaint = new Paint(); 128 | String text = mCurPercent + "%"; 129 | 130 | textPaint.setTextSize(mCenterTextSize); 131 | float textLength = textPaint.measureText(text); 132 | 133 | textPaint.setColor(Color.WHITE); 134 | canvas.drawText(text, x - textLength/2, y, textPaint); 135 | 136 | 137 | } 138 | 139 | //外部设置百分比数 140 | public void setPercent(int percent) { 141 | if (percent > 100) { 142 | throw new IllegalArgumentException("percent must less than 100!"); 143 | } 144 | 145 | setCurPercent(percent); 146 | 147 | 148 | } 149 | 150 | //内部设置百分比 用于动画效果 151 | private void setCurPercent(int percent) { 152 | 153 | mPercent = percent; 154 | 155 | new Thread(new Runnable() { 156 | @Override 157 | public void run() { 158 | int sleepTime = 1; 159 | for(int i =0;i 2 | 13 | 20 |