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

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

Merge "Dropdown mode for ActionBar; style and API updates"

parents 1a0ce1cc a408291e
Loading
Loading
Loading
Loading
+42 −10
Original line number Diff line number Diff line
@@ -19417,7 +19417,7 @@
<parameter name="callback" type="android.app.ActionBar.Callback">
</parameter>
</method>
<method name="setCustomNavigationView"
<method name="setCustomNavigationMode"
 return="void"
 abstract="true"
 native="false"
@@ -19471,7 +19471,7 @@
<parameter name="d" type="android.graphics.drawable.Drawable">
</parameter>
</method>
<method name="setNavigationMode"
<method name="setDropdownNavigationMode"
 return="void"
 abstract="true"
 native="false"
@@ -19481,10 +19481,10 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="mode" type="int">
<parameter name="adapter" type="android.widget.SpinnerAdapter">
</parameter>
</method>
<method name="setSubtitle"
<method name="setStandardNavigationMode"
 return="void"
 abstract="true"
 native="false"
@@ -19494,10 +19494,12 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="title" type="java.lang.CharSequence">
</parameter>
<parameter name="subtitle" type="java.lang.CharSequence">
</parameter>
</method>
<method name="setTitle"
<method name="setStandardNavigationMode"
 return="void"
 abstract="true"
 native="false"
@@ -19565,7 +19567,7 @@
 visibility="public"
>
</field>
<field name="NAVIGATION_MODE_NORMAL"
<field name="NAVIGATION_MODE_STANDARD"
 type="int"
 transient="false"
 volatile="false"
@@ -19595,7 +19597,7 @@
 deprecated="not deprecated"
 visibility="public"
>
<method name="onActionItemSelected"
<method name="onActionItemClicked"
 return="boolean"
 abstract="true"
 native="false"
@@ -19608,7 +19610,7 @@
<parameter name="item" type="android.view.MenuItem">
</parameter>
</method>
<method name="onContextItemSelected"
<method name="onContextItemClicked"
 return="boolean"
 abstract="true"
 native="false"
@@ -19651,6 +19653,21 @@
<parameter name="menu" type="android.view.Menu">
</parameter>
</method>
<method name="onNavigationItemSelected"
 return="boolean"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="itemPosition" type="int">
</parameter>
<parameter name="itemId" type="long">
</parameter>
</method>
<method name="onPrepareContextMode"
 return="boolean"
 abstract="true"
@@ -19698,7 +19715,7 @@
 visibility="public"
>
</constructor>
<method name="onActionItemSelected"
<method name="onActionItemClicked"
 return="boolean"
 abstract="false"
 native="false"
@@ -19711,7 +19728,7 @@
<parameter name="item" type="android.view.MenuItem">
</parameter>
</method>
<method name="onContextItemSelected"
<method name="onContextItemClicked"
 return="boolean"
 abstract="false"
 native="false"
@@ -19754,6 +19771,21 @@
<parameter name="menu" type="android.view.Menu">
</parameter>
</method>
<method name="onNavigationItemSelected"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="itemPosition" type="int">
</parameter>
<parameter name="itemId" type="long">
</parameter>
</method>
<method name="onPrepareContextMode"
 return="boolean"
 abstract="false"
+78 −38
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.SpinnerAdapter;

/**
 * This is the public interface to the contextual ActionBar.
@@ -29,12 +31,12 @@ import android.view.View;
 */
public abstract class ActionBar {
    /**
     * Normal/standard navigation mode. Consists of either a logo or icon
     * Standard navigation mode. Consists of either a logo or icon
     * and title text with an optional subtitle. Clicking any of these elements
     * will dispatch onActionItemSelected to the registered Callback with
     * a MenuItem with item ID android.R.id.home.
     */
    public static final int NAVIGATION_MODE_NORMAL = 0;
    public static final int NAVIGATION_MODE_STANDARD = 0;
    
    /**
     * Dropdown list navigation mode. Instead of static title text this mode
@@ -74,48 +76,51 @@ public abstract class ActionBar {
    public abstract void setCallback(Callback callback);
    
    /**
     * Set a custom navigation view.
     * Set the action bar into custom navigation mode, supplying a view
     * for custom navigation.
     * 
     * 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 address bar
     * for a browser or other navigation mechanisms that do not translate
     * well to provided navigation modes.
     * 
     * Setting a non-null custom navigation view will also set the
     * navigation mode to NAVMODE_CUSTOM.
     * 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.
     * 
     * @param view Custom navigation view to place in the ActionBar.
     */
    public abstract void setCustomNavigationView(View view);
    public abstract void setCustomNavigationMode(View view);
    
    /**
     * Set the ActionBar's title.
     * 
     * This is set automatically to the name of your Activity,
     * but may be changed here.
     * Set the action bar into dropdown navigation mode and supply an adapter
     * that will provide views for navigation choices.
     * 
     * @param title Title text
     * @param adapter An adapter that will provide views both to display
     *                the current navigation selection and populate views
     *                within the dropdown navigation menu.
     */
    public abstract void setTitle(CharSequence title);
    public abstract void setDropdownNavigationMode(SpinnerAdapter adapter);

    /**
     * Set the ActionBar's subtitle.
     * Set the action bar into standard navigation mode, supplying a title and subtitle.
     * 
     * The subtitle is usually displayed as a second line of text
     * under the title. Good for extended descriptions of activity state.
     * Standard navigation mode is default. The title is automatically set to the
     * name of your Activity. Subtitles are displayed underneath the title, usually
     * in a smaller font or otherwise less prominently than the title. Subtitles are
     * good for extended descriptions of activity state.
     *
     * @param subtitle Subtitle text. 
     * @param title The action bar's title. null is treated as an empty string.
     * @param subtitle The action bar's subtitle. null is treated as an empty string.
     */
    public abstract void setSubtitle(CharSequence subtitle);
    public abstract void setStandardNavigationMode(CharSequence title, CharSequence subtitle);

    /**
     * Set the navigation mode.
     * Set the action bar into standard navigation mode, supplying a title and subtitle.
     * 
     * @param mode One of {@link #NAVIGATION_MODE_NORMAL}, {@link #NAVIGATION_MODE_DROPDOWN_LIST},
     * {@link #NAVIGATION_MODE_TABS}, or {@link #NAVIGATION_MODE_CUSTOM}.
     * Standard navigation mode is default. The title is automatically set to the
     * name of your Activity.
     *
     * @param title The action bar's title. null is treated as an empty string.
     */
    public abstract void setNavigationMode(int mode);
    public abstract void setStandardNavigationMode(CharSequence title);

    /**
     * Set display options. This changes all display option bits at once. To change
@@ -161,17 +166,38 @@ public abstract class ActionBar {
    public abstract View getCustomNavigationView();
    
    /**
     * @return The current ActionBar title.
     * Returns the current ActionBar title in standard mode.
     * Returns null if {@link #getNavigationMode()} would not return
     * {@link #NAVIGATION_MODE_STANDARD}. 
     *
     * @return The current ActionBar title or null.
     */
    public abstract CharSequence getTitle();
    
    /**
     * @return The current ActionBar subtitle.
     * Returns the current ActionBar subtitle in standard mode.
     * Returns null if {@link #getNavigationMode()} would not return
     * {@link #NAVIGATION_MODE_STANDARD}. 
     *
     * @return The current ActionBar subtitle or null.
     */
    public abstract CharSequence getSubtitle();
    
    /**
     * Returns the current navigation mode. The result will be one of:
     * <ul>
     * <li>{@link #NAVIGATION_MODE_STANDARD}</li>
     * <li>{@link #NAVIGATION_MODE_DROPDOWN_LIST}</li>
     * <li>{@link #NAVIGATION_MODE_TABS}</li>
     * <li>{@link #NAVIGATION_MODE_CUSTOM}</li>
     * </ul>
     *
     * @return The current navigation mode.
     * 
     * @see #setStandardNavigationMode(CharSequence)
     * @see #setStandardNavigationMode(CharSequence, CharSequence)
     * @see #setDropdownNavigationMode(SpinnerAdapter)
     * @see #setCustomNavigationMode(View)
     */
    public abstract int getNavigationMode();
    
@@ -201,7 +227,7 @@ public abstract class ActionBar {
         * @return You must return true for actions to be displayed;
         *         if you return false they will not be shown.
         *
         * @see #onActionItemSelected(MenuItem)
         * @see #onActionItemClicked(MenuItem)
         */
        public boolean onCreateActionMenu(Menu menu);

@@ -215,7 +241,7 @@ public abstract class ActionBar {
        public boolean onUpdateActionMenu(Menu menu);

        /**
         * This hook is called whenever an item in your action bar is selected.
         * This hook is called whenever an action item in your action bar is clicked.
         * The default implementation simply returns false to have the normal
         * processing happen (sending a message to its handler). You can use this
         * method for any items for which you would like to do processing without
@@ -225,14 +251,24 @@ public abstract class ActionBar {
         * @return boolean Return false to allow normal menu processing to proceed,
         *         true to consume it here.
         */
        public boolean onActionItemSelected(MenuItem item);
        public boolean onActionItemClicked(MenuItem item);
        
        /**
         * This method is called whenever a navigation item in your action bar
         * is selected.
         *    
         * @param itemPosition Position of the item clicked.
         * @param itemId ID of the item clicked.
         * @return True if the event was handled, false otherwise.
         */
        public boolean onNavigationItemSelected(int itemPosition, long itemId);
        
        /*
         * In progress
         */
        public boolean onCreateContextMode(int modeId, Menu menu);
        public boolean onPrepareContextMode(int modeId, Menu menu);
        public boolean onContextItemSelected(int modeId, MenuItem item);
        public boolean onContextItemClicked(int modeId, MenuItem item);
    }
    
    /**
@@ -248,7 +284,7 @@ public abstract class ActionBar {
            return false;
        }
        
        public boolean onActionItemSelected(MenuItem item) {
        public boolean onActionItemClicked(MenuItem item) {
            return false;
        }
        
@@ -260,7 +296,11 @@ public abstract class ActionBar {
            return false;
        }
        
        public boolean onContextItemSelected(int modeId, MenuItem item) {
        public boolean onContextItemClicked(int modeId, MenuItem item) {
            return false;
        }

        public boolean onNavigationItemSelected(int itemPosition, long itemId) {
            return false;
        }
    }
+68 −25
Original line number Diff line number Diff line
@@ -31,7 +31,10 @@ import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.SparseArray;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import com.android.internal.R;
@@ -78,12 +81,12 @@ public class ActionBarView extends ViewGroup {
    private ImageView mLogoView;
    private TextView mTitleView;
    private TextView mSubtitleView;
    private View mNavigationView;
    private Spinner mSpinner;
    private View mCustomNavView;
    
    private boolean mShowMenu;

    private ActionMenuItem mLogoNavItem;
    private ActionMenu mNavMenu;
    private ActionMenu mActionMenu;
    private ActionMenu mOptionsMenu;
    
@@ -97,12 +100,24 @@ public class ActionBarView extends ViewGroup {
            ActionView av = (ActionView) v;
            ActionMenuItem item = (ActionMenuItem) av.menuItem;

            if (!mCallback.onActionItemSelected(item)) {
            if (mCallback == null || !mCallback.onActionItemClicked(item)) {
                item.invoke();
            }
        }
    };

    private final AdapterView.OnItemSelectedListener mNavItemSelectedListener =
            new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView parent, View view, int position, long id) {
            if (mCallback != null) {
                mCallback.onNavigationItemSelected(position, id);
            }
        }
        public void onNothingSelected(AdapterView parent) {
            // Do nothing
        }
    };

    private OnClickListener mHomeClickListener = null;

    public ActionBarView(Context context, AttributeSet attrs) {
@@ -123,7 +138,7 @@ public class ActionBarView extends ViewGroup {

        ApplicationInfo info = context.getApplicationInfo();
        PackageManager pm = context.getPackageManager();
        mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode, ActionBar.NAVIGATION_MODE_NORMAL);
        mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode, ActionBar.NAVIGATION_MODE_STANDARD);
        mTitle = a.getText(R.styleable.ActionBar_title);
        mSubtitle = a.getText(R.styleable.ActionBar_subtitle);
        mDisplayOptions = a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT);
@@ -146,7 +161,7 @@ public class ActionBarView extends ViewGroup {
        final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
        if (customNavId != 0) {
            LayoutInflater inflater = LayoutInflater.from(context);
            mNavigationView = (View) inflater.inflate(customNavId, null);
            mCustomNavView = (View) inflater.inflate(customNavId, null);
            mNavigationMode = ActionBar.NAVIGATION_MODE_CUSTOM;
        }

@@ -164,7 +179,7 @@ public class ActionBarView extends ViewGroup {
            mHomeClickListener = new OnClickListener() {
                public void onClick(View v) {
                    if (mCallback != null) {
                        mCallback.onActionItemSelected(mLogoNavItem);
                        mCallback.onActionItemClicked(mLogoNavItem);
                    }
                }
            };
@@ -201,7 +216,7 @@ public class ActionBarView extends ViewGroup {
    }
    
    public void setCustomNavigationView(View view) {
        mNavigationView = view;
        mCustomNavView = view;
        if (view != null) {
            setNavigationMode(ActionBar.NAVIGATION_MODE_CUSTOM);
        }
@@ -258,25 +273,38 @@ public class ActionBarView extends ViewGroup {
        final int oldMode = mNavigationMode;
        if (mode != oldMode) {
            switch (oldMode) {
            case ActionBar.NAVIGATION_MODE_NORMAL:
            case ActionBar.NAVIGATION_MODE_STANDARD:
                if (mTitleView != null) {
                    removeView(mTitleView);
                    mTitleView = null;
                }
                break;
            case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
                if (mSpinner != null) {
                    removeView(mSpinner);
                    mSpinner = null;
                }
                break;
            case ActionBar.NAVIGATION_MODE_CUSTOM:
                if (mNavigationView != null) {
                    removeView(mNavigationView);
                    mNavigationView = null;
                if (mCustomNavView != null) {
                    removeView(mCustomNavView);
                    mCustomNavView = null;
                }
                break;
            }
            
            switch (mode) {
            case ActionBar.NAVIGATION_MODE_NORMAL:
            case ActionBar.NAVIGATION_MODE_STANDARD:
                initTitle();
                break;
            case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
                mSpinner = new Spinner(mContext, null,
                        com.android.internal.R.attr.dropDownSpinnerStyle);
                mSpinner.setOnItemSelectedListener(mNavItemSelectedListener);
                addView(mSpinner);
                break;
            case ActionBar.NAVIGATION_MODE_CUSTOM:
                addView(mNavigationView);
                addView(mCustomNavView);
                break;
            }
            mNavigationMode = mode;
@@ -284,8 +312,12 @@ public class ActionBarView extends ViewGroup {
        }
    }
    
    public void setDropdownAdapter(SpinnerAdapter adapter) {
        mSpinner.setAdapter(adapter);
    }
    
    public View getCustomNavigationView() {
        return mNavigationView;
        return mCustomNavView;
    }
    
    public int getNavigationMode() {
@@ -451,7 +483,7 @@ public class ActionBarView extends ViewGroup {
        }

        switch (mNavigationMode) {
        case ActionBar.NAVIGATION_MODE_NORMAL:
        case ActionBar.NAVIGATION_MODE_STANDARD:
            if (mLogoView == null) {
                initTitle();
            }
@@ -459,15 +491,15 @@ public class ActionBarView extends ViewGroup {
            
        case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
            throw new UnsupportedOperationException(
                    "Dropdown list navigation isn't supported yet!");
                    "Inflating dropdown list navigation isn't supported yet!");
            
        case ActionBar.NAVIGATION_MODE_TABS:
            throw new UnsupportedOperationException(
                    "Tab navigation isn't supported yet!");
            
        case ActionBar.NAVIGATION_MODE_CUSTOM:
            if (mNavigationView != null) {
                addView(mNavigationView);
            if (mCustomNavView != null) {
                addView(mCustomNavView);
            }
            break;
        }
@@ -520,14 +552,21 @@ public class ActionBarView extends ViewGroup {
        }
        
        switch (mNavigationMode) {
        case ActionBar.NAVIGATION_MODE_NORMAL:
        case ActionBar.NAVIGATION_MODE_STANDARD:
            if (mTitleView != null) {
                measureChildView(mTitleView, availableWidth, childSpecHeight, mSpacing);
            }
            break;
        case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
            if (mSpinner != null) {
                mSpinner.measure(
                        MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
            }
            break;
        case ActionBar.NAVIGATION_MODE_CUSTOM:
            if (mNavigationView != null) {
                mNavigationView.measure(
            if (mCustomNavView != null) {
                mCustomNavView.measure(
                        MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
            }
@@ -561,15 +600,19 @@ public class ActionBarView extends ViewGroup {
        }
        
        switch (mNavigationMode) {
        case ActionBar.NAVIGATION_MODE_NORMAL:
        case ActionBar.NAVIGATION_MODE_STANDARD:
            if (mTitleView != null) {
                x += positionChild(mTitleView, x, y, contentHeight) + mSpacing;
            }
            break;
            
        case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
            if (mSpinner != null) {
                x += positionChild(mSpinner, x, y, contentHeight) + mSpacing;
            }
            break;
        case ActionBar.NAVIGATION_MODE_CUSTOM:
            if (mNavigationView != null) {
                x += positionChild(mNavigationView, x, y, contentHeight) + mSpacing;
            if (mCustomNavView != null) {
                x += positionChild(mCustomNavView, x, y, contentHeight) + mSpacing;
            }
            break;
        }
+0 −28
Original line number Diff line number Diff line
@@ -251,8 +251,6 @@ public class Spinner extends AbsSpinner implements OnClickListener {
        return child;
    }



    /**
     * Helper for makeAndAddView to set the position of a view
     * and fill out its layout paramters.
@@ -341,32 +339,6 @@ public class Spinner extends AbsSpinner implements OnClickListener {
        return mPopup.getHintText();
    }
    
    /*
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (mPopup.onKeyDown(keyCode, event)) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (mPopup.onKeyUp(keyCode, event)) {
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }
    
    @Override
    public boolean onKeyPreIme(int keyCode, KeyEvent event) {
        if (mPopup.onKeyPreIme(keyCode, event)) {
            return true;
        }
        return super.onKeyPreIme(keyCode, event);
    }
    */
    
    /**
     * <p>Wrapper class for an Adapter. Transforms the embedded Adapter instance
     * into a ListAdapter.</p>
+17 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.graphics.drawable.Drawable;
import android.view.ActionBarView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.SpinnerAdapter;

/**
 * SplitActionBar is the ActionBar implementation used
@@ -42,10 +43,25 @@ public class SplitActionBar extends ActionBar {
        mActionView.setCallback(callback);
    }

    public void setCustomNavigationView(View view) {
    public void setCustomNavigationMode(View view) {
        mActionView.setCustomNavigationView(view);
    }
    
    public void setDropdownNavigationMode(SpinnerAdapter adapter) {
        mActionView.setNavigationMode(NAVIGATION_MODE_DROPDOWN_LIST);
        mActionView.setDropdownAdapter(adapter);
    }
    
    public void setStandardNavigationMode(CharSequence title) {
        setStandardNavigationMode(title, null);
    }
    
    public void setStandardNavigationMode(CharSequence title, CharSequence subtitle) {
        mActionView.setNavigationMode(NAVIGATION_MODE_STANDARD);
        mActionView.setTitle(title);
        mActionView.setSubtitle(subtitle);
    }

    public void setTitle(CharSequence title) {
        mActionView.setTitle(title);
    }
@@ -54,10 +70,6 @@ public class SplitActionBar extends ActionBar {
        mActionView.setSubtitle(subtitle);
    }

    public void setNavigationMode(int mode) {
        mActionView.setNavigationMode(mode);
    }

    public void setDisplayOptions(int options) {
        mActionView.setDisplayOptions(options);
    }
Loading