Example usage for android.support.v4.app FragmentManager beginTransaction

List of usage examples for android.support.v4.app FragmentManager beginTransaction

Introduction

In this page you can find the example usage for android.support.v4.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.codeslap.topy.BaseMultiPaneActivity.java

/** {@inheritDoc} */
@Override//w w  w.  j a  va  2  s.  c  o m
public void openActivityOrFragment(final Intent intent) {
    final PackageManager pm = getPackageManager();
    List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo resolveInfo : resolveInfoList) {
        final FragmentReplaceInfo fri = onSubstituteFragmentForActivityLaunch(resolveInfo.activityInfo.name);
        if (fri != null) {
            final Bundle arguments = intentToFragmentArguments(intent);
            final FragmentManager fm = getSupportFragmentManager();

            try {
                Fragment fragment = (Fragment) fri.getFragmentClass().newInstance();
                fragment.setArguments(arguments);

                FragmentTransaction ft = fm.beginTransaction();
                ft.replace(fri.getContainerId(), fragment, fri.getFragmentTag());
                onBeforeCommitReplaceFragment(fm, ft, fragment);
                ft.commit();
            } catch (InstantiationException e) {
                throw new IllegalStateException("Error creating new fragment.", e);
            } catch (IllegalAccessException e) {
                throw new IllegalStateException("Error creating new fragment.", e);
            }
            return;
        }
    }
    super.openActivityOrFragment(intent);
}

From source file:ch.berta.fabio.popularmovies.presentation.ui.fragments.MovieDetailsOnlFragment.java

@Override
public void loadQueryMovieDetailsWorker(int movieDbId) {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment worker = WorkerUtils.findWorker(fragmentManager, QueryMovieDetailsWorker.WORKER_TAG);

    if (worker == null) {
        worker = QueryMovieDetailsWorker.newInstance(movieDbId);
        fragmentManager.beginTransaction().add(worker, QueryMovieDetailsWorker.WORKER_TAG).commit();
    }//from   w  w  w .  j  av a 2 s .  c  o m
}

From source file:com.actionbarsherlock.sample.demos.app.LoaderCursorSupport.java

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

    FragmentManager fm = getSupportFragmentManager();

    // Create the list fragment and add it as our sole content.
    if (fm.findFragmentById(android.R.id.content) == null) {
        CursorLoaderListFragment list = new CursorLoaderListFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit();
    }/*from  w  ww .  j a va 2  s. co  m*/
}

From source file:com.arbol.reegle.MainActivity.java

private void stuffReegle() {
    setContentView(R.layout.main);//w w  w.  ja va  2s  .  c  o  m
    FragmentManager fm = getSupportFragmentManager();
    ReegleStuffFragment reegleStuffFragment = (ReegleStuffFragment) fm
            .findFragmentByTag(ReegleStuffFragment.TAG);
    if (reegleStuffFragment == null) {
        reegleStuffFragment = new ReegleStuffFragment();
        fm.beginTransaction().add(R.id.fragment_container, reegleStuffFragment, ReegleStuffFragment.TAG)
                .commit();
    }
}

From source file:com.beacon.afterui.views.PickFriendsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pick_friends_activity);

    FragmentManager fm = getSupportFragmentManager();

    if (savedInstanceState == null) {
        // First time through, we create our fragment programmatically.
        final Bundle args = getIntent().getExtras();
        friendPickerFragment = new FriendPickerFragment(args);
        fm.beginTransaction().add(R.id.friend_picker_fragment, friendPickerFragment).commit();
    } else {/*from   ww  w  .j a v a2  s  . c o m*/
        // Subsequent times, our fragment is recreated by the framework and already has saved and
        // restored its state, so we don't need to specify args again. (In fact, this might be
        // incorrect if the fragment was modified programmatically since it was created.)
        friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment);
    }

    friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override
        public void onError(PickerFragment<?> fragment, FacebookException error) {
            PickFriendsActivity.this.onError(error);
        }
    });

    friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
        @Override
        public void onDoneButtonClicked(PickerFragment<?> fragment) {
            // We just store our selection in the Application for other activities to look at.
            AfterYouApplication application = (AfterYouApplication) getApplication();
            application.setSelectedUsers(friendPickerFragment.getSelection());

            setResult(RESULT_OK, null);
            finish();
        }
    });
}

From source file:com.cypress.cysmart.GATTDBFragments.GattCharacteristicsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_gatt_list, container, false);
    mApplication = (CySmartApplication) getActivity().getApplication();
    getActivity().getActionBar().setTitle(R.string.gatt_db);
    mgattListView = (ListView) rootView.findViewById(R.id.ListView_gatt_services);
    mTextHeading = (TextView) rootView.findViewById(R.id.txtservices);
    mTextHeading.setText(getString(R.string.gatt_characteristics_heading));
    mBackButton = (ImageView) rootView.findViewById(R.id.imgback);

    // Back button listener
    mBackButton.setOnClickListener(new OnClickListener() {

        @Override/*from   ww  w  .  j  av a  2 s.  c o  m*/
        public void onClick(View v) {
            getActivity().onBackPressed();

        }
    });
    // Getting the GATT characteristics from application
    gattCharacteristics = mApplication.getGattCharacteristics();

    // Getting the selected service from the arguments
    Bundle bundle = this.getArguments();
    if (bundle != null) {
        mGattServiceName = bundle.getString(Constants.GATTDB_SELECTED_SERVICE);
    }
    // Preparing list data
    GattCharacteriscticsListAdapter adapter = new GattCharacteriscticsListAdapter(getActivity(),
            gattCharacteristics);
    if (adapter != null) {
        mgattListView.setAdapter(adapter);
    }

    // List listener
    mgattListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int pos, long arg3) {
            mApplication.setBluetoothgattcharacteristic(gattCharacteristics.get(pos));
            String characteristicuuid = gattCharacteristics.get(pos).getUuid().toString();
            String characteristicsname = GattAttributes.lookup(characteristicuuid, characteristicuuid);

            /**
             * Passing the characteristic details to GattDetailsFragment and
             * adding that fragment to the view
             */
            Bundle bundle = new Bundle();
            bundle.putString(Constants.GATTDB_SELECTED_SERVICE, mGattServiceName);
            bundle.putString(Constants.GATTDB_SELECTED_CHARACTERISTICE, characteristicsname);
            FragmentManager fragmentManager = getFragmentManager();
            GattDetailsFragment gattDetailsfragment = new GattDetailsFragment().create();
            gattDetailsfragment.setArguments(bundle);
            fragmentManager.beginTransaction().add(R.id.container, gattDetailsfragment).addToBackStack(null)
                    .commit();
        }
    });
    setHasOptionsMenu(true);
    return rootView;
}

From source file:com.akop.bach.activity.RibbonedMultiPane.java

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

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(getLayout());/*from  w ww  . j a  v  a 2  s .c  o m*/

    if ((mAccount = (BasicAccount) getIntent().getParcelableExtra("account")) == null && !allowNullAccounts()) {
        if (App.getConfig().logToConsole())
            App.logv("Account is null");

        finish();
        return;
    }

    if (android.os.Build.VERSION.SDK_INT >= 11) {
        new ActionBarHelper().init();
    }

    // this part was under each activity

    if (!initializeParameters()) {
        finish();
        return;
    }

    FragmentManager fm = getSupportFragmentManager();
    Fragment titleFrag;

    FragmentTransaction ft = fm.beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    if ((titleFrag = fm.findFragmentByTag("title")) == null) {
        titleFrag = instantiateTitleFragment();
        ft.replace(R.id.fragment_titles, titleFrag, "title");
    }

    if (isDualPane()) {
        if ((mDetailFragment = fm.findFragmentByTag("details")) == null) {
            if ((mDetailFragment = instantiateDetailFragment()) != null)
                ft.replace(R.id.fragment_details, mDetailFragment, "details");
        } else if (mDetailFragment.isDetached()) {
            ft.attach(mDetailFragment);
        }
    } else {
        Fragment detailFragment;
        if ((detailFragment = fm.findFragmentByTag("details")) != null) {
            ft.detach(detailFragment);
        }
    }

    ft.commit();
}

From source file:com.asksven.betterbatterystats.PermissionsFragmentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // we need a layout to inflate the fragment into

    FragmentManager fm = getSupportFragmentManager();

    // Create the list fragment and add it as our sole content.
    if (fm.findFragmentById(android.R.id.content) == null) {
        PermissionsListFragment list = new PermissionsListFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit();
    }/*  w  w w  . j  av a 2 s  .c  o  m*/
}

From source file:ch.berta.fabio.popularmovies.presentation.ui.activities.MovieGridActivity.java

@Override
public void hideDetailsFragment() {
    final FragmentManager fragmentManager = getSupportFragmentManager();
    final Fragment detailsFragment = fragmentManager.findFragmentByTag(FRAGMENT_TWO_PANE_DETAILS);
    fragmentManager.beginTransaction().remove(detailsFragment)
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit();

    mViewModel.setUserSelectedMovie(false);
}

From source file:ca.ualberta.cmput301w14t08.geochan.activities.MainActivity.java

/**
 * Calls the respective change location method in the fragment.
 * /*from  w w w . j a v  a  2  s  .  c o  m*/
 * @param view
 *            View passed to the activity to check which button was pressed
 */
public void changeLocation(View view) {
    Bundle args = new Bundle();
    if (view.getId() == R.id.location_button) {
        args.putInt("postType", CustomLocationFragment.POST);
    } else if (view.getId() == R.id.edit_location_button) {
        args.putInt("postType", CustomLocationFragment.EDIT);
    }
    CustomLocationFragment frag = new CustomLocationFragment();
    frag.setArguments(args);
    FavouritesFragment favFrag = (FavouritesFragment) getSupportFragmentManager()
            .findFragmentByTag("favouritesFrag");
    if (favFrag != null) {
        //This bit here solves the issue of a crash when changing location
        //in a reply to a comment in a favourited thread.
        FragmentManager childMan = favFrag.getChildFragmentManager();
        childMan.beginTransaction().replace(R.id.container, frag, "customLocFrag").addToBackStack(null)
                .commit();
    } else {
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, frag, "customLocFrag")
                .addToBackStack(null).commit();
        getSupportFragmentManager().executePendingTransactions();
    }
}