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

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

Introduction

In this page you can find the example usage for android.support.v4.app FragmentManager findFragmentByTag.

Prototype

public abstract Fragment findFragmentByTag(String tag);

Source Link

Document

Finds a fragment that was identified by the given tag either when inflated from XML or as supplied when added in a transaction.

Usage

From source file:com.maxwen.wallpaper.board.fragments.dialogs.FilterFragment.java

public static void showFilterDialog(FragmentManager fm) {
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(TAG);
    if (prev != null) {
        ft.remove(prev);/*from  w w  w  .ja v  a 2 s .com*/
    }

    try {
        DialogFragment dialog = FilterFragment.newInstance();
        dialog.show(ft, TAG);
    } catch (IllegalArgumentException | IllegalStateException ignored) {
    }
}

From source file:cn.nekocode.rxlifecycle.compact.RxLifecycleCompact.java

public static RxLifecycleCompact bind(@NonNull FragmentManager fragmentManager) {
    BindingV4Fragment fragment = (BindingV4Fragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
    if (fragment == null) {
        fragment = new BindingV4Fragment();

        final FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.add(fragment, FRAGMENT_TAG);
        transaction.commit();//ww w  .  j  av  a 2s .  c  o  m

    } else if (fragment.isDetached()) {
        final FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.attach(fragment);
        transaction.commit();
    }

    return bind(fragment.getLifecycleBehavior());
}

From source file:com.deange.textfaker.utils.FragmentUtils.java

/**
 * Find a Fragment within a given activity, and recaptures the reference
 *
 * @param outFragment the fragment to find
 * @param manager     the support fragment manager of the activity
 * @param fragmentTag the tag associated with the fragment
 *///from  w  ww  .ja  va  2 s  .  c o  m
public static void findFragment(Fragment outFragment, final FragmentManager manager, final String fragmentTag) {
    if (outFragment == null) {
        try {
            outFragment = manager.findFragmentByTag(fragmentTag);
        } catch (final ClassCastException e) {
            Log.e(TAG, "Error attempting to find Fragment with tag: \"" + fragmentTag + "\": " + e.toString());
        }
    }
}

From source file:com.dm.material.dashboard.candybar.fragments.dialog.WallpaperSettingsFragment.java

public static void showWallpaperSettings(FragmentManager fm) {
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(TAG);
    if (prev != null) {
        ft.remove(prev);// w  w w  . jav a2  s. co m
    }

    try {
        DialogFragment dialog = WallpaperSettingsFragment.newInstance();
        dialog.show(ft, TAG);
    } catch (IllegalArgumentException | IllegalStateException ignored) {
    }
}

From source file:com.androidinahurry.utils.DialogUtils.java

public static void showAboutDialog(FragmentActivity activity) {
    FragmentManager fm = activity.getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("about_dialog");
    if (prev != null) {
        ft.remove(prev);// www .j  a va 2 s .  c o m
    }
    ft.addToBackStack(null);

    new HtmlDialogFragment().show(ft, "dialog_licenses");
}

From source file:com.by_syk.lib.nanoiconpack.fragment.RetainedFragment.java

@NonNull
public static RetainedFragment initRetainedFragment(@NonNull FragmentManager fragmentManager,
        @NonNull String tag) {/*www .j a va 2 s.c  om*/
    RetainedFragment fragment = (RetainedFragment) fragmentManager.findFragmentByTag(tag);
    if (fragment == null) {
        fragment = new RetainedFragment();
        fragmentManager.beginTransaction().add(fragment, tag).commit();
    }
    return fragment;
}

From source file:com.artemchep.horario.ui.DialogHelper.java

private static void showDialog(@NonNull AppCompatActivity activity, @NonNull DialogFragment fragment,
        @NonNull String tag) {/*  w  w w. j av a 2  s . c o  m*/
    FragmentManager fm = activity.getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(tag);
    if (prev != null)
        ft.remove(prev);
    ft.addToBackStack(null);
    fragment.show(ft, tag);
}

From source file:com.github.fi3te.iliasdownloader.view.Eula.java

public static void show(AppCompatActivity activity) {
    PackageInfo versionInfo = getPackageInfo(activity);
    final String eulaKey = EULA_PREFIX + versionInfo.versionCode;
    final SharedPreferences preferences = PreferencesUtil.getPreferences(activity);

    boolean hasBeenShown = preferences.getBoolean(eulaKey, false);
    if (hasBeenShown == false) {
        FragmentManager fm = activity.getSupportFragmentManager();
        Fragment f = fm.findFragmentByTag(EULA_FFRAGMENT_TAG);
        if (f == null) {
            Fragment eulaFragment = new Eula();
            fm.beginTransaction().add(eulaFragment, EULA_FFRAGMENT_TAG).commit();
            fm.executePendingTransactions();
        }//  ww w.j a  v a2s . c o m
    }
}

From source file:au.com.museumvictoria.fieldguide.bunurong.util.RetainFragment.java

/**
 * Locate an existing instance of this Fragment or if not found, create and
 * add it using FragmentManager./*w  w w. j av 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).commit();
    }

    return mRetainFragment;
}

From source file:com.baseproject.image.RetainFragment.java

/**
 * Locate an existing instance of this Fragment or if not found, create and
 * add it using FragmentManager./*w ww .  j  a  va 2  s  .  c  o 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).commit();
    }

    return mRetainFragment;
}