List of usage examples for android.app FragmentTransaction addToBackStack
public abstract FragmentTransaction addToBackStack(@Nullable String name);
From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java
/** * /*from w ww . j a v a2s . c om*/ * @param uid */ public void showQoSTestDetails(List<QoSServerResult> resultList, List<QoSServerResultDesc> descList, int index) { FragmentTransaction ft; //final RMBTResultDetailPagerFragment fragment = new RMBTResultDetailPagerFragment(); final QoSTestDetailPagerFragment fragment = new QoSTestDetailPagerFragment(); fragment.setQoSResultList(resultList); fragment.setQoSDescList(descList); fragment.setInitPosition(index); ft = fm.beginTransaction(); ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_TEST_DETAIL_QOS); ft.addToBackStack(AppConstants.PAGE_TITLE_TEST_DETAIL_QOS); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); refreshActionBar(AppConstants.PAGE_TITLE_TEST_DETAIL_QOS); }
From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java
public void showMap(boolean popBackStack) { if (popBackStack) { popBackStackFull();//from w w w . j a va 2 s. c om } FragmentTransaction ft; ft = fm.beginTransaction(); Fragment f = new RMBTMapFragment(); Bundle bundle = new Bundle(); bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_ALL_GESTURES, true); bundle.putBoolean(RMBTMapFragment.OPTION_SHOW_INFO_TOAST, true); bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_CONTROL_BUTTONS, true); f.setArguments(bundle); ft.replace(R.id.fragment_content, f, AppConstants.PAGE_TITLE_MAP); ft.addToBackStack(AppConstants.PAGE_TITLE_MAP); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); refreshActionBar(AppConstants.PAGE_TITLE_MAP); }
From source file:co.taqat.call.LinphoneActivity.java
private void changeFragmentForTablets(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) { if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) { if (newFragmentType == FragmentsAvailable.DIALER) { showStatusBar();/* w w w . j av a 2 s .co m*/ } else { hideStatusBar(); } } emptyFragment = false; LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2); FragmentTransaction transaction = getFragmentManager().beginTransaction(); if (newFragmentType == FragmentsAvailable.EMPTY) { ll.setVisibility(View.VISIBLE); emptyFragment = true; transaction.replace(R.id.fragmentContainer2, newFragment); transaction.commitAllowingStateLoss(); getFragmentManager().executePendingTransactions(); } else { if (newFragmentType.shouldAddItselfToTheRightOf(currentFragment)) { ll.setVisibility(View.VISIBLE); if (newFragmentType == FragmentsAvailable.CONTACT_EDITOR) { transaction.addToBackStack(newFragmentType.toString()); } transaction.replace(R.id.fragmentContainer2, newFragment); } else { if (newFragmentType == FragmentsAvailable.EMPTY) { ll.setVisibility(View.VISIBLE); transaction.replace(R.id.fragmentContainer2, new EmptyFragment()); emptyFragment = true; } if (newFragmentType == FragmentsAvailable.DIALER || newFragmentType == FragmentsAvailable.ABOUT || newFragmentType == FragmentsAvailable.SETTINGS || newFragmentType == FragmentsAvailable.ACCOUNT_SETTINGS) { ll.setVisibility(View.GONE); } else { ll.setVisibility(View.VISIBLE); transaction.replace(R.id.fragmentContainer2, new EmptyFragment()); } /*if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) { if (newFragmentType.isRightOf(currentFragment)) { transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left, R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right); } else { transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right, R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left); } }*/ transaction.replace(R.id.fragmentContainer, newFragment); } transaction.commitAllowingStateLoss(); getFragmentManager().executePendingTransactions(); currentFragment = newFragmentType; if (newFragmentType == FragmentsAvailable.DIALER || newFragmentType == FragmentsAvailable.SETTINGS || newFragmentType == FragmentsAvailable.CONTACTS_LIST || newFragmentType == FragmentsAvailable.CHAT_LIST || newFragmentType == FragmentsAvailable.HISTORY_LIST) { try { getFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); } catch (java.lang.IllegalStateException e) { } } fragmentsHistory.add(currentFragment); } }
From source file:co.taqat.call.LinphoneActivity.java
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) { FragmentManager fm = getFragmentManager(); FragmentTransaction transaction = fm.beginTransaction(); /*//from www.j av a 2 s. c om if (!withoutAnimation && currentFragment.shouldAnimate()) { if (newFragmentType.isRightOf(currentFragment)) { transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left, R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right); } else { transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right, R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left); } }*/ if (newFragmentType != FragmentsAvailable.DIALER && newFragmentType != FragmentsAvailable.CONTACTS_LIST && newFragmentType != FragmentsAvailable.CHAT_LIST && newFragmentType != FragmentsAvailable.HISTORY_LIST) { transaction.addToBackStack(newFragmentType.toString()); } else { while (fm.getBackStackEntryCount() > 0) { fm.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); } } transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString()); transaction.commitAllowingStateLoss(); fm.executePendingTransactions(); currentFragment = newFragmentType; }
From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java
/** * @param testPoint /*from w w w .j av a 2s . com*/ * @param mapType * */ public RMBTMapFragment showMap(String mapType, LatLng initialCenter, boolean clearFilter, int viewId, boolean popBackStack) { if (popBackStack) { popBackStackFull(); } FragmentTransaction ft; setCurrentMapType(mapType); if (clearFilter) { final List<MapListSection> mapFilterListSelectionList = getMapFilterListSelectionList(); if (mapFilterListSelectionList != null) { for (final MapListSection section : mapFilterListSelectionList) { for (final MapListEntry entry : section.getMapListEntryList()) entry.setChecked(entry.isDefault()); } updateMapFilter(); } } final RMBTMapFragment fragment = new RMBTMapFragment(); final Bundle bundle = new Bundle(); bundle.putParcelable("initialCenter", initialCenter); if (viewId >= 0) { bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_ALL_GESTURES, false); bundle.putBoolean(RMBTMapFragment.OPTION_SHOW_INFO_TOAST, false); bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_CONTROL_BUTTONS, false); bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_OVERLAY, false); fragment.setArguments(bundle); ft = fm.beginTransaction(); //replace the given viewgroup, but do not add to backstack ft.replace(viewId, fragment, AppConstants.PAGE_TITLE_MINI_MAP); //ft.addToBackStack(AppConstants.PAGE_TITLE_MINI_MAP); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); } else { System.out.println("SHOW MAP"); fragment.setArguments(bundle); ft = fm.beginTransaction(); ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_MAP); ft.addToBackStack(AppConstants.PAGE_TITLE_MAP); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); refreshActionBar(AppConstants.PAGE_TITLE_MAP); } return fragment; }
From source file:de.sourcestream.movieDB.controller.SearchList.java
public void onSuggestionClick(int id, String mediaType, String title) { FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); boolean result; Bundle args;// www .j a v a 2 s . co m switch (mediaType) { case "movie": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (movieDetails != null && lastVisitedId == id && 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", id); Bundle save = movieDetails.getSave(); movieDetails = new MovieDetails(); movieDetails.setTimeOut(0); movieDetails.setSave(save); movieDetails.setArguments(bundle); } else movieDetails = new MovieDetails(); args = new Bundle(); args.putInt("id", id); movieDetails.setArguments(args); movieDetails.setTitle(title); transaction.replace(R.id.frame_container, movieDetails); result = true; break; case "person": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (castDetails != null && lastVisitedId == id && castDetails.getTimeOut() == 0) { // Old movie details retrieve info and re-init component else crash castDetails.onSaveInstanceState(new Bundle()); Bundle bundle = new Bundle(); bundle.putInt("id", id); Bundle save = castDetails.getSave(); castDetails = new CastDetails(); castDetails.setTimeOut(0); castDetails.setSave(save); castDetails.setArguments(bundle); } else castDetails = new CastDetails(); args = new Bundle(); args.putInt("id", id); castDetails.setArguments(args); castDetails.setTitle(title); transaction.replace(R.id.frame_container, castDetails); result = true; break; case "tv": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (tvDetails != null && lastVisitedId == id && tvDetails.getTimeOut() == 0) { // Old movie details retrieve info and re-init component else crash tvDetails.onSaveInstanceState(new Bundle()); Bundle bundle = new Bundle(); bundle.putInt("id", id); Bundle save = tvDetails.getSave(); tvDetails = new TVDetails(); tvDetails.setTimeOut(0); tvDetails.setSave(save); tvDetails.setArguments(bundle); } else tvDetails = new TVDetails(); args = new Bundle(); args.putInt("id", id); tvDetails.setArguments(args); tvDetails.setTitle(title); transaction.replace(R.id.frame_container, tvDetails); result = true; break; default: result = false; break; } lastVisitedId = id; if (result) { // add the current transaction to the back stack: transaction.addToBackStack("movieList"); transaction.commit(); // collapse the search View ((MainActivity) getActivity()).collapseSearchView(); } }
From source file:de.sourcestream.movieDB.controller.SearchList.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. *//* www . j a va 2s. com*/ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); boolean result; Bundle args; switch (searchList.get(position).getMediaType()) { case "movie": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (movieDetails != null && lastVisitedId == searchList.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", searchList.get(position).getId()); Bundle save = movieDetails.getSave(); movieDetails = new MovieDetails(); movieDetails.setTimeOut(0); movieDetails.setSave(save); movieDetails.setArguments(bundle); } else movieDetails = new MovieDetails(); args = new Bundle(); args.putInt("id", searchList.get(position).getId()); movieDetails.setArguments(args); movieDetails.setTitle(searchList.get(position).getTitle()); transaction.replace(R.id.frame_container, movieDetails); result = true; break; case "person": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (castDetails != null && lastVisitedId == searchList.get(position).getId() && castDetails.getTimeOut() == 0) { // Old movie details retrieve info and re-init component else crash castDetails.onSaveInstanceState(new Bundle()); Bundle bundle = new Bundle(); bundle.putInt("id", searchList.get(position).getId()); Bundle save = castDetails.getSave(); castDetails = new CastDetails(); castDetails.setTimeOut(0); castDetails.setSave(save); castDetails.setArguments(bundle); } else castDetails = new CastDetails(); args = new Bundle(); args.putInt("id", searchList.get(position).getId()); castDetails.setArguments(args); castDetails.setTitle(searchList.get(position).getTitle()); transaction.replace(R.id.frame_container, castDetails); result = true; break; case "tv": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (tvDetails != null && lastVisitedId == searchList.get(position).getId() && tvDetails.getTimeOut() == 0) { // Old movie details retrieve info and re-init component else crash tvDetails.onSaveInstanceState(new Bundle()); Bundle bundle = new Bundle(); bundle.putInt("id", searchList.get(position).getId()); Bundle save = tvDetails.getSave(); tvDetails = new TVDetails(); tvDetails.setTimeOut(0); tvDetails.setSave(save); tvDetails.setArguments(bundle); } else tvDetails = new TVDetails(); args = new Bundle(); args.putInt("id", searchList.get(position).getId()); tvDetails.setArguments(args); tvDetails.setTitle(searchList.get(position).getTitle()); transaction.replace(R.id.frame_container, tvDetails); result = true; break; default: result = false; break; } lastVisitedId = searchList.get(position).getId(); if (result) { // add the current transaction to the back stack: transaction.addToBackStack("movieList"); transaction.commit(); // collapse the search View ((MainActivity) getActivity()).collapseSearchView(); } }
From source file:org.opendatakit.survey.activities.MainMenuActivity.java
public void swapToFragmentView(ScreenList newScreenType) { WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView: " + newScreenType.name()); FragmentManager mgr = getFragmentManager(); FragmentTransaction trans = null; Fragment newFragment = null;/*w ww . j av a2 s . c om*/ if (newScreenType == ScreenList.MAIN_SCREEN) { throw new IllegalStateException("unexpected reference to generic main screen"); } else if (newScreenType == ScreenList.FORM_CHOOSER) { newFragment = mgr.findFragmentByTag(newScreenType.name()); if (newFragment == null) { newFragment = new FormChooserListFragment(); } } else if (newScreenType == ScreenList.FRONT_PAGE) { newFragment = mgr.findFragmentByTag(newScreenType.name()); if (newFragment == null) { newFragment = new FrontPageFragment(); } } else if (newScreenType == ScreenList.INITIALIZATION_DIALOG) { newFragment = mgr.findFragmentByTag(newScreenType.name()); if (newFragment == null) { newFragment = new InitializationFragment(); } } else if (newScreenType == ScreenList.WEBKIT) { newFragment = mgr.findFragmentByTag(newScreenType.name()); if (newFragment == null) { WebLogger.getLogger(getAppName()).i(t, "[" + this.hashCode() + "] creating new webkit fragment " + newScreenType.name()); newFragment = new WebViewFragment(); } } else if (newScreenType == ScreenList.ABOUT_MENU) { newFragment = mgr.findFragmentByTag(newScreenType.name()); if (newFragment == null) { newFragment = new AboutMenuFragment(); } } else { throw new IllegalStateException("Unrecognized ScreenList type"); } boolean matchingBackStackEntry = false; for (int i = 0; i < mgr.getBackStackEntryCount(); ++i) { BackStackEntry e = mgr.getBackStackEntryAt(i); WebLogger.getLogger(getAppName()).i(t, "BackStackEntry[" + i + "] " + e.getName()); if (e.getName().equals(newScreenType.name())) { matchingBackStackEntry = true; } } if (matchingBackStackEntry) { if (trans != null) { WebLogger.getLogger(getAppName()).e(t, "Unexpected active transaction when popping state!"); trans = null; } // flush backward, to the screen we want to go back to currentFragment = newScreenType; WebLogger.getLogger(getAppName()).e(t, "[" + this.hashCode() + "] popping back stack " + currentFragment.name()); mgr.popBackStackImmediate(currentFragment.name(), 0); } else { // add transaction to show the screen we want if (trans == null) { trans = mgr.beginTransaction(); } currentFragment = newScreenType; trans.replace(R.id.main_content, newFragment, currentFragment.name()); WebLogger.getLogger(getAppName()).i(t, "[" + this.hashCode() + "] adding to back stack " + currentFragment.name()); trans.addToBackStack(currentFragment.name()); } // and see if we should re-initialize... if ((currentFragment != ScreenList.INITIALIZATION_DIALOG) && ((Survey) getApplication()).shouldRunInitializationTask(getAppName())) { WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView -- calling clearRunInitializationTask"); // and immediately clear the should-run flag... ((Survey) getApplication()).clearRunInitializationTask(getAppName()); // OK we should swap to the InitializationFragment view // this will skip the transition to whatever screen we were trying to // go to and will instead show the InitializationFragment view. We // restore to the desired screen via the setFragmentToShowNext() // // NOTE: this discards the uncommitted transaction. // Robolectric complains about a recursive state transition. if (trans != null) { trans.commit(); } swapToFragmentView(ScreenList.INITIALIZATION_DIALOG); } else { // before we actually switch to a WebKit, be sure // we have the form definition for it... if (currentFragment == ScreenList.WEBKIT && getCurrentForm() == null) { // we were sent off to the initialization dialog to try to // discover the form. We need to inquire about the form again // and, if we cannot find it, report an error to the user. final Uri uriFormsProvider = FormsProviderAPI.CONTENT_URI; Uri uri = getIntent().getData(); Uri formUri = null; if (uri.getScheme().equalsIgnoreCase(uriFormsProvider.getScheme()) && uri.getAuthority().equalsIgnoreCase(uriFormsProvider.getAuthority())) { List<String> segments = uri.getPathSegments(); if (segments != null && segments.size() >= 2) { String appName = segments.get(0); setAppName(appName); String tableId = segments.get(1); String formId = (segments.size() > 2) ? segments.get(2) : null; formUri = Uri.withAppendedPath(Uri.withAppendedPath( Uri.withAppendedPath(FormsProviderAPI.CONTENT_URI, appName), tableId), formId); } else { swapToFragmentView(ScreenList.FRONT_PAGE); createErrorDialog(getString(R.string.invalid_uri_expecting_n_segments, uri.toString(), 2), EXIT); return; } // request specifies a specific formUri -- try to open that FormIdStruct newForm = FormIdStruct.retrieveFormIdStruct(getContentResolver(), formUri); if (newForm == null) { // error swapToFragmentView(ScreenList.FRONT_PAGE); createErrorDialog(getString(R.string.form_not_found, segments.get(1)), EXIT); return; } else { transitionToFormHelper(uri, newForm); } } } if (trans != null) { trans.commit(); } invalidateOptionsMenu(); } }
From source file:com.bernard.beaconportal.activities.activity.MessageList.java
private void addMessageListFragment(MessageListFragment fragment, boolean addToBackStack) { FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.message_list_container, fragment); if (addToBackStack) ft.addToBackStack(null); mMessageListFragment = fragment;/*from w w w. j a v a2 s. c om*/ int transactionId = ft.commit(); if (transactionId >= 0 && mFirstBackStackId < 0) { mFirstBackStackId = transactionId; } }