Java Code Examples for android.app.FragmentTransaction#show()

The following examples show how to use android.app.FragmentTransaction#show() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallActivity.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
private void toggleCallControlFragmentVisibility() {
    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();
}
 
Example 2
Source File: SupportActivity.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 用Fragment替换视图
 *
 * @param resView        将要被替换掉的视图
 * @param targetFragment 用来替换的Fragment
 */
public void changeFragment(int resView, KJFragment targetFragment) {
    if (targetFragment.equals(currentKJFragment)) {
        return;
    }
    FragmentTransaction transaction = getFragmentManager()
            .beginTransaction();
    if (!targetFragment.isAdded()) {
        transaction.add(resView, targetFragment, targetFragment.getClass()
                .getName());
    }
    if (targetFragment.isHidden()) {
        transaction.show(targetFragment);
        targetFragment.onChange();
    }
    if (currentKJFragment != null && currentKJFragment.isVisible()) {
        transaction.hide(currentKJFragment);
    }
    currentKJFragment = targetFragment;
    transaction.commit();
}
 
Example 3
Source File: KJActivity.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 用Fragment替换视图
 *
 * @param resView        将要被替换掉的视图
 * @param targetFragment 用来替换的Fragment
 */
public void changeFragment(int resView, KJFragment targetFragment) {
    if (targetFragment.equals(currentKJFragment)) {
        return;
    }
    FragmentTransaction transaction = getFragmentManager()
            .beginTransaction();
    if (!targetFragment.isAdded()) {
        transaction.add(resView, targetFragment, targetFragment.getClass()
                .getName());
    }
    if (targetFragment.isHidden()) {
        transaction.show(targetFragment);
        targetFragment.onChange();
    }
    if (currentKJFragment != null && currentKJFragment.isVisible()) {
        transaction.hide(currentKJFragment);
    }
    currentKJFragment = targetFragment;
    transaction.commit();
}
 
Example 4
Source File: MainActivity.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
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);
    }

    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;
}
 
Example 5
Source File: MainActivity.java    From BlackLight with GNU General Public License v3.0 6 votes vote down vote up
private void switchTo(int id) {
	FragmentTransaction ft = mManager.beginTransaction();
	ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out, android.R.animator.fade_in, android.R.animator.fade_out);
	
	for (int i = 0; i < mFragments.length; i++) {
		Fragment f = mFragments[i];
		
		if (f != null) {
			if (i != id) {
				ft.hide(f);
			} else {
				ft.show(f);
			}
		}
	}
	
	ft.commit();
}
 
Example 6
Source File: FragmentMenu.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
void updateFragmentVisibility() {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    if (mCheckBox1.isChecked()) ft.show(mFragment1);
    else ft.hide(mFragment1);
    if (mCheckBox2.isChecked()) ft.show(mFragment2);
    else ft.hide(mFragment2);
    ft.commit();
}
 
Example 7
Source File: MainActivity.java    From MBEStyle with GNU General Public License v3.0 5 votes vote down vote up
private void switchFragment(int index) {
    if (index == mCurrentIndex) return;

    Fragment fragment = mFragments.get(index);
    FragmentTransaction transaction =
            mFragmentManager
                    .beginTransaction()
                    .setCustomAnimations(R.animator.fragment_in, R.animator.fragment_out);

    String indexString = String.valueOf(index);
    Fragment targetFragment = mFragmentManager.findFragmentByTag(indexString);

    if (mCurrentIndex != -1) {
        // 不是首次启动
        transaction.hide(mFragments.get(mCurrentIndex));
    }

    if (targetFragment == null) {
        // 之前没有添加过
        transaction.add(R.id.fl_content, fragment, indexString);
    } else {
        transaction.show(targetFragment);
    }

    transaction.commit();
    mCurrentIndex = index;
}
 
Example 8
Source File: GilgaMeshActivity.java    From gilgamesh with GNU General Public License v3.0 5 votes vote down vote up
private void showInfo ()
{
 FragmentManager fm = getFragmentManager();
 FragmentTransaction ft = fm.beginTransaction();
 ft.hide(fm.findFragmentById(R.id.status_list));
 ft.show(fm.findFragmentById(R.id.info_screen));
 ft.hide(fm.findFragmentById(R.id.device_list));
 
  ft.commit();
}
 
Example 9
Source File: GilgaMeshActivity.java    From gilgamesh with GNU General Public License v3.0 5 votes vote down vote up
private void showNearby ()
{
 FragmentManager fm = getFragmentManager();
 FragmentTransaction ft = fm.beginTransaction();
 ft.hide(fm.findFragmentById(R.id.status_list));
 ft.hide(fm.findFragmentById(R.id.info_screen));
 ft.show(fm.findFragmentById(R.id.device_list));
 
  ft.commit();
}
 
Example 10
Source File: GilgaMeshActivity.java    From gilgamesh with GNU General Public License v3.0 5 votes vote down vote up
private void showStatus ()
{
FragmentManager fm = getFragmentManager();
 FragmentTransaction ft = fm.beginTransaction();
 ft.show(fm.findFragmentById(R.id.status_list));
 ft.hide(fm.findFragmentById(R.id.device_list));
 ft.hide(fm.findFragmentById(R.id.info_screen));

  ft.commit();
}
 
Example 11
Source File: Utilities.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
private static
void switchToFragment(Fragment fragment, boolean addToBackStack)
{
    if(fragment.isHidden())
    {
        Fragment[] fragments = {
                s_fragmentFavourites, s_fragmentManage, s_fragmentFeeds, s_fragmentSettings
        };
        FragmentTransaction transaction = s_fragmentManager.beginTransaction();

        for(Fragment frag : fragments)
        {
            if(frag.isVisible())
            {
                transaction.hide(frag);
            }
        }
        transaction.show(fragment);
        if(addToBackStack)
        {
            transaction.addToBackStack(null);

            // Set the default transition for adding to the stack.
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        }
        transaction.commit();
        s_fragmentManager.executePendingTransactions();
        fragment.getActivity().invalidateOptionsMenu();
    }
}
 
Example 12
Source File: Constants.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
static
void showFragments(Fragment... fragments)
{
    FragmentTransaction transaction = s_fragmentManager.beginTransaction();
    for(Fragment fragment : fragments)
    {
        transaction.show(fragment);
    }
    transaction.commit();
}
 
Example 13
Source File: CameraPreview.java    From cordova-plugin-camera-preview with MIT License 5 votes vote down vote up
private boolean showCamera(CallbackContext callbackContext) {
  if(this.hasView(callbackContext) == false){
    return true;
  }

  FragmentManager fragmentManager = cordova.getActivity().getFragmentManager();
  FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  fragmentTransaction.show(fragment);
  fragmentTransaction.commit();

  callbackContext.success();
  return true;
}
 
Example 14
Source File: HomeActivity.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public void onTabSelect(View v) {
	int id = v.getId();
	FragmentManager manager = getFragmentManager();
	FragmentTransaction transaction = manager.beginTransaction();
	hideFragments(transaction);
	setNormalBackgrounds();
	if (id == R.id.btn_message) {
		if (conversationFragment == null) {
			conversationFragment = new LoveFragment();
			transaction.add(R.id.fragment_container, conversationFragment);
		}
		transaction.show(conversationFragment);
	} else if (id == R.id.btn_contact) {
		if (contactFragment == null) {
			contactFragment = new ContactFragment();
			transaction.add(R.id.fragment_container, contactFragment);
		}
		transaction.show(contactFragment);
	} else if (id == R.id.btn_discover) {
		if (discoverFragment == null) {
			discoverFragment = new MeetFragment();
			transaction.add(R.id.fragment_container, discoverFragment);
		}
		transaction.show(discoverFragment);
	} else if (id == R.id.btn_my_space) {
		if (mySpaceFragment == null) {
			mySpaceFragment = new MySpaceFragment();
			transaction.add(R.id.fragment_container, mySpaceFragment);
		}
		transaction.show(mySpaceFragment);
	}
	int pos;
	for (pos = 0; pos < FRAGMENT_N; pos++) {
		if (tabs[pos] == v) {
			break;
		}
	}
	transaction.commit();
	setTopDrawable(tabs[pos], tabsActiveBackIds[pos]);
}
 
Example 15
Source File: UserActivity.java    From UPMiss with GNU General Public License v3.0 5 votes vote down vote up
private void navToFragment(boolean isMain) {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    if (isMain) {
        fragmentTransaction.show(mMain);
        mToolbar.setTitle(R.string.title_activity_user);
        mIsMain = true;
    } else {
        fragmentTransaction.hide(mMain);


        mToolbar.setTitle(R.string.title_activity_follow);
        mIsMain = false;
    }
    fragmentTransaction.commit();
}
 
Example 16
Source File: FragmentUtil.java    From SmallGdufe-Android with GNU General Public License v3.0 5 votes vote down vote up
/**使用本方法前必须先add*/
public void show(Fragment fragment){
    if (currentFragment==fragment) {
        return;//如果是当前fragment,则不重新show一遍了,无意义
    }
    FragmentTransaction ft = fm.beginTransaction();
    for (Fragment f:fs) {
        ft.hide(f);
    }
    ft.show(fragment);
    ft.commit();
    currentFragment = fragment;
}
 
Example 17
Source File: DialtactsActivity.java    From coursera-android with MIT License 4 votes vote down vote up
/**
 * Hides every tab and shows search UI for phone lookup.
 */
private void enterSearchUi() {
    if (mSearchFragment == null) {
        // We add the search fragment dynamically in the first onLayoutChange() and
        // mSearchFragment is set sometime later when the fragment transaction is actually
        // executed, which means there's a window when users are able to hit the (physical)
        // search key but mSearchFragment is still null.
        // It's quite hard to handle this case right, so let's just ignore the search key
        // in this case.  Users can just hit it again and it will work this time.
        return;
    }
    if (mSearchView == null) {
        prepareSearchView();
    }

    final ActionBar actionBar = getActionBar();

    final Tab tab = actionBar.getSelectedTab();

    // User can search during the call, but we don't want to remember the status.
    if (tab != null && !DialpadFragment.phoneIsInUse()) {
        mLastManuallySelectedFragment = tab.getPosition();
    }

    mSearchView.setQuery(null, true);

    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    updateFakeMenuButtonsVisibility(false);

    for (int i = 0; i < TAB_INDEX_COUNT; i++) {
        sendFragmentVisibilityChange(i, false /* not visible */ );
    }

    // Show the search fragment and hide everything else.
    mSearchFragment.setUserVisibleHint(true);
    final FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.show(mSearchFragment);
    transaction.commitAllowingStateLoss();
    mViewPager.setVisibility(View.GONE);

    // We need to call this and onActionViewCollapsed() manually, since we are using a custom
    // layout instead of asking the search menu item to take care of SearchView.
    mSearchView.onActionViewExpanded();
    mInSearchUi = true;
}
 
Example 18
Source File: MainActivity.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
private void selectItem(int position) {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment newFragment;
    String tag;
    switch (position) {
        default:
            // Lyrics
            tag = LYRICS_FRAGMENT_TAG;
            newFragment = fragmentManager.findFragmentByTag(tag);
            if (newFragment == null || !(newFragment instanceof LyricsViewFragment))
                newFragment = new LyricsViewFragment();
            ((LyricsViewFragment) newFragment).showTransitionAnim = true;
            break;
        case 1:
            // Recent Tracks
            tag = RECENT_TRACKS_FRAGMENT_TAG;
            newFragment = fragmentManager.findFragmentByTag(tag);
            if (newFragment == null || !(newFragment instanceof RecentTracksFragment))
                newFragment = new RecentTracksFragment();
            ((RecentTracksFragment) newFragment).showTransitionAnim = true;
            break;
        case 2:
            // Saved Lyrics
            tag = LOCAL_LYRICS_FRAGMENT_TAG;
            newFragment = fragmentManager.findFragmentByTag(tag);
            if (newFragment == null || !(newFragment instanceof LocalLyricsFragment))
                newFragment = new LocalLyricsFragment();
            ((LocalLyricsFragment) newFragment).showTransitionAnim = true;
            break;
        case 3:
            // Separator
            return;
        case 4:
            // Settings
            if (drawer instanceof DrawerLayout)
                ((DrawerLayout) drawer).closeDrawer(drawerView);
            drawer.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class);
                    startActivityForResult(settingsIntent, 77);
                }
            }, 250);
            return;
        case 5:
            // Feedback
            return;
        case 6:
            // About Dialog
            if (drawer instanceof DrawerLayout)
                ((DrawerLayout) drawer).closeDrawer(drawerView);
            drawer.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent aboutIntent = new Intent(MainActivity.this, AboutActivity.class);
                    startActivityForResult(aboutIntent, 77);
                }
            }, 250);
            return;
    }

    final Fragment activeFragment = getDisplayedFragment(getActiveFragments());
    prepareAnimations(activeFragment);

    // Insert the fragment by replacing any existing fragment
    if (newFragment != activeFragment) {
        if (mActionMode != null)
            mActionMode.finish();
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.setCustomAnimations(R.animator.slide_in_start, R.animator.slide_out_start, R.animator.slide_in_start, R.animator.slide_out_start);
        fragmentTransaction.hide(activeFragment);
        if (newFragment.isAdded())
            fragmentTransaction.show(newFragment);
        else
            fragmentTransaction.add(id.main_fragment_container, newFragment, tag);
        ((CollapsingToolbarLayout) findViewById(R.id.toolbar_layout)).setCollapsedTitleTextColor(Color.WHITE);
        fragmentTransaction.commitAllowingStateLoss();
        if (activeFragment instanceof LyricsViewFragment || newFragment instanceof LyricsViewFragment) {
            final Fragment newFragmentCopy = newFragment;
            activeFragment.getView().postDelayed(() -> {
                if (activeFragment instanceof LyricsViewFragment && activeFragment.getView() != null) {
                    expandToolbar(false);
                    showRefreshFab(false);
                } else if (newFragmentCopy instanceof LyricsViewFragment && activeFragment.getView() != null) {
                    expandToolbar(true);
                    showRefreshFab(true);
                }
            }, getResources().getInteger(android.R.integer.config_longAnimTime));
        }
        MaterialSuggestionsSearchView suggestionsSearchView = findViewById(id.material_search_view);
        if (suggestionsSearchView.isSearchOpen())
            suggestionsSearchView.closeSearch();
    }
    if (drawer instanceof DrawerLayout && (newFragment == activeFragment))
        ((DrawerLayout) drawer).closeDrawer(drawerView);
}
 
Example 19
Source File: MainActivity.java    From Girls with Apache License 2.0 4 votes vote down vote up
private void switchToFragment(int i) {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(android.R.animator.fade_in,
            android.R.animator.fade_out);

    if (mCurrentFragmentIndex == i) {
        fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
        fragmentTransaction.commitAllowingStateLoss();
        mCurrentFragmentIndex = i;
        if (i == BOTTOM_ITEM_TITLE_MEIZI_INDEX) {
            mGirlFragmentAdded = true;
        }
        return;
    }

    fragmentTransaction.hide(getFragment(mCurrentFragmentIndex));

    switch (i) {
        case BOTTOM_ITEM_TITLE_MEIZI_INDEX:
            if (mGirlFragmentAdded) {
                fragmentTransaction.show(getFragment(i));
            } else {
                fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
                mGirlFragmentAdded = true;
            }
            break;
        case BOTTOM_ITEM_TITLE_ANDROID_INDEX:
            if (mAndroidFragmentAdded) {
                fragmentTransaction.show(getFragment(i));
            } else {
                fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
                mAndroidFragmentAdded = true;
            }
            break;
        case BOTTOM_ITEM_TITLE_IOS_INDEX:
            if (mIOSFragmentAdded) {
                fragmentTransaction.show(getFragment(i));
            } else {
                fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
                mIOSFragmentAdded = true;
            }
            break;
        case BOTTOM_ITEM_TITLE_VIDEO_INDEX:
            if (mVideoFragmentAdded) {
                fragmentTransaction.show(getFragment(i));
            } else {
                fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
                mVideoFragmentAdded = true;
            }
            break;
        case BOTTOM_ITEM_TITLE_WEB_INDEX:
            if (mWebFragmentAdded) {
                fragmentTransaction.show(getFragment(i));
            } else {
                fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
                mWebFragmentAdded = true;
            }
            break;
        default:
            break;
    }


    fragmentTransaction.commitAllowingStateLoss();
    mCurrentFragmentIndex = i;
}