List of usage examples for android.support.v4.app FragmentTransaction commit
public abstract int commit();
From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java
private OutputsFragment initializeOutputsFragment() { OutputsFragment fragment = (OutputsFragment) mFragmentManager.findFragmentByTag(FRAGMENT_TAG_OUTPUTS); if (fragment == null) { fragment = new OutputsFragment(); final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.replace(R.id.outputs_root_frame, fragment, FRAGMENT_TAG_OUTPUTS); ft.commit(); }/*from www. j a v a 2 s.c o m*/ return fragment; }
From source file:com.androzic.MainActivity.java
private void selectItem(int position) { if (mDrawerAdapter.getSelectedItem() == position) return;/*from w ww . jav a2s . c o m*/ DrawerItem item = mDrawerItems.get(position); // Actions if (item.type == DrawerItem.ItemType.INTENT) { if (position > 0) startActivity(item.intent); } // Fragments else if (item.type == DrawerItem.ItemType.FRAGMENT) { FragmentManager fm = getSupportFragmentManager(); if (fm.getBackStackEntryCount() > 0) { fm.popBackStackImmediate(0, FragmentManager.POP_BACK_STACK_INCLUSIVE); } FragmentTransaction ft = fm.beginTransaction(); Fragment parent = fm.findFragmentById(R.id.content_frame); if (parent != null) { ft.detach(parent); } Fragment fragment = fm.findFragmentByTag(item.name); if (fragment != null) { ft.attach(fragment); } else { ft.add(R.id.content_frame, item.fragment, item.name); } ft.commit(); // update selected item and title, then close the drawer updateDrawerUI(item, position); } else if (item.type == DrawerItem.ItemType.ACTION) { Log.e(TAG, "ACTION"); runOnUiThread(item.action); } mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java
@Override public void pushLibraryFragment(final Fragment fragment, final String label) { final String title; if (fragment instanceof BrowseFragment) { title = ((BrowseFragment) fragment).getTitle(); } else {// w ww .ja v a 2s .c o m title = fragment.toString(); } final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.replace(R.id.library_root_frame, fragment); ft.addToBackStack(label); ft.setBreadCrumbTitle(title); ft.commit(); }
From source file:com.arcgis.android.samples.geometrysample.GeometrySampleActivity.java
public void onArticleSelected(int position) { FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction(); if (bufferFrag != null && !bufferFrag.isDetached()) { fragTransaction.detach(bufferFrag); bufferFrag = null;//from w w w. j a v a2 s . com } if (uniondiffFrag != null && !uniondiffFrag.isDetached()) { fragTransaction.detach(uniondiffFrag); uniondiffFrag = null; } if (spatialrelationFrag != null && !spatialrelationFrag.isDetached()) { fragTransaction.detach(spatialrelationFrag); spatialrelationFrag = null; } switch (position) { case 0: if (bufferFrag == null || bufferFrag.getShownIndex() != position) { // Make new fragment to show this selection. bufferFrag = BufferFragment.newInstance(position); // Execute a transaction, replacing any existing fragment // with this one inside the frame. fragTransaction.add(R.id.sample_fragment, bufferFrag); fragTransaction.setTransition(FragmentTransaction.TRANSIT_NONE); fragTransaction.commit(); } break; case 1: if (uniondiffFrag == null || uniondiffFrag.getShownIndex() != position) { // Make new fragment to show this selection. uniondiffFrag = UnionDifferenceFragment.newInstance(position); // Execute a transaction, replacing any existing fragment // with this one inside the frame. fragTransaction.add(R.id.sample_fragment, uniondiffFrag); fragTransaction.setTransition(FragmentTransaction.TRANSIT_NONE); fragTransaction.commit(); } break; case 2: if (spatialrelationFrag == null || spatialrelationFrag.getShownIndex() != position) { // Make new fragment to show this selection. spatialrelationFrag = SpatialRelationshipsFragment.newInstance(position); // Execute a transaction, replacing any existing fragment // with this one inside the frame. fragTransaction.add(R.id.sample_fragment, spatialrelationFrag); fragTransaction.setTransition(FragmentTransaction.TRANSIT_NONE); fragTransaction.commit(); } break; default: break; } }
From source file:com.asy.animations.ui.fragment.HeroesMainActivity.java
public void goToHeroeDetail(Heroe heroe, HeroesAdapter.Holder holder) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); heroeDetailFragment = HeroeDetailFragment.newInstance(heroe); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Inflate transitions to apply Transition changeTransform = TransitionInflater.from(this) .inflateTransition(R.transition.change_image_transform); Transition explodeTransform = TransitionInflater.from(this) .inflateTransition(android.R.transition.explode); // // Setup exit transition on first fragment heroesListFragment.setSharedElementReturnTransition(changeTransform); heroesListFragment.setExitTransition(explodeTransform); // Setup enter transition on second fragment heroeDetailFragment.setSharedElementEnterTransition(changeTransform); heroeDetailFragment.setEnterTransition(explodeTransform); transaction.addSharedElement(holder.getIvAvatar(), getString(R.string.transition_avatar)); }//from w w w . j a va2s .c o m transaction.addToBackStack(null); transaction.replace(R.id.main_container, heroeDetailFragment); transaction.commit(); }
From source file:com.abid_mujtaba.fetchheaders.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/* ww w . j a v a2 s . c o m*/ if (savedInstanceState != null) // If the passed in state information bundle is non-empty we expect it to contain the saved value of fShowSeen. We also pass in a default value. { fShowSeen = savedInstanceState.getBoolean(BUNDLE_FLAG_SHOW_SEEN, false); } scrollList = (LinearLayout) findViewById(R.id.scrollList); if (mTTS == null) // If onCreate is called multiple times we do NOT want to create multiple TextToSpeech objects { mTTS = new TextToSpeech(this, this); } if (Account.numberOfAccounts() > 0) // Accounts have been specified { TextView tvEmpty = (TextView) findViewById(R.id.txtNoAccounts); // We start by removing the No Accounts view since accounts are present scrollList.removeView(tvEmpty); FragmentManager fM = getSupportFragmentManager(); FragmentTransaction fT = fM.beginTransaction(); for (int ii = 0; ii < Account.numberOfAccounts(); ii++) { String tag = "TAG_" + ii; // This is the tag we will use to get a handle on the fragment in the FragmentManager AccountFragment aF = (AccountFragment) fM.findFragmentByTag(tag); // We attempt to access the fragment via the specified tag if (aF == null) // This indicates that the Fragment does not exist yet so we create it. It has setRetainInstance(true) so it persists across configuration changes. { aF = AccountFragment.newInstance(ii); fT.add(R.id.scrollList, aF, tag); // Note: The addition to the scrollList only happens when aF == null, which happens when the persistent fragment has not been created yet } // Since Views retain state across config changes the scrollList remembers that it has fragments added to it mFragments.add(aF); } fT.commit(); } }
From source file:com.appybite.customer.AllowedHotels.java
public void removeFragment(Fragment fg) { if (fg == null) return;/* w ww . j av a2 s.c o m*/ FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.remove(fg); ft.commit(); }
From source file:com.awrtechnologies.carbudgetsales.MainActivity.java
public void back() { currentfragment = fragmentstack.pop(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right); ft.replace(R.id.contanier, currentfragment); ft.commit(); }
From source file:com.awrtechnologies.carbudgetsales.MainActivity.java
public void openFragment(Fragment f) { try {/*from ww w .ja v a 2s . c o m*/ InputMethodManager input = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); input.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0); } catch (Exception e) { } FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left); ft.replace(R.id.contanier, f); currentfragment = f; ft.commit(); }
From source file:com.andreadec.musicplayer.MainActivity.java
private void openPage(int page) { MusicPlayerFragment fragment;/* w w w .j a v a 2 s . co m*/ switch (page) { case PAGE_BROWSER: fragment = new BrowserFragment(); break; case PAGE_PLAYLISTS: fragment = new PlaylistFragment(); break; case PAGE_RADIOS: fragment = new RadioFragment(); break; case PAGE_PODCASTS: fragment = new PodcastsFragment(); break; default: return; } currentPage = page; currentFragment = fragment; FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.remove(currentFragment); transaction.replace(R.id.page, fragment); transaction.addToBackStack(null); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.commit(); fragmentManager.executePendingTransactions(); drawerList.setItemChecked(currentPage, true); setTitle(pages[currentPage]); }