Example usage for android.app FragmentTransaction commit

List of usage examples for android.app FragmentTransaction commit

Introduction

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

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

From source file:com.google.samples.apps.iosched.ui.SessionLivestreamActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_captions:
        if (mIsFullscreen) {
            if (mFullscreenCaptions.getVisibility() == View.GONE) {
                mFullscreenCaptions.setVisibility(View.VISIBLE);
                SessionCaptionsFragment captionsFragment;
                captionsFragment = (SessionCaptionsFragment) getFragmentManager()
                        .findFragmentByTag(TAG_CAPTIONS);
                if (captionsFragment == null) {
                    captionsFragment = new SessionCaptionsFragment();
                    captionsFragment.setDarkTheme(true);
                    FragmentTransaction ft = getFragmentManager().beginTransaction();
                    ft.add(R.id.fullscreen_captions, captionsFragment, TAG_CAPTIONS);
                    ft.commit();
                }/*w w w. ja v a2s .c  om*/
                captionsFragment.updateViews(mCaptionsUrl);
                return true;
            }
        }
        mFullscreenCaptions.setVisibility(View.GONE);
        break;
    case R.id.menu_share:
        if (mSessionShareData != null) {
            new SessionsHelper(this).shareSession(this, R.string.share_livestream_template,
                    mSessionShareData.title, mSessionShareData.hashtag, mSessionShareData.sessionUrl);
            return true;
        }
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.akvo.caddisfly.ui.activity.MainActivity.java

void displayView(int position, boolean addToBackStack) {
    int index = getCurrentFragmentIndex();

    if (index == position) {
        // requested fragment is already showing
        return;//  w  w  w  .jav  a 2  s .c  o m
    }

    MainApp mainApp = (MainApp) getApplicationContext();

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Config.FLOW_ACTION_EXTERNAL_SOURCE.equals(action) && type != null) {
        if ("text/plain".equals(type)) { //NON-NLS
            external = true;
            //mQuestionId = getIntent().getStringExtra("questionId");
            mQuestionTitle = getIntent().getStringExtra("questionTitle");

            String code = mQuestionTitle.substring(Math.max(0, mQuestionTitle.length() - 5));

            mainApp.setSwatches(code);
        }
    }

    if (mainApp.currentTestInfo == null) {
        mainApp.currentTestInfo = new TestInfo("", "", "");
    }

    Fragment fragment;

    switch (position) {
    case Config.HOME_SCREEN_INDEX:
        mStartFragment = StartFragment.newInstance(external, mainApp.currentTestInfo.getCode());
        fragment = mStartFragment;
        break;
    case Config.CALIBRATE_SCREEN_INDEX:
        mCalibrateFragment = new CalibrateFragment();
        fragment = mCalibrateFragment;
        setupActionBarSpinner();

        break;
    case Config.SETTINGS_SCREEN_INDEX:
        if (mSettingsFragment == null) {
            mSettingsFragment = new SettingsFragment();
        }
        fragment = mSettingsFragment;
        break;
    default:
        return;
    }
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(R.id.container, fragment, String.valueOf(position));
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    if (addToBackStack) {
        ft.addToBackStack(null);
    }
    ft.commit();

    invalidateOptionsMenu();
    updateActionBarNavigation(position);
}

From source file:com.dvn.vindecoder.ui.seller.GetAllVehicalSellerDetails.java

@Override
public void onDataComplete(int i, String image_path) {
    if (i == 1) {
        Bitmap bitmap = ((BitmapDrawable) car_image.getDrawable()).getBitmap();
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
        File destination = new File(getCacheDir(), "car.jpg");
        FileOutputStream fo;/*  ww w .  j a  va 2s. com*/
        try {
            fo = new FileOutputStream(destination);
            fo.write(bytes.toByteArray());
            fo.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        image_path = destination.getAbsolutePath();
        // car_image.setImageBitmap(bitmap);
        newFragment.setImagePath(image_path);
    } else if (i == 2) {
        /*car_image.setOnClickListener(null);
        car_image1.setOnClickListener(null);*/
        collapsingToolbarLayout.setVisibility(View.GONE);
        Fragment newFragment = UserAddNewVehicalSecond.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //  ft.addToBackStack(null);
        ft.commit();
    } else if (i == 3) {
        Fragment newFragment = UserAddNewVehicalThird.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        // ft.addToBackStack(null);
        ft.commit();
    } else if (i == 4) {
        Fragment newFragment = UserNewVehicalFourth.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //   ft.addToBackStack(null);
        ft.commit();
    } else if (i == 5) {
        Fragment newFragment = UserAddNewVehicalFifth.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //  ft.addToBackStack(null);
        ft.commit();
    }

    else if (i == 0) {

        Glide.with(GetAllVehicalSellerDetails.this).load(image_path).asBitmap()
                .into(new SimpleTarget<Bitmap>(300, 300) {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
                        //setBackgroundImage(resource);
                        car_image.setImageBitmap(resource);
                        car_image1.setImageBitmap(resource);
                    }
                });
    }
}

From source file:com.google.cloud.solutions.cloudadventure.GameActivity.java

/**
 * This method is called when the Activity receives a message via {@link BroadcastRecevier} that
 * the game has ended./*from ww  w  . j a v  a 2s  .  c om*/
 */
private void onGameEnd() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    mScoresFragment = new GameScoresFragment();
    mScoresFragment.setCurrentUserHandle(mHandle);
    fragmentTransaction.add(R.id.game_activity, mScoresFragment);
    fragmentTransaction.commit();

    new SaveScoresAndSend().execute(mHandle, mGameId, Long.toString(mPlayer.getGemsCollected()),
            Long.toString(mPlayer.getMobsKilled()), Long.toString(mPlayer.getNumDeaths()));
}

From source file:com.kyleszombathy.sms_scheduler.AddMessage.java

/**Set up the fragment view (this is the view that everything is displayed in)*/
private void createFragmentView() {
    AddMessageFragment firstFragment = new AddMessageFragment();
    firstFragment.setArguments(getIntent().getExtras());
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.AddMessage_FragmentContainer, firstFragment);
    transaction.commit();
    Log.d(TAG, "Fragment view created");
}

From source file:com.zte.permissioncontrol.ui.PermissionControlPageActivity.java

protected void addUI() {
    Log.d(TAG, "addUI()");
    // must get a new transaction each time
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    // set empty view to gone
    mEmptyView.setVisibility(View.GONE);
    // add all the fragment
    mPermissionsFragment = (PermissionsFragment) getFragmentManager().findFragmentByTag(mPermissionsTag);
    mAppsFragment = (AppsFragment) getFragmentManager().findFragmentByTag(mAppsTag);

    if (mPermissionsFragment == null) {
        mPermissionsFragment = new PermissionsFragment();
        mAppsFragment = new AppsFragment();
        transaction.add(R.id.tab_pager, mPermissionsFragment, mPermissionsTag);
        transaction.add(R.id.tab_pager, mAppsFragment, mAppsTag);
    }//from   ww  w .j av  a 2 s .  c  om
    transaction.show(mPermissionsFragment);
    transaction.show(mAppsFragment);

    transaction.commit();

    getFragmentManager().executePendingTransactions();
    // firstly remove tabs ,then add tabs and update it
    mActionBarAdapter.removeAllTab();
    mActionBarAdapter.addUpdateTab(mSavedInstanceState);
}

From source file:com.nuvolect.securesuite.main.ContactListActivity.java

private void startContactDetailFragment() {

    if (mTwoPane) {
        ContactDetailFragment frag = new ContactDetailFragment();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.contact_detail_container, frag, CConst.CONTACT_DETAIL_FRAGMENT_TAG);
        ft.commit();
    } else {//from   w  w w. j  a  v a  2s  .  c  o m

        Intent i = new Intent(getApplicationContext(), ContactDetailActivity.class);
        startActivity(i);
    }
}

From source file:com.nuvolect.securesuite.main.ContactListActivity.java

private void startContactEditFragment() {

    if (mTwoPane) {
        ContactEditFragment fragment = new ContactEditFragment();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.contact_detail_container, fragment, CConst.CONTACT_EDIT_FRAGMENT_TAG);
        ft.commit();
    } else {//from  www .j a va2  s.  c om

        Intent i = new Intent(getApplicationContext(), ContactEditActivity.class);
        startActivity(i);
    }
}

From source file:org.symptomcheck.capstone.ui.MainActivityOld.java

@Override
public void onBackPressed() {

    if (mFabActionsMenu.isExpanded()) {
        mFabActionsMenu.collapse();/*from  www  .j a v a 2 s . c o m*/
    } else {
        // initialize variables
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();

        // check to see if stack is empty
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
            ft.commit();
            //            } else {
            //                askForExit();
        } else {
            if (mDoubleBackToExitPressedOnce) {
                super.onBackPressed();
                return;
            }
            this.mDoubleBackToExitPressedOnce = true;
            Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();

            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mDoubleBackToExitPressedOnce = false;
                }
            }, 2000);
        }
    }
}

From source file:cz.metaverse.android.bilingualreader.ReaderActivity.java

/**
 * Detach panel from view.//from  w  w  w. j  av a 2  s .c om
 */
public void detachPanel(SplitPanel p) {
    Log.d(LOG, "ReaderActivity.detachPanel");

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.detach(p);
    fragmentTransaction.commit();

    panelCount--;
}