1bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/*
2bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Copyright (C) 2010 The Android Open Source Project
3bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *
4bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Licensed under the Apache License, Version 2.0 (the "License");
5bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * you may not use this file except in compliance with the License.
6bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * You may obtain a copy of the License at
7bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *
8bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *      http://www.apache.org/licenses/LICENSE-2.0
9bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell *
10bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Unless required by applicable law or agreed to in writing, software
11bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * distributed under the License is distributed on an "AS IS" BASIS,
12bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * See the License for the specific language governing permissions and
14bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * limitations under the License.
15bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */
16bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
17ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikaspackage androidx.appcompat.view;
18bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
19ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
208e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas
2130837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.view.Menu;
2230837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.view.MenuInflater;
2330837f1095c803f332f4a1c3f0917c8afdd50156Adam Powellimport android.view.MenuItem;
24bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.View;
25bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
263de8a4e8305507475d7890205184946a25cf45e7Aurimas Liutikasimport androidx.annotation.RestrictTo;
273de8a4e8305507475d7890205184946a25cf45e7Aurimas Liutikas
28bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/**
29bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Represents a contextual mode of the user interface. Action modes can be used to provide
3013ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes * alternative interaction modes and replace parts of the normal UI until finished.
3113ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes * Examples of good action modes include text selection and contextual actions.
32bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * <div class="special reference">
3320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns *
34bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * <h3>Developer Guides</h3>
3513ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes * <p>For information about how to provide contextual actions with {@code ActionMode},
3613ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes * read the <a href="{@docRoot}guide/topics/ui/menus.html#context-menu">Menus</a>
37bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * developer guide.</p>
3820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns *
39bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * </div>
40bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */
41bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellpublic abstract class ActionMode {
42bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
4320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    private Object mTag;
4420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    private boolean mTitleOptionalHint;
45bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
4620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
4720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Set a tag object associated with this ActionMode.
4820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
4913ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * <p>Like the tag available to views, this allows applications to associate arbitrary
5013ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * data with an ActionMode for later reference.
5120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
5220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param tag Tag to associate with this ActionMode
5313ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     *
5420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #getTag()
5520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
5620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public void setTag(Object tag) {
5720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        mTag = tag;
5820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
59bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
6020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
6120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Retrieve the tag object associated with this ActionMode.
6220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
6313ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * <p>Like the tag available to views, this allows applications to associate arbitrary
6413ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * data with an ActionMode for later reference.
6520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
6620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @return Tag associated with this ActionMode
6713ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     *
6820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setTag(Object)
6920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
7020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public Object getTag() {
7120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        return mTag;
7220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
73bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
7420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
7513ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * Set the title of the action mode. This method will have no visible effect if
7613ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * a custom view has been set.
7720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
7820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param title Title string to set
7913ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     *
8020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setTitle(int)
8120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setCustomView(View)
8220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
8320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract void setTitle(CharSequence title);
84bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
8520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
8613ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * Set the title of the action mode. This method will have no visible effect if
8713ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * a custom view has been set.
8820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
8920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param resId Resource ID of a string to set as the title
9013ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     *
9120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setTitle(CharSequence)
9220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setCustomView(View)
9320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
9420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract void setTitle(int resId);
95bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
9620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
9713ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * Set the subtitle of the action mode. This method will have no visible effect if
9813ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * a custom view has been set.
9920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
10020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param subtitle Subtitle string to set
10113ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     *
10220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setSubtitle(int)
10320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setCustomView(View)
10420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
10520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract void setSubtitle(CharSequence subtitle);
106bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
10720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
10813ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * Set the subtitle of the action mode. This method will have no visible effect if
10913ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * a custom view has been set.
11020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
11120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param resId Resource ID of a string to set as the subtitle
11213ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     *
11320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setSubtitle(CharSequence)
11420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setCustomView(View)
11520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
11620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract void setSubtitle(int resId);
117bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
11820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
11913ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * Set whether or not the title/subtitle display for this action mode
12013ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * is optional.
12120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
12213ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * <p>In many cases the supplied title for an action mode is merely
12313ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * meant to add context and is not strictly required for the action
12413ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * mode to be useful. If the title is optional, the system may choose
12513ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * to hide the title entirely rather than truncate it due to a lack
12613ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * of available space.</p>
12720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
12813ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * <p>Note that this is merely a hint; the underlying implementation
12913ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * may choose to ignore this setting under some circumstances.</p>
13020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
13120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param titleOptional true if the title only presents optional information.
13220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
13320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public void setTitleOptionalHint(boolean titleOptional) {
13420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        mTitleOptionalHint = titleOptional;
13520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
136bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
13720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
13813ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * @return true if this action mode has been given a hint to consider the
13913ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     *         title/subtitle display to be optional.
14013ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     *
14120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setTitleOptionalHint(boolean)
14220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #isTitleOptional()
14320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
14420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public boolean getTitleOptionalHint() {
14520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        return mTitleOptionalHint;
14620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
147bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
14820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
14913ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * @return true if this action mode considers the title and subtitle fields
15013ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     *         as optional. Optional titles may not be displayed to the user.
15120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
15220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public boolean isTitleOptional() {
15320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        return false;
15420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
155bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
15620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
15713ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * Set a custom view for this action mode. The custom view will take the place of
15813ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * the title and subtitle. Useful for things like search boxes.
15920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
16020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @param view Custom view to use in place of the title/subtitle.
16113ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     *
16220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setTitle(CharSequence)
16320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @see #setSubtitle(CharSequence)
16420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
16520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract void setCustomView(View view);
166bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
16720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
16813ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * Invalidate the action mode and refresh menu content. The mode's
16913ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * {@link ActionMode.Callback} will have its
17013ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * {@link Callback#onPrepareActionMode(ActionMode, Menu)} method called.
17113ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * If it returns true the menu will be scanned for updated content and any relevant changes
17213ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * will be reflected to the user.
17320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
17420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract void invalidate();
175bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
17620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
17713ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * Finish and close this action mode. The action mode's {@link ActionMode.Callback} will
17813ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * have its {@link Callback#onDestroyActionMode(ActionMode)} method called.
17920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
18020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract void finish();
181bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
18220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
18320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Returns the menu of actions that this action mode presents.
18420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
18520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @return The action mode's menu.
18620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
18720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract Menu getMenu();
188bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
18920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
19020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Returns the current title of this action mode.
19120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
19220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @return Title text
19320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
19420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract CharSequence getTitle();
195bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
196bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    /**
19720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Returns the current subtitle of this action mode.
198bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     *
19920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @return Subtitle text
200bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     */
20120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract CharSequence getSubtitle();
202bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
203bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    /**
20420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Returns the current custom view for this action mode.
205bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     *
20620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @return The current custom view
207bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     */
20820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract View getCustomView();
209bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
210bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    /**
21120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * Returns a {@link MenuInflater} with the ActionMode's context.
21220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     */
21320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public abstract MenuInflater getMenuInflater();
21420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
21520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    /**
21613ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * Returns whether the UI presenting this action mode can take focus or not.
21713ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * This is used by internal components within the framework that would otherwise
21813ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * present an action mode UI that requires focus, such as an EditText as a custom view.
219bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     *
22020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @return true if the UI used to show this action mode can take focus
22120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * @hide Internal use only
222bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     */
2238e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas    @RestrictTo(LIBRARY_GROUP)
22420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public boolean isUiFocusable() {
22520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        return true;
22620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
227bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell
228bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell    /**
22930837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * Callback interface for action modes. Supplied to
230ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas     * {@link androidx.appcompat.app.AppCompatDelegate#startSupportActionMode(Callback)} (Callback)},
23130837f1095c803f332f4a1c3f0917c8afdd50156Adam Powell     * a Callback configures and handles events raised by a user's interaction with an action mode.
23220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     *
23320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns     * <p>An action mode's lifecycle is as follows:
23413ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * <ul>
23513ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * <li>{@link Callback#onCreateActionMode(ActionMode, Menu)} once on initial
23613ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * creation</li>
23713ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * <li>{@link Callback#onPrepareActionMode(ActionMode, Menu)} after creation
23813ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * and any time the {@link ActionMode} is invalidated</li>
23913ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * <li>{@link Callback#onActionItemClicked(ActionMode, MenuItem)} any time a
24013ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * contextual action button is clicked</li>
24113ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * <li>{@link Callback#onDestroyActionMode(ActionMode)} when the action mode
24213ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * is closed</li>
24313ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes     * </ul>
244bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell     */
24520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    public interface Callback {
24620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
24720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        /**
24813ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes         * Called when action mode is first created. The menu supplied will be used to
24913ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes         * generate action buttons for the action mode.
25020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         *
25120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * @param mode ActionMode being created
25220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * @param menu Menu used to populate action buttons
25313ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes         * @return true if the action mode should be created, false if entering this
25413ab4aa8a1d337c414c887a81b9829f2286cdd37Chris Banes         *              mode should be aborted.
25520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         */
25620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        public boolean onCreateActionMode(ActionMode mode, Menu menu);
25720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
25820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        /**
25920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * Called to refresh an action mode's action menu whenever it is invalidated.
26020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         *
26120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * @param mode ActionMode being prepared
26220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * @param menu Menu used to populate action buttons
26320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * @return true if the menu or action mode was updated, false otherwise.
26420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         */
26520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        public boolean onPrepareActionMode(ActionMode mode, Menu menu);
26620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
26720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        /**
26820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * Called to report a user click on an action button.
26920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         *
27020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * @param mode The current ActionMode
27120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * @param item The item that was clicked
27220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * @return true if this callback handled the event, false if the standard MenuItem
27320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         *         invocation should continue.
27420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         */
27520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        public boolean onActionItemClicked(ActionMode mode, MenuItem item);
27620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns
27720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        /**
27820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * Called when an action mode is about to be exited and destroyed.
27920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         *
28020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         * @param mode The current ActionMode being destroyed
28120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns         */
28220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns        public void onDestroyActionMode(ActionMode mode);
28320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns    }
284ced50ab7536cd3d3573f03310fc899f10c414d37Anirudh Dewani}
285