Example usage for android.app FragmentTransaction show

List of usage examples for android.app FragmentTransaction show

Introduction

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

Prototype

public abstract FragmentTransaction show(Fragment fragment);

Source Link

Document

Shows a previously hidden fragment.

Usage

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

public void showDetailFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.DETAIL);
    this.updateChildViewVisibility(ViewFragmentType.DETAIL);
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    this.hideAllOtherViewFragments(ViewFragmentType.DETAIL, fragmentTransaction);
    String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras());
    // Try and use the default.
    if (fileName == null) {
        WebLogger.getLogger(getAppName()).d(TAG, "[showDetailFragment] fileName not found in Intent");
        SQLiteDatabase db = null;//from  w w w.  ja  v a  2  s. c o m
        try {
            db = DatabaseFactory.get().getDatabase(this, getAppName());
            fileName = TableUtil.get().getDetailViewFilename(db, getTableId());
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
    String rowId = IntentUtil.retrieveRowIdFromBundle(this.getIntent().getExtras());
    // Try to retrieve one that already exists.
    DetailViewFragment detailViewFragment = (DetailViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.DETAIL_FRAGMENT);
    if (detailViewFragment == null || createNew) {
        if (detailViewFragment != null) {
            WebLogger.getLogger(getAppName()).d(TAG,
                    "[showDetailViewFragment] removing old detail view fragment");
            fragmentTransaction.remove(detailViewFragment);
        } else {
            WebLogger.getLogger(getAppName()).d(TAG,
                    "[showDetailViewFragment] no existing detail view fragment found");
        }
        detailViewFragment = this.createDetailViewFragment(fileName, rowId);

        fragmentTransaction.add(R.id.activity_table_display_activity_one_pane_content, detailViewFragment,
                Constants.FragmentTags.DETAIL_FRAGMENT);
    } else {
        WebLogger.getLogger(getAppName()).d(TAG,
                "[showDetailViewFragment] existing detail view fragment found");
        fragmentTransaction.show(detailViewFragment);
    }

    fragmentTransaction.commit();
}

From source file:com.android.dialer.DialtactsFragment.java

/**
 * Shows the search fragment/*www .  j a v  a2  s  . c  o  m*/
 */
private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) {
    if (mStateSaved || getChildFragmentManager().isDestroyed()) {
        // Weird race condition where fragment is doing work after the activity is destroyed
        // due to talkback being on (b/10209937). Just return since we can't do any
        // constructive here.
        return;
    }
    mDialpadFragment.showSearchView();

    if (DEBUG) {
        Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
    }

    final FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    if (mInDialpadSearch && mSmartDialSearchFragment != null) {
        transaction.remove(mSmartDialSearchFragment);
    } else if (mInRegularSearch && mRegularSearchFragment != null) {
        transaction.remove(mRegularSearchFragment);
    }

    final String tag;
    if (smartDialSearch) {
        tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
    } else {
        tag = TAG_REGULAR_SEARCH_FRAGMENT;
    }
    mInDialpadSearch = smartDialSearch;
    mInRegularSearch = !smartDialSearch;

    mFloatingActionButtonController.scaleOut();

    SearchFragment fragment = (SearchFragment) getChildFragmentManager().findFragmentByTag(tag);
    if (animate) {
        transaction.setCustomAnimations(android.R.animator.fade_in, 0);
    } else {
        transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
    }
    if (fragment == null) {

        Log.e(TAG, " --- enterSearchUi --- null");
        if (smartDialSearch) {
            fragment = new SmartDialSearchFragment();
            transaction.add(R.id.dialtacts_frame, fragment, tag);
        } else {
            fragment = new RegularSearchFragment();
            fragment.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // Show the FAB when the user touches the lists fragment and the soft
                    // keyboard is hidden.
                    showFabInSearchUi();
                    return false;
                }
            });
        }

    } else {
        transaction.show(fragment);

    }
    // DialtactsFragment will provide the options menu
    fragment.setHasOptionsMenu(false);
    fragment.setShowEmptyListForNullQuery(true);
    fragment.setQueryString(query, false /* delaySelection */);
    transaction.commitAllowingStateLoss();
    //        transaction.commit();

    //        if (animate) {
    //            mListsFragment.getView().animate().alpha(0).withLayer();
    //        }
    //        mListsFragment.setUserVisibleHint(false);
}

From source file:com.xplink.android.carchecklist.CarCheckListActivity.java

public void menuToggle(int motionin, int motionout, int fragment) {

    /*/*from ww  w .ja v  a 2s  . co  m*/
     * final Dialog settingdialog = new Dialog(CarCheckListActivity.this,
     * R.style.backgrounddialog); settingdialog.dismiss();
     */

    new Dialog(CarCheckListActivity.this, R.style.backgrounddialog).dismiss();

    headsetting.setVisibility(ImageView.VISIBLE);
    TranslateAnimation slideoutheadsetting = new TranslateAnimation(0, 0, 0, -468);
    slideoutheadsetting.setDuration(500);
    slideoutheadsetting.setFillAfter(true);
    headsetting.startAnimation(slideoutheadsetting);

    int prefer = getSharedPreferences("mysettings", MODE_PRIVATE).getInt("already", 1);
    if (prefer == 1) {
        getSharedPreferences("mysettings", MODE_PRIVATE).edit().putInt("already", 0).commit();

        FragmentTransaction ft = getFragmentManager().beginTransaction().setCustomAnimations(motionin,
                motionout);
        FragmentManager fm = getFragmentManager();
        Fragment fmTarget = fm.findFragmentById(fragment);
        ft.show(fmTarget);
        ft.commit();
    } else {
        getSharedPreferences("mysettings", MODE_PRIVATE).edit().putInt("already", 1).commit();
        FragmentTransaction ft = getFragmentManager().beginTransaction().setCustomAnimations(motionin,
                motionout);
        FragmentManager fm = getFragmentManager();
        final Fragment fmTarget = fm.findFragmentById(fragment);
        ft.hide(fmTarget);
        ft.commit();
    }
}

From source file:de.anderdonau.spacetrader.Main.java

public void changeFragment(FRAGMENTS fragment) {
    hide_keyboard(this);
    if (fragment == gameState.currentState && currentFragment != null) {
        // Sometimes this seems to be unset. Try to workaround it.
        currentFragment.gameState = gameState;
        if (currentFragment.update()) {
            return;
        }/*from   w  w  w  . j a  v  a2s  .  c o  m*/
    }
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();

    if (fragment == FRAGMENTS.NEW_GAME || fragment == FRAGMENTS.ENCOUNTER) {
        transaction.hide(mNavigationDrawerFragment);
    } else {
        transaction.show(mNavigationDrawerFragment);
    }

    Bundle args = new Bundle();
    args.putSerializable("gamestate", gameState);

    switch (fragment) {
    case AVERAGE_PRICES:
        currentFragment = new FragmentAveragePrices();
        break;
    case BANK:
        currentFragment = new FragmentBank();
        break;
    case BUY_CARGO:
        currentFragment = new FragmentBuyCargo();
        break;
    case BUY_EQUIPMENT:
        currentFragment = new FragmentBuyEquipment();
        break;
    case BUY_NEW_SHIP:
        currentFragment = new FragmentBuyNewShip();
        break;
    case COMMANDER_STATUS:
        currentFragment = new FragmentCommanderStatus();
        break;
    case DUMP:
        currentFragment = new FragmentDumpCargo();
        break;
    case ENCOUNTER:
        currentFragment = new FragmentEncounter();
        break;
    case GALACTIC_CHART:
        currentFragment = new FragmentGalacticChart();
        break;
    case NEW_GAME:
        currentFragment = new FragmentStartNewGame();
        break;
    case OPTIONS:
        currentFragment = new FragmentOptions();
        break;
    case PERSONNEL_ROSTER:
        currentFragment = new FragmentPersonnelRoster();
        break;
    case PLUNDER:
        currentFragment = new FragmentPlunderCargo();
        break;
    case SELL_CARGO:
        currentFragment = new FragmentSellCargo();
        break;
    case SELL_EQUIPMENT:
        currentFragment = new FragmentSellEquipment();
        break;
    case SHIPYARD:
        currentFragment = new FragmentShipyard();
        break;
    case SHIP_INFO:
        currentFragment = new FragmentShipInfo();
        break;
    case SHORTCUTS:
        currentFragment = new FragmentShortcuts();
        break;
    case SHORT_RANGE_CHART:
        currentFragment = new FragmentShortRangeChart();
        break;
    case SYSTEM_INFORMATION:
        currentFragment = new FragmentSystemInformation();
        break;
    case VERY_RARE_CHEAT:
        currentFragment = new FragmentVeryRare();
        break;
    case WARP_SYSTEM_INFORMATION:
        currentFragment = new FragmentWarpSystemInformation();
        break;
    default:
        return;
    }

    currentFragment.setArguments(args);
    transaction.replace(R.id.container, currentFragment);
    transaction.commit();
    gameState.currentState = fragment;

    invalidateOptionsMenu();
}