blob: 34e65ad3cc0ca11a2b2b7559f7cf1ba271e5951f [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 /**
212 * End of types of sub-windows.
213 */
214 public static final int LAST_SUB_WINDOW = 1999;
215
216 /**
217 * Start of system-specific window types. These are not normally
218 * created by applications.
219 */
220 public static final int FIRST_SYSTEM_WINDOW = 2000;
221
222 /**
223 * Window type: the status bar. There can be only one status bar
224 * window; it is placed at the top of the screen, and all other
225 * windows are shifted down so they are below it.
226 */
227 public static final int TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW;
228
229 /**
230 * Window type: the search bar. There can be only one search bar
231 * window; it is placed at the top of the screen.
232 */
233 public static final int TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW+1;
234
235 /**
236 * Window type: phone. These are non-application windows providing
237 * user interaction with the phone (in particular incoming calls).
238 * These windows are normally placed above all applications, but behind
239 * the status bar.
240 */
241 public static final int TYPE_PHONE = FIRST_SYSTEM_WINDOW+2;
242
243 /**
244 * Window type: system window, such as low power alert. These windows
245 * are always on top of application windows.
246 */
247 public static final int TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3;
248
249 /**
250 * Window type: keyguard window.
251 */
252 public static final int TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW+4;
253
254 /**
255 * Window type: transient notifications.
256 */
257 public static final int TYPE_TOAST = FIRST_SYSTEM_WINDOW+5;
258
259 /**
260 * Window type: system overlay windows, which need to be displayed
261 * on top of everything else. These windows must not take input
262 * focus, or they will interfere with the keyguard.
263 */
264 public static final int TYPE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+6;
265
266 /**
267 * Window type: priority phone UI, which needs to be displayed even if
268 * the keyguard is active. These windows must not take input
269 * focus, or they will interfere with the keyguard.
270 */
271 public static final int TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW+7;
272
273 /**
274 * Window type: panel that slides out from the status bar
275 */
276 public static final int TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW+8;
277
278 /**
279 * Window type: panel that slides out from the status bar
280 */
281 public static final int TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW+8;
282
283 /**
284 * Window type: dialogs that the keyguard shows
285 */
286 public static final int TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW+9;
287
288 /**
289 * Window type: internal system error windows, appear on top of
290 * everything they can.
291 */
292 public static final int TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW+10;
293
294 /**
295 * Window type: internal input methods windows, which appear above
296 * the normal UI. Application windows may be resized or panned to keep
297 * the input focus visible while this window is displayed.
298 */
299 public static final int TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW+11;
300
301 /**
302 * Window type: internal input methods dialog windows, which appear above
303 * the current input method window.
304 */
305 public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12;
306
307 /**
308 * End of types of system windows.
309 */
310 public static final int LAST_SYSTEM_WINDOW = 2999;
311
312 /**
313 * Specifies what type of memory buffers should be used by this window.
314 * Default is normal.
315 *
316 * @see #MEMORY_TYPE_NORMAL
317 * @see #MEMORY_TYPE_HARDWARE
318 * @see #MEMORY_TYPE_GPU
319 * @see #MEMORY_TYPE_PUSH_BUFFERS
320 */
321 public int memoryType;
322
323 /** Memory type: The window's surface is allocated in main memory. */
324 public static final int MEMORY_TYPE_NORMAL = 0;
325 /** Memory type: The window's surface is configured to be accessible
326 * by DMA engines and hardware accelerators. */
327 public static final int MEMORY_TYPE_HARDWARE = 1;
328 /** Memory type: The window's surface is configured to be accessible
329 * by graphics accelerators. */
330 public static final int MEMORY_TYPE_GPU = 2;
331 /** Memory type: The window's surface doesn't own its buffers and
332 * therefore cannot be locked. Instead the buffers are pushed to
333 * it through native binder calls. */
334 public static final int MEMORY_TYPE_PUSH_BUFFERS = 3;
335
336 /**
337 * Various behavioral options/flags. Default is none.
338 *
339 * @see #FLAG_BLUR_BEHIND
340 * @see #FLAG_DIM_BEHIND
341 * @see #FLAG_NOT_FOCUSABLE
342 * @see #FLAG_NOT_TOUCHABLE
343 * @see #FLAG_NOT_TOUCH_MODAL
344 * @see #FLAG_LAYOUT_IN_SCREEN
345 * @see #FLAG_DITHER
346 * @see #FLAG_KEEP_SCREEN_ON
347 * @see #FLAG_FULLSCREEN
348 * @see #FLAG_FORCE_NOT_FULLSCREEN
349 * @see #FLAG_IGNORE_CHEEK_PRESSES
350 */
351 public int flags;
352
353 /** Window flag: everything behind this window will be dimmed.
354 * Use {@link #dimAmount} to control the amount of dim. */
355 public static final int FLAG_DIM_BEHIND = 0x00000002;
356
357 /** Window flag: blur everything behind this window. */
358 public static final int FLAG_BLUR_BEHIND = 0x00000004;
359
360 /** Window flag: this window won't ever get key input focus, so the
361 * user can not send key or other button events to it. Those will
362 * instead go to whatever focusable window is behind it. This flag
363 * will also enable {@link #FLAG_NOT_TOUCH_MODAL} whether or not that
364 * is explicitly set.
365 *
366 * <p>Setting this flag also implies that the window will not need to
367 * interact with
368 * a soft input method, so it will be Z-ordered and positioned
369 * independently of any active input method (typically this means it
370 * gets Z-ordered on top of the input method, so it can use the full
371 * screen for its content and cover the input method if needed. You
372 * can use {@link #FLAG_ALT_FOCUSABLE_IM} to modify this behavior. */
373 public static final int FLAG_NOT_FOCUSABLE = 0x00000008;
374
375 /** Window flag: this window can never receive touch events. */
376 public static final int FLAG_NOT_TOUCHABLE = 0x00000010;
377
378 /** Window flag: Even when this window is focusable (its
379 * {@link #FLAG_NOT_FOCUSABLE is not set), allow any pointer events
380 * outside of the window to be sent to the windows behind it. Otherwise
381 * it will consume all pointer events itself, regardless of whether they
382 * are inside of the window. */
383 public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020;
384
385 /** Window flag: When set, if the device is asleep when the touch
386 * screen is pressed, you will receive this first touch event. Usually
387 * the first touch event is consumed by the system since the user can
388 * not see what they are pressing on.
389 */
390 public static final int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040;
391
392 /** Window flag: as long as this window is visible to the user, keep
393 * the device's screen turned on and bright. */
394 public static final int FLAG_KEEP_SCREEN_ON = 0x00000080;
395
396 /** Window flag: place the window within the entire screen, ignoring
397 * decorations around the border (a.k.a. the status bar). The
398 * window must correctly position its contents to take the screen
399 * decoration into account. This flag is normally set for you
400 * by Window as described in {@link Window#setFlags}. */
401 public static final int FLAG_LAYOUT_IN_SCREEN = 0x00000100;
402
403 /** Window flag: allow window to extend outside of the screen. */
404 public static final int FLAG_LAYOUT_NO_LIMITS = 0x00000200;
405
406 /** Window flag: Hide all screen decorations (e.g. status bar) while
407 * this window is displayed. This allows the window to use the entire
408 * display space for itself -- the status bar will be hidden when
409 * an app window with this flag set is on the top layer. */
410 public static final int FLAG_FULLSCREEN = 0x00000400;
411
412 /** Window flag: Override {@link #FLAG_FULLSCREEN and force the
413 * screen decorations (such as status bar) to be shown. */
414 public static final int FLAG_FORCE_NOT_FULLSCREEN = 0x00000800;
415
416 /** Window flag: turn on dithering when compositing this window to
417 * the screen. */
418 public static final int FLAG_DITHER = 0x00001000;
419
420 /** Window flag: don't allow screen shots while this window is
421 * displayed. */
422 public static final int FLAG_SECURE = 0x00002000;
423
424 /** Window flag: a special mode where the layout parameters are used
425 * to perform scaling of the surface when it is composited to the
426 * screen. */
427 public static final int FLAG_SCALED = 0x00004000;
428
429 /** Window flag: intended for windows that will often be used when the user is
430 * holding the screen against their face, it will aggressively filter the event
431 * stream to prevent unintended presses in this situation that may not be
432 * desired for a particular window, when such an event stream is detected, the
433 * application will receive a CANCEL motion event to indicate this so applications
434 * can handle this accordingly by taking no action on the event
435 * until the finger is released. */
436 public static final int FLAG_IGNORE_CHEEK_PRESSES = 0x00008000;
437
438 /** Window flag: a special option only for use in combination with
439 * {@link #FLAG_LAYOUT_IN_SCREEN}. When requesting layout in the
440 * screen your window may appear on top of or behind screen decorations
441 * such as the status bar. By also including this flag, the window
442 * manager will report the inset rectangle needed to ensure your
443 * content is not covered by screen decorations. This flag is normally
444 * set for you by Window as described in {@link Window#setFlags}.*/
445 public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000;
446
447 /** Window flag: invert the state of {@link #FLAG_NOT_FOCUSABLE} with
448 * respect to how this window interacts with the current method. That
449 * is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the
450 * window will behave as if it needs to interact with the input method
451 * and thus be placed behind/away from it; if FLAG_NOT_FOCUSABLE is
452 * not set and this flag is set, then the window will behave as if it
453 * doesn't need to interact with the input method and can be placed
454 * to use more space and cover the input method.
455 */
456 public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000;
457
458 /** Window flag: if you have set {@link #FLAG_NOT_TOUCH_MODAL}, you
459 * can set this flag to receive a single special MotionEvent with
460 * the action
461 * {@link MotionEvent#ACTION_OUTSIDE MotionEvent.ACTION_OUTSIDE} for
462 * touches that occur outside of your window. Note that you will not
463 * receive the full down/move/up gesture, only the location of the
464 * first down as an ACTION_OUTSIDE.
465 */
466 public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000;
467
468 /** Window flag: a special option intended for system dialogs. When
469 * this flag is set, the window will demand focus unconditionally when
470 * it is created.
471 * {@hide} */
472 public static final int FLAG_SYSTEM_ERROR = 0x40000000;
473
474 /**
475 * Given a particular set of window manager flags, determine whether
476 * such a window may be a target for an input method when it has
477 * focus. In particular, this checks the
478 * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM}
479 * flags and returns true if the combination of the two corresponds
480 * to a window that needs to be behind the input method so that the
481 * user can type into it.
482 *
483 * @param flags The current window manager flags.
484 *
485 * @return Returns true if such a window should be behind/interact
486 * with an input method, false if not.
487 */
488 public static boolean mayUseInputMethod(int flags) {
489 switch (flags&(FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
490 case 0:
491 case FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM:
492 return true;
493 }
494 return false;
495 }
496
497 /**
498 * Mask for {@link #softInputMode} of the bits that determine the
499 * desired visibility state of the soft input area for this window.
500 */
501 public static final int SOFT_INPUT_MASK_STATE = 0x0f;
502
503 /**
504 * Visibility state for {@link #softInputMode}: no state has been specified.
505 */
506 public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0;
507
508 /**
509 * Visibility state for {@link #softInputMode}: please don't change the state of
510 * the soft input area.
511 */
512 public static final int SOFT_INPUT_STATE_UNCHANGED = 1;
513
514 /**
515 * Visibility state for {@link #softInputMode}: please hide any soft input
516 * area when normally appropriate (when the user is navigating
517 * forward to your window).
518 */
519 public static final int SOFT_INPUT_STATE_HIDDEN = 2;
520
521 /**
522 * Visibility state for {@link #softInputMode}: please always hide any
523 * soft input area when this window receives focus.
524 */
525 public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3;
526
527 /**
528 * Visibility state for {@link #softInputMode}: please show the soft
529 * input area when normally appropriate (when the user is navigating
530 * forward to your window).
531 */
532 public static final int SOFT_INPUT_STATE_VISIBLE = 4;
533
534 /**
535 * Visibility state for {@link #softInputMode}: please always make the
536 * soft input area visible when this window receives input focus.
537 */
538 public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5;
539
540 /**
541 * Mask for {@link #softInputMode} of the bits that determine the
542 * way that the window should be adjusted to accommodate the soft
543 * input window.
544 */
545 public static final int SOFT_INPUT_MASK_ADJUST = 0xf0;
546
547 /** Adjustment option for {@link #softInputMode}: nothing specified.
548 * The system will try to pick one or
549 * the other depending on the contents of the window.
550 */
551 public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00;
552
553 /** Adjustment option for {@link #softInputMode}: set to allow the
554 * window to be resized when an input
555 * method is shown, so that its contents are not covered by the input
556 * method. This can <em>not<em> be combined with
557 * {@link #SOFT_INPUT_ADJUST_PAN}; if
558 * neither of these are set, then the system will try to pick one or
559 * the other depending on the contents of the window.
560 */
561 public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10;
562
563 /** Adjustment option for {@link #softInputMode}: set to have a window
564 * pan when an input method is
565 * shown, so it doesn't need to deal with resizing but just panned
566 * by the framework to ensure the current input focus is visible. This
567 * can <em>not<em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if
568 * neither of these are set, then the system will try to pick one or
569 * the other depending on the contents of the window.
570 */
571 public static final int SOFT_INPUT_ADJUST_PAN = 0x20;
572
573 /**
574 * Bit for {@link #softInputMode}: set when the user has navigated
575 * forward to the window. This is normally set automatically for
576 * you by the system, though you may want to set it in certain cases
577 * when you are displaying a window yourself. This flag will always
578 * be cleared automatically after the window is displayed.
579 */
580 public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;
581
582 /**
583 * Desired operating mode for any soft input area. May any combination
584 * of:
585 *
586 * <ul>
587 * <li> One of the visibility states
588 * {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED},
589 * {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}, or
590 * {@link #SOFT_INPUT_STATE_VISIBLE}.
591 * <li> One of the adjustment options
592 * {@link #SOFT_INPUT_ADJUST_UNSPECIFIED},
593 * {@link #SOFT_INPUT_ADJUST_RESIZE}, or
594 * {@link #SOFT_INPUT_ADJUST_PAN}.
595 */
596 public int softInputMode;
597
598 /**
599 * Placement of window within the screen as per {@link Gravity}
600 *
601 * @see Gravity
602 */
603 public int gravity;
604
605 /**
606 * The horizontal margin, as a percentage of the container's width,
607 * between the container and the widget.
608 */
609 public float horizontalMargin;
610
611 /**
612 * The vertical margin, as a percentage of the container's height,
613 * between the container and the widget.
614 */
615 public float verticalMargin;
616
617 /**
618 * The desired bitmap format. May be one of the constants in
619 * {@link android.graphics.PixelFormat}. Default is OPAQUE.
620 */
621 public int format;
622
623 /**
624 * A style resource defining the animations to use for this window.
625 * This must be a system resource; it can not be an application resource
626 * because the window manager does not have access to applications.
627 */
628 public int windowAnimations;
629
630 /**
631 * An alpha value to apply to this entire window.
632 * An alpha of 1.0 means fully opaque and 0.0 means fully transparent
633 */
634 public float alpha = 1.0f;
635
636 /**
637 * When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming
638 * to apply. Range is from 1.0 for completely opaque to 0.0 for no
639 * dim.
640 */
641 public float dimAmount = 1.0f;
642
643 /**
644 * This can be used to override the user's preferred brightness of
645 * the screen. A value of less than 0, the default, means to use the
646 * preferred screen brightness. 0 to 1 adjusts the brightness from
647 * dark to full bright.
648 */
649 public float screenBrightness = -1.0f;
650
651 /**
652 * Identifier for this window. This will usually be filled in for
653 * you.
654 */
655 public IBinder token = null;
656
657 /**
658 * Name of the package owning this window.
659 */
660 public String packageName = null;
661
662 /**
663 * Specific orientation value for a window.
664 * May be any of the same values allowed
665 * for {@link android.content.pm.ActivityInfo#screenOrientation}.
666 * If not set, a default value of
667 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}
668 * will be used.
669 */
670 public int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
671
672
673 public LayoutParams() {
674 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
675 type = TYPE_APPLICATION;
676 format = PixelFormat.OPAQUE;
677 }
678
679 public LayoutParams(int _type) {
680 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
681 type = _type;
682 format = PixelFormat.OPAQUE;
683 }
684
685 public LayoutParams(int _type, int _flags) {
686 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
687 type = _type;
688 flags = _flags;
689 format = PixelFormat.OPAQUE;
690 }
691
692 public LayoutParams(int _type, int _flags, int _format) {
693 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
694 type = _type;
695 flags = _flags;
696 format = _format;
697 }
698
699 public LayoutParams(int w, int h, int _type, int _flags, int _format) {
700 super(w, h);
701 type = _type;
702 flags = _flags;
703 format = _format;
704 }
705
706 public LayoutParams(int w, int h, int xpos, int ypos, int _type,
707 int _flags, int _format) {
708 super(w, h);
709 x = xpos;
710 y = ypos;
711 type = _type;
712 flags = _flags;
713 format = _format;
714 }
715
716 public final void setTitle(CharSequence title) {
717 if (null == title)
718 title = "";
719
720 mTitle = TextUtils.stringOrSpannedString(title);
721 }
722
723 public final CharSequence getTitle() {
724 return mTitle;
725 }
726
727 public int describeContents() {
728 return 0;
729 }
730
731 public void writeToParcel(Parcel out, int parcelableFlags) {
732 out.writeInt(width);
733 out.writeInt(height);
734 out.writeInt(x);
735 out.writeInt(y);
736 out.writeInt(type);
737 out.writeInt(memoryType);
738 out.writeInt(flags);
739 out.writeInt(softInputMode);
740 out.writeInt(gravity);
741 out.writeFloat(horizontalMargin);
742 out.writeFloat(verticalMargin);
743 out.writeInt(format);
744 out.writeInt(windowAnimations);
745 out.writeFloat(alpha);
746 out.writeFloat(dimAmount);
747 out.writeFloat(screenBrightness);
748 out.writeStrongBinder(token);
749 out.writeString(packageName);
750 TextUtils.writeToParcel(mTitle, out, parcelableFlags);
751 out.writeInt(screenOrientation);
752 }
753
754 public static final Parcelable.Creator<LayoutParams> CREATOR
755 = new Parcelable.Creator<LayoutParams>() {
756 public LayoutParams createFromParcel(Parcel in) {
757 return new LayoutParams(in);
758 }
759
760 public LayoutParams[] newArray(int size) {
761 return new LayoutParams[size];
762 }
763 };
764
765
766 public LayoutParams(Parcel in) {
767 width = in.readInt();
768 height = in.readInt();
769 x = in.readInt();
770 y = in.readInt();
771 type = in.readInt();
772 memoryType = in.readInt();
773 flags = in.readInt();
774 softInputMode = in.readInt();
775 gravity = in.readInt();
776 horizontalMargin = in.readFloat();
777 verticalMargin = in.readFloat();
778 format = in.readInt();
779 windowAnimations = in.readInt();
780 alpha = in.readFloat();
781 dimAmount = in.readFloat();
782 screenBrightness = in.readFloat();
783 token = in.readStrongBinder();
784 packageName = in.readString();
785 mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
786 screenOrientation = in.readInt();
787 }
788
789 public static final int LAYOUT_CHANGED = 1<<0;
790 public static final int TYPE_CHANGED = 1<<1;
791 public static final int FLAGS_CHANGED = 1<<2;
792 public static final int FORMAT_CHANGED = 1<<3;
793 public static final int ANIMATION_CHANGED = 1<<4;
794 public static final int DIM_AMOUNT_CHANGED = 1<<5;
795 public static final int TITLE_CHANGED = 1<<6;
796 public static final int ALPHA_CHANGED = 1<<7;
797 public static final int MEMORY_TYPE_CHANGED = 1<<8;
798 public static final int SOFT_INPUT_MODE_CHANGED = 1<<9;
799 public static final int SCREEN_ORIENTATION_CHANGED = 1<<10;
800 public static final int SCREEN_BRIGHTNESS_CHANGED = 1<<11;
801
802 public final int copyFrom(LayoutParams o) {
803 int changes = 0;
804
805 if (width != o.width) {
806 width = o.width;
807 changes |= LAYOUT_CHANGED;
808 }
809 if (height != o.height) {
810 height = o.height;
811 changes |= LAYOUT_CHANGED;
812 }
813 if (x != o.x) {
814 x = o.x;
815 changes |= LAYOUT_CHANGED;
816 }
817 if (y != o.y) {
818 y = o.y;
819 changes |= LAYOUT_CHANGED;
820 }
821 if (horizontalWeight != o.horizontalWeight) {
822 horizontalWeight = o.horizontalWeight;
823 changes |= LAYOUT_CHANGED;
824 }
825 if (verticalWeight != o.verticalWeight) {
826 verticalWeight = o.verticalWeight;
827 changes |= LAYOUT_CHANGED;
828 }
829 if (horizontalMargin != o.horizontalMargin) {
830 horizontalMargin = o.horizontalMargin;
831 changes |= LAYOUT_CHANGED;
832 }
833 if (verticalMargin != o.verticalMargin) {
834 verticalMargin = o.verticalMargin;
835 changes |= LAYOUT_CHANGED;
836 }
837 if (type != o.type) {
838 type = o.type;
839 changes |= TYPE_CHANGED;
840 }
841 if (memoryType != o.memoryType) {
842 memoryType = o.memoryType;
843 changes |= MEMORY_TYPE_CHANGED;
844 }
845 if (flags != o.flags) {
846 flags = o.flags;
847 changes |= FLAGS_CHANGED;
848 }
849 if (softInputMode != o.softInputMode) {
850 softInputMode = o.softInputMode;
851 changes |= SOFT_INPUT_MODE_CHANGED;
852 }
853 if (gravity != o.gravity) {
854 gravity = o.gravity;
855 changes |= LAYOUT_CHANGED;
856 }
857 if (horizontalMargin != o.horizontalMargin) {
858 horizontalMargin = o.horizontalMargin;
859 changes |= LAYOUT_CHANGED;
860 }
861 if (verticalMargin != o.verticalMargin) {
862 verticalMargin = o.verticalMargin;
863 changes |= LAYOUT_CHANGED;
864 }
865 if (format != o.format) {
866 format = o.format;
867 changes |= FORMAT_CHANGED;
868 }
869 if (windowAnimations != o.windowAnimations) {
870 windowAnimations = o.windowAnimations;
871 changes |= ANIMATION_CHANGED;
872 }
873 if (token == null) {
874 // NOTE: token only copied if the recipient doesn't
875 // already have one.
876 token = o.token;
877 }
878 if (packageName == null) {
879 // NOTE: packageName only copied if the recipient doesn't
880 // already have one.
881 packageName = o.packageName;
882 }
883 if (!mTitle.equals(o.mTitle)) {
884 mTitle = o.mTitle;
885 changes |= TITLE_CHANGED;
886 }
887 if (alpha != o.alpha) {
888 alpha = o.alpha;
889 changes |= ALPHA_CHANGED;
890 }
891 if (dimAmount != o.dimAmount) {
892 dimAmount = o.dimAmount;
893 changes |= DIM_AMOUNT_CHANGED;
894 }
895 if (screenBrightness != o.screenBrightness) {
896 screenBrightness = o.screenBrightness;
897 changes |= SCREEN_BRIGHTNESS_CHANGED;
898 }
899
900 if (screenOrientation != o.screenOrientation) {
901 screenOrientation = o.screenOrientation;
902 changes |= SCREEN_ORIENTATION_CHANGED;
903 }
904 return changes;
905 }
906
907 @Override
908 public String debug(String output) {
909 output += "Contents of " + this + ":";
910 Log.d("Debug", output);
911 output = super.debug("");
912 Log.d("Debug", output);
913 Log.d("Debug", "");
914 Log.d("Debug", "WindowManager.LayoutParams={title=" + mTitle + "}");
915 return "";
916 }
917
918 @Override
919 public String toString() {
920 StringBuilder sb = new StringBuilder(256);
921 sb.append("WM.LayoutParams{");
922 sb.append("(");
923 sb.append(x);
924 sb.append(',');
925 sb.append(y);
926 sb.append(")(");
927 sb.append((width==FILL_PARENT?"fill":(width==WRAP_CONTENT?"wrap":width)));
928 sb.append('x');
929 sb.append((height==FILL_PARENT?"fill":(height==WRAP_CONTENT?"wrap":height)));
930 sb.append(")");
931 if (softInputMode != 0) {
932 sb.append(" sim=#");
933 sb.append(Integer.toHexString(softInputMode));
934 }
935 if (gravity != 0) {
936 sb.append(" gr=#");
937 sb.append(Integer.toHexString(gravity));
938 }
939 sb.append(" ty=");
940 sb.append(type);
941 sb.append(" fl=#");
942 sb.append(Integer.toHexString(flags));
943 sb.append(" fmt=");
944 sb.append(format);
945 if (windowAnimations != 0) {
946 sb.append(" wanim=0x");
947 sb.append(Integer.toHexString(windowAnimations));
948 }
949 if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
950 sb.append(" or=");
951 sb.append(screenOrientation);
952 }
953 sb.append('}');
954 return sb.toString();
955 }
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700956
957 void scaleUp(float scale) {
958 if (scale != 1.0f) {
959 x *= scale;
960 y *= scale;
961 if (width > 0) {
962 width *= scale;
963 }
964 if (height > 0) {
965 height *= scale;
966 }
967 }
968 }
969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 private CharSequence mTitle = "";
971 }
972}