Java Code Examples for android.app.Fragment#instantiate()
The following examples show how to use
android.app.Fragment#instantiate() .
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: PreferenceActivity.java From ticdesign with Apache License 2.0 | 6 votes |
/** * Start a new fragment containing a preference panel. If the preferences * are being displayed in multi-pane mode, the given fragment class will * be instantiated and placed in the appropriate pane. If running in * single-pane mode, a new activity will be launched in which to show the * fragment. * * @param fragmentClass Full name of the class implementing the fragment. * @param args Any desired arguments to supply to the fragment. * @param titleRes Optional resource identifier of the title of this * fragment. * @param titleText Optional text of the title of this fragment. * @param resultTo Optional fragment that result data should be sent to. * If non-null, resultTo.onActivityResult() will be called when this * preference panel is done. The launched panel must use * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. * @param resultRequestCode If resultTo is non-null, this is the caller's * request code to be received with the result. */ public void startPreferencePanel(String fragmentClass, Bundle args, @StringRes int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) { if (mSinglePane) { startWithFragment(fragmentClass, args, resultTo, resultRequestCode, titleRes, 0); } else { Fragment f = Fragment.instantiate(this, fragmentClass, args); if (resultTo != null) { f.setTargetFragment(resultTo, resultRequestCode); } FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.prefs, f); if (titleRes != 0) { transaction.setBreadCrumbTitle(titleRes); } else if (titleText != null) { transaction.setBreadCrumbTitle(titleText); } transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.addToBackStack(BACK_STACK_PREFS); transaction.commitAllowingStateLoss(); } }
Example 2
Source File: MainActivity.java From trekarta with GNU General Public License v3.0 | 6 votes |
@Override public void showMarkerInformation(@NonNull GeoPoint point, @Nullable String name) { if (mFragmentManager.getBackStackEntryCount() > 0) { popAll(); } Bundle args = new Bundle(3); args.putDouble(MarkerInformation.ARG_LATITUDE, point.getLatitude()); args.putDouble(MarkerInformation.ARG_LONGITUDE, point.getLongitude()); args.putString(MarkerInformation.ARG_NAME, name); Fragment fragment = Fragment.instantiate(this, MarkerInformation.class.getName(), args); fragment.setEnterTransition(new Slide()); FragmentTransaction ft = mFragmentManager.beginTransaction(); ft.replace(R.id.contentPanel, fragment, "markerInformation"); ft.addToBackStack("markerInformation"); ft.commit(); updateMapViewArea(); }
Example 3
Source File: EnvelopesActivity.java From budget-envelopes with GNU General Public License v3.0 | 5 votes |
public void switchFragment(Class<?> cls, String name, Bundle args) { Fragment frag = Fragment.instantiate( this, cls.getName(), args ); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.content_frame, frag) .addToBackStack(name) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .commit(); fragmentManager.executePendingTransactions(); configureFragment(frag); }
Example 4
Source File: FragmentConcludingBuilder.java From Akatsuki with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public T build(Context context) { Class<? super T> targetClass = targetClass(); if (Fragment.class.isAssignableFrom(targetClass)) return (T) Fragment.instantiate(context, targetClass.getName(), bundle); else if (android.support.v4.app.Fragment.class.isAssignableFrom(targetClass)) { return (T) android.support.v4.app.Fragment.instantiate(context, targetClass.getName(), bundle); } else { throw new AssertionError("Target class of " + targetClass + " is neither android.app.Fragment or android.support.v4.app.Fragment, " + "this error should have been caught by the processor and should not happen"); } }
Example 5
Source File: EnvelopesFragment.java From budget-envelopes with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate(Bundle state) { super.onCreate(state); Fragment frag = Fragment.instantiate( getActivity(), GraphFragment.class.getName() ); getChildFragmentManager().beginTransaction() .replace(R.id.graph, frag) .commit(); }
Example 6
Source File: SettingActivity.java From Toutiao with Apache License 2.0 | 5 votes |
private void setupFragment(String fragmentName, Bundle args) { Fragment fragment = Fragment.instantiate(this, fragmentName, args); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.replace(R.id.container, fragment); transaction.commitAllowingStateLoss(); }
Example 7
Source File: MainActivity.java From Paperwork-Android with MIT License | 5 votes |
@Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); Fragment fragment; FragmentManager fm = getFragmentManager(); switch (menuItem.getItemId()) { case R.id.nav_all_notes: setTitle(getString(R.string.all_notes)); fragment = Fragment.instantiate(MainActivity.this, NotesFragment.class.getName()); (fm.beginTransaction().replace(R.id.main_container, fragment)).commit(); mCurrentSelectedPosition = 0; break; case R.id.nav_notebooks: setTitle(getString(R.string.notebooks)); fragment = Fragment.instantiate(MainActivity.this, NotebooksFragment.class.getName()); (fm.beginTransaction().replace(R.id.main_container, fragment)).commit(); mCurrentSelectedPosition = 1; break; default: return true; } mDrawerLayout.closeDrawer(GravityCompat.START); return true; }
Example 8
Source File: SettingAboutActivity.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
protected void onCreate(Bundle bundle) { super.onCreate(bundle); FragmentTransaction fragmenttransaction = getFragmentManager().beginTransaction(); b = (SettingAboutFragment)Fragment.instantiate(this, cn/com/smartdevices/bracelet/ui/SettingAboutActivity$SettingAboutFragment.getName()); fragmenttransaction.add(0x1020002, b); fragmenttransaction.commit(); a(); }
Example 9
Source File: MainActivity.java From trekarta with GNU General Public License v3.0 | 5 votes |
@SuppressLint("ClickableViewAccessibility") @Override public void onWaypointDetails(Waypoint waypoint, boolean fromList) { Bundle args = new Bundle(3); args.putBoolean(WaypointInformation.ARG_DETAILS, fromList); if (fromList || mLocationState != LocationState.DISABLED) { if (mLocationState != LocationState.DISABLED && mLocationService != null) { Location location = mLocationService.getLocation(); args.putDouble(WaypointInformation.ARG_LATITUDE, location.getLatitude()); args.putDouble(WaypointInformation.ARG_LONGITUDE, location.getLongitude()); } else { MapPosition position = mMap.getMapPosition(); args.putDouble(WaypointInformation.ARG_LATITUDE, position.getLatitude()); args.putDouble(WaypointInformation.ARG_LONGITUDE, position.getLongitude()); } } Fragment fragment = mFragmentManager.findFragmentByTag("amenityInformation"); if (fragment != null) { mFragmentManager.popBackStack("amenityInformation", FragmentManager.POP_BACK_STACK_INCLUSIVE); } fragment = mFragmentManager.findFragmentByTag("waypointInformation"); if (fragment == null) { fragment = Fragment.instantiate(this, WaypointInformation.class.getName(), args); Slide slide = new Slide(Gravity.BOTTOM); slide.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime)); fragment.setEnterTransition(slide); FragmentTransaction ft = mFragmentManager.beginTransaction(); ft.replace(R.id.bottomSheetPanel, fragment, "waypointInformation"); ft.addToBackStack("waypointInformation"); ft.commit(); } ((WaypointInformation) fragment).setWaypoint(waypoint); mViews.extendPanel.setForeground(getDrawable(R.drawable.dim)); mViews.extendPanel.getForeground().setAlpha(0); ObjectAnimator anim = ObjectAnimator.ofInt(mViews.extendPanel.getForeground(), "alpha", 0, 255); anim.setDuration(500); anim.start(); }
Example 10
Source File: TestFragmentActivity.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
@Override protected void onCreate(final Bundle savedState) { super.onCreate(savedState); final Intent intent = getIntent(); final String fragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); if (fragmentName == null) { throw new IllegalArgumentException("No fragment name specified for testing"); } mFragment = Fragment.instantiate(this, fragmentName); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().add(mFragment, fragmentName).commit(); }
Example 11
Source File: TestFragmentActivity.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
@Override protected void onCreate(final Bundle savedState) { super.onCreate(savedState); final Intent intent = getIntent(); final String fragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); if (fragmentName == null) { throw new IllegalArgumentException("No fragment name specified for testing"); } mFragment = Fragment.instantiate(this, fragmentName); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().add(mFragment, fragmentName).commit(); }
Example 12
Source File: MainActivity.java From trekarta with GNU General Public License v3.0 | 5 votes |
private void onRecordClicked() { HelperUtils.showTargetedAdvice(this, Configuration.ADVICE_RECORD_TRACK, R.string.advice_record_track, mViews.recordButton, false); Bundle args = new Bundle(1); args.putBoolean(DataSourceList.ARG_NATIVE_TRACKS, true); Fragment fragment = Fragment.instantiate(this, DataSourceList.class.getName(), args); showExtendPanel(PANEL_STATE.RECORD, "nativeTrackList", fragment); }
Example 13
Source File: MainActivity.java From trekarta with GNU General Public License v3.0 | 5 votes |
private void onMoreClicked() { if (mViews.locationButton.getVisibility() == View.VISIBLE) { PanelMenuFragment fragment = (PanelMenuFragment) Fragment.instantiate(this, PanelMenuFragment.class.getName()); fragment.setMenu(R.menu.menu_main, menu -> { Resources resources = getResources(); MenuItem item = menu.findItem(R.id.actionActivity); String[] activities = resources.getStringArray(R.array.activities); int activity = Configuration.getActivity(); if (activity > 0) ((TextView) item.getActionView()).setText(activities[activity]); if (BuildConfig.FULL_VERSION) { menu.findItem(R.id.actionHideSystemUI).setChecked(Configuration.getHideSystemUI()); } else { menu.removeItem(R.id.actionHideSystemUI); } if (Configuration.ratingActionPerformed() || (Configuration.getRunningTime() < 120 && mWaypointDbDataSource.getWaypointsCount() < 3 && mData.size() == 0 && mMapIndex.getMaps().size() == 0)) { menu.removeItem(R.id.actionRate); } if (mViews.gaugePanel.hasVisibleGauges() || (mLocationState != LocationState.NORTH && mLocationState != LocationState.TRACK)) menu.removeItem(R.id.actionAddGauge); java.util.Map<String, Pair<Drawable, Intent>> tools = getPluginsTools(); String[] toolNames = tools.keySet().toArray(new String[0]); Arrays.sort(toolNames, Collections.reverseOrder(String.CASE_INSENSITIVE_ORDER)); for (String toolName : toolNames) { Pair<Drawable, Intent> tool = tools.get(toolName); item = menu.add(PanelMenuItem.HEADER_ID_UNDEFINED, 0, toolName); //item.setIcon(tool.first); if (tool != null) item.setIntent(tool.second); } }); showExtendPanel(PANEL_STATE.MORE, "panelMenu", fragment); } else { showActionPanel(true, true); } }
Example 14
Source File: TestFragmentActivity.java From Android-Keyboard with Apache License 2.0 | 5 votes |
@Override protected void onCreate(final Bundle savedState) { super.onCreate(savedState); final Intent intent = getIntent(); final String fragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); if (fragmentName == null) { throw new IllegalArgumentException("No fragment name specified for testing"); } mFragment = Fragment.instantiate(this, fragmentName); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().add(mFragment, fragmentName).commit(); }
Example 15
Source File: CannyEdgesProcessor.java From Camdroid with Apache License 2.0 | 4 votes |
@Override public Fragment getConfigUiFragment(Context context) { return Fragment.instantiate(context, CannyEdgesUIFragment.class.getName()); }
Example 16
Source File: AdaptiveThresholdProcessor.java From Camdroid with Apache License 2.0 | 4 votes |
@Override public Fragment getConfigUiFragment(Context context) { return Fragment.instantiate(context, AdaptiveThresholdUIFragment.class.getName()); }
Example 17
Source File: PageListAdapter.java From SmileEssence with MIT License | 4 votes |
@Override public synchronized Fragment getItem(int position) { PageInfo info = pages.get(position); return Fragment.instantiate(context, info.fragmentClass.getName(), info.args); }
Example 18
Source File: MovementDetectionProcessor.java From Camdroid with Apache License 2.0 | 4 votes |
@Override public Fragment getConfigUiFragment(Context context) { return Fragment.instantiate(context, BackgroundSubstractionUIFragment.class.getName()); }
Example 19
Source File: FragmentNestingStatePagerSupport.java From V.FlyoutTest with MIT License | 4 votes |
@Override public Fragment getItem(int position) { TabInfo info = mTabs.get(position); return Fragment.instantiate(mContext, info.clss.getName(), info.args); }
Example 20
Source File: PreferenceActivity.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Start a new fragment containing a preference panel. If the preferences * are being displayed in multi-pane mode, the given fragment class will * be instantiated and placed in the appropriate pane. If running in * single-pane mode, a new activity will be launched in which to show the * fragment. * * @param fragmentClass Full name of the class implementing the fragment. * @param args Any desired arguments to supply to the fragment. * @param titleRes Optional resource identifier of the title of this * fragment. * @param titleText Optional text of the title of this fragment. * @param resultTo Optional fragment that result data should be sent to. * If non-null, resultTo.onActivityResult() will be called when this * preference panel is done. The launched panel must use * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. * @param resultRequestCode If resultTo is non-null, this is the caller's * request code to be received with the result. */ public void startPreferencePanel(String fragmentClass, Bundle args, @StringRes int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) { Fragment f = Fragment.instantiate(this, fragmentClass, args); if (resultTo != null) { f.setTargetFragment(resultTo, resultRequestCode); } FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(com.android.internal.R.id.prefs, f); if (titleRes != 0) { transaction.setBreadCrumbTitle(titleRes); } else if (titleText != null) { transaction.setBreadCrumbTitle(titleText); } transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.addToBackStack(BACK_STACK_PREFS); transaction.commitAllowingStateLoss(); }