android.app.FragmentTransaction#commit ( )源码实例Demo

下面列出了android.app.FragmentTransaction#commit ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: trekarta   文件: MainActivity.java
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();
}
 
源代码2 项目: trekarta   文件: MainActivity.java
@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();
}
 
源代码4 项目: coursera-android   文件: QuoteViewerActivity.java
@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();

}
 
源代码5 项目: trekarta   文件: MainActivity.java
@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();
}
 
源代码6 项目: CSCI4669-Fall15-Android   文件: MainActivity.java
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
}
 
源代码7 项目: codeexamples-android   文件: MainActivity.java
@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;
}
 
源代码8 项目: Android-Basics-Codes   文件: MainActivity.java
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();
}
 
源代码9 项目: tv-samples   文件: VideoExampleActivity.java
@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();
    }
}
 
源代码10 项目: hex   文件: MainActivity.java
@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();
}
 
源代码12 项目: NewsPushMonitor   文件: SettingsActivity.java
@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();
}
 
源代码13 项目: Pedometer   文件: Activity_Main.java
@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);
    }
}
 
源代码14 项目: GuideView   文件: MainActivity.java
@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();
}
 
源代码15 项目: coursera-android   文件: QuoteViewerActivity.java
@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);

}
 
源代码16 项目: Android-Basics-Codes   文件: MainActivity.java
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();
}
 
源代码17 项目: Android-Basics-Codes   文件: MainActivity.java
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();
}
 
源代码18 项目: tv-samples   文件: VideoPlaybackActivity.java
@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();
}
 
源代码19 项目: flutter-incall-manager   文件: PermissionUtils.java
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);
    }
}
 
源代码20 项目: android_coursera_1   文件: MainActivity.java
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);

	}