Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 19 | import android.annotation.IntDef; |
| 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.res.TypedArray; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 24 | import android.graphics.drawable.Drawable; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 25 | import android.util.AttributeSet; |
| 26 | import android.view.Gravity; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 27 | import android.view.View; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 28 | import android.view.ViewDebug; |
| 29 | import android.view.ViewGroup; |
| 30 | import android.view.ViewGroup.MarginLayoutParams; |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 31 | import android.view.Window; |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 32 | import android.widget.SpinnerAdapter; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 33 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 34 | import java.lang.annotation.Retention; |
| 35 | import java.lang.annotation.RetentionPolicy; |
| 36 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 37 | /** |
Scott Main | e797ed6 | 2011-09-22 16:17:45 -0700 | [diff] [blame] | 38 | * A window feature at the top of the activity that may display the activity title, navigation |
| 39 | * modes, and other interactive items. |
| 40 | * <p>Beginning with Android 3.0 (API level 11), the action bar appears at the top of an |
| 41 | * activity's window when the activity uses the system's {@link |
| 42 | * android.R.style#Theme_Holo Holo} theme (or one of its descendant themes), which is the default. |
| 43 | * You may otherwise add the action bar by calling {@link |
| 44 | * android.view.Window#requestFeature requestFeature(FEATURE_ACTION_BAR)} or by declaring it in a |
| 45 | * custom theme with the {@link android.R.styleable#Theme_windowActionBar windowActionBar} property. |
| 46 | * <p>By default, the action bar shows the application icon on |
| 47 | * the left, followed by the activity title. If your activity has an options menu, you can make |
| 48 | * select items accessible directly from the action bar as "action items". You can also |
| 49 | * modify various characteristics of the action bar or remove it completely.</p> |
Scott Main | 36193d0 | 2011-07-12 15:24:01 -0700 | [diff] [blame] | 50 | * <p>From your activity, you can retrieve an instance of {@link ActionBar} by calling {@link |
| 51 | * android.app.Activity#getActionBar getActionBar()}.</p> |
Scott Main | e797ed6 | 2011-09-22 16:17:45 -0700 | [diff] [blame] | 52 | * <p>In some cases, the action bar may be overlayed by another bar that enables contextual actions, |
| 53 | * using an {@link android.view.ActionMode}. For example, when the user selects one or more items in |
| 54 | * your activity, you can enable an action mode that offers actions specific to the selected |
| 55 | * items, with a UI that temporarily replaces the action bar. Although the UI may occupy the |
| 56 | * same space, the {@link android.view.ActionMode} APIs are distinct and independent from those for |
| 57 | * {@link ActionBar}. |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 58 | * <div class="special reference"> |
| 59 | * <h3>Developer Guides</h3> |
| 60 | * <p>For information about how to use the action bar, including how to add action items, navigation |
| 61 | * modes and more, read the <a href="{@docRoot}guide/topics/ui/actionbar.html">Action |
| 62 | * Bar</a> developer guide.</p> |
| 63 | * </div> |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 64 | */ |
| 65 | public abstract class ActionBar { |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 66 | /** @hide */ |
| 67 | @Retention(RetentionPolicy.SOURCE) |
| 68 | @IntDef({NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS}) |
| 69 | public @interface NavigationMode {} |
| 70 | |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 71 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 72 | * Standard navigation mode. Consists of either a logo or icon |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 73 | * and title text with an optional subtitle. Clicking any of these elements |
Adam Powell | cf03576 | 2010-12-06 11:49:45 -0800 | [diff] [blame] | 74 | * will dispatch onOptionsItemSelected to the host Activity with |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 75 | * a MenuItem with item ID android.R.id.home. |
| 76 | */ |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 77 | public static final int NAVIGATION_MODE_STANDARD = 0; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 80 | * List navigation mode. Instead of static title text this mode |
| 81 | * presents a list menu for navigation within the activity. |
| 82 | * e.g. this might be presented to the user as a dropdown list. |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 83 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 84 | public static final int NAVIGATION_MODE_LIST = 1; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Tab navigation mode. Instead of static title text this mode |
| 88 | * presents a series of tabs for navigation within the activity. |
| 89 | */ |
| 90 | public static final int NAVIGATION_MODE_TABS = 2; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 91 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 92 | /** @hide */ |
| 93 | @Retention(RetentionPolicy.SOURCE) |
| 94 | @IntDef(flag = true, |
| 95 | value = { |
| 96 | DISPLAY_USE_LOGO, |
| 97 | DISPLAY_SHOW_HOME, |
| 98 | DISPLAY_HOME_AS_UP, |
| 99 | DISPLAY_SHOW_TITLE, |
| 100 | DISPLAY_SHOW_CUSTOM, |
| 101 | DISPLAY_TITLE_MULTIPLE_LINES |
| 102 | }) |
| 103 | public @interface DisplayOptions {} |
| 104 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 105 | /** |
| 106 | * Use logo instead of icon if available. This flag will cause appropriate |
| 107 | * navigation modes to use a wider logo in place of the standard icon. |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 108 | * |
| 109 | * @see #setDisplayOptions(int) |
| 110 | * @see #setDisplayOptions(int, int) |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 111 | */ |
| 112 | public static final int DISPLAY_USE_LOGO = 0x1; |
| 113 | |
| 114 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 115 | * Show 'home' elements in this action bar, leaving more space for other |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 116 | * navigation elements. This includes logo and icon. |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 117 | * |
| 118 | * @see #setDisplayOptions(int) |
| 119 | * @see #setDisplayOptions(int, int) |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 120 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 121 | public static final int DISPLAY_SHOW_HOME = 0x2; |
| 122 | |
| 123 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 124 | * Display the 'home' element such that it appears as an 'up' affordance. |
| 125 | * e.g. show an arrow to the left indicating the action that will be taken. |
| 126 | * |
| 127 | * Set this flag if selecting the 'home' button in the action bar to return |
| 128 | * up by a single level in your UI rather than back to the top level or front page. |
| 129 | * |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 130 | * <p>Setting this option will implicitly enable interaction with the home/up |
| 131 | * button. See {@link #setHomeButtonEnabled(boolean)}. |
| 132 | * |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 133 | * @see #setDisplayOptions(int) |
| 134 | * @see #setDisplayOptions(int, int) |
| 135 | */ |
| 136 | public static final int DISPLAY_HOME_AS_UP = 0x4; |
| 137 | |
| 138 | /** |
| 139 | * Show the activity title and subtitle, if present. |
| 140 | * |
| 141 | * @see #setTitle(CharSequence) |
| 142 | * @see #setTitle(int) |
| 143 | * @see #setSubtitle(CharSequence) |
| 144 | * @see #setSubtitle(int) |
| 145 | * @see #setDisplayOptions(int) |
| 146 | * @see #setDisplayOptions(int, int) |
| 147 | */ |
| 148 | public static final int DISPLAY_SHOW_TITLE = 0x8; |
| 149 | |
| 150 | /** |
| 151 | * Show the custom view if one has been set. |
| 152 | * @see #setCustomView(View) |
| 153 | * @see #setDisplayOptions(int) |
| 154 | * @see #setDisplayOptions(int, int) |
| 155 | */ |
| 156 | public static final int DISPLAY_SHOW_CUSTOM = 0x10; |
| 157 | |
| 158 | /** |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 159 | * Allow the title to wrap onto multiple lines if space is available |
| 160 | * @hide pending API approval |
| 161 | */ |
| 162 | public static final int DISPLAY_TITLE_MULTIPLE_LINES = 0x20; |
| 163 | |
| 164 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 165 | * Set the action bar into custom navigation mode, supplying a view |
| 166 | * for custom navigation. |
| 167 | * |
| 168 | * Custom navigation views appear between the application icon and |
| 169 | * any action buttons and may use any space available there. Common |
| 170 | * use cases for custom navigation views might include an auto-suggesting |
| 171 | * address bar for a browser or other navigation mechanisms that do not |
| 172 | * translate well to provided navigation modes. |
| 173 | * |
| 174 | * @param view Custom navigation view to place in the ActionBar. |
| 175 | */ |
| 176 | public abstract void setCustomView(View view); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 177 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 178 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 179 | * Set the action bar into custom navigation mode, supplying a view |
| 180 | * for custom navigation. |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 181 | * |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 182 | * <p>Custom navigation views appear between the application icon and |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 183 | * any action buttons and may use any space available there. Common |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 184 | * use cases for custom navigation views might include an auto-suggesting |
| 185 | * address bar for a browser or other navigation mechanisms that do not |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 186 | * translate well to provided navigation modes.</p> |
| 187 | * |
| 188 | * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for |
| 189 | * the custom view to be displayed.</p> |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 190 | * |
| 191 | * @param view Custom navigation view to place in the ActionBar. |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 192 | * @param layoutParams How this custom view should layout in the bar. |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 193 | * |
| 194 | * @see #setDisplayOptions(int, int) |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 195 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 196 | public abstract void setCustomView(View view, LayoutParams layoutParams); |
| 197 | |
| 198 | /** |
Adam Powell | 3f476b3 | 2011-01-03 19:25:36 -0800 | [diff] [blame] | 199 | * Set the action bar into custom navigation mode, supplying a view |
| 200 | * for custom navigation. |
| 201 | * |
| 202 | * <p>Custom navigation views appear between the application icon and |
| 203 | * any action buttons and may use any space available there. Common |
| 204 | * use cases for custom navigation views might include an auto-suggesting |
| 205 | * address bar for a browser or other navigation mechanisms that do not |
| 206 | * translate well to provided navigation modes.</p> |
| 207 | * |
| 208 | * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for |
| 209 | * the custom view to be displayed.</p> |
| 210 | * |
| 211 | * @param resId Resource ID of a layout to inflate into the ActionBar. |
| 212 | * |
| 213 | * @see #setDisplayOptions(int, int) |
| 214 | */ |
| 215 | public abstract void setCustomView(int resId); |
| 216 | |
| 217 | /** |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 218 | * Set the icon to display in the 'home' section of the action bar. |
| 219 | * The action bar will use an icon specified by its style or the |
| 220 | * activity icon by default. |
| 221 | * |
| 222 | * Whether the home section shows an icon or logo is controlled |
| 223 | * by the display option {@link #DISPLAY_USE_LOGO}. |
| 224 | * |
| 225 | * @param resId Resource ID of a drawable to show as an icon. |
| 226 | * |
| 227 | * @see #setDisplayUseLogoEnabled(boolean) |
| 228 | * @see #setDisplayShowHomeEnabled(boolean) |
| 229 | */ |
| 230 | public abstract void setIcon(int resId); |
| 231 | |
| 232 | /** |
| 233 | * Set the icon to display in the 'home' section of the action bar. |
| 234 | * The action bar will use an icon specified by its style or the |
| 235 | * activity icon by default. |
| 236 | * |
| 237 | * Whether the home section shows an icon or logo is controlled |
| 238 | * by the display option {@link #DISPLAY_USE_LOGO}. |
| 239 | * |
| 240 | * @param icon Drawable to show as an icon. |
| 241 | * |
| 242 | * @see #setDisplayUseLogoEnabled(boolean) |
| 243 | * @see #setDisplayShowHomeEnabled(boolean) |
| 244 | */ |
| 245 | public abstract void setIcon(Drawable icon); |
| 246 | |
| 247 | /** |
| 248 | * Set the logo to display in the 'home' section of the action bar. |
| 249 | * The action bar will use a logo specified by its style or the |
| 250 | * activity logo by default. |
| 251 | * |
| 252 | * Whether the home section shows an icon or logo is controlled |
| 253 | * by the display option {@link #DISPLAY_USE_LOGO}. |
| 254 | * |
| 255 | * @param resId Resource ID of a drawable to show as a logo. |
| 256 | * |
| 257 | * @see #setDisplayUseLogoEnabled(boolean) |
| 258 | * @see #setDisplayShowHomeEnabled(boolean) |
| 259 | */ |
| 260 | public abstract void setLogo(int resId); |
| 261 | |
| 262 | /** |
| 263 | * Set the logo to display in the 'home' section of the action bar. |
| 264 | * The action bar will use a logo specified by its style or the |
| 265 | * activity logo by default. |
| 266 | * |
| 267 | * Whether the home section shows an icon or logo is controlled |
| 268 | * by the display option {@link #DISPLAY_USE_LOGO}. |
| 269 | * |
| 270 | * @param logo Drawable to show as a logo. |
| 271 | * |
| 272 | * @see #setDisplayUseLogoEnabled(boolean) |
| 273 | * @see #setDisplayShowHomeEnabled(boolean) |
| 274 | */ |
| 275 | public abstract void setLogo(Drawable logo); |
| 276 | |
| 277 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 278 | * Set the adapter and navigation callback for list navigation mode. |
| 279 | * |
| 280 | * The supplied adapter will provide views for the expanded list as well as |
| 281 | * the currently selected item. (These may be displayed differently.) |
| 282 | * |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 283 | * The supplied OnNavigationListener will alert the application when the user |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 284 | * changes the current list selection. |
| 285 | * |
| 286 | * @param adapter An adapter that will provide views both to display |
| 287 | * the current navigation selection and populate views |
| 288 | * within the dropdown navigation menu. |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 289 | * @param callback An OnNavigationListener that will receive events when the user |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 290 | * selects a navigation item. |
| 291 | */ |
| 292 | public abstract void setListNavigationCallbacks(SpinnerAdapter adapter, |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 293 | OnNavigationListener callback); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 294 | |
| 295 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 296 | * Set the selected navigation item in list or tabbed navigation modes. |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 297 | * |
| 298 | * @param position Position of the item to select. |
| 299 | */ |
| 300 | public abstract void setSelectedNavigationItem(int position); |
| 301 | |
| 302 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 303 | * Get the position of the selected navigation item in list or tabbed navigation modes. |
| 304 | * |
| 305 | * @return Position of the selected item. |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 306 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 307 | public abstract int getSelectedNavigationIndex(); |
| 308 | |
| 309 | /** |
| 310 | * Get the number of navigation items present in the current navigation mode. |
| 311 | * |
| 312 | * @return Number of navigation items. |
| 313 | */ |
| 314 | public abstract int getNavigationItemCount(); |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 315 | |
| 316 | /** |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 317 | * Set the action bar's title. This will only be displayed if |
| 318 | * {@link #DISPLAY_SHOW_TITLE} is set. |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 319 | * |
| 320 | * @param title Title to set |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 321 | * |
| 322 | * @see #setTitle(int) |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 323 | * @see #setDisplayOptions(int, int) |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 324 | */ |
| 325 | public abstract void setTitle(CharSequence title); |
| 326 | |
| 327 | /** |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 328 | * Set the action bar's title. This will only be displayed if |
| 329 | * {@link #DISPLAY_SHOW_TITLE} is set. |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 330 | * |
| 331 | * @param resId Resource ID of title string to set |
| 332 | * |
| 333 | * @see #setTitle(CharSequence) |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 334 | * @see #setDisplayOptions(int, int) |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 335 | */ |
| 336 | public abstract void setTitle(int resId); |
| 337 | |
| 338 | /** |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 339 | * Set the action bar's subtitle. This will only be displayed if |
| 340 | * {@link #DISPLAY_SHOW_TITLE} is set. Set to null to disable the |
| 341 | * subtitle entirely. |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 342 | * |
| 343 | * @param subtitle Subtitle to set |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 344 | * |
| 345 | * @see #setSubtitle(int) |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 346 | * @see #setDisplayOptions(int, int) |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 347 | */ |
| 348 | public abstract void setSubtitle(CharSequence subtitle); |
| 349 | |
| 350 | /** |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 351 | * Set the action bar's subtitle. This will only be displayed if |
| 352 | * {@link #DISPLAY_SHOW_TITLE} is set. |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 353 | * |
| 354 | * @param resId Resource ID of subtitle string to set |
| 355 | * |
| 356 | * @see #setSubtitle(CharSequence) |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 357 | * @see #setDisplayOptions(int, int) |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 358 | */ |
| 359 | public abstract void setSubtitle(int resId); |
| 360 | |
| 361 | /** |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 362 | * Set display options. This changes all display option bits at once. To change |
| 363 | * a limited subset of display options, see {@link #setDisplayOptions(int, int)}. |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 364 | * |
| 365 | * @param options A combination of the bits defined by the DISPLAY_ constants |
| 366 | * defined in ActionBar. |
| 367 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 368 | public abstract void setDisplayOptions(@DisplayOptions int options); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 369 | |
| 370 | /** |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 371 | * Set selected display options. Only the options specified by mask will be changed. |
| 372 | * To change all display option bits at once, see {@link #setDisplayOptions(int)}. |
| 373 | * |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 374 | * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the |
| 375 | * {@link #DISPLAY_SHOW_HOME} option. |
Ben Komalo | 5ad7af6 | 2010-11-01 12:04:51 -0700 | [diff] [blame] | 376 | * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO) |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 377 | * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}. |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 378 | * |
| 379 | * @param options A combination of the bits defined by the DISPLAY_ constants |
| 380 | * defined in ActionBar. |
| 381 | * @param mask A bit mask declaring which display options should be changed. |
| 382 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 383 | public abstract void setDisplayOptions(@DisplayOptions int options, @DisplayOptions int mask); |
Adam Powell | 3f476b3 | 2011-01-03 19:25:36 -0800 | [diff] [blame] | 384 | |
| 385 | /** |
| 386 | * Set whether to display the activity logo rather than the activity icon. |
| 387 | * A logo is often a wider, more detailed image. |
| 388 | * |
| 389 | * <p>To set several display options at once, see the setDisplayOptions methods. |
| 390 | * |
| 391 | * @param useLogo true to use the activity logo, false to use the activity icon. |
| 392 | * |
| 393 | * @see #setDisplayOptions(int) |
| 394 | * @see #setDisplayOptions(int, int) |
| 395 | */ |
| 396 | public abstract void setDisplayUseLogoEnabled(boolean useLogo); |
| 397 | |
| 398 | /** |
| 399 | * Set whether to include the application home affordance in the action bar. |
| 400 | * Home is presented as either an activity icon or logo. |
| 401 | * |
| 402 | * <p>To set several display options at once, see the setDisplayOptions methods. |
| 403 | * |
| 404 | * @param showHome true to show home, false otherwise. |
| 405 | * |
| 406 | * @see #setDisplayOptions(int) |
| 407 | * @see #setDisplayOptions(int, int) |
| 408 | */ |
| 409 | public abstract void setDisplayShowHomeEnabled(boolean showHome); |
| 410 | |
| 411 | /** |
| 412 | * Set whether home should be displayed as an "up" affordance. |
| 413 | * Set this to true if selecting "home" returns up by a single level in your UI |
| 414 | * rather than back to the top level or front page. |
| 415 | * |
| 416 | * <p>To set several display options at once, see the setDisplayOptions methods. |
| 417 | * |
| 418 | * @param showHomeAsUp true to show the user that selecting home will return one |
| 419 | * level up rather than to the top level of the app. |
| 420 | * |
| 421 | * @see #setDisplayOptions(int) |
| 422 | * @see #setDisplayOptions(int, int) |
| 423 | */ |
| 424 | public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp); |
| 425 | |
| 426 | /** |
| 427 | * Set whether an activity title/subtitle should be displayed. |
| 428 | * |
| 429 | * <p>To set several display options at once, see the setDisplayOptions methods. |
| 430 | * |
| 431 | * @param showTitle true to display a title/subtitle if present. |
| 432 | * |
| 433 | * @see #setDisplayOptions(int) |
| 434 | * @see #setDisplayOptions(int, int) |
| 435 | */ |
| 436 | public abstract void setDisplayShowTitleEnabled(boolean showTitle); |
| 437 | |
| 438 | /** |
| 439 | * Set whether a custom view should be displayed, if set. |
| 440 | * |
| 441 | * <p>To set several display options at once, see the setDisplayOptions methods. |
| 442 | * |
| 443 | * @param showCustom true if the currently set custom view should be displayed, false otherwise. |
| 444 | * |
| 445 | * @see #setDisplayOptions(int) |
| 446 | * @see #setDisplayOptions(int, int) |
| 447 | */ |
| 448 | public abstract void setDisplayShowCustomEnabled(boolean showCustom); |
| 449 | |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 450 | /** |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 451 | * Set the ActionBar's background. This will be used for the primary |
| 452 | * action bar. |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 453 | * |
| 454 | * @param d Background drawable |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 455 | * @see #setStackedBackgroundDrawable(Drawable) |
| 456 | * @see #setSplitBackgroundDrawable(Drawable) |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 457 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 458 | public abstract void setBackgroundDrawable(@Nullable Drawable d); |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 459 | |
| 460 | /** |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 461 | * Set the ActionBar's stacked background. This will appear |
| 462 | * in the second row/stacked bar on some devices and configurations. |
| 463 | * |
| 464 | * @param d Background drawable for the stacked row |
| 465 | */ |
Adam Powell | 0145322 | 2011-09-07 16:13:36 -0700 | [diff] [blame] | 466 | public void setStackedBackgroundDrawable(Drawable d) { } |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 467 | |
| 468 | /** |
| 469 | * Set the ActionBar's split background. This will appear in |
| 470 | * the split action bar containing menu-provided action buttons |
| 471 | * on some devices and configurations. |
Scott Main | e797ed6 | 2011-09-22 16:17:45 -0700 | [diff] [blame] | 472 | * <p>You can enable split action bar with {@link android.R.attr#uiOptions} |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 473 | * |
| 474 | * @param d Background drawable for the split bar |
| 475 | */ |
Adam Powell | 0145322 | 2011-09-07 16:13:36 -0700 | [diff] [blame] | 476 | public void setSplitBackgroundDrawable(Drawable d) { } |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 477 | |
| 478 | /** |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 479 | * @return The current custom view. |
| 480 | */ |
| 481 | public abstract View getCustomView(); |
| 482 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 483 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 484 | * Returns the current ActionBar title in standard mode. |
| 485 | * Returns null if {@link #getNavigationMode()} would not return |
| 486 | * {@link #NAVIGATION_MODE_STANDARD}. |
| 487 | * |
| 488 | * @return The current ActionBar title or null. |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 489 | */ |
| 490 | public abstract CharSequence getTitle(); |
| 491 | |
| 492 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 493 | * Returns the current ActionBar subtitle in standard mode. |
| 494 | * Returns null if {@link #getNavigationMode()} would not return |
| 495 | * {@link #NAVIGATION_MODE_STANDARD}. |
| 496 | * |
| 497 | * @return The current ActionBar subtitle or null. |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 498 | */ |
| 499 | public abstract CharSequence getSubtitle(); |
| 500 | |
| 501 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 502 | * Returns the current navigation mode. The result will be one of: |
| 503 | * <ul> |
| 504 | * <li>{@link #NAVIGATION_MODE_STANDARD}</li> |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 505 | * <li>{@link #NAVIGATION_MODE_LIST}</li> |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 506 | * <li>{@link #NAVIGATION_MODE_TABS}</li> |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 507 | * </ul> |
| 508 | * |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 509 | * @return The current navigation mode. |
| 510 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 511 | @NavigationMode |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 512 | public abstract int getNavigationMode(); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 513 | |
| 514 | /** |
| 515 | * Set the current navigation mode. |
| 516 | * |
| 517 | * @param mode The new mode to set. |
| 518 | * @see #NAVIGATION_MODE_STANDARD |
| 519 | * @see #NAVIGATION_MODE_LIST |
| 520 | * @see #NAVIGATION_MODE_TABS |
| 521 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 522 | public abstract void setNavigationMode(@NavigationMode int mode); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 523 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 524 | /** |
| 525 | * @return The current set of display options. |
| 526 | */ |
| 527 | public abstract int getDisplayOptions(); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 528 | |
| 529 | /** |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 530 | * Create and return a new {@link Tab}. |
| 531 | * This tab will not be included in the action bar until it is added. |
| 532 | * |
Dianne Hackborn | 2f04883 | 2011-06-16 13:31:57 -0700 | [diff] [blame] | 533 | * <p>Very often tabs will be used to switch between {@link Fragment} |
| 534 | * objects. Here is a typical implementation of such tabs:</p> |
| 535 | * |
| 536 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.java |
| 537 | * complete} |
| 538 | * |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 539 | * @return A new Tab |
| 540 | * |
| 541 | * @see #addTab(Tab) |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 542 | */ |
| 543 | public abstract Tab newTab(); |
| 544 | |
| 545 | /** |
| 546 | * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list. |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 547 | * If this is the first tab to be added it will become the selected tab. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 548 | * |
| 549 | * @param tab Tab to add |
| 550 | */ |
| 551 | public abstract void addTab(Tab tab); |
| 552 | |
| 553 | /** |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 554 | * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list. |
| 555 | * |
| 556 | * @param tab Tab to add |
| 557 | * @param setSelected True if the added tab should become the selected tab. |
| 558 | */ |
| 559 | public abstract void addTab(Tab tab, boolean setSelected); |
| 560 | |
| 561 | /** |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 562 | * Add a tab for use in tabbed navigation mode. The tab will be inserted at |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 563 | * <code>position</code>. If this is the first tab to be added it will become |
| 564 | * the selected tab. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 565 | * |
| 566 | * @param tab The tab to add |
| 567 | * @param position The new position of the tab |
| 568 | */ |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 569 | public abstract void addTab(Tab tab, int position); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 570 | |
| 571 | /** |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 572 | * Add a tab for use in tabbed navigation mode. The tab will be insterted at |
| 573 | * <code>position</code>. |
| 574 | * |
| 575 | * @param tab The tab to add |
| 576 | * @param position The new position of the tab |
| 577 | * @param setSelected True if the added tab should become the selected tab. |
| 578 | */ |
| 579 | public abstract void addTab(Tab tab, int position, boolean setSelected); |
| 580 | |
| 581 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 582 | * Remove a tab from the action bar. If the removed tab was selected it will be deselected |
| 583 | * and another tab will be selected if present. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 584 | * |
| 585 | * @param tab The tab to remove |
| 586 | */ |
| 587 | public abstract void removeTab(Tab tab); |
| 588 | |
| 589 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 590 | * Remove a tab from the action bar. If the removed tab was selected it will be deselected |
| 591 | * and another tab will be selected if present. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 592 | * |
| 593 | * @param position Position of the tab to remove |
| 594 | */ |
| 595 | public abstract void removeTabAt(int position); |
| 596 | |
| 597 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 598 | * Remove all tabs from the action bar and deselect the current tab. |
| 599 | */ |
| 600 | public abstract void removeAllTabs(); |
| 601 | |
| 602 | /** |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 603 | * Select the specified tab. If it is not a child of this action bar it will be added. |
| 604 | * |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 605 | * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p> |
| 606 | * |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 607 | * @param tab Tab to select |
| 608 | */ |
| 609 | public abstract void selectTab(Tab tab); |
| 610 | |
| 611 | /** |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 612 | * Returns the currently selected tab if in tabbed navigation mode and there is at least |
| 613 | * one tab present. |
| 614 | * |
| 615 | * @return The currently selected tab or null |
| 616 | */ |
| 617 | public abstract Tab getSelectedTab(); |
| 618 | |
| 619 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 620 | * Returns the tab at the specified index. |
| 621 | * |
| 622 | * @param index Index value in the range 0-get |
| 623 | * @return |
| 624 | */ |
| 625 | public abstract Tab getTabAt(int index); |
| 626 | |
| 627 | /** |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 628 | * Returns the number of tabs currently registered with the action bar. |
| 629 | * @return Tab count |
| 630 | */ |
| 631 | public abstract int getTabCount(); |
| 632 | |
| 633 | /** |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 634 | * Retrieve the current height of the ActionBar. |
| 635 | * |
| 636 | * @return The ActionBar's height |
| 637 | */ |
| 638 | public abstract int getHeight(); |
| 639 | |
| 640 | /** |
| 641 | * Show the ActionBar if it is not currently showing. |
| 642 | * If the window hosting the ActionBar does not have the feature |
| 643 | * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application |
| 644 | * content to fit the new space available. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 645 | * |
| 646 | * <p>If you are hiding the ActionBar through |
| 647 | * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN}, |
| 648 | * you should not call this function directly. |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 649 | */ |
| 650 | public abstract void show(); |
| 651 | |
| 652 | /** |
Scott Main | e797ed6 | 2011-09-22 16:17:45 -0700 | [diff] [blame] | 653 | * Hide the ActionBar if it is currently showing. |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 654 | * If the window hosting the ActionBar does not have the feature |
| 655 | * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application |
| 656 | * content to fit the new space available. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 657 | * |
| 658 | * <p>Instead of calling this function directly, you can also cause an |
| 659 | * ActionBar using the overlay feature to hide through |
| 660 | * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN}. |
| 661 | * Hiding the ActionBar through this system UI flag allows you to more |
| 662 | * seamlessly hide it in conjunction with other screen decorations. |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 663 | */ |
| 664 | public abstract void hide(); |
| 665 | |
| 666 | /** |
| 667 | * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise. |
| 668 | */ |
| 669 | public abstract boolean isShowing(); |
| 670 | |
| 671 | /** |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 672 | * Add a listener that will respond to menu visibility change events. |
| 673 | * |
| 674 | * @param listener The new listener to add |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 675 | */ |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 676 | public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener); |
| 677 | |
| 678 | /** |
| 679 | * Remove a menu visibility listener. This listener will no longer receive menu |
| 680 | * visibility change events. |
| 681 | * |
| 682 | * @param listener A listener to remove that was previously added |
| 683 | */ |
| 684 | public abstract void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener); |
| 685 | |
| 686 | /** |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 687 | * Enable or disable the "home" button in the corner of the action bar. (Note that this |
| 688 | * is the application home/up affordance on the action bar, not the systemwide home |
| 689 | * button.) |
| 690 | * |
| 691 | * <p>This defaults to true for packages targeting < API 14. For packages targeting |
| 692 | * API 14 or greater, the application should call this method to enable interaction |
| 693 | * with the home/up affordance. |
| 694 | * |
| 695 | * <p>Setting the {@link #DISPLAY_HOME_AS_UP} display option will automatically enable |
| 696 | * the home button. |
| 697 | * |
| 698 | * @param enabled true to enable the home button, false to disable the home button. |
| 699 | */ |
Adam Powell | 88ab697 | 2011-07-28 11:25:01 -0700 | [diff] [blame] | 700 | public void setHomeButtonEnabled(boolean enabled) { } |
| 701 | |
| 702 | /** |
| 703 | * Returns a {@link Context} with an appropriate theme for creating views that |
| 704 | * will appear in the action bar. If you are inflating or instantiating custom views |
| 705 | * that will appear in an action bar, you should use the Context returned by this method. |
| 706 | * (This includes adapters used for list navigation mode.) |
| 707 | * This will ensure that views contrast properly against the action bar. |
| 708 | * |
| 709 | * @return A themed Context for creating views |
| 710 | */ |
| 711 | public Context getThemedContext() { return null; } |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 712 | |
| 713 | /** |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 714 | * Returns true if the Title field has been truncated during layout for lack |
| 715 | * of available space. |
| 716 | * |
| 717 | * @return true if the Title field has been truncated |
| 718 | * @hide pending API approval |
| 719 | */ |
| 720 | public boolean isTitleTruncated() { return false; } |
| 721 | |
| 722 | /** |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 723 | * Set an alternate drawable to display next to the icon/logo/title |
| 724 | * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using |
| 725 | * this mode to display an alternate selection for up navigation, such as a sliding drawer. |
| 726 | * |
| 727 | * <p>If you pass <code>null</code> to this method, the default drawable from the theme |
| 728 | * will be used.</p> |
| 729 | * |
| 730 | * <p>If you implement alternate or intermediate behavior around Up, you should also |
| 731 | * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()} |
| 732 | * to provide a correct description of the action for accessibility support.</p> |
| 733 | * |
| 734 | * @param indicator A drawable to use for the up indicator, or null to use the theme's default |
| 735 | * |
| 736 | * @see #setDisplayOptions(int, int) |
| 737 | * @see #setDisplayHomeAsUpEnabled(boolean) |
| 738 | * @see #setHomeActionContentDescription(int) |
| 739 | */ |
| 740 | public void setHomeAsUpIndicator(Drawable indicator) { } |
| 741 | |
| 742 | /** |
| 743 | * Set an alternate drawable to display next to the icon/logo/title |
| 744 | * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using |
| 745 | * this mode to display an alternate selection for up navigation, such as a sliding drawer. |
| 746 | * |
| 747 | * <p>If you pass <code>0</code> to this method, the default drawable from the theme |
| 748 | * will be used.</p> |
| 749 | * |
| 750 | * <p>If you implement alternate or intermediate behavior around Up, you should also |
| 751 | * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()} |
| 752 | * to provide a correct description of the action for accessibility support.</p> |
| 753 | * |
| 754 | * @param resId Resource ID of a drawable to use for the up indicator, or null |
| 755 | * to use the theme's default |
| 756 | * |
| 757 | * @see #setDisplayOptions(int, int) |
| 758 | * @see #setDisplayHomeAsUpEnabled(boolean) |
| 759 | * @see #setHomeActionContentDescription(int) |
| 760 | */ |
| 761 | public void setHomeAsUpIndicator(int resId) { } |
| 762 | |
| 763 | /** |
| 764 | * Set an alternate description for the Home/Up action, when enabled. |
| 765 | * |
| 766 | * <p>This description is commonly used for accessibility/screen readers when |
| 767 | * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.) |
| 768 | * Examples of this are, "Navigate Home" or "Navigate Up" depending on the |
| 769 | * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up |
| 770 | * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific |
| 771 | * functionality such as a sliding drawer, you should also set this to accurately |
| 772 | * describe the action.</p> |
| 773 | * |
| 774 | * <p>Setting this to <code>null</code> will use the system default description.</p> |
| 775 | * |
| 776 | * @param description New description for the Home action when enabled |
| 777 | * @see #setHomeAsUpIndicator(int) |
| 778 | * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable) |
| 779 | */ |
| 780 | public void setHomeActionContentDescription(CharSequence description) { } |
| 781 | |
| 782 | /** |
| 783 | * Set an alternate description for the Home/Up action, when enabled. |
| 784 | * |
| 785 | * <p>This description is commonly used for accessibility/screen readers when |
| 786 | * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.) |
| 787 | * Examples of this are, "Navigate Home" or "Navigate Up" depending on the |
| 788 | * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up |
| 789 | * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific |
| 790 | * functionality such as a sliding drawer, you should also set this to accurately |
| 791 | * describe the action.</p> |
| 792 | * |
| 793 | * <p>Setting this to <code>0</code> will use the system default description.</p> |
| 794 | * |
| 795 | * @param resId Resource ID of a string to use as the new description |
| 796 | * for the Home action when enabled |
| 797 | * @see #setHomeAsUpIndicator(int) |
| 798 | * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable) |
| 799 | */ |
| 800 | public void setHomeActionContentDescription(int resId) { } |
| 801 | |
| 802 | /** |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 803 | * Listener interface for ActionBar navigation events. |
| 804 | */ |
| 805 | public interface OnNavigationListener { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 806 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 807 | * This method is called whenever a navigation item in your action bar |
| 808 | * is selected. |
| 809 | * |
| 810 | * @param itemPosition Position of the item clicked. |
| 811 | * @param itemId ID of the item clicked. |
| 812 | * @return True if the event was handled, false otherwise. |
| 813 | */ |
| 814 | public boolean onNavigationItemSelected(int itemPosition, long itemId); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 815 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 816 | |
| 817 | /** |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 818 | * Listener for receiving events when action bar menus are shown or hidden. |
| 819 | */ |
| 820 | public interface OnMenuVisibilityListener { |
| 821 | /** |
| 822 | * Called when an action bar menu is shown or hidden. Applications may want to use |
| 823 | * this to tune auto-hiding behavior for the action bar or pause/resume video playback, |
| 824 | * gameplay, or other activity within the main content area. |
| 825 | * |
| 826 | * @param isVisible True if an action bar menu is now visible, false if no action bar |
| 827 | * menus are visible. |
| 828 | */ |
| 829 | public void onMenuVisibilityChanged(boolean isVisible); |
| 830 | } |
| 831 | |
| 832 | /** |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 833 | * A tab in the action bar. |
| 834 | * |
| 835 | * <p>Tabs manage the hiding and showing of {@link Fragment}s. |
| 836 | */ |
| 837 | public static abstract class Tab { |
| 838 | /** |
| 839 | * An invalid position for a tab. |
| 840 | * |
| 841 | * @see #getPosition() |
| 842 | */ |
| 843 | public static final int INVALID_POSITION = -1; |
| 844 | |
| 845 | /** |
| 846 | * Return the current position of this tab in the action bar. |
| 847 | * |
| 848 | * @return Current position, or {@link #INVALID_POSITION} if this tab is not currently in |
| 849 | * the action bar. |
| 850 | */ |
| 851 | public abstract int getPosition(); |
| 852 | |
| 853 | /** |
| 854 | * Return the icon associated with this tab. |
| 855 | * |
| 856 | * @return The tab's icon |
| 857 | */ |
| 858 | public abstract Drawable getIcon(); |
| 859 | |
| 860 | /** |
| 861 | * Return the text of this tab. |
| 862 | * |
| 863 | * @return The tab's text |
| 864 | */ |
| 865 | public abstract CharSequence getText(); |
| 866 | |
| 867 | /** |
| 868 | * Set the icon displayed on this tab. |
| 869 | * |
| 870 | * @param icon The drawable to use as an icon |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 871 | * @return The current instance for call chaining |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 872 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 873 | public abstract Tab setIcon(Drawable icon); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 874 | |
| 875 | /** |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 876 | * Set the icon displayed on this tab. |
| 877 | * |
| 878 | * @param resId Resource ID referring to the drawable to use as an icon |
| 879 | * @return The current instance for call chaining |
| 880 | */ |
| 881 | public abstract Tab setIcon(int resId); |
| 882 | |
| 883 | /** |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 884 | * Set the text displayed on this tab. Text may be truncated if there is not |
| 885 | * room to display the entire string. |
| 886 | * |
| 887 | * @param text The text to display |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 888 | * @return The current instance for call chaining |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 889 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 890 | public abstract Tab setText(CharSequence text); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 891 | |
| 892 | /** |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 893 | * Set the text displayed on this tab. Text may be truncated if there is not |
| 894 | * room to display the entire string. |
| 895 | * |
| 896 | * @param resId A resource ID referring to the text that should be displayed |
| 897 | * @return The current instance for call chaining |
| 898 | */ |
| 899 | public abstract Tab setText(int resId); |
| 900 | |
| 901 | /** |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 902 | * Set a custom view to be used for this tab. This overrides values set by |
| 903 | * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 904 | * |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 905 | * @param view Custom view to be used as a tab. |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 906 | * @return The current instance for call chaining |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 907 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 908 | public abstract Tab setCustomView(View view); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 909 | |
| 910 | /** |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 911 | * Set a custom view to be used for this tab. This overrides values set by |
| 912 | * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}. |
| 913 | * |
| 914 | * @param layoutResId A layout resource to inflate and use as a custom tab view |
| 915 | * @return The current instance for call chaining |
| 916 | */ |
| 917 | public abstract Tab setCustomView(int layoutResId); |
| 918 | |
| 919 | /** |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 920 | * Retrieve a previously set custom view for this tab. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 921 | * |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 922 | * @return The custom view set by {@link #setCustomView(View)}. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 923 | */ |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 924 | public abstract View getCustomView(); |
| 925 | |
| 926 | /** |
| 927 | * Give this Tab an arbitrary object to hold for later use. |
| 928 | * |
| 929 | * @param obj Object to store |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 930 | * @return The current instance for call chaining |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 931 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 932 | public abstract Tab setTag(Object obj); |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 933 | |
| 934 | /** |
| 935 | * @return This Tab's tag object. |
| 936 | */ |
| 937 | public abstract Object getTag(); |
| 938 | |
| 939 | /** |
| 940 | * Set the {@link TabListener} that will handle switching to and from this tab. |
| 941 | * All tabs must have a TabListener set before being added to the ActionBar. |
| 942 | * |
| 943 | * @param listener Listener to handle tab selection events |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 944 | * @return The current instance for call chaining |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 945 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 946 | public abstract Tab setTabListener(TabListener listener); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 947 | |
| 948 | /** |
| 949 | * Select this tab. Only valid if the tab has been added to the action bar. |
| 950 | */ |
| 951 | public abstract void select(); |
Adam Powell | 94e56ef | 2011-09-06 21:22:22 -0700 | [diff] [blame] | 952 | |
| 953 | /** |
| 954 | * Set a description of this tab's content for use in accessibility support. |
| 955 | * If no content description is provided the title will be used. |
| 956 | * |
| 957 | * @param resId A resource ID referring to the description text |
| 958 | * @return The current instance for call chaining |
| 959 | * @see #setContentDescription(CharSequence) |
| 960 | * @see #getContentDescription() |
| 961 | */ |
| 962 | public abstract Tab setContentDescription(int resId); |
| 963 | |
| 964 | /** |
| 965 | * Set a description of this tab's content for use in accessibility support. |
| 966 | * If no content description is provided the title will be used. |
| 967 | * |
| 968 | * @param contentDesc Description of this tab's content |
| 969 | * @return The current instance for call chaining |
| 970 | * @see #setContentDescription(int) |
| 971 | * @see #getContentDescription() |
| 972 | */ |
| 973 | public abstract Tab setContentDescription(CharSequence contentDesc); |
| 974 | |
| 975 | /** |
| 976 | * Gets a brief description of this tab's content for use in accessibility support. |
| 977 | * |
| 978 | * @return Description of this tab's content |
| 979 | * @see #setContentDescription(CharSequence) |
| 980 | * @see #setContentDescription(int) |
| 981 | */ |
| 982 | public abstract CharSequence getContentDescription(); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 983 | } |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 984 | |
| 985 | /** |
| 986 | * Callback interface invoked when a tab is focused, unfocused, added, or removed. |
| 987 | */ |
| 988 | public interface TabListener { |
| 989 | /** |
| 990 | * Called when a tab enters the selected state. |
| 991 | * |
| 992 | * @param tab The tab that was selected |
| 993 | * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute |
| 994 | * during a tab switch. The previous tab's unselect and this tab's select will be |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 995 | * executed in a single transaction. This FragmentTransaction does not support |
| 996 | * being added to the back stack. |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 997 | */ |
| 998 | public void onTabSelected(Tab tab, FragmentTransaction ft); |
| 999 | |
| 1000 | /** |
| 1001 | * Called when a tab exits the selected state. |
| 1002 | * |
| 1003 | * @param tab The tab that was unselected |
| 1004 | * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute |
| 1005 | * during a tab switch. This tab's unselect and the newly selected tab's select |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 1006 | * will be executed in a single transaction. This FragmentTransaction does not |
| 1007 | * support being added to the back stack. |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 1008 | */ |
| 1009 | public void onTabUnselected(Tab tab, FragmentTransaction ft); |
Adam Powell | 7f9b905 | 2010-10-19 16:56:07 -0700 | [diff] [blame] | 1010 | |
| 1011 | /** |
| 1012 | * Called when a tab that is already selected is chosen again by the user. |
| 1013 | * Some applications may use this action to return to the top level of a category. |
| 1014 | * |
| 1015 | * @param tab The tab that was reselected. |
| 1016 | * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 1017 | * once this method returns. This FragmentTransaction does not support |
| 1018 | * being added to the back stack. |
Adam Powell | 7f9b905 | 2010-10-19 16:56:07 -0700 | [diff] [blame] | 1019 | */ |
| 1020 | public void onTabReselected(Tab tab, FragmentTransaction ft); |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 1021 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1022 | |
| 1023 | /** |
| 1024 | * Per-child layout information associated with action bar custom views. |
| 1025 | * |
| 1026 | * @attr ref android.R.styleable#ActionBar_LayoutParams_layout_gravity |
| 1027 | */ |
| 1028 | public static class LayoutParams extends MarginLayoutParams { |
| 1029 | /** |
| 1030 | * Gravity for the view associated with these LayoutParams. |
| 1031 | * |
| 1032 | * @see android.view.Gravity |
| 1033 | */ |
| 1034 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
| 1035 | @ViewDebug.IntToString(from = -1, to = "NONE"), |
| 1036 | @ViewDebug.IntToString(from = Gravity.NO_GRAVITY, to = "NONE"), |
| 1037 | @ViewDebug.IntToString(from = Gravity.TOP, to = "TOP"), |
| 1038 | @ViewDebug.IntToString(from = Gravity.BOTTOM, to = "BOTTOM"), |
| 1039 | @ViewDebug.IntToString(from = Gravity.LEFT, to = "LEFT"), |
| 1040 | @ViewDebug.IntToString(from = Gravity.RIGHT, to = "RIGHT"), |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1041 | @ViewDebug.IntToString(from = Gravity.START, to = "START"), |
| 1042 | @ViewDebug.IntToString(from = Gravity.END, to = "END"), |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1043 | @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL, to = "CENTER_VERTICAL"), |
| 1044 | @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL, to = "FILL_VERTICAL"), |
| 1045 | @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"), |
| 1046 | @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL, to = "FILL_HORIZONTAL"), |
| 1047 | @ViewDebug.IntToString(from = Gravity.CENTER, to = "CENTER"), |
| 1048 | @ViewDebug.IntToString(from = Gravity.FILL, to = "FILL") |
| 1049 | }) |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1050 | public int gravity = Gravity.NO_GRAVITY; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1051 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 1052 | public LayoutParams(@NonNull Context c, AttributeSet attrs) { |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1053 | super(c, attrs); |
| 1054 | |
| 1055 | TypedArray a = c.obtainStyledAttributes(attrs, |
| 1056 | com.android.internal.R.styleable.ActionBar_LayoutParams); |
| 1057 | gravity = a.getInt( |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1058 | com.android.internal.R.styleable.ActionBar_LayoutParams_layout_gravity, |
| 1059 | Gravity.NO_GRAVITY); |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 1060 | a.recycle(); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | public LayoutParams(int width, int height) { |
| 1064 | super(width, height); |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1065 | this.gravity = Gravity.CENTER_VERTICAL | Gravity.START; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | public LayoutParams(int width, int height, int gravity) { |
| 1069 | super(width, height); |
| 1070 | this.gravity = gravity; |
| 1071 | } |
| 1072 | |
| 1073 | public LayoutParams(int gravity) { |
| 1074 | this(WRAP_CONTENT, MATCH_PARENT, gravity); |
| 1075 | } |
| 1076 | |
| 1077 | public LayoutParams(LayoutParams source) { |
| 1078 | super(source); |
| 1079 | |
| 1080 | this.gravity = source.gravity; |
| 1081 | } |
| 1082 | |
| 1083 | public LayoutParams(ViewGroup.LayoutParams source) { |
| 1084 | super(source); |
| 1085 | } |
| 1086 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1087 | } |