Example usage for android.app FragmentTransaction addToBackStack

List of usage examples for android.app FragmentTransaction addToBackStack

Introduction

In this page you can find the example usage for android.app FragmentTransaction addToBackStack.

Prototype

public abstract FragmentTransaction addToBackStack(@Nullable String name);

Source Link

Document

Add this transaction to the back stack.

Usage

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

public void showFilter() {
    final FragmentManager fm = getFragmentManager();
    FragmentTransaction ft;

    final Fragment fragment = new RMBTFilterFragment();

    ft = fm.beginTransaction();/*from w ww  .  j  ava  2s. c  o m*/
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_HISTORY_FILTER);
    ft.addToBackStack(AppConstants.PAGE_TITLE_HISTORY_FILTER);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();

    refreshActionBar(AppConstants.PAGE_TITLE_HISTORY_FILTER);
}

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
 * information commissioner check//  w w w.j  a va 2  s.  c  o m
 */
public void showIcCheck() {
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.fragment_content, RMBTCheckFragment.newInstance(CheckType.INFORMATION_COMMISSIONER),
            AppConstants.PAGE_TITLE_CHECK_INFORMATION_COMMISSIONER);
    ft.addToBackStack(AppConstants.PAGE_TITLE_CHECK_INFORMATION_COMMISSIONER);
    ft.commit();
}

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
 * //from   w  ww.  ja  v  a2 s .com
 * @param popStack
 */
public void startTest(final boolean popStack) {
    if (networkInfoCollector != null) {
        if (!networkInfoCollector.hasConnectionFromAndroidApi()) {
            showNoNetworkConnectionToast();
            return;
        }
    }

    final boolean loopMode = ConfigHelper.isLoopMode(this);
    if (loopMode) {
        startService(new Intent(this, RMBTLoopService.class));
    } else {
        FragmentTransaction ft;
        ft = fm.beginTransaction();
        final RMBTTestFragment rmbtTestFragment = new RMBTTestFragment();
        ft.replace(R.id.fragment_content, rmbtTestFragment, AppConstants.PAGE_TITLE_TEST);
        ft.addToBackStack(AppConstants.PAGE_TITLE_TEST);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        if (popStack)
            fm.popBackStack();
        ft.commit();

        final Intent service = new Intent(RMBTService.ACTION_START_TEST, null, this, RMBTService.class);
        startService(service);
    }
}

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

public void showHelp(final String url, boolean popBackStack, String titleId) {
    if (popBackStack) {
        popBackStackFull();//from   w  w w. j av  a2 s  . co  m
    }

    FragmentTransaction ft;

    ft = fm.beginTransaction();

    final Fragment fragment = new RMBTHelpFragment();
    final Bundle args = new Bundle();

    args.putString(RMBTHelpFragment.ARG_URL, url);
    fragment.setArguments(args);
    ft.replace(R.id.fragment_content, fragment, titleId);
    ft.addToBackStack(titleId);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    ft.commit();
    refreshActionBar(titleId);
}

From source file:org.path.episample.android.activities.MainMenuActivity.java

public void swapToFragmentView(ScreenList newFragment) {
    WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView: " + newFragment.toString());

    String get = PropertiesSingleton.getProperty("survey",
            AdminPreferencesActivity.KEY_TURN_ON_OFF_WIFI_AUTOMATICALLY);
    if (!(get != null && get.equalsIgnoreCase("false"))) {
        if (mWifiManager.isWifiEnabled() && mWifiManager.getWifiState() != WifiManager.WIFI_STATE_DISABLED) {
            mWifiManager.setWifiEnabled(false);
        }//from   w w w .jav a2  s  . co  m
    }

    FragmentManager mgr = getFragmentManager();
    Fragment f;
    if (newFragment == ScreenList.MAIN_SCREEN) {
        throw new IllegalStateException("unexpected reference to generic main screen");
    } else if (newFragment == ScreenList.CUSTOM_VIEW) {
        WebLogger.getLogger(getAppName()).w(t,
                "swapToFragmentView: changing navigation to move to WebKit (was custom view)");
        f = mgr.findFragmentById(WebViewFragment.ID);
        if (f == null) {
            f = new WebViewFragment();
        }
        newFragment = ScreenList.WEBKIT;
    } else if (newFragment == ScreenList.MAIN_MENU) {
        f = mgr.findFragmentById(MainMenuFragment.ID);
        if (f == null) {
            f = new MainMenuFragment();
        }
    } else if (newFragment == ScreenList.COLLECT_MODULE) {
        f = mgr.findFragmentById(CollectFragment.ID);
        if (f == null) {
            f = new CollectFragment();
        }
    } else if (newFragment == ScreenList.SEND_RECEIVE_WIFI_DIRECT_MODULE) {
        f = mgr.findFragmentById(SendReceiveFragment.ID);
        if (f == null) {
            f = new SendReceiveFragment();
        }
    } /*else if (newFragment == ScreenList.SEND_RECEIVE_BLUETOOTH_MODULE) {
       f = mgr.findFragmentById(SendReceiveFragmentBT.ID);
       if (f == null) {
          f = new SendReceiveFragmentBT();
       }
      }*/ else if (newFragment == ScreenList.SELECT_MODULE) {
        f = mgr.findFragmentById(SelectFragment.ID);
        if (f == null) {
            f = new SelectFragment();
        }
    } else if (newFragment == ScreenList.NAVIGATE_MODULE) {
        f = mgr.findFragmentById(NavigateFragment.ID);
        if (f == null) {
            f = new NavigateFragment();
        }
    } else if (newFragment == ScreenList.RESTORE_MODULE) {
        f = mgr.findFragmentById(RestoreFragment.ID);
        if (f == null) {
            f = new RestoreFragment();
        }
    } else if (newFragment == ScreenList.EDIT_CENSUS_MODULE) {
        f = mgr.findFragmentById(EditCensusFragment.ID);
        if (f == null) {
            f = new EditCensusFragment();
        }
    } else if (newFragment == ScreenList.REMOVE_CENSUS_MODULE) {
        f = mgr.findFragmentById(RemoveCensusFragment.ID);
        if (f == null) {
            f = new RemoveCensusFragment();
        }
    } else if (newFragment == ScreenList.INVALIDATE_CENSUS_MODULE) {
        f = mgr.findFragmentById(InvalidateCensusFragment.ID);
        if (f == null) {
            f = new InvalidateCensusFragment();
        }
    } else if (newFragment == ScreenList.FORM_CHOOSER) {
        f = mgr.findFragmentById(FormChooserListFragment.ID);
        if (f == null) {
            f = new FormChooserListFragment();
        }
    } else if (newFragment == ScreenList.INITIALIZATION_DIALOG) {
        if (currentFragment == ScreenList.INITIALIZATION_DIALOG) {
            WebLogger.getLogger(getAppName()).e(t, "Unexpected: currentFragment == INITIALIZATION_DIALOG");
            return;
        } else {
            f = mgr.findFragmentById(InitializationFragment.ID);
            if (f == null) {
                f = new InitializationFragment();
            }
            ((InitializationFragment) f).setFragmentToShowNext(
                    (currentFragment == null) ? ScreenList.FORM_CHOOSER.name() : currentFragment.name());
        }
    } else if (newFragment == ScreenList.FORM_DELETER) {
        f = mgr.findFragmentById(FormDeleteListFragment.ID);
        if (f == null) {
            f = new FormDeleteListFragment();
        }
    } else if (newFragment == ScreenList.FORM_DOWNLOADER) {
        f = mgr.findFragmentById(FormDownloadListFragment.ID);
        if (f == null) {
            f = new FormDownloadListFragment();
        }
    } else if (newFragment == ScreenList.INSTANCE_UPLOADER_TABLE_CHOOSER) {
        f = mgr.findFragmentById(InstanceUploaderTableChooserListFragment.ID);
        if (f == null) {
            f = new InstanceUploaderTableChooserListFragment();
        }
    } else if (newFragment == ScreenList.INSTANCE_UPLOADER) {
        f = mgr.findFragmentById(InstanceUploaderListFragment.ID);
        if (f == null) {
            f = new InstanceUploaderListFragment();
        }
        ((InstanceUploaderListFragment) f).changeUploadTableId();
    } else if (newFragment == ScreenList.WEBKIT) {
        f = mgr.findFragmentById(WebViewFragment.ID);
        if (f == null) {
            f = new WebViewFragment();
        }
    } else if (newFragment == ScreenList.ABOUT_MENU) {
        f = mgr.findFragmentById(AboutMenuFragment.ID);
        if (f == null) {
            f = new AboutMenuFragment();
        }

    } else {
        throw new IllegalStateException("Unrecognized ScreenList type");
    }

    FrameLayout shadow = (FrameLayout) findViewById(R.id.shadow_content);
    View frags = findViewById(R.id.main_content);
    View wkt = findViewById(R.id.webkit_view);
    shadow.setVisibility(View.GONE);
    shadow.removeAllViews();
    if (newFragment == ScreenList.WEBKIT) {
        frags.setVisibility(View.GONE);
        wkt.setVisibility(View.VISIBLE);
        wkt.invalidate();
    } else {
        wkt.setVisibility(View.GONE);
        frags.setVisibility(View.VISIBLE);
    }

    currentFragment = newFragment;
    BackStackEntry entry = null;
    for (int i = 0; i < mgr.getBackStackEntryCount(); ++i) {
        BackStackEntry e = mgr.getBackStackEntryAt(i);
        if (e.getName().equals(currentFragment.name())) {
            entry = e;
            break;
        }
    }
    if (entry != null) {
        // flush backward, including the screen want to go back to
        mgr.popBackStackImmediate(currentFragment.name(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }

    // add transaction to show the screen we want
    FragmentTransaction trans = mgr.beginTransaction();
    trans.replace(R.id.main_content, f);
    trans.addToBackStack(currentFragment.name());
    trans.commit();

    // and see if we should re-initialize...
    if ((currentFragment != ScreenList.INITIALIZATION_DIALOG)
            && Survey.getInstance().shouldRunInitializationTask(getAppName())) {
        WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView -- calling clearRunInitializationTask");
        // and immediately clear the should-run flag...
        Survey.getInstance().clearRunInitializationTask(getAppName());
        // OK we should swap to the InitializationFragment view
        swapToFragmentView(ScreenList.INITIALIZATION_DIALOG);
    } else {
        levelSafeInvalidateOptionsMenu();
    }
}

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
 * /* ww  w  .ja  v a  2  s . c om*/
 * @param uid
 */
public void showResultDetail(final String testUUid) {
    FragmentTransaction ft;

    final Fragment fragment = new RMBTTestResultDetailFragment();

    final Bundle args = new Bundle();

    args.putString(RMBTTestResultDetailFragment.ARG_UID, testUUid);
    fragment.setArguments(args);

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

    refreshActionBar(AppConstants.PAGE_TITLE_RESULT_DETAIL);
}

From source file:org.iota.wallet.ui.activity.MainActivity.java

/**
 * Shows a fragment and hides the old one if there was a fragment previously visible
 *///www.  ja  v  a  2  s  . c o  m
private void showFragment(Fragment fragment, boolean addToBackStack, boolean killFragments) {

    if (fragment == null) {
        // Do nothing
        return;
    }

    FragmentManager fragmentManager = getFragmentManager();
    Fragment currentFragment = fragmentManager.findFragmentByTag(currentFragmentTag);

    if (currentFragment != null && currentFragment.getClass().getName().equals(fragment.getClass().getName())) {
        // Fragment already shown, do nothing
        return;
    }

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();

    if (killFragments) {
        Class[] fragmentsToKill = { AboutFragment.class, GenerateQRCodeFragment.class, NeighborsFragment.class,
                NodeInfoFragment.class, PasswordLoginFragment.class, QRScannerFragment.class,
                SeedLoginFragment.class, SettingsFragment.class, TangleExplorerTabFragment.class,
                NewTransferFragment.class, WalletAddressesFragment.class, WalletTabFragment.class,
                WalletTransfersFragment.class };
        for (Class fragmentClass : fragmentsToKill) {
            String tag = fragmentClass.getSimpleName();
            if (tag.equals(fragment.getClass().getSimpleName())) {
                continue;
            }
            Fragment fragmentToKill = fragmentManager.findFragmentByTag(tag);
            if (fragmentToKill != null) {
                fragmentTransaction.remove(fragmentToKill);
            }
        }
    }

    fragmentTransaction.setCustomAnimations(R.animator.fade_in, R.animator.fade_out, R.animator.fade_in,
            R.animator.fade_out);

    if (currentFragment != null) {
        // Hide old fragment
        fragmentTransaction.hide(currentFragment);
    }

    String tag = fragment.getClass().getSimpleName();
    Fragment cachedFragment = fragmentManager.findFragmentByTag(tag);
    if (cachedFragment != null) {
        // Cached fragment available
        fragmentTransaction.show(cachedFragment);
    } else {
        fragmentTransaction.add(FRAGMENT_CONTAINER_ID, fragment, tag);
    }
    if (addToBackStack) {
        fragmentTransaction.addToBackStack(null);
    }
    fragmentTransaction.commit();

    if (fragment instanceof OnBackPressedClickListener) {
        onBackPressedClickListener = (OnBackPressedClickListener) fragment;
    } else
        onBackPressedClickListener = null;

    // setChecked if open from WalletItemDialog
    if (fragment instanceof TangleExplorerTabFragment)
        navigationView.getMenu().findItem(R.id.nav_tangle_explorer).setChecked(true);

    currentFragmentTag = tag;
}

From source file:it.scoppelletti.mobilepower.app.FragmentLayoutController.java

/**
 * Ricostruisce la successione della disposizione dei frammenti nei
 * pannelli.//w w  w.ja v  a2 s.  c o m
 * 
 * @param  fragmentMgr   Gestore dei frammenti.
 * @param  fragmentQueue Frammenti.
 * @return               Identificatore dell&rsquo;ultimo elemento inserito
 *                       nel back stack.
 */
private int arrangeFragments(FragmentManager fragmentMgr,
        Queue<FragmentLayoutController.FragmentEntry> fragmentQueue) {
    int i;
    int frameCount, tnId, lastTnId;
    FragmentLayoutController.FragmentEntry entry;
    FragmentSupport newFragment, oldFragment;
    FragmentLayoutController.FragmentEntry[] frames;
    FragmentTransaction fragmentTn = null;

    frameCount = 1;
    frames = new FragmentLayoutController.FragmentEntry[myFrameCount];
    Arrays.fill(frames, null);

    lastTnId = -1;
    while (!fragmentQueue.isEmpty()) {
        tnId = -1;
        entry = fragmentQueue.remove();

        try {
            fragmentTn = fragmentMgr.beginTransaction();

            if (frameCount == myFrameCount) {
                // Tutti i pannelli sono occupati:
                // Sposto ogni frammento nel pannello precedente per
                // liberare l'ultimo.
                for (i = 0; i < frameCount; i++) {
                    if (frames[i] == null) {
                        // Inizialmente il primo pannello risulta vuoto
                        // anche se in realta' e' occupato dal frammento
                        // principale (non di dettaglio).
                        continue;
                    }

                    oldFragment = frames[i].getFragment();
                    newFragment = (i > 0) ? oldFragment.cloneFragment() : null;
                    fragmentTn.remove(oldFragment.asFragment());
                    frames[i] = null;

                    if (newFragment != null) {
                        fragmentTn.replace(myFrameIds[i - 1], newFragment.asFragment(), entry.getTag());
                        frames[i - 1] = new FragmentLayoutController.FragmentEntry(newFragment, entry.getTag());
                    }
                }

                frameCount--;
            }

            fragmentTn.add(myFrameIds[frameCount], entry.getFragment().asFragment(), entry.getTag());
            frames[frameCount++] = entry;

            fragmentTn.addToBackStack(null);
        } finally {
            if (fragmentTn != null) {
                tnId = fragmentTn.commit();
                fragmentTn = null;
            }
        }

        if (tnId >= 0) {
            lastTnId = tnId;
        }
    }

    return lastTnId;
}

From source file:com.esri.android.mapsapp.MapFragment.java

/**
 * Opens the map represented by the specified portal item or if null, opens
 * a default map.//w  w  w  . j  a  v  a  2 s.  c o m
 */
public void showMap(String portalItemId, String basemapPortalItemId) {

    // remove existing MapFragment explicitly, simply replacing it can cause
    // the app to freeze when switching basemaps
    FragmentTransaction transaction;
    FragmentManager fragmentManager = getFragmentManager();
    Fragment currentMapFragment = fragmentManager.findFragmentByTag(MapFragment.TAG);
    if (currentMapFragment != null) {
        transaction = fragmentManager.beginTransaction();
        transaction.remove(currentMapFragment);
        transaction.commit();
    }

    MapFragment mapFragment = MapFragment.newInstance(portalItemId, basemapPortalItemId);

    transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.maps_app_activity_content_frame, mapFragment, MapFragment.TAG);
    transaction.addToBackStack(null);
    transaction.commit();

    getActivity().invalidateOptionsMenu(); // reload the options menu
}

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
 * //  w  w w  .  j  a v a  2s  .  co m
 * @param uid
 */
public void showExpandedResultDetail(QoSServerResultCollection testResultArray, DetailType detailType,
        int position) {
    FragmentTransaction ft;

    //final RMBTResultDetailPagerFragment fragment = new RMBTResultDetailPagerFragment();
    final QoSCategoryPagerFragment fragment = new QoSCategoryPagerFragment();

    fragment.setQoSResult(testResultArray);
    fragment.setDetailType(detailType);

    ft = fm.beginTransaction();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_RESULT_QOS);
    ft.addToBackStack("result_detail_expanded");
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();

    fragment.setCurrentPosition(position);
    refreshActionBar(AppConstants.PAGE_TITLE_RESULT_QOS);
}