Java Code Examples for android.support.v4.app.fragment#getFragmentManager()

The following examples show how to use android.support.v4.app.fragment#getFragmentManager() . 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: FragmentsAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
    Fragment fragment = (Fragment)object;
    if (fragment != mCurrentPrimaryItem) {
        if (mCurrentPrimaryItem != null) {
            mCurrentPrimaryItem.setMenuVisibility(false);
            mCurrentPrimaryItem.setUserVisibleHint(false);
        }
        if (fragment != null) {
            fragment.setMenuVisibility(true);
            if(fragment.getFragmentManager() == null) {
                Log.v(TAG, "fragment manager == null item #"+position+": f="+object);
            }
            fragment.setUserVisibleHint(true);
        }
        mCurrentPrimaryItem = fragment;
    }
}
 
Example 2
Source File: FragmentIdHelper.java    From android-task with Apache License 2.0 6 votes vote down vote up
@SuppressLint("RestrictedApi")
private static String getIndex(Fragment fragment) {
    String index;
    if (fragment.getParentFragment() != null) {
        index = getIndex(fragment.getParentFragment()) + "-";
    } else {
        index = "";
    }

    FragmentManager fragmentManager = fragment.getFragmentManager();
    if (fragmentManager != null) {
        List<Fragment> fragments = fragmentManager.getFragments();
        if (fragments != null && !fragments.isEmpty()) {
            for (int i = 0; i < fragments.size(); i++) {
                if (fragment.equals(fragments.get(i))) {
                    index += i;
                    break;
                }
            }
        }
    }

    return index;
}
 
Example 3
Source File: FragmentsAdapter.java    From 920-text-editor-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
    Fragment fragment = (Fragment)object;
    if (fragment != mCurrentPrimaryItem) {
        if (mCurrentPrimaryItem != null) {
            mCurrentPrimaryItem.setMenuVisibility(false);
            mCurrentPrimaryItem.setUserVisibleHint(false);
        }
        if (fragment != null) {
            fragment.setMenuVisibility(true);
            if(fragment.getFragmentManager() == null) {
                Log.v(TAG, "fragment manager == null item #"+position+": f="+object);
            }
            fragment.setUserVisibleHint(true);
        }
        mCurrentPrimaryItem = fragment;
    }
}
 
Example 4
Source File: FragmentUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * Replace fragment.
 *
 * @param srcFragment    The source of fragment.
 * @param destFragment   The destination of fragment.
 * @param destTag        The destination of fragment's tag.
 * @param isAddStack     True to add fragment in stack, false otherwise.
 * @param sharedElements A View in a disappearing Fragment to match with a View in an
 *                       appearing Fragment.
 */
public static void replace(@NonNull final Fragment srcFragment,
                           @NonNull final Fragment destFragment,
                           final String destTag,
                           final boolean isAddStack,
                           final View... sharedElements) {
    FragmentManager fm = srcFragment.getFragmentManager();
    if (fm == null) return;
    Args args = getArgs(srcFragment);
    replace(fm,
            destFragment,
            args.id,
            destTag,
            isAddStack,
            sharedElements
    );
}
 
Example 5
Source File: FragmentUtils.java    From MVVMArms with Apache License 2.0 6 votes vote down vote up
/**
 * 获取目标fragment的前一个fragment
 *
 * @param destFragment 目标fragment
 * @return 目标fragment的前一个fragment
 */
public static Fragment getPreFragment(@NonNull Fragment destFragment) {
    FragmentManager fragmentManager = destFragment.getFragmentManager();
    if (fragmentManager == null) {
        return null;
    }
    List<Fragment> fragments = getFragments(fragmentManager);
    boolean flag = false;
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (flag && fragment != null) {
            return fragment;
        }
        if (fragment == destFragment) {
            flag = true;
        }
    }
    return null;
}
 
Example 6
Source File: FragmentUtils.java    From Android-UtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * 获取目标fragment的前一个fragment
 *
 * @param destFragment 目标fragment
 * @return 目标fragment的前一个fragment
 */
public static Fragment getPreFragment(@NonNull Fragment destFragment) {
    FragmentManager fragmentManager = destFragment.getFragmentManager();
    if (fragmentManager == null) return null;
    List<Fragment> fragments = getFragments(fragmentManager);
    boolean flag = false;
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (flag && fragment != null) {
            return fragment;
        }
        if (fragment == destFragment) {
            flag = true;
        }
    }
    return null;
}
 
Example 7
Source File: FragmentUtils.java    From TikTok with Apache License 2.0 6 votes vote down vote up
/**
 * 获取目标fragment的前一个fragment
 *
 * @param destFragment 目标fragment
 * @return 目标fragment的前一个fragment
 */
public static Fragment getPreFragment(@NonNull Fragment destFragment) {
    FragmentManager fragmentManager = destFragment.getFragmentManager();
    if (fragmentManager == null)
        return null;
    List<Fragment> fragments = getFragments(fragmentManager);
    boolean flag = false;
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (flag && fragment != null) {
            return fragment;
        }
        if (fragment == destFragment) {
            flag = true;
        }
    }
    return null;
}
 
Example 8
Source File: FragmentUtils.java    From styT with Apache License 2.0 6 votes vote down vote up
/**
 * 获取目标fragment的前一个fragment
 *
 * @param destFragment 目标fragment
 * @return 目标fragment的前一个fragment
 */
public static Fragment getPreFragment(@NonNull final Fragment destFragment) {
    FragmentManager fragmentManager = destFragment.getFragmentManager();
    if (fragmentManager == null) return null;
    List<Fragment> fragments = getFragments(fragmentManager);
    boolean flag = false;
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (flag && fragment != null) {
            return fragment;
        }
        if (fragment == destFragment) {
            flag = true;
        }
    }
    return null;
}
 
Example 9
Source File: CC.java    From CC with Apache License 2.0 5 votes vote down vote up
void addCancelOnFragmentDestroyIfSet() {
    if (cancelOnDestroyFragment == null) {
        return;
    }
    Fragment fragment = cancelOnDestroyFragment.get();
    if (fragment == null) {
        return;
    }
    FragmentManager manager = fragment.getFragmentManager();
    if (manager != null) {
        manager.registerFragmentLifecycleCallbacks(
                new CCMonitor.FragmentMonitor(this)
                , false);
    }
}
 
Example 10
Source File: AutoClearedValue.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
public AutoClearedValue(Fragment fragment, T value) {
    FragmentManager fragmentManager = fragment.getFragmentManager();
    fragmentManager.registerFragmentLifecycleCallbacks(
            new FragmentManager.FragmentLifecycleCallbacks() {
                @Override
                public void onFragmentViewDestroyed(FragmentManager fm, Fragment f) {
                    AutoClearedValue.this.value = null;
                    fragmentManager.unregisterFragmentLifecycleCallbacks(this);
                }
            },false);
    this.value = value;
}
 
Example 11
Source File: BaseCommonActivity.java    From SimpleProject with MIT License 5 votes vote down vote up
/**
 * 恢复嵌套的Fragment
 */
public void restoreChildFragment(Fragment currentFragment) {
	FragmentManager fm = currentFragment.getFragmentManager();
	List<Fragment> fragmentList = fm != null ? fm.getFragments() : null;
	if (CollectionUtil.isEmpty(fragmentList)) {
		return;
	}

	for (Fragment fragment : fragmentList) {
		fragment.onAttach((Context)context);
	}
}
 
Example 12
Source File: FragmentUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Replace fragment.
 *
 * @param srcFragment  The source of fragment.
 * @param destFragment The destination of fragment.
 * @param destTag      The destination of fragment's tag.
 * @param isAddStack   True to add fragment in stack, false otherwise.
 */
public static void replace(@NonNull final Fragment srcFragment,
                           @NonNull final Fragment destFragment,
                           final String destTag,
                           final boolean isAddStack) {
    FragmentManager fm = srcFragment.getFragmentManager();
    if (fm == null) return;
    Args args = getArgs(srcFragment);
    replace(fm, destFragment, args.id, destTag, isAddStack);
}
 
Example 13
Source File: FragmentHandlerManager.java    From SimpleProject with MIT License 5 votes vote down vote up
/**
 * 恢复嵌套的Fragment
 */
public void resumeChildFragment(Fragment fragment) {
	FragmentManager fm = fragment.getFragmentManager();
	if (fm == null) {
		return;
	}

	for (int i = 0, size = fm.getFragments().size(); i < size; i++) {
		fm.getFragments().get(i).onAttach((Context) context);
	}
}
 
Example 14
Source File: ColorPreference.java    From hsv-alpha-color-picker-android with Apache License 2.0 5 votes vote down vote up
public ColorPreferenceFragment showDialog(@NonNull Fragment targetFragment, int requestCode) {
	ColorPreferenceFragment fragment = ColorPreferenceFragment.newInstance(getKey());
	fragment.setTargetFragment(targetFragment, requestCode);
	FragmentManager fragmentManager = targetFragment.getFragmentManager();
	if (fragmentManager != null) {
		fragment.show(fragmentManager, getKey());
		hideKeyboard(targetFragment);
	}
	return fragment;
}
 
Example 15
Source File: FragmentCompatSupportLib.java    From weex with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public FragmentManager getFragmentManager(Fragment fragment) {
  return fragment.getFragmentManager();
}
 
Example 16
Source File: FragmentCompatSupportLib.java    From stetho with MIT License 4 votes vote down vote up
@Nullable
@Override
public FragmentManager getFragmentManager(Fragment fragment) {
  return fragment.getFragmentManager();
}
 
Example 17
Source File: FragmentUtils.java    From AndroidUtilCode with Apache License 2.0 3 votes vote down vote up
/**
 * Replace fragment.
 *
 * @param srcFragment  The source of fragment.
 * @param destFragment The destination of fragment.
 * @param destTag      The destination of fragment's tag.
 * @param isAddStack   True to add fragment in stack, false otherwise.
 * @param enterAnim    An animation or animator resource ID used for the enter animation on the
 *                     view of the fragment being added or attached.
 * @param exitAnim     An animation or animator resource ID used for the exit animation on the
 *                     view of the fragment being removed or detached.
 * @param popEnterAnim An animation or animator resource ID used for the enter animation on the
 *                     view of the fragment being readded or reattached caused by
 *                     popBackStack() or similar methods.
 * @param popExitAnim  An animation or animator resource ID used for the enter animation on the
 *                     view of the fragment being removed or detached caused by
 *                     popBackStack() or similar methods.
 */
public static void replace(@NonNull final Fragment srcFragment,
                           @NonNull final Fragment destFragment,
                           final String destTag,
                           final boolean isAddStack,
                           @AnimatorRes @AnimRes final int enterAnim,
                           @AnimatorRes @AnimRes final int exitAnim,
                           @AnimatorRes @AnimRes final int popEnterAnim,
                           @AnimatorRes @AnimRes final int popExitAnim) {
    FragmentManager fm = srcFragment.getFragmentManager();
    if (fm == null) return;
    Args args = getArgs(srcFragment);
    replace(fm, destFragment, args.id, destTag, isAddStack,
            enterAnim, exitAnim, popEnterAnim, popExitAnim);
}