예제 #1
0
  public boolean performItemAction(MenuItem item, int flags) {
    MenuItemImpl itemImpl = (MenuItemImpl) item;

    if (itemImpl == null || !itemImpl.isEnabled()) {
      return false;
    }

    boolean invoked = itemImpl.invoke();

    if (itemImpl.hasCollapsibleActionView()) {
      invoked |= itemImpl.expandActionView();
      if (invoked) close(true);
    } else if (item.hasSubMenu()) {
      close(false);

      final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
      final ActionProvider provider = item.getActionProvider();
      if (provider != null && provider.hasSubMenu()) {
        provider.onPrepareSubMenu(subMenu);
      }
      invoked |= dispatchSubMenuSelected(subMenu);
      if (!invoked) close(true);
    } else {
      if ((flags & FLAG_PERFORM_NO_CLOSE) == 0) {
        close(true);
      }
    }

    return invoked;
  }
예제 #2
0
  /**
   * Invokes the item by calling various listeners or callbacks.
   *
   * @return true if the invocation was handled, false otherwise
   */
  public boolean invoke() {
    if (mClickListener != null && mClickListener.onMenuItemClick(this)) {
      return true;
    }

    if (mMenu.dispatchMenuItemSelected(mMenu.getRootMenu(), this)) {
      return true;
    }

    if (mItemCallback != null) {
      mItemCallback.run();
      return true;
    }

    if (mIntent != null) {
      try {
        mMenu.getContext().startActivity(mIntent);
        return true;
      } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Can't find activity to handle intent; ignoring", e);
      }
    }

    if (mActionProvider != null && mActionProvider.onPerformDefaultAction()) {
      return true;
    }

    return false;
  }
  @Override
  public void updateMenuView(boolean cleared) {
    super.updateMenuView(cleared);

    if (mMenu != null) {
      final ArrayList<MenuItemImpl> actionItems = mMenu.getActionItems();
      final int count = actionItems.size();
      for (int i = 0; i < count; i++) {
        final ActionProvider provider = actionItems.get(i).getActionProvider();
        if (provider != null) {
          provider.setSubUiVisibilityListener(this);
        }
      }
    }

    final ArrayList<MenuItemImpl> nonActionItems = mMenu != null ? mMenu.getNonActionItems() : null;

    boolean hasOverflow = false;
    if (mReserveOverflow && nonActionItems != null) {
      final int count = nonActionItems.size();
      if (count == 1) {
        hasOverflow = !nonActionItems.get(0).isActionViewExpanded();
      } else {
        hasOverflow = count > 0;
      }
    }

    if (hasOverflow) {
      if (mOverflowButton == null) {
        mOverflowButton = new OverflowMenuButton(mSystemContext);
      }
      ViewGroup parent = (ViewGroup) mOverflowButton.getParent();
      if (parent != mMenuView) {
        if (parent != null) {
          parent.removeView(mOverflowButton);
        }
        ActionMenuView menuView = (ActionMenuView) mMenuView;
        menuView.addView(mOverflowButton, menuView.generateOverflowButtonLayoutParams());
      }
    } else if (mOverflowButton != null && mOverflowButton.getParent() == mMenuView) {
      ((ViewGroup) mMenuView).removeView(mOverflowButton);
    }

    ((ActionMenuView) mMenuView).setOverflowReserved(mReserveOverflow);
  }
예제 #4
0
 public View getActionView() {
   if (mActionView != null) {
     return mActionView;
   } else if (mActionProvider != null) {
     mActionView = mActionProvider.onCreateActionView();
     return mActionView;
   } else {
     return null;
   }
 }
 @Override
 public void onGlobalLayout() {
   if (isShowingPopup()) {
     if (!isShown()) {
       getListPopupWindow().dismiss();
     } else {
       getListPopupWindow().show();
       if (mProvider != null) {
         mProvider.subUiVisibilityChanged(true);
       }
     }
   }
 }
  /**
   * Shows the popup no matter if it was already showing.
   *
   * @param maxActivityCount The max number of activities to display.
   */
  private void showPopupUnchecked(int maxActivityCount) {
    if (mAdapter.getDataModel() == null) {
      throw new IllegalStateException("No data model. Did you call #setDataModel?");
    }

    getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);

    final boolean defaultActivityButtonShown = mDefaultActivityButton.getVisibility() == VISIBLE;

    final int activityCount = mAdapter.getActivityCount();
    final int maxActivityCountOffset = defaultActivityButtonShown ? 1 : 0;
    if (maxActivityCount != ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED
        && activityCount > maxActivityCount + maxActivityCountOffset) {
      mAdapter.setShowFooterView(true);
      mAdapter.setMaxActivityCount(maxActivityCount - 1);
    } else {
      mAdapter.setShowFooterView(false);
      mAdapter.setMaxActivityCount(maxActivityCount);
    }

    IcsListPopupWindow popupWindow = getListPopupWindow();
    if (!popupWindow.isShowing()) {
      if (mIsSelectingDefaultActivity || !defaultActivityButtonShown) {
        mAdapter.setShowDefaultActivity(true, defaultActivityButtonShown);
      } else {
        mAdapter.setShowDefaultActivity(false, false);
      }
      final int contentWidth = Math.min(mAdapter.measureContentWidth(), mListPopupMaxWidth);
      popupWindow.setContentWidth(contentWidth);
      popupWindow.show();
      if (mProvider != null) {
        mProvider.subUiVisibilityChanged(true);
      }
      popupWindow
          .getListView()
          .setContentDescription(
              mContext.getString(R.string.abs__activitychooserview_choose_application));
    }
  }