當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。