本文整理汇总了Java中android.support.v4.app.Fragment.getArguments方法的典型用法代码示例。如果您正苦于以下问题:Java Fragment.getArguments方法的具体用法?Java Fragment.getArguments怎么用?Java Fragment.getArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.Fragment
的用法示例。
在下文中一共展示了Fragment.getArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultScreenGettingFunction
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
public static <ScreenT extends Screen> Function<Fragment, ScreenT> getDefaultScreenGettingFunction(final Class<ScreenT> screenClass) {
return new Function<Fragment, ScreenT>() {
@Override
@SuppressWarnings("unchecked")
public ScreenT call(Fragment fragment) {
if (fragment.getArguments() == null) {
throw new IllegalArgumentException("Fragment has no arguments.");
} else if (Serializable.class.isAssignableFrom(screenClass)) {
return (ScreenT) fragment.getArguments().getSerializable(KEY_SCREEN);
} else if (Parcelable.class.isAssignableFrom(screenClass)) {
return (ScreenT) fragment.getArguments().getParcelable(KEY_SCREEN);
} else {
throw new IllegalArgumentException("Screen " + screenClass.getSimpleName() + " should be Serializable or Parcelable.");
}
}
};
}
示例2: replaceFragment
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* 替换fragment
*
* @param srcFragment 源fragment
* @param destFragment 目标fragment
* @param isAddStack 是否入回退栈
* @param sharedElement 共享元素
* @return 目标fragment
*/
public static Fragment replaceFragment(@NonNull final Fragment srcFragment,
@NonNull final Fragment destFragment,
final boolean isAddStack,
final SharedElement... sharedElement) {
if (srcFragment.getArguments() == null) return null;
int containerId = srcFragment.getArguments().getInt(ARGS_ID);
if (containerId == 0) return null;
return replaceFragment(srcFragment.getFragmentManager(), destFragment, containerId, isAddStack, sharedElement);
}
示例3: replaceFragment
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* 替换fragment
*
* @param srcFragment 源fragment
* @param destFragment 目标fragment
* @param isAddStack 是否入回退栈
* @return 目标fragment
*/
public static Fragment replaceFragment(@NonNull Fragment srcFragment,
@NonNull Fragment destFragment,
boolean isAddStack) {
if (srcFragment.getArguments() == null) return null;
int containerId = srcFragment.getArguments().getInt(ARGS_ID);
if (containerId == 0) return null;
return replaceFragment(srcFragment.getFragmentManager(), destFragment, containerId, isAddStack);
}
示例4: onFragmentStopped
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void onFragmentStopped(FragmentManager fm, Fragment f) {
Bundle savedState = savedStates.remove(f);
if (savedState != null) {
String message = f.getClass().getSimpleName() + ".onSaveInstanceState wrote: " + TooLargeTool.bundleBreakdown(savedState);
if (f.getArguments() != null) {
message += "\n* fragment arguments = " + TooLargeTool.bundleBreakdown(f.getArguments());
}
log(message);
}
}
示例5: fetchFragmentDelegate
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private FragmentDelegate fetchFragmentDelegate(Fragment fragment) {
if (fragment instanceof IFragment && fragment.getArguments() != null) {
fragment.getArguments().setClassLoader(getClass().getClassLoader());
return fragment.getArguments().getParcelable(FragmentDelegate.FRAGMENT_DELEGATE);
}
return null;
}
示例6: getArgs
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* 获取参数
*
* @param fragment fragment
*/
private static Args getArgs(@NonNull Fragment fragment) {
Bundle bundle = fragment.getArguments();
if (bundle == null || bundle.getInt(ARGS_ID) == 0) {
return null;
}
return new Args(bundle.getInt(ARGS_ID), bundle.getBoolean(ARGS_IS_HIDE), bundle.getBoolean(ARGS_IS_ADD_STACK));
}
示例7: getArgs
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* 获取参数
*
* @param fragment fragment
*/
private static Args getArgs(@NonNull Fragment fragment) {
Bundle bundle = fragment.getArguments();
if (bundle == null || bundle.getInt(ARGS_ID) == 0)
return null;
return new Args(bundle.getInt(ARGS_ID), bundle.getBoolean(ARGS_IS_HIDE), bundle.getBoolean(ARGS_IS_ADD_STACK));
}
示例8: handleResultRecord
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
void handleResultRecord(Fragment from) {
SupportFragment preFragment = getPreFragment(from);
if (preFragment == null) return;
Bundle args = from.getArguments();
if (args == null || !args.containsKey(FRAGMENTATION_ARG_RESULT_RECORD)) return;
ResultRecord resultRecord = args.getParcelable(FRAGMENTATION_ARG_RESULT_RECORD);
if (resultRecord == null) return;
preFragment.onFragmentResult(resultRecord.requestCode, resultRecord.resultCode, resultRecord.resultBundle);
}
示例9: getArgs
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* Get the parameters
*
* @param fragment fragment
*/
private static Args getArgs(@NonNull Fragment fragment) {
Bundle bundle = fragment.getArguments();
if (bundle == null || bundle.getInt(ARGS_ID) == 0)
return null;
return new Args(bundle.getInt(ARGS_ID), bundle.getBoolean(ARGS_IS_HIDE), bundle.getBoolean(ARGS_IS_ADD_STACK));
}
示例10: onFragmentAttached
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void onFragmentAttached(FragmentManager fm, Fragment f, Context context) {
super.onFragmentAttached(fm, f, context);
if (f instanceof IFragment && f.getArguments() != null) {
FragmentDelegate delegate = getFragmentDelegate(f);
if (delegate == null) {
delegate = new FragmentDelegate(f);
f.getArguments().putSerializable(FragmentDelegate.FRAGMENT_LIFECYCLE, delegate);
}
delegate.onAttach(context);
}
}
示例11: replaceFragment
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* 替换fragment
*
* @param srcFragment 源fragment
* @param destFragment 目标fragment
* @param isAddStack 是否入回退栈
* @param sharedElement 共享元素
* @return 目标fragment
*/
public static Fragment replaceFragment(@NonNull Fragment srcFragment,
@NonNull Fragment destFragment,
boolean isAddStack,
SharedElement... sharedElement) {
if (srcFragment.getArguments() == null) return null;
int containerId = srcFragment.getArguments().getInt(ARGS_ID);
if (containerId == 0) return null;
return replaceFragment(srcFragment.getFragmentManager(), destFragment, containerId, isAddStack, sharedElement);
}
示例12: getArgs
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* 获取参数
*
* @param fragment fragment
*/
private static Args getArgs(@NonNull final Fragment fragment) {
Bundle bundle = fragment.getArguments();
if (bundle == null || bundle.getInt(ARGS_ID) == 0) return null;
return new Args(bundle.getInt(ARGS_ID), bundle.getBoolean(ARGS_IS_HIDE), bundle.getBoolean(ARGS_IS_ADD_STACK));
}
示例13: operateFragment
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* 操作fragment
*
* @param fragmentManager fragment管理器
* @param srcFragment 源fragment
* @param destFragment 目标fragment
* @param type 操作类型
* @param sharedElements 共享元素
* @return destFragment
*/
private static Fragment operateFragment(@NonNull final FragmentManager fragmentManager,
final Fragment srcFragment,
@NonNull Fragment destFragment,
final int type,
final SharedElement... sharedElements) {
if (srcFragment == destFragment) return null;
if (srcFragment != null && srcFragment.isRemoving()) {
Log.e("FragmentUtils", srcFragment.getClass().getName() + " is isRemoving");
return null;
}
String name = destFragment.getClass().getName();
Bundle args = destFragment.getArguments();
FragmentTransaction ft = fragmentManager.beginTransaction();
if (sharedElements == null || sharedElements.length == 0) {
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
} else {
for (SharedElement element : sharedElements) {// 添加共享元素动画
ft.addSharedElement(element.sharedElement, element.name);
}
}
switch (type) {
case TYPE_ADD_HIDE_FRAGMENT:
ft.hide(srcFragment);
case TYPE_ADD_FRAGMENT:
Fragment fragmentByTag = fragmentManager.findFragmentByTag(name);
if (fragmentByTag != null) {
if (fragmentByTag.isAdded()) {
ft.remove(fragmentByTag);
}
}
ft.add(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_HIDE)) ft.hide(destFragment);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
break;
case TYPE_REMOVE_FRAGMENT:
ft.remove(destFragment);
break;
case TYPE_REMOVE_TO_FRAGMENT:
List<Fragment> fragments = getFragments(fragmentManager);
for (int i = fragments.size() - 1; i >= 0; --i) {
Fragment fragment = fragments.get(i);
if (fragment == destFragment) {
if (srcFragment != null) ft.remove(fragment);
break;
}
ft.remove(fragment);
}
break;
case TYPE_REPLACE_FRAGMENT:
ft.replace(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
break;
case TYPE_ADD_POP_FRAGMENT:
popFragment(fragmentManager);
ft.add(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
break;
case TYPE_HIDE_FRAGMENT:
ft.hide(destFragment);
break;
case TYPE_SHOW_FRAGMENT:
ft.show(destFragment);
break;
case TYPE_SHOW_HIDE_FRAGMENT:
ft.hide(srcFragment).show(destFragment);
break;
}
ft.commitAllowingStateLoss();
return destFragment;
}
示例14: getArgs
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* 获取参数
*
* @param fragment fragment
*/
private static Args getArgs(@NonNull Fragment fragment) {
Bundle bundle = fragment.getArguments();
if (bundle == null || bundle.getInt(ARGS_ID) == 0) return null;
return new Args(bundle.getInt(ARGS_ID), bundle.getBoolean(ARGS_IS_HIDE), bundle.getBoolean(ARGS_IS_ADD_STACK));
}
示例15: fetchFragmentDelegate
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private FragmentDelegate fetchFragmentDelegate(Fragment fragment) {
if (fragment instanceof IFragment) {
return fragment.getArguments() == null ? null : fragment.getArguments().getParcelable(FragmentDelegate.FRAGMENT_DELEGATE);
}
return null;
}