Example usage for android.app FragmentManager beginTransaction

List of usage examples for android.app FragmentManager beginTransaction

Introduction

In this page you can find the example usage for android.app FragmentManager beginTransaction.

Prototype

public abstract FragmentTransaction beginTransaction();

Source Link

Document

Start a series of edit operations on the Fragments associated with this FragmentManager.

Usage

From source file:com.google.cloud.solutions.cloudadventure.GameActivity.java

/**
 * This method is called when the Activity receives a message via {@link BroadcastRecevier} that
 * the game has started./*  w  w w.j a v  a2s.com*/
 */
private void onGameStart() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.remove(mPreGameFragment);
    fragmentTransaction.commit();
    progressDialog.dismiss();

    // Set the starting point for fragments
    mNavFragment.setNewDirectionMapper(Cardinal.valueOf(mPlayer.getOrientation()));
    mNavFragment.setCurrentTile(mPlayer.getCurrentTile());
}

From source file:com.google.cloud.solutions.cloudadventure.GameActivity.java

/**
 * This method is called when the Activity receives a message via {@link BroadcastRecevier} that
 * the game has ended./*from  ww w  .j  a  v a  2 s .  co  m*/
 */
private void onGameEnd() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    mScoresFragment = new GameScoresFragment();
    mScoresFragment.setCurrentUserHandle(mHandle);
    fragmentTransaction.add(R.id.game_activity, mScoresFragment);
    fragmentTransaction.commit();

    new SaveScoresAndSend().execute(mHandle, mGameId, Long.toString(mPlayer.getGemsCollected()),
            Long.toString(mPlayer.getMobsKilled()), Long.toString(mPlayer.getNumDeaths()));
}

From source file:com.dsna.android.main.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.demo_activity_main);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    _initMenu();/*from   www .jav a2 s .co  m*/
    mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
    mDrawer.setDrawerListener(mDrawerToggle);

    //-----------------------------------------------------------------
    //BaseFragment baseFragment = null;
    if (savedInstanceState != null) {
        mSelectedFragment = savedInstanceState.getInt(BUNDLE_SELECTEDFRAGMENT);

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        if (fragmentManager.findFragmentById(R.id.fragment_main) == null)
            mBaseFragment = selectFragment(mSelectedFragment);
        //if (mBaseFragment==null)
        //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
        mBaseFragment = new NewFeedsFragment(feeds);
        openFragment(mBaseFragment);
    }

    // Store the booting information to pass to the service
    mBootIp = getIntent().getStringExtra(bIp);
    mBootPort = getIntent().getStringExtra(bPort);
    mBindPort = getIntent().getStringExtra(biPort);
    mUsername = getIntent().getStringExtra(uName);

    // Initiate database helper
    dbHelper = new DatabaseHandler(this, mUsername);

    // Initiate cipher parameters
    publicKeys = null;
    secretKeys = null;
    ps06 = new PS06();
    cd07 = new IBBECD07();

    GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(this,
            java.util.Arrays.asList(DriveScopes.DRIVE));
    credential.setSelectedAccountName(mUsername);
    new googleCloudAuthorizationRequestTask().execute(credential);

}

From source file:com.hit.jj.mapshow.RoutingActivity.java

/**
 * Updates the UI after a successful rest response has been received.
 *//*from   w  ww . j a v a  2  s  . c om*/
void updateUI() {
    dialog.dismiss();
    img_cancel.setVisibility(View.VISIBLE);
    FragmentManager fm = getFragmentManager();
    if (fm.findFragmentByTag("Nav Drawer") == null) {
        FragmentTransaction ft = fm.beginTransaction();
        RoutingListFragment frag = new RoutingListFragment(this);
        ft.add(frag, "Nav Drawer");
        ft.commit();
    } else {
        FragmentTransaction ft = fm.beginTransaction();
        ft.remove(fm.findFragmentByTag("Nav Drawer"));
        RoutingListFragment frag = new RoutingListFragment(this);
        ft.add(frag, "Nav Drawer");
        ft.commit();
    }
    //img_showDirections.setVisibility(View.VISIBLE);

}

From source file:com.jforce.chapelhillnextbus.HomeActivity.java

public void selectItem(int position, boolean alreadyOpen) {
    // update the main content by replacing fragments
    //        Fragment fragment = new PlanetFragment();
    //        Bundle args = new Bundle();
    //        args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
    //        fragment.setArguments(args);

    final int finalPosition = position;

    // update selected item and title, then close the drawer
    if (!alreadyOpen) {

        mDrawerLayout.openDrawer(mDrawerArea);
        new Handler().postDelayed(new Runnable() {
            @Override/*from   w w w .ja  v  a  2 s. c  om*/
            public void run() {

                mDrawerList.setItemChecked(finalPosition, true);
                setTitle(mDrawerTitles[finalPosition]);

                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {

                        FragmentManager fragmentManager = getFragmentManager();

                        if (finalPosition == 0) {

                            Fragment fragment = new PredictionsFragment();

                            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
                        }

                        if (finalPosition == 1) {

                            Fragment fragment = new FavoritesFragment();
                            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

                        }

                        if (finalPosition == 2) {
                            Fragment fragment = new MapFragment();
                            getSupportActionBar().setSubtitle(mSubtitle);
                            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

                        }

                        mDrawerLayout.closeDrawer(mDrawerArea);

                    }
                }, 325);

            }
        }, 400);

    } else {
        mDrawerList.setItemChecked(position, true);
        setTitle(mDrawerTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerArea);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                FragmentManager fragmentManager = getFragmentManager();

                if (finalPosition == 0) {

                    Fragment fragment = new PredictionsFragment();

                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
                }

                if (finalPosition == 1) {

                    Fragment fragment = new FavoritesFragment();
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

                }

                if (finalPosition == 2) {
                    Fragment fragment = new MapFragment();
                    getSupportActionBar().setSubtitle(mSubtitle);
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

                }

            }
        }, 325);

    }

}

From source file:com.hit.jj.mapshow.RoutingActivity.java

/**
 * Clear the graphics and empty the directions list
 *//*from w  w  w.j a  v a 2  s.  c  o m*/
public void clearAll() {
    mFeatureLayer.removeAll();
    //Removing the graphics from the layer
    routeLayer.removeAll();
    hiddenSegmentsLayer.removeAll();

    curDirections = new ArrayList<String>();
    mResults = null;
    curRoute = null;

    //Setting to default text
    directionsLabel.setText(getString(R.string.route_label));

    //Locking the Drawer
    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

    //Removing the cancel icon
    img_cancel.setVisibility(View.GONE);

    //Removing the RoutingListFragment if present
    FragmentManager fm = getFragmentManager();
    if (fm.findFragmentByTag("Nav Drawer") != null) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.remove(fm.findFragmentByTag("Nav Drawer"));
        ft.commit();
    }

}

From source file:org.symptomcheck.capstone.ui.MainActivityOld.java

@Override
public void onBackPressed() {

    if (mFabActionsMenu.isExpanded()) {
        mFabActionsMenu.collapse();//from   w  w  w .  jav  a2s . c  o m
    } else {
        // initialize variables
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();

        // check to see if stack is empty
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
            ft.commit();
            //            } else {
            //                askForExit();
        } else {
            if (mDoubleBackToExitPressedOnce) {
                super.onBackPressed();
                return;
            }
            this.mDoubleBackToExitPressedOnce = true;
            Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();

            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mDoubleBackToExitPressedOnce = false;
                }
            }, 2000);
        }
    }
}

From source file:org.symptomcheck.capstone.ui.MainActivityOld.java

private void openFragment(Fragment fragment, boolean addToBackStack) {

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

    if (addToBackStack) {
        fragmentTransaction.addToBackStack(null).replace(R.id.content_frame, fragment);
    } else {//from   ww w.  ja v  a2 s.com
        fragmentTransaction.replace(R.id.content_frame, fragment);
    }
    fragmentTransaction.commit();

}

From source file:at.flack.MainActivity.java

private void selectItem(int position) {
    if (position == 0 || getFragmentManager() == null || mDrawerLayout == null || mDrawerList == null)
        return;//from   www  . j  a  v a2s. co  m
    Fragment fragment = null;
    if (position == 7 && !sharedPrefs.getBoolean("in_debug_mode", false))
        position = 8;

    switch (position) {
    case 1: { // SMS Main
        fragment = SMSMainActivity.getInstance();
        current_fragment = 1;
        break;
    }
    case 2: { // Facebook Main
        fragment = FacebookMainActivity.getInstance();
        current_fragment = 2;
        break;
    }
    case 3: { // Mail Main
        fragment = MailMainActivity.getInstance();
        current_fragment = 3;
        break;
    }
    case 4: { // Mail Out
        if (!getSharedPreferences("mail", Context.MODE_PRIVATE).getString("mailaddress", "").equals("")) {
            fragment = MailOutActivity.getInstance();
            current_fragment = 4;
        } else {
            fragment = MailMainActivity.getInstance();
            current_fragment = 3;
        }
        break;
    }
    case 6: { // Settings
        Intent settings = new Intent(MainActivity.this, QuickPrefsActivity.class);
        startActivityForResult(settings, 3);
        fragment = null;
        break;
    }
    case 7: {// Debug
        Intent debug = new Intent(MainActivity.this, DebugActivity.class);
        startActivity(debug);
        break;
    }
    case 8: {// About
        new AlertDialog.Builder(this).setTitle("Version " + VERSION)
                .setMessage("Developed by:\n" + "- Manuel S. Caspari\n" + "- Nicolas Lukaschek \n"
                        + "- Philipp Adam\n\n" + "Graphics by Michael Kroimayr\n\n" + "Used Librarys:\n"
                        + "- Emojicon by Hieu Rocker\n" + "- Floating Action Button by Oleksandr Melnykov\n"
                        + "- Material Design Library by navasmdc\n" + "- Jsoup by Jonathan Hedley\n"
                        + "- Android Mail by Jon Simon\n" + "- ASync HTTP by James Smith\n"
                        + "- Appcompat & Play Services by Google\n" + "- Bouncycastle / Spongycastle\n\n"
                        + "Contact: contact@ravenapp.org\n" + "GNU GPL | 2014 - 2015")
                .setIcon(R.drawable.ic_action_image_wb_incandescent).show();

        break;
    }
    default: {
        return;
    }
    }
    try {
        FragmentManager fragmentManager = getFragmentManager();

        if (fragment != null) {
            fragment.onAttach(this);
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        }
    } catch (Exception e) {
    }

    if (position < 5 && position > 0) {
        mDrawerList.setItemChecked(position, true);
        setWhiteIcon(position);
        setTitle(((NavItemModel) (mDrawerList.getItemAtPosition(position))).getTitle());
    } else {
        mDrawerList.setItemChecked(position, false);
        setAllIconsBlack();
    }

    mDrawerLayout.closeDrawer(mDrawerList);

}

From source file:it.scoppelletti.mobilepower.app.FragmentLayoutController.java

/**
 * Ricostruisce la successione della disposizione dei frammenti nei
 * pannelli./*from   w w  w  . j  a v a2s  .co  m*/
 * 
 * @param  fragmentMgr   Gestore dei frammenti.
 * @param  fragmentQueue Frammenti.
 * @return               Identificatore dell&rsquo;ultimo elemento inserito
 *                       nel back stack.
 */
private int arrangeFragments(FragmentManager fragmentMgr,
        Queue<FragmentLayoutController.FragmentEntry> fragmentQueue) {
    int i;
    int frameCount, tnId, lastTnId;
    FragmentLayoutController.FragmentEntry entry;
    FragmentSupport newFragment, oldFragment;
    FragmentLayoutController.FragmentEntry[] frames;
    FragmentTransaction fragmentTn = null;

    frameCount = 1;
    frames = new FragmentLayoutController.FragmentEntry[myFrameCount];
    Arrays.fill(frames, null);

    lastTnId = -1;
    while (!fragmentQueue.isEmpty()) {
        tnId = -1;
        entry = fragmentQueue.remove();

        try {
            fragmentTn = fragmentMgr.beginTransaction();

            if (frameCount == myFrameCount) {
                // Tutti i pannelli sono occupati:
                // Sposto ogni frammento nel pannello precedente per
                // liberare l'ultimo.
                for (i = 0; i < frameCount; i++) {
                    if (frames[i] == null) {
                        // Inizialmente il primo pannello risulta vuoto
                        // anche se in realta' e' occupato dal frammento
                        // principale (non di dettaglio).
                        continue;
                    }

                    oldFragment = frames[i].getFragment();
                    newFragment = (i > 0) ? oldFragment.cloneFragment() : null;
                    fragmentTn.remove(oldFragment.asFragment());
                    frames[i] = null;

                    if (newFragment != null) {
                        fragmentTn.replace(myFrameIds[i - 1], newFragment.asFragment(), entry.getTag());
                        frames[i - 1] = new FragmentLayoutController.FragmentEntry(newFragment, entry.getTag());
                    }
                }

                frameCount--;
            }

            fragmentTn.add(myFrameIds[frameCount], entry.getFragment().asFragment(), entry.getTag());
            frames[frameCount++] = entry;

            fragmentTn.addToBackStack(null);
        } finally {
            if (fragmentTn != null) {
                tnId = fragmentTn.commit();
                fragmentTn = null;
            }
        }

        if (tnId >= 0) {
            lastTnId = tnId;
        }
    }

    return lastTnId;
}