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:at.tugraz.ist.akm.activities.MainActivity.java

private void fragmentTransaction(String fragmentTag) {
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    mCurrentFragment = Fragment.instantiate(MainActivity.this, fragmentTag);
    transaction.replace(R.id.navigation_drawer_content_frame, mCurrentFragment, fragmentTag);
    transaction.commit();
}

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

public void addTestLicenseFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    TestLicense testLicense = new TestLicense();
    testLicense.setUserModel(userModel);
    fragmentTransaction.replace(R.id.fragment_container, testLicense);
    fragmentTransaction.commit();
}

From source file:net.wespot.pim.controller.InquiryActivity.java

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        INQ.init(this);
        INQ.accounts.syncMyAccountDetails();
        INQ.inquiry.setCurrentInquiry(DaoConfiguration.getInstance().getInquiryLocalObjectDao()
                .load(savedInstanceState.getLong(CURRENT_INQUIRY)));

        INQ.inquiry.getCurrentInquiry().setRunLocalObject(DaoConfiguration.getInstance().getRunLocalObjectDao()
                .load(savedInstanceState.getLong(CURRENT_INQUIRY_RUN)));

        Log.e(TAG, "RUN ID: " + INQ.inquiry.getCurrentInquiry().getRunLocalObject().getId() + " "
                + INQ.inquiry.getCurrentInquiry().getRunLocalObject().getTitle());
        Log.e(TAG, "INQUIRY ID: " + INQ.inquiry.getCurrentInquiry().getId() + " "
                + INQ.inquiry.getCurrentInquiry().getTitle());
    }// www .j  a  v  a2 s .  c  o  m

    if (INQ.inquiry.getCurrentInquiry() == null) {
        Log.e(TAG, "New inquiry");

        setContentView(R.layout.wrapper);
        FragmentManager fragmentManager = getSupportFragmentManager();
        android.support.v4.app.FragmentTransaction fragmentTransaction;

        fragmentTransaction = fragmentManager.beginTransaction();
        InqCreateInquiryFragment fragment = new InqCreateInquiryFragment();
        fragmentTransaction.add(R.id.content, fragment);
        fragmentTransaction.commit();

        setTitle(R.string.actionbar_inquiry_list);

    } else {
        setContentView(R.layout.activity_inquiry);

        // Create an adapter that when requested, will return a fragment representing an object in
        // the collection.
        // ViewPager and its adapters use support library fragments, so we must use
        // getSupportFragmentManager.
        /*
          The {@link android.support.v4.view.PagerAdapter} that will provide fragments representing
          each object in a collection. We use a {@link android.support.v4.app.FragmentStatePagerAdapter}
          derivative, which will destroy and re-create fragments as needed, saving and restoring their
          state in the process. This is important to conserve memory and is a best practice when
          allowing navigation between objects in a potentially large collection.
         */
        InquiryPagerAdapter mInquiryPagerAdapter = new InquiryPagerAdapter(getSupportFragmentManager(),
                mViewPager);
        getmActionBarHelper().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);

        // Set up the ViewPager, attaching the adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mInquiryPagerAdapter);
        mViewPager.setOnPageChangeListener(this);

        // For each of the sections in the app, add a tab to the action bar.
        for (int i = 0; i < mInquiryPagerAdapter.getCount(); i++) {
            // Create a tab with text corresponding to the page title defined by the adapter.
            // Also specify this Activity object, which implements the TabListener interface, as the
            // listener for when this tab is selected.
            getmActionBarHelper().addTab(getmActionBarHelper().newTab()
                    .setText(mInquiryPagerAdapter.getPageTitle(i)).setTabListener(this));
        }

        getActionBar().setTitle(getResources().getString(R.string.actionbar_inquiry) + " - "
                + INQ.inquiry.getCurrentInquiry().getTitle());

        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            mViewPager.setCurrentItem(extras.getInt(PHASE));
        }
    }
}

From source file:jsettlers.main.android.JsettlersActivity.java

public void showFragment(JsettlersFragment fragment) {
    FragmentManager manager = getFragmentManager();
    if (!fragment.shouldAddToBackStack()) {
        manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }/*from  w  ww. j a va2 s  .c  o m*/
    FragmentTransaction transaction = manager.beginTransaction();
    if (fragment.shouldAddToBackStack()) {
        transaction.addToBackStack(fragment.getName());
    }
    transaction.replace(R.id.base_menu, fragment);
    transaction.commit();
}

From source file:com.galois.qrstream.MainActivity.java

private void showFragment(Fragment fragment, boolean addToBackStack) {
    FragmentTransaction ft = fragmentManager.beginTransaction();

    // Replace null parameter with string only if
    // change to ft.replace(int,Fragment,String)
    ft.replace(R.id.container, fragment);
    if (addToBackStack) {
        ft.addToBackStack(null);//ww w . j  av a  2s. com
    }
    ft.commit();
    lastFragment = currentFragment;
    currentFragment = fragment;
}

From source file:com.example.ogadrive.HomeActivity2.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;/*from  w  w w.  jav a 2 s .  com*/

    if (position == 1) {
        /*fragment = new HomeFragement();
        fragment.setArguments(bundle);*/

        fragment = new FragmentHistory();
        fragment.setArguments(bundle);
    } else if (position == 0) {
        fragment = new FragmentProfile();
        fragment.setArguments(bundle);

    } else if (position == 2) {

        setTitle("Contact Us");
    } else if (position == 3) {

        fragment = new FragmentHistory();
        fragment.setArguments(bundle);
    }

    if (fragment == null) {
        fragment = new HomeFragement();
        fragment.setArguments(bundle);
    }

    FragmentManager fragmentManager = getFragmentManager();
    // fragmentManager.popBackStack();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    fragmentTransaction.add(R.id.content_frame, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
    // fragmentTransaction.addToBackStack("hradesh").commit();
    // fragmentManager.getBackStackEntryAt(fragmentManager.getBackStackEntryCount()-1);

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);

    // }
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:org.chromium.chrome.browser.bookmark.ManageBookmarkActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {/*from   w  ww  . j a v  a 2  s . c o  m*/
        if (getApplication() instanceof ChromeApplication) {
            ((ChromeApplication) getApplication()).startBrowserProcessesAndLoadLibrariesSync(true);
        }
    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        ChromeApplication.reportStartupErrorAndExit(e);
        return;
    }
    if (!DeviceFormFactor.isTablet(this)) {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
                | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }

    if (savedInstanceState == null) {
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.add(android.R.id.content, generateBaseFragment(), BASE_ADD_EDIT_FRAGMENT_TAG);
        fragmentTransaction.commit();
    } else {
        initializeFragmentState();
    }

    // When adding or removing fragments, ensure the keyboard is hidden if visible as the
    // editing fields are no longer on the screen.
    getFragmentManager().addOnBackStackChangedListener(new OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            UiUtils.hideKeyboard(findViewById(android.R.id.content));
        }
    });
    if (checkPermission(Manifest.permission.NFC, Process.myPid(),
            Process.myUid()) == PackageManager.PERMISSION_GRANTED) {
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter != null)
            nfcAdapter.setNdefPushMessage(null, this);
    }
}

From source file:com.example.atsuto5.yahoo_rss_reader.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*www.j a v a  2  s . c o  m*/
public boolean onNavigationItemSelected(MenuItem item) {

    int id = item.getItemId();

    android.app.FragmentManager fragmentManager = getFragmentManager();
    android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (id == R.id.maintopics_logo) {
        fragmentTransaction.replace(R.id.fragment_container, MainTopicsFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(140, 0, 0, 0);

    } else if (id == R.id.international_logo) {
        fragmentTransaction.replace(R.id.fragment_container, InternationalFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.entertainment) {
        fragmentTransaction.replace(R.id.fragment_container, EntertainmentFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(260, 0, 0, 0);

    } else if (id == R.id.it_logo) {
        fragmentTransaction.replace(R.id.fragment_container, ItFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("IT");
        mToolbar.setTitleMargin(340, 0, 0, 0);

    } else if (id == R.id.local_logo) {
        fragmentTransaction.replace(R.id.fragment_container, LocalFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.domestic_logo) {
        fragmentTransaction.replace(R.id.fragment_container, DomesticFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.economy_logo) {
        fragmentTransaction.replace(R.id.fragment_container, EconomyFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.sports_logo) {
        fragmentTransaction.replace(R.id.fragment_container, SportsFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("?");
        mToolbar.setTitleMargin(260, 0, 0, 0);

    } else if (id == R.id.science_logo) {
        fragmentTransaction.replace(R.id.fragment_container, ScienceFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.interestgraph_logo) {
        fragmentTransaction.replace(R.id.fragment_container, InterestChartFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("?????");
        mToolbar.setTitleMargin(200, 0, 0, 0);

    } else if (id == R.id.your_like_logo) {
        fragmentTransaction.replace(R.id.fragment_container, InterestChartFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("?????");
        mToolbar.setTitleMargin(200, 0, 0, 0);

    } else if ("License".equals(item.getTitle())) {
        fragmentTransaction.replace(R.id.fragment_container, LicenseFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("License");
        mToolbar.setTitleMargin(280, 0, 0, 0);

    } else if ("?".equals(item.getTitle())) {
        fragmentTransaction.replace(R.id.fragment_container, MainTopicsFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(140, 0, 0, 0);

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.orpheusdroid.screenrecorder.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from   w w w . j ava 2s .c  o  m*/

    //Arbitrary "Write to external storage" permission since this permission is most important for the app
    requestPermissionStorage();

    //final boolean isServiceRunning = isServiceRunning(RecorderService.class);
    //Let's add SettingsPreferenceFragment to the activity
    FragmentManager mFragmentManager = getFragmentManager();
    FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction();
    SettingsPreferenceFragment mPrefsFragment = new SettingsPreferenceFragment();
    mFragmentTransaction.replace(R.id.settingsFragment, mPrefsFragment);
    mFragmentTransaction.commit();

    //Acquiring media projection service to start screen mirroring
    mProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);

    //Respond to app shortcut
    if (getIntent().getAction() != null
            && getIntent().getAction().equals(getString(R.string.app_shortcut_action))) {
        startActivityForResult(mProjectionManager.createScreenCaptureIntent(), SCREEN_RECORD_REQUEST_CODE);
        return;
    }

    fab = (FloatingActionButton) findViewById(R.id.fab);

    if (isServiceRunning(RecorderService.class)) {
        Log.d(Const.TAG, "service is running");
        changeFabIcon(Status.RECORDING);
    }
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mMediaProjection == null && !isServiceRunning(RecorderService.class)) {
                //Request Screen recording permission
                startActivityForResult(mProjectionManager.createScreenCaptureIntent(),
                        SCREEN_RECORD_REQUEST_CODE);
            } else if (isServiceRunning(RecorderService.class)) {
                //stop recording if the service is already active and recording
                Intent stopRecording = new Intent(MainActivity.this, RecorderService.class);
                stopRecording.setAction(Const.SCREEN_RECORDING_STOP);
                startService(stopRecording);
                changeFabIcon(Status.STOPPED);
            }
        }
    });
    fab.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            //Show hint toast based on recording status
            if (isServiceRunning(RecorderService.class))
                Toast.makeText(MainActivity.this, R.string.fab_record_hint, Toast.LENGTH_SHORT).show();
            else
                Toast.makeText(MainActivity.this, R.string.fab_stop_hint, Toast.LENGTH_SHORT).show();
            return true;
        }
    });

}

From source file:com.ppgllrd.alfil.MainActivity.java

private void selectCourse(int position) {
    Log.d("ppgllrd", "selectCourse" + position + " " + drawerSelectedIdx);
    boolean isSelectable = drawerItems.get(position) instanceof DrawerCourse;

    if (isSelectable) {
        final DrawerCourse drawerCourse = (DrawerCourse) drawerItems.get(position);
        FragmentManager fragmentManager = getFragmentManager();
        Log.d("ppgllrd", "Count:" + fragmentManager.getBackStackEntryCount());

        if (position != drawerSelectedIdx) {
            Log.d("ppgllrd", "YES");
            drawerSelectedIdx = position;

            studentsListFragment = new StudentsListFragment();
            Bundle args = new Bundle();
            args.putParcelable(StudentsListFragment.ARG_GROUP_STUDENTS_COURSE, drawerCourse.getCourse());
            studentsListFragment.setArguments(args);

            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.replace(R.id.list_Fragment_Placeholder, studentsListFragment, StudentsListFragment.FragmentTag);
            //ft.addToBackStack(StudentInfoFragment.FragmentTag);
            ft.commit();
        }// w w w. j  ava2 s .  c o  m
        Log.d("ppgllrd", "YYY");

        actionBarTitleController.closeDrawer();

        if (studentInfoFragment.isShown()) {
            FragmentManager fm = getFragmentManager();
            if (fm.getBackStackEntryCount() > 0) {
                fm.popBackStack();
            }
        }
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.show(studentsListFragment);
        ft.hide(studentInfoFragment);
        // ft.addToBackStack(StudentInfoFragment.FragmentTag);
        ft.commit();

    }
    Log.d("ppgllrd", "ZZZ");
}