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:biz.wiz.android.wallet.ui.MaybeMaintenanceFragment.java

public static void add(final FragmentManager fm) {
    Fragment fragment = fm.findFragmentByTag(FRAGMENT_TAG);
    if (fragment == null) {
        fragment = new MaybeMaintenanceFragment();
        fm.beginTransaction().add(fragment, FRAGMENT_TAG).commit();
    }/*from ww w. jav  a 2  s . c o  m*/
}

From source file:com.github.chenxiaolong.dualbootpatcher.settings.RomSettingsEventCollector.java

public static RomSettingsEventCollector getInstance(FragmentManager fm) {
    RomSettingsEventCollector rsec = (RomSettingsEventCollector) fm.findFragmentByTag(TAG);
    if (rsec == null) {
        rsec = new RomSettingsEventCollector();
        fm.beginTransaction().add(rsec, RomSettingsEventCollector.TAG).commit();
    }/* w  ww .  j av  a  2  s. c o m*/
    return rsec;
}

From source file:com.afollestad.overhear.ui.OverviewScreen.java

@SuppressLint("CommitTransaction")
private static void showAboutDialog(Activity activity) {
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("dialog_about");
    if (prev != null)
        ft.remove(prev);//from w ww  .  j  av  a 2  s.  c o m
    ft.addToBackStack(null);
    new AboutDialog().show(ft, "dialog_about");
}

From source file:cn.edu.wyu.documentviewer.RecentsCreateFragment.java

public static void show(FragmentManager fm) {
    final RecentsCreateFragment fragment = new RecentsCreateFragment();
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_directory, fragment);
    ft.commitAllowingStateLoss();/*from  www .j  a  v a  2s  .c  o m*/
}

From source file:com.achep.activedisplay.DialogHelper.java

private static void showDialog(Activity activity, Class clazz, String tag) {
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(tag);
    if (prev != null) {
        ft.remove(prev);//w w  w.  ja v a2s.  c om
    }
    ft.addToBackStack(null);

    try {
        ((DialogFragment) clazz.newInstance()).show(ft, tag);
    } catch (InstantiationException | IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.readystatesoftware.ghostlog.GhostLogSettingsFragment.java

private static void setupOpenSourceInfoPreference(final Activity activity, Preference preference) {
    preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override// w  ww .  j  a  v a  2s  . com
        public boolean onPreferenceClick(Preference preference) {
            FragmentManager fm = activity.getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            Fragment prev = fm.findFragmentByTag("dialog");
            if (prev != null) {
                ft.remove(prev);
            }
            ft.addToBackStack(null);
            new OpenSourceLicensesDialog().show(ft, "dialog");
            return true;
        }
    });
}

From source file:com.readystatesoftware.ghostlog.GhostLogSettingsFragment.java

private static void setupVersionPref(final Activity activity, Preference preference) {
    preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override/*from   www  .j  a  v a  2 s.  com*/
        public boolean onPreferenceClick(Preference preference) {
            FragmentManager fm = activity.getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            Fragment prev = fm.findFragmentByTag("dialog");
            if (prev != null) {
                ft.remove(prev);
            }
            ft.addToBackStack(null);
            new AboutDialog().show(ft, "dialog");
            return true;
        }
    });
}

From source file:fr.simon.marquis.preferencesmanager.util.Utils.java

public static void displayNoRoot(FragmentManager fm) {
    fm.beginTransaction().add(RootDialog.newInstance(), TAG_ROOT_DIALOG).commitAllowingStateLoss();
}

From source file:org.onepf.opfiab.opfiab_uitest.tests.ui.UnifiedFragmentHelperTest.java

private static Object createFragment(boolean isSupport, Activity activity, Instrumentation instrumentation,
        int color) throws InterruptedException {
    final Object fragment;
    if (isSupport) {
        fragment = SupportTestFragment.getInstance(color);
        final android.support.v4.app.FragmentManager supportFragmentManager = ((FragmentActivity) activity)
                .getSupportFragmentManager();
        supportFragmentManager.beginTransaction()
                .replace(R.id.content, (android.support.v4.app.Fragment) fragment, FRAGMENT_TAG).commit();
        instrumentation.runOnMainSync(new Runnable() {
            @Override//from  w  w w . j  a  va2 s . co m
            public void run() {
                supportFragmentManager.executePendingTransactions();
            }
        });
    } else {
        fragment = TestFragment.getInstance(color);
        final FragmentManager fragmentManager = activity.getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content, (Fragment) fragment, FRAGMENT_TAG).commit();
        instrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                fragmentManager.executePendingTransactions();
            }
        });
    }
    Thread.sleep(WAIT_INIT);
    return fragment;
}

From source file:com.bluepixel.android.sgpool.util.BitmapCache.java

/**
 * Locate an existing instance of this Fragment or if not found, create and
 * add it using FragmentManager./*from  w ww.ja  va2 s  .c om*/
 *
 * @param fm The FragmentManager manager to use.
 * @param fragmentTag The tag of the retained fragment (should be unique for each memory
 *                    cache that needs to be retained).
 * @return The existing instance of the Fragment or the new instance if just
 *         created.
 */
private static RetainFragment getRetainFragment(FragmentManager fm, String fragmentTag) {
    // Check to see if we have retained the worker fragment.
    RetainFragment mRetainFragment = (RetainFragment) fm.findFragmentByTag(fragmentTag);

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

    return mRetainFragment;
}