WindowManager.java revision e898ac59db04d8ab0762180ca8ec7cea1347aa09
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
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    /**
69     * Return true if this window manager is configured to request hardware
70     * accelerated windows.  This does <em>not</em> guarantee that they will
71     * actually be accelerated, since that depends on the device supporting them.
72     * @hide
73     */
74    public boolean isHardwareAccelerated();
75
76    public static class LayoutParams extends ViewGroup.LayoutParams
77            implements Parcelable {
78        /**
79         * X position for this window.  With the default gravity it is ignored.
80         * When using {@link Gravity#LEFT} or {@link Gravity#START} or {@link Gravity#RIGHT} or
81         * {@link Gravity#END} it provides an offset from the given edge.
82         */
83        @ViewDebug.ExportedProperty
84        public int x;
85
86        /**
87         * Y position for this window.  With the default gravity it is ignored.
88         * When using {@link Gravity#TOP} or {@link Gravity#BOTTOM} it provides
89         * an offset from the given edge.
90         */
91        @ViewDebug.ExportedProperty
92        public int y;
93
94        /**
95         * Indicates how much of the extra space will be allocated horizontally
96         * to the view associated with these LayoutParams. Specify 0 if the view
97         * should not be stretched. Otherwise the extra pixels will be pro-rated
98         * among all views whose weight is greater than 0.
99         */
100        @ViewDebug.ExportedProperty
101        public float horizontalWeight;
102
103        /**
104         * Indicates how much of the extra space will be allocated vertically
105         * to the view associated with these LayoutParams. Specify 0 if the view
106         * should not be stretched. Otherwise the extra pixels will be pro-rated
107         * among all views whose weight is greater than 0.
108         */
109        @ViewDebug.ExportedProperty
110        public float verticalWeight;
111
112        /**
113         * The general type of window.  There are three main classes of
114         * window types:
115         * <ul>
116         * <li> <strong>Application windows</strong> (ranging from
117         * {@link #FIRST_APPLICATION_WINDOW} to
118         * {@link #LAST_APPLICATION_WINDOW}) are normal top-level application
119         * windows.  For these types of windows, the {@link #token} must be
120         * set to the token of the activity they are a part of (this will
121         * normally be done for you if {@link #token} is null).
122         * <li> <strong>Sub-windows</strong> (ranging from
123         * {@link #FIRST_SUB_WINDOW} to
124         * {@link #LAST_SUB_WINDOW}) are associated with another top-level
125         * window.  For these types of windows, the {@link #token} must be
126         * the token of the window it is attached to.
127         * <li> <strong>System windows</strong> (ranging from
128         * {@link #FIRST_SYSTEM_WINDOW} to
129         * {@link #LAST_SYSTEM_WINDOW}) are special types of windows for
130         * use by the system for specific purposes.  They should not normally
131         * be used by applications, and a special permission is required
132         * to use them.
133         * </ul>
134         *
135         * @see #TYPE_BASE_APPLICATION
136         * @see #TYPE_APPLICATION
137         * @see #TYPE_APPLICATION_STARTING
138         * @see #TYPE_APPLICATION_PANEL
139         * @see #TYPE_APPLICATION_MEDIA
140         * @see #TYPE_APPLICATION_SUB_PANEL
141         * @see #TYPE_APPLICATION_ATTACHED_DIALOG
142         * @see #TYPE_STATUS_BAR
143         * @see #TYPE_SEARCH_BAR
144         * @see #TYPE_PHONE
145         * @see #TYPE_SYSTEM_ALERT
146         * @see #TYPE_KEYGUARD
147         * @see #TYPE_TOAST
148         * @see #TYPE_SYSTEM_OVERLAY
149         * @see #TYPE_PRIORITY_PHONE
150         * @see #TYPE_STATUS_BAR_PANEL
151         * @see #TYPE_SYSTEM_DIALOG
152         * @see #TYPE_KEYGUARD_DIALOG
153         * @see #TYPE_SYSTEM_ERROR
154         * @see #TYPE_INPUT_METHOD
155         * @see #TYPE_INPUT_METHOD_DIALOG
156         */
157        @ViewDebug.ExportedProperty(mapping = {
158            @ViewDebug.IntToString(from = TYPE_BASE_APPLICATION, to = "TYPE_BASE_APPLICATION"),
159            @ViewDebug.IntToString(from = TYPE_APPLICATION, to = "TYPE_APPLICATION"),
160            @ViewDebug.IntToString(from = TYPE_APPLICATION_STARTING, to = "TYPE_APPLICATION_STARTING"),
161            @ViewDebug.IntToString(from = TYPE_APPLICATION_PANEL, to = "TYPE_APPLICATION_PANEL"),
162            @ViewDebug.IntToString(from = TYPE_APPLICATION_MEDIA, to = "TYPE_APPLICATION_MEDIA"),
163            @ViewDebug.IntToString(from = TYPE_APPLICATION_SUB_PANEL, to = "TYPE_APPLICATION_SUB_PANEL"),
164            @ViewDebug.IntToString(from = TYPE_APPLICATION_ATTACHED_DIALOG, to = "TYPE_APPLICATION_ATTACHED_DIALOG"),
165            @ViewDebug.IntToString(from = TYPE_STATUS_BAR, to = "TYPE_STATUS_BAR"),
166            @ViewDebug.IntToString(from = TYPE_SEARCH_BAR, to = "TYPE_SEARCH_BAR"),
167            @ViewDebug.IntToString(from = TYPE_PHONE, to = "TYPE_PHONE"),
168            @ViewDebug.IntToString(from = TYPE_SYSTEM_ALERT, to = "TYPE_SYSTEM_ALERT"),
169            @ViewDebug.IntToString(from = TYPE_KEYGUARD, to = "TYPE_KEYGUARD"),
170            @ViewDebug.IntToString(from = TYPE_TOAST, to = "TYPE_TOAST"),
171            @ViewDebug.IntToString(from = TYPE_SYSTEM_OVERLAY, to = "TYPE_SYSTEM_OVERLAY"),
172            @ViewDebug.IntToString(from = TYPE_PRIORITY_PHONE, to = "TYPE_PRIORITY_PHONE"),
173            @ViewDebug.IntToString(from = TYPE_STATUS_BAR_PANEL, to = "TYPE_STATUS_BAR_PANEL"),
174            @ViewDebug.IntToString(from = TYPE_STATUS_BAR_SUB_PANEL, to = "TYPE_STATUS_BAR_SUB_PANEL"),
175            @ViewDebug.IntToString(from = TYPE_SYSTEM_DIALOG, to = "TYPE_SYSTEM_DIALOG"),
176            @ViewDebug.IntToString(from = TYPE_KEYGUARD_DIALOG, to = "TYPE_KEYGUARD_DIALOG"),
177            @ViewDebug.IntToString(from = TYPE_SYSTEM_ERROR, to = "TYPE_SYSTEM_ERROR"),
178            @ViewDebug.IntToString(from = TYPE_INPUT_METHOD, to = "TYPE_INPUT_METHOD"),
179            @ViewDebug.IntToString(from = TYPE_INPUT_METHOD_DIALOG, to = "TYPE_INPUT_METHOD_DIALOG"),
180            @ViewDebug.IntToString(from = TYPE_WALLPAPER, to = "TYPE_WALLPAPER"),
181            @ViewDebug.IntToString(from = TYPE_STATUS_BAR_PANEL, to = "TYPE_STATUS_BAR_PANEL"),
182            @ViewDebug.IntToString(from = TYPE_SECURE_SYSTEM_OVERLAY, to = "TYPE_SECURE_SYSTEM_OVERLAY"),
183            @ViewDebug.IntToString(from = TYPE_DRAG, to = "TYPE_DRAG"),
184            @ViewDebug.IntToString(from = TYPE_STATUS_BAR_SUB_PANEL, to = "TYPE_STATUS_BAR_SUB_PANEL"),
185            @ViewDebug.IntToString(from = TYPE_POINTER, to = "TYPE_POINTER"),
186            @ViewDebug.IntToString(from = TYPE_NAVIGATION_BAR, to = "TYPE_NAVIGATION_BAR"),
187            @ViewDebug.IntToString(from = TYPE_VOLUME_OVERLAY, to = "TYPE_VOLUME_OVERLAY"),
188            @ViewDebug.IntToString(from = TYPE_BOOT_PROGRESS, to = "TYPE_BOOT_PROGRESS")
189        })
190        public int type;
191
192        /**
193         * Start of window types that represent normal application windows.
194         */
195        public static final int FIRST_APPLICATION_WINDOW = 1;
196
197        /**
198         * Window type: an application window that serves as the "base" window
199         * of the overall application; all other application windows will
200         * appear on top of it.
201         */
202        public static final int TYPE_BASE_APPLICATION   = 1;
203
204        /**
205         * Window type: a normal application window.  The {@link #token} must be
206         * an Activity token identifying who the window belongs to.
207         */
208        public static final int TYPE_APPLICATION        = 2;
209
210        /**
211         * Window type: special application window that is displayed while the
212         * application is starting.  Not for use by applications themselves;
213         * this is used by the system to display something until the
214         * application can show its own windows.
215         */
216        public static final int TYPE_APPLICATION_STARTING = 3;
217
218        /**
219         * End of types of application windows.
220         */
221        public static final int LAST_APPLICATION_WINDOW = 99;
222
223        /**
224         * Start of types of sub-windows.  The {@link #token} of these windows
225         * must be set to the window they are attached to.  These types of
226         * windows are kept next to their attached window in Z-order, and their
227         * coordinate space is relative to their attached window.
228         */
229        public static final int FIRST_SUB_WINDOW        = 1000;
230
231        /**
232         * Window type: a panel on top of an application window.  These windows
233         * appear on top of their attached window.
234         */
235        public static final int TYPE_APPLICATION_PANEL  = FIRST_SUB_WINDOW;
236
237        /**
238         * Window type: window for showing media (e.g. video).  These windows
239         * are displayed behind their attached window.
240         */
241        public static final int TYPE_APPLICATION_MEDIA  = FIRST_SUB_WINDOW+1;
242
243        /**
244         * Window type: a sub-panel on top of an application window.  These
245         * windows are displayed on top their attached window and any
246         * {@link #TYPE_APPLICATION_PANEL} panels.
247         */
248        public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2;
249
250        /** Window type: like {@link #TYPE_APPLICATION_PANEL}, but layout
251         * of the window happens as that of a top-level window, <em>not</em>
252         * as a child of its container.
253         */
254        public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3;
255
256        /**
257         * Window type: window for showing overlays on top of media windows.
258         * These windows are displayed between TYPE_APPLICATION_MEDIA and the
259         * application window.  They should be translucent to be useful.  This
260         * is a big ugly hack so:
261         * @hide
262         */
263        public static final int TYPE_APPLICATION_MEDIA_OVERLAY  = FIRST_SUB_WINDOW+4;
264
265        /**
266         * End of types of sub-windows.
267         */
268        public static final int LAST_SUB_WINDOW         = 1999;
269
270        /**
271         * Start of system-specific window types.  These are not normally
272         * created by applications.
273         */
274        public static final int FIRST_SYSTEM_WINDOW     = 2000;
275
276        /**
277         * Window type: the status bar.  There can be only one status bar
278         * window; it is placed at the top of the screen, and all other
279         * windows are shifted down so they are below it.
280         */
281        public static final int TYPE_STATUS_BAR         = FIRST_SYSTEM_WINDOW;
282
283        /**
284         * Window type: the search bar.  There can be only one search bar
285         * window; it is placed at the top of the screen.
286         */
287        public static final int TYPE_SEARCH_BAR         = FIRST_SYSTEM_WINDOW+1;
288
289        /**
290         * Window type: phone.  These are non-application windows providing
291         * user interaction with the phone (in particular incoming calls).
292         * These windows are normally placed above all applications, but behind
293         * the status bar.
294         */
295        public static final int TYPE_PHONE              = FIRST_SYSTEM_WINDOW+2;
296
297        /**
298         * Window type: system window, such as low power alert. These windows
299         * are always on top of application windows.
300         */
301        public static final int TYPE_SYSTEM_ALERT       = FIRST_SYSTEM_WINDOW+3;
302
303        /**
304         * Window type: keyguard window.
305         */
306        public static final int TYPE_KEYGUARD           = FIRST_SYSTEM_WINDOW+4;
307
308        /**
309         * Window type: transient notifications.
310         */
311        public static final int TYPE_TOAST              = FIRST_SYSTEM_WINDOW+5;
312
313        /**
314         * Window type: system overlay windows, which need to be displayed
315         * on top of everything else.  These windows must not take input
316         * focus, or they will interfere with the keyguard.
317         */
318        public static final int TYPE_SYSTEM_OVERLAY     = FIRST_SYSTEM_WINDOW+6;
319
320        /**
321         * Window type: priority phone UI, which needs to be displayed even if
322         * the keyguard is active.  These windows must not take input
323         * focus, or they will interfere with the keyguard.
324         */
325        public static final int TYPE_PRIORITY_PHONE     = FIRST_SYSTEM_WINDOW+7;
326
327        /**
328         * Window type: panel that slides out from the status bar
329         */
330        public static final int TYPE_SYSTEM_DIALOG      = FIRST_SYSTEM_WINDOW+8;
331
332        /**
333         * Window type: dialogs that the keyguard shows
334         */
335        public static final int TYPE_KEYGUARD_DIALOG    = FIRST_SYSTEM_WINDOW+9;
336
337        /**
338         * Window type: internal system error windows, appear on top of
339         * everything they can.
340         */
341        public static final int TYPE_SYSTEM_ERROR       = FIRST_SYSTEM_WINDOW+10;
342
343        /**
344         * Window type: internal input methods windows, which appear above
345         * the normal UI.  Application windows may be resized or panned to keep
346         * the input focus visible while this window is displayed.
347         */
348        public static final int TYPE_INPUT_METHOD       = FIRST_SYSTEM_WINDOW+11;
349
350        /**
351         * Window type: internal input methods dialog windows, which appear above
352         * the current input method window.
353         */
354        public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12;
355
356        /**
357         * Window type: wallpaper window, placed behind any window that wants
358         * to sit on top of the wallpaper.
359         */
360        public static final int TYPE_WALLPAPER          = FIRST_SYSTEM_WINDOW+13;
361
362        /**
363         * Window type: panel that slides out from over the status bar
364         */
365        public static final int TYPE_STATUS_BAR_PANEL   = FIRST_SYSTEM_WINDOW+14;
366
367        /**
368         * Window type: secure system overlay windows, which need to be displayed
369         * on top of everything else.  These windows must not take input
370         * focus, or they will interfere with the keyguard.
371         *
372         * This is exactly like {@link #TYPE_SYSTEM_OVERLAY} except that only the
373         * system itself is allowed to create these overlays.  Applications cannot
374         * obtain permission to create secure system overlays.
375         * @hide
376         */
377        public static final int TYPE_SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+15;
378
379        /**
380         * Window type: the drag-and-drop pseudowindow.  There is only one
381         * drag layer (at most), and it is placed on top of all other windows.
382         * @hide
383         */
384        public static final int TYPE_DRAG               = FIRST_SYSTEM_WINDOW+16;
385
386        /**
387         * Window type: panel that slides out from under the status bar
388         * @hide
389         */
390        public static final int TYPE_STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW+17;
391
392        /**
393         * Window type: (mouse) pointer
394         * @hide
395         */
396        public static final int TYPE_POINTER = FIRST_SYSTEM_WINDOW+18;
397
398        /**
399         * Window type: Navigation bar (when distinct from status bar)
400         * @hide
401         */
402        public static final int TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19;
403
404        /**
405         * Window type: The volume level overlay/dialog shown when the user
406         * changes the system volume.
407         * @hide
408         */
409        public static final int TYPE_VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW+20;
410
411        /**
412         * Window type: The boot progress dialog, goes on top of everything
413         * in the world.
414         * @hide
415         */
416        public static final int TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21;
417
418        /**
419         * Window type: Fake window to consume touch events when the navigation
420         * bar is hidden.
421         * @hide
422         */
423        public static final int TYPE_HIDDEN_NAV_CONSUMER = FIRST_SYSTEM_WINDOW+22;
424
425        /**
426         * Window type: Dreams (screen saver) window, just above keyguard.
427         * @hide
428         */
429        public static final int TYPE_DREAM = FIRST_SYSTEM_WINDOW+23;
430
431        /**
432         * Window type: Navigation bar panel (when navigation bar is distinct from status bar)
433         * @hide
434         */
435        public static final int TYPE_NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW+24;
436
437        /**
438         * End of types of system windows.
439         */
440        public static final int LAST_SYSTEM_WINDOW      = 2999;
441
442        /** @deprecated this is ignored, this value is set automatically when needed. */
443        @Deprecated
444        public static final int MEMORY_TYPE_NORMAL = 0;
445        /** @deprecated this is ignored, this value is set automatically when needed. */
446        @Deprecated
447        public static final int MEMORY_TYPE_HARDWARE = 1;
448        /** @deprecated this is ignored, this value is set automatically when needed. */
449        @Deprecated
450        public static final int MEMORY_TYPE_GPU = 2;
451        /** @deprecated this is ignored, this value is set automatically when needed. */
452        @Deprecated
453        public static final int MEMORY_TYPE_PUSH_BUFFERS = 3;
454
455        /**
456         * @deprecated this is ignored
457         */
458        @Deprecated
459        public int memoryType;
460
461        /** Window flag: as long as this window is visible to the user, allow
462         *  the lock screen to activate while the screen is on.
463         *  This can be used independently, or in combination with
464         *  {@link #FLAG_KEEP_SCREEN_ON} and/or {@link #FLAG_SHOW_WHEN_LOCKED} */
465        public static final int FLAG_ALLOW_LOCK_WHILE_SCREEN_ON     = 0x00000001;
466
467        /** Window flag: everything behind this window will be dimmed.
468         *  Use {@link #dimAmount} to control the amount of dim. */
469        public static final int FLAG_DIM_BEHIND        = 0x00000002;
470
471        /** Window flag: blur everything behind this window.
472         * @deprecated Blurring is no longer supported. */
473        @Deprecated
474        public static final int FLAG_BLUR_BEHIND        = 0x00000004;
475
476        /** Window flag: this window won't ever get key input focus, so the
477         * user can not send key or other button events to it.  Those will
478         * instead go to whatever focusable window is behind it.  This flag
479         * will also enable {@link #FLAG_NOT_TOUCH_MODAL} whether or not that
480         * is explicitly set.
481         *
482         * <p>Setting this flag also implies that the window will not need to
483         * interact with
484         * a soft input method, so it will be Z-ordered and positioned
485         * independently of any active input method (typically this means it
486         * gets Z-ordered on top of the input method, so it can use the full
487         * screen for its content and cover the input method if needed.  You
488         * can use {@link #FLAG_ALT_FOCUSABLE_IM} to modify this behavior. */
489        public static final int FLAG_NOT_FOCUSABLE      = 0x00000008;
490
491        /** Window flag: this window can never receive touch events. */
492        public static final int FLAG_NOT_TOUCHABLE      = 0x00000010;
493
494        /** Window flag: Even when this window is focusable (its
495         * {@link #FLAG_NOT_FOCUSABLE is not set), allow any pointer events
496         * outside of the window to be sent to the windows behind it.  Otherwise
497         * it will consume all pointer events itself, regardless of whether they
498         * are inside of the window. */
499        public static final int FLAG_NOT_TOUCH_MODAL    = 0x00000020;
500
501        /** Window flag: When set, if the device is asleep when the touch
502         * screen is pressed, you will receive this first touch event.  Usually
503         * the first touch event is consumed by the system since the user can
504         * not see what they are pressing on.
505         */
506        public static final int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040;
507
508        /** Window flag: as long as this window is visible to the user, keep
509         *  the device's screen turned on and bright. */
510        public static final int FLAG_KEEP_SCREEN_ON     = 0x00000080;
511
512        /** Window flag: place the window within the entire screen, ignoring
513         *  decorations around the border (a.k.a. the status bar).  The
514         *  window must correctly position its contents to take the screen
515         *  decoration into account.  This flag is normally set for you
516         *  by Window as described in {@link Window#setFlags}. */
517        public static final int FLAG_LAYOUT_IN_SCREEN   = 0x00000100;
518
519        /** Window flag: allow window to extend outside of the screen. */
520        public static final int FLAG_LAYOUT_NO_LIMITS   = 0x00000200;
521
522        /** Window flag: Hide all screen decorations (e.g. status bar) while
523         * this window is displayed.  This allows the window to use the entire
524         * display space for itself -- the status bar will be hidden when
525         * an app window with this flag set is on the top layer. */
526        public static final int FLAG_FULLSCREEN      = 0x00000400;
527
528        /** Window flag: Override {@link #FLAG_FULLSCREEN and force the
529         *  screen decorations (such as status bar) to be shown. */
530        public static final int FLAG_FORCE_NOT_FULLSCREEN   = 0x00000800;
531
532        /** Window flag: turn on dithering when compositing this window to
533         *  the screen. */
534        public static final int FLAG_DITHER             = 0x00001000;
535
536        /** Window flag: don't allow screen shots while this window is
537         * displayed. Maps to Surface.SECURE. */
538        public static final int FLAG_SECURE             = 0x00002000;
539
540        /** Window flag: a special mode where the layout parameters are used
541         * to perform scaling of the surface when it is composited to the
542         * screen. */
543        public static final int FLAG_SCALED             = 0x00004000;
544
545        /** Window flag: intended for windows that will often be used when the user is
546         * holding the screen against their face, it will aggressively filter the event
547         * stream to prevent unintended presses in this situation that may not be
548         * desired for a particular window, when such an event stream is detected, the
549         * application will receive a CANCEL motion event to indicate this so applications
550         * can handle this accordingly by taking no action on the event
551         * until the finger is released. */
552        public static final int FLAG_IGNORE_CHEEK_PRESSES    = 0x00008000;
553
554        /** Window flag: a special option only for use in combination with
555         * {@link #FLAG_LAYOUT_IN_SCREEN}.  When requesting layout in the
556         * screen your window may appear on top of or behind screen decorations
557         * such as the status bar.  By also including this flag, the window
558         * manager will report the inset rectangle needed to ensure your
559         * content is not covered by screen decorations.  This flag is normally
560         * set for you by Window as described in {@link Window#setFlags}.*/
561        public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000;
562
563        /** Window flag: invert the state of {@link #FLAG_NOT_FOCUSABLE} with
564         * respect to how this window interacts with the current method.  That
565         * is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the
566         * window will behave as if it needs to interact with the input method
567         * and thus be placed behind/away from it; if FLAG_NOT_FOCUSABLE is
568         * not set and this flag is set, then the window will behave as if it
569         * doesn't need to interact with the input method and can be placed
570         * to use more space and cover the input method.
571         */
572        public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000;
573
574        /** Window flag: if you have set {@link #FLAG_NOT_TOUCH_MODAL}, you
575         * can set this flag to receive a single special MotionEvent with
576         * the action
577         * {@link MotionEvent#ACTION_OUTSIDE MotionEvent.ACTION_OUTSIDE} for
578         * touches that occur outside of your window.  Note that you will not
579         * receive the full down/move/up gesture, only the location of the
580         * first down as an ACTION_OUTSIDE.
581         */
582        public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000;
583
584        /** Window flag: special flag to let windows be shown when the screen
585         * is locked. This will let application windows take precedence over
586         * key guard or any other lock screens. Can be used with
587         * {@link #FLAG_KEEP_SCREEN_ON} to turn screen on and display windows
588         * directly before showing the key guard window.  Can be used with
589         * {@link #FLAG_DISMISS_KEYGUARD} to automatically fully dismisss
590         * non-secure keyguards.  This flag only applies to the top-most
591         * full-screen window.
592         */
593        public static final int FLAG_SHOW_WHEN_LOCKED = 0x00080000;
594
595        /** Window flag: ask that the system wallpaper be shown behind
596         * your window.  The window surface must be translucent to be able
597         * to actually see the wallpaper behind it; this flag just ensures
598         * that the wallpaper surface will be there if this window actually
599         * has translucent regions.
600         */
601        public static final int FLAG_SHOW_WALLPAPER = 0x00100000;
602
603        /** Window flag: when set as a window is being added or made
604         * visible, once the window has been shown then the system will
605         * poke the power manager's user activity (as if the user had woken
606         * up the device) to turn the screen on. */
607        public static final int FLAG_TURN_SCREEN_ON = 0x00200000;
608
609        /** Window flag: when set the window will cause the keyguard to
610         * be dismissed, only if it is not a secure lock keyguard.  Because such
611         * a keyguard is not needed for security, it will never re-appear if
612         * the user navigates to another window (in contrast to
613         * {@link #FLAG_SHOW_WHEN_LOCKED}, which will only temporarily
614         * hide both secure and non-secure keyguards but ensure they reappear
615         * when the user moves to another UI that doesn't hide them).
616         * If the keyguard is currently active and is secure (requires an
617         * unlock pattern) than the user will still need to confirm it before
618         * seeing this window, unless {@link #FLAG_SHOW_WHEN_LOCKED} has
619         * also been set.
620         */
621        public static final int FLAG_DISMISS_KEYGUARD = 0x00400000;
622
623        /** Window flag: when set the window will accept for touch events
624         * outside of its bounds to be sent to other windows that also
625         * support split touch.  When this flag is not set, the first pointer
626         * that goes down determines the window to which all subsequent touches
627         * go until all pointers go up.  When this flag is set, each pointer
628         * (not necessarily the first) that goes down determines the window
629         * to which all subsequent touches of that pointer will go until that
630         * pointer goes up thereby enabling touches with multiple pointers
631         * to be split across multiple windows.
632         */
633        public static final int FLAG_SPLIT_TOUCH = 0x00800000;
634
635        /**
636         * <p>Indicates whether this window should be hardware accelerated.
637         * Requesting hardware acceleration does not guarantee it will happen.</p>
638         *
639         * <p>This flag can be controlled programmatically <em>only</em> to enable
640         * hardware acceleration. To enable hardware acceleration for a given
641         * window programmatically, do the following:</p>
642         *
643         * <pre>
644         * Window w = activity.getWindow(); // in Activity's onCreate() for instance
645         * w.setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
646         *         WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
647         * </pre>
648         *
649         * <p>It is important to remember that this flag <strong>must</strong>
650         * be set before setting the content view of your activity or dialog.</p>
651         *
652         * <p>This flag cannot be used to disable hardware acceleration after it
653         * was enabled in your manifest using
654         * {@link android.R.attr#hardwareAccelerated}. If you need to selectively
655         * and programmatically disable hardware acceleration (for automated testing
656         * for instance), make sure it is turned off in your manifest and enable it
657         * on your activity or dialog when you need it instead, using the method
658         * described above.</p>
659         *
660         * <p>This flag is automatically set by the system if the
661         * {@link android.R.attr#hardwareAccelerated android:hardwareAccelerated}
662         * XML attribute is set to true on an activity or on the application.</p>
663         */
664        public static final int FLAG_HARDWARE_ACCELERATED = 0x01000000;
665
666        // ----- HIDDEN FLAGS.
667        // These start at the high bit and go down.
668
669        /** Window flag: Enable touches to slide out of a window into neighboring
670         * windows in mid-gesture instead of being captured for the duration of
671         * the gesture.
672         *
673         * This flag changes the behavior of touch focus for this window only.
674         * Touches can slide out of the window but they cannot necessarily slide
675         * back in (unless the other window with touch focus permits it).
676         *
677         * {@hide}
678         */
679        public static final int FLAG_SLIPPERY = 0x04000000;
680
681        /**
682         * Flag for a window belonging to an activity that responds to {@link KeyEvent#KEYCODE_MENU}
683         * and therefore needs a Menu key. For devices where Menu is a physical button this flag is
684         * ignored, but on devices where the Menu key is drawn in software it may be hidden unless
685         * this flag is set.
686         *
687         * (Note that Action Bars, when available, are the preferred way to offer additional
688         * functions otherwise accessed via an options menu.)
689         *
690         * {@hide}
691         */
692        public static final int FLAG_NEEDS_MENU_KEY = 0x08000000;
693
694        /** Window flag: *sigh* The lock screen wants to continue running its
695         * animation while it is fading.  A kind-of hack to allow this.  Maybe
696         * in the future we just make this the default behavior.
697         *
698         * {@hide} */
699        public static final int FLAG_KEEP_SURFACE_WHILE_ANIMATING = 0x10000000;
700
701        /** Window flag: special flag to limit the size of the window to be
702         * original size ([320x480] x density). Used to create window for applications
703         * running under compatibility mode.
704         *
705         * {@hide} */
706        public static final int FLAG_COMPATIBLE_WINDOW = 0x20000000;
707
708        /** Window flag: a special option intended for system dialogs.  When
709         * this flag is set, the window will demand focus unconditionally when
710         * it is created.
711         * {@hide} */
712        public static final int FLAG_SYSTEM_ERROR = 0x40000000;
713
714        /**
715         * Various behavioral options/flags.  Default is none.
716         *
717         * @see #FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
718         * @see #FLAG_DIM_BEHIND
719         * @see #FLAG_NOT_FOCUSABLE
720         * @see #FLAG_NOT_TOUCHABLE
721         * @see #FLAG_NOT_TOUCH_MODAL
722         * @see #FLAG_TOUCHABLE_WHEN_WAKING
723         * @see #FLAG_KEEP_SCREEN_ON
724         * @see #FLAG_LAYOUT_IN_SCREEN
725         * @see #FLAG_LAYOUT_NO_LIMITS
726         * @see #FLAG_FULLSCREEN
727         * @see #FLAG_FORCE_NOT_FULLSCREEN
728         * @see #FLAG_DITHER
729         * @see #FLAG_SECURE
730         * @see #FLAG_SCALED
731         * @see #FLAG_IGNORE_CHEEK_PRESSES
732         * @see #FLAG_LAYOUT_INSET_DECOR
733         * @see #FLAG_ALT_FOCUSABLE_IM
734         * @see #FLAG_WATCH_OUTSIDE_TOUCH
735         * @see #FLAG_SHOW_WHEN_LOCKED
736         * @see #FLAG_SHOW_WALLPAPER
737         * @see #FLAG_TURN_SCREEN_ON
738         * @see #FLAG_DISMISS_KEYGUARD
739         * @see #FLAG_SPLIT_TOUCH
740         * @see #FLAG_HARDWARE_ACCELERATED
741         */
742        @ViewDebug.ExportedProperty(flagMapping = {
743            @ViewDebug.FlagToString(mask = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON, equals = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON,
744                    name = "FLAG_ALLOW_LOCK_WHILE_SCREEN_ON"),
745            @ViewDebug.FlagToString(mask = FLAG_DIM_BEHIND, equals = FLAG_DIM_BEHIND,
746                    name = "FLAG_DIM_BEHIND"),
747            @ViewDebug.FlagToString(mask = FLAG_BLUR_BEHIND, equals = FLAG_BLUR_BEHIND,
748                    name = "FLAG_BLUR_BEHIND"),
749            @ViewDebug.FlagToString(mask = FLAG_NOT_FOCUSABLE, equals = FLAG_NOT_FOCUSABLE,
750                    name = "FLAG_NOT_FOCUSABLE"),
751            @ViewDebug.FlagToString(mask = FLAG_NOT_TOUCHABLE, equals = FLAG_NOT_TOUCHABLE,
752                    name = "FLAG_NOT_TOUCHABLE"),
753            @ViewDebug.FlagToString(mask = FLAG_NOT_TOUCH_MODAL, equals = FLAG_NOT_TOUCH_MODAL,
754                    name = "FLAG_NOT_TOUCH_MODAL"),
755            @ViewDebug.FlagToString(mask = FLAG_TOUCHABLE_WHEN_WAKING, equals = FLAG_TOUCHABLE_WHEN_WAKING,
756                    name = "FLAG_TOUCHABLE_WHEN_WAKING"),
757            @ViewDebug.FlagToString(mask = FLAG_KEEP_SCREEN_ON, equals = FLAG_KEEP_SCREEN_ON,
758                    name = "FLAG_KEEP_SCREEN_ON"),
759            @ViewDebug.FlagToString(mask = FLAG_LAYOUT_IN_SCREEN, equals = FLAG_LAYOUT_IN_SCREEN,
760                    name = "FLAG_LAYOUT_IN_SCREEN"),
761            @ViewDebug.FlagToString(mask = FLAG_LAYOUT_NO_LIMITS, equals = FLAG_LAYOUT_NO_LIMITS,
762                    name = "FLAG_LAYOUT_NO_LIMITS"),
763            @ViewDebug.FlagToString(mask = FLAG_FULLSCREEN, equals = FLAG_FULLSCREEN,
764                    name = "FLAG_FULLSCREEN"),
765            @ViewDebug.FlagToString(mask = FLAG_FORCE_NOT_FULLSCREEN, equals = FLAG_FORCE_NOT_FULLSCREEN,
766                    name = "FLAG_FORCE_NOT_FULLSCREEN"),
767            @ViewDebug.FlagToString(mask = FLAG_DITHER, equals = FLAG_DITHER,
768                    name = "FLAG_DITHER"),
769            @ViewDebug.FlagToString(mask = FLAG_SECURE, equals = FLAG_SECURE,
770                    name = "FLAG_SECURE"),
771            @ViewDebug.FlagToString(mask = FLAG_SCALED, equals = FLAG_SCALED,
772                    name = "FLAG_SCALED"),
773            @ViewDebug.FlagToString(mask = FLAG_IGNORE_CHEEK_PRESSES, equals = FLAG_IGNORE_CHEEK_PRESSES,
774                    name = "FLAG_IGNORE_CHEEK_PRESSES"),
775            @ViewDebug.FlagToString(mask = FLAG_LAYOUT_INSET_DECOR, equals = FLAG_LAYOUT_INSET_DECOR,
776                    name = "FLAG_LAYOUT_INSET_DECOR"),
777            @ViewDebug.FlagToString(mask = FLAG_ALT_FOCUSABLE_IM, equals = FLAG_ALT_FOCUSABLE_IM,
778                    name = "FLAG_ALT_FOCUSABLE_IM"),
779            @ViewDebug.FlagToString(mask = FLAG_WATCH_OUTSIDE_TOUCH, equals = FLAG_WATCH_OUTSIDE_TOUCH,
780                    name = "FLAG_WATCH_OUTSIDE_TOUCH"),
781            @ViewDebug.FlagToString(mask = FLAG_SHOW_WHEN_LOCKED, equals = FLAG_SHOW_WHEN_LOCKED,
782                    name = "FLAG_SHOW_WHEN_LOCKED"),
783            @ViewDebug.FlagToString(mask = FLAG_SHOW_WALLPAPER, equals = FLAG_SHOW_WALLPAPER,
784                    name = "FLAG_SHOW_WALLPAPER"),
785            @ViewDebug.FlagToString(mask = FLAG_TURN_SCREEN_ON, equals = FLAG_TURN_SCREEN_ON,
786                    name = "FLAG_TURN_SCREEN_ON"),
787            @ViewDebug.FlagToString(mask = FLAG_DISMISS_KEYGUARD, equals = FLAG_DISMISS_KEYGUARD,
788                    name = "FLAG_DISMISS_KEYGUARD"),
789            @ViewDebug.FlagToString(mask = FLAG_SPLIT_TOUCH, equals = FLAG_SPLIT_TOUCH,
790                    name = "FLAG_SPLIT_TOUCH"),
791            @ViewDebug.FlagToString(mask = FLAG_HARDWARE_ACCELERATED, equals = FLAG_HARDWARE_ACCELERATED,
792                    name = "FLAG_HARDWARE_ACCELERATED")
793        })
794        public int flags;
795
796        /**
797         * If the window has requested hardware acceleration, but this is not
798         * allowed in the process it is in, then still render it as if it is
799         * hardware accelerated.  This is used for the starting preview windows
800         * in the system process, which don't need to have the overhead of
801         * hardware acceleration (they are just a static rendering), but should
802         * be rendered as such to match the actual window of the app even if it
803         * is hardware accelerated.
804         * Even if the window isn't hardware accelerated, still do its rendering
805         * as if it was.
806         * Like {@link #FLAG_HARDWARE_ACCELERATED} except for trusted system windows
807         * that need hardware acceleration (e.g. LockScreen), where hardware acceleration
808         * is generally disabled. This flag must be specified in addition to
809         * {@link #FLAG_HARDWARE_ACCELERATED} to enable hardware acceleration for system
810         * windows.
811         *
812         * @hide
813         */
814        public static final int PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED = 0x00000001;
815
816        /**
817         * In the system process, we globally do not use hardware acceleration
818         * because there are many threads doing UI there and they conflict.
819         * If certain parts of the UI that really do want to use hardware
820         * acceleration, this flag can be set to force it.  This is basically
821         * for the lock screen.  Anyone else using it, you are probably wrong.
822         *
823         * @hide
824         */
825        public static final int PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED = 0x00000002;
826
827        /**
828         * By default, wallpapers are sent new offsets when the wallpaper is scrolled. Wallpapers
829         * may elect to skip these notifications if they are not doing anything productive with
830         * them (they do not affect the wallpaper scrolling operation) by calling
831         * {@link
832         * android.service.wallpaper.WallpaperService.Engine#setOffsetNotificationsEnabled(boolean)}.
833         *
834         * @hide
835         */
836        public static final int PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS = 0x00000004;
837
838        /**
839         * This is set for a window that has explicitly specified its
840         * FLAG_NEEDS_MENU_KEY, so we know the value on this window is the
841         * appropriate one to use.  If this is not set, we should look at
842         * windows behind it to determine the appropriate value.
843         *
844         * @hide
845         */
846        public static final int PRIVATE_FLAG_SET_NEEDS_MENU_KEY = 0x00000008;
847
848        /**
849         * Control flags that are private to the platform.
850         * @hide
851         */
852        public int privateFlags;
853
854        /**
855         * Given a particular set of window manager flags, determine whether
856         * such a window may be a target for an input method when it has
857         * focus.  In particular, this checks the
858         * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM}
859         * flags and returns true if the combination of the two corresponds
860         * to a window that needs to be behind the input method so that the
861         * user can type into it.
862         *
863         * @param flags The current window manager flags.
864         *
865         * @return Returns true if such a window should be behind/interact
866         * with an input method, false if not.
867         */
868        public static boolean mayUseInputMethod(int flags) {
869            switch (flags&(FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
870                case 0:
871                case FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM:
872                    return true;
873            }
874            return false;
875        }
876
877        /**
878         * Mask for {@link #softInputMode} of the bits that determine the
879         * desired visibility state of the soft input area for this window.
880         */
881        public static final int SOFT_INPUT_MASK_STATE = 0x0f;
882
883        /**
884         * Visibility state for {@link #softInputMode}: no state has been specified.
885         */
886        public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0;
887
888        /**
889         * Visibility state for {@link #softInputMode}: please don't change the state of
890         * the soft input area.
891         */
892        public static final int SOFT_INPUT_STATE_UNCHANGED = 1;
893
894        /**
895         * Visibility state for {@link #softInputMode}: please hide any soft input
896         * area when normally appropriate (when the user is navigating
897         * forward to your window).
898         */
899        public static final int SOFT_INPUT_STATE_HIDDEN = 2;
900
901        /**
902         * Visibility state for {@link #softInputMode}: please always hide any
903         * soft input area when this window receives focus.
904         */
905        public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3;
906
907        /**
908         * Visibility state for {@link #softInputMode}: please show the soft
909         * input area when normally appropriate (when the user is navigating
910         * forward to your window).
911         */
912        public static final int SOFT_INPUT_STATE_VISIBLE = 4;
913
914        /**
915         * Visibility state for {@link #softInputMode}: please always make the
916         * soft input area visible when this window receives input focus.
917         */
918        public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5;
919
920        /**
921         * Mask for {@link #softInputMode} of the bits that determine the
922         * way that the window should be adjusted to accommodate the soft
923         * input window.
924         */
925        public static final int SOFT_INPUT_MASK_ADJUST = 0xf0;
926
927        /** Adjustment option for {@link #softInputMode}: nothing specified.
928         * The system will try to pick one or
929         * the other depending on the contents of the window.
930         */
931        public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00;
932
933        /** Adjustment option for {@link #softInputMode}: set to allow the
934         * window to be resized when an input
935         * method is shown, so that its contents are not covered by the input
936         * method.  This can <em>not</em> be combined with
937         * {@link #SOFT_INPUT_ADJUST_PAN}; if
938         * neither of these are set, then the system will try to pick one or
939         * the other depending on the contents of the window.
940         */
941        public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10;
942
943        /** Adjustment option for {@link #softInputMode}: set to have a window
944         * pan when an input method is
945         * shown, so it doesn't need to deal with resizing but just panned
946         * by the framework to ensure the current input focus is visible.  This
947         * can <em>not</em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if
948         * neither of these are set, then the system will try to pick one or
949         * the other depending on the contents of the window.
950         */
951        public static final int SOFT_INPUT_ADJUST_PAN = 0x20;
952
953        /** Adjustment option for {@link #softInputMode}: set to have a window
954         * not adjust for a shown input method.  The window will not be resized,
955         * and it will not be panned to make its focus visible.
956         */
957        public static final int SOFT_INPUT_ADJUST_NOTHING = 0x30;
958
959        /**
960         * Bit for {@link #softInputMode}: set when the user has navigated
961         * forward to the window.  This is normally set automatically for
962         * you by the system, though you may want to set it in certain cases
963         * when you are displaying a window yourself.  This flag will always
964         * be cleared automatically after the window is displayed.
965         */
966        public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;
967
968        /**
969         * Desired operating mode for any soft input area.  May be any combination
970         * of:
971         *
972         * <ul>
973         * <li> One of the visibility states
974         * {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED},
975         * {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}, or
976         * {@link #SOFT_INPUT_STATE_VISIBLE}.
977         * <li> One of the adjustment options
978         * {@link #SOFT_INPUT_ADJUST_UNSPECIFIED},
979         * {@link #SOFT_INPUT_ADJUST_RESIZE}, or
980         * {@link #SOFT_INPUT_ADJUST_PAN}.
981         */
982        public int softInputMode;
983
984        /**
985         * Placement of window within the screen as per {@link Gravity}.  Both
986         * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
987         * android.graphics.Rect) Gravity.apply} and
988         * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect)
989         * Gravity.applyDisplay} are used during window layout, with this value
990         * given as the desired gravity.  For example you can specify
991         * {@link Gravity#DISPLAY_CLIP_HORIZONTAL Gravity.DISPLAY_CLIP_HORIZONTAL} and
992         * {@link Gravity#DISPLAY_CLIP_VERTICAL Gravity.DISPLAY_CLIP_VERTICAL} here
993         * to control the behavior of
994         * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect)
995         * Gravity.applyDisplay}.
996         *
997         * @see Gravity
998         */
999        public int gravity;
1000
1001        /**
1002         * The horizontal margin, as a percentage of the container's width,
1003         * between the container and the widget.  See
1004         * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
1005         * android.graphics.Rect) Gravity.apply} for how this is used.  This
1006         * field is added with {@link #x} to supply the <var>xAdj</var> parameter.
1007         */
1008        public float horizontalMargin;
1009
1010        /**
1011         * The vertical margin, as a percentage of the container's height,
1012         * between the container and the widget.  See
1013         * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
1014         * android.graphics.Rect) Gravity.apply} for how this is used.  This
1015         * field is added with {@link #y} to supply the <var>yAdj</var> parameter.
1016         */
1017        public float verticalMargin;
1018
1019        /**
1020         * The desired bitmap format.  May be one of the constants in
1021         * {@link android.graphics.PixelFormat}.  Default is OPAQUE.
1022         */
1023        public int format;
1024
1025        /**
1026         * A style resource defining the animations to use for this window.
1027         * This must be a system resource; it can not be an application resource
1028         * because the window manager does not have access to applications.
1029         */
1030        public int windowAnimations;
1031
1032        /**
1033         * An alpha value to apply to this entire window.
1034         * An alpha of 1.0 means fully opaque and 0.0 means fully transparent
1035         */
1036        public float alpha = 1.0f;
1037
1038        /**
1039         * When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming
1040         * to apply.  Range is from 1.0 for completely opaque to 0.0 for no
1041         * dim.
1042         */
1043        public float dimAmount = 1.0f;
1044
1045        /**
1046         * Default value for {@link #screenBrightness} and {@link #buttonBrightness}
1047         * indicating that the brightness value is not overridden for this window
1048         * and normal brightness policy should be used.
1049         */
1050        public static final float BRIGHTNESS_OVERRIDE_NONE = -1.0f;
1051
1052        /**
1053         * Value for {@link #screenBrightness} and {@link #buttonBrightness}
1054         * indicating that the screen or button backlight brightness should be set
1055         * to the lowest value when this window is in front.
1056         */
1057        public static final float BRIGHTNESS_OVERRIDE_OFF = 0.0f;
1058
1059        /**
1060         * Value for {@link #screenBrightness} and {@link #buttonBrightness}
1061         * indicating that the screen or button backlight brightness should be set
1062         * to the hightest value when this window is in front.
1063         */
1064        public static final float BRIGHTNESS_OVERRIDE_FULL = 1.0f;
1065
1066        /**
1067         * This can be used to override the user's preferred brightness of
1068         * the screen.  A value of less than 0, the default, means to use the
1069         * preferred screen brightness.  0 to 1 adjusts the brightness from
1070         * dark to full bright.
1071         */
1072        public float screenBrightness = BRIGHTNESS_OVERRIDE_NONE;
1073
1074        /**
1075         * This can be used to override the standard behavior of the button and
1076         * keyboard backlights.  A value of less than 0, the default, means to
1077         * use the standard backlight behavior.  0 to 1 adjusts the brightness
1078         * from dark to full bright.
1079         */
1080        public float buttonBrightness = BRIGHTNESS_OVERRIDE_NONE;
1081
1082        /**
1083         * Identifier for this window.  This will usually be filled in for
1084         * you.
1085         */
1086        public IBinder token = null;
1087
1088        /**
1089         * Name of the package owning this window.
1090         */
1091        public String packageName = null;
1092
1093        /**
1094         * Specific orientation value for a window.
1095         * May be any of the same values allowed
1096         * for {@link android.content.pm.ActivityInfo#screenOrientation}.
1097         * If not set, a default value of
1098         * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}
1099         * will be used.
1100         */
1101        public int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
1102
1103        /**
1104         * Control the visibility of the status bar.
1105         *
1106         * @see View#STATUS_BAR_VISIBLE
1107         * @see View#STATUS_BAR_HIDDEN
1108         */
1109        public int systemUiVisibility;
1110
1111        /**
1112         * @hide
1113         * The ui visibility as requested by the views in this hierarchy.
1114         * the combined value should be systemUiVisibility | subtreeSystemUiVisibility.
1115         */
1116        public int subtreeSystemUiVisibility;
1117
1118        /**
1119         * Get callbacks about the system ui visibility changing.
1120         *
1121         * TODO: Maybe there should be a bitfield of optional callbacks that we need.
1122         *
1123         * @hide
1124         */
1125        public boolean hasSystemUiListeners;
1126
1127        /**
1128         * When this window has focus, disable touch pad pointer gesture processing.
1129         * The window will receive raw position updates from the touch pad instead
1130         * of pointer movements and synthetic touch events.
1131         *
1132         * @hide
1133         */
1134        public static final int INPUT_FEATURE_DISABLE_POINTER_GESTURES = 0x00000001;
1135
1136        /**
1137         * Does not construct an input channel for this window.  The channel will therefore
1138         * be incapable of receiving input.
1139         *
1140         * @hide
1141         */
1142        public static final int INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002;
1143
1144        /**
1145         * Control special features of the input subsystem.
1146         *
1147         * @see #INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES
1148         * @see #INPUT_FEATURE_NO_INPUT_CHANNEL
1149         * @hide
1150         */
1151        public int inputFeatures;
1152
1153        public LayoutParams() {
1154            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1155            type = TYPE_APPLICATION;
1156            format = PixelFormat.OPAQUE;
1157        }
1158
1159        public LayoutParams(int _type) {
1160            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1161            type = _type;
1162            format = PixelFormat.OPAQUE;
1163        }
1164
1165        public LayoutParams(int _type, int _flags) {
1166            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1167            type = _type;
1168            flags = _flags;
1169            format = PixelFormat.OPAQUE;
1170        }
1171
1172        public LayoutParams(int _type, int _flags, int _format) {
1173            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1174            type = _type;
1175            flags = _flags;
1176            format = _format;
1177        }
1178
1179        public LayoutParams(int w, int h, int _type, int _flags, int _format) {
1180            super(w, h);
1181            type = _type;
1182            flags = _flags;
1183            format = _format;
1184        }
1185
1186        public LayoutParams(int w, int h, int xpos, int ypos, int _type,
1187                int _flags, int _format) {
1188            super(w, h);
1189            x = xpos;
1190            y = ypos;
1191            type = _type;
1192            flags = _flags;
1193            format = _format;
1194        }
1195
1196        public final void setTitle(CharSequence title) {
1197            if (null == title)
1198                title = "";
1199
1200            mTitle = TextUtils.stringOrSpannedString(title);
1201        }
1202
1203        public final CharSequence getTitle() {
1204            return mTitle;
1205        }
1206
1207        public int describeContents() {
1208            return 0;
1209        }
1210
1211        public void writeToParcel(Parcel out, int parcelableFlags) {
1212            out.writeInt(width);
1213            out.writeInt(height);
1214            out.writeInt(x);
1215            out.writeInt(y);
1216            out.writeInt(type);
1217            out.writeInt(flags);
1218            out.writeInt(privateFlags);
1219            out.writeInt(softInputMode);
1220            out.writeInt(gravity);
1221            out.writeFloat(horizontalMargin);
1222            out.writeFloat(verticalMargin);
1223            out.writeInt(format);
1224            out.writeInt(windowAnimations);
1225            out.writeFloat(alpha);
1226            out.writeFloat(dimAmount);
1227            out.writeFloat(screenBrightness);
1228            out.writeFloat(buttonBrightness);
1229            out.writeStrongBinder(token);
1230            out.writeString(packageName);
1231            TextUtils.writeToParcel(mTitle, out, parcelableFlags);
1232            out.writeInt(screenOrientation);
1233            out.writeInt(systemUiVisibility);
1234            out.writeInt(subtreeSystemUiVisibility);
1235            out.writeInt(hasSystemUiListeners ? 1 : 0);
1236            out.writeInt(inputFeatures);
1237        }
1238
1239        public static final Parcelable.Creator<LayoutParams> CREATOR
1240                    = new Parcelable.Creator<LayoutParams>() {
1241            public LayoutParams createFromParcel(Parcel in) {
1242                return new LayoutParams(in);
1243            }
1244
1245            public LayoutParams[] newArray(int size) {
1246                return new LayoutParams[size];
1247            }
1248        };
1249
1250
1251        public LayoutParams(Parcel in) {
1252            width = in.readInt();
1253            height = in.readInt();
1254            x = in.readInt();
1255            y = in.readInt();
1256            type = in.readInt();
1257            flags = in.readInt();
1258            privateFlags = in.readInt();
1259            softInputMode = in.readInt();
1260            gravity = in.readInt();
1261            horizontalMargin = in.readFloat();
1262            verticalMargin = in.readFloat();
1263            format = in.readInt();
1264            windowAnimations = in.readInt();
1265            alpha = in.readFloat();
1266            dimAmount = in.readFloat();
1267            screenBrightness = in.readFloat();
1268            buttonBrightness = in.readFloat();
1269            token = in.readStrongBinder();
1270            packageName = in.readString();
1271            mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
1272            screenOrientation = in.readInt();
1273            systemUiVisibility = in.readInt();
1274            subtreeSystemUiVisibility = in.readInt();
1275            hasSystemUiListeners = in.readInt() != 0;
1276            inputFeatures = in.readInt();
1277        }
1278
1279        @SuppressWarnings({"PointlessBitwiseExpression"})
1280        public static final int LAYOUT_CHANGED = 1<<0;
1281        public static final int TYPE_CHANGED = 1<<1;
1282        public static final int FLAGS_CHANGED = 1<<2;
1283        public static final int FORMAT_CHANGED = 1<<3;
1284        public static final int ANIMATION_CHANGED = 1<<4;
1285        public static final int DIM_AMOUNT_CHANGED = 1<<5;
1286        public static final int TITLE_CHANGED = 1<<6;
1287        public static final int ALPHA_CHANGED = 1<<7;
1288        public static final int MEMORY_TYPE_CHANGED = 1<<8;
1289        public static final int SOFT_INPUT_MODE_CHANGED = 1<<9;
1290        public static final int SCREEN_ORIENTATION_CHANGED = 1<<10;
1291        public static final int SCREEN_BRIGHTNESS_CHANGED = 1<<11;
1292        /** {@hide} */
1293        public static final int BUTTON_BRIGHTNESS_CHANGED = 1<<12;
1294        /** {@hide} */
1295        public static final int SYSTEM_UI_VISIBILITY_CHANGED = 1<<13;
1296        /** {@hide} */
1297        public static final int SYSTEM_UI_LISTENER_CHANGED = 1<<14;
1298        /** {@hide} */
1299        public static final int INPUT_FEATURES_CHANGED = 1<<15;
1300        /** {@hide} */
1301        public static final int PRIVATE_FLAGS_CHANGED = 1<<16;
1302        /** {@hide} */
1303        public static final int EVERYTHING_CHANGED = 0xffffffff;
1304
1305        // internal buffer to backup/restore parameters under compatibility mode.
1306        private int[] mCompatibilityParamsBackup = null;
1307
1308        public final int copyFrom(LayoutParams o) {
1309            int changes = 0;
1310
1311            if (width != o.width) {
1312                width = o.width;
1313                changes |= LAYOUT_CHANGED;
1314            }
1315            if (height != o.height) {
1316                height = o.height;
1317                changes |= LAYOUT_CHANGED;
1318            }
1319            if (x != o.x) {
1320                x = o.x;
1321                changes |= LAYOUT_CHANGED;
1322            }
1323            if (y != o.y) {
1324                y = o.y;
1325                changes |= LAYOUT_CHANGED;
1326            }
1327            if (horizontalWeight != o.horizontalWeight) {
1328                horizontalWeight = o.horizontalWeight;
1329                changes |= LAYOUT_CHANGED;
1330            }
1331            if (verticalWeight != o.verticalWeight) {
1332                verticalWeight = o.verticalWeight;
1333                changes |= LAYOUT_CHANGED;
1334            }
1335            if (horizontalMargin != o.horizontalMargin) {
1336                horizontalMargin = o.horizontalMargin;
1337                changes |= LAYOUT_CHANGED;
1338            }
1339            if (verticalMargin != o.verticalMargin) {
1340                verticalMargin = o.verticalMargin;
1341                changes |= LAYOUT_CHANGED;
1342            }
1343            if (type != o.type) {
1344                type = o.type;
1345                changes |= TYPE_CHANGED;
1346            }
1347            if (flags != o.flags) {
1348                flags = o.flags;
1349                changes |= FLAGS_CHANGED;
1350            }
1351            if (privateFlags != o.privateFlags) {
1352                privateFlags = o.privateFlags;
1353                changes |= PRIVATE_FLAGS_CHANGED;
1354            }
1355            if (softInputMode != o.softInputMode) {
1356                softInputMode = o.softInputMode;
1357                changes |= SOFT_INPUT_MODE_CHANGED;
1358            }
1359            if (gravity != o.gravity) {
1360                gravity = o.gravity;
1361                changes |= LAYOUT_CHANGED;
1362            }
1363            if (format != o.format) {
1364                format = o.format;
1365                changes |= FORMAT_CHANGED;
1366            }
1367            if (windowAnimations != o.windowAnimations) {
1368                windowAnimations = o.windowAnimations;
1369                changes |= ANIMATION_CHANGED;
1370            }
1371            if (token == null) {
1372                // NOTE: token only copied if the recipient doesn't
1373                // already have one.
1374                token = o.token;
1375            }
1376            if (packageName == null) {
1377                // NOTE: packageName only copied if the recipient doesn't
1378                // already have one.
1379                packageName = o.packageName;
1380            }
1381            if (!mTitle.equals(o.mTitle)) {
1382                mTitle = o.mTitle;
1383                changes |= TITLE_CHANGED;
1384            }
1385            if (alpha != o.alpha) {
1386                alpha = o.alpha;
1387                changes |= ALPHA_CHANGED;
1388            }
1389            if (dimAmount != o.dimAmount) {
1390                dimAmount = o.dimAmount;
1391                changes |= DIM_AMOUNT_CHANGED;
1392            }
1393            if (screenBrightness != o.screenBrightness) {
1394                screenBrightness = o.screenBrightness;
1395                changes |= SCREEN_BRIGHTNESS_CHANGED;
1396            }
1397            if (buttonBrightness != o.buttonBrightness) {
1398                buttonBrightness = o.buttonBrightness;
1399                changes |= BUTTON_BRIGHTNESS_CHANGED;
1400            }
1401
1402            if (screenOrientation != o.screenOrientation) {
1403                screenOrientation = o.screenOrientation;
1404                changes |= SCREEN_ORIENTATION_CHANGED;
1405            }
1406
1407            if (systemUiVisibility != o.systemUiVisibility
1408                    || subtreeSystemUiVisibility != o.subtreeSystemUiVisibility) {
1409                systemUiVisibility = o.systemUiVisibility;
1410                subtreeSystemUiVisibility = o.subtreeSystemUiVisibility;
1411                changes |= SYSTEM_UI_VISIBILITY_CHANGED;
1412            }
1413
1414            if (hasSystemUiListeners != o.hasSystemUiListeners) {
1415                hasSystemUiListeners = o.hasSystemUiListeners;
1416                changes |= SYSTEM_UI_LISTENER_CHANGED;
1417            }
1418
1419            if (inputFeatures != o.inputFeatures) {
1420                inputFeatures = o.inputFeatures;
1421                changes |= INPUT_FEATURES_CHANGED;
1422            }
1423
1424            return changes;
1425        }
1426
1427        @Override
1428        public String debug(String output) {
1429            output += "Contents of " + this + ":";
1430            Log.d("Debug", output);
1431            output = super.debug("");
1432            Log.d("Debug", output);
1433            Log.d("Debug", "");
1434            Log.d("Debug", "WindowManager.LayoutParams={title=" + mTitle + "}");
1435            return "";
1436        }
1437
1438        @Override
1439        public String toString() {
1440            StringBuilder sb = new StringBuilder(256);
1441            sb.append("WM.LayoutParams{");
1442            sb.append("(");
1443            sb.append(x);
1444            sb.append(',');
1445            sb.append(y);
1446            sb.append(")(");
1447            sb.append((width== MATCH_PARENT ?"fill":(width==WRAP_CONTENT?"wrap":width)));
1448            sb.append('x');
1449            sb.append((height== MATCH_PARENT ?"fill":(height==WRAP_CONTENT?"wrap":height)));
1450            sb.append(")");
1451            if (horizontalMargin != 0) {
1452                sb.append(" hm=");
1453                sb.append(horizontalMargin);
1454            }
1455            if (verticalMargin != 0) {
1456                sb.append(" vm=");
1457                sb.append(verticalMargin);
1458            }
1459            if (gravity != 0) {
1460                sb.append(" gr=#");
1461                sb.append(Integer.toHexString(gravity));
1462            }
1463            if (softInputMode != 0) {
1464                sb.append(" sim=#");
1465                sb.append(Integer.toHexString(softInputMode));
1466            }
1467            sb.append(" ty=");
1468            sb.append(type);
1469            sb.append(" fl=#");
1470            sb.append(Integer.toHexString(flags));
1471            if (privateFlags != 0) {
1472                sb.append(" pfl=0x").append(Integer.toHexString(privateFlags));
1473            }
1474            if (format != PixelFormat.OPAQUE) {
1475                sb.append(" fmt=");
1476                sb.append(format);
1477            }
1478            if (windowAnimations != 0) {
1479                sb.append(" wanim=0x");
1480                sb.append(Integer.toHexString(windowAnimations));
1481            }
1482            if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
1483                sb.append(" or=");
1484                sb.append(screenOrientation);
1485            }
1486            if (alpha != 1.0f) {
1487                sb.append(" alpha=");
1488                sb.append(alpha);
1489            }
1490            if (screenBrightness != BRIGHTNESS_OVERRIDE_NONE) {
1491                sb.append(" sbrt=");
1492                sb.append(screenBrightness);
1493            }
1494            if (buttonBrightness != BRIGHTNESS_OVERRIDE_NONE) {
1495                sb.append(" bbrt=");
1496                sb.append(buttonBrightness);
1497            }
1498            if ((flags & FLAG_COMPATIBLE_WINDOW) != 0) {
1499                sb.append(" compatible=true");
1500            }
1501            if (systemUiVisibility != 0) {
1502                sb.append(" sysui=0x");
1503                sb.append(Integer.toHexString(systemUiVisibility));
1504            }
1505            if (subtreeSystemUiVisibility != 0) {
1506                sb.append(" vsysui=0x");
1507                sb.append(Integer.toHexString(subtreeSystemUiVisibility));
1508            }
1509            if (hasSystemUiListeners) {
1510                sb.append(" sysuil=");
1511                sb.append(hasSystemUiListeners);
1512            }
1513            if (inputFeatures != 0) {
1514                sb.append(" if=0x").append(Integer.toHexString(inputFeatures));
1515            }
1516            sb.append('}');
1517            return sb.toString();
1518        }
1519
1520        /**
1521         * Scale the layout params' coordinates and size.
1522         * @hide
1523         */
1524        public void scale(float scale) {
1525            x = (int) (x * scale + 0.5f);
1526            y = (int) (y * scale + 0.5f);
1527            if (width > 0) {
1528                width = (int) (width * scale + 0.5f);
1529            }
1530            if (height > 0) {
1531                height = (int) (height * scale + 0.5f);
1532            }
1533        }
1534
1535        /**
1536         * Backup the layout parameters used in compatibility mode.
1537         * @see LayoutParams#restore()
1538         */
1539        void backup() {
1540            int[] backup = mCompatibilityParamsBackup;
1541            if (backup == null) {
1542                // we backup 4 elements, x, y, width, height
1543                backup = mCompatibilityParamsBackup = new int[4];
1544            }
1545            backup[0] = x;
1546            backup[1] = y;
1547            backup[2] = width;
1548            backup[3] = height;
1549        }
1550
1551        /**
1552         * Restore the layout params' coordinates, size and gravity
1553         * @see LayoutParams#backup()
1554         */
1555        void restore() {
1556            int[] backup = mCompatibilityParamsBackup;
1557            if (backup != null) {
1558                x = backup[0];
1559                y = backup[1];
1560                width = backup[2];
1561                height = backup[3];
1562            }
1563        }
1564
1565        private CharSequence mTitle = "";
1566    }
1567}
1568