16e34636749217654f43221885afb7a29bb5ca96aAdam Powell/*
26e34636749217654f43221885afb7a29bb5ca96aAdam Powell * Copyright (C) 2010 The Android Open Source Project
36e34636749217654f43221885afb7a29bb5ca96aAdam Powell *
46e34636749217654f43221885afb7a29bb5ca96aAdam Powell * Licensed under the Apache License, Version 2.0 (the "License");
56e34636749217654f43221885afb7a29bb5ca96aAdam Powell * you may not use this file except in compliance with the License.
66e34636749217654f43221885afb7a29bb5ca96aAdam Powell * You may obtain a copy of the License at
76e34636749217654f43221885afb7a29bb5ca96aAdam Powell *
86e34636749217654f43221885afb7a29bb5ca96aAdam Powell *      http://www.apache.org/licenses/LICENSE-2.0
96e34636749217654f43221885afb7a29bb5ca96aAdam Powell *
106e34636749217654f43221885afb7a29bb5ca96aAdam Powell * Unless required by applicable law or agreed to in writing, software
116e34636749217654f43221885afb7a29bb5ca96aAdam Powell * distributed under the License is distributed on an "AS IS" BASIS,
126e34636749217654f43221885afb7a29bb5ca96aAdam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136e34636749217654f43221885afb7a29bb5ca96aAdam Powell * See the License for the specific language governing permissions and
146e34636749217654f43221885afb7a29bb5ca96aAdam Powell * limitations under the License.
156e34636749217654f43221885afb7a29bb5ca96aAdam Powell */
166e34636749217654f43221885afb7a29bb5ca96aAdam Powell
176e34636749217654f43221885afb7a29bb5ca96aAdam Powellpackage android.view;
186e34636749217654f43221885afb7a29bb5ca96aAdam Powell
196e34636749217654f43221885afb7a29bb5ca96aAdam Powell
207b9c912f536925ac6ec43935d6e97506851b33d6Tor Norbyeimport android.annotation.StringRes;
21ba51f15998e7aa284a09ca53053b340c744fcd9dAbodunrinwa Tokiimport android.annotation.TestApi;
22cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarriimport android.graphics.Rect;
237b9c912f536925ac6ec43935d6e97506851b33d6Tor Norbye
246e34636749217654f43221885afb7a29bb5ca96aAdam Powell/**
255e0959393426371dadef2c7905d5c915a1ac2dd4Scott Main * Represents a contextual mode of the user interface. Action modes can be used to provide
265e0959393426371dadef2c7905d5c915a1ac2dd4Scott Main * alternative interaction modes and replace parts of the normal UI until finished.
275e0959393426371dadef2c7905d5c915a1ac2dd4Scott Main * Examples of good action modes include text selection and contextual actions.
285e0959393426371dadef2c7905d5c915a1ac2dd4Scott Main * <div class="special reference">
295e0959393426371dadef2c7905d5c915a1ac2dd4Scott Main * <h3>Developer Guides</h3>
305e0959393426371dadef2c7905d5c915a1ac2dd4Scott Main * <p>For information about how to provide contextual actions with {@code ActionMode},
31ef0314b2c693c6cfa34680a784210dfb540fe36cScott Main * read the <a href="{@docRoot}guide/topics/ui/menus.html#context-menu">Menus</a>
325e0959393426371dadef2c7905d5c915a1ac2dd4Scott Main * developer guide.</p>
335e0959393426371dadef2c7905d5c915a1ac2dd4Scott Main * </div>
346e34636749217654f43221885afb7a29bb5ca96aAdam Powell */
356e34636749217654f43221885afb7a29bb5ca96aAdam Powellpublic abstract class ActionMode {
36d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri
37d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri    /**
38d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     * The action mode is treated as a Primary mode. This is the default.
39d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     * Use with {@link #setType}.
40d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     */
41d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri    public static final int TYPE_PRIMARY = 0;
42d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri    /**
43d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     * The action mode is treated as a Floating Toolbar.
44d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     * Use with {@link #setType}.
45d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     */
46d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri    public static final int TYPE_FLOATING = 1;
47d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri
48fd3a3a1163c5096821cef351309fcdd9a4f48002Abodunrinwa Toki    /**
499e211282d3ee54c9840947951593554c3bd5a77cAbodunrinwa Toki     * Default value to hide the action mode for
509e211282d3ee54c9840947951593554c3bd5a77cAbodunrinwa Toki     * {@link ViewConfiguration#getDefaultActionModeHideDuration()}.
51fd3a3a1163c5096821cef351309fcdd9a4f48002Abodunrinwa Toki     */
529e211282d3ee54c9840947951593554c3bd5a77cAbodunrinwa Toki    public static final int DEFAULT_HIDE_DURATION = -1;
53fd3a3a1163c5096821cef351309fcdd9a4f48002Abodunrinwa Toki
54f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell    private Object mTag;
55785c447b2bc625209706fd128ce61781c3a4183bAdam Powell    private boolean mTitleOptionalHint;
56d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri    private int mType = TYPE_PRIMARY;
57f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell
58f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell    /**
59f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     * Set a tag object associated with this ActionMode.
60f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     *
61f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     * <p>Like the tag available to views, this allows applications to associate arbitrary
62f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     * data with an ActionMode for later reference.
63f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     *
64f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     * @param tag Tag to associate with this ActionMode
65f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     *
66f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     * @see #getTag()
67f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     */
68f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell    public void setTag(Object tag) {
69f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell        mTag = tag;
70f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell    }
71f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell
72f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell    /**
73f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     * Retrieve the tag object associated with this ActionMode.
74f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     *
75f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     * <p>Like the tag available to views, this allows applications to associate arbitrary
76f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     * data with an ActionMode for later reference.
77f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     *
78f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     * @return Tag associated with this ActionMode
79f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     *
80f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     * @see #setTag(Object)
81f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell     */
82f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell    public Object getTag() {
83f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell        return mTag;
84f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell    }
85f178737f823cf22d9a07df6f51071b7189a95e7eAdam Powell
866e34636749217654f43221885afb7a29bb5ca96aAdam Powell    /**
876e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * Set the title of the action mode. This method will have no visible effect if
886e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * a custom view has been set.
896e34636749217654f43221885afb7a29bb5ca96aAdam Powell     *
906e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * @param title Title string to set
916e34636749217654f43221885afb7a29bb5ca96aAdam Powell     *
92c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * @see #setTitle(int)
936e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * @see #setCustomView(View)
946e34636749217654f43221885afb7a29bb5ca96aAdam Powell     */
956e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public abstract void setTitle(CharSequence title);
966e34636749217654f43221885afb7a29bb5ca96aAdam Powell
976e34636749217654f43221885afb7a29bb5ca96aAdam Powell    /**
98c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * Set the title of the action mode. This method will have no visible effect if
99c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * a custom view has been set.
100c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     *
101c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * @param resId Resource ID of a string to set as the title
102c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     *
103c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * @see #setTitle(CharSequence)
104c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * @see #setCustomView(View)
105c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     */
1067b9c912f536925ac6ec43935d6e97506851b33d6Tor Norbye    public abstract void setTitle(@StringRes int resId);
107c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell
108c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell    /**
1096e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * Set the subtitle of the action mode. This method will have no visible effect if
1106e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * a custom view has been set.
1116e34636749217654f43221885afb7a29bb5ca96aAdam Powell     *
1126e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * @param subtitle Subtitle string to set
1136e34636749217654f43221885afb7a29bb5ca96aAdam Powell     *
114c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * @see #setSubtitle(int)
1156e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * @see #setCustomView(View)
1166e34636749217654f43221885afb7a29bb5ca96aAdam Powell     */
1176e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public abstract void setSubtitle(CharSequence subtitle);
1186e34636749217654f43221885afb7a29bb5ca96aAdam Powell
1196e34636749217654f43221885afb7a29bb5ca96aAdam Powell    /**
120c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * Set the subtitle of the action mode. This method will have no visible effect if
121c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * a custom view has been set.
122c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     *
123c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * @param resId Resource ID of a string to set as the subtitle
124c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     *
125c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * @see #setSubtitle(CharSequence)
126c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     * @see #setCustomView(View)
127c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell     */
1287b9c912f536925ac6ec43935d6e97506851b33d6Tor Norbye    public abstract void setSubtitle(@StringRes int resId);
129c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell
130c9ae2a24dc1fa274ca0916c91a2e9a2764ba4bb3Adam Powell    /**
131b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     * Set whether or not the title/subtitle display for this action mode
132b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     * is optional.
133b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     *
134b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     * <p>In many cases the supplied title for an action mode is merely
135b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     * meant to add context and is not strictly required for the action
136b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     * mode to be useful. If the title is optional, the system may choose
137b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     * to hide the title entirely rather than truncate it due to a lack
138b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     * of available space.</p>
139b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     *
140b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     * <p>Note that this is merely a hint; the underlying implementation
141b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     * may choose to ignore this setting under some circumstances.</p>
142b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     *
143b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     * @param titleOptional true if the title only presents optional information.
144b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     */
145b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    public void setTitleOptionalHint(boolean titleOptional) {
146785c447b2bc625209706fd128ce61781c3a4183bAdam Powell        mTitleOptionalHint = titleOptional;
147785c447b2bc625209706fd128ce61781c3a4183bAdam Powell    }
148785c447b2bc625209706fd128ce61781c3a4183bAdam Powell
149785c447b2bc625209706fd128ce61781c3a4183bAdam Powell    /**
150785c447b2bc625209706fd128ce61781c3a4183bAdam Powell     * @return true if this action mode has been given a hint to consider the
151785c447b2bc625209706fd128ce61781c3a4183bAdam Powell     *         title/subtitle display to be optional.
152785c447b2bc625209706fd128ce61781c3a4183bAdam Powell     *
153785c447b2bc625209706fd128ce61781c3a4183bAdam Powell     * @see #setTitleOptionalHint(boolean)
154785c447b2bc625209706fd128ce61781c3a4183bAdam Powell     * @see #isTitleOptional()
155785c447b2bc625209706fd128ce61781c3a4183bAdam Powell     */
156785c447b2bc625209706fd128ce61781c3a4183bAdam Powell    public boolean getTitleOptionalHint() {
157785c447b2bc625209706fd128ce61781c3a4183bAdam Powell        return mTitleOptionalHint;
158b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    }
159b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell
160b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    /**
161b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     * @return true if this action mode considers the title and subtitle fields
162b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     *         as optional. Optional titles may not be displayed to the user.
163b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell     */
164b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    public boolean isTitleOptional() {
165b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell        return false;
166b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    }
167b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell
168b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    /**
1696e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * Set a custom view for this action mode. The custom view will take the place of
1706e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * the title and subtitle. Useful for things like search boxes.
1716e34636749217654f43221885afb7a29bb5ca96aAdam Powell     *
1726e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * @param view Custom view to use in place of the title/subtitle.
1736e34636749217654f43221885afb7a29bb5ca96aAdam Powell     *
1746e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * @see #setTitle(CharSequence)
1756e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * @see #setSubtitle(CharSequence)
1766e34636749217654f43221885afb7a29bb5ca96aAdam Powell     */
1776e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public abstract void setCustomView(View view);
1786e34636749217654f43221885afb7a29bb5ca96aAdam Powell
1796e34636749217654f43221885afb7a29bb5ca96aAdam Powell    /**
180d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     * Set a type for this action mode. This will affect how the system renders the action mode if
181d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     * it has to.
182d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     *
183d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     * @param type One of {@link #TYPE_PRIMARY} or {@link #TYPE_FLOATING}.
184d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     */
185d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri    public void setType(int type) {
186d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri        mType = type;
187d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri    }
188d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri
189d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri    /**
190d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     * Returns the type for this action mode.
191d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     *
192d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     * @return One of {@link #TYPE_PRIMARY} or {@link #TYPE_FLOATING}.
193d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri     */
194d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri    public int getType() {
195d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri        return mType;
196d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri    }
197d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri
198d6aeff17e620cf4a8a6370102cae5997332deb1cClara Bayarri    /**
1996e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * Invalidate the action mode and refresh menu content. The mode's
2006e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * {@link ActionMode.Callback} will have its
2016e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * {@link Callback#onPrepareActionMode(ActionMode, Menu)} method called.
2026e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * If it returns true the menu will be scanned for updated content and any relevant changes
2036e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * will be reflected to the user.
2046e34636749217654f43221885afb7a29bb5ca96aAdam Powell     */
2056e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public abstract void invalidate();
2066e34636749217654f43221885afb7a29bb5ca96aAdam Powell
2076e34636749217654f43221885afb7a29bb5ca96aAdam Powell    /**
208cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri     * Invalidate the content rect associated to this ActionMode. This only makes sense for
209cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri     * action modes that support dynamic positioning on the screen, and provides a more efficient
210cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri     * way to reposition it without invalidating the whole action mode.
211cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri     *
212cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri     * @see Callback2#onGetContentRect(ActionMode, View, Rect) .
213cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri     */
214cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri    public void invalidateContentRect() {}
215cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri
216cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri    /**
2179e211282d3ee54c9840947951593554c3bd5a77cAbodunrinwa Toki     * Hide the action mode view from obstructing the content below for a short duration.
218fd3a3a1163c5096821cef351309fcdd9a4f48002Abodunrinwa Toki     * This only makes sense for action modes that support dynamic positioning on the screen.
2199e211282d3ee54c9840947951593554c3bd5a77cAbodunrinwa Toki     * If this method is called again before the hide duration expires, the later hide call will
220fd3a3a1163c5096821cef351309fcdd9a4f48002Abodunrinwa Toki     * cancel the former and then take effect.
2219e211282d3ee54c9840947951593554c3bd5a77cAbodunrinwa Toki     * NOTE that there is an internal limit to how long the mode can be hidden for. It's typically
222fd3a3a1163c5096821cef351309fcdd9a4f48002Abodunrinwa Toki     * about a few seconds.
223fd3a3a1163c5096821cef351309fcdd9a4f48002Abodunrinwa Toki     *
2249e211282d3ee54c9840947951593554c3bd5a77cAbodunrinwa Toki     * @param duration The number of milliseconds to hide for.
2259e211282d3ee54c9840947951593554c3bd5a77cAbodunrinwa Toki     * @see #DEFAULT_HIDE_DURATION
226fd3a3a1163c5096821cef351309fcdd9a4f48002Abodunrinwa Toki     */
2279e211282d3ee54c9840947951593554c3bd5a77cAbodunrinwa Toki    public void hide(long duration) {}
228fd3a3a1163c5096821cef351309fcdd9a4f48002Abodunrinwa Toki
229fd3a3a1163c5096821cef351309fcdd9a4f48002Abodunrinwa Toki    /**
2306e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * Finish and close this action mode. The action mode's {@link ActionMode.Callback} will
2316e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * have its {@link Callback#onDestroyActionMode(ActionMode)} method called.
2326e34636749217654f43221885afb7a29bb5ca96aAdam Powell     */
2336e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public abstract void finish();
2346e34636749217654f43221885afb7a29bb5ca96aAdam Powell
2356e34636749217654f43221885afb7a29bb5ca96aAdam Powell    /**
2366e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * Returns the menu of actions that this action mode presents.
2376e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * @return The action mode's menu.
2386e34636749217654f43221885afb7a29bb5ca96aAdam Powell     */
2396e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public abstract Menu getMenu();
2406e34636749217654f43221885afb7a29bb5ca96aAdam Powell
2416e34636749217654f43221885afb7a29bb5ca96aAdam Powell    /**
2426e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * Returns the current title of this action mode.
2436e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * @return Title text
2446e34636749217654f43221885afb7a29bb5ca96aAdam Powell     */
2456e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public abstract CharSequence getTitle();
2466e34636749217654f43221885afb7a29bb5ca96aAdam Powell
2476e34636749217654f43221885afb7a29bb5ca96aAdam Powell    /**
2486e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * Returns the current subtitle of this action mode.
2496e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * @return Subtitle text
2506e34636749217654f43221885afb7a29bb5ca96aAdam Powell     */
2516e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public abstract CharSequence getSubtitle();
2526e34636749217654f43221885afb7a29bb5ca96aAdam Powell
2536e34636749217654f43221885afb7a29bb5ca96aAdam Powell    /**
2546e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * Returns the current custom view for this action mode.
2556e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * @return The current custom view
2566e34636749217654f43221885afb7a29bb5ca96aAdam Powell     */
2576e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public abstract View getCustomView();
2586e34636749217654f43221885afb7a29bb5ca96aAdam Powell
2596e34636749217654f43221885afb7a29bb5ca96aAdam Powell    /**
2609168f0b170c6a99371ae46e7d3f5d66c8c4c930dAdam Powell     * Returns a {@link MenuInflater} with the ActionMode's context.
2619168f0b170c6a99371ae46e7d3f5d66c8c4c930dAdam Powell     */
2629168f0b170c6a99371ae46e7d3f5d66c8c4c930dAdam Powell    public abstract MenuInflater getMenuInflater();
2639168f0b170c6a99371ae46e7d3f5d66c8c4c930dAdam Powell
2649168f0b170c6a99371ae46e7d3f5d66c8c4c930dAdam Powell    /**
265972ab4f8588c365cf9c06e1f22b30a96fb0a06fcAbodunrinwa Toki     * Called when the window containing the view that started this action mode gains or loses
266972ab4f8588c365cf9c06e1f22b30a96fb0a06fcAbodunrinwa Toki     * focus.
267972ab4f8588c365cf9c06e1f22b30a96fb0a06fcAbodunrinwa Toki     *
268972ab4f8588c365cf9c06e1f22b30a96fb0a06fcAbodunrinwa Toki     * @param hasWindowFocus True if the window containing the view that started this action mode
269972ab4f8588c365cf9c06e1f22b30a96fb0a06fcAbodunrinwa Toki     *        now has focus, false otherwise.
270972ab4f8588c365cf9c06e1f22b30a96fb0a06fcAbodunrinwa Toki     *
271972ab4f8588c365cf9c06e1f22b30a96fb0a06fcAbodunrinwa Toki     */
272972ab4f8588c365cf9c06e1f22b30a96fb0a06fcAbodunrinwa Toki    public void onWindowFocusChanged(boolean hasWindowFocus) {}
273972ab4f8588c365cf9c06e1f22b30a96fb0a06fcAbodunrinwa Toki
274972ab4f8588c365cf9c06e1f22b30a96fb0a06fcAbodunrinwa Toki    /**
275f8419a0299680ed580975b0fcb758990b4367db8Adam Powell     * Returns whether the UI presenting this action mode can take focus or not.
276f8419a0299680ed580975b0fcb758990b4367db8Adam Powell     * This is used by internal components within the framework that would otherwise
277f8419a0299680ed580975b0fcb758990b4367db8Adam Powell     * present an action mode UI that requires focus, such as an EditText as a custom view.
278f8419a0299680ed580975b0fcb758990b4367db8Adam Powell     *
279f8419a0299680ed580975b0fcb758990b4367db8Adam Powell     * @return true if the UI used to show this action mode can take focus
280f8419a0299680ed580975b0fcb758990b4367db8Adam Powell     * @hide Internal use only
281f8419a0299680ed580975b0fcb758990b4367db8Adam Powell     */
282ba51f15998e7aa284a09ca53053b340c744fcd9dAbodunrinwa Toki    @TestApi
283f8419a0299680ed580975b0fcb758990b4367db8Adam Powell    public boolean isUiFocusable() {
284f8419a0299680ed580975b0fcb758990b4367db8Adam Powell        return true;
285f8419a0299680ed580975b0fcb758990b4367db8Adam Powell    }
286f8419a0299680ed580975b0fcb758990b4367db8Adam Powell
287f8419a0299680ed580975b0fcb758990b4367db8Adam Powell    /**
2886e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * Callback interface for action modes. Supplied to
2896e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * {@link View#startActionMode(Callback)}, a Callback
2906e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * configures and handles events raised by a user's interaction with an action mode.
2916e34636749217654f43221885afb7a29bb5ca96aAdam Powell     *
2926e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * <p>An action mode's lifecycle is as follows:
2936e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * <ul>
2946e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * <li>{@link Callback#onCreateActionMode(ActionMode, Menu)} once on initial
2956e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * creation</li>
2966e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * <li>{@link Callback#onPrepareActionMode(ActionMode, Menu)} after creation
2976e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * and any time the {@link ActionMode} is invalidated</li>
2986e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * <li>{@link Callback#onActionItemClicked(ActionMode, MenuItem)} any time a
2996e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * contextual action button is clicked</li>
3006e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * <li>{@link Callback#onDestroyActionMode(ActionMode)} when the action mode
3016e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * is closed</li>
3026e34636749217654f43221885afb7a29bb5ca96aAdam Powell     * </ul>
3036e34636749217654f43221885afb7a29bb5ca96aAdam Powell     */
3046e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public interface Callback {
3056e34636749217654f43221885afb7a29bb5ca96aAdam Powell        /**
3066e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * Called when action mode is first created. The menu supplied will be used to
3076e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * generate action buttons for the action mode.
3086e34636749217654f43221885afb7a29bb5ca96aAdam Powell         *
3096e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * @param mode ActionMode being created
3106e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * @param menu Menu used to populate action buttons
3116e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * @return true if the action mode should be created, false if entering this
3126e34636749217654f43221885afb7a29bb5ca96aAdam Powell         *              mode should be aborted.
3136e34636749217654f43221885afb7a29bb5ca96aAdam Powell         */
3146e34636749217654f43221885afb7a29bb5ca96aAdam Powell        public boolean onCreateActionMode(ActionMode mode, Menu menu);
3156e34636749217654f43221885afb7a29bb5ca96aAdam Powell
3166e34636749217654f43221885afb7a29bb5ca96aAdam Powell        /**
3176e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * Called to refresh an action mode's action menu whenever it is invalidated.
3186e34636749217654f43221885afb7a29bb5ca96aAdam Powell         *
3196e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * @param mode ActionMode being prepared
3206e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * @param menu Menu used to populate action buttons
3216e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * @return true if the menu or action mode was updated, false otherwise.
3226e34636749217654f43221885afb7a29bb5ca96aAdam Powell         */
3236e34636749217654f43221885afb7a29bb5ca96aAdam Powell        public boolean onPrepareActionMode(ActionMode mode, Menu menu);
3246e34636749217654f43221885afb7a29bb5ca96aAdam Powell
3256e34636749217654f43221885afb7a29bb5ca96aAdam Powell        /**
3266e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * Called to report a user click on an action button.
3276e34636749217654f43221885afb7a29bb5ca96aAdam Powell         *
3286e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * @param mode The current ActionMode
3296e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * @param item The item that was clicked
3306e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * @return true if this callback handled the event, false if the standard MenuItem
3316e34636749217654f43221885afb7a29bb5ca96aAdam Powell         *          invocation should continue.
3326e34636749217654f43221885afb7a29bb5ca96aAdam Powell         */
3336e34636749217654f43221885afb7a29bb5ca96aAdam Powell        public boolean onActionItemClicked(ActionMode mode, MenuItem item);
3346e34636749217654f43221885afb7a29bb5ca96aAdam Powell
3356e34636749217654f43221885afb7a29bb5ca96aAdam Powell        /**
3366e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * Called when an action mode is about to be exited and destroyed.
3376e34636749217654f43221885afb7a29bb5ca96aAdam Powell         *
3386e34636749217654f43221885afb7a29bb5ca96aAdam Powell         * @param mode The current ActionMode being destroyed
3396e34636749217654f43221885afb7a29bb5ca96aAdam Powell         */
3406e34636749217654f43221885afb7a29bb5ca96aAdam Powell        public void onDestroyActionMode(ActionMode mode);
3416e34636749217654f43221885afb7a29bb5ca96aAdam Powell    }
342cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri
343cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri    /**
344cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri     * Extension of {@link ActionMode.Callback} to provide content rect information. This is
345cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri     * required for ActionModes with dynamic positioning such as the ones with type
346cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri     * {@link ActionMode#TYPE_FLOATING} to ensure the positioning doesn't obscure app content. If
347cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri     * an app fails to provide a subclass of this class, a default implementation will be used.
348cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri     */
349cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri    public static abstract class Callback2 implements ActionMode.Callback {
350cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri
351cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri        /**
352cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri         * Called when an ActionMode needs to be positioned on screen, potentially occluding view
353cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri         * content. Note this may be called on a per-frame basis.
354cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri         *
355cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri         * @param mode The ActionMode that requires positioning.
356cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri         * @param view The View that originated the ActionMode, in whose coordinates the Rect should
357cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri         *          be provided.
358e95cc176bb6b4577ec8dcc0f37a6efe6ca40e9bdClara Bayarri         * @param outRect The Rect to be populated with the content position. Use this to specify
359e95cc176bb6b4577ec8dcc0f37a6efe6ca40e9bdClara Bayarri         *          where the content in your app lives within the given view. This will be used
360e95cc176bb6b4577ec8dcc0f37a6efe6ca40e9bdClara Bayarri         *          to avoid occluding the given content Rect with the created ActionMode.
361cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri         */
362cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri        public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
363cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri            if (view != null) {
364cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri                outRect.set(0, 0, view.getWidth(), view.getHeight());
365cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri            } else {
366cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri                outRect.set(0, 0, 0, 0);
367cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri            }
368cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri        }
369cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri
370cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri    }
371cba5fc22d17eafd755d9a248841bc9b69fb34763Clara Bayarri}
372