Example usage for android.support.v4.app FragmentTransaction commit

List of usage examples for android.support.v4.app FragmentTransaction commit

Introduction

In this page you can find the example usage for android.support.v4.app FragmentTransaction commit.

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

From source file:com.ameron32.apps.tapnotes.MainActivity.java

public void changeFragment(Fragment newFragment) {
    final int container = R.id.container;
    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction transaction = fm.beginTransaction();
    final String newTag = newFragment.getClass().getName();

    Fragment fragment = fm.findFragmentByTag(newTag);
    if (fragment == null) {
        fragment = newFragment;//from   ww  w .ja v  a2  s. c  o m
    }

    transaction.replace(container, fragment, newTag);
    transaction.addToBackStack(newTag);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    transaction.commit();
}

From source file:com.chatwing.whitelabel.fragments.ChatMessagesFragment.java

private void hide() {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.hide(this);
    fragmentTransaction.commit();
}

From source file:com.chatwing.whitelabel.fragments.ChatMessagesFragment.java

private void show() {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.show(this);
    fragmentTransaction.commit();
}

From source file:biz.easymenu.easymenung.EasymenuNGActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.main);//from  w ww  . j  ava  2  s.co  m

    emp = new EmPrefs(this);
    rpc = new Emrpc(this);

    try {
        ((ImageView) findViewById(R.id.logoImg))
                .setImageBitmap(BitmapFactory.decodeStream(openFileInput("logo.img")));
    } catch (FileNotFoundException e) {
        Log.e(EasymenuNGActivity.TAG, "Error image file not found: " + e.getMessage());
    }

    this.findViewById(R.id.lblTable).setClickable(true);
    this.findViewById(R.id.lblTable).setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {

            ((TextView) findViewById(R.id.lblTable)).setText("");
            findViewById(R.id.btnMenu).setEnabled(false);
            findViewById(R.id.btnDrinks).setEnabled(false);
            findViewById(R.id.btnWaiter).setEnabled(false);
            findViewById(R.id.btnOrder).setEnabled(false);
            findViewById(R.id.btnBill).setEnabled(false);
            findViewById(R.id.btnConfig).setVisibility(View.GONE);

            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction ft;
            Fragment f = null;
            f = new TableListFragment();
            if (fm.findFragmentByTag("rightfragment") != null) {
                ft = fm.beginTransaction();
                ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
                ft.remove(fm.findFragmentByTag("rightfragment"));
                ft.commit();
            }
            ft = fm.beginTransaction();
            ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
            ft.add(R.id.rightcontent, f, "rightfragment");
            ft.commit();
            return true;
        }

    });

    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft;
    Fragment f = null;
    f = new TableListFragment();
    ft = fm.beginTransaction();
    ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
    ft.add(R.id.rightcontent, f, "rightfragment");
    ft.commit();

}

From source file:com.citrus.sample.UIActivity.java

private void showUI() {
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction()
            .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
            .add(R.id.container, UIActivityFragment.newInstance());
    fragmentTransaction.commit();
}

From source file:com.chintanrathod.fragmenttabbackstack.MainActivity.java

private void initViews() {

    firstStack = new Stack<Fragment>();
    secondStack = new Stack<Fragment>();
    thirdStack = new Stack<Fragment>();

    rbFirst = (RadioButton) findViewById(R.id.rbFirst);
    rbSecond = (RadioButton) findViewById(R.id.rbSecond);
    rbThird = (RadioButton) findViewById(R.id.rbThird);
    radioGroup = (RadioGroup) findViewById(R.id.radioGroup);

    fragmentManager = getSupportFragmentManager();

    FragmentTransaction ft = fragmentManager.beginTransaction();

    // Start default first fragment
    firstListFragment = new FirstListFragment();
    firstListFragment.registerForListener(MainActivity.this);
    setFragmentStartAnimation(ft);//  ww  w  .  j  ava2 s.c  o  m
    ft.add(R.id.container, firstListFragment);
    firstStack.push(firstListFragment);
    ft.commit();

    setListener();

    changeRadioButtonTextColor();
}

From source file:com.awt.supark.LayoutHandler.java

public void pullDown(final MainActivity act) {
    act.animInProgress = true;/*ww w.  j a v a2 s  .  com*/
    act.CarHandler.updateLicense(act);

    // ****** BUTTON AND LAYOUT PULL DOWN ANIMATION
    // Declaring animator
    ValueAnimator animation = ValueAnimator.ofFloat(0f, 1f);

    // Sets the animation properties
    animation.setDuration(act.layoutPullUpDuration);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            act.tableRowTopHalf.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT, value));
            act.btnMap.setAlpha(value);
            act.btnCars.setAlpha(value);
            act.btnStatistics.setAlpha(value);
            act.btnEtc.setAlpha(value);
        }
    });

    animation.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            // Starts layout pull down and fade out animation
            act.otherContent.startAnimation(act.anim_slide_down_fade_out);
            act.anim_slide_down_fade_out.setFillAfter(true);

            // Makes layout invisible
            act.otherContent.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            act.contentLinear.setVisibility(View.VISIBLE);

            // ****** UI ELEMENTS FADE IN ANIMATION ******
            // Declaring animator
            ValueAnimator nextAnimation = ValueAnimator.ofFloat(0.17f, 1f);

            // Sets the animation properties
            nextAnimation.setDuration(act.layoutFadeInDuration);
            nextAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float value = (float) animation.getAnimatedValue();
                    act.contentLinear.setAlpha(value);
                }
            });
            nextAnimation.start();

            act.pullUp = false;
            act.openedLayout = 0;
            act.animInProgress = false;
            FragmentTransaction transaction = act.fragmentManager.beginTransaction();
            transaction.remove(act.fragmentManager.findFragmentById(R.id.otherContent));
            transaction.commit();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    animation.start();
}

From source file:com.actionbarsherlock.plus.SherlockDialogPlusFragment.java

/**
 * Display the dialog, adding the fragment to the given FragmentManager.  This
 * is a convenience for explicitly creating a transaction, adding the
 * fragment to it with the given tag, and committing it.  This does
 * <em>not</em> add the transaction to the back stack.  When the fragment
 * is dismissed, a new transaction will be executed to remove it from
 * the activity./*w ww  .  java  2 s. com*/
 * @param manager The FragmentManager this fragment will be added to.
 * @param tag The tag for this fragment, as per
 * {@link FragmentTransaction#add(Fragment, String) FragmentTransaction.add}.
 */
public void show(FragmentManager manager, String tag) {
    mDismissed = false;
    mShownByMe = true;
    FragmentTransaction ft = manager.beginTransaction();
    ft.add(this, tag);
    ft.commit();
}

From source file:cn.figo.mydemo.ui.activity.VideoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_toggle_ratio) {
        int aspectRatio = mVideoView.toggleAspectRatio();
        String aspectRatioText = MeasureHelper.getAspectRatioText(this, aspectRatio);
        mToastTextView.setText(aspectRatioText);
        mMediaController.showOnce(mToastTextView);
        return true;
    } else if (id == R.id.action_toggle_player) {
        int player = mVideoView.togglePlayer();
        String playerText = IjkVideoView.getPlayerText(this, player);
        mToastTextView.setText(playerText);
        mMediaController.showOnce(mToastTextView);
        return true;
    } else if (id == R.id.action_toggle_render) {
        int render = mVideoView.toggleRender();
        String renderText = IjkVideoView.getRenderText(this, render);
        mToastTextView.setText(renderText);
        mMediaController.showOnce(mToastTextView);
        return true;
    } else if (id == R.id.action_show_info) {
        mVideoView.showMediaInfo();/*from   w  w w  .  ja  va 2s  . co m*/
    } else if (id == R.id.action_show_tracks) {
        if (mDrawerLayout.isDrawerOpen(mRightDrawer)) {
            Fragment f = getSupportFragmentManager().findFragmentById(R.id.right_drawer);
            if (f != null) {
                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.remove(f);
                transaction.commit();
            }
            mDrawerLayout.closeDrawer(mRightDrawer);
        } else {
            Fragment f = TracksFragment.newInstance();
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            transaction.replace(R.id.right_drawer, f);
            transaction.commit();
            mDrawerLayout.openDrawer(mRightDrawer);
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.android.bleserver.MainActivity.java

private void setupFragments() {
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    ScannerFragment scannerFragment = new ScannerFragment();
    // Fragments can't access system services directly, so pass it the BluetoothAdapter
    scannerFragment.setBluetoothAdapter(mBluetoothAdapter);
    transaction.replace(R.id.scanner_fragment_container, scannerFragment);

    AdvertiserFragment advertiserFragment = new AdvertiserFragment();
    transaction.replace(R.id.advertiser_fragment_container, advertiserFragment);

    transaction.commit();
}