81b4cd4d20c5704369d66535ea9d949e4f7198dd
2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.actionbarsherlock
.view
;
19 import android
.view
.View
;
23 * Represents a contextual mode of the user interface. Action modes can be used for
24 * modal interactions with content and replace parts of the normal UI until finished.
25 * Examples of good action modes include selection modes, search, content editing, etc.
27 public abstract class ActionMode
{
31 * Set a tag object associated with this ActionMode.
33 * <p>Like the tag available to views, this allows applications to associate arbitrary
34 * data with an ActionMode for later reference.
36 * @param tag Tag to associate with this ActionMode
40 public void setTag(Object tag
) {
45 * Retrieve the tag object associated with this ActionMode.
47 * <p>Like the tag available to views, this allows applications to associate arbitrary
48 * data with an ActionMode for later reference.
50 * @return Tag associated with this ActionMode
52 * @see #setTag(Object)
54 public Object
getTag() {
59 * Set the title of the action mode. This method will have no visible effect if
60 * a custom view has been set.
62 * @param title Title string to set
65 * @see #setCustomView(View)
67 public abstract void setTitle(CharSequence title
);
70 * Set the title of the action mode. This method will have no visible effect if
71 * a custom view has been set.
73 * @param resId Resource ID of a string to set as the title
75 * @see #setTitle(CharSequence)
76 * @see #setCustomView(View)
78 public abstract void setTitle(int resId
);
81 * Set the subtitle of the action mode. This method will have no visible effect if
82 * a custom view has been set.
84 * @param subtitle Subtitle string to set
86 * @see #setSubtitle(int)
87 * @see #setCustomView(View)
89 public abstract void setSubtitle(CharSequence subtitle
);
92 * Set the subtitle of the action mode. This method will have no visible effect if
93 * a custom view has been set.
95 * @param resId Resource ID of a string to set as the subtitle
97 * @see #setSubtitle(CharSequence)
98 * @see #setCustomView(View)
100 public abstract void setSubtitle(int resId
);
103 * Set a custom view for this action mode. The custom view will take the place of
104 * the title and subtitle. Useful for things like search boxes.
106 * @param view Custom view to use in place of the title/subtitle.
108 * @see #setTitle(CharSequence)
109 * @see #setSubtitle(CharSequence)
111 public abstract void setCustomView(View view
);
114 * Invalidate the action mode and refresh menu content. The mode's
115 * {@link ActionMode.Callback} will have its
116 * {@link Callback#onPrepareActionMode(ActionMode, Menu)} method called.
117 * If it returns true the menu will be scanned for updated content and any relevant changes
118 * will be reflected to the user.
120 public abstract void invalidate();
123 * Finish and close this action mode. The action mode's {@link ActionMode.Callback} will
124 * have its {@link Callback#onDestroyActionMode(ActionMode)} method called.
126 public abstract void finish();
129 * Returns the menu of actions that this action mode presents.
130 * @return The action mode's menu.
132 public abstract Menu
getMenu();
135 * Returns the current title of this action mode.
138 public abstract CharSequence
getTitle();
141 * Returns the current subtitle of this action mode.
142 * @return Subtitle text
144 public abstract CharSequence
getSubtitle();
147 * Returns the current custom view for this action mode.
148 * @return The current custom view
150 public abstract View
getCustomView();
153 * Returns a {@link MenuInflater} with the ActionMode's context.
155 public abstract MenuInflater
getMenuInflater();
158 * Returns whether the UI presenting this action mode can take focus or not.
159 * This is used by internal components within the framework that would otherwise
160 * present an action mode UI that requires focus, such as an EditText as a custom view.
162 * @return true if the UI used to show this action mode can take focus
163 * @hide Internal use only
165 public boolean isUiFocusable() {
170 * Callback interface for action modes. Supplied to
171 * {@link View#startActionMode(Callback)}, a Callback
172 * configures and handles events raised by a user's interaction with an action mode.
174 * <p>An action mode's lifecycle is as follows:
176 * <li>{@link Callback#onCreateActionMode(ActionMode, Menu)} once on initial
178 * <li>{@link Callback#onPrepareActionMode(ActionMode, Menu)} after creation
179 * and any time the {@link ActionMode} is invalidated</li>
180 * <li>{@link Callback#onActionItemClicked(ActionMode, MenuItem)} any time a
181 * contextual action button is clicked</li>
182 * <li>{@link Callback#onDestroyActionMode(ActionMode)} when the action mode
186 public interface Callback
{
188 * Called when action mode is first created. The menu supplied will be used to
189 * generate action buttons for the action mode.
191 * @param mode ActionMode being created
192 * @param menu Menu used to populate action buttons
193 * @return true if the action mode should be created, false if entering this
194 * mode should be aborted.
196 public boolean onCreateActionMode(ActionMode mode
, Menu menu
);
199 * Called to refresh an action mode's action menu whenever it is invalidated.
201 * @param mode ActionMode being prepared
202 * @param menu Menu used to populate action buttons
203 * @return true if the menu or action mode was updated, false otherwise.
205 public boolean onPrepareActionMode(ActionMode mode
, Menu menu
);
208 * Called to report a user click on an action button.
210 * @param mode The current ActionMode
211 * @param item The item that was clicked
212 * @return true if this callback handled the event, false if the standard MenuItem
213 * invocation should continue.
215 public boolean onActionItemClicked(ActionMode mode
, MenuItem item
);
218 * Called when an action mode is about to be exited and destroyed.
220 * @param mode The current ActionMode being destroyed
222 public void onDestroyActionMode(ActionMode mode
);