Example usage for android.support.v4.app FragmentManager getBackStackEntryCount

List of usage examples for android.support.v4.app FragmentManager getBackStackEntryCount

Introduction

In this page you can find the example usage for android.support.v4.app FragmentManager getBackStackEntryCount.

Prototype

public abstract int getBackStackEntryCount();

Source Link

Document

Return the number of entries currently in the back stack.

Usage

From source file:poche.fm.potunes.ActionBarCastActivity.java

@Override
public void onBackPressed() {
    if (result != null && result.isDrawerOpen()) {
        result.closeDrawer();/* w  ww .  j  a  va 2 s  .co  m*/
    } else {
        // If the drawer is open, back will close it
        // Otherwise, it may return to the previous fragment stack
        FragmentManager fragmentManager = getSupportFragmentManager();
        if (fragmentManager.getBackStackEntryCount() > 0) {
            fragmentManager.popBackStackImmediate();
        } else {
            // Lastly, it will rely on the system behavior for back
            moveTaskToBack(true);
        }
    }

}

From source file:com.recurly.androidsdk.BaseActivity.java

public BaseFragment pushFragment(Class fragmentClass) {

    FragmentManager fragmentManager = getSupportFragmentManager();

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    BaseFragment currentFragment = (BaseFragment) fragmentManager
            .findFragmentByTag("" + fragmentManager.getBackStackEntryCount());

    BaseFragment fragment = makeInstance(fragmentClass);

    if (currentFragment != null) {
        fragmentTransaction.hide(currentFragment);
    }/*from   ww  w. j  a v a 2  s. com*/
    fragmentTransaction.add(R.id.container, fragment, "" + (fragmentManager.getBackStackEntryCount() + 1));

    // add new fragment to the back stack
    fragmentTransaction.addToBackStack(fragmentClass.getName());

    fragmentTransaction.commit();

    return fragment;
}

From source file:org.mariotaku.twidere.activity.DualPaneActivity.java

@Override
protected void onStart() {
    final FragmentManager fm = getSupportFragmentManager();
    if (!isDualPaneMode() && !FragmentManagerTrojan.isStateSaved(fm)) {
        final int count = fm.getBackStackEntryCount();
        for (int i = 0; i < count; i++) {
            fm.popBackStackImmediate();/*w  w w  . jav  a2  s  .  c o  m*/
        }
    }
    super.onStart();
    final boolean dual_pane_in_portrait = mPreferences.getBoolean(PREFERENCE_KEY_DUAL_PANE_IN_PORTRAIT, false);
    final boolean dual_pane_in_landscape = mPreferences.getBoolean(PREFERENCE_KEY_DUAL_PANE_IN_LANDSCAPE,
            false);
    final Resources res = getResources();
    final int orientation = res.getConfiguration().orientation;
    switch (orientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        if (mDualPaneInLandscape != dual_pane_in_landscape) {
            restart();
        }
        break;
    case Configuration.ORIENTATION_PORTRAIT:
        if (mDualPaneInPortrait != dual_pane_in_portrait) {
            restart();
        }
        break;
    }
}

From source file:com.cw.litenote.drawer.Drawer.java

public Drawer(AppCompatActivity activity) {
    drawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);

    mNavigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    mNavigationView.setItemIconTintList(null);// use original icon color

    // set icon for folder draggable: portrait
    if (Util.isPortraitOrientation(MainAct.mAct) && (MainAct.mPref_show_note_attribute != null)) {
        if (MainAct.mPref_show_note_attribute.getString("KEY_ENABLE_FOLDER_DRAGGABLE", "no")
                .equalsIgnoreCase("yes"))
            mNavigationView.getMenu().findItem(R.id.ENABLE_FOLDER_DRAG_AND_DROP)
                    .setIcon(R.drawable.btn_check_on_holo_light);
        else//  ww w  . j a v  a 2 s  . com
            mNavigationView.getMenu().findItem(R.id.ENABLE_FOLDER_DRAG_AND_DROP)
                    .setIcon(R.drawable.btn_check_off_holo_light);
    }

    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            menuItem.setChecked(true);
            switch (menuItem.getItemId()) {
            case R.id.ADD_NEW_FOLDER:
                FolderUi.renewFirstAndLast_folderId();
                FolderUi.addNewFolder(MainAct.mAct, FolderUi.mLastExist_folderTableId + 1,
                        MainAct.mFolder.getAdapter());
                return true;

            case R.id.ENABLE_FOLDER_DRAG_AND_DROP:
                if (MainAct.mPref_show_note_attribute.getString("KEY_ENABLE_FOLDER_DRAGGABLE", "no")
                        .equalsIgnoreCase("yes")) {
                    menuItem.setIcon(R.drawable.btn_check_off_holo_light);
                    MainAct.mPref_show_note_attribute.edit().putString("KEY_ENABLE_FOLDER_DRAGGABLE", "no")
                            .apply();
                    DragSortListView listView = (DragSortListView) act.findViewById(R.id.drawer_listview);
                    listView.setDragEnabled(false);
                    Toast.makeText(act,
                            act.getResources().getString(R.string.drag_folder) + ": "
                                    + act.getResources().getString(R.string.set_disable),
                            Toast.LENGTH_SHORT).show();
                } else {
                    menuItem.setIcon(R.drawable.btn_check_on_holo_light);
                    MainAct.mPref_show_note_attribute.edit().putString("KEY_ENABLE_FOLDER_DRAGGABLE", "yes")
                            .apply();
                    DragSortListView listView = (DragSortListView) act.findViewById(R.id.drawer_listview);
                    listView.setDragEnabled(true);
                    Toast.makeText(act,
                            act.getResources().getString(R.string.drag_folder) + ": "
                                    + act.getResources().getString(R.string.set_enable),
                            Toast.LENGTH_SHORT).show();
                }
                MainAct.mFolder.getAdapter().notifyDataSetChanged();
                act.invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
                return true;

            case R.id.DELETE_FOLDERS:

                DB_drawer dB_drawer = new DB_drawer(act);
                if (dB_drawer.getFoldersCount(true) > 0) {
                    closeDrawer();
                    MainAct.mMenu.setGroupVisible(R.id.group_notes, false); //hide the menu
                    DeleteFolders delFoldersFragment = new DeleteFolders();
                    MainAct.mFragmentTransaction = MainAct.mAct.getSupportFragmentManager().beginTransaction();
                    MainAct.mFragmentTransaction.setCustomAnimations(R.anim.fragment_slide_in_left,
                            R.anim.fragment_slide_out_left, R.anim.fragment_slide_in_right,
                            R.anim.fragment_slide_out_right);
                    MainAct.mFragmentTransaction.replace(R.id.content_frame, delFoldersFragment)
                            .addToBackStack("delete_folders").commit();
                } else {
                    Toast.makeText(act, R.string.config_export_none_toast, Toast.LENGTH_SHORT).show();
                }
                return true;

            default:
                return true;
            }
        }
    });

    act = activity;
    listView = (DragSortListView) act.findViewById(R.id.drawer_listview);
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    drawerToggle = new ActionBarDrawerToggle(act, /* host Activity */
            drawerLayout, /* DrawerLayout object */
            MainAct.mToolbar, /* tool bar */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerOpened(View drawerView) {
            System.out.println("Drawer / _onDrawerOpened ");

            if (act.getSupportActionBar() != null) {
                act.getSupportActionBar().setTitle(R.string.app_name);
                MainAct.mToolbar.setLogo(R.drawable.ic_launcher);
            }

            act.invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()

            if (listView.getCount() > 0) {
                // will call Folder_adapter _getView to update audio playing high light
                listView.invalidateViews();
            }
        }

        public void onDrawerClosed(View view) {
            System.out.println("Drawer / _onDrawerClosed / FolderUi.getFocus_folderPos() = "
                    + FolderUi.getFocus_folderPos());

            FragmentManager fragmentManager = act.getSupportFragmentManager();
            if (fragmentManager.getBackStackEntryCount() == 0) {
                act.invalidateOptionsMenu(); // creates a call to onPrepareOptionsMenu()

                DB_drawer dB_drawer = new DB_drawer(act);
                if (dB_drawer.getFoldersCount(true) > 0) {
                    int pos = listView.getCheckedItemPosition();
                    MainAct.mFolderTitle = dB_drawer.getFolderTitle(pos, true);

                    if (act.getSupportActionBar() != null) {
                        act.getSupportActionBar().setTitle(MainAct.mFolderTitle);
                        MainAct.mToolbar.setLogo(null);
                    }
                }

                MainAct.openFolder();
            }
        }
    };
}

From source file:sample.multithreading.DownloaderActivity.java

/**
 * This works with the compatible action bar as well as with menus on
 * pre-Honeycomb devices.//from  ww w . j av  a 2s. com
 */
@Override
public boolean onOptionsItemSelected(MenuItem paramMenuItem) {
    switch (paramMenuItem.getItemId()) {
    case android.R.id.home: {
        FragmentManager localFragmentManager = getSupportFragmentManager();
        int count = localFragmentManager.getBackStackEntryCount();
        if (count > 0) {
            localFragmentManager.popBackStack();
        }
    }
    default:
        return super.onOptionsItemSelected(paramMenuItem);
    }
}

From source file:com.inter.trade.ui.fragment.buylicensekey.BuyLicenseKeyBindFragment.java

/**
 * ?????  BuyLicenseKeyMainFragment//w w  w.j  ava  2 s.  c om
 */
private void goBack() {
    if (getActivity() == null) {
        Logger.d(TAG, "goBack()-->getActivity()==null");
        return;
    }

    FragmentManager manager = getActivity().getSupportFragmentManager();

    if (manager == null) {
        Logger.d(TAG, "goBack()-->getSupportFragmentManager()==null");
        return;
    }

    int len = manager.getBackStackEntryCount();
    if (len > 0) {
        manager.popBackStack();
    }
}

From source file:sample.multithreading.DownloaderActivity.java

@Override
public void onBackStackChanged() {
    int previousStackCount = mPreviousStackCount;
    FragmentManager localFragmentManager = getSupportFragmentManager();
    int currentStackCount = localFragmentManager.getBackStackEntryCount();
    mPreviousStackCount = currentStackCount;
    boolean popping = currentStackCount < previousStackCount;
    Log.d(LOG_TAG, "backstackchanged: popping = " + popping);
    if (popping) {
        setFullScreen(false);//w ww .  j  a v  a  2  s. c o m
    }
}

From source file:org.jnrain.mobile.ui.MainActivity.java

@Override
public void onBackPressed() {
    FragmentManager fm = getSupportFragmentManager();
    int fragCount = fm.getBackStackEntryCount();

    Log.d(TAG, "[onBackPressed] getBackStackEntryCount() = " + Integer.toString(fragCount));

    if (fragCount > 0) {
        // navigate to previous fragment
        fm.popBackStack();//w w  w .ja  v  a2s  . c om

        // update SlidingMenu Back behavior
        if (fragCount == 1) {
            // we've just popped the last entry, restore to
            // BACK_TO_MENU
            setBackAction(SlidingActivityBackAction.BACK_TO_MENU);
        }

        return;
    }

    super.onBackPressed();
}

From source file:org.dmfs.android.microfragments.transitions.BackTransition.java

@Override
public void prepare(@NonNull Context context, @NonNull FragmentManager fragmentManager,
        @NonNull MicroFragmentHost host, @NonNull MicroFragment<?> previousStep) {
    boolean result = fragmentManager.popBackStackImmediate();
    // make sure we also skip all skipable steps.
    if (result && fragmentManager.getBackStackEntryCount() > 0 && "skip".equals(
            fragmentManager.getBackStackEntryAt(fragmentManager.getBackStackEntryCount() - 1).getName())) {
        fragmentManager.popBackStackImmediate("skip", FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }/*from  www. j  ava  2  s .c o m*/

    mResponseCage.pigeon(result).send(context);
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.tablet.ScheduleMultiPaneActivity.java

@Override
public void onBeforeCommitReplaceFragment(FragmentManager fm, FragmentTransaction ft, Fragment fragment) {
    super.onBeforeCommitReplaceFragment(fm, ft, fragment);

    if (fragment instanceof SessionsFragment) {
        fm.popBackStack();/*  w w  w . jav a 2  s.c  o  m*/
    } else if (fragment instanceof SessionDetailFragment) {
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
        }
        ft.addToBackStack(null);
    }
    updateBreadCrumb();
}