List of usage examples for android.app FragmentManager executePendingTransactions
public abstract boolean executePendingTransactions();
From source file:com.android.mail.ui.OnePaneController.java
/** * Replace the content_pane with the fragment specified here. The tag is specified so that * the {@link ActivityController} can look up the fragments through the * {@link android.app.FragmentManager}.// w w w . jav a 2 s . c o m * @param fragment the new fragment to put * @param transition the transition to show * @param tag a tag for the fragment manager. * @param anchor ID of view to replace fragment in * @return transaction ID returned when the transition is committed. */ private int replaceFragment(Fragment fragment, int transition, String tag, int anchor) { final FragmentManager fm = mActivity.getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.setTransition(transition); fragmentTransaction.replace(anchor, fragment, tag); final int id = fragmentTransaction.commitAllowingStateLoss(); fm.executePendingTransactions(); return id; }
From source file:net.sf.sprockets.app.ui.PanesActivity.java
/** * Use your own layout for the panes./*from w w w. j ava2 s .c o m*/ * * @param pagerId {@code R.id} value for the ViewPager in the single pane layout * @param pane1Id {@code R.id} value for the first pane in the multi-pane layout * @param pane2Id {@code R.id} value for the second pane in the multi-pane layout */ public void setContentView(int layoutResId, int pagerId, int pane1Id, int pane2Id) { setContentView(layoutResId); Fragment pane1 = findFragmentByPane(1); Fragment pane2 = findFragmentByPane(2); ViewPager pager = findById(this, pagerId); /* do we need to move the fragments between the single and multi-pane layouts? */ FragmentManager fm = getFragmentManager(); FragmentTransaction ft = null; if (pane2 == null) { pane2 = getFragment(2); } else if (pane2.getId() != (pager != null ? pagerId : pane2Id)) { ft = fm.beginTransaction().remove(pane2); // remove in reverse to preserve indices } if (pane1 == null) { pane1 = getFragment(1); } else if (pane1.getId() != (pager != null ? pagerId : pane1Id)) { if (ft == null) { ft = fm.beginTransaction(); } ft.remove(pane1); } if (ft != null) { ft.commitAllowingStateLoss(); fm.executePendingTransactions(); // force removes so can add to a different container } /* add the fragments to the panes */ if (pager != null) { pager.setAdapter(new PanesAdapter(pane1, pane2)); } else { ft = null; if (pane1.getId() != pane1Id) { ft = Fragments.open(this).add(pane1Id, pane1, PANE_1); } if (pane2.getId() != pane2Id) { if (ft == null) { ft = Fragments.open(this); } ft.add(pane2Id, pane2, PANE_2); } if (ft != null) { ft.commitAllowingStateLoss(); } } }
From source file:systems.soapbox.ombuds.client.ui.AddressBookActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.address_book_content); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); super.setAnimateOnPause(true); final FragmentManager fragmentManager = getFragmentManager(); walletAddressesFragment = (WalletAddressesFragment) fragmentManager.findFragmentByTag(TAG_LEFT); sendingAddressesFragment = (SendingAddressesFragment) fragmentManager.findFragmentByTag(TAG_RIGHT); final FragmentTransaction removal = fragmentManager.beginTransaction(); if (walletAddressesFragment == null) walletAddressesFragment = new WalletAddressesFragment(); else//w w w. j av a 2 s . c o m removal.remove(walletAddressesFragment); if (sendingAddressesFragment == null) sendingAddressesFragment = new SendingAddressesFragment(); else removal.remove(sendingAddressesFragment); if (!removal.isEmpty()) { removal.commit(); fragmentManager.executePendingTransactions(); } final ViewPager pager = (ViewPager) findViewById(R.id.address_book_pager); if (pager != null) { pager.setAdapter( new TwoFragmentAdapter(fragmentManager, walletAddressesFragment, sendingAddressesFragment)); final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.address_book_pager_tabs); pagerTabs.addTabLabels(R.string.address_book_list_receiving_title, R.string.address_book_list_sending_title); pager.setOnPageChangeListener(pagerTabs); final int position = 1; pager.setCurrentItem(position); pager.setPageMargin(2); pager.setPageMarginDrawable(R.color.bg_less_bright); pagerTabs.onPageSelected(position); pagerTabs.onPageScrolled(position, 0, 0); } else { fragmentManager.beginTransaction() .add(R.id.wallet_addresses_fragment, walletAddressesFragment, TAG_LEFT) .add(R.id.sending_addresses_fragment, sendingAddressesFragment, TAG_RIGHT).commit(); } updateFragments(); }
From source file:biz.wiz.android.wallet.ui.AddressBookActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.address_book_content); final ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); final FragmentManager fragmentManager = getFragmentManager(); walletAddressesFragment = (WalletAddressesFragment) fragmentManager.findFragmentByTag(TAG_LEFT); sendingAddressesFragment = (SendingAddressesFragment) fragmentManager.findFragmentByTag(TAG_RIGHT); final FragmentTransaction removal = fragmentManager.beginTransaction(); if (walletAddressesFragment == null) walletAddressesFragment = new WalletAddressesFragment(); else/*from w ww. j av a 2 s .c o m*/ removal.remove(walletAddressesFragment); if (sendingAddressesFragment == null) sendingAddressesFragment = new SendingAddressesFragment(); else removal.remove(sendingAddressesFragment); if (!removal.isEmpty()) { removal.commit(); fragmentManager.executePendingTransactions(); } final ViewPager pager = (ViewPager) findViewById(R.id.address_book_pager); if (pager != null) { pager.setAdapter( new TwoFragmentAdapter(fragmentManager, walletAddressesFragment, sendingAddressesFragment)); final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.address_book_pager_tabs); pagerTabs.addTabLabels(R.string.address_book_list_receiving_title, R.string.address_book_list_sending_title); pager.setOnPageChangeListener(pagerTabs); final int position = 1; pager.setCurrentItem(position); pager.setPageMargin(2); pager.setPageMarginDrawable(R.color.bg_less_bright); pagerTabs.onPageSelected(position); pagerTabs.onPageScrolled(position, 0, 0); } else { fragmentManager.beginTransaction() .add(R.id.wallet_addresses_fragment, walletAddressesFragment, TAG_LEFT) .add(R.id.sending_addresses_fragment, sendingAddressesFragment, TAG_RIGHT).commit(); } updateFragments(); }
From source file:com.android.mail.ui.TwoPaneController.java
@Override public void launchFragment(final Fragment fragment, final int selectPosition) { final int containerViewId = TwoPaneLayout.MISCELLANEOUS_VIEW_ID; final FragmentManager fragmentManager = mActivity.getFragmentManager(); if (fragmentManager.findFragmentByTag(TAG_CUSTOM_FRAGMENT) == null) { final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.addToBackStack(null); fragmentTransaction.replace(containerViewId, fragment, TAG_CUSTOM_FRAGMENT); mMiscellaneousViewTransactionId = fragmentTransaction.commitAllowingStateLoss(); fragmentManager.executePendingTransactions(); }/* w w w . j av a 2s . c om*/ if (selectPosition >= 0) { getConversationListFragment().setRawSelected(selectPosition, true); } }
From source file:com.matthewmitchell.peercoin_android_wallet.ui.AddressBookActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.address_book_content); final ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); final FragmentManager fragmentManager = getFragmentManager(); walletAddressesFragment = (WalletAddressesFragment) fragmentManager.findFragmentByTag(TAG_LEFT); sendingAddressesFragment = (SendingAddressesFragment) fragmentManager.findFragmentByTag(TAG_RIGHT); final FragmentTransaction removal = fragmentManager.beginTransaction(); if (walletAddressesFragment == null) walletAddressesFragment = new WalletAddressesFragment(); else//from w w w . j av a2 s . c o m removal.remove(walletAddressesFragment); if (sendingAddressesFragment == null) sendingAddressesFragment = new SendingAddressesFragment(); else removal.remove(sendingAddressesFragment); if (!removal.isEmpty()) { removal.commit(); fragmentManager.executePendingTransactions(); } final ViewPager pager = (ViewPager) findViewById(R.id.address_book_pager); if (pager != null) { pager.setAdapter( new TwoFragmentAdapter(fragmentManager, walletAddressesFragment, sendingAddressesFragment)); final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.address_book_pager_tabs); pagerTabs.addTabLabels(R.string.address_book_list_receiving_title, R.string.address_book_list_sending_title); pager.setOnPageChangeListener(pagerTabs); final int position = 1; pager.setCurrentItem(position); pager.setPageMargin(2); pager.setPageMarginDrawable(R.color.bg_less_bright); pagerTabs.onPageSelected(position); pagerTabs.onPageScrolled(position, 0, 0); } else { fragmentManager.beginTransaction() .add(R.id.wallet_addresses_fragment, walletAddressesFragment, TAG_LEFT) .add(R.id.sending_addresses_fragment, sendingAddressesFragment, TAG_RIGHT).commit(); } runAfterLoad(new Runnable() { @Override public void run() { updateFragments(); } }); }
From source file:us.cboyd.android.dicom.DcmBrowser.java
/** Called when the activity is first created. */ @Override//from w ww .j a va 2s.c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dcm_browser); FragmentManager fragManager = getFragmentManager(); if (savedInstanceState != null) { mListFragment = (DcmListFragment) fragManager.getFragment(savedInstanceState, DcmVar.FRAGLIST); mInfoFragment = (DcmInfoFragment) fragManager.getFragment(savedInstanceState, DcmVar.FRAGINFO); // Remove existing fragments from associated views. fragManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); fragManager.beginTransaction().remove(mListFragment).commit(); fragManager.beginTransaction().remove(mInfoFragment).commit(); fragManager.executePendingTransactions(); } // Restore the retained fragments, if this is a configuration change. if (mListFragment == null) { mListFragment = new DcmListFragment(); } if (mInfoFragment == null) { mInfoFragment = new DcmInfoFragment(); } // Specify that the Home/Up button should not be enabled, // since there is no hierarchical parent yet. ActionBar actionBar = getActionBar(); // enable ActionBar app icon to behave as action to toggle nav drawer actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setHomeButtonEnabled(false); // Check whether the activity is using the layout version with // the fragment_container FrameLayout. If so, we must add the first fragment if (findViewById(R.id.fragment_container) != null) { Log.i("cpb", "mListFrag: One-pane"); mFragmented = true; // Add the fragment to the 'fragment_container' FrameLayout fragManager.beginTransaction().add(R.id.fragment_container, mListFragment).commit(); generateDrawer(); } else { Log.i("cpb", "mListFrag: Two-pane"); mFragmented = false; // Add the fragments to the respective FrameLayouts fragManager.beginTransaction().add(R.id.fragment_left, mListFragment).commit(); fragManager.beginTransaction().add(R.id.fragment_right, mInfoFragment).commit(); } }
From source file:com.zte.permissioncontrol.ui.PermissionControlPageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.permission_control_pages); mEmptyView = (FrameLayout) findViewById(R.id.empty_view); mSavedInstanceState = savedInstanceState; // add the switch on Action bar LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); mSwitch = (Switch) inflater.inflate(R.layout.imageswitch_layout, null); final int padding = getResources().getDimensionPixelSize(R.dimen.action_bar_switch_padding); mSwitch.setPadding(0, 0, padding, 0); getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM); getActionBar().setCustomView(mSwitch, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END)); mSwitch.setOnCheckedChangeListener(this); // hide fragment firstly , then update it in onResume() according to switch status final FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); mPermissionsFragment = (PermissionsFragment) fragmentManager.findFragmentByTag(mPermissionsTag); mAppsFragment = (AppsFragment) fragmentManager.findFragmentByTag(mAppsTag); if (mPermissionsFragment == null) { mPermissionsFragment = new PermissionsFragment(); mAppsFragment = new AppsFragment(); transaction.add(R.id.tab_pager, mPermissionsFragment, mPermissionsTag); transaction.add(R.id.tab_pager, mAppsFragment, mAppsTag); }// w ww. j a v a2 s . c o m transaction.hide(mPermissionsFragment); transaction.hide(mAppsFragment); transaction.commit(); fragmentManager.executePendingTransactions(); // set page adapter mTabPager = (ViewPager) findViewById(R.id.tab_pager); mTabPagerAdapter = new TabPagerAdapter(); mTabPager.setAdapter(mTabPagerAdapter); mTabPager.setOnPageChangeListener(mTabPagerListener); // Configure action bar mActionBarAdapter = new ActionBarAdapter(this, this, getActionBar()); boolean isShow = PermControlUtils.isPermControlOn(this); Log.d(TAG, "oncreate(), isShow " + isShow); }
From source file:com.github.chenxiaolong.dualbootpatcher.MainActivity.java
private void hideFragments(boolean animate) { FragmentManager fm = getFragmentManager(); Fragment prevRoms = fm.findFragmentByTag(SwitcherListFragment.TAG); Fragment prevPatchFile = fm.findFragmentByTag(PatchFileFragment.TAG); Fragment prevFreeSpace = fm.findFragmentByTag(FreeSpaceFragment.TAG); Fragment prevAbout = fm.findFragmentByTag(AboutFragment.TAG); FragmentTransaction ft = fm.beginTransaction(); if (animate) { ft.setCustomAnimations(0, R.animator.fragment_out); }// ww w. j a v a 2s . c om if (prevRoms != null) { ft.hide(prevRoms); } if (prevPatchFile != null) { ft.hide(prevPatchFile); } if (prevFreeSpace != null) { ft.hide(prevFreeSpace); } if (prevAbout != null) { ft.hide(prevAbout); } ft.commit(); fm.executePendingTransactions(); }
From source file:com.chen.mail.ui.OnePaneController.java
@Override protected void showConversation(Conversation conversation, boolean inLoaderCallbacks) { super.showConversation(conversation, inLoaderCallbacks); mConversationListVisible = false;//from w w w . ja va2 s. com if (conversation == null) { transitionBackToConversationListMode(); return; } disableCabMode(); if (ConversationListContext.isSearchResult(mConvListContext)) { mViewMode.enterSearchResultsConversationMode(); } else { mViewMode.enterConversationMode(); } final FragmentManager fm = mActivity.getFragmentManager(); final FragmentTransaction ft = fm.beginTransaction(); // Switching to conversation view is an incongruous transition: // we are not replacing a fragment with another fragment as // usual. Instead, reveal the heretofore inert conversation // ViewPager and just remove the previously visible fragment // e.g. conversation list, or possibly label list?). final Fragment f = fm.findFragmentById(R.id.content_pane); // FragmentManager#findFragmentById can return fragments that are not added to the activity. // We want to make sure that we don't attempt to remove fragments that are not added to the // activity, as when the transaction is popped off, the FragmentManager will attempt to // readd the same fragment twice if (f != null && f.isAdded()) { ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.remove(f); ft.commitAllowingStateLoss(); fm.executePendingTransactions(); } mPagerController.show(mAccount, mFolder, conversation, true /* changeVisibility */); onConversationVisibilityChanged(true); onConversationListVisibilityChanged(false); }