Search in sources :

Example 1 with ProfileHolder

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

the class CustomViewHolderFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_default, null, false);
    final ViewGroup containerView = (ViewGroup) rootView.findViewById(R.id.container);
    rootView.findViewById(R.id.status_bar).setVisibility(View.GONE);
    final TreeNode root = TreeNode.root();
    TreeNode myProfile = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_person, "My Profile")).setViewHolder(new ProfileHolder(getActivity()));
    TreeNode bruce = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_person, "Bruce Wayne")).setViewHolder(new ProfileHolder(getActivity()));
    TreeNode clark = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_person, "Clark Kent")).setViewHolder(new ProfileHolder(getActivity()));
    TreeNode barry = new TreeNode(new IconTreeItemHolder.IconTreeItem(R.string.ic_person, "Barry Allen")).setViewHolder(new ProfileHolder(getActivity()));
    addProfileData(myProfile);
    addProfileData(clark);
    addProfileData(bruce);
    addProfileData(barry);
    root.addChildren(myProfile, bruce, barry, clark);
    tView = new AndroidTreeView(getActivity(), root);
    tView.setDefaultAnimation(true);
    tView.setDefaultContainerStyle(R.style.TreeNodeStyleDivided, 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) AndroidTreeView(com.unnamed.b.atv.view.AndroidTreeView) View(android.view.View) ProfileHolder(com.unnamed.b.atv.sample.holder.ProfileHolder)

Example 2 with ProfileHolder

use of com.unnamed.b.atv.sample.holder.ProfileHolder 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)

Aggregations

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