Exemplo n.º 1
0
  private void setHeaderInternal(
      final int titleRes,
      final CharSequence title,
      final int iconRes,
      final Drawable icon,
      final View view) {
    final Resources r = getResources();

    if (view != null) {
      mHeaderView = view;

      // If using a custom view, then the title and icon aren't used
      mHeaderTitle = null;
      mHeaderIcon = null;
    } else {
      if (titleRes > 0) {
        mHeaderTitle = r.getText(titleRes);
      } else if (title != null) {
        mHeaderTitle = title;
      }

      if (iconRes > 0) {
        mHeaderIcon = r.getDrawable(iconRes);
      } else if (icon != null) {
        mHeaderIcon = icon;
      }

      // If using the title or icon, then a custom view isn't used
      mHeaderView = null;
    }

    // Notify of change
    onItemsChanged(false);
  }
 void setCheckedInt(boolean checked) {
   final int oldFlags = mFlags;
   mFlags = (mFlags & ~CHECKED) | (checked ? CHECKED : 0);
   if (oldFlags != mFlags) {
     mMenu.onItemsChanged(false);
   }
 }
Exemplo n.º 3
0
  /**
   * * Remove the item at the given index and optionally forces menu views to update.
   *
   * @param index The index of the item to be removed. If this index is invalid an exception is
   *     thrown.
   * @param updateChildrenOnMenuViews Whether to force update on menu views. Please make sure you
   *     eventually call this after your batch of removals.
   */
  private void removeItemAtInt(int index, boolean updateChildrenOnMenuViews) {
    if ((index < 0) || (index >= mItems.size())) return;

    mItems.remove(index);

    if (updateChildrenOnMenuViews) onItemsChanged(true);
  }
  public MenuItem setIcon(Drawable icon) {
    mIconResId = NO_ICON;
    mIconDrawable = icon;
    mMenu.onItemsChanged(false);

    return this;
  }
Exemplo n.º 5
0
  public void clearHeader() {
    mHeaderIcon = null;
    mHeaderTitle = null;
    mHeaderView = null;

    onItemsChanged(false);
  }
Exemplo n.º 6
0
 public void clearAll() {
   mPreventDispatchingItemsChanged = true;
   clear();
   clearHeader();
   mPreventDispatchingItemsChanged = false;
   mItemsChangedWhileDispatchPrevented = false;
   onItemsChanged(true);
 }
Exemplo n.º 7
0
  public void clear() {
    if (mExpandedItem != null) {
      collapseItemActionView(mExpandedItem);
    }
    mItems.clear();

    onItemsChanged(true);
  }
Exemplo n.º 8
0
  public void startDispatchingItemsChanged() {
    mPreventDispatchingItemsChanged = false;

    if (mItemsChangedWhileDispatchPrevented) {
      mItemsChangedWhileDispatchPrevented = false;
      onItemsChanged(true);
    }
  }
  public MenuItem setShortcut(char numericChar, char alphaChar) {
    mShortcutNumericChar = numericChar;
    mShortcutAlphabeticChar = Character.toLowerCase(alphaChar);

    mMenu.onItemsChanged(false);

    return this;
  }
  public MenuItem setAlphabeticShortcut(char alphaChar) {
    if (mShortcutAlphabeticChar == alphaChar) return this;

    mShortcutAlphabeticChar = Character.toLowerCase(alphaChar);

    mMenu.onItemsChanged(false);

    return this;
  }
  public MenuItem setCheckable(boolean checkable) {
    final int oldFlags = mFlags;
    mFlags = (mFlags & ~CHECKABLE) | (checkable ? CHECKABLE : 0);
    if (oldFlags != mFlags) {
      mMenu.onItemsChanged(false);
    }

    return this;
  }
  public MenuItem setIcon(int iconResId) {
    mIconDrawable = null;
    mIconResId = iconResId;

    // If we have a view, we need to push the Drawable to them
    mMenu.onItemsChanged(false);

    return this;
  }
  public MenuItem setNumericShortcut(char numericChar) {
    if (mShortcutNumericChar == numericChar) return this;

    mShortcutNumericChar = numericChar;

    mMenu.onItemsChanged(false);

    return this;
  }
  public MenuItem setTitle(CharSequence title) {
    mTitle = title;

    mMenu.onItemsChanged(false);

    if (mSubMenu != null) {
      mSubMenu.setHeaderTitle(title);
    }

    return this;
  }
  public MenuItem setEnabled(boolean enabled) {
    if (enabled) {
      mFlags |= ENABLED;
    } else {
      mFlags &= ~ENABLED;
    }

    mMenu.onItemsChanged(false);

    return this;
  }
  public MenuItem setTitleCondensed(CharSequence title) {
    mTitleCondensed = title;

    // Could use getTitle() in the loop below, but just cache what it would do here
    if (title == null) {
      title = mTitle;
    }

    mMenu.onItemsChanged(false);

    return this;
  }
Exemplo n.º 17
0
  public void removeGroup(int group) {
    final int i = findGroupIndex(group);

    if (i >= 0) {
      final int maxRemovable = mItems.size() - i;
      int numRemoved = 0;
      while ((numRemoved++ < maxRemovable) && (mItems.get(i).getGroupId() == group)) {
        // Don't force update for each one, this method will do it at the end
        removeItemAtInt(i, false);
      }

      // Notify menu views
      onItemsChanged(true);
    }
  }
Exemplo n.º 18
0
  public void setGroupVisible(int group, boolean visible) {
    final int N = mItems.size();

    // We handle the notification of items being changed ourselves, so we use setVisibleInt rather
    // than setVisible and at the end notify of items being changed

    boolean changedAtLeastOneItem = false;
    for (int i = 0; i < N; i++) {
      MenuItemImpl item = mItems.get(i);
      if (item.getGroupId() == group) {
        if (item.setVisibleInt(visible)) changedAtLeastOneItem = true;
      }
    }

    if (changedAtLeastOneItem) onItemsChanged(true);
  }
Exemplo n.º 19
0
  /** * Adds an item to the menu. The other add methods funnel to this. */
  private MenuItem addInternal(int group, int id, int categoryOrder, CharSequence title) {
    final int ordering = getOrdering(categoryOrder);

    final MenuItemImpl item =
        new MenuItemImpl(this, group, id, categoryOrder, ordering, title, mDefaultShowAsAction);

    if (mCurrentMenuInfo != null) {
      // Pass along the current menu info
      item.setMenuInfo(mCurrentMenuInfo);
    }

    mItems.add(findInsertIndex(mItems, ordering), item);
    onItemsChanged(true);

    return item;
  }
 public MenuItem setActionProvider(ActionProvider actionProvider) {
   if (mActionProvider != null) {
     mActionProvider.setVisibilityListener(null);
   }
   mActionView = null;
   mActionProvider = actionProvider;
   mMenu.onItemsChanged(true); // Measurement can be changed
   if (mActionProvider != null) {
     mActionProvider.setVisibilityListener(
         new ActionProvider.VisibilityListener() {
           @Override
           public void onActionProviderVisibilityChanged(boolean isVisible) {
             mMenu.onItemVisibleChanged(MenuItemImpl.this);
           }
         });
   }
   return this;
 }
Exemplo n.º 21
0
 /**
  * * Called by {@link MenuItemImpl} when its action request status is changed.
  *
  * @param item The item that has gone through a change in action request status.
  */
 void onItemActionRequestChanged(MenuItemImpl item) {
   // Notify of items being changed
   mIsActionItemsStale = true;
   onItemsChanged(true);
 }
Exemplo n.º 22
0
 /**
  * * Called by {@link MenuItemImpl} when its visible flag is changed.
  *
  * @param item The item that has gone through a visibility change.
  */
 void onItemVisibleChanged(MenuItemImpl item) {
   // Notify of items being changed
   mIsVisibleItemsStale = true;
   onItemsChanged(true);
 }
Exemplo n.º 23
0
  /**
   * * Sets whether the shortcuts should be visible on menus. Devices without hardware key input
   * will never make shortcuts visible even if this method is passed 'true'.
   *
   * @param shortcutsVisible Whether shortcuts should be visible (if true and a menu item does not
   *     have a shortcut defined, that item will still NOT show a shortcut)
   */
  public void setShortcutsVisible(boolean shortcutsVisible) {
    if (mShortcutsVisible == shortcutsVisible) return;

    setShortcutsVisibleInner(shortcutsVisible);
    onItemsChanged(false);
  }
Exemplo n.º 24
0
  public void setQwertyMode(boolean isQwerty) {
    mQwertyMode = isQwerty;

    onItemsChanged(false);
  }
 public void setActionViewExpanded(boolean isExpanded) {
   mIsActionViewExpanded = isExpanded;
   mMenu.onItemsChanged(false);
 }