Example usage for android.support.v4.app FragmentActivity getSupportFragmentManager

List of usage examples for android.support.v4.app FragmentActivity getSupportFragmentManager

Introduction

In this page you can find the example usage for android.support.v4.app FragmentActivity getSupportFragmentManager.

Prototype

public FragmentManager getSupportFragmentManager() 

Source Link

Document

Return the FragmentManager for interacting with fragments associated with this activity.

Usage

From source file:com.yallaya.fragments.FragmentsModule.java

public static FragmentManager getFragmentManager() {
    FragmentActivity act = (FragmentActivity) TiApplication.getAppCurrentActivity();
    FragmentManager fm = act.getSupportFragmentManager();
    return fm;//from  w w  w  .  j av a2  s.  c om
}

From source file:me.onemobile.client.image.ImageCache.java

/**
 * Find and return an existing ImageCache stored in a {@link RetainFragment}
 * , if not found a new one is created using the supplied params and saved
 * to a {@link RetainFragment}./* w  w  w .j  a  va  2 s  . c  o m*/
 * 
 * @param activity
 *            The calling {@link FragmentActivity}
 * @param cacheParams
 *            The cache parameters to use if creating the ImageCache
 * @return An existing retained ImageCache object or a new one if one did
 *         not exist
 */
public static ImageCache findOrCreateCache(final FragmentActivity activity, ImageCacheParams cacheParams) {

    // Search for, or create an instance of the non-UI RetainFragment
    final RetainFragment mRetainFragment = RetainFragment
            .findOrCreateRetainFragment(activity.getSupportFragmentManager());

    ImageCache imageCache = null;
    if (mRetainFragment != null) {
        // See if we already have an ImageCache stored in RetainFragment
        imageCache = (ImageCache) mRetainFragment.getObject();
    }

    // No existing ImageCache, create one and store it in RetainFragment
    if (imageCache == null) {
        imageCache = new ImageCache(activity, cacheParams);
        if (mRetainFragment != null) {
            mRetainFragment.setObject(imageCache);
        }
    }

    return imageCache;
}

From source file:ca.rmen.android.networkmonitor.app.dialog.DialogFragmentFactory.java

/**
 * Show a visible warning dialog fragment with the given title and message, and just one OK button.
 *///from  w  w w  .  j  a  va  2s  .c  o  m
public static void showWarningDialog(FragmentActivity activity, String title, String message) {
    Log.v(TAG, "showInfoDialog");
    Bundle arguments = new Bundle(3);
    arguments.putString(EXTRA_TITLE, title);
    arguments.putString(EXTRA_MESSAGE, message);
    arguments.putInt(EXTRA_ICON_ID, R.drawable.ic_alert);
    InfoDialogFragment result = new InfoDialogFragment();
    result.setArguments(arguments);
    result.show(activity.getSupportFragmentManager(), InfoDialogFragment.class.getSimpleName());
}

From source file:com.dabay6.libraries.androidshared.ui.dialogs.changelog.util.ChangeLogDialogUtils.java

/**
 * Displays the applications change log.
 *
 * @param context {@link Context} used to create the {@link ChangeLogDialogFragment}.
 *///  ww w. j  a  v  a  2s .c o m
public static void displayChangeLogDialogFragment(final FragmentActivity context, final String assetName,
        final String style) {
    if (context.isFinishing()) {
        return;
    }

    final DialogFragment fragment = ChangeLogDialogFragment.newInstance(assetName, style);

    fragment.show(context.getSupportFragmentManager(), "change_log");
}

From source file:dev.drsoran.moloko.util.UIUtils.java

public final static void showDialogFragment(FragmentActivity fragmentActivity, DialogFragment dialogFragment,
        String fragmentTag) {/*from   w  w  w  . j ava  2  s .  co  m*/
    if (!isDialogFragmentAdded(fragmentActivity, fragmentTag))
        dialogFragment.show(fragmentActivity.getSupportFragmentManager(), fragmentTag);
}

From source file:com.yallaya.fragments.FragmentsModule.java

public static void s_popBackStack(String name) {

    if (name.isEmpty()) {
        name = null;// www.  j a v a  2  s.  c  om
    }

    final FragmentActivity act = (FragmentActivity) TiApplication.getAppCurrentActivity();
    final FragmentManager fm = act.getSupportFragmentManager();

    final String tag = name;

    act.runOnUiThread(new Runnable() {
        public void run() {
            try {
                fm.popBackStackImmediate(tag, 1);
            } catch (Exception ex) {
                throw new RuntimeException("popBackStack exception: " + ex.getMessage());
            }
        }
    });

}

From source file:com.ultramegasoft.flavordex2.util.PermissionUtils.java

/**
 * Make a request for external storage permissions from the user if they are not already
 * granted./*from  w  ww  .  ja v  a2 s .  c  om*/
 *
 * @param activity  The Activity making the request
 * @param rationale Rationale for requesting external storage permissions
 * @return Whether we already have external storage permissions
 */
public static boolean checkExternalStoragePerm(@NonNull FragmentActivity activity, int rationale) {
    if (hasExternalStoragePerm(activity)) {
        return true;
    }

    if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
            Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        PermissionDialog.showDialog(activity.getSupportFragmentManager(),
                Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_STORAGE, activity.getString(rationale),
                null);
        getPreferences(activity).edit().putBoolean(PREF_ASKED_STORAGE, true).apply();
    } else {
        requestExternalStoragePerm(activity);
    }

    return false;
}

From source file:com.trovebox.android.app.bitmapfun.util.ImageCache.java

/**
 * Find and return an existing ImageCache stored in a {@link RetainFragment}
 * , if not found a new one is created using the supplied params and saved
 * to a {@link RetainFragment}./*from ww w  .  j ava 2s.  co m*/
 * 
 * @param activity The calling {@link FragmentActivity}
 * @param cacheParams The cache parameters to use if creating the ImageCache
 * @return An existing retained ImageCache object or a new one if one did
 *         not exist
 */
public static ImageCache findOrCreateCache(final FragmentActivity activity, ImageCacheParams cacheParams) {

    // Search for, or create an instance of the non-UI RetainFragment
    final RetainFragment mRetainFragment = RetainFragment
            .findOrCreateRetainFragment(activity.getSupportFragmentManager());

    // See if we already have an ImageCache stored in RetainFragment
    ImageCache imageCache = (ImageCache) mRetainFragment.getObject(cacheParams.uniqueName);

    // No existing ImageCache, create one and store it in RetainFragment
    if (imageCache == null) {
        imageCache = new ImageCache(activity, cacheParams);
        mRetainFragment.setObject(cacheParams.uniqueName, imageCache);
    }

    return imageCache;
}

From source file:net.abcdroid.devfest12.util.HelpUtils.java

public static void maybeShowAddToScheduleTutorial(FragmentActivity activity) {
    if (hasSeenTutorial(activity, "add_to_schedule")) {
        return;/*from   w ww  . j  a v a 2s  .  c o m*/
    }

    // 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.
    FragmentManager fm = activity.getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("dialog_add_to_schedule");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    new AddToScheduleTutorialDialog().show(ft, "dialog_add_to_schedule");
    setSeenTutorial(activity, "add_to_schedule");
}

From source file:com.scvngr.levelup.core.test.TestThreadingUtils.java

/**
 * Saves a {@link Fragment} to instance state, removes it from the activity. Then creates a new
 * one of the same class, restores the instance state, and re-adds it to the activity.
 *
 * @param <T> the type of Fragment
 * @param instrumentation the test {@link Instrumentation}.
 * @param activity the {@link FragmentActivity} to add it to.
 * @param fragment Fragment to remove and re-add.
 * @return the new instance of the input fragment created using the saved/restored state.
 */// w ww.ja v a 2 s. c  o m
@NonNull
public static <T extends Fragment> T saveAndRestoreFragmentStateSync(
        @NonNull final Instrumentation instrumentation, @NonNull final FragmentActivity activity,
        @NonNull final T fragment) {
    final boolean inView = fragment.isInLayout();

    final FragmentManager fm = activity.getSupportFragmentManager();
    final SavedState savedState = fm.saveFragmentInstanceState(fragment);

    @SuppressWarnings("unchecked")
    final T newInstance = (T) Fragment.instantiate(activity, fragment.getClass().getName());
    newInstance.setInitialSavedState(savedState);

    runOnMainSync(instrumentation, activity, new Runnable() {
        @Override
        public void run() {
            fm.beginTransaction().remove(fragment).commit();
        }
    });

    addFragmentInMainSync(instrumentation, activity, newInstance, inView);

    return newInstance;
}