├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── github │ │ │ └── leelion96 │ │ │ └── piechartview │ │ │ ├── Entity │ │ │ └── PieEntry.java │ │ │ ├── MainActivity.java │ │ │ └── View │ │ │ └── PieView.java │ ├── test │ │ └── java │ │ │ └── github │ │ │ └── leelion96 │ │ │ └── piechartview │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── github │ │ └── leelion96 │ │ └── piechartview │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── .idea ├── runConfigurations.xml ├── gradle.xml ├── inspectionProfiles │ └── Project_Default.xml ├── codeStyles │ └── Project.xml └── misc.xml ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PieChartView 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leelion96/PieChartView/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leelion96/PieChartView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leelion96/PieChartView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leelion96/PieChartView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leelion96/PieChartView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leelion96/PieChartView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leelion96/PieChartView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leelion96/PieChartView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leelion96/PieChartView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leelion96/PieChartView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leelion96/PieChartView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches/build_file_checksums.ser 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | .DS_Store 9 | /build 10 | /captures 11 | .externalNativeBuild 12 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/github/leelion96/piechartview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package github.leelion96.piechartview; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 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 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/github/leelion96/piechartview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package github.leelion96.piechartview; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("github.leelion96.piechartview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "github.leelion96.piechartview" 7 | minSdkVersion 19 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:28.0.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 16 | 17 | 28 | 29 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/java/github/leelion96/piechartview/Entity/PieEntry.java: -------------------------------------------------------------------------------- 1 | package github.leelion96.piechartview.Entity; 2 | 3 | /** 4 | * @author LiCheng 5 | * @date 2019/2/22 6 | */ 7 | public class PieEntry { 8 | 9 | //颜色 10 | private int color; 11 | //比分比 12 | private float percentage; 13 | //条目名 14 | private String label; 15 | //扇区起始角度 16 | private float currentStartAngle; 17 | //扇区总角度 18 | private float sweepAngle; 19 | 20 | public PieEntry(float percentage, String label) { 21 | this.percentage = percentage; 22 | this.label = label; 23 | } 24 | 25 | public int getColor() { 26 | return color; 27 | } 28 | 29 | public void setColor(int color) { 30 | this.color = color; 31 | } 32 | 33 | public float getPercentage() { 34 | return percentage; 35 | } 36 | 37 | public void setPercentage(float percentage) { 38 | this.percentage = percentage; 39 | } 40 | 41 | public String getLabel() { 42 | return label; 43 | } 44 | 45 | public void setLabel(String label) { 46 | this.label = label; 47 | } 48 | 49 | public float getSweepAngle() { 50 | return sweepAngle; 51 | } 52 | 53 | public void setSweepAngle(float sweepAngle) { 54 | this.sweepAngle = sweepAngle; 55 | } 56 | 57 | public float getCurrentStartAngle() { 58 | return currentStartAngle; 59 | } 60 | 61 | public void setCurrentStartAngle(float currentStartAngle) { 62 | this.currentStartAngle = currentStartAngle; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/src/main/java/github/leelion96/piechartview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package github.leelion96.piechartview; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import java.util.ArrayList; 11 | 12 | import github.leelion96.piechartview.Entity.PieEntry; 13 | import github.leelion96.piechartview.View.PieView; 14 | 15 | public class MainActivity extends AppCompatActivity { 16 | private PieView mPieView; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_main); 22 | mPieView = findViewById(R.id.pieView); 23 | initPieView(); 24 | initAddAndReduce(); 25 | } 26 | 27 | private void initPieView() { 28 | mPieView.setColors(createColors()); 29 | mPieView.setData(createData()); 30 | } 31 | 32 | private ArrayList createData() { 33 | ArrayList pieLists = new ArrayList<>(); 34 | pieLists.add(new PieEntry(20.00F, "服装")); 35 | pieLists.add(new PieEntry(20.00F, "数码产品")); 36 | pieLists.add(new PieEntry(20.00F, "保健品")); 37 | pieLists.add(new PieEntry(20.00F, "户外运动用品")); 38 | pieLists.add(new PieEntry(20.00F, "其他")); 39 | return pieLists; 40 | } 41 | 42 | private ArrayList createColors() { 43 | ArrayList colorLists = new ArrayList<>(); 44 | colorLists.add(Color.parseColor("#EBBF03")); 45 | colorLists.add(Color.parseColor("#ff4d4d")); 46 | colorLists.add(Color.parseColor("#8d5ff5")); 47 | colorLists.add(Color.parseColor("#41D230")); 48 | colorLists.add(Color.parseColor("#4FAAFF")); 49 | return colorLists; 50 | } 51 | 52 | private void initAddAndReduce() { 53 | TextView tvAdd = findViewById(R.id.tv_add); 54 | TextView tvReduce = findViewById(R.id.tv_reduce); 55 | tvAdd.setOnClickListener(new View.OnClickListener() { 56 | @Override 57 | public void onClick(View v) { 58 | ViewGroup.LayoutParams layoutParams = mPieView.getLayoutParams(); 59 | layoutParams.height = mPieView.getMeasuredHeight() + 10; 60 | mPieView.setLayoutParams(layoutParams); 61 | } 62 | }); 63 | tvReduce.setOnClickListener(new View.OnClickListener() { 64 | @Override 65 | public void onClick(View v) { 66 | ViewGroup.LayoutParams layoutParams = mPieView.getLayoutParams(); 67 | layoutParams.height = mPieView.getMeasuredHeight() - 10; 68 | mPieView.setLayoutParams(layoutParams); 69 | } 70 | }); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 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 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 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 | 99 | 111 | 112 | 113 | 114 | 115 | 116 | 118 | -------------------------------------------------------------------------------- /app/src/main/java/github/leelion96/piechartview/View/PieView.java: -------------------------------------------------------------------------------- 1 | package github.leelion96.piechartview.View; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 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.view.View; 11 | 12 | 13 | import java.text.DecimalFormat; 14 | import java.util.ArrayList; 15 | 16 | import github.leelion96.piechartview.Entity.PieEntry; 17 | 18 | /** 19 | * @author LiCheng 20 | * @date 2019/2/22 21 | */ 22 | public class PieView extends View { 23 | private final int[] colors = {0xFFCCFF00, 0xFF6495ED, 0xFFE32636, 0xFF800000, 0xFF808000, 0xFFFF8C69, 0xFF808080, 24 | 0xFFE6B800, 0xFF7CFC00}; 25 | 26 | //是否显示中间的空洞 27 | private boolean mShowHole = true; 28 | //空洞的颜色 29 | private int holeColor = Color.WHITE; 30 | //饼图中间的空洞占据的比例 31 | private float holeRadiusProportion = 59; 32 | //饼图初始绘制角度 33 | private float startAngle = -90; 34 | //延长点和饼图边缘的间距 35 | private float distance = 14F; 36 | //延长点的大小 37 | private float smallCircleRadius = 3F; 38 | //延长点上的同心圆环的大小 39 | private float bigCircleRadius = 7F; 40 | //延长线转折点的横向偏移 41 | private float xOffset = 7F; 42 | //延长线转折点的纵向偏移 43 | private float yOffset = 14F; 44 | //延长线最长段部分的长度 45 | private float extend = 180F; 46 | 47 | 48 | private Paint mPaint; 49 | private RectF mRectF; 50 | //View的可用总宽高 51 | private float mTotalWidth; 52 | private float mTotalHeight; 53 | //饼图+延长线+文字 所占用长方形总空间的长宽比 54 | private float mScale; 55 | //饼图的半径 56 | private float mRadius; 57 | 58 | private ArrayList mColorLists; 59 | private ArrayList mPieLists; 60 | 61 | 62 | public PieView(Context context) { 63 | super(context); 64 | } 65 | 66 | public PieView(Context context, AttributeSet attrs) { 67 | super(context, attrs); 68 | initPaint(); 69 | } 70 | 71 | public PieView(Context context, AttributeSet attrs, int defStyleAttr) { 72 | super(context, attrs, defStyleAttr); 73 | } 74 | 75 | @Override 76 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 77 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 78 | //高度为WrapContent时,设置默认高度 79 | if (mScale != 0 && MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) { 80 | int height = (int) (mTotalWidth / mScale); 81 | setMeasuredDimension(widthMeasureSpec, height); 82 | } 83 | 84 | } 85 | 86 | @Override 87 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 88 | super.onSizeChanged(w, h, oldw, oldh); 89 | //获取实际View的宽高 90 | mTotalWidth = w - getPaddingStart() - getPaddingEnd(); 91 | mTotalHeight = h - getPaddingTop() - getPaddingBottom(); 92 | //绘制饼图所处的正方形RectF 93 | initRectF(); 94 | 95 | } 96 | 97 | //绘制饼图所处的正方形RectF 98 | private void initRectF() { 99 | 100 | Paint.FontMetrics fontMetrics = mPaint.getFontMetrics(); 101 | //文字的高度 102 | float textHeight = fontMetrics.bottom - fontMetrics.top + fontMetrics.leading; 103 | //延长线的纵向长度 104 | float lineHeight = distance + bigCircleRadius + yOffset; 105 | //延长线的横向长度 106 | float lineWidth = distance + bigCircleRadius + xOffset + extend; 107 | //求出饼状图加延长线和文字 所有内容需要的长方形空间的长宽比 108 | mScale = mTotalWidth / (mTotalWidth + lineHeight * 2 + textHeight * 2 - lineWidth * 2); 109 | 110 | 111 | //长方形空间其短边的长度 112 | float shortSideLength; 113 | //通过宽高比选择短边 114 | if (mTotalWidth / mTotalHeight >= mScale) { 115 | shortSideLength = mTotalHeight; 116 | } else { 117 | shortSideLength = mTotalWidth / mScale; 118 | } 119 | //饼图所在的区域为正方形,处于长方形空间的中心 120 | //空间的高度减去上下两部分文字显示需要的高度,除以2即为饼图的半径 121 | mRadius = shortSideLength / 2 - lineHeight - textHeight; 122 | //设置RectF的坐标 123 | mRectF = new RectF(-mRadius, -mRadius, mRadius, mRadius); 124 | } 125 | 126 | @Override 127 | protected void onDraw(Canvas canvas) { 128 | super.onDraw(canvas); 129 | //将坐标中心设到View的中心 130 | canvas.translate(mTotalWidth / 2, mTotalHeight / 2); 131 | 132 | if (isPieListsNull()) { 133 | mPaint.setColor(Color.BLACK); 134 | canvas.drawText("请通过setData添加数据", -120, 0, mPaint); 135 | } else { 136 | //绘制饼状图 137 | drawPie(canvas); 138 | //绘制中心空洞 139 | drawHole(canvas); 140 | //绘制延长线和文字 141 | drawLineAndText(canvas); 142 | } 143 | 144 | } 145 | 146 | //绘制饼图 147 | private void drawPie(Canvas canvas) { 148 | //当前起始角度 149 | for (PieEntry pie : mPieLists) { 150 | mPaint.setColor(pie.getColor()); 151 | canvas.drawArc(mRectF, 152 | pie.getCurrentStartAngle(), 153 | pie.getSweepAngle(), 154 | true, mPaint); 155 | } 156 | } 157 | 158 | //绘制中心空洞 159 | private void drawHole(Canvas canvas) { 160 | if (mShowHole) { 161 | mPaint.setColor(holeColor); 162 | canvas.drawCircle(0, 0, mRadius * holeRadiusProportion / 100, mPaint); 163 | } 164 | } 165 | 166 | //延长线分为 延长点、同心圆环和线三个部分 167 | private void drawLineAndText(Canvas canvas) { 168 | 169 | //算出延长线转折点相对起点的正余弦值 170 | double offsetRadians = Math.atan(yOffset / xOffset); 171 | float cosOffset = (float) Math.cos(offsetRadians); 172 | float sinOffset = (float) Math.sin(offsetRadians); 173 | 174 | for (PieEntry pie : mPieLists) { 175 | 176 | //延长点的位置处于扇形的中间 177 | float halfAngle = pie.getCurrentStartAngle() + pie.getSweepAngle() / 2; 178 | float cos = (float) Math.cos(Math.toRadians(halfAngle)); 179 | float sin = (float) Math.sin(Math.toRadians(halfAngle)); 180 | //通过正余弦算出延长点的位置 181 | float xCirclePoint = (mRadius + distance) * cos; 182 | float yCirclePoint = (mRadius + distance) * sin; 183 | 184 | mPaint.setColor(pie.getColor()); 185 | //绘制延长点 186 | canvas.drawCircle(xCirclePoint, yCirclePoint, smallCircleRadius, mPaint); 187 | //绘制同心圆环 188 | mPaint.setStyle(Paint.Style.STROKE); 189 | canvas.drawCircle(xCirclePoint, yCirclePoint, bigCircleRadius, mPaint); 190 | mPaint.setStyle(Paint.Style.FILL); 191 | 192 | //将饼图分为4个象限,从右上角开始顺时针,每90度分为一个象限 193 | int quadrant = (int) (halfAngle + 90) / 90; 194 | //初始化 延长线的起点、转折点、终点 195 | float xLineStartPoint = 0; 196 | float yLineStartPoint = 0; 197 | float xLineTurningPoint = 0; 198 | float yLineTurningPoint = 0; 199 | float xLineEndPoint = 0; 200 | float yLineEndPoint = 0; 201 | 202 | String text = pie.getLabel() + " " + 203 | new DecimalFormat("#.#").format(pie.getPercentage()) + "%"; 204 | 205 | 206 | //延长点、起点、转折点在同一条线上 207 | //不同象限转折的方向不同 208 | float cosLength = bigCircleRadius * cosOffset; 209 | float sinLength = bigCircleRadius * sinOffset; 210 | switch (quadrant) { 211 | case 0: 212 | xLineStartPoint = xCirclePoint + cosLength; 213 | yLineStartPoint = yCirclePoint - sinLength; 214 | xLineTurningPoint = xLineStartPoint + xOffset; 215 | yLineTurningPoint = yLineStartPoint - yOffset; 216 | xLineEndPoint = xLineTurningPoint + extend; 217 | yLineEndPoint = yLineTurningPoint; 218 | mPaint.setTextAlign(Paint.Align.RIGHT); 219 | canvas.drawText(text, xLineEndPoint, yLineEndPoint - 5, mPaint); 220 | break; 221 | case 1: 222 | xLineStartPoint = xCirclePoint + cosLength; 223 | yLineStartPoint = yCirclePoint + sinLength; 224 | xLineTurningPoint = xLineStartPoint + xOffset; 225 | yLineTurningPoint = yLineStartPoint + yOffset; 226 | xLineEndPoint = xLineTurningPoint + extend; 227 | yLineEndPoint = yLineTurningPoint; 228 | mPaint.setTextAlign(Paint.Align.RIGHT); 229 | canvas.drawText(text, xLineEndPoint, yLineEndPoint - 5, mPaint); 230 | break; 231 | case 2: 232 | xLineStartPoint = xCirclePoint - cosLength; 233 | yLineStartPoint = yCirclePoint + sinLength; 234 | xLineTurningPoint = xLineStartPoint - xOffset; 235 | yLineTurningPoint = yLineStartPoint + yOffset; 236 | xLineEndPoint = xLineTurningPoint - extend; 237 | yLineEndPoint = yLineTurningPoint; 238 | mPaint.setTextAlign(Paint.Align.LEFT); 239 | canvas.drawText(text, xLineEndPoint, yLineEndPoint - 5, mPaint); 240 | break; 241 | case 3: 242 | xLineStartPoint = xCirclePoint - cosLength; 243 | yLineStartPoint = yCirclePoint - sinLength; 244 | xLineTurningPoint = xLineStartPoint - xOffset; 245 | yLineTurningPoint = yLineStartPoint - yOffset; 246 | xLineEndPoint = xLineTurningPoint - extend; 247 | yLineEndPoint = yLineTurningPoint; 248 | mPaint.setTextAlign(Paint.Align.LEFT); 249 | canvas.drawText(text, xLineEndPoint, yLineEndPoint - 5, mPaint); 250 | break; 251 | default: 252 | } 253 | //绘制延长线 254 | canvas.drawLine(xLineStartPoint, yLineStartPoint, xLineTurningPoint, yLineTurningPoint, mPaint); 255 | canvas.drawLine(xLineTurningPoint, yLineTurningPoint, xLineEndPoint, yLineEndPoint, mPaint); 256 | } 257 | } 258 | 259 | 260 | //初始化画笔 261 | private void initPaint() { 262 | mPaint = new Paint(); 263 | mPaint.setAntiAlias(true); 264 | mPaint.setColor(Color.WHITE); 265 | mPaint.setTextSize(sp2px(12)); 266 | mPaint.setStyle(Paint.Style.FILL); 267 | mPaint.setStrokeWidth(1f); 268 | } 269 | 270 | //初始化数据 271 | private void initData() { 272 | if (isPieListsNull()) { 273 | return; 274 | } 275 | //当前起始角度 276 | float currentStartAngle = startAngle; 277 | for (int i = 0; i < mPieLists.size(); i++) { 278 | PieEntry pie = mPieLists.get(i); 279 | pie.setCurrentStartAngle(currentStartAngle); 280 | //每个数据百分比对应的角度 281 | float sweepAngle = pie.getPercentage() / 100 * 360; 282 | pie.setSweepAngle(sweepAngle); 283 | //起始角度不断增加 284 | currentStartAngle += sweepAngle; 285 | 286 | 287 | //未传入颜色时 以默认的颜色表作为颜色 288 | if (mColorLists == null || mColorLists.size() == 0) { 289 | int j = i % colors.length; 290 | pie.setColor(colors[j]); 291 | } else { 292 | pie.setColor(mColorLists.get(i)); 293 | } 294 | } 295 | } 296 | 297 | //初始化颜色 298 | private void initColors() { 299 | if (isPieListsNull()) { 300 | return; 301 | } 302 | for (int i = 0; i < mPieLists.size(); i++) { 303 | mPieLists.get(i).setColor(mColorLists.get(i)); 304 | } 305 | } 306 | 307 | //判断数据是否为空 308 | private boolean isPieListsNull() { 309 | return mPieLists == null || mPieLists.size() == 0; 310 | } 311 | 312 | //添加数据 313 | public void setData(ArrayList pieLists) { 314 | this.mPieLists = pieLists; 315 | initData(); 316 | invalidate(); 317 | } 318 | 319 | //添加颜色 320 | public void setColors(ArrayList colorLists) { 321 | this.mColorLists = colorLists; 322 | initColors(); 323 | invalidate(); 324 | } 325 | 326 | //是否显示空洞 327 | public void setShowHole(boolean isShowHole) { 328 | this.mShowHole = isShowHole; 329 | invalidate(); 330 | } 331 | 332 | /** 333 | * Value of sp to value of px. 334 | * 335 | * @param spValue The value of sp. 336 | * @return value of px 337 | */ 338 | public static int sp2px(final float spValue) { 339 | final float fontScale = Resources.getSystem().getDisplayMetrics().scaledDensity; 340 | return (int) (spValue * fontScale + 0.5f); 341 | } 342 | } 343 | --------------------------------------------------------------------------------