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.apchernykh.todo.atleap.sample.ui.MainActivity.java

private static void replaceFragmentIfNeeded(FragmentActivity activity, int containerId,
        Class<? extends Fragment> fragmentClazz) {
    if (activity == null) {
        return;/*  w ww .  j a  v  a  2  s . c  om*/
    }

    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentById(containerId);

    if (fragment == null || !fragmentClazz.isAssignableFrom(fragment.getClass())) {
        try {
            fragment = fragmentClazz.newInstance();

            NavUtil.replaceFragment(activity, containerId, fragment);

        } catch (InstantiationException ex) {
            Ln.e(ex, "Cannot create instance of fragment");
        } catch (IllegalAccessException ex) {
            Ln.e(ex, "Cannot create instance of fragment");
        }
    }
}

From source file:com.github.rutvijkumar.twittfuse.Util.java

public static void onCompose(FragmentActivity activity) {
    FragmentManager fm = activity.getSupportFragmentManager();
    ComposeDialog compose = Util.newInstance(activity);
    Bundle args = new Bundle();
    compose.setArguments(args);/*from  w w  w  .  j  a v  a  2  s .  c om*/
    compose.show(fm, "");

}

From source file:com.mifashow.tool.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}.
 *
 * @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
 */// w ww .  j a  v  a 2  s. com
public static ImageCache findOrCreateCache(final FragmentActivity activity, ImageCacheParams cacheParams) {
    final RetainFragment mRetainFragment = RetainFragment
            .findOrCreateRetainFragment(activity.getSupportFragmentManager());
    ImageCache imageCache = (ImageCache) mRetainFragment.getObject();
    if (imageCache == null) {
        imageCache = new ImageCache(activity, cacheParams);
        mRetainFragment.setObject(imageCache);
    }

    return imageCache;
}

From source file:de.luhmer.owncloudnewsreader.MenuUtilsFragmentActivity.java

public static boolean onOptionsItemSelected(MenuItem item, FragmentActivity activity) {
    switch (item.getItemId()) {
    case R.id.menu_About_Changelog:
        DialogFragment dialog = new VersionInfoDialogFragment();
        dialog.show(activity.getSupportFragmentManager(), "VersionChangelogDialogFragment");
        return true;

    case R.id.menu_markAllAsRead:
        NewsReaderDetailFragment ndf = ((NewsReaderDetailFragment) activity.getSupportFragmentManager()
                .findFragmentById(R.id.content_frame));
        if (ndf != null) {
            DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(activity);
            //dbConn.markAllItemsAsReadForCurrentView();

            for (int i = 0; i < ndf.getListAdapter().getCount(); i++) {
                RssItem rssItem = (RssItem) ndf.getListAdapter().getItem(i);
                rssItem.setRead_temp(true);
                dbConn.updateRssItem(rssItem);
            }// www .java2 s  .c om

            ndf.notifyDataSetChangedOnAdapter();

            //If tablet view is enabled update the listview as well
            if (activity instanceof NewsReaderListActivity)
                ((NewsReaderListActivity) activity).updateAdapter();

        }
        return true;

    case R.id.menu_downloadMoreItems:
        DownloadMoreItems();
        return true;
    }
    return false;
}

From source file:pub.devrel.easygoogle.FragmentUtils.java

/**
 * Check if an Activity already has an instance of a particular Fragment/Tag.  If so, return the
 * existing instance.  If it does not have one, add a new instance and return it.
 * @param activity the FragmentActivity to host the Fragment.
 * @param tag the Fragment tag, should be a unique string for each instance.
 * @param instance an instance of the desired Fragment sub-class, to add if necessary.
 * @param <T> a class that extends Fragment.
 * @return an instance of T which is added to the activity.
 */// w ww  .j  a  v  a  2s  .c om
public static <T extends Fragment> T getOrCreate(FragmentActivity activity, String tag, T instance) {
    // TODO(samstern): I'd like to avoid having to ask for an instance but I'd also like to avoid
    //                 having to create an instance using reflection...

    T result = null;
    boolean shouldAdd = false;

    FragmentManager fm = activity.getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();

    Fragment fragment = fm.findFragmentByTag(tag);
    if (fragment == null) {
        shouldAdd = true;
    } else {
        // TODO(samstern): how to be more confident about this cast?
        Log.d(TAG, "Found fragment instance: " + tag);
        result = (T) fragment;
    }

    if (shouldAdd) {
        Log.d(TAG, "Adding new Fragment: " + tag);

        // Use empty instance
        result = instance;
        ft.add(result, tag).disallowAddToBackStack().commit();
    }

    return result;
}

From source file:eu.inmite.demo.dialogs.FavoriteCharacterDialogFragment.java

public static void show(FragmentActivity activity, String title, String[] items) {
    FavoriteCharacterDialogFragment dialog = new FavoriteCharacterDialogFragment();
    Bundle args = new Bundle();
    args.putString(ARG_TITLE, title);//from www . j a v a2s.  c om
    args.putStringArray(ARG_ITEMS, items);
    dialog.setArguments(args);
    dialog.show(activity.getSupportFragmentManager(), TAG);
}

From source file:com.tony.mushrommstreet.waterfall.ImageCache.java

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();

    // No existing ImageCache, create one and store it in RetainFragment
    if (imageCache == null) {
        imageCache = new ImageCache(activity, cacheParams);
        mRetainFragment.setObject(imageCache);
    }/*from  w  w  w  .java  2 s . com*/

    return imageCache;
}

From source file:com.bingzer.android.eula.EulaFragment.java

public static void showDialog(FragmentActivity fa) {
    boolean accepted = Res.getPreference(getPreferenceName(), false);
    if (!accepted) {
        EulaFragment fragment = (EulaFragment) EulaFragment.instantiate(fa, EulaFragment.class.getName());
        fragment.show(fa.getSupportFragmentManager(), TAG);
    } else {//from w  w  w . j  av  a2s .c o  m
        // go to eula agreed to
        if (fa instanceof OnEulaAgreedTo)
            ((OnEulaAgreedTo) fa).onEulaAgreed();
    }
}

From source file:com.zapp.library.merchant.util.PBBAAppUtils.java

/**
 * Dismiss the Pay by Bank app popup. This method does not have any effect if there is no PBBA popup displayed.
 *
 * @param activity The activity to use./*from w w  w . j  av  a 2  s  . c  o  m*/
 * @return True if the popup was dismissed, false if there was no popup displayed (so there was nothing to dismiss).
 * @see #showPBBAPopup(FragmentActivity, String, String, PBBAPopupCallback)
 * @see #showPBBAErrorPopup(FragmentActivity, String, String, String, PBBAPopupCallback)
 */
@SuppressWarnings({ "BooleanMethodNameMustStartWithQuestion", "ElementOnlyUsedFromTestCode" })
public static boolean dismissPBBAPopup(@NonNull final FragmentActivity activity) {

    verifyActivity(activity);

    final FragmentManager fragmentManager = activity.getSupportFragmentManager();
    final PBBAPopup fragment = (PBBAPopup) fragmentManager.findFragmentByTag(PBBAPopup.TAG);
    if (fragment != null) {
        fragment.dismissWithCallback();
        return true;
    }

    return false;
}

From source file:com.github.rutvijkumar.twittfuse.Util.java

public static void onReply(FragmentActivity activity, HashSet<String> replyScreeName, String replyToTweetId) {
    FragmentManager fm = activity.getSupportFragmentManager();
    ComposeDialog reply = Util.newInstance(activity);
    reply.setReplyTo(replyScreeName, replyToTweetId);
    Bundle args = new Bundle();
    reply.setArguments(args);// ww w  . j a v a  2 s  .c o  m
    reply.show(fm, "");

}