예제 #1
0
  protected void showFragment(Fragment oldFragment, Fragment newFragment) {
    android.support.v4.app.Fragment currentFragment =
        getSupportFragmentManager().findFragmentByTag(newFragment.getFragmentTag());

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    if (currentFragment != null) {
      if (oldFragment != null) transaction.hide(oldFragment);

      if (currentFragment.isDetached()) transaction.attach(currentFragment);

      transaction.show(currentFragment);
    } else {
      if (oldFragment != null) transaction.hide(oldFragment);

      if (newFragment != null) {
        if (newFragment.isDetached()) {
          transaction.attach(newFragment);
        } else {
          transaction.add(R.id.MainLayout, newFragment, newFragment.getFragmentTag());
        }
      }
    }

    if (oldFragment != null) transaction.addToBackStack(null);

    transaction.commit();
  }
 @Override
 public void onClick(View v) {
   fraTra = getChildFragmentManager().beginTransaction();
   switch (v.getId()) {
     case R.id.btn_girl:
       btn_girl.setTextColor(getResources().getColor(R.color.pciture_blue));
       btn_boy.setTextColor(getResources().getColor(R.color.pciture_text));
       if (boy_fragment != null) {
         fraTra.hide(boy_fragment);
       }
       fraTra.show(gril_fragment);
       break;
     case R.id.btn_boy:
       btn_boy.setTextColor(getResources().getColor(R.color.pciture_blue));
       btn_girl.setTextColor(getResources().getColor(R.color.pciture_text));
       if (boy_fragment == null) {
         boy_fragment = new BoyFragment();
         fraTra.add(R.id.main_layout, boy_fragment);
       } else {
         gril_fragment.onResume();
       }
       if (gril_fragment != null) {
         fraTra.hide(gril_fragment);
       }
       fraTra.show(boy_fragment);
       break;
     default:
       break;
   }
   fraTra.commit();
 }
  public void changeFragment() {
    FragmentTransaction trx = getSupportFragmentManager().beginTransaction();
    trx.hide(loginNotFragment);
    trx.hide(fragments[currentTabIndex]);
    // 将之前tab设为未选中状态
    mTabs[currentTabIndex].setSelected(false);
    // 更新当前tab值
    currentTabIndex = index;
    // 把当前tab设为选中状态
    mTabs[currentTabIndex].setSelected(true);

    if (currentTabIndex != 0 && currentTabIndex != 1) {
      SSOAuth ssoAuth = SSOAuth.getInstance(this);
      if (ssoAuth.getCurrUser() == null) {
        if (!loginNotFragment.isAdded()) {
          trx.add(R.id.fragment_container, loginNotFragment);
        }
        trx.show(loginNotFragment).commit();
        return;
      }
    }

    if (!fragments[currentTabIndex].isAdded()) {
      trx.add(R.id.fragment_container, fragments[currentTabIndex]);
    }
    trx.show(fragments[currentTabIndex]).commit();
  }
  private void switchRecentlyReportFragment() {

    switchActionBar(true);
    FragmentManager fm = getChildFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    if (recentFragment == null) {
      // recentFragment = new BORecentTrendFragment();
      BloodOxygenRecentlyController controller = new BloodOxygenRecentlyController();
      recentFragment =
          (BloodOxygenRecentTrendFragment)
              controller.getFragment(
                  AbstractUsePagingTaskCacheController.MEASURE_TYPE_RECENTLY, false);
    }
    if (!recentFragment.isAdded()) {
      if (monthFragment != null) {
        ft.hide(monthFragment);
      }
      ft.add(id.fragment_container, recentFragment);
    } else {
      if (monthFragment != null) {
        ft.hide(monthFragment);
      }
      ft.show(recentFragment);
    }
    ft.commitAllowingStateLoss();
  }
예제 #5
0
  // 显示某个相册的照片列表Fragment;
  private void showPhotoPickerFragment(String albumName, List<PhotoInfo> list) {
    // 显示左边按钮;
    mTvLeftCancleBtn.setVisibility(View.VISIBLE);
    mTvLeftArrowBtn.setVisibility(View.VISIBLE);
    mTitleTextView.setText(albumName);

    FragmentTransaction transaction =
        mFragmentManager
            .beginTransaction()
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    // 替换当前的Fragment;
    if (!mPhotoPickerFragment.isAdded()) { // 先判断是否被add过,如果没有add过,直接add这个fragment;
      Bundle args = new Bundle();
      // 这个每次进入前都要把文件夹照片列表发送给photopickfragment;
      PhotoList photoSerializable = new PhotoList();
      photoSerializable.setList(list);
      args.putSerializable("list", photoSerializable);
      mPhotoPickerFragment.setArguments(args);
      transaction
          .hide(mPhotoFolderFragment)
          .add(R.id.fragment_container, mPhotoPickerFragment)
          .commit(); // 隐藏当前的fragment,add下一个到Activity中
    } else { // 如果已经add过,隐藏这个fragment,并且显示下一个fragment;
      mPhotoPickerFragment.updateDataList(list);
      transaction
          .hide(mPhotoFolderFragment)
          .show(mPhotoPickerFragment)
          .commit(); // 隐藏当前的fragment,显示下一个
    }
    mCurrentFragment = mPhotoPickerFragment;
  }
 // Update fragment visibility based on current check box state.
 void updateFragmentVisibility() {
   FragmentTransaction ft = getChildFragmentManager().beginTransaction();
   if (mCheckBox1.isChecked()) ft.show(mFragment1);
   else ft.hide(mFragment1);
   if (mCheckBox2.isChecked()) ft.show(mFragment2);
   else ft.hide(mFragment2);
   ft.commit();
 }
예제 #7
0
 /**
  * 将所有的Fragment都置为隐藏状态。
  *
  * @param transaction 用于对Fragment执行操作的事务
  */
 @SuppressLint("NewApi")
 private void hideFragments(FragmentTransaction transaction) {
   if (mTab01 != null) {
     transaction.hide(mTab01);
   }
   if (mTab02 != null) {
     transaction.hide(mTab02);
   }
 }
예제 #8
0
 // 隐藏所有的Fragment,避免fragment混乱
 private void hideFragments(FragmentTransaction transaction) {
   if (fg1 != null) {
     transaction.hide(fg1);
   }
   if (fg2 != null) {
     transaction.hide(fg2);
   }
   if (fg3 != null) {
     transaction.hide(fg3);
   }
 }
예제 #9
0
  private void hideFragments() {
    fragmentTransaction = getSupportFragmentManager().beginTransaction();
    if (staffStateFragment != null) fragmentTransaction.hide(staffStateFragment);

    if (borrowApplyFragment != null) fragmentTransaction.hide(borrowApplyFragment);

    if (repaymentListFragment != null) fragmentTransaction.hide(repaymentListFragment);

    if (settingFragment != null) fragmentTransaction.hide(settingFragment);

    if (messageCenterFragment != null) fragmentTransaction.hide(messageCenterFragment);
  }
예제 #10
0
  // 底部按钮的点击事件
  @Override
  public void onCheckedChanged(RadioGroup group, int checkedId) {
    // TODO Auto-generated method stub
    // 得到一个碎片管理器
    fragmentManager = this.getSupportFragmentManager();
    // 开始准备切换
    fragmentTransaction = fragmentManager.beginTransaction();

    if (allSchoolFragment != null) {
      fragmentTransaction.hide(allSchoolFragment);
    }
    if (zhaoSchoolFragment != null) {
      fragmentTransaction.hide(zhaoSchoolFragment);
    }
    if (colSchoolFragment != null) {
      fragmentTransaction.hide(colSchoolFragment);
    }

    switch (checkedId) {
      case R.id.allschool_rg_index:
        if (allSchoolFragment == null) {
          allSchoolFragment = new AllSchoolFragment();
          fragmentTransaction.add(R.id.allschool_fl, allSchoolFragment);
        } else {
          fragmentTransaction.show(allSchoolFragment);
        }
        break;
      case R.id.inschool_rg_bm:
        if (zhaoSchoolFragment == null) {
          zhaoSchoolFragment = new ZhaoSchoolFragment();
          fragmentTransaction.add(R.id.allschool_fl, zhaoSchoolFragment);
        } else {
          fragmentTransaction.show(zhaoSchoolFragment);
        }
        break;
      case R.id.colschool_rg_sc:
        if (colSchoolFragment == null) {
          colSchoolFragment = new ColSchoolFragment();
          fragmentTransaction.add(R.id.allschool_fl, colSchoolFragment);
        } else {
          fragmentTransaction.show(colSchoolFragment);
        }
        break;

      default:
        break;
    }

    // 选择好Fragment进行提交
    fragmentTransaction.commit();
  }
예제 #11
0
 /**
  * 将所有的Fragment都置为隐藏状态。
  *
  * @param transaction 用于对Fragment执行操作的事务
  */
 private void hideFragments(FragmentTransaction transaction) {
   if (alarmFragment != null) {
     transaction.hide(alarmFragment);
   }
   if (antiCheatFragment != null) {
     transaction.hide(antiCheatFragment);
   }
   if (newsFragment != null) {
     transaction.hide(newsFragment);
   }
   if (settingFragment != null) {
     transaction.hide(settingFragment);
   }
 }
예제 #12
0
 /**
  * 将所有的Fragment设置为隐藏状态
  *
  * @param transaction
  */
 private void hideFragments(FragmentTransaction transaction) {
   if (homeFragment != null) {
     transaction.hide(homeFragment);
   }
   if (typeFragment != null) {
     transaction.hide(typeFragment);
   }
   if (foodFragment != null) {
     transaction.hide(foodFragment);
   }
   if (mineFragment != null) {
     transaction.hide(mineFragment);
   }
 }
 /**
  * 先全部隐藏Fragment,再显示需要显示的Fragment
  *
  * @param transaction
  * @author liuyunlong
  * @date 2015-9-15下午3:06:17
  */
 private void hideFragment(FragmentTransaction transaction) {
   if (null != mFrag1) {
     transaction.hide(mFrag1);
   }
   if (null != mFrag2) {
     transaction.hide(mFrag2);
   }
   if (null != mFrag3) {
     transaction.hide(mFrag3);
   }
   if (null != mFrag4) {
     transaction.hide(mFrag4);
   }
 }
예제 #14
0
 private void hideFragments(FragmentTransaction transaction) {
   if (null != mNewHomeFragment) {
     transaction.hide(mNewHomeFragment);
   }
   if (null != mToolFragment) {
     transaction.hide(mToolFragment);
   }
   if (null != mInformationFragment) {
     transaction.hide(mInformationFragment);
   }
   if (null != mMyFragment) {
     transaction.hide(mMyFragment);
   }
 }
예제 #15
0
 @Override
 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
   if (tab.getPosition() == 0) {
     if (mMapFragment != null) {
       // Detach the fragment, because another one is being attached
       ft.hide(mMapFragment);
     }
   }
   if (tab.getPosition() == 1) {
     if (mListFragment != null) {
       // Detach the fragment, because another one is being attached
       ft.hide(mListFragment);
     }
   }
 }
예제 #16
0
  /**
   * 将所有的Fragment都置为隐藏状态。
   *
   * @param transaction 用于对Fragment执行操作的事务
   */
  private void hideFragments(FragmentTransaction transaction) {
    if (jiedaiFragment != null) {
      transaction.hide(jiedaiFragment);
      // transaction.detach(jiedaiFragment);
    }
    if (chacheFragment != null) {
      transaction.hide(chacheFragment);
      // transaction.detach(chacheFragment);

    }
    if (gdcxFragment != null) {
      transaction.hide(gdcxFragment);
      // transaction.detach(gdcxFragment);

    }
  }
예제 #17
0
 /**
  * button点击事件
  *
  * @param view
  */
 public void onTabClicked(View view) {
   switch (view.getId()) {
     case R.id.btn_conversation:
       index = 0;
       break;
     case R.id.btn_address_list:
       index = 1;
       break;
     case R.id.btn_setting:
       index = 2;
       break;
   }
   if (currentTabIndex != index) {
     FragmentTransaction trx = getSupportFragmentManager().beginTransaction();
     trx.hide(fragments[currentTabIndex]);
     if (!fragments[index].isAdded()) {
       trx.add(R.id.fragment_container, fragments[index]);
     }
     trx.show(fragments[index]).commit();
   }
   mTabs[currentTabIndex].setSelected(false);
   // 把当前tab设为选中状态
   mTabs[index].setSelected(true);
   currentTabIndex = index;
 }
예제 #18
0
  boolean showFragment(Fragment fragment, String ftag, FragType type, int anim) {
    FragmentManager fragmentManager = MainActivity.getInstance().getSupportFragmentManager();
    if (getFragment(ftag) != null) {
      StringBuilder sb = new StringBuilder();
      sb.append("Fragment:");
      sb.append(fragment.getClass().getName());
      sb.append(" Tag:");
      sb.append(ftag);
      sb.append(" has exist!");
      return false;
    }

    FragmentTransaction transaction = fragmentManager.beginTransaction();

    if (anim != 0) transaction.setCustomAnimations(anim, 0);

    transaction.add(R.id.main_frame, fragment, ftag);

    // 只保留当前层和其下一�?
    if (fragmentStack.size() > 1)
      transaction.hide(fragmentStack.get(fragmentStack.size() - 2).second);
    transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
    transaction.addToBackStack(ftag);
    pushFragment(fragment, ftag);
    transaction.commitAllowingStateLoss();
    return true;
  }
예제 #19
0
  public void switchContent(Fragment fragment) {
    try {
      FragmentTransaction t = fm.beginTransaction();
      List<Fragment> flist = fm.getFragments();
      if (flist == null) {
        t.add(R.id.main_content, fragment);
      } else {
        if (!flist.contains(fragment)) {
          t.add(R.id.main_content, fragment);
        }
        t.hide(slist.get(slist.size() - 1));
        t.show(fragment);
      }

      if (slist.contains(fragment)) {
        slist.remove(fragment);
      }

      slist.add(fragment);

      t.commitAllowingStateLoss();

    } catch (Exception e) {
    }
  }
예제 #20
0
 /**
  * 隐藏一个Fragment
  *
  * @param fragment
  */
 public void hideFragment(Fragment fragment) {
   if (!fragment.isHidden()) {
     FragmentTransaction fragmentTransaction = getFragmentTransaction();
     fragmentTransaction.hide(fragment);
     fragmentTransaction.commit();
   }
 }
예제 #21
0
  public static void RecreateFragemnt(
      FragmentManager manager, String fragmentName, int containerId, String tag) {
    List<Fragment> fragments = manager.getFragments();
    FragmentTransaction transaction = manager.beginTransaction();
    boolean isexist = false;
    try {
      for (Fragment fragment : fragments) {
        transaction.hide(fragment);
        if (fragment.getClass().toString().contains(fragmentName)) {
          transaction.remove(fragment);
          Class c = Class.forName(fragmentName);
          Fragment newfragment = (Fragment) c.newInstance();
          transaction.add(containerId, newfragment, tag);
          isexist = true;
          transaction.show(newfragment);
        }
      }
      if (!isexist) {
        Class c = Class.forName(fragmentName);
        Fragment newfragment = (Fragment) c.newInstance();
        transaction.add(containerId, newfragment, tag);
        transaction.show(newfragment);
      }
      transaction.commit();
    } catch (Exception ex) {

    }
  }
예제 #22
0
 /**
  * 切换界面
  *
  * @param oldPosition 旧位置 第一次这里应该时-1
  * @param newPosition 新位置
  * @param isAnim 是否使用预设动画
  */
 protected void switchFragment(int oldPosition, int newPosition, boolean isAnim) {
   if (oldPosition == newPosition) return;
   FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
   // 切换前检查是否有预制动画
   onSwitchFragmentAnim(oldPosition, newPosition, isAnim, ft);
   BasicFragment newFragment =
       (BasicFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(newPosition));
   BasicFragment oldFragment =
       (BasicFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(oldPosition));
   if (newFragment != null) {
     newFragment.setMenuVisibility(true);
     newFragment.setUserVisibleHint(true);
     ft.show(newFragment);
   } else {
     newFragment = fragments[newPosition];
     ft.add(
         getResources().getIdentifier("container", "id", getPackageName()),
         newFragment,
         String.valueOf(newPosition));
   }
   if (oldFragment != null) {
     ft.hide(oldFragment);
   }
   // 切换Fragment后触发switchFragmentAfter方法
   onSwitchFragmentAfter(ft, oldFragment, newFragment);
   ft.commitAllowingStateLoss();
   getSupportFragmentManager().executePendingTransactions();
   currentPosition = newPosition;
 }
 public void hide(Fragment fragment) {
   if (fragment != null) {
     FragmentTransaction transaction = fm.beginTransaction();
     transaction.hide(fragment);
     transaction.commitAllowingStateLoss();
   }
 }
예제 #24
0
  private FragmentTransaction doTabChanged(String tabId, FragmentTransaction ft) {
    TabInfo newTab = null;
    for (int i = 0; i < mTabs.size(); i++) {
      TabInfo tab = mTabs.get(i);
      if (tab.tag.equals(tabId)) {
        newTab = tab;
      }
    }
    if (newTab == null) {
      throw new IllegalStateException("No tab known for tag " + tabId);
    }
    if (mLastTab != newTab) {
      if (ft == null) {
        ft = mFragmentManager.beginTransaction();
      }
      if (mLastTab != null) {
        if (mLastTab.fragment != null) {
          //					ft.detach(mLastTab.fragment);
          ft.hide(mLastTab.fragment);
        }
      }
      if (newTab != null) {
        if (newTab.fragment == null) {
          newTab.fragment = Fragment.instantiate(mContext, newTab.clss.getName(), newTab.args);
          ft.add(mContainerId, newTab.fragment, newTab.tag);
        } else {
          //					ft.attach(newTab.fragment);
          ft.show(newTab.fragment);
        }
      }

      mLastTab = newTab;
    }
    return ft;
  }
 public void onKeyboardHide() {
   Log.i("KeyboardFragment", "Hiding keyboard");
   FragmentManager fm = getFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();
   ft.hide(this);
   ft.commit();
 }
예제 #26
0
  public void openFragment(
      Class<? extends Fragment> fragmentClazz, Bundle args, boolean addBackStack) {
    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    String tag = fragmentClazz.getName();

    try {
      if (!isFragmentAdded(tag)) {
        Fragment fragment = null;

        fragment = fragmentClazz.newInstance();
        if (args != null) {
          fragment.setArguments(args);
        }

        Fragment fragCurr = FragmentUtils.getCurrentFragment(this);
        if (fragCurr != null) transaction.hide(fragCurr);
        transaction.add(R.id.frameContent, fragment, tag);
        if (addBackStack) {
          transaction.addToBackStack(tag);
        }
        transaction.commit();

      } else {
        showFragment(tag, transaction);
      }

    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }
  }
예제 #27
0
  @Override
  public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE);
    String[] ids = savedInstanceState.getStringArray(Constants.MAIN_BACK_STACK);
    FragmentManager fm = getSupportFragmentManager();
    currentFragment = (SubsonicFragment) fm.findFragmentByTag(ids[0]);
    currentFragment.setPrimaryFragment(true);
    currentFragment.setSupportTag(ids[0]);
    supportInvalidateOptionsMenu();
    FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
    for (int i = 1; i < size; i++) {
      SubsonicFragment frag = (SubsonicFragment) fm.findFragmentByTag(ids[i]);
      frag.setSupportTag(ids[i]);
      if (secondaryContainer != null) {
        frag.setPrimaryFragment(false, true);
      }
      trans.hide(frag);
      backStack.add(frag);
    }
    trans.commit();

    // Current fragment is hidden in secondaryContainer
    if (secondaryContainer == null && !currentFragment.isVisible()) {
      trans = getSupportFragmentManager().beginTransaction();
      trans.remove(currentFragment);
      trans.commit();
      getSupportFragmentManager().executePendingTransactions();

      trans = getSupportFragmentManager().beginTransaction();
      trans.add(R.id.fragment_container, currentFragment, ids[0]);
      trans.commit();
    }
    // Current fragment needs to be moved over to secondaryContainer
    else if (secondaryContainer != null
        && secondaryContainer.findViewById(currentFragment.getRootId()) == null
        && backStack.size() > 0) {
      trans = getSupportFragmentManager().beginTransaction();
      trans.remove(currentFragment);
      trans.show(backStack.get(backStack.size() - 1));
      trans.commit();
      getSupportFragmentManager().executePendingTransactions();

      trans = getSupportFragmentManager().beginTransaction();
      trans.add(R.id.fragment_second_container, currentFragment, ids[0]);
      trans.commit();

      secondaryContainer.setVisibility(View.VISIBLE);
    }

    lastSelectedPosition = savedInstanceState.getInt(Constants.FRAGMENT_POSITION);
    if (lastSelectedPosition != 0) {
      MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
      if (item != null) {
        item.setChecked(true);
      }
    }
    recreateSpinner();
  }
예제 #28
0
 public static void HideAllFragemnt(FragmentManager manager) {
   List<Fragment> fragments = manager.getFragments();
   FragmentTransaction transaction = manager.beginTransaction();
   for (Fragment fragment : fragments) {
     transaction.hide(fragment);
   }
   transaction.commit();
 }
예제 #29
0
 private FragmentTransaction hideFragments(FragmentTransaction ts) {
   return ts.hide(search)
       .hide(library)
       .hide(transfers)
       .hide(peers)
       .hide(peersDisabled)
       .hide(about);
 }
예제 #30
0
  private void hideFragments(FragmentTransaction transaction) {

    if (fhd != null) {
      transaction.hide(fhd);
    }
    if (fxs != null) {
      transaction.hide(fxs);
    }
    if (fjjy != null) {
      transaction.hide(fjjy);
    }
    if (fqz != null) {
      transaction.hide(fqz);
    }
    if (ffaxian != null) {
      transaction.hide(ffaxian);
    }
  }