Java Code Examples for android.app.FragmentManager#BackStackEntry

The following examples show how to use android.app.FragmentManager#BackStackEntry . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void popCurrent() {
    logger.debug("popCurrent()");
    int count = mFragmentManager.getBackStackEntryCount();
    if (count > 0) {
        FragmentManager.BackStackEntry bse = mFragmentManager.getBackStackEntryAt(count - 1);
        String fragmentName = bse.getName();
        if ("baseMapDownload".equals(fragmentName)) {
            if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                HelperUtils.showTargetedAdvice(MainActivity.this, Configuration.ADVICE_ENABLE_LOCATIONS, R.string.advice_enable_locations, mViews.locationButton, false);
            }
        } else if ("trackProperties".equals(fragmentName)) {
            HelperUtils.showTargetedAdvice(this, Configuration.ADVICE_RECORDED_TRACKS, R.string.advice_recorded_tracks, mViews.recordButton, false);
        }
    }
    mFragmentManager.popBackStack();
}
 
Example 2
Source File: FragmentManagerHelper.java    From Snake with Apache License 2.0 5 votes vote down vote up
public Fragment getLastFragment() {
    int backStackCount = mFragmentManager.getBackStackEntryCount();
    if (backStackCount <= 0) return null;

    FragmentManager.BackStackEntry backStackEntry = mFragmentManager.getBackStackEntryAt(backStackCount - 1);
    String fragmentTag = backStackEntry.getName();
    return mFragmentManager.findFragmentByTag(fragmentTag);
}
 
Example 3
Source File: ThreadFragment.java    From Ouroboros with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
    int backStackCount = getFragmentManager().getBackStackEntryCount();
    if (backStackCount > 0) {
        FragmentManager.BackStackEntry backEntry = getFragmentManager().getBackStackEntryAt(backStackCount - 1);
        String str = backEntry.getName();
        if (str.equals("threadDialog")){
            getActivity().onBackPressed();
            return false;
        }
    }
    startStatusCheck();
    return true;
}
 
Example 4
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    logger.debug("onBackPressed()");
    if (backKeyIntercepted())
        return;

    int count = mFragmentManager.getBackStackEntryCount();
    if (count > 0) {
        FragmentManager.BackStackEntry bse = mFragmentManager.getBackStackEntryAt(count - 1);
        if (BuildConfig.FULL_VERSION && "settings".equals(bse.getName()))
            HelperUtils.showTargetedAdvice(this, Configuration.ADVICE_MAP_SETTINGS, R.string.advice_map_settings, mViews.mapsButton, false);
        if ("trackProperties".equals(bse.getName()))
            HelperUtils.showTargetedAdvice(this, Configuration.ADVICE_RECORDED_TRACKS, R.string.advice_recorded_tracks, mViews.recordButton, false);
        super.onBackPressed();
        if (count == 1 && mPanelState != PANEL_STATE.NONE)
            setPanelState(PANEL_STATE.NONE);
        return;
    }

    if (count == 0 || secondBack) {
        //mBackToast.cancel();
        finish();
    } else {
        secondBack = true;
        mBackToast.show();
        mBackHandler.postDelayed(() -> secondBack = false, 2000);
    }
}
 
Example 5
Source File: MainActivity.java    From hex with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackStackChanged() {

    if (getFragmentManager().getBackStackEntryCount() < 1) {
        mCurrentItem = HexDrawer.Item.FrontPage;
    } else {
        FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(getFragmentManager().getBackStackEntryCount() - 1);
        mCurrentItem = HexDrawer.Item.valueOf(bse.getName());
    }

    updateToolbarTitle();
    updateDrawer();
}
 
Example 6
Source File: SettingsActivity.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    hideTabBar();

    int count = getFragmentManager().getBackStackEntryCount();
    if (count == 0) {
        showTopBarWithTitle(getString(R.string.settings));
    } else {
        FragmentManager.BackStackEntry entry =
                getFragmentManager().getBackStackEntryAt(count - 1);
        showTopBarWithTitle(entry.getName());
    }
}
 
Example 7
Source File: MainActivity.java    From secrecy with Apache License 2.0 5 votes vote down vote up
void addFragment(final Fragment fragment, int transition1, int transition2) {
    if (mFragmentNameList.contains(fragment.getClass())) {
        mNavigation.setSelectedItem(mFragmentNameList.indexOf(fragment.getClass()));
    }
    String tag = fragment.getClass().getName();
    if (fragmentManager.getBackStackEntryCount() >= 1) {

        String activeFragmentTag = fragmentManager
                .getBackStackEntryAt(fragmentManager
                        .getBackStackEntryCount() - 1).getName();
        Fragment activeFragment =  fragmentManager
                .findFragmentByTag(activeFragmentTag);
        // Don't switch fragment if already active
        if (activeFragment.getClass().equals(fragment.getClass())){
            return;
        }
        //clear all except lowest
        FragmentManager.BackStackEntry first = fragmentManager.getBackStackEntryAt(0);
        fragmentManager.popBackStackImmediate(first.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }
    FragmentTransaction transaction = fragmentManager.beginTransaction()
            .setCustomAnimations(transition1, transition2)
            .replace(R.id.content_frame, fragment, tag);
    if (fragment.getClass() != VaultsListFragment.class) {
        transaction = transaction
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
                .addToBackStack(tag);
    }
    transaction.commit();
}
 
Example 8
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void popAll() {
    logger.debug("popAll()");
    FragmentManager.BackStackEntry bse = mFragmentManager.getBackStackEntryAt(0);
    mFragmentManager.popBackStack(bse.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
 
Example 9
Source File: MainActivity.java    From linphone-android with GNU General Public License v3.0 4 votes vote down vote up
protected void changeFragment(Fragment fragment, String name, boolean isChild) {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();

    if (transaction.isAddToBackStackAllowed()) {
        int count = fragmentManager.getBackStackEntryCount();
        if (count > 0) {
            FragmentManager.BackStackEntry entry =
                    fragmentManager.getBackStackEntryAt(count - 1);

            if (entry != null && name.equals(entry.getName())) {
                fragmentManager.popBackStack();
                if (!isChild) {
                    // We just removed it's duplicate from the back stack
                    // And we want at least one in it
                    transaction.addToBackStack(name);
                }
            }
        }

        if (isChild) {
            transaction.addToBackStack(name);
        }
    }

    if (getResources().getBoolean(R.bool.hide_bottom_bar_on_second_level_views)) {
        if (isChild) {
            if (!isTablet()) {
                hideTabBar();
            }
        } else {
            showTabBar();
        }
    }

    Compatibility.setFragmentTransactionReorderingAllowed(transaction, false);
    if (isChild && isTablet()) {
        transaction.replace(R.id.fragmentContainer2, fragment, name);
        findViewById(R.id.fragmentContainer2).setVisibility(View.VISIBLE);
    } else {
        transaction.replace(R.id.fragmentContainer, fragment, name);
    }
    transaction.commitAllowingStateLoss();
    fragmentManager.executePendingTransactions();
}