Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dfb25e20 authored by Adam Powell's avatar Adam Powell Committed by Android (Google) Code Review
Browse files

Merge "Implement bug 4500971 - Collapsable action views"

parents 77c1cc0a 8d02deab
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -20972,6 +20972,8 @@ package android.view {
  }
  public abstract interface MenuItem {
    method public abstract boolean collapseActionView();
    method public abstract boolean expandActionView();
    method public abstract android.view.View getActionView();
    method public abstract char getAlphabeticShortcut();
    method public abstract int getGroupId();
@@ -20985,6 +20987,7 @@ package android.view {
    method public abstract java.lang.CharSequence getTitle();
    method public abstract java.lang.CharSequence getTitleCondensed();
    method public abstract boolean hasSubMenu();
    method public abstract boolean isActionViewExpanded();
    method public abstract boolean isCheckable();
    method public abstract boolean isChecked();
    method public abstract boolean isEnabled();
@@ -20999,19 +21002,27 @@ package android.view {
    method public abstract android.view.MenuItem setIcon(int);
    method public abstract android.view.MenuItem setIntent(android.content.Intent);
    method public abstract android.view.MenuItem setNumericShortcut(char);
    method public abstract android.view.MenuItem setOnActionExpandListener(android.view.MenuItem.OnActionExpandListener);
    method public abstract android.view.MenuItem setOnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener);
    method public abstract android.view.MenuItem setShortcut(char, char);
    method public abstract void setShowAsAction(int);
    method public abstract android.view.MenuItem setShowAsActionFlags(int);
    method public abstract android.view.MenuItem setTitle(java.lang.CharSequence);
    method public abstract android.view.MenuItem setTitle(int);
    method public abstract android.view.MenuItem setTitleCondensed(java.lang.CharSequence);
    method public abstract android.view.MenuItem setVisible(boolean);
    field public static final int SHOW_AS_ACTION_ALWAYS = 2; // 0x2
    field public static final int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW = 8; // 0x8
    field public static final int SHOW_AS_ACTION_IF_ROOM = 1; // 0x1
    field public static final int SHOW_AS_ACTION_NEVER = 0; // 0x0
    field public static final int SHOW_AS_ACTION_WITH_TEXT = 4; // 0x4
  }
  public static abstract interface MenuItem.OnActionExpandListener {
    method public abstract boolean onMenuItemActionCollapse(android.view.MenuItem);
    method public abstract boolean onMenuItemActionExpand(android.view.MenuItem);
  }
  public static abstract interface MenuItem.OnMenuItemClickListener {
    method public abstract boolean onMenuItemClick(android.view.MenuItem);
  }
+104 −0
Original line number Diff line number Diff line
@@ -52,6 +52,13 @@ public interface MenuItem {
     */
    public static final int SHOW_AS_ACTION_WITH_TEXT = 4;

    /**
     * This item's action view collapses to a normal menu item.
     * When expanded, the action view temporarily takes over
     * a larger segment of its container.
     */
    public static final int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW = 8;
    
    /**
     * Interface definition for a callback to be invoked when a menu item is
     * clicked.
@@ -73,6 +80,34 @@ public interface MenuItem {
        public boolean onMenuItemClick(MenuItem item);
    }

    /**
     * Interface definition for a callback to be invoked when a menu item
     * marked with {@link MenuItem#SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW} is
     * expanded or collapsed.
     *
     * @see MenuItem#expandActionView()
     * @see MenuItem#collapseActionView()
     * @see MenuItem#setShowAsActionFlags(int)
     * @see MenuItem#
     */
    public interface OnActionExpandListener {
        /**
         * Called when a menu item with {@link MenuItem#SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}
         * is expanded.
         * @param item Item that was expanded
         * @return true if the item should expand, false if expansion should be suppressed.
         */
        public boolean onMenuItemActionExpand(MenuItem item);

        /**
         * Called when a menu item with {@link MenuItem#SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}
         * is collapsed.
         * @param item Item that was collapsed
         * @return true if the item should collapse, false if collapsing should be suppressed.
         */
        public boolean onMenuItemActionCollapse(MenuItem item);
    }

    /**
     * Return the identifier for this menu item.  The identifier can not
     * be changed after the menu is created.
@@ -420,6 +455,27 @@ public interface MenuItem {
     */
    public void setShowAsAction(int actionEnum);

    /**
     * Sets how this item should display in the presence of an Action Bar.
     * The parameter actionEnum is a flag set. One of {@link #SHOW_AS_ACTION_ALWAYS},
     * {@link #SHOW_AS_ACTION_IF_ROOM}, or {@link #SHOW_AS_ACTION_NEVER} should
     * be used, and you may optionally OR the value with {@link #SHOW_AS_ACTION_WITH_TEXT}.
     * SHOW_AS_ACTION_WITH_TEXT requests that when the item is shown as an action,
     * it should be shown with a text label.
     *
     * <p>Note: This method differs from {@link #setShowAsAction(int)} only in that it
     * returns the current MenuItem instance for call chaining.
     *
     * @param actionEnum How the item should display. One of
     * {@link #SHOW_AS_ACTION_ALWAYS}, {@link #SHOW_AS_ACTION_IF_ROOM}, or
     * {@link #SHOW_AS_ACTION_NEVER}. SHOW_AS_ACTION_NEVER is the default.
     *
     * @see android.app.ActionBar
     * @see #setActionView(View)
     * @return This MenuItem instance for call chaining.
     */
    public MenuItem setShowAsActionFlags(int actionEnum);

    /**
     * Set an action view for this menu item. An action view will be displayed in place
     * of an automatically generated menu item element in the UI when this item is shown
@@ -453,4 +509,52 @@ public interface MenuItem {
     * @see #setShowAsAction(int)
     */
    public View getActionView();

    /**
     * Expand the action view associated with this menu item.
     * The menu item must have an action view set, as well as
     * the showAsAction flag {@link #SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}.
     * If a listener has been set using {@link #setOnActionExpandListener(OnActionExpandListener)}
     * it will have its {@link OnActionExpandListener#onMenuItemActionExpand(MenuItem)}
     * method invoked. The listener may return false from this method to prevent expanding
     * the action view.
     *
     * @return true if the action view was expanded, false otherwise.
     */
    public boolean expandActionView();

    /**
     * Collapse the action view associated with this menu item.
     * The menu item must have an action view set, as well as the showAsAction flag
     * {@link #SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}. If a listener has been set using
     * {@link #setOnActionExpandListener(OnActionExpandListener)} it will have its
     * {@link OnActionExpandListener#onMenuItemActionCollapse(MenuItem)} method invoked.
     * The listener may return false from this method to prevent collapsing the action view.
     *
     * @return true if the action view was collapsed, false otherwise.
     */
    public boolean collapseActionView();

    /**
     * Returns true if this menu item's action view has been expanded.
     *
     * @return true if the item's action view is expanded, false otherwise.
     *
     * @see #expandActionView()
     * @see #collapseActionView()
     * @see #SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
     * @see OnActionExpandListener
     */
    public boolean isActionViewExpanded();

    /**
     * Set an {@link OnActionExpandListener} on this menu item to be notified when
     * the associated action view is expanded or collapsed. The menu item must
     * be configured to expand or collapse its action view using the flag
     * {@link #SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW}.
     *
     * @param listener Listener that will respond to expand/collapse events
     * @return This menu item instance for call chaining
     */
    public MenuItem setOnActionExpandListener(OnActionExpandListener listener);
}
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
@@ -236,4 +236,31 @@ public class ActionMenuItem implements MenuItem {
    public MenuItem setActionView(int resId) {
        throw new UnsupportedOperationException();
    }

    @Override
    public MenuItem setShowAsActionFlags(int actionEnum) {
        setShowAsAction(actionEnum);
        return this;
    }

    @Override
    public boolean expandActionView() {
        return false;
    }

    @Override
    public boolean collapseActionView() {
        return false;
    }

    @Override
    public boolean isActionViewExpanded() {
        return false;
    }

    @Override
    public MenuItem setOnActionExpandListener(OnActionExpandListener listener) {
        // No need to save the listener; ActionMenuItem does not support collapsing items.
        return this;
    }
}
+7 −4
Original line number Diff line number Diff line
@@ -112,8 +112,11 @@ public class ActionMenuPresenter extends BaseMenuPresenter {

    @Override
    public View getItemView(MenuItemImpl item, View convertView, ViewGroup parent) {
        final View actionView = item.getActionView();
        return actionView != null ? actionView : super.getItemView(item, convertView, parent);
        View actionView = item.getActionView();
        actionView = actionView != null && !item.hasCollapsibleActionView() ?
                actionView : super.getItemView(item, convertView, parent);
        actionView.setVisibility(item.isActionViewExpanded() ? View.GONE : View.VISIBLE);
        return actionView;
    }

    @Override
@@ -303,7 +306,7 @@ public class ActionMenuPresenter extends BaseMenuPresenter {

            if (item.requiresActionButton()) {
                View v = item.getActionView();
                if (v == null) {
                if (v == null || item.hasCollapsibleActionView()) {
                    v = getItemView(item, mScrapActionButtonView, parent);
                    if (mScrapActionButtonView == null) {
                        mScrapActionButtonView = v;
@@ -329,7 +332,7 @@ public class ActionMenuPresenter extends BaseMenuPresenter {

                if (isAction) {
                    View v = item.getActionView();
                    if (v == null) {
                    if (v == null || item.hasCollapsibleActionView()) {
                        v = getItemView(item, mScrapActionButtonView, parent);
                        if (mScrapActionButtonView == null) {
                            mScrapActionButtonView = v;
+8 −0
Original line number Diff line number Diff line
@@ -192,4 +192,12 @@ public abstract class BaseMenuPresenter implements MenuPresenter {
    public boolean flagActionItems() {
        return false;
    }

    public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) {
        return false;
    }

    public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) {
        return false;
    }
}
Loading