Example usage for android.app FragmentManager findFragmentByTag

List of usage examples for android.app FragmentManager findFragmentByTag

Introduction

In this page you can find the example usage for android.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.spazedog.lib.taskmanager.Utils.java

@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static IManager buildManager(Object object, Boolean fragment) {
    android.app.FragmentManager fm = fragment ? ((android.app.Fragment) object).getChildFragmentManager()
            : ((android.app.Activity) object).getFragmentManager();

    IManager lManager;/* w  w  w . j av a  2  s . co  m*/

    if ((lManager = ((IManager) fm
            .findFragmentByTag((fragment ? ChildManager.TAG : TaskManager.TAG)))) == null) {
        if (fragment) {
            log("Utils", "buildManager",
                    "Attching a new ChildManager to " + ((android.app.Fragment) object).getClass().getName());

            buildSupportManager(((android.app.Fragment) object).getActivity(), false);

            fm.beginTransaction().add((android.app.Fragment) (lManager = new ChildManager()), ChildManager.TAG)
                    .commit();

        } else {
            log("Utils", "buildManager",
                    "Attching a new TaskManager to " + ((android.app.Activity) object).getClass().getName());

            fm.beginTransaction().add((android.app.Fragment) (lManager = new TaskManager()), TaskManager.TAG)
                    .commit();
        }
    }

    return lManager;
}

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  a v a  2  s.  c  om
    ft.addToBackStack(null);
    new AboutDialog().show(ft, "dialog_about");
}

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  w w.ja va 2  s  . c o m*/
 *
 * @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;
}

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);/*from  w ww . ja  va 2  s  .  c o  m*/
    }
    ft.addToBackStack(null);

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

From source file:it.scoppelletti.mobilepower.app.ProgressDialogFragment.java

/**
 * Chiude un dialogo./*from   w  w w  . jav  a 2s  .c o m*/
 * 
 * @param fragmentMgr Gestore dei frammenti.
 * @param tag         Tag del frammento.
 */
public static void dismiss(FragmentManager fragmentMgr, String tag) {
    ProgressDialogFragment dlg;

    if (StringUtils.isBlank(tag)) {
        throw new NullPointerException("Argument tag is null.");
    }
    if (fragmentMgr == null) {
        return;
    }

    dlg = (ProgressDialogFragment) fragmentMgr.findFragmentByTag(tag);
    if (dlg != null) {
        dlg.dismiss();
    }
}

From source file:it.scoppelletti.mobilepower.app.ProgressDialogFragment.java

/**
 * Imposta la percentuale di avanzamento esposta da un dialogo.
 * /* w  w  w.  j ava2  s  .  com*/
 * @param fragmentMgr Gestore dei frammenti.
 * @param tag         Tag del frammento.
 * @param progress    Percentuale di avanzamento.
 */
public static void setProgress(FragmentManager fragmentMgr, String tag, int progress) {
    ProgressDialogFragment dlg;

    if (StringUtils.isBlank(tag)) {
        throw new NullPointerException("Argument tag is null.");
    }
    if (fragmentMgr == null) {
        return;
    }

    dlg = (ProgressDialogFragment) fragmentMgr.findFragmentByTag(tag);
    if (dlg != null) {
        dlg.setProgress(progress);
    }
}

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

private static void setupOpenSourceInfoPreference(final Activity activity, Preference preference) {
    preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override/*  w w w  .j av a  2s .c o m*/
        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// w ww  .  java 2  s.  co m
        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:com.breadwallet.tools.animation.BRAnimator.java

public static void hideDecoderFragment() {
    try {/*from   w  w w .  j  a v  a  2s  .  c o  m*/
        MainActivity app = MainActivity.app;
        if (app == null)
            return;
        decoderFragmentOn = false;
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                BRAnimator.multiplePressingAvailable = true;
            }
        }, 300);
        final FragmentManager fragmentManager = app.getFragmentManager();
        FragmentDecoder fragmentDecoder = (FragmentDecoder) fragmentManager
                .findFragmentByTag(FragmentDecoder.class.getName());
        if (fragmentDecoder == null)
            return;
        fragmentManager.beginTransaction().setCustomAnimations(R.animator.from_top, R.animator.to_bottom)
                .remove(fragmentDecoder).commit();
        CustomPagerAdapter.adapter.showFragments(true, app);
        app.activityButtonsEnable(true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void hideScanResultFragment() {
    try {/*from   w  w w .ja  v a  2  s.c om*/
        MainActivity app = MainActivity.app;
        if (app == null)
            return;
        CustomPagerAdapter.adapter.showFragments(true, app);
        scanResultFragmentOn = false;
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                multiplePressingAvailable = true;
            }
        }, 300);

        FragmentManager fragmentManager = app.getFragmentManager();
        FragmentScanResult fragmentScanResult = (FragmentScanResult) fragmentManager
                .findFragmentByTag(FragmentScanResult.class.getName());
        if (fragmentScanResult == null)
            return;
        fragmentManager.beginTransaction().setCustomAnimations(R.animator.from_left, R.animator.to_right)
                .remove(fragmentScanResult).commit();
        app.setBurgerButtonImage(BRConstants.BURGER);

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        FragmentScanResult.address = null;
    }
}