Example usage for android.app FragmentTransaction add

List of usage examples for android.app FragmentTransaction add

Introduction

In this page you can find the example usage for android.app FragmentTransaction add.

Prototype

public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment, String tag);

Source Link

Document

Add a fragment to the activity state.

Usage

From source file:Main.java

public static void addFragmentToLayout(final int containerId, final FragmentManager fragmentManager,
        final Fragment fragment, final String tag) {
    final FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.add(containerId, fragment, tag);
    ft.commit();/*ww  w  .  java  2  s .  co  m*/
}

From source file:Main.java

public static void replaceFragmentToLayout(final int containerId, final FragmentManager fragmentManager,
        final Fragment fragment, final String tag) {
    final FragmentTransaction ft = fragmentManager.beginTransaction();
    final Fragment previousFragment = fragmentManager.findFragmentByTag(tag);
    if (previousFragment != null) {
        ft.remove(previousFragment);/*from  w  w w . j a v a2s . c  o m*/
    }
    ft.add(containerId, fragment, tag);
    ft.commit();
}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void showMenuFragment(Activity app) {
    if (app == null) {
        Log.e(TAG, "showReceiveFragment: app is null");
        return;/* w  w w  .  j  av  a2  s .  c o  m*/
    }
    FragmentTransaction transaction = app.getFragmentManager().beginTransaction();
    transaction.setCustomAnimations(0, 0, 0, R.animator.plain_300);
    transaction.add(android.R.id.content, new FragmentMenu(), FragmentMenu.class.getName());
    transaction.addToBackStack(FragmentMenu.class.getName());
    transaction.commit();

}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void showGreetingsMessage(Activity app) {
    if (app == null) {
        Log.e(TAG, "showGreetingsMessage: app is null");
        return;//from w  w  w. ja va  2s.  c  o  m
    }
    FragmentTransaction transaction = app.getFragmentManager().beginTransaction();
    transaction.setCustomAnimations(0, 0, 0, R.animator.plain_300);
    transaction.add(android.R.id.content, new FragmentGreetings(), FragmentGreetings.class.getName());
    transaction.addToBackStack(FragmentGreetings.class.getName());
    transaction.commit();

}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void showBreadSignal(Activity activity, String title, String iconDescription, int drawableId,
        BROnSignalCompletion completion) {
    fragmentSignal = new FragmentSignal();
    Bundle bundle = new Bundle();
    bundle.putString(FragmentSignal.TITLE, title);
    bundle.putString(FragmentSignal.ICON_DESCRIPTION, iconDescription);
    fragmentSignal.setCompletion(completion);
    bundle.putInt(FragmentSignal.RES_ID, drawableId);
    fragmentSignal.setArguments(bundle);
    FragmentTransaction transaction = activity.getFragmentManager().beginTransaction();
    transaction.setCustomAnimations(R.animator.from_bottom, R.animator.to_bottom, R.animator.from_bottom,
            R.animator.to_bottom);/* w w  w  .j  a  v a  2  s  .c  o m*/
    transaction.add(android.R.id.content, fragmentSignal, fragmentSignal.getClass().getName());
    transaction.addToBackStack(null);
    if (!activity.isDestroyed())
        transaction.commit();
}

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

/**
 * Animate the transition on burgerButton/MenuButton pressed
 *///from   w  ww. ja  v  a  2 s.c o  m
public static void pressMenuButton(final MainActivity context) {
    try {
        if (context == null)
            return;
        ((BreadWalletApp) context.getApplication()).cancelToast();
        final FragmentManager fragmentManager = context.getFragmentManager();
        if (level == 0) {
            if (PLATFORM_ON)
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        HTTPServer.startServer();
                    }
                }).start();
            level++;
            CustomPagerAdapter.adapter.showFragments(false, context);
            context.setBurgerButtonImage(BRConstants.CLOSE);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            FragmentSettingsAll to = (FragmentSettingsAll) fragmentManager
                    .findFragmentByTag(FragmentSettingsAll.class.getName());
            if (to == null)
                to = new FragmentSettingsAll();
            fragmentTransaction.add(R.id.main_layout, to, FragmentSettingsAll.class.getName());
            fragmentTransaction.commit();
            final FragmentSettingsAll finalTo = to;
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    TranslateAnimation trans = new TranslateAnimation(0, 0, 1920, 0);
                    trans.setDuration(500);
                    trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                    View view = finalTo.getView();
                    if (view != null)
                        view.startAnimation(trans);
                }
            }, 1);

            InputMethodManager keyboard = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);

            if (keyboard != null)
                keyboard.hideSoftInputFromWindow(
                        CustomPagerAdapter.adapter.mainFragment.addressEditText.getWindowToken(), 0);
        } else if (level == 1) {
            if (PLATFORM_ON)
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        HTTPServer.stopServer();
                    }
                }).start();

            level--;
            context.setBurgerButtonImage(BRConstants.BURGER);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.setCustomAnimations(R.animator.from_top, R.animator.to_bottom);
            FragmentSettingsAll fragmentSettingsAll = (FragmentSettingsAll) fragmentManager
                    .findFragmentByTag(FragmentSettingsAll.class.getName());
            fragmentTransaction.remove(fragmentSettingsAll);
            fragmentTransaction.commit();
            CustomPagerAdapter.adapter.showFragments(true, context);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.ab.util.AbDialogUtil.java

/**
 * ?????View//from w  ww .j  ava2 s.  c om
 * @param view
 * @return
 */
public static AbSampleDialogFragment showTipsDialog(View view) {
    FragmentActivity activity = (FragmentActivity) view.getContext();
    // Create and show the dialog.
    AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE,
            android.R.style.Theme_Holo_Light);
    newFragment.setContentView(view);

    FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
    //    
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    // ?,content?fragment,Activity  
    ft.add(android.R.id.content, newFragment, mDialogTag).addToBackStack(null).commit();

    return newFragment;
}

From source file:com.samsung.msca.samsungvr.sampleapp.EndPointConfigActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
    mFragmentManager = getFragmentManager();

    setContentView(R.layout.activity_main);

    if (null != savedInstanceState) {
        return;//from   w w w.  ja  v a 2  s. c om
    }

    FragmentTransaction ft = mFragmentManager.beginTransaction();

    ft.add(android.R.id.content, EndPointConfigFragment.newFragment(), EndPointConfigFragment.TAG);
    ft.commitAllowingStateLoss();
}

From source file:android.support.v17.leanback.supportleanbackshowcase.app.media.VideoExampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video_example);

    FragmentTransaction ft1 = getFragmentManager().beginTransaction();
    ft1.replace(R.id.videoFragment, new VideoSurfaceFragment(), VideoSurfaceFragment.TAG);
    ft1.commit();//from  w  w w . j  a v  a  2  s. co  m

    FragmentTransaction ft2 = getFragmentManager().beginTransaction();
    ft2.add(R.id.videoFragment, new VideoConsumptionExampleFragment(), VideoConsumptionExampleFragment.TAG);
    ft2.commit();
}

From source file:com.example.android.leanback.VideoActivityWithDetailedCard.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video_activity_detailed_card);

    if (savedInstanceState == null) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(R.id.videoFragment, new VideoConsumptionWithDetailCardFragment(),
                VideoConsumptionWithDetailCardFragment.TAG);
        ft.commit();// w w  w .  ja v  a 2 s . c om
    }
}