当前位置: 首页>>代码示例>>Java>>正文


Java FragmentManager.getFragments方法代码示例

本文整理汇总了Java中android.support.v4.app.FragmentManager.getFragments方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentManager.getFragments方法的具体用法?Java FragmentManager.getFragments怎么用?Java FragmentManager.getFragments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.app.FragmentManager的用法示例。


在下文中一共展示了FragmentManager.getFragments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dispatchBackPress

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * 处理fragment回退键
 * <p>如果fragment实现了OnBackClickListener接口,返回{@code true}: 表示已消费回退键事件,反之则没消费</p>
 * <p>具体示例见FragmentActivity</p>
 *
 * @param fragmentManager fragment管理器
 * @return 是否消费回退事件
 */
public static boolean dispatchBackPress(@NonNull FragmentManager fragmentManager) {
    List<Fragment> fragments = fragmentManager.getFragments();
    if (fragments == null || fragments.isEmpty()) return false;
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null
                && fragment.isResumed()
                && fragment.isVisible()
                && fragment.getUserVisibleHint()
                && fragment instanceof OnBackClickListener
                && ((OnBackClickListener) fragment).onBackClick()) {
            return true;
        }
    }
    return false;
}
 
开发者ID:hoangkien0705,项目名称:Android-UtilCode,代码行数:25,代码来源:FragmentUtils.java

示例2: getAllFragmentsIsInStack

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * 根据栈参数获取所有fragment
 * <p>需之前对fragment的操作都借助该工具类</p>
 *
 * @param fragmentManager fragment管理器
 * @param result          结果
 * @param isInStack       是否是栈中的
 * @return 栈中所有fragment
 */
private static List<FragmentNode> getAllFragmentsIsInStack(@NonNull final FragmentManager fragmentManager,
                                                           final List<FragmentNode> result,
                                                           final boolean isInStack) {
    List<Fragment> fragments = fragmentManager.getFragments();
    if (fragments == null || fragments.isEmpty()) return Collections.emptyList();
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null) {
            if (isInStack) {
                if (fragment.getArguments().getBoolean(ARGS_IS_ADD_STACK)) {
                    result.add(new FragmentNode(fragment, getAllFragmentsIsInStack(fragment.getChildFragmentManager(), new ArrayList<FragmentNode>(), true)));
                }
            } else {
                result.add(new FragmentNode(fragment, getAllFragmentsIsInStack(fragment.getChildFragmentManager(), new ArrayList<FragmentNode>(), false)));
            }
        }
    }
    return result;
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:29,代码来源:FragmentUtils.java

示例3: dispatchBackPress

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * 处理fragment回退键
 * <p>如果fragment实现了OnBackClickListener接口,返回{@code true}: 表示已消费回退键事件,反之则没消费</p>
 * <p>具体示例见FragmentActivity</p>
 *
 * @param fragmentManager fragment管理器
 * @return 是否消费回退事件
 */
public static boolean dispatchBackPress(@NonNull FragmentManager fragmentManager) {
    List<Fragment> fragments = fragmentManager.getFragments();
    if (fragments == null || fragments.isEmpty()) {
        return false;
    }
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null
                && fragment.isResumed()
                && fragment.isVisible()
                && fragment.getUserVisibleHint()
                && fragment instanceof OnBackClickListener
                && ((OnBackClickListener) fragment).onBackClick()) {
            return true;
        }
    }
    return false;
}
 
开发者ID:xiaobailong24,项目名称:MVVMArms,代码行数:27,代码来源:FragmentUtils.java

示例4: dispatchBackPress

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * Handle the fragment back key
 * <p>If fragment implements the OnBackClickListener interface, returns {@code true}: indicates that the consumer has returned the key event, otherwise it is not consumed</p>
 * <p>See FragmentActivity for specific examples</p>
 *
 * @param fragmentManager fragment manager
 * @return Whether to consume back events
 */
public static boolean dispatchBackPress(@NonNull FragmentManager fragmentManager) {
    List<Fragment> fragments = fragmentManager.getFragments();
    if (fragments == null || fragments.isEmpty())
        return false;
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null
                && fragment.isResumed()
                && fragment.isVisible()
                && fragment.getUserVisibleHint()
                && fragment instanceof OnBackClickListener
                && ((OnBackClickListener) fragment).onBackClick()) {
            return true;
        }
    }
    return false;
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:26,代码来源:FragmentUtils.java

示例5: showOneFragmentOnBackPressed

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * 返回键显示特定Tag的Fragment
 */
private void showOneFragmentOnBackPressed() {
    mFragmentBackDeque.pop();
    String fragmentTab = mFragmentBackDeque.peek();

    FragmentManager manager = getSupportFragmentManager();
    if (manager != null) {
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.setCustomAnimations(R.anim.left_enter, R.anim.right_exit, 0, 0);

        List<Fragment> fragments = manager.getFragments();
        for (Fragment f : fragments) {
            if (f != null) {
                transaction.hide(f);
            }
        }
        Fragment fragmentByTag = manager.findFragmentByTag(fragmentTab);
        if (fragmentByTag != null) {
            mCurrentFragment = fragmentByTag;
            transaction.show(fragmentByTag);
        }

        transaction.commitAllowingStateLoss();
    }
}
 
开发者ID:Sugarya,项目名称:FragmentCapsulation,代码行数:28,代码来源:BasicActivity.java

示例6: dispatchBackPress

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * 处理fragment回退键
 * <p>如果fragment实现了OnBackClickListener接口,返回{@code true}: 表示已消费回退键事件,反之则没消费</p>
 * <p>具体示例见FragmentActivity</p>
 *
 * @param fragmentManager fragment管理器
 * @return 是否消费回退事件
 */
public static boolean dispatchBackPress(@NonNull FragmentManager fragmentManager) {
    List<Fragment> fragments = fragmentManager.getFragments();
    if (fragments == null || fragments.isEmpty())
        return false;
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null
                && fragment.isResumed()
                && fragment.isVisible()
                && fragment.getUserVisibleHint()
                && fragment instanceof OnBackClickListener
                && ((OnBackClickListener) fragment).onBackClick()) {
            return true;
        }
    }
    return false;
}
 
开发者ID:yangxp108,项目名称:MVPArms_Fragment-fragment,代码行数:26,代码来源:FragmentUtils.java

示例7: recoverFragment

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
protected void recoverFragment(String currentFragmentTag){
    if (currentFragmentTag==null){
        return;
    }
    FragmentManager fm=getSupportFragmentManager();
    FragmentTransaction ft=fm.beginTransaction();
    List<Fragment> fragments=fm.getFragments();
    for (Fragment fragment:fragments){
        if (fragment.getTag().equals(currentFragmentTag)){
            ft.show(fragment);
        }else {
            ft.hide(fragment);
        }
    }
    ft.commitAllowingStateLoss();
    Fragment current=fm.findFragmentByTag(currentFragmentTag);
    switchFragment(current);
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:19,代码来源:BaseActivity.java

示例8: getRxGoogleAuthFragment

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * Get instance of RxGoogleAuthFragment
 *
 * @return a RxGoogleAuthFragment
 */
private RxGoogleAuthFragment getRxGoogleAuthFragment(Builder builder) {
    FragmentManager fragmentManager = mActivity.getSupportFragmentManager();

    // prevent fragment manager already executing transaction
    int stackCount = fragmentManager.getBackStackEntryCount();
    if( fragmentManager.getFragments() != null )
        fragmentManager = fragmentManager.getFragments().get( stackCount > 0 ? stackCount-1 : stackCount ).getChildFragmentManager();

    RxGoogleAuthFragment rxGoogleAuthFragment = (RxGoogleAuthFragment)
            mActivity.getSupportFragmentManager().findFragmentByTag(RxGoogleAuthFragment.TAG);

    if (rxGoogleAuthFragment == null) {
        rxGoogleAuthFragment = RxGoogleAuthFragment.newInstance(builder);
        fragmentManager
                .beginTransaction()
                .add(rxGoogleAuthFragment, RxGoogleAuthFragment.TAG)
                .commit();
        fragmentManager.executePendingTransactions();
    }
    return rxGoogleAuthFragment;
}
 
开发者ID:pchmn,项目名称:RxSocialAuth,代码行数:27,代码来源:RxGoogleAuth.java

示例9: getFragmentsIsInStack

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * 根据栈参数获取同级别fragment
 *
 * @param fragmentManager fragment管理器
 * @param isInStack       是否是栈中的
 * @return 栈中同级别fragment
 */
private static List<Fragment> getFragmentsIsInStack(@NonNull FragmentManager fragmentManager, boolean isInStack) {
    List<Fragment> fragments = fragmentManager.getFragments();
    if (fragments == null || fragments.isEmpty()) return Collections.emptyList();
    List<Fragment> result = new ArrayList<>();
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null) {
            if (isInStack) {
                if (fragment.getArguments().getBoolean(ARGS_IS_ADD_STACK)) {
                    result.add(fragment);
                }
            } else {
                result.add(fragment);
            }
        }
    }
    return result;
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:26,代码来源:FragmentUtils.java

示例10: getAllFragmentsIsInStack

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * Get all the fragments based on the stack parameters
 * <p>Before the need for the operation of the fragment are using the tool class</p>
 *
 * @param fragmentManager fragment manager
 * @param result          result
 * @param isInStack       Whether it is in the stack
 * @return All the fragments in the stack
 */
private static List<FragmentNode> getAllFragmentsIsInStack(@NonNull FragmentManager fragmentManager,
                                                           List<FragmentNode> result,
                                                           boolean isInStack) {
    List<Fragment> fragments = fragmentManager.getFragments();
    if (fragments == null || fragments.isEmpty())
        return Collections.emptyList();
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null) {
            if (isInStack) {
                if (fragment.getArguments().getBoolean(ARGS_IS_ADD_STACK)) {
                    result.add(new FragmentNode(fragment, getAllFragmentsIsInStack(fragment.getChildFragmentManager(), new ArrayList<FragmentNode>(), true)));
                }
            } else {
                result.add(new FragmentNode(fragment, getAllFragmentsIsInStack(fragment.getChildFragmentManager(), new ArrayList<FragmentNode>(), false)));
            }
        }
    }
    return result;
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:30,代码来源:FragmentUtils.java

示例11: showHideFragment

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
public static void showHideFragment(FragmentManager manager, Fragment show, Fragment hide, boolean animation, boolean backStack) {
    FragmentTransaction transaction = manager.beginTransaction();
    if (animation) {
        transaction.setCustomAnimations(
                R.anim .fragment_translate_in, R.anim.fragment_translate_out
        ,R.anim.fragment_pop_in,R.anim.fragment_pop_out);
    }
    transaction.show(show);
    if (hide == null) {
        List<Fragment> fragments = manager.getFragments();
        if (fragments != null) {
            for (Fragment fragment : fragments) {
                if (fragment != show) {
                    transaction.hide(fragment);
                }
            }
        }
    } else {
        transaction.hide(hide);
    }
    if (backStack) {
        transaction.addToBackStack("showHideFragment");
    }
    transaction.commit();
}
 
开发者ID:bigjelly,项目名称:ShaddockVideoPlayer,代码行数:26,代码来源:FragmentUtils.java

示例12: showHideFragment

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:LonelyMushroom,项目名称:aarLibrary,代码行数:29,代码来源:FragmentationDelegate.java

示例13: deleteAllFragments

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
protected void deleteAllFragments() {
    if (getAllFragmentTags() != null) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        if (!BaseTypeUtils.isListEmpty(fragmentManager.getFragments())) {
            FragmentTransaction transaction = fragmentManager.beginTransaction();
            for (Fragment fragment : fragmentManager.getFragments()) {
                transaction.remove(fragment);
            }
            try {
                transaction.commitAllowingStateLoss();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:17,代码来源:LetvBaseActivity.java

示例14: handleBackPress

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * 将back事件分发给 FragmentManager 中管理的子Fragment,
 * 如果该 FragmentManager 中的所有Fragment都没有处理back事件,则尝试 FragmentManager.popBackStack()
 * @return 如果处理了back键则返回 <b>true</b>
 * @see #handleBackPress(Fragment)
 * @see #handleBackPress(FragmentActivity)
 */
public static boolean handleBackPress(FragmentManager fragmentManager) {
    List<Fragment> fragments = fragmentManager.getFragments();
    if (fragments == null) return false;
    for (int i = fragments.size() - 1; i >= 0; i--) {
        Fragment child = fragments.get(i);
        if (isFragmentBackHandled(child)) {
            return true;
        }
    }

    if (fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStack();
        return true;
    }
    return false;
}
 
开发者ID:yangchong211,项目名称:YCUtils,代码行数:24,代码来源:BackHandlerHelper.java

示例15: getActiveFragment

import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
 * 从栈顶开始查找,状态为show & userVisible的Fragment
 */
SupportFragment getActiveFragment(SupportFragment parentFragment, FragmentManager fragmentManager) {
    List<Fragment> fragmentList = fragmentManager.getFragments();
    if (fragmentList == null) {
        return parentFragment;
    }
    for (int i = fragmentList.size() - 1; i >= 0; i--) {
        Fragment fragment = fragmentList.get(i);
        if (fragment instanceof SupportFragment) {
            SupportFragment supportFragment = (SupportFragment) fragment;
            if (supportFragment.isResumed() && !supportFragment.isHidden() && supportFragment.getUserVisibleHint()) {
                return getActiveFragment(supportFragment, supportFragment.getChildFragmentManager());
            }
        }
    }
    return parentFragment;
}
 
开发者ID:LonelyMushroom,项目名称:aarLibrary,代码行数:20,代码来源:FragmentationDelegate.java


注:本文中的android.support.v4.app.FragmentManager.getFragments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。