Java 类android.support.v4.app.FragmentManager 实例源码

项目:XinFramework    文件:TransactionDelegate.java   
private void executeDebouncePop(FragmentManager fm) {
    Fragment popF = fm.findFragmentByTag(fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName());
    if (popF instanceof ISupportFragment) {
        ISupportFragment supportF = (ISupportFragment) popF;
        if (supportF.getSupportDelegate().mIsSharedElement) {
            long now = System.currentTimeMillis();
            if (now < mShareElementDebounceTime) {
                mShareElementDebounceTime = System.currentTimeMillis() + supportF.getSupportDelegate().mAnimHelper.exitAnim.getDuration();
                return;
            }
        }
        mShareElementDebounceTime = System.currentTimeMillis() + supportF.getSupportDelegate().mAnimHelper.exitAnim.getDuration();
    }

    fm.popBackStack();
}
项目:ShotsNewsApp    文件:HomeActivity.java   
void btnclick(View view)
{
    //Fragment fragment=null;
    switch (view.getId()){
        case R.id.btn_learn:
            fragment=new On_going_Courses_Fragment();
            break;
        case R.id.btn_explore:
      //      getNews();
            fragment=new NewsFragment();
            break;
        case R.id.btn_profile:
            fragment=new profile_fragment();
            break;

    }
    FragmentManager fragmentManager=getSupportFragmentManager();
    FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.homeFrame_PlaceHolder,fragment);

    fragmentTransaction.commit();

}
项目:Programmers    文件:IntentUtils.java   
public static void showProgressFragmentDialog(Activity activity, boolean show) {
    try {
        FragmentManager fm = ((AppCompatActivity) activity).getSupportFragmentManager();

        if (show && progressFragmentDialog == null) {
            progressFragmentDialog = new ProgressFragmentDialog();
            progressFragmentDialog.show(fm, null);
            return;
        }

        if (show) {
            progressFragmentDialog.show(fm, null);
            return;
        }


        if (progressFragmentDialog == null) {
            return;
        }
        progressFragmentDialog.dismiss();
    }catch (Exception ex){
        ex.printStackTrace();
    }
}
项目:open-rmbt    文件:RMBTMainActivity.java   
public void showResultsAfterTest(String testUuid) {
    popBackStackFull();

    final RMBTResultPagerFragment fragment = new RMBTResultPagerFragment();
    final Bundle args = new Bundle();
    args.putString(RMBTResultPagerFragment.ARG_TEST_UUID, testUuid);
    fragment.setArguments(args);


    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction ft;
    ft = fm.beginTransaction();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_HISTORY_PAGER);
    ft.addToBackStack(AppConstants.PAGE_TITLE_HISTORY_PAGER);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();

    refreshActionBar(AppConstants.PAGE_TITLE_HISTORY_PAGER);
}
项目:TripleTap    文件:MainMenuFragment.java   
/**
 * Swaps in the Single Player Options Fragment
 */
@Override
public void openSinglePlayerOptions() {
    // Swap in single player menu fragment
    Fragment fragment = MainMenuSinglePlayerFragment.newInstance();

    // Set transitions
    fragment.setEnterTransition(mNewEnterTransition);
    fragment.setExitTransition(mNewExitTransition);

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.menu_frame, fragment);
    transaction.addToBackStack(null);
    transaction.commit();
}
项目:Chidori    文件:ErrorDialogManager.java   
public void onEventMainThread(ThrowableFailureEvent event) {
    if (!isInExecutionScope(executionScope, event)) {
        return;
    }
    checkLogException(event);
    // Execute pending commits before finding to avoid multiple error fragments being shown
    FragmentManager fm = getFragmentManager();
    fm.executePendingTransactions();

    DialogFragment existingFragment = (DialogFragment) fm.findFragmentByTag(TAG_ERROR_DIALOG);
    if (existingFragment != null) {
        // Just show the latest error
        existingFragment.dismiss();
    }

    DialogFragment errorFragment = (DialogFragment) factory
            .prepareErrorFragment(event, finishAfterDialog, argumentsForErrorDialog);
    if (errorFragment != null) {
        errorFragment.show(fm, TAG_ERROR_DIALOG);
    }
}
项目:MVVMArms    文件:FragmentUtils.java   
/**
 * 新增多个fragment
 *
 * @param fragmentManager fragment管理器
 * @param fragments       fragments
 * @param containerId     布局Id
 * @param showIndex       要显示的fragment索引
 * @param lists           共享元素链表
 * @return 要显示的fragment
 */
public static Fragment addFragments(@NonNull FragmentManager fragmentManager,
                                    @NonNull List<Fragment> fragments,
                                    @IdRes int containerId,
                                    int showIndex,
                                    @NonNull List<SharedElement>... lists) {
    for (int i = 0, size = fragments.size(); i < size; ++i) {
        Fragment fragment = fragments.get(i);
        List<SharedElement> list = lists[i];
        if (fragment != null) {
            if (list != null) {
                putArgs(fragment, new Args(containerId, showIndex != i, false));
                return operateFragment(fragmentManager, null, fragment, TYPE_ADD_FRAGMENT, list.toArray(new SharedElement[0]));
            }
        }
    }
    return fragments.get(showIndex);
}
项目:mvvm-template    文件:AppInjector.java   
private static void handleActivity(Activity activity) {
    if (activity instanceof HasSupportFragmentInjector || activity instanceof Injectable) {
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                                          Bundle savedInstanceState) {
                                if (f instanceof Injectable) {
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
项目:RxSocialAuth    文件:RxFacebookAuth.java   
/**
 * Get instance of RxFacebookAuthFragment
 *
 * @return a RxFacebookAuthFragment
 */
private RxFacebookAuthFragment getRxFacebookAuthFragment(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();

    RxFacebookAuthFragment rxFacebookAuthFragment = (RxFacebookAuthFragment)
            fragmentManager.findFragmentByTag(RxFacebookAuthFragment.TAG);

    if (rxFacebookAuthFragment == null) {
        rxFacebookAuthFragment = RxFacebookAuthFragment.newInstance(builder);
        fragmentManager
                .beginTransaction()
                .add(rxFacebookAuthFragment, RxFacebookAuthFragment.TAG)
                .commit();
        fragmentManager.executePendingTransactions();
    }
    return rxFacebookAuthFragment;
}
项目:freehkkai-android    文件:SettingsActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    C.detectLanguage(mContext);

    setContentView(R.layout.activity_container_adview);
    ButterKnife.bind(this);
    setSupportActionBar(toolbar);

    initActionBar(getSupportActionBar(), R.string.title_activity_settings);

    Fragment fragment = SettingsFragment.newInstance();
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction()
            .replace(R.id.container, fragment)
            .commit();
}
项目:chromium-for-android-56-debug-video    文件:BaseMediaRouteDialogManager.java   
@Override
public void openDialog() {
    if (mAndroidMediaRouter == null) {
        mDelegate.onDialogCancelled();
        return;
    }

    FragmentActivity currentActivity =
            (FragmentActivity) ApplicationStatus.getLastTrackedFocusedActivity();
    if (currentActivity == null)  {
        mDelegate.onDialogCancelled();
        return;
    }

    FragmentManager fm = currentActivity.getSupportFragmentManager();
    if (fm == null)  {
        mDelegate.onDialogCancelled();
        return;
    }

    mDialogFragment = openDialogInternal(fm);
    if (mDialogFragment == null)  {
        mDelegate.onDialogCancelled();
        return;
    }
}
项目:OldNews    文件:MainPageAdapter.java   
public MainPageAdapter(FragmentManager fragmentManager, Context context){
    super(fragmentManager);
    mFragmentArrayList = new ArrayList<Fragment>();

    mFragmentArrayList.add(new FeedFragment());
    mFragmentArrayList.add(new FavouriteFeedFragment());
    //mFragmentArrayList.add(new FeedFragment());

    mTitleList = new ArrayList<String>();
    mTitleList.add(context.getResources().getString(R.string.feed_tab));
    mTitleList.add(context.getResources().getString(R.string.favorites_tab));
    //mTitleList.add(context.getResources().getString(R.string.ocr_tab));

}
项目:TextEmoji    文件:ActivityUtils.java   
/**
 * The {@code fragment} is added to the container view with id {@code frameId}. The operation is
 * performed by the {@code fragmentManager}.
 *
 */
public static void addFragmentToActivity (@NonNull FragmentManager fragmentManager,
                                          @NonNull Fragment fragment, int frameId) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(frameId, fragment);
    transaction.commit();
}
项目:text_converter    文件:ApplicationHelper.java   
@Nullable
public static ApplicationPagerAdapter setup(AutoScrollViewPager viewPager, FragmentManager fragmentManager, Context context) {
    if (viewPager == null) return null;
    DLog.d(TAG, "setup() called");
    ApplicationPagerAdapter adapter = new ApplicationPagerAdapter(fragmentManager, context);
    viewPager.setAdapter(adapter);
    viewPager.startAutoScroll();
    return adapter;
}
项目:decoy    文件:UI.java   
public List<TFragment> addFragments(List<TFragment> fragments) {
    List<TFragment> fragments2 = new ArrayList<TFragment>(fragments.size());

    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction transaction = fm.beginTransaction();

    boolean commit = false;
    for (int i = 0; i < fragments.size(); i++) {
        // install
        TFragment fragment = fragments.get(i);
        int id = fragment.getContainerId();

        // exists
        TFragment fragment2 = (TFragment) fm.findFragmentById(id);

        if (fragment2 == null) {
            fragment2 = fragment;
            transaction.add(id, fragment);
            commit = true;
        }

        fragments2.add(i, fragment2);
    }

    if (commit) {
        try {
            transaction.commitAllowingStateLoss();
        } catch (Exception e) {

        }
    }

    return fragments2;
}
项目:hands-on-api-proxy    文件:SingleFragmentActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutResId());

    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);

    if (fragment == null) {
        fragment = createFragment();
        fm.beginTransaction()
                .add(R.id.fragment_container, fragment)
                .commit();
    }
}
项目:mapbook-android    文件:ActivityUtils.java   
/**
 * The {@code fragment} is added to the container view with id {@code frameId}. The operation is
 * performed by the {@code fragmentManager}.
 *
 */
public static void addFragmentToActivity (final FragmentManager fragmentManager,
    final Fragment fragment, final int frameId) {
  checkNotNull(fragmentManager);
  checkNotNull(fragment);
  final FragmentTransaction transaction = fragmentManager.beginTransaction();
  transaction.add(frameId, fragment);
  transaction.commit();
}
项目:android-mvvm-architecture    文件:BaseDialog.java   
public void show(FragmentManager fragmentManager, String tag) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Fragment prevFragment = fragmentManager.findFragmentByTag(tag);
    if (prevFragment != null) {
        transaction.remove(prevFragment);
    }
    transaction.addToBackStack(null);
    show(transaction, tag);
}
项目:GxIconDIY    文件:RetainedFragment.java   
@NonNull
public static RetainedFragment initRetainedFragment(@NonNull FragmentManager fragmentManager,
                                                    @NonNull String tag) {
    RetainedFragment fragment = (RetainedFragment) fragmentManager.findFragmentByTag(tag);
    if (fragment == null) {
        fragment = new RetainedFragment();
        fragmentManager.beginTransaction().add(fragment, tag).commit();
    }
    return fragment;
}
项目:RunMap    文件:FragmentAdapter.java   
public FragmentAdapter(FragmentManager fm) {
    super(fm);
    mFragments = new ArrayList<>();
    mFragments.add(FunctionFragment.newInstance());
    mFragments.add(PersonalFragment.newInstance());
    mFragments.add(V2MainFragment.newInstance());
}
项目:phonk    文件:BaseActivity.java   
public void changeFragment(int id, Fragment fragment) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    fragmentTransaction.replace(id, fragment);
    fragmentTransaction.commit();
}
项目:StopApp    文件:ComponentPagerAdapter.java   
public ComponentPagerAdapter(FragmentManager fm, Context context) {
    super(fm);
    mFragments = new ArrayList<>();
    tabNames = new ArrayList<>();
    tabNames.add(context.getString(R.string.component_activity));
    tabNames.add(context.getString(R.string.component_service));
    tabNames.add(context.getString(R.string.component_receiver));
    tabNames.add(context.getString(R.string.component_provider));
}
项目:MVPArms_Fragment-fragment    文件:FragmentUtils.java   
/**
 * 移除所有fragment
 */
public static void removeAllFragments(@NonNull FragmentManager fragmentManager) {
    List<Fragment> fragments = getFragments(fragmentManager);
    if (fragments.isEmpty())
        return;
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null) {
            removeAllFragments(fragment.getChildFragmentManager());
            removeFragment(fragment);
        }
    }
}
项目:GmArchMvvm    文件:FragmentUtils.java   
/**
 * Add multiple fragments
 *
 * @param fragmentManager fragment manager
 * @param fragments       fragments
 * @param containerId     Layout Id
 * @param showIndex       The fragment index to be displayed
 * @return The fragment to be displayed
 */
public static Fragment addFragments(@NonNull FragmentManager fragmentManager,
                                    @NonNull List<Fragment> fragments,
                                    @IdRes int containerId,
                                    int showIndex) {
    for (int i = 0, size = fragments.size(); i < size; ++i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null) {
            addFragment(fragmentManager, fragment, containerId, showIndex != i, false);
        }
    }
    return fragments.get(showIndex);
}
项目:MVVMArms    文件:FragmentLifecycle.java   
@Override
public void onFragmentStopped(FragmentManager fm, Fragment f) {
    super.onFragmentStopped(fm, f);
    FragmentDelegate fragmentDelegate = fetchFragmentDelegate(f);
    if (fragmentDelegate != null) {
        Timber.i("%s ---> onFragmentStopped", f.toString());
        fragmentDelegate.onStop();
    }
}
项目:aarLibrary    文件:VisibleDelegate.java   
private void dispatchSupportVisible(boolean visible) {
    mIsSupportVisible = visible;

    if (!mNeedDispatch) {
        mNeedDispatch = true;
    } else {
        FragmentManager fragmentManager = mSupportFragment.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).getVisibleDelegate().dispatchSupportVisible(visible);
                    }
                }
            }
        }
    }

    if (visible) {
        mSupportFragment.onSupportVisible();

        if (mIsFirstVisible) {
            mIsFirstVisible = false;
            mSupportFragment.onLazyInitView(mSaveInstanceState);
        }
    } else {
        mSupportFragment.onSupportInvisible();
    }
}
项目:AndroidProgramming3e    文件:SingleFragmentActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment);

    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);

    if (fragment == null) {
        fragment = createFragment();
        fm.beginTransaction()
                .add(R.id.fragment_container, fragment)
                .commit();
    }
}
项目:Bigbang    文件:BaseActivity.java   
public void switchFragment(Fragment fragment){
    if (currentFragment!=null&&currentFragment==fragment){
        return;
    }
    FragmentManager fm=getSupportFragmentManager();
    FragmentTransaction ft=fm.beginTransaction();
    if (currentFragment!=null){
        ft.hide(currentFragment);
    }
    ft.show(fragment);
    ft.commitAllowingStateLoss();
    currentFragment=fragment;
}
项目:GmArchMvvm    文件:FragmentUtils.java   
/**
 * Hide the same level fragment
 *
 * @param fragmentManager fragment manager
 */
public static void hideFragments(@NonNull FragmentManager fragmentManager) {
    List<Fragment> fragments = getFragments(fragmentManager);
    if (fragments.isEmpty())
        return;
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null)
            hideFragment(fragment);
    }
}
项目:firefox-tv    文件:MainActivity.java   
@Override
public void onClick(View view) {
    final FragmentManager fragmentManager = getSupportFragmentManager();
    final BrowserFragment fragment = (BrowserFragment) fragmentManager.findFragmentByTag(BrowserFragment.FRAGMENT_TAG);
    if (fragment == null || !fragment.isVisible()) {
        return;
    }
    switch (view.getId()) {
        case R.id.drawer_refresh_button:
            fragment.reload();
            break;
        case R.id.drawer_back_button:
            if (fragment.canGoBack()) {
                fragment.goBack();
            }
            break;
        case R.id.drawer_forward_button:
            if (fragment.canGoForward()) {
                fragment.goForward();
            }
            break;
        default:
            // Return so that we don't try to close the drawer
            return;
    }
    drawer.closeDrawer(GravityCompat.START);
}
项目:XinFramework    文件:TransactionDelegate.java   
private void startWithPop(final FragmentManager fragmentManager, final ISupportFragment from, final ISupportFragment to) {
    if (FragmentationHack.isExecutingActions(fragmentManager)) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                executeStartWithPop(fragmentManager, from, to);
            }
        });
        return;
    }

    executeStartWithPop(fragmentManager, from, to);
}
项目:NUI_Project    文件:ActivityUtils.java   
/**
 * The {@code fragment} is added to the container view with id {@code frameId}. The operation is
 * performed by the {@code fragmentManager}.
 *
 */
public static void addFragmentToActivity (@NonNull FragmentManager fragmentManager,
                                          @NonNull Fragment fragment, int frameId) {
    checkNotNull(fragmentManager);
    checkNotNull(fragment);
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(frameId, fragment);
    transaction.commit();
}
项目:GitHub    文件:BaseDialog.java   
public void show(FragmentManager fragmentManager, String tag) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Fragment prevFragment = fragmentManager.findFragmentByTag(tag);
    if (prevFragment != null) {
        transaction.remove(prevFragment);
    }
    transaction.addToBackStack(null);
    show(transaction, tag);
}
项目:IslamicLibraryAndroid    文件:BookmarkFragment.java   
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_sort:
            SortListDialogFragment sortListDialogFragment = SortListDialogFragment.newInstance(
                    R.array.bookmark_list_sorting,
                    bookmarkRecyclerViewAdapter != null ? bookmarkRecyclerViewAdapter.getmCurrentSortIndex() : 0);
            //see this answer http://stackoverflow.com/a/37794319/3061221
            FragmentManager fm = getChildFragmentManager();
            sortListDialogFragment.show(fm, "fragment_sort");
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
项目:frogment    文件:StateAwareFrogmentCallbacks.java   
@Override
public void onFragmentActivityCreated(FragmentManager fm, Fragment f, Bundle savedInstanceState) {
    super.onFragmentActivityCreated(fm, f, savedInstanceState);

    if (f instanceof StateAwareFrogment) {
        final StateAwareFrogment stateAwareFrogment = (StateAwareFrogment) f;

        stateAwareFrogment.onViewReady();
    }
}
项目:ActivityStack    文件:LifecycleUtils.java   
private void unregisterFragmentLifecycleCallback(Activity activity
        , FragmentManager.FragmentLifecycleCallbacks callbacks) {
    if (callbacks != null && activity instanceof FragmentActivity) {
        FragmentManager supportFragmentManager = ((FragmentActivity) activity).getSupportFragmentManager();
        supportFragmentManager.unregisterFragmentLifecycleCallbacks(callbacks);
    }
}
项目:AndroidProgramming3e    文件:CrimeActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_crime);

    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);

    if (fragment == null) {
        fragment = new CrimeFragment();
        fm.beginTransaction()
            .add(R.id.fragment_container, fragment)
            .commit();
    }
}
项目:easyfilemanager    文件:DetailFragment.java   
public static void showAsDialog(FragmentManager fm, DocumentInfo doc) {
final Bundle args = new Bundle();
args.putParcelable(EXTRA_DOC, doc);
args.putBoolean(EXTRA_IS_DIALOG, true);

final DetailFragment fragment = new DetailFragment();
fragment.setArguments(args);
fragment.show(fm, TAG_DETAIL);
  }
项目:AndroidProgramming3e    文件:SingleFragmentActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutResId());

    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);

    if (fragment == null) {
        fragment = createFragment();
        fm.beginTransaction()
                .add(R.id.fragment_container, fragment)
                .commit();
    }
}
项目:MVPArms_Fragment-fragment    文件:ActivityLifecycle.java   
@Override
public void onFragmentStopped(FragmentManager fm, Fragment f) {
    super.onFragmentStopped(fm, f);
    Timber.w(f.toString() + " - onFragmentStopped");
    FragmentDelegate fragmentDelegate = fetchFragmentDelegate(f);
    if (fragmentDelegate != null) {
        fragmentDelegate.onStop();
    }
}