├── .gitignore
├── README-zh.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── unstoppable
│ │ └── submitbutton
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── unstoppable
│ │ │ └── submitbutton
│ │ │ └── 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
│ └── unstoppable
│ └── submitbutton
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screens
├── submitbutton_failed.gif
├── submitbutton_progress.gif
└── submitbutton_succeed.gif
├── settings.gradle
└── submitbuttonview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── unstoppable
│ └── submitbuttonview
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── unstoppable
│ │ └── submitbuttonview
│ │ └── SubmitButton.java
└── res
│ └── values
│ └── attrs.xml
└── test
└── java
└── com
└── unstoppable
└── submitbuttonview
└── ExampleUnitTest.java
/.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 |
--------------------------------------------------------------------------------
/README-zh.md:
--------------------------------------------------------------------------------
1 | ## SubmitButton
2 |
3 | [](https://bintray.com/unstoppable/maven/submitbutton/1.1.3)
4 |
5 |
6 | README: [English](https://github.com/Someonewow/SubmitButton/blob/master/README.md) | [中文](https://github.com/Someonewow/SubmitButton/blob/master/README-zh.md)
7 |
8 |
9 |
10 | >带有进度动画的Android自定义提交按钮.
11 |
12 | ## 示例
13 |
14 | 
15 |
16 | 
17 |
18 | 
19 |
20 | ## 如何使用
21 |
22 | ##### 1.在要使用的Module的build.gradle文件中添加依赖;
23 |
24 | dependencies {
25 | '''
26 | compile 'com.unstoppable:submitbutton:1.1.3'
27 | }
28 |
29 | ##### 2.布局文件中添加SubmitButton;
30 |
31 |
35 |
36 | ##### 3.自定义属性
37 |
38 | | 属性名 | 类型 | 描述 |默认值 |
39 | |:--------------|:----- |:------------------|:---- |
40 | |buttonColor |color |按钮主题色 | #19CC95 |
41 | |buttonText |String |按钮文本 |null |
42 | |buttonTextSize |dimension |按钮文本大小 |15sp |
43 | |succeedColor |color |submit成功按钮主题色 | #19CC95 |
44 | |failedColor |color |submit失败按钮主题色 | #FC8E34 |
45 | |progressStyle |enum |设置进度样式(可选:loading 或 progress)|loading|
46 |
47 | ##### 4.接口方法
48 |
49 | /**
50 | * 传入submit结果以呈现不同结果反馈效果
51 | *
52 | * @param boolean isSucceed
53 | */
54 | mSubmitView.doResult(isSucceed);
55 |
56 | /**
57 | * 重置SubmitButton
58 | */
59 | mSubmitView.reset();
60 |
61 | /**
62 | * 设置进度(该方法仅在progressStyle设置为progress时有效)
63 | *
64 | * @param progress 进度值 (0-100)
65 | */
66 | mSubmitView.setProgress();
67 |
68 | /**
69 | * 设置动画结束回调接口
70 | *
71 | * @param listener
72 | */
73 | mSubmitView.setOnResultEndListener(OnResultEndListener listener)
74 |
75 | ## 更新日志
76 |
77 | #### 当前版本:1.1.3
78 |
79 | - **完成一些改进**
80 |
81 | #### 版本:1.1.2
82 |
83 | - **修复由于硬件加速导致的在某些机型上无法绘制动画的问题**
84 |
85 |
86 | #### 版本:1.1.1
87 |
88 | - **增加结果动画结束回调接口**
89 |
90 | - **修复问题**
91 |
92 | #### 版本:1.1.0
93 |
94 | - **新增进度样式设置方法**
95 |
96 | #### 版本:1.0.1
97 |
98 | - **修复问题**
99 |
100 | #### 版本:1.0.0
101 |
102 | - **初始构建**
103 |
104 | ## License
105 |
106 | Copyright 2017 Unstoppable
107 |
108 | Licensed under the Apache License, Version 2.0 (the "License");
109 | you may not use this file except in compliance with the License.
110 | You may obtain a copy of the License at
111 |
112 | http://www.apache.org/licenses/LICENSE-2.0
113 |
114 | Unless required by applicable law or agreed to in writing, software
115 | distributed under the License is distributed on an "AS IS" BASIS,
116 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
117 | See the License for the specific language governing permissions and
118 | limitations under the License.
119 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## SubmitButton
2 |
3 | [](https://bintray.com/unstoppable/maven/submitbutton/1.1.3)
4 |
5 |
6 | README: [English](https://github.com/Someonewow/SubmitButton/blob/master/README.md) | [中文](https://github.com/Someonewow/SubmitButton/blob/master/README-zh.md)
7 |
8 |
9 | >It's a submit button with a fun animation for Android.
10 |
11 | ## Demo
12 |
13 | 
14 |
15 | 
16 |
17 | 
18 |
19 | ## Getting Started
20 |
21 | ##### 1.Specify SubmitButton as a dependency in your build.gradle file;
22 |
23 | dependencies {
24 | '''
25 | compile 'com.unstoppable:submitbutton:1.1.3'
26 | }
27 |
28 | ##### 2.Add SubmitButton to the layout file;
29 |
30 |
34 |
35 | ##### 3.Attribute
36 |
37 | | name | format | description |default |
38 | |:--------------|:----- |:------------------------------------------------------|:--------|
39 | |buttonColor |color |set the button theme color |#19CC95 |
40 | |buttonText |String |set the button text |null |
41 | |buttonTextSize |dimension |set the button text size |15sp |
42 | |succeedColor |color |set the button color after the submission is successful|#19CC95 |
43 | |failedColor |color |set the button color after the submission fails |#FC8E34 |
44 | |progressStyle |enum |set the button progress style (Optional:loading or progress) |loading|
45 |
46 | ##### 4.Method
47 |
48 | /**
49 | * Pass the results to show different feedback results
50 | *
51 | * @param boolean isSucceed
52 | */
53 | mSubmitView.doResult(boolean isSucceed);
54 |
55 | /**
56 | * Reset SubmitButton
57 | */
58 | mSubmitView.reset();
59 |
60 | /**
61 | * set progress(This method is valid only if progressStyle is set to progress)
62 | *
63 | * @param progress (0-100)
64 | */
65 | mSubmitView.setProgress();
66 |
67 | /**
68 | * set the animation end callback interface
69 | *
70 | * @param listener
71 | */
72 | mSubmitView.setOnResultEndListener(OnResultEndListener listener)
73 |
74 | ## Changelog
75 |
76 | #### Current Version:1.1.3
77 |
78 | - **Made some improvements.**
79 |
80 | #### Version:1.1.2
81 |
82 | - **Fix bugs that can not be displayed on some phones because of HardwareAccelerated.**
83 |
84 | #### Version:1.1.1
85 |
86 | - **Add animation end callback interface.**
87 |
88 | - **Bug fixes.**
89 |
90 | #### Version:1.1.0
91 |
92 | - **Add progress style setting mothod.**
93 |
94 | #### Version:1.0.1
95 |
96 | - **Bug fixes.**
97 |
98 | #### Version:1.0.0
99 |
100 | - **Initial Build.**
101 |
102 | ## License
103 |
104 | Copyright 2017 Unstoppable
105 |
106 | Licensed under the Apache License, Version 2.0 (the "License");
107 | you may not use this file except in compliance with the License.
108 | You may obtain a copy of the License at
109 |
110 | http://www.apache.org/licenses/LICENSE-2.0
111 |
112 | Unless required by applicable law or agreed to in writing, software
113 | distributed under the License is distributed on an "AS IS" BASIS,
114 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
115 | See the License for the specific language governing permissions and
116 | limitations under the License.
117 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/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.unstoppable.submitbutton"
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 project(':submitbuttonview')
28 | compile 'com.android.support:appcompat-v7:25.3.1'
29 | compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
30 | testCompile 'junit:junit:4.12'
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:\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/unstoppable/submitbutton/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.unstoppable.submitbutton;
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.unstoppable.submitbutton", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/unstoppable/submitbutton/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.unstoppable.submitbutton;
2 |
3 | import android.os.AsyncTask;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.view.accessibility.AccessibilityManager;
8 | import android.widget.Button;
9 | import android.widget.CompoundButton;
10 | import android.widget.LinearLayout;
11 | import android.widget.Switch;
12 | import android.widget.Toast;
13 |
14 | import com.unstoppable.submitbuttonview.SubmitButton;
15 |
16 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
17 |
18 | private SubmitButton sBtnLoading, sBtnProgress;
19 | private Button btnSucceed, btnFailed, btnReset;
20 | private Switch mSwitch;
21 | private MyTask task;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 |
28 | sBtnLoading = (SubmitButton) findViewById(R.id.sbtn_loading);
29 | sBtnProgress = (SubmitButton) findViewById(R.id.sbtn_progress);
30 | mSwitch = (Switch) findViewById(R.id.switch1);
31 |
32 | btnFailed = (Button) findViewById(R.id.btn_failed);
33 | btnSucceed = (Button) findViewById(R.id.btn_succeed);
34 | btnReset = (Button) findViewById(R.id.btn_reset);
35 |
36 | sBtnLoading.setOnClickListener(this);
37 | sBtnProgress.setOnClickListener(this);
38 | btnSucceed.setOnClickListener(this);
39 | btnFailed.setOnClickListener(this);
40 | btnReset.setOnClickListener(this);
41 |
42 |
43 | sBtnLoading.setOnResultEndListener(new SubmitButton.OnResultEndListener() {
44 | @Override
45 | public void onResultEnd() {
46 | Toast.makeText(MainActivity.this, "ResultEnd", Toast.LENGTH_SHORT).show();
47 | }
48 | });
49 |
50 | mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
51 | @Override
52 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
53 | if (isChecked) {
54 | sBtnLoading.setVisibility(View.GONE);
55 | sBtnProgress.setVisibility(View.VISIBLE);
56 | sBtnLoading.reset();
57 | } else {
58 | sBtnLoading.setVisibility(View.VISIBLE);
59 | sBtnProgress.setVisibility(View.GONE);
60 | if (task != null && !task.isCancelled()) {
61 | task.cancel(true);
62 | sBtnProgress.reset();
63 | }
64 | }
65 | }
66 | });
67 | }
68 |
69 | @Override
70 | public void onClick(View v) {
71 | switch (v.getId()) {
72 | case R.id.sbtn_loading:
73 | Toast.makeText(this, "SubmitButton be clicked", Toast.LENGTH_SHORT).show();
74 | break;
75 | case R.id.sbtn_progress:
76 | if (task == null || task.isCancelled()) {
77 | task = new MyTask();
78 | task.execute();
79 | }
80 | break;
81 | case R.id.btn_succeed:
82 | if (mSwitch.isChecked()) {
83 | sBtnProgress.doResult(true);
84 | } else {
85 | sBtnLoading.doResult(true);
86 | }
87 | break;
88 | case R.id.btn_failed:
89 | if (mSwitch.isChecked()) {
90 | sBtnProgress.doResult(false);
91 | } else {
92 | sBtnLoading.doResult(false);
93 | }
94 | break;
95 | case R.id.btn_reset:
96 | if (mSwitch.isChecked()) {
97 | if (task != null && !task.isCancelled()) {
98 | task.cancel(true);
99 | sBtnProgress.reset();
100 | }
101 | } else {
102 | sBtnLoading.reset();
103 | }
104 | break;
105 | }
106 | }
107 |
108 | private class MyTask extends AsyncTask {
109 |
110 | @Override
111 | protected Boolean doInBackground(Void... params) {
112 | int i = 0;
113 | while (i <= 100) {
114 | if (isCancelled()) {
115 | return null;
116 | }
117 | try {
118 | Thread.sleep(30);
119 | } catch (InterruptedException e) {
120 | e.printStackTrace();
121 | }
122 | i++;
123 | publishProgress(i);
124 | }
125 | return true;
126 | }
127 |
128 | @Override
129 | protected void onPostExecute(Boolean aBoolean) {
130 | if (aBoolean == null) {
131 | sBtnProgress.reset();
132 | }
133 | sBtnProgress.doResult(aBoolean);
134 | }
135 |
136 | @Override
137 | protected void onProgressUpdate(Integer... values) {
138 | sBtnProgress.setProgress(values[0]);
139 | }
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
26 |
27 |
34 |
35 |
36 |
44 |
45 |
53 |
54 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/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 | SubmitButton
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/unstoppable/submitbutton/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.unstoppable.submitbutton;
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.2'
9 | classpath 'com.novoda:bintray-release:0.4.0'
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 | tasks.withType(Javadoc) {
20 | options{
21 | encoding "UTF-8"
22 | charSet 'UTF-8'
23 | links "http://docs.oracle.com/javase/7/docs/api"
24 | }
25 | }
26 | }
27 |
28 | task clean(type: Delete) {
29 | delete rootProject.buildDir
30 | }
31 |
--------------------------------------------------------------------------------
/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/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Apr 18 09:09:14 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 |
--------------------------------------------------------------------------------
/screens/submitbutton_failed.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/screens/submitbutton_failed.gif
--------------------------------------------------------------------------------
/screens/submitbutton_progress.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/screens/submitbutton_progress.gif
--------------------------------------------------------------------------------
/screens/submitbutton_succeed.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Someonewow/SubmitButton/e1a8fa79364af26297b1c0c8f088bf81372d63a7/screens/submitbutton_succeed.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':submitbuttonview'
2 |
--------------------------------------------------------------------------------
/submitbuttonview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/submitbuttonview/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 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | lintOptions {
26 | abortOnError false
27 | }
28 | }
29 |
30 | dependencies {
31 | compile fileTree(dir: 'libs', include: ['*.jar'])
32 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
33 | exclude group: 'com.android.support', module: 'support-annotations'
34 | })
35 | compile 'com.android.support:appcompat-v7:25.3.1'
36 | testCompile 'junit:junit:4.12'
37 | }
38 |
39 | publish {
40 | userOrg = 'unstoppable'
41 | groupId = 'com.unstoppable'
42 | artifactId = 'submitbutton'
43 | publishVersion = '1.1.3'
44 | desc = 'It\'s a submit button with a fun animation for Android.'
45 | website = 'https://github.com/Someonewow/SubmitButton'
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/submitbuttonview/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:\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 |
--------------------------------------------------------------------------------
/submitbuttonview/src/androidTest/java/com/unstoppable/submitbuttonview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.unstoppable.submitbuttonview;
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.unstoppable.submitbuttonview.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/submitbuttonview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/submitbuttonview/src/main/java/com/unstoppable/submitbuttonview/SubmitButton.java:
--------------------------------------------------------------------------------
1 | package com.unstoppable.submitbuttonview;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Paint;
10 | import android.graphics.Path;
11 | import android.graphics.PathMeasure;
12 | import android.graphics.Rect;
13 | import android.graphics.RectF;
14 | import android.support.v4.content.ContextCompat;
15 | import android.util.AttributeSet;
16 | import android.util.Log;
17 | import android.view.MotionEvent;
18 | import android.view.View;
19 | import android.view.animation.AccelerateInterpolator;
20 |
21 | /**
22 | * Created by Unstoppable on 2016/12/31.
23 | */
24 |
25 | public class SubmitButton extends View {
26 |
27 | private static final int STATE_NONE = 0;
28 | private static final int STATE_SUBMIT = 1;
29 | private static final int STATE_LOADING = 2;
30 | private static final int STATE_RESULT = 3;
31 |
32 | //view状态
33 | private int viewState = STATE_NONE;
34 |
35 | //View宽高
36 | private int mWidth;
37 | private int mHeight;
38 |
39 | private int MAX_WIDTH;
40 | private int MAX_HEIGHT;
41 |
42 | //画布坐标原点
43 | private int x, y;
44 |
45 | private String buttonText = "";
46 | private int buttonColor;
47 | private int succeedColor;
48 | private int failedColor;
49 | private int textSize;
50 |
51 | //文本宽高
52 | private int textWidth;
53 | private int textHeight;
54 |
55 | private Paint bgPaint, loadingPaint, resultPaint, textPaint;
56 |
57 | private Path buttonPath;
58 | private Path loadPath;
59 | private Path dst;
60 | private PathMeasure pathMeasure;
61 | private Path resultPath;
62 |
63 | private RectF circleLeft, circleMid, circleRight;
64 |
65 | private float loadValue;
66 |
67 | private ValueAnimator submitAnim, loadingAnim, resultAnim;
68 |
69 | private boolean isDoResult;
70 | private boolean isSucceed;
71 |
72 | private static final int STYLE_LOADING = 0;
73 | private static final int STYLE_PROGRESS = 1;
74 |
75 | //view加载等待模式
76 | private int progressStyle = STYLE_LOADING;
77 | private float currentProgress;
78 |
79 | private OnResultEndListener listener;
80 |
81 | public SubmitButton(Context context) {
82 | this(context, null);
83 | }
84 |
85 | public SubmitButton(Context context, AttributeSet attrs) {
86 | this(context, attrs, 0);
87 | }
88 |
89 | public SubmitButton(Context context, AttributeSet attrs, int defStyleAttr) {
90 | super(context, attrs, defStyleAttr);
91 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SubmitButton, defStyleAttr, 0);
92 | if (typedArray.getString(R.styleable.SubmitButton_buttonText) != null) {
93 | buttonText = typedArray.getString(R.styleable.SubmitButton_buttonText);
94 | }
95 | buttonColor = typedArray.getColor(R.styleable.SubmitButton_buttonColor, Color.parseColor("#19CC95"));
96 | succeedColor = typedArray.getColor(R.styleable.SubmitButton_succeedColor, Color.parseColor("#19CC95"));
97 | failedColor = typedArray.getColor(R.styleable.SubmitButton_failedColor, Color.parseColor("#FC8E34"));
98 | textSize = (int) typedArray.getDimension(R.styleable.SubmitButton_buttonTextSize, sp2px(15));
99 | progressStyle = typedArray.getInt(R.styleable.SubmitButton_progressStyle, STYLE_LOADING);
100 | typedArray.recycle();
101 | //关闭硬件加速
102 | this.setLayerType(LAYER_TYPE_SOFTWARE, null);
103 | init();
104 | }
105 |
106 | /**
107 | * 初始化Paint、Path
108 | */
109 | private void init() {
110 | bgPaint = new Paint();
111 | bgPaint.setColor(buttonColor);
112 | bgPaint.setStyle(Paint.Style.STROKE);
113 | bgPaint.setStrokeWidth(5);
114 | bgPaint.setAntiAlias(true);
115 |
116 | loadingPaint = new Paint();
117 | loadingPaint.setColor(buttonColor);
118 | loadingPaint.setStyle(Paint.Style.STROKE);
119 | loadingPaint.setStrokeWidth(9);
120 | loadingPaint.setAntiAlias(true);
121 |
122 | resultPaint = new Paint();
123 | resultPaint.setColor(Color.WHITE);
124 | resultPaint.setStyle(Paint.Style.STROKE);
125 | resultPaint.setStrokeWidth(9);
126 | resultPaint.setStrokeCap(Paint.Cap.ROUND);
127 | resultPaint.setAntiAlias(true);
128 |
129 | textPaint = new Paint();
130 | textPaint.setColor(buttonColor);
131 | textPaint.setStrokeWidth(textSize / 6);
132 | textPaint.setTextSize(textSize);
133 | textPaint.setAntiAlias(true);
134 |
135 | textWidth = getTextWidth(textPaint, buttonText);
136 | textHeight = getTextHeight(textPaint, buttonText);
137 |
138 | buttonPath = new Path();
139 | loadPath = new Path();
140 | resultPath = new Path();
141 | dst = new Path();
142 | circleMid = new RectF();
143 | circleLeft = new RectF();
144 | circleRight = new RectF();
145 | pathMeasure = new PathMeasure();
146 | }
147 |
148 |
149 | @Override
150 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
151 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
152 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
153 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
154 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
155 |
156 | if (widthMode == MeasureSpec.AT_MOST) {
157 | widthSize = textWidth + 100;
158 | }
159 |
160 | if (heightMode == MeasureSpec.AT_MOST) {
161 | heightSize = (int) (textHeight * 2.5);
162 | }
163 |
164 | if (heightSize > widthSize) {
165 | heightSize = (int) (widthSize * 0.25);
166 | }
167 |
168 | mWidth = widthSize - 10;
169 | mHeight = heightSize - 10;
170 | x = (int) (widthSize * 0.5);
171 | y = (int) (heightSize * 0.5);
172 | MAX_WIDTH = mWidth;
173 | MAX_HEIGHT = mHeight;
174 |
175 | setMeasuredDimension(widthSize, heightSize);
176 | }
177 |
178 | @Override
179 | protected void onDraw(Canvas canvas) {
180 | super.onDraw(canvas);
181 | canvas.translate(x, y);
182 | drawButton(canvas);
183 | if (viewState == STATE_NONE || viewState == STATE_SUBMIT && mWidth > textWidth) {
184 | drawButtonText(canvas);
185 | }
186 | if (viewState == STATE_LOADING) {
187 | drawLoading(canvas);
188 | }
189 | if (viewState == STATE_RESULT) {
190 | drawResult(canvas, isSucceed);
191 | }
192 | }
193 |
194 | /**
195 | * 绘制初始状态Button
196 | *
197 | * @param canvas 画布
198 | */
199 | private void drawButton(Canvas canvas) {
200 | buttonPath.reset();
201 | circleLeft.set(-mWidth / 2, -mHeight / 2, -mWidth / 2 + mHeight, mHeight / 2);
202 | buttonPath.arcTo(circleLeft, 90, 180);
203 | buttonPath.lineTo(mWidth / 2 - mHeight / 2, -mHeight / 2);
204 | circleRight.set(mWidth / 2 - mHeight, -mHeight / 2, mWidth / 2, mHeight / 2);
205 | buttonPath.arcTo(circleRight, 270, 180);
206 | buttonPath.lineTo(-mWidth / 2 + mHeight / 2, mHeight / 2);
207 | canvas.drawPath(buttonPath, bgPaint);
208 | }
209 |
210 | /**
211 | * 绘制加载状态Button
212 | *
213 | * @param canvas 画布
214 | */
215 | private void drawLoading(Canvas canvas) {
216 | dst.reset();
217 | circleMid.set(-MAX_HEIGHT / 2, -MAX_HEIGHT / 2, MAX_HEIGHT / 2, MAX_HEIGHT / 2);
218 | loadPath.addArc(circleMid, 270, 359.999f);
219 | pathMeasure.setPath(loadPath, true);
220 | float startD = 0f, stopD;
221 | if (progressStyle == STYLE_LOADING) {
222 | startD = pathMeasure.getLength() * loadValue;
223 | stopD = startD + pathMeasure.getLength() / 2 * loadValue;
224 | } else {
225 | stopD = pathMeasure.getLength() * currentProgress;
226 | }
227 | pathMeasure.getSegment(startD, stopD, dst, true);
228 | canvas.drawPath(dst, loadingPaint);
229 | }
230 |
231 | /**
232 | * 绘制结果状态Button
233 | *
234 | * @param canvas 画布
235 | */
236 | private void drawResult(Canvas canvas, boolean isSucceed) {
237 | if (isSucceed) {
238 | resultPath.moveTo(-mHeight / 6, 0);
239 | resultPath.lineTo(0, (float) (-mHeight / 6 + (1 + Math.sqrt(5)) * mHeight / 12));
240 | resultPath.lineTo(mHeight / 6, -mHeight / 6);
241 | } else {
242 | resultPath.moveTo(-mHeight / 6, mHeight / 6);
243 | resultPath.lineTo(mHeight / 6, -mHeight / 6);
244 | resultPath.moveTo(-mHeight / 6, -mHeight / 6);
245 | resultPath.lineTo(mHeight / 6, mHeight / 6);
246 | }
247 | canvas.drawPath(resultPath, resultPaint);
248 | }
249 |
250 | /**
251 | * 绘制Button文本
252 | *
253 | * @param canvas 画布
254 | */
255 | private void drawButtonText(Canvas canvas) {
256 | textPaint.setAlpha(((mWidth - textWidth) * 255) / (MAX_WIDTH - textWidth));
257 | canvas.drawText(buttonText, -textWidth / 2, getTextBaseLineOffset(), textPaint);
258 | }
259 |
260 | /**
261 | * 开始提交动画
262 | */
263 | private void startSubmitAnim() {
264 | viewState = STATE_SUBMIT;
265 | submitAnim = new ValueAnimator().ofInt(MAX_WIDTH, MAX_HEIGHT);
266 | submitAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
267 | @Override
268 | public void onAnimationUpdate(ValueAnimator animation) {
269 | mWidth = (int) animation.getAnimatedValue();
270 | if (mWidth == mHeight) {
271 | bgPaint.setColor(Color.parseColor("#DDDDDD"));
272 | }
273 | invalidate();
274 | }
275 | });
276 | submitAnim.setDuration(300);
277 | submitAnim.setInterpolator(new AccelerateInterpolator());
278 | submitAnim.start();
279 | submitAnim.addListener(new Animator.AnimatorListener() {
280 | @Override
281 | public void onAnimationStart(Animator animation) {
282 |
283 | }
284 |
285 | @Override
286 | public void onAnimationEnd(Animator animation) {
287 | if (isDoResult) {
288 | startResultAnim();
289 | } else {
290 | startLoadingAnim();
291 | }
292 | }
293 |
294 | @Override
295 | public void onAnimationCancel(Animator animation) {
296 |
297 | }
298 |
299 | @Override
300 | public void onAnimationRepeat(Animator animation) {
301 |
302 | }
303 | });
304 | }
305 |
306 | /**
307 | * 开始加载动画
308 | */
309 | private void startLoadingAnim() {
310 | viewState = STATE_LOADING;
311 | if (progressStyle == STYLE_PROGRESS) {
312 | return;
313 | }
314 | loadingAnim = new ValueAnimator().ofFloat(0.0f, 1.0f);
315 | loadingAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
316 | @Override
317 | public void onAnimationUpdate(ValueAnimator animation) {
318 | loadValue = (float) animation.getAnimatedValue();
319 | invalidate();
320 | }
321 | });
322 | loadingAnim.setDuration(2000);
323 | loadingAnim.setRepeatCount(ValueAnimator.INFINITE);
324 | loadingAnim.start();
325 | }
326 |
327 | /**
328 | * 开始结果动画
329 | */
330 | private void startResultAnim() {
331 | viewState = STATE_RESULT;
332 | if (loadingAnim != null) {
333 | loadingAnim.cancel();
334 | }
335 | resultAnim = new ValueAnimator().ofInt(MAX_HEIGHT, MAX_WIDTH);
336 | resultAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
337 | @Override
338 | public void onAnimationUpdate(ValueAnimator animation) {
339 | mWidth = (int) animation.getAnimatedValue();
340 | resultPaint.setAlpha(((mWidth - mHeight) * 255) / (MAX_WIDTH - MAX_HEIGHT));
341 | if (mWidth == mHeight) {
342 | if (isSucceed) {
343 | bgPaint.setColor(succeedColor);
344 | } else {
345 | bgPaint.setColor(failedColor);
346 | }
347 | bgPaint.setStyle(Paint.Style.FILL_AND_STROKE);
348 | }
349 | invalidate();
350 | }
351 | });
352 | resultAnim.addListener(new Animator.AnimatorListener() {
353 | @Override
354 | public void onAnimationStart(Animator animation) {
355 |
356 | }
357 |
358 | @Override
359 | public void onAnimationEnd(Animator animation) {
360 | if (listener == null) {
361 | return;
362 | }
363 | postDelayed(new Runnable() {
364 | @Override
365 | public void run() {
366 | listener.onResultEnd();
367 | }
368 | }, 500);
369 | }
370 |
371 | @Override
372 | public void onAnimationCancel(Animator animation) {
373 |
374 | }
375 |
376 | @Override
377 | public void onAnimationRepeat(Animator animation) {
378 |
379 | }
380 | });
381 | resultAnim.setDuration(300);
382 | resultAnim.setInterpolator(new AccelerateInterpolator());
383 | resultAnim.start();
384 | }
385 |
386 | @Override
387 | public boolean onTouchEvent(MotionEvent event) {
388 | switch (event.getAction()) {
389 | case MotionEvent.ACTION_UP:
390 | if (viewState == STATE_NONE) {
391 | startSubmitAnim();
392 | } else {
393 | return true;
394 | }
395 | }
396 | return super.onTouchEvent(event);
397 | }
398 |
399 |
400 | @Override
401 | protected void onDetachedFromWindow() {
402 | super.onDetachedFromWindow();
403 | if (submitAnim != null) {
404 | submitAnim.cancel();
405 | }
406 | if (loadingAnim != null) {
407 | loadingAnim.cancel();
408 | }
409 | if (resultAnim != null) {
410 | resultAnim.cancel();
411 | }
412 | }
413 |
414 | /**
415 | * 设置submit结果
416 | *
417 | * @param isSucceed 是否成功
418 | */
419 | public void doResult(boolean isSucceed) {
420 | if (viewState == STATE_NONE || viewState == STATE_RESULT || isDoResult) {
421 | return;
422 | }
423 | isDoResult = true;
424 | this.isSucceed = isSucceed;
425 | if (viewState == STATE_LOADING) {
426 | startResultAnim();
427 | }
428 | }
429 |
430 | /**
431 | * 恢复初始化Button状态
432 | */
433 | public void reset() {
434 | if (submitAnim != null) {
435 | submitAnim.cancel();
436 | }
437 | if (loadingAnim != null) {
438 | loadingAnim.cancel();
439 | }
440 | if (resultAnim != null) {
441 | resultAnim.cancel();
442 | }
443 | viewState = STATE_NONE;
444 | mWidth = MAX_WIDTH;
445 | mHeight = MAX_HEIGHT;
446 | isSucceed = false;
447 | isDoResult = false;
448 | currentProgress = 0;
449 | init();
450 | invalidate();
451 | }
452 |
453 | /**
454 | * 设置进度
455 | *
456 | * @param progress 进度值 (0-100)
457 | */
458 | public void setProgress(int progress) {
459 | if (progress < 0 || progress > 100) {
460 | return;
461 | }
462 | currentProgress = (float) (progress * 0.01);
463 | if (progressStyle == STYLE_PROGRESS && viewState == STATE_LOADING) {
464 | invalidate();
465 | }
466 | }
467 |
468 |
469 | /**
470 | * 设置动画结束回调接口
471 | *
472 | * @param listener
473 | */
474 | public void setOnResultEndListener(OnResultEndListener listener) {
475 | this.listener = listener;
476 | }
477 |
478 | /**
479 | * 结果动画结束回调接口
480 | */
481 | public interface OnResultEndListener {
482 | void onResultEnd();
483 | }
484 |
485 | /**
486 | * sp to dp
487 | *
488 | * @param sp
489 | * @return dp
490 | */
491 | private int sp2px(float sp) {
492 | final float fontScale = getContext().getResources().getDisplayMetrics().scaledDensity;
493 | return (int) (sp * fontScale + 0.5f);
494 | }
495 |
496 | /**
497 | * 计算水平居中的baseline
498 | *
499 | * @return
500 | */
501 | private float getTextBaseLineOffset() {
502 | Paint.FontMetrics fm = textPaint.getFontMetrics();
503 | return -(fm.bottom + fm.top) / 2;
504 | }
505 |
506 | /**
507 | * 获取Text高度
508 | *
509 | * @param paint
510 | * @param str 文本内容
511 | * @return
512 | */
513 | private int getTextHeight(Paint paint, String str) {
514 | Rect rect = new Rect();
515 | paint.getTextBounds(str, 0, str.length(), rect);
516 | return rect.height();
517 | }
518 |
519 | /**
520 | * 获取Text宽度
521 | *
522 | * @param paint
523 | * @param str 文本内容
524 | * @return
525 | */
526 | private int getTextWidth(Paint paint, String str) {
527 | int mRet = 0;
528 | if (str != null && str.length() > 0) {
529 | int len = str.length();
530 | float[] widths = new float[len];
531 | paint.getTextWidths(str, widths);
532 | for (int j = 0; j < len; j++) {
533 | mRet += (int) Math.ceil(widths[j]);
534 | }
535 | }
536 | return mRet;
537 | }
538 | }
--------------------------------------------------------------------------------
/submitbuttonview/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/submitbuttonview/src/test/java/com/unstoppable/submitbuttonview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.unstoppable.submitbuttonview;
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 | }
--------------------------------------------------------------------------------