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.microsoft.rightsmanagement.sampleapp.App.java

/**
 * Display message dialog.//  ww w  . j  a v  a2s  .  c o  m
 * 
 * @param message the message
 */
public static void displayMessageDialog(FragmentManager supportedFragmentManager, String message) {
    FragmentTransaction fragmentTransaction = supportedFragmentManager.beginTransaction();
    Fragment previous = supportedFragmentManager.findFragmentByTag(MessageDialogFragment.TAG);
    if (previous != null) {
        fragmentTransaction.remove(previous);
    }
    DialogFragment newFragment = MessageDialogFragment.newInstance(message);
    fragmentTransaction.add(newFragment, MessageDialogFragment.TAG);
    fragmentTransaction.commitAllowingStateLoss();
}

From source file:com.microsoft.rightsmanagement.sampleapp.App.java

/**
 * Display progress dialog./*from   ww  w  . ja  va 2  s  .co m*/
 * 
 * @param message the message
 */
public static void displayProgressDialog(FragmentManager supportedFragmentManager, String message) {
    FragmentTransaction fragmentTransaction = supportedFragmentManager.beginTransaction();
    Fragment previous = supportedFragmentManager.findFragmentByTag(ProgressDialogFragment.TAG);
    if (previous != null) {
        fragmentTransaction.remove(previous);
    }
    DialogFragment newFragment = ProgressDialogFragment.newInstance(message);
    fragmentTransaction.add(newFragment, ProgressDialogFragment.TAG);
    fragmentTransaction.commitAllowingStateLoss();
    sProgressDialogFragment = newFragment;// save
}

From source file:com.grarak.kerneladiutor.utils.ViewUtils.java

public static void showDialog(FragmentManager manager, DialogFragment fragment) {
    FragmentTransaction ft = manager.beginTransaction();
    Fragment prev = manager.findFragmentByTag("dialog");
    if (prev != null) {
        ft.remove(prev);/*from   w  w  w  .j ava2s.  c om*/
    }
    ft.addToBackStack(null);

    fragment.show(ft, "dialog");
}

From source file:com.android.volley.cache.BitmapCache.java

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

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

public static void showDirectoryChooserDialog(FragmentManager fm, ChosenDirectoryListener listener,
        String startFolder) {/*w  w w  .jav a2s  .  c  o m*/
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(TAG);
    if (prev != null) {
        ft.remove(prev);
    }

    try {
        android.support.v4.app.DialogFragment dialog = DirectoryChooserDialog.newInstance(listener,
                startFolder);
        dialog.show(ft, TAG);
    } catch (IllegalArgumentException | IllegalStateException ignored) {
    }
}

From source file:com.dm.wallpaper.board.fragments.dialogs.InAppBillingFragment.java

public static void showInAppBillingDialog(@NonNull FragmentManager fm, BillingProcessor billingProcessor,
        @NonNull String key, @NonNull String[] productId) {
    mBillingProcessor = billingProcessor;
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(TAG);
    if (prev != null) {
        ft.remove(prev);/*  w w w  . ja  v  a2  s  .com*/
    }

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

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

/**
 * Display a dialog which asks if the user wants to add the given show to his show database. If
 * necessary an AsyncTask will be started which takes care of adding the show.
 *///from   w ww.ja  va  2s .co m
public static void showAddDialog(SearchResult show, FragmentManager fm) {
    // 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("dialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    DialogFragment newFragment = AddDialogFragment.newInstance(show);
    newFragment.show(ft, "dialog");
}

From source file:com.dm.material.dashboard.candybar.helpers.RequestHelper.java

public static void prepareIconRequest(@NonNull Context context) {
    new AsyncTask<Void, Void, Boolean>() {

        @Override/*from   w  w  w  .j av  a 2  s  . co  m*/
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    if (context.getResources().getBoolean(R.bool.enable_icon_request)
                            || context.getResources().getBoolean(R.bool.enable_premium_request)) {
                        CandyBarMainActivity.sMissedApps = RequestHelper.loadMissingApps(context);
                    }
                    return true;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            if (aBoolean) {
                if (context == null)
                    return;

                FragmentManager fm = ((AppCompatActivity) context).getSupportFragmentManager();
                if (fm == null)
                    return;

                Fragment fragment = fm.findFragmentByTag("home");
                if (fragment == null)
                    return;

                HomeListener listener = (HomeListener) fragment;
                listener.onHomeDataUpdated(null);
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

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

/**
 * Display a dialog which allows to edit the title of this list or remove
 * it./*www  . j  a va 2s  . c  om*/
 */
public static void showAddListDialog(FragmentManager fm) {
    // 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("addlistdialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    DialogFragment newFragment = AddListDialogFragment.newInstance();
    newFragment.show(ft, "addlistdialog");
}

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 {/*www  .ja v a  2  s. co  m*/
            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);
        }
    }
}