├── .gitignore ├── LICENSE ├── README.md ├── layout.png ├── layout2.png ├── menu.png ├── method分析.txt └── recyclerView4Tv ├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── lp │ │ └── recyclerview4tv │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── lp │ │ │ └── recyclerview4tv │ │ │ ├── MainActivity.java │ │ │ ├── data │ │ │ └── Datas.java │ │ │ └── example │ │ │ ├── BaseExampleActivity.java │ │ │ ├── GridLayoutActivity.java │ │ │ ├── LinearLayoutActivity.java │ │ │ └── StaggeredGridActivity.java │ └── res │ │ ├── drawable │ │ └── select_border.9.png │ │ ├── layout │ │ ├── activity_grid_layout.xml │ │ ├── activity_main.xml │ │ ├── activity_staggered_grid.xml │ │ ├── activity_staggered_layout.xml │ │ ├── item_example.xml │ │ ├── item_linear_h.xml │ │ └── item_main_example.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── loaderror.png │ │ └── loading.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── lp │ └── recyclerview4tv │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── recyclerview4tvlibrary ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── lp │ │ └── recyclerview4tvlibrary │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── lp │ │ │ └── recyclerview4tvlibrary │ │ │ ├── effect │ │ │ ├── BaseEffect.java │ │ │ └── RecyclerViewEffect.java │ │ │ ├── utils │ │ │ ├── OperationManager.java │ │ │ └── ViewUtils.java │ │ │ └── view │ │ │ ├── FocusFrameView.java │ │ │ ├── MenuDialogView.java │ │ │ ├── OperateView.java │ │ │ └── TvRecyclerView.java │ └── res │ │ ├── drawable │ │ ├── menu_btn_bg.xml │ │ ├── shape_selected.xml │ │ └── shape_unselected.xml │ │ ├── layout │ │ ├── layout_menu_dialog.xml │ │ ├── layout_operateview.xml │ │ └── layout_place_holder.xml │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── lp │ └── recyclerview4tvlibrary │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | 39 | # Keystore files 40 | *.jks 41 | -------------------------------------------------------------------------------- /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 | # recyclerView4Tv 2 | 在Tv端使用的RecyclerView,修复了由于数据更新,导致的布局错乱,焦点乱跑. 3 | ![Aaron Swartz](https://github.com/lph2012/recyclerView4Tv/blob/master/menu.png) 4 | 5 | ![Aaron Swartz](https://github.com/lph2012/recyclerView4Tv/blob/master/layout.png) 6 | 7 | 8 | ![Aaron Swartz](https://github.com/lph2012/recyclerView4Tv/blob/master/layout2.png) 9 | -------------------------------------------------------------------------------- /layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/layout.png -------------------------------------------------------------------------------- /layout2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/layout2.png -------------------------------------------------------------------------------- /menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/menu.png -------------------------------------------------------------------------------- /method分析.txt: -------------------------------------------------------------------------------- 1 | 2 | //当前选中的第一个条目时候 3 | 11-18 10:15:37.236 8451-8451/com.lp.recyclerview4tv I/System.out: child:=========>android.support.v7.widget.AppCompatTextView{41e4b9d0 VFED..CL .F....I. 20,20-520,100 #7f0b0058 app:id/tv_example} 4 | 11-18 10:15:37.236 8451-8451/com.lp.recyclerview4tv I/System.out: rect:==========>Rect(0, 0 - 500, 80) 5 | 11-18 10:15:37.236 8451-8451/com.lp.recyclerview4tv I/System.out: ******************************** 6 | 11-18 10:15:37.236 8451-8451/com.lp.recyclerview4tv I/System.out: parentLeft:======>10 7 | 11-18 10:15:37.236 8451-8451/com.lp.recyclerview4tv I/System.out: parentTop:======>10 8 | 11-18 10:15:37.236 8451-8451/com.lp.recyclerview4tv I/System.out: parentRight:======>530 9 | 11-18 10:15:37.236 8451-8451/com.lp.recyclerview4tv I/System.out: parentBottom:======>610 10 | 11-18 10:15:37.236 8451-8451/com.lp.recyclerview4tv I/System.out: ******************************** 11 | 11-18 10:15:37.236 8451-8451/com.lp.recyclerview4tv I/System.out: childLeft:======>20 12 | 11-18 10:15:37.236 8451-8451/com.lp.recyclerview4tv I/System.out: childTop:======>20 13 | 11-18 10:15:37.236 8451-8451/com.lp.recyclerview4tv I/System.out: childRight:======>520 14 | 11-18 10:15:37.246 8451-8451/com.lp.recyclerview4tv I/System.out: childBottom:======>100 15 | 11-18 10:15:37.246 8451-8451/com.lp.recyclerview4tv I/System.out: ******************************** 16 | 11-18 10:15:37.246 8451-8451/com.lp.recyclerview4tv I/System.out: offScreenLeft:======>0 17 | 11-18 10:15:37.246 8451-8451/com.lp.recyclerview4tv I/System.out: offScreenTop:======>0 18 | 11-18 10:15:37.246 8451-8451/com.lp.recyclerview4tv I/System.out: offScreenRight:======>0 19 | 11-18 10:15:37.246 8451-8451/com.lp.recyclerview4tv I/System.out: offScreenBottom:======>0 20 | ... 21 | ... 22 | ... -------------------------------------------------------------------------------- /recyclerView4Tv/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /recyclerView4Tv/.idea/.name: -------------------------------------------------------------------------------- 1 | recyclerView4Tv -------------------------------------------------------------------------------- /recyclerView4Tv/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /recyclerView4Tv/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /recyclerView4Tv/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /recyclerView4Tv/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 25 | -------------------------------------------------------------------------------- /recyclerView4Tv/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /recyclerView4Tv/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /recyclerView4Tv/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /recyclerView4Tv/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, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | 167 | END OF TERMS AND CONDITIONS 168 | 169 | APPENDIX: How to apply the Apache License to your work 170 | 171 | To apply the Apache License to your work, attach the following boilerplate 172 | notice, with the fields enclosed by brackets "{}" replaced with your own 173 | identifying information. (Don't include the brackets!) The text should be 174 | enclosed in the appropriate comment syntax for the file format. We also 175 | recommend that a file or class name and description of purpose be included on 176 | the same "printed page" as the copyright notice for easier identification within 177 | third-party archives. 178 | 179 | Copyright 2016 lph_xiaoloulou 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /recyclerView4Tv/README.md: -------------------------------------------------------------------------------- 1 | #recyclerView4Tv 2 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion '23.0.3' 6 | 7 | defaultConfig { 8 | applicationId "com.lp.recyclerview4tv" 9 | minSdkVersion 16 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:24.2.1' 26 | compile project(':recyclerview4tvlibrary') 27 | compile 'com.github.bumptech.glide:glide:3.7.0' 28 | } 29 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\dev\android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/androidTest/java/com/lp/recyclerview4tv/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tv; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/java/com/lp/recyclerview4tv/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tv; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.TextView; 11 | 12 | import com.lp.recyclerview4tv.example.GridLayoutActivity; 13 | import com.lp.recyclerview4tv.example.LinearLayoutActivity; 14 | import com.lp.recyclerview4tv.example.StaggeredGridActivity; 15 | import com.lp.recyclerview4tvlibrary.view.FocusFrameView; 16 | import com.lp.recyclerview4tvlibrary.view.TvRecyclerView; 17 | 18 | public class MainActivity extends AppCompatActivity { 19 | 20 | private TvRecyclerView mTvList; 21 | private FocusFrameView mFocusFrame; 22 | private LinearLayoutManager mManager; 23 | 24 | private static final String[] mDatas = { 25 | "LinearLayout--->HORIZONTAL", 26 | "LinearLayout--->VERTICAL", 27 | "GridLayout--->HORIZONTAL", 28 | "GridLayout--->VERTICAL", 29 | "StaggeredGridLayout--->HORIZONTAL", 30 | "StaggeredGridLayout--->VERTICAL", 31 | }; 32 | private MenuAdapter mAdapter; 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_main); 38 | initView(); 39 | } 40 | 41 | 42 | private void initView() { 43 | mTvList = ((TvRecyclerView) findViewById(R.id.trv)); 44 | mFocusFrame = ((FocusFrameView) findViewById(R.id.frame)); 45 | mTvList.initFrame(mFocusFrame, R.drawable.select_border, -2); 46 | mManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); 47 | mTvList.setLayoutManager(mManager); 48 | mTvList.setOnItemListener(new TvRecyclerView.OnItemListener() { 49 | @Override 50 | public boolean onItemPreSelected(TvRecyclerView parent, View itemView, int position) { 51 | return false; 52 | } 53 | 54 | @Override 55 | public boolean onItemSelected(TvRecyclerView parent, View itemView, int position) { 56 | return false; 57 | } 58 | 59 | @Override 60 | public boolean onReviseFocusFollow(TvRecyclerView parent, View itemView, int position) { 61 | return false; 62 | } 63 | 64 | @Override 65 | public void onItemClick(TvRecyclerView parent, View itemView, int position) { 66 | switch (position) { 67 | case 0: 68 | Intent intent = new Intent(MainActivity.this, LinearLayoutActivity.class); 69 | intent.putExtra("isVertical", "0"); 70 | startActivity(intent); 71 | break; 72 | case 1: 73 | Intent intent1 = new Intent(MainActivity.this, LinearLayoutActivity.class); 74 | intent1.putExtra("isVertical", "1"); 75 | startActivity(intent1); 76 | break; 77 | case 2: 78 | Intent intent2 = new Intent(MainActivity.this, GridLayoutActivity.class); 79 | intent2.putExtra("isVertical", "0"); 80 | startActivity(intent2); 81 | break; 82 | case 3: 83 | Intent intent3 = new Intent(MainActivity.this, GridLayoutActivity.class); 84 | intent3.putExtra("isVertical", "1"); 85 | startActivity(intent3); 86 | break; 87 | case 4: 88 | Intent intent4 = new Intent(MainActivity.this, StaggeredGridActivity.class); 89 | intent4.putExtra("isVertical", "0"); 90 | startActivity(intent4); 91 | break; 92 | case 5: 93 | Intent intent5 = new Intent(MainActivity.this, StaggeredGridActivity.class); 94 | intent5.putExtra("isVertical", "1"); 95 | startActivity(intent5); 96 | break; 97 | } 98 | } 99 | 100 | @Override 101 | public boolean onItemLongClick(TvRecyclerView parent, View itemView, int position) { 102 | return false; 103 | } 104 | }); 105 | mAdapter = new MenuAdapter(); 106 | mTvList.setAdapter(mAdapter); 107 | } 108 | 109 | class MenuAdapter extends TvRecyclerView.TvAdapter { 110 | @Override 111 | public TvRecyclerView.TvViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 112 | return new MenuHolder(LayoutInflater.from(MainActivity.this).inflate(R.layout.item_main_example, parent, false)); 113 | } 114 | 115 | @Override 116 | public void onBindViewHolder(TvRecyclerView.TvViewHolder holder, int position) { 117 | ((TextView) holder.itemView).setText(mDatas[position]); 118 | } 119 | 120 | @Override 121 | public int getItemCount() { 122 | return mDatas.length; 123 | } 124 | 125 | @Override 126 | protected Object getData(int start) { 127 | return null; 128 | } 129 | } 130 | 131 | class MenuHolder extends TvRecyclerView.TvViewHolder { 132 | public MenuHolder(View itemView) { 133 | super(itemView); 134 | } 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/java/com/lp/recyclerview4tv/data/Datas.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tv.data; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by lph on 2016/11/3. 10 | * 模拟数据,如果想扩展可以使用RxJava 和 Retrofit 从网络获取资源 11 | */ 12 | public class Datas { 13 | private static List dataLists = new ArrayList<>(); 14 | 15 | //这样写会item条目越来越多,这种效果 16 | public static List getDatas() { 17 | String[] datas = { 18 | "http://img4.imgtn.bdimg.com/it/u=2263564587,3827516789&fm=11&gp=0.jpg", 19 | "http://img4.imgtn.bdimg.com/it/u=2001849689,2934143493&fm=11&gp=0.jpg", 20 | "http://img1.imgtn.bdimg.com/it/u=3757412355,3884139848&fm=21&gp=0.jpg", 21 | "http://img3.imgtn.bdimg.com/it/u=419977589,4263339770&fm=11&gp=0.jpg", 22 | "http://img4.imgtn.bdimg.com/it/u=3059488398,1048400338&fm=21&gp=0.jpg", 23 | "http://img3.imgtn.bdimg.com/it/u=1560600784,4035223257&fm=21&gp=0.jpg", 24 | "http://img3.imgtn.bdimg.com/it/u=2497352402,3816602579&fm=21&gp=0.jpg", 25 | "http://d.ifengimg.com/w155_h107_q80/p0.ifengimg.com/a/2016_45/293f360c3994b17_size66_w206_h142.jpg", 26 | "http://d.ifengimg.com/w512_h288_q80/p3.ifengimg.com/cmpp/2016/11/03/502bdc446946330749bd670e73252746_size298_w640_h360.jpg", 27 | "http://d.ifengimg.com/w132_h94_q80/p0.ifengimg.com/a/2016_45/be27daf8bd89165_size64_w554_h361.jpg", 28 | "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=412147864,1332891885&fm=80&w=179&h=119&img.jpg", 29 | "http://d.ifengimg.com/w132_h94_q80/p0.ifengimg.com/ifengimcp/pic/20161103/199466c84c143bc76a61_size9_w168_h120.jpg", 30 | "http://img1.imgtn.bdimg.com/it/u=1207158778,2343027651&fm=11&gp=0.jpg", 31 | "http://d.hiphotos.baidu.com/image/h%3D360/sign=856d60650933874483c5297a610fd937/55e736d12f2eb938e81944c7d0628535e5dd6f8a.jpg", 32 | "http://d.ifengimg.com/w166_h120/p0.ifengimg.com/ifengiclient/ipic/2016052821/swoole_location_0b913b85734fa084386466b74facd719_size96_w533_h768.jpg", 33 | "http://img4.imgtn.bdimg.com/it/u=2263564587,3827516789&fm=11&gp=0.jpg", 34 | "http://img4.imgtn.bdimg.com/it/u=2001849689,2934143493&fm=11&gp=0.jpg", 35 | "http://img1.imgtn.bdimg.com/it/u=3757412355,3884139848&fm=21&gp=0.jpg", 36 | "http://img3.imgtn.bdimg.com/it/u=419977589,4263339770&fm=11&gp=0.jpg", 37 | "http://img4.imgtn.bdimg.com/it/u=3059488398,1048400338&fm=21&gp=0.jpg", 38 | "http://img3.imgtn.bdimg.com/it/u=1560600784,4035223257&fm=21&gp=0.jpg", 39 | "http://img3.imgtn.bdimg.com/it/u=2497352402,3816602579&fm=21&gp=0.jpg", 40 | "http://d.ifengimg.com/w155_h107_q80/p0.ifengimg.com/a/2016_45/293f360c3994b17_size66_w206_h142.jpg", 41 | "http://d.ifengimg.com/w512_h288_q80/p3.ifengimg.com/cmpp/2016/11/03/502bdc446946330749bd670e73252746_size298_w640_h360.jpg", 42 | "http://d.ifengimg.com/w132_h94_q80/p0.ifengimg.com/a/2016_45/be27daf8bd89165_size64_w554_h361.jpg", 43 | "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=412147864,1332891885&fm=80&w=179&h=119&img.jpg", 44 | "http://d.ifengimg.com/w132_h94_q80/p0.ifengimg.com/ifengimcp/pic/20161103/199466c84c143bc76a61_size9_w168_h120.jpg", 45 | "http://img1.imgtn.bdimg.com/it/u=1207158778,2343027651&fm=11&gp=0.jpg", 46 | "http://d.hiphotos.baidu.com/image/h%3D360/sign=856d60650933874483c5297a610fd937/55e736d12f2eb938e81944c7d0628535e5dd6f8a.jpg", 47 | "http://d.ifengimg.com/w166_h120/p0.ifengimg.com/ifengiclient/ipic/2016052821/swoole_location_0b913b85734fa084386466b74facd719_size96_w533_h768.jpg", 48 | "http://img4.imgtn.bdimg.com/it/u=2263564587,3827516789&fm=11&gp=0.jpg", 49 | "http://img4.imgtn.bdimg.com/it/u=2001849689,2934143493&fm=11&gp=0.jpg", 50 | "http://img1.imgtn.bdimg.com/it/u=3757412355,3884139848&fm=21&gp=0.jpg", 51 | "http://img3.imgtn.bdimg.com/it/u=419977589,4263339770&fm=11&gp=0.jpg", 52 | "http://img4.imgtn.bdimg.com/it/u=3059488398,1048400338&fm=21&gp=0.jpg", 53 | "http://img3.imgtn.bdimg.com/it/u=1560600784,4035223257&fm=21&gp=0.jpg", 54 | "http://img3.imgtn.bdimg.com/it/u=2497352402,3816602579&fm=21&gp=0.jpg", 55 | "http://d.ifengimg.com/w155_h107_q80/p0.ifengimg.com/a/2016_45/293f360c3994b17_size66_w206_h142.jpg", 56 | "http://d.ifengimg.com/w512_h288_q80/p3.ifengimg.com/cmpp/2016/11/03/502bdc446946330749bd670e73252746_size298_w640_h360.jpg", 57 | "http://d.ifengimg.com/w132_h94_q80/p0.ifengimg.com/a/2016_45/be27daf8bd89165_size64_w554_h361.jpg", 58 | "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=412147864,1332891885&fm=80&w=179&h=119&img.jpg", 59 | "http://d.ifengimg.com/w132_h94_q80/p0.ifengimg.com/ifengimcp/pic/20161103/199466c84c143bc76a61_size9_w168_h120.jpg", 60 | "http://img1.imgtn.bdimg.com/it/u=1207158778,2343027651&fm=11&gp=0.jpg", 61 | "http://d.hiphotos.baidu.com/image/h%3D360/sign=856d60650933874483c5297a610fd937/55e736d12f2eb938e81944c7d0628535e5dd6f8a.jpg", 62 | "http://d.ifengimg.com/w166_h120/p0.ifengimg.com/ifengiclient/ipic/2016052821/swoole_location_0b913b85734fa084386466b74facd719_size96_w533_h768.jpg" 63 | }; 64 | if (dataLists.size() > 0) { 65 | return dataLists; 66 | } 67 | dataLists.addAll(Arrays.asList(datas)); 68 | // 下面这样写会抛出异常的,原因是因为Arrays.asList返回的ArrayList 并不是java.utils包下的ArrayList,而是java.utils.arrays.ArrayList 69 | //他们都实现了List接口 70 | //改ArrayList 不支持add 和 addAll操作,想想也毕竟是通过数组转换而来的,而数组的长度是不可以动态增加的 71 | // List list1 = Arrays.asList(datas); 72 | // List list2 = Arrays.asList(datas2); 73 | // list2.addAll(list1); 74 | return dataLists; 75 | } 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/java/com/lp/recyclerview4tv/example/BaseExampleActivity.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tv.example; 2 | 3 | import android.graphics.Rect; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.KeyEvent; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.ImageView; 13 | import android.widget.Toast; 14 | 15 | import com.bumptech.glide.Glide; 16 | import com.lp.recyclerview4tv.R; 17 | import com.lp.recyclerview4tv.data.Datas; 18 | import com.lp.recyclerview4tvlibrary.utils.OperationManager; 19 | import com.lp.recyclerview4tvlibrary.utils.ViewUtils; 20 | import com.lp.recyclerview4tvlibrary.view.FocusFrameView; 21 | import com.lp.recyclerview4tvlibrary.view.MenuDialogView; 22 | import com.lp.recyclerview4tvlibrary.view.OperateView; 23 | import com.lp.recyclerview4tvlibrary.view.TvRecyclerView; 24 | 25 | import java.util.ArrayList; 26 | import java.util.Collections; 27 | import java.util.List; 28 | 29 | /** 30 | * Created by lph on 2016/11/3. 31 | */ 32 | public abstract class BaseExampleActivity extends AppCompatActivity { 33 | 34 | private List mDatas = new ArrayList<>(); 35 | protected TvRecyclerView mTvRecyclerView; 36 | protected FocusFrameView mFocusFrame; 37 | protected DefaultAdapter mAdapter; 38 | protected String mIsVertical; 39 | private MenuDialogView mMenuDialog; 40 | private int mCurrentFocus; 41 | private OperationManager.OperateParameter mParameter; 42 | private OperationManager mManager; 43 | private List mOperateData; 44 | private View mCrurrentItemView; 45 | 46 | @Override 47 | protected void onCreate(@Nullable Bundle savedInstanceState) { 48 | super.onCreate(savedInstanceState); 49 | setContentView(getContentResource()); 50 | mIsVertical = getIntent().getStringExtra("isVertical"); 51 | initData(); 52 | initView(); 53 | } 54 | 55 | protected void initView() { 56 | mTvRecyclerView = ((TvRecyclerView) findViewById(R.id.trv)); 57 | mFocusFrame = ((FocusFrameView) findViewById(R.id.frame)); 58 | mTvRecyclerView.initFrame(mFocusFrame, R.drawable.select_border, getFramePadding()); 59 | mTvRecyclerView.setOnItemListener(getItemListener()); 60 | mTvRecyclerView.setLayoutManager(getLayoutManager()); 61 | mTvRecyclerView.setItemScale(1.1f); 62 | mAdapter = new DefaultAdapter(); 63 | mTvRecyclerView.setAdapter(mAdapter); 64 | } 65 | 66 | protected abstract RecyclerView.LayoutManager getLayoutManager(); 67 | 68 | protected TvRecyclerView.OnItemListener getItemListener() { 69 | return new TvRecyclerView.OnItemListener() { 70 | @Override 71 | public boolean onItemPreSelected(TvRecyclerView parent, View itemView, int position) { 72 | return false; 73 | } 74 | 75 | @Override 76 | public boolean onItemSelected(TvRecyclerView parent, View itemView, int position) { 77 | mCrurrentItemView = itemView; 78 | mCurrentFocus = position; 79 | return false; 80 | } 81 | 82 | @Override 83 | public boolean onReviseFocusFollow(TvRecyclerView parent, View itemView, int position) { 84 | return false; 85 | } 86 | 87 | @Override 88 | public void onItemClick(TvRecyclerView parent, View itemView, int position) { 89 | Toast.makeText(BaseExampleActivity.this, "按菜单键对item进行操作", Toast.LENGTH_LONG).show(); 90 | } 91 | 92 | @Override 93 | public boolean onItemLongClick(TvRecyclerView parent, View itemView, int position) { 94 | Toast.makeText(BaseExampleActivity.this, "onItemLongClick------>:" + position, Toast.LENGTH_SHORT).show(); 95 | return true; 96 | } 97 | }; 98 | } 99 | 100 | protected abstract int getFramePadding(); 101 | 102 | 103 | protected void initData() { 104 | /* for (int i = 0; i < 20; i++) { 105 | if (i < Datas.getDatas().size()) { 106 | mDatas.add(Datas.getDatas().get(i)); 107 | } else { 108 | mDatas.add(i + ""); 109 | } 110 | }*/ 111 | mDatas.clear(); 112 | for (String data : Datas.getDatas()) { 113 | mDatas.add(data); 114 | } 115 | } 116 | 117 | protected int getContentResource() { 118 | return R.layout.activity_main; 119 | } 120 | 121 | class DefaultAdapter extends TvRecyclerView.TvAdapter { 122 | @Override 123 | public TvRecyclerView.TvViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 124 | return getViewHolder(parent, viewType); 125 | } 126 | 127 | @Override 128 | public void onBindViewHolder(TvRecyclerView.TvViewHolder holder, int position) { 129 | changeSize(holder.itemView, position); 130 | holder.setData(mDatas.get(position)); 131 | } 132 | 133 | @Override 134 | public int getItemCount() { 135 | return mDatas.size(); 136 | } 137 | 138 | @Override 139 | public void onBindViewHolder(TvRecyclerView.TvViewHolder holder, int position, List payloads) { 140 | changeSize(holder.itemView, position); 141 | if (payloads != null && payloads.size() > 0) { 142 | holder.setData(mDatas.get(position)); 143 | } else { 144 | super.onBindViewHolder(holder, position, payloads); 145 | } 146 | } 147 | 148 | @Override 149 | protected Object getData(int start) { 150 | return mDatas.get(start); 151 | } 152 | } 153 | 154 | /** 155 | * 根据位置动态设置条目的大小,为了实现瀑布流效果 156 | * 157 | * @param itemView 当前的itemView 158 | * @param position 当前位置 159 | */ 160 | protected void changeSize(View itemView, int position) { 161 | 162 | } 163 | 164 | protected TvRecyclerView.TvViewHolder getViewHolder(ViewGroup parent, int viewType) { 165 | return new DefaultViewHolder(LayoutInflater.from(BaseExampleActivity.this).inflate(R.layout.item_example, parent, false)); 166 | } 167 | 168 | 169 | private int mCurrentDir = KeyEvent.KEYCODE_DPAD_LEFT; 170 | 171 | @Override 172 | public boolean onKeyDown(int keyCode, KeyEvent event) { 173 | if (keyCode == KeyEvent.KEYCODE_MENU) { 174 | // showMenu(); 175 | showMenuByManager(); 176 | return true; 177 | } 178 | if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { 179 | mCurrentDir = keyCode; 180 | } 181 | return super.onKeyDown(keyCode, event); 182 | } 183 | 184 | protected void showMenu() { 185 | if (mMenuDialog == null) { 186 | mMenuDialog = ((MenuDialogView) LayoutInflater.from(this).inflate(R.layout.layout_menu_dialog, null)); 187 | mMenuDialog.setOnMenuItemClickListener(new MenuDialogView.OnMenuItemClickListener() { 188 | @Override 189 | public boolean onMenuItemClick(View view) { 190 | switch (view.getId()) { 191 | case R.id.btn_add: 192 | mDatas.add(mCurrentFocus + 1, "https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1478153124&di=16d621c728b7dc54cb6aefc57fe700b4&src=http://pic15.nipic.com/20110716/7558254_103836442000_2.jpg"); 193 | mAdapter.notifyItemRangeInserted(mCurrentFocus + 1, 1); 194 | break; 195 | case R.id.btn_del: 196 | mDatas.remove(mCurrentFocus); 197 | mAdapter.notifyItemRangeRemoved(mCurrentFocus, 1); 198 | break; 199 | case R.id.btn_update: 200 | mDatas.set(mCurrentFocus, "http://img5.imgtn.bdimg.com/it/u=2551799743,2144415698&fm=21&gp=0.jpg"); 201 | //使用这个重载避免更新数据后闪屏,并且要重写onBinderViewHolder的重载 202 | mAdapter.notifyItemChangedWrapper(mCurrentFocus, 1); 203 | break; 204 | case R.id.btn_update_some: 205 | int index = mCurrentFocus + 3; 206 | for (int i = mCurrentFocus; i < (mDatas.size() - 1) && i < index; i++) { 207 | mDatas.set(i, "http://img5.imgtn.bdimg.com/it/u=2551799743,2144415698&fm=21&gp=0.jpg"); 208 | } 209 | mAdapter.notifyItemRangeChangedWrapper(mCurrentFocus, index, 1); 210 | break; 211 | case R.id.btn_move: 212 | if (mCurrentFocus < 2) { 213 | return false; 214 | } 215 | Collections.swap(mDatas, mCurrentFocus, mCurrentFocus - 2); 216 | mAdapter.notifyItemMoved(mCurrentFocus, mCurrentFocus - 2); 217 | mAdapter.notifyDataSetChanged(); 218 | mMenuDialog.updateLayout(); 219 | break; 220 | } 221 | return view.getId() != R.id.btn_move; 222 | } 223 | }); 224 | } 225 | int[] location = new int[2]; 226 | mFocusFrame.getLocationInWindow(location); 227 | mMenuDialog.ShowDialog(location[0], location[1]); 228 | } 229 | 230 | public void showMenuByManager() { 231 | mManager = OperationManager.newInstance(this); 232 | mManager.attachViewAndData(mTvRecyclerView, mAdapter, mDatas); 233 | OperateView ov = mManager.createOperateView(R.layout.layout_operateview); 234 | mParameter = new OperationManager.OperateParameter(); 235 | mOperateData = new ArrayList<>(); 236 | ov.setOnOperatingListener(new OperateView.OnOperatingListener() { 237 | @Override 238 | public void onItemAdd(Object data) { 239 | mOperateData.clear(); 240 | mOperateData.add("https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1478153124&di=16d621c728b7dc54cb6aefc57fe700b4&src=http://pic15.nipic.com/20110716/7558254_103836442000_2.jpg"); 241 | mParameter.setOperateCount(1); 242 | mParameter.setOperateData(mOperateData); 243 | mParameter.setCurrentOperatePosition(mCurrentFocus); 244 | mParameter.setOperateType(OperationManager.OPERATION_TYPE_ADD); 245 | mManager.operateItem(mParameter); 246 | } 247 | 248 | @Override 249 | public void onItemDelete(Object data) { 250 | mOperateData.clear(); 251 | mParameter.setCurrentOperatePosition(mCurrentFocus); 252 | mParameter.setOperateCount(1); 253 | mParameter.setOperateType(OperationManager.OPERATION_TYPE_DEL); 254 | mManager.operateItem(mParameter); 255 | } 256 | 257 | @Override 258 | public void onItemUpdate(Object data) { 259 | mOperateData.clear(); 260 | mOperateData.add("http://img5.imgtn.bdimg.com/it/u=2551799743,2144415698&fm=21&gp=0.jpg"); 261 | mParameter.setOperateCount(1); 262 | mParameter.setOperateType(OperationManager.OPERATION_TYPE_UPDATE); 263 | mParameter.setOperateData(mOperateData); 264 | mParameter.setCurrentOperatePosition(mCurrentFocus); 265 | mManager.operateItem(mParameter); 266 | } 267 | 268 | @Override 269 | public void onItemMove(Object direction) { 270 | mParameter.setOperateType(OperationManager.OPERATION_TYPE_MOVE); 271 | mParameter.setCurrentOperatePosition(mCurrentFocus); 272 | mParameter.setMoveDirection(Integer.parseInt(direction.toString())); 273 | mManager.operateItem(mParameter); 274 | } 275 | }); 276 | Rect onScreenLocation = ViewUtils.getViewOnScreenLocation(mCrurrentItemView); 277 | //当x==y==0时,操作框显示在屏幕中央,否则会根据客户端传入的位置确定操作框的位置 278 | mManager.showOperateViewAt(onScreenLocation.left, onScreenLocation.top); 279 | } 280 | 281 | class DefaultViewHolder extends TvRecyclerView.TvViewHolder { 282 | private final ImageView mIv; 283 | 284 | public DefaultViewHolder(View itemView) { 285 | super(itemView); 286 | mIv = getView(R.id.iv); 287 | } 288 | 289 | @Override 290 | public void setData(Object obj) { 291 | Glide.with(BaseExampleActivity.this) 292 | .load(obj.toString()) 293 | .placeholder(R.mipmap.loading) 294 | .dontAnimate() 295 | .error(R.mipmap.loaderror) 296 | .into(mIv); 297 | } 298 | } 299 | 300 | @Override 301 | protected void onResume() { 302 | super.onResume(); 303 | Toast.makeText(this, "按菜单键对item进行操作", Toast.LENGTH_LONG).show(); 304 | } 305 | 306 | } 307 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/java/com/lp/recyclerview4tv/example/GridLayoutActivity.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tv.example; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.widget.GridLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | 7 | import com.lp.recyclerview4tvlibrary.utils.ViewUtils; 8 | 9 | public class GridLayoutActivity extends BaseExampleActivity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | } 15 | 16 | @Override 17 | protected RecyclerView.LayoutManager getLayoutManager() { 18 | if ("0".equals(mIsVertical)) { 19 | return new GridLayoutManager(this, 2, GridLayoutManager.HORIZONTAL, false); 20 | } else { 21 | return new GridLayoutManager(this, 5, GridLayoutManager.VERTICAL, false); 22 | } 23 | } 24 | 25 | @Override 26 | protected int getFramePadding() { 27 | return ViewUtils.dpToPx(this,-3); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/java/com/lp/recyclerview4tv/example/LinearLayoutActivity.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tv.example; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | public class LinearLayoutActivity extends BaseExampleActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | } 12 | 13 | @Override 14 | protected RecyclerView.LayoutManager getLayoutManager() { 15 | if ("0".equals(mIsVertical)) { 16 | return new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); 17 | } else { 18 | return new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); 19 | } 20 | } 21 | 22 | @Override 23 | protected int getFramePadding() { 24 | return 0; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/java/com/lp/recyclerview4tv/example/StaggeredGridActivity.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tv.example; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.support.v7.widget.StaggeredGridLayoutManager; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.lp.recyclerview4tv.R; 10 | import com.lp.recyclerview4tvlibrary.utils.ViewUtils; 11 | 12 | public class StaggeredGridActivity extends BaseExampleActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | } 18 | 19 | @Override 20 | protected RecyclerView.LayoutManager getLayoutManager() { 21 | if ("0".equals(mIsVertical)) { 22 | return new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.HORIZONTAL); 23 | } else { 24 | ViewGroup.LayoutParams layoutParams = 25 | mTvRecyclerView.getLayoutParams(); 26 | layoutParams.width = ViewUtils.dpToPx(this, 886f); 27 | mTvRecyclerView.setLayoutParams(layoutParams); 28 | return new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL); 29 | } 30 | } 31 | 32 | @Override 33 | protected int getContentResource() { 34 | return R.layout.activity_staggered_layout; 35 | } 36 | 37 | @Override 38 | protected int getFramePadding() { 39 | return ViewUtils.dpToPx(this, -2); 40 | } 41 | 42 | @Override 43 | protected void changeSize(View itemView, int position) { 44 | StaggeredGridLayoutManager.LayoutParams lp = (StaggeredGridLayoutManager.LayoutParams) itemView.getLayoutParams(); 45 | if ("0".equals(mIsVertical)) { 46 | if (position == 0 || position == 4) { 47 | lp.height = ViewUtils.dpToPx(this, 420); 48 | lp.width = ViewUtils.dpToPx(this, 220); 49 | lp.setFullSpan(true); 50 | } else if (position == 1) { 51 | lp.height = ViewUtils.dpToPx(this, 200); 52 | lp.width = ViewUtils.dpToPx(this, 420); 53 | lp.setFullSpan(false); 54 | } else { 55 | lp.height = ViewUtils.dpToPx(this, 200); 56 | lp.width = ViewUtils.dpToPx(this, 200); 57 | lp.setFullSpan(false); 58 | } 59 | } else { 60 | if (position == 0) { 61 | lp.width = StaggeredGridLayoutManager.LayoutParams.MATCH_PARENT; 62 | lp.height = ViewUtils.dpToPx(this, 266); 63 | lp.setFullSpan(true); 64 | } else if (position == 4 || position == 5 || position == 10) { 65 | lp.width = ViewUtils.dpToPx(this, 200); 66 | lp.height = ViewUtils.dpToPx(this, 420); 67 | lp.setFullSpan(false); 68 | } else { 69 | lp.width = ViewUtils.dpToPx(this, 200); 70 | lp.height = ViewUtils.dpToPx(this, 200); 71 | lp.setFullSpan(false); 72 | } 73 | } 74 | itemView.setLayoutParams(lp); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/drawable/select_border.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/recyclerView4Tv/app/src/main/res/drawable/select_border.9.png -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/layout/activity_grid_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 22 | 26 | 27 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/layout/activity_staggered_grid.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/layout/activity_staggered_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/layout/item_example.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/layout/item_linear_h.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/layout/item_main_example.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/recyclerView4Tv/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/mipmap-hdpi/loaderror.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/recyclerView4Tv/app/src/main/res/mipmap-hdpi/loaderror.png -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/mipmap-hdpi/loading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/recyclerView4Tv/app/src/main/res/mipmap-hdpi/loading.png -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/recyclerView4Tv/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/recyclerView4Tv/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/recyclerView4Tv/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/recyclerView4Tv/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #BF000000 7 | 8 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RecyclerView4Tv 3 | 4 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /recyclerView4Tv/app/src/test/java/com/lp/recyclerview4tv/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tv; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /recyclerView4Tv/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /recyclerView4Tv/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /recyclerView4Tv/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littleloulou/TvRecyclerView/5dbe5f3c92f67c64200387950c8418b00f7cf903/recyclerView4Tv/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /recyclerView4Tv/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Nov 02 11:48:43 CST 2016 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-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /recyclerView4Tv/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /recyclerView4Tv/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 16 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(include: ['*.jar'], dir: 'libs') 23 | testCompile 'junit:junit:4.12' 24 | compile 'com.android.support:appcompat-v7:24.2.1' 25 | compile 'com.android.support:recyclerview-v7:24.2.1' 26 | } 27 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\dev\android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/androidTest/java/com/lp/recyclerview4tvlibrary/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tvlibrary; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/java/com/lp/recyclerview4tvlibrary/effect/BaseEffect.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tvlibrary.effect; 2 | 3 | import android.animation.AnimatorSet; 4 | import android.animation.IntEvaluator; 5 | import android.animation.ObjectAnimator; 6 | import android.animation.ValueAnimator; 7 | import android.content.Context; 8 | import android.graphics.Canvas; 9 | import android.graphics.Rect; 10 | import android.graphics.drawable.Drawable; 11 | import android.util.TypedValue; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.view.animation.DecelerateInterpolator; 15 | 16 | import com.lp.recyclerview4tvlibrary.view.FocusFrameView; 17 | 18 | /** 19 | * Created by lph on 2016/11/2. 20 | */ 21 | public abstract class BaseEffect { 22 | public FocusFrameView mFocusFrameView; 23 | protected Rect mFocusFramePadding; 24 | protected int mDuration = 300; 25 | protected AnimatorSet mAnimatorSet; 26 | protected Drawable mFocusDrawable; 27 | private Context mContext; 28 | protected IntEvaluator mEvaluator = new IntEvaluator(); 29 | 30 | 31 | /** 32 | * 拿到焦点框引用 33 | * 34 | * @param focusFrameView 焦点框 35 | */ 36 | public void setFocusFrameView(FocusFrameView focusFrameView) { 37 | mFocusFrameView = focusFrameView; 38 | } 39 | 40 | public FocusFrameView getFocusFrameView() { 41 | return mFocusFrameView; 42 | } 43 | 44 | /** 45 | * 绘制移动的焦点框,由具体子类实现 46 | * 47 | * @param canvas 绘制焦点框时canvas实例 48 | */ 49 | public abstract boolean onFocusViewDraw(Canvas canvas); 50 | 51 | 52 | public abstract void onUnFocusView(View view); 53 | 54 | /** 55 | * 根据实际情况放大或者是缩小焦点框 56 | * 57 | * @param framePadding paddingLeft paddingTop paddingRight,paddingBottom 58 | */ 59 | public void setFocusFramePadding(Rect framePadding) { 60 | this.mFocusFramePadding = framePadding; 61 | } 62 | 63 | protected int mNewWidth = 0; 64 | protected int mNewHeight = 0; 65 | protected int mOldWidth = 0; 66 | protected int mOldHeight = 0; 67 | 68 | /** 69 | * 执行焦点移动动画效果 70 | * 71 | * @param focusView 获取焦点的View 72 | * @param moveView 焦点框 73 | * @param scaleX x轴的缩放 74 | * @param scaleY y轴的缩放 75 | */ 76 | protected void runFocusMoveAnimation(View focusView, final View moveView, float scaleX, float scaleY) { 77 | if (mAnimatorSet != null && mAnimatorSet.isRunning()) { 78 | return; 79 | } 80 | int newX = 0; 81 | int newY = 0; 82 | if (focusView != null) { 83 | mNewWidth = (int) (focusView.getMeasuredWidth() * scaleX); 84 | mNewHeight = (int) (focusView.getMeasuredHeight() * scaleY); 85 | mOldWidth = moveView.getMeasuredWidth(); 86 | mOldHeight = moveView.getMeasuredHeight(); 87 | Rect fromRect = findLocationWithView(moveView); 88 | Rect toRect = findLocationWithView(focusView); 89 | int x = toRect.left - fromRect.left; 90 | int y = toRect.top - fromRect.top; 91 | newX = x - Math.abs(focusView.getMeasuredWidth() - mNewWidth) / 2; 92 | newY = y - Math.abs(focusView.getMeasuredHeight() - mNewHeight) / 2; 93 | } 94 | 95 | mAnimatorSet = new AnimatorSet(); 96 | final ObjectAnimator transAnimatorX = ObjectAnimator.ofFloat(moveView, "translationX", newX); 97 | ObjectAnimator transAnimatorY = ObjectAnimator.ofFloat(moveView, "translationY", newY); 98 | transAnimatorX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 99 | @Override 100 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 101 | ViewGroup.LayoutParams lp = moveView.getLayoutParams(); 102 | lp.width = mEvaluator.evaluate(valueAnimator.getAnimatedFraction(), mOldWidth, mNewWidth); 103 | lp.height = mEvaluator.evaluate(valueAnimator.getAnimatedFraction(), mOldHeight, mNewHeight); 104 | moveView.setLayoutParams(lp); 105 | moveView.requestLayout(); 106 | } 107 | }); 108 | //获取焦点的view 109 | ObjectAnimator scaleFocusViewX = ObjectAnimator.ofFloat(focusView, "scaleX", scaleX); 110 | ObjectAnimator scaleFocusViewY = ObjectAnimator.ofFloat(focusView, "scaleY", scaleY); 111 | 112 | mAnimatorSet.playTogether(transAnimatorX, transAnimatorY, scaleFocusViewX, scaleFocusViewY); 113 | mAnimatorSet.setInterpolator(new DecelerateInterpolator(1)); 114 | mAnimatorSet.setDuration(mDuration); 115 | mAnimatorSet.start(); 116 | } 117 | 118 | protected Rect findLocationWithView(View view) { 119 | ViewGroup root = (ViewGroup) view.getParent(); 120 | Rect rect = new Rect(); 121 | root.offsetDescendantRectToMyCoords(view, rect); 122 | return rect; 123 | } 124 | 125 | /** 126 | * 焦点移动 127 | * 128 | * @param focusView 当前获取焦点的View 129 | * @param scaleX x轴的缩放比例 130 | * @param scaleY Y轴的缩放比例 131 | */ 132 | public abstract void onFocusView(View focusView, float scaleX, float scaleY); 133 | 134 | public void setFocusView(View focusView, float scale) { 135 | onFocusView(focusView, scale, scale); 136 | } 137 | 138 | public void setUnFocusView(View unFocusView) { 139 | onUnFocusView(unFocusView); 140 | } 141 | 142 | /** 143 | * 设置显示的焦点框 144 | * 145 | * @param focusDrawable drawable 146 | */ 147 | public void setFocusDrawable(Drawable focusDrawable) { 148 | mFocusDrawable = focusDrawable; 149 | } 150 | 151 | /** 152 | * 设置显示的焦点框 153 | * 154 | * @param resource 资源id 155 | */ 156 | public void setFocusResource(int resource) { 157 | mFocusDrawable = mContext.getResources().getDrawable(resource); 158 | } 159 | 160 | public void init(Context context) { 161 | mContext = context; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/java/com/lp/recyclerview4tvlibrary/effect/RecyclerViewEffect.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tvlibrary.effect; 2 | 3 | import android.animation.AnimatorSet; 4 | import android.animation.ObjectAnimator; 5 | import android.animation.ValueAnimator; 6 | import android.graphics.Canvas; 7 | import android.graphics.Rect; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.view.animation.DecelerateInterpolator; 11 | 12 | import com.lp.recyclerview4tvlibrary.view.TvRecyclerView; 13 | 14 | /** 15 | * Created by lph on 2016/11/2. 16 | * 17 | */ 18 | public class RecyclerViewEffect extends BaseEffect { 19 | 20 | @Override 21 | public boolean onFocusViewDraw(Canvas canvas) { 22 | if (mFocusDrawable != null && mFocusFramePadding != null) { 23 | canvas.save(); 24 | int width = mFocusFrameView.getWidth(); 25 | int height = mFocusFrameView.getHeight(); 26 | Rect padding = new Rect(); 27 | // 边框的绘制. 28 | mFocusDrawable.getPadding(padding); 29 | mFocusDrawable.setBounds(-padding.left - (mFocusFramePadding.left), -padding.top - (mFocusFramePadding.top), 30 | width + padding.right + (mFocusFramePadding.right), height + padding.bottom + (mFocusFramePadding.bottom)); 31 | mFocusDrawable.draw(canvas); 32 | canvas.restore(); 33 | return true; 34 | } else { 35 | return false; 36 | } 37 | } 38 | 39 | @Override 40 | public void onUnFocusView(View view) { 41 | if (view == null) return; 42 | view.animate().scaleX(1.0f).scaleY(1.0f).setDuration(mDuration).start(); 43 | } 44 | 45 | @Override 46 | public void onFocusView(View focusView, float scaleX, float scaleY) { 47 | if (focusView == null) return; 48 | //执行移动动画 49 | runFocusMoveAnimation(focusView, mFocusFrameView, scaleX, scaleY); 50 | } 51 | 52 | @Override 53 | protected void runFocusMoveAnimation(View focusView, final View moveView, float scaleX, float scaleY) { 54 | if (mAnimatorSet != null && mAnimatorSet.isRunning()) { 55 | mAnimatorSet.cancel(); 56 | } 57 | int newX = 0; 58 | int newY = 0; 59 | if (focusView != null) { 60 | mNewWidth = (int) (focusView.getMeasuredWidth() * scaleX); 61 | mNewHeight = (int) (focusView.getMeasuredHeight() * scaleY); 62 | mOldWidth = moveView.getMeasuredWidth(); 63 | mOldHeight = moveView.getMeasuredHeight(); 64 | Rect fromRect = findLocationWithView(moveView); 65 | Rect toRect = findLocationWithView(focusView); 66 | // 这里用来修正由于recyclerView滚动导致的焦点框错位 67 | if (null != focusView.getParent() && focusView.getParent() instanceof TvRecyclerView) { 68 | TvRecyclerView rv = (TvRecyclerView) focusView.getParent(); 69 | int offset = rv.getSelectedItemScrollOffset(); 70 | if (offset != -1) { 71 | toRect.offset(rv.getLayoutManager().canScrollHorizontally() ? -offset : 0, 72 | rv.getLayoutManager().canScrollVertically() ? -offset : 0); 73 | } 74 | } 75 | 76 | int x = toRect.left - fromRect.left; 77 | int y = toRect.top - fromRect.top; 78 | newX = x - Math.abs(focusView.getMeasuredWidth() - mNewWidth) / 2; 79 | newY = y - Math.abs(focusView.getMeasuredHeight() - mNewHeight) / 2; 80 | } 81 | mAnimatorSet = new AnimatorSet(); 82 | //焦点框 83 | final ObjectAnimator transAnimatorX = ObjectAnimator.ofFloat(moveView, "translationX", newX); 84 | ObjectAnimator transAnimatorY = ObjectAnimator.ofFloat(moveView, "translationY", newY); 85 | transAnimatorX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 86 | @Override 87 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 88 | ViewGroup.LayoutParams lp = moveView.getLayoutParams(); 89 | lp.width = mEvaluator.evaluate(valueAnimator.getAnimatedFraction(), mOldWidth, mNewWidth); 90 | lp.height = mEvaluator.evaluate(valueAnimator.getAnimatedFraction(), mOldHeight, mNewHeight); 91 | moveView.setLayoutParams(lp); 92 | moveView.requestLayout(); 93 | } 94 | }); 95 | //获取焦点的view 96 | ObjectAnimator scaleFocusViewX = ObjectAnimator.ofFloat(focusView, "scaleX", scaleX); 97 | ObjectAnimator scaleFocusViewY = ObjectAnimator.ofFloat(focusView, "scaleY", scaleY); 98 | mAnimatorSet.playTogether(transAnimatorX, transAnimatorY, scaleFocusViewX, scaleFocusViewY); 99 | mAnimatorSet.setInterpolator(new DecelerateInterpolator(1)); 100 | mAnimatorSet.setDuration(mDuration); 101 | mAnimatorSet.start(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/java/com/lp/recyclerview4tvlibrary/utils/OperationManager.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tvlibrary.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.Rect; 5 | import android.support.annotation.NonNull; 6 | import android.support.v7.widget.GridLayoutManager; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.support.v7.widget.StaggeredGridLayoutManager; 10 | import android.util.DisplayMetrics; 11 | import android.view.Gravity; 12 | import android.view.KeyEvent; 13 | import android.view.LayoutInflater; 14 | import android.view.View; 15 | import android.view.ViewTreeObserver; 16 | import android.view.WindowManager; 17 | 18 | import com.lp.recyclerview4tvlibrary.view.OperateView; 19 | import com.lp.recyclerview4tvlibrary.view.TvRecyclerView; 20 | 21 | import java.util.Collections; 22 | import java.util.List; 23 | 24 | /** 25 | * Created by lph on 2016/12/8. 26 | * 对条目操作的管理类 27 | */ 28 | public class OperationManager { 29 | private final LayoutInflater mLayoutInflater; 30 | private Context mContext; 31 | /** 32 | * 操作类型 33 | */ 34 | public final static int OPERATION_TYPE_ADD = 1000; 35 | public final static int OPERATION_TYPE_UPDATE = OPERATION_TYPE_ADD + 1; 36 | public final static int OPERATION_TYPE_DEL = OPERATION_TYPE_ADD + 2; 37 | public final static int OPERATION_TYPE_MOVE = OPERATION_TYPE_ADD + 3; 38 | private final static String TAG = "OperationManager"; 39 | private TvRecyclerView mRecyclerView; 40 | private TvRecyclerView.TvAdapter mAdapter; 41 | private List mData; 42 | 43 | private OperateView mOperateView; 44 | 45 | private boolean mHadShow; 46 | private WindowManager mWm; 47 | private WindowManager.LayoutParams mWmParams; 48 | private RecyclerView.LayoutManager mLayoutManager; 49 | 50 | 51 | private OperationManager(Context context) { 52 | mContext = context; 53 | mLayoutInflater = LayoutInflater.from(context); 54 | } 55 | 56 | private static OperationManager instance; 57 | 58 | public static OperationManager newInstance(Context context) { 59 | if (instance == null) { 60 | synchronized (OperationManager.class) { 61 | if (instance == null) { 62 | instance = new OperationManager(context); 63 | } 64 | } 65 | } 66 | return instance; 67 | } 68 | 69 | public void attachViewAndData(TvRecyclerView containerView, TvRecyclerView.TvAdapter adapter, List data) { 70 | mRecyclerView = containerView; 71 | mLayoutManager = mRecyclerView.getLayoutManager(); 72 | mAdapter = adapter; 73 | mData = data; 74 | mRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 75 | @Override 76 | public void onGlobalLayout() { 77 | View focusedChild = mRecyclerView.getFocusedChild(); 78 | if (mWm != null && mWmParams != null && focusedChild != null) { 79 | Rect location = ViewUtils.getViewOnScreenLocation(focusedChild); 80 | mWmParams.x = location.left; 81 | mWmParams.y = location.top; 82 | mWm.updateViewLayout(mOperateView, mWmParams); 83 | } 84 | } 85 | }); 86 | } 87 | 88 | public OperateView createOperateView(OperateView operateView) { 89 | mOperateView = operateView; 90 | return operateView; 91 | } 92 | 93 | public OperateView createOperateView(int layoutId) { 94 | View operateView = mLayoutInflater.inflate(layoutId, null); 95 | if (operateView instanceof OperateView) { 96 | mOperateView = ((OperateView) operateView); 97 | return mOperateView; 98 | } else { 99 | throw new IllegalArgumentException("a layout must be a operateView or it's descendant !!!"); 100 | } 101 | 102 | } 103 | 104 | public void showOperateViewAt(int locationX, int locationY) { 105 | dismissOperateView(); 106 | if (mOperateView == null) { 107 | throw new IllegalStateException("mOperateView can't be null!!!"); 108 | } 109 | mWm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); 110 | mWmParams = new WindowManager.LayoutParams(); 111 | mWmParams.type = WindowManager.LayoutParams.TYPE_PHONE; 112 | mWmParams.gravity = Gravity.START | Gravity.TOP; 113 | mOperateView.measure(0, 0); 114 | if (locationX == 0 && locationY == 0) { 115 | DisplayMetrics outMetrics = new DisplayMetrics(); 116 | mWm.getDefaultDisplay().getMetrics(outMetrics); 117 | locationX = outMetrics.widthPixels / 2 - mOperateView.getMeasuredWidth() / 2; 118 | locationY = outMetrics.heightPixels / 2 - mOperateView.getMeasuredHeight() / 2; 119 | } 120 | mWmParams.x = locationX; 121 | mWmParams.y = locationY; 122 | mWmParams.width = ViewUtils.dpToPx(mContext, mOperateView.getMeasuredWidth()); 123 | mWmParams.height = ViewUtils.dpToPx(mContext, mOperateView.getMeasuredHeight()); 124 | mWmParams.format = 1; 125 | mWm.addView(mOperateView, mWmParams); 126 | mHadShow = true; 127 | } 128 | 129 | public void dismissOperateView() { 130 | if (mOperateView == null) { 131 | throw new IllegalStateException("mOperateView can't be null!!!"); 132 | } 133 | if (mWm != null) { 134 | mWm.removeView(mOperateView); 135 | mWm = null; 136 | } 137 | mHadShow = false; 138 | } 139 | 140 | /** 141 | * 操作条目的封装 142 | * 143 | * @param parameter 操作参数 144 | */ 145 | public void operateItem(@NonNull OperateParameter parameter) { 146 | int currentFocus = parameter.getCurrentOperatePosition(); 147 | int operateCount = parameter.getOperateCount(); 148 | List operateData = parameter.getOperateData(); 149 | switch (parameter.getOperateType()) { 150 | case OPERATION_TYPE_ADD: 151 | for (int i = 0; i < operateCount; i++) { 152 | mData.add(currentFocus + 1 + i, operateData.get(i)); 153 | } 154 | mAdapter.notifyItemRangeInserted(currentFocus + 1, operateCount); 155 | break; 156 | case OPERATION_TYPE_DEL: 157 | for (int i = 0; i < operateCount; i++) { 158 | mData.remove(currentFocus + i); 159 | } 160 | mAdapter.notifyItemRangeRemoved(currentFocus, operateCount); 161 | break; 162 | case OPERATION_TYPE_UPDATE: 163 | for (int i = 0; i < operateCount; i++) { 164 | System.out.println("mData:" + mData); 165 | mData.set(currentFocus + i, operateData.get(i)); 166 | } 167 | mAdapter.notifyItemRangeChangedWrapper(currentFocus, operateCount, "payload"); 168 | break; 169 | case OPERATION_TYPE_MOVE: 170 | switch (parameter.getMoveDirection()) { 171 | case KeyEvent.KEYCODE_DPAD_LEFT: 172 | moveToLeftOrUp(KeyEvent.KEYCODE_DPAD_LEFT, currentFocus); 173 | break; 174 | case KeyEvent.KEYCODE_DPAD_UP: 175 | moveToLeftOrUp(KeyEvent.KEYCODE_DPAD_UP, currentFocus); 176 | break; 177 | case KeyEvent.KEYCODE_DPAD_RIGHT: 178 | moveToRightOrDown(KeyEvent.KEYCODE_DPAD_RIGHT, currentFocus); 179 | break; 180 | case KeyEvent.KEYCODE_DPAD_DOWN: 181 | moveToRightOrDown(KeyEvent.KEYCODE_DPAD_DOWN, currentFocus); 182 | break; 183 | } 184 | break; 185 | } 186 | } 187 | 188 | 189 | private void moveToRightOrDown(int moveDir, int currentFocus) { 190 | int moveNum = calcMoveNum(moveDir); 191 | if (mData == null || mData.size() < moveNum || currentFocus + moveNum >= mData.size()) 192 | return; 193 | notifyMove(currentFocus, currentFocus + moveNum); 194 | } 195 | 196 | 197 | private void moveToLeftOrUp(int moveDir, int currentFocus) { 198 | int moveNum = calcMoveNum(moveDir); 199 | if (mData == null || mData.size() < moveNum || currentFocus - moveNum < 0) return; 200 | notifyMove(currentFocus, currentFocus - moveNum); 201 | } 202 | 203 | private void notifyMove(int currentFocus, int newFocus) { 204 | Collections.swap(mData, currentFocus, newFocus); 205 | mAdapter.notifyItemChanged(currentFocus, "payLoad"); 206 | mAdapter.notifyItemChanged(newFocus, "payLoad"); 207 | } 208 | 209 | public int calcMoveNum(int moveDirection) { 210 | RecyclerView.LayoutManager layoutManager = 211 | mRecyclerView.getLayoutManager(); 212 | if (layoutManager instanceof GridLayoutManager) { 213 | if (((GridLayoutManager) layoutManager).getOrientation() == GridLayoutManager.HORIZONTAL) { 214 | if (moveDirection == KeyEvent.KEYCODE_DPAD_LEFT || moveDirection == KeyEvent.KEYCODE_DPAD_RIGHT) { 215 | return ((GridLayoutManager) layoutManager).getSpanCount(); 216 | } else { 217 | return 1; 218 | } 219 | } else { 220 | if (moveDirection == KeyEvent.KEYCODE_DPAD_DOWN || moveDirection == KeyEvent.KEYCODE_DPAD_UP) { 221 | return ((GridLayoutManager) layoutManager).getSpanCount(); 222 | } else { 223 | return 1; 224 | } 225 | } 226 | } else if (layoutManager instanceof LinearLayoutManager) { 227 | return 1; 228 | } else if (layoutManager instanceof StaggeredGridLayoutManager) { 229 | if (((StaggeredGridLayoutManager) layoutManager).getOrientation() == StaggeredGridLayoutManager.HORIZONTAL) { 230 | if (moveDirection == KeyEvent.KEYCODE_DPAD_LEFT || moveDirection == KeyEvent.KEYCODE_DPAD_DOWN) { 231 | return ((StaggeredGridLayoutManager) layoutManager).getSpanCount(); 232 | } else { 233 | return 1; 234 | } 235 | } else { 236 | if (moveDirection == KeyEvent.KEYCODE_DPAD_DOWN || moveDirection == KeyEvent.KEYCODE_DPAD_UP) { 237 | return ((StaggeredGridLayoutManager) layoutManager).getSpanCount(); 238 | } else { 239 | return 1; 240 | } 241 | } 242 | } 243 | return 1; 244 | } 245 | 246 | 247 | public static class OperateParameter { 248 | private int operateType; 249 | private int currentOperatePosition; 250 | private int operateCount; 251 | private List operateData; 252 | 253 | public int getMoveDirection() { 254 | return moveDirection; 255 | } 256 | 257 | public void setMoveDirection(int moveDirection) { 258 | this.moveDirection = moveDirection; 259 | } 260 | 261 | private int moveDirection; 262 | 263 | public int getOperateType() { 264 | return operateType; 265 | } 266 | 267 | public void setOperateType(int operateType) { 268 | this.operateType = operateType; 269 | } 270 | 271 | public int getCurrentOperatePosition() { 272 | return currentOperatePosition; 273 | } 274 | 275 | public void setCurrentOperatePosition(int currentOperatePosition) { 276 | this.currentOperatePosition = currentOperatePosition; 277 | } 278 | 279 | public int getOperateCount() { 280 | return operateCount; 281 | } 282 | 283 | public void setOperateCount(int operateCount) { 284 | this.operateCount = operateCount; 285 | } 286 | 287 | public List getOperateData() { 288 | return operateData; 289 | } 290 | 291 | public void setOperateData(List operateData) { 292 | this.operateData = operateData; 293 | } 294 | } 295 | 296 | } 297 | 298 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/java/com/lp/recyclerview4tvlibrary/utils/ViewUtils.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tvlibrary.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.Rect; 5 | import android.view.View; 6 | 7 | /** 8 | * Created by lph on 2016/11/3. 9 | */ 10 | public class ViewUtils { 11 | public static int dpToPx(Context ctx, float dp) { 12 | final float scale = ctx.getResources().getDisplayMetrics().density; 13 | return (int) (dp * scale + 0.5f); 14 | } 15 | 16 | public static int pxToDp(Context ctx, float px) { 17 | final float scale = ctx.getResources().getDisplayMetrics().density; 18 | return (int) (px / scale + 0.5f); 19 | } 20 | 21 | public static Rect getViewOnScreenLocation(View view) { 22 | Rect area = new Rect(); 23 | view.getGlobalVisibleRect(area); 24 | return area; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/java/com/lp/recyclerview4tvlibrary/view/FocusFrameView.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tvlibrary.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Rect; 6 | import android.util.AttributeSet; 7 | import android.widget.FrameLayout; 8 | 9 | import com.lp.recyclerview4tvlibrary.effect.BaseEffect; 10 | 11 | /** 12 | * Created by lph on 2016/11/2. 13 | * FocusFrameView 焦点移动框. 14 | */ 15 | public class FocusFrameView extends FrameLayout { 16 | 17 | 18 | private BaseEffect mEffect; 19 | 20 | public BaseEffect getEffect() { 21 | return mEffect; 22 | } 23 | 24 | public void setEffect(BaseEffect effect) { 25 | if (effect == null) { 26 | throw new RuntimeException("parameter effect can'not is null"); 27 | } 28 | this.mEffect = effect; 29 | mEffect.setFocusFrameView(this); 30 | mEffect.init(getContext()); 31 | } 32 | 33 | public FocusFrameView(Context context) { 34 | this(context, null); 35 | } 36 | 37 | public FocusFrameView(Context context, AttributeSet attrs) { 38 | this(context, attrs, 0); 39 | } 40 | 41 | public FocusFrameView(Context context, AttributeSet attrs, int defStyleAttr) { 42 | super(context, attrs, defStyleAttr); 43 | init(); 44 | } 45 | 46 | private void init() { 47 | setWillNotDraw(false); 48 | } 49 | 50 | @Override 51 | protected void onDraw(Canvas canvas) { 52 | if (mEffect == null) { 53 | throw new RuntimeException("mEffect can'not is null"); 54 | } 55 | if (!mEffect.onFocusViewDraw(canvas)) { 56 | super.onDraw(canvas); 57 | } 58 | } 59 | 60 | public void setFocusFramePadding(int padding) { 61 | if (mEffect == null) { 62 | throw new RuntimeException("mEffect can'not is null"); 63 | } 64 | mEffect.setFocusFramePadding(new Rect(padding, padding, padding, padding)); 65 | invalidate(); 66 | } 67 | 68 | public void setFocusFramePadding(Rect padding) { 69 | if (mEffect == null) { 70 | throw new RuntimeException("mEffect can'not is null"); 71 | } 72 | mEffect.setFocusFramePadding(padding); 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/java/com/lp/recyclerview4tvlibrary/view/MenuDialogView.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tvlibrary.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.Gravity; 6 | import android.view.KeyEvent; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.view.WindowManager; 10 | import android.widget.ScrollView; 11 | 12 | import com.lp.recyclerview4tvlibrary.utils.ViewUtils; 13 | 14 | /** 15 | * Created by lph on 2016/11/1. 16 | */ 17 | public class MenuDialogView extends ScrollView implements View.OnClickListener { 18 | 19 | private WindowManager mWm; 20 | private WindowManager.LayoutParams mWmParams; 21 | 22 | public MenuDialogView(Context context) { 23 | super(context); 24 | } 25 | 26 | public MenuDialogView(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | } 29 | 30 | public MenuDialogView(Context context, AttributeSet attrs, int defStyleAttr) { 31 | super(context, attrs, defStyleAttr); 32 | } 33 | 34 | @Override 35 | protected void onFinishInflate() { 36 | super.onFinishInflate(); 37 | if (getChildAt(0) instanceof ViewGroup) { 38 | ViewGroup vp = (ViewGroup) getChildAt(0); 39 | for (int i = 0; i < vp.getChildCount(); i++) { 40 | vp.getChildAt(i).setOnClickListener(this); 41 | } 42 | } 43 | } 44 | 45 | private void createView(int locationX, int locationY) { 46 | mWm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); 47 | mWmParams = new WindowManager.LayoutParams(); 48 | mWmParams.type = WindowManager.LayoutParams.TYPE_PHONE; 49 | mWmParams.gravity = Gravity.LEFT | Gravity.TOP; 50 | mWmParams.x = locationX; 51 | mWmParams.y = locationY; 52 | mWmParams.width = ViewUtils.dpToPx(getContext(), 220); 53 | mWmParams.height = ViewUtils.dpToPx(getContext(), 220); 54 | mWmParams.format = 1; 55 | mWm.addView(this, mWmParams); 56 | } 57 | 58 | public void ShowDialog(int locationX, int locationY) { 59 | createView(locationX, locationY); 60 | } 61 | 62 | public void dismissDialog() { 63 | if (mWm != null) { 64 | mWm.removeView(this); 65 | mWm = null; 66 | } 67 | } 68 | 69 | private OnMenuItemClickListener mOnMenuItemClickListener; 70 | 71 | @Override 72 | public void onClick(View v) { 73 | if (mOnMenuItemClickListener.onMenuItemClick(v)) { 74 | dismissDialog(); 75 | } 76 | } 77 | 78 | public interface OnMenuItemClickListener { 79 | /** 80 | * 点击菜单回调 81 | * 82 | * @param view 当前点击的菜单item 83 | * @return 是否关闭菜单 84 | */ 85 | boolean onMenuItemClick(View view); 86 | } 87 | 88 | public void setOnMenuItemClickListener(OnMenuItemClickListener mOnMenuItemClickListener) { 89 | this.mOnMenuItemClickListener = mOnMenuItemClickListener; 90 | } 91 | 92 | @Override 93 | public boolean dispatchKeyEvent(KeyEvent event) { 94 | int action = event.getAction(); 95 | int keyCode = event.getKeyCode(); 96 | if (action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) { 97 | dismissDialog(); 98 | return true; 99 | } 100 | return super.dispatchKeyEvent(event); 101 | } 102 | 103 | public void updateLayout() { 104 | if (mWm != null && mWmParams != null) { 105 | mWmParams.x -= 220; 106 | if (mWmParams.x < 0) { 107 | mWmParams.x = 80; 108 | } 109 | mWm.updateViewLayout(this, mWmParams); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/java/com/lp/recyclerview4tvlibrary/view/OperateView.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tvlibrary.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.view.KeyEvent; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.RelativeLayout; 10 | 11 | import com.lp.recyclerview4tvlibrary.R; 12 | import com.lp.recyclerview4tvlibrary.utils.OperationManager; 13 | 14 | /** 15 | * Created by lph on 2016/12/8. 16 | * 可以继承此View实现自己的操作view 17 | * 请看下下面关于回调的说明 18 | */ 19 | public class OperateView extends RelativeLayout implements View.OnClickListener { 20 | private static final String TAG = "OperateView"; 21 | private OperationManager mManager; 22 | 23 | private OnOperatingListener mListener; 24 | 25 | public OperateView(Context context) { 26 | this(context, null); 27 | } 28 | 29 | public OperateView(Context context, AttributeSet attrs) { 30 | this(context, attrs, 0); 31 | } 32 | 33 | public OperateView(Context context, AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | init(); 36 | } 37 | 38 | protected void init() { 39 | mManager = OperationManager.newInstance(getContext()); 40 | setCanFocus(this); 41 | setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); 42 | } 43 | 44 | @Override 45 | protected void onFinishInflate() { 46 | super.onFinishInflate(); 47 | //客户端使用的view根据需要添加相应的子view的id为下面的其中之一 48 | View operateAdd = findViewById(R.id.operate_add); 49 | if (operateAdd != null) { 50 | setCanFocus(operateAdd); 51 | operateAdd.setOnClickListener(this); 52 | } 53 | View operateDel = findViewById(R.id.operate_delete); 54 | if (operateDel != null) { 55 | setCanFocus(operateDel); 56 | operateDel.setOnClickListener(this); 57 | } 58 | View operateUpdate = findViewById(R.id.operate_update); 59 | if (operateUpdate != null) { 60 | setCanFocus(operateUpdate); 61 | operateUpdate.setOnClickListener(this); 62 | } 63 | View operateMoveLeft = findViewById(R.id.operate_moveLeft); 64 | if (operateMoveLeft != null) { 65 | setCanFocus(operateMoveLeft); 66 | operateMoveLeft.setOnClickListener(this); 67 | } 68 | View operateMoveRight = findViewById(R.id.operate_moveRight); 69 | if (operateMoveRight != null) { 70 | setCanFocus(operateMoveRight); 71 | operateMoveRight.setOnClickListener(this); 72 | } 73 | View operateMoveUp = findViewById(R.id.operate_moveUp); 74 | if (operateMoveUp != null) { 75 | setCanFocus(operateMoveUp); 76 | operateMoveUp.setOnClickListener(this); 77 | } 78 | View operateMoveDown = findViewById(R.id.operate_moveDown); 79 | if (operateMoveDown != null) { 80 | setCanFocus(operateMoveDown); 81 | operateMoveDown.setOnClickListener(this); 82 | } 83 | } 84 | 85 | /** 86 | * 关于回调: 87 | */ 88 | 89 | //根据自己的需求在合适的地方调用mListener的各个回调,或者只是调用部分回调, 90 | //这里这样写,适合一般的情况,就是只有一级弹出框,当出现弹出多个层级的弹出操作框时,回调就需要在最后一级的弹出框完成了. 91 | //并且会伴随着数据的回传. 92 | 93 | /** 94 | * 必要的时候重写OperateView,在合适的地方回调mListener的某个方法,客户端的代码根据自己的业务逻辑,进行相应修改 95 | * 这里在onClick里面回调适合一般情况,比如一个操作框,上面显示了一些基本操作,当又有新的弹出框时,这种情况将不再适用 96 | * 请重写OperateView,在合适的地方回调. 97 | */ 98 | @Override 99 | public void onClick(View view) { 100 | if (mListener == null) { 101 | Log.e(TAG, "you should set setOnOperatingListener first !!!"); 102 | return; 103 | } 104 | int id = view.getId(); 105 | if (id == R.id.operate_add) { 106 | mManager.dismissOperateView(); 107 | mListener.onItemAdd(null); 108 | } else if (id == R.id.operate_delete) { 109 | mManager.dismissOperateView(); 110 | mListener.onItemDelete(null); 111 | } else if (id == R.id.operate_update) { 112 | mManager.dismissOperateView(); 113 | mListener.onItemUpdate(null); 114 | } else if (id == R.id.operate_moveLeft) { 115 | mListener.onItemMove(KeyEvent.KEYCODE_DPAD_LEFT); 116 | }else if (id == R.id.operate_moveRight) { 117 | mListener.onItemMove(KeyEvent.KEYCODE_DPAD_RIGHT); 118 | }else if (id == R.id.operate_moveUp) { 119 | mListener.onItemMove(KeyEvent.KEYCODE_DPAD_UP); 120 | }else if (id == R.id.operate_moveDown) { 121 | mListener.onItemMove(KeyEvent.KEYCODE_DPAD_DOWN); 122 | } 123 | } 124 | 125 | 126 | public void setOnOperatingListener(OnOperatingListener listener) { 127 | this.mListener = listener; 128 | } 129 | 130 | /** 131 | * 操作监听,每个方法的参数有时候是不需要的,有的时候很有必要,当出现多级菜单时,比如是一个列表,用户选择了要替换 132 | * 的数据,就需要将该数据回传到调用者,去拿到当前选择的数据去更新已有数据. 133 | */ 134 | public interface OnOperatingListener { 135 | void onItemAdd(Object newData); 136 | 137 | void onItemDelete(Object delData); 138 | 139 | void onItemUpdate(Object update); 140 | 141 | void onItemMove(Object direction); 142 | } 143 | 144 | public void setCanFocus(View view) { 145 | view.setClickable(true); 146 | view.setFocusable(true); 147 | view.setFocusableInTouchMode(true); 148 | } 149 | 150 | @Override 151 | public boolean dispatchKeyEvent(KeyEvent event) { 152 | if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { 153 | mManager.dismissOperateView(); 154 | return true; 155 | } 156 | return super.dispatchKeyEvent(event); 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/java/com/lp/recyclerview4tvlibrary/view/TvRecyclerView.java: -------------------------------------------------------------------------------- 1 | package com.lp.recyclerview4tvlibrary.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Rect; 5 | import android.graphics.drawable.Drawable; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.view.ViewCompat; 8 | import android.support.v7.widget.GridLayoutManager; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.support.v7.widget.StaggeredGridLayoutManager; 12 | import android.util.AttributeSet; 13 | import android.view.FocusFinder; 14 | import android.view.View; 15 | import android.view.ViewTreeObserver; 16 | import android.widget.ImageView; 17 | 18 | import com.lp.recyclerview4tvlibrary.effect.RecyclerViewEffect; 19 | import com.lp.recyclerview4tvlibrary.utils.ViewUtils; 20 | 21 | 22 | /** 23 | * Created by lph on 2016/10/20. 24 | * a descendant of RecyclerView for Tv 25 | */ 26 | public class TvRecyclerView extends RecyclerView { 27 | 28 | private ItemListener mItemListener; 29 | private final int DEFAULT_EDGE = ViewUtils.dpToPx(getContext(), 80); 30 | private int mRightEdge = DEFAULT_EDGE; 31 | private int mLeftEdge = DEFAULT_EDGE; 32 | private int mUpEdge = DEFAULT_EDGE; 33 | private int mDownEdge = DEFAULT_EDGE; 34 | 35 | private final static float DEFAULT_SCALE = 1.1f; 36 | private float mScale = DEFAULT_SCALE; 37 | 38 | private int mSaveFocusPosition = -1; 39 | private FocusFrameView mFocusFrameView; 40 | private RecyclerViewEffect mRecyclerViewEffect; 41 | 42 | 43 | public TvRecyclerView(Context context) { 44 | this(context, null); 45 | } 46 | 47 | public TvRecyclerView(Context context, @Nullable AttributeSet attrs) { 48 | this(context, attrs, 0); 49 | } 50 | 51 | public TvRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) { 52 | super(context, attrs, defStyle); 53 | init(); 54 | } 55 | 56 | private void init() { 57 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); 58 | setChildrenDrawingOrderEnabled(true); 59 | setWillNotDraw(true); 60 | setHasFixedSize(false); 61 | setOverScrollMode(View.OVER_SCROLL_NEVER); 62 | setClipChildren(false); 63 | setClipToPadding(false); 64 | setClickable(false); 65 | setFocusable(true); 66 | setFocusableInTouchMode(true); 67 | 68 | mItemListener = new ItemListener() { 69 | @Override 70 | public boolean onLongClick(View view) { 71 | if (mOnItemListener != null) { 72 | return mOnItemListener.onItemLongClick(TvRecyclerView.this, view, getChildLayoutPosition(view)); 73 | } 74 | return false; 75 | } 76 | 77 | @Override 78 | public void onFocusChange(View view, boolean b) { 79 | if (null != mOnItemListener) { 80 | if (view != null) { 81 | view.setSelected(b); 82 | if (b) { 83 | mSaveFocusPosition = getChildLayoutPosition(view); 84 | //当返回true表示用户处理,不需要RecyclerView自动处理 85 | boolean result = mOnItemListener.onItemSelected(TvRecyclerView.this, view, getChildLayoutPosition(view)); 86 | if (!result) { 87 | mRecyclerViewEffect.setFocusView(view, mScale); 88 | } 89 | } else { 90 | boolean result = mOnItemListener.onItemPreSelected(TvRecyclerView.this, view, getChildLayoutPosition(view)); 91 | if (!result) { 92 | mRecyclerViewEffect.setUnFocusView(view); 93 | } 94 | } 95 | } 96 | } 97 | } 98 | 99 | @Override 100 | public void onClick(View itemView) { 101 | if (null != mOnItemListener) { 102 | mOnItemListener.onItemClick(TvRecyclerView.this, itemView, getChildLayoutPosition(itemView)); 103 | } 104 | } 105 | }; 106 | 107 | } 108 | 109 | //选中状态下方法之后的item不会被后面的条目遮挡,更改绘制顺序 110 | int position = 0; 111 | 112 | @Override 113 | protected int getChildDrawingOrder(int childCount, int i) { 114 | //获取当前选中的View 115 | View view = getFocusedChild(); 116 | if (null != view) { 117 | position = getChildAdapterPosition(view) - getFirstVisiblePosition(); 118 | if (position < 0) { 119 | return i; 120 | } else { 121 | if (i == childCount - 1) {//这是最后一个需要刷新的item 122 | if (position > i) { 123 | position = i; 124 | } 125 | return position; 126 | } 127 | if (i == position) {//这是原本要在最后一个刷新的item 128 | return childCount - 1; 129 | } 130 | } 131 | } 132 | return i; 133 | } 134 | 135 | 136 | @Override 137 | public void onChildAttachedToWindow(View child) { 138 | if (!ViewCompat.hasOnClickListeners(child)) { 139 | child.setOnClickListener(mItemListener); 140 | } 141 | child.setOnLongClickListener(mItemListener); 142 | if (child.getOnFocusChangeListener() == null) { 143 | child.setOnFocusChangeListener(mItemListener); 144 | } 145 | 146 | } 147 | 148 | 149 | public int getRightEdge() { 150 | return mRightEdge; 151 | } 152 | 153 | public int getLeftEdge() { 154 | return mLeftEdge; 155 | } 156 | 157 | public void setmLeftEdge(int mLeftEdge) { 158 | this.mLeftEdge = mLeftEdge; 159 | } 160 | 161 | public void setmRightEdge(int mRightEdge) { 162 | this.mRightEdge = mRightEdge; 163 | } 164 | 165 | public void setmUpEdge(int mUpEdge) { 166 | this.mUpEdge = mUpEdge; 167 | } 168 | 169 | public void setmDownEdge(int mDownEdge) { 170 | this.mDownEdge = mDownEdge; 171 | } 172 | 173 | public int getUpEdge() { 174 | return mUpEdge; 175 | } 176 | 177 | public int getDownEdge() { 178 | return mDownEdge; 179 | } 180 | 181 | public interface OnItemListener { 182 | /** 183 | * 焦点离开 184 | * 185 | * @param parent TvRecyclerView 186 | * @param itemView 失去焦点的itemView 187 | * @param position 失去焦点item的位置 188 | * @return true表示用户处理焦点移动, TvRecyclerView不再处理焦点移动, 否则用户不再处理焦点移动,交给TvRecyclerView处理焦点移动 189 | */ 190 | boolean onItemPreSelected(TvRecyclerView parent, View itemView, int position); 191 | 192 | /** 193 | * 获取焦点 194 | * 195 | * @param parent TvRecyclerView 196 | * @param itemView 获取焦点的itemView 197 | * @param position 获取焦点item的位置 198 | * @return true表示用户处理焦点移动, TvRecyclerView不再处理焦点移动, 否则用户不再处理焦点移动,交给TvRecyclerView处理焦点移动 199 | */ 200 | boolean onItemSelected(TvRecyclerView parent, View itemView, int position); 201 | 202 | /** 203 | * 处理一些偏差 204 | * 205 | * @param parent TvRecyclerView 206 | * @param itemView 获取焦点的itemView 207 | * @param position 获取焦点item的位置 208 | * @return true表示用户处理焦点移动, TvRecyclerView不再处理焦点移动, 否则用户不再处理焦点移动,交给TvRecyclerView处理焦点移动 209 | */ 210 | boolean onReviseFocusFollow(TvRecyclerView parent, View itemView, int position); 211 | 212 | void onItemClick(TvRecyclerView parent, View itemView, int position); 213 | 214 | boolean onItemLongClick(TvRecyclerView parent, View itemView, int position); 215 | } 216 | 217 | private interface ItemListener extends OnClickListener, OnFocusChangeListener, OnLongClickListener { 218 | } 219 | 220 | 221 | private OnItemListener mOnItemListener; 222 | 223 | public void setOnItemListener(OnItemListener mOnItemListener) { 224 | this.mOnItemListener = mOnItemListener; 225 | } 226 | 227 | public int getFirstVisiblePosition() { 228 | if (getChildCount() == 0) 229 | return 0; 230 | else 231 | return getChildLayoutPosition(getChildAt(0)); 232 | } 233 | 234 | @Override 235 | public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) { 236 | /** 237 | * 重写这个方法,可以控制焦点框距离父容器的距离,以及由于recyclerView的滚动,产生的偏移量,导致焦点框错位,这里可以记录滑动偏移量。 238 | */ 239 | System.out.println("child:=========>" + child); 240 | System.out.println("rect:==========>" + rect); 241 | //计算出当前viewGroup即是RecyclerView的内容区域 242 | final int parentLeft = getPaddingLeft(); 243 | final int parentTop = getPaddingTop(); 244 | final int parentRight = getWidth() - getPaddingRight(); 245 | final int parentBottom = getHeight() - getPaddingBottom(); 246 | System.out.println("********************************"); 247 | System.out.println("parentLeft:======>" + parentLeft); 248 | System.out.println("parentTop:======>" + parentTop); 249 | System.out.println("parentRight:======>" + parentRight); 250 | System.out.println("parentBottom:======>" + parentBottom); 251 | 252 | //计算出child,此时是获取焦点的view请求的区域 253 | final int childLeft = child.getLeft() + rect.left; 254 | final int childTop = child.getTop() + rect.top; 255 | final int childRight = childLeft + rect.width(); 256 | final int childBottom = childTop + rect.height(); 257 | System.out.println("********************************"); 258 | System.out.println("childGetLeft:======>" + child.getLeft()); 259 | System.out.println("childGetTop:======>" + child.getTop()); 260 | System.out.println("********************************"); 261 | System.out.println("childLeft:======>" + childLeft); 262 | System.out.println("childTop:======>" + childTop); 263 | System.out.println("childRight:======>" + childRight); 264 | System.out.println("childBottom:======>" + childBottom); 265 | System.out.println("********************************"); 266 | //获取请求区域四个方向与RecyclerView内容四个方向的距离 267 | //当请求的新位置在child的左边时,这个时候计算新位置距离RecyclerView内容的左边界的距离,取0和这个值最小的那一个,当这个值为正,说明请求位置处于为可见状态,没有超出屏幕的左边界,反之则超出了边界; 268 | //当请求的新位置在child的上面时,这个时候计算新位置距离RecyclerView的内容上边界的距离,取0和这个值最小的一个当这个值为正,说明请求位置处于为可见状态,没有超出屏幕的上边界,反之则超出了边界; 269 | //当请求的新位置在child的右边时,这个时候计算新位置距离RecyclerView的内容右边界的距离,取0和这个值最大的一个,当这个值为负时,说明请求位置处于屏幕可见状态,没有超出屏幕右边界,反之则超出了屏幕右边界; 270 | //当请求的新位置在child的下面时,这个时候计算新位置距离RecyclerView的内容下边界的距离,取0和这个值最大的一个,当这个值为负时,说明请求位置处于屏幕可见状态,没有超出屏幕下边界,反之则超出了屏幕下边界. 271 | final int offScreenLeft = Math.min(0, childLeft - parentLeft); 272 | final int offScreenTop = Math.min(0, childTop - parentTop); 273 | final int offScreenRight = Math.max(0, childRight - parentRight); 274 | final int offScreenBottom = Math.max(0, childBottom - parentBottom); 275 | 276 | System.out.println("offScreenLeft:======>" + offScreenLeft); 277 | System.out.println("offScreenTop:======>" + offScreenTop); 278 | System.out.println("offScreenRight:======>" + offScreenRight); 279 | System.out.println("offScreenBottom:======>" + offScreenBottom); 280 | //判断是否可以在水平方向滑动,这个是由LayoutManager实现类决定的,只要在LayoutManager的实现类设置为水平方向滑动,这方法返回值恒为true 281 | final boolean canScrollHorizontal = getLayoutManager().canScrollHorizontally(); 282 | // Favor the "start" layout direction over the end when bringing one side or the other 283 | // of a large rect into view. If we decide to bring in end because start is already 284 | // visible, limit the scroll such that start won't go out of bounds. 285 | //如果是LayoutManager是水平方向滑动 286 | int dx; 287 | if (canScrollHorizontal) { 288 | //判断当前布局是否是从右往左(这是android4.2开始新增的一种布局方式),一般情况下都是从左往右的布局,所以if里面的情况基本不会发生 289 | if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL) { 290 | dx = offScreenRight != 0 ? offScreenRight 291 | : Math.max(offScreenLeft, childRight - parentRight); 292 | } else { 293 | //分为两种情况: 294 | // offScreenLeft==0: 295 | //当请求的新的位置没有超出recyclerView内容的左边界时 296 | //那么就去看offScreenRight的值 和 childLeft - parentLeft 的值比较了,这个时候很显然childLeft - parentLeft的值是大于等于0的 297 | //否则不可能会走到这一步,因为上面的计算步骤offScreenLef=Math.min(0, childLeft - parentLeft),而offScreenLef的值又等于0,所以 298 | //才会执行到Math.min(childLeft - parentLeft, offScreenRight)这一步,会取较小的一个,为什么呢? 299 | //这里假设一下:当前焦点移动方向是向左移动的,其实recyclerView中的内容是向右移动的,childLeft - parentLeft的值显然大于0(这是我们的大前提),而此时offScreenRight值,经过计算是为0的,所以最终dx为0,不会发生滑动 300 | //另外一种情况:当焦点是向右移动的时候,其实recyclerView中的内容是向左移动的,childLeft - parentLeft的值显然大于0(这是我们的大前提),而此时offScreenRight的值,就不确定了, 301 | //当请求的新位置位于RecyclerView的右边界之外时,offScreenRight的值就不在是0了,而这个值一般是小于相对左边的值,所以就会发生向右滑动,针对一些极端的情况,比如item比RecyclerView还要大 302 | 303 | //总结一下:当offScreenLeft的值为0的时候,是否发生滑动就依赖于offScreenRight的值了,offScreenRight就是由前面计算得到的 304 | // offScreenLeft!=0: 305 | //当前求的新的位置超出了recyclerView的内容左边界,这种情况dx的值直接就是offScreenLeft的值了 306 | dx = offScreenLeft != 0 ? offScreenLeft 307 | : Math.min(childLeft - parentLeft, offScreenRight); 308 | } 309 | } else { 310 | dx = 0; 311 | } 312 | // Favor bringing the top into view over the bottom. If top is already visible and 313 | // we should scroll to make bottom visible, make sure top does not go out of bounds. 314 | //同理,不再分析,只是少了判断布局方式,也没有必要判断布局方式 315 | int dy = offScreenTop != 0 ? offScreenTop 316 | : Math.min(childTop - parentTop, offScreenBottom); 317 | mOffset = isVertical() ? dy : dx; 318 | //在这里可以微调滑动的距离,根据项目的需要 319 | if (dx != 0 || dy != 0) { 320 | if (dx > 0) { 321 | dx = dx + mRightEdge; 322 | } else { 323 | dx = dx - mLeftEdge; 324 | } 325 | if (dy > 0) { 326 | dy = dy + mUpEdge; 327 | } else { 328 | dy = dy - mDownEdge; 329 | } 330 | mOffset = isVertical() ? dy : dx; 331 | //最后执行滑动 332 | if (immediate) { 333 | scrollBy(dx, dy); 334 | } else { 335 | smoothScrollBy(dx, dy); 336 | } 337 | return true; 338 | } 339 | postInvalidate(); 340 | return false; 341 | } 342 | 343 | @Override 344 | public void onScrollStateChanged(int state) { 345 | super.onScrollStateChanged(state); 346 | //用来微调位置 347 | if (RecyclerView.SCROLL_STATE_IDLE == state) { 348 | mOffset = -1; 349 | boolean result = mOnItemListener.onReviseFocusFollow(this, getFocusedChild(), getChildLayoutPosition(getFocusedChild())); 350 | if (!result) { 351 | mRecyclerViewEffect.setFocusView(getFocusedChild(), mScale); 352 | System.out.println("onScrollStateChanged"); 353 | } 354 | } 355 | } 356 | 357 | @Override 358 | public void onScrolled(int dx, int dy) { 359 | super.onScrolled(dx, dy); 360 | System.out.println("onScrolled:----->" + "dx:" + dx + "," + "dy:" + dy); 361 | } 362 | 363 | private int mOffset; 364 | 365 | /** 366 | * 获取选中ITEM的滚动偏移量 367 | * 368 | * @return 预选中的item由于recyclerView的滚动,产生的偏移量,主要用于修正焦点框 369 | */ 370 | public int getSelectedItemScrollOffset() { 371 | return mOffset; 372 | } 373 | 374 | public boolean isVertical() { 375 | LayoutManager lm = getLayoutManager(); 376 | if (lm instanceof GridLayoutManager) { 377 | return ((GridLayoutManager) getLayoutManager()).getOrientation() == GridLayoutManager.VERTICAL; 378 | } 379 | if (lm instanceof LinearLayoutManager) { 380 | LinearLayoutManager llm = (LinearLayoutManager) lm; 381 | return llm.getOrientation() == LinearLayoutManager.VERTICAL; 382 | } 383 | if (lm instanceof StaggeredGridLayoutManager) { 384 | StaggeredGridLayoutManager sglm = (StaggeredGridLayoutManager) lm; 385 | return sglm.getOrientation() == StaggeredGridLayoutManager.VERTICAL; 386 | } 387 | return false; 388 | } 389 | 390 | @Override 391 | public void onWindowFocusChanged(boolean hasWindowFocus) { 392 | if (hasWindowFocus) { 393 | recoverFocus(); 394 | } 395 | } 396 | 397 | private void recoverFocus() { 398 | View saveFocusView = getLayoutManager().findViewByPosition(mSaveFocusPosition); 399 | if (saveFocusView != null) { 400 | saveFocusView.requestFocus(); 401 | } 402 | } 403 | 404 | /** 405 | * 做了一些焦点记录处理,焦点记录处理只在一下四个方法做了处理 406 | * 若是需要更新数据,请使用notifyItemRangeXXX()的方法, 407 | * 否则更新后,可能会出现焦点框位置错乱. 408 | */ 409 | public static abstract class TvAdapter extends Adapter { 410 | protected RecyclerView.AdapterDataObserver mDataObserver; 411 | protected TvRecyclerView mRecyclerView; 412 | 413 | public TvAdapter() { 414 | mDataObserver = new RecyclerView.AdapterDataObserver() { 415 | @Override 416 | public void onChanged() { 417 | super.onChanged(); 418 | } 419 | 420 | @Override 421 | public void onItemRangeInserted(final int positionStart, int itemCount) { 422 | registerRecoverFocus(positionStart); 423 | super.onItemRangeInserted(positionStart, itemCount); 424 | } 425 | 426 | @Override 427 | public void onItemRangeRemoved(int positionStart, int itemCount) { 428 | registerRecoverFocus(positionStart - itemCount); 429 | super.onItemRangeRemoved(positionStart, itemCount); 430 | } 431 | 432 | @Override 433 | public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { 434 | registerRecoverFocus(toPosition); 435 | super.onItemRangeMoved(fromPosition, toPosition, itemCount); 436 | } 437 | 438 | @Override 439 | public void onItemRangeChanged(int positionStart, int itemCount) { 440 | registerRecoverFocus(positionStart); 441 | super.onItemRangeChanged(positionStart, itemCount); 442 | } 443 | }; 444 | 445 | registerAdapterDataObserver(mDataObserver); 446 | } 447 | 448 | /** 449 | * 注册事件,更新完毕RecyclerView重新获取焦点 450 | * 451 | * @param focusPosition 恢复焦点的位置 452 | */ 453 | private void registerRecoverFocus(final int focusPosition) { 454 | mRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 455 | @Override 456 | public void onGlobalLayout() { 457 | View addView = mRecyclerView.getLayoutManager().findViewByPosition(focusPosition); 458 | if (addView != null) { 459 | addView.requestFocus(); 460 | mRecyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this); 461 | } 462 | } 463 | }); 464 | } 465 | 466 | @Override 467 | public void onAttachedToRecyclerView(RecyclerView recyclerView) { 468 | super.onAttachedToRecyclerView(recyclerView); 469 | mRecyclerView = (TvRecyclerView) recyclerView; 470 | } 471 | 472 | @Override 473 | public void onDetachedFromRecyclerView(RecyclerView recyclerView) { 474 | super.onDetachedFromRecyclerView(recyclerView); 475 | if (mDataObserver != null) { 476 | unregisterAdapterDataObserver(mDataObserver); 477 | } 478 | } 479 | 480 | /** 481 | * 由于在StaggeredGridLayout布局中,更新完数据后RecyclerView有时候会发生滑动,导致焦点框错位,所以使用这个方法更新数据 482 | * 483 | * @param start 开始位置 484 | * @param count 更新数据的数目 485 | * @param payLoad 是否全部更新 486 | */ 487 | public void notifyItemRangeChangedWrapper(int start, int count, Object payLoad) { 488 | if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager || mRecyclerView.getLayoutManager() instanceof GridLayoutManager) { 489 | for (int i = start; i < start + count; i++) { 490 | ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(i); 491 | if (holder != null) { 492 | Object data = getData(i); 493 | if (data != null) { 494 | //TvViewHolder的子类,重写setData(data)方法,进行相应的数据更新 495 | ((TvViewHolder) holder).setData(data); 496 | } 497 | } 498 | } 499 | } else { 500 | notifyItemRangeChanged(start, count, payLoad); 501 | } 502 | } 503 | 504 | public void notifyItemRangeChangedWrapper(int start, int count) { 505 | notifyItemRangeChangedWrapper(start, count, null); 506 | } 507 | 508 | public void notifyItemChangedWrapper(int position, Object payLoad) { 509 | notifyItemRangeChangedWrapper(position, 1, payLoad); 510 | } 511 | 512 | public void notifyItemChangedWrapper(int position) { 513 | notifyItemRangeChangedWrapper(position, 1, null); 514 | } 515 | 516 | /** 517 | * 用来获取需要更新的数据 518 | * 519 | * @param start 当前更新的位置 520 | * @return 当前更新的数据 521 | */ 522 | protected abstract Object getData(int start); 523 | } 524 | 525 | public static class TvViewHolder extends ViewHolder { 526 | protected View mContainer; 527 | 528 | public TvViewHolder(View itemView) { 529 | super(itemView); 530 | mContainer = itemView; 531 | } 532 | 533 | public void setData(Object obj) { 534 | 535 | } 536 | 537 | @SuppressWarnings("unchecked") 538 | public K getView(int resId) { 539 | return (K) mContainer.findViewById(resId); 540 | } 541 | } 542 | 543 | /** 544 | * 必须执行此方法 545 | * 546 | * @param view 焦点框VIew 547 | * @param frameResId 焦点框图片效果资源id 548 | * @param framePadding 可以缩放焦点框 549 | */ 550 | public void initFrame(FocusFrameView view, int frameResId, int framePadding) { 551 | mFocusFrameView = view; 552 | mRecyclerViewEffect = new RecyclerViewEffect(); 553 | mFocusFrameView.setEffect(mRecyclerViewEffect); 554 | mRecyclerViewEffect.setFocusResource(frameResId); 555 | mFocusFrameView.setFocusFramePadding(framePadding); 556 | } 557 | 558 | public void initFrame(FocusFrameView view, Drawable frameDrawable, int framePadding) { 559 | mFocusFrameView = view; 560 | mRecyclerViewEffect = new RecyclerViewEffect(); 561 | mFocusFrameView.setEffect(mRecyclerViewEffect); 562 | mRecyclerViewEffect.setFocusDrawable(frameDrawable); 563 | mFocusFrameView.setFocusFramePadding(framePadding); 564 | } 565 | 566 | public void setItemScale(float scale) { 567 | this.mScale = scale; 568 | } 569 | 570 | 571 | @Override 572 | public View focusSearch(View focused, int direction) { 573 | return super.focusSearch(focused, direction); 574 | } 575 | } 576 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/res/drawable/menu_btn_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/res/drawable/shape_selected.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/res/drawable/shape_unselected.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /recyclerView4Tv/recyclerview4tvlibrary/src/main/res/layout/layout_menu_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 21 |