Search in sources :

Example 6 with BackStackEntry

use of android.support.v4.app.FragmentManager.BackStackEntry in project little-bear-dictionary by daimajia.

the class FragmentBreadCrumbs method updateCrumbs.

void updateCrumbs() {
    FragmentManager fm = mActivity.getSupportFragmentManager();
    int numEntries = fm.getBackStackEntryCount();
    int numPreEntries = getPreEntryCount();
    int numViews = mContainer.getChildCount();
    for (int i = 0; i < numEntries + numPreEntries; i++) {
        BackStackEntry bse = i < numPreEntries ? getPreEntry(i) : fm.getBackStackEntryAt(i - numPreEntries);
        if (i < numViews) {
            View v = mContainer.getChildAt(i);
            Object tag = v.getTag();
            if (tag != bse) {
                for (int j = i; j < numViews; j++) {
                    mContainer.removeViewAt(i);
                }
                numViews = i;
            }
        }
        if (i >= numViews) {
            final View item = mInflater.inflate(R.layout.fragment_bread_crumb_item, this, false);
            final TextView text = (TextView) item.findViewById(R.id.title);
            text.setText(bse.getBreadCrumbTitle());
            text.setTag(bse);
            if (i == 0) {
                item.findViewById(R.id.left_icon).setVisibility(View.GONE);
            }
            mContainer.addView(item);
            text.setOnClickListener(mOnClickListener);
        }
    }
    int viewI = numEntries + numPreEntries;
    numViews = mContainer.getChildCount();
    while (numViews > viewI) {
        mContainer.removeViewAt(numViews - 1);
        numViews--;
    }
    for (int i = 0; i < numViews; i++) {
        final View child = mContainer.getChildAt(i);
        child.findViewById(R.id.title).setEnabled(i < numViews - 1);
        if (mMaxVisible > 0) {
            child.setVisibility(i < numViews - mMaxVisible ? View.GONE : View.VISIBLE);
            final View leftIcon = child.findViewById(R.id.left_icon);
            leftIcon.setVisibility(i > numViews - mMaxVisible && i != 0 ? View.VISIBLE : View.GONE);
        }
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) BackStackEntry(android.support.v4.app.FragmentManager.BackStackEntry) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Aggregations

BackStackEntry (android.support.v4.app.FragmentManager.BackStackEntry)6 SuppressLint (android.annotation.SuppressLint)3 FragmentManager (android.support.v4.app.FragmentManager)3 View (android.view.View)3 TextView (android.widget.TextView)3