Search in sources :

Example 1 with SelectableHeaderHolder

use of com.unnamed.b.atv.sample.holder.SelectableHeaderHolder in project AndroidTreeView by bmelnychuk.

the class SelectableTreeFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_selectable_nodes, null, false);
    ViewGroup containerView = (ViewGroup) rootView.findViewById(R.id.container);
    View selectionModeButton = rootView.findViewById(R.id.btn_toggleSelection);
    selectionModeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            selectionModeEnabled = !selectionModeEnabled;
            tView.setSelectionModeEnabled(selectionModeEnabled);
        }
    });
    View selectAllBtn = rootView.findViewById(R.id.btn_selectAll);
    selectAllBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!selectionModeEnabled) {
                Toast.makeText(getActivity(), "Enable selection mode first", Toast.LENGTH_SHORT).show();
            }
            tView.selectAll(true);
        }
    });
    View deselectAll = rootView.findViewById(R.id.btn_deselectAll);
    deselectAll.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!selectionModeEnabled) {
                Toast.makeText(getActivity(), "Enable selection mode first", Toast.LENGTH_SHORT).show();
            }
            tView.deselectAll();
        }
    });
    View check = rootView.findViewById(R.id.btn_checkSelection);
    check.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!selectionModeEnabled) {
                Toast.makeText(getActivity(), "Enable selection mode first", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getActivity(), tView.getSelected().size() + " selected", Toast.LENGTH_SHORT).show();
            }
        }
    });
    TreeNode root = TreeNode.root();
    TreeNode s1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_sd_storage, "Storage1")).setViewHolder(new ProfileHolder(getActivity()));
    TreeNode s2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_sd_storage, "Storage2")).setViewHolder(new ProfileHolder(getActivity()));
    s1.setSelectable(false);
    s2.setSelectable(false);
    TreeNode folder1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Folder 1")).setViewHolder(new SelectableHeaderHolder(getActivity()));
    TreeNode folder2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Folder 2")).setViewHolder(new SelectableHeaderHolder(getActivity()));
    TreeNode folder3 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Folder 3")).setViewHolder(new SelectableHeaderHolder(getActivity()));
    fillFolder(folder1);
    fillFolder(folder2);
    fillFolder(folder3);
    s1.addChildren(folder1, folder2);
    s2.addChildren(folder3);
    root.addChildren(s1, s2);
    tView = new AndroidTreeView(getActivity(), root);
    tView.setDefaultAnimation(true);
    containerView.addView(tView.getView());
    if (savedInstanceState != null) {
        String state = savedInstanceState.getString("tState");
        if (!TextUtils.isEmpty(state)) {
            tView.restoreState(state);
        }
    }
    return rootView;
}
Also used : ViewGroup(android.view.ViewGroup) TreeNode(com.unnamed.b.atv.model.TreeNode) AndroidTreeView(com.unnamed.b.atv.view.AndroidTreeView) SelectableHeaderHolder(com.unnamed.b.atv.sample.holder.SelectableHeaderHolder) AndroidTreeView(com.unnamed.b.atv.view.AndroidTreeView) View(android.view.View) ProfileHolder(com.unnamed.b.atv.sample.holder.ProfileHolder)

Example 2 with SelectableHeaderHolder

use of com.unnamed.b.atv.sample.holder.SelectableHeaderHolder in project AndroidTreeView by bmelnychuk.

the class TwoDScrollingFragment method fillFolder.

private void fillFolder(TreeNode folder) {
    TreeNode currentNode = folder;
    for (int i = 0; i < 10; i++) {
        TreeNode file = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, NAME)).setViewHolder(new SelectableHeaderHolder(getActivity()));
        currentNode.addChild(file);
        currentNode = file;
    }
}
Also used : TreeNode(com.unnamed.b.atv.model.TreeNode) SelectableHeaderHolder(com.unnamed.b.atv.sample.holder.SelectableHeaderHolder)

Example 3 with SelectableHeaderHolder

use of com.unnamed.b.atv.sample.holder.SelectableHeaderHolder in project AndroidTreeView by bmelnychuk.

the class TwoDScrollingFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_selectable_nodes, null, false);
    rootView.findViewById(R.id.status).setVisibility(View.GONE);
    ViewGroup containerView = (ViewGroup) rootView.findViewById(R.id.container);
    TreeNode root = TreeNode.root();
    TreeNode s1 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Folder with very long name ")).setViewHolder(new SelectableHeaderHolder(getActivity()));
    TreeNode s2 = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_folder, "Another folder with very long name")).setViewHolder(new SelectableHeaderHolder(getActivity()));
    fillFolder(s1);
    fillFolder(s2);
    root.addChildren(s1, s2);
    tView = new AndroidTreeView(getActivity(), root);
    tView.setDefaultAnimation(true);
    tView.setUse2dScroll(true);
    tView.setDefaultContainerStyle(R.style.TreeNodeStyleCustom);
    containerView.addView(tView.getView());
    tView.expandAll();
    if (savedInstanceState != null) {
        String state = savedInstanceState.getString("tState");
        if (!TextUtils.isEmpty(state)) {
            tView.restoreState(state);
        }
    }
    return rootView;
}
Also used : ViewGroup(android.view.ViewGroup) TreeNode(com.unnamed.b.atv.model.TreeNode) AndroidTreeView(com.unnamed.b.atv.view.AndroidTreeView) SelectableHeaderHolder(com.unnamed.b.atv.sample.holder.SelectableHeaderHolder) AndroidTreeView(com.unnamed.b.atv.view.AndroidTreeView) View(android.view.View)

Aggregations

TreeNode (com.unnamed.b.atv.model.TreeNode)3 SelectableHeaderHolder (com.unnamed.b.atv.sample.holder.SelectableHeaderHolder)3 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 AndroidTreeView (com.unnamed.b.atv.view.AndroidTreeView)2 ProfileHolder (com.unnamed.b.atv.sample.holder.ProfileHolder)1