├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── GIF.gif ├── LICENSE ├── README.md ├── app ├── .gitignore ├── app-release.apk ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── king │ │ └── spincounter │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── king │ │ │ └── spincounter │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.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 │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── king │ └── spincounter │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── king │ │ └── view │ │ └── spincounterview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── king │ │ │ └── view │ │ │ └── spincounterview │ │ │ └── SpinCounterView.java │ └── res │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── king │ └── view │ └── spincounterview │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.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 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 34 | 35 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Android 39 | 40 | 41 | Android > Lint > Correctness 42 | 43 | 44 | Java 45 | 46 | 47 | Java language level migration aidsJava 48 | 49 | 50 | 51 | 52 | Android 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 74 | 75 | 76 | 77 | 78 | 1.8 79 | 80 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /GIF.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/GIF.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jenly 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpinCounterView 2 | 3 | [![JitPack](https://img.shields.io/jitpack/v/github/jenly1314/SpinCounterView?logo=jitpack)](https://jitpack.io/#jenly1314/SpinCounterView) 4 | [![Download](https://img.shields.io/badge/download-APK-brightgreen?logo=github)](https://raw.githubusercontent.com/jenly1314/SpinCounterView/master/app/app-release.apk) 5 | [![API](https://img.shields.io/badge/API-15%2B-brightgreen?logo=android)](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) 6 | [![License](https://img.shields.io/github/license/jenly1314/SpinCounterView?logo=open-source-initiative)](https://opensource.org/licenses/mit) 7 | 8 | SpinCounterView for Android 一个类似码表变化的旋转计数器动画控件。 9 | 10 | ## 效果展示 11 | ![Image](GIF.gif) 12 | 13 | > 你也可以直接下载 [演示App](https://raw.githubusercontent.com/jenly1314/SpinCounterView/master/app/app-release.apk) 体验效果 14 | 15 | ## 引入 16 | 17 | ### Gradle: 18 | 19 | 1. 在Project的 **build.gradle** 或 **setting.gradle** 中添加远程仓库 20 | 21 | ```gradle 22 | repositories { 23 | //... 24 | mavenCentral() 25 | maven { url 'https://jitpack.io' } 26 | } 27 | ``` 28 | 29 | 2. 在Module的 **build.gradle** 中添加依赖项 30 | 31 | ```gradle 32 | implementation 'com.github.jenly1314:SpinCounterView:1.1.1' 33 | ``` 34 | 35 | ## 使用 36 | 37 | 布局示例 38 | ```Xml 39 | 45 | ``` 46 | 47 | 代码示例 48 | ```Java 49 | // 显示动画 50 | spinCounterView.showAnimation(80); 51 | ``` 52 | 53 | 更多使用详情,请查看[app](app)中的源码使用示例或直接查看[API帮助文档](https://jitpack.io/com/github/jenly1314/SpinCounterView/latest/javadoc/) 54 | 55 | 56 | ## 相关推荐 57 | - [CounterView](https://github.com/jenly1314/CounterView) 一个数字变化效果的计数器视图控件。 58 | - [RadarView](https://github.com/jenly1314/RadarView) 一个雷达扫描动画后,然后展示得分效果的控件。 59 | - [SuperTextView](https://github.com/jenly1314/SuperTextView) 一个在TextView的基础上扩展了几种动画效果的控件。 60 | - [LoadingView](https://github.com/jenly1314/LoadingView) 一个圆弧加载过渡动画,圆弧个数,大小,弧度,渐变颜色,完全可配。 61 | - [WaveView](https://github.com/jenly1314/WaveView) 一个水波纹动画控件视图,支持波纹数,波纹振幅,波纹颜色,波纹速度,波纹方向等属性完全可配。 62 | - [GiftSurfaceView](https://github.com/jenly1314/GiftSurfaceView) 一个适用于直播间送礼物拼图案的动画控件。 63 | - [FlutteringLayout](https://github.com/jenly1314/FlutteringLayout) 一个适用于直播间点赞桃心飘动效果的控件。 64 | - [DragPolygonView](https://github.com/jenly1314/DragPolygonView) 一个支持可拖动多边形,支持通过拖拽多边形的角改变其形状的任意多边形控件。 65 | - [CircleProgressView](https://github.com/jenly1314/CircleProgressView) 一个圆形的进度动画控件,动画效果纵享丝滑。 66 | - [ArcSeekBar](https://github.com/jenly1314/ArcSeekBar) 一个弧形的拖动条进度控件,配置参数完全可定制化。 67 | - [DrawBoard](https://github.com/jenly1314/DrawBoard) 一个自定义View实现的画板;方便对图片进行编辑和各种涂鸦相关操作。 68 | - [compose-component](https://github.com/jenly1314/compose-component) 一个Jetpack Compose的组件库;主要提供了一些小组件,便于快速使用。 69 | 70 | --- 71 | 72 | ![footer](https://jenly1314.github.io/page/footer.svg) 73 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/app/app-release.apk -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.king.spincounter" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 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(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.0' 28 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 29 | testCompile 'junit:junit:4.12' 30 | compile project(':lib') 31 | } 32 | -------------------------------------------------------------------------------- /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 D:\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/king/spincounter/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.king.spincounter; 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 | * Instrumentation 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() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.king.spincounter", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/king/spincounter/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.king.spincounter; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | import com.king.view.spincounterview.SpinCounterView; 8 | 9 | import java.util.Random; 10 | 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | private SpinCounterView scv; 14 | 15 | private Random mRandom; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | mRandom = new Random(); 22 | 23 | scv = (SpinCounterView) findViewById(R.id.scv); 24 | scv.setFormat(SpinCounterView.RMB_FORMAT); 25 | 26 | scv.setOnClickListener(new View.OnClickListener() { 27 | @Override 28 | public void onClick(View v) { 29 | scv.showAnimation(random(100)); 30 | } 31 | }); 32 | } 33 | 34 | 35 | private int random(int n){ 36 | return mRandom.nextInt(n); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SpinCounterView 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/king/spincounter/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.king.spincounter; 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() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.3' 9 | classpath 'com.novoda:bintray-release:0.3.4' 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | 25 | allprojects { 26 | tasks.withType(Javadoc) { 27 | options{ 28 | encoding "UTF-8" 29 | charSet 'UTF-8' 30 | links "http://docs.oracle.com/javase/8/docs/api" 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/SpinCounterView/b88e2b3599a5f7c1d292cb6335874526ebe876c7/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 05 15:06:17 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /lib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.novoda.bintray-release' 3 | 4 | android { 5 | compileSdkVersion 25 6 | buildToolsVersion "25.0.2" 7 | 8 | defaultConfig { 9 | minSdkVersion 15 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | 24 | lintOptions { 25 | abortOnError false 26 | } 27 | } 28 | 29 | dependencies { 30 | compile fileTree(dir: 'libs', include: ['*.jar']) 31 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 32 | exclude group: 'com.android.support', module: 'support-annotations' 33 | }) 34 | testCompile 'junit:junit:4.12' 35 | } 36 | 37 | 38 | //添加 39 | publish { 40 | userOrg = 'jenly'//bintray.com用户名 41 | groupId = 'com.king.view'//jcenter上的路径 42 | artifactId = 'spincounterview'//项目名称 43 | publishVersion = '1.1.1'//版本号 44 | desc = 'SpinCounterView for Android'//描述 45 | website = 'https://github.com/jenly1314/SpinCounterView'//网站 46 | } -------------------------------------------------------------------------------- /lib/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 D:\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /lib/src/androidTest/java/com/king/view/spincounterview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.king.view.spincounterview; 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 | * Instrumentation 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() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.king.view.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /lib/src/main/java/com/king/view/spincounterview/SpinCounterView.java: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | Copyright (c) 2017 Jenly Yu 4 | https://github.com/jenly1314 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files 8 | (the "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to permit 11 | persons to whom the Software is furnished to do so, subject to the 12 | following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | */ 25 | package com.king.view.spincounterview; 26 | 27 | import android.animation.ValueAnimator; 28 | import android.content.Context; 29 | import android.content.res.TypedArray; 30 | import android.graphics.Canvas; 31 | import android.graphics.Color; 32 | import android.graphics.Paint; 33 | import android.graphics.Path; 34 | import android.graphics.RectF; 35 | import android.graphics.Typeface; 36 | import android.util.AttributeSet; 37 | import android.util.DisplayMetrics; 38 | import android.util.TypedValue; 39 | import android.view.View; 40 | 41 | /** 42 | * @author Jenly Jenly 43 | * @since 2017/4/5 44 | */ 45 | 46 | public class SpinCounterView extends View { 47 | 48 | public static final String DEFAULT_FORMAT = getDecimalFormat(2); 49 | public static final String RMB_FORMAT = "¥%1$.2f"; 50 | public static final String DOLLAR_FORMAT = "$%1$.2f"; 51 | 52 | private Paint mPaint; 53 | 54 | private int mNormalColor = Color.parseColor("#c8c8c8"); 55 | private int mProgressColor = Color.parseColor("#f97203"); 56 | 57 | private int mLabelTextColor = Color.parseColor("#c8c8c8"); 58 | private int mTextColor = Color.parseColor("#f97203"); 59 | 60 | /** 61 | * 笔画的宽度 62 | */ 63 | private float mStrokeWidth = 20; 64 | 65 | /** 66 | * 开始角度 67 | */ 68 | private int mStartAngle = 145; 69 | /** 70 | * 扫描角度 71 | */ 72 | private int mSweepAngle = 250; 73 | 74 | /** 75 | * 刻度 类似于时钟的刻度 76 | */ 77 | private int mScaleAngle = 5; 78 | 79 | /** 80 | * 圆心 81 | */ 82 | private float mCircleCenterX; 83 | private float mCircleCenterY; 84 | 85 | /** 86 | * 半径 87 | */ 88 | private float mRadius = 300; 89 | 90 | /** 91 | * 最大进度 92 | */ 93 | private float mMax = 100; 94 | 95 | /** 96 | * 当前进度 97 | */ 98 | private float mProgress = 0; 99 | 100 | /** 101 | * 圆弧间的间距 102 | */ 103 | private float mSpace = 30; 104 | 105 | /** 106 | * 箭头与刻度的距离 107 | */ 108 | private float mArrow = 20; 109 | 110 | /** 111 | * 动画持续的时间 112 | */ 113 | private int mDuration = 500; 114 | 115 | /** 116 | * 标签内容 117 | */ 118 | private String mLabelText; 119 | 120 | /** 121 | * 值 122 | */ 123 | private float mValue; 124 | 125 | /** 126 | * 最大值 127 | */ 128 | private float mMaxValue = 100; 129 | 130 | /** 131 | * 值与进度的比率 mValueRatio = mValue / mProgress 132 | */ 133 | private float mValueRatio = 1; 134 | 135 | /** 136 | * 字体大小 137 | */ 138 | private float mTextSize = 60; 139 | private float mLabelTextSize = 46; 140 | 141 | 142 | /** 143 | * 文本里圆心的Y轴偏移量 144 | */ 145 | private float mTextOffsetY = 40; 146 | 147 | private String mFormat = DEFAULT_FORMAT; 148 | 149 | private boolean isShowLabel = true; 150 | 151 | private boolean isShowText = true; 152 | 153 | private OnUpdateListener mOnUpdateListener; 154 | 155 | public interface OnUpdateListener{ 156 | boolean onUpdate(float progress,float curValue,String format); 157 | } 158 | 159 | public SpinCounterView(Context context) { 160 | this(context,null); 161 | } 162 | 163 | public SpinCounterView(Context context,AttributeSet attrs) { 164 | this(context, attrs, 0); 165 | } 166 | 167 | public SpinCounterView(Context context,AttributeSet attrs, int defStyleAttr) { 168 | super(context, attrs, defStyleAttr); 169 | init(context,attrs); 170 | } 171 | 172 | private void init(Context context,AttributeSet attrs){ 173 | 174 | mPaint = new Paint(); 175 | 176 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SpinCounterView); 177 | 178 | 179 | mLabelTextSize = a.getDimension(R.styleable.SpinCounterView_android_textSize,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,16,getDisplayMetrics())); 180 | mLabelTextColor = a.getColor(R.styleable.SpinCounterView_android_textColor,mLabelTextColor); 181 | mLabelText = a.getString(R.styleable.SpinCounterView_labelText); 182 | 183 | mTextSize = a.getDimension(R.styleable.SpinCounterView_android_textSize,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,22,getDisplayMetrics())); 184 | mTextColor = a.getColor(R.styleable.SpinCounterView_android_textColor,mTextColor); 185 | 186 | mNormalColor = a.getColor(R.styleable.SpinCounterView_normalColor,mNormalColor); 187 | mProgressColor = a.getColor(R.styleable.SpinCounterView_progressColor,mProgressColor); 188 | 189 | mStrokeWidth = a.getDimension(R.styleable.SpinCounterView_strokeWidth,mStrokeWidth); 190 | mStartAngle = a.getInt(R.styleable.SpinCounterView_startAngle,mStartAngle); 191 | mSweepAngle = a.getInt(R.styleable.SpinCounterView_sweepAngle,mSweepAngle); 192 | mScaleAngle = a.getInt(R.styleable.SpinCounterView_scaleAngle,mScaleAngle); 193 | 194 | mMax = a.getFloat(R.styleable.SpinCounterView_max,mMax); 195 | mProgress = a.getFloat(R.styleable.SpinCounterView_progress,0); 196 | mMaxValue = mMax; 197 | mMaxValue = a.getFloat(R.styleable.SpinCounterView_maxValue,mMaxValue); 198 | 199 | mValueRatio = mMaxValue / mMax; 200 | 201 | mSpace = a.getDimension(R.styleable.SpinCounterView_space,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,10,getDisplayMetrics())); 202 | mArrow = a.getDimension(R.styleable.SpinCounterView_space,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,6.7f,getDisplayMetrics())); 203 | mDuration = a.getInt(R.styleable.SpinCounterView_duration,mDuration); 204 | mTextOffsetY = a.getDimension(R.styleable.SpinCounterView_duration,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,13,getDisplayMetrics())); 205 | isShowLabel = a.getBoolean(R.styleable.SpinCounterView_showLabelText,true); 206 | isShowText = a.getBoolean(R.styleable.SpinCounterView_showText,true); 207 | 208 | a.recycle(); 209 | } 210 | 211 | private DisplayMetrics getDisplayMetrics(){ 212 | return getResources().getDisplayMetrics(); 213 | } 214 | 215 | @Override 216 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 217 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 218 | 219 | int defaultValue = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,200,getDisplayMetrics()); 220 | 221 | 222 | int defaultWidth = defaultValue + getPaddingLeft() + getPaddingRight(); 223 | int defaultHeight = defaultValue + getPaddingTop() + getPaddingBottom(); 224 | 225 | int width = measureHandler(widthMeasureSpec,defaultWidth); 226 | int height = measureHandler(heightMeasureSpec,defaultHeight); 227 | 228 | //圆心坐标 229 | mCircleCenterX = (width + getPaddingLeft() - getPaddingRight())/ 2.0f; 230 | mCircleCenterY = (height + getPaddingTop() - getPaddingBottom())/ 2.0f; 231 | 232 | //半径 233 | mRadius = (width- getPaddingLeft() - getPaddingRight()) / 2.0f - mSpace; 234 | 235 | setMeasuredDimension(width,height); 236 | } 237 | 238 | private int measureHandler(int measureSpec,int defaultSize){ 239 | 240 | int result = defaultSize; 241 | int measureMode = MeasureSpec.getMode(measureSpec); 242 | int measureSize = MeasureSpec.getSize(measureSpec); 243 | if(measureMode == MeasureSpec.EXACTLY){ 244 | result = measureSize; 245 | }else if(measureMode == MeasureSpec.AT_MOST){ 246 | result = Math.min(defaultSize,measureSize); 247 | } 248 | return result; 249 | } 250 | 251 | 252 | @Override 253 | protected void onDraw(Canvas canvas) { 254 | super.onDraw(canvas); 255 | drawArc(canvas); 256 | drawCenterText(canvas); 257 | } 258 | 259 | private void drawArc(Canvas canvas){ 260 | 261 | mPaint.reset(); 262 | mPaint.setAntiAlias(true); 263 | mPaint.setStyle(Paint.Style.STROKE); 264 | mPaint.setStrokeCap(Paint.Cap.ROUND); 265 | 266 | mPaint.setStrokeWidth(mStrokeWidth); 267 | mPaint.setColor(mNormalColor); 268 | 269 | float diameter = mRadius * 2; 270 | float startX = mCircleCenterX - mRadius; 271 | float startY = mCircleCenterY - mRadius; 272 | RectF rectF = new RectF(startX,startY,startX + diameter,startY + diameter); 273 | //画最外层的弧形 274 | canvas.drawArc(rectF,mStartAngle,mSweepAngle,false,mPaint); 275 | 276 | 277 | mPaint.setColor(mProgressColor); 278 | //画最外层的弧形(当前进度) 279 | canvas.drawArc(rectF,mStartAngle,mSweepAngle * getRatio(),false,mPaint); 280 | 281 | //------------------- 282 | 283 | mPaint.setStrokeWidth(mStrokeWidth/2); 284 | 285 | float radius = mRadius - mSpace - mStrokeWidth; 286 | float ratioAngle = (float)(2 * Math.PI /360) * (mStartAngle + Math.round(mSweepAngle * getRatio()/mScaleAngle) * mScaleAngle); 287 | int size = mSweepAngle / mScaleAngle; 288 | //算出弧形上的点坐标并画点 289 | for (int i = 0; i <= size; i++) { 290 | float angle = (float)(2 * Math.PI /360) * (mStartAngle + i * mScaleAngle); 291 | 292 | float x = (float)(mCircleCenterX + Math.cos(angle) * radius); 293 | float y = (float)(mCircleCenterY + Math.sin(angle) * radius); 294 | if(ratioAngle>=angle){ 295 | mPaint.setColor(mProgressColor); 296 | }else{ 297 | mPaint.setColor(mNormalColor); 298 | } 299 | canvas.drawPoint(x,y,mPaint); 300 | } 301 | 302 | 303 | //------------------- 304 | //弧形上指示器的坐标点(当前进度) 305 | float x = (float)(mCircleCenterX + Math.cos(ratioAngle) * radius); 306 | float y = (float)(mCircleCenterY + Math.sin(ratioAngle) * radius); 307 | 308 | mPaint.setStrokeWidth(mStrokeWidth/3); 309 | mPaint.setColor(mProgressColor); 310 | //指示器的圆的半径 311 | float indicatorRadius = mStrokeWidth/2; 312 | //画进度指示器的圆 313 | canvas.drawCircle(x,y,indicatorRadius,mPaint); 314 | //指示器箭头的坐标 315 | float x1 = (float)(mCircleCenterX + Math.cos(ratioAngle) * (radius + mArrow)); 316 | float y1 = (float)(mCircleCenterY + Math.sin(ratioAngle) * (radius + mArrow)); 317 | 318 | //算出指示器到指示器圆心的直线与指示器切线的夹角 319 | float a = (float) Math.sin(radius/(radius + mArrow)); 320 | //指示器与指示器圆的切线坐标角度 321 | float angle2 = ratioAngle + a; 322 | //指示器与指示器圆的切线坐标1 323 | float x2 = (float)(x + Math.cos(angle2) * indicatorRadius); 324 | float y2 = (float)(y + Math.sin(angle2) * indicatorRadius); 325 | 326 | //指示器与指示器圆的切线坐标角度 327 | float angle3 = ratioAngle - a; 328 | //指示器与指示器圆的切线坐标2 329 | float x3 = (float)(x + Math.cos(angle3) * indicatorRadius); 330 | float y3 = (float)(y + Math.sin(angle3) * indicatorRadius); 331 | 332 | Path path = new Path(); 333 | path.moveTo(x2,y2); 334 | path.lineTo(x1,y1); 335 | path.lineTo(x3,y3); 336 | //画指示器的箭头 337 | canvas.drawPath(path,mPaint); 338 | // canvas.drawPoint(x1,y1,mPaint); 339 | 340 | //------------------- 341 | mPaint.setColor(mNormalColor); 342 | 343 | float innerDiameter = (mRadius - mStrokeWidth * 1.5f - mSpace - mSpace) * 2; 344 | float innerStartX = mCircleCenterX - mRadius + mStrokeWidth * 1.5f + mSpace + mSpace; 345 | float innerStartY = mCircleCenterY - mRadius + mStrokeWidth * 1.5f + mSpace + mSpace; 346 | RectF innerRectF = new RectF(innerStartX,innerStartY,innerStartX + innerDiameter,innerStartY + innerDiameter); 347 | //画内层的弧形 348 | canvas.drawArc(innerRectF,mStartAngle,mSweepAngle,false,mPaint); 349 | } 350 | 351 | private void drawCenterText(Canvas canvas){ 352 | mPaint.reset(); 353 | mPaint.setAntiAlias(true); 354 | mPaint.setTypeface(Typeface.DEFAULT); 355 | mPaint.setTextAlign(Paint.Align.CENTER); 356 | 357 | if(isShowLabel && mLabelText != null){//画标签文本逻辑 358 | mPaint.setColor(mLabelTextColor); 359 | mPaint.setTextSize(mLabelTextSize); 360 | float x = mCircleCenterX; 361 | float y = mCircleCenterY - mTextOffsetY; 362 | canvas.drawText(mLabelText,x,y,mPaint); 363 | } 364 | 365 | if(isShowText){//画文本逻辑 366 | mPaint.setColor(mTextColor); 367 | mPaint.setTextSize(mTextSize); 368 | mPaint.setFakeBoldText(true); 369 | String text = getFormatText(mValue,mFormat); 370 | float x = mCircleCenterX; 371 | float y = mCircleCenterY + mTextOffsetY; 372 | canvas.drawText(text,x,y,mPaint); 373 | } 374 | } 375 | 376 | private String getFormatText(float value,String format){ 377 | return String.format(format,value); 378 | } 379 | 380 | public void showAppendAnimation(float progress){ 381 | showAnimation(mProgress,progress,mDuration); 382 | } 383 | 384 | 385 | 386 | 387 | public void showAnimation(float progress){ 388 | showAnimation(progress,mDuration); 389 | } 390 | 391 | public void showAnimation(float progress,int duration){ 392 | showAnimation(0,progress,duration); 393 | } 394 | 395 | public void showAnimation(float from,float to,int duration){ 396 | showAnimation(from,to,duration,mFormat); 397 | } 398 | 399 | public void showAnimation(float from,float to,int duration,String format){ 400 | this.mDuration = duration; 401 | this.mFormat = (format == null ? DEFAULT_FORMAT : format); 402 | setProgress(to); 403 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(from,mProgress); 404 | valueAnimator.setDuration(duration); 405 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 406 | @Override 407 | public void onAnimationUpdate(ValueAnimator animation) { 408 | mProgress = (float)animation.getAnimatedValue(); 409 | mValue = mProgress * mValueRatio; 410 | if(mOnUpdateListener==null || !mOnUpdateListener.onUpdate(mProgress,mValue,mFormat)){ 411 | invalidate(); 412 | } 413 | } 414 | }); 415 | 416 | valueAnimator.start(); 417 | } 418 | 419 | public void setText(float value,String format){ 420 | this.mValue = value; 421 | this.mFormat = (format == null ? DEFAULT_FORMAT : format); 422 | invalidate(); 423 | } 424 | 425 | private float getRatio(){ 426 | return mProgress/mMax; 427 | } 428 | 429 | public void setProgress(int progress){ 430 | if(progress 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /lib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SpinCounterView 3 | 4 | -------------------------------------------------------------------------------- /lib/src/test/java/com/king/view/spincounterview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.king.view.spincounterview; 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() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':lib' 2 | --------------------------------------------------------------------------------