├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── github
│ │ └── chengang
│ │ └── tickview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── chengang
│ │ │ └── tickview
│ │ │ └── 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
│ └── github
│ └── chengang
│ └── tickview
│ └── ExampleUnitTest.java
├── art
└── tick_view_animation.gif
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── github
│ │ └── chengang
│ │ └── library
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── chengang
│ │ │ └── library
│ │ │ ├── DisplayUtil.java
│ │ │ ├── OnCheckedChangeListener.java
│ │ │ ├── TickAnimatorListener.java
│ │ │ ├── TickRateEnum.java
│ │ │ ├── TickView.java
│ │ │ └── TickViewConfig.java
│ └── res
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── github
│ └── chengang
│ └── library
│ └── 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/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
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 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 urchankong
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 | # TickView
2 | 一个精致的打钩小动画,模仿轻芒杂志标记已读的动画
3 |
4 |
5 | ## 效果图
6 | 
7 |
8 | ## 使用
9 |
10 | ### Step 1
11 | ``` gradle
12 | allprojects {
13 | repositories {
14 | ...
15 | maven { url 'https://www.jitpack.io' }
16 | }
17 | }
18 | ```
19 |
20 | ### Step 2
21 | ``` gradle
22 | dependencies {
23 | compile 'com.github.ChengangFeng:TickView:v1.0.2'
24 | }
25 | ```
26 |
27 | ### Step 3
28 |
29 | #### xml配置
30 | ``` xml
31 |
37 | ```
38 |
39 | #### 点击事件回调
40 | ``` java
41 | tickView.setOnCheckedChangeListener(new TickView.OnCheckedChangeListener() {
42 | @Override
43 | public void onCheckedChanged(TickView tickView, boolean isCheck) {
44 | //do something here
45 | }
46 | });
47 | ```
48 |
49 | #### 模拟点击效果
50 | ``` java
51 | tickView.toggle();
52 | ```
53 |
54 | #### 手动更改控件状态
55 | ``` java
56 | tickView.setChecked(true);
57 | ```
58 |
59 | ## 思路实现
60 | * 简书,[http://www.jianshu.com/p/673e3b3715a2](http://www.jianshu.com/p/1b2cdba03d23)
61 | * 掘金,[https://juejin.im/post/59ebe2b75188250989513b1b](https://juejin.im/post/59ebe2b75188250989513b1b)
62 |
63 | ## 优化思路
64 | * 简书,[http://www.jianshu.com/p/1ff14c0156b0](http://www.jianshu.com/p/1ff14c0156b0)
65 | * 掘金,[https://juejin.im/post/59f5609851882534af2538c0](https://juejin.im/post/59f5609851882534af2538c0)
66 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.2"
6 | defaultConfig {
7 | applicationId "com.github.chengang.tickview"
8 | minSdkVersion 19
9 | targetSdkVersion 26
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(dir: 'libs', include: ['*.jar'])
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:26.+'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
29 | testCompile 'junit:junit:4.12'
30 | // compile 'com.github.ChengangFeng:TickView:v1.0.2'
31 | compile project(path: ':library')
32 | }
33 |
--------------------------------------------------------------------------------
/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:\chengang\Android\AndroidSDK/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/github/chengang/tickview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.chengang.tickview;
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.github.chengang.tickview", 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/github/chengang/tickview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.chengang.tickview;
2 |
3 | import android.graphics.Color;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.Toast;
9 |
10 | import com.github.chengang.library.OnCheckedChangeListener;
11 | import com.github.chengang.library.TickAnimatorListener;
12 | import com.github.chengang.library.TickView;
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | private static final String TAG = MainActivity.class.getSimpleName();
17 |
18 | TickView tickView;
19 | TickView tickViewAccent;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_main);
25 | tickView = (TickView) findViewById(R.id.tick_view);
26 | tickView.getConfig().setOnCheckedChangeListener(new OnCheckedChangeListener() {
27 | @Override
28 | public void onCheckedChanged(TickView tickView, boolean isCheck) {
29 |
30 | }
31 | }).setTickAnimatorListener(new TickAnimatorListener.TickAnimatorListenerAdapter() {
32 | @Override
33 | public void onAnimationStart(TickView tickView) {
34 | super.onAnimationStart(tickView);
35 | }
36 | });
37 |
38 |
39 | tickViewAccent = (TickView) findViewById(R.id.tick_view_accent);
40 | findViewById(R.id.check_btn).setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View view) {
43 | tickView.setChecked(true);
44 | tickViewAccent.setChecked(true);
45 | }
46 | });
47 | findViewById(R.id.uncheck_btn).setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View view) {
50 | tickView.setChecked(false);
51 | tickViewAccent.setChecked(false);
52 | }
53 | });
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
25 |
26 |
32 |
33 |
34 |
35 |
41 |
42 |
48 |
49 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/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 | TickView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/github/chengang/tickview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.chengang.tickview;
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 | }
--------------------------------------------------------------------------------
/art/tick_view_animation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/art/tick_view_animation.gif
--------------------------------------------------------------------------------
/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.github.dcendents:android-maven-gradle-plugin:1.5'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | maven { url "https://jitpack.io" }
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/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/ChengangFeng/TickView/a3c496d18b7ee6727b6725ed4b8e5ce865eabd46/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Oct 26 14:17:02 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 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.ChengangFeng'
4 |
5 | android {
6 | compileSdkVersion 26
7 | buildToolsVersion "26.0.2"
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 26
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compile fileTree(dir: 'libs', include: ['*.jar'])
28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
29 | exclude group: 'com.android.support', module: 'support-annotations'
30 | })
31 | provided 'com.android.support:appcompat-v7:26.+'
32 | testCompile 'junit:junit:4.12'
33 | }
34 |
--------------------------------------------------------------------------------
/library/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:\chengang\Android\AndroidSDK/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 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/github/chengang/library/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.chengang.library;
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.github.chengang.library.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/java/com/github/chengang/library/DisplayUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.chengang.library;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by 陈岗不姓陈 on 2017/10/30.
7 | *
8 | */
9 |
10 | class DisplayUtil {
11 | static int dp2px(Context context, float dpValue) {
12 | if (context == null) return (int) (dpValue * 1.5f + 0.5f);
13 | final float scale = context.getResources().getDisplayMetrics().density;
14 | return (int) (dpValue * scale + 0.5f);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/library/src/main/java/com/github/chengang/library/OnCheckedChangeListener.java:
--------------------------------------------------------------------------------
1 | package com.github.chengang.library;
2 |
3 | /**
4 | * Created by 陈岗不姓陈 on 2017/10/30.
5 | *
6 | */
7 |
8 | public interface OnCheckedChangeListener {
9 | void onCheckedChanged(TickView tickView, boolean isCheck);
10 | }
11 |
--------------------------------------------------------------------------------
/library/src/main/java/com/github/chengang/library/TickAnimatorListener.java:
--------------------------------------------------------------------------------
1 | package com.github.chengang.library;
2 |
3 | /**
4 | * Created by 陈岗不姓陈 on 2017/10/30.
5 | *
6 | */
7 |
8 | public interface TickAnimatorListener {
9 | void onAnimationStart(TickView tickView);
10 |
11 | void onAnimationEnd(TickView tickView);
12 |
13 | abstract class TickAnimatorListenerAdapter implements TickAnimatorListener {
14 | @Override
15 | public void onAnimationStart(TickView tickView) {
16 |
17 | }
18 |
19 | @Override
20 | public void onAnimationEnd(TickView tickView) {
21 |
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/library/src/main/java/com/github/chengang/library/TickRateEnum.java:
--------------------------------------------------------------------------------
1 | package com.github.chengang.library;
2 |
3 |
4 | /**
5 | * Created by 陈岗不姓陈 on 2017/10/19.
6 | *
7 | * 动画执行速率枚举配置
8 | */
9 |
10 | enum TickRateEnum {
11 |
12 | SLOW(800, 480, 720),
13 | NORMAL(500, 300, 450),
14 | FAST(300, 180, 270);
15 |
16 | public static final int RATE_MODE_SLOW = 0;
17 | public static final int RATE_MODE_NORMAL = 1;
18 | public static final int RATE_MODE_FAST = 2;
19 |
20 | private int mRingAnimatorDuration;
21 | private int mCircleAnimatorDuration;
22 | private int mScaleAnimatorDuration;
23 |
24 | TickRateEnum(int mRingAnimatorDuration, int mCircleAnimatorDuration, int mScaleAnimatorDuration) {
25 | this.mRingAnimatorDuration = mRingAnimatorDuration;
26 | this.mCircleAnimatorDuration = mCircleAnimatorDuration;
27 | this.mScaleAnimatorDuration = mScaleAnimatorDuration;
28 | }
29 |
30 | public int getmRingAnimatorDuration() {
31 | return mRingAnimatorDuration;
32 | }
33 |
34 | public TickRateEnum setmRingAnimatorDuration(int mRingAnimatorDuration) {
35 | this.mRingAnimatorDuration = mRingAnimatorDuration;
36 | return this;
37 | }
38 |
39 | public int getmCircleAnimatorDuration() {
40 | return mCircleAnimatorDuration;
41 | }
42 |
43 | public TickRateEnum setmCircleAnimatorDuration(int mCircleAnimatorDuration) {
44 | this.mCircleAnimatorDuration = mCircleAnimatorDuration;
45 | return this;
46 | }
47 |
48 | public int getmScaleAnimatorDuration() {
49 | return mScaleAnimatorDuration;
50 | }
51 |
52 | public TickRateEnum setmScaleAnimatorDuration(int mScaleAnimatorDuration) {
53 | this.mScaleAnimatorDuration = mScaleAnimatorDuration;
54 | return this;
55 | }
56 |
57 | public static TickRateEnum getRateEnum(int rateMode) {
58 | TickRateEnum tickRateEnum;
59 | switch (rateMode) {
60 | case RATE_MODE_SLOW:
61 | tickRateEnum = TickRateEnum.SLOW;
62 | break;
63 | case RATE_MODE_NORMAL:
64 | tickRateEnum = TickRateEnum.NORMAL;
65 | break;
66 | case RATE_MODE_FAST:
67 | tickRateEnum = TickRateEnum.FAST;
68 | break;
69 | default:
70 | tickRateEnum = TickRateEnum.NORMAL;
71 | break;
72 | }
73 | return tickRateEnum;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/library/src/main/java/com/github/chengang/library/TickView.java:
--------------------------------------------------------------------------------
1 | package com.github.chengang.library;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.AnimatorSet;
6 | import android.animation.ObjectAnimator;
7 | import android.animation.ValueAnimator;
8 | import android.content.Context;
9 | import android.content.res.TypedArray;
10 | import android.graphics.Canvas;
11 | import android.graphics.Paint;
12 | import android.graphics.Path;
13 | import android.graphics.PathMeasure;
14 | import android.graphics.RectF;
15 | import android.support.annotation.Nullable;
16 | import android.util.AttributeSet;
17 | import android.util.Log;
18 | import android.view.View;
19 | import android.view.animation.DecelerateInterpolator;
20 |
21 | /**
22 | * Created by 陈岗不姓陈 on 2017/10/17.
23 | *
24 | * 自定义view -- checkbox
25 | * 一个打钩的小动画
26 | */
27 |
28 | public class TickView extends View {
29 |
30 | //内圆的画笔
31 | private Paint mPaintCircle;
32 | //外层圆环的画笔
33 | private Paint mPaintRing;
34 | //打钩的画笔
35 | private Paint mPaintTick;
36 |
37 | //整个圆外切的矩形
38 | private RectF mRectF = new RectF();
39 |
40 | //控件中心的X,Y坐标
41 | private int centerX;
42 | private int centerY;
43 |
44 | //计数器
45 | private int circleRadius = -1;
46 | private int ringProgress = 0;
47 |
48 | //是否被点亮
49 | private boolean isChecked = false;
50 | //是否处于动画中
51 | private boolean isAnimationRunning = false;
52 |
53 | //最后扩大缩小动画中,画笔的宽度的最大倍数
54 | private static final int SCALE_TIMES = 6;
55 |
56 | private AnimatorSet mFinalAnimatorSet;
57 |
58 | private int mRingAnimatorDuration;
59 | private int mCircleAnimatorDuration;
60 | private int mScaleAnimatorDuration;
61 |
62 | TickViewConfig mConfig;
63 |
64 | private Path mTickPath;
65 | private Path mTickPathMeasureDst;
66 | private PathMeasure mPathMeasure;
67 |
68 | public TickView(Context context) {
69 | this(context, null);
70 | }
71 |
72 | public TickView(Context context, @Nullable AttributeSet attrs) {
73 | this(context, attrs, 0);
74 | }
75 |
76 | public TickView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
77 | super(context, attrs, defStyleAttr);
78 | initAttrs(attrs);
79 | initPaint();
80 | initAnimatorCounter();
81 | setUpEvent();
82 | }
83 |
84 | private void initAttrs(AttributeSet attrs) {
85 | if (mConfig == null) {
86 | mConfig = new TickViewConfig(getContext());
87 | }
88 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.TickView);
89 | mConfig.setUnCheckBaseColor(typedArray.getColor(R.styleable.TickView_uncheck_base_color, getResources().getColor(R.color.tick_gray)))
90 | .setCheckBaseColor(typedArray.getColor(R.styleable.TickView_check_base_color, getResources().getColor(R.color.tick_yellow)))
91 | .setCheckTickColor(typedArray.getColor(R.styleable.TickView_check_tick_color, getResources().getColor(R.color.tick_white)))
92 | .setRadius(typedArray.getDimensionPixelOffset(R.styleable.TickView_radius, dp2px(30)))
93 | .setClickable(typedArray.getBoolean(R.styleable.TickView_clickable, true))
94 | .setTickRadius(dp2px(12))
95 | .setTickRadiusOffset(dp2px(4));
96 |
97 | int rateMode = typedArray.getInt(R.styleable.TickView_rate, 1);
98 | TickRateEnum mTickRateEnum = TickRateEnum.getRateEnum(rateMode);
99 | mRingAnimatorDuration = mTickRateEnum.getmRingAnimatorDuration();
100 | mCircleAnimatorDuration = mTickRateEnum.getmCircleAnimatorDuration();
101 | mScaleAnimatorDuration = mTickRateEnum.getmScaleAnimatorDuration();
102 | typedArray.recycle();
103 | applyConfig(mConfig);
104 | setUpEvent();
105 | if (mTickPath == null) mTickPath = new Path();
106 | if (mTickPathMeasureDst == null) mTickPathMeasureDst = new Path();
107 | if (mPathMeasure == null) mPathMeasure = new PathMeasure();
108 | }
109 |
110 | private void applyConfig(TickViewConfig config) {
111 | assert mConfig != null : "TickView Config must not be null";
112 | mConfig.setConfig(config);
113 | if (mConfig.isNeedToReApply()) {
114 | initPaint();
115 | initAnimatorCounter();
116 | mConfig.setNeedToReApply(false);
117 | }
118 | }
119 |
120 | /**
121 | * 初始化画笔
122 | */
123 | private void initPaint() {
124 | if (mPaintRing == null) mPaintRing = new Paint(Paint.ANTI_ALIAS_FLAG);
125 | mPaintRing.setStyle(Paint.Style.STROKE);
126 | mPaintRing.setColor(isChecked ? mConfig.getCheckBaseColor() : mConfig.getUnCheckBaseColor());
127 | mPaintRing.setStrokeCap(Paint.Cap.ROUND);
128 | mPaintRing.setStrokeWidth(dp2px(2.5f));
129 |
130 | if (mPaintCircle == null) mPaintCircle = new Paint(Paint.ANTI_ALIAS_FLAG);
131 | mPaintCircle.setColor(mConfig.getCheckBaseColor());
132 |
133 | if (mPaintTick == null) mPaintTick = new Paint(Paint.ANTI_ALIAS_FLAG);
134 | mPaintTick.setColor(isChecked ? mConfig.getCheckTickColor() : mConfig.getUnCheckBaseColor());
135 | mPaintTick.setStyle(Paint.Style.STROKE);
136 | mPaintTick.setStrokeCap(Paint.Cap.ROUND);
137 | mPaintTick.setStrokeWidth(dp2px(2.5f));
138 | }
139 |
140 | /**
141 | * 用ObjectAnimator初始化一些计数器
142 | */
143 | private void initAnimatorCounter() {
144 | //圆环进度
145 | ObjectAnimator mRingAnimator = ObjectAnimator.ofInt(this, "ringProgress", 0, 360);
146 | mRingAnimator.setDuration(mRingAnimatorDuration);
147 | mRingAnimator.setInterpolator(null);
148 | //收缩动画
149 | ObjectAnimator mCircleAnimator = ObjectAnimator.ofInt(this, "circleRadius", mConfig.getRadius() - 5, 0);
150 | mCircleAnimator.setInterpolator(new DecelerateInterpolator());
151 | mCircleAnimator.setDuration(mCircleAnimatorDuration);
152 | Animator mTickAnima;
153 | //勾勾alpha动画
154 | if (mConfig.getTickAnim() == TickViewConfig.ANIM_ALPHA) {
155 | //勾出来的透明渐变
156 | mTickAnima = ObjectAnimator.ofInt(this, "tickAlpha", 0, 255);
157 | mTickAnima.setDuration(200);
158 | } else {
159 | //勾勾采取动态画出
160 | mTickAnima = ValueAnimator.ofFloat(0.0f, 1.0f);
161 | mTickAnima.setDuration(400);
162 | mTickAnima.addListener(new AnimatorListenerAdapter() {
163 | @Override
164 | public void onAnimationStart(Animator animation) {
165 | super.onAnimationStart(animation);
166 | setTickProgress(0);
167 | mPathMeasure.nextContour();
168 | mPathMeasure.setPath(mTickPath, false);
169 | mTickPathMeasureDst.reset();
170 | }
171 | });
172 | ((ValueAnimator) mTickAnima).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
173 | @Override
174 | public void onAnimationUpdate(ValueAnimator animation) {
175 | setTickProgress((Float) animation.getAnimatedValue());
176 | }
177 | });
178 | mTickAnima.setInterpolator(new DecelerateInterpolator());
179 | }
180 | //最后的放大再回弹的动画,改变画笔的宽度来实现
181 | ObjectAnimator mScaleAnimator = ObjectAnimator.ofFloat(this, "ringStrokeWidth", mPaintRing.getStrokeWidth(), mPaintRing.getStrokeWidth() * SCALE_TIMES, mPaintRing.getStrokeWidth() / SCALE_TIMES);
182 | mScaleAnimator.setInterpolator(null);
183 | mScaleAnimator.setDuration(mScaleAnimatorDuration);
184 |
185 | //打钩和放大回弹的动画一起执行
186 | AnimatorSet mAlphaScaleAnimatorSet = new AnimatorSet();
187 | mAlphaScaleAnimatorSet.playTogether(mTickAnima, mScaleAnimator);
188 |
189 | mFinalAnimatorSet = new AnimatorSet();
190 | mFinalAnimatorSet.playSequentially(mRingAnimator, mCircleAnimator, mAlphaScaleAnimatorSet);
191 | mFinalAnimatorSet.addListener(new AnimatorListenerAdapter() {
192 | @Override
193 | public void onAnimationEnd(Animator animation) {
194 | super.onAnimationEnd(animation);
195 | if (mConfig.getTickAnimatorListener() != null) {
196 | mConfig.getTickAnimatorListener().onAnimationEnd(TickView.this);
197 | }
198 | }
199 |
200 | @Override
201 | public void onAnimationStart(Animator animation) {
202 | super.onAnimationStart(animation);
203 | if (mConfig.getTickAnimatorListener() != null) {
204 | mConfig.getTickAnimatorListener().onAnimationStart(TickView.this);
205 | }
206 | }
207 | });
208 | }
209 |
210 | /**
211 | * 设置点击事件
212 | */
213 | private void setUpEvent() {
214 | setOnClickListener(new OnClickListener() {
215 | @Override
216 | public void onClick(View view) {
217 | if (mConfig.isClickable()) {
218 | toggle();
219 | if (mConfig.getOnCheckedChangeListener() != null) {
220 | mConfig.getOnCheckedChangeListener().onCheckedChanged((TickView) view, isChecked);
221 | }
222 | }
223 | }
224 | });
225 | }
226 |
227 | private int getMySize(int defaultSize, int measureSpec) {
228 | int mySize = defaultSize;
229 |
230 | int mode = MeasureSpec.getMode(measureSpec);
231 | int size = MeasureSpec.getSize(measureSpec);
232 |
233 | switch (mode) {
234 | case MeasureSpec.UNSPECIFIED:
235 | case MeasureSpec.AT_MOST:
236 | mySize = defaultSize;
237 | break;
238 | case MeasureSpec.EXACTLY:
239 | mySize = size;
240 | break;
241 | default:
242 | break;
243 | }
244 | return mySize;
245 | }
246 |
247 | @Override
248 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
249 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
250 |
251 | final int radius = mConfig.getRadius();
252 | final float tickRadius = mConfig.getTickRadius();
253 | final float tickRadiusOffset = mConfig.getTickRadiusOffset();
254 |
255 | //控件的宽度等于动画最后的扩大范围的半径
256 | int width = getMySize((radius + dp2px(2.5f) * SCALE_TIMES) * 2, widthMeasureSpec);
257 | int height = getMySize((radius + dp2px(2.5f) * SCALE_TIMES) * 2, heightMeasureSpec);
258 |
259 | height = width = Math.max(width, height);
260 |
261 | setMeasuredDimension(width, height);
262 |
263 | centerX = getMeasuredWidth() / 2;
264 | centerY = getMeasuredHeight() / 2;
265 |
266 | //设置圆圈的外切矩形
267 | mRectF.set(centerX - radius, centerY - radius, centerX + radius, centerY + radius);
268 |
269 | //设置打钩的几个点坐标
270 | final float startX = centerX - tickRadius + tickRadiusOffset;
271 | final float startY = (float) centerY;
272 |
273 | final float middleX = centerX - tickRadius / 2 + tickRadiusOffset;
274 | final float middleY = centerY + tickRadius / 2;
275 |
276 | final float endX = centerX + tickRadius * 2 / 4 + tickRadiusOffset;
277 | final float endY = centerY - tickRadius * 2 / 4;
278 |
279 | mTickPath.reset();
280 | mTickPath.moveTo(startX, startY);
281 | mTickPath.lineTo(middleX, middleY);
282 | mTickPath.lineTo(endX, endY);
283 | }
284 |
285 | @Override
286 | protected void onDraw(Canvas canvas) {
287 | if (mConfig.isNeedToReApply()) {
288 | applyConfig(mConfig);
289 | }
290 | super.onDraw(canvas);
291 | if (!isChecked) {
292 | canvas.drawArc(mRectF, 90, 360, false, mPaintRing);
293 | canvas.drawPath(mTickPath, mPaintTick);
294 | return;
295 | }
296 | //画圆弧进度
297 | canvas.drawArc(mRectF, 90, ringProgress, false, mPaintRing);
298 | //画黄色的背景
299 | mPaintCircle.setColor(mConfig.getCheckBaseColor());
300 | canvas.drawCircle(centerX, centerY, ringProgress == 360 ? mConfig.getRadius() : 0, mPaintCircle);
301 | //画收缩的白色圆
302 | if (ringProgress == 360) {
303 | mPaintCircle.setColor(mConfig.getCheckTickColor());
304 | canvas.drawCircle(centerX, centerY, circleRadius, mPaintCircle);
305 | }
306 | //画勾,以及放大收缩的动画
307 | if (circleRadius == 0) {
308 | if (mConfig.getTickAnim() == TickViewConfig.ANIM_DYNAMIC) {
309 | mPaintTick.setAlpha((int) (255 * tickProgress));
310 | mPathMeasure.getSegment(0, tickProgress * mPathMeasure.getLength(), mTickPathMeasureDst, true);
311 | canvas.drawPath(mTickPathMeasureDst, mPaintTick);
312 | } else {
313 | canvas.drawPath(mTickPath, mPaintTick);
314 | }
315 | canvas.drawArc(mRectF, 0, 360, false, mPaintRing);
316 | }
317 | //ObjectAnimator动画替换计数器
318 | if (!isAnimationRunning) {
319 | isAnimationRunning = true;
320 | mFinalAnimatorSet.start();
321 | }
322 | }
323 |
324 | /*--------------属性动画---getter/setter begin---------------*/
325 |
326 | private int getRingProgress() {
327 | return ringProgress;
328 | }
329 |
330 | private void setRingProgress(int ringProgress) {
331 | this.ringProgress = ringProgress;
332 | postInvalidate();
333 | }
334 |
335 | private int getCircleRadius() {
336 | return circleRadius;
337 | }
338 |
339 | private void setCircleRadius(int circleRadius) {
340 | this.circleRadius = circleRadius;
341 | postInvalidate();
342 | }
343 |
344 | private float tickProgress = 0.0f;
345 |
346 | private float getTickProgress() {
347 | return tickProgress;
348 | }
349 |
350 | private void setTickProgress(float tickProgress) {
351 | this.tickProgress = tickProgress;
352 | Log.i("progress", "setTickProgress: " + tickProgress);
353 | invalidate();
354 | }
355 |
356 | private void setTickAlpha(int tickAlpha) {
357 | mPaintTick.setAlpha(tickAlpha);
358 | postInvalidate();
359 | }
360 |
361 | private float getRingStrokeWidth() {
362 | return mPaintRing.getStrokeWidth();
363 | }
364 |
365 | private void setRingStrokeWidth(float strokeWidth) {
366 | mPaintRing.setStrokeWidth(strokeWidth);
367 | postInvalidate();
368 | }
369 |
370 | /*--------------属性动画---getter/setter end---------------*/
371 |
372 | /**
373 | * 改变状态
374 | *
375 | * @param checked 选中还是未选中
376 | */
377 | public void setChecked(boolean checked) {
378 | if (this.isChecked != checked) {
379 | isChecked = checked;
380 | reset();
381 | }
382 | }
383 |
384 | /**
385 | * @return 当前状态是否选中
386 | */
387 | public boolean isChecked() {
388 | return isChecked;
389 | }
390 |
391 | /**
392 | * 改变当前的状态
393 | */
394 | public void toggle() {
395 | setChecked(!isChecked);
396 | }
397 |
398 | /**
399 | * 重置
400 | */
401 | private void reset() {
402 | initPaint();
403 | mFinalAnimatorSet.cancel();
404 | ringProgress = 0;
405 | circleRadius = -1;
406 | isAnimationRunning = false;
407 | final int radius = mConfig.getRadius();
408 | mRectF.set(centerX - radius, centerY - radius, centerX + radius, centerY + radius);
409 | invalidate();
410 | }
411 |
412 | public TickViewConfig getConfig() {
413 | return mConfig;
414 | }
415 |
416 | public void setConfig(TickViewConfig tickViewConfig) {
417 | if (tickViewConfig == null) return;
418 | applyConfig(tickViewConfig);
419 | }
420 |
421 | private int dp2px(float dpValue) {
422 | return DisplayUtil.dp2px(getContext(), dpValue);
423 | }
424 | }
425 |
--------------------------------------------------------------------------------
/library/src/main/java/com/github/chengang/library/TickViewConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.chengang.library;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.support.annotation.IntDef;
6 | import android.support.annotation.NonNull;
7 |
8 | import java.io.Serializable;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 |
12 | /**
13 | * Created by 陈岗不姓陈 on 2017/10/30.
14 | *
15 | * 控件配置
16 | */
17 |
18 | public class TickViewConfig implements Serializable {
19 |
20 | @Retention(RetentionPolicy.SOURCE)
21 | @IntDef({ANIM_ALPHA, ANIM_DYNAMIC})
22 | public @interface TickAnimType {
23 |
24 | }
25 |
26 | public static final int ANIM_ALPHA = 0;
27 | public static final int ANIM_DYNAMIC = 1;
28 |
29 | public int tickAnim = ANIM_ALPHA;
30 |
31 | private volatile boolean isNeedToReApply;
32 |
33 | private boolean clickable = true;
34 |
35 | private int unCheckBaseColor;
36 | private int checkBaseColor;
37 | private int checkTickColor;
38 | private int radius;
39 |
40 | //勾的半径
41 | private float tickRadius;
42 | //勾的偏移
43 | private float tickRadiusOffset;
44 |
45 | private OnCheckedChangeListener mOnCheckedChangeListener;
46 | private TickAnimatorListener mTickAnimatorListener;
47 |
48 | public TickViewConfig(Context context) {
49 | this(context, null);
50 | }
51 |
52 | public TickViewConfig(Context context, TickViewConfig config) {
53 | if (config != null) {
54 | setConfig(config);
55 | } else {
56 | setNeedToReApply(true);
57 | setupDefaultValue(context);
58 | }
59 | }
60 |
61 | private void setupDefaultValue(Context context) {
62 | this.setUnCheckBaseColor(Color.parseColor("#ffeaeaea"))
63 | .setCheckBaseColor(Color.parseColor("#fff5d747"))
64 | .setCheckTickColor(Color.WHITE)
65 | .setRadius(DisplayUtil.dp2px(context, 30))
66 | .setClickable(true)
67 | .setTickRadius(DisplayUtil.dp2px(context, 12))
68 | .setTickRadiusOffset(DisplayUtil.dp2px(context, 4))
69 | .setTickAnim(ANIM_ALPHA);
70 | }
71 |
72 | boolean isNeedToReApply() {
73 | return isNeedToReApply;
74 | }
75 |
76 | TickViewConfig setNeedToReApply(boolean needToReApply) {
77 | this.isNeedToReApply = needToReApply;
78 | return this;
79 | }
80 |
81 |
82 | public boolean isClickable() {
83 | return clickable;
84 | }
85 |
86 | public TickViewConfig setClickable(boolean clickable) {
87 | this.clickable = clickable;
88 | return this;
89 | }
90 |
91 | public int getUnCheckBaseColor() {
92 | return unCheckBaseColor;
93 | }
94 |
95 | public TickViewConfig setUnCheckBaseColor(int unCheckBaseColor) {
96 | this.unCheckBaseColor = unCheckBaseColor;
97 | return setNeedToReApply(true);
98 | }
99 |
100 | public int getCheckBaseColor() {
101 | return checkBaseColor;
102 | }
103 |
104 | public TickViewConfig setCheckBaseColor(int checkBaseColor) {
105 | this.checkBaseColor = checkBaseColor;
106 | return setNeedToReApply(true);
107 | }
108 |
109 | public int getCheckTickColor() {
110 | return checkTickColor;
111 | }
112 |
113 | public TickViewConfig setCheckTickColor(int checkTickColor) {
114 | this.checkTickColor = checkTickColor;
115 | return setNeedToReApply(true);
116 | }
117 |
118 | public int getRadius() {
119 | return radius;
120 | }
121 |
122 | public TickViewConfig setRadius(int radius) {
123 | this.radius = radius;
124 | return setNeedToReApply(true);
125 | }
126 |
127 | public float getTickRadius() {
128 | return tickRadius;
129 | }
130 |
131 | public TickViewConfig setTickRadius(float tickRadius) {
132 | this.tickRadius = tickRadius;
133 | return setNeedToReApply(true);
134 | }
135 |
136 | public float getTickRadiusOffset() {
137 | return tickRadiusOffset;
138 | }
139 |
140 | public TickViewConfig setTickRadiusOffset(float tickRadiusOffset) {
141 | this.tickRadiusOffset = tickRadiusOffset;
142 | return setNeedToReApply(true);
143 | }
144 |
145 | public OnCheckedChangeListener getOnCheckedChangeListener() {
146 | return mOnCheckedChangeListener;
147 | }
148 |
149 | public TickViewConfig setOnCheckedChangeListener(OnCheckedChangeListener onCheckedChangeListener) {
150 | mOnCheckedChangeListener = onCheckedChangeListener;
151 | return this;
152 | }
153 |
154 | public TickAnimatorListener getTickAnimatorListener() {
155 | return mTickAnimatorListener;
156 | }
157 |
158 | public TickViewConfig setTickAnimatorListener(TickAnimatorListener tickAnimatorListener) {
159 | mTickAnimatorListener = tickAnimatorListener;
160 | return this;
161 | }
162 |
163 | public int getTickAnim() {
164 | return tickAnim;
165 | }
166 |
167 | public TickViewConfig setTickAnim(@TickAnimType int tickAnim) {
168 | this.tickAnim = tickAnim;
169 | return setNeedToReApply(true);
170 | }
171 |
172 | public TickViewConfig setConfig(@NonNull TickViewConfig config) {
173 | if (config == null) return this;
174 | return setClickable(config.isClickable())
175 | .setUnCheckBaseColor(config.getUnCheckBaseColor())
176 | .setCheckBaseColor(config.getCheckBaseColor())
177 | .setCheckTickColor(config.getCheckTickColor())
178 | .setOnCheckedChangeListener(config.getOnCheckedChangeListener())
179 | .setTickAnimatorListener(config.getTickAnimatorListener())
180 | .setTickRadius(config.getTickRadius())
181 | .setTickRadiusOffset(config.getTickRadiusOffset())
182 | .setTickAnim(config.getTickAnim());
183 |
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #f5d747
4 | #eaeaea
5 | #fff
6 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/library/src/test/java/com/github/chengang/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.chengang.library;
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', ':library'
2 |
--------------------------------------------------------------------------------