Example usage for android.app FragmentManager beginTransaction

List of usage examples for android.app FragmentManager beginTransaction

Introduction

In this page you can find the example usage for android.app FragmentManager beginTransaction.

Prototype

public abstract FragmentTransaction beginTransaction();

Source Link

Document

Start a series of edit operations on the Fragments associated with this FragmentManager.

Usage

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void goToMainActivity(final Fragment fragment) {
    try {/*  w w  w  .  jav  a 2 s . co m*/
        final MainActivity app = MainActivity.app;
        if (app == null)
            return;
        if (fragment != null) {
            app.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    FragmentManager fragmentManager = app.getFragmentManager();
                    fragmentManager.beginTransaction()
                            .setCustomAnimations(R.animator.from_top, R.animator.to_bottom).remove(fragment)
                            .commit();
                    CustomPagerAdapter.adapter.showFragments(true, app);
                    app.activityButtonsEnable(true);
                    app.setBurgerButtonImage(0);
                }
            });

        }
        resetFragmentAnimator();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T extends Fragment> T attach(Activity activity, int containerId, Class<T> fragmentType,
        String tag) {//from   w w  w . ja v a 2 s.c o  m
    if (activity == null) {
        throw new IllegalArgumentException("activity is null");
    }
    if (fragmentType == null) {
        throw new IllegalArgumentException("fragmentType is null");
    }
    if (tag == null) {
        throw new IllegalArgumentException("tag is null");
    }

    T result;

    FragmentManager manager = activity.getFragmentManager();
    Fragment fragment = manager.findFragmentByTag(tag);

    if (fragment == null) {
        try {
            result = fragmentType.newInstance();
        } catch (InstantiationException e) {
            throw new IllegalArgumentException(
                    "fragmentType cannot be instantiated (default constructor is not visible)", e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException(
                    "fragmentType cannot be instantiated (instance could not be created)", e);
        }

        manager.beginTransaction().add(containerId, result, tag).commit();
    } else {
        if (!fragmentType.isInstance(fragment)) {
            throw new IllegalArgumentException("Different fragmentType for tag");
        }

        result = (T) fragment;
    }

    return result;
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void animateScanResultFragment() {
    try {/*from w w w .j  a  v  a 2 s.c  o  m*/
        final MainActivity app = MainActivity.app;
        if (app == null || scanResultFragmentOn)
            return;
        CustomPagerAdapter.adapter.showFragments(false, app);
        scanResultFragmentOn = true;
        InputMethodManager keyboard = (InputMethodManager) app.getSystemService(Context.INPUT_METHOD_SERVICE);

        try {
            keyboard.hideSoftInputFromWindow(
                    CustomPagerAdapter.adapter.mainFragment.addressEditText.getWindowToken(), 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        app.setBurgerButtonImage(BRConstants.BACK);
        //Disabled inspection: <Expected resource type anim>
        final FragmentManager fragmentManager = app.getFragmentManager();
        final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        final FragmentScanResult scanResult = new FragmentScanResult();
        fragmentTransaction.replace(R.id.main_layout, scanResult, FragmentScanResult.class.getName());
        fragmentTransaction.commit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                TranslateAnimation trans = new TranslateAnimation(MainActivity.screenParametersPoint.x, 0, 0,
                        0);
                trans.setDuration(500);
                trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                View view = scanResult.getView();
                if (view != null)
                    view.startAnimation(trans);
            }
        }, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.spazedog.lib.taskmanager.Utils.java

@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static IManager buildManager(Object object, Boolean fragment) {
    android.app.FragmentManager fm = fragment ? ((android.app.Fragment) object).getChildFragmentManager()
            : ((android.app.Activity) object).getFragmentManager();

    IManager lManager;//from ww  w  .jav a  2s . c  om

    if ((lManager = ((IManager) fm
            .findFragmentByTag((fragment ? ChildManager.TAG : TaskManager.TAG)))) == null) {
        if (fragment) {
            log("Utils", "buildManager",
                    "Attching a new ChildManager to " + ((android.app.Fragment) object).getClass().getName());

            buildSupportManager(((android.app.Fragment) object).getActivity(), false);

            fm.beginTransaction().add((android.app.Fragment) (lManager = new ChildManager()), ChildManager.TAG)
                    .commit();

        } else {
            log("Utils", "buildManager",
                    "Attching a new TaskManager to " + ((android.app.Activity) object).getClass().getName());

            fm.beginTransaction().add((android.app.Fragment) (lManager = new TaskManager()), TaskManager.TAG)
                    .commit();
        }
    }

    return lManager;
}

From source file:com.tony.selene.dialog.AbDialogUtil.java

/**
 * ??.//from  ww w . ja  v a 2 s .c om
 * 
 * @param context
 *            the context
 * @param indeterminateDrawable
 *            0
 * @param message
 *            the message
 */
public static AbProgressDialogFragment showProgressDialog(Context context, int indeterminateDrawable,
        String message) {
    FragmentActivity activity = (FragmentActivity) context;
    AbProgressDialogFragment newFragment = AbProgressDialogFragment.newInstance(indeterminateDrawable, message);
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    // 
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    newFragment.show(ft, dialogTag);
    return newFragment;
}

From source file:com.tony.selene.dialog.AbDialogUtil.java

/**
 * ?string?.//from  ww  w.  ja  v a2 s .c  o  m
 * 
 * @param context
 * @param icon
 * @param title
 *            ?
 * @param message
 *            ???
 * @param onClickListener
 *            ?
 */
public static TCAlertDialogFragment showAlertDialog(Context context, int icon, String title, String message,
        TCAlertDialogFragmentOnClickListener onClickListener) {
    FragmentActivity activity = (FragmentActivity) context;
    TCAlertDialogFragment newFragment = TCAlertDialogFragment.newInstance(icon, title, message, null,
            onClickListener);
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    // 
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    newFragment.show(ft, dialogTag);
    return newFragment;
}

From source file:com.tony.selene.dialog.AbDialogUtil.java

/**
 * ??./*from  w w w . j a v a 2 s.  co m*/
 * 
 * @param view
 * @return
 */
public static AbSampleDialogFragment showFullScreenDialog(View view) {
    FragmentActivity activity = (FragmentActivity) view.getContext();
    // Create and show the dialog.
    AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NORMAL,
            android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    newFragment.setContentView(view);
    FragmentManager fm = activity.getFragmentManager();
    android.app.FragmentTransaction ft = fm.beginTransaction();
    // 
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    newFragment.show(fm, dialogTag);
    return newFragment;
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void hideDecoderFragment() {
    try {/*from   ww w . j av a2  s.co  m*/
        MainActivity app = MainActivity.app;
        if (app == null)
            return;
        decoderFragmentOn = false;
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                BRAnimator.multiplePressingAvailable = true;
            }
        }, 300);
        final FragmentManager fragmentManager = app.getFragmentManager();
        FragmentDecoder fragmentDecoder = (FragmentDecoder) fragmentManager
                .findFragmentByTag(FragmentDecoder.class.getName());
        if (fragmentDecoder == null)
            return;
        fragmentManager.beginTransaction().setCustomAnimations(R.animator.from_top, R.animator.to_bottom)
                .remove(fragmentDecoder).commit();
        CustomPagerAdapter.adapter.showFragments(true, app);
        app.activityButtonsEnable(true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void hideScanResultFragment() {
    try {//from w w w . j a v a2s  .c o m
        MainActivity app = MainActivity.app;
        if (app == null)
            return;
        CustomPagerAdapter.adapter.showFragments(true, app);
        scanResultFragmentOn = false;
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                multiplePressingAvailable = true;
            }
        }, 300);

        FragmentManager fragmentManager = app.getFragmentManager();
        FragmentScanResult fragmentScanResult = (FragmentScanResult) fragmentManager
                .findFragmentByTag(FragmentScanResult.class.getName());
        if (fragmentScanResult == null)
            return;
        fragmentManager.beginTransaction().setCustomAnimations(R.animator.from_left, R.animator.to_right)
                .remove(fragmentScanResult).commit();
        app.setBurgerButtonImage(BRConstants.BURGER);

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        FragmentScanResult.address = null;
    }
}

From source file:com.hyphenate.easeui.utils.ImageCache.java

/**
 * Locate an existing instance of this Fragment or if not found, create and
 * add it using FragmentManager./*  ww w  . j  av  a2  s  .  c  o m*/
 *
 * @param fm The FragmentManager manager to use.
 * @return The existing instance of the Fragment or the new instance if just
 * created.
 */
private static RetainFragment findOrCreateRetainFragment(android.support.v4.app.FragmentManager fm) {
    // BEGIN_INCLUDE(find_create_retain_fragment)
    // Check to see if we have retained the worker fragment.
    RetainFragment mRetainFragment = (RetainFragment) fm.findFragmentByTag(TAG);

    // If not retained (or first time running), we need to create and add
    // it.
    if (mRetainFragment == null) {
        mRetainFragment = new RetainFragment();
        fm.beginTransaction().add(mRetainFragment, TAG).commitAllowingStateLoss();
    }

    return mRetainFragment;
    // END_INCLUDE(find_create_retain_fragment)
}