@Override public void setArguments(Bundle args) { super.setArguments(args); setSettingsFromBundle(args); }
/** * Set the argument of Fragment. * * @param fragment a fragment * @return a fragment */ public <T extends Fragment> T into(T fragment) { fragment.setArguments(get()); return fragment; }
private FragmentController(F fragment, Class<? extends Activity> activityClass, Intent intent, Bundle arguments) { super(fragment, intent); this.fragment = fragment; if (arguments != null) { this.fragment.setArguments(arguments); } this.activityController = ActivityController.of(ReflectionHelpers.callConstructor(activityClass), intent); }
/** * You should call this method after init your argumentsBundle.otherwise the transitionBundle will be not work. */ public void prepare(Fragment toFragment) { final Bundle transitionBundle = TransitionBundleFactory.createTransitionBundle(context, fromView, bitmap); Bundle arguments = toFragment.getArguments(); if (arguments == null) { arguments = new Bundle(); } arguments.putBundle(TRANSITION_BUNDLE, transitionBundle); toFragment.setArguments(arguments); } /**
@Override public void setArguments(Bundle args) { super.setArguments(args); }
public static Fragment newInstance(News news) { Bundle bundle = new Bundle(); bundle.putParcelable(NewsDetailActivity.KEY_NEWS, news); Fragment fragment = new NewsDetailFragment(); fragment.setArguments(bundle); return fragment; }
/** * Creates a new instance of the given <var>classOfFragment</var> with the given <var>args</var>. * * @param classOfFragment Class of the desired fragment to instantiate. * @param args Arguments to set to new instance of fragment by {@link Fragment#setArguments(android.os.Bundle)}. * @param <F> Type of the desired fragment. * @return New instance of fragment with the given arguments or {@code null} if some instantiation * error occurs. */ @Nullable public static <F extends Fragment> F newInstanceWithArguments(@NonNull Class<F> classOfFragment, @Nullable Bundle args) { try { final F fragment = classOfFragment.newInstance(); fragment.setArguments(args); return fragment; } catch (Exception e) { e.printStackTrace(); } return null; }
private Fragment buildTvFragment(ServerFile serverFile, ServerShare serverShare) { Fragment fragment = new ServerFileTvFragment(); Bundle bundle = new Bundle(); bundle.putParcelable(Intents.Extras.SERVER_FILE, serverFile); bundle.putParcelable(Intents.Extras.SERVER_SHARE, serverShare); fragment.setArguments(bundle); return fragment; }
public static Fragment newInstance(int position) { Fragment fragment = new PlanetFragment(); Bundle args = new Bundle(); args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(args); return fragment; }
public static android.app.Fragment buildFirstTvFragment(ServerFile serverFile, ServerShare serverShare) { android.app.Fragment fragment = new ServerFileTvFragment(); Bundle bundle = new Bundle(); bundle.putParcelable(Intents.Extras.SERVER_FILE, serverFile); bundle.putParcelable(Intents.Extras.SERVER_SHARE, serverShare); fragment.setArguments(bundle); return fragment; }
/** * Creates a new instance of Fragment type of specified for this item. * * @param arguments Arguments to be attached to the new Fragment instance via {@link Fragment#setArguments(Bundle)}. * @return New fragment instance or {@code null} if type of this item is {@link Fragment Fragment.class} * which is default and can not be instantiated or some instantiation error occurred. */ @Nullable public Fragment newFragmentInstance(@Nullable Bundle arguments) { if (type.equals(Fragment.class)) { return null; } try { final Fragment fragment = type.newInstance(); if (arguments != null) { fragment.setArguments(arguments); } return fragment; } catch (Exception e) { final String fragmentName = type.getSimpleName(); Log.e(TAG, "Failed to instantiate a new fragment instance class of(" + fragmentName + "). " + "Make sure that this fragment is accessible and has public empty constructor.", e); } return null; }
public static android.app.Fragment buildVideoFragment(ServerFile serverFile, ServerShare serverShare, ArrayList<ServerFile> serverFiles) { android.app.Fragment fragment = new TvPlaybackVideoFragment(); Bundle bundle = new Bundle(); bundle.putParcelable(Intents.Extras.SERVER_SHARE, serverShare); bundle.putParcelable(Intents.Extras.SERVER_FILE, serverFile); bundle.putParcelableArrayList(Intents.Extras.SERVER_FILES, serverFiles); fragment.setArguments(bundle); return fragment; }
public static android.app.Fragment buildAudioFragment(ServerFile serverFile, ServerShare serverShare, ArrayList<ServerFile> serverFiles) { android.app.Fragment fragment = new TvPlaybackAudioFragment(); Bundle bundle = new Bundle(); bundle.putParcelable(Intents.Extras.SERVER_SHARE, serverShare); bundle.putParcelable(Intents.Extras.SERVER_FILE, serverFile); bundle.putParcelableArrayList(Intents.Extras.SERVER_FILES, serverFiles); fragment.setArguments(bundle); return fragment; }
public final Fragment createFragment() { Fragment frag = getFragment(); frag.setArguments(getIntent().getExtras()); return frag; }
private FragmentController(F fragment, Class<? extends Activity> activityClass, Intent intent, Bundle arguments) { super(fragment, intent); this.fragment = fragment; if (arguments != null) { this.fragment.setArguments(arguments); } this.activityController = ActivityController.of(ReflectionHelpers.callConstructor(activityClass), intent); }
@Override public void replaceFragment(Class<? extends Fragment> claz, boolean addToBackStack, Bundle args) { FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment newFragment; try { // Create new fragment newFragment = claz.newInstance(); if (args != null) newFragment.setArguments(args); } catch (InstantiationException e) { e.printStackTrace(); return; } catch (IllegalAccessException e) { e.printStackTrace(); return; } if (addToBackStack) { // Add this transaction to the back stack ft.addToBackStack(null); } // Change to a new fragment ft.replace(R.id.frame_contents, newFragment, claz.getClass().getSimpleName()); ft.commit(); } // End of fragments management
private void commitFragment(String fragmentStr) { try { Object fragment = Class.forName(fragmentStr).newInstance(); if (fragment instanceof BaseFragment) { mBaseFragment = (BaseFragment) fragment; Bundle bundle = getIntent().getExtras(); mBaseFragment.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(android.R.id.content, mBaseFragment).commit(); } else { Bundle bundle = getIntent().getExtras(); ((Fragment) fragment).setArguments(bundle); getFragmentManager().beginTransaction().replace(android.R.id.content, (Fragment) fragment).commit(); } } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { e.printStackTrace(); } }
public void replaceFragment(int containerId, @NonNull android.app.Fragment fragment, Bundle args) { if(args != null) { fragment.setArguments(args);} android.app.FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction().replace(containerId, fragment, null); ft.commit(); getActivity().getFragmentManager().executePendingTransactions(); }
private void selectItem(int position) { // check that the activity is using the layout version with the fragment_container FrameLayout (the one-pane layout) if (this.findViewById(R.id.fragment_container) != null) { // create a new Fragment to be placed in the activity layout Fragment firstFragment = null; switch (position) { case 1: firstFragment = new BatteryCapacityGraphFragment(); break; case 2: firstFragment = new TemperatureGraphFragment(); break; case 0: default: firstFragment = new OverviewFragment(); break; } // in case this activity was started with special instructions from an Intent, pass the Intent's extras to the fragment as arguments firstFragment.setArguments(this.getIntent().getExtras()); // add the fragment to the 'fragment_container' FrameLayout this.getFragmentManager().beginTransaction().replace(R.id.fragment_container, firstFragment).commit(); // store the last selected fragment lastSelectedFragment = position; } } }
@Override public void onCreate(Bundle savedInstanceState) { setTheme(MiscUtils.getThemeId(this)); super.onCreate(savedInstanceState); setContentView(R.layout.settings_activity); MiscUtils.setLanguage(this); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } snackbarMessageReceiver = new SnackbarMessageReceiver(this); String settingType = "default"; if (getIntent().hasExtra("setting_type")) { settingType = getIntent().getStringExtra("setting_type"); } Fragment fragment; if (savedInstanceState == null) { Timber.d("Saved instance is null, creating settings fragment"); fragment = getSettingsFragment(settingType); fragment.setArguments(getIntent().getExtras()); } else { Timber.d("Saved instance is not null, trying to find settings fragment"); fragment = getFragmentManager().findFragmentById(R.id.main); } Timber.d("Replacing fragment"); getFragmentManager().beginTransaction().replace(R.id.main, fragment).commit(); }