Java Code Examples for android.support.v4.app.FragmentManager#BackStackEntry

The following examples show how to use android.support.v4.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: NavigatorHelper.java    From Navigator with Apache License 2.0 6 votes vote down vote up
public boolean canGoBack(String tag, int container, FragmentManager fragmentManager) {
    if (TextUtils.isEmpty(tag)) {
        return (fragmentManager.getBackStackEntryCount() > 1);
    } else {
        List<FragmentManager.BackStackEntry> fragmentList = fragmentList();
        Fragment fragment = fragmentManager.findFragmentById(container);
        if (fragment != null && tag.equalsIgnoreCase(fragment.getTag())) {
            return false;
        }
        for (int i = 0; i < fragmentList.size(); i++) {
            if (tag.equalsIgnoreCase(fragmentList.get(i).getName())) {
                return true;
            }
        }
        return false;
    }
}
 
Example 2
Source File: NavigatorHelper.java    From Navigator with Apache License 2.0 6 votes vote down vote up
public void goBackTo(String tag) throws NavigatorException {
    FragmentManager fragmentManager = ((FragmentActivity) mContext).getSupportFragmentManager();
    if (fragmentManager.findFragmentByTag(tag) != null) {
        List<FragmentManager.BackStackEntry> fragmentList = fragmentList();
        Collections.reverse(fragmentList);
        for (int i = 0; i < fragmentList.size(); i++) {
            if (!tag.equalsIgnoreCase(fragmentList.get(i).getName())) {
                fragmentManager.popBackStack();
            } else {
                listStep.add(tag);
                return;
            }
        }
    } else {
        Log.e(TAG, "no fragment found");
        String message = "Fragment with TAG[" + tag + "] not found into backstack entry";
        throw new NavigatorException(message);
    }
}
 
Example 3
Source File: NavigatorUtils.java    From Navigator with Apache License 2.0 6 votes vote down vote up
/**
 * @param tag point to return
 * @throws NavigatorException navigator specific error
 */
public void goBackToSpecificPoint(String tag) throws NavigatorException {
    FragmentManager fragmentManager = ((FragmentActivity) mContextReference.getContext()).getSupportFragmentManager();
    if (fragmentManager.findFragmentByTag(tag) != null) {
        List<FragmentManager.BackStackEntry> fragmentList = fragmentList();
        Collections.reverse(fragmentList);
        for (int i = 0; i < fragmentList.size(); i++) {
            if (!tag.equalsIgnoreCase(fragmentList.get(i).getName())) {
                fragmentManager.popBackStack();
            } else {
                break;
            }
        }
    } else {
        Log.e(TAG, "no fragment found");
        String message = "Fragment with TAG[" + tag + "] not found into back stack entry";
        throw new NavigatorException(message);
    }
}
 
Example 4
Source File: MainActivity.java    From openshop.io-android with MIT License 6 votes vote down vote up
/**
     * Method clear fragment backStack (back history). On bottom of stack will remain Fragment added by {@link #addInitialFragment()}.
     */
    private void clearBackStack() {
        Timber.d("Clearing backStack");
        FragmentManager manager = getSupportFragmentManager();
        if (manager.getBackStackEntryCount() > 0) {
            if (BuildConfig.DEBUG) {
                for (int i = 0; i < manager.getBackStackEntryCount(); i++) {
                    Timber.d("BackStack content_%d= id: %d, name: %s", i, manager.getBackStackEntryAt(i).getId(), manager.getBackStackEntryAt(i).getName());
                }
            }
            FragmentManager.BackStackEntry first = manager.getBackStackEntryAt(0);
            manager.popBackStackImmediate(first.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
        Timber.d("backStack cleared.");
//        TODO maybe implement own fragment backStack handling to prevent banner fragment recreation during clearing.
//        http://stackoverflow.com/questions/12529499/problems-with-android-fragment-back-stack
    }
 
Example 5
Source File: SettingsActivity.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
private int setTitleFromBackStack() {
    final int count = getFragmentManager().getBackStackEntryCount();

    if (count == 0) {
        if (mInitialTitleResId > 0) {
            setTitle(mInitialTitleResId);
        } else {
            setTitle(mInitialTitle);
        }
        return 0;
    }

    FragmentManager.BackStackEntry bse = getSupportFragmentManager().getBackStackEntryAt(count - 1);
    setTitleFromBackStackEntry(bse);

    return count;
}
 
Example 6
Source File: SettingsActivity.java    From HeadsUp with GNU General Public License v2.0 6 votes vote down vote up
private int setTitleFromBackStack() {
    final int count = getFragmentManager().getBackStackEntryCount();

    if (count == 0) {
        if (mInitialTitleResId > 0) {
            setTitle(mInitialTitleResId);
        } else {
            setTitle(mInitialTitle);
        }
        return 0;
    }

    FragmentManager.BackStackEntry bse = getSupportFragmentManager().getBackStackEntryAt(count - 1);
    setTitleFromBackStackEntry(bse);

    return count;
}
 
Example 7
Source File: MainActivity.java    From Androzic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addFragment(Fragment fragment, String tag)
{
	FragmentManager fm = getSupportFragmentManager();
	// Get topmost fragment
	Fragment parent;
	if (fm.getBackStackEntryCount() > 0)
	{
		FragmentManager.BackStackEntry bse = fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1);
		parent = fm.findFragmentByTag(bse.getName());
	}
	else
	{
		parent = fm.findFragmentById(R.id.content_frame);
	}
	FragmentTransaction ft = fm.beginTransaction();
	// Detach parent
	ft.detach(parent);
	// Add new fragment to back stack
	ft.add(R.id.content_frame, fragment, tag);
	ft.addToBackStack(tag);
	ft.commit();
}
 
Example 8
Source File: FragmentUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Pop all fragments.
 *
 * @param fm The manager of fragment.
 */
public static void popAll(@NonNull final FragmentManager fm, final boolean isImmediate) {
    if (fm.getBackStackEntryCount() > 0) {
        FragmentManager.BackStackEntry entry = fm.getBackStackEntryAt(0);
        if (isImmediate) {
            fm.popBackStackImmediate(entry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
        } else {
            fm.popBackStack(entry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
    }
}
 
Example 9
Source File: NavigatorUtils.java    From Navigator with Apache License 2.0 5 votes vote down vote up
/**
 * @return tag of fragment that is actually visible, return null if no fragment are added in back stack
 */
public String getActualTag() {
    List<FragmentManager.BackStackEntry> fragmentList = fragmentList();
    if (fragmentList == null || fragmentList.size() == 0) {
        return null;
    }
    return fragmentList.get(fragmentList.size() - 1).getName();
}
 
Example 10
Source File: SettingsActivity.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
    final CharSequence title;
    final int titleRes = bse.getBreadCrumbTitleRes();
    if (titleRes > 0) {
        title = getText(titleRes);
    } else {
        title = bse.getBreadCrumbTitle();
    }
    if (title != null) {
        setTitle(title);
    }
}
 
Example 11
Source File: SettingsActivity.java    From HeadsUp with GNU General Public License v2.0 5 votes vote down vote up
private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
    final CharSequence title;
    final int titleRes = bse.getBreadCrumbTitleRes();
    if (titleRes > 0) {
        title = getText(titleRes);
    } else {
        title = bse.getBreadCrumbTitle();
    }
    if (title != null) {
        setTitle(title);
    }
}
 
Example 12
Source File: NavigatorUtils.java    From Navigator with Apache License 2.0 4 votes vote down vote up
/**
 * @param tag             point to return
 * @param container       id container
 * @param fragmentManager variable contain fragment stack
 * @return true if is possible return to tag param
 */
public boolean canGoBackToSpecificPoint(String tag, int container, FragmentManager fragmentManager) {
    if (TextUtils.isEmpty(tag)) {
        return (fragmentManager.getBackStackEntryCount() > 1);
    } else {
        List<FragmentManager.BackStackEntry> fragmentList = fragmentList();
        Fragment fragment = fragmentManager.findFragmentById(container);
        if (fragment != null && tag.equalsIgnoreCase(fragment.getTag())) {
            return false;
        }
        for (int i = 0; i < fragmentList.size(); i++) {
            if (tag.equalsIgnoreCase(fragmentList.get(i).getName())) {
                return true;
            }
        }
        return false;
    }
}
 
Example 13
Source File: NavigatorUtils.java    From Navigator with Apache License 2.0 4 votes vote down vote up
/**
 * @param tag fragment tag
 * @return true if fragment is actual visible, otherwise false
 */
public boolean isActualShowing(String tag) {
    List<FragmentManager.BackStackEntry> fragmentList = fragmentList();
    return fragmentList.get(fragmentList.size() - 1).getName().equals(tag);
}