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(); }
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(); }
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(); } }
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); }
/** * 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(); }
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); } }
/** * 新增多个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); }
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); } }
/** * 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; }
@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(); }
@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; } }
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)); }
/** * 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(); }
@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; }
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; }
@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(); } }
/** * 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(); }
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); }
@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; }
public FragmentAdapter(FragmentManager fm) { super(fm); mFragments = new ArrayList<>(); mFragments.add(FunctionFragment.newInstance()); mFragments.add(PersonalFragment.newInstance()); mFragments.add(V2MainFragment.newInstance()); }
public void changeFragment(int id, Fragment fragment) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(id, fragment); fragmentTransaction.commit(); }
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)); }
/** * 移除所有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); } } }
/** * 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); }
@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(); } }
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(); } }
@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(); } }
public void switchFragment(Fragment fragment){ if (currentFragment!=null&¤tFragment==fragment){ return; } FragmentManager fm=getSupportFragmentManager(); FragmentTransaction ft=fm.beginTransaction(); if (currentFragment!=null){ ft.hide(currentFragment); } ft.show(fragment); ft.commitAllowingStateLoss(); currentFragment=fragment; }
/** * 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); } }
@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); }
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); }
/** * 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(); }
@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); } }
@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(); } }
private void unregisterFragmentLifecycleCallback(Activity activity , FragmentManager.FragmentLifecycleCallbacks callbacks) { if (callbacks != null && activity instanceof FragmentActivity) { FragmentManager supportFragmentManager = ((FragmentActivity) activity).getSupportFragmentManager(); supportFragmentManager.unregisterFragmentLifecycleCallbacks(callbacks); } }
@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(); } }
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); }
@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(); } }