@Override
  public void onBackPressed() {
    FragmentManager manager = getSupportFragmentManager();
    long currentTimeMillis = System.currentTimeMillis();
    if (manager.getBackStackEntryCount() == 0) {
      boolean shouldExit = ((currentTimeMillis - lastBackPressTime) / 1000) < 3000;
      if (shouldExit) {
        super.onBackPressed();
      } else {
        Toast.makeText(this, "Press back again to exit", Toast.LENGTH_LONG).show();
      }
    } else {
      // If there are back-stack entries, leave the FragmentActivity
      // implementation take care of them.
      // super.onBackPressed();
      manager.popBackStack();

      if (preTitle1 != null) {
        tv_thu_menu.setText(preTitle1);
        preTitle1 = null;
      } else if (preTitle != null) {
        tv_thu_menu.setText(preTitle);
        if (preTitle.equalsIgnoreCase(weekDay)) {
          tv_ngay_menu.setVisibility(View.VISIBLE);
        } else {
          tv_ngay_menu.setVisibility(View.GONE);
        }
        preTitle = null;
      }
    }
    lastBackPressTime = currentTimeMillis;
  }
  @Override
  public void onThemeSelected(String themeId) {
    FragmentManager fm = getSupportFragmentManager();

    if (!Utils.isXLarge(ThemeBrowserActivity.this)) {
      // show details as a fragment on top
      FragmentTransaction ft = fm.beginTransaction();

      if (mSearchFragment != null && mSearchFragment.isVisible()) {
        fm.popBackStack();
      }

      setupBaseLayout();
      mDetailsFragment = ThemeDetailsFragment.newInstance(themeId);
      ft.add(R.id.theme_browser_container, mDetailsFragment, ThemeDetailsFragment.TAG);
      ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
      ft.addToBackStack(null);
      ft.commit();
    } else {
      // show details as a dialog
      mDetailsFragment = ThemeDetailsFragment.newInstance(themeId);
      mDetailsFragment.show(getSupportFragmentManager(), ThemeDetailsFragment.TAG);
      getSupportFragmentManager().executePendingTransactions();
      int minWidth = getResources().getDimensionPixelSize(R.dimen.theme_details_dialog_min_width);
      int height = getResources().getDimensionPixelSize(R.dimen.theme_details_dialog_height);
      int width = Math.max((int) (DisplayUtils.getDisplayPixelWidth(this) * 0.6), minWidth);
      mDetailsFragment.getDialog().getWindow().setLayout(width, height);
    }
  }
 protected void popCommentDetail() {
   FragmentManager fm = getSupportFragmentManager();
   CommentFragment f = (CommentFragment) fm.findFragmentById(R.id.commentDetail);
   if (f == null) {
     fm.popBackStack();
   }
 }
 public void removeFragment(Fragment fragment) {
   if (fragment != null) {
     // Get fragment manager form our activity
     FragmentManager fragmentManager = mActivity.getSupportFragmentManager();
     fragmentManager.popBackStack();
   }
 }
 protected void popBackQuestionFragment() {
   FragmentManager fm = getActivity().getSupportFragmentManager();
   fm.popBackStack();
   FragmentTransaction transaction = fm.beginTransaction();
   transaction.detach(CameraFragment.this);
   transaction.commit();
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();

    if (itemId == android.R.id.home) {
      FragmentManager fm = getSupportFragmentManager();
      if (fm.getBackStackEntryCount() > 0) {
        fm.popBackStack();
        setupBaseLayout();
        return true;
      }
    } else if (itemId == R.id.menu_search) {
      FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
      if (mSearchFragment == null) {
        mSearchFragment = ThemeSearchFragment.newInstance();
      }
      ft.add(R.id.theme_browser_container, mSearchFragment, ThemeSearchFragment.TAG);
      ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
      ft.addToBackStack(null);
      ft.commit();
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
 public void clearBackStack() {
   FragmentManager manager = getSupportFragmentManager();
   if (manager.getBackStackEntryCount() > 0) {
     FragmentManager.BackStackEntry first = manager.getBackStackEntryAt(0);
     manager.popBackStack(first.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
   }
 }
 @Override
 public void onBackPressed() {
   FragmentManager fragmentManager = getSupportFragmentManager();
   if (fragmentManager.getBackStackEntryCount() > 0) {
     fragmentManager.popBackStack();
   } else {
     super.onBackPressed();
   }
 }
  @Override
  public void switchToWelcome() {
    for (int i = 0; i < fm.getBackStackEntryCount(); ++i) {
      fm.popBackStack();
    }

    Intent intent = new Intent(this, WelcomeActivity.class);
    startActivity(intent);
  }
 private void clearBackStack() {
   FragmentManager fragmentManager = MainActivity.getInstance().getSupportFragmentManager();
   int count = fragmentManager.getBackStackEntryCount();
   if (count > 0) {
     BackStackEntry entry = fragmentManager.getBackStackEntryAt(0);
     fragmentManager.popBackStack(entry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
     popAllFragment();
   }
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        mFragmentManager.popBackStack();
        return true;
    }

    return super.onOptionsItemSelected(item);
  }
 /*package*/ void finishFragment() {
   FragmentActivity activity = getActivity();
   if (activity instanceof JRFragmentHostActivity) {
     if (mFragmentResult != null) ((JRFragmentHostActivity) activity)._setResult(mFragmentResult);
     activity.finish();
   } else if (null != activity) {
     FragmentManager fm = activity.getSupportFragmentManager();
     int bsec = fm.getBackStackEntryCount();
     if (bsec > 0 && fm.getBackStackEntryAt(bsec - 1).getName().equals(getLogTag())) {
       fm.popBackStack();
     } else if (bsec > 0) {
       Log.e(TAG, "Error trying to finish fragment not on top of back stack");
       fm.popBackStack(getLogTag(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
     } else { // bsec == 0
       // Root fragment, if it's finishing it's because authentication finished?
       fm.beginTransaction().remove(this).setTransition(FragmentTransaction.TRANSIT_NONE).commit();
     }
   }
 }
 // 切界面
 public void changeFrament(Fragment fragment, Bundle bundle, String tag) {
   for (int i = 0, count = fragmentManager.getBackStackEntryCount(); i < count; i++) {
     fragmentManager.popBackStack();
   }
   FragmentTransaction fg = fragmentManager.beginTransaction();
   fragment.setArguments(bundle);
   fg.add(R.id.fragmentRootLinearLayout, fragment, tag);
   fg.addToBackStack(tag);
   fg.commitAllowingStateLoss();
 }
Exemple #14
0
  @Override
  public void customOnNavigateUp() {
    final FragmentManager manager = getSupportFragmentManager();
    if (manager.getBackStackEntryCount() == 0) {
      NavUtils.navigateUpFromSameTask(this);
      return;
    }

    manager.popBackStack();
  }
 public void showDoctorFragment() {
   Fragment generalFragment = new DoctorManagementFragment();
   FragmentManager fragmentManager = getSupportFragmentManager();
   fragmentManager.popBackStack();
   FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
   fragmentTransaction.replace(R.id.fragmentContainer, generalFragment, DOCTOR_FRAGMENT_TAG);
   fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
   fragmentTransaction.addToBackStack(DOCTOR_FRAGMENT_TAG);
   fragmentTransaction.commit();
 }
Exemple #16
0
 private void popFragmentStack() {
   if (((MainActivity) getActivity()).getOnKeyBackPressedListener() instanceof FanFragment) {
     if (mFM.getBackStackEntryCount() > 0) {
       mFM.popBackStack();
     } else {
       MainActivity activity = (MainActivity) getActivity();
       activity.setOnKeyBackPressedListener(null);
       activity.onBackPressed();
     }
   }
 }
  @Override
  public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
      Log.d("BACK", "Back tracking");
      FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
      fragmentManager.popBackStack();
      return true;
    }

    return false;
  }
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK) {
     FragmentManager fragmentManager = getSupportFragmentManager();
     if (fragmentManager.getBackStackEntryCount() > 1) {
       fragmentManager.popBackStack();
       return false;
     }
   }
   return super.onKeyDown(keyCode, event);
 }
  public void clear() {
    FragmentElement fragmentElement = popInternal();
    while (fragmentElement != null) {
      hide(fragmentElement.getFragment());
      fragmentElement = popInternal();
    }

    int backStackSize = fm.getBackStackEntryCount();
    for (int i = 0; i < backStackSize; i++) {
      fm.popBackStack();
    }
  }
 public void showVaccinFragment(String id) {
   Fragment generalFragment = VaccinationInformationFragment.getInstance(id);
   FragmentManager fragmentManager = getSupportFragmentManager();
   fragmentManager.popBackStack();
   FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
   fragmentTransaction.replace(R.id.fragmentContainer, generalFragment, HOME_FRAGMENT_TAG);
   fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
   fragmentTransaction.addToBackStack(HOME_FRAGMENT_TAG);
   fragmentTransaction.commit();
   which = HOME_FRAGMENT;
   invalidateOptionsMenu();
 }
 @Override
 public void onBackPressed() {
   FragmentManager fm = getSupportFragmentManager();
   if (mMenuDrawer.isMenuVisible()) {
     super.onBackPressed();
   } else if (fm.getBackStackEntryCount() > 0) {
     fm.popBackStack();
     setupBaseLayout();
   } else {
     super.onBackPressed();
   }
 }
 public void showGeneralFragment(String id) {
   Fragment generalFragment = GeneralInformationFragment.getInstance(id);
   FragmentManager fragmentManager = getSupportFragmentManager();
   fragmentManager.popBackStack();
   FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
   fragmentTransaction.replace(R.id.fragmentContainer, generalFragment, GENERAL_FRAGMENT_TAG);
   fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
   fragmentTransaction.addToBackStack(GENERAL_FRAGMENT_TAG);
   fragmentTransaction.commit();
   which = GENERAL_FRAGMENT;
   invalidateOptionsMenu();
   menuItemClickListener = (OnMenuItemClickListener) generalFragment;
 }
 public void showDietFragment(String profileName) {
   Fragment dietFragment = DietInformationFragment.getInstance(profileName);
   FragmentManager fragmentManager = getSupportFragmentManager();
   fragmentManager.popBackStack();
   FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
   fragmentTransaction.replace(R.id.fragmentContainer, dietFragment, DIET_FRAGMENT_TAG);
   fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
   fragmentTransaction.addToBackStack(DIET_FRAGMENT_TAG);
   fragmentTransaction.commit();
   which = DIET_FRAGMENT;
   invalidateOptionsMenu();
   onDietCreateListener = (OnDietCreateListener) dietFragment;
 }
 @Override
 public void onBack() {
   if (((MainActivity) getActivity()).getOnKeyBackPressedListener()
       instanceof NotificationFragment) {
     if (mFM.getBackStackEntryCount() > 0) {
       mFM.popBackStack();
     } else {
       MainActivity activity = (MainActivity) getActivity();
       activity.setOnKeyBackPressedListener(null);
       activity.onBackPressed();
     }
   }
 }
 @Override
 public void onBackPressed() {
   if (binding.drawer.isDrawerOpen(GravityCompat.START)) {
     binding.drawer.closeDrawer(GravityCompat.START);
     return;
   }
   FragmentManager fm = getSupportFragmentManager();
   if (fm.getBackStackEntryCount() > 0) {
     fm.popBackStack();
     return;
   }
   super.onBackPressed();
 }
Exemple #26
0
 @Override
 public void popFragment() throws Exception {
   boolean isLast = false;
   FragmentManager fm = getSupportFragmentManager();
   if (fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1)
       .getName()
       .equals(FIRST_POPOVER_FRAGMENT_FLAG)) {
     isLast = true;
   }
   fm.popBackStack();
   if (isLast) {
     viewHolder.showHideExtendFragment(View.GONE);
   }
 }
 @Override
 public void onCrumbSelection(String absolutePath, int index, int count) {
   FragmentManager fm = getChildFragmentManager();
   boolean poppedAny = false;
   while (mDirStack.size() > 1 && !TextUtils.equals(absolutePath, mDirStack.peek())) {
     mDirStack.pop();
     fm.popBackStack();
     poppedAny = true;
   }
   if (poppedAny) {
     fm.executePendingTransactions();
     updateBreadcrumbs();
   }
 }
  private void loadAddProductFragment(String productId) {
    if (drawerLayout.isDrawerOpen(Gravity.LEFT)) {
      drawerLayout.closeDrawer(Gravity.LEFT);
    }

    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    fragmentManager.executePendingTransactions();
    Fragment addProductFragment = AddProductFragment.getInstance(productId.toString());
    fragmentManager
        .beginTransaction()
        .add(R.id.frame, addProductFragment, AddProductFragment.class.getSimpleName())
        .commit();
  }
 private void onSessionStateChange(Session session, SessionState state, Exception exception) {
   if (isResumed) {
     FragmentManager manager = getSupportFragmentManager();
     int backStackSize = manager.getBackStackEntryCount();
     for (int i = 0; i < backStackSize; i++) {
       manager.popBackStack();
     }
     if (state.isOpened()) {
       showFragment(SELECTION, false);
     } else if (state.isClosed()) {
       showFragment(SPLASH, false);
     }
   }
 }
  private void onPlacePickerDone(PlacePickerFragment fragment) {
    FragmentManager fm = getSupportFragmentManager();
    fm.popBackStack();

    String result = "";

    GraphPlace selection = fragment.getSelection();
    if (selection != null) {
      result = selection.getName();
    } else {
      result = "no place";
    }

    showAlert("picked", result);
  }