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.cloudbees.gasp.activity.GaspRESTLoaderActivity.java

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

    // Set main content view for Gasp! Reviews
    setContentView(R.layout.gasp_review_activity);

    // Use the Fragments API to display review data
    FragmentManager fm = getFragmentManager();
    ListFragment list = (ListFragment) fm.findFragmentById(R.id.gasp_review_content);
    if (list == null) {
        list = new ListFragment();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.gasp_review_content, list);
        ft.commit();//from  w  w  w.  j a  v  a  2 s .  c  o  m
    }

    // Array adapter provides access to the review list data
    mAdapter = new ArrayAdapter<String>(this, R.layout.gasp_review_list);
    list.setListAdapter(mAdapter);

    // Load shared preferences from res/xml/preferences.xml (first time only)
    // Subsequent activations will use the saved shared preferences from the device
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    SharedPreferences gaspSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    Log.i(TAG, "Using Gasp Server URI: " + gaspSharedPreferences.getString("gasp_endpoint_uri", ""));
    Uri gaspReviewsUri = Uri.parse(gaspSharedPreferences.getString("gasp_endpoint_uri", ""));

    // Loader arguments: LoaderManager will maintain the state of our Loaders
    // and reload if necessary. 
    Bundle args = new Bundle();
    Bundle params = new Bundle();
    args.putParcelable(ARGS_URI, gaspReviewsUri);
    args.putParcelable(ARGS_PARAMS, params);

    // Initialize the Loader.
    getLoaderManager().initLoader(LOADER_GASP_REVIEWS, args, this);

    // Use gasp-mongo REST service
    new ReviewsRequest().execute();

    try {
        LocationsRequest locations = new LocationsRequest(
                new SpatialQuery(new Location(-122.1139858, 37.3774655), 0.005));

        List<GeoLocation> locationList = locations.execute().get();
        for (GeoLocation geoLocation : locationList) {
            Log.i(TAG, geoLocation.getName());
            Log.i(TAG, " " + geoLocation.getFormattedAddress());
            Log.i(TAG, " " + String.valueOf(geoLocation.getLocation().getLng()));
            Log.i(TAG, " " + String.valueOf(geoLocation.getLocation().getLat()));
        }
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage());
    }
}

From source file:com.royclarkson.springagram.MainActivity.java

private void showPhotoAddFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    String url = this.apiResource.getLink(ApiResource.REL_ITEMS).getHref();
    PhotoAddFragment photoAddFragment = PhotoAddFragment.newInstance(url);
    FragmentTransaction transaction = fragmentManager.beginTransaction().add(R.id.container, photoAddFragment)
            .addToBackStack(null);/*from  w w w .ja  v a  2s. c  om*/
    transaction.commit();
}

From source file:edu.scranton.fisherc5.busybusy.MainActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getFragmentManager();

    if (fragmentManager.findFragmentByTag("PRE_COMPARE") != null) {
        fragmentManager.popBackStack("PRE_COMPARE_PUSH", FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }//from   w  w w. j a va  2s  .c  om

    switch (position) {
    case 0:
        Fragment updateFrag = new UpdateFragment();
        fragmentManager.beginTransaction().replace(R.id.content_frame, updateFrag).commit();
        break;

    case 1:
        Fragment precompareFrag = new PreCompareFragment();
        fragmentManager.beginTransaction().replace(R.id.content_frame, precompareFrag).commit();
        break;

    case 3:
        Fragment updateActivityFrag = new UpdateUserActivityFragment();
        fragmentManager.beginTransaction().replace(R.id.content_frame, updateActivityFrag).commit();
        break;
    }

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

From source file:com.royclarkson.springagram.MainActivity.java

private void showGalleryAddFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    String url = this.apiResource.getLink(ApiResource.REL_GALLERIES).getHref();
    GalleryAddFragment galleryAddFragment = GalleryAddFragment.newInstance(url);
    FragmentTransaction transaction = fragmentManager.beginTransaction().add(R.id.container, galleryAddFragment)
            .addToBackStack(null);// w  ww .j  a  va 2 s .com
    transaction.commit();
}

From source file:com.ternup.caddisfly.fragment.DetailsFragment.java

private void goBack() {
    FragmentManager fm = getFragmentManager();
    try {//from   w w  w.  ja va2s .  c o  m
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
            fm.executePendingTransactions();
        } else {
            Fragment fragment = new HomeFragment();
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction ft = fragmentManager.beginTransaction();
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.replace(R.id.container, fragment, "0");
            ft.addToBackStack(null);
            ft.commit();
            fm.executePendingTransactions();
            ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer);
            drawerList.setItemChecked(0, true);
            drawerList.setSelection(0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:it.gmariotti.cardslib.demo.MainNativeActivity.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  w w  w  . j  ava 2  s.  c o m
    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) == null)
            mBaseFragment = selectFragment(mSelectedFragment);
        //if (mBaseFragment==null)
        //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
        mBaseFragment = new TodoNativeCardFragment();
        openFragment(mBaseFragment);
    }

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

From source file:gl.iglou.scenegraph.MatModeInterface.java

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

    snapshotToast = Toast.makeText(this, "", Toast.LENGTH_LONG);

    LayoutInflater inflater = getLayoutInflater();

    arrow_l = getResources().getDrawable(R.drawable.scene_arrow_l);
    arrow_r = getResources().getDrawable(R.drawable.scene_arrow_r);
    arrowListener = new ArrowClickListener();

    currentSceneId = getIntent().getIntExtra("SCENE_ID", 0);
    SharedData.TYPE current_mode = SharedData.GetMode();

    setContentView(R.layout.scene_activity);

    mainLayout = (RelativeLayout) findViewById(R.id.content_frame);
    buttonGroup = findViewById(R.id.scene_button_frame);
    snapshotContainer = (FrameLayout) findViewById(R.id.scene_snapshot_container);
    //drawerStartId = getIdAssignedByR(this,"outliner_container");
    drawerStartId = R.id.outliner_container;
    drawerEndId = getIdAssignedByR(this, "gl_configurator_container");

    GLView = (GL2JNIView) findViewById(R.id.content_view);

    arrowL = (ImageView) findViewById(R.id.arrow_l);
    arrowR = (ImageView) findViewById(R.id.arrow_r);
    arrowL.setOnClickListener(arrowListener);
    arrowR.setOnClickListener(arrowListener);

    targetButton = (ImageButton) findViewById(R.id.scene_target);
    meshButton = (ImageButton) findViewById(R.id.scene_mesh_mode);
    AABBButton = (ImageButton) findViewById(R.id.scene_AABB_mode);

    selection = (TextView) findViewById(R.id.scene_selection);
    UpdateSelection();/*from  w  ww.  j  av a 2 s. c o  m*/

    mDrawerLayout = (SceneDrawer) findViewById(R.id.drawer_layout);

    mDrawerLayout.setDrawerListener(new MyDrawerListener());
    mDrawerLayout.SetDrawerId(drawerStartId, drawerEndId);

    mDrawerLayout.setScrimColor(0x00ffffff);

    decorView = getWindow().getDecorView();

    outlinerFrag = new SceneOutlinerFragment();
    GLConfFrag = new SceneGLConfiguratorFragment();

    matModeView = inflater.inflate(R.layout.scene_mat_mode, null);
    mainLayout.addView(matModeView);
    if (SharedData.TYPE.MAT == current_mode) {
        //matModeView.setVisibility(View.VISIBLE);
        EnableMatMode(true);
    } else {
        EnableMatMode(false);
        //matModeView.setVisibility(View.INVISIBLE);
    }

    snapShot = inflater.inflate(R.layout.scene_snapshot_frame, null);
    snapshotContainer.addView(snapShot);
    photo = (ImageView) snapShot.findViewById(R.id.snapshot);
    snapshotIndicator = (ProgressBar) snapShot.findViewById(R.id.scene_snapshot_progress_bar);
    snapshotContainer.setVisibility(View.INVISIBLE);
    snapshotIndicator.setVisibility(View.INVISIBLE);

    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(R.id.outliner_container, outlinerFrag);
    ft.commit();

    FragmentTransaction ft0 = fm.beginTransaction();
    ft0.add(R.id.gl_configurator_container, GLConfFrag);
    ft0.commit();
    Log.v(TAG, "Activity ON_CREATE CALL");

}

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

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(com.ffmpeger.card.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(com.ffmpeger.card.R.id.drawer_layout);

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

    _initMenu();//from  ww w  .  j  av a 2s.com
    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(com.ffmpeger.card.R.id.fragment_main) == null)
            mBaseFragment = selectFragment(mSelectedFragment);
        //if (mBaseFragment==null)
        //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
        mBaseFragment = new TodoNativeCardFragment();
        openFragment(mBaseFragment);
    }

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

From source file:com.cliff.comichelper.MainActivity.java

private void selectItem(int position, boolean blank) {
    // update the main content by replacing fragments
    Fragment fragment = new WebViewFragment();
    Bundle args = new Bundle();
    if (blank)//  w  ww  .j  a va 2  s .  co  m
        args.putString(WebViewFragment.ARG_URL, "about:blank");
    else
        args.putString(WebViewFragment.ARG_URL, "http://www.manhua8.com");
    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);
    //      setTitle(mWebsiteNames[position]);
    mDrawerLayout.closeDrawer(mDrawerList);

    currentFragment = (WebViewFragment) fragment;
}

From source file:it.gmariotti.cardslib.demo.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  w ww.java2 s . c o m
    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) == null)
            mBaseFragment = selectFragment(mSelectedFragment);
        //if (mBaseFragment==null)
        //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
        mBaseFragment = new HeaderFragment();
        openFragment(mBaseFragment);
    }

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