├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── moe
│ │ └── codeest
│ │ └── enviewsdemo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── moe
│ │ │ └── codeest
│ │ │ └── enviewsdemo
│ │ │ ├── DownloadActivity.java
│ │ │ ├── LoadingActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── PlayActivity.java
│ │ │ ├── RefreshActivity.java
│ │ │ ├── ScrollActivity.java
│ │ │ ├── SearchActivity.java
│ │ │ └── VolumeActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_download.xml
│ │ ├── activity_loading.xml
│ │ ├── activity_main.xml
│ │ ├── activity_play.xml
│ │ ├── activity_refresh.xml
│ │ ├── activity_scroll.xml
│ │ ├── activity_search.xml
│ │ └── activity_volume.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── moe
│ └── codeest
│ └── enviewsdemo
│ └── ExampleUnitTest.java
├── 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
│ │ └── moe
│ │ └── codeest
│ │ └── enviews
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── moe
│ │ │ └── codeest
│ │ │ └── enviews
│ │ │ ├── ENDownloadView.java
│ │ │ ├── ENLoadingView.java
│ │ │ ├── ENPlayView.java
│ │ │ ├── ENRefreshView.java
│ │ │ ├── ENScrollView.java
│ │ │ ├── ENSearchView.java
│ │ │ └── ENVolumeView.java
│ └── res
│ │ └── values
│ │ ├── attrs.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── moe
│ └── codeest
│ └── enviews
│ └── ExampleUnitTest.java
├── preview
├── download.gif
├── loading.gif
├── o_download.gif
├── o_loading.gif
├── o_play.gif
├── o_refresh.gif
├── o_scroll.gif
├── o_search.gif
├── o_volume.gif
├── play.gif
├── refresh.gif
├── scroll.gif
├── search.gif
└── volume.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ENViews
2 |
3 | [](https://android-arsenal.com/details/1/4749)
4 | [](https://jitpack.io/#codeestX/ENViews)
5 |
6 | ENViews, A cool dynamic view library.All designed by [Nick Buturishvili](https://dribbble.com/nick_buturishvili
7 | )
8 | ENViews, 一个华丽丽的动效控件库,所有控件原型取自[Nick Buturishvili](https://dribbble.com/nick_buturishvili
9 | )的设计作品
10 |
11 | # Preview
12 |
13 | | Original design | Android demo | Class |
14 | | :--: | :--: | :--: |
15 | |  |  |ENDownloadView|
16 | |  | |ENVolumeView|
17 | |  |  | ENLoadingView |
18 | | |  | ENPlayView |
19 | | |  |ENSearchView
20 | | |  |ENScrollView
21 | | |  |ENRefreshView|
22 |
23 | # Usage
24 |
25 | Step 1. Add the JitPack repository to your build file
26 |
27 | allprojects {
28 | repositories {
29 | ...
30 | maven { url "https://jitpack.io" }
31 | }
32 | }
33 |
34 | Step 2. Add the dependency
35 |
36 | dependencies {
37 | compile 'com.github.codeestX:ENViews:v1.0.3'
38 | }
39 |
40 | Step 3. See DemoProject for details.
41 |
42 |
43 | # Thanks
44 | * [Nick Buturishvili](https://dribbble.com/nick_buturishvili)
45 |
46 | * [GcsSloop](http://www.gcssloop.com/customview/CustomViewIndex)
47 |
48 | # License
49 |
50 | Copyright (c) 2016 codeestX
51 |
52 | Licensed under the Apache License, Version 2.0 (the "License");
53 | you may not use this file except in compliance with the License.
54 | You may obtain a copy of the License at
55 |
56 | http://www.apache.org/licenses/LICENSE-2.0
57 |
58 | Unless required by applicable law or agreed to in writing, software
59 | distributed under the License is distributed on an "AS IS" BASIS,
60 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
61 | See the License for the specific language governing permissions and
62 | limitations under the License.
63 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion '25.0.0'
6 | defaultConfig {
7 | applicationId "moe.codeest.enviewsdemo"
8 | minSdkVersion 21
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:24.1.1'
28 | testCompile 'junit:junit:4.12'
29 | compile project(':library')
30 | }
31 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/chenyulong/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/moe/codeest/enviewsdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviewsdemo;
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("moe.codeest.enviewsdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/codeest/enviewsdemo/DownloadActivity.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviewsdemo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import moe.codeest.enviews.ENDownloadView;
9 |
10 | /**
11 | * Created by codeest on 16/11/11.
12 | */
13 |
14 | public class DownloadActivity extends Activity {
15 |
16 | private ENDownloadView downloadView;
17 |
18 | private Button btnStart;
19 | private Button btnReset;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_download);
25 |
26 | downloadView = (ENDownloadView) findViewById(R.id.view_download);
27 | btnStart = (Button) findViewById(R.id.btn_start);
28 | btnReset = (Button) findViewById(R.id.btn_reset);
29 |
30 | downloadView.setDownloadConfig(2000, 20 , ENDownloadView.DownloadUnit.MB);
31 |
32 | btnStart.setOnClickListener(new View.OnClickListener() {
33 | @Override
34 | public void onClick(View view) {
35 | downloadView.start();
36 | }
37 | });
38 |
39 | btnReset.setOnClickListener(new View.OnClickListener() {
40 | @Override
41 | public void onClick(View view) {
42 | downloadView.reset();
43 | }
44 | });
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/codeest/enviewsdemo/LoadingActivity.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviewsdemo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import moe.codeest.enviews.ENLoadingView;
9 |
10 | /**
11 | * Created by codeest on 16/11/15.
12 | */
13 |
14 | public class LoadingActivity extends Activity{
15 |
16 | ENLoadingView loadingView;
17 | Button btnShow;
18 | Button btnHide;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_loading);
24 | loadingView = (ENLoadingView) findViewById(R.id.view_loading);
25 | btnShow = (Button) findViewById(R.id.btn_show);
26 | btnHide = (Button) findViewById(R.id.btn_hide);
27 | btnShow.setOnClickListener(new View.OnClickListener() {
28 | @Override
29 | public void onClick(View view) {
30 | loadingView.show();
31 | }
32 | });
33 | btnHide.setOnClickListener(new View.OnClickListener() {
34 | @Override
35 | public void onClick(View view) {
36 | loadingView.hide();
37 | }
38 | });
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/codeest/enviewsdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviewsdemo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | public class MainActivity extends AppCompatActivity implements View.OnClickListener{
10 |
11 | Button btnRefresh;
12 | Button btnPlay;
13 | Button btnDownload;
14 | Button btnScroll;
15 | Button btnVolume;
16 | Button btnSearch;
17 | Button btnLoading;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 |
24 | btnRefresh = (Button) findViewById(R.id.btn_refresh);
25 | btnPlay = (Button) findViewById(R.id.btn_play);
26 | btnDownload = (Button) findViewById(R.id.btn_download);
27 | btnScroll = (Button) findViewById(R.id.btn_scroll);
28 | btnVolume = (Button) findViewById(R.id.btn_volume);
29 | btnSearch = (Button) findViewById(R.id.btn_search);
30 | btnLoading = (Button) findViewById(R.id.btn_loading);
31 | btnRefresh.setOnClickListener(this);
32 | btnPlay.setOnClickListener(this);
33 | btnDownload.setOnClickListener(this);
34 | btnScroll.setOnClickListener(this);
35 | btnVolume.setOnClickListener(this);
36 | btnSearch.setOnClickListener(this);
37 | btnLoading.setOnClickListener(this);
38 | }
39 |
40 | @Override
41 | public void onClick(View view) {
42 | switch (view.getId()) {
43 | case R.id.btn_refresh:
44 | startActivity(new Intent(this, RefreshActivity.class));
45 | break;
46 | case R.id.btn_play:
47 | startActivity(new Intent(this, PlayActivity.class));
48 | break;
49 | case R.id.btn_download:
50 | startActivity(new Intent(this, DownloadActivity.class));
51 | break;
52 | case R.id.btn_scroll:
53 | startActivity(new Intent(this, ScrollActivity.class));
54 | break;
55 | case R.id.btn_volume:
56 | startActivity(new Intent(this, VolumeActivity.class));
57 | break;
58 | case R.id.btn_search:
59 | startActivity(new Intent(this, SearchActivity.class));
60 | break;
61 | case R.id.btn_loading:
62 | startActivity(new Intent(this, LoadingActivity.class));
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/codeest/enviewsdemo/PlayActivity.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviewsdemo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import moe.codeest.enviews.ENPlayView;
9 |
10 | /**
11 | * Created by codeest on 16/11/8.
12 | */
13 |
14 | public class PlayActivity extends Activity{
15 |
16 | ENPlayView playView;
17 | Button btnPause;
18 | Button btnPlay;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_play);
24 | playView = (ENPlayView) findViewById(R.id.view_play);
25 | btnPause = (Button) findViewById(R.id.btn_pause);
26 | btnPlay = (Button) findViewById(R.id.btn_play);
27 | btnPause.setOnClickListener(new View.OnClickListener() {
28 | @Override
29 | public void onClick(View view) {
30 | playView.pause();
31 | }
32 | });
33 | btnPlay.setOnClickListener(new View.OnClickListener() {
34 | @Override
35 | public void onClick(View view) {
36 | playView.play();
37 | }
38 | });
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/codeest/enviewsdemo/RefreshActivity.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviewsdemo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import moe.codeest.enviews.ENRefreshView;
9 |
10 | /**
11 | * Created by codeest on 16/11/6.
12 | */
13 |
14 | public class RefreshActivity extends Activity{
15 |
16 | ENRefreshView refreshView;
17 | Button btnRefresh;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_refresh);
23 | refreshView = (ENRefreshView) findViewById(R.id.view_refresh);
24 | btnRefresh = (Button) findViewById(R.id.btn_refresh);
25 | btnRefresh.setOnClickListener(new View.OnClickListener() {
26 | @Override
27 | public void onClick(View view) {
28 | refreshView.startRefresh();
29 | }
30 | });
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/codeest/enviewsdemo/ScrollActivity.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviewsdemo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import moe.codeest.enviews.ENScrollView;
9 |
10 | /**
11 | * Created by codeest on 16/11/9.
12 | */
13 |
14 | public class ScrollActivity extends Activity{
15 |
16 | ENScrollView scrollView;
17 | Button btnSwitch;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_scroll);
23 | scrollView = (ENScrollView) findViewById(R.id.view_scroll);
24 | btnSwitch = (Button) findViewById(R.id.btn_switch);
25 | btnSwitch.setOnClickListener(new View.OnClickListener() {
26 | @Override
27 | public void onClick(View view) {
28 | if (scrollView.isSelected()) {
29 | scrollView.unSelect();
30 | } else {
31 | scrollView.select();
32 | }
33 | }
34 | });
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/codeest/enviewsdemo/SearchActivity.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviewsdemo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import moe.codeest.enviews.ENSearchView;
9 |
10 | /**
11 | * Created by codeest on 16/11/13.
12 | */
13 |
14 | public class SearchActivity extends Activity{
15 |
16 | ENSearchView searchView;
17 | Button btnStart;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_search);
23 | searchView = (ENSearchView) findViewById(R.id.view_search);
24 | btnStart = (Button) findViewById(R.id.btn_search);
25 | btnStart.setOnClickListener(new View.OnClickListener() {
26 | @Override
27 | public void onClick(View view) {
28 | searchView.start();
29 | }
30 | });
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/codeest/enviewsdemo/VolumeActivity.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviewsdemo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.widget.SeekBar;
6 |
7 | import moe.codeest.enviews.ENVolumeView;
8 |
9 | /**
10 | * Created by codeest on 16/11/13.
11 | */
12 |
13 | public class VolumeActivity extends Activity{
14 |
15 | ENVolumeView volumeView;
16 | SeekBar sbVolume;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_volume);
22 | volumeView = (ENVolumeView) findViewById(R.id.view_volume);
23 | sbVolume = (SeekBar) findViewById(R.id.sb_volume);
24 |
25 | sbVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
26 | @Override
27 | public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
28 | volumeView.updateVolumeValue(i);
29 | }
30 |
31 | @Override
32 | public void onStartTrackingTouch(SeekBar seekBar) {
33 |
34 | }
35 |
36 | @Override
37 | public void onStopTrackingTouch(SeekBar seekBar) {
38 |
39 | }
40 | });
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_download.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
28 |
29 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
21 |
22 |
29 |
30 |
37 |
38 |
45 |
46 |
53 |
54 |
61 |
62 |
69 |
70 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_play.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
19 |
20 |
26 |
27 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_refresh.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scroll.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_search.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_volume.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
19 |
20 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ENViewsDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/moe/codeest/enviewsdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviewsdemo;
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.0'
9 |
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
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/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Mar 18 00:52:18 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 | // JitPack Maven
3 | apply plugin: 'com.github.dcendents.android-maven'
4 | // Group
5 | group='com.github.codeestX'
6 |
7 | android {
8 | compileSdkVersion 24
9 | buildToolsVersion '25.0.0'
10 |
11 | defaultConfig {
12 | minSdkVersion 21
13 | targetSdkVersion 24
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
18 |
19 | }
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | compile fileTree(dir: 'libs', include: ['*.jar'])
30 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
31 | exclude group: 'com.android.support', module: 'support-annotations'
32 | })
33 | compile 'com.android.support:appcompat-v7:24.1.1'
34 | testCompile 'junit:junit:4.12'
35 | }
36 |
--------------------------------------------------------------------------------
/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 /Users/chenyulong/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/moe/codeest/enviews/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviews;
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("moe.codeest.enviews.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/java/moe/codeest/enviews/ENDownloadView.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviews;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Paint;
11 | import android.graphics.Path;
12 | import android.graphics.RectF;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.animation.LinearInterpolator;
16 | import android.view.animation.OvershootInterpolator;
17 |
18 | /**
19 | * Created by codeest on 2016/11/9.
20 | *
21 | * 感觉是这个系列里设计的最赞的一款了 >//<
22 | */
23 |
24 | public class ENDownloadView extends View {
25 |
26 | private static final int STATE_PRE = 0;
27 |
28 | private static final int STATE_DOWNLOADING = 1;
29 |
30 | private static final int STATE_END = 2;
31 |
32 | private static final int STATE_RESET = 3;
33 |
34 | private static final int DEFAULT_LINE_COLOR = Color.WHITE;
35 |
36 | private static final int DEFAULT_BG_LINE_COLOR = 0xff3a3f45;
37 |
38 | private static final int DEFAULT_TEXT_COLOR = Color.WHITE;
39 |
40 | private static final int DEFAULT_LINE_WIDTH = 9;
41 |
42 | private static final int DEFAULT_BG_LINE_WIDTH = 9;
43 |
44 | private static final int DEFAULT_TEXT_SIZE = 14;
45 |
46 | private static final int DEFAULT_STATE = STATE_PRE;
47 |
48 | private static final int DEFAULT_RIPPLE_SPEED = 2;
49 |
50 | private static final int DEFAULT_DOWNLOAD_TIME = 2000;
51 |
52 | private static final DownloadUnit DEFAULT_DOWNLOAD_UNIT = DownloadUnit.B;
53 |
54 | private OnDownloadStateListener onDownloadStateListener;
55 |
56 | private int mCurrentState;
57 |
58 | private float mCurrentRippleX;
59 |
60 | private double mCurrentSize, mTotalSize;
61 |
62 | private int mTextSize;
63 |
64 | private int mDownloadTime;
65 |
66 | private DownloadUnit mUnit;
67 |
68 | private Paint mPaint, mBgPaint, mTextPaint;
69 |
70 | private Path mPath;
71 |
72 | private RectF mRectF ,mClipRectF;
73 |
74 | private float mFraction;
75 |
76 | private float mWidth, mHeight;
77 |
78 | private float mCenterX, mCenterY;
79 |
80 | private float mBaseLength, mCircleRadius, mBaseRippleLength;
81 |
82 | public static enum DownloadUnit {
83 | GB,
84 | MB,
85 | KB,
86 | B,
87 | NONE;
88 |
89 | private DownloadUnit() {
90 | }
91 | }
92 |
93 | public ENDownloadView(Context context) {
94 | super(context);
95 | }
96 |
97 | public ENDownloadView(Context context, AttributeSet attrs) {
98 | super(context, attrs);
99 |
100 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.download);
101 | int lineColor = ta.getColor(R.styleable.download_download_line_color, DEFAULT_LINE_COLOR);
102 | int bgLineColor = ta.getColor(R.styleable.download_download_bg_line_color, DEFAULT_BG_LINE_COLOR);
103 | int textColor = ta.getColor(R.styleable.download_download_text_color, DEFAULT_TEXT_COLOR);
104 | int lineWidth = ta.getInteger(R.styleable.download_download_line_width, DEFAULT_LINE_WIDTH);
105 | int bgLineWidth = ta.getInteger(R.styleable.download_download_bg_line_width, DEFAULT_BG_LINE_WIDTH);
106 | int textSize = ta.getInteger(R.styleable.download_download_text_size, DEFAULT_TEXT_SIZE);
107 | ta.recycle();
108 |
109 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
110 | mPaint.setStyle(Paint.Style.STROKE);
111 | mPaint.setStrokeCap(Paint.Cap.ROUND);
112 | mPaint.setStrokeWidth(lineWidth);
113 | mPaint.setColor(lineColor);
114 |
115 | mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
116 | mBgPaint.setStyle(Paint.Style.STROKE);
117 | mBgPaint.setStrokeCap(Paint.Cap.ROUND);
118 | mBgPaint.setStrokeWidth(bgLineWidth);
119 | mBgPaint.setColor(bgLineColor);
120 |
121 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
122 | mTextPaint.setColor(textColor);
123 | mTextPaint.setTextSize(textSize);
124 | mTextPaint.setTextAlign(Paint.Align.CENTER);
125 |
126 | mPath = new Path();
127 |
128 | mTextSize = textSize;
129 | mCurrentState = DEFAULT_STATE;
130 | mUnit = DEFAULT_DOWNLOAD_UNIT;
131 | mDownloadTime = DEFAULT_DOWNLOAD_TIME;
132 | }
133 |
134 | @Override
135 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
136 | super.onSizeChanged(w, h, oldw, oldh);
137 | mWidth = w;
138 | mHeight = h;
139 | mCenterX = mWidth / 2;
140 | mCenterY = mHeight / 2;
141 | mCircleRadius = mWidth * 5 / 12;
142 | mBaseLength = mCircleRadius / 3;
143 | mBaseRippleLength = 4.4f * mBaseLength / 12;
144 | mCurrentRippleX = mCenterX - mBaseRippleLength * 10;
145 | mRectF = new RectF(mCenterX - mCircleRadius, mCenterY - mCircleRadius, mCenterX + mCircleRadius, mCenterY + mCircleRadius);
146 | mClipRectF = new RectF(mCenterX - 6 * mBaseRippleLength, 0 , mCenterX + 6 * mBaseRippleLength , mHeight);
147 | }
148 |
149 | @Override
150 | protected void onDraw(Canvas canvas) {
151 | super.onDraw(canvas);
152 | switch (mCurrentState) {
153 | case STATE_PRE: //嗷~ 开始阶段:线弹起小球
154 | if (mFraction <= 0.4) {
155 | canvas.drawCircle(mCenterX, mCenterY ,mCircleRadius, mBgPaint);
156 | canvas.drawLine(mCenterX - mBaseLength, mCenterY, mCenterX, mCenterY + mBaseLength, mPaint);
157 | canvas.drawLine(mCenterX, mCenterY + mBaseLength, mCenterX + mBaseLength ,mCenterY , mPaint);
158 | canvas.drawLine(mCenterX , mCenterY + mBaseLength - 1.3f * mBaseLength / 0.4f * mFraction,
159 | mCenterX, mCenterY - 1.6f * mBaseLength + 1.3f * mBaseLength / 0.4f * mFraction, mPaint);
160 | } else if(mFraction <= 0.6) {
161 | canvas.drawCircle(mCenterX, mCenterY ,mCircleRadius, mBgPaint);
162 | canvas.drawCircle(mCenterX, mCenterY -0.3f * mBaseLength , 2, mPaint);
163 | canvas.drawLine(mCenterX - mBaseLength - mBaseLength * 1.2f / 0.2f * (mFraction - 0.4f), mCenterY, mCenterX, mCenterY + mBaseLength - mBaseLength / 0.2f * (mFraction - 0.4f), mPaint);
164 | canvas.drawLine(mCenterX, mCenterY + mBaseLength - mBaseLength / 0.2f * (mFraction - 0.4f), mCenterX + mBaseLength + mBaseLength * 1.2f / 0.2f * (mFraction - 0.4f) ,mCenterY , mPaint);
165 | } else if (mFraction <= 1){
166 | canvas.drawCircle(mCenterX, mCenterY ,mCircleRadius, mBgPaint);
167 | canvas.drawCircle(mCenterX, mCenterY -0.3f * mBaseLength - (mCircleRadius - 0.3f * mBaseLength) / 0.4f * (mFraction - 0.6f), 2, mPaint);
168 | canvas.drawLine(mCenterX - mBaseLength * 2.2f , mCenterY , mCenterX + mBaseLength * 2.2f, mCenterY, mPaint);
169 | } else {
170 | canvas.drawCircle(mCenterX, mCenterY ,mCircleRadius, mBgPaint);
171 | canvas.drawCircle(mCenterX, mCenterY - mCircleRadius - mBaseLength * 3 * (mFraction - 1), 3 ,mPaint);
172 | canvas.drawLine(mCenterX - mBaseLength * 2.2f , mCenterY , mCenterX + mBaseLength * 2.2f, mCenterY, mPaint);
173 | }
174 | break;
175 | case STATE_DOWNLOADING: //嗷~ 下载阶段:波浪线与文字
176 | if (mFraction <= 0.2) {
177 | mTextPaint.setTextSize(mTextSize / 0.2f * mFraction);
178 | }
179 | canvas.drawCircle(mCenterX, mCenterY ,mCircleRadius, mBgPaint);
180 | canvas.drawArc(mRectF, -90, 359.99f * mFraction, false ,mPaint);
181 | mPath.reset();
182 | mCurrentRippleX += DEFAULT_RIPPLE_SPEED;
183 | if (mCurrentRippleX > mCenterX - mBaseRippleLength * 6)
184 | mCurrentRippleX = mCenterX - mBaseRippleLength * 10;
185 | mPath.moveTo(mCurrentRippleX , mCenterY);
186 | for (int i = 0; i< 4 ; i++) {
187 | mPath.rQuadTo(mBaseRippleLength, -(1 - mFraction) * mBaseRippleLength, mBaseRippleLength * 2, 0);
188 | mPath.rQuadTo(mBaseRippleLength, (1 - mFraction) * mBaseRippleLength, mBaseRippleLength * 2, 0);
189 | }
190 | canvas.save();
191 | canvas.clipRect(mClipRectF);
192 | canvas.drawPath(mPath, mPaint);
193 | canvas.restore();
194 | if (mUnit != DownloadUnit.NONE && mCurrentSize > 0) {
195 | canvas.drawText(String.format("%.2f", mCurrentSize) + getUnitStr(mUnit), mCenterX , mCenterY + 1.4f * mBaseLength , mTextPaint);
196 | }
197 | break;
198 | case STATE_END: //嗷~ 结束阶段:线变勾
199 | canvas.drawCircle(mCenterX, mCenterY ,mCircleRadius, mPaint);
200 | if (mFraction <= 0.5) {
201 | mTextPaint.setTextSize(mTextSize - mTextSize / 0.2f * mFraction);
202 | } else {
203 | mTextPaint.setTextSize(0);
204 | }
205 | if (mUnit != DownloadUnit.NONE && mCurrentSize > 0) {
206 | canvas.drawText(String.format("%.2f", mCurrentSize) + getUnitStr(mUnit), mCenterX , mCenterY + 1.4f * mBaseLength , mTextPaint);
207 | }
208 | canvas.drawLine(mCenterX - mBaseLength * 2.2f + mBaseLength * 1.2f * mFraction, mCenterY,
209 | mCenterX - mBaseLength * 0.5f, mCenterY + mBaseLength * 0.5f * mFraction * 1.3f, mPaint);
210 | canvas.drawLine(mCenterX - mBaseLength * 0.5f, mCenterY + mBaseLength * 0.5f * mFraction * 1.3f,
211 | mCenterX + mBaseLength * 2.2f - mBaseLength * mFraction, mCenterY - mBaseLength * mFraction * 1.3f, mPaint);
212 | break;
213 | case STATE_RESET: //嗷~ 复位阶段:勾变箭头
214 | canvas.drawCircle(mCenterX, mCenterY ,mCircleRadius, mBgPaint);
215 | canvas.drawLine(mCenterX - mBaseLength, mCenterY,
216 | mCenterX - mBaseLength * 0.5f + mBaseLength * 0.5f * mFraction, mCenterY + mBaseLength * 0.65f + mBaseLength * 0.35f * mFraction, mPaint);
217 | canvas.drawLine(mCenterX - mBaseLength * 0.5f + mBaseLength * 0.5f * mFraction, mCenterY + mBaseLength * 0.65f + mBaseLength * 0.35f * mFraction,
218 | mCenterX + mBaseLength * 1.2f - mBaseLength * 0.2f * mFraction, mCenterY - 1.3f * mBaseLength + 1.3f * mBaseLength * mFraction, mPaint);
219 | canvas.drawLine(mCenterX - mBaseLength * 0.5f + mBaseLength * 0.5f * mFraction, mCenterY + mBaseLength * 0.65f + mBaseLength * 0.35f * mFraction,
220 | mCenterX - mBaseLength * 0.5f + mBaseLength * 0.5f * mFraction,
221 | mCenterY + mBaseLength * 0.65f - mBaseLength * 2.25f * mFraction, mPaint);
222 | break;
223 | }
224 | }
225 |
226 | public void start() {
227 | if (mCurrentState != STATE_PRE) {
228 | return;
229 | }
230 | mCurrentState = STATE_PRE;
231 | ValueAnimator preAnim = ValueAnimator.ofFloat(1.f, 100.f);
232 | preAnim.setDuration(1500);
233 | preAnim.setInterpolator(new OvershootInterpolator());
234 | preAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
235 | @Override
236 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
237 | mFraction = valueAnimator.getAnimatedFraction();
238 | invalidate();
239 | }
240 | });
241 | preAnim.addListener(new AnimatorListenerAdapter() {
242 | @Override
243 | public void onAnimationEnd(Animator animation) {
244 | mCurrentState = STATE_DOWNLOADING;
245 | downloadAnim();
246 | }
247 | });
248 | preAnim.start();
249 | }
250 |
251 | private void downloadAnim() {
252 | ValueAnimator downloadAnim = ValueAnimator.ofFloat(1.f, 100.f);
253 | downloadAnim.setDuration(mDownloadTime);
254 | downloadAnim.setInterpolator(new LinearInterpolator());
255 | downloadAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
256 | @Override
257 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
258 | mFraction = valueAnimator.getAnimatedFraction();
259 | if (mUnit != DownloadUnit.NONE && mTotalSize > 0)
260 | mCurrentSize = mFraction * mTotalSize;
261 | invalidate();
262 | }
263 | });
264 | downloadAnim.addListener(new AnimatorListenerAdapter() {
265 | @Override
266 | public void onAnimationEnd(Animator animation) {
267 | mCurrentState = STATE_END;
268 | endAnim();
269 | }
270 | });
271 | downloadAnim.start();
272 | }
273 |
274 | private void endAnim() {
275 | ValueAnimator endAnim = ValueAnimator.ofFloat(1.f, 100.f);
276 | endAnim.setDuration(700);
277 | endAnim.setInterpolator(new OvershootInterpolator());
278 | endAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
279 | @Override
280 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
281 | mFraction = valueAnimator.getAnimatedFraction();
282 | invalidate();
283 | }
284 | });
285 | endAnim.addListener(new AnimatorListenerAdapter() {
286 | @Override
287 | public void onAnimationEnd(Animator animation) {
288 | mFraction = 0;
289 | mCurrentState = STATE_RESET;
290 | if (onDownloadStateListener != null) {
291 | onDownloadStateListener.onDownloadFinish();
292 | }
293 | }
294 | });
295 | endAnim.start();
296 | }
297 |
298 | public void reset() {
299 | if (mCurrentState != STATE_RESET) {
300 | return;
301 | }
302 | ValueAnimator resetAnim = ValueAnimator.ofFloat(1.f, 100.f);
303 | resetAnim.setDuration(500);
304 | resetAnim.setInterpolator(new OvershootInterpolator());
305 | resetAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
306 | @Override
307 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
308 | mFraction = valueAnimator.getAnimatedFraction();
309 | invalidate();
310 | }
311 | });
312 | resetAnim.addListener(new AnimatorListenerAdapter() {
313 | @Override
314 | public void onAnimationEnd(Animator animation) {
315 | mFraction = 0;
316 | mCurrentState = STATE_PRE;
317 | if (onDownloadStateListener != null) {
318 | onDownloadStateListener.onResetFinish();
319 | }
320 | }
321 | });
322 | resetAnim.start();
323 | }
324 |
325 | private String getUnitStr(DownloadUnit unit) {
326 | switch (unit) {
327 | case GB:
328 | return " gb";
329 | case MB:
330 | return " mb";
331 | case KB:
332 | return " kb";
333 | case B:
334 | return " b";
335 | }
336 | return " b";
337 | }
338 |
339 | public void setDownloadConfig(int downloadTime, double downloadFileSize, DownloadUnit unit) {
340 | mDownloadTime = downloadTime;
341 | mTotalSize = downloadFileSize;
342 | mUnit = unit;
343 | }
344 |
345 | public int getCurrentState() {
346 | return mCurrentState;
347 | }
348 |
349 | interface OnDownloadStateListener {
350 |
351 | void onDownloadFinish();
352 |
353 | void onResetFinish();
354 | }
355 |
356 | public void setOnDownloadStateListener(OnDownloadStateListener onDownloadStateListener) {
357 | this.onDownloadStateListener = onDownloadStateListener;
358 | }
359 | }
360 |
--------------------------------------------------------------------------------
/library/src/main/java/moe/codeest/enviews/ENLoadingView.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviews;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.graphics.PixelFormat;
9 | import android.graphics.PorterDuffXfermode;
10 | import android.util.AttributeSet;
11 | import android.view.SurfaceHolder;
12 | import android.view.SurfaceView;
13 |
14 | /**
15 | * Created by codeest on 2016/11/15.
16 | *
17 | * 我还在好奇里面装的究竟是啤酒还是橙汁 0v0
18 | */
19 |
20 | public class ENLoadingView extends SurfaceView {
21 |
22 | private static final int STATE_SHOW = 0;
23 |
24 | private static final int STATE_HIDE = 1;
25 |
26 | private static final int DEFAULT_RIPPLE_SPEED = 2;
27 |
28 | private static final float DEFAULT_MOVE_SPEED = 0.01f;
29 |
30 | private Paint mPaint[], mBeerPaint[], mBubblePaint[];
31 |
32 | private Path mPath, mBgPath;
33 |
34 | private Thread mThread;
35 |
36 | private boolean isItemReady[];
37 |
38 | private float mCurrentRippleX[];
39 |
40 | private float mFraction[];
41 |
42 | private float mTemp = 0;
43 |
44 | private int mCurrentState;
45 |
46 | private float mWidth, mHeight;
47 |
48 | private float mCenterX, mCenterY;
49 |
50 | private SurfaceHolder surfaceHolder;
51 |
52 | private float mBaseLength, mBgBaseLength;
53 |
54 | public ENLoadingView(Context context) {
55 | super(context);
56 | init();
57 | }
58 |
59 | public ENLoadingView(Context context, AttributeSet attrs) {
60 | super(context, attrs);
61 | init();
62 | }
63 |
64 | private void init() {
65 | mPaint = new Paint[4];
66 | mBeerPaint = new Paint[4];
67 | mBubblePaint = new Paint[4];
68 | mPath = new Path();
69 | mBgPath = new Path();
70 | isItemReady = new boolean[4];
71 | mFraction = new float[4];
72 | mCurrentRippleX = new float[4];
73 | mCurrentState = STATE_HIDE;
74 |
75 | for (int i = 0; i< 4 ; i++) {
76 | mPaint[i] = new Paint(Paint.ANTI_ALIAS_FLAG);
77 | mPaint[i].setStyle(Paint.Style.STROKE);
78 | mPaint[i].setStrokeCap(Paint.Cap.ROUND);
79 | mPaint[i].setStrokeJoin(Paint.Join.ROUND);
80 | mPaint[i].setColor(Color.parseColor("#f0cc36"));
81 | mPaint[i].setStrokeWidth(9);
82 |
83 | mBeerPaint[i] = new Paint(Paint.ANTI_ALIAS_FLAG);
84 | mBeerPaint[i].setStyle(Paint.Style.FILL);
85 | mBeerPaint[i].setColor(Color.parseColor("#fbce0f"));
86 |
87 | mBubblePaint[i] = new Paint(Paint.ANTI_ALIAS_FLAG);
88 | mBubblePaint[i].setStyle(Paint.Style.FILL);
89 | mBubblePaint[i].setColor(Color.parseColor("#f5fba1"));
90 | }
91 | surfaceHolder = getHolder();
92 | setZOrderOnTop(true);
93 | surfaceHolder.setFormat(PixelFormat.TRANSLUCENT);
94 | surfaceHolder.addCallback(new SurfaceHolder.Callback() {
95 | @Override
96 | public void surfaceCreated(SurfaceHolder surfaceHolder) {
97 |
98 | }
99 |
100 | @Override
101 | public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
102 |
103 | }
104 |
105 | @Override
106 | public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
107 | if (mThread != null) {
108 | mThread.interrupt();
109 | mThread = null;
110 | }
111 | }
112 | });
113 | }
114 |
115 | @Override
116 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
117 | super.onSizeChanged(w, h, oldw, oldh);
118 | mWidth = w;
119 | mHeight = h;
120 | mCenterX = w / 2;
121 | mCenterY = h / 2;
122 | mBaseLength = w / 10;
123 | mBgBaseLength = w / 8;
124 | for (int i = 0; i < 4 ;i++) {
125 | mCurrentRippleX[i] = - 2 * mBgBaseLength;
126 | }
127 |
128 | mPath.reset();
129 | mPath.moveTo(0, mCenterY + 2 * mBaseLength);
130 | mPath.lineTo(0, mCenterY);
131 | mPath.lineTo(mBaseLength / 4, mCenterY - mBaseLength);
132 | mPath.lineTo(mBaseLength / 4, mCenterY - 1.5f * mBaseLength);
133 | mPath.lineTo(mBaseLength * 3 / 4, mCenterY - 1.5f * mBaseLength);
134 | mPath.lineTo(mBaseLength * 3 / 4, mCenterY - mBaseLength);
135 | mPath.lineTo(mBaseLength, mCenterY);
136 | mPath.lineTo(mBaseLength, mCenterY + 2 * mBaseLength);
137 | mPath.close();
138 | }
139 |
140 | private Runnable animRunnable = new Runnable() {
141 | @Override
142 | public void run() {
143 | try {
144 | while (mCurrentState == STATE_SHOW) {
145 | Thread.sleep(5);
146 | flush();
147 | draw();
148 | }
149 | if (mCurrentState == STATE_HIDE) {
150 | clearCanvas();
151 | }
152 | } catch (InterruptedException e) {
153 | e.printStackTrace();
154 | }
155 | }
156 | };
157 |
158 | private void flush() {
159 | if (mTemp >= 1)
160 | mTemp = 0;
161 | mTemp += DEFAULT_MOVE_SPEED;
162 | for (int i = 0;i < 4 ; i++) {
163 | float temp = mTemp - i * 0.25f;
164 | if (temp < 0)
165 | temp += 1;
166 | mFraction[i] = temp;
167 | if (mFraction[0] > i * 0.25f && !isItemReady[i]) {
168 | isItemReady[i] = true;
169 | }
170 | }
171 | }
172 |
173 | private void draw() {
174 | Canvas canvas = surfaceHolder.lockCanvas();
175 | if(canvas == null)
176 | return;
177 | mPaint[0].setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR)); //使用这只画笔清屏,清屏后恢复画笔
178 | canvas.drawPaint(mPaint[0]);
179 | mPaint[0].setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_OVER));
180 | for (int i = 0; i < 4 ; i++) {
181 | drawItem(canvas, mFraction[i], i);
182 | }
183 | surfaceHolder.unlockCanvasAndPost(canvas);
184 | }
185 |
186 | private void drawItem(Canvas canvas, float mFraction, int index) {
187 | if (!isItemReady[index]) {
188 | return;
189 | }
190 | canvas.save();
191 | canvas.translate(mFraction * mWidth ,0);
192 | float mCurrentY;
193 | if (mFraction < 0.1) { //嗷~ 从这开始画封口器以及确定波浪线高度
194 | mBeerPaint[index].setAlpha((int) (255 * 10 * mFraction));
195 | mPaint[index].setAlpha((int) (255 * 10 * mFraction));
196 | mBubblePaint[index].setAlpha((int) (255 * 10 * mFraction));
197 | mCurrentY = mCenterY + 2.2f * mBaseLength;
198 | canvas.drawLine(0.1f * mBaseLength ,mCenterY - 2.5f * mBaseLength, 0.9f * mBaseLength, mCenterY - 2.5f * mBaseLength, mPaint[index]);
199 | } else if(mFraction > 0.7) {
200 | mBeerPaint[index].setAlpha((int) (255 / 0.3f * (1 - mFraction)));
201 | mPaint[index].setAlpha((int) (255 / 0.3f * (1 - mFraction)));
202 | mBubblePaint[index].setAlpha((int) (255 / 0.3f * (1 - mFraction)));
203 | mCurrentY = mCenterY - mBaseLength;
204 | if (mFraction <= 0.75) {
205 | canvas.drawLine(mBaseLength * 0.5f, mCenterY - 2.5f * mBaseLength,
206 | mBaseLength * 0.5f, mCenterY - 2.5f * mBaseLength + mBaseLength / 0.05f * (mFraction - 0.7f), mPaint[index]);
207 | canvas.drawLine(0.1f * mBaseLength ,mCenterY - 2.5f * mBaseLength + mBaseLength / 0.05f * (mFraction - 0.7f),
208 | 0.9f * mBaseLength, mCenterY - 2.5f * mBaseLength + mBaseLength / 0.05f * (mFraction - 0.7f), mPaint[index]);
209 | } else {
210 | if (mFraction < 0.8) {
211 | canvas.drawLine(mBaseLength * 0.5f, mCenterY - 2.5f * mBaseLength,
212 | mBaseLength * 0.5f, mCenterY - 1.5f * mBaseLength - mBaseLength / 0.05f * (mFraction - 0.75f), mPaint[index]);
213 | }
214 | canvas.drawLine(mBaseLength / 4 - 6, mCenterY - 1.5f * mBaseLength - 6,
215 | mBaseLength * 3 / 4 + 6, mCenterY - 1.5f * mBaseLength - 6, mPaint[index]);
216 | }
217 | } else {
218 | mCurrentY = mCenterY + 2.2f * mBaseLength - 3.2f * mBaseLength / 0.6f * (mFraction - 0.1f);
219 | canvas.drawLine(0.1f * mBaseLength ,mCenterY - 2.5f * mBaseLength, 0.9f * mBaseLength, mCenterY - 2.5f * mBaseLength, mPaint[index]);
220 | }
221 | canvas.drawPath(mPath, mPaint[index]); //嗷~ 在这画酒瓶
222 | mCurrentRippleX[index] += DEFAULT_RIPPLE_SPEED;
223 | if (mCurrentRippleX[index] >= 0) {
224 | mCurrentRippleX[index] = - 2 * mBgBaseLength;
225 | }
226 | mBgPath.reset();
227 | mBgPath.moveTo(mCurrentRippleX[index], mCurrentY);
228 | for (int i = 0; i< 9 ; i++) {
229 | mBgPath.rQuadTo(mBgBaseLength / 2, mBgBaseLength / 8, mBgBaseLength, 0);
230 | mBgPath.rQuadTo(mBgBaseLength / 2, - mBgBaseLength / 8, mBgBaseLength, 0);
231 | }
232 | mBgPath.lineTo(mWidth, mHeight);
233 | mBgPath.lineTo(0, mHeight);
234 | mBgPath.close();
235 | canvas.clipPath(mPath);
236 | canvas.save();
237 | canvas.translate(- mBaseLength / 12, - mBaseLength / 10 - mBaseLength / 4 * (1 - mFraction));
238 | canvas.drawPath(mBgPath, mBubblePaint[index]); //嗷~ 在这画啤酒沫
239 | canvas.restore();
240 | canvas.drawPath(mBgPath, mBeerPaint[index]); //嗷~ 在这画啤酒
241 | canvas.restore();
242 | }
243 |
244 | public void show() {
245 | if (mCurrentState == STATE_SHOW) {
246 | return;
247 | }
248 | mCurrentState = STATE_SHOW;
249 | mThread = new Thread(animRunnable);
250 | mThread.start();
251 | }
252 |
253 | public void hide() {
254 | if (mCurrentState == STATE_HIDE) {
255 | return;
256 | }
257 | mCurrentState = STATE_HIDE;
258 | resetData();
259 | }
260 |
261 | private void clearCanvas() {
262 | Canvas canvas = surfaceHolder.lockCanvas();
263 | if(canvas == null)
264 | return;
265 | mPaint[0].setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
266 | canvas.drawPaint(mPaint[0]);
267 | mPaint[0].setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_OVER));
268 | surfaceHolder.unlockCanvasAndPost(canvas);
269 | mThread.interrupt();
270 | mThread = null;
271 | }
272 |
273 | private void resetData() {
274 | for (int i = 0; i<4 ; i++) {
275 | isItemReady[i] = false;
276 | mCurrentRippleX[i] = - 2 * mBgBaseLength;
277 | }
278 | mTemp = 0;
279 | }
280 | }
--------------------------------------------------------------------------------
/library/src/main/java/moe/codeest/enviews/ENPlayView.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviews;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.CornerPathEffect;
9 | import android.graphics.Paint;
10 | import android.graphics.Path;
11 | import android.graphics.PathMeasure;
12 | import android.graphics.RectF;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.animation.AnticipateInterpolator;
16 |
17 | /**
18 | * Created by codeest on 16/11/7.
19 | *
20 | * 论如何从直线到曲线再到三角形 =。=
21 | */
22 |
23 | public class ENPlayView extends View{
24 |
25 | public static int STATE_PLAY = 0;
26 |
27 | public static int STATE_PAUSE = 1;
28 |
29 | public static int DEFAULT_LINE_COLOR = Color.WHITE;
30 |
31 | public static int DEFAULT_BG_LINE_COLOR = 0xff444a4f;
32 |
33 | public static int DEFAULT_LINE_WIDTH = 14;
34 |
35 | public static int DEFAULT_BG_LINE_WIDTH = 12;
36 |
37 | public static int DEFAULT_DURATION = 1200;
38 |
39 | private int mCurrentState = STATE_PAUSE;
40 |
41 | private Paint mPaint, mBgPaint;
42 |
43 | private int mWidth, mHeight;
44 |
45 | private int mCenterX, mCenterY;
46 |
47 | private int mCircleRadius;
48 |
49 | private RectF mRectF, mBgRectF;
50 |
51 | private float mFraction = 1;
52 |
53 | private Path mPath, mDstPath;
54 |
55 | private PathMeasure mPathMeasure;
56 |
57 | private float mPathLength;
58 |
59 | private int mDuration;
60 |
61 | public ENPlayView(Context context) {
62 | super(context);
63 | }
64 |
65 | public ENPlayView(Context context, AttributeSet attrs) {
66 | super(context, attrs);
67 |
68 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.play);
69 | int lineColor = ta.getColor(R.styleable.play_play_line_color, DEFAULT_LINE_COLOR);
70 | int bgLineColor = ta.getColor(R.styleable.play_play_bg_line_color, DEFAULT_BG_LINE_COLOR);
71 | int lineWidth = ta.getInteger(R.styleable.play_play_line_width, DEFAULT_LINE_WIDTH);
72 | int bgLineWidth = ta.getInteger(R.styleable.play_play_bg_line_width, DEFAULT_BG_LINE_WIDTH);
73 | ta.recycle();
74 |
75 | setLayerType(View.LAYER_TYPE_SOFTWARE, null);
76 |
77 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
78 | mPaint.setStyle(Paint.Style.STROKE);
79 | mPaint.setStrokeCap(Paint.Cap.ROUND);
80 | mPaint.setColor(lineColor);
81 | mPaint.setStrokeWidth(lineWidth);
82 | mPaint.setPathEffect(new CornerPathEffect(1));
83 |
84 | mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
85 | mBgPaint.setStyle(Paint.Style.STROKE);
86 | mBgPaint.setStrokeCap(Paint.Cap.ROUND);
87 | mBgPaint.setColor(bgLineColor);
88 | mBgPaint.setStrokeWidth(bgLineWidth);
89 |
90 | mPath = new Path();
91 | mDstPath = new Path();
92 | mPathMeasure = new PathMeasure();
93 |
94 | mDuration = DEFAULT_DURATION;
95 | }
96 |
97 | @Override
98 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
99 | super.onSizeChanged(w, h, oldw, oldh);
100 | mWidth = w * 9 / 10;
101 | mHeight = h * 9 / 10;
102 | mCircleRadius = mWidth / 10;
103 | mCenterX = w / 2;
104 | mCenterY = h / 2;
105 | mRectF = new RectF(mCenterX - mCircleRadius, mCenterY + 0.6f * mCircleRadius,
106 | mCenterX + mCircleRadius, mCenterY + 2.6f * mCircleRadius);
107 | mBgRectF = new RectF(mCenterX - mWidth / 2 ,mCenterY - mHeight / 2 ,mCenterX + mWidth / 2, mCenterY + mHeight / 2);
108 | mPath.moveTo(mCenterX - mCircleRadius, mCenterY + 1.8f * mCircleRadius);
109 | mPath.lineTo(mCenterX - mCircleRadius, mCenterY - 1.8f * mCircleRadius);
110 | mPath.lineTo(mCenterX + mCircleRadius, mCenterY);
111 | mPath.close();
112 | mPathMeasure.setPath(mPath, false);
113 | mPathLength = mPathMeasure.getLength();
114 | }
115 |
116 | @Override
117 | protected void onDraw(Canvas canvas) {
118 | super.onDraw(canvas);
119 | canvas.drawCircle(mCenterX, mCenterY, mWidth / 2, mBgPaint);
120 | if (mFraction < 0) { //嗷~~ 弹性部分
121 | canvas.drawLine(mCenterX + mCircleRadius, mCenterY - 1.6f * mCircleRadius + 10 * mCircleRadius * mFraction,
122 | mCenterX + mCircleRadius, mCenterY + 1.6f * mCircleRadius + 10 * mCircleRadius * mFraction, mPaint);
123 |
124 | canvas.drawLine(mCenterX - mCircleRadius, mCenterY - 1.6f * mCircleRadius,
125 | mCenterX - mCircleRadius, mCenterY + 1.6f * mCircleRadius, mPaint);
126 |
127 | canvas.drawArc(mBgRectF, -105 , 360 , false, mPaint);
128 | } else if (mFraction <= 0.3) { //嗷~~ 右侧直线和下方曲线
129 | canvas.drawLine(mCenterX + mCircleRadius, mCenterY - 1.6f * mCircleRadius + mCircleRadius * 3.2f / 0.3f * mFraction,
130 | mCenterX + mCircleRadius, mCenterY + 1.6f * mCircleRadius, mPaint);
131 |
132 | canvas.drawLine(mCenterX - mCircleRadius, mCenterY - 1.6f * mCircleRadius,
133 | mCenterX - mCircleRadius, mCenterY + 1.6f * mCircleRadius, mPaint);
134 |
135 | if (mFraction != 0)
136 | canvas.drawArc(mRectF, 0f, 180f / 0.3f * mFraction, false, mPaint);
137 |
138 | canvas.drawArc(mBgRectF, -105 + 360 * mFraction, 360 * (1 - mFraction), false, mPaint);
139 | } else if (mFraction <= 0.6) { //嗷~~ 下方曲线和三角形
140 | canvas.drawArc(mRectF, 180f / 0.3f * (mFraction - 0.3f), 180 - 180f / 0.3f * (mFraction - 0.3f), false , mPaint);
141 |
142 | mDstPath.reset();
143 | mPathMeasure.getSegment(0.02f * mPathLength, 0.38f * mPathLength + 0.42f * mPathLength / 0.3f * (mFraction - 0.3f) ,
144 | mDstPath, true);
145 | canvas.drawPath(mDstPath, mPaint);
146 |
147 | canvas.drawArc(mBgRectF, -105 + 360 * mFraction, 360 * (1 - mFraction), false, mPaint);
148 | } else if (mFraction <= 0.8) { //嗷~~ 三角形
149 | mDstPath.reset();
150 | mPathMeasure.getSegment(0.02f * mPathLength + 0.2f * mPathLength / 0.2f * (mFraction - 0.6f)
151 | , 0.8f * mPathLength + 0.2f * mPathLength / 0.2f * (mFraction - 0.6f) ,
152 | mDstPath, true);
153 | canvas.drawPath(mDstPath, mPaint);
154 |
155 | canvas.drawArc(mBgRectF, -105 + 360 * mFraction, 360 * (1 - mFraction), false, mPaint);
156 | } else { //嗷~~ 弹性部分
157 | mDstPath.reset();
158 | mPathMeasure.getSegment(10 * mCircleRadius * (mFraction - 1)
159 | , mPathLength ,
160 | mDstPath, true);
161 | canvas.drawPath(mDstPath, mPaint);
162 | }
163 | }
164 |
165 | public void play() {
166 | if (mCurrentState == STATE_PLAY) {
167 | return;
168 | }
169 | mCurrentState = STATE_PLAY;
170 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.f, 100.f);
171 | valueAnimator.setDuration(mDuration);
172 | valueAnimator.setInterpolator(new AnticipateInterpolator());
173 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
174 | @Override
175 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
176 | mFraction = 1 - valueAnimator.getAnimatedFraction();
177 | invalidate();
178 | }
179 | });
180 | if (!valueAnimator.isRunning()) {
181 | valueAnimator.start();
182 | }
183 | }
184 |
185 | public void pause() {
186 | if (mCurrentState == STATE_PAUSE) {
187 | return;
188 | }
189 | mCurrentState = STATE_PAUSE;
190 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.f, 100.f);
191 | valueAnimator.setDuration(mDuration);
192 | valueAnimator.setInterpolator(new AnticipateInterpolator());
193 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
194 | @Override
195 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
196 | mFraction = valueAnimator.getAnimatedFraction();
197 | invalidate();
198 | }
199 | });
200 | if (!valueAnimator.isRunning()) {
201 | valueAnimator.start();
202 | }
203 | }
204 |
205 | public int getCurrentState() {
206 | return mCurrentState;
207 | }
208 |
209 | public void setDuration(int duration) {
210 | mDuration = duration;
211 | }
212 | }
213 |
--------------------------------------------------------------------------------
/library/src/main/java/moe/codeest/enviews/ENRefreshView.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviews;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 | import android.view.animation.AccelerateDecelerateInterpolator;
12 |
13 | /**
14 | * Created by codeest on 16/11/6.
15 | * 最简单的一个,先拿这个热热身~
16 | */
17 |
18 | public class ENRefreshView extends View{
19 |
20 | private static final int DEFAULT_LINE_COLOR = Color.WHITE;
21 |
22 | private static final int DEFAULT_LINE_WIDTH = 14;
23 |
24 | private static final int DEFAULT_DURATION = 2000;
25 |
26 | private Paint mPaint;
27 |
28 | private int mWidth, mHeight;
29 |
30 | private int mCircleRadius;
31 |
32 | private float mArrowLength;
33 |
34 | private float mArrowVarLength;
35 |
36 | private float mArcVarLength;
37 |
38 | private int mCenterX, mCenterY;
39 |
40 | private float mArrowX, mArrowY;
41 |
42 | private float mFraction;
43 |
44 | private int mDuration;
45 |
46 | public ENRefreshView(Context context) {
47 | super(context);
48 | }
49 |
50 | public ENRefreshView(Context context, AttributeSet attrs) {
51 | super(context, attrs);
52 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.refresh);
53 | int color = ta.getColor(R.styleable.refresh_refresh_line_color, DEFAULT_LINE_COLOR);
54 | int width = ta.getInteger(R.styleable.refresh_refresh_line_width, DEFAULT_LINE_WIDTH);
55 | ta.recycle();
56 | mDuration = DEFAULT_DURATION;
57 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
58 | mPaint.setStyle(Paint.Style.STROKE);
59 | mPaint.setStrokeCap(Paint.Cap.ROUND);
60 | mPaint.setColor(color);
61 | mPaint.setStrokeWidth(width);
62 | }
63 |
64 | @Override
65 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
66 | super.onSizeChanged(w, h, oldw, oldh);
67 | mWidth = w;
68 | mHeight = h;
69 | mCenterX = mWidth / 2;
70 | mCenterY = mHeight / 2;
71 | mCircleRadius = mCenterX / 3 * 2;
72 | mArrowLength = mWidth / 6;
73 | mArrowX = (float) (- mCircleRadius * Math.sin(30 * Math.PI / 180));
74 | mArrowY = (float) (- mCircleRadius * Math.cos(30 * Math.PI / 180));
75 | }
76 |
77 | @Override
78 | protected void onDraw(Canvas canvas) {
79 | if (mFraction <= 0.2) { //转上半圈
80 | mArrowVarLength = (mArrowLength / 0.4f * (0.4f - mFraction));
81 | mArcVarLength = 119.99f / 0.2f * mFraction;
82 | } else if (mFraction <= 0.4) { //转下半圈
83 | mArrowVarLength = (mArrowLength / 0.4f * (0.4f - mFraction));
84 | mArcVarLength = 119.99f / 0.2f * (0.4f - mFraction);
85 | } else if (mFraction <= 0.55) { //再弹.
86 | mArrowVarLength = (mArrowLength * 1.4f / 0.15f * (mFraction - 0.4f));
87 | mArcVarLength = - 28 / 0.15f * (mFraction - 0.4f);
88 | } else if (mFraction <= 0.7) { //再弹..
89 | mArrowVarLength = mArrowLength * 1.4f - mArrowLength * 0.7f / 0.15f * (mFraction - 0.55f);
90 | mArcVarLength = - 28 + 36 / 0.15f * (mFraction - 0.55f);
91 | } else if (mFraction <= 0.85) { //再弹...
92 | mArrowVarLength = mArrowLength * 0.7f + mArrowLength * 0.5f / 0.15f * (mFraction - 0.7f);
93 | mArcVarLength = 14 - 20 / 0.15f * (mFraction - 0.7f);
94 | } else { //好吧...再弹 =。=
95 | mArrowVarLength = mArrowLength * 1.2f - mArrowLength * 0.2f / 0.15f * (mFraction - 0.85f);
96 | mArcVarLength = - 6 + 6 / 0.15f * (mFraction - 0.85f);
97 | }
98 | canvas.save();
99 | canvas.translate(mCenterX, mCenterY);
100 | if (mFraction <= 0.4) {
101 | canvas.rotate((float) (-10 + 360 / 0.4 * mFraction));
102 | } else {
103 | canvas.rotate(-10);
104 | }
105 | canvas.drawArc( - mCircleRadius, - mCircleRadius, mCircleRadius, mCircleRadius, 0 - mArcVarLength, 240 + mArcVarLength, false, mPaint);
106 | canvas.drawLine(mArrowX, mArrowY,mArrowX - mArrowVarLength, mArrowY, mPaint);
107 | canvas.drawLine(mArrowX, mArrowY, mArrowX, mArrowY + mArrowVarLength, mPaint);
108 | canvas.restore();
109 | }
110 |
111 | public void startRefresh() {
112 | mArrowLength = mWidth / 6;
113 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.f, 100.f);
114 | valueAnimator.setDuration(mDuration);
115 | valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
116 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
117 | @Override
118 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
119 | mFraction = valueAnimator.getAnimatedFraction();
120 | invalidate();
121 | }
122 | });
123 | if (!valueAnimator.isRunning()) {
124 | valueAnimator.start();
125 | }
126 | }
127 |
128 | public void setDuration(int duration) {
129 | this.mDuration = duration;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/library/src/main/java/moe/codeest/enviews/ENScrollView.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviews;
2 |
3 | import android.animation.ArgbEvaluator;
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.RectF;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.animation.AccelerateDecelerateInterpolator;
16 |
17 | /**
18 | * Created by codeest on 16/11/9.
19 | *
20 | * 我把它做成了SwitchView...不知道设计师是不是这个想法.. 0.0
21 | */
22 |
23 | public class ENScrollView extends View {
24 |
25 | private static final int STATE_SELECT = 0;
26 |
27 | private static final int STATE_UNSELECT = 1;
28 |
29 | private static final int DEFAULT_LINE_COLOR = Color.WHITE;
30 |
31 | private static final int DEFAULT_BG_LINE_COLOR = 0xff444a4f;
32 |
33 | private static final int DEFAULT_LINE_WIDTH = 10;
34 |
35 | private static final int DEFAULT_BG_LINE_WIDTH = 10;
36 |
37 | private static final int DEFAULT_DURATION = 700;
38 |
39 | private static final int DEFAULT_VIEW_TRANSLATION_X = 16;
40 |
41 | private static final boolean DEFAULT_STATE = false;
42 |
43 | private int mCurrentState = STATE_UNSELECT;
44 |
45 | private int mCurrentColor = DEFAULT_LINE_COLOR;
46 |
47 | private Paint mPaint, mBgPaint, mColorPaint;
48 |
49 | private Path mPath, mDstPath;
50 |
51 | private PathMeasure mPathMeasure;
52 |
53 | private RectF mRectF;
54 |
55 | private float mFraction;
56 |
57 | private float mWidth, mHeight;
58 |
59 | private float mCenterX, mCenterY;
60 |
61 | private float mCircleRadius;
62 |
63 | private float mPathLength;
64 |
65 | private int mLineColor, mBgLineColor, mDuration, mViewTranslationX;
66 |
67 | public ENScrollView(Context context) {
68 | super(context);
69 | }
70 |
71 | public ENScrollView(Context context, AttributeSet attrs) {
72 | super(context, attrs);
73 |
74 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.scroll);
75 | int lineColor = ta.getColor(R.styleable.scroll_scroll_line_color, DEFAULT_LINE_COLOR);
76 | int lineWidth = ta.getInteger(R.styleable.scroll_scroll_line_width, DEFAULT_LINE_WIDTH);
77 | int bgLineColor = ta.getInteger(R.styleable.scroll_scroll_bg_line_color, DEFAULT_BG_LINE_COLOR);
78 | int bgLineWidth = ta.getInteger(R.styleable.scroll_scroll_bg_line_width, DEFAULT_BG_LINE_WIDTH);
79 | boolean isSelected = ta.getBoolean(R.styleable.scroll_scroll_is_selected, DEFAULT_STATE);
80 | int viewTranslationX = ta.getInteger(R.styleable.scroll_scroll_view_translation_x, DEFAULT_VIEW_TRANSLATION_X);
81 | ta.recycle();
82 |
83 | mLineColor = lineColor;
84 | mBgLineColor = bgLineColor;
85 |
86 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
87 | mPaint.setStyle(Paint.Style.STROKE);
88 | mPaint.setStrokeCap(Paint.Cap.ROUND);
89 | mPaint.setColor(lineColor);
90 | mPaint.setStrokeWidth(lineWidth);
91 |
92 | mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
93 | mBgPaint.setStyle(Paint.Style.STROKE);
94 | mBgPaint.setStrokeCap(Paint.Cap.ROUND);
95 | mBgPaint.setColor(bgLineColor);
96 | mBgPaint.setStrokeWidth(bgLineWidth);
97 |
98 | mColorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
99 | mColorPaint.setStyle(Paint.Style.FILL);
100 | mColorPaint.setStrokeCap(Paint.Cap.ROUND);
101 | mColorPaint.setColor(mCurrentColor);
102 |
103 | mPath = new Path();
104 | mDstPath = new Path();
105 | mPathMeasure = new PathMeasure();
106 |
107 | mDuration = DEFAULT_DURATION;
108 | mViewTranslationX = viewTranslationX;
109 | if (isSelected) {
110 | mFraction = 1;
111 | mCurrentState = STATE_SELECT;
112 | } else {
113 | mFraction = 0;
114 | mCurrentState = STATE_UNSELECT;
115 | }
116 | }
117 |
118 | @Override
119 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
120 | super.onSizeChanged(w, h, oldw, oldh);
121 | mHeight = h * 4 / 5;
122 | mWidth = h * 2.5f; //控件长宽比定义为 5 : 2
123 | mCenterX = w / 2;
124 | mCenterY = h / 2;
125 | mCircleRadius = mHeight / 2;
126 | mRectF = new RectF(mCenterX - mCircleRadius * 2 , mCenterY - mCircleRadius,
127 | mCenterX + mCircleRadius * 2 , mCenterY + mCircleRadius); //外圆矩形长宽比定义为 2 : 1
128 | mPath.addRoundRect(mRectF, mCircleRadius, mCircleRadius, Path.Direction.CW);
129 | mPathMeasure.setPath(mPath, false);
130 | mPathLength = mPathMeasure.getLength();
131 | }
132 |
133 | @Override
134 | protected void onDraw(Canvas canvas) {
135 | super.onDraw(canvas);
136 | canvas.save();
137 | canvas.translate(mFraction * mViewTranslationX, 0);
138 | canvas.drawRoundRect(mRectF, mCircleRadius, mCircleRadius, mBgPaint); //嗷~ 在这画背景线
139 | mDstPath.reset();
140 | mPathMeasure.getSegment(0 ,mPathLength / 2 * mFraction, mDstPath, true);
141 | canvas.drawPath(mDstPath, mPaint); //嗷~ 在这画上半圈
142 | mDstPath.reset();
143 | mPathMeasure.getSegment(mPathLength - mPathLength / 2 * mFraction ,mPathLength, mDstPath, true);
144 | canvas.drawPath(mDstPath, mPaint); //嗷~ 在这画下半圈
145 | mColorPaint.setColor(mCurrentColor);
146 | if (mFraction <= 0.8 && mFraction > 0.2) { //嗷~ 在这画球
147 | canvas.drawCircle(mCenterX - mCircleRadius + 2 * mCircleRadius * mFraction , mCenterY , mCircleRadius / 6 / 0.6f * (mFraction - 0.2f) , mColorPaint);
148 | } else if (mFraction > 0.8) {
149 | canvas.drawCircle(mCenterX - mCircleRadius + 2 * mCircleRadius * mFraction , mCenterY , mCircleRadius / 6 , mColorPaint);
150 | }
151 | canvas.restore();
152 | }
153 |
154 | public void select() {
155 | if (mCurrentState == STATE_SELECT) {
156 | return;
157 | }
158 | mCurrentState = STATE_SELECT;
159 | ValueAnimator valueAnimator = ValueAnimator.ofObject(new ArgbEvaluator(),
160 | mBgLineColor, mLineColor);
161 | valueAnimator.setDuration(mDuration);
162 | valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
163 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
164 | @Override
165 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
166 | mFraction = valueAnimator.getAnimatedFraction();
167 | mCurrentColor = (int) valueAnimator.getAnimatedValue();
168 | invalidate();
169 | }
170 | });
171 | if (!valueAnimator.isRunning()) {
172 | valueAnimator.start();
173 | }
174 | valueAnimator.start();
175 | }
176 |
177 | public void unSelect() {
178 | if (mCurrentState == STATE_UNSELECT) {
179 | return;
180 | }
181 | mCurrentState = STATE_UNSELECT;
182 | ValueAnimator valueAnimator = ValueAnimator.ofObject(new ArgbEvaluator(),
183 | mLineColor, mBgLineColor);
184 | valueAnimator.setDuration(mDuration);
185 | valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
186 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
187 | @Override
188 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
189 | mFraction = 1 - valueAnimator.getAnimatedFraction();
190 | mCurrentColor = (int) valueAnimator.getAnimatedValue();
191 | invalidate();
192 | }
193 | });
194 | if (!valueAnimator.isRunning()) {
195 | valueAnimator.start();
196 | }
197 | valueAnimator.start();
198 | }
199 |
200 | public boolean isSelected() {
201 | return mCurrentState == 0;
202 | }
203 |
204 | public void setDuration(int duration) {
205 | mDuration = duration;
206 | }
207 | }
208 |
--------------------------------------------------------------------------------
/library/src/main/java/moe/codeest/enviews/ENSearchView.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviews;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Paint;
11 | import android.graphics.Path;
12 | import android.graphics.PathMeasure;
13 | import android.graphics.RectF;
14 | import android.util.AttributeSet;
15 | import android.view.View;
16 | import android.view.animation.LinearInterpolator;
17 |
18 | /**
19 | * Created by codeest on 2016/11/14.
20 | *
21 | * 很Q 很弹 duang~ duang~ duang~
22 | */
23 |
24 | public class ENSearchView extends View {
25 |
26 | private static final int STATE_SEARCHING = 0;
27 |
28 | private static final int STATE_WAIT = 1;
29 |
30 | private static final int DEFAULT_LINE_COLOR = Color.WHITE;
31 |
32 | private static final int DEFAULT_LINE_WIDTH = 9;
33 |
34 | private static final int DEFAULT_DOT_SIZE = 3;
35 |
36 | private static final int DEFAULT_DURATION = 3000;
37 |
38 | private Paint mPaint, mArcPaint;
39 |
40 | private float mFraction;
41 |
42 | private int mCurrentState;
43 |
44 | private Path mPath, mArcPath;
45 |
46 | private PathMeasure mPathMeasure;
47 |
48 | private RectF mRectF;
49 |
50 | private float mWidth, mHeight;
51 |
52 | private float mCenterX, mCenterY;
53 |
54 | private float mPathLength, mCircleRadius;
55 |
56 | private float mCurrentPos[], mCurrentTan[];
57 |
58 | private boolean isDotShowing = true;
59 |
60 | private int mDotSize, mDuration;
61 |
62 | public ENSearchView(Context context) {
63 | super(context);
64 | }
65 |
66 | public ENSearchView(Context context, AttributeSet attrs) {
67 | super(context, attrs);
68 |
69 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.search);
70 | int lineColor = ta.getColor(R.styleable.search_search_line_color, DEFAULT_LINE_COLOR);
71 | int lineWidth = ta.getInteger(R.styleable.search_search_line_width, DEFAULT_LINE_WIDTH);
72 | int dotSize = ta.getInteger(R.styleable.search_search_dot_size, DEFAULT_DOT_SIZE);
73 | ta.recycle();
74 |
75 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
76 | mPaint.setStyle(Paint.Style.STROKE);
77 | mPaint.setStrokeCap(Paint.Cap.ROUND);
78 | mPaint.setStrokeWidth(lineWidth);
79 | mPaint.setColor(lineColor);
80 |
81 | mArcPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
82 | mArcPaint.setStyle(Paint.Style.FILL);
83 | mArcPaint.setColor(Color.WHITE);
84 |
85 | mDotSize = dotSize;
86 | mDuration = DEFAULT_DURATION;
87 | mCurrentState = STATE_WAIT;
88 | mCurrentPos = new float[2];
89 | mCurrentTan = new float[2];
90 | mPath = new Path();
91 | mArcPath = new Path();
92 | mPathMeasure = new PathMeasure();
93 | }
94 |
95 | @Override
96 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
97 | super.onSizeChanged(w, h, oldw, oldh);
98 | mWidth = w;
99 | mHeight = h;
100 | mCenterX = mWidth / 2;
101 | mCenterY = mHeight / 2;
102 | mCircleRadius = mWidth / 4;
103 |
104 | mRectF = new RectF(mCenterX - 0.95f * mCircleRadius,mCenterY - 0.95f * mCircleRadius,
105 | mCenterX + 0.95f * mCircleRadius, mCenterY + 0.95f * mCircleRadius);
106 |
107 | mPath.moveTo(mCenterX + 2.2f * mCircleRadius / (float) Math.sqrt(2), mCenterY + 2.2f * mCircleRadius / (float) Math.sqrt(2));
108 | mPath.lineTo(mCenterX , mCenterY);
109 | mPath.lineTo(mCenterX - 0.45f * mCircleRadius * (float) Math.sqrt(3), mCenterY + 0.45f * mCircleRadius);
110 | mPath.lineTo(mCenterX - 0.45f * mCircleRadius * (float) Math.sqrt(3), mCenterY - 0.45f * mCircleRadius);
111 | mPath.lineTo(mCenterX + 0.45f * mCircleRadius * (float) Math.sqrt(3), mCenterY);
112 | mPath.lineTo(mCenterX, mCenterY);
113 | mPath.lineTo(mCenterX + 2.2f * mCircleRadius / (float) Math.sqrt(2), mCenterY + 2.2f * mCircleRadius / (float) Math.sqrt(2));
114 |
115 | mPathMeasure.setPath(mPath, false);
116 | mPathLength = mPathMeasure.getLength();
117 | }
118 |
119 | @Override
120 | protected void onDraw(Canvas canvas) {
121 | super.onDraw(canvas);
122 | if (mFraction <= 0.2) { //嗷~ 放大镜手柄收缩
123 | canvas.drawCircle(mCenterX , mCenterY ,mCircleRadius - mCircleRadius * mFraction, mPaint);
124 | canvas.drawLine(mCenterX + mCircleRadius / (float) Math.sqrt(2) + 1.2f * mCircleRadius / (float) Math.sqrt(2) / 0.2f * mFraction,
125 | mCenterY + mCircleRadius / (float) Math.sqrt(2) + 1.2f * mCircleRadius / (float) Math.sqrt(2) / 0.2f * mFraction,
126 | mCenterX + 2.2f * mCircleRadius / (float) Math.sqrt(2),
127 | mCenterY + 2.2f * mCircleRadius / (float) Math.sqrt(2)
128 | ,mPaint);
129 | } else if (mFraction <= 0.8) {
130 | mPathMeasure.getPosTan(0 + mPathLength / 0.6f * (mFraction - 0.2f), mCurrentPos, mCurrentTan);
131 | if (mCurrentPos[1] == mCenterY && mCurrentPos[0] <= mCenterX + mCircleRadius / 3 && mCurrentPos[0] >= mCenterX - mCircleRadius / 3) {
132 | if (isDotShowing) {
133 | isDotShowing = false;
134 | } else {
135 | canvas.drawCircle(mCurrentPos[0], mCurrentPos[1], mDotSize, mPaint); //嗷~ 轨迹中的小球
136 | isDotShowing = true;
137 | }
138 | } else {
139 | canvas.drawCircle(mCurrentPos[0], mCurrentPos[1], mDotSize, mPaint);
140 | }
141 | if (mFraction <= 0.3) { //嗷~ 内圈粘性部分
142 | canvas.drawCircle(mCenterX , mCenterY ,0.8f * mCircleRadius + mCircleRadius * 2 * (mFraction - 0.2f), mPaint);
143 | } else {
144 | canvas.drawCircle(mCenterX , mCenterY ,mCircleRadius , mPaint);
145 | }
146 |
147 | if (mFraction <= 0.35 && mFraction > 0.3) {
148 | canvas.drawArc(mRectF, 45 - 55 / 0.05f * (mFraction - 0.3f), 110 / 0.05f * (mFraction - 0.3f), false, mArcPaint);
149 | } else if(mFraction <= 0.4 && mFraction > 0.35) {
150 | canvas.drawArc(mRectF, 45 - 55 / 0.05f * (0.4f - mFraction), 110 / 0.05f * (0.4f - mFraction), false, mArcPaint);
151 | }
152 |
153 | if (mFraction <= 0.75 && mFraction > 0.7) { //嗷~ 外圈粘性部分
154 | mArcPath.reset();
155 | mArcPath.moveTo(mCenterX + mCircleRadius, mCenterY);
156 | mArcPath.cubicTo(mCenterX + mCircleRadius + 8 / 0.05f * (mFraction - 0.7f), mCenterY + mCircleRadius / 2 + 8 / 0.05f * (mFraction - 0.7f),
157 | mCenterX + mCircleRadius / 2 + 8 / 0.05f * (mFraction - 0.7f), mCenterY + mCircleRadius + 8 / 0.05f * (mFraction - 0.7f),
158 | mCenterX, mCenterY + mCircleRadius);
159 | canvas.drawPath(mArcPath, mPaint);
160 | } else if(mFraction <= 0.8 && mFraction > 0.75) {
161 | mArcPath.reset();
162 | mArcPath.moveTo(mCenterX + mCircleRadius, mCenterY);
163 | mArcPath.cubicTo(mCenterX + mCircleRadius + 8 / 0.05f * (0.8f - mFraction), mCenterY + mCircleRadius / 2 + 8 / 0.05f * (0.8f - mFraction),
164 | mCenterX + mCircleRadius/ 2 + 8 / 0.05f * (0.8f - mFraction), mCenterY + mCircleRadius + 8 / 0.05f * (0.8f - mFraction),
165 | mCenterX, mCenterY + mCircleRadius);
166 | canvas.drawPath(mArcPath, mPaint);
167 | }
168 | } else { //嗷~ 放大镜手柄伸长
169 | canvas.drawCircle(mCenterX , mCenterY ,mCircleRadius , mPaint);
170 | canvas.drawLine(mCenterX + 2.2f *mCircleRadius / (float) Math.sqrt(2) - 1.2f * mCircleRadius / (float) Math.sqrt(2) / 0.2f * (mFraction - 0.8f),
171 | mCenterY + 2.2f * mCircleRadius / (float) Math.sqrt(2) - 1.2f * mCircleRadius / (float) Math.sqrt(2) / 0.2f * (mFraction - 0.8f),
172 | mCenterX + 2.2f * mCircleRadius / (float) Math.sqrt(2),
173 | mCenterY + 2.2f * mCircleRadius / (float) Math.sqrt(2)
174 | ,mPaint);
175 | }
176 | }
177 |
178 | public void start() {
179 | if (mCurrentState == STATE_SEARCHING) {
180 | return;
181 | }
182 | mCurrentState = STATE_SEARCHING;
183 | ValueAnimator valueAnim = ValueAnimator.ofFloat(1.f, 100.f);
184 | valueAnim.setDuration(mDuration);
185 | valueAnim.setInterpolator(new LinearInterpolator());
186 | valueAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
187 | @Override
188 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
189 | mFraction = valueAnimator.getAnimatedFraction();
190 | invalidate();
191 | }
192 | });
193 | valueAnim.addListener(new AnimatorListenerAdapter() {
194 | @Override
195 | public void onAnimationEnd(Animator animation) {
196 | mCurrentState = STATE_WAIT;
197 | }
198 | });
199 | valueAnim.start();
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/library/src/main/java/moe/codeest/enviews/ENVolumeView.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviews;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Paint;
11 | import android.graphics.Path;
12 | import android.graphics.PathMeasure;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.animation.AccelerateDecelerateInterpolator;
16 | import android.view.animation.LinearInterpolator;
17 |
18 | /**
19 | * Created by codeest on 16/11/13.
20 | *
21 | * 嗯..这个控件很带感 隔着屏幕都能感受到声音有木有~
22 | */
23 |
24 | public class ENVolumeView extends View{
25 |
26 | private static final int STATE_SILENT = 0;
27 |
28 | private static final int STATE_VOLUME = 1;
29 |
30 | private static final int STATE_VIBRATE = 2;
31 |
32 | private static final int DEFAULT_LINE_COLOR = Color.WHITE;
33 |
34 | private static final int DEFAULT_BG_LINE_COLOR = 0xff64696d;
35 |
36 | private static final int DEFAULT_LINE_WIDTH = 10;
37 |
38 | private static final int DEFAULT_BG_LINE_WIDTH = 10;
39 |
40 | private Paint mPaint, mBgPaint;
41 |
42 | private Path mPath, mDstPath;
43 |
44 | private PathMeasure mPathMeasure;
45 |
46 | private float mFraction;
47 |
48 | private int mVolumeValue;
49 |
50 | private float mCurrentState = STATE_SILENT;
51 |
52 | private float mWidth, mHeight;
53 |
54 | private float mCenterX, mCenterY;
55 |
56 | private float mBaseLength, mPathLength;
57 |
58 | private ValueAnimator vibrateAnim;
59 |
60 | public ENVolumeView(Context context) {
61 | super(context);
62 | }
63 |
64 | public ENVolumeView(Context context, AttributeSet attrs) {
65 | super(context, attrs);
66 |
67 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.volume);
68 | int lineColor = ta.getColor(R.styleable.volume_volume_line_color, DEFAULT_LINE_COLOR);
69 | int lineWidth = ta.getInteger(R.styleable.volume_volume_line_width, DEFAULT_LINE_WIDTH);
70 | int bgLineColor = ta.getInteger(R.styleable.volume_volume_bg_line_color, DEFAULT_BG_LINE_COLOR);
71 | int bgLineWidth = ta.getInteger(R.styleable.volume_volume_bg_line_width, DEFAULT_BG_LINE_WIDTH);
72 | ta.recycle();
73 |
74 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
75 | mPaint.setStyle(Paint.Style.STROKE);
76 | mPaint.setStrokeCap(Paint.Cap.ROUND);
77 | mPaint.setStrokeJoin(Paint.Join.ROUND);
78 | mPaint.setColor(lineColor);
79 | mPaint.setStrokeWidth(lineWidth);
80 |
81 | mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
82 | mBgPaint.setStyle(Paint.Style.STROKE);
83 | mBgPaint.setStrokeCap(Paint.Cap.ROUND);
84 | mBgPaint.setStrokeJoin(Paint.Join.ROUND);
85 | mBgPaint.setColor(bgLineColor);
86 | mBgPaint.setStrokeWidth(bgLineWidth);
87 |
88 | mPath = new Path();
89 | mDstPath = new Path();
90 | mPathMeasure = new PathMeasure();
91 | }
92 |
93 | @Override
94 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
95 | super.onSizeChanged(w, h, oldw, oldh);
96 | mWidth = w * 5 / 6;
97 | mHeight = h;
98 | mBaseLength = mWidth / 6;
99 | mCenterX = w / 2;
100 | mCenterY = h / 2;
101 |
102 | mPath.moveTo(mCenterX - 3 * mBaseLength, mCenterY);
103 | mPath.lineTo(mCenterX - 3 * mBaseLength, mCenterY - 0.5f * mBaseLength);
104 | mPath.lineTo(mCenterX - 2 * mBaseLength, mCenterY - 0.5f * mBaseLength);
105 | mPath.lineTo(mCenterX, mCenterY - 2 * mBaseLength);
106 | mPath.lineTo(mCenterX, mCenterY + 2 * mBaseLength);
107 | mPath.lineTo(mCenterX - 2 * mBaseLength, mCenterY + 0.5f * mBaseLength);
108 | mPath.lineTo(mCenterX - 3 * mBaseLength, mCenterY + 0.5f * mBaseLength);
109 | mPath.close();
110 | mPathMeasure.setPath(mPath, false);
111 | mPathLength = mPathMeasure.getLength();
112 |
113 | vibrateAnim = ValueAnimator.ofFloat(1.f, 100.f);
114 | vibrateAnim.setDuration(100);
115 | vibrateAnim.setInterpolator(new LinearInterpolator());
116 | vibrateAnim.setRepeatCount(ValueAnimator.INFINITE);
117 | vibrateAnim.setRepeatMode(ValueAnimator.REVERSE);
118 | vibrateAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
119 | @Override
120 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
121 | mFraction = valueAnimator.getAnimatedFraction();
122 | invalidate();
123 | }
124 | });
125 | }
126 |
127 | @Override
128 | protected void onDraw(Canvas canvas) {
129 | super.onDraw(canvas);
130 | if (mCurrentState != STATE_VIBRATE) {
131 | if (mFraction <= 0.5) {
132 | mDstPath.reset(); //嗷~ 在这画喇叭
133 | mPathMeasure.getSegment(0, mPathLength * 0.38f - mPathLength * 0.13f * mFraction, mDstPath, true);
134 | canvas.drawPath(mDstPath, mBgPaint);
135 | mDstPath.reset();
136 | mPathMeasure.getSegment(mPathLength * 0.62f + mPathLength * 0.13f * mFraction, mPathLength, mDstPath, true);
137 | canvas.drawPath(mDstPath, mBgPaint);
138 |
139 | canvas.save(); //嗷~ 在这画X
140 | canvas.translate(- mFraction * mBaseLength * 2, 0);
141 | canvas.drawLine(mCenterX - mBaseLength * (0.5f - mFraction) , mCenterY - mBaseLength * (0.5f - mFraction)
142 | ,mCenterX + mBaseLength * (0.5f - mFraction), mCenterY + mBaseLength * (0.5f - mFraction), mBgPaint);
143 | canvas.drawLine(mCenterX - mBaseLength * (0.5f - mFraction), mCenterY + mBaseLength * (0.5f - mFraction)
144 | ,mCenterX + mBaseLength * (0.5f - mFraction), mCenterY - mBaseLength * (0.5f - mFraction), mBgPaint);
145 | canvas.restore();
146 | } else {
147 | mDstPath.reset(); //嗷~ 在这画喇叭
148 | mPathMeasure.getSegment(0, mPathLength * 0.25f + mPathLength * 0.13f * (mFraction - 0.5f), mDstPath, true);
149 | canvas.drawPath(mDstPath, mBgPaint);
150 | mDstPath.reset();
151 | mPathMeasure.getSegment(mPathLength * 0.75f - mPathLength * 0.13f * (mFraction - 0.5f), mPathLength, mDstPath, true);
152 | canvas.drawPath(mDstPath, mBgPaint);
153 | mDstPath.reset();
154 | mPathMeasure.getSegment(0, mPathLength * 0.38f / 0.5f * (mFraction - 0.5f), mDstPath, true);
155 | canvas.drawPath(mDstPath, mPaint);
156 | mDstPath.reset();
157 | mPathMeasure.getSegment(mPathLength - mPathLength * 0.38f / 0.5f * (mFraction - 0.5f), mPathLength, mDstPath, true);
158 | canvas.drawPath(mDstPath, mPaint);
159 |
160 | canvas.save(); //嗷~ 在这画小声波
161 | canvas.translate( - (1 - mFraction) * mBaseLength * 2, 0);
162 | canvas.drawArc(mCenterX - 0.5f * mBaseLength - mBaseLength / 0.5f * (mFraction - 0.5f),
163 | mCenterY - mBaseLength / 0.5f * (mFraction - 0.5f),
164 | mCenterX - 0.5f * mBaseLength + mBaseLength / 0.5f * (mFraction - 0.5f),
165 | mCenterY + mBaseLength / 0.5f * (mFraction - 0.5f), -55, 110 ,false, mBgPaint);
166 | int sVolume = mVolumeValue;
167 | if (sVolume > 50)
168 | sVolume = 50;
169 | canvas.drawArc(mCenterX - 0.5f * mBaseLength - mBaseLength / 0.5f * (mFraction - 0.5f),
170 | mCenterY - mBaseLength / 0.5f * (mFraction - 0.5f),
171 | mCenterX - 0.5f * mBaseLength + mBaseLength / 0.5f * (mFraction - 0.5f),
172 | mCenterY + mBaseLength / 0.5f * (mFraction - 0.5f), -55 / 50 * sVolume, 110 / 50 * sVolume ,false, mPaint);
173 | canvas.restore();
174 |
175 | canvas.save(); //嗷~ 在这画大声波
176 | canvas.translate( - (1 - mFraction) * mBaseLength * 3, 0);
177 | canvas.drawArc(mCenterX - 1.6f * mBaseLength / 0.5f * (mFraction - 0.5f),
178 | mCenterY - 1.6f * mBaseLength / 0.5f * (mFraction - 0.5f),
179 | mCenterX + 1.6f * mBaseLength / 0.5f * (mFraction - 0.5f),
180 | mCenterY + 1.6f * mBaseLength / 0.5f * (mFraction - 0.5f), -55, 110 ,false, mBgPaint);
181 | int lVolume = mVolumeValue - 50;
182 | if (lVolume < 0)
183 | lVolume = 0;
184 | canvas.drawArc(mCenterX - 1.6f * mBaseLength / 0.5f * (mFraction - 0.5f),
185 | mCenterY - 1.6f * mBaseLength / 0.5f * (mFraction - 0.5f),
186 | mCenterX + 1.6f * mBaseLength / 0.5f * (mFraction - 0.5f),
187 | mCenterY + 1.6f * mBaseLength / 0.5f * (mFraction - 0.5f), -55 / 50 * lVolume, 110 / 50 * lVolume ,false, mPaint);
188 | canvas.restore();
189 | }
190 | } else {
191 | mDstPath.reset(); //嗷~ 在这画喇叭
192 | mPathMeasure.getSegment(0, mPathLength * 0.38f, mDstPath, true);
193 | canvas.drawPath(mDstPath, mPaint);
194 | mDstPath.reset();
195 | mPathMeasure.getSegment(mPathLength - mPathLength * 0.38f, mPathLength, mDstPath, true);
196 | canvas.drawPath(mDstPath, mPaint);
197 |
198 | canvas.save(); //嗷~ 在这画小声波
199 | canvas.translate( - (1 - mFraction) * mBaseLength / 5 * 2 * mVolumeValue / 100, 0);
200 | canvas.drawArc(mCenterX - 1.5f * mBaseLength,
201 | mCenterY - mBaseLength,
202 | mCenterX + 0.5f * mBaseLength,
203 | mCenterY + mBaseLength, -55, 110 ,false, mBgPaint);
204 | int sVolume = mVolumeValue;
205 | if (sVolume > 50)
206 | sVolume = 50;
207 | canvas.drawArc(mCenterX - 1.5f * mBaseLength,
208 | mCenterY - mBaseLength,
209 | mCenterX + 0.5f * mBaseLength,
210 | mCenterY + mBaseLength, -55 / 50 * sVolume, 110 / 50 * sVolume ,false, mPaint);
211 | canvas.restore();
212 |
213 | canvas.save(); //嗷~ 在这画大声波
214 | canvas.translate( - (1 - mFraction) * mBaseLength / 5 * 2 * mVolumeValue / 100, 0);
215 | canvas.drawArc(mCenterX - 1.6f * mBaseLength,
216 | mCenterY - 1.6f * mBaseLength,
217 | mCenterX + 1.6f * mBaseLength,
218 | mCenterY + 1.6f * mBaseLength, -55, 110 ,false, mBgPaint);
219 | int lVolume = mVolumeValue - 50;
220 | if (lVolume < 0)
221 | lVolume = 0;
222 | canvas.drawArc(mCenterX - 1.6f * mBaseLength,
223 | mCenterY - 1.6f * mBaseLength,
224 | mCenterX + 1.6f * mBaseLength,
225 | mCenterY + 1.6f * mBaseLength, -55 / 50 * lVolume, 110 / 50 * lVolume ,false, mPaint);
226 | canvas.restore();
227 | }
228 | }
229 |
230 | private void closeVolume() {
231 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.f, 100.f);
232 | valueAnimator.setDuration(800);
233 | valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
234 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
235 | @Override
236 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
237 | mFraction = 1 - valueAnimator.getAnimatedFraction();
238 | invalidate();
239 | }
240 | });
241 | if (!valueAnimator.isRunning()) {
242 | valueAnimator.start();
243 | }
244 | }
245 |
246 | private void openVolume() {
247 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.f, 100.f);
248 | valueAnimator.setDuration(800);
249 | valueAnimator.setInterpolator(new LinearInterpolator());
250 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
251 | @Override
252 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
253 | mFraction = valueAnimator.getAnimatedFraction();
254 | invalidate();
255 | }
256 | });
257 | if (!valueAnimator.isRunning()) {
258 | valueAnimator.start();
259 | }
260 | valueAnimator.addListener(new AnimatorListenerAdapter() {
261 | @Override
262 | public void onAnimationEnd(Animator animation) {
263 | if (mVolumeValue == 0) {
264 | closeVolume();
265 | } else {
266 | startVibration();
267 | }
268 | }
269 | });
270 | }
271 |
272 | private void startVibration() {
273 | mCurrentState = STATE_VIBRATE;
274 | if (!vibrateAnim.isRunning()) {
275 | vibrateAnim.start();
276 | }
277 | }
278 |
279 | private void stopVibration() {
280 | if (vibrateAnim.isRunning()) {
281 | vibrateAnim.cancel();
282 | }
283 | }
284 |
285 | public void updateVolumeValue(int value) {
286 | if (value < 0 || value > 100) {
287 | return;
288 | }
289 | mVolumeValue = value;
290 | if (value == 0 && mCurrentState != STATE_SILENT) {
291 | mCurrentState = STATE_SILENT;
292 | stopVibration();
293 | closeVolume();
294 | } else if (value != 0 && mCurrentState == STATE_SILENT){
295 | mCurrentState = STATE_VOLUME;
296 | openVolume();
297 | }
298 | }
299 | }
300 |
--------------------------------------------------------------------------------
/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 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/library/src/test/java/moe/codeest/enviews/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package moe.codeest.enviews;
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 | }
--------------------------------------------------------------------------------
/preview/download.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/download.gif
--------------------------------------------------------------------------------
/preview/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/loading.gif
--------------------------------------------------------------------------------
/preview/o_download.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/o_download.gif
--------------------------------------------------------------------------------
/preview/o_loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/o_loading.gif
--------------------------------------------------------------------------------
/preview/o_play.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/o_play.gif
--------------------------------------------------------------------------------
/preview/o_refresh.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/o_refresh.gif
--------------------------------------------------------------------------------
/preview/o_scroll.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/o_scroll.gif
--------------------------------------------------------------------------------
/preview/o_search.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/o_search.gif
--------------------------------------------------------------------------------
/preview/o_volume.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/o_volume.gif
--------------------------------------------------------------------------------
/preview/play.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/play.gif
--------------------------------------------------------------------------------
/preview/refresh.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/refresh.gif
--------------------------------------------------------------------------------
/preview/scroll.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/scroll.gif
--------------------------------------------------------------------------------
/preview/search.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/search.gif
--------------------------------------------------------------------------------
/preview/volume.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeestX/ENViews/3b9ded6979136de1bb3a929fbb09637166b0945f/preview/volume.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------