use of android.support.v4.app.FragmentManager in project Fragmentation by YoKeyword.
the class FragmentationDelegate method getPreFragment.
/**
* 获取目标Fragment的前一个Fragment
*
* @param fragment 目标Fragment
*/
SupportFragment getPreFragment(Fragment fragment) {
FragmentManager fragmentManager = fragment.getFragmentManager();
fragmentManager = checkFragmentManager(fragmentManager, null);
if (fragmentManager == null)
return null;
List<Fragment> fragmentList = fragmentManager.getFragments();
if (fragmentList == null)
return null;
int index = fragmentList.indexOf(fragment);
for (int i = index - 1; i >= 0; i--) {
Fragment preFragment = fragmentList.get(i);
if (preFragment instanceof SupportFragment) {
return (SupportFragment) preFragment;
}
}
return null;
}
use of android.support.v4.app.FragmentManager 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);
}
use of android.support.v4.app.FragmentManager 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);
}
use of android.support.v4.app.FragmentManager in project Fragmentation by YoKeyword.
the class SupportFragment method dispatchSupportVisible.
private void dispatchSupportVisible(boolean visible) {
mIsSupportVisible = visible;
if (!mNeedDispatch) {
mNeedDispatch = true;
} else {
FragmentManager fragmentManager = getChildFragmentManager();
if (fragmentManager != null) {
List<Fragment> childFragments = fragmentManager.getFragments();
if (childFragments != null) {
for (Fragment child : childFragments) {
if (child instanceof SupportFragment && !child.isHidden() && child.getUserVisibleHint()) {
((SupportFragment) child).dispatchSupportVisible(visible);
}
}
}
}
}
if (visible) {
if (mIsFirstVisible) {
mIsFirstVisible = false;
onLazyInitView(mSaveInstanceState);
dispatchFragmentLifecycle(LifecycleHelper.LIFECYLCE_ONLAZYINITVIEW, null, false);
}
onSupportVisible();
if (_mActivity != null) {
_mActivity.setFragmentClickable(true);
}
dispatchFragmentLifecycle(LifecycleHelper.LIFECYLCE_ONSUPPORTVISIBLE, null, true);
} else {
onSupportInvisible();
dispatchFragmentLifecycle(LifecycleHelper.LIFECYLCE_ONSUPPORTINVISIBLE, null, false);
}
}
use of android.support.v4.app.FragmentManager in project DesignLibrary by StylingAndroid.
the class ArticleViewPagerAdapter method destroyItem.
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
FragmentManager manager = ((Fragment) object).getFragmentManager();
FragmentTransaction trans = manager.beginTransaction();
trans.remove((Fragment) object);
trans.commit();
super.destroyItem(container, position, object);
}
Aggregations