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

Commit 3f476b34 authored by Adam Powell's avatar Adam Powell
Browse files

Revisiting ActionBar API and layout.

Fix several bugs where ActionBar was ignoring LayoutParams in action
views.

Add convenience methods for toggling display options flags.

Add layout resource version of ActionBar#setCustomView

Fix a bug preventing actionViewClasses from being loaded properly in
menu xml.

Change-Id: I0d9a0b635fd9cfc020bac69369c0c7749c226349
parent eb492a02
Loading
Loading
Loading
Loading
+92 −1
Original line number Diff line number Diff line
@@ -21662,6 +21662,32 @@
<parameter name="layoutParams" type="android.app.ActionBar.LayoutParams">
</parameter>
</method>
<method name="setCustomView"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="resId" type="int">
</parameter>
</method>
<method name="setDisplayHomeAsUpEnabled"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="showHomeAsUp" type="boolean">
</parameter>
</method>
<method name="setDisplayOptions"
 return="void"
 abstract="true"
@@ -21690,6 +21716,58 @@
<parameter name="mask" type="int">
</parameter>
</method>
<method name="setDisplayShowCustomEnabled"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="showCustom" type="boolean">
</parameter>
</method>
<method name="setDisplayShowHomeEnabled"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="showHome" type="boolean">
</parameter>
</method>
<method name="setDisplayShowTitleEnabled"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="showTitle" type="boolean">
</parameter>
</method>
<method name="setDisplayUseLogoEnabled"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="useLogo" type="boolean">
</parameter>
</method>
<method name="setDropdownNavigationMode"
 return="void"
 abstract="true"
@@ -208325,6 +208403,19 @@
<parameter name="view" type="android.view.View">
</parameter>
</method>
<method name="setActionView"
 return="android.view.MenuItem"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="resId" type="int">
</parameter>
</method>
<method name="setAlphabeticShortcut"
 return="android.view.MenuItem"
 abstract="true"
@@ -257495,7 +257586,7 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="t" type="T">
<parameter name="arg0" type="T">
</parameter>
</method>
</interface>
+85 −1
Original line number Diff line number Diff line
@@ -153,6 +153,25 @@ public abstract class ActionBar {
     */
    public abstract void setCustomView(View view, LayoutParams layoutParams);

    /**
     * Set the action bar into custom navigation mode, supplying a view
     * for custom navigation.
     *
     * <p>Custom navigation views appear between the application icon and
     * any action buttons and may use any space available there. Common
     * use cases for custom navigation views might include an auto-suggesting
     * address bar for a browser or other navigation mechanisms that do not
     * translate well to provided navigation modes.</p>
     *
     * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
     * the custom view to be displayed.</p>
     *
     * @param resId Resource ID of a layout to inflate into the ActionBar.
     *
     * @see #setDisplayOptions(int, int)
     */
    public abstract void setCustomView(int resId);

    /**
     * @param view
     * @deprecated Use {@link #setCustomView(View)} and {@link #setDisplayOptions(int)} instead.
@@ -320,6 +339,71 @@ public abstract class ActionBar {
     */
    public abstract void setDisplayOptions(int options, int mask);

    /**
     * Set whether to display the activity logo rather than the activity icon.
     * A logo is often a wider, more detailed image.
     *
     * <p>To set several display options at once, see the setDisplayOptions methods.
     *
     * @param useLogo true to use the activity logo, false to use the activity icon.
     *
     * @see #setDisplayOptions(int)
     * @see #setDisplayOptions(int, int)
     */
    public abstract void setDisplayUseLogoEnabled(boolean useLogo);

    /**
     * Set whether to include the application home affordance in the action bar.
     * Home is presented as either an activity icon or logo.
     *
     * <p>To set several display options at once, see the setDisplayOptions methods.
     *
     * @param showHome true to show home, false otherwise.
     *
     * @see #setDisplayOptions(int)
     * @see #setDisplayOptions(int, int)
     */
    public abstract void setDisplayShowHomeEnabled(boolean showHome);

    /**
     * Set whether home should be displayed as an "up" affordance.
     * Set this to true if selecting "home" returns up by a single level in your UI
     * rather than back to the top level or front page.
     *
     * <p>To set several display options at once, see the setDisplayOptions methods.
     *
     * @param showHomeAsUp true to show the user that selecting home will return one
     *                     level up rather than to the top level of the app.
     *
     * @see #setDisplayOptions(int)
     * @see #setDisplayOptions(int, int)
     */
    public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);

    /**
     * Set whether an activity title/subtitle should be displayed.
     *
     * <p>To set several display options at once, see the setDisplayOptions methods.
     *
     * @param showTitle true to display a title/subtitle if present.
     *
     * @see #setDisplayOptions(int)
     * @see #setDisplayOptions(int, int)
     */
    public abstract void setDisplayShowTitleEnabled(boolean showTitle);

    /**
     * Set whether a custom view should be displayed, if set.
     *
     * <p>To set several display options at once, see the setDisplayOptions methods.
     *
     * @param showCustom true if the currently set custom view should be displayed, false otherwise.
     *
     * @see #setDisplayOptions(int)
     * @see #setDisplayOptions(int, int)
     */
    public abstract void setDisplayShowCustomEnabled(boolean showCustom);

    /**
     * Set the ActionBar's background.
     * 
+3 −3
Original line number Diff line number Diff line
@@ -379,15 +379,15 @@ public class MenuInflater {

            if (itemActionViewClassName != null) {
                try {
                    final Class<?> clazz = Class.forName(itemActionViewClassName);
                    final Class<?> clazz = Class.forName(itemActionViewClassName, true,
                            mContext.getClassLoader());
                    Constructor<?> c = clazz.getConstructor(ACTION_VIEW_CONSTRUCTOR_SIGNATURE);
                    item.setActionView((View) c.newInstance(mContext));
                } catch (Exception e) {
                    throw new InflateException(e);
                }
            } else if (itemActionViewLayout > 0) {
                final LayoutInflater inflater = LayoutInflater.from(mContext);
                item.setActionView(inflater.inflate(itemActionViewLayout, null));
                item.setActionView(itemActionViewLayout);
            }
        }
        
+12 −0
Original line number Diff line number Diff line
@@ -432,6 +432,18 @@ public interface MenuItem {
     */
    public MenuItem setActionView(View view);

    /**
     * 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
     * as an action within a parent.
     *
     * @param resId Layout resource to use for presenting this item to the user.
     * @return This Item so additional setters can be called.
     *
     * @see #setShowAsAction(int)
     */
    public MenuItem setActionView(int resId);

    /**
     * Returns the currently set action view for this menu item.
     *
+30 −0
Original line number Diff line number Diff line
@@ -237,6 +237,36 @@ public class ActionBarImpl extends ActionBar {
        }
    }

    @Override
    public void setCustomView(int resId) {
        setCustomView(LayoutInflater.from(mContext).inflate(resId, mActionView, false));
    }

    @Override
    public void setDisplayUseLogoEnabled(boolean useLogo) {
        setDisplayOptions(useLogo ? DISPLAY_USE_LOGO : 0, DISPLAY_USE_LOGO);
    }

    @Override
    public void setDisplayShowHomeEnabled(boolean showHome) {
        setDisplayOptions(showHome ? DISPLAY_SHOW_HOME : 0, DISPLAY_SHOW_HOME);
    }

    @Override
    public void setDisplayHomeAsUpEnabled(boolean showHomeAsUp) {
        setDisplayOptions(showHomeAsUp ? DISPLAY_HOME_AS_UP : 0, DISPLAY_HOME_AS_UP);
    }

    @Override
    public void setDisplayShowTitleEnabled(boolean showTitle) {
        setDisplayOptions(showTitle ? DISPLAY_SHOW_TITLE : 0, DISPLAY_SHOW_TITLE);
    }

    @Override
    public void setDisplayShowCustomEnabled(boolean showCustom) {
        setDisplayOptions(showCustom ? DISPLAY_SHOW_CUSTOM : 0, DISPLAY_SHOW_CUSTOM);
    }

    @Override
    public void setTitle(int resId) {
        setTitle(mContext.getString(resId));
Loading