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

Commit a1b06eba authored by Daniel Santiago Rivera's avatar Daniel Santiago Rivera
Browse files

Add setter and getter for Toolbar's collapse icon.

Bug: 78187236
Test: make java
Change-Id: Id0faacaa95c8c4ee54b3dec66e3b16e589ebd370
parent ab73b70e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -54060,6 +54060,8 @@ package android.widget {
    method protected android.widget.Toolbar.LayoutParams generateDefaultLayoutParams();
    method public android.widget.Toolbar.LayoutParams generateLayoutParams(android.util.AttributeSet);
    method protected android.widget.Toolbar.LayoutParams generateLayoutParams(android.view.ViewGroup.LayoutParams);
    method public java.lang.CharSequence getCollapseContentDescription();
    method public android.graphics.drawable.Drawable getCollapseIcon();
    method public int getContentInsetEnd();
    method public int getContentInsetEndWithActions();
    method public int getContentInsetLeft();
@@ -54087,6 +54089,10 @@ package android.widget {
    method public boolean hideOverflowMenu();
    method public void inflateMenu(int);
    method public boolean isOverflowMenuShowing();
    method public void setCollapseContentDescription(int);
    method public void setCollapseContentDescription(java.lang.CharSequence);
    method public void setCollapseIcon(int);
    method public void setCollapseIcon(android.graphics.drawable.Drawable);
    method public void setContentInsetEndWithActions(int);
    method public void setContentInsetStartWithNavigation(int);
    method public void setContentInsetsAbsolute(int, int);
+92 −0
Original line number Diff line number Diff line
@@ -1007,6 +1007,98 @@ public class Toolbar extends ViewGroup {
        return mNavButtonView;
    }

    /**
     * Retrieve the currently configured content description for the collapse button view.
     * This will be used to describe the collapse action to users through mechanisms such
     * as screen readers or tooltips.
     *
     * @return The collapse button's content description
     *
     * @attr ref android.R.styleable#Toolbar_collapseContentDescription
     */
    @Nullable
    public CharSequence getCollapseContentDescription() {
        return mCollapseButtonView != null ? mCollapseButtonView.getContentDescription() : null;
    }

    /**
     * Set a content description for the collapse button if one is present. The content description
     * will be read via screen readers or other accessibility systems to explain the action of the
     * collapse button.
     *
     * @param resId Resource ID of a content description string to set, or 0 to
     *              clear the description
     *
     * @attr ref android.R.styleable#Toolbar_collapseContentDescription
     */
    public void setCollapseContentDescription(@StringRes int resId) {
        setCollapseContentDescription(resId != 0 ? getContext().getText(resId) : null);
    }

    /**
     * Set a content description for the collapse button if one is present. The content description
     * will be read via screen readers or other accessibility systems to explain the action of the
     * navigation button.
     *
     * @param description Content description to set, or <code>null</code> to
     *                    clear the content description
     *
     * @attr ref android.R.styleable#Toolbar_collapseContentDescription
     */
    public void setCollapseContentDescription(@Nullable CharSequence description) {
        if (!TextUtils.isEmpty(description)) {
            ensureCollapseButtonView();
        }
        if (mCollapseButtonView != null) {
            mCollapseButtonView.setContentDescription(description);
        }
    }

    /**
     * Return the current drawable used as the collapse icon.
     *
     * @return The collapse icon drawable
     *
     * @attr ref android.R.styleable#Toolbar_collapseIcon
     */
    @Nullable
    public Drawable getCollapseIcon() {
        return mCollapseButtonView != null ? mCollapseButtonView.getDrawable() : null;
    }

    /**
     * Set the icon to use for the toolbar's collapse button.
     *
     * <p>The collapse button appears at the start of the toolbar when an action view is present
     * .</p>
     *
     * @param resId Resource ID of a drawable to set
     *
     * @attr ref android.R.styleable#Toolbar_collapseIcon
     */
    public void setCollapseIcon(@DrawableRes int resId) {
        setCollapseIcon(getContext().getDrawable(resId));
    }

    /**
     * Set the icon to use for the toolbar's collapse button.
     *
     * <p>The collapse button appears at the start of the toolbar when an action view is present
     * .</p>
     *
     * @param icon Drawable to set, may be null to use the default icon
     *
     * @attr ref android.R.styleable#Toolbar_collapseIcon
     */
    public void setCollapseIcon(@Nullable Drawable icon) {
        if (icon != null) {
            ensureCollapseButtonView();
            mCollapseButtonView.setImageDrawable(icon);
        } else if (mCollapseButtonView != null) {
            mCollapseButtonView.setImageDrawable(mCollapseIcon);
        }
    }

    /**
     * Return the Menu shown in the toolbar.
     *