├── .gitignore
├── .idea
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── test
│ │ └── viewtest
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── test
│ │ │ └── viewtest
│ │ │ ├── activities
│ │ │ └── MainActivity.java
│ │ │ ├── adapters
│ │ │ ├── BaseAdapter.java
│ │ │ └── ImageAdapter.java
│ │ │ ├── utils
│ │ │ ├── ImmerseUtil.java
│ │ │ └── LogUtil.java
│ │ │ └── views
│ │ │ └── CoffinLayout.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_0.webp
│ │ ├── ic_1.webp
│ │ ├── ic_10.webp
│ │ ├── ic_11.webp
│ │ ├── ic_12.webp
│ │ ├── ic_13.webp
│ │ ├── ic_14.webp
│ │ ├── ic_15.webp
│ │ ├── ic_16.webp
│ │ ├── ic_17.webp
│ │ ├── ic_18.webp
│ │ ├── ic_19.webp
│ │ ├── ic_2.webp
│ │ ├── ic_3.webp
│ │ ├── ic_4.webp
│ │ ├── ic_5.webp
│ │ ├── ic_6.webp
│ │ ├── ic_7.webp
│ │ ├── ic_8.webp
│ │ ├── ic_9.webp
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── act_main_view.xml
│ │ ├── adapter_item_view.xml
│ │ ├── adapter_item_view2.xml
│ │ ├── bottom_bar.xml
│ │ ├── header_view.xml
│ │ ├── residual_view.xml
│ │ └── top_bar.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── attr.xml
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── test
│ └── viewtest
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── preview.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
56 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
16 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | Android
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | 1.8
54 |
55 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/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 | # CoffinLayout
2 | ## 仿燃兔APP的游戏详情界面
3 | ## 详细见: http://blog.csdn.net/u011387817/article/details/79552699
4 | ## 只需一个CoffinLayout
5 | ```
6 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | ```
23 | 
24 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.test.viewtest"
7 | minSdkVersion 21
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | compileOptions {
20 | targetCompatibility 1.8
21 | sourceCompatibility 1.8
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(include: ['*.jar'], dir: 'libs')
27 | implementation 'com.android.support:appcompat-v7:27.1.0'
28 | testImplementation 'junit:junit:4.12'
29 | androidTestImplementation 'com.android.support.test:runner:0.5'
30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
31 | implementation 'com.android.support:recyclerview-v7:27.1.0'
32 | implementation 'com.github.bumptech.glide:glide:4.6.1'
33 | annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
34 | }
35 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/test/viewtest/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.test.viewtest;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.test.viewtest", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/test/viewtest/activities/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.test.viewtest.activities;
2 |
3 | import android.graphics.Color;
4 | import android.os.Build;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.support.v7.widget.StaggeredGridLayoutManager;
11 | import android.view.View;
12 | import android.view.Window;
13 | import android.view.WindowManager;
14 | import android.widget.Toast;
15 |
16 | import com.test.viewtest.R;
17 | import com.test.viewtest.adapters.ImageAdapter;
18 | import com.test.viewtest.utils.ImmerseUtil;
19 | import com.test.viewtest.utils.LogUtil;
20 | import com.test.viewtest.views.CoffinLayout;
21 |
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | /**
26 | * Created by wuyr on 18-3-8 下午10:26.
27 | */
28 |
29 | public class MainActivity extends AppCompatActivity {
30 |
31 | private CoffinLayout mCoffinLayout;
32 |
33 | @Override
34 | protected void onCreate(@Nullable Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | LogUtil.setDebugLevel(LogUtil.ERROR);
37 | setContentView(R.layout.act_main_view);
38 | initStatusBar();
39 |
40 | mCoffinLayout = findViewById(R.id.coffin_layout);
41 |
42 | View view = mCoffinLayout.getTopBar();
43 | if (view != null) {
44 | int statusBarHeight = ImmerseUtil.getStatusBarHeight(this);
45 | view.setPadding(0, statusBarHeight, 0, 0);
46 | view.getLayoutParams().height += statusBarHeight;
47 | mCoffinLayout.requestLayout();
48 | }
49 | view = mCoffinLayout.getResidualView();
50 | if (view != null) {
51 | view.setOnClickListener(v -> mCoffinLayout.closeCoffin());
52 | }
53 | view = mCoffinLayout.getBottomBar();
54 | if (view != null) {
55 | view.setOnClickListener(v -> Toast.makeText(this, "bottomBar clicked", Toast.LENGTH_SHORT).show());
56 | }
57 |
58 | RecyclerView topView = findViewById(R.id.top_recycler_view);
59 | topView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
60 | topView.setAdapter(new ImageAdapter(this, getData(), R.layout.adapter_item_view));
61 |
62 | RecyclerView bottomView = findViewById(R.id.bottom_recycler_view);
63 | bottomView.setLayoutManager(new LinearLayoutManager(this));
64 | bottomView.setAdapter(new ImageAdapter(this, getData(), R.layout.adapter_item_view));
65 |
66 | RecyclerView horizontalView = findViewById(R.id.horizontal_recycler_view);
67 | horizontalView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
68 | horizontalView.setAdapter(new ImageAdapter(this, getData(), R.layout.adapter_item_view2));
69 | }
70 |
71 | @Override
72 | public void onBackPressed() {
73 | if (mCoffinLayout.getCurrentStatus() == CoffinLayout.STATE_NAKED) {
74 | mCoffinLayout.closeCoffin();
75 | } else {
76 | super.onBackPressed();
77 | }
78 | }
79 |
80 | public List getData() {
81 | List result = new ArrayList<>();
82 | for (int i = 0; i < 19; i++) {
83 | result.add(0x7f060055 + i);
84 | }
85 | return result;
86 | }
87 |
88 | private void initStatusBar() {
89 | //设置状态栏透明
90 | Window window = getWindow();
91 | // Translucent status bar
92 | window.setFlags(
93 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
94 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
95 | // Translucent navigation bar
96 | /*window.setFlags(
97 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
98 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);*/
99 | //android 5.0以上的
100 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
101 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
102 | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
103 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
104 | //| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
105 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
106 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
107 | window.setStatusBarColor(Color.TRANSPARENT);
108 | window.setNavigationBarColor(Color.TRANSPARENT);
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/app/src/main/java/com/test/viewtest/adapters/BaseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.test.viewtest.adapters;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * Created by wuyr on 17-10-24 下午1:05.
13 | */
14 |
15 | @SuppressWarnings({"WeakerAccess", "unused"})
16 | public abstract class BaseAdapter extends RecyclerView.Adapter {
17 |
18 | Context mContext;
19 | List mData;
20 | int mLayoutId;
21 | LayoutInflater mLayoutInflater;
22 | OnSizeChangedListener mOnSizeChangedListener;
23 |
24 | public BaseAdapter(Context context, List data, int layoutId) {
25 | mContext = context;
26 | mData = data == null ? new ArrayList<>() : data;
27 | mLayoutId = layoutId;
28 | mLayoutInflater = LayoutInflater.from(context);
29 | }
30 |
31 | @Override
32 | public int getItemCount() {
33 | return mData.size();
34 | }
35 |
36 | public void addData(@NonNull O o) {
37 | mData.add(o);
38 | notifyItemInserted(mData.size());
39 | notifyOnSizeChanged();
40 | }
41 |
42 | public void addData(int index, @NonNull O o) {
43 | mData.add(index, o);
44 | notifyItemInserted(index);
45 | notifyOnSizeChanged();
46 | }
47 |
48 | public void addData(@NonNull List data) {
49 | if (!data.isEmpty()) {
50 | int oldSize = mData.size() - 1;
51 | mData.addAll(data);
52 | notifyItemRangeChanged(oldSize, mData.size());
53 | notifyOnSizeChanged();
54 | }
55 | }
56 |
57 | public boolean removeData(@NonNull O o) {
58 | int pos = mData.indexOf(o);
59 | if (pos != -1) {
60 | mData.remove(o);
61 | notifyItemRemoved(pos);
62 | notifyOnSizeChanged();
63 | return true;
64 | }
65 | return false;
66 | }
67 |
68 | public void setData(List data) {
69 | if (data != null) {
70 | mData = data;
71 | notifyDataSetChanged();
72 | notifyOnSizeChanged();
73 | }
74 | }
75 |
76 | public void clearData() {
77 | mData.clear();
78 | notifyDataSetChanged();
79 | notifyOnSizeChanged();
80 | }
81 |
82 | private void notifyOnSizeChanged() {
83 | if (mOnSizeChangedListener != null) {
84 | mOnSizeChangedListener.onSizeChanged(mData.size());
85 | }
86 | }
87 |
88 | public void setOnSizeChangedListener(OnSizeChangedListener listener) {
89 | mOnSizeChangedListener = listener;
90 | }
91 |
92 | public interface OnSizeChangedListener {
93 | void onSizeChanged(int currentSize);
94 | }
95 |
96 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/test/viewtest/adapters/ImageAdapter.java:
--------------------------------------------------------------------------------
1 | package com.test.viewtest.adapters;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 | import android.widget.Toast;
10 |
11 | import com.bumptech.glide.Glide;
12 | import com.test.viewtest.R;
13 |
14 | import java.util.List;
15 |
16 | /**
17 | * Created by wuyr on 3/8/18 10:40 AM.
18 | */
19 |
20 | public class ImageAdapter extends BaseAdapter {
21 |
22 | public ImageAdapter(Context context, List data, int layoutId) {
23 | super(context, data, layoutId);
24 | }
25 |
26 | @Override
27 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
28 | return new ViewHolder(mLayoutInflater.inflate(mLayoutId, parent, false));
29 | }
30 |
31 | @Override
32 | public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
33 | Glide.with(mContext).load(mData.get(position)).into(holder.imageView);
34 | holder.imageView.setOnClickListener(v -> Toast.makeText(mContext, holder.getAdapterPosition() + " clicked", Toast.LENGTH_SHORT).show());
35 | }
36 |
37 | static class ViewHolder extends RecyclerView.ViewHolder {
38 |
39 | ImageView imageView;
40 |
41 | ViewHolder(View itemView) {
42 | super(itemView);
43 | imageView = itemView.findViewById(R.id.image_view);
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/test/viewtest/utils/ImmerseUtil.java:
--------------------------------------------------------------------------------
1 | package com.test.viewtest.utils;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.os.Build;
6 | import android.util.Log;
7 |
8 | import java.lang.reflect.Method;
9 |
10 | /**
11 | * Created by wuyr on 2/21/16 4:00 PM.
12 | */
13 | /*
14 | * 状态栏沉浸工具类
15 | * */
16 | public class ImmerseUtil {
17 |
18 | private static final String STATUS_BAR_HEIGHT = "status_bar_height",
19 | NAVIGATION_BAT_HEIGHT = "navigation_bar_height",
20 | DIMEN = "dimen", ANDROID = "android";
21 |
22 | public static boolean isHasNavigationBar(Context context) {
23 | boolean isHasNavigationBar = false;
24 | Resources rs = context.getResources();
25 | int id = rs.getIdentifier("config_showNavigationBar", "bool", ANDROID);
26 | if (id > 0)
27 | isHasNavigationBar = rs.getBoolean(id);
28 | try {
29 | Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
30 | Method m = systemPropertiesClass.getMethod("get", String.class);
31 | String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
32 | if ("1".equals(navBarOverride)) {
33 | isHasNavigationBar = false;
34 | } else if ("0".equals(navBarOverride)) {
35 | isHasNavigationBar = true;
36 | }
37 | } catch (Exception e) {
38 | Log.w(ImmerseUtil.class.getSimpleName(), e.toString(), e);
39 | }
40 | return isHasNavigationBar;
41 | }
42 |
43 | public static int getNavigationBarHeight(Context context) {
44 | int navigationBarHeight = 0;
45 | Resources rs = context.getResources();
46 | int id = rs.getIdentifier(NAVIGATION_BAT_HEIGHT, DIMEN, ANDROID);
47 | if (id > 0 && isHasNavigationBar(context))
48 | navigationBarHeight = rs.getDimensionPixelSize(id);
49 | return navigationBarHeight;
50 | }
51 |
52 | public static int getStatusBarHeight(Context context) {
53 | int result = 0;
54 | try {
55 | int resourceId = context.getResources().getIdentifier(STATUS_BAR_HEIGHT, DIMEN, ANDROID);
56 | if (resourceId > 0) {
57 | result = context.getResources().getDimensionPixelSize(resourceId);
58 | }
59 | } catch (Exception e) {
60 | e.printStackTrace();
61 | }
62 | return result;
63 | }
64 |
65 | public static boolean isAboveKITKAT() {
66 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/test/viewtest/utils/LogUtil.java:
--------------------------------------------------------------------------------
1 | package com.test.viewtest.utils;
2 |
3 | import android.support.annotation.IntDef;
4 | import android.util.Log;
5 |
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 |
9 | /**
10 | * Created by wuyr on 6/8/16 6:54 PM.
11 | */
12 | @SuppressWarnings({"unused", "WeakerAccess", "SameParameterValue"})
13 | public class LogUtil {
14 |
15 | public static final int VERBOSE = 1, DEBUG = 2, INFO = 3, WARN = 4, ERROR = 5;
16 | private static boolean isDebugOn, isShowClassName;
17 | private static int debugLevel = DEBUG;
18 |
19 | public static void setDebugOn(boolean isDebugOn) {
20 | LogUtil.isDebugOn = isDebugOn;
21 | LogUtil.isShowClassName = true;
22 | }
23 |
24 | public static void setIsShowClassName(boolean isShowClassName) {
25 | LogUtil.isShowClassName = isShowClassName;
26 | }
27 |
28 | public static void setDebugLevel(@DEBUG_LEVEL int l) {
29 | debugLevel = l;
30 | setDebugOn(true);
31 | }
32 |
33 | public static void print(Object s) {
34 | print(null, s);
35 | }
36 |
37 | public static void printf(String format, Object... args) {
38 | print(format, args);
39 | }
40 |
41 | private static void print(String format, Object... args) {
42 | if (isDebugOn) {
43 | if (args == null || args.length == 0) {
44 | return;
45 | }
46 | StackTraceElement element = Thread.currentThread().getStackTrace()[4];
47 | String tag = isShowClassName ? String.format("%s-->%s", element.getClassName(), element.getMethodName()) : element.getMethodName();
48 | String msg = format != null ? String.format(format, args) : String.valueOf(args[0]);
49 | switch (debugLevel) {
50 | case VERBOSE:
51 | Log.v(tag, msg);
52 | break;
53 | case DEBUG:
54 | Log.d(tag, msg);
55 | break;
56 | case INFO:
57 | Log.i(tag, msg);
58 | break;
59 | case WARN:
60 | Log.w(tag, msg);
61 | break;
62 | case ERROR:
63 | Log.e(tag, msg);
64 | break;
65 | default:
66 | break;
67 | }
68 | }
69 | }
70 |
71 | @IntDef({VERBOSE, DEBUG, INFO, WARN, ERROR})
72 | @Retention(RetentionPolicy.SOURCE)
73 | private @interface DEBUG_LEVEL {
74 | }
75 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/test/viewtest/views/CoffinLayout.java:
--------------------------------------------------------------------------------
1 | package com.test.viewtest.views;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Color;
7 | import android.graphics.drawable.GradientDrawable;
8 | import android.util.AttributeSet;
9 | import android.view.LayoutInflater;
10 | import android.view.MotionEvent;
11 | import android.view.VelocityTracker;
12 | import android.view.View;
13 | import android.view.ViewConfiguration;
14 | import android.view.ViewGroup;
15 | import android.widget.FrameLayout;
16 | import android.widget.LinearLayout;
17 | import android.widget.Scroller;
18 |
19 | import com.test.viewtest.R;
20 |
21 | /**
22 | * Created by wuyr on 18-3-8 下午10:36.
23 | */
24 |
25 | /**
26 | * 棺材布局: 滑盖那种
27 | */
28 | public class CoffinLayout extends ViewGroup {
29 |
30 | public static final int STATE_HALF = 0, //棺材盖半开状态
31 | STATE_COVER = 1,//棺材盖盖住
32 | STATE_NAKED = 2, //棺材盖打开
33 | STATE_OPENING = 3,//棺材盖正在打开
34 | STATE_CLOSING = 4;//棺材盖正在关闭
35 |
36 | private static final int ANIMATION_DURATION = 500;//过渡动画时长
37 | private int mCurrentStatus;//当前状态
38 | private Scroller mScroller;//平滑滚动辅助
39 | private VelocityTracker mVelocityTracker;//手指滑动速率搜集
40 | private View mElevationView;//阴影view
41 | private View mLidView;//棺材盖
42 | private View mBottomView;//棺材底
43 | private View mResidualView;//棺材盖打开后, 显示在底部的view (一般用来点击合上棺材盖)
44 | private View mTransitionView;//棺材盖下面那一张白布 (可以设置颜色)
45 | private View mHeaderView;//头部
46 | private View mTopBar;//顶栏
47 | private View mBottomBar;//底栏
48 | private int mTouchSlop;//触发滑动的最小距离
49 | private int mLidOffset;//棺材盖的偏移量
50 | private int mLidElevation;//棺材盖阴影
51 | private int mTriggerOffset;//触发棺材盖开关的距离
52 | private int mLastY;//记录上次触摸事件的y坐标
53 | private int mScrollOffset;//记录Scroller上次的y坐标
54 | private int mLidViewOffset,//棺材盖的当前偏移量
55 | mBottomViewOffset, //棺材底的当前偏移量
56 | mHeaderViewOffset;//头部的当前偏移量
57 | private int mTransitionColor;//过渡颜色
58 | private boolean isNewScroll;//用来判断是否要打断上一次未完成的动画 true:打断, 反之
59 | private boolean isBeingDragged;//已经开始了拖动
60 | private OnStateChangedListener mOnStateChangedListener;//状态变更的监听
61 |
62 | public CoffinLayout(Context context) {
63 | this(context, null);
64 | }
65 |
66 | public CoffinLayout(Context context, AttributeSet attrs) {
67 | this(context, attrs, 0);
68 | }
69 |
70 | public CoffinLayout(Context context, AttributeSet attrs, int defStyleAttr) {
71 | super(context, attrs, defStyleAttr);
72 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CoffinLayout, defStyleAttr, 0);
73 | mLidElevation = a.getDimensionPixelOffset(R.styleable.CoffinLayout_lid_elevation, 0);
74 | mLidOffset = a.getDimensionPixelOffset(R.styleable.CoffinLayout_lid_offset, 0);
75 | int resId;
76 | resId = a.getResourceId(R.styleable.CoffinLayout_residual_view, 0);
77 | if (resId > 0) {
78 | mResidualView = LayoutInflater.from(context).inflate(resId, this, false);
79 | }
80 | resId = a.getResourceId(R.styleable.CoffinLayout_header_view, 0);
81 | if (resId > 0) {
82 | mHeaderView = LayoutInflater.from(context).inflate(resId, this, false);
83 | }
84 | resId = a.getResourceId(R.styleable.CoffinLayout_top_bar, 0);
85 | if (resId > 0) {
86 | mTopBar = LayoutInflater.from(context).inflate(resId, this, false);
87 | }
88 | resId = a.getResourceId(R.styleable.CoffinLayout_bottom_bar, 0);
89 | if (resId > 0) {
90 | mBottomBar = LayoutInflater.from(context).inflate(resId, this, false);
91 | }
92 | mTransitionColor = a.getColor(R.styleable.CoffinLayout_transition_color, Color.WHITE);
93 | mLidOffset -= mLidElevation;
94 | mTriggerOffset = a.getDimensionPixelOffset(R.styleable.CoffinLayout_trigger_open_offset, mLidOffset / 2);
95 | mTriggerOffset += mLidOffset;
96 | a.recycle();
97 | final ViewConfiguration configuration = ViewConfiguration.get(context);
98 | mTouchSlop = configuration.getScaledTouchSlop();
99 | init();
100 | }
101 |
102 | private void init() {
103 | GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, new int[]{0x88444444, 0x00000000});
104 | mElevationView = new View(getContext());
105 | LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, mLidElevation);
106 | mElevationView.setLayoutParams(layoutParams);
107 | mElevationView.setBackground(gradientDrawable);
108 | mScroller = new Scroller(getContext());
109 | mVelocityTracker = VelocityTracker.obtain();
110 | mTransitionView = new View(getContext());
111 | mTransitionView.setBackgroundColor(mTransitionColor);
112 | }
113 |
114 | /**
115 | * 打开棺材盖
116 | */
117 | public void openCoffin() {
118 | if (mCurrentStatus == STATE_OPENING) {
119 | return;
120 | }
121 | abortScrollerAnimation();
122 | isNewScroll = true;
123 | int offset = getBottom() - mLidView.getTop();
124 | mScroller.startScroll(0, 0, 0, offset, ANIMATION_DURATION);
125 | mCurrentStatus = STATE_OPENING;
126 | notifyListener();
127 | invalidate();
128 | if (mBottomBar != null) {
129 | hideBottomBar();
130 | }
131 | if (mTopBar != null) {
132 | if (mTopBar.getTranslationY() == 0) {
133 | hideTopBar();
134 | } else{
135 | postDelayed(() -> {
136 | if (mTopBar.getTranslationY() == 0) {
137 | hideTopBar();
138 | }
139 | }, ANIMATION_DURATION);
140 | }
141 | }
142 | }
143 |
144 | /**
145 | * 关闭棺材盖
146 | */
147 | public void closeCoffin() {
148 | if (mCurrentStatus == STATE_CLOSING) {
149 | return;
150 | }
151 | abortScrollerAnimation();
152 | isNewScroll = true;
153 | int offset = mLidOffset - mLidView.getTop();
154 | mScroller.startScroll(0, 0, 0, offset, ANIMATION_DURATION);
155 | mTransitionView.setVisibility(VISIBLE);
156 | mHeaderView.setVisibility(VISIBLE);
157 | if (mCurrentStatus == STATE_NAKED) {
158 | showHeaderView();
159 | }
160 | mCurrentStatus = STATE_CLOSING;
161 | notifyListener();
162 | invalidate();
163 | if (mBottomBar != null && mBottomBar.getTranslationY() > 0) {
164 | showBottomBar();
165 | }
166 | if (mTopBar != null && mTopBar.getTranslationY() < 0) {
167 | showTopBar();
168 | }
169 | }
170 |
171 | @Override
172 | public boolean onTouchEvent(MotionEvent event) {
173 | mVelocityTracker.addMovement(event);
174 | int y = (int) event.getY();
175 | switch (event.getAction()) {
176 | case MotionEvent.ACTION_DOWN:
177 | if (!isLidOpeningOrClosing()) {
178 | abortScrollerAnimation();
179 | } else {
180 | return false;
181 | }
182 | mLastY = y;
183 | break;
184 | case MotionEvent.ACTION_MOVE:
185 | if (mCurrentStatus == STATE_NAKED) {
186 | offsetBottomView(y);
187 | } else {
188 | offsetLidView(y);
189 | }
190 | if (mCurrentStatus != STATE_NAKED) {
191 | mVelocityTracker.computeCurrentVelocity(1000);
192 | float velocityY = mVelocityTracker.getYVelocity();
193 | //根据手指滑动的速率和方向来判断是否要隐藏或显示TopBar
194 | if (Math.abs(velocityY) > 4000) {
195 | if (velocityY > 0) {
196 | if (mTopBar != null && mTopBar.getTranslationY() == -mTopBar.getLayoutParams().height) {
197 | showTopBar();
198 | }
199 | } else {
200 | if (mTopBar != null && mTopBar.getTranslationY() == 0) {
201 | hideTopBar();
202 | }
203 | }
204 | }
205 | }
206 | break;
207 | case MotionEvent.ACTION_UP:
208 | case MotionEvent.ACTION_OUTSIDE:
209 | case MotionEvent.ACTION_CANCEL:
210 | boolean isHandle = false;
211 | if (mCurrentStatus == STATE_HALF) {
212 | //大于触发距离, 则打开棺材盖, 反之
213 | if (mLidView.getTop() >= mTriggerOffset) {
214 | openCoffin();
215 | isHandle = true;
216 | } else if (mLidView.getTop() > mLidOffset) {
217 | closeCoffin();
218 | isHandle = true;
219 | }
220 | }
221 | //没有触发打开或关闭棺材盖的动画, 则开始惯性滚动
222 | if (!isHandle) {
223 | mVelocityTracker.computeCurrentVelocity(1000);
224 | mScroller.fling(0, 0, 0, (int) mVelocityTracker.getYVelocity(),
225 | 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
226 | invalidate();
227 | }
228 | //标记状态
229 | isBeingDragged = false;
230 | break;
231 | default:
232 | break;
233 | }
234 | return true;
235 | }
236 |
237 | @Override
238 | public boolean onInterceptTouchEvent(MotionEvent ev) {
239 | //正在播放开关动画: 拦截
240 | if (isLidOpeningOrClosing()) {
241 | return true;
242 | }
243 | //已经开始拖动: 拦截
244 | final int action = ev.getAction();
245 | if ((action == MotionEvent.ACTION_MOVE) && (isBeingDragged)) {
246 | return true;
247 | }
248 | //爸爸需要拦截: 拦截
249 | if (super.onInterceptTouchEvent(ev)) {
250 | return true;
251 | }
252 | //不能拖动: 放行
253 | if (!canScroll()) {
254 | return false;
255 | }
256 | int y = (int) ev.getY();
257 | switch (ev.getAction()) {
258 | case MotionEvent.ACTION_DOWN:
259 | //停止惯性滚动并刷新y坐标
260 | if (!isLidOpeningOrClosing()) {
261 | abortScrollerAnimation();
262 | }
263 | mLastY = y;
264 | break;
265 | case MotionEvent.ACTION_MOVE:
266 | int offset = y - mLastY;
267 | //判断是否触发拖动事件
268 | if (Math.abs(offset) > mTouchSlop) {
269 | mLastY = y;
270 | isBeingDragged = true;
271 | }
272 | break;
273 | case MotionEvent.ACTION_UP:
274 | case MotionEvent.ACTION_CANCEL:
275 | case MotionEvent.ACTION_OUTSIDE:
276 | isBeingDragged = false;
277 | break;
278 | }
279 | return isBeingDragged;
280 | }
281 |
282 | @Override
283 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
284 | for (int i = 0; i < getChildCount(); i++) {
285 | View view = getChildAt(i);
286 | //子view想要多高,就给它多高
287 | view.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
288 | }
289 | //测量棺材底
290 | View view = ((ViewGroup) mBottomView).getChildAt(0);
291 | if (view != null) {
292 | view.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
293 | }
294 | mTransitionView.measure(widthMeasureSpec, heightMeasureSpec);
295 | setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
296 | }
297 |
298 | @Override
299 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
300 | switch (getChildCount()) {
301 | case 6:
302 | //BottomBar当然是放在底部了
303 | mBottomBar.layout(0, b - mBottomBar.getLayoutParams().height, r, b);
304 | case 5:
305 | //TopBar当然是顶部了
306 | mTopBar.layout(0, 0, r, mTopBar.getLayoutParams().height);
307 | case 4:
308 | //顶部 + 偏移量
309 | mHeaderView.layout(0, mHeaderViewOffset, r, mHeaderViewOffset + mHeaderView.getLayoutParams().height);
310 | mHeaderView.setTranslationY(0);
311 | case 3:
312 | case 2:
313 | //棺材盖: 棺材盖固定的偏移量 + 当前的偏移量
314 | mLidView.layout(0, mLidOffset + mLidViewOffset, r, mLidOffset + mLidViewOffset + mLidView.getMeasuredHeight());
315 | if (mResidualView != null) {
316 | //棺材盖上面用来切换开关的view: 放在底部
317 | mResidualView.layout(0, b, r, b + mResidualView.getLayoutParams().height);
318 | }
319 | case 1:
320 | //棺材底: 顶部 + 偏移量
321 | mBottomView.layout(0, mBottomViewOffset, r, mBottomViewOffset + mBottomView.getMeasuredHeight());
322 | //过渡view: 与棺材底偏移量相反 (因为它要始终显示在屏幕内)
323 | mTransitionView.layout(0, -mBottomViewOffset, r, -mBottomViewOffset + mTransitionView.getHeight());
324 | break;
325 | default:
326 | break;
327 | }
328 | }
329 |
330 | /**
331 | * 计算平滑滚动
332 | */
333 | @Override
334 | public void computeScroll() {
335 | if (mScroller.computeScrollOffset()) {
336 | int y = mScroller.getCurrY();
337 | //是新的一轮则刷新offset
338 | if (isNewScroll) {
339 | isNewScroll = false;
340 | mScrollOffset = y;
341 | }
342 | //未开盖: 滚动棺材盖
343 | if (mCurrentStatus != STATE_NAKED) {
344 | //判断是否还可以滚动
345 | if (mLidView != null && mLidView.getBottom() >= getBottom()) {
346 | int offset = y - mScrollOffset;
347 | //判断是否越界: 如果越界,则本次偏移量为可以滑动的最大值
348 | if (mLidView.getBottom() + offset < getBottom()) {
349 | offset = getBottom() - mLidView.getBottom();
350 | } else if (mScroller.getCurrVelocity() > 0 && offset > 0) {//手指滑动, 并且是向下滑
351 | if (mLidView.getTop() + offset >= mLidOffset && !isLidOpeningOrClosing()) {
352 | offset = mLidOffset - mLidView.getTop();
353 | }
354 | }
355 | offsetChildView(offset);
356 | }
357 | } else {//已开盖: 滚动棺材底
358 | //判断是否还可以滚动
359 | if (mBottomView != null && mBottomView.getBottom() >= getBottom()
360 | && mBottomView.getTop() <= getTop()) {
361 | int offset = y - mScrollOffset;
362 | //判断是否越界: 如果越界,则本次偏移量为可以滑动的最大值
363 | if (mBottomView.getBottom() + offset < getBottom()) {
364 | offset = getBottom() - mBottomView.getBottom();
365 | } else if (mBottomView.getTop() + offset > getTop()) {
366 | offset = getTop() - mBottomView.getTop();
367 | }
368 | mBottomViewOffset += offset;
369 | mBottomView.offsetTopAndBottom(offset);
370 | mTransitionView.offsetTopAndBottom(-offset);
371 | }
372 | }
373 | mScrollOffset = y;
374 | invalidate();
375 | }
376 | if (mScroller.isFinished()) {
377 | isNewScroll = true;
378 | //滚动结束, 更新状态
379 | if (mCurrentStatus == STATE_OPENING) {
380 | mTransitionView.setVisibility(INVISIBLE);
381 | mHeaderView.setVisibility(INVISIBLE);
382 | if (mResidualView != null) {
383 | showResidualView();
384 | }
385 | mCurrentStatus = STATE_NAKED;
386 | notifyListener();
387 | } else if (mCurrentStatus == STATE_CLOSING) {
388 | int offset = getTop() - mBottomView.getTop();
389 | mBottomViewOffset += offset;
390 | mBottomView.offsetTopAndBottom(offset);
391 | mTransitionView.offsetTopAndBottom(-offset);
392 | if (mResidualView != null) {
393 | mResidualView.setTranslationY(0);
394 | }
395 | mCurrentStatus = STATE_HALF;
396 | notifyListener();
397 | }
398 | }
399 | }
400 |
401 | private void addTopBar(int index) {
402 | if (mTopBar != null) {
403 | LayoutParams layoutParams = mTopBar.getLayoutParams();
404 | if (layoutParams == null) {
405 | layoutParams = generateDefaultLayoutParams();
406 | }
407 | super.addView(mTopBar, index, layoutParams);
408 | setTopBarBackgroundAlpha(1);
409 | }
410 | }
411 |
412 | private void addBottomBar(int index) {
413 | if (mBottomBar != null) {
414 | LayoutParams layoutParams = mBottomBar.getLayoutParams();
415 | if (layoutParams == null) {
416 | layoutParams = generateDefaultLayoutParams();
417 | }
418 | super.addView(mBottomBar, index, layoutParams);
419 | }
420 | }
421 |
422 | private void addHeaderView(int index) {
423 | if (mHeaderView != null) {
424 | LayoutParams layoutParams = mHeaderView.getLayoutParams();
425 | if (layoutParams == null) {
426 | layoutParams = generateDefaultLayoutParams();
427 | }
428 | super.addView(mHeaderView, index, layoutParams);
429 | }
430 | }
431 |
432 | private void addResidualView(int index) {
433 | if (mResidualView != null) {
434 | LayoutParams layoutParams = mResidualView.getLayoutParams();
435 | if (layoutParams == null) {
436 | layoutParams = generateDefaultLayoutParams();
437 | }
438 | super.addView(mResidualView, index, layoutParams);
439 | }
440 | }
441 |
442 | /**
443 | * 给他包装一下, 加上一个过渡的view
444 | *
445 | * @param view 棺材底
446 | * @return 包装后的棺材底
447 | */
448 | private View packingBottomView(View view) {
449 | if (mTransitionView != null && view != null) {
450 | FrameLayout frameLayout = new FrameLayout(getContext());
451 | frameLayout.addView(view);
452 | frameLayout.addView(mTransitionView);
453 | return frameLayout;
454 | }
455 | return null;
456 | }
457 |
458 | /**
459 | * 给他包装一下, 加上阴影
460 | *
461 | * @param view 棺材盖
462 | * @return 包装后的棺材盖
463 | */
464 | private View packingLidView(View view) {
465 | if (mElevationView != null && view != null) {
466 | LinearLayout linearLayout = new LinearLayout(getContext());
467 | linearLayout.setOrientation(LinearLayout.VERTICAL);
468 | linearLayout.addView(mElevationView);
469 | linearLayout.addView(view);
470 | return linearLayout;
471 | }
472 | return null;
473 | }
474 |
475 | public View getTopBar() {
476 | return mTopBar;
477 | }
478 |
479 | public View getBottomBar() {
480 | return mBottomBar;
481 | }
482 |
483 | public View getHeaderView() {
484 | return mHeaderView;
485 | }
486 |
487 | public View getResidualView() {
488 | return mResidualView;
489 | }
490 |
491 | public boolean isLidOpeningOrClosing() {
492 | return mCurrentStatus == STATE_OPENING || mCurrentStatus == STATE_CLOSING;
493 | }
494 |
495 | public int getCurrentStatus() {
496 | return mCurrentStatus;
497 | }
498 |
499 | public int getLidViewOffset() {
500 | return mLidViewOffset;
501 | }
502 |
503 | public void showBottomBar() {
504 | startValueAnimation(mBottomBar, mBottomBar.getLayoutParams().height, 0);
505 | }
506 |
507 | public void hideBottomBar() {
508 | startValueAnimation(mBottomBar, 0, mBottomBar.getLayoutParams().height);
509 | }
510 |
511 | private void showResidualView() {
512 | startValueAnimation(mResidualView, 0, -mResidualView.getLayoutParams().height);
513 | }
514 |
515 | private void showHeaderView() {
516 | startValueAnimation(mHeaderView, Math.abs(mBottomView.getTop()) >
517 | mHeaderView.getHeight() ? -mHeaderView.getHeight() : mBottomView.getTop(), 0);
518 | }
519 |
520 | private void showTopBar() {
521 | startValueAnimation(mTopBar, -mTopBar.getLayoutParams().height, 0);
522 | }
523 |
524 | private void hideTopBar() {
525 | startValueAnimation(mTopBar, 0, -mTopBar.getLayoutParams().height);
526 | }
527 |
528 | /**
529 | * 执行动画
530 | *
531 | * @param target 要执行动画的view
532 | * @param startY 开始值
533 | * @param endY 结束值
534 | */
535 | private void startValueAnimation(View target, int startY, int endY) {
536 | ValueAnimator animator = ValueAnimator.ofInt(startY, endY).setDuration(ANIMATION_DURATION);
537 | animator.addUpdateListener(animation -> target.setTranslationY((int) animation.getAnimatedValue()));
538 | animator.start();
539 | }
540 |
541 | /**
542 | * 打断滚动动画
543 | */
544 | private void abortScrollerAnimation() {
545 | if (!mScroller.isFinished()) {
546 | mScroller.abortAnimation();
547 | }
548 | }
549 |
550 | /**
551 | * 设置TopBar的不透明度
552 | *
553 | * @param percent 透明度的百分比
554 | */
555 | private void setTopBarBackgroundAlpha(float percent) {
556 | if (mTopBar != null) {
557 | percent = 1F - percent;
558 | mTopBar.getBackground().setAlpha((int) (255F * percent));
559 | }
560 | }
561 |
562 | /**
563 | * 判断是否可以滑动
564 | */
565 | private boolean canScroll() {
566 | return mCurrentStatus != STATE_NAKED && (mLidView.getTop() < getTop() || mLidView.getBottom() > getBottom())
567 | || mCurrentStatus == STATE_NAKED && (mBottomView.getTop() < getTop() || mBottomView.getBottom() > getBottom());
568 | }
569 |
570 | private void notifyListener() {
571 | if (mOnStateChangedListener != null) {
572 | mOnStateChangedListener.onStateChanged(mCurrentStatus);
573 | }
574 | }
575 |
576 | /**
577 | * 更新棺材盖的位置
578 | *
579 | * @param y 偏移量
580 | */
581 | private void offsetLidView(int y) {
582 | if (mLidView != null && mLidView.getBottom() >= getBottom()) {
583 | int offset = y - mLastY;
584 | //判断是否越界
585 | if (mLidView.getBottom() + offset < getBottom()) {
586 | offset = getBottom() - mLidView.getBottom();
587 | }
588 | if (offset > 0 && mLidView.getTop() > mLidOffset) {
589 | offset /= 2;
590 | }
591 | //更新需要联动的其他view
592 | offsetChildView(offset);
593 | //更新状态
594 | int newState = mLidView.getTop() <= getTop() ? STATE_COVER : STATE_HALF;
595 | if (mCurrentStatus != newState) {
596 | mCurrentStatus = newState;
597 | notifyListener();
598 | }
599 | }
600 | mLastY = y;
601 | }
602 |
603 | /**
604 | * 更新棺材盖和其他需要联动的View的位置
605 | *
606 | * @param offset 偏移量
607 | */
608 | private void offsetChildView(int offset) {
609 | //不是正在打开或关闭状态,并且棺材盖当前位置高于默认的偏移量
610 | if (!isLidOpeningOrClosing() && mLidView.getTop() < mLidOffset) {
611 | int bottomViewOffset = offset / 2;//损失一半
612 | //判断越界
613 | if (mBottomView.getTop() > getTop() || mBottomView.getTop() + bottomViewOffset > getTop()) {
614 | bottomViewOffset = getTop() - mBottomView.getTop();
615 | }
616 | //更新BottomView和HeaderView的位置
617 | mBottomViewOffset += bottomViewOffset;
618 | mBottomView.offsetTopAndBottom(bottomViewOffset);
619 | mHeaderViewOffset += bottomViewOffset;
620 | mHeaderView.offsetTopAndBottom(bottomViewOffset);
621 | mTransitionView.offsetTopAndBottom(-bottomViewOffset);
622 | }
623 | //更新棺材盖的位置
624 | mLidViewOffset += offset;
625 | mLidView.offsetTopAndBottom(offset);
626 | //更新TopBar的透明度
627 | float percent = (float) mLidViewOffset / (getBottom() - mLidOffset);
628 | mTransitionView.setAlpha(1F - percent);
629 | percent = (float) (mLidView.getTop() - mTopBar.getHeight()) / (mLidOffset - mTopBar.getHeight());
630 | if (percent > 1F) {
631 | percent = 1F;
632 | }
633 | if (percent < 0) {
634 | percent = 0;
635 | }
636 | setTopBarBackgroundAlpha(percent);
637 | }
638 |
639 | /**
640 | * 更新棺材盖的位置
641 | *
642 | * @param y 偏移量
643 | */
644 | private void offsetBottomView(int y) {
645 | //判断是否还能滚动
646 | if (mBottomView != null && mBottomView.getBottom() >= getBottom()
647 | && mBottomView.getTop() <= getTop()) {
648 | int offset = y - mLastY;
649 | //判断越界
650 | if (mBottomView.getBottom() + offset < getBottom()) {
651 | offset = getBottom() - mBottomView.getBottom();
652 | } else if (mBottomView.getTop() + offset > getTop()) {
653 | offset = getTop() - mBottomView.getTop();
654 | }
655 | //更新位置
656 | mBottomViewOffset += offset;
657 | mBottomView.offsetTopAndBottom(offset);
658 | mTransitionView.offsetTopAndBottom(-offset);
659 | }
660 | mLastY = y;
661 | }
662 |
663 | @Override
664 | public void addView(View child) {
665 | addView(child, -1);
666 | }
667 |
668 | @Override
669 | public void addView(View child, int index) {
670 | if (child == null) {
671 | throw new IllegalArgumentException("Cannot add a null child view to a ViewGroup");
672 | }
673 | LayoutParams params = child.getLayoutParams();
674 | if (params == null) {
675 | params = generateDefaultLayoutParams();
676 | if (params == null) {
677 | throw new IllegalArgumentException("generateDefaultLayoutParams() cannot return null");
678 | }
679 | }
680 | addView(child, index, params);
681 | }
682 |
683 | @Override
684 | public void addView(View child, int width, int height) {
685 | final LayoutParams params = generateDefaultLayoutParams();
686 | params.width = width;
687 | params.height = height;
688 | addView(child, -1, params);
689 | }
690 |
691 | @Override
692 | public void addView(View child, ViewGroup.LayoutParams params) {
693 | addView(child, -1, params);
694 | }
695 |
696 | @Override
697 | public void addView(View child, int index, LayoutParams params) {
698 | switch (getChildCount()) {
699 | case 0:
700 | mBottomView = child = packingBottomView(child);
701 | break;
702 | case 1:
703 | addResidualView(index);
704 | mLidView = child = packingLidView(child);
705 | addHeaderView(index);
706 | if (child != null) {
707 | super.addView(child, index, params);
708 | }
709 | addTopBar(index);
710 | addBottomBar(index);
711 | return;
712 | case 6:
713 | throw new IllegalStateException("CoffinLayout child can't > 2");
714 | default:
715 | break;
716 | }
717 | if (child != null) {
718 | super.addView(child, index, params);
719 | }
720 | }
721 |
722 | public void setOnStateChangedListener(OnStateChangedListener listener) {
723 | mOnStateChangedListener = listener;
724 | }
725 |
726 | public interface OnStateChangedListener {
727 | void onStateChanged(int newState);
728 | }
729 | }
730 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_0.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_0.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_1.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_1.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_10.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_10.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_11.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_11.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_12.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_12.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_13.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_13.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_14.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_14.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_15.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_15.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_16.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_16.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_17.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_17.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_18.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_18.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_19.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_19.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_2.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_2.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_3.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_3.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_4.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_4.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_5.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_5.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_6.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_6.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_7.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_7.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_8.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_8.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_9.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/drawable/ic_9.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/act_main_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
16 |
20 |
21 |
27 |
28 |
32 |
33 |
34 |
38 |
39 |
44 |
45 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/adapter_item_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/adapter_item_view2.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/bottom_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/header_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/residual_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/top_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ViewTest
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/test/viewtest/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.test.viewtest;
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 |
5 | repositories {
6 | google()
7 | jcenter()
8 | mavenCentral()
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.0.1'
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/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/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 06 22:14:35 CST 2018
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-4.1-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 |
--------------------------------------------------------------------------------
/preview.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuyr/CoffinLayout/506ea9533b868725f8a12fe1e9a140fe56a8cc03/preview.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------