Search in sources :

Example 56 with FragmentManager

use of android.support.v4.app.FragmentManager in project Fragmentation by YoKeyword.

the class FragmentationDelegate method getPreFragment.

/**
     * 获取目标Fragment的前一个Fragment
     *
     * @param fragment 目标Fragment
     */
SupportFragment getPreFragment(Fragment fragment) {
    FragmentManager fragmentManager = fragment.getFragmentManager();
    fragmentManager = checkFragmentManager(fragmentManager, null);
    if (fragmentManager == null)
        return null;
    List<Fragment> fragmentList = fragmentManager.getFragments();
    if (fragmentList == null)
        return null;
    int index = fragmentList.indexOf(fragment);
    for (int i = index - 1; i >= 0; i--) {
        Fragment preFragment = fragmentList.get(i);
        if (preFragment instanceof SupportFragment) {
            return (SupportFragment) preFragment;
        }
    }
    return null;
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) Fragment(android.support.v4.app.Fragment)

Example 57 with FragmentManager

use of android.support.v4.app.FragmentManager in project Fragmentation by YoKeyword.

the class FragmentationDelegate method loadMultipleRootTransaction.

/**
     * 加载多个根Fragment
     */
void loadMultipleRootTransaction(FragmentManager fragmentManager, int containerId, int showPosition, SupportFragment... tos) {
    fragmentManager = checkFragmentManager(fragmentManager, null);
    if (fragmentManager == null)
        return;
    FragmentTransaction ft = fragmentManager.beginTransaction();
    for (int i = 0; i < tos.length; i++) {
        SupportFragment to = tos[i];
        bindContainerId(containerId, tos[i]);
        String toName = to.getClass().getName();
        ft.add(containerId, to, toName);
        if (i != showPosition) {
            ft.hide(to);
        }
    }
    supportCommit(fragmentManager, ft);
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction)

Example 58 with FragmentManager

use of android.support.v4.app.FragmentManager in project Fragmentation by YoKeyword.

the class FragmentationDelegate method showHideFragment.

/**
     * show一个Fragment,hide另一个/多个Fragment ; 主要用于类似微信主页那种 切换tab的情况
     *
     * @param showFragment 需要show的Fragment
     * @param hideFragment 需要hide的Fragment
     */
void showHideFragment(FragmentManager fragmentManager, SupportFragment showFragment, SupportFragment hideFragment) {
    fragmentManager = checkFragmentManager(fragmentManager, null);
    if (fragmentManager == null)
        return;
    if (showFragment == hideFragment)
        return;
    FragmentTransaction ft = fragmentManager.beginTransaction().show(showFragment);
    if (hideFragment == null) {
        List<Fragment> fragmentList = fragmentManager.getFragments();
        if (fragmentList != null) {
            for (Fragment fragment : fragmentList) {
                if (fragment != null && fragment != showFragment) {
                    ft.hide(fragment);
                }
            }
        }
    } else {
        ft.hide(hideFragment);
    }
    supportCommit(fragmentManager, ft);
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) Fragment(android.support.v4.app.Fragment)

Example 59 with FragmentManager

use of android.support.v4.app.FragmentManager in project Fragmentation by YoKeyword.

the class SupportFragment method dispatchSupportVisible.

private void dispatchSupportVisible(boolean visible) {
    mIsSupportVisible = visible;
    if (!mNeedDispatch) {
        mNeedDispatch = true;
    } else {
        FragmentManager fragmentManager = getChildFragmentManager();
        if (fragmentManager != null) {
            List<Fragment> childFragments = fragmentManager.getFragments();
            if (childFragments != null) {
                for (Fragment child : childFragments) {
                    if (child instanceof SupportFragment && !child.isHidden() && child.getUserVisibleHint()) {
                        ((SupportFragment) child).dispatchSupportVisible(visible);
                    }
                }
            }
        }
    }
    if (visible) {
        if (mIsFirstVisible) {
            mIsFirstVisible = false;
            onLazyInitView(mSaveInstanceState);
            dispatchFragmentLifecycle(LifecycleHelper.LIFECYLCE_ONLAZYINITVIEW, null, false);
        }
        onSupportVisible();
        if (_mActivity != null) {
            _mActivity.setFragmentClickable(true);
        }
        dispatchFragmentLifecycle(LifecycleHelper.LIFECYLCE_ONSUPPORTVISIBLE, null, true);
    } else {
        onSupportInvisible();
        dispatchFragmentLifecycle(LifecycleHelper.LIFECYLCE_ONSUPPORTINVISIBLE, null, false);
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) Fragment(android.support.v4.app.Fragment)

Example 60 with FragmentManager

use of android.support.v4.app.FragmentManager in project DesignLibrary by StylingAndroid.

the class ArticleViewPagerAdapter method destroyItem.

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    FragmentManager manager = ((Fragment) object).getFragmentManager();
    FragmentTransaction trans = manager.beginTransaction();
    trans.remove((Fragment) object);
    trans.commit();
    super.destroyItem(container, position, object);
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) Fragment(android.support.v4.app.Fragment)

Aggregations

FragmentManager (android.support.v4.app.FragmentManager)293 FragmentTransaction (android.support.v4.app.FragmentTransaction)106 Fragment (android.support.v4.app.Fragment)99 View (android.view.View)53 TextView (android.widget.TextView)35 Bundle (android.os.Bundle)31 OnClickListener (android.view.View.OnClickListener)24 DialogFragment (android.support.v4.app.DialogFragment)23 Intent (android.content.Intent)20 ImageView (android.widget.ImageView)16 ScrollView (android.widget.ScrollView)14 ListFragment (android.support.v4.app.ListFragment)12 Button (android.widget.Button)11 ArrayList (java.util.ArrayList)9 FrontPageFragment (ingage.ingage20.fragments.FrontPageFragment)8 SearchResultFragment (ingage.ingage20.fragments.SearchResultFragment)8 ViewPager (android.support.v4.view.ViewPager)7 ActionBar (android.support.v7.app.ActionBar)7 RecyclerView (android.support.v7.widget.RecyclerView)7 CategoriesPageFragment (ingage.ingage20.fragments.CategoriesPageFragment)7