List of usage examples for android.app FragmentManager popBackStack
public abstract void popBackStack();
From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java
private void hideFragment(final Fragment fragment, final boolean removeParentView, final boolean addedToBackStack, final String tag) { final FragmentManager manager = getFragmentManager(); if (manager.findFragmentByTag(tag) != null) { final FragmentTransaction transaction = manager.beginTransaction(); transaction.remove(fragment);/*from w ww .ja v a 2s . c o m*/ transaction.commit(); if (addedToBackStack) { manager.popBackStack(); } final int viewId = getParentId(fragment); if (removeParentView && viewId != 0) { mContentContainer.removeBorderView(viewId); } } }
From source file:com.lgallardo.qbittorrentclient.ItemstFragment.java
private void newDetailsFragment(int position) { detailsFragment = new TorrentDetailsFragment(); // Get torrent from MainActivity detailsFragment.setTorrent(MainActivity.lines[position]); detailsFragment.setPosition(position); if (detailsFragment != null) { FragmentManager fragmentManager = getFragmentManager(); if (getActivity().findViewById(R.id.one_frame) != null) { fragmentManager.beginTransaction() .replace(this.getSecondFragmentContainer(), detailsFragment, "firstFragment") .addToBackStack("secondFragment").commit(); // Change toolbar home button behaviour originalListener = MainActivity.drawerToggle.getToolbarNavigationClickListener(); MainActivity.drawerToggle.setDrawerIndicatorEnabled(false); MainActivity.drawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer); MainActivity.drawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override//from w w w. ja v a2 s. c o m public void onClick(View v) { // Disable refreshing MainActivity.disableRefreshSwipeLayout(); // Set default toolbar behaviour ((MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true); MainActivity.drawerToggle.setDrawerIndicatorEnabled(true); MainActivity.drawerToggle.setToolbarNavigationClickListener(originalListener); ((MainActivity) getActivity()).setSelectionAndTitle(MainActivity.currentState); // Show herderInfo in phone's view if (getActivity().findViewById(R.id.one_frame) != null) { if (MainActivity.headerInfo != null) { if (MainActivity.header) { MainActivity.headerInfo.setVisibility(View.VISIBLE); } else { MainActivity.headerInfo.setVisibility(View.GONE); } } } FragmentManager fm = getFragmentManager(); fm.popBackStack(); } }); } else { fragmentManager.beginTransaction() .replace(this.getSecondFragmentContainer(), detailsFragment, "secondFragment") .addToBackStack("secondFragment").commit(); } } }
From source file:cx.ring.client.HomeActivity.java
private void popCustomBackStack() { FragmentManager fm = getFragmentManager(); FragmentManager.BackStackEntry entry = fm.getBackStackEntryAt(0); fContent = fm.findFragmentByTag(entry.getName()); for (int i = 0; i < fm.getBackStackEntryCount() - 1; ++i) { fm.popBackStack(); }/*from ww w. ja v a 2s . co m*/ }
From source file:me.raatiniemi.worker.presentation.settings.view.SettingsActivity.java
@Override public void onBackPressed() { FragmentManager fragmentManager = getFragmentManager(); // Depending on which fragment is contained within the // container, the back button will behave differently. Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_container); Class<SettingsFragment> settings = SettingsFragment.class; if (!settings.equals(fragment.getClass())) { fragmentManager.popBackStack(); } else {//from w ww .j a v a 2s .c o m super.onBackPressed(); } }
From source file:by.zatta.pilight.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { /*//from w ww . ja v a2s. c o m * The action bar home/up should open or close the drawer. ActionBarDrawerToggle will take care of this. */ publishList(); if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); switch (item.getItemId()) { case R.id.menu_about: openDialogFragment(AboutDialog.newInstance()); return true; case R.id.menu_settings: Fragment pref = fm.findFragmentByTag("prefs"); if (pref == null) { ft.replace(R.id.fragment_main, new PrefFragment(), "prefs"); fm.popBackStack(); ft.addToBackStack(null); ft.commit(); } else { ft.remove(fm.findFragmentByTag("prefs")); ft.commit(); fm.popBackStack(); } return true; default: break; } // Handle your other action bar items... return super.onOptionsItemSelected(item); }
From source file:org.symptomcheck.capstone.ui.MainActivityOld.java
@Override public void onBackPressed() { if (mFabActionsMenu.isExpanded()) { mFabActionsMenu.collapse();/*from www . java2 s. c om*/ } else { // initialize variables FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); // check to see if stack is empty if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); ft.commit(); // } else { // askForExit(); } else { if (mDoubleBackToExitPressedOnce) { super.onBackPressed(); return; } this.mDoubleBackToExitPressedOnce = true; Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show(); new Handler().postDelayed(new Runnable() { @Override public void run() { mDoubleBackToExitPressedOnce = false; } }, 2000); } } }
From source file:it.scoppelletti.mobilepower.app.FragmentLayoutController.java
/** * Ripristina lo stato dell’istanza. * /*from w w w. ja v a 2 s. c om*/ * <P>L’attività ripristina lo stato dell’istanza * {@code FragmentLayoutController} all’interno del proprio metodo * {@code onRestoreInstanceState}.</P> * * @param savedInstanceState Stato dell’istanza. * @param fragmentCollector Collettore dei frammenti di dettaglio. */ public void onRestoreInstanceState(Bundle savedInstanceState, FragmentLayoutController.FragmentCollector fragmentCollector) { int n, oldPanelCount, tnId; String tag; ActivitySupport activitySupport; FragmentSupport fragment; FragmentManager fragmentMgr; FragmentLayoutController.BackStackChangedListener backStackListener; Queue<FragmentSupport> fragmentQueue; Queue<FragmentLayoutController.FragmentEntry> clonedQueue; if (savedInstanceState == null) { throw new NullPointerException("Argument savedInstanceState is null."); } if (fragmentCollector == null) { throw new NullPointerException("Argument fragmentCollector is null."); } if (!(myActivity instanceof ActivitySupport)) { myLogger.warn("Activity not implement interface ActivitySupport."); return; } oldPanelCount = savedInstanceState.getInt(FragmentLayoutController.STATE_PANELCOUNT, 0); if (oldPanelCount < 1) { myLogger.warn("Unexpected {}={} in saved instance state.", FragmentLayoutController.STATE_PANELCOUNT, oldPanelCount); return; } myLogger.debug("{}: current={}, saved instance state={}.", new Object[] { FragmentLayoutController.STATE_PANELCOUNT, myFrameCount, oldPanelCount }); if (oldPanelCount == myFrameCount) { // Il numero di pannelli non e' cambiato: // Il sistema ha gia' ripristinato correttamente i frammenti. return; } fragmentQueue = new ArrayDeque<FragmentSupport>(); fragmentCollector.collectFragments(fragmentQueue); // Ad ogni frammento associo il tag con il quale è stato // inserito clonedQueue = new ArrayDeque<FragmentLayoutController.FragmentEntry>(); while (!fragmentQueue.isEmpty()) { fragment = fragmentQueue.remove(); if (fragment == null) { myLogger.warn("Ignoring null."); continue; } tag = fragment.asFragment().getTag(); if (StringUtils.isBlank(tag)) { myLogger.warn("Ignoring fragment with empty tag."); continue; } clonedQueue.offer(new FragmentLayoutController.FragmentEntry(fragment.cloneFragment(), tag)); } fragmentQueue = null; // free memory activitySupport = (ActivitySupport) myActivity; fragmentMgr = activitySupport.getSupportFragmentManager(); // Ripristino la configurazione dei frammenti iniziale for (n = fragmentMgr.getBackStackEntryCount(); n > 0; n--) { fragmentMgr.popBackStack(); } if (myFrameCount > 1) { tnId = arrangeFragments(fragmentMgr, clonedQueue); } else { tnId = arrangePanel(fragmentMgr, clonedQueue); } if (Build.VERSION.SDK_INT < BuildCompat.VERSION_CODES.HONEYCOMB) { return; } // - Android 4.1.2 // La barra delle azioni non e' correttamente aggiornata forse perche' // si assume che non ce ne sia bisogno con transazioni schedulate // durante il ripristino dell'attivita' (o magari perche' non e' proprio // previsto che si schedulino transazioni durante il ripristino // dell'attivita'): // Visto che l'esecuzione delle transazioni e' asincrona, devo // utilizzare un gestore degli eventi di modifica del back stack che // gestisca l’ultima transazione che ho schedulato. backStackListener = new FragmentLayoutController.BackStackChangedListener(myActivity, fragmentMgr, tnId); fragmentMgr.addOnBackStackChangedListener(backStackListener); }
From source file:de.sourcestream.movieDB.MainActivity.java
/** * Pops the last item from the back stack. * If searchView is opened it hides it./* w w w . j a v a2 s. co m*/ * reAttachMovieFragments re-creates our fragments this is due to a bug in the viewPager * restoreMovieDetailsState -> when we press back button we would like to restore our previous (if any) * saved state for the current fragment. We use custom backStack since the original doesn't save fragment's state. */ @Override public void onBackPressed() { FragmentManager fm = getFragmentManager(); if (mDrawerLayout.isDrawerOpen(mDrawerList)) mDrawerLayout.closeDrawer(mDrawerList); else { if (searchViewItem.isActionViewExpanded()) searchViewItem.collapseActionView(); else if (fm.getBackStackEntryCount() > 0) { String backStackEntry = fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName(); if (backStackEntry.equals("movieList")) reAttachMovieFragments = true; if (backStackEntry.equals("TVList")) reAttachTVFragments = true; if (backStackEntry.equals("searchList:1")) reAttachMovieFragments = true; if (backStackEntry.equals("searchList:2")) reAttachTVFragments = true; restoreMovieDetailsState = true; restoreMovieDetailsAdapterState = false; if (orientationChanged) restoreMovieDetailsAdapterState = true; fm.popBackStack(); } else { super.onBackPressed(); } } }
From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java
private void selectItem(int position) { if (findViewById(R.id.one_frame) != null) { FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager.findFragmentByTag( "firstFragment") instanceof com.lgallardo.youtorrentcontroller.TorrentDetailsFragment) { // Reset back button stack for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) { fragmentManager.popBackStack(); }/*from www.ja v a 2s . co m*/ } } // switch (position-1) { // case 0: // // Set the refresh layout (refresh icon, etc) // refreshSwipeLayout(); // refresh("all"); // saveLastState("all"); // break; // case 1: // // Set the refresh layout (refresh icon, etc) // refreshSwipeLayout(); // refresh("downloading"); // saveLastState("downloading"); // break; // case 2: // // Set the refresh layout (refresh icon, etc) // refreshSwipeLayout(); // refresh("completed"); // saveLastState("completed"); // break; // case 3: // // Set the refresh layout (refresh icon, etc) // refreshSwipeLayout(); // refresh("pause"); // saveLastState("pause"); // break; // case 4: // // Set the refresh layout (refresh icon, etc) // refreshSwipeLayout(); // refresh("active"); // saveLastState("active"); // break; // case 5: // // Set the refresh layout (refresh icon, etc) // refreshSwipeLayout(); // refresh("inactive"); // saveLastState("inactive"); // break; // case 6: ////TODO: Uncomment to add options, and +1 to each case //// // Options - Execute the task in background //// Toast.makeText(getApplicationContext(), R.string.getQBittorrentPrefefrences, Toast.LENGTH_SHORT).show(); //// qBittorrentOptions qso = new qBittorrentOptions(); //// qso.execute(new String[]{qbQueryString + "/preferences", "setOptions"}); //// break; //// case 7: // // Settings // openSettings(); // break; // case 7: // if (packageName.equals("com.lgallardo.youtorrentcontroller")) { // // Get Pro version // getPRO(); // }else { // openHelp(); // } // break; // case 8: // openHelp(); // break; // default: // break; // // } // // if (position < 6) { // // Set checked item //// drawerList.setItemChecked(position, true); //// drawerList.setSelection(position); // mRecyclerView.findViewHolderForAdapterPosition(position+1).itemView.performClick(); // setTitle(navigationDrawerItemTitles[position]); // }else{ // // Set current selection // saveLastState(currentState); // setSelectionAndTitle(currentState); // }x // //// drawerLayout.closeDrawer(drawerList); // drawerLayout.closeDrawer(mRecyclerView); // // // Load banner // loadBanner(); }
From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java
@Override public void onBackPressed() { // If drawer is opened, close it // if(drawerLayout.isDrawerOpen(drawerList)){ // drawerLayout.closeDrawer(drawerList); if (drawerLayout.isDrawerOpen(mRecyclerView)) { drawerLayout.closeDrawer(mRecyclerView); return;//from www . ja v a 2 s .c o m } FragmentManager fm = getFragmentManager(); com.lgallardo.youtorrentcontroller.ItemstFragment fragment = null; // Close Contextual Action Bar if (com.lgallardo.youtorrentcontroller.ItemstFragment.mActionMode != null) { com.lgallardo.youtorrentcontroller.ItemstFragment.mActionMode.finish(); } else { if (fm.getBackStackEntryCount() == 0) { // Set About first load to true AboutFragment.isFragmentFirstLoaded = true; // Close the app this.finish(); } else { // Disable refreshing disableRefreshSwipeLayout(); // Enable toolbar title getSupportActionBar().setDisplayShowTitleEnabled(true); fm.popBackStack(); } } if (findViewById(R.id.one_frame) != null) { getSupportActionBar().setDisplayShowTitleEnabled(true); MainActivity.drawerToggle.setDrawerIndicatorEnabled(true); MainActivity.drawerToggle.setToolbarNavigationClickListener(ItemstFragment.originalListener); // Set title setSelectionAndTitle(MainActivity.currentState); if (headerInfo != null) { if (header) { headerInfo.setVisibility(View.VISIBLE); } else { headerInfo.setVisibility(View.GONE); } } } }