├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── fonts │ │ └── material-icon-font.ttf │ ├── java │ └── com │ │ └── unnamed │ │ └── b │ │ └── atv │ │ └── sample │ │ ├── activity │ │ ├── MainActivity.java │ │ └── SingleFragmentActivity.java │ │ ├── fragment │ │ ├── CustomViewHolderFragment.java │ │ ├── FolderStructureFragment.java │ │ ├── SelectableTreeFragment.java │ │ ├── TwoDScrollingArrowExpandFragment.java │ │ └── TwoDScrollingFragment.java │ │ └── holder │ │ ├── ArrowExpandSelectableHeaderHolder.java │ │ ├── HeaderHolder.java │ │ ├── IconTreeItemHolder.java │ │ ├── PlaceHolderHolder.java │ │ ├── ProfileHolder.java │ │ ├── SelectableHeaderHolder.java │ │ ├── SelectableItemHolder.java │ │ └── SocialViewHolder.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── drawable-xxxhdpi │ └── ic_launcher.png │ ├── layout │ ├── activity_main.xml │ ├── activity_single_fragment.xml │ ├── fragment_default.xml │ ├── fragment_selectable_nodes.xml │ ├── layout_header_node.xml │ ├── layout_icon_node.xml │ ├── layout_place_node.xml │ ├── layout_profile_node.xml │ ├── layout_selectable_header.xml │ ├── layout_selectable_item.xml │ └── layout_social_node.xml │ ├── menu │ └── menu.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── unnamed │ │ └── b │ │ └── atv │ │ ├── holder │ │ └── SimpleViewHolder.java │ │ ├── model │ │ └── TreeNode.java │ │ └── view │ │ ├── AndroidTreeView.java │ │ ├── TreeNodeWrapperView.java │ │ └── TwoDScrollView.java │ └── res │ └── values │ ├── ids.xml │ └── styles.xml ├── maven_push.gradle └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # IntelliJ IDEA 19 | .idea/ 20 | *.iml 21 | *.iws 22 | *.ipr 23 | 24 | # Gradle 25 | .gradle 26 | build/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## This project is deprecated. You can still use it as it. Let me know if someone is interested in supporting it. 2 | 3 | AndroidTreeView 4 | ==================== 5 | 6 | ### Recent changes 7 | 8 | 9 | 2D scrolling mode added, keep in mind this comes with few limitations: you won't be able not place views on right side like alignParentRight. Everything should be align left. Is not enabled by default 10 | 11 | 12 | ### Description 13 | 14 | Tree view implementation for android 15 | 16 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-AndroidTreeView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1534) 17 | 18 | ### Demo 19 | 20 | [![AndroidTreeView Demo on Google Play Store](http://style.anu.edu.au/_anu/images/icons/icon-google-play-small.png)](https://play.google.com/store/apps/details?id=com.unnamed.b.atv.demo) 21 | 22 | 23 | ### Features 24 | + 1. N - level expandable/collapsable tree 25 | + 2. Custom values, views, styles for nodes 26 | + 3. Save state after rotation 27 | + 4. Selection mode for nodes 28 | + 5. Dynamic add/remove node 29 | 30 | ### Known Limitations 31 | + For Android 4.0 (+/- nearest version) if you have too deep view hierarchy and with tree its easily possible, your app may crash 32 | 33 |
34 |
35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | ### Integration 45 | 46 | **1)** Add library as a dependency to your project 47 | 48 | ```compile 'com.github.bmelnychuk:atv:1.2.+'``` 49 | 50 | **2)** Create your tree starting from root element. ```TreeNode.root()``` element will not be displayed so it doesn't require anything to be set. 51 | ```java 52 | TreeNode root = TreeNode.root(); 53 | ``` 54 | 55 | Create and add your nodes (use your custom object as constructor param) 56 | ```java 57 | TreeNode parent = new TreeNode("MyParentNode"); 58 | TreeNode child0 = new TreeNode("ChildNode0"); 59 | TreeNode child1 = new TreeNode("ChildNode1"); 60 | parent.addChildren(child0, child1); 61 | root.addChild(parent); 62 | ``` 63 | 64 | **3)** Add tree view to layout 65 | ```java 66 | AndroidTreeView tView = new AndroidTreeView(getActivity(), root); 67 | containerView.addView(tView.getView()); 68 | ``` 69 | The simplest but not styled tree is ready. Now you can see ```parent``` node as root of your tree 70 | 71 | **4)** Custom view for nodes 72 | 73 | Extend ```TreeNode.BaseNodeViewHolder``` and overwrite ```createNodeView``` method to prepare custom view for node: 74 | ```java 75 | public class MyHolder extends TreeNode.BaseNodeViewHolder { 76 | ... 77 | @Override 78 | public View createNodeView(TreeNode node, IconTreeItem value) { 79 | final LayoutInflater inflater = LayoutInflater.from(context); 80 | final View view = inflater.inflate(R.layout.layout_profile_node, null, false); 81 | TextView tvValue = (TextView) view.findViewById(R.id.node_value); 82 | tvValue.setText(value.text); 83 | 84 | return view; 85 | } 86 | ... 87 | public static class IconTreeItem { 88 | public int icon; 89 | public String text; 90 | } 91 | } 92 | ``` 93 | 94 | **5)** Connect view holder with node 95 | ```java 96 | IconTreeItem nodeItem = new IconTreeItem(); 97 | TreeNode child1 = new TreeNode(nodeItem).setViewHolder(new MyHolder(mContext)); 98 | ``` 99 | 100 | **6)** Consider using 101 | ```java 102 | TreeNode.setClickListener(TreeNodeClickListener listener); 103 | AndroidTreeView.setDefaultViewHolder 104 | AndroidTreeView.setDefaultNodeClickListener 105 | ... 106 | ``` 107 | 108 | For more details use sample application as example 109 | 110 | Let me know if i missed something, appreciate your support, thanks! 111 | 112 | ### Projects using this library 113 | 114 | [Blue Dot : World Chat](https://play.google.com/store/apps/details?id=com.commandapps.bluedot) 115 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION) 5 | buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION 6 | 7 | defaultConfig { 8 | applicationId "com.unnamed.b.atv.demo" 9 | minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION) 10 | targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION) 11 | versionName project.VERSION_NAME 12 | versionCode Integer.parseInt(project.VERSION_CODE) 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | compile 'com.android.support:appcompat-v7:21.0.3' 24 | compile 'com.github.johnkil.print:print:1.2.2' 25 | compile project(':library') 26 | } 27 | -------------------------------------------------------------------------------- /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/bogdan/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/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/assets/fonts/material-icon-font.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmelnychuk/AndroidTreeView/5850dc8252b94e3ce9c5f2a375dea57683b326a1/app/src/main/assets/fonts/material-icon-font.ttf -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.activity; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v7.app.ActionBarActivity; 7 | import android.view.View; 8 | import android.widget.AdapterView; 9 | import android.widget.ArrayAdapter; 10 | import android.widget.ListView; 11 | 12 | import com.unnamed.b.atv.sample.R; 13 | import com.unnamed.b.atv.sample.fragment.CustomViewHolderFragment; 14 | import com.unnamed.b.atv.sample.fragment.FolderStructureFragment; 15 | import com.unnamed.b.atv.sample.fragment.SelectableTreeFragment; 16 | import com.unnamed.b.atv.sample.fragment.TwoDScrollingArrowExpandFragment; 17 | import com.unnamed.b.atv.sample.fragment.TwoDScrollingFragment; 18 | 19 | import java.util.ArrayList; 20 | import java.util.LinkedHashMap; 21 | import java.util.List; 22 | 23 | 24 | public class MainActivity extends ActionBarActivity { 25 | 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_main); 31 | 32 | 33 | final LinkedHashMap> listItems = new LinkedHashMap<>(); 34 | listItems.put("Folder Structure Example", FolderStructureFragment.class); 35 | listItems.put("Custom Holder Example", CustomViewHolderFragment.class); 36 | listItems.put("Selectable Nodes", SelectableTreeFragment.class); 37 | listItems.put("2d scrolling", TwoDScrollingFragment.class); 38 | listItems.put("Expand with arrow only", TwoDScrollingArrowExpandFragment.class); 39 | 40 | 41 | final List list = new ArrayList(listItems.keySet()); 42 | final ListView listview = (ListView) findViewById(R.id.listview); 43 | final SimpleArrayAdapter adapter = new SimpleArrayAdapter(this, list); 44 | listview.setAdapter(adapter); 45 | listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { 46 | @Override 47 | public void onItemClick(AdapterView parent, View view, int position, long id) { 48 | Class clazz = listItems.values().toArray(new Class[]{})[position]; 49 | Intent i = new Intent(MainActivity.this, SingleFragmentActivity.class); 50 | i.putExtra(SingleFragmentActivity.FRAGMENT_PARAM, clazz); 51 | MainActivity.this.startActivity(i); 52 | } 53 | }); 54 | 55 | } 56 | 57 | private class SimpleArrayAdapter extends ArrayAdapter { 58 | public SimpleArrayAdapter(Context context, List objects) { 59 | super(context, android.R.layout.simple_list_item_1, objects); 60 | 61 | } 62 | 63 | @Override 64 | public long getItemId(int position) { 65 | return position; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/activity/SingleFragmentActivity.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.activity; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v7.app.ActionBarActivity; 6 | 7 | import com.unnamed.b.atv.sample.R; 8 | 9 | /** 10 | * Created by Bogdan Melnychuk on 2/12/15. 11 | */ 12 | public class SingleFragmentActivity extends ActionBarActivity { 13 | public final static String FRAGMENT_PARAM = "fragment"; 14 | 15 | @Override 16 | protected void onCreate(Bundle bundle) { 17 | super.onCreate(bundle); 18 | setContentView(R.layout.activity_single_fragment); 19 | 20 | Bundle b = getIntent().getExtras(); 21 | Class fragmentClass = (Class) b.get(FRAGMENT_PARAM); 22 | if (bundle == null) { 23 | Fragment f = Fragment.instantiate(this, fragmentClass.getName()); 24 | f.setArguments(b); 25 | getFragmentManager().beginTransaction().replace(R.id.fragment, f, fragmentClass.getName()).commit(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/fragment/CustomViewHolderFragment.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.fragment; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.text.TextUtils; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.unnamed.b.atv.model.TreeNode; 11 | import com.unnamed.b.atv.sample.R; 12 | import com.unnamed.b.atv.sample.holder.HeaderHolder; 13 | import com.unnamed.b.atv.sample.holder.IconTreeItemHolder; 14 | import com.unnamed.b.atv.sample.holder.PlaceHolderHolder; 15 | import com.unnamed.b.atv.sample.holder.ProfileHolder; 16 | import com.unnamed.b.atv.sample.holder.SocialViewHolder; 17 | import com.unnamed.b.atv.view.AndroidTreeView; 18 | 19 | /** 20 | * Created by Bogdan Melnychuk on 2/12/15. 21 | */ 22 | public class CustomViewHolderFragment extends Fragment { 23 | private AndroidTreeView tView; 24 | 25 | @Override 26 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 27 | final View rootView = inflater.inflate(R.layout.fragment_default, null, false); 28 | final ViewGroup containerView = (ViewGroup) rootView.findViewById(R.id.container); 29 | rootView.findViewById(R.id.status_bar).setVisibility(View.GONE); 30 | 31 | final TreeNode root = TreeNode.root(); 32 | 33 | TreeNode myProfile = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_person, "My Profile")).setViewHolder(new ProfileHolder(getActivity())); 34 | TreeNode bruce = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_person, "Bruce Wayne")).setViewHolder(new ProfileHolder(getActivity())); 35 | TreeNode clark = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_person, "Clark Kent")).setViewHolder(new ProfileHolder(getActivity())); 36 | TreeNode barry = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_person, "Barry Allen")).setViewHolder(new ProfileHolder(getActivity())); 37 | addProfileData(myProfile); 38 | addProfileData(clark); 39 | addProfileData(bruce); 40 | addProfileData(barry); 41 | root.addChildren(myProfile, bruce, barry, clark); 42 | 43 | tView = new AndroidTreeView(getActivity(), root); 44 | tView.setDefaultAnimation(true); 45 | tView.setDefaultContainerStyle(R.style.TreeNodeStyleDivided, true); 46 | containerView.addView(tView.getView()); 47 | 48 | if (savedInstanceState != null) { 49 | String state = savedInstanceState.getString("tState"); 50 | if (!TextUtils.isEmpty(state)) { 51 | tView.restoreState(state); 52 | } 53 | } 54 | 55 | return rootView; 56 | } 57 | 58 | private void addProfileData(TreeNode profile) { 59 | TreeNode socialNetworks = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_people, "Social")).setViewHolder(new HeaderHolder(getActivity())); 60 | TreeNode places = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_place, "Places")).setViewHolder(new HeaderHolder(getActivity())); 61 | 62 | TreeNode facebook = new TreeNode(new SocialViewHolder.SocialItem(R.string.ic_post_facebook)).setViewHolder(new SocialViewHolder(getActivity())); 63 | TreeNode linkedin = new TreeNode(new SocialViewHolder.SocialItem(R.string.ic_post_linkedin)).setViewHolder(new SocialViewHolder(getActivity())); 64 | TreeNode google = new TreeNode(new SocialViewHolder.SocialItem(R.string.ic_post_gplus)).setViewHolder(new SocialViewHolder(getActivity())); 65 | TreeNode twitter = new TreeNode(new SocialViewHolder.SocialItem(R.string.ic_post_twitter)).setViewHolder(new SocialViewHolder(getActivity())); 66 | 67 | TreeNode lake = new TreeNode(new PlaceHolderHolder.PlaceItem("A rose garden")).setViewHolder(new PlaceHolderHolder(getActivity())); 68 | TreeNode mountains = new TreeNode(new PlaceHolderHolder.PlaceItem("The white house")).setViewHolder(new PlaceHolderHolder(getActivity())); 69 | 70 | places.addChildren(lake, mountains); 71 | socialNetworks.addChildren(facebook, google, twitter, linkedin); 72 | profile.addChildren(socialNetworks, places); 73 | } 74 | 75 | @Override 76 | public void onSaveInstanceState(Bundle outState) { 77 | super.onSaveInstanceState(outState); 78 | outState.putString("tState", tView.getSaveState()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/fragment/FolderStructureFragment.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.fragment; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.text.TextUtils; 6 | import android.view.LayoutInflater; 7 | import android.view.Menu; 8 | import android.view.MenuInflater; 9 | import android.view.MenuItem; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.TextView; 13 | import android.widget.Toast; 14 | 15 | import com.unnamed.b.atv.model.TreeNode; 16 | import com.unnamed.b.atv.sample.R; 17 | import com.unnamed.b.atv.sample.holder.IconTreeItemHolder; 18 | import com.unnamed.b.atv.view.AndroidTreeView; 19 | 20 | /** 21 | * Created by Bogdan Melnychuk on 2/12/15. 22 | */ 23 | public class FolderStructureFragment extends Fragment { 24 | private TextView statusBar; 25 | private AndroidTreeView tView; 26 | 27 | 28 | @Override 29 | public void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setHasOptionsMenu(true); 32 | } 33 | 34 | @Override 35 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 36 | 37 | View rootView = inflater.inflate(R.layout.fragment_default, null, false); 38 | ViewGroup containerView = (ViewGroup) rootView.findViewById(R.id.container); 39 | 40 | statusBar = (TextView) rootView.findViewById(R.id.status_bar); 41 | 42 | TreeNode root = TreeNode.root(); 43 | TreeNode computerRoot = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_laptop, "My Computer")); 44 | 45 | TreeNode myDocuments = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "My Documents")); 46 | TreeNode downloads = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Downloads")); 47 | TreeNode file1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_drive_file, "Folder 1")); 48 | TreeNode file2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_drive_file, "Folder 2")); 49 | TreeNode file3 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_drive_file, "Folder 3")); 50 | TreeNode file4 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_drive_file, "Folder 4")); 51 | fillDownloadsFolder(downloads); 52 | downloads.addChildren(file1, file2, file3, file4); 53 | 54 | TreeNode myMedia = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_photo_library, "Photos")); 55 | TreeNode photo1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_photo, "Folder 1")); 56 | TreeNode photo2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_photo, "Folder 2")); 57 | TreeNode photo3 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_photo, "Folder 3")); 58 | myMedia.addChildren(photo1, photo2, photo3); 59 | 60 | myDocuments.addChild(downloads); 61 | computerRoot.addChildren(myDocuments, myMedia); 62 | 63 | root.addChildren(computerRoot); 64 | 65 | tView = new AndroidTreeView(getActivity(), root); 66 | tView.setDefaultAnimation(true); 67 | tView.setDefaultContainerStyle(R.style.TreeNodeStyleCustom); 68 | tView.setDefaultViewHolder(IconTreeItemHolder.class); 69 | tView.setDefaultNodeClickListener(nodeClickListener); 70 | tView.setDefaultNodeLongClickListener(nodeLongClickListener); 71 | 72 | containerView.addView(tView.getView()); 73 | 74 | if (savedInstanceState != null) { 75 | String state = savedInstanceState.getString("tState"); 76 | if (!TextUtils.isEmpty(state)) { 77 | tView.restoreState(state); 78 | } 79 | } 80 | 81 | return rootView; 82 | } 83 | 84 | @Override 85 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 86 | inflater.inflate(R.menu.menu, menu); 87 | super.onCreateOptionsMenu(menu, inflater); 88 | } 89 | 90 | @Override 91 | public boolean onOptionsItemSelected(MenuItem item) { 92 | switch (item.getItemId()) { 93 | case R.id.expandAll: 94 | tView.expandAll(); 95 | break; 96 | 97 | case R.id.collapseAll: 98 | tView.collapseAll(); 99 | break; 100 | } 101 | return true; 102 | } 103 | 104 | private int counter = 0; 105 | 106 | private void fillDownloadsFolder(TreeNode node) { 107 | TreeNode downloads = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Downloads" + (counter++))); 108 | node.addChild(downloads); 109 | if (counter < 5) { 110 | fillDownloadsFolder(downloads); 111 | } 112 | } 113 | 114 | private TreeNode.TreeNodeClickListener nodeClickListener = new TreeNode.TreeNodeClickListener() { 115 | @Override 116 | public void onClick(TreeNode node, Object value) { 117 | IconTreeItemHolder.IconTreeItem item = (IconTreeItemHolder.IconTreeItem) value; 118 | statusBar.setText("Last clicked: " + item.text); 119 | } 120 | }; 121 | 122 | private TreeNode.TreeNodeLongClickListener nodeLongClickListener = new TreeNode.TreeNodeLongClickListener() { 123 | @Override 124 | public boolean onLongClick(TreeNode node, Object value) { 125 | IconTreeItemHolder.IconTreeItem item = (IconTreeItemHolder.IconTreeItem) value; 126 | Toast.makeText(getActivity(), "Long click: " + item.text, Toast.LENGTH_SHORT).show(); 127 | return true; 128 | } 129 | }; 130 | 131 | @Override 132 | public void onSaveInstanceState(Bundle outState) { 133 | super.onSaveInstanceState(outState); 134 | outState.putString("tState", tView.getSaveState()); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/fragment/SelectableTreeFragment.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.fragment; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.text.TextUtils; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.Toast; 10 | 11 | import com.unnamed.b.atv.model.TreeNode; 12 | import com.unnamed.b.atv.sample.R; 13 | import com.unnamed.b.atv.sample.holder.IconTreeItemHolder; 14 | import com.unnamed.b.atv.sample.holder.ProfileHolder; 15 | import com.unnamed.b.atv.sample.holder.SelectableHeaderHolder; 16 | import com.unnamed.b.atv.sample.holder.SelectableItemHolder; 17 | import com.unnamed.b.atv.view.AndroidTreeView; 18 | 19 | /** 20 | * Created by Bogdan Melnychuk on 2/12/15. 21 | */ 22 | public class SelectableTreeFragment extends Fragment { 23 | private AndroidTreeView tView; 24 | private boolean selectionModeEnabled = false; 25 | 26 | @Override 27 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 28 | 29 | View rootView = inflater.inflate(R.layout.fragment_selectable_nodes, null, false); 30 | ViewGroup containerView = (ViewGroup) rootView.findViewById(R.id.container); 31 | 32 | View selectionModeButton = rootView.findViewById(R.id.btn_toggleSelection); 33 | selectionModeButton.setOnClickListener(new View.OnClickListener() { 34 | @Override 35 | public void onClick(View v) { 36 | selectionModeEnabled = !selectionModeEnabled; 37 | tView.setSelectionModeEnabled(selectionModeEnabled); 38 | } 39 | }); 40 | 41 | View selectAllBtn = rootView.findViewById(R.id.btn_selectAll); 42 | selectAllBtn.setOnClickListener(new View.OnClickListener() { 43 | @Override 44 | public void onClick(View v) { 45 | if (!selectionModeEnabled) { 46 | Toast.makeText(getActivity(), "Enable selection mode first", Toast.LENGTH_SHORT).show(); 47 | } 48 | tView.selectAll(true); 49 | } 50 | }); 51 | 52 | View deselectAll = rootView.findViewById(R.id.btn_deselectAll); 53 | deselectAll.setOnClickListener(new View.OnClickListener() { 54 | @Override 55 | public void onClick(View v) { 56 | if (!selectionModeEnabled) { 57 | Toast.makeText(getActivity(), "Enable selection mode first", Toast.LENGTH_SHORT).show(); 58 | } 59 | tView.deselectAll(); 60 | } 61 | }); 62 | 63 | View check = rootView.findViewById(R.id.btn_checkSelection); 64 | check.setOnClickListener(new View.OnClickListener() { 65 | @Override 66 | public void onClick(View v) { 67 | if (!selectionModeEnabled) { 68 | Toast.makeText(getActivity(), "Enable selection mode first", Toast.LENGTH_SHORT).show(); 69 | } else { 70 | Toast.makeText(getActivity(), tView.getSelected().size() + " selected", Toast.LENGTH_SHORT).show(); 71 | } 72 | } 73 | }); 74 | 75 | TreeNode root = TreeNode.root(); 76 | 77 | TreeNode s1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_sd_storage, "Storage1")).setViewHolder(new ProfileHolder(getActivity())); 78 | TreeNode s2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_sd_storage, "Storage2")).setViewHolder(new ProfileHolder(getActivity())); 79 | s1.setSelectable(false); 80 | s2.setSelectable(false); 81 | 82 | TreeNode folder1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Folder 1")).setViewHolder(new SelectableHeaderHolder(getActivity())); 83 | TreeNode folder2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Folder 2")).setViewHolder(new SelectableHeaderHolder(getActivity())); 84 | TreeNode folder3 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Folder 3")).setViewHolder(new SelectableHeaderHolder(getActivity())); 85 | 86 | fillFolder(folder1); 87 | fillFolder(folder2); 88 | fillFolder(folder3); 89 | 90 | s1.addChildren(folder1, folder2); 91 | s2.addChildren(folder3); 92 | 93 | root.addChildren(s1, s2); 94 | 95 | tView = new AndroidTreeView(getActivity(), root); 96 | tView.setDefaultAnimation(true); 97 | containerView.addView(tView.getView()); 98 | 99 | if (savedInstanceState != null) { 100 | String state = savedInstanceState.getString("tState"); 101 | if (!TextUtils.isEmpty(state)) { 102 | tView.restoreState(state); 103 | } 104 | } 105 | return rootView; 106 | } 107 | 108 | private void fillFolder(TreeNode folder) { 109 | TreeNode file1 = new TreeNode("File1").setViewHolder(new SelectableItemHolder(getActivity())); 110 | TreeNode file2 = new TreeNode("File2").setViewHolder(new SelectableItemHolder(getActivity())); 111 | TreeNode file3 = new TreeNode("File3").setViewHolder(new SelectableItemHolder(getActivity())); 112 | folder.addChildren(file1, file2, file3); 113 | } 114 | 115 | @Override 116 | public void onSaveInstanceState(Bundle outState) { 117 | super.onSaveInstanceState(outState); 118 | outState.putString("tState", tView.getSaveState()); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/fragment/TwoDScrollingArrowExpandFragment.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.fragment; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.text.TextUtils; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.Toast; 10 | 11 | import com.unnamed.b.atv.model.TreeNode; 12 | import com.unnamed.b.atv.sample.R; 13 | import com.unnamed.b.atv.sample.holder.ArrowExpandSelectableHeaderHolder; 14 | import com.unnamed.b.atv.sample.holder.IconTreeItemHolder; 15 | import com.unnamed.b.atv.view.AndroidTreeView; 16 | 17 | /** 18 | * Created by Bogdan Melnychuk on 2/12/15 modified by Szigeti Peter 2/2/16. 19 | */ 20 | public class TwoDScrollingArrowExpandFragment extends Fragment implements TreeNode.TreeNodeClickListener{ 21 | private static final String NAME = "Very long name for folder"; 22 | private AndroidTreeView tView; 23 | 24 | @Override 25 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 26 | View rootView = inflater.inflate(R.layout.fragment_selectable_nodes, null, false); 27 | rootView.findViewById(R.id.status).setVisibility(View.GONE); 28 | ViewGroup containerView = (ViewGroup) rootView.findViewById(R.id.container); 29 | 30 | TreeNode root = TreeNode.root(); 31 | 32 | TreeNode s1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Folder with very long name ")).setViewHolder( 33 | new ArrowExpandSelectableHeaderHolder(getActivity())); 34 | TreeNode s2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Another folder with very long name")).setViewHolder( 35 | new ArrowExpandSelectableHeaderHolder(getActivity())); 36 | 37 | fillFolder(s1); 38 | fillFolder(s2); 39 | 40 | root.addChildren(s1, s2); 41 | 42 | tView = new AndroidTreeView(getActivity(), root); 43 | tView.setDefaultAnimation(true); 44 | tView.setUse2dScroll(true); 45 | tView.setDefaultContainerStyle(R.style.TreeNodeStyleCustom); 46 | tView.setDefaultNodeClickListener(TwoDScrollingArrowExpandFragment.this); 47 | tView.setDefaultViewHolder(ArrowExpandSelectableHeaderHolder.class); 48 | containerView.addView(tView.getView()); 49 | tView.setUseAutoToggle(false); 50 | 51 | tView.expandAll(); 52 | 53 | if (savedInstanceState != null) { 54 | String state = savedInstanceState.getString("tState"); 55 | if (!TextUtils.isEmpty(state)) { 56 | tView.restoreState(state); 57 | } 58 | } 59 | return rootView; 60 | } 61 | 62 | private void fillFolder(TreeNode folder) { 63 | TreeNode currentNode = folder; 64 | for (int i = 0; i < 4; i++) { 65 | TreeNode file = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, NAME + " " + i)); 66 | currentNode.addChild(file); 67 | currentNode = file; 68 | } 69 | } 70 | 71 | @Override 72 | public void onSaveInstanceState(Bundle outState) { 73 | super.onSaveInstanceState(outState); 74 | outState.putString("tState", tView.getSaveState()); 75 | } 76 | 77 | @Override 78 | public void onClick(TreeNode node, Object value) { 79 | Toast toast = Toast.makeText(getActivity(), ((IconTreeItemHolder.IconTreeItem)value).text, Toast.LENGTH_SHORT); 80 | toast.show(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/fragment/TwoDScrollingFragment.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.fragment; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.text.TextUtils; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.unnamed.b.atv.model.TreeNode; 11 | import com.unnamed.b.atv.sample.R; 12 | import com.unnamed.b.atv.sample.holder.IconTreeItemHolder; 13 | import com.unnamed.b.atv.sample.holder.SelectableHeaderHolder; 14 | import com.unnamed.b.atv.view.AndroidTreeView; 15 | 16 | /** 17 | * Created by Bogdan Melnychuk on 2/12/15. 18 | */ 19 | public class TwoDScrollingFragment extends Fragment { 20 | private static final String NAME = "Very long name for folder"; 21 | private AndroidTreeView tView; 22 | 23 | @Override 24 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 25 | View rootView = inflater.inflate(R.layout.fragment_selectable_nodes, null, false); 26 | rootView.findViewById(R.id.status).setVisibility(View.GONE); 27 | ViewGroup containerView = (ViewGroup) rootView.findViewById(R.id.container); 28 | 29 | TreeNode root = TreeNode.root(); 30 | 31 | TreeNode s1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Folder with very long name ")).setViewHolder(new SelectableHeaderHolder(getActivity())); 32 | TreeNode s2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Another folder with very long name")).setViewHolder(new SelectableHeaderHolder(getActivity())); 33 | 34 | fillFolder(s1); 35 | fillFolder(s2); 36 | 37 | root.addChildren(s1, s2); 38 | 39 | tView = new AndroidTreeView(getActivity(), root); 40 | tView.setDefaultAnimation(true); 41 | tView.setUse2dScroll(true); 42 | tView.setDefaultContainerStyle(R.style.TreeNodeStyleCustom); 43 | containerView.addView(tView.getView()); 44 | 45 | tView.expandAll(); 46 | 47 | if (savedInstanceState != null) { 48 | String state = savedInstanceState.getString("tState"); 49 | if (!TextUtils.isEmpty(state)) { 50 | tView.restoreState(state); 51 | } 52 | } 53 | return rootView; 54 | } 55 | 56 | private void fillFolder(TreeNode folder) { 57 | TreeNode currentNode = folder; 58 | for (int i = 0; i < 10; i++) { 59 | TreeNode file = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, NAME)).setViewHolder(new SelectableHeaderHolder(getActivity())); 60 | currentNode.addChild(file); 61 | currentNode = file; 62 | } 63 | } 64 | 65 | @Override 66 | public void onSaveInstanceState(Bundle outState) { 67 | super.onSaveInstanceState(outState); 68 | outState.putString("tState", tView.getSaveState()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/holder/ArrowExpandSelectableHeaderHolder.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.holder; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.CheckBox; 7 | import android.widget.CompoundButton; 8 | import android.widget.TextView; 9 | 10 | import com.github.johnkil.print.PrintView; 11 | import com.unnamed.b.atv.model.TreeNode; 12 | import com.unnamed.b.atv.sample.R; 13 | 14 | /** 15 | * Created by Bogdan Melnychuk on 2/15/15, modified by Szigeti Peter 2/2/16. 16 | */ 17 | public class ArrowExpandSelectableHeaderHolder extends TreeNode.BaseNodeViewHolder { 18 | private TextView tvValue; 19 | private PrintView arrowView; 20 | private CheckBox nodeSelector; 21 | 22 | public ArrowExpandSelectableHeaderHolder(Context context) { 23 | super(context); 24 | } 25 | 26 | @Override 27 | public View createNodeView(final TreeNode node, IconTreeItemHolder.IconTreeItem value) { 28 | final LayoutInflater inflater = LayoutInflater.from(context); 29 | final View view = inflater.inflate(R.layout.layout_selectable_header, null, false); 30 | 31 | tvValue = (TextView) view.findViewById(R.id.node_value); 32 | tvValue.setText(value.text); 33 | 34 | final PrintView iconView = (PrintView) view.findViewById(R.id.icon); 35 | iconView.setIconText(context.getResources().getString(value.icon)); 36 | 37 | arrowView = (PrintView) view.findViewById(R.id.arrow_icon); 38 | arrowView.setPadding(20,10,10,10); 39 | if (node.isLeaf()) { 40 | arrowView.setVisibility(View.GONE); 41 | } 42 | arrowView.setOnClickListener(new View.OnClickListener() { 43 | @Override 44 | public void onClick(View view) { 45 | tView.toggleNode(node); 46 | } 47 | }); 48 | 49 | nodeSelector = (CheckBox) view.findViewById(R.id.node_selector); 50 | nodeSelector.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 51 | @Override 52 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 53 | node.setSelected(isChecked); 54 | for (TreeNode n : node.getChildren()) { 55 | getTreeView().selectNode(n, isChecked); 56 | } 57 | } 58 | }); 59 | nodeSelector.setChecked(node.isSelected()); 60 | 61 | return view; 62 | } 63 | 64 | @Override 65 | public void toggle(boolean active) { 66 | arrowView.setIconText(context.getResources().getString(active ? R.string.ic_keyboard_arrow_down : R.string.ic_keyboard_arrow_right)); 67 | } 68 | 69 | @Override 70 | public void toggleSelectionMode(boolean editModeEnabled) { 71 | nodeSelector.setVisibility(editModeEnabled ? View.VISIBLE : View.GONE); 72 | nodeSelector.setChecked(mNode.isSelected()); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/holder/HeaderHolder.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.holder; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import com.github.johnkil.print.PrintView; 9 | import com.unnamed.b.atv.model.TreeNode; 10 | import com.unnamed.b.atv.sample.R; 11 | 12 | /** 13 | * Created by Bogdan Melnychuk on 2/13/15. 14 | */ 15 | public class HeaderHolder extends TreeNode.BaseNodeViewHolder { 16 | 17 | private PrintView arrowView; 18 | 19 | public HeaderHolder(Context context) { 20 | super(context); 21 | } 22 | 23 | @Override 24 | public View createNodeView(TreeNode node, IconTreeItemHolder.IconTreeItem value) { 25 | final LayoutInflater inflater = LayoutInflater.from(context); 26 | final View view = inflater.inflate(R.layout.layout_header_node, null, false); 27 | TextView tvValue = (TextView) view.findViewById(R.id.node_value); 28 | tvValue.setText(value.text); 29 | 30 | final PrintView iconView = (PrintView) view.findViewById(R.id.icon); 31 | iconView.setIconText(context.getResources().getString(value.icon)); 32 | 33 | arrowView = (PrintView) view.findViewById(R.id.arrow_icon); 34 | if (node.isLeaf()) { 35 | arrowView.setVisibility(View.INVISIBLE); 36 | } 37 | 38 | return view; 39 | } 40 | 41 | @Override 42 | public void toggle(boolean active) { 43 | arrowView.setIconText(context.getResources().getString(active ? R.string.ic_keyboard_arrow_down : R.string.ic_keyboard_arrow_right)); 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/holder/IconTreeItemHolder.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.holder; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import com.github.johnkil.print.PrintView; 9 | import com.unnamed.b.atv.model.TreeNode; 10 | import com.unnamed.b.atv.sample.R; 11 | 12 | /** 13 | * Created by Bogdan Melnychuk on 2/12/15. 14 | */ 15 | public class IconTreeItemHolder extends TreeNode.BaseNodeViewHolder { 16 | private TextView tvValue; 17 | private PrintView arrowView; 18 | 19 | public IconTreeItemHolder(Context context) { 20 | super(context); 21 | } 22 | 23 | @Override 24 | public View createNodeView(final TreeNode node, IconTreeItem value) { 25 | final LayoutInflater inflater = LayoutInflater.from(context); 26 | final View view = inflater.inflate(R.layout.layout_icon_node, null, false); 27 | tvValue = (TextView) view.findViewById(R.id.node_value); 28 | tvValue.setText(value.text); 29 | 30 | final PrintView iconView = (PrintView) view.findViewById(R.id.icon); 31 | iconView.setIconText(context.getResources().getString(value.icon)); 32 | 33 | arrowView = (PrintView) view.findViewById(R.id.arrow_icon); 34 | 35 | view.findViewById(R.id.btn_addFolder).setOnClickListener(new View.OnClickListener() { 36 | @Override 37 | public void onClick(View v) { 38 | TreeNode newFolder = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "New Folder")); 39 | getTreeView().addNode(node, newFolder); 40 | } 41 | }); 42 | 43 | view.findViewById(R.id.btn_delete).setOnClickListener(new View.OnClickListener() { 44 | @Override 45 | public void onClick(View v) { 46 | getTreeView().removeNode(node); 47 | } 48 | }); 49 | 50 | //if My computer 51 | if (node.getLevel() == 1) { 52 | view.findViewById(R.id.btn_delete).setVisibility(View.GONE); 53 | } 54 | 55 | return view; 56 | } 57 | 58 | @Override 59 | public void toggle(boolean active) { 60 | arrowView.setIconText(context.getResources().getString(active ? R.string.ic_keyboard_arrow_down : R.string.ic_keyboard_arrow_right)); 61 | } 62 | 63 | public static class IconTreeItem { 64 | public int icon; 65 | public String text; 66 | 67 | public IconTreeItem(int icon, String text) { 68 | this.icon = icon; 69 | this.text = text; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/holder/PlaceHolderHolder.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.holder; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import com.github.johnkil.print.PrintView; 9 | import com.unnamed.b.atv.model.TreeNode; 10 | import com.unnamed.b.atv.sample.R; 11 | 12 | import java.util.Random; 13 | 14 | /** 15 | * Created by Bogdan Melnychuk on 2/13/15. 16 | */ 17 | public class PlaceHolderHolder extends TreeNode.BaseNodeViewHolder { 18 | 19 | 20 | public PlaceHolderHolder(Context context) { 21 | super(context); 22 | } 23 | 24 | @Override 25 | public View createNodeView(TreeNode node, PlaceItem value) { 26 | final LayoutInflater inflater = LayoutInflater.from(context); 27 | final View view = inflater.inflate(R.layout.layout_place_node, null, false); 28 | 29 | 30 | TextView placeName = (TextView) view.findViewById(R.id.place_name); 31 | placeName.setText(value.name); 32 | 33 | Random r = new Random(); 34 | boolean like = r.nextBoolean(); 35 | 36 | PrintView likeView = (PrintView) view.findViewById(R.id.like); 37 | likeView.setIconText(context.getString(like ? R.string.ic_thumbs_up : R.string.ic_thumbs_down)); 38 | return view; 39 | } 40 | 41 | @Override 42 | public void toggle(boolean active) { 43 | } 44 | 45 | 46 | public static class PlaceItem { 47 | public String name; 48 | 49 | public PlaceItem(String name) { 50 | this.name = name; 51 | } 52 | // rest will be hardcoded 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/holder/ProfileHolder.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.holder; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import com.github.johnkil.print.PrintView; 9 | import com.unnamed.b.atv.model.TreeNode; 10 | import com.unnamed.b.atv.sample.R; 11 | 12 | /** 13 | * Created by Bogdan Melnychuk on 2/13/15. 14 | */ 15 | public class ProfileHolder extends TreeNode.BaseNodeViewHolder { 16 | 17 | 18 | public ProfileHolder(Context context) { 19 | super(context); 20 | } 21 | 22 | @Override 23 | public View createNodeView(TreeNode node, IconTreeItemHolder.IconTreeItem value) { 24 | final LayoutInflater inflater = LayoutInflater.from(context); 25 | final View view = inflater.inflate(R.layout.layout_profile_node, null, false); 26 | TextView tvValue = (TextView) view.findViewById(R.id.node_value); 27 | tvValue.setText(value.text); 28 | 29 | final PrintView iconView = (PrintView) view.findViewById(R.id.icon); 30 | iconView.setIconText(context.getResources().getString(value.icon)); 31 | 32 | return view; 33 | } 34 | 35 | @Override 36 | public void toggle(boolean active) { 37 | } 38 | 39 | @Override 40 | public int getContainerStyle() { 41 | return R.style.TreeNodeStyleCustom; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/holder/SelectableHeaderHolder.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.holder; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.CheckBox; 7 | import android.widget.CompoundButton; 8 | import android.widget.TextView; 9 | 10 | import com.github.johnkil.print.PrintView; 11 | import com.unnamed.b.atv.model.TreeNode; 12 | import com.unnamed.b.atv.sample.R; 13 | 14 | /** 15 | * Created by Bogdan Melnychuk on 2/15/15. 16 | */ 17 | public class SelectableHeaderHolder extends TreeNode.BaseNodeViewHolder { 18 | private TextView tvValue; 19 | private PrintView arrowView; 20 | private CheckBox nodeSelector; 21 | 22 | public SelectableHeaderHolder(Context context) { 23 | super(context); 24 | } 25 | 26 | @Override 27 | public View createNodeView(final TreeNode node, IconTreeItemHolder.IconTreeItem value) { 28 | final LayoutInflater inflater = LayoutInflater.from(context); 29 | final View view = inflater.inflate(R.layout.layout_selectable_header, null, false); 30 | 31 | tvValue = (TextView) view.findViewById(R.id.node_value); 32 | tvValue.setText(value.text); 33 | 34 | final PrintView iconView = (PrintView) view.findViewById(R.id.icon); 35 | iconView.setIconText(context.getResources().getString(value.icon)); 36 | 37 | arrowView = (PrintView) view.findViewById(R.id.arrow_icon); 38 | if (node.isLeaf()) { 39 | arrowView.setVisibility(View.GONE); 40 | } 41 | 42 | nodeSelector = (CheckBox) view.findViewById(R.id.node_selector); 43 | nodeSelector.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 44 | @Override 45 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 46 | node.setSelected(isChecked); 47 | for (TreeNode n : node.getChildren()) { 48 | getTreeView().selectNode(n, isChecked); 49 | } 50 | } 51 | }); 52 | nodeSelector.setChecked(node.isSelected()); 53 | 54 | return view; 55 | } 56 | 57 | @Override 58 | public void toggle(boolean active) { 59 | arrowView.setIconText(context.getResources().getString(active ? R.string.ic_keyboard_arrow_down : R.string.ic_keyboard_arrow_right)); 60 | } 61 | 62 | @Override 63 | public void toggleSelectionMode(boolean editModeEnabled) { 64 | nodeSelector.setVisibility(editModeEnabled ? View.VISIBLE : View.GONE); 65 | nodeSelector.setChecked(mNode.isSelected()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/holder/SelectableItemHolder.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.holder; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.CheckBox; 7 | import android.widget.CompoundButton; 8 | import android.widget.TextView; 9 | 10 | import com.unnamed.b.atv.model.TreeNode; 11 | import com.unnamed.b.atv.sample.R; 12 | 13 | /** 14 | * Created by Bogdan Melnychuk on 2/15/15. 15 | */ 16 | public class SelectableItemHolder extends TreeNode.BaseNodeViewHolder { 17 | private TextView tvValue; 18 | private CheckBox nodeSelector; 19 | 20 | public SelectableItemHolder(Context context) { 21 | super(context); 22 | } 23 | 24 | @Override 25 | public View createNodeView(final TreeNode node, String value) { 26 | final LayoutInflater inflater = LayoutInflater.from(context); 27 | final View view = inflater.inflate(R.layout.layout_selectable_item, null, false); 28 | 29 | tvValue = (TextView) view.findViewById(R.id.node_value); 30 | tvValue.setText(value); 31 | 32 | 33 | nodeSelector = (CheckBox) view.findViewById(R.id.node_selector); 34 | nodeSelector.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 35 | @Override 36 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 37 | node.setSelected(isChecked); 38 | } 39 | }); 40 | nodeSelector.setChecked(node.isSelected()); 41 | 42 | if (node.isLastChild()) { 43 | view.findViewById(R.id.bot_line).setVisibility(View.INVISIBLE); 44 | } 45 | 46 | return view; 47 | } 48 | 49 | 50 | @Override 51 | public void toggleSelectionMode(boolean editModeEnabled) { 52 | nodeSelector.setVisibility(editModeEnabled ? View.VISIBLE : View.GONE); 53 | nodeSelector.setChecked(mNode.isSelected()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/unnamed/b/atv/sample/holder/SocialViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.unnamed.b.atv.sample.holder; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import com.github.johnkil.print.PrintView; 9 | import com.unnamed.b.atv.model.TreeNode; 10 | import com.unnamed.b.atv.sample.R; 11 | 12 | import java.util.Random; 13 | 14 | /** 15 | * Created by Bogdan Melnychuk on 2/13/15. 16 | */ 17 | public class SocialViewHolder extends TreeNode.BaseNodeViewHolder { 18 | 19 | private static final String[] NAMES = new String[]{"Bruce Wayne", "Clark Kent", "Barry Allen", "Hal Jordan"}; 20 | 21 | public SocialViewHolder(Context context) { 22 | super(context); 23 | } 24 | 25 | @Override 26 | public View createNodeView(TreeNode node, SocialItem value) { 27 | final LayoutInflater inflater = LayoutInflater.from(context); 28 | final View view = inflater.inflate(R.layout.layout_social_node, null, false); 29 | 30 | final PrintView iconView = (PrintView) view.findViewById(R.id.icon); 31 | iconView.setIconText(context.getResources().getString(value.icon)); 32 | 33 | TextView connectionsLabel = (TextView) view.findViewById(R.id.connections); 34 | Random r = new Random(); 35 | connectionsLabel.setText(r.nextInt(150) + " connections"); 36 | 37 | TextView userNameLabel = (TextView) view.findViewById(R.id.username); 38 | userNameLabel.setText(NAMES[r.nextInt(4)]); 39 | 40 | TextView sizeText = (TextView) view.findViewById(R.id.size); 41 | sizeText.setText(r.nextInt(10) + " items"); 42 | 43 | return view; 44 | } 45 | 46 | @Override 47 | public void toggle(boolean active) { 48 | } 49 | 50 | 51 | public static class SocialItem { 52 | public int icon; 53 | 54 | public SocialItem(int icon) { 55 | this.icon = icon; 56 | } 57 | // rest will be hardcoded 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmelnychuk/AndroidTreeView/5850dc8252b94e3ce9c5f2a375dea57683b326a1/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmelnychuk/AndroidTreeView/5850dc8252b94e3ce9c5f2a375dea57683b326a1/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmelnychuk/AndroidTreeView/5850dc8252b94e3ce9c5f2a375dea57683b326a1/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmelnychuk/AndroidTreeView/5850dc8252b94e3ce9c5f2a375dea57683b326a1/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmelnychuk/AndroidTreeView/5850dc8252b94e3ce9c5f2a375dea57683b326a1/app/src/main/res/drawable-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_single_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_default.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 15 | 16 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_selectable_nodes.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 14 | 22 | 23 | 24 |