├── .github
└── FUNDING.yml
├── LICENSE
├── README.md
├── app
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── ccy
│ │ └── focuslayoutmanagerproject
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── ccy
│ │ │ └── focuslayoutmanagerproject
│ │ │ ├── DetailActivity.java
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── h1.jpg
│ │ ├── h2.jpg
│ │ ├── h3.jpg
│ │ ├── h4.jpg
│ │ ├── h5.jpg
│ │ ├── h6.jpg
│ │ ├── h7.jpg
│ │ ├── ic_launcher_background.xml
│ │ ├── v1.jpg
│ │ ├── v2.jpg
│ │ ├── v3.jpg
│ │ ├── v4.jpg
│ │ ├── v5.jpg
│ │ ├── v6.jpg
│ │ └── v7.jpg
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── detail_act.xml
│ │ └── item_card.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
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── ccy
│ └── focuslayoutmanagerproject
│ └── ExampleUnitTest.java
├── build.gradle
├── ccy_ identity
├── focuslayoutmanager
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── ccy
│ │ └── focuslayoutmanager
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── ccy
│ │ │ └── focuslayoutmanager
│ │ │ └── FocusLayoutManager.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── ccy
│ └── focuslayoutmanager
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── pic
├── 341561604648_.pic.jpg
├── detail.png
├── gif_hor.gif
├── gif_hor_2.gif
├── gif_mac_os.gif
├── gif_ver.gif
├── hor.jpg
└── ver.jpg
└── settings.gradle
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: https://github.com/CCY0122/FocusLayoutManager/blob/master/pic/341561604648_.pic.jpg
13 |
--------------------------------------------------------------------------------
/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 | [  ](https://bintray.com/ccy01220122/FocusLayoutManager/FocusLayoutManager/1.0.2/link)
2 | # FocusLayoutManager
3 | 有焦点item的水平/垂直滚动RecyclerView-LayoutManager。仿Android豆瓣书影音“推荐“频道列表布局
4 |
5 |
6 | ## 效果
7 |
8 |
**截图:**
9 |
10 |
11 |
12 |
13 |
**GIF:**
14 | 
15 | 
16 |
17 |
可自己监听滚动编写效果,如修改成仿MacOS文件浏览:
18 |
19 |
20 |
21 |
22 | ## 依赖
23 |
24 | ```
25 | implementation 'com.ccy:FocusLayoutManager:1.0.2'
26 | // (or api)
27 | ```
28 |
29 | ## 使用
30 |
31 |
32 | ```java
33 | focusLayoutManager =
34 | new FocusLayoutManager.Builder()
35 | .layerPadding(dp2px(this, 14))
36 | .normalViewGap(dp2px(this, 14))
37 | .focusOrientation(FocusLayoutManager.FOCUS_LEFT)
38 | .isAutoSelect(true)
39 | .maxLayerCount(3)
40 | .setOnFocusChangeListener(new FocusLayoutManager.OnFocusChangeListener() {
41 | @Override
42 | public void onFocusChanged(int focusdPosition, int lastFocusdPosition) {
43 |
44 | }
45 | })
46 | .build();
47 | recyclerView.setLayoutManager(focusLayoutManager);
48 | ```
49 | 各属性意义见图:
50 |
51 |
52 | 注意:因为item在不同区域随着滑动会有不同的缩放(受动画控制),所以实际视觉上堆叠view的间距、普通view的间距未必等于layerPadding、normalViewGap
53 |
54 | #### 调整动画效果:
55 | ```java
56 | new FocusLayoutManager.Builder()
57 | ......
58 | .setSimpleTrasitionListener(new FocusLayoutManager.SimpleTrasitionListener() {
59 | @Override
60 | public float getLayerViewMaxAlpha(int maxLayerCount) {
61 | return super.getLayerViewMaxAlpha(maxLayerCount);
62 | }
63 |
64 | @Override
65 | public float getLayerViewMinAlpha(int maxLayerCount) {
66 | return super.getLayerViewMinAlpha(maxLayerCount);
67 | }
68 |
69 | @Override
70 | public float getLayerChangeRangePercent() {
71 | return super.getLayerChangeRangePercent();
72 | }
73 | //and more
74 |
75 | //更多可重写方法和释义见接口声明
76 | })
77 | .build();
78 | ```
79 |
80 | #### 自定义动画/滚动监听:
81 | 如果你想在滑动时不仅仅改变item的大小、透明度,你有更多的想法,可以监听TrasitionListener,该监听暴露了很多关键布局数据,
82 | ```java
83 |
84 | ......
85 | .setSimpleTrasitionListener(null) //如果默认动画不想要,移除之。or use removeTrasitionlistener(XXX)
86 | .addTrasitionListener(new FocusLayoutManager.TrasitionListener() {
87 | @Override
88 | public void handleLayerView(FocusLayoutManager focusLayoutManager,
89 | View view, int viewLayer,
90 | int maxLayerCount, int position,
91 | float fraction, float offset) {
92 |
93 | }
94 |
95 | @Override
96 | public void handleFocusingView(FocusLayoutManager focusLayoutManager,
97 | View view, int position,
98 | float fraction, float offset) {
99 |
100 | }
101 |
102 | @Override
103 | public void handleNormalView(FocusLayoutManager focusLayoutManager, View view, int position, float fraction, float offset) {
104 |
105 | }
106 | })
107 | ```
108 | 各参数意义见接口注释。
109 | 实际上`SimpleTrasitionListener`内部就会被转为`TrasitionListener`。可参考转换类是怎么做的:`TrasitionListenerConvert`
110 |
111 | ## 源码解析
112 |
113 | [https://blog.csdn.net/ccy0122/article/details/90515386](https://blog.csdn.net/ccy0122/article/details/90515386)
114 |
115 |
116 |
117 |
118 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "ccy.focuslayoutmanagerproject"
7 | minSdkVersion 21
8 | targetSdkVersion 28
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-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | implementation 'com.android.support:appcompat-v7:28.0.0'
24 | testImplementation 'junit:junit:4.12'
25 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
26 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
27 | implementation 'com.android.support:recyclerview-v7:28.0.0'
28 | implementation 'com.android.support:cardview-v7:28.0.0'
29 | implementation 'com.github.bumptech.glide:glide:4.8.0'
30 | annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
31 | implementation project(':focuslayoutmanager')
32 | }
33 |
--------------------------------------------------------------------------------
/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/ccy/focuslayoutmanagerproject/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package ccy.focuslayoutmanagerproject;
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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("ccy.focuslayoutmanagerproject", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/ccy/focuslayoutmanagerproject/DetailActivity.java:
--------------------------------------------------------------------------------
1 | package ccy.focuslayoutmanagerproject;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.Window;
7 | import android.widget.ImageView;
8 |
9 | import com.bumptech.glide.Glide;
10 |
11 | /**
12 | * Created by ccy(17022) on 2019/5/23 上午10:47
13 | */
14 | public class DetailActivity extends AppCompatActivity {
15 |
16 |
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
21 | setContentView(R.layout.detail_act);
22 |
23 | int res = getIntent().getIntExtra("resId",0);
24 | if(res != 0){
25 | Glide.with(this).load(res).into((ImageView) findViewById(R.id.img));
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/ccy/focuslayoutmanagerproject/MainActivity.java:
--------------------------------------------------------------------------------
1 | package ccy.focuslayoutmanagerproject;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.NonNull;
7 | import android.support.v4.app.ActivityOptionsCompat;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.CardView;
10 | import android.support.v7.widget.RecyclerView;
11 | import android.util.Log;
12 | import android.util.TypedValue;
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.view.Window;
17 | import android.widget.CheckBox;
18 | import android.widget.CompoundButton;
19 | import android.widget.EditText;
20 | import android.widget.ImageView;
21 | import android.widget.RadioGroup;
22 | import android.widget.TextView;
23 | import android.widget.Toast;
24 |
25 | import com.bumptech.glide.Glide;
26 |
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | import ccy.focuslayoutmanager.FocusLayoutManager;
31 |
32 | public class MainActivity extends AppCompatActivity {
33 |
34 | public static Toast mToast;
35 | View emptyView;
36 | TextView tvFocusedPos;
37 | CheckBox cbAutoSelect;
38 | CheckBox cbInfinite;
39 | RecyclerView recyclerView;
40 | FocusLayoutManager focusLayoutManager;
41 | Adapter adapter;
42 |
43 | int colors[] = {0xffff0000, 0xff00ff00, 0xff0000ff, 0xffffff00, 0xff00ffff, 0xffff00ff,
44 | 0xffd0d0d0, 0xff000000, 0xffe04900, 0xff900909};
45 | int horRes[] = {R.drawable.h5, R.drawable.h6, R.drawable.h7, R.drawable.h1, R.drawable.h2,
46 | R.drawable.h3, R.drawable.h4, R.drawable.h5, R.drawable.h6, R.drawable.h7,
47 | R.drawable.h5, R.drawable.h6, R.drawable.h7, R.drawable.h1, R.drawable.h2,
48 | R.drawable.h3, R.drawable.h4, R.drawable.h5, R.drawable.h6, R.drawable.h7};
49 | int verRes[] = {R.drawable.v5, R.drawable.v6, R.drawable.v7, R.drawable.v1, R.drawable.v2,
50 | R.drawable.v3, R.drawable.v4, R.drawable.v5, R.drawable.v6, R.drawable.v7};
51 |
52 | List datas;
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
58 | setContentView(R.layout.activity_main);
59 |
60 | recyclerView = findViewById(R.id.rv);
61 | emptyView = findViewById(R.id.empty);
62 | tvFocusedPos = findViewById(R.id.tv_focus_pos);
63 | cbAutoSelect = findViewById(R.id.auto_select_cb);
64 | cbInfinite = findViewById(R.id.infinite_cb);
65 |
66 | focusLayoutManager =
67 | new FocusLayoutManager.Builder()
68 | .layerPadding(dp2px(this, 14))
69 | .normalViewGap(dp2px(this, 14))
70 | .focusOrientation(FocusLayoutManager.FOCUS_LEFT)
71 | .isAutoSelect(true)
72 | .maxLayerCount(3)
73 | .setOnFocusChangeListener(new FocusLayoutManager.OnFocusChangeListener() {
74 | @Override
75 | public void onFocusChanged(int focusdPosition, int lastFocusdPosition) {
76 | tvFocusedPos.setText("[" + focusdPosition + "],[" + lastFocusdPosition + "]");
77 | if (focusdPosition == datas.size() - 1 &&
78 | (focusLayoutManager.getFocusOrientation() == FocusLayoutManager.FOCUS_LEFT)) {
79 | emptyView.setVisibility(View.VISIBLE);
80 | } else {
81 | emptyView.setVisibility(View.GONE);
82 | }
83 | }
84 | })
85 | .build();
86 |
87 | // datas = new ArrayList<>();
88 | // for (int i = 0; i < 20; i++) {
89 | // Bean bean = new Bean();
90 | // bean.useColor = true;
91 | // bean.msg = "" + (i);
92 | // bean.color = colors[i % 10];
93 | // datas.add(bean);
94 | // }
95 | datas = getDatas(false);
96 | adapter = new Adapter(datas);
97 | recyclerView.setAdapter(adapter);
98 | recyclerView.setLayoutManager(focusLayoutManager);
99 |
100 | cbAutoSelect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
101 | @Override
102 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
103 | focusLayoutManager.setAutoSelect(isChecked);
104 | }
105 | });
106 | cbInfinite.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
107 | @Override
108 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
109 | recyclerView.setAdapter(new Adapter(datas));
110 | if (isChecked) {
111 | emptyView.setVisibility(View.GONE);
112 | recyclerView.post(new Runnable() {
113 | @Override
114 | public void run() {
115 | focusLayoutManager.scrollToPosition(1000);
116 | }
117 | });
118 | }
119 | }
120 | });
121 |
122 | }
123 |
124 | public List getDatas(boolean vertical) {
125 | List datas = new ArrayList<>();
126 | if (vertical) {
127 | for (int i = 0; i < verRes.length; i++) {
128 | Bean bean = new Bean();
129 | bean.useColor = false;
130 | bean.background = verRes[i];
131 | datas.add(bean);
132 | }
133 | } else {
134 | for (int i = 0; i < horRes.length; i++) {
135 | Bean bean = new Bean();
136 | bean.useColor = false;
137 | bean.background = horRes[i];
138 | datas.add(bean);
139 | }
140 | }
141 |
142 | return datas;
143 | }
144 |
145 | public static float dp2px(Context context, float dp) {
146 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
147 | context.getResources().getDisplayMetrics());
148 | }
149 |
150 | public void layerCount_btn(View view) {
151 | EditText et = findViewById(R.id.layerCount);
152 | try {
153 | int count = Integer.parseInt(et.getText().toString());
154 | if (count <= 0) {
155 | Toast.makeText(this, "不合法", Toast.LENGTH_SHORT).show();
156 | return;
157 | }
158 | focusLayoutManager.setMaxLayerCount(count);
159 | } catch (NumberFormatException e) {
160 | e.printStackTrace();
161 | }
162 | }
163 |
164 |
165 | public void changeTrasition(View view) {
166 | focusLayoutManager.setMaxLayerCount(3);
167 | focusLayoutManager.setNormalViewGap(dp2px(this, 4));
168 | focusLayoutManager.setLayerPadding(dp2px(this, 50));
169 | focusLayoutManager.removeTrasitionlistener(null);
170 | focusLayoutManager.addTrasitionListener(new FocusLayoutManager.TrasitionListener() {
171 | @Override
172 | public void handleLayerView(FocusLayoutManager focusLayoutManager, View view,
173 | int viewLayer, int maxLayerCount, int position,
174 | float fraction, float offset) {
175 | if (view instanceof CardView) {
176 | ((CardView) view).setCardElevation(0);
177 | }
178 | float realFraction = fraction;
179 |
180 | float minRo = 80;
181 | float maxRo = 0;
182 | float roDelta = maxRo - minRo;
183 | float currentLayerMaxRo =
184 | minRo + roDelta * (viewLayer + 1) / (maxLayerCount * 1.0f);
185 | float currentLayerMinRo =
186 | minRo + roDelta * viewLayer / (maxLayerCount * 1.0f);
187 | float realRo =
188 | currentLayerMaxRo - (currentLayerMaxRo - currentLayerMinRo) * realFraction;
189 |
190 | float minScale = 0.7f;
191 | float maxScale = 1f;
192 | float scaleDelta = maxScale - minScale;
193 | float currentLayerMaxScale =
194 | minScale + scaleDelta * (viewLayer + 1) / (maxLayerCount * 1.0f);
195 | float currentLayerMinScale =
196 | minScale + scaleDelta * viewLayer / (maxLayerCount * 1.0f);
197 | float realScale =
198 | currentLayerMaxScale - (currentLayerMaxScale - currentLayerMinScale) * realFraction;
199 |
200 | float minAlpha = 0;
201 | float maxAlpha = 1;
202 | float alphaDelta = maxAlpha - minAlpha; //总透明度差
203 | float currentLayerMaxAlpha =
204 | minAlpha + alphaDelta * (viewLayer + 1) / (maxLayerCount * 1.0f);
205 | float currentLayerMinAlpha =
206 | minAlpha + alphaDelta * viewLayer / (maxLayerCount * 1.0f);
207 | float realAlpha =
208 | currentLayerMaxAlpha - (currentLayerMaxAlpha - currentLayerMinAlpha) * realFraction;
209 |
210 | view.setScaleX(realScale);
211 | view.setScaleY(realScale);
212 | view.setRotationY(realRo);
213 | view.setAlpha(realAlpha);
214 |
215 | }
216 |
217 | @Override
218 | public void handleFocusingView(FocusLayoutManager focusLayoutManager, View view,
219 | int position, float fraction, float offset) {
220 | if (view instanceof CardView) {
221 | ((CardView) view).setCardElevation(0);
222 | }
223 | float realFraction = fraction;
224 |
225 | float realScale =
226 | 0.85f + (1f - 0.85f) * realFraction;
227 | float realAlpha = 1;
228 |
229 | view.setScaleX(realScale);
230 | view.setScaleY(realScale);
231 | view.setAlpha(realAlpha);
232 | view.setRotationY(0);
233 |
234 | }
235 |
236 | @Override
237 | public void handleNormalView(FocusLayoutManager focusLayoutManager, View view,
238 | int position, float fraction, float offset) {
239 | if (view instanceof CardView) {
240 | ((CardView) view).setCardElevation(0);
241 | }
242 | view.setScaleX(0.85f);
243 | view.setScaleY(0.85f);
244 | view.setAlpha(1);
245 | view.setRotationY(0);
246 | }
247 | });
248 | }
249 |
250 | public void normalViewGap_btn(View view) {
251 | EditText et = findViewById(R.id.normalViewGap);
252 | try {
253 | int count = Integer.parseInt(et.getText().toString());
254 |
255 | focusLayoutManager.setNormalViewGap(dp2px(this, count));
256 | } catch (NumberFormatException e) {
257 | e.printStackTrace();
258 | }
259 | }
260 |
261 | public void layerPadding_btn(View view) {
262 | EditText et = findViewById(R.id.layerPadding);
263 | try {
264 | int count = Integer.parseInt(et.getText().toString());
265 |
266 | focusLayoutManager.setLayerPadding(dp2px(this, count));
267 | } catch (NumberFormatException e) {
268 | e.printStackTrace();
269 | }
270 | }
271 |
272 | public void orientation_btn(View view) {
273 | RadioGroup rg = findViewById(R.id.ori_rg);
274 | int id = rg.getCheckedRadioButtonId();
275 | if (id == R.id.l) {
276 | focusLayoutManager.setFocusOrientation(FocusLayoutManager.FOCUS_LEFT);
277 | ViewGroup.LayoutParams p = recyclerView.getLayoutParams();
278 | p.width = RecyclerView.LayoutParams.MATCH_PARENT;
279 | p.height = RecyclerView.LayoutParams.WRAP_CONTENT;
280 | recyclerView.setAdapter(new Adapter(datas = getDatas(false)));
281 | }
282 | if (id == R.id.r) {
283 | focusLayoutManager.setFocusOrientation(FocusLayoutManager.FOCUS_RIGHT);
284 | ViewGroup.LayoutParams p = recyclerView.getLayoutParams();
285 | p.width = RecyclerView.LayoutParams.MATCH_PARENT;
286 | p.height = RecyclerView.LayoutParams.WRAP_CONTENT;
287 | recyclerView.setAdapter(new Adapter(datas = getDatas(false)));
288 | }
289 | if (id == R.id.t) {
290 | focusLayoutManager.setFocusOrientation(FocusLayoutManager.FOCUS_TOP);
291 | ViewGroup.LayoutParams p = recyclerView.getLayoutParams();
292 | p.width = RecyclerView.LayoutParams.WRAP_CONTENT;
293 | p.height = (int) dp2px(this, 480);
294 | recyclerView.setAdapter(new Adapter(datas = getDatas(true)));
295 | }
296 | if (id == R.id.b) {
297 | focusLayoutManager.setFocusOrientation(FocusLayoutManager.FOCUS_BOTTOM);
298 | ViewGroup.LayoutParams p = recyclerView.getLayoutParams();
299 | p.width = RecyclerView.LayoutParams.WRAP_CONTENT;
300 | p.height = (int) dp2px(this, 480);
301 | recyclerView.setAdapter(new Adapter(datas = getDatas(true)));
302 | }
303 | }
304 |
305 |
306 | public class Adapter extends RecyclerView.Adapter {
307 |
308 | private final List datas;
309 | private int index = 0;
310 |
311 | public Adapter(List datas) {
312 | this.datas = datas;
313 | }
314 |
315 |
316 | @NonNull
317 | @Override
318 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
319 | View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_card,
320 | viewGroup, false);
321 | if (focusLayoutManager.getFocusOrientation() == FocusLayoutManager.FOCUS_LEFT || focusLayoutManager.getFocusOrientation() == FocusLayoutManager.FOCUS_RIGHT) {
322 | ViewGroup.MarginLayoutParams p =
323 | (ViewGroup.MarginLayoutParams) view.getLayoutParams();
324 | p.topMargin = (int) dp2px(view.getContext(), 25);
325 | p.bottomMargin = (int) dp2px(view.getContext(), 25);
326 | p.leftMargin = (int) dp2px(view.getContext(), 0);
327 | p.rightMargin = (int) dp2px(view.getContext(), 0);
328 | p.width = (int) dp2px(view.getContext(), 100);
329 | p.height = (int) dp2px(view.getContext(), 150);
330 | } else {
331 | ViewGroup.MarginLayoutParams p =
332 | (ViewGroup.MarginLayoutParams) view.getLayoutParams();
333 | p.topMargin = (int) dp2px(view.getContext(), 0);
334 | p.bottomMargin = (int) dp2px(view.getContext(), 0);
335 | p.leftMargin = (int) dp2px(view.getContext(), 25);
336 | p.rightMargin = (int) dp2px(view.getContext(), 25);
337 | p.width = (int) dp2px(view.getContext(), 150);
338 | p.height = (int) dp2px(view.getContext(), 100);
339 | }
340 | view.setTag(++index);
341 | Log.d("ccy", "onCreateViewHolder = " + index);
342 | return new ViewHolder(view);
343 | }
344 |
345 | @Override
346 | public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
347 | Log.d("ccy", "onBindViewHolder,index = " + (int) (viewHolder.itemView.getTag()));
348 | int realPosition = cbInfinite.isChecked() ? position % datas.size() : position;
349 |
350 | Bean bean = datas.get(realPosition);
351 |
352 | if (bean.useColor) {
353 | ((CardView) viewHolder.itemView).setBackgroundResource(0);
354 | ((CardView) viewHolder.itemView).setBackgroundColor(bean.color);
355 | } else {
356 | Glide.with(viewHolder.itemView)
357 | .load(bean.background)
358 | .into(viewHolder.iv);
359 | }
360 | viewHolder.tv.setText(bean.msg);
361 | }
362 |
363 | @Override
364 | public int getItemCount() {
365 | return cbInfinite.isChecked() ? Integer.MAX_VALUE : datas.size();
366 | }
367 |
368 | public class ViewHolder extends RecyclerView.ViewHolder {
369 |
370 | TextView tv;
371 | ImageView iv;
372 |
373 | public ViewHolder(@NonNull final View itemView) {
374 | super(itemView);
375 | tv = itemView.findViewById(R.id.item_tv);
376 | iv = itemView.findViewById(R.id.item_iv);
377 | itemView.setOnClickListener(new View.OnClickListener() {
378 | @Override
379 | public void onClick(View v) {
380 | int pos = getAdapterPosition();
381 | if (mToast == null) {
382 | mToast = Toast.makeText(MainActivity.this, "" + pos,
383 | Toast.LENGTH_SHORT);
384 | }
385 | mToast.setText("" + pos);
386 | mToast.show();
387 |
388 | if (pos == focusLayoutManager.getFocusdPosition()) {
389 |
390 | Intent intent = new Intent(MainActivity.this, DetailActivity.class);
391 | intent.putExtra("resId", datas.get(pos).background);
392 | startActivity(intent, ActivityOptionsCompat.makeSceneTransitionAnimation
393 | (MainActivity.this, itemView, "img").toBundle());
394 | } else {
395 | focusLayoutManager.setFocusdPosition(pos, true);
396 | }
397 | }
398 | });
399 | }
400 | }
401 |
402 | }
403 |
404 | public static class Bean {
405 | boolean useColor = true;
406 | int color;
407 | int background;
408 | String msg;
409 | }
410 | }
411 |
--------------------------------------------------------------------------------
/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/h1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/h1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/h2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/h2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/h3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/h3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/h4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/h4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/h5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/h5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/h6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/h6.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/h7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/h7.jpg
--------------------------------------------------------------------------------
/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/drawable/v1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/v1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/v2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/v2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/v3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/v3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/v4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/v4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/v5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/v5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/v6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/v6.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/v7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/drawable/v7.jpg
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
16 |
17 |
22 |
23 |
32 |
33 |
39 |
40 |
45 |
46 |
51 |
52 |
53 |
54 |
60 |
61 |
66 |
67 |
72 |
73 |
79 |
80 |
81 |
82 |
87 |
88 |
93 |
94 |
99 |
100 |
106 |
107 |
108 |
113 |
114 |
119 |
120 |
125 |
126 |
132 |
133 |
134 |
139 |
140 |
146 |
147 |
152 |
153 |
158 |
159 |
164 |
165 |
166 |
172 |
173 |
176 |
177 |
183 |
189 |
190 |
191 |
197 |
198 |
199 |
200 |
201 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/detail_act.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
21 |
22 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/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/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FocusLayoutManagerProject
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/ccy/focuslayoutmanagerproject/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package ccy.focuslayoutmanagerproject;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 |
18 | @Test
19 | public void testDuration(){
20 | assertEquals(getDuration(10f),100+20);
21 | assertEquals(getDuration(50f),100+100);
22 | assertEquals(getDuration(100f),300);
23 | assertEquals(getDuration(150f),300 + 150);
24 | assertEquals(getDuration(200f),300 + 300);
25 | }
26 |
27 | public long getDuration(float distance){
28 | float onceCompleteScrollLength = 100;
29 |
30 | long minDuration = 100;
31 | long maxDuration = 300;
32 | long duration;
33 | float distanceFraction = (Math.abs(distance) / (onceCompleteScrollLength));
34 | if(distance <= onceCompleteScrollLength){
35 | duration = (long) (minDuration + (maxDuration - minDuration) * distanceFraction);
36 | }else {
37 | duration = (long) (maxDuration * distanceFraction);
38 | }
39 |
40 | return duration;
41 | }
42 | }
--------------------------------------------------------------------------------
/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 | google()
6 | jcenter()
7 |
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.3.0'
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 | google()
20 | jcenter()
21 |
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/ccy_ identity:
--------------------------------------------------------------------------------
1 | i am ccy
2 | 联系我671518768@qq.com
--------------------------------------------------------------------------------
/focuslayoutmanager/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release' // must be applied after your artifact generating plugin (eg. java / com.android.library)
3 |
4 | buildscript {
5 | repositories {
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.novoda:bintray-release:0.9.1'
10 | }
11 | }
12 | android {
13 | compileSdkVersion 28
14 |
15 |
16 |
17 | defaultConfig {
18 | minSdkVersion 19
19 | targetSdkVersion 28
20 | versionCode 1
21 | versionName "1.0"
22 |
23 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
24 |
25 | }
26 |
27 | buildTypes {
28 | release {
29 | minifyEnabled false
30 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 |
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(include: ['*.jar'], dir: 'libs')
38 | implementation 'com.android.support:appcompat-v7:28.0.0'
39 | testImplementation 'junit:junit:4.12'
40 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
41 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
42 | implementation 'com.android.support:recyclerview-v7:28.0.0'
43 | }
44 |
45 | publish {
46 | repoName = 'FocusLayoutManager' // 此字段为你的仓库名称,默认为"maven",上传的时候记得检查,否则上传会报错
47 | userOrg = 'ccy01220122'
48 | groupId = 'com.ccy'
49 | artifactId = 'FocusLayoutManager'
50 | publishVersion = '1.0.2'
51 | desc = '具有有焦点item的水平/垂直滚动RecyclerView-LayoutManager'
52 | website = 'https://github.com/CCY0122/FocusLayoutManager'
53 | }
54 |
--------------------------------------------------------------------------------
/focuslayoutmanager/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 |
--------------------------------------------------------------------------------
/focuslayoutmanager/src/androidTest/java/ccy/focuslayoutmanager/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package ccy.focuslayoutmanager;
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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("ccy.focuslayoutmanager.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/focuslayoutmanager/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/focuslayoutmanager/src/main/java/ccy/focuslayoutmanager/FocusLayoutManager.java:
--------------------------------------------------------------------------------
1 | package ccy.focuslayoutmanager;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.content.Context;
5 | import android.support.annotation.FloatRange;
6 | import android.support.annotation.IntDef;
7 | import android.support.annotation.IntRange;
8 | import android.support.annotation.NonNull;
9 | import android.support.annotation.Nullable;
10 | import android.support.v7.widget.RecyclerView;
11 | import android.util.Log;
12 | import android.util.TypedValue;
13 | import android.view.View;
14 | import android.view.animation.LinearInterpolator;
15 |
16 | import java.lang.annotation.Retention;
17 | import java.lang.annotation.RetentionPolicy;
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | /**
22 | * Created by ccy(17022) on 2019/5/18 下午5:07
23 | */
24 | public class FocusLayoutManager extends RecyclerView.LayoutManager {
25 | public static final String TAG = "FocusLayoutManager";
26 | /**
27 | * 堆叠方向在左
28 | */
29 | public static final int FOCUS_LEFT = 1;
30 | /**
31 | * 堆叠方向在右
32 | */
33 | public static final int FOCUS_RIGHT = 2;
34 | /**
35 | * 堆叠方向在上
36 | */
37 | public static final int FOCUS_TOP = 3;
38 | /**
39 | * 堆叠方向在下
40 | */
41 | public static final int FOCUS_BOTTOM = 4;
42 |
43 | /**
44 | * 最大可堆叠层级
45 | */
46 | int maxLayerCount;
47 |
48 | /**
49 | * 堆叠的方向。
50 | * 期望滚动方向为水平时,传{@link #FOCUS_LEFT}或{@link #FOCUS_RIGHT};
51 | * 期望滚动方向为垂直时,传{@link #FOCUS_TOP}或{@link #FOCUS_BOTTOM}。
52 | */
53 | @FocusOrientation
54 | private int focusOrientation = FOCUS_LEFT;
55 | /**
56 | * 堆叠view之间的偏移量
57 | */
58 | private float layerPadding;
59 | /**
60 | * 普通view之间的margin
61 | */
62 | private float normalViewGap;
63 | /**
64 | * 是否自动选中
65 | */
66 | private boolean isAutoSelect;
67 | /**
68 | * 变换监听接口。
69 | */
70 | private List trasitionListeners;
71 | /**
72 | *
73 | */
74 | private OnFocusChangeListener onFocusChangeListener;
75 | /**
76 | * 水平方向累计偏移量
77 | */
78 | private long mHorizontalOffset;
79 | /**
80 | * 垂直方向累计偏移量
81 | */
82 | private long mVerticalOffset;
83 | /**
84 | * 屏幕可见的第一个View的Position
85 | */
86 | private int mFirstVisiPos;
87 | /**
88 | * 屏幕可见的最后一个View的Position
89 | */
90 | private int mLastVisiPos;
91 | /**
92 | * 一次完整的聚焦滑动所需要移动的距离。
93 | */
94 | private float onceCompleteScrollLength = -1;
95 | /**
96 | * 焦点view的position
97 | */
98 | private int focusdPosition = -1;
99 | /**
100 | * 自动选中动画
101 | */
102 | private ValueAnimator selectAnimator;
103 | private long autoSelectMinDuration;
104 | private long autoSelectMaxDuration;
105 |
106 |
107 | @IntDef({FOCUS_LEFT, FOCUS_RIGHT, FOCUS_TOP, FOCUS_BOTTOM})
108 | @Retention(RetentionPolicy.SOURCE)
109 | public @interface FocusOrientation {
110 | }
111 |
112 |
113 | public FocusLayoutManager() {
114 | this(new Builder());
115 | }
116 |
117 | private FocusLayoutManager(Builder builder) {
118 | this.maxLayerCount = builder.maxLayerCount;
119 | this.focusOrientation = builder.focusOrientation;
120 | this.layerPadding = builder.layerPadding;
121 | this.trasitionListeners = builder.trasitionListeners;
122 | this.normalViewGap = builder.normalViewGap;
123 | this.isAutoSelect = builder.isAutoSelect;
124 | this.onFocusChangeListener = builder.onFocusChangeListener;
125 | this.autoSelectMinDuration = builder.autoSelectMinDuration;
126 | this.autoSelectMaxDuration = builder.autoSelectMaxDuration;
127 | }
128 |
129 |
130 | @Override
131 | public RecyclerView.LayoutParams generateDefaultLayoutParams() {
132 | return new RecyclerView.LayoutParams(RecyclerView.LayoutParams.WRAP_CONTENT,
133 | RecyclerView.LayoutParams.WRAP_CONTENT);
134 | }
135 |
136 | @Override
137 | public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
138 | if (state.getItemCount() == 0) {
139 | removeAndRecycleAllViews(recycler);
140 | return;
141 | }
142 |
143 | onceCompleteScrollLength = -1;
144 | //分离全部已有的view,放入临时缓存
145 | detachAndScrapAttachedViews(recycler);
146 |
147 | fill(recycler, state, 0);
148 | }
149 |
150 |
151 | @Override
152 | public boolean canScrollHorizontally() {
153 | return focusOrientation == FOCUS_LEFT || focusOrientation == FOCUS_RIGHT;
154 | }
155 |
156 | @Override
157 | public boolean canScrollVertically() {
158 | return focusOrientation == FOCUS_TOP || focusOrientation == FOCUS_BOTTOM;
159 | }
160 |
161 | @Override
162 | public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler,
163 | RecyclerView.State state) {
164 | //手指从右向左滑动,dx > 0; 手指从左向右滑动,dx < 0;
165 |
166 | //位移0、没有子View 当然不移动
167 | if (dx == 0 || getChildCount() == 0) {
168 | return 0;
169 | }
170 |
171 | mHorizontalOffset += dx;//累加实际滑动距离
172 |
173 |
174 | dx = fill(recycler, state, dx);
175 |
176 | return dx;
177 | }
178 |
179 | @Override
180 | public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler,
181 | RecyclerView.State state) {
182 | //位移0、没有子View 当然不移动
183 | if (dy == 0 || getChildCount() == 0) {
184 | return 0;
185 | }
186 |
187 | mVerticalOffset += dy;//累加实际滑动距离
188 |
189 |
190 | dy = fill(recycler, state, dy);
191 |
192 | return dy;
193 | }
194 |
195 |
196 | @Override
197 | public void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler) {
198 | cancelAnimator();
199 | super.onDetachedFromWindow(view, recycler);
200 | }
201 |
202 | /**
203 | * @param recycler
204 | * @param state
205 | * @param delta
206 | */
207 | private int fill(RecyclerView.Recycler recycler, RecyclerView.State state, int delta) {
208 | int resultDelta = delta;
209 |
210 | //为了可读性,分成四个方法
211 | switch (focusOrientation) {
212 | case FOCUS_LEFT:
213 | resultDelta = fillHorizontalLeft(recycler, state, delta);
214 | break;
215 | case FOCUS_RIGHT:
216 | resultDelta = fillHorizontalRight(recycler, state, delta);
217 | break;
218 | case FOCUS_TOP:
219 | resultDelta = fillVerticalTop(recycler, state, delta);
220 | break;
221 | case FOCUS_BOTTOM:
222 | resultDelta = fillVerticalBottom(recycler, state, delta);
223 | break;
224 | default:
225 | break;
226 | }
227 |
228 | recycleChildren(recycler);
229 |
230 | // log("childCount= [" + getChildCount() + "]" + ",[recycler.getScrapList().size():" +
231 | // recycler.getScrapList().size());
232 | return resultDelta;
233 | }
234 |
235 |
236 | /**
237 | * 水平滚动、向左堆叠布局
238 | *
239 | * @param recycler
240 | * @param state
241 | * @param dx 偏移量。手指从右向左滑动,dx > 0; 手指从左向右滑动,dx < 0;
242 | */
243 | private int fillHorizontalLeft(RecyclerView.Recycler recycler, RecyclerView.State state,
244 | int dx) {
245 |
246 | //----------------1、边界检测-----------------
247 | if (dx < 0) {
248 | //已达左边界
249 | if (mHorizontalOffset < 0) {
250 | mHorizontalOffset = dx = 0;
251 | }
252 | }
253 |
254 | if (dx > 0) {
255 | //滑动到只剩堆叠view,没有普通view了,说明已经到达右边界了
256 | if (mLastVisiPos - mFirstVisiPos <= maxLayerCount - 1) {
257 | //因为scrollHorizontallyBy里加了一次dx,现在减回去
258 | mHorizontalOffset -= dx;
259 | dx = 0;
260 | }
261 | }
262 |
263 | //分离全部的view,放入临时缓存
264 | detachAndScrapAttachedViews(recycler);
265 |
266 | //----------------2、初始化布局数据-----------------
267 |
268 | float startX = getPaddingLeft() - layerPadding;
269 |
270 | View tempView = null;
271 | int tempPosition = -1;
272 | if (onceCompleteScrollLength == -1) {
273 | //因为mFirstVisiPos在下面可能会被改变,所以用tempPosition暂存一下。
274 | tempPosition = mFirstVisiPos;
275 | tempView = recycler.getViewForPosition(tempPosition);
276 | measureChildWithMargins(tempView, 0, 0);
277 | onceCompleteScrollLength = getDecoratedMeasurementHorizontal(tempView) + normalViewGap;
278 | }
279 | //当前"一次完整的聚焦滑动"所在的进度百分比.百分比增加方向为向着堆叠移动的方向(即如果为FOCUS_LEFT,从右向左移动fraction将从0%到100%)
280 | float fraction =
281 | (Math.abs(mHorizontalOffset) % onceCompleteScrollLength) / (onceCompleteScrollLength * 1.0f);
282 |
283 | //堆叠区域view偏移量。在一次完整的聚焦滑动期间,其总偏移量是一个layerPadding的距离
284 | float layerViewOffset = layerPadding * fraction;
285 | //普通区域view偏移量。在一次完整的聚焦滑动期间,其总位移量是一个onceCompleteScrollLength
286 | float normalViewOffset = onceCompleteScrollLength * fraction;
287 | boolean isLayerViewOffsetSetted = false;
288 | boolean isNormalViewOffsetSetted = false;
289 |
290 | //修正第一个可见的view:mFirstVisiPos。已经滑动了多少个完整的onceCompleteScrollLength就代表滑动了多少个item
291 | mFirstVisiPos = (int) Math.floor(Math.abs(mHorizontalOffset) / onceCompleteScrollLength); //向下取整
292 | //临时将mLastVisiPos赋值为getItemCount() - 1,放心,下面遍历时会判断view是否已溢出屏幕,并及时修正该值并结束布局
293 | mLastVisiPos = getItemCount() - 1;
294 |
295 | // log("fill.fraction = " + fraction + ";offset = " + mHorizontalOffset + ";mfirstPos = "
296 | // + mFirstVisiPos);
297 |
298 |
299 | int newFocusedPosition = mFirstVisiPos + maxLayerCount - 1;
300 | if (newFocusedPosition != focusdPosition) {
301 | if (onFocusChangeListener != null) {
302 | onFocusChangeListener.onFocusChanged(newFocusedPosition, focusdPosition);
303 | }
304 | focusdPosition = newFocusedPosition;
305 | }
306 |
307 |
308 | //----------------3、开始布局-----------------
309 |
310 | for (int i = mFirstVisiPos; i <= mLastVisiPos; i++) {
311 | //属于堆叠区域
312 | if (i - mFirstVisiPos < maxLayerCount) {
313 | View item;
314 |
315 | if (i == tempPosition && tempView != null) {
316 | //如果初始化数据时已经取了一个临时view,可别浪费了!
317 | item = tempView;
318 | } else {
319 | item = recycler.getViewForPosition(i);
320 | }
321 | addView(item);
322 | measureChildWithMargins(item, 0, 0);
323 |
324 | startX += layerPadding;
325 | if (!isLayerViewOffsetSetted) {
326 | startX -= layerViewOffset;
327 | isLayerViewOffsetSetted = true;
328 | }
329 |
330 | if (trasitionListeners != null && !trasitionListeners.isEmpty()) {
331 | for (TrasitionListener trasitionListener : trasitionListeners) {
332 | trasitionListener.handleLayerView(this, item, i - mFirstVisiPos,
333 | maxLayerCount, i, fraction, dx);
334 | }
335 | }
336 |
337 | int l, t, r, b;
338 | l = (int) startX;
339 | t = getPaddingTop();
340 | r = (int) (startX + getDecoratedMeasurementHorizontal(item));
341 | b = getPaddingTop() + getDecoratedMeasurementVertical(item);
342 | layoutDecoratedWithMargins(item, l, t, r, b);
343 |
344 |
345 | } else {//属于普通区域
346 |
347 | View item = recycler.getViewForPosition(i);
348 | addView(item);
349 | measureChildWithMargins(item, 0, 0);
350 |
351 | startX += onceCompleteScrollLength;
352 | if (!isNormalViewOffsetSetted) {
353 | startX += layerViewOffset;
354 | startX -= normalViewOffset;
355 | isNormalViewOffsetSetted = true;
356 | }
357 |
358 | if (trasitionListeners != null && !trasitionListeners.isEmpty()) {
359 | for (TrasitionListener trasitionListener : trasitionListeners) {
360 | if (i - mFirstVisiPos == maxLayerCount) {
361 | trasitionListener.handleFocusingView(this, item, i, fraction, dx);
362 | } else {
363 | trasitionListener.handleNormalView(this, item, i, fraction, dx);
364 | }
365 | }
366 | }
367 |
368 | int l, t, r, b;
369 | l = (int) startX;
370 | t = getPaddingTop();
371 | r = (int) (startX + getDecoratedMeasurementHorizontal(item));
372 | b = getPaddingTop() + getDecoratedMeasurementVertical(item);
373 | layoutDecoratedWithMargins(item, l, t, r, b);
374 |
375 | //判断下一个view的布局位置是不是已经超出屏幕了,若超出,修正mLastVisiPos并跳出遍历
376 | if (startX + onceCompleteScrollLength > getWidth() - getPaddingRight()) {
377 | mLastVisiPos = i;
378 | break;
379 | }
380 | }
381 | }
382 |
383 | return dx;
384 | }
385 |
386 | /**
387 | * 水平滚动、向右堆叠布局。详细注释请参考
388 | * {@link #fillHorizontalLeft(RecyclerView.Recycler, RecyclerView.State, int)}。
389 | *
390 | * @param recycler
391 | * @param state
392 | * @param dx 偏移量。手指从右向左滑动,dx > 0; 手指从左向右滑动,dx < 0;
393 | */
394 | private int fillHorizontalRight(RecyclerView.Recycler recycler, RecyclerView.State state,
395 | int dx) {
396 |
397 | //----------------1、边界检测-----------------
398 |
399 | //从最右边开始布局,所以mHorizontalOffset一直是负数
400 | if (dx > 0) {
401 | if (mHorizontalOffset > 0) {
402 | mHorizontalOffset = dx = 0;
403 | }
404 | }
405 | if (dx < 0) {
406 | if (mLastVisiPos - mFirstVisiPos <= maxLayerCount - 1) {
407 | mHorizontalOffset -= dx;
408 | dx = 0;
409 | }
410 | }
411 |
412 | detachAndScrapAttachedViews(recycler);
413 |
414 | //----------------2、初始化布局数据-----------------
415 |
416 | float startX = getWidth() - getPaddingRight() + layerPadding;
417 |
418 | View tempView = null;
419 | int tempPosition = -1;
420 | if (onceCompleteScrollLength == -1) {
421 | //因为mFirstVisiPos在下面可能会被改变,所以用tempPosition暂存一下。
422 | tempPosition = mFirstVisiPos;
423 | tempView = recycler.getViewForPosition(tempPosition);
424 | measureChildWithMargins(tempView, 0, 0);
425 | onceCompleteScrollLength = getDecoratedMeasurementHorizontal(tempView) + normalViewGap;
426 | }
427 | //当前"一次完整的聚焦滑动"所在的进度百分比.百分比增加方向为向着堆叠移动的方向(即如果为FOCUS_LEFT,从右向左移动fraction将从0%到100%)
428 | float fraction =
429 | (Math.abs(mHorizontalOffset) % onceCompleteScrollLength) / (onceCompleteScrollLength * 1.0f);
430 |
431 | //堆叠区域view偏移量。在一次完整的聚焦滑动期间,其总偏移量是一个layerPadding的距离
432 | float layerViewOffset = layerPadding * fraction;
433 | //普通区域view偏移量。在一次完整的聚焦滑动期间,其总位移量是一个onceCompleteScrollLength
434 | float normalViewOffset = onceCompleteScrollLength * fraction;
435 | boolean isLayerViewOffsetSetted = false;
436 | boolean isNormalViewOffsetSetted = false;
437 |
438 | //修正第一个可见的view:mFirstVisiPos。已经滑动了多少个完整的onceCompleteScrollLength就代表滑动了多少个item
439 | mFirstVisiPos = (int) Math.floor(Math.abs(mHorizontalOffset) / onceCompleteScrollLength); //向下取整
440 | //临时将mLastVisiPos赋值为getItemCount() - 1,放心,下面遍历时会判断view是否已溢出屏幕,并及时修正该值并结束布局
441 | mLastVisiPos = getItemCount() - 1;
442 |
443 |
444 | int newFocusedPosition = mFirstVisiPos + maxLayerCount - 1;
445 | if (newFocusedPosition != focusdPosition) {
446 | if (onFocusChangeListener != null) {
447 | onFocusChangeListener.onFocusChanged(newFocusedPosition, focusdPosition);
448 | }
449 | focusdPosition = newFocusedPosition;
450 | }
451 |
452 |
453 | //----------------3、开始布局-----------------
454 |
455 | for (int i = mFirstVisiPos; i <= mLastVisiPos; i++) {
456 | //属于堆叠区域
457 | if (i - mFirstVisiPos < maxLayerCount) {
458 | View item;
459 |
460 | if (i == tempPosition && tempView != null) {
461 | //如果初始化数据时已经取了一个临时view,可别浪费了!
462 | item = tempView;
463 | } else {
464 | item = recycler.getViewForPosition(i);
465 | }
466 | addView(item);
467 | measureChildWithMargins(item, 0, 0);
468 |
469 | startX -= layerPadding;
470 | if (!isLayerViewOffsetSetted) {
471 | startX += layerViewOffset;
472 | isLayerViewOffsetSetted = true;
473 | }
474 |
475 | if (trasitionListeners != null && !trasitionListeners.isEmpty()) {
476 | for (TrasitionListener trasitionListener : trasitionListeners) {
477 | trasitionListener.handleLayerView(this, item, i - mFirstVisiPos,
478 | maxLayerCount, i, fraction, dx);
479 | }
480 | }
481 |
482 | int l, t, r, b;
483 | l = (int) (startX - getDecoratedMeasurementHorizontal(item));
484 | t = getPaddingTop();
485 | r = (int) (startX);
486 | b = getPaddingTop() + getDecoratedMeasurementVertical(item);
487 | layoutDecoratedWithMargins(item, l, t, r, b);
488 |
489 |
490 | } else {//属于普通区域
491 |
492 | View item = recycler.getViewForPosition(i);
493 | addView(item);
494 | measureChildWithMargins(item, 0, 0);
495 | startX -= onceCompleteScrollLength;
496 | if (!isNormalViewOffsetSetted) {
497 | startX -= layerViewOffset;
498 | startX += normalViewOffset;
499 | isNormalViewOffsetSetted = true;
500 | }
501 |
502 | if (trasitionListeners != null && !trasitionListeners.isEmpty()) {
503 | for (TrasitionListener trasitionListener : trasitionListeners) {
504 | if (i - mFirstVisiPos == maxLayerCount) {
505 | trasitionListener.handleFocusingView(this, item, i, fraction, dx);
506 | } else {
507 | trasitionListener.handleNormalView(this, item, i, fraction, dx);
508 | }
509 | }
510 | }
511 |
512 | int l, t, r, b;
513 | l = (int) (startX - getDecoratedMeasurementHorizontal(item));
514 | t = getPaddingTop();
515 | r = (int) (startX);
516 | b = getPaddingTop() + getDecoratedMeasurementVertical(item);
517 | layoutDecoratedWithMargins(item, l, t, r, b);
518 |
519 | //判断下一个view的布局位置是不是已经超出屏幕了,若超出,修正mLastVisiPos并跳出遍历
520 | if (startX - onceCompleteScrollLength < getPaddingLeft()) {
521 | mLastVisiPos = i;
522 | break;
523 | }
524 | }
525 | }
526 |
527 | return dx;
528 | }
529 |
530 | /**
531 | * 垂直滚动、向上堆叠布局
532 | * 详细注释请参考{@link #fillHorizontalLeft(RecyclerView.Recycler, RecyclerView.State, int)}。
533 | *
534 | * @param recycler
535 | * @param state
536 | * @param dy 偏移量。手指从上向下滑动,dy < 0; 手指从下向上滑动,dy > 0;
537 | */
538 | private int fillVerticalTop(RecyclerView.Recycler recycler, RecyclerView.State state,
539 | int dy) {
540 |
541 | //----------------1、边界检测-----------------
542 | if (dy < 0) {
543 | if (mVerticalOffset < 0) {
544 | mVerticalOffset = dy = 0;
545 | }
546 | }
547 |
548 | if (dy > 0) {
549 | if (mLastVisiPos - mFirstVisiPos <= maxLayerCount - 1) {
550 | mVerticalOffset -= dy;
551 | dy = 0;
552 | }
553 | }
554 |
555 | detachAndScrapAttachedViews(recycler);
556 |
557 | //----------------2、初始化布局数据-----------------
558 |
559 | float startY = getPaddingTop() - layerPadding;
560 |
561 | View tempView = null;
562 | int tempPosition = -1;
563 | if (onceCompleteScrollLength == -1) {
564 | //因为mFirstVisiPos在下面可能会被改变,所以用tempPosition暂存一下。
565 | tempPosition = mFirstVisiPos;
566 | tempView = recycler.getViewForPosition(tempPosition);
567 | measureChildWithMargins(tempView, 0, 0);
568 | onceCompleteScrollLength = getDecoratedMeasurementVertical(tempView) + normalViewGap;
569 | }
570 | //当前"一次完整的聚焦滑动"所在的进度百分比.百分比增加方向为向着堆叠移动的方向(即如果为FOCUS_LEFT,从右向左移动fraction将从0%到100%)
571 | float fraction =
572 | (Math.abs(mVerticalOffset) % onceCompleteScrollLength) / (onceCompleteScrollLength * 1.0f);
573 |
574 | //堆叠区域view偏移量。在一次完整的聚焦滑动期间,其总偏移量是一个layerPadding的距离
575 | float layerViewOffset = layerPadding * fraction;
576 | //普通区域view偏移量。在一次完整的聚焦滑动期间,其总位移量是一个onceCompleteScrollLength
577 | float normalViewOffset = onceCompleteScrollLength * fraction;
578 | boolean isLayerViewOffsetSetted = false;
579 | boolean isNormalViewOffsetSetted = false;
580 |
581 | //修正第一个可见的view:mFirstVisiPos。已经滑动了多少个完整的onceCompleteScrollLength就代表滑动了多少个item
582 | mFirstVisiPos = (int) Math.floor(Math.abs(mVerticalOffset) / onceCompleteScrollLength);
583 | //向下取整
584 | //临时将mLastVisiPos赋值为getItemCount() - 1,放心,下面遍历时会判断view是否已溢出屏幕,并及时修正该值并结束布局
585 | mLastVisiPos = getItemCount() - 1;
586 |
587 |
588 | int newFocusedPosition = mFirstVisiPos + maxLayerCount - 1;
589 | if (newFocusedPosition != focusdPosition) {
590 | if (onFocusChangeListener != null) {
591 | onFocusChangeListener.onFocusChanged(newFocusedPosition, focusdPosition);
592 | }
593 | focusdPosition = newFocusedPosition;
594 | }
595 |
596 |
597 | //----------------3、开始布局-----------------
598 |
599 | for (int i = mFirstVisiPos; i <= mLastVisiPos; i++) {
600 | //属于堆叠区域
601 | if (i - mFirstVisiPos < maxLayerCount) {
602 | View item;
603 |
604 | if (i == tempPosition && tempView != null) {
605 | //如果初始化数据时已经取了一个临时view,可别浪费了!
606 | item = tempView;
607 | } else {
608 | item = recycler.getViewForPosition(i);
609 | }
610 | addView(item);
611 | measureChildWithMargins(item, 0, 0);
612 |
613 | startY += layerPadding;
614 | if (!isLayerViewOffsetSetted) {
615 | startY -= layerViewOffset;
616 | isLayerViewOffsetSetted = true;
617 | }
618 |
619 | if (trasitionListeners != null && !trasitionListeners.isEmpty()) {
620 | for (TrasitionListener trasitionListener : trasitionListeners) {
621 | trasitionListener.handleLayerView(this, item, i - mFirstVisiPos,
622 | maxLayerCount, i, fraction, dy);
623 | }
624 | }
625 |
626 | int l, t, r, b;
627 | l = getPaddingLeft();
628 | t = (int) startY;
629 | r = getPaddingLeft() + getDecoratedMeasurementHorizontal(item);
630 | b = (int) (startY + getDecoratedMeasurementVertical(item));
631 | layoutDecoratedWithMargins(item, l, t, r, b);
632 |
633 |
634 | } else {//属于普通区域
635 |
636 | View item = recycler.getViewForPosition(i);
637 | addView(item);
638 | measureChildWithMargins(item, 0, 0);
639 | startY += onceCompleteScrollLength;
640 | if (!isNormalViewOffsetSetted) {
641 | startY += layerViewOffset;
642 | startY -= normalViewOffset;
643 | isNormalViewOffsetSetted = true;
644 | }
645 |
646 |
647 | if (trasitionListeners != null && !trasitionListeners.isEmpty()) {
648 | for (TrasitionListener trasitionListener : trasitionListeners) {
649 | if (i - mFirstVisiPos == maxLayerCount) {
650 | trasitionListener.handleFocusingView(this, item, i, fraction, dy);
651 | } else {
652 | trasitionListener.handleNormalView(this, item, i, fraction, dy);
653 | }
654 | }
655 | }
656 |
657 | int l, t, r, b;
658 | l = getPaddingLeft();
659 | t = (int) startY;
660 | r = getPaddingLeft() + getDecoratedMeasurementHorizontal(item);
661 | b = (int) (startY + getDecoratedMeasurementVertical(item));
662 | layoutDecoratedWithMargins(item, l, t, r, b);
663 |
664 | //判断下一个view的布局位置是不是已经超出屏幕了,若超出,修正mLastVisiPos并跳出遍历
665 | if (startY + onceCompleteScrollLength > getHeight() - getPaddingBottom()) {
666 | mLastVisiPos = i;
667 | break;
668 | }
669 | }
670 | }
671 |
672 | return dy;
673 | }
674 |
675 | /**
676 | * 垂直滚动、向下堆叠布局
677 | * 详细注释请参考{@link #fillHorizontalLeft(RecyclerView.Recycler, RecyclerView.State, int)}。
678 | *
679 | * @param recycler
680 | * @param state
681 | * @param dy 偏移量。手指从上向下滑动,dy < 0; 手指从下向上滑动,dy > 0;
682 | */
683 | private int fillVerticalBottom(RecyclerView.Recycler recycler, RecyclerView.State state,
684 | int dy) {
685 |
686 | //----------------1、边界检测-----------------
687 | //从最下边开始布局,所以mVerticalOffset一直是负数
688 |
689 | if (dy > 0) {
690 | //已达上边界
691 | if (mVerticalOffset > 0) {
692 | mVerticalOffset = dy = 0;
693 | }
694 | }
695 |
696 | if (dy < 0) {
697 | if (mLastVisiPos - mFirstVisiPos <= maxLayerCount - 1) {
698 | mVerticalOffset -= dy;
699 | dy = 0;
700 | }
701 | }
702 |
703 | detachAndScrapAttachedViews(recycler);
704 |
705 | //----------------2、初始化布局数据-----------------
706 |
707 | float startY = getHeight() - getPaddingBottom() + layerPadding;
708 |
709 | View tempView = null;
710 | int tempPosition = -1;
711 | if (onceCompleteScrollLength == -1) {
712 | //因为mFirstVisiPos在下面可能会被改变,所以用tempPosition暂存一下。
713 | tempPosition = mFirstVisiPos;
714 | tempView = recycler.getViewForPosition(tempPosition);
715 | measureChildWithMargins(tempView, 0, 0);
716 | onceCompleteScrollLength = getDecoratedMeasurementVertical(tempView) + normalViewGap;
717 | }
718 | //当前"一次完整的聚焦滑动"所在的进度百分比.百分比增加方向为向着堆叠移动的方向(即如果为FOCUS_LEFT,从右向左移动fraction将从0%到100%)
719 | float fraction =
720 | (Math.abs(mVerticalOffset) % onceCompleteScrollLength) / (onceCompleteScrollLength * 1.0f);
721 |
722 | //堆叠区域view偏移量。在一次完整的聚焦滑动期间,其总偏移量是一个layerPadding的距离
723 | float layerViewOffset = layerPadding * fraction;
724 | //普通区域view偏移量。在一次完整的聚焦滑动期间,其总位移量是一个onceCompleteScrollLength
725 | float normalViewOffset = onceCompleteScrollLength * fraction;
726 | boolean isLayerViewOffsetSetted = false;
727 | boolean isNormalViewOffsetSetted = false;
728 |
729 | //修正第一个可见的view:mFirstVisiPos。已经滑动了多少个完整的onceCompleteScrollLength就代表滑动了多少个item
730 | mFirstVisiPos = (int) Math.floor(Math.abs(mVerticalOffset) / onceCompleteScrollLength);
731 | //向下取整
732 | //临时将mLastVisiPos赋值为getItemCount() - 1,放心,下面遍历时会判断view是否已溢出屏幕,并及时修正该值并结束布局
733 | mLastVisiPos = getItemCount() - 1;
734 |
735 |
736 | int newFocusedPosition = mFirstVisiPos + maxLayerCount - 1;
737 | if (newFocusedPosition != focusdPosition) {
738 | if (onFocusChangeListener != null) {
739 | onFocusChangeListener.onFocusChanged(newFocusedPosition, focusdPosition);
740 | }
741 | focusdPosition = newFocusedPosition;
742 | }
743 |
744 |
745 | //----------------3、开始布局-----------------
746 |
747 | for (int i = mFirstVisiPos; i <= mLastVisiPos; i++) {
748 | //属于堆叠区域
749 | if (i - mFirstVisiPos < maxLayerCount) {
750 | View item;
751 |
752 | if (i == tempPosition && tempView != null) {
753 | //如果初始化数据时已经取了一个临时view,可别浪费了!
754 | item = tempView;
755 | } else {
756 | item = recycler.getViewForPosition(i);
757 | }
758 | addView(item);
759 | measureChildWithMargins(item, 0, 0);
760 |
761 | startY -= layerPadding;
762 | if (!isLayerViewOffsetSetted) {
763 | startY += layerViewOffset;
764 | isLayerViewOffsetSetted = true;
765 | }
766 |
767 | if (trasitionListeners != null && !trasitionListeners.isEmpty()) {
768 | for (TrasitionListener trasitionListener : trasitionListeners) {
769 | trasitionListener.handleLayerView(this, item, i - mFirstVisiPos,
770 | maxLayerCount, i, fraction, dy);
771 | }
772 | }
773 |
774 | int l, t, r, b;
775 | l = getPaddingLeft();
776 | t = (int) (startY - getDecoratedMeasurementVertical(item));
777 | r = getPaddingLeft() + getDecoratedMeasurementHorizontal(item);
778 | b = (int) (startY);
779 | layoutDecoratedWithMargins(item, l, t, r, b);
780 |
781 |
782 | } else {//属于普通区域
783 |
784 | View item = recycler.getViewForPosition(i);
785 | addView(item);
786 | measureChildWithMargins(item, 0, 0);
787 | startY -= onceCompleteScrollLength;
788 | if (!isNormalViewOffsetSetted) {
789 | startY -= layerViewOffset;
790 | startY += normalViewOffset;
791 | isNormalViewOffsetSetted = true;
792 | }
793 |
794 | if (trasitionListeners != null && !trasitionListeners.isEmpty()) {
795 | for (TrasitionListener trasitionListener : trasitionListeners) {
796 | if (i - mFirstVisiPos == maxLayerCount) {
797 | trasitionListener.handleFocusingView(this, item, i, fraction, dy);
798 | } else {
799 | trasitionListener.handleNormalView(this, item, i, fraction, dy);
800 | }
801 | }
802 | }
803 |
804 | int l, t, r, b;
805 | l = getPaddingLeft();
806 | t = (int) (startY - getDecoratedMeasurementVertical(item));
807 | r = getPaddingLeft() + getDecoratedMeasurementHorizontal(item);
808 | b = (int) (startY);
809 | layoutDecoratedWithMargins(item, l, t, r, b);
810 |
811 | //判断下一个view的布局位置是不是已经超出屏幕了,若超出,修正mLastVisiPos并跳出遍历
812 | if (startY - onceCompleteScrollLength < getPaddingTop()) {
813 | mLastVisiPos = i;
814 | break;
815 | }
816 | }
817 | }
818 |
819 | return dy;
820 | }
821 |
822 | @Override
823 | public void onAdapterChanged(@Nullable RecyclerView.Adapter oldAdapter,
824 | @Nullable RecyclerView.Adapter newAdapter) {
825 | resetData();
826 | super.onAdapterChanged(oldAdapter, newAdapter);
827 | }
828 |
829 | @Override
830 | public void onMeasure(@NonNull RecyclerView.Recycler recycler,
831 | @NonNull RecyclerView.State state, int widthSpec, int heightSpec) {
832 |
833 | int widthMode = View.MeasureSpec.getMode(widthSpec);
834 | int heightMode = View.MeasureSpec.getMode(heightSpec);
835 | if (widthMode == View.MeasureSpec.AT_MOST && (focusOrientation == FOCUS_LEFT || focusOrientation == FOCUS_RIGHT)) {
836 | if (BuildConfig.DEBUG) {
837 | throw new RuntimeException("FocusLayoutManager-onMeasure:当滚动方向为水平时,recyclerView" +
838 | "的宽度请不要使用wrap_content");
839 | } else {
840 | Log.e(TAG, "FocusLayoutManager-onMeasure:当滚动方向为水平时,recyclerView" +
841 | "的宽度请不要使用wrap_content");
842 | }
843 |
844 | }
845 | if (heightMode == View.MeasureSpec.AT_MOST && (focusOrientation == FOCUS_TOP || focusOrientation == FOCUS_BOTTOM)) {
846 | if (BuildConfig.DEBUG) {
847 | throw new RuntimeException("FocusLayoutManager-onMeasure:当滚动方向为垂直时,recyclerView" +
848 | "的高度请不要使用wrap_content");
849 | } else {
850 | Log.e(TAG, "FocusLayoutManager-onMeasure:当滚动方向为垂直时,recyclerView" +
851 | "的高度请不要使用wrap_content");
852 | }
853 | }
854 | super.onMeasure(recycler, state, widthSpec, heightSpec);
855 | }
856 |
857 | @Override
858 | public boolean isAutoMeasureEnabled() {
859 | return true;
860 | }
861 |
862 | /**
863 | * 回收需回收的Item。
864 | */
865 | private void recycleChildren(RecyclerView.Recycler recycler) {
866 | List scrapList = recycler.getScrapList();
867 | for (int i = 0; i < scrapList.size(); i++) {
868 | RecyclerView.ViewHolder holder = scrapList.get(i);
869 | removeAndRecycleView(holder.itemView, recycler);
870 | }
871 | }
872 |
873 | @Override
874 | public void onScrollStateChanged(int state) {
875 | super.onScrollStateChanged(state);
876 | switch (state) {
877 | case RecyclerView.SCROLL_STATE_DRAGGING:
878 | //当手指按下时,停止当前正在播放的动画
879 | cancelAnimator();
880 | break;
881 | case RecyclerView.SCROLL_STATE_IDLE:
882 | //当列表滚动停止后,判断一下自动选中是否打开
883 | if (isAutoSelect) {
884 | //找到离目标落点最近的item索引
885 | smoothScrollToPosition(findShouldSelectPosition());
886 | }
887 | break;
888 | default:
889 | break;
890 | }
891 | }
892 |
893 | /**
894 | * 返回应当选中的position
895 | *
896 | * @return
897 | */
898 | private int findShouldSelectPosition() {
899 | if (onceCompleteScrollLength == -1 || mFirstVisiPos == -1) {
900 | return -1;
901 | }
902 | int remainder = -1;
903 | if (focusOrientation == FOCUS_LEFT || focusOrientation == FOCUS_RIGHT) {
904 | remainder = (int) (Math.abs(mHorizontalOffset) % onceCompleteScrollLength);
905 | } else if (focusOrientation == FOCUS_TOP || focusOrientation == FOCUS_BOTTOM) {
906 | remainder = (int) (Math.abs(mVerticalOffset) % onceCompleteScrollLength);
907 | }
908 |
909 | if (remainder >= onceCompleteScrollLength / 2.0f) { //超过一半,应当选中下一项
910 | if (mFirstVisiPos + 1 <= getItemCount() - 1) {
911 | return mFirstVisiPos + 1;
912 | }
913 | }
914 |
915 | return mFirstVisiPos;
916 | }
917 |
918 | /**
919 | * 返回移动到position所需的偏移量
920 | *
921 | * @param position
922 | * @return
923 | */
924 | private float getScrollToPositionOffset(int position) {
925 | if (focusOrientation == FOCUS_LEFT) {
926 | return position * onceCompleteScrollLength - Math.abs(mHorizontalOffset);
927 | } else if (focusOrientation == FOCUS_RIGHT) {
928 | return -(position * onceCompleteScrollLength - Math.abs(mHorizontalOffset));
929 | } else if (focusOrientation == FOCUS_TOP) {
930 | return position * onceCompleteScrollLength - Math.abs(mVerticalOffset);
931 | } else if (focusOrientation == FOCUS_BOTTOM) {
932 | return -(position * onceCompleteScrollLength - Math.abs(mVerticalOffset));
933 | }
934 | return 0;
935 | }
936 |
937 |
938 | @Override
939 | public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state,
940 | int position) {
941 | smoothScrollToPosition(position);
942 | }
943 |
944 | @Override
945 | public void scrollToPosition(int position) {
946 | if (focusOrientation == FOCUS_LEFT || focusOrientation == FOCUS_RIGHT) {
947 | mHorizontalOffset += getScrollToPositionOffset(position);
948 | requestLayout();
949 | } else if (focusOrientation == FOCUS_TOP || focusOrientation == FOCUS_BOTTOM) {
950 | mVerticalOffset += getScrollToPositionOffset(position);
951 | requestLayout();
952 | }
953 | }
954 |
955 | /**
956 | * 平滑滚动到某个位置
957 | *
958 | * @param position 目标Item索引
959 | */
960 | public void smoothScrollToPosition(int position) {
961 | if (position > -1 && position < getItemCount()) {
962 | startValueAnimator(position);
963 | }
964 | }
965 |
966 | private void startValueAnimator(int position) {
967 | cancelAnimator();
968 |
969 | final float distance = getScrollToPositionOffset(position);
970 | // log("onceLength = " + onceCompleteScrollLength);
971 | // log("curoffset = " + mHorizontalOffset + ";distance = " + distance + ";endOffset = " +
972 | // (mHorizontalOffset + distance));
973 | // log("currentpos = " + ((int) (Math.abs(mHorizontalOffset) / (int)
974 | // onceCompleteScrollLength)) + ";end pos = " + ((mHorizontalOffset + distance) %
975 | // onceCompleteScrollLength));
976 | // log("current fra = " + ((Math.abs(mHorizontalOffset) % onceCompleteScrollLength) /
977 | // (onceCompleteScrollLength * 1.0f)) + ";end fra = " + (Math.abs(mHorizontalOffset + distance) %
978 | // onceCompleteScrollLength) / (onceCompleteScrollLength * 1.0f));
979 |
980 | long minDuration = autoSelectMinDuration;
981 | long maxDuration = autoSelectMaxDuration;
982 | long duration;
983 | float distanceFraction = (Math.abs(distance) / (onceCompleteScrollLength));
984 | if (distance <= onceCompleteScrollLength) {
985 | duration = (long) (minDuration + (maxDuration - minDuration) * distanceFraction);
986 | } else {
987 | duration = (long) (maxDuration * distanceFraction);
988 | }
989 |
990 | selectAnimator = ValueAnimator.ofFloat(0.0f, distance);
991 | selectAnimator.setDuration(duration);
992 | selectAnimator.setInterpolator(new LinearInterpolator());
993 | final float startedOffset =
994 | (focusOrientation == FOCUS_LEFT || focusOrientation == FOCUS_RIGHT) ?
995 | mHorizontalOffset : mVerticalOffset;
996 |
997 | selectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
998 | @Override
999 | public void onAnimationUpdate(ValueAnimator animation) {
1000 | if (focusOrientation == FOCUS_LEFT || focusOrientation == FOCUS_RIGHT) {
1001 | if (mHorizontalOffset < 0) {
1002 | mHorizontalOffset =
1003 | (long) Math.floor(startedOffset + (float) animation.getAnimatedValue());
1004 | } else {
1005 | mHorizontalOffset =
1006 | (long) Math.ceil(startedOffset + (float) animation.getAnimatedValue());
1007 | }
1008 | requestLayout();
1009 | } else if (focusOrientation == FOCUS_TOP || focusOrientation == FOCUS_BOTTOM) {
1010 | if (mVerticalOffset < 0) {
1011 | mVerticalOffset =
1012 | (long) Math.floor(startedOffset + (float) animation.getAnimatedValue());
1013 | } else {
1014 | mVerticalOffset =
1015 | (long) Math.ceil(startedOffset + (float) animation.getAnimatedValue());
1016 | }
1017 | requestLayout();
1018 | }
1019 |
1020 | }
1021 | });
1022 | selectAnimator.start();
1023 |
1024 | }
1025 |
1026 | /**
1027 | * 获取某个childView在水平方向所占的空间,将margin考虑进去
1028 | *
1029 | * @param view
1030 | * @return
1031 | */
1032 | public int getDecoratedMeasurementHorizontal(View view) {
1033 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)
1034 | view.getLayoutParams();
1035 | return getDecoratedMeasuredWidth(view) + params.leftMargin
1036 | + params.rightMargin;
1037 | }
1038 |
1039 | /**
1040 | * 获取某个childView在竖直方向所占的空间,将margin考虑进去
1041 | *
1042 | * @param view
1043 | * @return
1044 | */
1045 | public int getDecoratedMeasurementVertical(View view) {
1046 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)
1047 | view.getLayoutParams();
1048 | return getDecoratedMeasuredHeight(view) + params.topMargin
1049 | + params.bottomMargin;
1050 | }
1051 |
1052 | public int getVerticalSpace() {
1053 | return getHeight() - getPaddingTop() - getPaddingBottom();
1054 | }
1055 |
1056 | public int getHorizontalSpace() {
1057 | return getWidth() - getPaddingLeft() - getPaddingRight();
1058 | }
1059 |
1060 | /**
1061 | * 重置数据
1062 | */
1063 | public void resetData() {
1064 | mFirstVisiPos = 0;
1065 | mLastVisiPos = 0;
1066 | onceCompleteScrollLength = -1;
1067 | mHorizontalOffset = 0;
1068 | mVerticalOffset = 0;
1069 | focusdPosition = -1;
1070 | cancelAnimator();
1071 | }
1072 |
1073 | public void cancelAnimator() {
1074 | if (selectAnimator != null && (selectAnimator.isStarted() || selectAnimator.isRunning())) {
1075 | selectAnimator.cancel();
1076 | }
1077 | }
1078 |
1079 | public int getFocusdPosition() {
1080 | return focusdPosition;
1081 | }
1082 |
1083 | public void setFocusdPosition(int focusdPosition, boolean anim) {
1084 | if (focusdPosition > -1 && focusdPosition < getItemCount() && focusdPosition >= maxLayerCount - 1) {
1085 | if (anim) {
1086 | smoothScrollToPosition(focusdPosition - (maxLayerCount - 1));
1087 | } else {
1088 | scrollToPosition(focusdPosition - (maxLayerCount - 1));
1089 | }
1090 | }
1091 | }
1092 |
1093 |
1094 | public boolean isAutoSelect() {
1095 | return isAutoSelect;
1096 | }
1097 |
1098 | public void setAutoSelect(boolean autoSelect) {
1099 | isAutoSelect = autoSelect;
1100 | }
1101 |
1102 |
1103 | public int getMaxLayerCount() {
1104 | return maxLayerCount;
1105 | }
1106 |
1107 | public void setMaxLayerCount(int maxLayerCount) {
1108 | this.maxLayerCount = maxLayerCount;
1109 | resetData();
1110 | requestLayout();
1111 | }
1112 |
1113 | public int getFocusOrientation() {
1114 | return focusOrientation;
1115 | }
1116 |
1117 | public void setFocusOrientation(@FocusOrientation int focusOrientation) {
1118 | this.focusOrientation = focusOrientation;
1119 | resetData();
1120 | requestLayout();
1121 | }
1122 |
1123 | public float getLayerPadding() {
1124 | return layerPadding;
1125 | }
1126 |
1127 | public void setLayerPadding(float layerPadding) {
1128 | if (layerPadding < 0) {
1129 | layerPadding = 0;
1130 | }
1131 | this.layerPadding = layerPadding;
1132 | resetData();
1133 | requestLayout();
1134 | }
1135 |
1136 | public float getNormalViewGap() {
1137 | return normalViewGap;
1138 | }
1139 |
1140 | public void setNormalViewGap(float normalViewGap) {
1141 | this.normalViewGap = normalViewGap;
1142 | resetData();
1143 | requestLayout();
1144 | }
1145 |
1146 | public List getTrasitionListeners() {
1147 | return trasitionListeners;
1148 | }
1149 |
1150 | public void addTrasitionListener(TrasitionListener trasitionListener) {
1151 | this.trasitionListeners.add(trasitionListener);
1152 | requestLayout();
1153 | }
1154 |
1155 | /**
1156 | * @param trasitionListener if null,remove all
1157 | * @return
1158 | */
1159 | public boolean removeTrasitionlistener(TrasitionListener trasitionListener) {
1160 | if (trasitionListener != null) {
1161 | return trasitionListeners.remove(trasitionListener);
1162 | } else {
1163 | trasitionListeners.clear();
1164 | return true;
1165 | }
1166 | }
1167 |
1168 |
1169 | public OnFocusChangeListener getOnFocusChangeListener() {
1170 | return onFocusChangeListener;
1171 | }
1172 |
1173 | public void setOnFocusChangeListener(OnFocusChangeListener onFocusChangeListener) {
1174 | this.onFocusChangeListener = onFocusChangeListener;
1175 | }
1176 |
1177 |
1178 | public static class Builder {
1179 |
1180 |
1181 | int maxLayerCount;
1182 | @FocusOrientation
1183 | private int focusOrientation;
1184 | private float layerPadding;
1185 | private float normalViewGap;
1186 | private boolean isAutoSelect;
1187 | private List trasitionListeners;
1188 | private OnFocusChangeListener onFocusChangeListener;
1189 | private long autoSelectMinDuration;
1190 | private long autoSelectMaxDuration;
1191 | private TrasitionListener defaultTrasitionListener;
1192 |
1193 |
1194 | public Builder() {
1195 | maxLayerCount = 3;
1196 | focusOrientation = FOCUS_LEFT;
1197 | layerPadding = 60;
1198 | normalViewGap = 60;
1199 | isAutoSelect = true;
1200 | trasitionListeners = new ArrayList<>();
1201 | defaultTrasitionListener = new TrasitionListenerConvert(new SimpleTrasitionListener() {
1202 | });
1203 | trasitionListeners.add(defaultTrasitionListener);
1204 | onFocusChangeListener = null;
1205 | autoSelectMinDuration = 100;
1206 | autoSelectMaxDuration = 300;
1207 | }
1208 |
1209 | /**
1210 | * 最大可堆叠层级
1211 | */
1212 | public Builder maxLayerCount(int maxLayerCount) {
1213 | if (maxLayerCount <= 0) {
1214 | throw new RuntimeException("maxLayerCount不能小于0");
1215 | }
1216 | this.maxLayerCount = maxLayerCount;
1217 | return this;
1218 | }
1219 |
1220 |
1221 | /**
1222 | * 堆叠的方向。
1223 | * 滚动方向为水平时,传{@link #FOCUS_LEFT}或{@link #FOCUS_RIGHT};
1224 | * 滚动方向为垂直时,传{@link #FOCUS_TOP}或{@link #FOCUS_BOTTOM}。
1225 | *
1226 | * @param focusOrientation
1227 | * @return
1228 | */
1229 | public Builder focusOrientation(@FocusOrientation int focusOrientation) {
1230 | this.focusOrientation = focusOrientation;
1231 | return this;
1232 | }
1233 |
1234 | /**
1235 | * 堆叠view之间的偏移量
1236 | *
1237 | * @param layerPadding
1238 | * @return
1239 | */
1240 | public Builder layerPadding(float layerPadding) {
1241 | if (layerPadding < 0) {
1242 | layerPadding = 0;
1243 | }
1244 | this.layerPadding = layerPadding;
1245 | return this;
1246 | }
1247 |
1248 | /**
1249 | * 普通view之间的margin
1250 | */
1251 | public Builder normalViewGap(float normalViewGap) {
1252 | this.normalViewGap = normalViewGap;
1253 | return this;
1254 | }
1255 |
1256 | /**
1257 | * 是否自动选中
1258 | */
1259 | public Builder isAutoSelect(boolean isAutoSelect) {
1260 | this.isAutoSelect = isAutoSelect;
1261 | return this;
1262 | }
1263 |
1264 | public Builder autoSelectDuration(@IntRange(from = 0) long minDuration, @IntRange(from =
1265 | 0) long maxDuration) {
1266 | if (minDuration < 0 || maxDuration < 0 || maxDuration < minDuration) {
1267 | throw new RuntimeException("autoSelectDuration入参不合法");
1268 | }
1269 | this.autoSelectMinDuration = minDuration;
1270 | this.autoSelectMaxDuration = maxDuration;
1271 | return this;
1272 | }
1273 |
1274 | /**
1275 | * 高级定制 添加滚动过程中view的变换监听接口
1276 | *
1277 | * @param trasitionListener
1278 | * @return
1279 | */
1280 | public Builder addTrasitionListener(TrasitionListener trasitionListener) {
1281 | if (trasitionListener != null) {
1282 | this.trasitionListeners.add(trasitionListener);
1283 | }
1284 | return this;
1285 | }
1286 |
1287 | /**
1288 | * 简化版 滚动过程中view的变换监听接口。实际会被转换为{@link TrasitionListener}
1289 | *
1290 | * @param simpleTrasitionListener if null,remove current
1291 | * @return
1292 | */
1293 | public Builder setSimpleTrasitionListener(SimpleTrasitionListener simpleTrasitionListener) {
1294 | this.trasitionListeners.remove(defaultTrasitionListener);
1295 | defaultTrasitionListener = null;
1296 | if (simpleTrasitionListener != null) {
1297 | defaultTrasitionListener = new TrasitionListenerConvert(simpleTrasitionListener);
1298 | this.trasitionListeners.add(defaultTrasitionListener);
1299 | }
1300 | return this;
1301 | }
1302 |
1303 | public Builder setOnFocusChangeListener(OnFocusChangeListener onFocusChangeListener) {
1304 | this.onFocusChangeListener = onFocusChangeListener;
1305 | return this;
1306 | }
1307 |
1308 | public FocusLayoutManager build() {
1309 | return new FocusLayoutManager(this);
1310 | }
1311 | }
1312 |
1313 |
1314 | /**
1315 | * 滚动过程中view的变换监听接口。属于高级定制,暴露了很多关键布局数据。若定制要求不高,考虑使用{@link SimpleTrasitionListener}
1316 | */
1317 | public interface TrasitionListener {
1318 |
1319 | /**
1320 | * 处理在堆叠里的view。
1321 | *
1322 | * @param focusLayoutManager
1323 | * @param view view对象。请仅在方法体范围内对view做操作,不要外部强引用它,view是要被回收复用的
1324 | * @param viewLayer 当前层级,0表示底层,maxLayerCount-1表示顶层
1325 | * @param maxLayerCount 最大层级
1326 | * @param position item所在的position
1327 | * @param fraction "一次完整的聚焦滑动"所在的进度百分比.百分比增加方向为向着堆叠移动的方向(即如果为FOCUS_LEFT
1328 | * ,从右向左移动fraction将从0%到100%)
1329 | * @param offset 当次滑动偏移量
1330 | */
1331 | void handleLayerView(FocusLayoutManager focusLayoutManager, View view, int viewLayer,
1332 | int maxLayerCount, int position, float fraction, float offset);
1333 |
1334 | /**
1335 | * 处理正聚焦的那个View(即正处在从普通位置滚向聚焦位置时的那个view,即堆叠顶层view)
1336 | *
1337 | * @param focusLayoutManager
1338 | * @param view view对象。请仅在方法体范围内对view做操作,不要外部强引用它,view是要被回收复用的
1339 | * @param position item所在的position
1340 | * @param fraction "一次完整的聚焦滑动"所在的进度百分比.百分比增加方向为向着堆叠移动的方向(即如果为FOCUS_LEFT
1341 | * ,从右向左移动fraction将从0%到100%)
1342 | * @param offset 当次滑动偏移量
1343 | */
1344 | void handleFocusingView(FocusLayoutManager focusLayoutManager, View view, int position,
1345 | float fraction, float offset);
1346 |
1347 | /**
1348 | * 处理不在堆叠里的普通view(正在聚焦的那个view除外)
1349 | *
1350 | * @param focusLayoutManager
1351 | * @param view view对象。请仅在方法体范围内对view做操作,不要外部强引用它,view是要被回收复用的
1352 | * @param position item所在的position
1353 | * @param fraction "一次完整的聚焦滑动"所在的进度百分比.百分比增加方向为向着堆叠移动的方向(即如果为FOCUS_LEFT
1354 | * ,从右向左移动fraction将从0%到100%)
1355 | * @param offset 当次滑动偏移量
1356 | */
1357 | void handleNormalView(FocusLayoutManager focusLayoutManager, View view, int position,
1358 | float fraction, float offset);
1359 |
1360 | }
1361 |
1362 | /**
1363 | * 简化版 滚动过程中view的变换监听接口。
1364 | */
1365 | public static abstract class SimpleTrasitionListener {
1366 |
1367 | /**
1368 | * 返回堆叠view最大透明度
1369 | *
1370 | * @param maxLayerCount 最大层级
1371 | * @return
1372 | */
1373 | @FloatRange(from = 0.0f, to = 1.0f)
1374 | public float getLayerViewMaxAlpha(int maxLayerCount) {
1375 | return getFocusingViewMaxAlpha();
1376 | }
1377 |
1378 | /**
1379 | * 返回堆叠view最小透明度
1380 | *
1381 | * @param maxLayerCount 最大层级
1382 | * @return
1383 | */
1384 | @FloatRange(from = 0.0f, to = 1.0f)
1385 | public float getLayerViewMinAlpha(int maxLayerCount) {
1386 | return 0;
1387 | }
1388 |
1389 |
1390 | /**
1391 | * 返回堆叠view最大缩放比例
1392 | *
1393 | * @param maxLayerCount 最大层级
1394 | * @return
1395 | */
1396 | public float getLayerViewMaxScale(int maxLayerCount) {
1397 | return getFocusingViewMaxScale();
1398 | }
1399 |
1400 | /**
1401 | * 返回堆叠view最小缩放比例
1402 | *
1403 | * @param maxLayerCount 最大层级
1404 | * @return
1405 | */
1406 | public float getLayerViewMinScale(int maxLayerCount) {
1407 | return 0.7f;
1408 | }
1409 |
1410 |
1411 | /**
1412 | * 返回一个百分比值,相对于"一次完整的聚焦滑动"期间,在该百分比值内view就完成缩放、透明度的渐变变化。
1413 | * 例:若返回值为1,说明在"一次完整的聚焦滑动"期间view将线性均匀完成缩放、透明度变化;
1414 | * 例:若返回值为0.5,说明在"一次完整的聚焦滑动"的一半路程内(具体从什么时候开始变由实际逻辑自己决定),view将完成的缩放、透明度变化
1415 | *
1416 | * @return
1417 | */
1418 | @FloatRange(from = 0.0f, to = 1.0f)
1419 | public float getLayerChangeRangePercent() {
1420 | return 0.35f;
1421 | }
1422 |
1423 | /**
1424 | * 返回聚焦view的最大透明度
1425 | *
1426 | * @return
1427 | */
1428 | @FloatRange(from = 0.0f, to = 1.0f)
1429 | public float getFocusingViewMaxAlpha() {
1430 | return 1f;
1431 | }
1432 |
1433 | /**
1434 | * 返回聚焦view的最小透明度
1435 | *
1436 | * @return
1437 | */
1438 | @FloatRange(from = 0.0f, to = 1.0f)
1439 | public float getFocusingViewMinAlpha() {
1440 | return getNormalViewAlpha();
1441 | }
1442 |
1443 | /**
1444 | * 返回聚焦view的最大缩放比例
1445 | *
1446 | * @return
1447 | */
1448 | public float getFocusingViewMaxScale() {
1449 | return 1.2f;
1450 | }
1451 |
1452 | /**
1453 | * 返回聚焦view的最小缩放比例
1454 | *
1455 | * @return
1456 | */
1457 | public float getFocusingViewMinScale() {
1458 | return getNormalViewScale();
1459 | }
1460 |
1461 | /**
1462 | * 返回值意义参考{@link #getLayerChangeRangePercent()}
1463 | *
1464 | * @return
1465 | */
1466 | @FloatRange(from = 0.0f, to = 1.0f)
1467 | public float getFocusingViewChangeRangePercent() {
1468 | return 0.5f;
1469 | }
1470 |
1471 | /**
1472 | * 返回普通view的透明度
1473 | *
1474 | * @return
1475 | */
1476 | @FloatRange(from = 0.0f, to = 1.0f)
1477 | public float getNormalViewAlpha() {
1478 | return 1.0f;
1479 | }
1480 |
1481 | /**
1482 | * 返回普通view的缩放比例
1483 | *
1484 | * @return
1485 | */
1486 | public float getNormalViewScale() {
1487 | return 1.0f;
1488 | }
1489 |
1490 | }
1491 |
1492 | /**
1493 | * 将SimpleTrasitionListener转换成实际的TrasitionListener的转换器
1494 | */
1495 | public static class TrasitionListenerConvert implements TrasitionListener {
1496 | SimpleTrasitionListener stl;
1497 |
1498 | public TrasitionListenerConvert(SimpleTrasitionListener simpleTrasitionListener) {
1499 | stl = simpleTrasitionListener;
1500 | }
1501 |
1502 | @Override
1503 | public void handleLayerView(FocusLayoutManager focusLayoutManager, View view,
1504 | int viewLayer, int maxLayerCount, int position,
1505 | float fraction, float offset) {
1506 | /**
1507 | * 期望效果:从0%开始到{@link SimpleTrasitionListener#getLayerChangeRangePercent()} 期间
1508 | * view均匀完成渐变,之后一直保持不变
1509 | */
1510 | //转换为真实的渐变变化百分比
1511 | float realFraction;
1512 | if (fraction <= stl.getLayerChangeRangePercent()) {
1513 | realFraction = fraction / stl.getLayerChangeRangePercent();
1514 | } else {
1515 | realFraction = 1.0f;
1516 | }
1517 |
1518 | float minScale = stl.getLayerViewMinScale(maxLayerCount);
1519 | float maxScale = stl.getLayerViewMaxScale(maxLayerCount);
1520 | float scaleDelta = maxScale - minScale; //总缩放差
1521 | float currentLayerMaxScale =
1522 | minScale + scaleDelta * (viewLayer + 1) / (maxLayerCount * 1.0f);
1523 | float currentLayerMinScale = minScale + scaleDelta * viewLayer / (maxLayerCount * 1.0f);
1524 | float realScale =
1525 | currentLayerMaxScale - (currentLayerMaxScale - currentLayerMinScale) * realFraction;
1526 |
1527 | float minAlpha = stl.getLayerViewMinAlpha(maxLayerCount);
1528 | float maxAlpha = stl.getLayerViewMaxAlpha(maxLayerCount);
1529 | float alphaDelta = maxAlpha - minAlpha; //总透明度差
1530 | float currentLayerMaxAlpha =
1531 | minAlpha + alphaDelta * (viewLayer + 1) / (maxLayerCount * 1.0f);
1532 | float currentLayerMinAlpha = minAlpha + alphaDelta * viewLayer / (maxLayerCount * 1.0f);
1533 | float realAlpha =
1534 | currentLayerMaxAlpha - (currentLayerMaxAlpha - currentLayerMinAlpha) * realFraction;
1535 |
1536 | // log("layer =" + viewLayer + ";alpha = " + realAlpha + ";fraction = " + fraction);
1537 | view.setScaleX(realScale);
1538 | view.setScaleY(realScale);
1539 | view.setAlpha(realAlpha);
1540 |
1541 | }
1542 |
1543 | @Override
1544 | public void handleFocusingView(FocusLayoutManager focusLayoutManager, View view,
1545 | int position, float fraction, float offset) {
1546 | /**
1547 | * 期望效果:从0%开始到{@link SimpleTrasitionListener#getFocusingViewChangeRangePercent()} 期间
1548 | * view均匀完成渐变,之后一直保持不变
1549 | */
1550 | //转换为真实的渐变百分比
1551 | float realFraction;
1552 | if (fraction <= stl.getFocusingViewChangeRangePercent()) {
1553 | realFraction = fraction / stl.getFocusingViewChangeRangePercent();
1554 | } else {
1555 | realFraction = 1.0f;
1556 | }
1557 |
1558 | float realScale =
1559 | stl.getFocusingViewMinScale() + (stl.getFocusingViewMaxScale() - stl.getFocusingViewMinScale()) * realFraction;
1560 | float realAlpha =
1561 | stl.getFocusingViewMinAlpha() + (stl.getFocusingViewMaxAlpha() - stl.getFocusingViewMinAlpha()) * realFraction;
1562 |
1563 | view.setScaleX(realScale);
1564 | view.setScaleY(realScale);
1565 | view.setAlpha(realAlpha);
1566 |
1567 | }
1568 |
1569 | @Override
1570 | public void handleNormalView(FocusLayoutManager focusLayoutManager, View view,
1571 | int position, float fraction, float offset) {
1572 | /**
1573 | * 期望效果:直接完成变换
1574 | */
1575 |
1576 | view.setScaleX(stl.getNormalViewScale());
1577 | view.setScaleY(stl.getNormalViewScale());
1578 | view.setAlpha(stl.getNormalViewAlpha());
1579 | }
1580 | }
1581 |
1582 |
1583 | public interface OnFocusChangeListener {
1584 |
1585 | /**
1586 | * @param focusdPosition
1587 | * @param lastFocusedPosition 可能为-1
1588 | */
1589 | void onFocusChanged(int focusdPosition, int lastFocusedPosition);
1590 | }
1591 |
1592 | public static float dp2px(Context context, float dp) {
1593 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
1594 | context.getResources().getDisplayMetrics());
1595 | }
1596 |
1597 |
1598 | public static void log(String msg) {
1599 | log(TAG, msg);
1600 | }
1601 |
1602 | public static void log(String tag, String msg) {
1603 | boolean isDebug = true;
1604 | if (isDebug) {
1605 | Log.d(tag, msg);
1606 | }
1607 | }
1608 |
1609 |
1610 | }
1611 |
--------------------------------------------------------------------------------
/focuslayoutmanager/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FocusLayoutManager
3 |
4 |
--------------------------------------------------------------------------------
/focuslayoutmanager/src/test/java/ccy/focuslayoutmanager/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package ccy.focuslayoutmanager;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat May 18 16:53:56 CST 2019
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.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/pic/341561604648_.pic.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/pic/341561604648_.pic.jpg
--------------------------------------------------------------------------------
/pic/detail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/pic/detail.png
--------------------------------------------------------------------------------
/pic/gif_hor.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/pic/gif_hor.gif
--------------------------------------------------------------------------------
/pic/gif_hor_2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/pic/gif_hor_2.gif
--------------------------------------------------------------------------------
/pic/gif_mac_os.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/pic/gif_mac_os.gif
--------------------------------------------------------------------------------
/pic/gif_ver.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/pic/gif_ver.gif
--------------------------------------------------------------------------------
/pic/hor.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/pic/hor.jpg
--------------------------------------------------------------------------------
/pic/ver.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CCY0122/FocusLayoutManager/165ae982f73433c3c73a56674a980ea9749cb656/pic/ver.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':focuslayoutmanager'
2 |
--------------------------------------------------------------------------------