コード例 #1
0
ファイル: MainActivity.java プロジェクト: chxip/equerycar
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Constants.PERSONALINFORMATION_TCDL) {
      Intent intent = new Intent(MainActivity.this, LoginActivity.class);
      startActivity(intent);
      finish();
    } else if (resultCode == Constants.PERSONALINFORMATION_BACK) { // 按返回键返回

    } else {
      FragmentManager fm = getSupportFragmentManager();
      int index = requestCode >> 16;
      if (index != 0) {
        index--;
        if (fm.getFragments() == null || index < 0 || index >= fm.getFragments().size()) {
          return;
        }
        Fragment frag = fm.getFragments().get(index);
        if (frag == null) {
        } else {
          handleResult(frag, requestCode, resultCode, data);
        }
        return;
      }
    }
  }
コード例 #2
0
  /** Swaps fragments in the main content view */
  private void selectItem(int position, View v) throws ParseException {
    FragmentManager fm = getSupportFragmentManager();

    frame.removeAllViews();
    int tView = R.layout.venue_list;
    if (position == 1) {
      if (fm.getFragments() != null) {
        fm.getFragments().clear();
      }
      tView = R.layout.movie_map;
    }

    if (position == 2) {
      tView = R.layout.about_layout;
    }

    inflater.inflate(tView, frame);

    if (position == 1) {
      MapPageFragment fragment = (MapPageFragment) fm.getFragments().get(0);
      FragmentManager cm = fragment.getChildFragmentManager();
      SupportMapFragment mapFragment = (SupportMapFragment) cm.findFragmentById(R.id.map);
      mMap = mapFragment.getMap();
      launchMap();
    }

    if (position == 0) {
      if (ensureUi()) {
        childList = new GetChildList();
        childList.execute();
      }
    }

    if (position == 2) {
      try {
        String versionName =
            v.getContext()
                .getPackageManager()
                .getPackageInfo(v.getContext().getPackageName(), 0)
                .versionName;
        TextView tv = (TextView) findViewById(R.id.appVersion);
        tv.setText("Version: " + versionName + " (Beta)");
      } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
      }
    }

    menuPos = position;

    // Highlight the selected item, update the title, and close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mMenuTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
  }
コード例 #3
0
 /**
  * Get the complete backstack
  *
  * @return the complete backstack
  */
 public ArrayList<FragmentStateHolder> getBackStack() {
   FragmentStateHolder currentFragmentStateHolder = getCurrentFragmentStateHolder();
   Fragment currentFragment = null;
   if (mFragmentManager != null && mFragmentManager.getFragments() != null) {
     currentFragment = mFragmentManager.getFragments().get(0);
   }
   if (currentFragment != null && currentFragment instanceof TomahawkFragment) {
     currentFragmentStateHolder.listScrollPosition =
         ((TomahawkFragment) currentFragment).getListScrollPosition();
     mBackstack.set(mBackstack.size() - 1, currentFragmentStateHolder);
   }
   return mBackstack;
 }
コード例 #4
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) {

    }
  }
コード例 #5
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) {
    }
  }
コード例 #6
0
ファイル: MainActivity.java プロジェクト: VNAPNIC/MySoha
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    try {
      FragmentManager fm = getSupportFragmentManager();
      List<Fragment> fragments = fm.getFragments();
      for (Fragment fragment : fragments) {
        if (fragment != null && fragment instanceof CalendarFragment) {
          ((CalendarFragment) fragment).hideCalendar();
          break;
        }
      }
      switch (item.getItemId()) {
        case android.R.id.home:
          viewHolder.openDrawer(GravityCompat.START);
          return true;

        case R.id.friend:
          viewHolder.openDrawer(GravityCompat.END);
          break;

        case R.id.create_group_chat:
          selectedIds = new ArrayList<>();
          FriendPickerActivity.start(
              this, selectedIds, true, getString(R.string.group_create_validate_member_empty));
          return true;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return super.onOptionsItemSelected(item);
  }
コード例 #7
0
 public static void RemoveAllFragemnt(FragmentManager manager) {
   List<Fragment> fragments = manager.getFragments();
   FragmentTransaction transaction = manager.beginTransaction();
   for (Fragment fragment : fragments) {
     transaction.remove(fragment);
   }
   transaction.commit();
 }
コード例 #8
0
 public Fragment getVisibleFragment() {
   FragmentManager fragmentManager = MenuEstudiante.this.getSupportFragmentManager();
   List<Fragment> fragments = fragmentManager.getFragments();
   for (Fragment fragment : fragments) {
     if (fragment != null && fragment.isVisible()) return fragment;
   }
   return null;
 }
コード例 #9
0
ファイル: BaseActivity.java プロジェクト: 601367322/dog
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   FragmentManager fm = getSupportFragmentManager();
   int index = requestCode >> 16;
   if (index != 0) {
     index--;
     if (fm.getFragments() == null || index < 0 || index >= fm.getFragments().size()) {
       return;
     }
     Fragment frag = fm.getFragments().get(index);
     if (frag == null) {
     } else {
       handleResult(frag, requestCode, resultCode, data);
     }
     return;
   }
 }
コード例 #10
0
 public Fragment getVisibleFragment() {
   FragmentManager fragmentManager = MainActivity.this.getSupportFragmentManager();
   List<Fragment> fragments = fragmentManager.getFragments();
   for (Fragment fragment : fragments) {
     if (fragment != null && fragment.getUserVisibleHint()) return (Fragment) fragment;
   }
   return null;
 }
コード例 #11
0
ファイル: UiUtils.java プロジェクト: votruk/components
  public static boolean tryForeachFragment(
      @NonNull final FragmentManager fragmentManager,
      @NonNull final Func1<AbstractBaseFragment, Boolean> actionOnChild,
      final boolean onlyForResumed) {
    if (fragmentManager.getFragments() == null) {
      return false;
    }

    boolean result = false;
    for (final Fragment fragment : fragmentManager.getFragments()) {
      if (fragment != null
          && (!onlyForResumed || fragment.isResumed())
          && fragment instanceof AbstractBaseFragment) {
        result = result || actionOnChild.call((AbstractBaseFragment) fragment);
      }
    }
    return result;
  }
コード例 #12
0
 public void checkAllFragmentsForViewPageChange() {
   List<Fragment> fragments = mFragmentManager.getFragments();
   for (Fragment fragment : fragments) {
     if (fragment instanceof MoviesGridFragment
         && ((MoviesGridFragment) fragment).checkFragmentActive()) {
       break;
     }
   }
 }
コード例 #13
0
ファイル: MainActivity.java プロジェクト: dai1993/LichVanNien
 private Boolean isFragmentAdded(String tag) {
   FragmentManager manager = getSupportFragmentManager();
   List<Fragment> fragmentList = manager.getFragments();
   if (fragmentList != null) {
     for (int i = fragmentList.size() - 1; i > -1; i--) {
       Fragment fragment = fragmentList.get(i);
       if (fragment != null && fragment.getClass().getName().equals(tag) && !fragment.isRemoving())
         return true;
     }
   }
   return false;
 }
コード例 #14
0
 public void switchToList() {
   FragmentTransaction transaction = mFragmentManager.beginTransaction();
   animateTransition(transaction, TRANSITION_HORIZONTAL);
   ListFragment mListFragment = new ListFragment();
   transaction
       .replace(R.id.fragment_container, mListFragment, FRAGMENT_LIST_TAG)
       .addToBackStack(FRAGMENT_DETAIL_TAG)
       .commitAllowingStateLoss();
   if (getDrawerToggle() != null) {
     getDrawerToggle().setDrawerIndicatorEnabled(false);
   }
   mFragmentManager.getFragments();
 }
コード例 #15
0
  private void clearPrevFragments(FragmentManager fm) {
    List<Fragment> listFragment = fm.getFragments();

    if (listFragment != null) {
      FragmentTransaction ft = fm.beginTransaction();

      for (Fragment f : listFragment) {
        if (f instanceof FrgCalendar) {
          ft.remove(f);
        }
      }
      ft.commitAllowingStateLoss();
    }
  }
コード例 #16
0
  public static Fragment GetFragemnt(FragmentManager manager, String fragmentName) {
    List<Fragment> fragments = manager.getFragments();
    try {
      for (Fragment fragment : fragments) {

        if (fragment.getClass().toString().contains(fragmentName)) {
          return fragment;
        }
      }
    } catch (Exception ex) {

    }
    return null;
  }
コード例 #17
0
ファイル: MainActivity.java プロジェクト: dai1993/LichVanNien
 private void showFragment(String tag, FragmentTransaction transaction) {
   FragmentManager manager = getSupportFragmentManager();
   List<Fragment> fragmentList = manager.getFragments();
   if (fragmentList != null)
     for (Fragment fragment : fragmentList) {
       if (fragment != null) {
         if (fragment.getClass().getName().equals(tag)) {
           transaction.show(fragment);
         } else {
           transaction.hide(fragment);
         }
       }
     }
   transaction.commit();
 }
コード例 #18
0
ファイル: MainActivity.java プロジェクト: lpjhblpj/football
 private void initFragment(Bundle savedInstanceState) {
   if (savedInstanceState == null) {
     FragmentTransaction ft = fMgr.beginTransaction();
     mFragment = mBaseNewsFragment = new BaseNewsFragment();
     // mFragment = new BaseTournamentFragment();
     // index = 1;
     initBottomButton();
     ft.replace(R.id.fragmentRoot, mFragment);
     ft.commitAllowingStateLoss();
   } else {
     List<Fragment> fragments = fMgr.getFragments();
     if (fragments == null || fragments.isEmpty()) {
       FragmentTransaction ft = fMgr.beginTransaction();
       mFragment = mBaseNewsFragment = new BaseNewsFragment();
       ft.replace(R.id.fragmentRoot, mFragment);
       ft.commitAllowingStateLoss();
     } else {
       index = savedInstanceState.getInt("INDEX");
       initBottomButton();
       FragmentTransaction ft = fMgr.beginTransaction();
       for (Fragment fragment : fragments) {
         if (fragment == null) {
           continue;
         } else if (fragment instanceof BaseNewsFragment && index == 0) {
           mFragment = mBaseNewsFragment = (BaseNewsFragment) fragment;
         } else if (fragment instanceof BaseTournamentFragment && index == 1) {
           mFragment = fragment;
         } else if (fragment instanceof FeedFragment && index == 2) {
           mFragment = mFeedFragment = (FeedFragment) fragment;
         } else if (fragment instanceof BaseGroupFragment && index == 3) {
           mFragment = fragment;
         } else if (fragment instanceof BaseStandingsFragment && index == 4) {
           mFragment = fragment;
         } else if (!(fragment instanceof LeftSlidingMenuFragment)) {
           ft.remove(fragment);
         }
       }
       if (mFragment != null) {
         ft.show(mFragment);
       }
       Trace.d(tag, "mFragment:" + mFragment);
       ft.commitAllowingStateLoss();
     }
   }
 }
コード例 #19
0
  private void clearBackStack() {
    FragmentManager fragmentManager = getSupportFragmentManager();

    if (0 < fragmentManager.getBackStackEntryCount()) {
      int id = fragmentManager.getBackStackEntryAt(0).getId();
      fragmentManager.popBackStackImmediate(id, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }

    List<Fragment> fragments = fragmentManager.getFragments();
    if (fragments == null) {
      return;
    }
    FragmentTransaction trans = fragmentManager.beginTransaction();
    for (Fragment fragment : fragments) {
      if (fragment != null) {
        trans.remove(fragment);
      }
    }
    trans.commit();
  }
コード例 #20
0
 /**
  * Replaces the {@link Fragment} in the hub with the given hub id and adds it to the backstack, if
  * isBackAction is false.
  *
  * @param fragmentStateHolder {@link FragmentStateHolder} contains all information of the to be
  *     replaced {@link Fragment}
  * @param isBackAction whether or not the replacement is part of an action going back in the
  *     backstack
  */
 public void replace(FragmentStateHolder fragmentStateHolder, boolean isBackAction) {
   // Get fragmentsStack for the given (tabs)position
   FragmentStateHolder currentFragmentStateHolder = getCurrentFragmentStateHolder();
   // Replace the fragment using a transaction.
   FragmentTransaction ft = mFragmentManager.beginTransaction();
   if (isBackAction) {
     mBackstack.remove(currentFragmentStateHolder);
     ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
   } else {
     Fragment currentFragment = null;
     if (mFragmentManager != null && mFragmentManager.getFragments() != null) {
       currentFragment = mFragmentManager.findFragmentByTag(FRAGMENT_TAG);
     }
     if (currentFragmentStateHolder != null
         && currentFragment != null
         && currentFragment instanceof TomahawkFragment) {
       currentFragmentStateHolder.listScrollPosition =
           ((TomahawkFragment) currentFragment).getListScrollPosition();
     }
     mBackstack.add(fragmentStateHolder);
     ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
   }
   Bundle bundle = new Bundle();
   bundle.putString(
       fragmentStateHolder.tomahawkListItemType, fragmentStateHolder.tomahawkListItemKey);
   bundle.putBoolean(
       TomahawkFragment.TOMAHAWK_LIST_ITEM_IS_LOCAL, fragmentStateHolder.tomahawkListItemIsLocal);
   bundle.putInt(
       TomahawkFragment.TOMAHAWK_LIST_SCROLL_POSITION, fragmentStateHolder.listScrollPosition);
   bundle.putString(
       SearchableFragment.SEARCHABLEFRAGMENT_QUERY_STRING, fragmentStateHolder.queryString);
   ft.replace(
       mContentFrameId,
       Fragment.instantiate(mTomahawkMainActivity, fragmentStateHolder.clss.getName(), bundle),
       FRAGMENT_TAG);
   ft.commit();
   mTomahawkMainActivity.updateViewVisibility();
 }
コード例 #21
0
  public static void ShowFragemnt(FragmentManager manager, String fragmentName) {
    List<Fragment> fragments = manager.getFragments();
    FragmentTransaction transaction = manager.beginTransaction();
    boolean isexist = false;
    for (Fragment fragment : fragments) {
      transaction.hide(fragment);
      if (fragment.getClass().toString().contains(fragmentName)) {
        transaction.show(fragment);
        isexist = true;
      }
    }
    if (!isexist) {
      try {
        Class c = Class.forName(fragmentName);
        Fragment newfragment = (Fragment) c.newInstance();
        transaction.add(newfragment, null);
        transaction.show(newfragment);
      } catch (Exception ex) {

      }
    }
    transaction.commit();
  }
コード例 #22
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(R.layout.custom_action_bar);

    fragmentManager = getSupportFragmentManager();
    fragmentManager.addOnBackStackChangedListener(this);

    if (savedInstanceState == null) {
      Log.d("", "SavedInstance = null");
      // setFragment(FragmentList.TAG);
      fragmentAlbumList = FragmentList.create(this);
      fragmentManager = getSupportFragmentManager();
      fragmentManager
          .beginTransaction()
          .add(R.id.mainframe, fragmentAlbumList, FragmentList.TAG)
          .commit();

      currentFrag = fragmentAlbumList;

    } else {
      Log.d("", "SavedInstance != null");
      Fragment temp = fragmentManager.findFragmentByTag(FragmentList.TAG);
      if (temp != null) ((FragmentList) temp).setListener(this);

      temp = fragmentManager.findFragmentByTag(FragmentDetail.TAG);
      if (temp != null) ((FragmentDetail) temp).setListener(this);

      currentFrag = fragmentManager.getFragments().get(0);
    }
  }