blob: 35d7cc9bf64eafe2955f1ff8abdc55c53aa1a6e1 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.view;
18
19import android.content.pm.ActivityInfo;
20import android.graphics.PixelFormat;
21import android.os.IBinder;
22import android.os.Parcel;
23import android.os.Parcelable;
24import android.text.TextUtils;
25import android.util.Log;
26
27
28/**
29 * The interface that apps use to talk to the window manager.
30 * <p>
31 * Use <code>Context.getSystemService(Context.WINDOW_SERVICE)</code> to get one of these.
32 *
33 * @see android.content.Context#getSystemService
34 * @see android.content.Context#WINDOW_SERVICE
35 */
36public interface WindowManager extends ViewManager {
37 /**
38 * Exception that is thrown when trying to add view whose
39 * {@link WindowManager.LayoutParams} {@link WindowManager.LayoutParams#token}
40 * is invalid.
41 */
42 public static class BadTokenException extends RuntimeException {
43 public BadTokenException() {
44 }
45
46 public BadTokenException(String name) {
47 super(name);
48 }
49 }
50
51 /**
52 * Use this method to get the default Display object.
53 *
54 * @return default Display object
55 */
56 public Display getDefaultDisplay();
57
58 /**
59 * Special variation of {@link #removeView} that immediately invokes
60 * the given view hierarchy's {@link View#onDetachedFromWindow()
61 * View.onDetachedFromWindow()} methods before returning. This is not
62 * for normal applications; using it correctly requires great care.
63 *
64 * @param view The view to be removed.
65 */
66 public void removeViewImmediate(View view);
67
68 public static class LayoutParams extends ViewGroup.LayoutParams
69 implements Parcelable {
70 /**
71 * X position for this window. With the default gravity it is ignored.
72 * When using {@link Gravity#LEFT} or {@link Gravity#RIGHT} it provides
73 * an offset from the given edge.
74 */
75 public int x;
76
77 /**
78 * Y position for this window. With the default gravity it is ignored.
79 * When using {@link Gravity#TOP} or {@link Gravity#BOTTOM} it provides
80 * an offset from the given edge.
81 */
82 public int y;
83
84 /**
85 * Indicates how much of the extra space will be allocated horizontally
86 * to the view associated with these LayoutParams. Specify 0 if the view
87 * should not be stretched. Otherwise the extra pixels will be pro-rated
88 * among all views whose weight is greater than 0.
89 */
90 public float horizontalWeight;
91
92 /**
93 * Indicates how much of the extra space will be allocated vertically
94 * to the view associated with these LayoutParams. Specify 0 if the view
95 * should not be stretched. Otherwise the extra pixels will be pro-rated
96 * among all views whose weight is greater than 0.
97 */
98 public float verticalWeight;
99
100 /**
101 * The general type of window. There are three main classes of
102 * window types:
103 * <ul>
104 * <li> <strong>Application windows</strong> (ranging from
105 * {@link #FIRST_APPLICATION_WINDOW} to
106 * {@link #LAST_APPLICATION_WINDOW}) are normal top-level application
107 * windows. For these types of windows, the {@link #token} must be
108 * set to the token of the activity they are a part of (this will
109 * normally be done for you if {@link #token} is null).
110 * <li> <strong>Sub-windows</strong> (ranging from
111 * {@link #FIRST_SUB_WINDOW} to
112 * {@link #LAST_SUB_WINDOW}) are associated with another top-level
113 * window. For these types of windows, the {@link #token} must be
114 * the token of the window it is attached to.
115 * <li> <strong>System windows</strong> (ranging from
116 * {@link #FIRST_SYSTEM_WINDOW} to
117 * {@link #LAST_SYSTEM_WINDOW}) are special types of windows for
118 * use by the system for specific purposes. They should not normally
119 * be used by applications, and a special permission is required
120 * to use them.
121 * </ul>
122 *
123 * @see #TYPE_BASE_APPLICATION
124 * @see #TYPE_APPLICATION
125 * @see #TYPE_APPLICATION_STARTING
126 * @see #TYPE_APPLICATION_PANEL
127 * @see #TYPE_APPLICATION_MEDIA
128 * @see #TYPE_APPLICATION_SUB_PANEL
129 * @see #TYPE_APPLICATION_ATTACHED_DIALOG
130 * @see #TYPE_STATUS_BAR
131 * @see #TYPE_SEARCH_BAR
132 * @see #TYPE_PHONE
133 * @see #TYPE_SYSTEM_ALERT
134 * @see #TYPE_KEYGUARD
135 * @see #TYPE_TOAST
136 * @see #TYPE_SYSTEM_OVERLAY
137 * @see #TYPE_PRIORITY_PHONE
138 * @see #TYPE_STATUS_BAR_PANEL
139 * @see #TYPE_SYSTEM_DIALOG
140 * @see #TYPE_KEYGUARD_DIALOG
141 * @see #TYPE_SYSTEM_ERROR
142 * @see #TYPE_INPUT_METHOD
143 * @see #TYPE_INPUT_METHOD_DIALOG
144 */
145 public int type;
146
147 /**
148 * Start of window types that represent normal application windows.
149 */
150 public static final int FIRST_APPLICATION_WINDOW = 1;
151
152 /**
153 * Window type: an application window that serves as the "base" window
154 * of the overall application; all other application windows will
155 * appear on top of it.
156 */
157 public static final int TYPE_BASE_APPLICATION = 1;
158
159 /**
160 * Window type: a normal application window. The {@link #token} must be
161 * an Activity token identifying who the window belongs to.
162 */
163 public static final int TYPE_APPLICATION = 2;
164
165 /**
166 * Window type: special application window that is displayed while the
167 * application is starting. Not for use by applications themselves;
168 * this is used by the system to display something until the
169 * application can show its own windows.
170 */
171 public static final int TYPE_APPLICATION_STARTING = 3;
172
173 /**
174 * End of types of application windows.
175 */
176 public static final int LAST_APPLICATION_WINDOW = 99;
177
178 /**
179 * Start of types of sub-windows. The {@link #token} of these windows
180 * must be set to the window they are attached to. These types of
181 * windows are kept next to their attached window in Z-order, and their
182 * coordinate space is relative to their attached window.
183 */
184 public static final int FIRST_SUB_WINDOW = 1000;
185
186 /**
187 * Window type: a panel on top of an application window. These windows
188 * appear on top of their attached window.
189 */
190 public static final int TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW;
191
192 /**
193 * Window type: window for showing media (e.g. video). These windows
194 * are displayed behind their attached window.
195 */
196 public static final int TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW+1;
197
198 /**
199 * Window type: a sub-panel on top of an application window. These
200 * windows are displayed on top their attached window and any
201 * {@link #TYPE_APPLICATION_PANEL} panels.
202 */
203 public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2;
204
205 /** Window type: like {@link #TYPE_APPLICATION_PANEL}, but layout
206 * of the window happens as that of a top-level window, <em>not</em>
207 * as a child of its container.
208 */
209 public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3;
210
211 /**
Dianne Hackbornc4d5d022009-05-21 17:32:42 -0700212 * Window type: window for showing overlays on top of media windows.
213 * These windows are displayed between TYPE_APPLICATION_MEDIA and the
214 * application window. They should be translucent to be useful. This
215 * is a big ugly hack so:
216 * @hide
217 */
218 public static final int TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW+4;
219
220 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 * End of types of sub-windows.
222 */
223 public static final int LAST_SUB_WINDOW = 1999;
224
225 /**
226 * Start of system-specific window types. These are not normally
227 * created by applications.
228 */
229 public static final int FIRST_SYSTEM_WINDOW = 2000;
230
231 /**
232 * Window type: the status bar. There can be only one status bar
233 * window; it is placed at the top of the screen, and all other
234 * windows are shifted down so they are below it.
235 */
236 public static final int TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW;
237
238 /**
239 * Window type: the search bar. There can be only one search bar
240 * window; it is placed at the top of the screen.
241 */
242 public static final int TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW+1;
243
244 /**
245 * Window type: phone. These are non-application windows providing
246 * user interaction with the phone (in particular incoming calls).
247 * These windows are normally placed above all applications, but behind
248 * the status bar.
249 */
250 public static final int TYPE_PHONE = FIRST_SYSTEM_WINDOW+2;
251
252 /**
253 * Window type: system window, such as low power alert. These windows
254 * are always on top of application windows.
255 */
256 public static final int TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3;
257
258 /**
259 * Window type: keyguard window.
260 */
261 public static final int TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW+4;
262
263 /**
264 * Window type: transient notifications.
265 */
266 public static final int TYPE_TOAST = FIRST_SYSTEM_WINDOW+5;
267
268 /**
269 * Window type: system overlay windows, which need to be displayed
270 * on top of everything else. These windows must not take input
271 * focus, or they will interfere with the keyguard.
272 */
273 public static final int TYPE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+6;
274
275 /**
276 * Window type: priority phone UI, which needs to be displayed even if
277 * the keyguard is active. These windows must not take input
278 * focus, or they will interfere with the keyguard.
279 */
280 public static final int TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW+7;
281
282 /**
283 * Window type: panel that slides out from the status bar
284 */
285 public static final int TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW+8;
286
287 /**
288 * Window type: panel that slides out from the status bar
289 */
290 public static final int TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW+8;
291
292 /**
293 * Window type: dialogs that the keyguard shows
294 */
295 public static final int TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW+9;
296
297 /**
298 * Window type: internal system error windows, appear on top of
299 * everything they can.
300 */
301 public static final int TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW+10;
302
303 /**
304 * Window type: internal input methods windows, which appear above
305 * the normal UI. Application windows may be resized or panned to keep
306 * the input focus visible while this window is displayed.
307 */
308 public static final int TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW+11;
309
310 /**
311 * Window type: internal input methods dialog windows, which appear above
312 * the current input method window.
313 */
314 public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12;
315
316 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700317 * Window type: wallpaper window, placed behind any window that wants
318 * to sit on top of the wallpaper.
319 */
320 public static final int TYPE_WALLPAPER = FIRST_SYSTEM_WINDOW+13;
321
322 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 * End of types of system windows.
324 */
325 public static final int LAST_SYSTEM_WINDOW = 2999;
326
327 /**
328 * Specifies what type of memory buffers should be used by this window.
329 * Default is normal.
330 *
331 * @see #MEMORY_TYPE_NORMAL
332 * @see #MEMORY_TYPE_HARDWARE
333 * @see #MEMORY_TYPE_GPU
334 * @see #MEMORY_TYPE_PUSH_BUFFERS
335 */
336 public int memoryType;
337
338 /** Memory type: The window's surface is allocated in main memory. */
339 public static final int MEMORY_TYPE_NORMAL = 0;
340 /** Memory type: The window's surface is configured to be accessible
341 * by DMA engines and hardware accelerators. */
342 public static final int MEMORY_TYPE_HARDWARE = 1;
343 /** Memory type: The window's surface is configured to be accessible
344 * by graphics accelerators. */
345 public static final int MEMORY_TYPE_GPU = 2;
346 /** Memory type: The window's surface doesn't own its buffers and
347 * therefore cannot be locked. Instead the buffers are pushed to
348 * it through native binder calls. */
349 public static final int MEMORY_TYPE_PUSH_BUFFERS = 3;
350
351 /**
352 * Various behavioral options/flags. Default is none.
353 *
354 * @see #FLAG_BLUR_BEHIND
355 * @see #FLAG_DIM_BEHIND
356 * @see #FLAG_NOT_FOCUSABLE
357 * @see #FLAG_NOT_TOUCHABLE
358 * @see #FLAG_NOT_TOUCH_MODAL
359 * @see #FLAG_LAYOUT_IN_SCREEN
360 * @see #FLAG_DITHER
361 * @see #FLAG_KEEP_SCREEN_ON
362 * @see #FLAG_FULLSCREEN
363 * @see #FLAG_FORCE_NOT_FULLSCREEN
364 * @see #FLAG_IGNORE_CHEEK_PRESSES
365 */
366 public int flags;
367
368 /** Window flag: everything behind this window will be dimmed.
369 * Use {@link #dimAmount} to control the amount of dim. */
370 public static final int FLAG_DIM_BEHIND = 0x00000002;
371
372 /** Window flag: blur everything behind this window. */
373 public static final int FLAG_BLUR_BEHIND = 0x00000004;
374
375 /** Window flag: this window won't ever get key input focus, so the
376 * user can not send key or other button events to it. Those will
377 * instead go to whatever focusable window is behind it. This flag
378 * will also enable {@link #FLAG_NOT_TOUCH_MODAL} whether or not that
379 * is explicitly set.
380 *
381 * <p>Setting this flag also implies that the window will not need to
382 * interact with
383 * a soft input method, so it will be Z-ordered and positioned
384 * independently of any active input method (typically this means it
385 * gets Z-ordered on top of the input method, so it can use the full
386 * screen for its content and cover the input method if needed. You
387 * can use {@link #FLAG_ALT_FOCUSABLE_IM} to modify this behavior. */
388 public static final int FLAG_NOT_FOCUSABLE = 0x00000008;
389
390 /** Window flag: this window can never receive touch events. */
391 public static final int FLAG_NOT_TOUCHABLE = 0x00000010;
392
393 /** Window flag: Even when this window is focusable (its
394 * {@link #FLAG_NOT_FOCUSABLE is not set), allow any pointer events
395 * outside of the window to be sent to the windows behind it. Otherwise
396 * it will consume all pointer events itself, regardless of whether they
397 * are inside of the window. */
398 public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020;
399
400 /** Window flag: When set, if the device is asleep when the touch
401 * screen is pressed, you will receive this first touch event. Usually
402 * the first touch event is consumed by the system since the user can
403 * not see what they are pressing on.
404 */
405 public static final int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040;
406
407 /** Window flag: as long as this window is visible to the user, keep
408 * the device's screen turned on and bright. */
409 public static final int FLAG_KEEP_SCREEN_ON = 0x00000080;
410
411 /** Window flag: place the window within the entire screen, ignoring
412 * decorations around the border (a.k.a. the status bar). The
413 * window must correctly position its contents to take the screen
414 * decoration into account. This flag is normally set for you
415 * by Window as described in {@link Window#setFlags}. */
416 public static final int FLAG_LAYOUT_IN_SCREEN = 0x00000100;
417
418 /** Window flag: allow window to extend outside of the screen. */
419 public static final int FLAG_LAYOUT_NO_LIMITS = 0x00000200;
420
421 /** Window flag: Hide all screen decorations (e.g. status bar) while
422 * this window is displayed. This allows the window to use the entire
423 * display space for itself -- the status bar will be hidden when
424 * an app window with this flag set is on the top layer. */
425 public static final int FLAG_FULLSCREEN = 0x00000400;
426
427 /** Window flag: Override {@link #FLAG_FULLSCREEN and force the
428 * screen decorations (such as status bar) to be shown. */
429 public static final int FLAG_FORCE_NOT_FULLSCREEN = 0x00000800;
430
431 /** Window flag: turn on dithering when compositing this window to
432 * the screen. */
433 public static final int FLAG_DITHER = 0x00001000;
434
435 /** Window flag: don't allow screen shots while this window is
436 * displayed. */
437 public static final int FLAG_SECURE = 0x00002000;
438
439 /** Window flag: a special mode where the layout parameters are used
440 * to perform scaling of the surface when it is composited to the
441 * screen. */
442 public static final int FLAG_SCALED = 0x00004000;
443
444 /** Window flag: intended for windows that will often be used when the user is
445 * holding the screen against their face, it will aggressively filter the event
446 * stream to prevent unintended presses in this situation that may not be
447 * desired for a particular window, when such an event stream is detected, the
448 * application will receive a CANCEL motion event to indicate this so applications
449 * can handle this accordingly by taking no action on the event
450 * until the finger is released. */
451 public static final int FLAG_IGNORE_CHEEK_PRESSES = 0x00008000;
452
453 /** Window flag: a special option only for use in combination with
454 * {@link #FLAG_LAYOUT_IN_SCREEN}. When requesting layout in the
455 * screen your window may appear on top of or behind screen decorations
456 * such as the status bar. By also including this flag, the window
457 * manager will report the inset rectangle needed to ensure your
458 * content is not covered by screen decorations. This flag is normally
459 * set for you by Window as described in {@link Window#setFlags}.*/
460 public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000;
461
462 /** Window flag: invert the state of {@link #FLAG_NOT_FOCUSABLE} with
463 * respect to how this window interacts with the current method. That
464 * is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the
465 * window will behave as if it needs to interact with the input method
466 * and thus be placed behind/away from it; if FLAG_NOT_FOCUSABLE is
467 * not set and this flag is set, then the window will behave as if it
468 * doesn't need to interact with the input method and can be placed
469 * to use more space and cover the input method.
470 */
471 public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000;
472
473 /** Window flag: if you have set {@link #FLAG_NOT_TOUCH_MODAL}, you
474 * can set this flag to receive a single special MotionEvent with
475 * the action
476 * {@link MotionEvent#ACTION_OUTSIDE MotionEvent.ACTION_OUTSIDE} for
477 * touches that occur outside of your window. Note that you will not
478 * receive the full down/move/up gesture, only the location of the
479 * first down as an ACTION_OUTSIDE.
480 */
481 public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000;
482
Suchi Amalapurapud1a93372009-05-14 17:54:31 -0700483 /** Window flag: special flag to let windows be shown when the screen
484 * is locked. This will let application windows take precedence over
485 * key guard or any other lock screens. Can be used with
486 * {@link #FLAG_KEEP_SCREEN_ON} to turn screen on and display windows
487 * directly before showing the key guard window
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700488 */
Suchi Amalapurapud1a93372009-05-14 17:54:31 -0700489 public static final int FLAG_SHOW_WHEN_LOCKED = 0x00080000;
490
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700491 /** Window flag: ask that the system wallpaper be shown behind
492 * your window. The window surface must be translucent to be able
493 * to actually see the wallpaper behind it; this flag just ensures
494 * that the wallpaper surface will be there if this window actually
495 * has translucent regions.
496 */
497 public static final int FLAG_SHOW_WALLPAPER = 0x00100000;
498
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700499 /** Window flag: special flag to limit the size of the window to be
500 * original size ([320x480] x density). Used to create window for applications
501 * running under compatibility mode.
502 *
503 * {@hide} */
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700504 public static final int FLAG_COMPATIBLE_WINDOW = 0x20000000;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 /** Window flag: a special option intended for system dialogs. When
507 * this flag is set, the window will demand focus unconditionally when
508 * it is created.
509 * {@hide} */
510 public static final int FLAG_SYSTEM_ERROR = 0x40000000;
511
512 /**
513 * Given a particular set of window manager flags, determine whether
514 * such a window may be a target for an input method when it has
515 * focus. In particular, this checks the
516 * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM}
517 * flags and returns true if the combination of the two corresponds
518 * to a window that needs to be behind the input method so that the
519 * user can type into it.
520 *
521 * @param flags The current window manager flags.
522 *
523 * @return Returns true if such a window should be behind/interact
524 * with an input method, false if not.
525 */
526 public static boolean mayUseInputMethod(int flags) {
527 switch (flags&(FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
528 case 0:
529 case FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM:
530 return true;
531 }
532 return false;
533 }
534
535 /**
536 * Mask for {@link #softInputMode} of the bits that determine the
537 * desired visibility state of the soft input area for this window.
538 */
539 public static final int SOFT_INPUT_MASK_STATE = 0x0f;
540
541 /**
542 * Visibility state for {@link #softInputMode}: no state has been specified.
543 */
544 public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0;
545
546 /**
547 * Visibility state for {@link #softInputMode}: please don't change the state of
548 * the soft input area.
549 */
550 public static final int SOFT_INPUT_STATE_UNCHANGED = 1;
551
552 /**
553 * Visibility state for {@link #softInputMode}: please hide any soft input
554 * area when normally appropriate (when the user is navigating
555 * forward to your window).
556 */
557 public static final int SOFT_INPUT_STATE_HIDDEN = 2;
558
559 /**
560 * Visibility state for {@link #softInputMode}: please always hide any
561 * soft input area when this window receives focus.
562 */
563 public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3;
564
565 /**
566 * Visibility state for {@link #softInputMode}: please show the soft
567 * input area when normally appropriate (when the user is navigating
568 * forward to your window).
569 */
570 public static final int SOFT_INPUT_STATE_VISIBLE = 4;
571
572 /**
573 * Visibility state for {@link #softInputMode}: please always make the
574 * soft input area visible when this window receives input focus.
575 */
576 public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5;
577
578 /**
579 * Mask for {@link #softInputMode} of the bits that determine the
580 * way that the window should be adjusted to accommodate the soft
581 * input window.
582 */
583 public static final int SOFT_INPUT_MASK_ADJUST = 0xf0;
584
585 /** Adjustment option for {@link #softInputMode}: nothing specified.
586 * The system will try to pick one or
587 * the other depending on the contents of the window.
588 */
589 public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00;
590
591 /** Adjustment option for {@link #softInputMode}: set to allow the
592 * window to be resized when an input
593 * method is shown, so that its contents are not covered by the input
594 * method. This can <em>not<em> be combined with
595 * {@link #SOFT_INPUT_ADJUST_PAN}; if
596 * neither of these are set, then the system will try to pick one or
597 * the other depending on the contents of the window.
598 */
599 public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10;
600
601 /** Adjustment option for {@link #softInputMode}: set to have a window
602 * pan when an input method is
603 * shown, so it doesn't need to deal with resizing but just panned
604 * by the framework to ensure the current input focus is visible. This
605 * can <em>not<em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if
606 * neither of these are set, then the system will try to pick one or
607 * the other depending on the contents of the window.
608 */
609 public static final int SOFT_INPUT_ADJUST_PAN = 0x20;
610
611 /**
612 * Bit for {@link #softInputMode}: set when the user has navigated
613 * forward to the window. This is normally set automatically for
614 * you by the system, though you may want to set it in certain cases
615 * when you are displaying a window yourself. This flag will always
616 * be cleared automatically after the window is displayed.
617 */
618 public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;
619
620 /**
621 * Desired operating mode for any soft input area. May any combination
622 * of:
623 *
624 * <ul>
625 * <li> One of the visibility states
626 * {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED},
627 * {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}, or
628 * {@link #SOFT_INPUT_STATE_VISIBLE}.
629 * <li> One of the adjustment options
630 * {@link #SOFT_INPUT_ADJUST_UNSPECIFIED},
631 * {@link #SOFT_INPUT_ADJUST_RESIZE}, or
632 * {@link #SOFT_INPUT_ADJUST_PAN}.
633 */
634 public int softInputMode;
635
636 /**
637 * Placement of window within the screen as per {@link Gravity}
638 *
639 * @see Gravity
640 */
641 public int gravity;
642
643 /**
644 * The horizontal margin, as a percentage of the container's width,
645 * between the container and the widget.
646 */
647 public float horizontalMargin;
648
649 /**
650 * The vertical margin, as a percentage of the container's height,
651 * between the container and the widget.
652 */
653 public float verticalMargin;
654
655 /**
656 * The desired bitmap format. May be one of the constants in
657 * {@link android.graphics.PixelFormat}. Default is OPAQUE.
658 */
659 public int format;
660
661 /**
662 * A style resource defining the animations to use for this window.
663 * This must be a system resource; it can not be an application resource
664 * because the window manager does not have access to applications.
665 */
666 public int windowAnimations;
667
668 /**
669 * An alpha value to apply to this entire window.
670 * An alpha of 1.0 means fully opaque and 0.0 means fully transparent
671 */
672 public float alpha = 1.0f;
673
674 /**
675 * When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming
676 * to apply. Range is from 1.0 for completely opaque to 0.0 for no
677 * dim.
678 */
679 public float dimAmount = 1.0f;
680
681 /**
682 * This can be used to override the user's preferred brightness of
683 * the screen. A value of less than 0, the default, means to use the
684 * preferred screen brightness. 0 to 1 adjusts the brightness from
685 * dark to full bright.
686 */
687 public float screenBrightness = -1.0f;
688
689 /**
690 * Identifier for this window. This will usually be filled in for
691 * you.
692 */
693 public IBinder token = null;
694
695 /**
696 * Name of the package owning this window.
697 */
698 public String packageName = null;
699
700 /**
701 * Specific orientation value for a window.
702 * May be any of the same values allowed
703 * for {@link android.content.pm.ActivityInfo#screenOrientation}.
704 * If not set, a default value of
705 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}
706 * will be used.
707 */
708 public int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
709
710
711 public LayoutParams() {
712 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
713 type = TYPE_APPLICATION;
714 format = PixelFormat.OPAQUE;
715 }
716
717 public LayoutParams(int _type) {
718 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
719 type = _type;
720 format = PixelFormat.OPAQUE;
721 }
722
723 public LayoutParams(int _type, int _flags) {
724 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
725 type = _type;
726 flags = _flags;
727 format = PixelFormat.OPAQUE;
728 }
729
730 public LayoutParams(int _type, int _flags, int _format) {
731 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
732 type = _type;
733 flags = _flags;
734 format = _format;
735 }
736
737 public LayoutParams(int w, int h, int _type, int _flags, int _format) {
738 super(w, h);
739 type = _type;
740 flags = _flags;
741 format = _format;
742 }
743
744 public LayoutParams(int w, int h, int xpos, int ypos, int _type,
745 int _flags, int _format) {
746 super(w, h);
747 x = xpos;
748 y = ypos;
749 type = _type;
750 flags = _flags;
751 format = _format;
752 }
753
754 public final void setTitle(CharSequence title) {
755 if (null == title)
756 title = "";
757
758 mTitle = TextUtils.stringOrSpannedString(title);
759 }
760
761 public final CharSequence getTitle() {
762 return mTitle;
763 }
764
765 public int describeContents() {
766 return 0;
767 }
768
769 public void writeToParcel(Parcel out, int parcelableFlags) {
770 out.writeInt(width);
771 out.writeInt(height);
772 out.writeInt(x);
773 out.writeInt(y);
774 out.writeInt(type);
775 out.writeInt(memoryType);
776 out.writeInt(flags);
777 out.writeInt(softInputMode);
778 out.writeInt(gravity);
779 out.writeFloat(horizontalMargin);
780 out.writeFloat(verticalMargin);
781 out.writeInt(format);
782 out.writeInt(windowAnimations);
783 out.writeFloat(alpha);
784 out.writeFloat(dimAmount);
785 out.writeFloat(screenBrightness);
786 out.writeStrongBinder(token);
787 out.writeString(packageName);
788 TextUtils.writeToParcel(mTitle, out, parcelableFlags);
789 out.writeInt(screenOrientation);
790 }
791
792 public static final Parcelable.Creator<LayoutParams> CREATOR
793 = new Parcelable.Creator<LayoutParams>() {
794 public LayoutParams createFromParcel(Parcel in) {
795 return new LayoutParams(in);
796 }
797
798 public LayoutParams[] newArray(int size) {
799 return new LayoutParams[size];
800 }
801 };
802
803
804 public LayoutParams(Parcel in) {
805 width = in.readInt();
806 height = in.readInt();
807 x = in.readInt();
808 y = in.readInt();
809 type = in.readInt();
810 memoryType = in.readInt();
811 flags = in.readInt();
812 softInputMode = in.readInt();
813 gravity = in.readInt();
814 horizontalMargin = in.readFloat();
815 verticalMargin = in.readFloat();
816 format = in.readInt();
817 windowAnimations = in.readInt();
818 alpha = in.readFloat();
819 dimAmount = in.readFloat();
820 screenBrightness = in.readFloat();
821 token = in.readStrongBinder();
822 packageName = in.readString();
823 mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
824 screenOrientation = in.readInt();
825 }
826
Romain Guy72998072009-06-22 11:09:20 -0700827 @SuppressWarnings({"PointlessBitwiseExpression"})
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 public static final int LAYOUT_CHANGED = 1<<0;
829 public static final int TYPE_CHANGED = 1<<1;
830 public static final int FLAGS_CHANGED = 1<<2;
831 public static final int FORMAT_CHANGED = 1<<3;
832 public static final int ANIMATION_CHANGED = 1<<4;
833 public static final int DIM_AMOUNT_CHANGED = 1<<5;
834 public static final int TITLE_CHANGED = 1<<6;
835 public static final int ALPHA_CHANGED = 1<<7;
836 public static final int MEMORY_TYPE_CHANGED = 1<<8;
837 public static final int SOFT_INPUT_MODE_CHANGED = 1<<9;
838 public static final int SCREEN_ORIENTATION_CHANGED = 1<<10;
839 public static final int SCREEN_BRIGHTNESS_CHANGED = 1<<11;
840
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -0700841 // internal buffer to backup/restore parameters under compatibility mode.
842 private int[] mCompatibilityParamsBackup = null;
843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 public final int copyFrom(LayoutParams o) {
845 int changes = 0;
846
847 if (width != o.width) {
848 width = o.width;
849 changes |= LAYOUT_CHANGED;
850 }
851 if (height != o.height) {
852 height = o.height;
853 changes |= LAYOUT_CHANGED;
854 }
855 if (x != o.x) {
856 x = o.x;
857 changes |= LAYOUT_CHANGED;
858 }
859 if (y != o.y) {
860 y = o.y;
861 changes |= LAYOUT_CHANGED;
862 }
863 if (horizontalWeight != o.horizontalWeight) {
864 horizontalWeight = o.horizontalWeight;
865 changes |= LAYOUT_CHANGED;
866 }
867 if (verticalWeight != o.verticalWeight) {
868 verticalWeight = o.verticalWeight;
869 changes |= LAYOUT_CHANGED;
870 }
871 if (horizontalMargin != o.horizontalMargin) {
872 horizontalMargin = o.horizontalMargin;
873 changes |= LAYOUT_CHANGED;
874 }
875 if (verticalMargin != o.verticalMargin) {
876 verticalMargin = o.verticalMargin;
877 changes |= LAYOUT_CHANGED;
878 }
879 if (type != o.type) {
880 type = o.type;
881 changes |= TYPE_CHANGED;
882 }
883 if (memoryType != o.memoryType) {
884 memoryType = o.memoryType;
885 changes |= MEMORY_TYPE_CHANGED;
886 }
887 if (flags != o.flags) {
888 flags = o.flags;
889 changes |= FLAGS_CHANGED;
890 }
891 if (softInputMode != o.softInputMode) {
892 softInputMode = o.softInputMode;
893 changes |= SOFT_INPUT_MODE_CHANGED;
894 }
895 if (gravity != o.gravity) {
896 gravity = o.gravity;
897 changes |= LAYOUT_CHANGED;
898 }
899 if (horizontalMargin != o.horizontalMargin) {
900 horizontalMargin = o.horizontalMargin;
901 changes |= LAYOUT_CHANGED;
902 }
903 if (verticalMargin != o.verticalMargin) {
904 verticalMargin = o.verticalMargin;
905 changes |= LAYOUT_CHANGED;
906 }
907 if (format != o.format) {
908 format = o.format;
909 changes |= FORMAT_CHANGED;
910 }
911 if (windowAnimations != o.windowAnimations) {
912 windowAnimations = o.windowAnimations;
913 changes |= ANIMATION_CHANGED;
914 }
915 if (token == null) {
916 // NOTE: token only copied if the recipient doesn't
917 // already have one.
918 token = o.token;
919 }
920 if (packageName == null) {
921 // NOTE: packageName only copied if the recipient doesn't
922 // already have one.
923 packageName = o.packageName;
924 }
925 if (!mTitle.equals(o.mTitle)) {
926 mTitle = o.mTitle;
927 changes |= TITLE_CHANGED;
928 }
929 if (alpha != o.alpha) {
930 alpha = o.alpha;
931 changes |= ALPHA_CHANGED;
932 }
933 if (dimAmount != o.dimAmount) {
934 dimAmount = o.dimAmount;
935 changes |= DIM_AMOUNT_CHANGED;
936 }
937 if (screenBrightness != o.screenBrightness) {
938 screenBrightness = o.screenBrightness;
939 changes |= SCREEN_BRIGHTNESS_CHANGED;
940 }
941
942 if (screenOrientation != o.screenOrientation) {
943 screenOrientation = o.screenOrientation;
944 changes |= SCREEN_ORIENTATION_CHANGED;
945 }
946 return changes;
947 }
948
949 @Override
950 public String debug(String output) {
951 output += "Contents of " + this + ":";
952 Log.d("Debug", output);
953 output = super.debug("");
954 Log.d("Debug", output);
955 Log.d("Debug", "");
956 Log.d("Debug", "WindowManager.LayoutParams={title=" + mTitle + "}");
957 return "";
958 }
959
960 @Override
961 public String toString() {
962 StringBuilder sb = new StringBuilder(256);
963 sb.append("WM.LayoutParams{");
964 sb.append("(");
965 sb.append(x);
966 sb.append(',');
967 sb.append(y);
968 sb.append(")(");
969 sb.append((width==FILL_PARENT?"fill":(width==WRAP_CONTENT?"wrap":width)));
970 sb.append('x');
971 sb.append((height==FILL_PARENT?"fill":(height==WRAP_CONTENT?"wrap":height)));
972 sb.append(")");
973 if (softInputMode != 0) {
974 sb.append(" sim=#");
975 sb.append(Integer.toHexString(softInputMode));
976 }
977 if (gravity != 0) {
978 sb.append(" gr=#");
979 sb.append(Integer.toHexString(gravity));
980 }
981 sb.append(" ty=");
982 sb.append(type);
983 sb.append(" fl=#");
984 sb.append(Integer.toHexString(flags));
985 sb.append(" fmt=");
986 sb.append(format);
987 if (windowAnimations != 0) {
988 sb.append(" wanim=0x");
989 sb.append(Integer.toHexString(windowAnimations));
990 }
991 if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
992 sb.append(" or=");
993 sb.append(screenOrientation);
994 }
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -0700995 if ((flags & FLAG_COMPATIBLE_WINDOW) != 0) {
996 sb.append(" compatible=true");
997 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 sb.append('}');
999 return sb.toString();
1000 }
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001001
Mitsuru Oshima3d914922009-05-13 22:29:15 -07001002 /**
1003 * Scale the layout params' coordinates and size.
Mitsuru Oshima64f59342009-06-21 00:03:11 -07001004 * @hide
Mitsuru Oshima3d914922009-05-13 22:29:15 -07001005 */
Mitsuru Oshima64f59342009-06-21 00:03:11 -07001006 public void scale(float scale) {
Mitsuru Oshima61324e52009-07-21 15:40:36 -07001007 x = (int) (x * scale + 0.5f);
1008 y = (int) (y * scale + 0.5f);
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -07001009 if (width > 0) {
Mitsuru Oshima61324e52009-07-21 15:40:36 -07001010 width = (int) (width * scale + 0.5f);
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -07001011 }
1012 if (height > 0) {
Mitsuru Oshima61324e52009-07-21 15:40:36 -07001013 height = (int) (height * scale + 0.5f);
Mitsuru Oshima8d112672009-04-27 12:01:23 -07001014 }
1015 }
1016
Mitsuru Oshima3d914922009-05-13 22:29:15 -07001017 /**
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -07001018 * Backup the layout parameters used in compatibility mode.
1019 * @see LayoutParams#restore()
Mitsuru Oshima3d914922009-05-13 22:29:15 -07001020 */
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -07001021 void backup() {
1022 int[] backup = mCompatibilityParamsBackup;
1023 if (backup == null) {
Mitsuru Oshima64f59342009-06-21 00:03:11 -07001024 // we backup 4 elements, x, y, width, height
1025 backup = mCompatibilityParamsBackup = new int[4];
Mitsuru Oshima3d914922009-05-13 22:29:15 -07001026 }
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -07001027 backup[0] = x;
1028 backup[1] = y;
1029 backup[2] = width;
1030 backup[3] = height;
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -07001031 }
1032
1033 /**
1034 * Restore the layout params' coordinates, size and gravity
1035 * @see LayoutParams#backup()
1036 */
1037 void restore() {
1038 int[] backup = mCompatibilityParamsBackup;
1039 if (backup != null) {
1040 x = backup[0];
1041 y = backup[1];
1042 width = backup[2];
Mitsuru Oshima3d914922009-05-13 22:29:15 -07001043 height = backup[3];
1044 }
1045 }
1046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 private CharSequence mTitle = "";
1048 }
1049}