コード例 #1
0
ファイル: SliderMenu.java プロジェクト: RyanLee7/ryan_reader
 private void changePage(int position, SliderItem item) {
   mIgnoreBackStack = true;
   if (mCurrentPage >= 0) {
     final SliderItem lastItem = mAdapter.getItem(mCurrentPage);
     final WeakReference<Fragment> ref = lastItem.mLastFragment;
     final Fragment fragment = ref == null ? null : ref.get();
     if (fragment != null && fragment.isAdded() && lastItem.mSaveState) {
       if (!fragment.isDetached()) {
         mFragmentManager.beginTransaction().detach(fragment).commit();
         mFragmentManager.executePendingTransactions();
       }
       lastItem.mSavedState = mFragmentManager.saveFragmentInstanceState(fragment);
     }
   }
   mCurrentPage = position;
   mAdapter.notifyDataSetInvalidated();
   while (mFragmentManager.popBackStackImmediate()) {}
   final Fragment fragment = Fragment.instantiate(item.mFragmentClass);
   if (item.mSavedState != null) {
     fragment.setInitialSavedState(item.mSavedState);
   }
   item.mLastFragment = new WeakReference<Fragment>(fragment);
   replaceFragment(mFragmentManager, fragment);
   mIgnoreBackStack = false;
 }
コード例 #2
0
ファイル: MainActivity.java プロジェクト: b2simms/Oldboys
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_settings) {
      FragmentManager fm = getSupportFragmentManager();
      fm.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
      tag = WELCOME;
      TextView title = (TextView) findViewById(R.id.nav_bar_title);
      title.setText(tag);
      fm.beginTransaction().replace(R.id.container, new Fragment_Welcome(), tag).commit();
      return true;
    }
    if (id == R.id.profile_icon) {
      tag = PROFILE;
      submenu_bar.setVisibility(View.VISIBLE);

      TextView title = (TextView) findViewById(R.id.nav_bar_title);
      title.setText(tag);
      setSubmenuOptions(submenu_profile);
      setSubmenuTitle(submenu_profile[0]);

      FragmentManager fragmentManager = getSupportFragmentManager();
      fragmentManager
          .beginTransaction()
          .replace(R.id.container, new Fragment_Profile_Overview(), tag)
          .addToBackStack(tag)
          .commit();
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
コード例 #3
0
ファイル: BaseActivity.java プロジェクト: roy9527/wolf
 @Override
 public void onBackPressed() {
   if (fragmentManager.getBackStackEntryCount() > 0) {
     fragmentManager.popBackStackImmediate();
     return;
   }
   super.onBackPressed();
 }
コード例 #4
0
 public void clearTop() {
   FragmentManager fm = getSupportFragmentManager();
   if (fm.getBackStackEntryCount() > 0)
     try {
       fm.popBackStackImmediate(
           fm.getBackStackEntryAt(0).getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
     } catch (IllegalStateException e) {
       // Random error clearing to top. Not critical if this did not succeed, no need to crash.
       if (ConnectedApp.DEBUG) throw e;
     }
 }
コード例 #5
0
ファイル: MainActivity.java プロジェクト: Archit4u/Bookmark
  public void switchContent(Fragment fragment, String tag) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    while (fragmentManager.popBackStackImmediate()) ;

    if (fragment != null) {
      FragmentTransaction transaction = fragmentManager.beginTransaction();
      transaction.replace(R.id.content_frame, fragment, tag);
      // Only FavoriteListFragment is added to the back stack.
      if (!(fragment instanceof ProductListFragment)) {
        transaction.addToBackStack(tag);
      }
      transaction.commit();
      contentFragment = fragment;
    }
  }
コード例 #6
0
 public void onClick(View view) {
   FragmentManager fm = getSupportFragmentManager();
   while (fm.popBackStackImmediate()) {
     fm.executePendingTransactions();
   }
   replaceFragment(Fragment.instantiate(clazz));
   fm.executePendingTransactions();
   postDelayed(
       new Runnable() {
         @Override
         public void run() {
           requireSlidingMenu().showContent();
         }
       },
       100);
 }
コード例 #7
0
ファイル: ActionBarView.java プロジェクト: kailIII/PostoPrint
  // Menu button opens and closes the drawer menu
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle menu item selection

    if (item.getItemId() == R.id.menu_threebar) {
      if (mDrawerLayout.isDrawerVisible(GravityCompat.END)) {
        mDrawerLayout.closeDrawer(GravityCompat.END);
      } else {
        mDrawerLayout.openDrawer(GravityCompat.END);
      }
    } else if (item.getItemId() == ImagesGridFragment.NEXTMENUITEM) {
      // Editting grid fragment
      switchTo(EdittingGridFragment.class, null);
    } else if (item.getItemId() == android.R.id.home) {
      // home button pressed
      if (!fm.popBackStackImmediate()) startActivity(new Intent(this, WelcomeActivity.class));
    }

    return super.onOptionsItemSelected(item);
  }
コード例 #8
0
  public void replaceFragment(Fragment fragment, boolean bCommitAllowingStateLoss) {
    String backStateName = fragment.getClass().getName();

    FragmentManager manager = getSupportFragmentManager();
    boolean fragmentPopped = false;

    try {
      fragmentPopped = manager.popBackStackImmediate(backStateName, 0);
    } catch (Exception e) {

    }

    if (!fragmentPopped) { // fragment not in back stack, create it.
      FragmentTransaction ft = manager.beginTransaction();
      ft.replace(R.id.frame_container, fragment);
      // ft.addToBackStack(backStateName);
      if (bCommitAllowingStateLoss) ft.commitAllowingStateLoss();
      else ft.commit();
    }
  }
コード例 #9
0
  private void clearBackStack() {
    FragmentManager fragmentManager = getSupportFragmentManager();

    if (0 < fragmentManager.getBackStackEntryCount()) {
      int id = fragmentManager.getBackStackEntryAt(0).getId();
      fragmentManager.popBackStackImmediate(id, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }

    List<Fragment> fragments = fragmentManager.getFragments();
    if (fragments == null) {
      return;
    }
    FragmentTransaction trans = fragmentManager.beginTransaction();
    for (Fragment fragment : fragments) {
      if (fragment != null) {
        trans.remove(fragment);
      }
    }
    trans.commit();
  }
コード例 #10
0
 private void popBackStackNoAction() {
   FragmentManager fragMan = getFragmentManager();
   fragMan.removeOnBackStackChangedListener(this);
   fragMan.popBackStackImmediate(BACK_STACK_INPUT, FragmentManager.POP_BACK_STACK_INCLUSIVE);
   mBackStackLevel = null;
 }