下面列出了android.app.FragmentTransaction#commit ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void onTrackProperties(String path) {
logger.debug("onTrackProperties({})", path);
//TODO Think of better way to find appropriate track
for (FileDataSource source : mData) {
if (source.path.equals(path)) {
mEditedTrack = source.tracks.get(0);
break;
}
}
if (mEditedTrack == null)
return;
Bundle args = new Bundle(2);
args.putString(TrackProperties.ARG_NAME, mEditedTrack.name);
args.putInt(TrackProperties.ARG_COLOR, mEditedTrack.style.color);
Fragment fragment = Fragment.instantiate(this, TrackProperties.class.getName(), args);
fragment.setEnterTransition(new Fade());
FragmentTransaction ft = mFragmentManager.beginTransaction();
ft.replace(R.id.contentPanel, fragment, "trackProperties");
ft.addToBackStack("trackProperties");
ft.commit();
updateMapViewArea();
}
@Override
public void onRouteDetails(Route route) {
Fragment fragment = mFragmentManager.findFragmentByTag("routeInformation");
if (fragment == null) {
fragment = Fragment.instantiate(this, RouteInformation.class.getName());
Slide slide = new Slide(mSlideGravity);
// Required to sync with FloatingActionButton
slide.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
fragment.setEnterTransition(slide);
FragmentTransaction ft = mFragmentManager.beginTransaction();
ft.replace(R.id.contentPanel, fragment, "routeInformation");
ft.addToBackStack("routeInformation");
ft.commit();
updateMapViewArea();
}
((RouteInformation) fragment).setRoute(route);
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();
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
switch (position) {
case 0:
ft.replace(R.id.container, VerticalFragment.newInstance());
break;
case 1:
ft.replace(R.id.container, HorizontalFragment.newInstance());
break;
case 2:
ft.replace(R.id.container, StaticTwoWayFragment.newInstance());
break;
case 3:
ft.replace(R.id.container, FixedTwoWayFragment.newInstance());
break;
default:
//Do nothing
break;
}
ft.commit();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the string arrays with the titles and qutoes
TitleArray = getResources().getStringArray(R.array.Titles);
QuoteArray = getResources().getStringArray(R.array.Quotes);
setContentView(R.layout.main);
// Get a reference to the FragmentManager
mFragmentManager = getFragmentManager();
// Start a new FragmentTransaction
FragmentTransaction fragmentTransaction = mFragmentManager
.beginTransaction();
// Add the TitleFragment to the layout
fragmentTransaction.add(R.id.title_fragment_container, mTitlesFragment);
// Commit the FragmentTransaction
fragmentTransaction.commit();
}
@Override
public void onDataSourceSelected(@NonNull DataSource source) {
Bundle args = new Bundle(3);
if (mLocationState != LocationState.DISABLED && mLocationService != null) {
Location location = mLocationService.getLocation();
args.putDouble(DataList.ARG_LATITUDE, location.getLatitude());
args.putDouble(DataList.ARG_LONGITUDE, location.getLongitude());
args.putBoolean(DataList.ARG_CURRENT_LOCATION, true);
} else {
MapPosition position = mMap.getMapPosition();
args.putDouble(DataList.ARG_LATITUDE, position.getLatitude());
args.putDouble(DataList.ARG_LONGITUDE, position.getLongitude());
args.putBoolean(DataList.ARG_CURRENT_LOCATION, false);
}
args.putInt(DataList.ARG_HEIGHT, mViews.extendPanel.getHeight());
DataList fragment = (DataList) Fragment.instantiate(this, DataList.class.getName(), args);
fragment.setDataSource(source);
FragmentTransaction ft = mFragmentManager.beginTransaction();
fragment.setEnterTransition(new Fade());
ft.add(R.id.extendPanel, fragment, "dataList");
ft.addToBackStack("dataList");
ft.commit();
}
private void displayContact(long rowID, int viewID)
{
DetailsFragment detailsFragment = new DetailsFragment();
// specify rowID as an argument to the DetailsFragment
Bundle arguments = new Bundle();
arguments.putLong(ROW_ID, rowID);
detailsFragment.setArguments(arguments);
// use a FragmentTransaction to display the DetailsFragment
FragmentTransaction transaction =
getFragmentManager().beginTransaction();
transaction.replace(viewID, detailsFragment);
transaction.addToBackStack(null);
transaction.commit(); // causes DetailsFragment to display
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
FragmentManager manager = getFragmentManager();
switch (item.getItemId()) {
case R.id.actionadd1:
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.fragmentcontainer1, new MyListFragment());
transaction
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
break;
case R.id.actionadd2:
transaction = manager.beginTransaction();
transaction.add(R.id.fragmentcontainer2, new DetailFragment());
transaction.commit();
break;
default:
break;
}
// transaction = getFragmentManager().beginTransaction();
// transaction.add(R.id.fragmentcontainer2, new DetailFragment());
// transaction.commit();
return true;
}
public void click3(View v){
//��ʾfragment03
//1.����Fragment����
Fragment03 fragment03 = new Fragment03();
//2.��ȡFragment������
FragmentManager fm = getFragmentManager();
//3.������
FragmentTransaction ft = fm.beginTransaction();
//4.������ʾfragment03
//arg0:������id��Ҳ����֡����
ft.replace(R.id.fl, fragment03);
//5.�ύ
ft.commit();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_example);
if (savedInstanceState == null) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.videoFragment, new VideoConsumptionExampleFragment(),
VideoConsumptionExampleFragment.TAG);
ft.commit();
}
}
@Override
public void onItemSelectedHandler(HexDrawer.Item item) {
String collection;
switch (item) {
case Settings:
Intent settingsIntent = new Intent(getApplicationContext(), SettingsActivity.class);
startActivity(settingsIntent);
break;
case About:
Intent aboutIntent = new Intent(getApplicationContext(), AboutActivity.class);
startActivity(aboutIntent);
break;
default:
mCurrentItem = item;
collection = itemToCollection.get(item).toString();
Bundle bundle = new Bundle();
bundle.putString(StoryListFragment.CollectionKey, collection);
StoryListFragment storyListFragment = new StoryListFragment();
storyListFragment.setArguments(bundle);
if (getFragmentManager().getBackStackEntryCount() > 0) {
getFragmentManager().popBackStackImmediate();
}
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.content_wrapper, storyListFragment);
transaction.addToBackStack(item.toString());
transaction.commit();
break;
}
}
/**
* ピンを選択するフラグメントを表示します.
* @param fragment 表示するフラグメント
*/
private void showPinFragment(final FaBoBasePinFragment fragment) {
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.container, fragment);
transaction.commit();
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.preferences_fragment, new SettingsFragment());
fragmentTransaction.commit();
}
@Override
protected void onCreate(final Bundle b) {
super.onCreate(b);
if (Build.VERSION.SDK_INT >= 26) {
API26Wrapper.startForegroundService(this, new Intent(this, SensorListener.class));
} else {
startService(new Intent(this, SensorListener.class));
}
if (b == null) {
// Create new fragment and transaction
Fragment newFragment = new Fragment_Overview();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this
// fragment,
// and add the transaction to the back stack
transaction.replace(android.R.id.content, newFragment);
// Commit the transaction
transaction.commit();
}
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this, this, this);
builder.addApi(Games.API, Games.GamesOptions.builder().build());
builder.addScope(Games.SCOPE_GAMES);
builder.addApi(Fitness.HISTORY_API);
builder.addApi(Fitness.RECORDING_API);
builder.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE));
mGoogleApiClient = builder.build();
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && PermissionChecker
.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
PermissionChecker.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout, new GuideViewFragment());
transaction.commit();
}
@Override
public void onListSelection(int index) {
// If the QuoteFragment has not been created, create and add it now
if (null == mFragmentManager.findFragmentById(R.id.quote_fragment_container)) {
// Start a new FragmentTransaction
FragmentTransaction fragmentTransaction = mFragmentManager
.beginTransaction();
mQuoteFragment = new QuotesFragment();
// Add the QuoteFragment to the layout
fragmentTransaction.add(R.id.quote_fragment_container,
mQuoteFragment);
// Add this FragmentTransaction to the backstack
fragmentTransaction.addToBackStack(null);
// Commit the FragmentTransaction
fragmentTransaction.commit();
// Force Android to execute the committed FragmentTransaction
mFragmentManager.executePendingTransactions();
}
// Tell the QuoteFragment to show the quote string at position index
mQuoteFragment.showQuoteAtIndex(index);
}
public void click3(View v){
//��ʾfragment03
//1.����Fragment����
Fragment03 fragment03 = new Fragment03();
//2.��ȡFragment������
FragmentManager fm = getFragmentManager();
//3.������
FragmentTransaction ft = fm.beginTransaction();
//4.������ʾfragment03
//arg0:������id��Ҳ����֡����
ft.replace(R.id.fl, fragment03);
//5.�ύ
ft.commit();
}
public void click3(View v){
//��ʾfragment03
//1.����Fragment����
Fragment03 fragment03 = new Fragment03();
//2.��ȡFragment������
FragmentManager fm = getFragmentManager();
//3.������
FragmentTransaction ft = fm.beginTransaction();
//4.������ʾfragment03
//arg0:������id��Ҳ����֡����
ft.replace(R.id.fl, fragment03);
//5.�ύ
ft.commit();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playback_rows_control);
VideoContent videoContent = null;
/**
* If this activity is started from the home screen (that is the only information
* we have is videoId)
* a videoContent will be constructed through it, and put as an extra to the intent
* So VideoConsumptionExampleFragment can find the video source to play
*/
Uri videoUri = getIntent().getData();
if (videoUri != null) {
String videoId = getVideoID(getIntent().getData());
/**
* Populate play lists firstly
*/
ChannelContents.initializePlaylists(this);
/**
* Iterate through all video clips to find the video content which is selected
* from home screen
*/
for (int i = 0; i < ChannelContents.sChannelContents.size(); ++i) {
List<VideoContent> videos = ChannelContents.sChannelContents.get(i).getVideos();
for (VideoContent candidateVideo : videos) {
if (TextUtils.equals(candidateVideo.getVideoId(), videoId)) {
videoContent = candidateVideo;
break;
}
}
}
} else {
/**
* If this activity is started from clicking the video content
* from DynamicRowFragment
*/
videoContent
= getIntent().getParcelableExtra(VideoExampleActivity.TAG);
}
/**
* Firstly convert VideoContent to MediaMetaData,
* then put MediaMetaData as an extra for this intent
*/
getIntent().putExtra(VideoExampleActivity.TAG,
videoContentToMediaMetaData(videoContent));
VideoConsumptionExampleFragment videoPlaybackFragment = new VideoConsumptionExampleFragment();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(android.R.id.content, videoPlaybackFragment);
fragmentTransaction.commit();
}
private static void requestPermissions(
FlutterIncallManagerPlugin plugin,
String[] permissions,
ResultReceiver resultReceiver) {
// Ask the Context whether we have already been granted the requested
// permissions.
int size = permissions.length;
int[] grantResults = new int[size];
boolean permissionsGranted = true;
for (int i = 0; i < size; ++i) {
int grantResult
= ContextCompat.checkSelfPermission(
plugin.getContext(),
permissions[i]);
grantResults[i] = grantResult;
if (grantResult != PackageManager.PERMISSION_GRANTED) {
permissionsGranted = false;
}
}
// Obviously, if the requested permissions have already been granted,
// there is nothing to ask the user about. On the other hand, if there
// is no Activity or the runtime permissions are not supported, there is
// no way to ask the user to grant us the denied permissions.
int requestCode = ++PermissionUtils.requestCode;
if (permissionsGranted
// Here we test for the target SDK version with which *the app*
// was compiled. If we use Build.VERSION.SDK_INT that would give
// us the API version of the device itself, not the version the
// app was compiled for. When compiled for API level < 23 we
// must still use old permissions model, regardless of the
// Android version on the device.
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.M
|| plugin.getActivity().getApplicationInfo().targetSdkVersion
< Build.VERSION_CODES.M) {
send(resultReceiver, requestCode, permissions, grantResults);
return;
}
Activity activity = plugin.getActivity();
// If a ReactContext does not have a current Activity, then wait for
// it to get a current Activity; otherwise, the user will not be asked
// about the denied permissions and getUserMedia will fail.
if (activity == null) {
maybeRequestPermissionsOnHostResume(
plugin,
permissions,
grantResults,
resultReceiver,
requestCode);
return;
}
Bundle args = new Bundle();
args.putInt(REQUEST_CODE, requestCode);
args.putParcelable(RESULT_RECEIVER, resultReceiver);
args.putStringArray(PERMISSIONS, permissions);
RequestPermissionsFragment fragment = new RequestPermissionsFragment();
fragment.setArguments(args);
fragment.setPlugin(plugin);
FragmentTransaction transaction
= activity.getFragmentManager().beginTransaction().add(
fragment,
fragment.getClass().getName() + "-" + requestCode);
try {
transaction.commit();
} catch (IllegalStateException ise) {
// The Activity has likely already saved its state.
maybeRequestPermissionsOnHostResume(
plugin,
permissions,
grantResults,
resultReceiver,
requestCode);
}
}
public void onItemSelected(int position) {
Log.i(TAG, "Entered onItemSelected(" + position + ")");
// If there is no FeedFragment instance, then create one
if (mFeedFragment == null)
mFeedFragment = new FeedFragment();
// If in single-pane mode, replace single visible Fragment
if (!isInTwoPaneMode()) {
//TODO 2 - replace the fragment_container with the FeedFragment
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, mFeedFragment);
transaction.addToBackStack(null);
transaction.commit();
// execute transaction now
getFragmentManager().executePendingTransactions();
}
// Update Twitter feed display on FriendFragment
mFeedFragment.updateFeedDisplay(position);
}