List of usage examples for android.app Activity getFragmentManager
@Deprecated
public FragmentManager getFragmentManager()
From source file:Main.java
/** * Get a Fragment// w w w . j a va 2 s.c om * @param activity The Activity using the Fragment * @param resId The ID of the Fragment * @return The Fragment */ public static Fragment getFragment(Activity activity, int resId) { return activity.getFragmentManager().findFragmentById(resId); }
From source file:Main.java
public static void replace(Activity activity, int containerId, Fragment to) { activity.getFragmentManager().beginTransaction().replace(containerId, to).commit(); }
From source file:Main.java
public static void addFragment(Activity activity, int containerViewId, Fragment fragment, String fragmentTag) { activity.getFragmentManager().beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .add(containerViewId, fragment, fragmentTag).disallowAddToBackStack().commit(); }
From source file:Main.java
public static void replaceFragment(Activity activity, int containerViewId, Fragment fragment, String fragmentTag, String backStackTransitionName) { activity.getFragmentManager().beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .replace(containerViewId, fragment, fragmentTag).addToBackStack(backStackTransitionName).commit(); }
From source file:Main.java
public static void removeFragment(Activity activity, Fragment fragment) { if (activity != null) { try {/*from ww w.j a v a 2 s . c om*/ FragmentManager fragmentManager = activity.getFragmentManager(); fragmentManager.executePendingTransactions(); if (fragment.isAdded()) { FragmentTransaction ft = fragmentManager.beginTransaction(); ft.remove(fragment); ft.commitAllowingStateLoss(); fragmentManager.executePendingTransactions(); } } catch (Exception e) { } } }
From source file:xyz.klinker.android.article.ArticleRobolectricSuite.java
public static <T extends android.app.Fragment> T startFragment(T fragment, Class<? extends Activity> activityClass) { Activity activity = Robolectric.buildActivity(activityClass).create().start().get(); android.app.FragmentManager fragmentManager = activity.getFragmentManager(); android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(fragment, null); fragmentTransaction.commit();/*w ww . j a v a 2 s . c o m*/ return fragment; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static boolean isDialogShown(Activity activity) { if (activity instanceof FragmentActivity) { return ((FragmentActivity) activity).getSupportFragmentManager().findFragmentByTag(DIALOG_TAG) != null; } else {//from w ww. ja v a2 s. c o m return activity.getFragmentManager().findFragmentByTag(DIALOG_TAG) != null; } }
From source file:Main.java
private static void waitForFragmentTransaction(final Activity activity) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); activity.runOnUiThread(new Runnable() { @Override//from w w w . j ava 2 s.c o m public void run() { activity.getFragmentManager().executePendingTransactions(); latch.countDown(); } }); latch.await(); }
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);/* ww w. j a va 2 s. c om*/ ft.addToBackStack(null); new AboutDialog().show(ft, "dialog_about"); }
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 w w. j a va 2 s . com*/ } ft.addToBackStack(null); try { ((DialogFragment) clazz.newInstance()).show(ft, tag); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } }