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 | |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.res.TypedArray; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 21 | import android.graphics.drawable.Drawable; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 22 | import android.util.AttributeSet; |
| 23 | import android.view.Gravity; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 24 | import android.view.View; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 25 | import android.view.ViewDebug; |
| 26 | import android.view.ViewGroup; |
| 27 | import android.view.ViewGroup.MarginLayoutParams; |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 28 | import android.view.Window; |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 29 | import android.widget.SpinnerAdapter; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * This is the public interface to the contextual ActionBar. |
| 33 | * The ActionBar acts as a replacement for the title bar in Activities. |
| 34 | * It provides facilities for creating toolbar actions as well as |
| 35 | * methods of navigating around an application. |
| 36 | */ |
| 37 | public abstract class ActionBar { |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 38 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 39 | * Standard navigation mode. Consists of either a logo or icon |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 40 | * and title text with an optional subtitle. Clicking any of these elements |
Adam Powell | cf03576 | 2010-12-06 11:49:45 -0800 | [diff] [blame] | 41 | * will dispatch onOptionsItemSelected to the host Activity with |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 42 | * a MenuItem with item ID android.R.id.home. |
| 43 | */ |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 44 | public static final int NAVIGATION_MODE_STANDARD = 0; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 47 | * List navigation mode. Instead of static title text this mode |
| 48 | * presents a list menu for navigation within the activity. |
| 49 | * 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] | 50 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 51 | public static final int NAVIGATION_MODE_LIST = 1; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Tab navigation mode. Instead of static title text this mode |
| 55 | * presents a series of tabs for navigation within the activity. |
| 56 | */ |
| 57 | public static final int NAVIGATION_MODE_TABS = 2; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * Use logo instead of icon if available. This flag will cause appropriate |
| 61 | * 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] | 62 | * |
| 63 | * @see #setDisplayOptions(int) |
| 64 | * @see #setDisplayOptions(int, int) |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 65 | */ |
| 66 | public static final int DISPLAY_USE_LOGO = 0x1; |
| 67 | |
| 68 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 69 | * Show 'home' elements in this action bar, leaving more space for other |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 70 | * navigation elements. This includes logo and icon. |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 71 | * |
| 72 | * @see #setDisplayOptions(int) |
| 73 | * @see #setDisplayOptions(int, int) |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 74 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 75 | public static final int DISPLAY_SHOW_HOME = 0x2; |
| 76 | |
| 77 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 78 | * Display the 'home' element such that it appears as an 'up' affordance. |
| 79 | * e.g. show an arrow to the left indicating the action that will be taken. |
| 80 | * |
| 81 | * Set this flag if selecting the 'home' button in the action bar to return |
| 82 | * up by a single level in your UI rather than back to the top level or front page. |
| 83 | * |
| 84 | * @see #setDisplayOptions(int) |
| 85 | * @see #setDisplayOptions(int, int) |
| 86 | */ |
| 87 | public static final int DISPLAY_HOME_AS_UP = 0x4; |
| 88 | |
| 89 | /** |
| 90 | * Show the activity title and subtitle, if present. |
| 91 | * |
| 92 | * @see #setTitle(CharSequence) |
| 93 | * @see #setTitle(int) |
| 94 | * @see #setSubtitle(CharSequence) |
| 95 | * @see #setSubtitle(int) |
| 96 | * @see #setDisplayOptions(int) |
| 97 | * @see #setDisplayOptions(int, int) |
| 98 | */ |
| 99 | public static final int DISPLAY_SHOW_TITLE = 0x8; |
| 100 | |
| 101 | /** |
| 102 | * Show the custom view if one has been set. |
| 103 | * @see #setCustomView(View) |
| 104 | * @see #setDisplayOptions(int) |
| 105 | * @see #setDisplayOptions(int, int) |
| 106 | */ |
| 107 | public static final int DISPLAY_SHOW_CUSTOM = 0x10; |
| 108 | |
| 109 | /** |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 110 | * Disable the 'home' element. This may be combined with |
| 111 | * {@link #DISPLAY_SHOW_HOME} to create a non-focusable/non-clickable |
| 112 | * 'home' element. Useful for a level of your app's navigation hierarchy |
| 113 | * where clicking 'home' doesn't do anything. |
| 114 | * |
| 115 | * @see #setDisplayOptions(int) |
| 116 | * @see #setDisplayOptions(int, int) |
| 117 | * @see #setDisplayDisableHomeEnabled(boolean) |
| 118 | */ |
| 119 | public static final int DISPLAY_DISABLE_HOME = 0x20; |
| 120 | |
| 121 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 122 | * Set the action bar into custom navigation mode, supplying a view |
| 123 | * for custom navigation. |
| 124 | * |
| 125 | * Custom navigation views appear between the application icon and |
| 126 | * any action buttons and may use any space available there. Common |
| 127 | * use cases for custom navigation views might include an auto-suggesting |
| 128 | * address bar for a browser or other navigation mechanisms that do not |
| 129 | * translate well to provided navigation modes. |
| 130 | * |
| 131 | * @param view Custom navigation view to place in the ActionBar. |
| 132 | */ |
| 133 | public abstract void setCustomView(View view); |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 134 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 135 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 136 | * Set the action bar into custom navigation mode, supplying a view |
| 137 | * for custom navigation. |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 138 | * |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 139 | * <p>Custom navigation views appear between the application icon and |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 140 | * any action buttons and may use any space available there. Common |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 141 | * use cases for custom navigation views might include an auto-suggesting |
| 142 | * address bar for a browser or other navigation mechanisms that do not |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 143 | * translate well to provided navigation modes.</p> |
| 144 | * |
| 145 | * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for |
| 146 | * the custom view to be displayed.</p> |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 147 | * |
| 148 | * @param view Custom navigation view to place in the ActionBar. |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 149 | * @param layoutParams How this custom view should layout in the bar. |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 150 | * |
| 151 | * @see #setDisplayOptions(int, int) |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 152 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 153 | public abstract void setCustomView(View view, LayoutParams layoutParams); |
| 154 | |
| 155 | /** |
Adam Powell | 3f476b3 | 2011-01-03 19:25:36 -0800 | [diff] [blame] | 156 | * Set the action bar into custom navigation mode, supplying a view |
| 157 | * for custom navigation. |
| 158 | * |
| 159 | * <p>Custom navigation views appear between the application icon and |
| 160 | * any action buttons and may use any space available there. Common |
| 161 | * use cases for custom navigation views might include an auto-suggesting |
| 162 | * address bar for a browser or other navigation mechanisms that do not |
| 163 | * translate well to provided navigation modes.</p> |
| 164 | * |
| 165 | * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for |
| 166 | * the custom view to be displayed.</p> |
| 167 | * |
| 168 | * @param resId Resource ID of a layout to inflate into the ActionBar. |
| 169 | * |
| 170 | * @see #setDisplayOptions(int, int) |
| 171 | */ |
| 172 | public abstract void setCustomView(int resId); |
| 173 | |
| 174 | /** |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 175 | * Set the icon to display in the 'home' section of the action bar. |
| 176 | * The action bar will use an icon specified by its style or the |
| 177 | * activity icon by default. |
| 178 | * |
| 179 | * Whether the home section shows an icon or logo is controlled |
| 180 | * by the display option {@link #DISPLAY_USE_LOGO}. |
| 181 | * |
| 182 | * @param resId Resource ID of a drawable to show as an icon. |
| 183 | * |
| 184 | * @see #setDisplayUseLogoEnabled(boolean) |
| 185 | * @see #setDisplayShowHomeEnabled(boolean) |
| 186 | */ |
| 187 | public abstract void setIcon(int resId); |
| 188 | |
| 189 | /** |
| 190 | * Set the icon to display in the 'home' section of the action bar. |
| 191 | * The action bar will use an icon specified by its style or the |
| 192 | * activity icon by default. |
| 193 | * |
| 194 | * Whether the home section shows an icon or logo is controlled |
| 195 | * by the display option {@link #DISPLAY_USE_LOGO}. |
| 196 | * |
| 197 | * @param icon Drawable to show as an icon. |
| 198 | * |
| 199 | * @see #setDisplayUseLogoEnabled(boolean) |
| 200 | * @see #setDisplayShowHomeEnabled(boolean) |
| 201 | */ |
| 202 | public abstract void setIcon(Drawable icon); |
| 203 | |
| 204 | /** |
| 205 | * Set the logo to display in the 'home' section of the action bar. |
| 206 | * The action bar will use a logo specified by its style or the |
| 207 | * activity logo by default. |
| 208 | * |
| 209 | * Whether the home section shows an icon or logo is controlled |
| 210 | * by the display option {@link #DISPLAY_USE_LOGO}. |
| 211 | * |
| 212 | * @param resId Resource ID of a drawable to show as a logo. |
| 213 | * |
| 214 | * @see #setDisplayUseLogoEnabled(boolean) |
| 215 | * @see #setDisplayShowHomeEnabled(boolean) |
| 216 | */ |
| 217 | public abstract void setLogo(int resId); |
| 218 | |
| 219 | /** |
| 220 | * Set the logo to display in the 'home' section of the action bar. |
| 221 | * The action bar will use a logo specified by its style or the |
| 222 | * activity logo by default. |
| 223 | * |
| 224 | * Whether the home section shows an icon or logo is controlled |
| 225 | * by the display option {@link #DISPLAY_USE_LOGO}. |
| 226 | * |
| 227 | * @param logo Drawable to show as a logo. |
| 228 | * |
| 229 | * @see #setDisplayUseLogoEnabled(boolean) |
| 230 | * @see #setDisplayShowHomeEnabled(boolean) |
| 231 | */ |
| 232 | public abstract void setLogo(Drawable logo); |
| 233 | |
| 234 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 235 | * Set the adapter and navigation callback for list navigation mode. |
| 236 | * |
| 237 | * The supplied adapter will provide views for the expanded list as well as |
| 238 | * the currently selected item. (These may be displayed differently.) |
| 239 | * |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 240 | * The supplied OnNavigationListener will alert the application when the user |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 241 | * changes the current list selection. |
| 242 | * |
| 243 | * @param adapter An adapter that will provide views both to display |
| 244 | * the current navigation selection and populate views |
| 245 | * within the dropdown navigation menu. |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 246 | * @param callback An OnNavigationListener that will receive events when the user |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 247 | * selects a navigation item. |
| 248 | */ |
| 249 | public abstract void setListNavigationCallbacks(SpinnerAdapter adapter, |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 250 | OnNavigationListener callback); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 251 | |
| 252 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 253 | * Set the selected navigation item in list or tabbed navigation modes. |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 254 | * |
| 255 | * @param position Position of the item to select. |
| 256 | */ |
| 257 | public abstract void setSelectedNavigationItem(int position); |
| 258 | |
| 259 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 260 | * Get the position of the selected navigation item in list or tabbed navigation modes. |
| 261 | * |
| 262 | * @return Position of the selected item. |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 263 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 264 | public abstract int getSelectedNavigationIndex(); |
| 265 | |
| 266 | /** |
| 267 | * Get the number of navigation items present in the current navigation mode. |
| 268 | * |
| 269 | * @return Number of navigation items. |
| 270 | */ |
| 271 | public abstract int getNavigationItemCount(); |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 272 | |
| 273 | /** |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 274 | * Set the action bar's title. This will only be displayed if |
| 275 | * {@link #DISPLAY_SHOW_TITLE} is set. |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 276 | * |
| 277 | * @param title Title to set |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 278 | * |
| 279 | * @see #setTitle(int) |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 280 | * @see #setDisplayOptions(int, int) |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 281 | */ |
| 282 | public abstract void setTitle(CharSequence title); |
| 283 | |
| 284 | /** |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 285 | * Set the action bar's title. This will only be displayed if |
| 286 | * {@link #DISPLAY_SHOW_TITLE} is set. |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 287 | * |
| 288 | * @param resId Resource ID of title string to set |
| 289 | * |
| 290 | * @see #setTitle(CharSequence) |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 291 | * @see #setDisplayOptions(int, int) |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 292 | */ |
| 293 | public abstract void setTitle(int resId); |
| 294 | |
| 295 | /** |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 296 | * Set the action bar's subtitle. This will only be displayed if |
| 297 | * {@link #DISPLAY_SHOW_TITLE} is set. Set to null to disable the |
| 298 | * subtitle entirely. |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 299 | * |
| 300 | * @param subtitle Subtitle to set |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 301 | * |
| 302 | * @see #setSubtitle(int) |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 303 | * @see #setDisplayOptions(int, int) |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 304 | */ |
| 305 | public abstract void setSubtitle(CharSequence subtitle); |
| 306 | |
| 307 | /** |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 308 | * Set the action bar's subtitle. This will only be displayed if |
| 309 | * {@link #DISPLAY_SHOW_TITLE} is set. |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 310 | * |
| 311 | * @param resId Resource ID of subtitle string to set |
| 312 | * |
| 313 | * @see #setSubtitle(CharSequence) |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 314 | * @see #setDisplayOptions(int, int) |
Adam Powell | a66c7b0 | 2010-07-28 15:28:25 -0700 | [diff] [blame] | 315 | */ |
| 316 | public abstract void setSubtitle(int resId); |
| 317 | |
| 318 | /** |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 319 | * Set display options. This changes all display option bits at once. To change |
| 320 | * a limited subset of display options, see {@link #setDisplayOptions(int, int)}. |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 321 | * |
| 322 | * @param options A combination of the bits defined by the DISPLAY_ constants |
| 323 | * defined in ActionBar. |
| 324 | */ |
| 325 | public abstract void setDisplayOptions(int options); |
| 326 | |
| 327 | /** |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 328 | * Set selected display options. Only the options specified by mask will be changed. |
| 329 | * To change all display option bits at once, see {@link #setDisplayOptions(int)}. |
| 330 | * |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 331 | * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the |
| 332 | * {@link #DISPLAY_SHOW_HOME} option. |
Ben Komalo | 5ad7af6 | 2010-11-01 12:04:51 -0700 | [diff] [blame] | 333 | * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO) |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 334 | * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}. |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 335 | * |
| 336 | * @param options A combination of the bits defined by the DISPLAY_ constants |
| 337 | * defined in ActionBar. |
| 338 | * @param mask A bit mask declaring which display options should be changed. |
| 339 | */ |
| 340 | public abstract void setDisplayOptions(int options, int mask); |
Adam Powell | 3f476b3 | 2011-01-03 19:25:36 -0800 | [diff] [blame] | 341 | |
| 342 | /** |
| 343 | * Set whether to display the activity logo rather than the activity icon. |
| 344 | * A logo is often a wider, more detailed image. |
| 345 | * |
| 346 | * <p>To set several display options at once, see the setDisplayOptions methods. |
| 347 | * |
| 348 | * @param useLogo true to use the activity logo, false to use the activity icon. |
| 349 | * |
| 350 | * @see #setDisplayOptions(int) |
| 351 | * @see #setDisplayOptions(int, int) |
| 352 | */ |
| 353 | public abstract void setDisplayUseLogoEnabled(boolean useLogo); |
| 354 | |
| 355 | /** |
| 356 | * Set whether to include the application home affordance in the action bar. |
| 357 | * Home is presented as either an activity icon or logo. |
| 358 | * |
| 359 | * <p>To set several display options at once, see the setDisplayOptions methods. |
| 360 | * |
| 361 | * @param showHome true to show home, false otherwise. |
| 362 | * |
| 363 | * @see #setDisplayOptions(int) |
| 364 | * @see #setDisplayOptions(int, int) |
| 365 | */ |
| 366 | public abstract void setDisplayShowHomeEnabled(boolean showHome); |
| 367 | |
| 368 | /** |
| 369 | * Set whether home should be displayed as an "up" affordance. |
| 370 | * Set this to true if selecting "home" returns up by a single level in your UI |
| 371 | * rather than back to the top level or front page. |
| 372 | * |
| 373 | * <p>To set several display options at once, see the setDisplayOptions methods. |
| 374 | * |
| 375 | * @param showHomeAsUp true to show the user that selecting home will return one |
| 376 | * level up rather than to the top level of the app. |
| 377 | * |
| 378 | * @see #setDisplayOptions(int) |
| 379 | * @see #setDisplayOptions(int, int) |
| 380 | */ |
| 381 | public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp); |
| 382 | |
| 383 | /** |
| 384 | * Set whether an activity title/subtitle should be displayed. |
| 385 | * |
| 386 | * <p>To set several display options at once, see the setDisplayOptions methods. |
| 387 | * |
| 388 | * @param showTitle true to display a title/subtitle if present. |
| 389 | * |
| 390 | * @see #setDisplayOptions(int) |
| 391 | * @see #setDisplayOptions(int, int) |
| 392 | */ |
| 393 | public abstract void setDisplayShowTitleEnabled(boolean showTitle); |
| 394 | |
| 395 | /** |
| 396 | * Set whether a custom view should be displayed, if set. |
| 397 | * |
| 398 | * <p>To set several display options at once, see the setDisplayOptions methods. |
| 399 | * |
| 400 | * @param showCustom true if the currently set custom view should be displayed, false otherwise. |
| 401 | * |
| 402 | * @see #setDisplayOptions(int) |
| 403 | * @see #setDisplayOptions(int, int) |
| 404 | */ |
| 405 | public abstract void setDisplayShowCustomEnabled(boolean showCustom); |
| 406 | |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 407 | /** |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 408 | * Set whether the 'home' affordance on the action bar should be disabled. |
| 409 | * If set, the 'home' element will not be focusable or clickable, useful if |
| 410 | * the user is at the top level of the app's navigation hierarchy. |
| 411 | * |
| 412 | * <p>To set several display options at once, see the setDisplayOptions methods. |
| 413 | * |
| 414 | * @param disableHome true to disable the 'home' element. |
| 415 | * |
| 416 | * @see #setDisplayOptions(int) |
| 417 | * @see #setDisplayOptions(int, int) |
| 418 | * @see #DISPLAY_DISABLE_HOME |
| 419 | */ |
| 420 | public abstract void setDisplayDisableHomeEnabled(boolean disableHome); |
| 421 | |
| 422 | /** |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 423 | * Set the ActionBar's background. |
| 424 | * |
| 425 | * @param d Background drawable |
| 426 | */ |
| 427 | public abstract void setBackgroundDrawable(Drawable d); |
Adam Powell | ef70444 | 2010-11-16 14:48:22 -0800 | [diff] [blame] | 428 | |
| 429 | /** |
| 430 | * @return The current custom view. |
| 431 | */ |
| 432 | public abstract View getCustomView(); |
| 433 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 434 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 435 | * Returns the current ActionBar title in standard mode. |
| 436 | * Returns null if {@link #getNavigationMode()} would not return |
| 437 | * {@link #NAVIGATION_MODE_STANDARD}. |
| 438 | * |
| 439 | * @return The current ActionBar title or null. |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 440 | */ |
| 441 | public abstract CharSequence getTitle(); |
| 442 | |
| 443 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 444 | * Returns the current ActionBar subtitle in standard mode. |
| 445 | * Returns null if {@link #getNavigationMode()} would not return |
| 446 | * {@link #NAVIGATION_MODE_STANDARD}. |
| 447 | * |
| 448 | * @return The current ActionBar subtitle or null. |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 449 | */ |
| 450 | public abstract CharSequence getSubtitle(); |
| 451 | |
| 452 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 453 | * Returns the current navigation mode. The result will be one of: |
| 454 | * <ul> |
| 455 | * <li>{@link #NAVIGATION_MODE_STANDARD}</li> |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 456 | * <li>{@link #NAVIGATION_MODE_LIST}</li> |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 457 | * <li>{@link #NAVIGATION_MODE_TABS}</li> |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 458 | * </ul> |
| 459 | * |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 460 | * @return The current navigation mode. |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 461 | * |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 462 | * @see #setStandardNavigationMode() |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 463 | * @see #setStandardNavigationMode(CharSequence) |
| 464 | * @see #setStandardNavigationMode(CharSequence, CharSequence) |
| 465 | * @see #setDropdownNavigationMode(SpinnerAdapter) |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 466 | * @see #setTabNavigationMode() |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 467 | * @see #setCustomNavigationMode(View) |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 468 | */ |
| 469 | public abstract int getNavigationMode(); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * Set the current navigation mode. |
| 473 | * |
| 474 | * @param mode The new mode to set. |
| 475 | * @see #NAVIGATION_MODE_STANDARD |
| 476 | * @see #NAVIGATION_MODE_LIST |
| 477 | * @see #NAVIGATION_MODE_TABS |
| 478 | */ |
| 479 | public abstract void setNavigationMode(int mode); |
| 480 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 481 | /** |
| 482 | * @return The current set of display options. |
| 483 | */ |
| 484 | public abstract int getDisplayOptions(); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 485 | |
| 486 | /** |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 487 | * Create and return a new {@link Tab}. |
| 488 | * This tab will not be included in the action bar until it is added. |
| 489 | * |
| 490 | * @return A new Tab |
| 491 | * |
| 492 | * @see #addTab(Tab) |
| 493 | * @see #insertTab(Tab, int) |
| 494 | */ |
| 495 | public abstract Tab newTab(); |
| 496 | |
| 497 | /** |
| 498 | * 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] | 499 | * 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] | 500 | * |
| 501 | * @param tab Tab to add |
| 502 | */ |
| 503 | public abstract void addTab(Tab tab); |
| 504 | |
| 505 | /** |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 506 | * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list. |
| 507 | * |
| 508 | * @param tab Tab to add |
| 509 | * @param setSelected True if the added tab should become the selected tab. |
| 510 | */ |
| 511 | public abstract void addTab(Tab tab, boolean setSelected); |
| 512 | |
| 513 | /** |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 514 | * 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] | 515 | * <code>position</code>. If this is the first tab to be added it will become |
| 516 | * the selected tab. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 517 | * |
| 518 | * @param tab The tab to add |
| 519 | * @param position The new position of the tab |
| 520 | */ |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 521 | public abstract void addTab(Tab tab, int position); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 522 | |
| 523 | /** |
Adam Powell | 81b8944 | 2010-11-02 17:58:56 -0700 | [diff] [blame] | 524 | * Add a tab for use in tabbed navigation mode. The tab will be insterted at |
| 525 | * <code>position</code>. |
| 526 | * |
| 527 | * @param tab The tab to add |
| 528 | * @param position The new position of the tab |
| 529 | * @param setSelected True if the added tab should become the selected tab. |
| 530 | */ |
| 531 | public abstract void addTab(Tab tab, int position, boolean setSelected); |
| 532 | |
| 533 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 534 | * Remove a tab from the action bar. If the removed tab was selected it will be deselected |
| 535 | * and another tab will be selected if present. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 536 | * |
| 537 | * @param tab The tab to remove |
| 538 | */ |
| 539 | public abstract void removeTab(Tab tab); |
| 540 | |
| 541 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 542 | * Remove a tab from the action bar. If the removed tab was selected it will be deselected |
| 543 | * and another tab will be selected if present. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 544 | * |
| 545 | * @param position Position of the tab to remove |
| 546 | */ |
| 547 | public abstract void removeTabAt(int position); |
| 548 | |
| 549 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 550 | * Remove all tabs from the action bar and deselect the current tab. |
| 551 | */ |
| 552 | public abstract void removeAllTabs(); |
| 553 | |
| 554 | /** |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 555 | * Select the specified tab. If it is not a child of this action bar it will be added. |
| 556 | * |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 557 | * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p> |
| 558 | * |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 559 | * @param tab Tab to select |
| 560 | */ |
| 561 | public abstract void selectTab(Tab tab); |
| 562 | |
| 563 | /** |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 564 | * Returns the currently selected tab if in tabbed navigation mode and there is at least |
| 565 | * one tab present. |
| 566 | * |
| 567 | * @return The currently selected tab or null |
| 568 | */ |
| 569 | public abstract Tab getSelectedTab(); |
| 570 | |
| 571 | /** |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 572 | * Returns the tab at the specified index. |
| 573 | * |
| 574 | * @param index Index value in the range 0-get |
| 575 | * @return |
| 576 | */ |
| 577 | public abstract Tab getTabAt(int index); |
| 578 | |
| 579 | /** |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 580 | * Returns the number of tabs currently registered with the action bar. |
| 581 | * @return Tab count |
| 582 | */ |
| 583 | public abstract int getTabCount(); |
| 584 | |
| 585 | /** |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 586 | * Retrieve the current height of the ActionBar. |
| 587 | * |
| 588 | * @return The ActionBar's height |
| 589 | */ |
| 590 | public abstract int getHeight(); |
| 591 | |
| 592 | /** |
| 593 | * Show the ActionBar if it is not currently showing. |
| 594 | * If the window hosting the ActionBar does not have the feature |
| 595 | * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application |
| 596 | * content to fit the new space available. |
| 597 | */ |
| 598 | public abstract void show(); |
| 599 | |
| 600 | /** |
| 601 | * Hide the ActionBar if it is not currently showing. |
| 602 | * If the window hosting the ActionBar does not have the feature |
| 603 | * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application |
| 604 | * content to fit the new space available. |
| 605 | */ |
| 606 | public abstract void hide(); |
| 607 | |
| 608 | /** |
| 609 | * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise. |
| 610 | */ |
| 611 | public abstract boolean isShowing(); |
| 612 | |
| 613 | /** |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 614 | * Add a listener that will respond to menu visibility change events. |
| 615 | * |
| 616 | * @param listener The new listener to add |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 617 | */ |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 618 | public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener); |
| 619 | |
| 620 | /** |
| 621 | * Remove a menu visibility listener. This listener will no longer receive menu |
| 622 | * visibility change events. |
| 623 | * |
| 624 | * @param listener A listener to remove that was previously added |
| 625 | */ |
| 626 | public abstract void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener); |
| 627 | |
| 628 | /** |
| 629 | * Listener interface for ActionBar navigation events. |
| 630 | */ |
| 631 | public interface OnNavigationListener { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 632 | /** |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 633 | * This method is called whenever a navigation item in your action bar |
| 634 | * is selected. |
| 635 | * |
| 636 | * @param itemPosition Position of the item clicked. |
| 637 | * @param itemId ID of the item clicked. |
| 638 | * @return True if the event was handled, false otherwise. |
| 639 | */ |
| 640 | public boolean onNavigationItemSelected(int itemPosition, long itemId); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 641 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 642 | |
| 643 | /** |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 644 | * Listener for receiving events when action bar menus are shown or hidden. |
| 645 | */ |
| 646 | public interface OnMenuVisibilityListener { |
| 647 | /** |
| 648 | * Called when an action bar menu is shown or hidden. Applications may want to use |
| 649 | * this to tune auto-hiding behavior for the action bar or pause/resume video playback, |
| 650 | * gameplay, or other activity within the main content area. |
| 651 | * |
| 652 | * @param isVisible True if an action bar menu is now visible, false if no action bar |
| 653 | * menus are visible. |
| 654 | */ |
| 655 | public void onMenuVisibilityChanged(boolean isVisible); |
| 656 | } |
| 657 | |
| 658 | /** |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 659 | * A tab in the action bar. |
| 660 | * |
| 661 | * <p>Tabs manage the hiding and showing of {@link Fragment}s. |
| 662 | */ |
| 663 | public static abstract class Tab { |
| 664 | /** |
| 665 | * An invalid position for a tab. |
| 666 | * |
| 667 | * @see #getPosition() |
| 668 | */ |
| 669 | public static final int INVALID_POSITION = -1; |
| 670 | |
| 671 | /** |
| 672 | * Return the current position of this tab in the action bar. |
| 673 | * |
| 674 | * @return Current position, or {@link #INVALID_POSITION} if this tab is not currently in |
| 675 | * the action bar. |
| 676 | */ |
| 677 | public abstract int getPosition(); |
| 678 | |
| 679 | /** |
| 680 | * Return the icon associated with this tab. |
| 681 | * |
| 682 | * @return The tab's icon |
| 683 | */ |
| 684 | public abstract Drawable getIcon(); |
| 685 | |
| 686 | /** |
| 687 | * Return the text of this tab. |
| 688 | * |
| 689 | * @return The tab's text |
| 690 | */ |
| 691 | public abstract CharSequence getText(); |
| 692 | |
| 693 | /** |
| 694 | * Set the icon displayed on this tab. |
| 695 | * |
| 696 | * @param icon The drawable to use as an icon |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 697 | * @return The current instance for call chaining |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 698 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 699 | public abstract Tab setIcon(Drawable icon); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 700 | |
| 701 | /** |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 702 | * Set the icon displayed on this tab. |
| 703 | * |
| 704 | * @param resId Resource ID referring to the drawable to use as an icon |
| 705 | * @return The current instance for call chaining |
| 706 | */ |
| 707 | public abstract Tab setIcon(int resId); |
| 708 | |
| 709 | /** |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 710 | * Set the text displayed on this tab. Text may be truncated if there is not |
| 711 | * room to display the entire string. |
| 712 | * |
| 713 | * @param text The text to display |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 714 | * @return The current instance for call chaining |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 715 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 716 | public abstract Tab setText(CharSequence text); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 717 | |
| 718 | /** |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 719 | * Set the text displayed on this tab. Text may be truncated if there is not |
| 720 | * room to display the entire string. |
| 721 | * |
| 722 | * @param resId A resource ID referring to the text that should be displayed |
| 723 | * @return The current instance for call chaining |
| 724 | */ |
| 725 | public abstract Tab setText(int resId); |
| 726 | |
| 727 | /** |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 728 | * Set a custom view to be used for this tab. This overrides values set by |
| 729 | * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 730 | * |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 731 | * @param view Custom view to be used as a tab. |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 732 | * @return The current instance for call chaining |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 733 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 734 | public abstract Tab setCustomView(View view); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 735 | |
| 736 | /** |
Adam Powell | 32555f3 | 2010-11-17 13:49:22 -0800 | [diff] [blame] | 737 | * Set a custom view to be used for this tab. This overrides values set by |
| 738 | * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}. |
| 739 | * |
| 740 | * @param layoutResId A layout resource to inflate and use as a custom tab view |
| 741 | * @return The current instance for call chaining |
| 742 | */ |
| 743 | public abstract Tab setCustomView(int layoutResId); |
| 744 | |
| 745 | /** |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 746 | * Retrieve a previously set custom view for this tab. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 747 | * |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 748 | * @return The custom view set by {@link #setCustomView(View)}. |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 749 | */ |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 750 | public abstract View getCustomView(); |
| 751 | |
| 752 | /** |
| 753 | * Give this Tab an arbitrary object to hold for later use. |
| 754 | * |
| 755 | * @param obj Object to store |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 756 | * @return The current instance for call chaining |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 757 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 758 | public abstract Tab setTag(Object obj); |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 759 | |
| 760 | /** |
| 761 | * @return This Tab's tag object. |
| 762 | */ |
| 763 | public abstract Object getTag(); |
| 764 | |
| 765 | /** |
| 766 | * Set the {@link TabListener} that will handle switching to and from this tab. |
| 767 | * All tabs must have a TabListener set before being added to the ActionBar. |
| 768 | * |
| 769 | * @param listener Listener to handle tab selection events |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 770 | * @return The current instance for call chaining |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 771 | */ |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 772 | public abstract Tab setTabListener(TabListener listener); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 773 | |
| 774 | /** |
| 775 | * Select this tab. Only valid if the tab has been added to the action bar. |
| 776 | */ |
| 777 | public abstract void select(); |
| 778 | } |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 779 | |
| 780 | /** |
| 781 | * Callback interface invoked when a tab is focused, unfocused, added, or removed. |
| 782 | */ |
| 783 | public interface TabListener { |
| 784 | /** |
| 785 | * Called when a tab enters the selected state. |
| 786 | * |
| 787 | * @param tab The tab that was selected |
| 788 | * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute |
| 789 | * 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] | 790 | * executed in a single transaction. This FragmentTransaction does not support |
| 791 | * being added to the back stack. |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 792 | */ |
| 793 | public void onTabSelected(Tab tab, FragmentTransaction ft); |
| 794 | |
| 795 | /** |
| 796 | * Called when a tab exits the selected state. |
| 797 | * |
| 798 | * @param tab The tab that was unselected |
| 799 | * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute |
| 800 | * 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] | 801 | * will be executed in a single transaction. This FragmentTransaction does not |
| 802 | * support being added to the back stack. |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 803 | */ |
| 804 | public void onTabUnselected(Tab tab, FragmentTransaction ft); |
Adam Powell | 7f9b905 | 2010-10-19 16:56:07 -0700 | [diff] [blame] | 805 | |
| 806 | /** |
| 807 | * Called when a tab that is already selected is chosen again by the user. |
| 808 | * Some applications may use this action to return to the top level of a category. |
| 809 | * |
| 810 | * @param tab The tab that was reselected. |
| 811 | * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 812 | * once this method returns. This FragmentTransaction does not support |
| 813 | * being added to the back stack. |
Adam Powell | 7f9b905 | 2010-10-19 16:56:07 -0700 | [diff] [blame] | 814 | */ |
| 815 | public void onTabReselected(Tab tab, FragmentTransaction ft); |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 816 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 817 | |
| 818 | /** |
| 819 | * Per-child layout information associated with action bar custom views. |
| 820 | * |
| 821 | * @attr ref android.R.styleable#ActionBar_LayoutParams_layout_gravity |
| 822 | */ |
| 823 | public static class LayoutParams extends MarginLayoutParams { |
| 824 | /** |
| 825 | * Gravity for the view associated with these LayoutParams. |
| 826 | * |
| 827 | * @see android.view.Gravity |
| 828 | */ |
| 829 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
| 830 | @ViewDebug.IntToString(from = -1, to = "NONE"), |
| 831 | @ViewDebug.IntToString(from = Gravity.NO_GRAVITY, to = "NONE"), |
| 832 | @ViewDebug.IntToString(from = Gravity.TOP, to = "TOP"), |
| 833 | @ViewDebug.IntToString(from = Gravity.BOTTOM, to = "BOTTOM"), |
| 834 | @ViewDebug.IntToString(from = Gravity.LEFT, to = "LEFT"), |
| 835 | @ViewDebug.IntToString(from = Gravity.RIGHT, to = "RIGHT"), |
| 836 | @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL, to = "CENTER_VERTICAL"), |
| 837 | @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL, to = "FILL_VERTICAL"), |
| 838 | @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"), |
| 839 | @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL, to = "FILL_HORIZONTAL"), |
| 840 | @ViewDebug.IntToString(from = Gravity.CENTER, to = "CENTER"), |
| 841 | @ViewDebug.IntToString(from = Gravity.FILL, to = "FILL") |
| 842 | }) |
| 843 | public int gravity = -1; |
| 844 | |
| 845 | public LayoutParams(Context c, AttributeSet attrs) { |
| 846 | super(c, attrs); |
| 847 | |
| 848 | TypedArray a = c.obtainStyledAttributes(attrs, |
| 849 | com.android.internal.R.styleable.ActionBar_LayoutParams); |
| 850 | gravity = a.getInt( |
| 851 | com.android.internal.R.styleable.ActionBar_LayoutParams_layout_gravity, -1); |
| 852 | } |
| 853 | |
| 854 | public LayoutParams(int width, int height) { |
| 855 | super(width, height); |
| 856 | this.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; |
| 857 | } |
| 858 | |
| 859 | public LayoutParams(int width, int height, int gravity) { |
| 860 | super(width, height); |
| 861 | this.gravity = gravity; |
| 862 | } |
| 863 | |
| 864 | public LayoutParams(int gravity) { |
| 865 | this(WRAP_CONTENT, MATCH_PARENT, gravity); |
| 866 | } |
| 867 | |
| 868 | public LayoutParams(LayoutParams source) { |
| 869 | super(source); |
| 870 | |
| 871 | this.gravity = source.gravity; |
| 872 | } |
| 873 | |
| 874 | public LayoutParams(ViewGroup.LayoutParams source) { |
| 875 | super(source); |
| 876 | } |
| 877 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 878 | } |