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.battlelancer.seriesguide.ui.dialogs.ListsDialogFragment.java

/**
 * Display a dialog which asks if the user wants to add the given show to one or more lists.
 *
 * @param itemId   TVDb/database id of the item to add
 * @param itemType type of the item to add (show, season or episode)
 *///  w  w  w.  j a  v  a  2s  .co  m
public static void showListsDialog(String itemId, int itemType, FragmentManager fm) {
    if (fm == null) {
        return;
    }

    // DialogFragment.show() will take care of adding the fragment
    // in a transaction. We also want to remove any currently showing
    // dialog, so make our own transaction and take care of that here.
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("listsdialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    DialogFragment newFragment = ListsDialogFragment.newInstance(itemId, itemType);
    newFragment.show(ft, "listsdialog");
}

From source file:com.battlelancer.seriesguide.ui.dialogs.ManageListsDialogFragment.java

/**
 * Display a dialog which asks if the user wants to add the given show to one or more lists.
 *
 * @param itemTvdbId   TVDb id of the item to add
 * @param itemType type of the item to add (show, season or episode)
 *//*from   w  w w.j  av  a2s. c  o  m*/
public static void showListsDialog(int itemTvdbId, int itemType, FragmentManager fm) {
    if (fm == null) {
        return;
    }

    // DialogFragment.show() will take care of adding the fragment
    // in a transaction. We also want to remove any currently showing
    // dialog, so make our own transaction and take care of that here.
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("listsdialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    DialogFragment newFragment = ManageListsDialogFragment.newInstance(itemTvdbId, itemType);
    newFragment.show(ft, "listsdialog");
}

From source file:ca.rmen.android.scrumchatter.meeting.detail.MeetingFragment.java

/**
 * Add a new {@link MeetingFragment} to the given {@link FragmentManager}, for the given meeting.
 *//*w  ww.j a va2 s  . c  om*/
public static void startMeeting(FragmentManager fragmentManager, Meeting meeting) {
    Bundle bundle = new Bundle(1);
    bundle.putLong(Meetings.EXTRA_MEETING_ID, meeting.getId());
    bundle.putSerializable(Meetings.EXTRA_MEETING_STATE, meeting.getState());
    MeetingFragment meetingFragment = new MeetingFragment();
    meetingFragment.setArguments(bundle);
    fragmentManager.beginTransaction().replace(R.id.meeting_fragment_placeholder, meetingFragment).commit();
}

From source file:com.app.blockydemo.ui.fragment.FormulaEditorFragment.java

public static void showFragment(View view, Brick brick, Formula formula) {

    FragmentActivity activity = null;/* ww  w  .  j a  v  a  2s.c om*/
    activity = (FragmentActivity) view.getContext();

    FormulaEditorFragment formulaEditorFragment = (FormulaEditorFragment) activity.getSupportFragmentManager()
            .findFragmentByTag(FORMULA_EDITOR_FRAGMENT_TAG);

    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    FragmentTransaction fragTransaction = fragmentManager.beginTransaction();

    if (formulaEditorFragment == null) {
        formulaEditorFragment = new FormulaEditorFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(BRICK_BUNDLE_ARGUMENT, brick);
        bundle.putSerializable(FORMULA_BUNDLE_ARGUMENT, formula);
        formulaEditorFragment.setArguments(bundle);

        fragTransaction.add(R.id.script_fragment_container, formulaEditorFragment, FORMULA_EDITOR_FRAGMENT_TAG);
        fragTransaction.hide(fragmentManager.findFragmentByTag(ScriptFragment.TAG));
        fragTransaction.show(formulaEditorFragment);
        BottomBar.hideBottomBar(activity);
    } else if (formulaEditorFragment.isHidden()) {
        formulaEditorFragment.updateBrickViewAndFormula(brick, formula);
        fragTransaction.hide(fragmentManager.findFragmentByTag(ScriptFragment.TAG));
        fragTransaction.show(formulaEditorFragment);
        BottomBar.hideBottomBar(activity);
    } else {
        formulaEditorFragment.setInputFormula(formula, SET_FORMULA_ON_SWITCH_EDIT_TEXT);
    }
    fragTransaction.commit();
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.ApptentiveBaseFragment.java

public static void replaceFragment(FragmentManager fragmentManager, int fragmentContainerId, Fragment fragment,
        String tag, String parentFragment, boolean showAnimation, boolean executePendingTransactions) {
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (showAnimation) {
        fragmentTransaction.setCustomAnimations(R.anim.apptentive_slide_right_in,
                R.anim.apptentive_slide_left_out, R.anim.apptentive_slide_left_in,
                R.anim.apptentive_slide_right_out);
    }/*w  ww  . j  av  a2s  . com*/

    fragmentTransaction.replace(fragmentContainerId, fragment, tag);
    if (!TextUtils.isEmpty(parentFragment)) {
        fragmentTransaction.addToBackStack(parentFragment);
    }

    fragmentTransaction.commit();
    if (executePendingTransactions) {
        fragmentManager.executePendingTransactions();
    }

}

From source file:com.alex.utils.FragmentNavigator.java

public static void moveTo(FragmentManager fragmentManager, @IdRes int containerId,
        Class<? extends Fragment> fragment, boolean addToBackStack, Context context, @Nullable Bundle args) {
    final String tag = fragment.getName();
    Fragment current = fragmentManager.findFragmentById(containerId);
    Fragment target = fragmentManager.findFragmentByTag(tag);

    if (target == null) {
        try {//from   www  .j  ava  2 s  . c  om
            target = Fragment.instantiate(context, fragment.getName(), args);
        } catch (Exception e) {
            // ignore
        }
        if (target == null) {
            return;
        }

        FragmentTransaction transaction = fragmentManager.beginTransaction();
        if (current == null) {
            transaction.add(containerId, target, tag);
        } else {
            transaction.replace(containerId, target, tag);
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            if (addToBackStack) {
                transaction.addToBackStack(tag);
            }
        }
        transaction.commit();
    } else {
        if (current == target) {
            return;
        }
        // set result
        Intent intent = new Intent();
        if (args != null) {
            intent.putExtras(args);
        }
        target.onActivityResult(REQUEST_CODE, Activity.RESULT_OK, intent);
        boolean result = fragmentManager.popBackStackImmediate(tag, 0);
        if (!result) {
            fragmentManager.popBackStackImmediate(0, POP_BACK_STACK_INCLUSIVE);
        }
    }
}

From source file:can.yrt.onebusaway.ReportTripProblemFragment.java

static void show(SherlockFragmentActivity activity, ObaArrivalInfo arrival) {
    FragmentManager fm = activity.getSupportFragmentManager();

    Bundle args = new Bundle();
    args.putString(TRIP_ID, arrival.getTripId());
    args.putString(STOP_ID, arrival.getStopId());
    // We don't use the stop name map here...we want the actual stop name.
    args.putString(TRIP_NAME, arrival.getHeadsign());
    args.putLong(TRIP_SERVICE_DATE, arrival.getServiceDate());
    args.putString(TRIP_VEHICLE_ID, arrival.getVehicleId());

    // Create the list fragment and add it as our sole content.
    ReportTripProblemFragment content = new ReportTripProblemFragment();
    content.setArguments(args);/*from  www .j  a  v  a 2 s  . c om*/

    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(android.R.id.content, content);
    ft.addToBackStack(null);
    ft.commit();
}

From source file:com.beacon.afterui.views.gallery.ImageCache.java

/**
 * Locate an existing instance of this Fragment or if not found, create and
 * add it using FragmentManager.//  ww  w.  j a va  2  s. co  m
 * 
 * @param fm
 *            The FragmentManager manager to use.
 * @return The existing instance of the Fragment or the new instance if just
 *         created.
 */
private static RetainFragment findOrCreateRetainFragment(FragmentManager fm) {
    // Check to see if we have retained the worker fragment.
    RetainFragment mRetainFragment = (RetainFragment) fm.findFragmentByTag(TAG);

    // If not retained (or first time running), we need to create and add
    // it.
    if (mRetainFragment == null) {
        mRetainFragment = new RetainFragment();
        fm.beginTransaction().add(mRetainFragment, TAG).commitAllowingStateLoss();
    }

    return mRetainFragment;
}

From source file:android.support.asy.image.ImageCache.java

/**
 * Locate an existing instance of this Fragment or if not found, create and
 * add it using FragmentManager.//from ww  w.j a  v  a 2  s  . co m
 * 
 * @param fm
 *            The FragmentManager manager to use.
 * @return The existing instance of the Fragment or the new instance if just
 *         created.
 */
public static RetainFragment findOrCreateRetainFragment(FragmentManager fm) {
    // Check to see if we have retained the worker fragment.
    RetainFragment mRetainFragment = (RetainFragment) fm.findFragmentByTag(TAG);

    // If not retained (or first time running), we need to create and add
    // it.
    if (mRetainFragment == null) {
        mRetainFragment = new RetainFragment();
        fm.beginTransaction().add(mRetainFragment, TAG).commitAllowingStateLoss();
    }

    return mRetainFragment;
}

From source file:cmu.cconfs.instantMessage.util.ImageCache.java

/**
 * Locate an existing instance of this Fragment or if not found, create and
 * add it using FragmentManager./*from  w  w  w.  ja va2s  . c om*/
 * 
 * @param fm
 *            The FragmentManager manager to use.
 * @return The existing instance of the Fragment or the new instance if just
 *         created.
 */
private static RetainFragment findOrCreateRetainFragment(FragmentManager fm) {
    // BEGIN_INCLUDE(find_create_retain_fragment)
    // Check to see if we have retained the worker fragment.
    RetainFragment mRetainFragment = (RetainFragment) fm.findFragmentByTag(TAG);

    // If not retained (or first time running), we need to create and add
    // it.
    if (mRetainFragment == null) {
        mRetainFragment = new RetainFragment();
        fm.beginTransaction().add(mRetainFragment, TAG).commitAllowingStateLoss();
    }

    return mRetainFragment;
    // END_INCLUDE(find_create_retain_fragment)
}