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:no.digipost.android.gui.MainContentActivity.java

private void showCreateEditDialog(int content, boolean editFolder) {

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment prev = getFragmentManager().findFragmentByTag(EditFolderFragment.fragmentName);
    if (prev != null) {
        ft.remove(prev);//from  w  w w. ja va  2 s .c o  m
    }
    ft.addToBackStack(null);
    DialogFragment editFolderFragment = EditFolderFragment.newInstance(content,
            account.getValidationRules().getFolderName(), editFolder);
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    editFolderFragment.show(ft, EditFolderFragment.fragmentName);
}

From source file:at.alladin.rmbt.android.map.RMBTMapFragment.java

@Override
public void onClick(View v) {
    final FragmentManager fm = getActivity().getFragmentManager();
    final FragmentTransaction ft;

    final GoogleMap map = getMap();

    switch (v.getId()) {

    case R.id.mapChooseButton:

        ft = fm.beginTransaction();/*from  www  .  ja v  a 2  s.  com*/
        ft.replace(R.id.fragment_content, new RMBTMapChooseFragment(), "map_choose");
        ft.addToBackStack("map_choose");
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.commit();

        break;

    case R.id.mapFilterButton:

        ft = fm.beginTransaction();
        ft.replace(R.id.fragment_content, new RMBTMapFilterFragment(), "map_filter");
        ft.addToBackStack("map_filter");
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.commit();

        break;

    case R.id.mapLocateButton:

        if (map != null) {
            final Location location = geoLocation.getLastKnownLocation();
            if (location != null) {
                final LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude());
                gMap.animateCamera(CameraUpdateFactory.newLatLng(latlng));
            }
        }
        break;

    case R.id.mapHelpButton:
        ((RMBTMainActivity) getActivity()).showHelp("", false, AppConstants.PAGE_TITLE_HELP); // TODO: put correct
        // help url
        break;

    case R.id.mapInfoButton:
        showInfoToast();
        break;

    case R.id.mapZoomInButton:

        if (map != null)
            map.animateCamera(CameraUpdateFactory.zoomIn());

        break;

    case R.id.mapZoomOutButton:

        if (map != null)
            map.animateCamera(CameraUpdateFactory.zoomOut());

        break;

    default:
        break;
    }

}

From source file:com.hijacker.MainActivity.java

static void isolate(String mac) {
    is_ap = getAPByMac(mac);/*from  w w  w . j ava2s . c  o m*/
    if (is_ap != null) {
        IsolatedFragment.exit_on = mFragmentManager.getBackStackEntryCount();
        FragmentTransaction ft = mFragmentManager.beginTransaction();
        ft.replace(R.id.fragment1, new IsolatedFragment());
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.addToBackStack(null);
        ft.commitAllowingStateLoss();
    }
    Tile.filter();
    if (debug) {
        if (is_ap == null)
            Log.d("HIJACKER/Main", "No AP isolated");
        else
            Log.d("HIJACKER/Main", "AP with MAC " + mac + " isolated");
    }
}

From source file:de.sourcestream.movieDB.controller.MovieList.java

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 *
 * @param parent   The AdapterView where the click happened.
 * @param view     The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position The position of the view in the adapter.
 * @param id       The row id of the item that was clicked.
 *//*w w  w  .j a  v  a2  s . c o  m*/
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    activity.setLastVisitedSimMovie(0);
    activity.resetMovieDetailsBundle();
    activity.setRestoreMovieDetailsAdapterState(true);
    activity.setRestoreMovieDetailsState(false);
    activity.setOrientationChanged(false);
    activity.resetCastDetailsBundle();
    if (movieDetails != null && lastVisitedMovie == moviesList.get(position).getId()
            && movieDetails.getTimeOut() == 0) {
        // Old movie details retrieve info and re-init component else crash
        movieDetails.onSaveInstanceState(new Bundle());
        Bundle bundle = new Bundle();
        bundle.putInt("id", moviesList.get(position).getId());
        Bundle save = movieDetails.getSave();
        movieDetails = new MovieDetails();
        movieDetails.setTimeOut(0);
        movieDetails.setSave(save);
        movieDetails.setArguments(bundle);
    } else
        movieDetails = new MovieDetails();

    lastVisitedMovie = moviesList.get(position).getId();
    movieDetails.setTitle(moviesList.get(position).getTitle());
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle bundle = new Bundle();
    bundle.putInt("id", moviesList.get(position).getId());
    movieDetails.setArguments(bundle);
    transaction.replace(R.id.frame_container, movieDetails);
    // add the current transaction to the back stack:
    transaction.addToBackStack("movieList");
    transaction.commit();
    fragmentActive = true;
    activity.getMovieSlideTab().showInstantToolbar();
    /*  ValueAnimator anim = ValueAnimator.ofFloat(0, 1);
      anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator valueAnimator) {
        float slideOffset = (Float) valueAnimator.getAnimatedValue();
        activity.getmDrawerToggle().onDrawerSlide(activity.getmDrawerLayout(), slideOffset);
    }
      });
      anim.setInterpolator(new DecelerateInterpolator());
    // You can change this duration to more closely match that of the default animation.
      anim.setDuration(700);
      anim.start();*/

}

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

/**
 * Opens the map represented by the specified portal item or if null, opens
 * a default map./*from   www .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();

    invalidateOptionsMenu(); // reload the options menu
}

From source file:com.sintef_energy.ubisolar.activities.DrawerActivity.java

/**
 * Helper method to add fragments to the view.
 *
 * @param fragment Fragment to swap in//ww  w  .  j a  v a  2s  .c  om
 * @param animate True if swap shall have an animation
 * @param addToBackStack True if the Fragment shall go to the back stack
 * @param tag String for the back stack
 */
public void addFragment(Fragment fragment, boolean animate, boolean addToBackStack, String tag) {
    FragmentManager manager = getFragmentManager();

    FragmentTransaction ft = manager.beginTransaction();
    if (animate) {
        ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right,
                // Pop enter
                android.R.anim.fade_in, android.R.anim.fade_out);
    }

    if (addToBackStack) {
        ft.addToBackStack(tag);
    }

    ft.replace(R.id.container, fragment, tag);
    ft.commit();
}

From source file:com.dsna.android.main.MainActivity.java

private void openFragment(BaseFragment baseFragment) {
    if (baseFragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        fragmentTransaction.replace(R.id.fragment_main, baseFragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();/*from w  w  w.j a  va  2s .c om*/
        if (baseFragment.getTitleResourceId() > 0)
            mCurrentTitle = baseFragment.getTitleResourceId();

    }
}

From source file:by.zatta.pilight.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    /*/*from  www  .j ava  2 s  .  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:de.sourcestream.movieDB.controller.CastDetailsInfo.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    activity.getCastDetailsFragment().showInstantToolbar();
    activity.setCastDetailsFragment(null);
    activity.setRestoreMovieDetailsAdapterState(true);
    activity.setRestoreMovieDetailsState(false);

    if (knownList.get(position).getMediaType().equals("movie")) {
        if (activity.getMovieDetailsFragment() != null
                && activity.getLastVisitedMovieInCredits() == knownList.get(position).getId()
                && activity.getMovieDetailsFragment().getTimeOut() == 0) {
            // Old movie details retrieve info and re-init component else crash
            activity.getMovieDetailsFragment().onSaveInstanceState(new Bundle());
            Bundle bundle = new Bundle();
            bundle.putInt("id", knownList.get(position).getId());
            Bundle save = activity.getMovieDetailsFragment().getSave();
            // Re-init movie details and set save information
            movieDetails = new MovieDetails();
            movieDetails.setTimeOut(0);/*from w w  w.j av  a 2s . co  m*/
            movieDetails.setSave(save);
            movieDetails.setArguments(bundle);
        } else
            movieDetails = new MovieDetails();
    }

    if (knownList.get(position).getMediaType().equals("tv")) {
        if (activity.getTvDetailsFragment() != null
                && activity.getLastVisitedMovieInCredits() == knownList.get(position).getId()
                && activity.getTvDetailsFragment().getTimeOut() == 0) {
            // Old movie details retrieve info and re-init component else crash
            activity.getTvDetailsFragment().onSaveInstanceState(new Bundle());
            Bundle bundle = new Bundle();
            bundle.putInt("id", knownList.get(position).getId());
            Bundle save = activity.getTvDetailsFragment().getSave();
            // Re-init movie details and set save information
            tvDetails = new TVDetails();
            tvDetails.setTimeOut(0);
            tvDetails.setSave(save);
            tvDetails.setArguments(bundle);
        } else
            tvDetails = new TVDetails();
    }

    activity.setLastVisitedMovieInCredits(knownList.get(position).getId());
    ((CastDetails) getParentFragment()).setAddToBackStack(true);
    getParentFragment().onSaveInstanceState(new Bundle());
    if (activity.getSearchViewCount())
        activity.incSearchCastDetails();

    FragmentManager manager = getActivity().getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle bundle = new Bundle();
    bundle.putInt("id", knownList.get(position).getId());

    if (knownList.get(position).getMediaType().equals("movie")) {
        movieDetails.setTitle(knownList.get(position).getTitle());
        movieDetails.setArguments(bundle);
        transaction.replace(R.id.frame_container, movieDetails);
    }
    if (knownList.get(position).getMediaType().equals("tv")) {
        tvDetails.setTitle(knownList.get(position).getTitle());
        tvDetails.setArguments(bundle);
        transaction.replace(R.id.frame_container, tvDetails);
    }
    // add the current transaction to the back stack:
    transaction.addToBackStack("castDetails");
    transaction.commit();

}

From source file:com.android.deskclock.timer.TimerFullScreenFragment.java

private void onLabelPressed(TimerObj t) {
    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    final Fragment prev = getFragmentManager().findFragmentByTag("label_dialog");
    if (prev != null) {
        ft.remove(prev);/*from w  ww . j a v a2s.  c  o m*/
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    final LabelDialogFragment newFragment = LabelDialogFragment.newInstance(t, t.mLabel, getTag());
    newFragment.show(ft, "label_dialog");
}