├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── anarchy │ │ └── classifyview │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── anarchy │ │ │ └── classifyview │ │ │ ├── ContentActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── core │ │ │ ├── BaseFragment.java │ │ │ ├── Bean.java │ │ │ └── MyAdapter.java │ │ │ ├── sample │ │ │ ├── demonstrate │ │ │ │ ├── DemonstrateFragment.java │ │ │ │ └── logic │ │ │ │ │ ├── Book.java │ │ │ │ │ ├── BookListAdapter.java │ │ │ │ │ ├── BookListener.java │ │ │ │ │ ├── NetManager.java │ │ │ │ │ └── SelectBookListAdapter.java │ │ │ ├── ireader │ │ │ │ ├── IReaderAdapter.java │ │ │ │ ├── IReaderMockFragment.java │ │ │ │ ├── model │ │ │ │ │ ├── IReaderMockData.java │ │ │ │ │ └── IReaderMockDataGroup.java │ │ │ │ └── widget │ │ │ │ │ ├── IReaderClassifyView.java │ │ │ │ │ ├── IReaderFolder.java │ │ │ │ │ └── IReaderGridLayout.java │ │ │ ├── layoutmanager │ │ │ │ ├── HHAdapter.java │ │ │ │ ├── HVAdapter.java │ │ │ │ ├── LayoutManagerFragment.java │ │ │ │ ├── LinearHHClassifyView.java │ │ │ │ ├── LinearHVClassifyView.java │ │ │ │ └── LinearVVClassifyView.java │ │ │ ├── normal │ │ │ │ └── NormalFragment.java │ │ │ ├── normalfolder │ │ │ │ ├── Constants.java │ │ │ │ ├── NormalFolderFragment.java │ │ │ │ ├── bean │ │ │ │ │ ├── BaseBean.java │ │ │ │ │ └── BookBean.java │ │ │ │ └── logic │ │ │ │ │ ├── FolderAdapter.java │ │ │ │ │ └── MyFolderAdapter.java │ │ │ └── viewpager │ │ │ │ └── ViewPagerFragment.java │ │ │ └── utils │ │ │ └── DataGenerate.java │ └── res │ │ ├── anim │ │ ├── slide_down.xml │ │ └── slide_up.xml │ │ ├── color-v21 │ │ └── selector_color_text.xml │ │ ├── drawable-xxhdpi │ │ ├── ic_checked.png │ │ ├── ic_number_bg.png │ │ └── ic_unchecked.png │ │ ├── drawable │ │ ├── bg_circle_red.xml │ │ ├── bg_i_reader_category_edit.xml │ │ ├── ic_add_black_24dp.xml │ │ ├── ic_delete.xml │ │ ├── ic_detail.xml │ │ ├── ic_move.xml │ │ ├── ic_order.xml │ │ ├── ic_share.xml │ │ └── round_shape.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── content_main.xml │ │ ├── demonstrate_main.xml │ │ ├── extra_ireader_bottom_bar.xml │ │ ├── extra_ireader_sub_content.xml │ │ ├── fragment_layoutmanager.xml │ │ ├── fragment_mock_ireader.xml │ │ ├── fragment_viewpager.xml │ │ ├── item_book.xml │ │ ├── item_book_inner.xml │ │ ├── item_i_reader_folder.xml │ │ ├── item_inner.xml │ │ ├── item_sample_horizontal.xml │ │ ├── item_sample_vertical.xml │ │ ├── item_select_list.xml │ │ ├── normal.xml │ │ ├── select_book.xml │ │ ├── stub_classify_hh.xml │ │ └── stub_classify_hv.xml │ │ ├── menu │ │ ├── menu_i_reader.xml │ │ └── menu_layout_manager_type.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── ids.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── anarchy │ └── classifyview │ └── ExampleUnitTest.java ├── build.gradle ├── classify ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── anarchy │ │ └── classify │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── anarchy │ │ │ └── classify │ │ │ ├── ClassifyDragShadowBuilder.java │ │ │ ├── ClassifyItemAnimator.java │ │ │ ├── ClassifyView.java │ │ │ ├── DragDrawable.java │ │ │ ├── MergeInfo.java │ │ │ ├── adapter │ │ │ ├── BaseMainAdapter.java │ │ │ └── BaseSubAdapter.java │ │ │ ├── callback │ │ │ ├── BaseCallBack.java │ │ │ ├── MainRecyclerViewCallBack.java │ │ │ └── SubRecyclerViewCallBack.java │ │ │ ├── simple │ │ │ ├── BaseSimpleAdapter.java │ │ │ ├── ChangeInfo.java │ │ │ ├── PrimitiveSimpleAdapter.java │ │ │ ├── SimpleAdapter.java │ │ │ └── widget │ │ │ │ ├── BagDrawable.java │ │ │ │ ├── CanMergeView.java │ │ │ │ ├── InsertAbleGridView.java │ │ │ │ └── MiViewHolder.java │ │ │ └── util │ │ │ └── L.java │ └── res │ │ ├── anim │ │ ├── slide_down.xml │ │ └── slide_up.xml │ │ ├── layout │ │ ├── simple_item.xml │ │ └── sub_content.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── classify_style.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── anarchy │ └── classify │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshot ├── classifyView.gif └── ireader.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle/ 3 | gradle.properties 4 | /local.properties 5 | /.idea/ 6 | .DS_Store 7 | /build 8 | /captures 9 | *.idea/ 10 | -------------------------------------------------------------------------------- /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 2017 AlphaBoom 190 | Licensed under the Apache License, Version 2.0 (the "License"); 191 | you may not use this file except in compliance with the License. 192 | You may obtain a copy of the License at 193 | 194 | http://www.apache.org/licenses/LICENSE-2.0 195 | 196 | Unless required by applicable law or agreed to in writing, software 197 | distributed under the License is distributed on an "AS IS" BASIS, 198 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 199 | See the License for the specific language governing permissions and 200 | limitations under the License. 201 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ClassifyView [![](https://jitpack.io/v/AlphaBoom/ClassifyView.svg)](https://jitpack.io/#AlphaBoom/ClassifyView)[![Codewake](https://www.codewake.com/badges/ask_question.svg)](https://www.codewake.com/p/classifyview) 2 | 实现原理 ClassifyView包裹这一个RecyclerView,当点击这个RecyclerView会弹出一个Dialog 该Dialog的布局会传入另一个RecyclerView.想详细了解,~可以查看 [博客](http://www.jianshu.com/p/a51a93366406)~ 3 | # 效果如下 4 | ![image](https://github.com/AlphaBoom/ClassifyView/blob/master/screenshot/classifyView.gif) 5 | ![image](https://github.com/AlphaBoom/ClassifyView/blob/master/screenshot/ireader.gif) 6 | # 配置依赖 7 | **Step one:** Add the JitPack repository to your build file 8 | 9 | ``` 10 | allprojects { 11 | repositories { 12 | ... 13 | maven { url "https://jitpack.io" } 14 | } 15 | } 16 | ``` 17 | **Step two:** Add the dependency 18 | 19 | ``` 20 | dependencies { 21 | compile 'com.github.AlphaBoom:ClassifyView:$LATEST_VERSION' 22 | } 23 | 24 | ``` 25 | 最新版本查看[Latest release](https://github.com/AlphaBoom/ClassifyView/releases) 26 | 27 | # 最近更新 28 | - [x] 关于仿照IReader的效果需要对原库做自定义的部分都已经更新在Sample 29 | - [x] 在adapter中增加了拖拽开始及拖拽开始完成和次级目录弹出的回调 30 | - [x] 增加拖拽item的可在拖拽时放大及可合并时缩小的设置 31 | - [x] 在拖拽开始时添加动画,效果更自然 32 | - [x] 添加了一个自定义的例子,效果大致仿IReader的书架 33 | 34 | # 快速使用 35 | 1. 继承SimpleAdapter 36 | 37 | ```java 38 |   public class MyAdapter extends SimpleAdapter { 39 | 40 | 41 | public MyAdapter(List> mData) { 42 | super(mData); 43 | } 44 | 45 | 46 | @Override 47 | protected ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 48 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item,parent,false); 49 | return new MyAdapter.ViewHolder(view); 50 | } 51 | //convertView是缓存的View 如何使用这个convertView 参考ListView的使用步骤 52 | @Override 53 | public View getView(ViewGroup parent, View convertView, int mainPosition, int subPosition) { 54 | //返回的View作为每一个Item的布局 55 | /*布局内容自定义 例子中如下: 56 | 60 | */ 61 | if (convertView == null) { 62 | convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_inner, parent, false); 63 | } 64 | return convertView; 65 | } 66 | 67 | @Override 68 | protected void onItemClick(View view, int parentIndex, int index) { 69 | Toast.makeText(view.getContext(),"parentIndex: "+parentIndex+"\nindex: "+index,Toast.LENGTH_SHORT).show(); 70 | } 71 | 72 | static class ViewHolder extends SimpleAdapter.ViewHolder { 73 | 74 | public ViewHolder(View itemView) { 75 | super(itemView); 76 | } 77 | } 78 | } 79 | ``` 80 | 2.找到ClassifyView 并设置Adapter 81 | 82 | ```java 83 | mClassifyView = (ClassifyView) view.findViewById(R.id.classify_view); 84 | List> data = new ArrayList<>(); 85 | for(int i=0;i<30;i++){ 86 | List inner = new ArrayList<>(); 87 | if(i>10) { 88 | int c = (int) (Math.random() * 15+1); 89 | for(int j=0;j>`的结构可以集成PrimitiveSimpleAdapter来实现其他数据源的adapter 198 | 199 | 关于如何继承PrimitiveSimpleAdapter可以参考[IReaderAdapter](https://github.com/AlphaBoom/ClassifyView/blob/master/app/src/main/java/com/anarchy/classifyview/sample/ireader/IReaderAdapter.java),如果不能满足可以考虑分别继承[BaseMainAdapter](https://github.com/AlphaBoom/ClassifyView/blob/master/classify/src/main/java/com/anarchy/classify/adapter/BaseMainAdapter.java)及[BaseSubAdapter](https://github.com/AlphaBoom/ClassifyView/blob/master/classify/src/main/java/com/anarchy/classify/adapter/BaseSubAdapter.java) 200 | 201 | ## 继承ClassifyView 重写以下方法: 202 | 203 | 1. **RecyclerView getMain(Context context, AttributeSet parentAttrs)**
返回主层级使用的 RecyclerView。 204 | 2. **RecyclerView getSub(Context context, AttributeSet parentAttrs)** 返回次级层级使用的RecyclerView 205 | 3. **View chooseTarget(View selected, List swapTargets, int curX, int curY)**
当拖拽的View 覆盖到子View时会通过该方法在候选View中选择一个View 为目标View 之后的交互操作都会作用于当前所选择的View 及 这个目标View
@param selected 当前选择的View
@param swapTargets 候选的目标View(候选的目标View 为当前选择的View 能够覆盖到所有View)
@param curX 当前选中View的X轴坐标
@param curY 当前选中View的Y轴坐标 206 | 4. **Drawable getDragDrawable(View view)**
返回用于渲染当前拖动View的显示
@param view 当前选中的View
@return drawable返回Drawable 用于设置拖拽View的背景 207 | 5. 自定义次级目录的布局: 208 | * 自定义次级目录的Dialog:重写 **Dialog createSubDialog()** 209 | * 自定义次级目录布局:重写 **View getSubContent()** 210 |
**注意:** 默认会在返回的View中查找有Tag 为 @String/sub_container 的View作为容器 如果没有 就已返回的View作为容器来添加次级目录的RecyclerView。 可以覆盖 **ViewGroup findHaveSubTagContainer(ViewGroup group)** 来重写查找容器的逻辑 211 | 212 | **设置数据方式有两种方式:** 213 | 214 | 1. 使用 *ClassifyView.setAdapter(BaseMainAdapter mainAdapter, BaseSubAdapter subAdapter)* 用于分别设置主层级及次级层级的适配器(使用这种方式只能获取到相应状态时的回调,注意这些回调返回值的处理) 215 | 2. 使用 *setAdapter(BaseSimpleAdapter baseSimpleAdapter)* 设置一个混合了主层级及次级层级的适配器,如何自定义可以参考 [SimpleAdapter](https://github.com/AlphaBoom/ClassifyView/blob/master/classify/src/main/java/com/anarchy/classify/simple/SimpleAdapter.java) 216 | 217 | 218 | ## 主层级提供的回调 219 | 在BaseAdapter中对于mergeStart等又增加了ViewHolder形式的回调 本质是一样的。 220 | 221 | 回调方法 | 说明 | 是否有默认实现在BaseSubAdapter中 222 | ------ | ----- | ---- 223 | setDragPosition | 设置当前被拖拽的位置 | true,默认效果为隐藏被拖拽的位置 224 | boolean canDragOnLongPress|是否可以长按拖拽该View | false 225 | boolean canDropOVer| 是否可以在对应点放下|true,默认返回true 226 | boolean onMergeStart|第一次处于可合并状态|false 227 | void onMerged|合并结束|false 228 | MergeInfo onPrepareMerge|当准备进行合并动画时回调,返回的MergeInfo用于做当前拖拽的View到目标位置的动画|false 229 | void onStartMergeAnimation|开始合并动画的回调|false 230 | void onMergeCancel|当脱离合并状态的回调|false 231 | boolean onMove|当需要触发移动时的回调|false 232 | void moved|移动完成的回调|false 233 | boolean canMergeItem|能否进行合并操作|false 234 | int onLeaveSubRegion|当从次级目录拖动出item到主层级时回调,返回int 为添加到主层级adapter的位置|false 235 | float getVelocity|只对低于这个速度的才判断能否移动(需要配合getCurrentState)|true 236 | int getCurrentState|判断当前处于的状态,返回三个值 Classify.STATE_NONE 无状态,Classify.STATE_MERGE 处于合并状态,Classify.STATE_MOVE 处于移动状态| true 237 | void onItemClick|当item被点击时的回调|false 238 | boolean canExplodeItem|用于判断当点击一个item时是否展开次级目录|false 239 | 240 | ## 次级层级的回调 241 | 次级层级与主层级相似 没有合并的相关回调: 242 | 243 | 方法|说明 244 | ---|--- 245 | void prepareExplodeItem|用于准备初始化次级层级数据 246 | boolean canDropOver | 对于次层级的item 能否拖动到主层级 247 | boolean canDragOut | 是否可以移出次级目录到主层级 248 | void onDialogShow | 次级窗口显示时的回调 249 | void onDialogCancel | 次级窗口隐藏时的回调 250 | 251 | # 结语 252 | **当前项目效果展现 使用[SimpleAdapter](https://github.com/AlphaBoom/ClassifyView/blob/master/classify/src/main/java/com/anarchy/classify/simple/SimpleAdapter.java)** 253 | 254 | 255 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | 6 | defaultConfig { 7 | applicationId "com.anarchy.classifyview" 8 | minSdkVersion 15 9 | targetSdkVersion 27 10 | versionCode 1 11 | versionName "1.0" 12 | vectorDrawables.useSupportLibrary true 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | dataBinding{ 22 | enabled true 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(include: ['*.jar'], dir: 'libs') 29 | testImplementation 'junit:junit:4.12' 30 | implementation 'com.android.support:appcompat-v7:27.1.1' 31 | implementation 'com.android.support:gridlayout-v7:27.1.1' 32 | implementation 'com.squareup.picasso:picasso:2.5.2' 33 | implementation project(':classify') 34 | implementation 'com.android.support:design:27.1.1' 35 | } 36 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/anarchy/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/anarchy/classifyview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview; 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 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/ContentActivity.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.support.v7.widget.helper.ItemTouchHelper; 8 | 9 | import com.anarchy.classifyview.core.BaseFragment; 10 | import com.anarchy.classifyview.sample.demonstrate.DemonstrateFragment; 11 | import com.anarchy.classifyview.sample.ireader.IReaderMockFragment; 12 | import com.anarchy.classifyview.sample.layoutmanager.LayoutManagerFragment; 13 | import com.anarchy.classifyview.sample.normal.NormalFragment; 14 | import com.anarchy.classifyview.sample.normalfolder.NormalFolderFragment; 15 | import com.anarchy.classifyview.sample.viewpager.ViewPagerFragment; 16 | 17 | /** 18 | *

19 | * Date: 16/6/12 09:40 20 | * Author: rsshinide38@163.com 21 | *

22 | */ 23 | public class ContentActivity extends AppCompatActivity { 24 | @SuppressWarnings("unchecked") 25 | private Class[] mClasses = new Class[]{NormalFragment.class, 26 | DemonstrateFragment.class, ViewPagerFragment.class, LayoutManagerFragment.class, 27 | NormalFolderFragment.class,IReaderMockFragment.class};//, 28 | private int position; 29 | 30 | @Override 31 | protected void onCreate(@Nullable Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.content_main); 34 | position = getIntent().getIntExtra(MainActivity.EXTRA_POSITION, 0); 35 | try { 36 | getSupportFragmentManager().beginTransaction().add(R.id.container, mClasses[position].newInstance()).commit(); 37 | } catch (InstantiationException e) { 38 | e.printStackTrace(); 39 | } catch (IllegalAccessException e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | 44 | 45 | @Override 46 | public void onBackPressed() { 47 | Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.container); 48 | if (!(fragment instanceof BaseFragment && ((BaseFragment) fragment).onBackPressed())) { 49 | super.onBackPressed(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.AdapterView; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.ListView; 10 | 11 | public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{ 12 | public static final String EXTRA_POSITION = "com.anarchy.classifyview.MainActivity.EXTRA_POSITION"; 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | ListView sampleList = (ListView) findViewById(R.id.sample_list); 18 | sampleList.setAdapter(new ArrayAdapter(this, 19 | android.R.layout.simple_list_item_1,getResources().getStringArray(R.array.list_name))); 20 | sampleList.setOnItemClickListener(this); 21 | } 22 | 23 | @Override 24 | public void onItemClick(AdapterView parent, View view, int position, long id) { 25 | Intent i = new Intent(this,ContentActivity.class); 26 | i.putExtra(EXTRA_POSITION,position); 27 | startActivity(i); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/core/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.core; 2 | 3 | import android.support.v4.app.Fragment; 4 | 5 | /** 6 | * Version 2.1.1 7 | *

8 | * Date: 16/12/28 10:33 9 | * Author: rsshinide38@163.com 10 | */ 11 | 12 | public class BaseFragment extends Fragment{ 13 | 14 | public boolean onBackPressed(){ 15 | return false; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/core/Bean.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.core; 2 | 3 | /** 4 | *

5 | * Date: 16/6/7 16:41 6 | * Author: rsshinide38@163.com 7 | *

8 | */ 9 | public class Bean { 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/core/MyAdapter.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.core; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.Toast; 7 | 8 | import com.anarchy.classify.simple.SimpleAdapter; 9 | import com.anarchy.classify.simple.widget.InsertAbleGridView; 10 | import com.anarchy.classifyview.R; 11 | 12 | import java.lang.reflect.Field; 13 | import java.lang.reflect.InvocationTargetException; 14 | import java.lang.reflect.Method; 15 | import java.util.List; 16 | 17 | /** 18 | *

19 | * Date: 16/6/7 16:40 20 | * Author: rsshinide38@163.com 21 | *

22 | */ 23 | public class MyAdapter extends SimpleAdapter { 24 | 25 | 26 | public MyAdapter(List> mData) { 27 | super(mData); 28 | } 29 | 30 | 31 | @Override 32 | protected ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 33 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample_vertical, parent, false); 34 | return new MyAdapter.ViewHolder(view); 35 | } 36 | 37 | 38 | @Override 39 | public View getView(ViewGroup parent, View convertView, int mainPosition, int subPosition) { 40 | if (convertView == null) { 41 | convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_inner, parent, false); 42 | } 43 | return convertView; 44 | } 45 | 46 | @Override 47 | protected void onItemClick(View view, int parentIndex, int index) { 48 | Toast.makeText(view.getContext(), "parentIndex: " + parentIndex + "\nindex: " + index, Toast.LENGTH_SHORT).show(); 49 | } 50 | 51 | static class ViewHolder extends SimpleAdapter.ViewHolder { 52 | 53 | public ViewHolder(View itemView) { 54 | super(itemView); 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/demonstrate/DemonstrateFragment.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.demonstrate; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.design.widget.FloatingActionButton; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v7.app.AlertDialog; 8 | import android.support.v7.widget.GridLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.util.Log; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.ProgressBar; 15 | import android.widget.Toast; 16 | 17 | import com.anarchy.classify.ClassifyView; 18 | import com.anarchy.classifyview.R; 19 | import com.anarchy.classifyview.core.BaseFragment; 20 | import com.anarchy.classifyview.sample.demonstrate.logic.Book; 21 | import com.anarchy.classifyview.sample.demonstrate.logic.BookListAdapter; 22 | import com.anarchy.classifyview.sample.demonstrate.logic.BookListener; 23 | import com.anarchy.classifyview.sample.demonstrate.logic.NetManager; 24 | import com.anarchy.classifyview.sample.demonstrate.logic.SelectBookListAdapter; 25 | 26 | import org.json.JSONArray; 27 | import org.json.JSONException; 28 | import org.json.JSONObject; 29 | 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | 33 | /** 34 | *

35 | * Date: 16/6/12 10:09 36 | * Author: rsshinide38@163.com 37 | *

38 | */ 39 | public class DemonstrateFragment extends BaseFragment { 40 | private NetManager mNetManager = new NetManager(); 41 | private List> mBooks = new ArrayList<>(); 42 | private BookListAdapter mAdapter; 43 | private ClassifyView mClassifyView; 44 | private SelectBookListAdapter mSelectBookListAdapter; 45 | 46 | @Nullable 47 | @Override 48 | public View onCreateView(LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) { 49 | View view = inflater.inflate(R.layout.demonstrate_main, container, false); 50 | FloatingActionButton button = (FloatingActionButton) view.findViewById(R.id.add_button); 51 | mClassifyView = (ClassifyView) view.findViewById(R.id.classify_view); 52 | mAdapter = new BookListAdapter(mBooks); 53 | mClassifyView.setAdapter(mAdapter); 54 | mClassifyView.setDebugAble(true); 55 | button.setOnClickListener(new View.OnClickListener() { 56 | @Override 57 | public void onClick(View v) { 58 | final AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); 59 | View content = LayoutInflater.from(v.getContext()).inflate(R.layout.select_book, null); 60 | RecyclerView recyclerView = (RecyclerView) content.findViewById(R.id.select_list); 61 | final ProgressBar progressBar = (ProgressBar) content.findViewById(R.id.progress_bar); 62 | recyclerView.setLayoutManager(new GridLayoutManager(v.getContext(), 2)); 63 | if (mSelectBookListAdapter == null) 64 | mSelectBookListAdapter = new SelectBookListAdapter(); 65 | recyclerView.setAdapter(mSelectBookListAdapter); 66 | builder.setView(content); 67 | final AlertDialog dialog = builder.show(); 68 | mSelectBookListAdapter.setItemClickListener(new SelectBookListAdapter.ItemClickListener() { 69 | @Override 70 | public void onItemClick(View parent, int position, Book book) { 71 | List books = new ArrayList<>(); 72 | books.add(book); 73 | mBooks.add(books); 74 | mAdapter.notifyItemInsert(mBooks.size() - 1); 75 | dialog.dismiss(); 76 | } 77 | }); 78 | if (mSelectBookListAdapter.getBookList() != null) { 79 | progressBar.setVisibility(View.GONE); 80 | return; 81 | } 82 | progressBar.setVisibility(View.VISIBLE); 83 | mNetManager.getBookList(new BookListener() { 84 | @Override 85 | public void onSuccess(String result) { 86 | progressBar.setVisibility(View.INVISIBLE); 87 | List books = new ArrayList<>(); 88 | try { 89 | JSONObject jsonObject = new JSONObject(result); 90 | JSONArray jsonArray = jsonObject.optJSONArray("list"); 91 | if (jsonArray != null) { 92 | for (int i = 0; i < jsonArray.length(); i++) { 93 | JSONObject object = jsonArray.optJSONObject(i); 94 | if (object != null) { 95 | Book book = new Book(); 96 | book.id = object.optString("id"); 97 | book.imageUrl = "http://tnfs.tngou.net/img" + object.optString("img"); 98 | book.name = object.optString("name"); 99 | book.summary = object.optString("summary"); 100 | books.add(book); 101 | } 102 | } 103 | } 104 | } catch (JSONException e) { 105 | e.printStackTrace(); 106 | } 107 | mSelectBookListAdapter.setBookList(books); 108 | } 109 | 110 | @Override 111 | public void onFailure(Exception e) { 112 | progressBar.setVisibility(View.INVISIBLE); 113 | Toast.makeText(getActivity(), "出错:" + e.getMessage(), Toast.LENGTH_SHORT).show(); 114 | } 115 | }); 116 | } 117 | }); 118 | return view; 119 | } 120 | 121 | 122 | @Override 123 | public void onDestroyView() { 124 | super.onDestroyView(); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/demonstrate/logic/Book.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.demonstrate.logic; 2 | 3 | /** 4 | *

5 | * Date: 16/6/12 14:02 6 | * Author: rsshinide38@163.com 7 | *

8 | */ 9 | public class Book { 10 | public String imageUrl; 11 | public String name; 12 | public String id; 13 | public String summary; 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/demonstrate/logic/BookListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.demonstrate.logic; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | 9 | import com.anarchy.classify.simple.SimpleAdapter; 10 | import com.anarchy.classifyview.R; 11 | import com.squareup.picasso.Picasso; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | *

17 | * Date: 16/6/12 14:38 18 | * Author: rsshinide38@163.com 19 | *

20 | */ 21 | public class BookListAdapter extends SimpleAdapter { 22 | 23 | 24 | public BookListAdapter(List> mData) { 25 | super(mData); 26 | } 27 | 28 | 29 | @Override 30 | protected ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 31 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_book,parent,false); 32 | return new ViewHolder(view); 33 | } 34 | 35 | @Override 36 | public View getView(ViewGroup parent,View convertView, int mainPosition, int subPosition) { 37 | ItemViewHolder itemViewHolder; 38 | if(convertView == null){ 39 | itemViewHolder = new ItemViewHolder(); 40 | convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_book_inner,parent,false); 41 | itemViewHolder.imageView = (ImageView) convertView.findViewById(R.id.image); 42 | convertView.setTag(itemViewHolder); 43 | }else { 44 | itemViewHolder = (ItemViewHolder) convertView.getTag(); 45 | } 46 | String url = mData.get(mainPosition).get(subPosition).imageUrl; 47 | Picasso.with(parent.getContext()).load(url).into(itemViewHolder.imageView); 48 | return convertView; 49 | } 50 | 51 | @Override 52 | protected void onBindMainViewHolder(ViewHolder holder, int position) { 53 | List books = mData.get(position); 54 | if(books.size()>1){ 55 | holder.name.setText(""); 56 | }else { 57 | holder.name.setText(books.get(0).name); 58 | } 59 | } 60 | 61 | @Override 62 | protected void onBindSubViewHolder(ViewHolder holder, int mainPosition, int subPosition) { 63 | holder.name.setText(mData.get(mainPosition).get(subPosition).name+""); 64 | } 65 | 66 | public static class ViewHolder extends SimpleAdapter.ViewHolder { 67 | TextView name; 68 | public ViewHolder(View itemView) { 69 | super(itemView); 70 | name = (TextView) itemView.findViewById(R.id.text_name); 71 | } 72 | } 73 | 74 | 75 | static class ItemViewHolder{ 76 | ImageView imageView; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/demonstrate/logic/BookListener.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.demonstrate.logic; 2 | 3 | /** 4 | *

5 | * Date: 16/6/12 14:03 6 | * Author: rsshinide38@163.com 7 | *

8 | */ 9 | public interface BookListener { 10 | void onSuccess(String result); 11 | void onFailure(Exception e); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/demonstrate/logic/NetManager.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.demonstrate.logic; 2 | 3 | import android.net.Uri; 4 | import android.os.Handler; 5 | import android.os.Looper; 6 | import android.os.Message; 7 | import android.text.TextUtils; 8 | 9 | import java.io.BufferedReader; 10 | import java.io.InputStream; 11 | import java.io.InputStreamReader; 12 | import java.net.HttpURLConnection; 13 | import java.net.URL; 14 | 15 | /** 16 | *

17 | * Date: 16/6/12 11:37 18 | * Author: rsshinide38@163.com 19 | *

20 | */ 21 | public class NetManager { 22 | private static final String BASE_URL = "http://www.tngou.net/api/book"; 23 | private static final int SUCCESS = 1; 24 | private static final int FAILURE = 0; 25 | 26 | private String get(String path) throws Exception { 27 | String result = ""; 28 | StringBuilder sb = new StringBuilder(); 29 | URL url = new URL(BASE_URL + path); 30 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 31 | connection.setRequestMethod("GET"); 32 | if (connection.getResponseCode() == 200) { 33 | InputStream in = connection.getInputStream(); 34 | BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); 35 | String strRead; 36 | while ((strRead = reader.readLine()) != null) { 37 | sb.append(strRead); 38 | } 39 | reader.close(); 40 | result = sb.toString(); 41 | } 42 | return result; 43 | } 44 | 45 | 46 | public String getClassify() throws Exception { 47 | return get("/classify"); 48 | } 49 | 50 | public String getList(String page, String rows, String id) throws Exception { 51 | Uri uri = Uri.parse("/list"); 52 | Uri.Builder builder = uri.buildUpon(); 53 | if(!TextUtils.isEmpty(page)) { 54 | builder.appendQueryParameter("page", page); 55 | } 56 | if(!TextUtils.isEmpty(rows)) { 57 | builder.appendQueryParameter("rows", rows); 58 | } 59 | if(!TextUtils.isEmpty(id)) { 60 | builder.appendQueryParameter("id", id); 61 | } 62 | uri = builder.build(); 63 | return get(uri.toString()); 64 | } 65 | 66 | public String getDetail(String id) throws Exception { 67 | Uri uri = Uri.parse("/show"); 68 | uri = uri.buildUpon().appendQueryParameter("id", id).build(); 69 | return get(uri.toString()); 70 | } 71 | 72 | 73 | public void getBookList(final BookListener bookListener) { 74 | final Handler handler = new Handler(Looper.getMainLooper()){ 75 | @Override 76 | public void handleMessage(Message msg) { 77 | int state = msg.what; 78 | if(state == SUCCESS){ 79 | bookListener.onSuccess((String) msg.obj); 80 | }else { 81 | bookListener.onFailure((Exception) msg.obj); 82 | } 83 | } 84 | }; 85 | new Thread(new Runnable() { 86 | @Override 87 | public void run() { 88 | try { 89 | String result = getList(null,40+"",null); 90 | Message message = Message.obtain(); 91 | message.what = SUCCESS; 92 | message.obj = result; 93 | handler.sendMessage(message); 94 | } catch (Exception e) { 95 | Message message = Message.obtain(); 96 | message.what = FAILURE; 97 | message.obj = e; 98 | handler.sendMessage(message); 99 | } 100 | } 101 | }).start(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/demonstrate/logic/SelectBookListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.demonstrate.logic; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.ImageView; 8 | import android.widget.TextView; 9 | 10 | import com.anarchy.classifyview.R; 11 | import com.squareup.picasso.Picasso; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | *

17 | * Date: 16/6/12 14:20 18 | * Author: rsshinide38@163.com 19 | *

20 | */ 21 | public class SelectBookListAdapter extends RecyclerView.Adapter { 22 | private List mBookList; 23 | private ItemClickListener mItemClickListener; 24 | 25 | 26 | 27 | public void setItemClickListener(ItemClickListener listener){ 28 | mItemClickListener = listener; 29 | } 30 | 31 | 32 | public void setBookList(List bookList){ 33 | mBookList = bookList; 34 | notifyDataSetChanged(); 35 | } 36 | 37 | public List getBookList() { 38 | return mBookList; 39 | } 40 | 41 | @Override 42 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 43 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_select_list,parent,false); 44 | return new ViewHolder(view); 45 | } 46 | 47 | @Override 48 | public void onBindViewHolder(ViewHolder holder, final int position) { 49 | final Book book = mBookList.get(position); 50 | holder.title.setText(book.name); 51 | holder.summary.setText(book.summary); 52 | Picasso.with(holder.itemView.getContext()).load(book.imageUrl).into(holder.cover); 53 | if(mItemClickListener != null){ 54 | holder.itemView.setOnClickListener(new View.OnClickListener() { 55 | @Override 56 | public void onClick(View v) { 57 | if(mItemClickListener != null){ 58 | mItemClickListener.onItemClick(v,position,book); 59 | } 60 | } 61 | }); 62 | } 63 | } 64 | 65 | @Override 66 | public int getItemCount() { 67 | if(mBookList != null) return mBookList.size(); 68 | return 0; 69 | } 70 | 71 | public interface ItemClickListener{ 72 | void onItemClick(View parent,int position,Book book); 73 | } 74 | 75 | 76 | public static class ViewHolder extends RecyclerView.ViewHolder{ 77 | private ImageView cover; 78 | private TextView title; 79 | private TextView summary; 80 | public ViewHolder(View itemView) { 81 | super(itemView); 82 | cover = (ImageView) itemView.findViewById(R.id.book_cover); 83 | title = (TextView) itemView.findViewById(R.id.text_title); 84 | summary = (TextView) itemView.findViewById(R.id.text_summary); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/ireader/IReaderMockFragment.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.ireader; 2 | 3 | import android.content.Context; 4 | import android.databinding.DataBindingUtil; 5 | import android.graphics.Color; 6 | import android.graphics.PixelFormat; 7 | import android.os.Bundle; 8 | import android.support.annotation.Nullable; 9 | import android.view.Gravity; 10 | import android.view.LayoutInflater; 11 | import android.view.Menu; 12 | import android.view.MenuInflater; 13 | import android.view.MenuItem; 14 | import android.view.View; 15 | import android.view.ViewGroup; 16 | import android.view.WindowManager; 17 | import android.widget.PopupWindow; 18 | 19 | import com.anarchy.classify.ClassifyView; 20 | import com.anarchy.classifyview.R; 21 | import com.anarchy.classifyview.core.BaseFragment; 22 | import com.anarchy.classifyview.databinding.ExtraIreaderBottomBarBinding; 23 | import com.anarchy.classifyview.databinding.FragmentMockIreaderBinding; 24 | import com.anarchy.classifyview.sample.ireader.model.IReaderMockData; 25 | 26 | import java.util.Random; 27 | 28 | /** 29 | * User: Anarchy 30 | * Email: rsshinide38@163.com 31 | * Date: 16/12/26 15:01 32 | * Description: 33 | */ 34 | public class IReaderMockFragment extends BaseFragment { 35 | private FragmentMockIreaderBinding mBinding; 36 | private ExtraIreaderBottomBarBinding mBottomBinding; 37 | private IReaderAdapter mAdapter; 38 | private Random mRandom; 39 | private WindowManager mWindowManager; 40 | private WindowManager.LayoutParams mLayoutParams; 41 | 42 | @Override 43 | public void onCreate(@Nullable Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | setHasOptionsMenu(true); 46 | setRetainInstance(true); 47 | mWindowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); 48 | mLayoutParams = new WindowManager.LayoutParams(); 49 | mLayoutParams.format = PixelFormat.TRANSPARENT; 50 | mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; 51 | mLayoutParams.token = getActivity().getWindow().getDecorView().getWindowToken(); 52 | mLayoutParams.gravity = Gravity.BOTTOM; 53 | mLayoutParams.flags |= WindowManager.LayoutParams.FLAG_SPLIT_TOUCH|WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 54 | mLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; 55 | mLayoutParams.width = -1; 56 | mLayoutParams.height = -2; 57 | } 58 | 59 | 60 | 61 | @Nullable 62 | @Override 63 | public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 64 | mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_mock_ireader, container, false); 65 | mBottomBinding = DataBindingUtil.inflate(inflater, R.layout.extra_ireader_bottom_bar, null, false); 66 | mRandom = new Random(System.currentTimeMillis()); 67 | mAdapter = new IReaderAdapter(); 68 | mAdapter.registerObserver(new IReaderAdapter.IReaderObserver() { 69 | int count = 0; 70 | 71 | 72 | 73 | 74 | @Override 75 | public void onChecked(boolean isChecked) { 76 | count += isChecked ? 1 : -1; 77 | if (count <= 0) { 78 | count = 0; 79 | mBottomBinding.icDeleteBadge.setVisibility(View.INVISIBLE); 80 | setBottomEnable(false); 81 | } else { 82 | if (mBottomBinding.icDeleteBadge.getVisibility() == View.INVISIBLE) { 83 | mBottomBinding.icDeleteBadge.setVisibility(View.VISIBLE); 84 | } 85 | mBottomBinding.icDeleteBadge.setText(String.valueOf(count)); 86 | setBottomEnable(true); 87 | } 88 | } 89 | 90 | @Override 91 | public void onEditChanged(boolean inEdit) { 92 | if(inEdit){ 93 | showEditMode(); 94 | }else { 95 | hideEditMode(); 96 | } 97 | } 98 | 99 | @Override 100 | public void onRestore() { 101 | count = 0; 102 | mBottomBinding.icDeleteBadge.setVisibility(View.INVISIBLE); 103 | setBottomEnable(false); 104 | } 105 | 106 | @Override 107 | public void onHideSubDialog() { 108 | mBinding.classifyView.hideSubContainer(); 109 | } 110 | }); 111 | mBinding.classifyView.setAdapter(mAdapter); 112 | mBinding.classifyView.setDebugAble(true); 113 | mBinding.textComplete.setOnClickListener(new View.OnClickListener() { 114 | @Override 115 | public void onClick(View v) { 116 | mAdapter.setEditMode(false); 117 | } 118 | }); 119 | mBottomBinding.containerDelete.setOnClickListener(new View.OnClickListener() { 120 | @Override 121 | public void onClick(View v) { 122 | mAdapter.removeAllCheckedBook(); 123 | } 124 | }); 125 | final float density = getResources().getDisplayMetrics().density; 126 | mBinding.getRoot().post(new Runnable() { 127 | @Override 128 | public void run() { 129 | mBottomBinding.getRoot().setTranslationY(55*density); 130 | mWindowManager.addView(mBottomBinding.getRoot(),mLayoutParams); 131 | } 132 | }); 133 | mBinding.toolBar.setTranslationY(-60*density); 134 | return mBinding.getRoot(); 135 | } 136 | 137 | @Override 138 | public void onResume() { 139 | super.onResume(); 140 | } 141 | 142 | private void setBottomEnable(boolean enable) { 143 | mBottomBinding.containerDelete.setEnabled(enable); 144 | mBottomBinding.containerMove.setEnabled(enable); 145 | mBottomBinding.containerShare.setEnabled(enable); 146 | mBottomBinding.containerOrder.setEnabled(enable); 147 | mBottomBinding.containerDetail.setEnabled(enable); 148 | } 149 | 150 | 151 | private void showEditMode() { 152 | mBinding.toolBar.animate().translationY(0).start(); 153 | mBottomBinding.getRoot().animate().translationY(0).start(); 154 | } 155 | 156 | private void hideEditMode() { 157 | mBinding.toolBar.animate().translationY(-mBinding.toolBar.getHeight()).start(); 158 | mBottomBinding.getRoot().animate().translationY(mBottomBinding.getRoot().getHeight()).start(); 159 | } 160 | 161 | @Override 162 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 163 | inflater.inflate(R.menu.menu_i_reader, menu); 164 | } 165 | 166 | @Override 167 | public boolean onOptionsItemSelected(MenuItem item) { 168 | if (item.getItemId() == R.id.action_add) { 169 | mAdapter.addBook(generateRandomMockData()); 170 | return true; 171 | } 172 | return super.onOptionsItemSelected(item); 173 | } 174 | 175 | 176 | private IReaderMockData generateRandomMockData() { 177 | IReaderMockData mockData = new IReaderMockData(); 178 | mockData.setColor(Color.rgb(mRandom.nextInt(256), mRandom.nextInt(256), mRandom.nextInt(256))); 179 | return mockData; 180 | } 181 | 182 | @Override 183 | public void onDestroyView() { 184 | mWindowManager.removeViewImmediate(mBottomBinding.getRoot()); 185 | super.onDestroyView(); 186 | } 187 | 188 | @Override 189 | public boolean onBackPressed() { 190 | if (mAdapter.isEditMode()) { 191 | mAdapter.setEditMode(false); 192 | return true; 193 | } 194 | return super.onBackPressed(); 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/ireader/model/IReaderMockData.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.ireader.model; 2 | 3 | import android.graphics.Color; 4 | 5 | public class IReaderMockData { 6 | private boolean isChecked; 7 | private int color = Color.BLUE; 8 | private IReaderMockDataGroup mParent; 9 | 10 | 11 | 12 | 13 | 14 | public boolean isChecked() { 15 | return isChecked; 16 | } 17 | 18 | public void setChecked(boolean checked) { 19 | isChecked = checked; 20 | } 21 | 22 | public int getColor() { 23 | return color; 24 | } 25 | 26 | public void setColor(int color) { 27 | this.color = color; 28 | } 29 | 30 | public IReaderMockDataGroup getParent() { 31 | return mParent; 32 | } 33 | 34 | public void setParent(IReaderMockDataGroup parent) { 35 | mParent = parent; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/ireader/model/IReaderMockDataGroup.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.ireader.model; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * User: Anarchy 10 | * Email: rsshinide38@163.com 11 | * CreateTime: 一月/02/2017 22:50. 12 | * Description: 13 | */ 14 | public class IReaderMockDataGroup extends IReaderMockData{ 15 | private List mChild = new ArrayList<>(); 16 | private String mCategory; 17 | 18 | public void addChild(@NonNull IReaderMockData iReaderMockData){ 19 | iReaderMockData.setParent(this); 20 | mChild.add(iReaderMockData); 21 | } 22 | 23 | public void addChild(int location,@NonNull IReaderMockData iReaderMockData){ 24 | iReaderMockData.setParent(this); 25 | mChild.add(location,iReaderMockData); 26 | } 27 | 28 | public IReaderMockData removeChild(int location){ 29 | IReaderMockData mockData = mChild.remove(location); 30 | mockData.setParent(null); 31 | return mockData; 32 | } 33 | 34 | public boolean removeChild(@NonNull IReaderMockData iReaderMockData){ 35 | iReaderMockData.setParent(null); 36 | return mChild.remove(iReaderMockData); 37 | } 38 | 39 | 40 | public int getChildCount(){ 41 | return mChild.size(); 42 | } 43 | 44 | 45 | public IReaderMockData getChild(int position){ 46 | return mChild.get(position); 47 | } 48 | 49 | 50 | public String getCategory() { 51 | return mCategory; 52 | } 53 | 54 | public void setCategory(String category) { 55 | mCategory = category; 56 | } 57 | 58 | public int getCheckedCount(){ 59 | if(mChild != null){ 60 | int i = 0; 61 | for(IReaderMockData data:mChild){ 62 | if(data.isChecked()){ 63 | i++; 64 | } 65 | } 66 | return i; 67 | } 68 | return 0; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/ireader/widget/IReaderClassifyView.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.ireader.widget; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.graphics.PixelFormat; 6 | import android.util.AttributeSet; 7 | import android.view.Gravity; 8 | import android.view.View; 9 | import android.view.Window; 10 | import android.view.WindowManager; 11 | 12 | import com.anarchy.classify.ClassifyView; 13 | import com.anarchy.classifyview.R; 14 | 15 | /** 16 | * Version 2.1.1 17 | *

18 | * Date: 17/1/10 15:46 19 | * Author: rsshinide38@163.com 20 | */ 21 | 22 | public class IReaderClassifyView extends ClassifyView { 23 | public IReaderClassifyView(Context context) { 24 | super(context); 25 | } 26 | 27 | public IReaderClassifyView(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | } 30 | 31 | public IReaderClassifyView(Context context, AttributeSet attrs, int defStyleAttr) { 32 | super(context, attrs, defStyleAttr); 33 | } 34 | 35 | @Override 36 | protected Dialog createSubDialog() { 37 | Dialog dialog = new Dialog(getContext(), R.style.SubDialogStyle); 38 | dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); 39 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 40 | WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes(); 41 | layoutParams.gravity = Gravity.BOTTOM; 42 | layoutParams.height = getHeight(); 43 | layoutParams.dimAmount = 0.6f; 44 | layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; 45 | layoutParams.format = PixelFormat.TRANSPARENT; 46 | layoutParams.windowAnimations = R.style.BottomDialogAnimation; 47 | dialog.setCancelable(true); 48 | dialog.setCanceledOnTouchOutside(true); 49 | dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); 50 | return dialog; 51 | } 52 | 53 | @Override 54 | protected View getSubContent() { 55 | return inflate(getContext(), R.layout.extra_ireader_sub_content, null); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/ireader/widget/IReaderFolder.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.ireader.widget; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.LayoutTransition; 6 | import android.annotation.TargetApi; 7 | import android.content.Context; 8 | import android.os.Build; 9 | import android.support.annotation.IntDef; 10 | import android.util.AttributeSet; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.FrameLayout; 14 | import android.widget.RelativeLayout; 15 | import android.widget.TextView; 16 | 17 | import com.anarchy.classify.simple.ChangeInfo; 18 | import com.anarchy.classify.simple.PrimitiveSimpleAdapter; 19 | import com.anarchy.classify.simple.widget.CanMergeView; 20 | import com.anarchy.classify.util.L; 21 | import com.anarchy.classifyview.R; 22 | 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | 26 | /** 27 | * User: Anarchy 28 | * Email: rsshinide38@163.com 29 | * Date: 16/12/27 14:44 30 | * Description: 31 | */ 32 | public class IReaderFolder extends RelativeLayout implements CanMergeView { 33 | 34 | public static final int STATE_AUTO = 0; 35 | /** 36 | * 永久显示Folder 37 | */ 38 | public static final int STATE_FOLDER = 1; 39 | 40 | @IntDef({STATE_AUTO, STATE_FOLDER}) 41 | @Retention(RetentionPolicy.SOURCE) 42 | @interface State { 43 | 44 | } 45 | 46 | private static final int FOLDER_ID = R.id.i_reader_folder_bg; 47 | private static final int TAG_ID = R.id.i_reader_folder_tag; 48 | private static final int CONTAINER_GRID_ID = R.id.i_reader_folder_grid; 49 | private static final int CHECK_BOX_ID = R.id.i_reader_folder_check_box; 50 | private static final int CONTENT_ID = R.id.i_reader_folder_content; 51 | private PrimitiveSimpleAdapter mSimpleAdapter; 52 | private IReaderGridLayout mGridLayout; 53 | private FrameLayout mContent; 54 | private TextView mTagView; 55 | private View mFolderBg; 56 | private int mState = STATE_AUTO; 57 | 58 | public IReaderFolder(Context context) { 59 | super(context); 60 | } 61 | 62 | public IReaderFolder(Context context, AttributeSet attrs) { 63 | super(context, attrs); 64 | } 65 | 66 | public IReaderFolder(Context context, AttributeSet attrs, int defStyleAttr) { 67 | super(context, attrs, defStyleAttr); 68 | } 69 | 70 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 71 | public IReaderFolder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 72 | super(context, attrs, defStyleAttr, defStyleRes); 73 | } 74 | 75 | 76 | @Override 77 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 78 | super.onLayout(changed, l, t, r, b); 79 | ensureViewFound(); 80 | switch (mState) { 81 | case STATE_AUTO: 82 | mFolderBg.setVisibility(getChildCount() > 1 ? View.VISIBLE : View.GONE); 83 | break; 84 | case STATE_FOLDER: 85 | mFolderBg.setVisibility(View.VISIBLE); 86 | break; 87 | } 88 | } 89 | 90 | /** 91 | * 设置显示状态 92 | * 93 | * @param state 94 | */ 95 | public void setState(@State int state) { 96 | mState = state; 97 | } 98 | 99 | 100 | /** 101 | * 进入merge状态 102 | */ 103 | @Override 104 | public void onMergeStart() { 105 | mFolderBg.setVisibility(View.VISIBLE); 106 | mFolderBg.setPivotX(mFolderBg.getWidth() / 2); 107 | mFolderBg.setPivotY(mFolderBg.getHeight() / 2); 108 | mFolderBg.animate().scaleX(1.2f).scaleY(1.1f).setDuration(200).start(); 109 | } 110 | 111 | /** 112 | * 离开merge状态 113 | */ 114 | @Override 115 | public void onMergeCancel() { 116 | mFolderBg.animate().scaleX(1f).scaleY(1f).setDuration(200).setListener(new AnimatorListenerAdapter() { 117 | @Override 118 | public void onAnimationEnd(Animator animation) { 119 | mFolderBg.animate().setListener(null); 120 | switch (mState) { 121 | case STATE_AUTO: 122 | if (getChildCount() <= 1) { 123 | mFolderBg.setVisibility(View.GONE); 124 | } 125 | break; 126 | case STATE_FOLDER: 127 | //nope 128 | break; 129 | } 130 | } 131 | }); 132 | } 133 | 134 | 135 | /** 136 | * 结束merge事件 137 | */ 138 | @Override 139 | public void onMerged() { 140 | mFolderBg.animate().scaleX(1f).scaleY(1f).setDuration(200).start(); 141 | } 142 | 143 | /** 144 | * 开始merge动画 145 | * 146 | * @param duration 动画持续时间 147 | */ 148 | @Override 149 | public void startMergeAnimation(final int duration) { 150 | if(mContent.getVisibility() == View.VISIBLE){ 151 | ChangeInfo info = mGridLayout.getSecondItemChangeInfo(); 152 | float scaleX = info.targetWidth/mContent.getWidth(); 153 | float scaleY = info.targetHeight/mContent.getHeight(); 154 | mContent.setPivotX(0); 155 | mContent.setPivotY(0); 156 | mContent.animate() 157 | .scaleX(scaleX).scaleY(scaleY) 158 | .translationX(info.targetLeft).translationY(info.targetTop) 159 | .setDuration(duration) 160 | .setListener(new AnimatorListenerAdapter() { 161 | @Override 162 | public void onAnimationCancel(Animator animation) { 163 | restoreViewDelayed(mContent,duration); 164 | } 165 | 166 | @Override 167 | public void onAnimationEnd(Animator animation) { 168 | restoreViewDelayed(mContent,duration); 169 | } 170 | }) 171 | .start(); 172 | }else { 173 | final View dummyView = new View(getContext()); 174 | mGridLayout.getLayoutTransition().setDuration(duration); 175 | mGridLayout.getLayoutTransition().addTransitionListener(new LayoutTransition.TransitionListener() { 176 | @Override 177 | public void startTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) { 178 | 179 | } 180 | 181 | @Override 182 | public void endTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) { 183 | mGridLayout.removeView(dummyView); 184 | } 185 | }); 186 | mGridLayout.addView(dummyView,0); 187 | } 188 | } 189 | 190 | 191 | private void restoreViewDelayed(final View view,int delayTime){ 192 | postDelayed(new Runnable() { 193 | @Override 194 | public void run() { 195 | view.setScaleX(1f); 196 | view.setScaleY(1f); 197 | view.setTranslationX(0f); 198 | view.setTranslationY(0f); 199 | } 200 | },delayTime); 201 | } 202 | 203 | /** 204 | * 准备merge 205 | * 206 | * @return 返回新添加的view 应该放置在布局中的位置坐标 207 | */ 208 | @Override 209 | public ChangeInfo prepareMerge() { 210 | ChangeInfo changeInfo = mGridLayout.getChangeInfo(); 211 | int left = getLeft(); 212 | int top = getTop(); 213 | //修正数值 214 | changeInfo.targetLeft += left + mGridLayout.getLeft(); 215 | changeInfo.targetTop += top + mGridLayout.getTop(); 216 | changeInfo.sourceLeft = left + mContent.getLeft(); 217 | changeInfo.sourceTop = top + mContent.getTop(); 218 | changeInfo.sourceWidth = mContent.getWidth(); 219 | changeInfo.sourceHeight = mContent.getHeight(); 220 | return changeInfo; 221 | } 222 | 223 | /** 224 | * 设置适配器 225 | * 226 | * @param primitiveSimpleAdapter 227 | */ 228 | @Override 229 | public void setAdapter(PrimitiveSimpleAdapter primitiveSimpleAdapter) { 230 | mSimpleAdapter = primitiveSimpleAdapter; 231 | } 232 | 233 | 234 | /** 235 | * 初始化或更新主层级 236 | * 237 | * @param parentIndex 238 | * @param requestCount 需要显示里面有几个子view 239 | */ 240 | @Override 241 | public void initOrUpdateMain(int parentIndex, int requestCount) { 242 | if(mGridLayout == null){ 243 | ensureViewFound(); 244 | } 245 | if (mGridLayout == null || requestCount <= 0) return; 246 | int childCount = mGridLayout.getChildCount(); 247 | if (childCount > requestCount) { 248 | mGridLayout.removeViews(requestCount,childCount - requestCount); 249 | } 250 | childCount = mGridLayout.getChildCount(); 251 | for (int i = 0; i < requestCount; i++) { 252 | View convertView = null; 253 | if (i < childCount) { 254 | convertView = mGridLayout.getChildAt(i); 255 | } 256 | View adapterChild = mSimpleAdapter.getView(this, convertView, parentIndex, i); 257 | if (adapterChild == null) continue; 258 | if (adapterChild == convertView) { 259 | //nope 260 | } else if (i < childCount) { 261 | mGridLayout.removeViewAt(i); 262 | mGridLayout.addView(adapterChild, i); 263 | } else { 264 | mGridLayout.addView(adapterChild, i); 265 | } 266 | } 267 | } 268 | 269 | 270 | /** 271 | * 初始化或更新次级层级 272 | * 273 | * @param parentIndex 274 | * @param subIndex 275 | */ 276 | @Override 277 | public void initOrUpdateSub(int parentIndex, int subIndex) { 278 | //nope 279 | } 280 | 281 | 282 | 283 | 284 | @Override 285 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 286 | super.onSizeChanged(w, h, oldw, oldh); 287 | } 288 | 289 | private void ensureViewFound() { 290 | if (mFolderBg == null | mContent == null | mTagView == null | mGridLayout == null) { 291 | mFolderBg = findViewById(FOLDER_ID); 292 | mContent = (FrameLayout) findViewById(CONTENT_ID); 293 | mTagView = (TextView) findViewById(TAG_ID); 294 | mGridLayout = (IReaderGridLayout) findViewById(CONTAINER_GRID_ID); 295 | mGridLayout.setLayoutTransition(new LayoutTransition()); 296 | } 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/ireader/widget/IReaderGridLayout.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.ireader.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.anarchy.classify.simple.ChangeInfo; 10 | import com.anarchy.classify.util.L; 11 | import com.anarchy.classifyview.R; 12 | 13 | 14 | /** 15 | * User: Anarchy 16 | * Email: rsshinide38@163.com 17 | * CreateTime: 一月/07/2017 18:21. 18 | * Description: 19 | */ 20 | 21 | public class IReaderGridLayout extends ViewGroup { 22 | private int mRowCount; 23 | private int mColumnCount; 24 | private int mGap; 25 | 26 | public IReaderGridLayout(Context context) { 27 | this(context, null); 28 | } 29 | 30 | public IReaderGridLayout(Context context, AttributeSet attrs) { 31 | this(context, attrs, 0); 32 | } 33 | 34 | public IReaderGridLayout(Context context, AttributeSet attrs, int defStyleAttr) { 35 | super(context, attrs, defStyleAttr); 36 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IReaderGridLayout, defStyleAttr, 0); 37 | mRowCount = a.getInt(R.styleable.IReaderGridLayout_iReaderRowCount, 2); 38 | mColumnCount = a.getInt(R.styleable.IReaderGridLayout_iReaderColumnCount, 2); 39 | mGap = a.getDimensionPixelSize(R.styleable.IReaderGridLayout_iReaderGap, 0); 40 | a.recycle(); 41 | } 42 | 43 | 44 | @Override 45 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 46 | int widthSize = MeasureSpec.getSize(widthMeasureSpec); 47 | int widthMode = MeasureSpec.getMode(widthMeasureSpec); 48 | int heightSize = MeasureSpec.getSize(heightMeasureSpec); 49 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); 50 | 51 | 52 | if (widthMode == MeasureSpec.AT_MOST || heightMode == MeasureSpec.AT_MOST) { 53 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 54 | } else { 55 | int suggestWidth = (widthSize - getPaddingLeft() - getPaddingRight() - (mColumnCount -1 )*mGap) / mColumnCount; 56 | int suggestHeight = (heightSize - getPaddingTop() - getPaddingBottom() - (mRowCount-1)*mGap) / mRowCount; 57 | int childCount = getChildCount(); 58 | for (int i = 0; i < childCount; i++) { 59 | View child = getChildAt(i); 60 | child.measure(MeasureSpec.makeMeasureSpec(suggestWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(suggestHeight, MeasureSpec.EXACTLY)); 61 | } 62 | setMeasuredDimension(widthSize, heightSize); 63 | } 64 | } 65 | 66 | @Override 67 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 68 | int childCount = getChildCount(); 69 | for (int i = 0; i < childCount; i++) { 70 | View child = getChildAt(i); 71 | int left = getPaddingLeft() + (i%mColumnCount)*(child.getMeasuredWidth() + mGap); 72 | int top = getPaddingTop() + (i/mRowCount)*(child.getMeasuredHeight() + mGap); 73 | child.layout(left,top,left + child.getMeasuredWidth(),top + child.getMeasuredHeight()); 74 | } 75 | } 76 | 77 | ChangeInfo getChangeInfo(){ 78 | ChangeInfo info = new ChangeInfo(); 79 | info.targetLeft = getPaddingLeft(); 80 | info.targetTop = getPaddingTop(); 81 | info.targetWidth = (getWidth() - getPaddingLeft() - getPaddingRight() - (mColumnCount -1 )*mGap)/mColumnCount; 82 | info.targetHeight = (getHeight() - getPaddingTop() - getPaddingBottom() - (mRowCount-1)*mGap)/mRowCount; 83 | return info; 84 | } 85 | 86 | /** 87 | * @hide 88 | */ 89 | ChangeInfo getSecondItemChangeInfo(){ 90 | ChangeInfo info = new ChangeInfo(); 91 | info.targetWidth = (getWidth() - getPaddingLeft() - getPaddingRight() - (mColumnCount -1 )*mGap)/mColumnCount; 92 | info.targetHeight = (getHeight() - getPaddingTop() - getPaddingBottom() - (mRowCount-1)*mGap)/mRowCount; 93 | info.targetLeft = (int) (getPaddingLeft() + info.targetWidth + mGap); 94 | info.targetTop = getPaddingTop(); 95 | return info; 96 | } 97 | 98 | 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/layoutmanager/HHAdapter.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.layoutmanager; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | 7 | import com.anarchy.classify.simple.SimpleAdapter; 8 | import com.anarchy.classify.simple.widget.InsertAbleGridView; 9 | import com.anarchy.classifyview.R; 10 | import com.anarchy.classifyview.core.Bean; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Version 2.1.1 16 | *

17 | * Date: 16/12/26 12:00 18 | * Author: rsshinide38@163.com 19 | */ 20 | 21 | public class HHAdapter extends SimpleAdapter{ 22 | 23 | 24 | public HHAdapter(List> data) { 25 | super(data); 26 | } 27 | 28 | @Override 29 | protected ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 30 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample_horizontal,parent,false); 31 | return new ViewHolder(view); 32 | } 33 | 34 | 35 | /** 36 | * 用于显示{@link InsertAbleGridView} 的item布局 37 | * 38 | * @param parent 父View 39 | * @param convertView 缓存的View 可能为null 40 | * @param mainPosition 主层级位置 41 | * @param subPosition 副层级位置 42 | * @return 43 | */ 44 | @Override 45 | public View getView(ViewGroup parent, View convertView, int mainPosition, int subPosition) { 46 | if (convertView == null) { 47 | convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_inner, parent, false); 48 | } 49 | return convertView; 50 | } 51 | 52 | static class ViewHolder extends SimpleAdapter.ViewHolder{ 53 | 54 | public ViewHolder(View itemView) { 55 | super(itemView); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/layoutmanager/HVAdapter.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.layoutmanager; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | 7 | import com.anarchy.classify.simple.SimpleAdapter; 8 | import com.anarchy.classify.simple.widget.InsertAbleGridView; 9 | import com.anarchy.classifyview.R; 10 | import com.anarchy.classifyview.core.Bean; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Date: 16/12/26 12:00 16 | * Author: rsshinide38@163.com 17 | */ 18 | 19 | public class HVAdapter extends SimpleAdapter{ 20 | 21 | 22 | public HVAdapter(List> data) { 23 | super(data); 24 | } 25 | 26 | 27 | @Override 28 | protected ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 29 | View view; 30 | if(getSpecialType(viewType) == TYPE_MAIN){ 31 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample_horizontal,parent,false); 32 | }else { 33 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample_vertical,parent,false); 34 | } 35 | return new HVAdapter.ViewHolder(view); 36 | } 37 | 38 | @Override 39 | protected boolean haveSpecialType() { 40 | return true; 41 | } 42 | 43 | /** 44 | * 用于显示{@link InsertAbleGridView} 的item布局 45 | * 46 | * @param parent 父View 47 | * @param convertView 缓存的View 可能为null 48 | * @param mainPosition 主层级位置 49 | * @param subPosition 副层级位置 50 | * @return 51 | */ 52 | @Override 53 | public View getView(ViewGroup parent, View convertView, int mainPosition, int subPosition) { 54 | if (convertView == null) { 55 | convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_inner, parent, false); 56 | } 57 | return convertView; 58 | } 59 | 60 | static class ViewHolder extends SimpleAdapter.ViewHolder{ 61 | 62 | public ViewHolder(View itemView) { 63 | super(itemView); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/layoutmanager/LayoutManagerFragment.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.layoutmanager; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.Menu; 9 | import android.view.MenuInflater; 10 | import android.view.MenuItem; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.view.ViewStub; 14 | 15 | import com.anarchy.classifyview.R; 16 | import com.anarchy.classifyview.core.BaseFragment; 17 | import com.anarchy.classifyview.core.MyAdapter; 18 | import com.anarchy.classifyview.databinding.FragmentLayoutmanagerBinding; 19 | import com.anarchy.classifyview.databinding.StubClassifyHhBinding; 20 | import com.anarchy.classifyview.databinding.StubClassifyHvBinding; 21 | import com.anarchy.classifyview.utils.DataGenerate; 22 | 23 | /** 24 | * User: Anarchy 25 | * Email: rsshinide38@163.com 26 | * CreateTime: 十二月/25/2016 11:45. 27 | * Description: 28 | */ 29 | 30 | public class LayoutManagerFragment extends BaseFragment { 31 | private FragmentLayoutmanagerBinding mBinding; 32 | @Override 33 | public void onCreate(@Nullable Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setHasOptionsMenu(true); 36 | } 37 | 38 | @Nullable 39 | @Override 40 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 41 | mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_layoutmanager,container,false); 42 | mBinding.classifyViewVv.setAdapter(new MyAdapter(DataGenerate.generateBean())); 43 | return mBinding.getRoot(); 44 | } 45 | 46 | @Override 47 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 48 | inflater.inflate(R.menu.menu_layout_manager_type,menu); 49 | } 50 | 51 | @Override 52 | public boolean onOptionsItemSelected(MenuItem item) { 53 | if(item.isChecked()) return false; 54 | item.setChecked(true); 55 | if(mBinding.stubClassifyViewHv.isInflated() && mBinding.stubClassifyViewHv.getRoot().getVisibility() == View.VISIBLE){ 56 | mBinding.stubClassifyViewHv.getRoot().setVisibility(View.GONE); 57 | } 58 | if(mBinding.stubClassifyViewHh.isInflated() && mBinding.stubClassifyViewHh.getRoot().getVisibility() == View.VISIBLE){ 59 | mBinding.stubClassifyViewHh.getRoot().setVisibility(View.GONE); 60 | } 61 | if(mBinding.classifyViewVv.getVisibility() == View.VISIBLE){ 62 | mBinding.classifyViewVv.setVisibility(View.GONE); 63 | } 64 | switch (item.getItemId()){ 65 | case R.id.menu_hh: 66 | if(mBinding.stubClassifyViewHh.isInflated()){ 67 | StubClassifyHhBinding binding = (StubClassifyHhBinding) mBinding.stubClassifyViewHh.getBinding(); 68 | binding.classifyViewHh.setVisibility(View.VISIBLE); 69 | }else { 70 | mBinding.stubClassifyViewHh.setOnInflateListener(new ViewStub.OnInflateListener() { 71 | @Override 72 | public void onInflate(ViewStub stub, View inflated) { 73 | StubClassifyHhBinding binding = (StubClassifyHhBinding) mBinding.stubClassifyViewHh.getBinding(); 74 | binding.classifyViewHh.setAdapter(new HHAdapter(DataGenerate.generateBean())); 75 | } 76 | }); 77 | mBinding.stubClassifyViewHh.getViewStub().inflate(); 78 | } 79 | return true; 80 | case R.id.menu_hv: 81 | if(mBinding.stubClassifyViewHv.isInflated()){ 82 | StubClassifyHvBinding binding = (StubClassifyHvBinding) mBinding.stubClassifyViewHv.getBinding(); 83 | binding.classifyViewHv.setVisibility(View.VISIBLE); 84 | }else { 85 | mBinding.stubClassifyViewHv.setOnInflateListener(new ViewStub.OnInflateListener() { 86 | @Override 87 | public void onInflate(ViewStub stub, View inflated) { 88 | StubClassifyHvBinding binding = (StubClassifyHvBinding) mBinding.stubClassifyViewHv.getBinding(); 89 | binding.classifyViewHv.setAdapter(new HVAdapter(DataGenerate.generateBean())); 90 | } 91 | }); 92 | mBinding.stubClassifyViewHv.getViewStub().inflate(); 93 | } 94 | return true; 95 | case R.id.menu_vv: 96 | mBinding.classifyViewVv.setVisibility(View.VISIBLE); 97 | return true; 98 | } 99 | return super.onOptionsItemSelected(item); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/layoutmanager/LinearHHClassifyView.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.layoutmanager; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.support.annotation.NonNull; 6 | import android.support.v7.widget.DefaultItemAnimator; 7 | import android.support.v7.widget.GridLayoutManager; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.util.AttributeSet; 11 | import android.view.ViewGroup; 12 | 13 | import com.anarchy.classify.ClassifyItemAnimator; 14 | import com.anarchy.classify.ClassifyView; 15 | 16 | /** 17 | * User: Anarchy 18 | * Email: rsshinide38@163.com 19 | * CreateTime: 十二月/25/2016 12:03. 20 | * Description: 21 | */ 22 | 23 | public class LinearHHClassifyView extends ClassifyView { 24 | public LinearHHClassifyView(Context context) { 25 | super(context); 26 | } 27 | 28 | public LinearHHClassifyView(Context context, AttributeSet attrs) { 29 | super(context, attrs); 30 | } 31 | 32 | public LinearHHClassifyView(Context context, AttributeSet attrs, int defStyleAttr) { 33 | super(context, attrs, defStyleAttr); 34 | } 35 | 36 | public LinearHHClassifyView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 37 | super(context, attrs, defStyleAttr, defStyleRes); 38 | } 39 | 40 | @NonNull 41 | @Override 42 | protected RecyclerView getMain(Context context, AttributeSet parentAttrs) { 43 | RecyclerView recyclerView = new RecyclerView(context); 44 | recyclerView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 45 | recyclerView.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false)); 46 | RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator(); 47 | itemAnimator.setChangeDuration(10); 48 | recyclerView.setItemAnimator(itemAnimator); 49 | return recyclerView; 50 | } 51 | 52 | @NonNull 53 | @Override 54 | protected RecyclerView getSub(Context context, AttributeSet parentAttrs) { 55 | RecyclerView recyclerView = new RecyclerView(context); 56 | recyclerView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 57 | recyclerView.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false)); 58 | RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator(); 59 | itemAnimator.setChangeDuration(10); 60 | recyclerView.setItemAnimator(itemAnimator); 61 | return recyclerView; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/layoutmanager/LinearHVClassifyView.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.layoutmanager; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.widget.DefaultItemAnimator; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.AttributeSet; 9 | import android.view.ViewGroup; 10 | 11 | import com.anarchy.classify.ClassifyItemAnimator; 12 | import com.anarchy.classify.ClassifyView; 13 | 14 | /** 15 | * User: Anarchy 16 | * Email: rsshinide38@163.com 17 | * CreateTime: 十二月/25/2016 12:03. 18 | * Description: 19 | */ 20 | 21 | public class LinearHVClassifyView extends ClassifyView { 22 | public LinearHVClassifyView(Context context) { 23 | super(context); 24 | } 25 | 26 | public LinearHVClassifyView(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | } 29 | 30 | public LinearHVClassifyView(Context context, AttributeSet attrs, int defStyleAttr) { 31 | super(context, attrs, defStyleAttr); 32 | } 33 | 34 | public LinearHVClassifyView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 35 | super(context, attrs, defStyleAttr, defStyleRes); 36 | } 37 | 38 | @NonNull 39 | @Override 40 | protected RecyclerView getMain(Context context, AttributeSet parentAttrs) { 41 | RecyclerView recyclerView = new RecyclerView(context); 42 | recyclerView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 43 | recyclerView.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false)); 44 | RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator(); 45 | itemAnimator.setChangeDuration(10); 46 | recyclerView.setItemAnimator(itemAnimator); 47 | return recyclerView; 48 | } 49 | 50 | @NonNull 51 | @Override 52 | protected RecyclerView getSub(Context context, AttributeSet parentAttrs) { 53 | RecyclerView recyclerView = new RecyclerView(context); 54 | recyclerView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 55 | recyclerView.setLayoutManager(new LinearLayoutManager(context)); 56 | RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator(); 57 | itemAnimator.setChangeDuration(10); 58 | recyclerView.setItemAnimator(itemAnimator); 59 | return recyclerView; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/layoutmanager/LinearVVClassifyView.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.layoutmanager; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.widget.DefaultItemAnimator; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.AttributeSet; 9 | import android.view.ViewGroup; 10 | 11 | import com.anarchy.classify.ClassifyItemAnimator; 12 | import com.anarchy.classify.ClassifyView; 13 | 14 | /** 15 | * User: Anarchy 16 | * Email: rsshinide38@163.com 17 | * CreateTime: 十二月/25/2016 11:59. 18 | * Description: 19 | */ 20 | 21 | public class LinearVVClassifyView extends ClassifyView { 22 | public LinearVVClassifyView(Context context) { 23 | super(context); 24 | } 25 | 26 | public LinearVVClassifyView(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | } 29 | 30 | public LinearVVClassifyView(Context context, AttributeSet attrs, int defStyleAttr) { 31 | super(context, attrs, defStyleAttr); 32 | } 33 | 34 | public LinearVVClassifyView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 35 | super(context, attrs, defStyleAttr, defStyleRes); 36 | } 37 | 38 | @NonNull 39 | @Override 40 | protected RecyclerView getMain(Context context, AttributeSet parentAttrs) { 41 | RecyclerView recyclerView = new RecyclerView(context); 42 | recyclerView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 43 | recyclerView.setLayoutManager(new LinearLayoutManager(context)); 44 | RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator(); 45 | itemAnimator.setChangeDuration(10); 46 | recyclerView.setItemAnimator(itemAnimator); 47 | return recyclerView; 48 | } 49 | 50 | @NonNull 51 | @Override 52 | protected RecyclerView getSub(Context context, AttributeSet parentAttrs) { 53 | RecyclerView recyclerView = new RecyclerView(context); 54 | recyclerView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 55 | recyclerView.setLayoutManager(new LinearLayoutManager(context)); 56 | RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator(); 57 | itemAnimator.setChangeDuration(10); 58 | recyclerView.setItemAnimator(itemAnimator); 59 | return recyclerView; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/normal/NormalFragment.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.normal; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.anarchy.classify.ClassifyView; 11 | import com.anarchy.classifyview.R; 12 | import com.anarchy.classifyview.core.BaseFragment; 13 | import com.anarchy.classifyview.core.MyAdapter; 14 | import com.anarchy.classifyview.utils.DataGenerate; 15 | 16 | /** 17 | *

18 | * Date: 16/6/12 09:51 19 | * Author: rsshinide38@163.com 20 | *

21 | */ 22 | public class NormalFragment extends BaseFragment{ 23 | private ClassifyView mClassifyView; 24 | @Nullable 25 | @Override 26 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 27 | View view = inflater.inflate(R.layout.normal,container,false); 28 | mClassifyView = (ClassifyView) view.findViewById(R.id.classify_view); 29 | mClassifyView.setAdapter(new MyAdapter(DataGenerate.generateBean())); 30 | mClassifyView.setDebugAble(true); 31 | return view; 32 | } 33 | 34 | @Override 35 | public void onDestroyView() { 36 | super.onDestroyView(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/normalfolder/Constants.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.normalfolder; 2 | 3 | /** 4 | * Created by lizhiming211223 on 2016/12/30. 5 | */ 6 | public class Constants { 7 | public static boolean IS_FOLDER_ADAPTER=false; 8 | public static String CLASSIFY_VIEW_INIT="CLASSIFY_VIEW_INIT"; 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/normalfolder/NormalFolderFragment.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.normalfolder; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.anarchy.classify.ClassifyView; 11 | import com.anarchy.classifyview.sample.normalfolder.bean.BaseBean; 12 | import com.anarchy.classifyview.R; 13 | import com.anarchy.classifyview.sample.normalfolder.logic.MyFolderAdapter; 14 | import com.anarchy.classifyview.utils.DataGenerate; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * Created by lizhiming211223 on 2016/12/29. 21 | */ 22 | public class NormalFolderFragment extends Fragment { 23 | private ClassifyView mClassifyView; 24 | private List baseBeans=new ArrayList<>(); 25 | @Nullable 26 | @Override 27 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 28 | View view = inflater.inflate(R.layout.normal,container,false); 29 | mClassifyView = (ClassifyView) view.findViewById(R.id.classify_view); 30 | initDatas(); 31 | mClassifyView.setAdapter(new MyFolderAdapter(baseBeans)); 32 | mClassifyView.setDebugAble(true); 33 | Constants.IS_FOLDER_ADAPTER=true; 34 | return view; 35 | } 36 | 37 | private void initDatas() { 38 | baseBeans= DataGenerate.generateBaseBean(); 39 | } 40 | 41 | @Override 42 | public void onDestroyView() { 43 | Constants.IS_FOLDER_ADAPTER=false; 44 | super.onDestroyView(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/normalfolder/bean/BaseBean.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.normalfolder.bean; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by lizhiming211223 on 2016/12/29. 7 | */ 8 | public class BaseBean { 9 | 10 | List bookList; 11 | public boolean isGroup; 12 | 13 | 14 | public boolean isGroup() { 15 | return isGroup; 16 | } 17 | 18 | public void setIsGroup(boolean isGroup) { 19 | this.isGroup = isGroup; 20 | } 21 | 22 | 23 | public BaseBean(List bookList) { 24 | this.bookList = bookList; 25 | } 26 | public List getBookList() { 27 | return bookList; 28 | } 29 | public BaseBean( ) { 30 | } 31 | public void setBookList(List bookList) { 32 | this.bookList = bookList; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/normalfolder/bean/BookBean.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.normalfolder.bean; 2 | 3 | /** 4 | * Created by lizhiming211223 on 2016/12/29. 5 | */ 6 | public class BookBean { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/normalfolder/logic/FolderAdapter.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.normalfolder.logic; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import com.anarchy.classify.R; 9 | import com.anarchy.classify.simple.PrimitiveSimpleAdapter; 10 | import com.anarchy.classifyview.sample.normalfolder.Constants; 11 | import com.anarchy.classifyview.sample.normalfolder.bean.BaseBean; 12 | import com.anarchy.classifyview.sample.normalfolder.bean.BookBean; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | /** 18 | *

19 | * Date: 16/12/29 11:55 20 | * Author: lizhiming 21 | *

22 | */ 23 | public abstract class FolderAdapter extends PrimitiveSimpleAdapter, VH> { 24 | protected List mData; 25 | 26 | public FolderAdapter(List data) { 27 | mData = data; 28 | } 29 | 30 | @SuppressWarnings("unchecked") 31 | protected VH onCreateViewHolder(ViewGroup parent, int viewType) { 32 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.simple_item, parent, false); 33 | return (VH) new ViewHolder(view); 34 | } 35 | 36 | 37 | protected void onBindMainViewHolder(VH holder, int position) { 38 | } 39 | 40 | protected void onBindSubViewHolder(VH holder, int mainPosition, int subPosition) { 41 | } 42 | 43 | /** 44 | * @param parentIndex 45 | * @param index if -1 in main region 46 | */ 47 | protected void onItemClick(View view, int parentIndex, int index) { 48 | } 49 | 50 | 51 | @Override 52 | public int getItemCount() { 53 | return mData.size(); 54 | } 55 | 56 | /** 57 | * 副层级的数量,用于主层级上的显示效果 58 | * 59 | * @param parentPosition 60 | * @return 61 | */ 62 | @Override 63 | protected int getSubItemCount(int parentPosition) { 64 | return mData.get(parentPosition).getBookList().size(); 65 | } 66 | 67 | @Override 68 | protected boolean canMergeItem(int selectPosition, int targetPosition) { 69 | if (selectPosition < 0) { 70 | return false; 71 | } 72 | BaseBean currentSelected = mData.get(selectPosition); 73 | List books = currentSelected.getBookList(); 74 | return books.size() < 2; 75 | } 76 | 77 | /** 78 | * 合并数据处理 79 | * 80 | * @param selectedPosition 81 | * @param targetPosition 82 | */ 83 | @Override 84 | protected void onMerged(int selectedPosition, int targetPosition) { 85 | List tarBookBeans = mData.get(targetPosition).getBookList(); 86 | BookBean bookBean = mData.get(selectedPosition).getBookList().get(0); 87 | tarBookBeans.add(bookBean); 88 | mData.get(targetPosition).setBookList(tarBookBeans); 89 | mData.get(targetPosition).isGroup = true; 90 | mData.remove(selectedPosition); 91 | } 92 | 93 | 94 | /** 95 | * 能否弹出次级窗口 96 | * 97 | * @param position 主层级点击的位置 98 | * @param pressedView 点击的view 99 | * @return 100 | */ 101 | @Override 102 | protected boolean canExplodeItem(int position, View pressedView) { 103 | if (position < mData.size() && mData.get(position).getBookList().size() > 1) { 104 | return true; 105 | } 106 | if(position < mData.size()&&(mData.get(position).getBookList().size()==1)&& mData.get(position).isGroup){ 107 | return true; 108 | } 109 | return false; 110 | } 111 | 112 | /** 113 | * 返回副层级的数据源 114 | * 115 | * @param parentPosition 116 | * @return 117 | */ 118 | @NonNull 119 | @Override 120 | protected List getSubSource(int parentPosition) { 121 | return mData.get(parentPosition).getBookList(); 122 | } 123 | 124 | @Override 125 | protected void onMove(int selectedPosition, int targetPosition) { 126 | BaseBean list = mData.remove(selectedPosition); 127 | mData.add(targetPosition, list); 128 | } 129 | 130 | /** 131 | * 副层级数据移动处理 132 | * 133 | * @param bookBeen 副层级数据源 134 | * @param selectedPosition 当前选择的item位置 135 | * @param targetPosition 要移动到的位置 136 | */ 137 | @Override 138 | protected void onSubMove(List bookBeen, int selectedPosition, int targetPosition) { 139 | bookBeen.add(targetPosition, bookBeen.remove(selectedPosition)); 140 | } 141 | 142 | /** 143 | * 从副层级移除的元素 144 | * 145 | * @param bookBeen 副层级数据源 146 | * @param selectedPosition 将要冲副层级移除的数据 147 | * @return 返回的数为添加到主层级的位置 148 | */ 149 | @Override 150 | protected int onLeaveSubRegion(int parentPosition,List bookBeen, int selectedPosition) { 151 | BookBean bookBean = bookBeen.remove(selectedPosition); 152 | if(bookBeen.size() == 0){ 153 | mData.remove(parentPosition); 154 | } 155 | BaseBean baseBean = new BaseBean(); 156 | List bookBeanList = new ArrayList<>(); 157 | bookBeanList.add(bookBean); 158 | baseBean.setBookList(bookBeanList); 159 | mData.add(baseBean); 160 | return mData.size() - 1; 161 | } 162 | 163 | 164 | public static class ViewHolder extends PrimitiveSimpleAdapter.ViewHolder { 165 | 166 | public ViewHolder(View itemView) { 167 | super(itemView); 168 | } 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/normalfolder/logic/MyFolderAdapter.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.normalfolder.logic; 2 | 3 | import android.util.Log; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.Toast; 8 | 9 | import com.anarchy.classify.simple.widget.MiViewHolder; 10 | import com.anarchy.classifyview.sample.normalfolder.Constants; 11 | import com.anarchy.classifyview.sample.normalfolder.bean.BaseBean; 12 | import com.anarchy.classifyview.R; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * Created by lizhiming211223 on 2016/12/29. 18 | */ 19 | public class MyFolderAdapter extends FolderAdapter { 20 | 21 | 22 | public MyFolderAdapter(List mData) { 23 | super(mData); 24 | } 25 | 26 | 27 | @Override 28 | protected ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 29 | // super.onCreateViewHolder(parent,viewType); 30 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample_vertical, parent, false); 31 | return new MyFolderAdapter.ViewHolder(view); 32 | } 33 | @Override 34 | public View getView(ViewGroup parent, View convertView, int mainPosition, int subPosition) { 35 | Log.i(Constants.CLASSIFY_VIEW_INIT,"CLASSIFY_VIEW_INIT"); 36 | BaseBean baseBean=mData.get(mainPosition); 37 | MiViewHolder michaelViewHolder; 38 | if (convertView == null) { 39 | michaelViewHolder = new MiViewHolder(); 40 | convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_inner, parent, false); 41 | if(baseBean.getBookList().size()==1&&!baseBean.isGroup){ 42 | michaelViewHolder.childTag=0; 43 | }else{ 44 | michaelViewHolder.childTag=1;//绘制 Folder 45 | } 46 | convertView.setTag(michaelViewHolder); 47 | }else { 48 | michaelViewHolder = (MiViewHolder) convertView.getTag(); 49 | } 50 | return convertView; 51 | } 52 | 53 | @Override 54 | protected void onItemClick(View view, int parentIndex, int index) { 55 | Toast.makeText(view.getContext(), "parentIndex: " + parentIndex + "\nindex: " + index, Toast.LENGTH_SHORT).show(); 56 | } 57 | 58 | static class ViewHolder extends FolderAdapter.ViewHolder { 59 | 60 | public ViewHolder(View itemView) { 61 | super(itemView); 62 | } 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/sample/viewpager/ViewPagerFragment.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.sample.viewpager; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.app.FragmentManager; 8 | import android.support.v4.app.FragmentStatePagerAdapter; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | import com.anarchy.classifyview.R; 14 | import com.anarchy.classifyview.core.BaseFragment; 15 | import com.anarchy.classifyview.databinding.FragmentViewpagerBinding; 16 | import com.anarchy.classifyview.sample.normal.NormalFragment; 17 | 18 | /** 19 | *

20 | * Date: 16/8/11 15:38 21 | * Author: rsshinide38@163.com 22 | *

23 | */ 24 | public class ViewPagerFragment extends BaseFragment{ 25 | @Nullable 26 | @Override 27 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 28 | FragmentViewpagerBinding binding = DataBindingUtil.inflate(inflater,R.layout.fragment_viewpager,container,false); 29 | binding.viewPager.setAdapter(new ViewPagerAdapter(getChildFragmentManager())); 30 | return binding.getRoot(); 31 | } 32 | 33 | static class ViewPagerAdapter extends FragmentStatePagerAdapter{ 34 | 35 | public ViewPagerAdapter(FragmentManager fm) { 36 | super(fm); 37 | } 38 | 39 | @Override 40 | public Fragment getItem(int position) { 41 | return new NormalFragment(); 42 | } 43 | 44 | @Override 45 | public int getCount() { 46 | return 2; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/anarchy/classifyview/utils/DataGenerate.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview.utils; 2 | 3 | import com.anarchy.classifyview.sample.normalfolder.bean.BaseBean; 4 | import com.anarchy.classifyview.sample.normalfolder.bean.BookBean; 5 | import com.anarchy.classifyview.core.Bean; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * User: Anarchy 12 | * Email: rsshinide38@163.com 13 | * CreateTime: 十二月/25/2016 11:57. 14 | * Description: 15 | */ 16 | 17 | public class DataGenerate { 18 | public static List> generateBean(){ 19 | List> data = new ArrayList<>(); 20 | for(int i=0;i<30;i++){ 21 | List inner = new ArrayList<>(); 22 | if(i>10) { 23 | int c = (int) (Math.random() * 15+1); 24 | for(int j=0;j generateBaseBean(){ 35 | List data = new ArrayList<>(); 36 | for(int i=0;i<6;i++){ 37 | BaseBean baseBean=new BaseBean(); 38 | List inner = new ArrayList<>(); 39 | inner.add(new BookBean()); 40 | 41 | baseBean.setBookList(inner); 42 | data.add(baseBean); 43 | } 44 | return data; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_down.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_up.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/color-v21/selector_color_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlphaBoom/ClassifyView/095ca71b63fd763f6c44fa979291b2c98e9409bd/app/src/main/res/drawable-xxhdpi/ic_checked.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_number_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlphaBoom/ClassifyView/095ca71b63fd763f6c44fa979291b2c98e9409bd/app/src/main/res/drawable-xxhdpi/ic_number_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlphaBoom/ClassifyView/095ca71b63fd763f6c44fa979291b2c98e9409bd/app/src/main/res/drawable-xxhdpi/ic_unchecked.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_circle_red.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_i_reader_category_edit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_add_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_delete.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_detail.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_move.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_order.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_share.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/round_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/demonstrate_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 14 | 15 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/extra_ireader_bottom_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 17 | 18 | 25 | 26 | 34 | 35 | 48 | 49 | 60 | 61 | 62 | 68 | 69 | 77 | 78 | 89 | 90 | 91 | 97 | 98 | 106 | 107 | 118 | 119 | 120 | 126 | 127 | 135 | 136 | 147 | 148 | 149 | 155 | 156 | 164 | 165 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /app/src/main/res/layout/extra_ireader_sub_content.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 16 | 25 | 38 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_layoutmanager.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 10 | 11 | 12 | 17 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_mock_ireader.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 17 | 23 | 24 | 25 | 35 | 41 | 42 | 43 | 60 | 68 | 69 | 72 | 73 | 84 | 85 | 93 | 94 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_viewpager.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_book.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_book_inner.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_i_reader_folder.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 16 | 17 | 23 | 32 | 33 | 34 | 35 | 39 | 40 | 41 | 42 | 54 | 55 | 56 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_inner.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_sample_horizontal.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_sample_vertical.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_select_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 12 | 21 | 33 | -------------------------------------------------------------------------------- /app/src/main/res/layout/normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/select_book.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 9 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/stub_classify_hh.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/stub_classify_hv.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_i_reader.xml: -------------------------------------------------------------------------------- 1 | 2 |

4 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_layout_manager_type.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 11 | 14 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlphaBoom/ClassifyView/095ca71b63fd763f6c44fa979291b2c98e9409bd/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlphaBoom/ClassifyView/095ca71b63fd763f6c44fa979291b2c98e9409bd/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlphaBoom/ClassifyView/095ca71b63fd763f6c44fa979291b2c98e9409bd/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlphaBoom/ClassifyView/095ca71b63fd763f6c44fa979291b2c98e9409bd/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlphaBoom/ClassifyView/095ca71b63fd763f6c44fa979291b2c98e9409bd/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #303030 7 | #bbbbbb 8 | #e53935 9 | #303030 10 | #e76813 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ClassifyView 3 | 模拟掌阅书架 4 | 完成 5 | 最近阅读 6 | 全选 7 | 删除 8 | 移动至 9 | 分享 10 | 加入书单 11 | 详情 12 | 分类名称最多显示10个字符 13 | 14 | 基本效果 15 | 使用演示 16 | 配合ViewPager使用(Test) 17 | 使用其他类型的LayoutManager 18 | 文件夹效果 19 | 模仿IRead的书架效果 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/test/java/com/anarchy/classifyview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classifyview; 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 | } -------------------------------------------------------------------------------- /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 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.4.1' 10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | google() 19 | jcenter() 20 | maven { url "https://jitpack.io" } 21 | } 22 | } 23 | 24 | task clean(type: Delete) { 25 | delete rootProject.buildDir 26 | } 27 | -------------------------------------------------------------------------------- /classify/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /classify/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.AlphaBoom' 5 | android { 6 | compileSdkVersion 27 7 | buildToolsVersion '28.0.3' 8 | 9 | defaultConfig { 10 | minSdkVersion 15 11 | targetSdkVersion 27 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | // build a jar with source files 23 | task sourcesJar(type: Jar) { 24 | from android.sourceSets.main.java.srcDirs 25 | classifier = 'sources' 26 | } 27 | 28 | task javadoc(type: Javadoc) { 29 | failOnError false 30 | source = android.sourceSets.main.java.sourceFiles 31 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 32 | classpath += configurations.compile 33 | } 34 | 35 | javadoc { 36 | options { 37 | encoding "UTF-8" 38 | charSet 'UTF-8' 39 | author true 40 | version true 41 | links "http://docs.oracle.com/javase/7/docs/api" 42 | } 43 | } 44 | 45 | // build a jar with javadoc 46 | task javadocJar(type: Jar, dependsOn: javadoc) { 47 | classifier = 'javadoc' 48 | from javadoc.destinationDir 49 | } 50 | 51 | artifacts { 52 | archives sourcesJar 53 | archives javadocJar 54 | } 55 | dependencies { 56 | implementation fileTree(include: ['*.jar'], dir: 'libs') 57 | testImplementation 'junit:junit:4.12' 58 | implementation 'com.android.support:recyclerview-v7:27.1.1' 59 | } 60 | -------------------------------------------------------------------------------- /classify/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/anarchy/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /classify/src/androidTest/java/com/anarchy/classify/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify; 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 | } -------------------------------------------------------------------------------- /classify/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/ClassifyDragShadowBuilder.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Color; 5 | import android.graphics.Point; 6 | import android.graphics.PorterDuff; 7 | import android.view.View; 8 | 9 | import java.lang.ref.WeakReference; 10 | 11 | /** 12 | *只是为了获取drag的触发事件 不绘制拖动的view 13 | */ 14 | public class ClassifyDragShadowBuilder extends View.DragShadowBuilder { 15 | private final WeakReference mView; 16 | public ClassifyDragShadowBuilder(){ 17 | mView = new WeakReference<>(null); 18 | } 19 | public ClassifyDragShadowBuilder(View view){ 20 | mView = new WeakReference<>(view); 21 | } 22 | 23 | @Override 24 | public void onDrawShadow(Canvas canvas) { 25 | //nothing 26 | } 27 | 28 | @Override 29 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { 30 | final View view = mView.get(); 31 | if (view != null) { 32 | shadowSize.set(view.getWidth(), view.getHeight()); 33 | shadowTouchPoint.set(shadowSize.x/2, shadowSize.y/2); 34 | } 35 | } 36 | 37 | public void showShadow(){ 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/DragDrawable.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.Canvas; 5 | import android.graphics.ColorFilter; 6 | import android.graphics.Paint; 7 | import android.graphics.PixelFormat; 8 | import android.graphics.RadialGradient; 9 | import android.graphics.Rect; 10 | import android.graphics.Shader; 11 | import android.graphics.drawable.Drawable; 12 | import android.support.annotation.NonNull; 13 | import android.view.View; 14 | 15 | import java.lang.ref.WeakReference; 16 | 17 | /** 18 | *

19 | * Date: 16/6/2 15:41 20 | * Author: rsshinide38@163.com 21 | * Description:用于绘制拖动的View 在拖动状况下显示的效果 22 | * 默认绘制整个拖动的Item 23 | *

24 | */ 25 | public class DragDrawable extends Drawable { 26 | private static final int KEY_SHADOW_COLOR = 0x1E000000; 27 | private static final int FILL_SHADOW_COLOR = 0x3D000000; 28 | private static final float Y_OFFSET = 1.75f; 29 | final private static float SHADOW_RADIUS = 3.5f; 30 | final private View mView; 31 | private Bitmap mBitmap; 32 | final private Paint mPaint; 33 | private boolean showShadow; 34 | private int shadowOffset; 35 | private Rect mShadowRect; 36 | 37 | public DragDrawable(@NonNull View view) { 38 | this(view, false); 39 | } 40 | 41 | public DragDrawable(@NonNull View view, boolean showShadow) { 42 | mShadowRect = new Rect(); 43 | this.showShadow = showShadow; 44 | float density = view.getContext().getResources().getDisplayMetrics().density; 45 | this.shadowOffset = (int) (density * SHADOW_RADIUS); 46 | mView = view; 47 | mView.setDrawingCacheEnabled(true); 48 | mView.destroyDrawingCache(); 49 | mView.buildDrawingCache(); 50 | mBitmap = Bitmap.createBitmap(mView.getDrawingCache()); 51 | mPaint = new Paint(); 52 | int radius = (getIntrinsicHeight() + getIntrinsicWidth()) / 2; 53 | mPaint.setShader(new RadialGradient(getIntrinsicWidth() / 2, getIntrinsicHeight() / 2, radius, new int[]{FILL_SHADOW_COLOR, 0}, null, Shader.TileMode.CLAMP)); 54 | } 55 | 56 | 57 | @Override 58 | public void draw(Canvas canvas) { 59 | if (mBitmap == null || mBitmap.isRecycled()) { 60 | mView.setDrawingCacheEnabled(true); 61 | mView.destroyDrawingCache(); 62 | mView.buildDrawingCache(); 63 | mBitmap = Bitmap.createBitmap(mView.getDrawingCache()); 64 | if(mBitmap == null || mBitmap.isRecycled()) { 65 | mView.draw(canvas); 66 | } 67 | } else { 68 | if (showShadow) { 69 | // mShadowRect.set(shadowOffset,shadowOffset,getIntrinsicWidth(),getIntrinsicHeight()); 70 | // canvas.drawRect(mShadowRect,mPaint); 71 | canvas.drawBitmap(mBitmap, 0, 0, null); 72 | } else { 73 | canvas.drawBitmap(mBitmap, 0, 0, null); 74 | } 75 | } 76 | } 77 | 78 | @Override 79 | public void setAlpha(int alpha) { 80 | //nothing 81 | } 82 | 83 | @Override 84 | public void setColorFilter(ColorFilter colorFilter) {//nothing 85 | } 86 | 87 | @Override 88 | public int getOpacity() { 89 | return PixelFormat.TRANSLUCENT; 90 | } 91 | 92 | @Override 93 | public int getIntrinsicWidth() { 94 | return showShadow ? mView.getWidth() + shadowOffset : mView.getWidth(); 95 | } 96 | 97 | @Override 98 | public int getIntrinsicHeight() { 99 | return showShadow ? mView.getHeight() + shadowOffset : mView.getHeight(); 100 | } 101 | 102 | 103 | public Paint getPaint() { 104 | return mPaint; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/MergeInfo.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify; 2 | 3 | /** 4 | *

5 | * Date: 16/6/22 09:44 6 | * Author: rsshinide38@163.com 7 | * 8 | * 执行合并动画所需要的属性 9 | * targetX 及 targetY 为相对于ClassifyView 的 x轴与y轴坐标 10 | *

11 | */ 12 | public class MergeInfo { 13 | public float scaleX; 14 | public float scaleY; 15 | public float targetX; 16 | public float targetY; 17 | 18 | public MergeInfo(float scaleX, float scaleY, float targetX, float targetY) { 19 | this.scaleX = scaleX; 20 | this.scaleY = scaleY; 21 | this.targetX = targetX; 22 | this.targetY = targetY; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/adapter/BaseMainAdapter.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.VelocityTracker; 6 | import android.view.View; 7 | 8 | import com.anarchy.classify.MergeInfo; 9 | import com.anarchy.classify.ClassifyView; 10 | import com.anarchy.classify.callback.MainRecyclerViewCallBack; 11 | import com.anarchy.classify.callback.SubRecyclerViewCallBack; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | *

18 | * Date: 16/6/1 15:33 19 | * Author: rsshinide38@163.com 20 | *

21 | */ 22 | public abstract class BaseMainAdapter extends RecyclerView.Adapter implements MainRecyclerViewCallBack { 23 | private final static int VELOCITY = 1; 24 | private int mSelectedPosition = SELECT_UNKNOWN; 25 | private List mDummySource = new ArrayList(); 26 | 27 | @Override 28 | public void setDragPosition(int position,boolean shouldNotify) { 29 | if (position >= getItemCount() || position < -1) return; 30 | if (position == -1 && mSelectedPosition != -1) { 31 | int oldPosition = mSelectedPosition; 32 | mSelectedPosition = position; 33 | if(shouldNotify) notifyItemChanged(oldPosition); 34 | } else { 35 | mSelectedPosition = position; 36 | if(shouldNotify) notifyItemChanged(mSelectedPosition); 37 | } 38 | } 39 | 40 | 41 | @Override 42 | public int getDragPosition() { 43 | return mSelectedPosition; 44 | } 45 | 46 | @SuppressWarnings("unchecked") 47 | @Override 48 | public void onDragStart(RecyclerView recyclerView, int position) { 49 | VH selectedViewHolder = (VH) recyclerView.findViewHolderForAdapterPosition(position); 50 | if(selectedViewHolder == null) return; 51 | onDragStart(selectedViewHolder,position); 52 | } 53 | 54 | @SuppressWarnings("unchecked") 55 | @Override 56 | public void onDragAnimationEnd(RecyclerView recyclerView, int position) { 57 | VH selectedViewHolder = (VH) recyclerView.findViewHolderForAdapterPosition(position); 58 | if(selectedViewHolder == null) return; 59 | onDragAnimationEnd(selectedViewHolder,position); 60 | } 61 | 62 | @SuppressWarnings("unchecked") 63 | @Override 64 | public boolean onMergeStart(RecyclerView parent, int selectedPosition, int targetPosition) { 65 | VH selectedViewHolder = (VH) parent.findViewHolderForAdapterPosition(selectedPosition); 66 | VH targetViewHolder = (VH) parent.findViewHolderForAdapterPosition(targetPosition); 67 | if(selectedViewHolder == null || targetViewHolder == null) return false; 68 | return onMergeStart(selectedViewHolder, targetViewHolder, selectedPosition, targetPosition); 69 | } 70 | @SuppressWarnings("unchecked") 71 | @Override 72 | public void onMergeCancel(RecyclerView parent, int selectedPosition, int targetPosition) { 73 | VH selectedViewHolder = (VH) parent.findViewHolderForAdapterPosition(selectedPosition); 74 | VH targetViewHolder = (VH) parent.findViewHolderForAdapterPosition(targetPosition); 75 | if(selectedViewHolder == null || targetViewHolder == null) return; 76 | onMergeCancel(selectedViewHolder, targetViewHolder, selectedPosition, targetPosition); 77 | } 78 | @SuppressWarnings("unchecked") 79 | @Override 80 | public void onMerged(RecyclerView parent, int selectedPosition, int targetPosition) { 81 | VH selectedViewHolder = (VH) parent.findViewHolderForAdapterPosition(selectedPosition); 82 | VH targetViewHolder = (VH) parent.findViewHolderForAdapterPosition(targetPosition); 83 | if(selectedViewHolder == null || targetViewHolder == null) return; 84 | onMerged(selectedViewHolder, targetViewHolder, selectedPosition, targetPosition); 85 | } 86 | @SuppressWarnings("unchecked") 87 | @Override 88 | public MergeInfo onPrepareMerge(RecyclerView parent, int selectedPosition, int targetPosition) { 89 | VH selectedViewHolder = (VH) parent.findViewHolderForAdapterPosition(selectedPosition); 90 | VH targetViewHolder = (VH) parent.findViewHolderForAdapterPosition(targetPosition); 91 | if(selectedViewHolder == null || targetViewHolder == null) return null; 92 | return onPrePareMerge(selectedViewHolder, targetViewHolder, selectedPosition, targetPosition); 93 | } 94 | @SuppressWarnings("unchecked") 95 | @Override 96 | public void onStartMergeAnimation(RecyclerView parent, int selectedPosition, int targetPosition,int duration) { 97 | VH selectedViewHolder = (VH) parent.findViewHolderForAdapterPosition(selectedPosition); 98 | VH targetViewHolder = (VH) parent.findViewHolderForAdapterPosition(targetPosition); 99 | if(selectedViewHolder == null || targetViewHolder == null) return; 100 | onStartMergeAnimation(selectedViewHolder, targetViewHolder, selectedPosition, targetPosition,duration); 101 | } 102 | 103 | public void onDragStart(VH selectedViewHolder,int selectedPosition){ 104 | 105 | } 106 | 107 | public void onDragAnimationEnd(VH selectedViewHolder,int selectedPosition){ 108 | 109 | } 110 | 111 | public abstract boolean onMergeStart(VH selectedViewHolder, VH targetViewHolder, int selectedPosition, int targetPosition); 112 | 113 | public abstract void onMergeCancel(VH selectedViewHolder, VH targetViewHolder, int selectedPosition, int targetPosition); 114 | 115 | public abstract void onMerged(VH selectedViewHolder, VH targetViewHolder, int selectedPosition, int targetPosition); 116 | 117 | public abstract MergeInfo onPrePareMerge(VH selectedViewHolder, VH targetViewHolder, int selectedPosition, int targetPosition); 118 | 119 | public abstract void onStartMergeAnimation(VH selectedViewHolder, VH targetViewHolder, int selectedPosition, int targetPosition,int duration); 120 | 121 | @Override 122 | public void onBindViewHolder(VH holder, int position, List payloads) { 123 | if (position == mSelectedPosition) { 124 | holder.itemView.setVisibility(View.INVISIBLE); 125 | } else { 126 | holder.itemView.setVisibility(View.VISIBLE); 127 | } 128 | super.onBindViewHolder(holder, position, payloads); 129 | } 130 | 131 | @Override 132 | public boolean canDropOver(int selectedPosition, int targetPosition) { 133 | return true; 134 | } 135 | 136 | @Override 137 | public int getCurrentState(View selectedView, View targetView, int x, int y, 138 | VelocityTracker velocityTracker, int selectedPosition, 139 | int targetPosition) { 140 | if (velocityTracker == null) return ClassifyView.MOVE_STATE_NONE; 141 | int left = x; 142 | int top = y; 143 | int right = left + selectedView.getWidth(); 144 | int bottom = top + selectedView.getHeight(); 145 | if (canMergeItem(selectedPosition, targetPosition)) { 146 | if ((Math.abs(left - targetView.getLeft()) + Math.abs(right - targetView.getRight()) + 147 | Math.abs(top - targetView.getTop()) + Math.abs(bottom - targetView.getBottom())) 148 | < (targetView.getWidth() + targetView.getHeight() 149 | ) / 3) { 150 | return ClassifyView.MOVE_STATE_MERGE; 151 | } 152 | } 153 | if ((Math.abs(left - targetView.getLeft()) + Math.abs(right - targetView.getRight()) + 154 | Math.abs(top - targetView.getTop()) + Math.abs(bottom - targetView.getBottom())) 155 | < (targetView.getWidth() + targetView.getHeight() 156 | ) / 2) { 157 | velocityTracker.computeCurrentVelocity(100); 158 | float xVelocity = velocityTracker.getXVelocity(); 159 | float yVelocity = velocityTracker.getYVelocity(); 160 | float limit = getVelocity(targetView.getContext()); 161 | if (xVelocity < limit && yVelocity < limit) { 162 | return ClassifyView.MOVE_STATE_MOVE; 163 | } 164 | } 165 | return ClassifyView.MOVE_STATE_NONE; 166 | } 167 | 168 | @Override 169 | public boolean canExplodeItem(int position, View pressedView) { 170 | return false; 171 | } 172 | 173 | @Override 174 | public List explodeItem(int position, View pressedView) { 175 | return canExplodeItem(position,pressedView)? mDummySource :null; 176 | } 177 | 178 | @Override 179 | public float getVelocity(Context context) { 180 | float density = context.getResources().getDisplayMetrics().density; 181 | return density * VELOCITY + .5f; 182 | } 183 | 184 | @Override 185 | public void moved(int selectedPosition, int targetPosition) { 186 | 187 | } 188 | 189 | @Override 190 | public void onItemClick(RecyclerView recyclerView, int position, View pressedView) { 191 | onItemClick(position,pressedView); 192 | } 193 | 194 | @Override 195 | public void onItemClick(int position, View pressedView) { 196 | 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/adapter/BaseSubAdapter.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.adapter; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.VelocityTracker; 7 | import android.view.View; 8 | 9 | 10 | import com.anarchy.classify.ClassifyView; 11 | import com.anarchy.classify.callback.SubRecyclerViewCallBack; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Version 1.0 17 | *

18 | * Date: 16/6/1 15:34 19 | * Author: rsshinide38@163.com 20 | *

21 | */ 22 | public abstract class BaseSubAdapter extends RecyclerView.Adapter implements SubRecyclerViewCallBack { 23 | private final static int VELOCITY = 1; 24 | @Override 25 | public boolean canDragOnLongPress(int position, View pressedView) { 26 | return true; 27 | } 28 | 29 | private int mSelectedPosition = SELECT_UNKNOWN; 30 | 31 | @Override 32 | public void setDragPosition(int position,boolean shouldNotify) { 33 | if(position >= getItemCount()||position<-1) return; 34 | if(position == -1 && mSelectedPosition != -1){ 35 | // int oldPosition = mSelectedPosition; 36 | mSelectedPosition = position; 37 | if(shouldNotify) notifyDataSetChanged(); 38 | // notifyItemChanged(oldPosition); 39 | }else { 40 | mSelectedPosition = position; 41 | if(shouldNotify) notifyItemChanged(mSelectedPosition); 42 | } 43 | } 44 | 45 | @Override 46 | public void initData(int parentIndex, List data) { 47 | prepareExplodeItem(parentIndex); 48 | } 49 | 50 | @Override 51 | public void prepareExplodeItem(int parentPosition) { 52 | 53 | } 54 | 55 | @Override 56 | public void onDialogShow(Dialog subDialog, int parentPosition) { 57 | 58 | } 59 | 60 | @Override 61 | public void onDialogCancel(Dialog subDialog, int parentPosition) { 62 | 63 | } 64 | 65 | @SuppressWarnings("unchecked") 66 | @Override 67 | public void onDragStart(RecyclerView recyclerView, int position) { 68 | VH selectedViewHolder = (VH) recyclerView.findViewHolderForAdapterPosition(position); 69 | if(selectedViewHolder == null) return; 70 | onDragStart(selectedViewHolder,position); 71 | } 72 | 73 | @SuppressWarnings("unchecked") 74 | @Override 75 | public void onDragAnimationEnd(RecyclerView recyclerView, int position) { 76 | VH selectedViewHolder = (VH) recyclerView.findViewHolderForAdapterPosition(position); 77 | if(selectedViewHolder == null) return; 78 | onDragAnimationEnd(selectedViewHolder,position); 79 | } 80 | 81 | 82 | public void onDragStart(VH selectedViewHolder,int selectedPosition){ 83 | 84 | } 85 | 86 | public void onDragAnimationEnd(VH selectedViewHolder,int selectedPosition){ 87 | 88 | } 89 | 90 | @Override 91 | public int getDragPosition() { 92 | return mSelectedPosition; 93 | } 94 | 95 | @Override 96 | public void onBindViewHolder(VH holder, int position, List payloads) { 97 | if(position == mSelectedPosition){ 98 | holder.itemView.setVisibility(View.INVISIBLE); 99 | }else { 100 | holder.itemView.setVisibility(View.VISIBLE); 101 | } 102 | super.onBindViewHolder(holder, position, payloads); 103 | } 104 | 105 | @Override 106 | public boolean canDropOver(int selectedPosition, int targetPosition) { 107 | return true; 108 | } 109 | 110 | @Override 111 | public boolean canDragOut(int selectedPosition) { 112 | return true; 113 | } 114 | 115 | @Override 116 | public void moved(int selectedPosition, int targetPosition) { 117 | 118 | } 119 | @Override 120 | public int getCurrentState(View selectedView, View targetView, int x, int y, 121 | VelocityTracker velocityTracker, int selectedPosition, 122 | int targetPosition) { 123 | if(velocityTracker == null) return ClassifyView.MOVE_STATE_NONE; 124 | int left = x; 125 | int top = y; 126 | int right = left + selectedView.getWidth(); 127 | int bottom = top + selectedView.getHeight(); 128 | if((Math.abs(left - targetView.getLeft())+Math.abs(right - targetView.getRight())+ 129 | Math.abs(top - targetView.getTop())+ Math.abs(bottom - targetView.getBottom())) 130 | <(targetView.getWidth()+targetView.getHeight() 131 | )/2){ 132 | velocityTracker.computeCurrentVelocity(100); 133 | float xVelocity = velocityTracker.getXVelocity(); 134 | float yVelocity = velocityTracker.getYVelocity(); 135 | float limit = getVelocity(targetView.getContext()); 136 | if(xVelocity < limit && yVelocity < limit){ 137 | return ClassifyView.MOVE_STATE_MOVE; 138 | } 139 | } 140 | return ClassifyView.MOVE_STATE_NONE; 141 | } 142 | 143 | @Override 144 | public float getVelocity(Context context) { 145 | float density = context.getResources().getDisplayMetrics().density; 146 | return density*VELOCITY + .5f; 147 | } 148 | 149 | @Override 150 | public void onItemClick(RecyclerView recyclerView, int position, View pressedView) { 151 | onItemClick(position,pressedView); 152 | } 153 | 154 | @Override 155 | public void onItemClick(int position, View pressedView) { 156 | 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/callback/BaseCallBack.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.callback; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.VelocityTracker; 6 | import android.view.View; 7 | 8 | import com.anarchy.classify.ClassifyView; 9 | 10 | /** 11 | * Version 1.0 12 | *

13 | * Date: 16/6/14 17:12 14 | * Author: rsshinide38@163.com 15 | *

16 | */ 17 | public interface BaseCallBack { 18 | int SELECT_UNKNOWN = -1; 19 | /** 20 | * 设置当前拖动的位置位于Adapter 21 | * @see #getDragPosition() 22 | * @param position 拖动的位置 23 | * @param shouldNotify 是否通知更新界面 24 | */ 25 | void setDragPosition(int position,boolean shouldNotify); 26 | 27 | /** 28 | * 获取当前拖动的位置位于Adapter 29 | * @see #setDragPosition(int, boolean) 30 | * @return 当前拖动的位置 如果是-1 则当前没用拖动的View 31 | */ 32 | int getDragPosition(); 33 | 34 | /** 35 | * 36 | * @param position 37 | * @param pressedView 38 | * @return true 长按可拖动 false 不可拖动 39 | */ 40 | boolean canDragOnLongPress(int position, View pressedView); 41 | boolean canDropOver(int selectedPosition,int targetPosition); 42 | 43 | /** 44 | * 拖拽发生时的回调 45 | * @param recyclerView 46 | * @param position 47 | */ 48 | void onDragStart(RecyclerView recyclerView,int position); 49 | 50 | /** 51 | * 拖拽动画执行结束的回调 52 | * @param recyclerView 53 | * @param position 54 | */ 55 | void onDragAnimationEnd(RecyclerView recyclerView,int position); 56 | 57 | /** 58 | * 返回判断移动需要的速度范围 59 | * 单位默认100 如果你没有重写 {@link #getCurrentState(View, View, int, int, VelocityTracker, int, int)}这个方法 60 | * @param context 61 | * @return 62 | */ 63 | float getVelocity(Context context); 64 | /** 65 | * 返回当前的状态 是移动 还是在merge范围中 66 | * @param selectedView 67 | * @param targetView 68 | * @param x 69 | * @param y 70 | * @return 71 | */ 72 | @ClassifyView.MoveState 73 | int getCurrentState(View selectedView, View targetView, int x, int y, VelocityTracker velocityTracker, int selectedPosition, int targetPosition); 74 | 75 | /** 76 | * item点击事件 77 | * @param recyclerView 78 | * @param position 79 | * @param pressedView 80 | */ 81 | void onItemClick(RecyclerView recyclerView,int position,View pressedView); 82 | /** 83 | * item 点击事件 84 | * @param position 85 | * @param pressedView 86 | * @deprecated {@link #onItemClick(RecyclerView, int, View)} 87 | */ 88 | void onItemClick(int position,View pressedView); 89 | 90 | } 91 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/callback/MainRecyclerViewCallBack.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.callback; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.View; 5 | 6 | import com.anarchy.classify.MergeInfo; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Version 1.0 12 | *

13 | * Date: 16/6/1 15:10 14 | * Author: rsshinide38@163.com 15 | *

16 | */ 17 | public interface MainRecyclerViewCallBack extends BaseCallBack{ 18 | /** 19 | * 进入准备合并状态 20 | * @param parent 21 | * @param selectedPosition 22 | * @param targetPosition 23 | * @return 24 | */ 25 | boolean onMergeStart(RecyclerView parent,int selectedPosition, int targetPosition); 26 | 27 | /** 28 | * 合并结束 29 | * @param parent 30 | * @param selectedPosition 31 | * @param targetPosition 32 | */ 33 | void onMerged(RecyclerView parent, int selectedPosition, int targetPosition); 34 | 35 | /** 36 | * 准备执行合并 37 | * @param parent 38 | * @param selectedPosition 39 | * @param targetPosition 40 | * @return 返回执行合并动画所需参数 41 | */ 42 | MergeInfo onPrepareMerge(RecyclerView parent, int selectedPosition, int targetPosition); 43 | 44 | /** 45 | * 合并动画开始 46 | * @param parent 47 | * @param selectedPosition 48 | * @param targetPosition 49 | * @param duration 50 | */ 51 | void onStartMergeAnimation(RecyclerView parent,int selectedPosition,int targetPosition,int duration); 52 | 53 | /** 54 | * 离开准备合并状态 55 | * @param parent 56 | * @param selectedPosition 57 | * @param targetPosition 58 | */ 59 | void onMergeCancel(RecyclerView parent,int selectedPosition,int targetPosition); 60 | 61 | /** 62 | * 是否进行移动 可以在这里做数据改变 63 | * @param selectedPosition 64 | * @param targetPosition 65 | * @return 66 | */ 67 | boolean onMove(int selectedPosition,int targetPosition); 68 | 69 | /** 70 | * 移动完成 71 | * @param selectedPosition 72 | * @param targetPosition 73 | */ 74 | void moved(int selectedPosition,int targetPosition); 75 | 76 | /** 77 | * 78 | * @param selectedPosition 79 | * @param targetPosition 80 | * @return true 可以合并 false 81 | */ 82 | boolean canMergeItem(int selectedPosition, int targetPosition); 83 | 84 | /** 85 | * 当次级目录移出范围时的回调 86 | * @param selectedPosition 87 | * @param subAdapter 88 | * @return 添加到主目录的位置 89 | */ 90 | int onLeaveSubRegion(int selectedPosition,Sub subAdapter); 91 | 92 | /** 93 | * 是否展开当前项 94 | * @param position 95 | * @return 96 | */ 97 | boolean canExplodeItem(int position, View pressedView); 98 | /** 99 | * 是否要展开这个view 100 | * @param position 101 | * @param pressedView 102 | * @return 如果返回空 则不会展开 之后会调用 {@link #onItemClick(int, View)} 103 | * 通知这是一个点击item的事件,其他情况会根据返回的List 通知 subAdapter 进行数据更新并打开显示subview的窗口 104 | * @deprecated 使用数据无关类型的回调 {@link #canExplodeItem(int, View)} 105 | */ 106 | List explodeItem(int position, View pressedView); 107 | 108 | } 109 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/callback/SubRecyclerViewCallBack.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.callback; 2 | 3 | import android.app.Dialog; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | *

9 | * Date: 16/6/1 15:11 10 | * Author: rsshinide38@163.com 11 | *

12 | */ 13 | public interface SubRecyclerViewCallBack extends BaseCallBack{ 14 | /** 15 | * 准备展开副层级 16 | * @param parentPosition 主层级点击的位置 17 | */ 18 | void prepareExplodeItem(int parentPosition); 19 | /** 20 | * 下面进行数据初始化 和 显示 21 | * @param data 22 | * @deprecated {@link #prepareExplodeItem(int)} 23 | */ 24 | void initData(int parentIndex,List data); 25 | 26 | /** 27 | * 当副层级的Dialog显示时的回调 28 | * @param subDialog 29 | * @param parentPosition 30 | */ 31 | void onDialogShow(Dialog subDialog, int parentPosition); 32 | 33 | /** 34 | * 当副层级的Dialog显示时的回调 35 | * @param subDialog 36 | * @param parentPosition 37 | */ 38 | void onDialogCancel(Dialog subDialog, int parentPosition); 39 | 40 | boolean onMove(int selectedPosition,int targetPosition); 41 | void moved(int selectedPosition,int targetPosition); 42 | 43 | /** 44 | * 是否支持移出次级目录 45 | * @param selectedPosition 46 | * @return 47 | */ 48 | boolean canDragOut(int selectedPosition); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/simple/BaseSimpleAdapter.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.simple; 2 | 3 | import com.anarchy.classify.adapter.BaseMainAdapter; 4 | import com.anarchy.classify.adapter.BaseSubAdapter; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Version 1.0 10 | *

11 | * Date: 16/6/7 12:00 12 | * Author: rsshinide38@163.com 13 | */ 14 | public interface BaseSimpleAdapter { 15 | BaseMainAdapter getMainAdapter(); 16 | BaseSubAdapter getSubAdapter(); 17 | boolean isShareViewPool(); 18 | } 19 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/simple/ChangeInfo.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.simple; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | 5 | /** 6 | * User: Anarchy 7 | * Email: rsshinide38@163.com 8 | * CreateTime: 六月/09/2016 15:54. 9 | * Description: 10 | * 用于告知如何将当前拖拽的view移动和缩放到目标位置 11 | * @see com.anarchy.classify.simple.SimpleAdapter.SimpleMainAdapter#onPrePareMerge(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int) 12 | */ 13 | public class ChangeInfo { 14 | /** 15 | * 目标位置横坐标 相对于ItemView 16 | */ 17 | public int targetLeft; 18 | /** 19 | * 目标位置纵坐标 相对于ItemView 20 | */ 21 | public int targetTop; 22 | /** 23 | * 目标位置宽度 24 | */ 25 | public float targetWidth; 26 | /** 27 | * 目标位置高度 28 | */ 29 | public float targetHeight; 30 | /** 31 | * 源位置横坐标 相对于ItemView 32 | */ 33 | public int sourceLeft; 34 | /** 35 | * 源位置纵坐标 相对于ItemView 36 | */ 37 | public int sourceTop; 38 | /** 39 | * 源位置宽度 40 | */ 41 | public float sourceWidth; 42 | /** 43 | * 源位置高度 44 | */ 45 | public float sourceHeight; 46 | 47 | @Override 48 | public String toString() { 49 | return "ChangeInfo{" + 50 | "targetLeft=" + targetLeft + 51 | ", targetTop=" + targetTop + 52 | ", targetWidth=" + targetWidth + 53 | ", targetHeight=" + targetHeight + 54 | ", sourceLeft=" + sourceLeft + 55 | ", sourceTop=" + sourceTop + 56 | ", sourceWidth=" + sourceWidth + 57 | ", sourceHeight=" + sourceHeight + 58 | '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/simple/SimpleAdapter.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.simple; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | 7 | import com.anarchy.classify.R; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | *

14 | * Date: 16/6/7 11:55 15 | * Author: rsshinide38@163.com 16 | *

17 | */ 18 | public abstract class SimpleAdapter extends PrimitiveSimpleAdapter, VH> { 19 | 20 | protected List> mData; 21 | 22 | public SimpleAdapter(List> data) { 23 | mData = data; 24 | } 25 | 26 | @SuppressWarnings("unchecked") 27 | @Override 28 | protected VH onCreateViewHolder(ViewGroup parent, int viewType) { 29 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.simple_item, parent, false); 30 | return (VH) new ViewHolder(view); 31 | } 32 | 33 | /** 34 | * 返回主层级数量 35 | * 36 | * @return 37 | */ 38 | @Override 39 | protected int getItemCount() { 40 | if (mData == null) return 0; 41 | return mData.size(); 42 | } 43 | 44 | /** 45 | * 副层级的数量,用于主层级上的显示效果 46 | * 47 | * @return 48 | */ 49 | @Override 50 | protected int getSubItemCount(int parentPosition) { 51 | if(mData == null) return 0; 52 | return mData.get(parentPosition).size(); 53 | } 54 | 55 | 56 | @Override 57 | protected List getSubSource(int parentPosition) { 58 | return mData.get(parentPosition); 59 | } 60 | 61 | @Override 62 | protected boolean canExplodeItem(int position, View pressedView) { 63 | if (position < mData.size() && mData.get(position).size() > 1) { 64 | return true; 65 | } 66 | return false; 67 | } 68 | 69 | 70 | /** 71 | * 在主层级触发move事件 在这里进行数据改变 72 | * 73 | * @param selectedPosition 当前选择的item位置 74 | * @param targetPosition 要移动到的位置 75 | */ 76 | @Override 77 | protected void onMove(int selectedPosition, int targetPosition) { 78 | List list = mData.remove(selectedPosition); 79 | mData.add(targetPosition, list); 80 | } 81 | 82 | 83 | @Override 84 | protected void onSubMove(List ts, int selectedPosition, int targetPosition) { 85 | ts.add(targetPosition, ts.remove(selectedPosition)); 86 | } 87 | 88 | @Override 89 | protected int onLeaveSubRegion(int parentPosition,List ts, int selectedPosition) { 90 | List list = new ArrayList<>(); 91 | list.add(ts.remove(selectedPosition)); 92 | mData.add(list); 93 | return mData.size() - 1; 94 | } 95 | 96 | /** 97 | * 两个选项能否合并 98 | * 99 | * @param selectPosition 100 | * @param targetPosition 101 | * @return 102 | */ 103 | @Override 104 | protected boolean canMergeItem(int selectPosition, int targetPosition) { 105 | List currentSelected = mData.get(selectPosition); 106 | return currentSelected.size() < 2; 107 | } 108 | 109 | /** 110 | * 合并数据处理 111 | * 112 | * @param selectedPosition 113 | * @param targetPosition 114 | */ 115 | @Override 116 | protected void onMerged(int selectedPosition, int targetPosition) { 117 | mData.get(targetPosition).add(mData.get(selectedPosition).get(0)); 118 | mData.remove(selectedPosition); 119 | } 120 | 121 | 122 | /** 123 | * 主层级数据绑定 124 | * 125 | * @param holder 126 | * @param position 127 | */ 128 | @Override 129 | protected void onBindMainViewHolder(VH holder, int position) { 130 | 131 | } 132 | 133 | /** 134 | * 副层级数据绑定 135 | * 136 | * @param holder 137 | * @param mainPosition 138 | * @param subPosition 139 | */ 140 | @Override 141 | protected void onBindSubViewHolder(VH holder, int mainPosition, int subPosition) { 142 | 143 | } 144 | 145 | public static class ViewHolder extends PrimitiveSimpleAdapter.ViewHolder { 146 | 147 | public ViewHolder(View itemView) { 148 | super(itemView); 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/simple/widget/BagDrawable.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.simple.widget; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.ObjectAnimator; 6 | import android.graphics.Canvas; 7 | import android.graphics.ColorFilter; 8 | import android.graphics.Paint; 9 | import android.graphics.PixelFormat; 10 | import android.graphics.RadialGradient; 11 | import android.graphics.RectF; 12 | import android.graphics.Shader; 13 | import android.graphics.drawable.Drawable; 14 | import android.util.Property; 15 | 16 | 17 | /** 18 | *

19 | * Date: 16/6/7 10:32 20 | * Author: rsshinide38@163.com 21 | *

22 | */ 23 | class BagDrawable extends Drawable { 24 | private RectF mRectF; 25 | private Paint mPaint; 26 | private Paint mOutlinePaint; 27 | private boolean keepShow = false; 28 | private boolean inMerge = false; 29 | private int mOutLineWidth; 30 | private int mOutLineColor; 31 | private int mOutlinePadding; 32 | private int mSavedOutlinePadding; 33 | private float mRadius = 5; 34 | private int mAnimationDuration = 200; 35 | private ObjectAnimator mStarAnimator; 36 | private ObjectAnimator mCancelAnimator; 37 | // private int[] mColors = new int[]{0xFF808080,0xFF808080,0xFFDDDDDD,0xFFFFFFFF,0xFFDDDDDD,0xFF808080,0xFF808080, 38 | // 0xFFDDDDDD,0xFFFFFFFF,0xFFDDDDDD,0xFF808080,0xFF808080}; 39 | // private float[] mPositions = new float[]{0f,0.11f,0.11f,0.125f,0.14f,0.14f,0.61f,0.61f,0.625f,0.64f,0.64f,1f}; 40 | private int mCenterColor = 0xFFFFFFFF; 41 | private int mEdgeColor = 0xFF808080; 42 | 43 | public BagDrawable(int outlinePadding) { 44 | mRectF = new RectF(); 45 | mPaint = new Paint(); 46 | mPaint.setAntiAlias(true); 47 | mOutlinePaint = new Paint(); 48 | mOutlinePaint.setAntiAlias(true); 49 | mOutlinePaint.setStyle(Paint.Style.STROKE); 50 | mOutlinePaint.setStrokeCap(Paint.Cap.ROUND); 51 | mOutlinePadding = outlinePadding; 52 | mSavedOutlinePadding = outlinePadding; 53 | mRadius = outlinePadding; 54 | } 55 | 56 | public void setKeepShow(boolean keepShow) { 57 | this.keepShow = keepShow; 58 | } 59 | 60 | public void setOutlineStyle(int color, int width) { 61 | mOutLineColor = color; 62 | mOutLineWidth = width; 63 | } 64 | 65 | @Override 66 | public void draw(Canvas canvas) { 67 | if (keepShow||inMerge) { 68 | canvas.save(); 69 | canvas.clipRect(getBounds()); 70 | mRectF.set(getBounds()); 71 | 72 | mRectF.inset(mOutlinePadding, mOutlinePadding); 73 | if (mOutLineWidth > 0) { 74 | mOutlinePaint.setStrokeWidth(mOutLineWidth); 75 | mRectF.inset(mOutLineWidth, mOutLineWidth); 76 | mOutlinePaint.setColor(mOutLineColor); 77 | canvas.drawRoundRect(mRectF, mRadius, mRadius, mOutlinePaint); 78 | } 79 | // mPaint.setShader(new SweepGradient(mRectF.centerX(),mRectF.centerY(),mColors,mPositions)); 80 | mPaint.setShader(new RadialGradient(mRectF.centerX(), mRectF.centerY(), mRectF.width(), mCenterColor, mEdgeColor, Shader.TileMode.CLAMP)); 81 | canvas.drawRoundRect(mRectF, mRadius, mRadius, mPaint); 82 | canvas.restore(); 83 | } 84 | } 85 | 86 | @Override 87 | public void setAlpha(int alpha) { 88 | mPaint.setAlpha(alpha); 89 | invalidateSelf(); 90 | } 91 | 92 | @Override 93 | public void setColorFilter(ColorFilter colorFilter) { 94 | mPaint.setColorFilter(colorFilter); 95 | invalidateSelf(); 96 | } 97 | 98 | @Override 99 | public int getOpacity() { 100 | return PixelFormat.TRANSLUCENT; 101 | } 102 | 103 | public void startMergeAnimation() { 104 | if(mCancelAnimator != null&&mCancelAnimator.isRunning()){ 105 | mCancelAnimator.cancel(); 106 | } 107 | if(mStarAnimator == null) { 108 | mStarAnimator = ObjectAnimator.ofInt(this, mOutlineProperty, 0); 109 | mStarAnimator.setDuration(mAnimationDuration); 110 | mStarAnimator.addListener(new AnimatorListenerAdapter() { 111 | @Override 112 | public void onAnimationStart(Animator animation) { 113 | inMerge = true; 114 | } 115 | }); 116 | }else if(mStarAnimator.isRunning()){ 117 | mStarAnimator.cancel(); 118 | } 119 | mStarAnimator.start(); 120 | } 121 | public void cancelMergeAnimation(){ 122 | if(mStarAnimator != null && mStarAnimator.isRunning()){ 123 | mStarAnimator.cancel(); 124 | } 125 | if(mCancelAnimator == null) { 126 | mCancelAnimator = ObjectAnimator.ofInt(this, mOutlineProperty, mSavedOutlinePadding); 127 | mCancelAnimator.setDuration(mAnimationDuration); 128 | mCancelAnimator.addListener(new AnimatorListenerAdapter() { 129 | @Override 130 | public void onAnimationEnd(Animator animation) { 131 | inMerge = false; 132 | } 133 | }); 134 | }else if(mCancelAnimator.isRunning()){ 135 | mCancelAnimator.cancel(); 136 | } 137 | mCancelAnimator.start(); 138 | } 139 | 140 | private Property mOutlineProperty = new Property(Integer.class,"outline") { 141 | @Override 142 | public Integer get(BagDrawable object) { 143 | return object.mOutlinePadding; 144 | } 145 | 146 | @Override 147 | public void set(BagDrawable object, Integer value) { 148 | object.mOutlinePadding = value; 149 | invalidateSelf(); 150 | } 151 | }; 152 | } 153 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/simple/widget/CanMergeView.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.simple.widget; 2 | 3 | 4 | import com.anarchy.classify.simple.ChangeInfo; 5 | import com.anarchy.classify.simple.PrimitiveSimpleAdapter; 6 | 7 | 8 | 9 | public interface CanMergeView { 10 | /** 11 | * 进入merge状态 12 | */ 13 | void onMergeStart(); 14 | 15 | /** 16 | * 离开merge状态 17 | */ 18 | void onMergeCancel(); 19 | 20 | /** 21 | * 结束merge事件 22 | */ 23 | void onMerged(); 24 | 25 | /** 26 | * 开始merge动画 27 | * @param duration 动画持续时间 28 | */ 29 | void startMergeAnimation(int duration); 30 | 31 | /** 32 | * 准备merge 33 | * @return 返回新添加的view 应该放置在布局中的位置坐标 34 | */ 35 | ChangeInfo prepareMerge(); 36 | /** 37 | * 设置适配器 38 | * @param primitiveSimpleAdapter 39 | */ 40 | void setAdapter(PrimitiveSimpleAdapter primitiveSimpleAdapter); 41 | 42 | /** 43 | * 初始化或更新主层级 44 | * @param requestCount 需要显示里面有几个子view 45 | */ 46 | void initOrUpdateMain(int parentIndex, int requestCount); 47 | 48 | /** 49 | * 初始化或更新次级层级 50 | * @param parentIndex 51 | * @param subIndex 52 | */ 53 | void initOrUpdateSub(int parentIndex, int subIndex); 54 | } 55 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/simple/widget/MiViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.simple.widget; 2 | 3 | /** 4 | * Created by lizhiming211223 on 2016/12/29. 5 | */ 6 | public class MiViewHolder { 7 | public int childTag=0; 8 | } 9 | -------------------------------------------------------------------------------- /classify/src/main/java/com/anarchy/classify/util/L.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify.util; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * Date: 16/6/1 16:06 7 | * Author: rsshinide38@163.com 8 | */ 9 | public class L { 10 | private static final String TAG = "ClassifyView"; 11 | private static boolean DEBUG = false; 12 | public static void setDebugAble(boolean debugAble){ 13 | DEBUG = debugAble; 14 | } 15 | public static void d(String msg){ 16 | if(DEBUG){ 17 | Log.d(TAG,msg); 18 | } 19 | } 20 | public static void d(String msg,Object... objects){ 21 | if(DEBUG){ 22 | Log.d(TAG,String.format(msg,objects)); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /classify/src/main/res/anim/slide_down.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /classify/src/main/res/anim/slide_up.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /classify/src/main/res/layout/simple_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /classify/src/main/res/layout/sub_content.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /classify/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /classify/src/main/res/values/classify_style.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 16 | 17 | 27 | 28 | 32 | -------------------------------------------------------------------------------- /classify/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | classify 3 | sub_container 4 | 5 | -------------------------------------------------------------------------------- /classify/src/test/java/com/anarchy/classify/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.anarchy.classify; 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 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlphaBoom/ClassifyView/095ca71b63fd763f6c44fa979291b2c98e9409bd/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jun 22 00:37:02 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /screenshot/classifyView.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlphaBoom/ClassifyView/095ca71b63fd763f6c44fa979291b2c98e9409bd/screenshot/classifyView.gif -------------------------------------------------------------------------------- /screenshot/ireader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlphaBoom/ClassifyView/095ca71b63fd763f6c44fa979291b2c98e9409bd/screenshot/ireader.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':classify' 2 | --------------------------------------------------------------------------------