下面列出了android.app.Fragment#instantiate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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();
}
/**
* 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();
}
}
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();
}
@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();
}
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);
}
}
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);
}
@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();
}
@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();
}
@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();
}
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);
}
@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;
}
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();
}
@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();
}
@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");
}
}
/**
* 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();
}
@Override
public synchronized Fragment getItem(int position) {
PageInfo info = pages.get(position);
return Fragment.instantiate(context, info.fragmentClass.getName(), info.args);
}
@Override
public Fragment getConfigUiFragment(Context context) {
return Fragment.instantiate(context, CannyEdgesUIFragment.class.getName());
}
@Override
public Fragment getConfigUiFragment(Context context) {
return Fragment.instantiate(context, AdaptiveThresholdUIFragment.class.getName());
}
@Override
public Fragment getConfigUiFragment(Context context) {
return Fragment.instantiate(context, BackgroundSubstractionUIFragment.class.getName());
}
@Override
public Fragment getItem(int position) {
TabInfo info = mTabs.get(position);
return Fragment.instantiate(mContext, info.clss.getName(), info.args);
}