List of usage examples for android.app FragmentTransaction show
public abstract FragmentTransaction show(Fragment fragment);
From source file:com.geecko.QuickLyric.MainActivity.java
private LyricsViewFragment init(FragmentManager fragmentManager, boolean startEmpty) { LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) fragmentManager .findFragmentByTag(LYRICS_FRAGMENT_TAG); if (lyricsViewFragment == null || lyricsViewFragment.isDetached()) lyricsViewFragment = new LyricsViewFragment(); lyricsViewFragment.startEmpty(startEmpty); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.setCustomAnimations(R.animator.slide_in_end, R.animator.slide_out_start, R.animator.slide_in_start, R.animator.slide_out_end); if (!lyricsViewFragment.isAdded()) { fragmentTransaction.add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG); }//from w ww . java 2s . c o m Fragment[] activeFragments = getActiveFragments(); displayedFragment = getDisplayedFragment(activeFragments); for (Fragment fragment : activeFragments) if (fragment != null) { if (fragment != displayedFragment && !fragment.isHidden()) { fragmentTransaction.hide(fragment); fragment.onHiddenChanged(true); } else if (fragment == displayedFragment) fragmentTransaction.show(fragment); } fragmentTransaction.commit(); return lyricsViewFragment; }
From source file:org.iota.wallet.ui.activity.MainActivity.java
/** * Shows a fragment and hides the old one if there was a fragment previously visible *///from w w w. j ava2s .c om private void showFragment(Fragment fragment, boolean addToBackStack, boolean killFragments) { if (fragment == null) { // Do nothing return; } FragmentManager fragmentManager = getFragmentManager(); Fragment currentFragment = fragmentManager.findFragmentByTag(currentFragmentTag); if (currentFragment != null && currentFragment.getClass().getName().equals(fragment.getClass().getName())) { // Fragment already shown, do nothing return; } FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); if (killFragments) { Class[] fragmentsToKill = { AboutFragment.class, GenerateQRCodeFragment.class, NeighborsFragment.class, NodeInfoFragment.class, PasswordLoginFragment.class, QRScannerFragment.class, SeedLoginFragment.class, SettingsFragment.class, TangleExplorerTabFragment.class, NewTransferFragment.class, WalletAddressesFragment.class, WalletTabFragment.class, WalletTransfersFragment.class }; for (Class fragmentClass : fragmentsToKill) { String tag = fragmentClass.getSimpleName(); if (tag.equals(fragment.getClass().getSimpleName())) { continue; } Fragment fragmentToKill = fragmentManager.findFragmentByTag(tag); if (fragmentToKill != null) { fragmentTransaction.remove(fragmentToKill); } } } fragmentTransaction.setCustomAnimations(R.animator.fade_in, R.animator.fade_out, R.animator.fade_in, R.animator.fade_out); if (currentFragment != null) { // Hide old fragment fragmentTransaction.hide(currentFragment); } String tag = fragment.getClass().getSimpleName(); Fragment cachedFragment = fragmentManager.findFragmentByTag(tag); if (cachedFragment != null) { // Cached fragment available fragmentTransaction.show(cachedFragment); } else { fragmentTransaction.add(FRAGMENT_CONTAINER_ID, fragment, tag); } if (addToBackStack) { fragmentTransaction.addToBackStack(null); } fragmentTransaction.commit(); if (fragment instanceof OnBackPressedClickListener) { onBackPressedClickListener = (OnBackPressedClickListener) fragment; } else onBackPressedClickListener = null; // setChecked if open from WalletItemDialog if (fragment instanceof TangleExplorerTabFragment) navigationView.getMenu().findItem(R.id.nav_tangle_explorer).setChecked(true); currentFragmentTag = tag; }
From source file:com.android.dialer.DialtactsFragment.java
/** * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual * updates are handled by a callback which is invoked after the dialpad fragment is shown. * @see #onDialpadShown//w w w . j a va2 s . c o m */ public void showDialpadFragment(boolean animate) { // if (mIsDialpadShown || mStateSaved) { // return; // } if (mIsDialpadShown || mStateSaved || mDialpadFragment == null) { Log.e("showDialpadFragment ", " return; "); return; } mIsDialpadShown = true; animate = false; mDialpadFragment.setAnimate(animate); // mListsFragment.setUserVisibleHint(false); AnalyticsUtil.sendScreenView(mDialpadFragment); final FragmentTransaction ft = getChildFragmentManager().beginTransaction(); //if (mDialpadFragment == null) { //mDialpadFragment = new DialpadFragment(); // ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT); //} else { ft.show(mDialpadFragment); //} // mDialpadFragment.setAnimate(animate); // ft.commit(); // if (animate) { //// mFloatingActionButtonController.scaleOut(); // } else { //// mFloatingActionButtonController.setVisible(false); // maybeEnterSearchUi(); // } if (!isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) { if (getCallLogFragment() == null) { mCalllogList = new CallLogFragment(CallLogQueryHandler.CALL_TYPE_ALL); mCalllogList.setRecyclerViewChangedImpl(mRecyclerViewChangedImpl); ft.add(R.id.dialtacts_frame, mCalllogList, "mCalllogList"); ft.show(mCalllogList); } else { if (mSearchViewShow) mDialpadFragment.showSearchView(); else mDialpadFragment.hideSearchView(); } } ft.commitAllowingStateLoss(); sendMessageToReflushEditerView(); Log.e(TAG, " showDialpadFragment mIsDialpadShown:" + mIsDialpadShown + " mInDialpadSearch:" + mInDialpadSearch + " isDialpadShown() :" + isDialpadShown()); // mListsFragment.getView().animate().alpha(0).withLayer(); }
From source file:com.android.dialer.DialtactsFragment.java
/** * @author bbk wangchunhe/* w ww.j a va2s . com*/ * @Date 2016/07/15 * show CallLogFragment of filterType * @param filterType */ private void showCallLogFragment(int filterType) { final FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); if (mCalllogList != null) { transaction.remove(mCalllogList); } mCalllogList = new CallLogFragment(filterType); transaction.add(R.id.dialtacts_frame, mCalllogList, "mCalllogList"); mCalllogList.setRecyclerViewChangedImpl(mRecyclerViewChangedImpl); transaction.show(mCalllogList); transaction.commitAllowingStateLoss(); }
From source file:com.android.dialer.DialtactsFragment.java
/** *?//from w w w .ja va 2 s . c om **/ private void addCallLogFragmentInList() { final FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); if (getCallLogFragment() == null) { mCalllogList = null; mCalllogList = new CallLogFragment(CallLogQueryHandler.CALL_TYPE_ALL); transaction.add(R.id.dialtacts_frame, mCalllogList, "mCalllogList"); } else { mCalllogList = (CallLogFragment) getCallLogFragment(); } mCalllogList.setRecyclerViewChangedImpl(mRecyclerViewChangedImpl); transaction.show(mCalllogList); transaction.commitAllowingStateLoss(); }
From source file:org.opendatakit.tables.activities.TableDisplayActivity.java
public void showListFragment(boolean createNew) { this.setCurrentFragmentType(ViewFragmentType.LIST); this.updateChildViewVisibility(ViewFragmentType.LIST); // Try to use a passed file name. If one doesn't exist, try to use the // default.// ww w.java2 s . c o m String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras()); if (fileName == null) { SQLiteDatabase db = null; try { db = DatabaseFactory.get().getDatabase(this, getAppName()); fileName = TableUtil.get().getListViewFilename(db, getTableId()); } finally { if (db != null) { db.close(); } } } FragmentManager fragmentManager = this.getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); this.hideAllOtherViewFragments(ViewFragmentType.LIST, fragmentTransaction); ListViewFragment listViewFragment = (ListViewFragment) fragmentManager .findFragmentByTag(Constants.FragmentTags.LIST); if (listViewFragment == null || createNew) { if (listViewFragment == null) { WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] existing list fragment not found"); } else { // remove the old fragment WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] removing old list fragment"); fragmentTransaction.remove(listViewFragment); } listViewFragment = this.createListViewFragment(fileName); fragmentTransaction.add(R.id.activity_table_display_activity_one_pane_content, listViewFragment, Constants.FragmentTags.LIST); } else { WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] existing list fragment found"); fragmentTransaction.show(listViewFragment); } fragmentTransaction.commit(); }
From source file:org.opendatakit.tables.activities.TableDisplayActivity.java
public void showMapFragment(boolean createNew) { this.setCurrentFragmentType(ViewFragmentType.MAP); this.updateChildViewVisibility(ViewFragmentType.MAP); // Set the list view file name. String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras()); if (fileName == null) { SQLiteDatabase db = null;/*from w w w .j a v a 2 s . com*/ try { db = DatabaseFactory.get().getDatabase(this, getAppName()); fileName = TableUtil.get().getMapListViewFilename(db, getTableId()); } finally { if (db != null) { db.close(); } } } FragmentManager fragmentManager = this.getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); this.hideAllOtherViewFragments(ViewFragmentType.MAP, fragmentTransaction); MapListViewFragment mapListViewFragment = (MapListViewFragment) fragmentManager .findFragmentByTag(Constants.FragmentTags.MAP_LIST); TableMapInnerFragment innerMapFragment = (TableMapInnerFragment) fragmentManager .findFragmentByTag(Constants.FragmentTags.MAP_INNER_MAP); if (mapListViewFragment == null || (fileName != null && !fileName.equals(mapListViewFragment.getFileName())) || createNew) { if (mapListViewFragment != null) { // remove the old fragment WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] removing old map list fragment"); fragmentTransaction.remove(mapListViewFragment); } WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] creating new map list fragment"); mapListViewFragment = this.createMapListViewFragment(fileName); fragmentTransaction.add(R.id.map_view_list, mapListViewFragment, Constants.FragmentTags.MAP_LIST); } else { WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] existing map list fragment found"); fragmentTransaction.show(mapListViewFragment); } if (innerMapFragment == null || createNew) { if (innerMapFragment != null) { // remove the old fragment WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] removing old inner map fragment"); fragmentTransaction.remove(innerMapFragment); } WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] creating new inner map fragment"); innerMapFragment = this.createInnerMapFragment(); fragmentTransaction.add(R.id.map_view_inner_map, innerMapFragment, Constants.FragmentTags.MAP_INNER_MAP); innerMapFragment.listener = this; } else { WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] existing inner map fragment found"); innerMapFragment.listener = this; fragmentTransaction.show(innerMapFragment); } fragmentTransaction.commit(); }
From source file:org.opendatakit.tables.activities.TableDisplayActivity.java
/** * Show the spreadsheet fragment.// w ww .j av a2 s. c om * * @param createNew */ public void showSpreadsheetFragment(boolean createNew) { this.setCurrentFragmentType(ViewFragmentType.SPREADSHEET); this.updateChildViewVisibility(ViewFragmentType.SPREADSHEET); FragmentManager fragmentManager = this.getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); // Hide all the other fragments. this.hideAllOtherViewFragments(ViewFragmentType.SPREADSHEET, fragmentTransaction); // Try to retrieve one already there. SpreadsheetFragment spreadsheetFragment = (SpreadsheetFragment) fragmentManager .findFragmentByTag(Constants.FragmentTags.SPREADSHEET); if (spreadsheetFragment == null) { WebLogger.getLogger(getAppName()).d(TAG, "[showSpreadsheetFragment] no existing spreadshseet " + "fragment found"); } else { WebLogger.getLogger(getAppName()).d(TAG, "[showSpreadsheetFragment] existing spreadsheet fragment " + "found"); } WebLogger.getLogger(getAppName()).d(TAG, "[showSpreadsheetFragment] createNew is: " + createNew); if (spreadsheetFragment == null || createNew) { if (spreadsheetFragment != null) { WebLogger.getLogger(getAppName()).d(TAG, "[showSpreadsheetFragment] removing existing fragment"); // Get rid of the existing fragment fragmentTransaction.remove(spreadsheetFragment); } spreadsheetFragment = this.createSpreadsheetFragment(); fragmentTransaction.add(R.id.activity_table_display_activity_one_pane_content, spreadsheetFragment, Constants.FragmentTags.SPREADSHEET); } else { fragmentTransaction.show(spreadsheetFragment); } fragmentTransaction.commit(); }
From source file:org.appspot.apprtc.CallActivity.java
private void toggleCallControlFragmentVisibility() { updateVideoView();//from www . j a v a 2 s . c o m if (!iceConnected || !callFragment.isAdded()) { return; } // Show/hide call control fragment callControlFragmentVisible = !callControlFragmentVisible; FragmentTransaction ft = getFragmentManager().beginTransaction(); if (callControlFragmentVisible) { ft.show(callFragment); ft.show(hudFragment); } else { ft.hide(callFragment); ft.hide(hudFragment); } ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.commit(); }
From source file:com.android.dialer.DialtactsActivity.java
/** * Shows the search fragment/*from w w w .j a v a2s . c om*/ */ private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) { if (mStateSaved || getFragmentManager().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; } if (DEBUG) { Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch); } final FragmentTransaction transaction = getFragmentManager().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) getFragmentManager().findFragmentByTag(tag); if (animate) { transaction.setCustomAnimations(android.R.animator.fade_in, 0); } else { transaction.setTransition(FragmentTransaction.TRANSIT_NONE); } if (fragment == null) { if (smartDialSearch) { fragment = new SmartDialSearchFragment(); } else { fragment = ObjectFactory.newRegularSearchFragment(); 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. hideDialpadFragment(true, false); showFabInSearchUi(); return false; } }); } transaction.add(R.id.dialtacts_frame, fragment, tag); } else { transaction.show(fragment); } // DialtactsActivity will provide the options menu fragment.setHasOptionsMenu(false); fragment.setShowEmptyListForNullQuery(true); if (!smartDialSearch) { fragment.setQueryString(query, false /* delaySelection */); } transaction.commit(); if (animate) { mListsFragment.getView().animate().alpha(0).withLayer(); } mListsFragment.setUserVisibleHint(false); if (smartDialSearch) { Logger.logScreenView(ScreenEvent.SMART_DIAL_SEARCH, this); } else { Logger.logScreenView(ScreenEvent.REGULAR_SEARCH, this); } }