Android Open Source - dexedd Tree Adapter






From Project

Back to project page dexedd.

License

The source code is released under:

MIT License

If you think the Android project dexedd listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nav.dexedd.adapter;
/*from w ww  . jav  a 2s  .  c  o  m*/
import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;

import com.google.common.collect.TreeTraverser;
import com.nav.dexedd.structure.Tree;

import java.util.ArrayList;
import java.util.List;

public abstract class TreeAdapter<T> {

    public static enum TraversalType {
        BREADTH_FIRST, PRE_ORDER, POST_ORDER;
    }

    private Context context;
    protected int layoutResourceId;
    private Tree<T> tree;
    private TraversalType traversalType;


    public TreeAdapter(Context context, int layoutResourceId, Tree<T> tree, TraversalType traversalType) {
        this.context = context;
        this.layoutResourceId = layoutResourceId;
        this.tree = tree;
        this.traversalType = traversalType;
    }

    public List<View> prepareViews() {
        TreeTraverser<Tree<T>> traverser = new TreeTraverser<Tree<T>>() {
            @Override
            public Iterable<Tree<T>> children(Tree<T> root) {
                return root.getChildren();
            }
        };

        Iterable<Tree<T>> iterable;

        switch (this.traversalType) {
            case BREADTH_FIRST:
                iterable = traverser.breadthFirstTraversal(tree);
                break;
            case PRE_ORDER:
                iterable = traverser.preOrderTraversal(tree);
                break;
            case POST_ORDER:
                iterable = traverser.postOrderTraversal(tree);
                break;
            default:
                iterable = traverser.breadthFirstTraversal(tree);
        }

        List<View> views = new ArrayList<>();

        for (Tree<T> i : iterable) {
            View view = getView(layoutResourceId, i);

            // todo process margin think on branch icons
            views.add(view);
        }

        return views;
    }

    public abstract View getView(int layoutResourceId, Tree<T> i);

    public Context getContext() {
        return context;
    }

}




Java Source Code List

com.nav.dexedd.activity.DexEntryActivity.java
com.nav.dexedd.activity.Dexedd.java
com.nav.dexedd.activity.MainActivity.java
com.nav.dexedd.activity.SplashActivity.java
com.nav.dexedd.adapter.DexAdapter.java
com.nav.dexedd.adapter.TreeAdapter.java
com.nav.dexedd.fragment.DatabaseInitFragment.java
com.nav.dexedd.fragment.NavigationDrawerFragment.java
com.nav.dexedd.model.Ability.java
com.nav.dexedd.model.EggGroup.java
com.nav.dexedd.model.EvolutionCondition.java
com.nav.dexedd.model.Item.java
com.nav.dexedd.model.Location.java
com.nav.dexedd.model.Move.java
com.nav.dexedd.model.Pokemon.java
com.nav.dexedd.model.Region.java
com.nav.dexedd.model.StatSpread.java
com.nav.dexedd.model.Stat.java
com.nav.dexedd.model.Type.java
com.nav.dexedd.persistence.DexDatabase.java
com.nav.dexedd.persistence.access.Access.java
com.nav.dexedd.persistence.access.DexEntry.java
com.nav.dexedd.persistence.access.Dex.java
com.nav.dexedd.structure.Tree.java
com.nav.dexedd.text.CleanClickableSpan.java
com.nav.dexedd.ui.BetterGridView.java
com.nav.dexedd.ui.BetterScrollView.java
com.nav.dexedd.ui.LabelView.java
com.nav.dexedd.ui.SquareImageView.java
com.nav.dexedd.ui.TreeLayout.java
com.nav.dexedd.ui.TypeTagView.java
com.nav.dexedd.util.AssetUtil.java
com.nav.dexedd.util.ConversionUtil.java
com.nav.dexedd.util.PokemonTextUtil.java
com.nav.dexedd.util.TypeUtil.java