The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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.view; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.res.Configuration; |
| 21 | import android.content.res.TypedArray; |
| 22 | import android.graphics.PixelFormat; |
| 23 | import android.graphics.drawable.Drawable; |
| 24 | import android.net.Uri; |
| 25 | import android.os.Bundle; |
| 26 | import android.os.IBinder; |
| 27 | import android.util.Log; |
| 28 | |
| 29 | /** |
| 30 | * Abstract base class for a top-level window look and behavior policy. An |
| 31 | * instance of this class should be used as the top-level view added to the |
| 32 | * window manager. It provides standard UI policies such as a background, title |
| 33 | * area, default key processing, etc. |
| 34 | * |
| 35 | * <p>The only existing implementation of this abstract class is |
| 36 | * android.policy.PhoneWindow, which you should instantiate when needing a |
| 37 | * Window. Eventually that class will be refactored and a factory method |
| 38 | * added for creating Window instances without knowing about a particular |
| 39 | * implementation. |
| 40 | */ |
| 41 | public abstract class Window { |
| 42 | /** Flag for the "options panel" feature. This is enabled by default. */ |
| 43 | public static final int FEATURE_OPTIONS_PANEL = 0; |
| 44 | /** Flag for the "no title" feature, turning off the title at the top |
| 45 | * of the screen. */ |
| 46 | public static final int FEATURE_NO_TITLE = 1; |
| 47 | /** Flag for the progress indicator feature */ |
| 48 | public static final int FEATURE_PROGRESS = 2; |
| 49 | /** Flag for having an icon on the left side of the title bar */ |
| 50 | public static final int FEATURE_LEFT_ICON = 3; |
| 51 | /** Flag for having an icon on the right side of the title bar */ |
| 52 | public static final int FEATURE_RIGHT_ICON = 4; |
| 53 | /** Flag for indeterminate progress */ |
| 54 | public static final int FEATURE_INDETERMINATE_PROGRESS = 5; |
| 55 | /** Flag for the context menu. This is enabled by default. */ |
| 56 | public static final int FEATURE_CONTEXT_MENU = 6; |
| 57 | /** Flag for custom title. You cannot combine this feature with other title features. */ |
| 58 | public static final int FEATURE_CUSTOM_TITLE = 7; |
| 59 | /* Flag for asking for an OpenGL enabled window. |
| 60 | All 2D graphics will be handled by OpenGL ES. |
| 61 | Private for now, until it is better tested (not shipping in 1.0) |
| 62 | */ |
| 63 | private static final int FEATURE_OPENGL = 8; |
| 64 | /** Flag for setting the progress bar's visibility to VISIBLE */ |
| 65 | public static final int PROGRESS_VISIBILITY_ON = -1; |
| 66 | /** Flag for setting the progress bar's visibility to GONE */ |
| 67 | public static final int PROGRESS_VISIBILITY_OFF = -2; |
| 68 | /** Flag for setting the progress bar's indeterminate mode on */ |
| 69 | public static final int PROGRESS_INDETERMINATE_ON = -3; |
| 70 | /** Flag for setting the progress bar's indeterminate mode off */ |
| 71 | public static final int PROGRESS_INDETERMINATE_OFF = -4; |
| 72 | /** Starting value for the (primary) progress */ |
| 73 | public static final int PROGRESS_START = 0; |
| 74 | /** Ending value for the (primary) progress */ |
| 75 | public static final int PROGRESS_END = 10000; |
| 76 | /** Lowest possible value for the secondary progress */ |
| 77 | public static final int PROGRESS_SECONDARY_START = 20000; |
| 78 | /** Highest possible value for the secondary progress */ |
| 79 | public static final int PROGRESS_SECONDARY_END = 30000; |
| 80 | |
| 81 | /** The default features enabled */ |
| 82 | @SuppressWarnings({"PointlessBitwiseExpression"}) |
| 83 | protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) | |
| 84 | (1 << FEATURE_CONTEXT_MENU); |
| 85 | |
| 86 | /** |
| 87 | * The ID that the main layout in the XML layout file should have. |
| 88 | */ |
| 89 | public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content; |
| 90 | |
| 91 | private final Context mContext; |
| 92 | |
| 93 | private TypedArray mWindowStyle; |
| 94 | private Callback mCallback; |
| 95 | private WindowManager mWindowManager; |
| 96 | private IBinder mAppToken; |
| 97 | private String mAppName; |
| 98 | private Window mContainer; |
| 99 | private Window mActiveChild; |
| 100 | private boolean mIsActive = false; |
| 101 | private boolean mHasChildren = false; |
| 102 | private int mForcedWindowFlags = 0; |
| 103 | |
| 104 | private int mFeatures = DEFAULT_FEATURES; |
| 105 | private int mLocalFeatures = DEFAULT_FEATURES; |
| 106 | |
| 107 | private boolean mHaveWindowFormat = false; |
| 108 | private int mDefaultWindowFormat = PixelFormat.OPAQUE; |
| 109 | |
| 110 | private boolean mHasSoftInputMode = false; |
| 111 | |
| 112 | // The current window attributes. |
| 113 | private final WindowManager.LayoutParams mWindowAttributes = |
| 114 | new WindowManager.LayoutParams(); |
| 115 | |
| 116 | /** |
| 117 | * API from a Window back to its caller. This allows the client to |
| 118 | * intercept key dispatching, panels and menus, etc. |
| 119 | */ |
| 120 | public interface Callback { |
| 121 | /** |
| 122 | * Called to process key events. At the very least your |
| 123 | * implementation must call |
| 124 | * {@link android.view.Window#superDispatchKeyEvent} to do the |
| 125 | * standard key processing. |
| 126 | * |
| 127 | * @param event The key event. |
| 128 | * |
| 129 | * @return boolean Return true if this event was consumed. |
| 130 | */ |
| 131 | public boolean dispatchKeyEvent(KeyEvent event); |
| 132 | |
| 133 | /** |
| 134 | * Called to process touch screen events. At the very least your |
| 135 | * implementation must call |
| 136 | * {@link android.view.Window#superDispatchTouchEvent} to do the |
| 137 | * standard touch screen processing. |
| 138 | * |
| 139 | * @param event The touch screen event. |
| 140 | * |
| 141 | * @return boolean Return true if this event was consumed. |
| 142 | */ |
| 143 | public boolean dispatchTouchEvent(MotionEvent event); |
| 144 | |
| 145 | /** |
| 146 | * Called to process trackball events. At the very least your |
| 147 | * implementation must call |
| 148 | * {@link android.view.Window#superDispatchTrackballEvent} to do the |
| 149 | * standard trackball processing. |
| 150 | * |
| 151 | * @param event The trackball event. |
| 152 | * |
| 153 | * @return boolean Return true if this event was consumed. |
| 154 | */ |
| 155 | public boolean dispatchTrackballEvent(MotionEvent event); |
| 156 | |
| 157 | /** |
| 158 | * Instantiate the view to display in the panel for 'featureId'. |
| 159 | * You can return null, in which case the default content (typically |
| 160 | * a menu) will be created for you. |
| 161 | * |
| 162 | * @param featureId Which panel is being created. |
| 163 | * |
| 164 | * @return view The top-level view to place in the panel. |
| 165 | * |
| 166 | * @see #onPreparePanel |
| 167 | */ |
| 168 | public View onCreatePanelView(int featureId); |
| 169 | |
| 170 | /** |
| 171 | * Initialize the contents of the menu for panel 'featureId'. This is |
| 172 | * called if onCreatePanelView() returns null, giving you a standard |
| 173 | * menu in which you can place your items. It is only called once for |
| 174 | * the panel, the first time it is shown. |
| 175 | * |
| 176 | * <p>You can safely hold on to <var>menu</var> (and any items created |
| 177 | * from it), making modifications to it as desired, until the next |
| 178 | * time onCreatePanelMenu() is called for this feature. |
| 179 | * |
| 180 | * @param featureId The panel being created. |
| 181 | * @param menu The menu inside the panel. |
| 182 | * |
| 183 | * @return boolean You must return true for the panel to be displayed; |
| 184 | * if you return false it will not be shown. |
| 185 | */ |
| 186 | public boolean onCreatePanelMenu(int featureId, Menu menu); |
| 187 | |
| 188 | /** |
| 189 | * Prepare a panel to be displayed. This is called right before the |
| 190 | * panel window is shown, every time it is shown. |
| 191 | * |
| 192 | * @param featureId The panel that is being displayed. |
| 193 | * @param view The View that was returned by onCreatePanelView(). |
| 194 | * @param menu If onCreatePanelView() returned null, this is the Menu |
| 195 | * being displayed in the panel. |
| 196 | * |
| 197 | * @return boolean You must return true for the panel to be displayed; |
| 198 | * if you return false it will not be shown. |
| 199 | * |
| 200 | * @see #onCreatePanelView |
| 201 | */ |
| 202 | public boolean onPreparePanel(int featureId, View view, Menu menu); |
| 203 | |
| 204 | /** |
| 205 | * Called when a panel's menu is opened by the user. This may also be |
| 206 | * called when the menu is changing from one type to another (for |
| 207 | * example, from the icon menu to the expanded menu). |
| 208 | * |
| 209 | * @param featureId The panel that the menu is in. |
| 210 | * @param menu The menu that is opened. |
| 211 | * @return Return true to allow the menu to open, or false to prevent |
| 212 | * the menu from opening. |
| 213 | */ |
| 214 | public boolean onMenuOpened(int featureId, Menu menu); |
| 215 | |
| 216 | /** |
| 217 | * Called when a panel's menu item has been selected by the user. |
| 218 | * |
| 219 | * @param featureId The panel that the menu is in. |
| 220 | * @param item The menu item that was selected. |
| 221 | * |
| 222 | * @return boolean Return true to finish processing of selection, or |
| 223 | * false to perform the normal menu handling (calling its |
| 224 | * Runnable or sending a Message to its target Handler). |
| 225 | */ |
| 226 | public boolean onMenuItemSelected(int featureId, MenuItem item); |
| 227 | |
| 228 | /** |
| 229 | * This is called whenever the current window attributes change. |
| 230 | * |
| 231 | |
| 232 | */ |
| 233 | public void onWindowAttributesChanged(WindowManager.LayoutParams attrs); |
| 234 | |
| 235 | /** |
| 236 | * This hook is called whenever the content view of the screen changes |
| 237 | * (due to a call to |
| 238 | * {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams) |
| 239 | * Window.setContentView} or |
| 240 | * {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams) |
| 241 | * Window.addContentView}). |
| 242 | */ |
| 243 | public void onContentChanged(); |
| 244 | |
| 245 | /** |
| 246 | * This hook is called whenever the window focus changes. |
| 247 | * |
| 248 | * @param hasFocus Whether the window now has focus. |
| 249 | */ |
| 250 | public void onWindowFocusChanged(boolean hasFocus); |
| 251 | |
| 252 | /** |
| 253 | * Called when a panel is being closed. If another logical subsequent |
| 254 | * panel is being opened (and this panel is being closed to make room for the subsequent |
| 255 | * panel), this method will NOT be called. |
| 256 | * |
| 257 | * @param featureId The panel that is being displayed. |
| 258 | * @param menu If onCreatePanelView() returned null, this is the Menu |
| 259 | * being displayed in the panel. |
| 260 | */ |
| 261 | public void onPanelClosed(int featureId, Menu menu); |
| 262 | |
| 263 | /** |
| 264 | * Called when the user signals the desire to start a search. |
| 265 | * |
| 266 | * @return true if search launched, false if activity refuses (blocks) |
| 267 | * |
| 268 | * @see android.app.Activity#onSearchRequested() |
| 269 | */ |
| 270 | public boolean onSearchRequested(); |
| 271 | } |
| 272 | |
| 273 | public Window(Context context) { |
| 274 | mContext = context; |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Return the Context this window policy is running in, for retrieving |
| 279 | * resources and other information. |
| 280 | * |
| 281 | * @return Context The Context that was supplied to the constructor. |
| 282 | */ |
| 283 | public final Context getContext() { |
| 284 | return mContext; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Return the {@link android.R.styleable#Window} attributes from this |
| 289 | * window's theme. |
| 290 | */ |
| 291 | public final TypedArray getWindowStyle() { |
| 292 | synchronized (this) { |
| 293 | if (mWindowStyle == null) { |
| 294 | mWindowStyle = mContext.obtainStyledAttributes( |
| 295 | com.android.internal.R.styleable.Window); |
| 296 | } |
| 297 | return mWindowStyle; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Set the container for this window. If not set, the DecorWindow |
| 303 | * operates as a top-level window; otherwise, it negotiates with the |
| 304 | * container to display itself appropriately. |
| 305 | * |
| 306 | * @param container The desired containing Window. |
| 307 | */ |
| 308 | public void setContainer(Window container) { |
| 309 | mContainer = container; |
| 310 | if (container != null) { |
| 311 | // Embedded screens never have a title. |
| 312 | mFeatures |= 1<<FEATURE_NO_TITLE; |
| 313 | mLocalFeatures |= 1<<FEATURE_NO_TITLE; |
| 314 | container.mHasChildren = true; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Return the container for this Window. |
| 320 | * |
| 321 | * @return Window The containing window, or null if this is a |
| 322 | * top-level window. |
| 323 | */ |
| 324 | public final Window getContainer() { |
| 325 | return mContainer; |
| 326 | } |
| 327 | |
| 328 | public final boolean hasChildren() { |
| 329 | return mHasChildren; |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Set the window manager for use by this Window to, for example, |
| 334 | * display panels. This is <em>not</em> used for displaying the |
| 335 | * Window itself -- that must be done by the client. |
| 336 | * |
| 337 | * @param wm The ViewManager for adding new windows. |
| 338 | */ |
| 339 | public void setWindowManager(WindowManager wm, |
| 340 | IBinder appToken, String appName) { |
| 341 | mAppToken = appToken; |
| 342 | mAppName = appName; |
| 343 | if (wm == null) { |
| 344 | wm = WindowManagerImpl.getDefault(); |
| 345 | } |
| 346 | mWindowManager = new LocalWindowManager(wm); |
| 347 | } |
| 348 | |
| 349 | private class LocalWindowManager implements WindowManager { |
| 350 | LocalWindowManager(WindowManager wm) { |
| 351 | mWindowManager = wm; |
| 352 | } |
| 353 | |
| 354 | public final void addView(View view, ViewGroup.LayoutParams params) { |
| 355 | // Let this throw an exception on a bad params. |
| 356 | WindowManager.LayoutParams wp = (WindowManager.LayoutParams)params; |
| 357 | CharSequence curTitle = wp.getTitle(); |
| 358 | if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW && |
| 359 | wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 360 | if (wp.token == null) { |
| 361 | View decor = peekDecorView(); |
| 362 | if (decor != null) { |
| 363 | wp.token = decor.getWindowToken(); |
| 364 | } |
| 365 | } |
| 366 | if (curTitle == null || curTitle.length() == 0) { |
| 367 | String title; |
| 368 | if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) { |
| 369 | title="Media"; |
| 370 | } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 371 | title="Panel"; |
| 372 | } else { |
| 373 | title=Integer.toString(wp.type); |
| 374 | } |
| 375 | if (mAppName != null) { |
| 376 | title += ":" + mAppName; |
| 377 | } |
| 378 | wp.setTitle(title); |
| 379 | } |
| 380 | } else { |
| 381 | if (wp.token == null) { |
| 382 | wp.token = mContainer == null ? mAppToken : mContainer.mAppToken; |
| 383 | } |
| 384 | if ((curTitle == null || curTitle.length() == 0) |
| 385 | && mAppName != null) { |
| 386 | wp.setTitle(mAppName); |
| 387 | } |
| 388 | } |
| 389 | if (wp.packageName == null) { |
| 390 | wp.packageName = mContext.getPackageName(); |
| 391 | } |
| 392 | mWindowManager.addView(view, params); |
| 393 | } |
| 394 | |
| 395 | public void updateViewLayout(View view, ViewGroup.LayoutParams params) { |
| 396 | mWindowManager.updateViewLayout(view, params); |
| 397 | } |
| 398 | |
| 399 | public final void removeView(View view) { |
| 400 | mWindowManager.removeView(view); |
| 401 | } |
| 402 | |
| 403 | public final void removeViewImmediate(View view) { |
| 404 | mWindowManager.removeViewImmediate(view); |
| 405 | } |
| 406 | |
| 407 | public Display getDefaultDisplay() { |
| 408 | return mWindowManager.getDefaultDisplay(); |
| 409 | } |
| 410 | |
| 411 | WindowManager mWindowManager; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Return the window manager allowing this Window to display its own |
| 416 | * windows. |
| 417 | * |
| 418 | * @return WindowManager The ViewManager. |
| 419 | */ |
| 420 | public WindowManager getWindowManager() { |
| 421 | return mWindowManager; |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Set the Callback interface for this window, used to intercept key |
| 426 | * events and other dynamic operations in the window. |
| 427 | * |
| 428 | * @param callback The desired Callback interface. |
| 429 | */ |
| 430 | public void setCallback(Callback callback) { |
| 431 | mCallback = callback; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Return the current Callback interface for this window. |
| 436 | */ |
| 437 | public final Callback getCallback() { |
| 438 | return mCallback; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Return whether this window is being displayed with a floating style |
| 443 | * (based on the {@link android.R.attr#windowIsFloating} attribute in |
| 444 | * the style/theme). |
| 445 | * |
| 446 | * @return Returns true if the window is configured to be displayed floating |
| 447 | * on top of whatever is behind it. |
| 448 | */ |
| 449 | public abstract boolean isFloating(); |
| 450 | |
| 451 | /** |
| 452 | * Set the width and height layout parameters of the window. The default |
| 453 | * for both of these is FILL_PARENT; you can change them to WRAP_CONTENT to |
| 454 | * make a window that is not full-screen. |
| 455 | * |
| 456 | * @param width The desired layout width of the window. |
| 457 | * @param height The desired layout height of the window. |
| 458 | */ |
| 459 | public void setLayout(int width, int height) |
| 460 | { |
| 461 | final WindowManager.LayoutParams attrs = getAttributes(); |
| 462 | attrs.width = width; |
| 463 | attrs.height = height; |
| 464 | if (mCallback != null) { |
| 465 | mCallback.onWindowAttributesChanged(attrs); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Set the gravity of the window, as per the Gravity constants. This |
| 471 | * controls how the window manager is positioned in the overall window; it |
| 472 | * is only useful when using WRAP_CONTENT for the layout width or height. |
| 473 | * |
| 474 | * @param gravity The desired gravity constant. |
| 475 | * |
| 476 | * @see Gravity |
| 477 | * @see #setLayout |
| 478 | */ |
| 479 | public void setGravity(int gravity) |
| 480 | { |
| 481 | final WindowManager.LayoutParams attrs = getAttributes(); |
| 482 | attrs.gravity = gravity; |
| 483 | if (mCallback != null) { |
| 484 | mCallback.onWindowAttributesChanged(attrs); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | /** |
| 489 | * Set the type of the window, as per the WindowManager.LayoutParams |
| 490 | * types. |
| 491 | * |
| 492 | * @param type The new window type (see WindowManager.LayoutParams). |
| 493 | */ |
| 494 | public void setType(int type) { |
| 495 | final WindowManager.LayoutParams attrs = getAttributes(); |
| 496 | attrs.type = type; |
| 497 | if (mCallback != null) { |
| 498 | mCallback.onWindowAttributesChanged(attrs); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Set the format of window, as per the PixelFormat types. This overrides |
| 504 | * the default format that is selected by the Window based on its |
| 505 | * window decorations. |
| 506 | * |
| 507 | * @param format The new window format (see PixelFormat). Use |
| 508 | * PixelFormat.UNKNOWN to allow the Window to select |
| 509 | * the format. |
| 510 | * |
| 511 | * @see PixelFormat |
| 512 | */ |
| 513 | public void setFormat(int format) { |
| 514 | final WindowManager.LayoutParams attrs = getAttributes(); |
| 515 | if (format != PixelFormat.UNKNOWN) { |
| 516 | attrs.format = format; |
| 517 | mHaveWindowFormat = true; |
| 518 | } else { |
| 519 | attrs.format = mDefaultWindowFormat; |
| 520 | mHaveWindowFormat = false; |
| 521 | } |
| 522 | if (mCallback != null) { |
| 523 | mCallback.onWindowAttributesChanged(attrs); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Specify custom animations to use for the window, as per |
| 529 | * {@link WindowManager.LayoutParams#windowAnimations |
| 530 | * WindowManager.LayoutParams.windowAnimations}. Providing anything besides |
| 531 | * 0 here will override the animations the window would |
| 532 | * normally retrieve from its theme. |
| 533 | */ |
| 534 | public void setWindowAnimations(int resId) { |
| 535 | final WindowManager.LayoutParams attrs = getAttributes(); |
| 536 | attrs.windowAnimations = resId; |
| 537 | if (mCallback != null) { |
| 538 | mCallback.onWindowAttributesChanged(attrs); |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | /** |
| 543 | * Specify an explicit soft input mode to use for the window, as per |
| 544 | * {@link WindowManager.LayoutParams#softInputMode |
| 545 | * WindowManager.LayoutParams.softInputMode}. Providing anything besides |
| 546 | * "unspecified" here will override the input mode the window would |
| 547 | * normally retrieve from its theme. |
| 548 | */ |
| 549 | public void setSoftInputMode(int mode) { |
| 550 | final WindowManager.LayoutParams attrs = getAttributes(); |
| 551 | if (mode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { |
| 552 | attrs.softInputMode = mode; |
| 553 | mHasSoftInputMode = true; |
| 554 | } else { |
| 555 | mHasSoftInputMode = false; |
| 556 | } |
| 557 | if (mCallback != null) { |
| 558 | mCallback.onWindowAttributesChanged(attrs); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * Convenience function to set the flag bits as specified in flags, as |
| 564 | * per {@link #setFlags}. |
| 565 | * @param flags The flag bits to be set. |
| 566 | * @see #setFlags |
| 567 | */ |
| 568 | public void addFlags(int flags) { |
| 569 | setFlags(flags, flags); |
| 570 | } |
| 571 | |
| 572 | /** |
| 573 | * Convenience function to clear the flag bits as specified in flags, as |
| 574 | * per {@link #setFlags}. |
| 575 | * @param flags The flag bits to be cleared. |
| 576 | * @see #setFlags |
| 577 | */ |
| 578 | public void clearFlags(int flags) { |
| 579 | setFlags(0, flags); |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * Set the flags of the window, as per the |
| 584 | * {@link WindowManager.LayoutParams WindowManager.LayoutParams} |
| 585 | * flags. |
| 586 | * |
| 587 | * <p>Note that some flags must be set before the window decoration is |
| 588 | * created (by the first call to |
| 589 | * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or |
| 590 | * {@link #getDecorView()}: |
| 591 | * {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and |
| 592 | * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}. These |
| 593 | * will be set for you based on the {@link android.R.attr#windowIsFloating} |
| 594 | * attribute. |
| 595 | * |
| 596 | * @param flags The new window flags (see WindowManager.LayoutParams). |
| 597 | * @param mask Which of the window flag bits to modify. |
| 598 | */ |
| 599 | public void setFlags(int flags, int mask) { |
| 600 | final WindowManager.LayoutParams attrs = getAttributes(); |
| 601 | attrs.flags = (attrs.flags&~mask) | (flags&mask); |
| 602 | mForcedWindowFlags |= mask; |
| 603 | if (mCallback != null) { |
| 604 | mCallback.onWindowAttributesChanged(attrs); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Specify custom window attributes. <strong>PLEASE NOTE:</strong> the |
| 610 | * layout params you give here should generally be from values previously |
| 611 | * retrieved with {@link #getAttributes()}; you probably do not want to |
| 612 | * blindly create and apply your own, since this will blow away any values |
| 613 | * set by the framework that you are not interested in. |
| 614 | * |
| 615 | * @param a The new window attributes, which will completely override any |
| 616 | * current values. |
| 617 | */ |
| 618 | public void setAttributes(WindowManager.LayoutParams a) { |
| 619 | mWindowAttributes.copyFrom(a); |
| 620 | if (mCallback != null) { |
| 621 | mCallback.onWindowAttributesChanged(mWindowAttributes); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * Retrieve the current window attributes associated with this panel. |
| 627 | * |
| 628 | * @return WindowManager.LayoutParams Either the existing window |
| 629 | * attributes object, or a freshly created one if there is none. |
| 630 | */ |
| 631 | public final WindowManager.LayoutParams getAttributes() { |
| 632 | return mWindowAttributes; |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * Return the window flags that have been explicitly set by the client, |
| 637 | * so will not be modified by {@link #getDecorView}. |
| 638 | */ |
| 639 | protected final int getForcedWindowFlags() { |
| 640 | return mForcedWindowFlags; |
| 641 | } |
| 642 | |
| 643 | /** |
| 644 | * Has the app specified their own soft input mode? |
| 645 | */ |
| 646 | protected final boolean hasSoftInputMode() { |
| 647 | return mHasSoftInputMode; |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * Enable extended screen features. This must be called before |
| 652 | * setContentView(). May be called as many times as desired as long as it |
| 653 | * is before setContentView(). If not called, no extended features |
| 654 | * will be available. You can not turn off a feature once it is requested. |
| 655 | * You canot use other title features with {@link #FEATURE_CUSTOM_TITLE}. |
| 656 | * |
| 657 | * @param featureId The desired features, defined as constants by Window. |
| 658 | * @return The features that are now set. |
| 659 | */ |
| 660 | public boolean requestFeature(int featureId) { |
| 661 | final int flag = 1<<featureId; |
| 662 | mFeatures |= flag; |
| 663 | mLocalFeatures |= mContainer != null ? (flag&~mContainer.mFeatures) : flag; |
| 664 | return (mFeatures&flag) != 0; |
| 665 | } |
| 666 | |
| 667 | public final void makeActive() { |
| 668 | if (mContainer != null) { |
| 669 | if (mContainer.mActiveChild != null) { |
| 670 | mContainer.mActiveChild.mIsActive = false; |
| 671 | } |
| 672 | mContainer.mActiveChild = this; |
| 673 | } |
| 674 | mIsActive = true; |
| 675 | onActive(); |
| 676 | } |
| 677 | |
| 678 | public final boolean isActive() |
| 679 | { |
| 680 | return mIsActive; |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * Finds a view that was identified by the id attribute from the XML that |
| 685 | * was processed in {@link android.app.Activity#onCreate}. This will |
| 686 | * implicitly call {@link #getDecorView} for you, with all of the |
| 687 | * associated side-effects. |
| 688 | * |
| 689 | * @return The view if found or null otherwise. |
| 690 | */ |
| 691 | public View findViewById(int id) { |
| 692 | return getDecorView().findViewById(id); |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * Convenience for |
| 697 | * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} |
| 698 | * to set the screen content from a layout resource. The resource will be |
| 699 | * inflated, adding all top-level views to the screen. |
| 700 | * |
| 701 | * @param layoutResID Resource ID to be inflated. |
| 702 | * @see #setContentView(View, android.view.ViewGroup.LayoutParams) |
| 703 | */ |
| 704 | public abstract void setContentView(int layoutResID); |
| 705 | |
| 706 | /** |
| 707 | * Convenience for |
| 708 | * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} |
| 709 | * set the screen content to an explicit view. This view is placed |
| 710 | * directly into the screen's view hierarchy. It can itself be a complex |
| 711 | * view hierarhcy. |
| 712 | * |
| 713 | * @param view The desired content to display. |
| 714 | * @see #setContentView(View, android.view.ViewGroup.LayoutParams) |
| 715 | */ |
| 716 | public abstract void setContentView(View view); |
| 717 | |
| 718 | /** |
| 719 | * Set the screen content to an explicit view. This view is placed |
| 720 | * directly into the screen's view hierarchy. It can itself be a complex |
| 721 | * view hierarchy. |
| 722 | * |
| 723 | * <p>Note that calling this function "locks in" various characteristics |
| 724 | * of the window that can not, from this point forward, be changed: the |
| 725 | * features that have been requested with {@link #requestFeature(int)}, |
| 726 | * and certain window flags as described in {@link #setFlags(int, int)}. |
| 727 | * |
| 728 | * @param view The desired content to display. |
| 729 | * @param params Layout parameters for the view. |
| 730 | */ |
| 731 | public abstract void setContentView(View view, ViewGroup.LayoutParams params); |
| 732 | |
| 733 | /** |
| 734 | * Variation on |
| 735 | * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} |
| 736 | * to add an additional content view to the screen. Added after any existing |
| 737 | * ones in the screen -- existing views are NOT removed. |
| 738 | * |
| 739 | * @param view The desired content to display. |
| 740 | * @param params Layout parameters for the view. |
| 741 | */ |
| 742 | public abstract void addContentView(View view, ViewGroup.LayoutParams params); |
| 743 | |
| 744 | /** |
| 745 | * Return the view in this Window that currently has focus, or null if |
| 746 | * there are none. Note that this does not look in any containing |
| 747 | * Window. |
| 748 | * |
| 749 | * @return View The current View with focus or null. |
| 750 | */ |
| 751 | public abstract View getCurrentFocus(); |
| 752 | |
| 753 | /** |
| 754 | * Quick access to the {@link LayoutInflater} instance that this Window |
| 755 | * retrieved from its Context. |
| 756 | * |
| 757 | * @return LayoutInflater The shared LayoutInflater. |
| 758 | */ |
| 759 | public abstract LayoutInflater getLayoutInflater(); |
| 760 | |
| 761 | public abstract void setTitle(CharSequence title); |
| 762 | |
| 763 | public abstract void setTitleColor(int textColor); |
| 764 | |
| 765 | public abstract void openPanel(int featureId, KeyEvent event); |
| 766 | |
| 767 | public abstract void closePanel(int featureId); |
| 768 | |
| 769 | public abstract void togglePanel(int featureId, KeyEvent event); |
| 770 | |
| 771 | public abstract boolean performPanelShortcut(int featureId, |
| 772 | int keyCode, |
| 773 | KeyEvent event, |
| 774 | int flags); |
| 775 | public abstract boolean performPanelIdentifierAction(int featureId, |
| 776 | int id, |
| 777 | int flags); |
| 778 | |
| 779 | public abstract void closeAllPanels(); |
| 780 | |
| 781 | public abstract boolean performContextMenuIdentifierAction(int id, int flags); |
| 782 | |
| 783 | /** |
| 784 | * Should be called when the configuration is changed. |
| 785 | * |
| 786 | * @param newConfig The new configuration. |
| 787 | */ |
| 788 | public abstract void onConfigurationChanged(Configuration newConfig); |
| 789 | |
| 790 | /** |
| 791 | * Change the background of this window to a Drawable resource. Setting the |
| 792 | * background to null will make the window be opaque. To make the window |
| 793 | * transparent, you can use an empty drawable (for instance a ColorDrawable |
| 794 | * with the color 0 or the system drawable android:drawable/empty.) |
| 795 | * |
| 796 | * @param resid The resource identifier of a drawable resource which will be |
| 797 | * installed as the new background. |
| 798 | */ |
| 799 | public void setBackgroundDrawableResource(int resid) |
| 800 | { |
| 801 | setBackgroundDrawable(mContext.getResources().getDrawable(resid)); |
| 802 | } |
| 803 | |
| 804 | /** |
| 805 | * Change the background of this window to a custom Drawable. Setting the |
| 806 | * background to null will make the window be opaque. To make the window |
| 807 | * transparent, you can use an empty drawable (for instance a ColorDrawable |
| 808 | * with the color 0 or the system drawable android:drawable/empty.) |
| 809 | * |
| 810 | * @param drawable The new Drawable to use for this window's background. |
| 811 | */ |
| 812 | public abstract void setBackgroundDrawable(Drawable drawable); |
| 813 | |
| 814 | /** |
| 815 | * Set the value for a drawable feature of this window, from a resource |
| 816 | * identifier. You must have called requestFeauture(featureId) before |
| 817 | * calling this function. |
| 818 | * |
| 819 | * @see android.content.res.Resources#getDrawable(int) |
| 820 | * |
| 821 | * @param featureId The desired drawable feature to change, defined as a |
| 822 | * constant by Window. |
| 823 | * @param resId Resource identifier of the desired image. |
| 824 | */ |
| 825 | public abstract void setFeatureDrawableResource(int featureId, int resId); |
| 826 | |
| 827 | /** |
| 828 | * Set the value for a drawable feature of this window, from a URI. You |
| 829 | * must have called requestFeature(featureId) before calling this |
| 830 | * function. |
| 831 | * |
| 832 | * <p>The only URI currently supported is "content:", specifying an image |
| 833 | * in a content provider. |
| 834 | * |
| 835 | * @see android.widget.ImageView#setImageURI |
| 836 | * |
| 837 | * @param featureId The desired drawable feature to change. Features are |
| 838 | * constants defined by Window. |
| 839 | * @param uri The desired URI. |
| 840 | */ |
| 841 | public abstract void setFeatureDrawableUri(int featureId, Uri uri); |
| 842 | |
| 843 | /** |
| 844 | * Set an explicit Drawable value for feature of this window. You must |
| 845 | * have called requestFeature(featureId) before calling this function. |
| 846 | * |
| 847 | * @param featureId The desired drawable feature to change. |
| 848 | * Features are constants defined by Window. |
| 849 | * @param drawable A Drawable object to display. |
| 850 | */ |
| 851 | public abstract void setFeatureDrawable(int featureId, Drawable drawable); |
| 852 | |
| 853 | /** |
| 854 | * Set a custom alpha value for the given drawale feature, controlling how |
| 855 | * much the background is visible through it. |
| 856 | * |
| 857 | * @param featureId The desired drawable feature to change. |
| 858 | * Features are constants defined by Window. |
| 859 | * @param alpha The alpha amount, 0 is completely transparent and 255 is |
| 860 | * completely opaque. |
| 861 | */ |
| 862 | public abstract void setFeatureDrawableAlpha(int featureId, int alpha); |
| 863 | |
| 864 | /** |
| 865 | * Set the integer value for a feature. The range of the value depends on |
| 866 | * the feature being set. For FEATURE_PROGRESSS, it should go from 0 to |
| 867 | * 10000. At 10000 the progress is complete and the indicator hidden. |
| 868 | * |
| 869 | * @param featureId The desired feature to change. |
| 870 | * Features are constants defined by Window. |
| 871 | * @param value The value for the feature. The interpretation of this |
| 872 | * value is feature-specific. |
| 873 | */ |
| 874 | public abstract void setFeatureInt(int featureId, int value); |
| 875 | |
| 876 | /** |
| 877 | * Request that key events come to this activity. Use this if your |
| 878 | * activity has no views with focus, but the activity still wants |
| 879 | * a chance to process key events. |
| 880 | */ |
| 881 | public abstract void takeKeyEvents(boolean get); |
| 882 | |
| 883 | /** |
| 884 | * Used by custom windows, such as Dialog, to pass the key press event |
| 885 | * further down the view hierarchy. Application developers should |
| 886 | * not need to implement or call this. |
| 887 | * |
| 888 | */ |
| 889 | public abstract boolean superDispatchKeyEvent(KeyEvent event); |
| 890 | |
| 891 | /** |
| 892 | * Used by custom windows, such as Dialog, to pass the touch screen event |
| 893 | * further down the view hierarchy. Application developers should |
| 894 | * not need to implement or call this. |
| 895 | * |
| 896 | */ |
| 897 | public abstract boolean superDispatchTouchEvent(MotionEvent event); |
| 898 | |
| 899 | /** |
| 900 | * Used by custom windows, such as Dialog, to pass the trackball event |
| 901 | * further down the view hierarchy. Application developers should |
| 902 | * not need to implement or call this. |
| 903 | * |
| 904 | */ |
| 905 | public abstract boolean superDispatchTrackballEvent(MotionEvent event); |
| 906 | |
| 907 | /** |
| 908 | * Retrieve the top-level window decor view (containing the standard |
| 909 | * window frame/decorations and the client's content inside of that), which |
| 910 | * can be added as a window to the window manager. |
| 911 | * |
| 912 | * <p><em>Note that calling this function for the first time "locks in" |
| 913 | * various window characteristics as described in |
| 914 | * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}.</em></p> |
| 915 | * |
| 916 | * @return Returns the top-level window decor view. |
| 917 | */ |
| 918 | public abstract View getDecorView(); |
| 919 | |
| 920 | /** |
| 921 | * Retrieve the current decor view, but only if it has already been created; |
| 922 | * otherwise returns null. |
| 923 | * |
| 924 | * @return Returns the top-level window decor or null. |
| 925 | * @see #getDecorView |
| 926 | */ |
| 927 | public abstract View peekDecorView(); |
| 928 | |
| 929 | public abstract Bundle saveHierarchyState(); |
| 930 | |
| 931 | public abstract void restoreHierarchyState(Bundle savedInstanceState); |
| 932 | |
| 933 | protected abstract void onActive(); |
| 934 | |
| 935 | /** |
| 936 | * Return the feature bits that are enabled. This is the set of features |
| 937 | * that were given to requestFeature(), and are being handled by this |
| 938 | * Window itself or its container. That is, it is the set of |
| 939 | * requested features that you can actually use. |
| 940 | * |
| 941 | * <p>To do: add a public version of this API that allows you to check for |
| 942 | * features by their feature ID. |
| 943 | * |
| 944 | * @return int The feature bits. |
| 945 | */ |
| 946 | protected final int getFeatures() |
| 947 | { |
| 948 | return mFeatures; |
| 949 | } |
| 950 | |
| 951 | /** |
| 952 | * Return the feature bits that are being implemented by this Window. |
| 953 | * This is the set of features that were given to requestFeature(), and are |
| 954 | * being handled by only this Window itself, not by its containers. |
| 955 | * |
| 956 | * @return int The feature bits. |
| 957 | */ |
| 958 | protected final int getLocalFeatures() |
| 959 | { |
| 960 | return mLocalFeatures; |
| 961 | } |
| 962 | |
| 963 | /** |
| 964 | * Set the default format of window, as per the PixelFormat types. This |
| 965 | * is the format that will be used unless the client specifies in explicit |
| 966 | * format with setFormat(); |
| 967 | * |
| 968 | * @param format The new window format (see PixelFormat). |
| 969 | * |
| 970 | * @see #setFormat |
| 971 | * @see PixelFormat |
| 972 | */ |
| 973 | protected void setDefaultWindowFormat(int format) { |
| 974 | mDefaultWindowFormat = format; |
| 975 | if (!mHaveWindowFormat) { |
| 976 | final WindowManager.LayoutParams attrs = getAttributes(); |
| 977 | attrs.format = format; |
| 978 | if (mCallback != null) { |
| 979 | mCallback.onWindowAttributesChanged(attrs); |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | public abstract void setChildDrawable(int featureId, Drawable drawable); |
| 985 | |
| 986 | public abstract void setChildInt(int featureId, int value); |
| 987 | |
| 988 | /** |
| 989 | * Is a keypress one of the defined shortcut keys for this window. |
| 990 | * @param keyCode the key code from {@link android.view.KeyEvent} to check. |
| 991 | * @param event the {@link android.view.KeyEvent} to use to help check. |
| 992 | */ |
| 993 | public abstract boolean isShortcutKey(int keyCode, KeyEvent event); |
| 994 | |
| 995 | /** |
| 996 | * @see android.app.Activity#setVolumeControlStream(int) |
| 997 | */ |
| 998 | public abstract void setVolumeControlStream(int streamType); |
| 999 | |
| 1000 | /** |
| 1001 | * @see android.app.Activity#getVolumeControlStream() |
| 1002 | */ |
| 1003 | public abstract int getVolumeControlStream(); |
| 1004 | |
| 1005 | } |