Java Code Examples for androidx.fragment.app.Fragment#getArguments()

The following examples show how to use androidx.fragment.app.Fragment#getArguments() . 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: FastLifecycleCallbacks.java    From FastLib with Apache License 2.0 6 votes vote down vote up
@Override
public void onFragmentViewCreated(FragmentManager fm, Fragment f, View v, Bundle savedInstanceState) {
    super.onFragmentViewCreated(fm, f, v, savedInstanceState);
    boolean isSet = f.getArguments() != null ? f.getArguments().getBoolean(FastConstant.IS_SET_CONTENT_VIEW_BACKGROUND, false) : false;
    if (!isSet) {
        setContentViewBackground(v, f.getClass());
    }
    //设置TitleBarView-先设置TitleBarView避免多状态将布局替换
    if (f instanceof IFastTitleView
            && !(f instanceof IFastRefreshLoadView)
            && v != null) {
        FastDelegateManager.getInstance().putFastTitleDelegate(f.getClass(),
                new FastTitleDelegate(v, (IFastTitleView) f, f.getClass()));
    }
    //刷新功能处理
    if (f instanceof IFastRefreshView
            && !(FastRefreshLoadFragment.class.isAssignableFrom(f.getClass()))) {
        IFastRefreshView refreshView = (IFastRefreshView) f;
        FastDelegateManager.getInstance().putFastRefreshDelegate(f.getClass(),
                new FastRefreshDelegate(
                        refreshView.getContentView() != null ? refreshView.getContentView() : f.getView(),
                        refreshView));
    }
}
 
Example 2
Source File: CourseDiscussionPostsActivity.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
@Override
public Fragment getFirstFragment() {
    final Fragment fragment;
    if (searchQuery != null) {
        fragment = courseDiscussionPostsSearchFragment;
    } else {
        fragment = courseDiscussionPostsThreadFragment;
    }

    // TODO: Move argument setting logic to base class
    // Currently RoboGuice doesn't allowing injecting arguments of a Fragment
    if (fragment.getArguments() == null) {
        final Bundle args = new Bundle();
        args.putAll(getIntent().getExtras());
        args.putSerializable(Router.EXTRA_COURSE_DATA, courseData);
        args.putBoolean(CourseDiscussionPostsThreadFragment.ARG_DISCUSSION_HAS_TOPIC_NAME,
                discussionTopic != null);
        fragment.setArguments(args);
    }
    fragment.setRetainInstance(true);

    return fragment;
}
 
Example 3
Source File: BookListPresenterImpl.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void initData(Fragment fragment) {
    Bundle args = fragment.getArguments();
    if (args != null) {
        group = args.getInt("group");
    }

    impl.setOnBookRefreshListener(this);
}
 
Example 4
Source File: ScreenClassHelper.java    From Alligator with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nullable
public Class<? extends Screen> getScreenClass(@NonNull Fragment fragment) {
	if (fragment.getArguments() == null) {
		return null;
	}

	String className = fragment.getArguments().getString(KEY_SCREEN_CLASS_NAME);
	return (Class<? extends Screen>) getClassByName(className);
}
 
Example 5
Source File: DefaultFragmentConverter.java    From Alligator with MIT License 5 votes vote down vote up
@Override
@NonNull
@SuppressWarnings("unchecked")
public ScreenT getScreen(@NonNull Fragment fragment) {
	if (fragment.getArguments() == null) {
		throw new IllegalArgumentException("Fragment has no arguments.");
	} else if (Serializable.class.isAssignableFrom(mScreenClass)) {
		return checkNotNull((ScreenT) (fragment.getArguments().getSerializable(KEY_SCREEN)));
	} else if (Parcelable.class.isAssignableFrom(mScreenClass)) {
		return checkNotNull((ScreenT) fragment.getArguments().getParcelable(KEY_SCREEN));
	} else {
		throw new IllegalArgumentException("Screen " + mScreenClass.getSimpleName() + " should be Serializable or Parcelable.");
	}
}
 
Example 6
Source File: FastLifecycleCallbacks.java    From FastLib with Apache License 2.0 5 votes vote down vote up
@Override
public void onFragmentViewDestroyed(@NonNull FragmentManager fm, @NonNull Fragment f) {
    super.onFragmentViewDestroyed(fm, f);
    if (f.getArguments() != null) {
        f.getArguments().putBoolean(FastConstant.IS_SET_CONTENT_VIEW_BACKGROUND, false);
    }
    FastDelegateManager.getInstance().removeFastRefreshDelegate(f.getClass());
    FastDelegateManager.getInstance().removeFastTitleDelegate(f.getClass());
}
 
Example 7
Source File: RouterInject.java    From grouter-android with Apache License 2.0 5 votes vote down vote up
public static void inject(Fragment fragment) {
    if (fragment == null) {
        return;
    }
    Bundle arguments = fragment.getArguments();
    if (arguments == null || arguments.size() == 0) {
        return;
    }
    try {
        inject(fragment, arguments, null);
    } catch (Exception e) {
        LoggerUtils.handleException(e);
    }
}
 
Example 8
Source File: StoreTabGridRecyclerFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public static Fragment newInstance(Event event, HomeEvent.Type type, String title,
    String storeTheme, String tag, StoreContext storeContext, boolean shouldShowToolbar) {
  Bundle args = buildBundle(event, type, title, storeTheme, tag, storeContext, shouldShowToolbar);
  Fragment fragment = StoreTabFragmentChooser.choose(event, type);
  Bundle arguments = fragment.getArguments();
  if (arguments != null) {
    args.putAll(arguments);
  }
  fragment.setArguments(args);
  return fragment;
}
 
Example 9
Source File: MessageActivity.java    From tindroid with Apache License 2.0 4 votes vote down vote up
void showFragment(String tag, Bundle args, boolean addToBackstack) {
    if (isFinishing() || isDestroyed()) {
        return;
    }

    FragmentManager fm = getSupportFragmentManager();

    Fragment fragment = fm.findFragmentByTag(tag);
    if (fragment == null) {
        switch (tag) {
            case FRAGMENT_MESSAGES:
                fragment = new MessagesFragment();
                break;
            case FRAGMENT_INFO:
                fragment = new TopicInfoFragment();
                break;
            case FRAGMENT_PERMISSIONS:
                fragment = new TopicPermissionsFragment();
                break;
            case FRAGMENT_EDIT_MEMBERS:
                fragment = new EditMembersFragment();
                break;
            case FRAGMENT_VIEW_IMAGE:
                fragment = new ImageViewFragment();
                break;
            case FRAGMENT_FILE_PREVIEW:
                fragment = new FilePreviewFragment();
                break;
            case FRAGMENT_INVALID:
                fragment = new InvalidTopicFragment();
                break;
        }
    } else if (args == null) {
        // Retain old arguments.
        args = fragment.getArguments();
    }
    if (fragment == null) {
        throw new NullPointerException();
    }

    args = args != null ? args : new Bundle();
    args.putString("topic", mTopicName);
    args.putString(MessagesFragment.MESSAGE_TO_SEND, mMessageText);
    if (fragment.getArguments() != null) {
        fragment.getArguments().putAll(args);
    } else {
        fragment.setArguments(args);
    }

    FragmentTransaction trx = fm.beginTransaction();
    if (!fragment.isAdded()) {
        trx = trx.replace(R.id.contentFragment, fragment, tag)
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    } else if (!fragment.isVisible()) {
        trx = trx.show(fragment);
    } else {
        addToBackstack = false;
    }

    if (FRAGMENT_MESSAGES.equals(tag)) {
        trx.setPrimaryNavigationFragment(fragment);
    }

    if (addToBackstack) {
        trx.addToBackStack(tag);
    }
    if (!trx.isEmpty()) {
        trx.commit();
    }
}
 
Example 10
Source File: FeatureDemoUtils.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
public static void startFragmentInternal(
    FragmentActivity activity,
    Fragment fragment,
    String tag,
    @Nullable View sharedElement,
    @Nullable String sharedElementName,
    @Nullable ContainerTransformConfiguration containerTransformConfiguration) {
  FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();

  if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP
      && sharedElement != null
      && sharedElementName != null) {
    Fragment currentFragment = getCurrentFragment(activity);
    Hold hold = new Hold();
    // Add root view as target for the Hold so that the entire view hierarchy is held in place as
    // one instead of each child view individually. Helps keep shadows during the transition.
    hold.addTarget(currentFragment.getView());
    currentFragment.setExitTransition(hold);

    MaterialContainerTransform transform = new MaterialContainerTransform();
    if (containerTransformConfiguration != null
        && containerTransformConfiguration.isArcMotionEnabled()) {
      transform.setPathMotion(new MaterialArcMotion());
    }
    transform.setContainerColor(MaterialColors.getColor(sharedElement, R.attr.colorSurface));
    transform.setFadeMode(MaterialContainerTransform.FADE_MODE_THROUGH);
    fragment.setSharedElementEnterTransition(transform);
    transaction.addSharedElement(sharedElement, sharedElementName);

    if (fragment.getArguments() == null) {
      Bundle args = new Bundle();
      args.putString(ARG_TRANSITION_NAME, sharedElementName);
      fragment.setArguments(args);
    } else {
      fragment.getArguments().putString(ARG_TRANSITION_NAME, sharedElementName);
    }
  } else {
    transaction.setCustomAnimations(
        R.anim.abc_grow_fade_in_from_bottom,
        R.anim.abc_fade_out,
        R.anim.abc_fade_in,
        R.anim.abc_shrink_fade_out_from_bottom);
  }

  transaction
      .replace(MAIN_ACTIVITY_FRAGMENT_CONTAINER_ID, fragment, tag)
      .addToBackStack(null /* name */)
      .commit();
}