List of usage examples for android.support.v4.app FragmentTransaction addToBackStack
public abstract FragmentTransaction addToBackStack(String name);
From source file:com.kuassivi.october.util.Navigator.java
/** * Prepares a Fragment to be committed./*from www .jav a 2s . c om*/ * * @param resourceId id for the fragment container * @param fragment Fragment to be loaded on the container * @param animate whether it must be animated * @param addToBackStack the BackStack string tag */ @Nullable private FragmentTransaction prepareFragment(@IdRes int resourceId, @NonNull Fragment fragment, boolean animate, String addToBackStack) { if (resourceId <= 0) { throw new RuntimeException("You must supply a resource id for the Fragment Container"); } if (!(activity instanceof FragmentActivity)) { throw new RuntimeException("The activity must inherits from FragmentActivity or AppCompatActivity"); } FragmentActivity fragmentActivity = (FragmentActivity) activity; FragmentManager fragmentManager = fragmentActivity.getSupportFragmentManager(); /* * The method isFinishing() prevents to load a Fragment * when the activity is going to be killed or destroyed. */ if ((fragmentManager == null || fragmentActivity.isFinishing())) { return null; } @SuppressLint("CommitTransaction") FragmentTransaction ft = fragmentManager.beginTransaction(); if (animate && animations.length > 0) { if (animations.length == 2) { ft.setCustomAnimations(animations[0], animations[1]); } else { ft.setCustomAnimations(animations[0], animations[1], animations[2], animations[3]); } } ft.addToBackStack(addToBackStack); this.fragment = fragment; return ft.replace(resourceId, fragment); }
From source file:com.munger.passwordkeeper.MainActivity.java
/** * Open the fragment that allows the user to create a new document. * @param type Type can either be CreateFileFragment.TYPE_CREATE or CreateFileFragment.TYPE_IMPORT *//* www .j av a 2 s. c om*/ public void addFile(int type) { if (!(type == CreateFileFragment.TYPE_CREATE || type == CreateFileFragment.TYPE_IMPORT || type == CreateFileFragment.TYPE_CREATE_DROPBOX)) return; //open the create file fragment setEditable(false); FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); createFileFragment = new CreateFileFragment(); createFileFragment.settype(type); //setup the back button trans.replace(R.id.container, createFileFragment); trans.addToBackStack(CreateFileFragment.getName()); trans.commit(); }
From source file:com.fastbootmobile.encore.app.MainActivity.java
public void showFragment(Fragment f, boolean addToStack, String tag) { // update the main content by replacing fragments FragmentManager fragmentManager = getSupportFragmentManager(); if (fragmentManager.getBackStackEntryCount() > 0) { fragmentManager.popBackStack();// www .j av a 2 s . c o m } FragmentTransaction ft = fragmentManager.beginTransaction(); if (addToStack) { ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE); ft.addToBackStack(f.toString()); } else { ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); } ft.replace(R.id.container, f, tag); ft.commit(); }
From source file:com.app.blockydemo.ui.fragment.ScriptFragment.java
private void showCategoryFragment() { BrickCategoryFragment brickCategoryFragment = new BrickCategoryFragment(); brickCategoryFragment.setOnCategorySelectedListener(this); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(R.id.script_fragment_container, brickCategoryFragment, BrickCategoryFragment.BRICK_CATEGORY_FRAGMENT_TAG); fragmentTransaction.addToBackStack(BrickCategoryFragment.BRICK_CATEGORY_FRAGMENT_TAG); fragmentTransaction.commit();// w w w .jav a 2 s . c o m adapter.notifyDataSetChanged(); }
From source file:com.clemot.julian.easylib.EasyActivity.java
/** * Add fragment with transition animation * * @param lastFrag fragment// w ww . j a v a 2s . c o m * @param frag fragment * @param id which child is loaded * @param animation (POP/PUSH LEFT/PUSH RIGHT) * @param backStack back stack or not */ public void addFragment(Fragment lastFrag, Fragment frag, int id, FragmentCustomAnimation animation, boolean backStack) { FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); addCustomAnimation(fragmentTransaction, animation); fragmentTransaction.add(id, frag, frag.getClass().getName()); // An optional name for this back stack state, or null. if (backStack) { fragmentTransaction.addToBackStack(null); } fragmentTransaction.commit(); try { fragmentManager.executePendingTransactions(); } catch (IllegalStateException iSe) { Log.e("MultiFrag", "Handle crash:" + iSe.getStackTrace()); } }
From source file:com.mifos.mifosxdroid.online.loanaccount.LoanAccountFragment.java
@OnClick(R.id.btn_loan_submit) public void submit() { LoansPayload loansPayload = new LoansPayload(); loansPayload.setAllowPartialPeriodInterestCalcualtion(cbCalculateInterest.isChecked()); loansPayload.setAmortizationType(amortizationTypeId); loansPayload.setClientId(clientId);//from w w w. j a va2s . com loansPayload.setDateFormat("dd MMMM yyyy"); loansPayload.setExpectedDisbursementDate(disbursementDate); loansPayload.setInterestCalculationPeriodType(interestCalculationPeriodTypeId); loansPayload.setLoanType("individual"); loansPayload.setLocale("en"); loansPayload.setNumberOfRepayments(etNumberOfRepayments.getEditableText().toString()); loansPayload.setPrincipal(etPrincipal.getEditableText().toString()); loansPayload.setProductId(productId); loansPayload.setRepaymentEvery(etRepaidEvery.getEditableText().toString()); loansPayload.setSubmittedOnDate(submissionDate); loansPayload.setLoanPurposeId(loanPurposeId); loansPayload.setLoanTermFrequency(Integer.parseInt(etLoanTerm.getEditableText().toString())); loansPayload.setLoanTermFrequencyType(loanTermFrequencyType); //loanTermFrequencyType and repaymentFrequencyType should be the same. loansPayload.setRepaymentFrequencyType(loanTermFrequencyType); loansPayload.setRepaymentFrequencyDayOfWeekType( repaymentFrequencyDayOfWeek != null ? repaymentFrequencyDayOfWeek : null); loansPayload.setRepaymentFrequencyNthDayType( repaymentFrequencyNthDayType != null ? repaymentFrequencyNthDayType : null); loansPayload.setTransactionProcessingStrategyId(transactionProcessingStrategyId); loansPayload.setFundId(fundId); loansPayload.setInterestType(interestTypeId); loansPayload.setLoanOfficerId(loanOfficerId); loansPayload.setLinkAccountId(linkAccountId); interestRatePerPeriod = Double.parseDouble(etNominalInterestRate.getEditableText().toString()); loansPayload.setInterestRatePerPeriod(interestRatePerPeriod); if (hasDataTables) { DataTableListFragment fragment = DataTableListFragment.newInstance(mLoanTemplate.getDataTables(), loansPayload, Constants.CLIENT_LOAN); FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction(); fragmentTransaction.addToBackStack(FragmentConstants.DATA_TABLE_LIST); fragmentTransaction.replace(R.id.container, fragment).commit(); } else { initiateLoanCreation(loansPayload); } }
From source file:com.ayuget.redface.ui.activity.PrivateMessagesActivity.java
/** * Loads a private message in the appropriate pane. *//* w w w .j a va 2 s .c o m*/ private void loadPrivateMessage(PrivateMessage privateMessage, int page, PagePosition pagePosition) { Log.d(LOG_TAG, String.format("Loading private message '%s' at page '%d'", privateMessage.getSubject(), page)); // Mask private message as a regular topic (kinda ugly, btw...) Topic pmAsTopic = privateMessage.asTopic(); pmAsTopic.setCategory(categoriesStore.getPrivateMessagesCategory()); TopicFragment topicFragment = new TopicFragmentBuilder(page, pmAsTopic).currentPagePosition(pagePosition) .build(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); int topicFragmentContainer = isTwoPaneMode() ? R.id.details_container : R.id.container; if (!isTwoPaneMode()) { Log.d(LOG_TAG, "Setting slide animation for topicFragment (private message)"); transaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); } transaction.replace(topicFragmentContainer, topicFragment, PM_FRAGMENT_TAG); transaction.addToBackStack(PM_FRAGMENT_TAG); transaction.commit(); }
From source file:com.akhbulatov.wordkeeper.ui.activity.MainActivity.java
private void selectDrawerItem(MenuItem item) { Class fragmentClass = null;//www . j a va2 s . c o m Fragment fragment = null; switch (item.getItemId()) { case R.id.menu_drawer_all_words: fragmentClass = WordListFragment.class; break; case R.id.menu_drawer_categories: fragmentClass = CategoryListFragment.class; break; case R.id.menu_drawer_rate_app: showRateApp(); break; case R.id.menu_drawer_about: showAbout(); break; default: fragmentClass = WordListFragment.class; } // Block is executed only if the selected item is a fragment, // otherwise was the selected activity and the replacement fragment is not executed if (fragmentClass != null) { try { fragment = (Fragment) fragmentClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (fragmentClass == WordListFragment.class) { getSupportFragmentManager().popBackStack(); transaction.replace(R.id.layout_root_container, fragment, WORD_LIST_FRAGMENT_TAG); mWordListFragment = (WordListFragment) fragment; } else { transaction.replace(R.id.layout_root_container, fragment, CATEGORY_LIST_FRAGMENT_TAG); transaction.addToBackStack(null); mCategoryListFragment = (CategoryListFragment) fragment; } transaction.commit(); // Not required for activity. Only for a fragment item.setChecked(true); setTitle(item.getTitle()); } mDrawerLayout.closeDrawers(); }
From source file:com.marcosedo.lagramola.MainActivity.java
public boolean onOptionsItemSelected(MenuItem item) { Log.i(TAG, "onOptionsItemSelected del mainActivity"); // Handle presses on the action bar items FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); switch (item.getItemId()) { case R.id.action_profile://Perfil de usuario ProfileFragment creaPerfilFragment = new ProfileFragment(); transaction.replace(R.id.outTabContent, creaPerfilFragment, "notificaciones"); transaction.addToBackStack(null); transaction.commit();// Commit the transaction break;//from ww w .j a va 2 s . c o m case R.id.action_help: HelpFragment helpFragment = new HelpFragment(); transaction.replace(R.id.outTabContent, helpFragment, "help"); transaction.addToBackStack(null); transaction.commit();// Commit the transaction break; } return super.onOptionsItemSelected(item); }
From source file:com.example.casthelloworld.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Fragment fragment = new ConnectFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.add(R.id.main, fragment, "first"); transaction.addToBackStack(null); transaction.commit();// w w w.jav a 2s.c om Log.d("Start", "ONcreate"); waiting = false; m_lastMagFields = new float[3]; m_lastAccels = new float[3]; mRotationMatrix = new float[16]; m_remappedR = new float[16]; m_orientation = new float[4]; orientationVals = new float[3]; directionMessage = new JSONObject(); playerId = ""; ActionBar actionBar = getSupportActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent))); v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); lastVal = 999; sManager = (SensorManager) getSystemService(SENSOR_SERVICE); // Configure Cast device discovery mMediaRouter = MediaRouter.getInstance(getApplicationContext()); mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory( CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build(); mMediaRouterCallback = new MyMediaRouterCallback(); }