Example usage for android.app FragmentTransaction commit

List of usage examples for android.app FragmentTransaction commit

Introduction

In this page you can find the example usage for android.app FragmentTransaction commit.

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

From source file:com.example.koppa.driverlicensev2.MainActivity.java

public void addPracticeFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    PracticeFragment practiceFragment = new PracticeFragment();
    fragmentTransaction.replace(R.id.fragment_container, practiceFragment);
    fragmentTransaction.commit();
}

From source file:com.example.android.touroflondon.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    //Verify that Google Play Services is available
    int playStatus = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    if (playStatus != ConnectionResult.SUCCESS) {
        // Google Play services is not available, prompt user and close application when dialog is dismissed
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(playStatus, this, 0);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override/* ww  w .j a  v a 2s.  co m*/
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        dialog.show();

        // Hide all active fragments
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.hide(mMapFragment);
        if (mPoiListFragment != null) {
            ft.hide(mPoiListFragment);
        }
        ft.commit();

    } else {

        // Getting reference to the SupportMapFragment of activity_main.xml
        TourMapFragment fm = (TourMapFragment) getFragmentManager().findFragmentById(R.id.fragment_map);

        // Getting GoogleMap object from the fragment
        googleMap = fm.getMap();

        // Enabling MyLocation Layer of Google Map
        googleMap.setMyLocationEnabled(true);

        // Getting LocationManager object from System Service LOCATION_SERVICE
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20000, 0, mMapFragment);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 20000, 0, mMapFragment);
        //            Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

        // Make sure active fragments are shown when returning from Play Services dialog interaction
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.show(mMapFragment);
        if (mPoiListFragment != null) {
            ft.show(mPoiListFragment);
        }
        ft.commit();

    }

}

From source file:la.marsave.fullscreentest.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WindowManager.LayoutParams layout = getWindow().getAttributes();
    layout.screenBrightness = 1F;//from w  ww  . jav a2 s.c om
    getWindow().setAttributes(layout);
    setContentView(R.layout.activity_main);

    getFragmentManager().addOnBackStackChangedListener(this);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    /*
      The {@link android.support.v4.view.PagerAdapter} that will provide
      fragments for each of the sections. We use a
      {@link SectionsPagerAdapter} derivative, which will keep every
      loaded fragment in memory. If this becomes too memory intensive, it
      may be best to switch to a
      {@link android.support.v13.app.FragmentStatePagerAdapter}.
     */
    SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

    mScrollDetector = new GestureDetector(this, new ViewPagerGestureDetector());

    // Set up the ViewPager with the sections adapter.
    mInfiniteViewPager = (InfiniteViewPager) findViewById(R.id.pager);
    mInfiniteViewPager.setAdapter(new InfinitePagerAdapter(mSectionsPagerAdapter));
    mInfiniteViewPager.setPageTransformer(true, new ZoomOutPageTransformer());
    mInfiniteViewPager.setOnTouchListener(mTouchViewPagerListener);

    // Set up the DarkHover that will be seen to cover the adapter once slided in.
    mDarkHoverView = findViewById(R.id.dark_hover_view);
    mDarkHoverView.setAlpha(0);
    mDarkHoverView.setOnTouchListener(mTouchDarkHoverListener);

    mTextFragment = new TextFragment();
    mTextFragment.setOnTextFragmentAnimationEnd(this);

    //we look for the help fragment if already exists.
    mHelpFragment = (HelpFragment) getFragmentManager().findFragmentByTag(HELPED);

    //If it doesn't, we create it, if needed.
    if (mHelpFragment == null
            && !getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE).getBoolean(HELPED, false)) {
        mHelpFragment = new HelpFragment();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.add(R.id.move_to_back_container, mHelpFragment, HELPED);
        transaction.commit();
    }
    if (mHelpFragment != null) {
        mDarkHoverView.setAlpha(0.7F);
        mHelpFragment.setClickListener(mClickHelper);
    }
}

From source file:com.roodie.materialmovies.views.activities.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    MMoviesApp.from(this).inject(this);

    setupActionBar();/*from  w w w. ja  v a2 s . com*/
    if (getDisplay() != null) {
        getDisplay().showUpNavigation(true);
        getDisplay().setActionBarTitle(MMoviesApp.get().getStringFetcher().getString(R.string.settings_title));
    }

    if (savedInstanceState == null) {
        Fragment fragment = new SettingsHeadersFragment();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(R.id.content_frame, fragment);
        ft.commit();
    }
}

From source file:com.pedometrak.ui.ActivityMain.java

@Override
protected void onCreate(final Bundle b) {
    super.onCreate(b);

    if (b == null) {
        // Create new fragment and transaction
        Fragment newFragment = new FragmentOverviewController();
        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();
    }/*from w w  w  .  ja  va  2  s  .  c  o  m*/

    Logger.log("Unsaved sessions: " + LocalDatabaseManager.getInstance(this).getUnsynchedSessions().size());
}

From source file:com.example.koppa.driverlicensev2.MainActivity.java

public void addCUQuestionFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    AddQuestionFragment addQuestionFragment = new AddQuestionFragment();
    fragmentTransaction.replace(R.id.fragment_container, addQuestionFragment);
    fragmentTransaction.commit();
}

From source file:com.example.koppa.driverlicensev2.MainActivity.java

public void addQuestionListFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    QuestionListFragment cuQuestionFragment = new QuestionListFragment();
    fragmentTransaction.replace(R.id.fragment_container, cuQuestionFragment);
    fragmentTransaction.commit();
}

From source file:com.example.koppa.driverlicensev2.MainActivity.java

public void addUserListFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    AdminStatisticFragment cuQuestionFragment = new AdminStatisticFragment();
    fragmentTransaction.replace(R.id.fragment_container, cuQuestionFragment);
    fragmentTransaction.commit();
}

From source file:com.amaze.filemanager.activities.Preferences.java

public void donate() {
    try {//from  w w w .  ja  va2 s.c o  m
        getFragmentManager().beginTransaction().remove(p).commit();
    } catch (Exception e) {
        e.printStackTrace();
    }

    String[] s = new String[] { "Minimal Donation", "Medium Donation", "High Donation" };
    DonationsFragment donationsFragment = DonationsFragment.newInstance(BuildConfig.DEBUG, true, GOOGLE_PUBKEY,
            GOOGLE_CATALOG, s, false, null, null, null, false, null, null, false, null);
    android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.prefsfragment, donationsFragment);
    transaction.commit();
    getSupportActionBar().setTitle(R.string.donate);

}

From source file:com.twp.music.MainActivity.java

private void changePage(PageType type) {
    Fragment fg = null;/*from   w w  w.j  a v a  2  s.  c om*/
    switch (type) {

    case FINDMUSIC:
        fg = new FindMusicFragment();
        break;
    case MYMUSIC:
        fg = new MyMusicFragment();
        break;
    default:

        break;
    }

    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.content, fg);
    ft.commit();
}