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:org.droidparts.inject.injector.FragmentInjector.java

static boolean inject(FragmentActivity activity, InjectFragment ann, Field field) {
    int fragmenId = ann.value();
    if (fragmenId == 0) {
        fragmenId = ResourceUtils.getResourceId(activity, field.getName());
    }/*from ww  w.jav  a2  s .com*/
    if (fragmenId != 0) {
        Fragment fragment = activity.getSupportFragmentManager().findFragmentById(fragmenId);
        try {
            setFieldVal(field, activity, fragment);
            return true;
        } catch (IllegalArgumentException e) {
            // swallow
        }
    }
    return false;
}

From source file:Main.java

/**
 * This method loads fragment in a backstack.
 * //from  www.jav  a2 s .c o  m
 * @param fragmentActivity
 * @param fragmentContainerId
 * @param fragmentClass
 * @param bundle
 * @param tag
 * @return true if loaded successfully, false otherwise
 */
public static boolean loadFragmentInBackstack(FragmentActivity fragmentActivity, int fragmentContainerId,
        Class<? extends Fragment> fragmentClass, Bundle bundle, String tag) {
    // TODO Auto-generated method stub
    boolean status = false;
    try {
        FragmentManager fragmentManager = fragmentActivity.getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out,
                android.R.anim.fade_in, android.R.anim.fade_out);
        Fragment fragment = fragmentClass.newInstance();
        fragment.setArguments(bundle);
        fragmentTransaction.replace(fragmentContainerId, fragment, tag).addToBackStack(null).commit();
        // finish pending transactions
        fragmentManager.executePendingTransactions();
        status = true;
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return status;
}

From source file:com.firebase.ui.auth.util.signincontainer.SaveSmartLock.java

@Nullable
public static SaveSmartLock getInstance(FragmentActivity activity, FlowParameters parameters) {
    SaveSmartLock result;//from  w w  w. j a  va 2  s  . c om

    FragmentManager fm = activity.getSupportFragmentManager();
    Fragment fragment = fm.findFragmentByTag(TAG);
    if (!(fragment instanceof SaveSmartLock)) {
        result = new SaveSmartLock();
        result.setArguments(FragmentHelper.getFlowParamsBundle(parameters));
        try {
            fm.beginTransaction().add(result, TAG).disallowAddToBackStack().commit();
        } catch (IllegalStateException e) {
            Log.e(TAG, "Cannot add fragment", e);
            return null;
        }
    } else {
        result = (SaveSmartLock) fragment;
    }

    return result;
}

From source file:org.melato.android.bookmark.BookmarksActivity.java

public static void addBookmarkDialog(FragmentActivity activity, Bookmark bookmark) {
    FragmentManager fm = activity.getSupportFragmentManager();
    SaveBookmarkHandler name = new SaveBookmarkHandler(activity, bookmark);
    RenameFragment rename = new RenameFragment(name);
    rename.setTitle(R.string.add_bookmark);
    rename.setOk(R.string.save);/*from  w ww.  j a  v  a 2  s .  c  o m*/
    rename.show(fm, "dialog");
}

From source file:com.xxxifan.devbox.core.util.Fragments.java

public static List<Fragment> getFragmentList(FragmentActivity activity) {
    return activity.getSupportFragmentManager().getFragments();
}

From source file:com.xxxifan.devbox.core.util.Fragments.java

public static Fragment getFragment(FragmentActivity activity, String tag) {
    return activity.getSupportFragmentManager().findFragmentByTag(tag);
}

From source file:com.fanchen.aisou.imagefetcher.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
 *///from w  w  w  .  j  av a2  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:jahirfiquitiva.iconshowcase.dialogs.AdviceDialog.java

public static void show(final FragmentActivity context, final Type type) {
    Preferences prefs = new Preferences(context);

    switch (type) {
    case WALLPAPER:
        if (prefs.getWallsDialogDismissed())
            return;
    }//from  w  w  w. j a v  a  2s.  co m

    Fragment frag = context.getSupportFragmentManager().findFragmentByTag(TAG);
    if (frag != null)
        ((AdviceDialog) frag).dismiss();
    AdviceDialog.newInstance(type).show(context.getSupportFragmentManager(), TAG);
}

From source file:com.normalexception.app.rx8club.fragment.FragmentUtils.java

/**
 * Perform a transaction to transition from one fragment to another
 * @param source      The source fragment
 * @param destination   The destination fragment
 * @param replace      If true, perform a replace, if false, add
 * @param backstack      If true, add to backstack
 * @param args         The bundle arguments to add
 *//*from  w w  w  .ja  va 2s .co  m*/
public static void fragmentTransaction(FragmentActivity source, Fragment destination, boolean replace,
        boolean backstack, Bundle args) {
    FragmentTransaction transaction = source.getSupportFragmentManager().beginTransaction();

    if (args != null)
        destination.setArguments(args);

    // Replace whatever is in the fragment_container view with this fragment,
    // and add the transaction to the back stack
    if (replace)
        transaction.replace(R.id.content_frame, destination);
    else
        transaction.add(R.id.content_frame, destination);

    if (backstack)
        transaction.addToBackStack(null);

    // Commit the transaction
    transaction.commit();
}

From source file:com.xxxifan.devbox.core.util.Fragments.java

/**
 * get current visible fragment on container
 *//*  w w w  . j a v a  2 s.  c o m*/
public static Fragment getCurrentFragment(FragmentActivity activity, int containerId) {
    return activity.getSupportFragmentManager().findFragmentById(containerId);
}