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:blackman.matt.infinitebrowser.InfinityBrowser.java

/**
 * Load a board using a variety of logics.
 *//* w  w  w.  j a  v a 2s  .  c  om*/
private void loadUpABoard() {
    // Load preferences for activity
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    Boolean ageAccept = preferences.getBoolean("age_guard_accept", false);

    // Checks if age guard has been accepted
    if (!ageAccept) {
        DialogFragment ageGuardDialog = new AgeGuardDialogFragment();
        ageGuardDialog.show(getFragmentManager(), "ageGuardDialog");

    } else {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        Board newBoard;
        Intent intent = getIntent();
        String defaultBoard = preferences.getString("default_board", "").toLowerCase();

        if (intent.getData() != null || intent.getExtras() != null) {
            newBoard = loadFromIntent(intent);

        } else if (!defaultBoard.equals("")) {
            newBoard = Board.newInstance(defaultBoard);
            mTitle = "/" + defaultBoard.toLowerCase() + "/";

        } else {
            newBoard = getFirstDrawerItem();

        }
        if (newBoard != null) {
            fragmentTransaction.replace(R.id.container, newBoard, mTitle.toString());
            findViewById(R.id.ll_help_add_boards).setVisibility(View.GONE);
            setTitle(mTitle);

        }
        fragmentTransaction.commit();
    }
}

From source file:com.github.cpmproto.categorystepfragment.base.GuidedStepListFragment.java

/**
 * Adds the specified GuidedStepListFragment as content of Activity; no backstack entry is added so
 * the activity will be dismissed when BACK key is pressed.  The method is typically called in
 * Activity.onCreate() when savedInstanceState is null.  When savedInstanceState is not null,
 * the Activity is being restored,  do not call addAsRoot() to duplicate the Fragment restored
 * by FragmentManager.//  ww  w  .j a  v a  2 s  . com
 * {@link #UI_STYLE_ACTIVITY_ROOT} is assigned.
 * <p/>
 * Note: currently fragments added using this method must be created programmatically rather
 * than via XML.
 *
 * @param activity The Activity to be used to insert GuidedStepListFragment.
 * @param fragment The GuidedStepListFragment to be inserted into the fragment stack.
 * @param id       The id of container to add GuidedStepListFragment, can be android.R.id.content.
 * @return The ID returned by the call FragmentTransaction.commit, or -1 there is already
 * GuidedStepListFragment.
 */
public static int addAsRoot(Activity activity, GuidedStepListFragment fragment, int id) {
    // Workaround b/23764120: call getDecorView() to force requestFeature of ActivityTransition.
    activity.getWindow().getDecorView();
    FragmentManager fragmentManager = activity.getFragmentManager();
    if (fragmentManager.findFragmentByTag(TAG_LEAN_BACK_ACTIONS_FRAGMENT) != null) {
        Log.w(TAG, "Fragment is already exists, likely calling "
                + "addAsRoot() when savedInstanceState is not null in Activity.onCreate().");
        return -1;
    }
    FragmentTransaction ft = fragmentManager.beginTransaction();
    fragment.setUiStyle(UI_STYLE_ACTIVITY_ROOT);
    return ft.replace(id, fragment, TAG_LEAN_BACK_ACTIONS_FRAGMENT).commit();
}

From source file:com.jainbooks.activitys.DashboardActivity.java

protected void executePendingTransactions() {
    if (pendingFragment == null) {
        return;/*from   w  w w. j av  a 2  s. c  om*/
    }

    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    fragmentManager.beginTransaction().replace(R.id.content_frame, pendingFragment).commit();

    // update selected item and title, then close the drawer
    setTitle(mFragmentTitlesTitles[pendingPosition]);
    mDrawerLayout.closeDrawer(mDrawerList);
    mDrawerList.smoothScrollToPosition(0);

}

From source file:com.luan.thermospy.android.activities.MainActivity.java

@Override
public void onBoundsSpecified(Boundary bounds) {
    FragmentManager fragmentManager = getFragmentManager();

    fragmentManager.beginTransaction().replace(R.id.container, SetupConfirm.newInstance()).commit();

}

From source file:com.ffmpeger.card.MainNativeActivity.java

private void openDialogFragment(DialogFragment dialogStandardFragment) {
    if (dialogStandardFragment != null) {
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment prev = fm.findFragmentByTag("carddemo_dialog");
        if (prev != null) {
            ft.remove(prev);//from w  w w  .j av a2s . co m
        }
        //ft.addToBackStack(null);

        dialogStandardFragment.show(ft, "carddemo_dialog");
    }
}

From source file:it.gmariotti.cardslib.demo.extras.MainActivity.java

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

    // The attacher should always be created in the Activity's onCreate
    //mPullToRefreshAttacher = PullToRefreshAttacher.get(this);

    // 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_extras);

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

    _initMenu();/*from w ww .  ja va2s  . c om*/
    mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
    mDrawer.setDrawerListener(mDrawerToggle);

    // ---------------------------------------------------------------
    // ...
    String base64EncodedPublicKey = IabUtil.key;

    // compute your public key and store it in base64EncodedPublicKey
    mHelper = new IabHelper(this, base64EncodedPublicKey);
    mHelper.enableDebugLogging(true);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d(TAG, "Problem setting up In-app Billing: " + result);
                return;
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null)
                return;

            // Hooray, IAB is fully set up!
            IabUtil.getInstance().retrieveData(mHelper);
        }
    });
    //-----------------------------------------------------------------
    //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_extras) == null)
            mBaseFragment = selectFragment(mSelectedFragment);
        //if (mBaseFragment==null)
        //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
        mBaseFragment = new PicassoFragment();
        openFragment(mBaseFragment);
    }

    //-----------------------------------------------------------------
}

From source file:com.dogar.geodesic.map.MainActivity.java

private void setGMFragment() {
    if (GMFragment == null) {
        FragmentManager fragmentManager = getFragmentManager();
        GMFragment = new GoogleMapFragment();
        fragmentManager.beginTransaction().replace(R.id.frame_container, GMFragment).commit();
    }/*  w ww  .j a va2s .  co  m*/
}

From source file:com.inde.shiningdays.MainActivity.java

private void selectItem(int position, String orderBy) {
    // update the main content by replacing fragments
    //Fragment fragment = new PlanetFragment();
    //       Intent intent = this.getIntent();
    //       Bundle extras = intent.getExtras();
    //       if(extras != null) {
    //          currentType = extras.getString(CountDown.PRIORITY);
    //       } else {
    //          currentType = mTypes[position];
    //       }/*from ww  w .  jav  a2s  . c  om*/
    if (position == mTypes.length) {
        return;
    }

    currentTypePosition = position;
    currentType = mTypes[position];
    Fragment fragment = new ItemListFragment();
    Bundle args = new Bundle();
    args.putString(CountDown.PRIORITY, currentType);
    args.putString(CountDown.ORDER_BY, orderBy);
    fragment.setArguments(args);

    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    StringBuilder title = new StringBuilder();
    title.append(getResources().getString(R.string.app_name)).append(".").append(currentType);
    setTitle(title.toString());
    mDrawerLayout.closeDrawer(mDrawerLeft);
}

From source file:com.google.android.apps.forscience.whistlepunk.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
    if (menuItem == null) {
        return false;
    }// w w w. java  2s.c o m
    if (menuItem.getGroupId() == R.id.navigation_top) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        Fragment fragment;
        int itemId = menuItem.getItemId();

        final String tag = String.valueOf(itemId);
        fragment = getFragmentManager().findFragmentByTag(tag);
        if (fragment == null) {
            fragment = createNewFragment(itemId);
        }
        adjustActivityForSelectedItem(itemId);

        mTitleToRestore = getTitleToRestore(menuItem);
        transaction.replace(R.id.content_container, fragment, tag).commit();
        if (menuItem.isCheckable()) {
            menuItem.setChecked(true);
        }
        mDrawerLayout.closeDrawers();
        restoreActionBar();
        mSelectedItemId = itemId;
    } else if (menuItem.getGroupId() == R.id.navigation_bottom) {
        mDrawerLayout.closeDrawers();
        // Launch intents
        Intent intent = null;
        int itemId = menuItem.getItemId();

        if (itemId == R.id.navigation_item_website) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.website_url)));
        } else if (itemId == R.id.navigation_item_settings) {
            intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(),
                    SettingsActivity.TYPE_SETTINGS);
        } else if (itemId == R.id.navigation_item_about) {
            intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(), SettingsActivity.TYPE_ABOUT);
        } else if (itemId == R.id.dev_testing_options) {
            intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(),
                    SettingsActivity.TYPE_DEV_OPTIONS);
        } else if (itemId == R.id.navigation_item_feedback) {
            mFeedbackProvider.sendFeedback(new LoggingConsumer<Boolean>(TAG, "Send feedback") {
                @Override
                public void success(Boolean value) {
                    if (!value) {
                        showFeedbackError();
                    }
                }

                @Override
                public void fail(Exception e) {
                    super.fail(e);
                    showFeedbackError();
                }
            });
        }
        if (intent != null) {
            startActivity(intent);
        }
    }

    return false;
}

From source file:com.google.samples.apps.abelana.BaseActivity.java

private void selectItem(int position) {
    FragmentManager fragmentManager = getFragmentManager();

    if (position == NAVDRAWER_ITEM_SETTINGS) {
        Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
        startActivity(intent);/* w ww.  ja  v a 2s  .com*/
    }
    if (position == NAVDRAWER_ITEM_FOLLOWING) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.content_frame, new FriendsFragment()).commit();
    }
    if (position == NAVDRAWER_ITEM_HOME) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.content_frame, new FeedFragment()).commit();
    }
    if (position == NAVDRAWER_ITEM_PROFILE) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.content_frame, new ProfileFragment()).commit();
    }

    //update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mNavItems[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}