Exemplo n.º 1
0
  @Override
  public boolean onCreatePanelMenu(int featureId, Menu menu) {
    if (ActionBarSherlock.DEBUG)
      Log.d(TAG, "[onCreatePanelMenu] featureId: " + featureId + ", menu: " + menu);

    if (featureId == Window.FEATURE_OPTIONS_PANEL) {
      boolean result = onCreateOptionsMenu(menu);
      if (ActionBarSherlock.DEBUG)
        Log.d(TAG, "[onCreatePanelMenu] activity create result: " + result);

      MenuInflater inflater = getSupportMenuInflater();
      boolean show = false;
      ArrayList<Fragment> newMenus = null;
      if (mFragments.mAdded != null) {
        for (int i = 0; i < mFragments.mAdded.size(); i++) {
          Fragment f = mFragments.mAdded.get(i);
          if (f != null
              && !f.mHidden
              && f.mHasMenu
              && f.mMenuVisible
              && f instanceof OnCreateOptionsMenuListener) {
            show = true;
            ((OnCreateOptionsMenuListener) f).onCreateOptionsMenu(menu, inflater);
            if (newMenus == null) {
              newMenus = new ArrayList<Fragment>();
            }
            newMenus.add(f);
          }
        }
      }

      if (mCreatedMenus != null) {
        for (int i = 0; i < mCreatedMenus.size(); i++) {
          Fragment f = mCreatedMenus.get(i);
          if (newMenus == null || !newMenus.contains(f)) {
            f.onDestroyOptionsMenu();
          }
        }
      }

      mCreatedMenus = newMenus;

      if (ActionBarSherlock.DEBUG)
        Log.d(TAG, "[onCreatePanelMenu] fragments create result: " + show);
      result |= show;

      if (ActionBarSherlock.DEBUG) Log.d(TAG, "[onCreatePanelMenu] returning " + result);
      return result;
    }
    return false;
  }
 @Override
 public void onDestroyOptionsMenu() {
   recLifeCycle(getClass(), CALL_TO_SUPER);
   super.onDestroyOptionsMenu();
   recLifeCycle(getClass(), RETURN_FROM_SUPER);
 }