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

Commit 89e0645b authored by Adam Powell's avatar Adam Powell
Browse files

Added context modes to ActionBar API.

Change-Id: I7c3e782cbf01be7bc671b377fb4d706040888833
parent 6443de56
Loading
Loading
Loading
Loading
+172 −60
Original line number Diff line number Diff line
@@ -2088,6 +2088,28 @@
 visibility="public"
>
</field>
<field name="actionBarCloseContextDrawable"
 type="int"
 transient="false"
 volatile="false"
 value="16843550"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="actionBarContextBackground"
 type="int"
 transient="false"
 volatile="false"
 value="16843549"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="actionButtonPadding"
 type="int"
 transient="false"
@@ -19435,6 +19457,17 @@
 visibility="public"
>
</constructor>
<method name="finishContextMode"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getCustomNavigationView"
 return="android.view.View"
 abstract="true"
@@ -19503,19 +19536,6 @@
<parameter name="d" type="android.graphics.drawable.Drawable">
</parameter>
</method>
<method name="setCallback"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="callback" type="android.app.ActionBar.Callback">
</parameter>
</method>
<method name="setCustomNavigationMode"
 return="void"
 abstract="true"
@@ -19569,6 +19589,8 @@
>
<parameter name="adapter" type="android.widget.SpinnerAdapter">
</parameter>
<parameter name="callback" type="android.app.ActionBar.NavigationCallback">
</parameter>
</method>
<method name="setStandardNavigationMode"
 return="void"
@@ -19598,6 +19620,19 @@
<parameter name="title" type="java.lang.CharSequence">
</parameter>
</method>
<method name="startContextMode"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="callback" type="android.app.ActionBar.ContextModeCallback">
</parameter>
</method>
<field name="DISPLAY_HIDE_HOME"
 type="int"
 transient="false"
@@ -19665,15 +19700,24 @@
>
</field>
</class>
<interface name="ActionBar.Callback"
<class name="ActionBar.ContextMode"
 extends="java.lang.Object"
 abstract="true"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<method name="onContextItemClicked"
 return="boolean"
<constructor name="ActionBar.ContextMode"
 type="android.app.ActionBar.ContextMode"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<method name="finish"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
@@ -19682,13 +19726,9 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="modeId" type="int">
</parameter>
<parameter name="item" type="android.view.MenuItem">
</parameter>
</method>
<method name="onCreateContextMode"
 return="boolean"
<method name="getMenu"
 return="android.view.Menu"
 abstract="true"
 native="false"
 synchronized="false"
@@ -19697,13 +19737,9 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="modeId" type="int">
</parameter>
<parameter name="menu" type="android.view.Menu">
</parameter>
</method>
<method name="onNavigationItemSelected"
 return="boolean"
<method name="invalidate"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
@@ -19712,13 +19748,9 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="itemPosition" type="int">
</parameter>
<parameter name="itemId" type="long">
</parameter>
</method>
<method name="onPrepareContextMode"
 return="boolean"
<method name="setCustomView"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
@@ -19727,33 +19759,46 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="modeId" type="int">
</parameter>
<parameter name="menu" type="android.view.Menu">
<parameter name="view" type="android.view.View">
</parameter>
</method>
</interface>
<class name="ActionBar.SimpleCallback"
 extends="java.lang.Object"
 abstract="false"
 static="true"
<method name="setSubtitle"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<implements name="android.app.ActionBar.Callback">
</implements>
<constructor name="ActionBar.SimpleCallback"
 type="android.app.ActionBar.SimpleCallback"
<parameter name="subtitle" type="java.lang.CharSequence">
</parameter>
</method>
<method name="setTitle"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<parameter name="title" type="java.lang.CharSequence">
</parameter>
</method>
</class>
<interface name="ActionBar.ContextModeCallback"
 abstract="true"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<method name="onContextItemClicked"
 return="boolean"
 abstract="false"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
@@ -19761,14 +19806,14 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="modeId" type="int">
<parameter name="mode" type="android.app.ActionBar.ContextMode">
</parameter>
<parameter name="item" type="android.view.MenuItem">
</parameter>
</method>
<method name="onCreateContextMode"
 return="boolean"
 abstract="false"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
@@ -19776,14 +19821,14 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="modeId" type="int">
<parameter name="mode" type="android.app.ActionBar.ContextMode">
</parameter>
<parameter name="menu" type="android.view.Menu">
</parameter>
</method>
<method name="onNavigationItemSelected"
 return="boolean"
 abstract="false"
<method name="onDestroyContextMode"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
@@ -19791,14 +19836,12 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="itemPosition" type="int">
</parameter>
<parameter name="itemId" type="long">
<parameter name="mode" type="android.app.ActionBar.ContextMode">
</parameter>
</method>
<method name="onPrepareContextMode"
 return="boolean"
 abstract="false"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
@@ -19806,12 +19849,35 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="modeId" type="int">
<parameter name="mode" type="android.app.ActionBar.ContextMode">
</parameter>
<parameter name="menu" type="android.view.Menu">
</parameter>
</method>
</class>
</interface>
<interface name="ActionBar.NavigationCallback"
 abstract="true"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<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>
</interface>
<class name="Activity"
 extends="android.view.ContextThemeWrapper"
 abstract="false"
@@ -180005,6 +180071,19 @@
<parameter name="alphaChar" type="char">
</parameter>
</method>
<method name="setShowAsAction"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="actionEnum" type="int">
</parameter>
</method>
<method name="setTitle"
 return="android.view.MenuItem"
 abstract="true"
@@ -180057,6 +180136,39 @@
<parameter name="visible" type="boolean">
</parameter>
</method>
<field name="SHOW_AS_ACTION_ALWAYS"
 type="int"
 transient="false"
 volatile="false"
 value="2"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="SHOW_AS_ACTION_IF_ROOM"
 type="int"
 transient="false"
 volatile="false"
 value="1"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="SHOW_AS_ACTION_NEVER"
 type="int"
 transient="false"
 volatile="false"
 value="0"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</interface>
<interface name="MenuItem.OnMenuItemClickListener"
 abstract="true"
+124 −40
Original line number Diff line number Diff line
@@ -67,13 +67,6 @@ public abstract class ActionBar {
     */
    public static final int DISPLAY_HIDE_HOME = 0x2;

    /**
     * Set the callback that the ActionBar will use to handle events
     * and populate menus.
     * @param callback Callback to use
     */
    public abstract void setCallback(Callback callback);
    
    /**
     * Set the action bar into custom navigation mode, supplying a view
     * for custom navigation.
@@ -95,8 +88,11 @@ public abstract class ActionBar {
     * @param adapter An adapter that will provide views both to display
     *                the current navigation selection and populate views
     *                within the dropdown navigation menu.
     * @param callback A NavigationCallback that will receive events when the user
     *                 selects a navigation item.
     */
    public abstract void setDropdownNavigationMode(SpinnerAdapter adapter);
    public abstract void setDropdownNavigationMode(SpinnerAdapter adapter,
            NavigationCallback callback);

    /**
     * Set the action bar into standard navigation mode, supplying a title and subtitle.
@@ -198,48 +194,136 @@ public abstract class ActionBar {
     */
    public abstract int getDisplayOptions();
    
    public abstract void startContextMode(ContextModeCallback callback);
    public abstract void finishContextMode();
    
    /**
     * Callback interface for ActionBar events. 
     * Represents a contextual mode of the Action Bar. Context modes can be used for
     * modal interactions with activity content and replace the normal Action Bar until finished.
     * Examples of good contextual modes include selection modes, search, content editing, etc.
     */
    public interface Callback {
    public static abstract class ContextMode {
        /**
         * This method is called whenever a navigation item in your action bar
         * is selected.
         * Set the title of the context mode. This method will have no visible effect if
         * a custom view has been set.
         * 
         * @param itemPosition Position of the item clicked.
         * @param itemId ID of the item clicked.
         * @return True if the event was handled, false otherwise.
         * @param title Title string to set
         * 
         * @see #setCustomView(View)
         */
        public boolean onNavigationItemSelected(int itemPosition, long itemId);
        public abstract void setTitle(CharSequence title);
        
        /*
         * In progress
        /**
         * Set the subtitle of the context mode. This method will have no visible effect if
         * a custom view has been set.
         * 
         * @param subtitle Subtitle string to set
         * 
         * @see #setCustomView(View)
         */
        public boolean onCreateContextMode(int modeId, Menu menu);
        public boolean onPrepareContextMode(int modeId, Menu menu);
        public boolean onContextItemClicked(int modeId, MenuItem item);
    }
        public abstract void setSubtitle(CharSequence subtitle);
        
        /**
     * Simple stub implementations of ActionBar.Callback methods.
     * Extend this if you only need a subset of Callback functionality.
         * Set a custom view for this context mode. The custom view will take the place of
         * the title and subtitle. Useful for things like search boxes.
         *  
         * @param view Custom view to use in place of the title/subtitle.
         * 
         * @see #setTitle(CharSequence)
         * @see #setSubtitle(CharSequence)
         */
    public static class SimpleCallback implements Callback {
        public boolean onCreateContextMode(int modeId, Menu menu) {
            return false;
        }
        public abstract void setCustomView(View view);
        
        public boolean onPrepareContextMode(int modeId, Menu menu) {
            return false;
        }
        /**
         * Invalidate the context mode and refresh menu content. The context mode's
         * {@link ContextModeCallback} will have its
         * {@link ContextModeCallback#onPrepareContextMode(ContextMode, Menu)} method called.
         * If it returns true the menu will be scanned for updated content and any relevant changes
         * will be reflected to the user.
         */
        public abstract void invalidate();
        
        public boolean onContextItemClicked(int modeId, MenuItem item) {
            return false;
        }
        /**
         * Finish and close this context mode. The context mode's {@link ContextModeCallback} will
         * have its {@link ContextModeCallback#onDestroyContextMode(ContextMode)} method called.
         */
        public abstract void finish();

        public boolean onNavigationItemSelected(int itemPosition, long itemId) {
            return false;
        /**
         * Returns the menu of actions that this context mode presents.
         * @return The context mode's menu.
         */
        public abstract Menu getMenu();
    }
    
    /**
     * Callback interface for ActionBar context modes. Supplied to
     * {@link ActionBar#startContextMode(ContextModeCallback)}, a ContextModeCallback
     * configures and handles events raised by a user's interaction with a context mode.
     * 
     * <p>A context mode's lifecycle is as follows:
     * <ul>
     * <li>{@link ContextModeCallback#onCreateContextMode(ContextMode, Menu)} once on initial
     * creation</li>
     * <li>{@link ContextModeCallback#onPrepareContextMode(ContextMode, Menu)} after creation
     * and any time the {@link ContextMode} is invalidated</li>
     * <li>{@link ContextModeCallback#onContextItemClicked(ContextMode, MenuItem)} any time a
     * contextual action button is clicked</li>
     * <li>{@link ContextModeCallback#onDestroyContextMode(ContextMode)} when the context mode
     * is closed</li>
     * </ul>
     */
    public interface ContextModeCallback {
        /**
         * Called when a context mode is first created. The menu supplied will be used to generate
         * action buttons for the context mode.
         * 
         * @param mode ContextMode being created
         * @param menu Menu used to populate contextual action buttons
         * @return true if the context mode should be created, false if entering this context mode
         *          should be aborted.
         */
        public boolean onCreateContextMode(ContextMode mode, Menu menu);
        
        /**
         * Called to refresh a context mode's action menu whenever it is invalidated.
         * 
         * @param mode ContextMode being prepared
         * @param menu Menu used to populate contextual action buttons
         * @return true if the menu or context mode was updated, false otherwise.
         */
        public boolean onPrepareContextMode(ContextMode mode, Menu menu);
        
        /**
         * Called to report a user click on a contextual action button.
         * 
         * @param mode The current ContextMode
         * @param item The item that was clicked
         * @return true if this callback handled the event, false if the standard MenuItem
         *          invocation should continue.
         */
        public boolean onContextItemClicked(ContextMode mode, MenuItem item);
        
        /**
         * Called when a context mode is about to be exited and destroyed.
         * 
         * @param mode The current ContextMode being destroyed
         */
        public void onDestroyContextMode(ContextMode mode);
    }
    
    /**
     * Callback interface for ActionBar navigation events. 
     */
    public interface NavigationCallback {
        /**
         * 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);
    }
}
+5 −13
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import android.util.Config;
import android.util.EventLog;
import android.util.Log;
import android.util.SparseArray;
import android.view.ActionBarView;
import android.view.ContextMenu;
import android.view.ContextThemeWrapper;
import android.view.InflateException;
@@ -74,8 +73,9 @@ import android.view.accessibility.AccessibilityEvent;
import android.widget.AdapterView;
import android.widget.LinearLayout;

import com.android.internal.app.SplitActionBar;
import com.android.internal.app.ActionBarImpl;
import com.android.internal.policy.PolicyManager;
import com.android.internal.widget.ActionBarView;

/**
 * An activity is a single, focused thing that the user can do.  Almost all
@@ -1675,20 +1675,12 @@ public class Activity extends ContextThemeWrapper
     * initializes the ActionBar with the view, and sets mActionBar.
     */
    private void initActionBar() {
        if (!getWindow().hasFeature(Window.FEATURE_ACTION_BAR)) {
        Window window = getWindow();
        if (!window.hasFeature(Window.FEATURE_ACTION_BAR)) {
            return;
        }
        
        ActionBarView view = (ActionBarView) findViewById(com.android.internal.R.id.action_bar);
        if (view != null) {
        	LinearLayout splitView = 
        		(LinearLayout) findViewById(com.android.internal.R.id.context_action_bar);
        	if (splitView != null) {
        		mActionBar = new SplitActionBar(view, splitView);
        	}
        } else {
            Log.e(TAG, "Could not create action bar; view not found in window decor.");
        }
        mActionBar = new ActionBarImpl(getWindow().getDecorView());
    }
    
    /**
+4 −4
Original line number Diff line number Diff line
@@ -242,12 +242,12 @@ public class MenuInflater {
        private boolean itemEnabled;
        
        /**
         * Sync to attrs.xml enum:
         * Sync to attrs.xml enum, values in MenuItem:
         * - 0: never
         * - 1: ifRoom
         * - 2: always
         */
        private int itemShowAsAction;
        private int itemShowAsAction = MenuItem.SHOW_AS_ACTION_NEVER;
        
        private String itemListenerMethodName;
        
@@ -346,7 +346,8 @@ public class MenuInflater {
                .setTitleCondensed(itemTitleCondensed)
                .setIcon(itemIconResId)
                .setAlphabeticShortcut(itemAlphabeticShortcut)
                .setNumericShortcut(itemNumericShortcut);
                .setNumericShortcut(itemNumericShortcut)
                .setShowAsAction(itemShowAsAction);
            
            if (itemListenerMethodName != null) {
                item.setOnMenuItemClickListener(
@@ -358,7 +359,6 @@ public class MenuInflater {
                if (itemCheckable >= 2) {
                    impl.setExclusiveCheckable(true);
                }
                impl.setShowAsAction(itemShowAsAction);
            }
        }
        
+24 −0
Original line number Diff line number Diff line
@@ -31,6 +31,21 @@ import android.view.View.OnCreateContextMenuListener;
 * For a feature set of specific menu types, see {@link Menu}.
 */
public interface MenuItem {
    /*
     * These should be kept in sync with attrs.xml enum constants for showAsAction
     */
    /** Never show this item as a button in an Action Bar. */
    public static final int SHOW_AS_ACTION_NEVER = 0;
    /** Show this item as a button in an Action Bar if the system decides there is room for it. */
    public static final int SHOW_AS_ACTION_IF_ROOM = 1;
    /**
     * Always show this item as a button in an Action Bar.
     * Use sparingly! If too many items are set to always show in the Action Bar it can
     * crowd the Action Bar and degrade the user experience on devices with smaller screens.
     * A good rule of thumb is to have no more than 2 items set to always show at a time.
     */
    public static final int SHOW_AS_ACTION_ALWAYS = 2;
    
    /**
     * Interface definition for a callback to be invoked when a menu item is
     * clicked.
@@ -381,4 +396,13 @@ public interface MenuItem {
     *         menu item to the menu. This can be null.
     */
    public ContextMenuInfo getMenuInfo();
    
    /**
     * Sets how this item should display in the presence of an Action Bar.
     *
     * @param actionEnum How the item should display. One of
     * 
     * @see android.app.ActionBar
     */
    public void setShowAsAction(int actionEnum);
}
 No newline at end of file
Loading