Search in sources :

Example 76 with FragmentTransaction

use of android.support.v4.app.FragmentTransaction in project native-navigation by airbnb.

the class ScreenCoordinator method pushScreen.

public void pushScreen(Fragment fragment, @Nullable Bundle options) {
    FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction().setAllowOptimization(true);
    Fragment currentFragment = getCurrentFragment();
    if (currentFragment == null) {
        throw new IllegalStateException("There is no current fragment. You must present one first.");
    }
    if (ViewUtils.isAtLeastLollipop() && options != null && options.containsKey(TRANSITION_GROUP)) {
        setupFragmentForSharedElement(currentFragment, fragment, ft, options);
    } else {
        PresentAnimation anim = PresentAnimation.Push;
        ft.setCustomAnimations(anim.enter, anim.exit, anim.popEnter, anim.popExit);
    }
    BackStack bsi = getCurrentBackStack();
    ft.detach(currentFragment).add(container.getId(), fragment).addToBackStack(null).commit();
    bsi.pushFragment(fragment);
    Log.d(TAG, toString());
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) Fragment(android.support.v4.app.Fragment)

Example 77 with FragmentTransaction

use of android.support.v4.app.FragmentTransaction in project Fragmentation by YoKeyword.

the class FragmentationDelegate method replaceTransaction.

/**
     * replace事务, 主要用于子Fragment之间的replace
     */
void replaceTransaction(FragmentManager fragmentManager, int containerId, SupportFragment to, boolean addToBack) {
    fragmentManager = checkFragmentManager(fragmentManager, null);
    if (fragmentManager == null)
        return;
    checkNotNull(to, "toFragment == null");
    bindContainerId(containerId, to);
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(containerId, to, to.getClass().getName());
    if (addToBack) {
        ft.addToBackStack(to.getClass().getName());
    }
    Bundle bundle = to.getArguments();
    bundle.putBoolean(FRAGMENTATION_ARG_IS_ROOT, true);
    supportCommit(fragmentManager, ft);
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) Bundle(android.os.Bundle)

Example 78 with FragmentTransaction

use of android.support.v4.app.FragmentTransaction in project Fragmentation by YoKeyword.

the class FragmentationDelegate method loadMultipleRootTransaction.

/**
     * 加载多个根Fragment
     */
void loadMultipleRootTransaction(FragmentManager fragmentManager, int containerId, int showPosition, SupportFragment... tos) {
    fragmentManager = checkFragmentManager(fragmentManager, null);
    if (fragmentManager == null)
        return;
    FragmentTransaction ft = fragmentManager.beginTransaction();
    for (int i = 0; i < tos.length; i++) {
        SupportFragment to = tos[i];
        bindContainerId(containerId, tos[i]);
        String toName = to.getClass().getName();
        ft.add(containerId, to, toName);
        if (i != showPosition) {
            ft.hide(to);
        }
    }
    supportCommit(fragmentManager, ft);
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction)

Example 79 with FragmentTransaction

use of android.support.v4.app.FragmentTransaction in project Fragmentation by YoKeyword.

the class SupportFragment method processRestoreInstanceState.

private void processRestoreInstanceState(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        if (isSupportHidden()) {
            ft.hide(this);
        } else {
            ft.show(this);
        }
        ft.commit();
    }
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction)

Example 80 with FragmentTransaction

use of android.support.v4.app.FragmentTransaction in project Fragmentation by YoKeyword.

the class FragmentationDelegate method showHideFragment.

/**
     * show一个Fragment,hide另一个/多个Fragment ; 主要用于类似微信主页那种 切换tab的情况
     *
     * @param showFragment 需要show的Fragment
     * @param hideFragment 需要hide的Fragment
     */
void showHideFragment(FragmentManager fragmentManager, SupportFragment showFragment, SupportFragment hideFragment) {
    fragmentManager = checkFragmentManager(fragmentManager, null);
    if (fragmentManager == null)
        return;
    if (showFragment == hideFragment)
        return;
    FragmentTransaction ft = fragmentManager.beginTransaction().show(showFragment);
    if (hideFragment == null) {
        List<Fragment> fragmentList = fragmentManager.getFragments();
        if (fragmentList != null) {
            for (Fragment fragment : fragmentList) {
                if (fragment != null && fragment != showFragment) {
                    ft.hide(fragment);
                }
            }
        }
    } else {
        ft.hide(hideFragment);
    }
    supportCommit(fragmentManager, ft);
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) Fragment(android.support.v4.app.Fragment)

Aggregations

FragmentTransaction (android.support.v4.app.FragmentTransaction)392 Fragment (android.support.v4.app.Fragment)135 FragmentManager (android.support.v4.app.FragmentManager)79 View (android.view.View)29 DialogFragment (android.support.v4.app.DialogFragment)27 FragmentActivity (android.support.v4.app.FragmentActivity)25 Bundle (android.os.Bundle)21 TextView (android.widget.TextView)19 FragmentTransaction (android.app.FragmentTransaction)18 Intent (android.content.Intent)18 Button (android.widget.Button)17 OnClickListener (android.view.View.OnClickListener)16 SherlockFragment (com.actionbarsherlock.app.SherlockFragment)12 ActionBar (android.support.v7.app.ActionBar)8 TargetApi (android.annotation.TargetApi)6 AppCompatActivity (android.support.v7.app.AppCompatActivity)6 Toolbar (android.support.v7.widget.Toolbar)6 FriendsTimeLineFragment (org.qii.weiciyuan.ui.maintimeline.FriendsTimeLineFragment)6 UserInfoFragment (org.qii.weiciyuan.ui.userinfo.UserInfoFragment)6 Transition (android.transition.Transition)5