WindowManager.java revision d9b3b7e8e1d8c919c3e5f5851daa80a2651ea7d1
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#RIGHT} it provides
81         * 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_SYSTEM_DIALOG, to = "TYPE_SYSTEM_DIALOG"),
175            @ViewDebug.IntToString(from = TYPE_KEYGUARD_DIALOG, to = "TYPE_KEYGUARD_DIALOG"),
176            @ViewDebug.IntToString(from = TYPE_SYSTEM_ERROR, to = "TYPE_SYSTEM_ERROR"),
177            @ViewDebug.IntToString(from = TYPE_INPUT_METHOD, to = "TYPE_INPUT_METHOD"),
178            @ViewDebug.IntToString(from = TYPE_INPUT_METHOD_DIALOG, to = "TYPE_INPUT_METHOD_DIALOG"),
179            @ViewDebug.IntToString(from = TYPE_SECURE_SYSTEM_OVERLAY, to = "TYPE_SECURE_SYSTEM_OVERLAY")
180        })
181        public int type;
182
183        /**
184         * Start of window types that represent normal application windows.
185         */
186        public static final int FIRST_APPLICATION_WINDOW = 1;
187
188        /**
189         * Window type: an application window that serves as the "base" window
190         * of the overall application; all other application windows will
191         * appear on top of it.
192         */
193        public static final int TYPE_BASE_APPLICATION   = 1;
194
195        /**
196         * Window type: a normal application window.  The {@link #token} must be
197         * an Activity token identifying who the window belongs to.
198         */
199        public static final int TYPE_APPLICATION        = 2;
200
201        /**
202         * Window type: special application window that is displayed while the
203         * application is starting.  Not for use by applications themselves;
204         * this is used by the system to display something until the
205         * application can show its own windows.
206         */
207        public static final int TYPE_APPLICATION_STARTING = 3;
208
209        /**
210         * End of types of application windows.
211         */
212        public static final int LAST_APPLICATION_WINDOW = 99;
213
214        /**
215         * Start of types of sub-windows.  The {@link #token} of these windows
216         * must be set to the window they are attached to.  These types of
217         * windows are kept next to their attached window in Z-order, and their
218         * coordinate space is relative to their attached window.
219         */
220        public static final int FIRST_SUB_WINDOW        = 1000;
221
222        /**
223         * Window type: a panel on top of an application window.  These windows
224         * appear on top of their attached window.
225         */
226        public static final int TYPE_APPLICATION_PANEL  = FIRST_SUB_WINDOW;
227
228        /**
229         * Window type: window for showing media (e.g. video).  These windows
230         * are displayed behind their attached window.
231         */
232        public static final int TYPE_APPLICATION_MEDIA  = FIRST_SUB_WINDOW+1;
233
234        /**
235         * Window type: a sub-panel on top of an application window.  These
236         * windows are displayed on top their attached window and any
237         * {@link #TYPE_APPLICATION_PANEL} panels.
238         */
239        public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2;
240
241        /** Window type: like {@link #TYPE_APPLICATION_PANEL}, but layout
242         * of the window happens as that of a top-level window, <em>not</em>
243         * as a child of its container.
244         */
245        public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3;
246
247        /**
248         * Window type: window for showing overlays on top of media windows.
249         * These windows are displayed between TYPE_APPLICATION_MEDIA and the
250         * application window.  They should be translucent to be useful.  This
251         * is a big ugly hack so:
252         * @hide
253         */
254        public static final int TYPE_APPLICATION_MEDIA_OVERLAY  = FIRST_SUB_WINDOW+4;
255
256        /**
257         * End of types of sub-windows.
258         */
259        public static final int LAST_SUB_WINDOW         = 1999;
260
261        /**
262         * Start of system-specific window types.  These are not normally
263         * created by applications.
264         */
265        public static final int FIRST_SYSTEM_WINDOW     = 2000;
266
267        /**
268         * Window type: the status bar.  There can be only one status bar
269         * window; it is placed at the top of the screen, and all other
270         * windows are shifted down so they are below it.
271         */
272        public static final int TYPE_STATUS_BAR         = FIRST_SYSTEM_WINDOW;
273
274        /**
275         * Window type: the search bar.  There can be only one search bar
276         * window; it is placed at the top of the screen.
277         */
278        public static final int TYPE_SEARCH_BAR         = FIRST_SYSTEM_WINDOW+1;
279
280        /**
281         * Window type: phone.  These are non-application windows providing
282         * user interaction with the phone (in particular incoming calls).
283         * These windows are normally placed above all applications, but behind
284         * the status bar.
285         */
286        public static final int TYPE_PHONE              = FIRST_SYSTEM_WINDOW+2;
287
288        /**
289         * Window type: system window, such as low power alert. These windows
290         * are always on top of application windows.
291         */
292        public static final int TYPE_SYSTEM_ALERT       = FIRST_SYSTEM_WINDOW+3;
293
294        /**
295         * Window type: keyguard window.
296         */
297        public static final int TYPE_KEYGUARD           = FIRST_SYSTEM_WINDOW+4;
298
299        /**
300         * Window type: transient notifications.
301         */
302        public static final int TYPE_TOAST              = FIRST_SYSTEM_WINDOW+5;
303
304        /**
305         * Window type: system overlay windows, which need to be displayed
306         * on top of everything else.  These windows must not take input
307         * focus, or they will interfere with the keyguard.
308         */
309        public static final int TYPE_SYSTEM_OVERLAY     = FIRST_SYSTEM_WINDOW+6;
310
311        /**
312         * Window type: priority phone UI, which needs to be displayed even if
313         * the keyguard is active.  These windows must not take input
314         * focus, or they will interfere with the keyguard.
315         */
316        public static final int TYPE_PRIORITY_PHONE     = FIRST_SYSTEM_WINDOW+7;
317
318        /**
319         * Window type: panel that slides out from the status bar
320         */
321        public static final int TYPE_SYSTEM_DIALOG      = FIRST_SYSTEM_WINDOW+8;
322
323        /**
324         * Window type: dialogs that the keyguard shows
325         */
326        public static final int TYPE_KEYGUARD_DIALOG    = FIRST_SYSTEM_WINDOW+9;
327
328        /**
329         * Window type: internal system error windows, appear on top of
330         * everything they can.
331         */
332        public static final int TYPE_SYSTEM_ERROR       = FIRST_SYSTEM_WINDOW+10;
333
334        /**
335         * Window type: internal input methods windows, which appear above
336         * the normal UI.  Application windows may be resized or panned to keep
337         * the input focus visible while this window is displayed.
338         */
339        public static final int TYPE_INPUT_METHOD       = FIRST_SYSTEM_WINDOW+11;
340
341        /**
342         * Window type: internal input methods dialog windows, which appear above
343         * the current input method window.
344         */
345        public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12;
346
347        /**
348         * Window type: wallpaper window, placed behind any window that wants
349         * to sit on top of the wallpaper.
350         */
351        public static final int TYPE_WALLPAPER          = FIRST_SYSTEM_WINDOW+13;
352
353        /**
354         * Window type: panel that slides out from the status bar
355         */
356        public static final int TYPE_STATUS_BAR_PANEL   = FIRST_SYSTEM_WINDOW+14;
357
358        /**
359         * Window type: secure system overlay windows, which need to be displayed
360         * on top of everything else.  These windows must not take input
361         * focus, or they will interfere with the keyguard.
362         *
363         * This is exactly like {@link #TYPE_SYSTEM_OVERLAY} except that only the
364         * system itself is allowed to create these overlays.  Applications cannot
365         * obtain permission to create secure system overlays.
366         * @hide
367         */
368        public static final int TYPE_SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+15;
369
370        /**
371         * Window type: the drag-and-drop pseudowindow.  There is only one
372         * drag layer (at most), and it is placed on top of all other windows.
373         * @hide
374         */
375        public static final int TYPE_DRAG               = FIRST_SYSTEM_WINDOW+16;
376
377        /**
378         * End of types of system windows.
379         */
380        public static final int LAST_SYSTEM_WINDOW      = 2999;
381
382        /**
383         * Specifies what type of memory buffers should be used by this window.
384         * Default is normal.
385         *
386         * @see #MEMORY_TYPE_NORMAL
387         * @see #MEMORY_TYPE_PUSH_BUFFERS
388         */
389        public int memoryType;
390
391        /** Memory type: The window's surface is allocated in main memory. */
392        public static final int MEMORY_TYPE_NORMAL = 0;
393        /** Memory type: The window's surface is configured to be accessible
394         * by DMA engines and hardware accelerators.
395         * @deprecated this is ignored, this value is set automatically when needed.
396         */
397        @Deprecated
398        public static final int MEMORY_TYPE_HARDWARE = 1;
399        /** Memory type: The window's surface is configured to be accessible
400         * by graphics accelerators.
401         * @deprecated this is ignored, this value is set automatically when needed.
402         */
403        @Deprecated
404        public static final int MEMORY_TYPE_GPU = 2;
405        /** Memory type: The window's surface doesn't own its buffers and
406         * therefore cannot be locked. Instead the buffers are pushed to
407         * it through native binder calls. */
408        public static final int MEMORY_TYPE_PUSH_BUFFERS = 3;
409
410        /**
411         * Various behavioral options/flags.  Default is none.
412         *
413         * @see #FLAG_BLUR_BEHIND
414         * @see #FLAG_DIM_BEHIND
415         * @see #FLAG_NOT_FOCUSABLE
416         * @see #FLAG_NOT_TOUCHABLE
417         * @see #FLAG_NOT_TOUCH_MODAL
418         * @see #FLAG_LAYOUT_IN_SCREEN
419         * @see #FLAG_DITHER
420         * @see #FLAG_KEEP_SCREEN_ON
421         * @see #FLAG_FULLSCREEN
422         * @see #FLAG_FORCE_NOT_FULLSCREEN
423         * @see #FLAG_IGNORE_CHEEK_PRESSES
424         * @see #FLAG_HARDWARE_ACCELERATED
425         */
426        @ViewDebug.ExportedProperty(flagMapping = {
427            @ViewDebug.FlagToString(mask = FLAG_BLUR_BEHIND, equals = FLAG_BLUR_BEHIND,
428                    name = "FLAG_BLUR_BEHIND"),
429            @ViewDebug.FlagToString(mask = FLAG_DIM_BEHIND, equals = FLAG_DIM_BEHIND,
430                    name = "FLAG_DIM_BEHIND"),
431            @ViewDebug.FlagToString(mask = FLAG_NOT_FOCUSABLE, equals = FLAG_NOT_FOCUSABLE,
432                    name = "FLAG_NOT_FOCUSABLE"),
433            @ViewDebug.FlagToString(mask = FLAG_NOT_TOUCHABLE, equals = FLAG_NOT_TOUCHABLE,
434                    name = "FLAG_NOT_TOUCHABLE"),
435            @ViewDebug.FlagToString(mask = FLAG_NOT_TOUCH_MODAL, equals = FLAG_NOT_TOUCH_MODAL,
436                    name = "FLAG_NOT_TOUCH_MODAL"),
437            @ViewDebug.FlagToString(mask = FLAG_LAYOUT_IN_SCREEN, equals = FLAG_LAYOUT_IN_SCREEN,
438                    name = "FLAG_LAYOUT_IN_SCREEN"),
439            @ViewDebug.FlagToString(mask = FLAG_DITHER, equals = FLAG_DITHER,
440                    name = "FLAG_DITHER"),
441            @ViewDebug.FlagToString(mask = FLAG_TURN_SCREEN_ON, equals = FLAG_TURN_SCREEN_ON,
442                    name = "FLAG_TURN_SCREEN_ON"),
443            @ViewDebug.FlagToString(mask = FLAG_KEEP_SCREEN_ON, equals = FLAG_KEEP_SCREEN_ON,
444                    name = "FLAG_KEEP_SCREEN_ON"),
445            @ViewDebug.FlagToString(mask = FLAG_SHOW_WHEN_LOCKED, equals = FLAG_SHOW_WHEN_LOCKED,
446                    name = "FLAG_SHOW_WHEN_LOCKED"),
447            @ViewDebug.FlagToString(mask = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON, equals = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON,
448                    name = "FLAG_ALLOW_LOCK_WHILE_SCREEN_ON"),
449            @ViewDebug.FlagToString(mask = FLAG_DISMISS_KEYGUARD, equals = FLAG_DISMISS_KEYGUARD,
450                    name = "FLAG_DISMISS_KEYGUARD"),
451            @ViewDebug.FlagToString(mask = FLAG_FULLSCREEN, equals = FLAG_FULLSCREEN,
452                    name = "FLAG_FULLSCREEN"),
453            @ViewDebug.FlagToString(mask = FLAG_FORCE_NOT_FULLSCREEN,
454                    equals = FLAG_FORCE_NOT_FULLSCREEN, name = "FLAG_FORCE_NOT_FULLSCREEN"),
455            @ViewDebug.FlagToString(mask = FLAG_IGNORE_CHEEK_PRESSES,
456                    equals = FLAG_IGNORE_CHEEK_PRESSES, name = "FLAG_IGNORE_CHEEK_PRESSES"),
457            @ViewDebug.FlagToString(mask = FLAG_HARDWARE_ACCELERATED,
458                    equals = FLAG_HARDWARE_ACCELERATED, name = "FLAG_HARDWARE_ACCELERATED")
459        })
460        public int flags;
461
462        /** Window flag: as long as this window is visible to the user, allow
463         *  the lock screen to activate while the screen is on.
464         *  This can be used independently, or in combination with
465         *  {@link #FLAG_KEEP_SCREEN_ON} and/or {@link #FLAG_SHOW_WHEN_LOCKED} */
466        public static final int FLAG_ALLOW_LOCK_WHILE_SCREEN_ON     = 0x00000001;
467
468        /** Window flag: everything behind this window will be dimmed.
469         *  Use {@link #dimAmount} to control the amount of dim. */
470        public static final int FLAG_DIM_BEHIND        = 0x00000002;
471
472        /** Window flag: blur everything behind this window. */
473        public static final int FLAG_BLUR_BEHIND        = 0x00000004;
474
475        /** Window flag: this window won't ever get key input focus, so the
476         * user can not send key or other button events to it.  Those will
477         * instead go to whatever focusable window is behind it.  This flag
478         * will also enable {@link #FLAG_NOT_TOUCH_MODAL} whether or not that
479         * is explicitly set.
480         *
481         * <p>Setting this flag also implies that the window will not need to
482         * interact with
483         * a soft input method, so it will be Z-ordered and positioned
484         * independently of any active input method (typically this means it
485         * gets Z-ordered on top of the input method, so it can use the full
486         * screen for its content and cover the input method if needed.  You
487         * can use {@link #FLAG_ALT_FOCUSABLE_IM} to modify this behavior. */
488        public static final int FLAG_NOT_FOCUSABLE      = 0x00000008;
489
490        /** Window flag: this window can never receive touch events. */
491        public static final int FLAG_NOT_TOUCHABLE      = 0x00000010;
492
493        /** Window flag: Even when this window is focusable (its
494         * {@link #FLAG_NOT_FOCUSABLE is not set), allow any pointer events
495         * outside of the window to be sent to the windows behind it.  Otherwise
496         * it will consume all pointer events itself, regardless of whether they
497         * are inside of the window. */
498        public static final int FLAG_NOT_TOUCH_MODAL    = 0x00000020;
499
500        /** Window flag: When set, if the device is asleep when the touch
501         * screen is pressed, you will receive this first touch event.  Usually
502         * the first touch event is consumed by the system since the user can
503         * not see what they are pressing on.
504         */
505        public static final int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040;
506
507        /** Window flag: as long as this window is visible to the user, keep
508         *  the device's screen turned on and bright. */
509        public static final int FLAG_KEEP_SCREEN_ON     = 0x00000080;
510
511        /** Window flag: place the window within the entire screen, ignoring
512         *  decorations around the border (a.k.a. the status bar).  The
513         *  window must correctly position its contents to take the screen
514         *  decoration into account.  This flag is normally set for you
515         *  by Window as described in {@link Window#setFlags}. */
516        public static final int FLAG_LAYOUT_IN_SCREEN   = 0x00000100;
517
518        /** Window flag: allow window to extend outside of the screen. */
519        public static final int FLAG_LAYOUT_NO_LIMITS   = 0x00000200;
520
521        /** Window flag: Hide all screen decorations (e.g. status bar) while
522         * this window is displayed.  This allows the window to use the entire
523         * display space for itself -- the status bar will be hidden when
524         * an app window with this flag set is on the top layer. */
525        public static final int FLAG_FULLSCREEN      = 0x00000400;
526
527        /** Window flag: Override {@link #FLAG_FULLSCREEN and force the
528         *  screen decorations (such as status bar) to be shown. */
529        public static final int FLAG_FORCE_NOT_FULLSCREEN   = 0x00000800;
530
531        /** Window flag: turn on dithering when compositing this window to
532         *  the screen. */
533        public static final int FLAG_DITHER             = 0x00001000;
534
535        /** Window flag: don't allow screen shots while this window is
536         * displayed. */
537        public static final int FLAG_SECURE             = 0x00002000;
538
539        /** Window flag: a special mode where the layout parameters are used
540         * to perform scaling of the surface when it is composited to the
541         * screen. */
542        public static final int FLAG_SCALED             = 0x00004000;
543
544        /** Window flag: intended for windows that will often be used when the user is
545         * holding the screen against their face, it will aggressively filter the event
546         * stream to prevent unintended presses in this situation that may not be
547         * desired for a particular window, when such an event stream is detected, the
548         * application will receive a CANCEL motion event to indicate this so applications
549         * can handle this accordingly by taking no action on the event
550         * until the finger is released. */
551        public static final int FLAG_IGNORE_CHEEK_PRESSES    = 0x00008000;
552
553        /** Window flag: a special option only for use in combination with
554         * {@link #FLAG_LAYOUT_IN_SCREEN}.  When requesting layout in the
555         * screen your window may appear on top of or behind screen decorations
556         * such as the status bar.  By also including this flag, the window
557         * manager will report the inset rectangle needed to ensure your
558         * content is not covered by screen decorations.  This flag is normally
559         * set for you by Window as described in {@link Window#setFlags}.*/
560        public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000;
561
562        /** Window flag: invert the state of {@link #FLAG_NOT_FOCUSABLE} with
563         * respect to how this window interacts with the current method.  That
564         * is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the
565         * window will behave as if it needs to interact with the input method
566         * and thus be placed behind/away from it; if FLAG_NOT_FOCUSABLE is
567         * not set and this flag is set, then the window will behave as if it
568         * doesn't need to interact with the input method and can be placed
569         * to use more space and cover the input method.
570         */
571        public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000;
572
573        /** Window flag: if you have set {@link #FLAG_NOT_TOUCH_MODAL}, you
574         * can set this flag to receive a single special MotionEvent with
575         * the action
576         * {@link MotionEvent#ACTION_OUTSIDE MotionEvent.ACTION_OUTSIDE} for
577         * touches that occur outside of your window.  Note that you will not
578         * receive the full down/move/up gesture, only the location of the
579         * first down as an ACTION_OUTSIDE.
580         */
581        public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000;
582
583        /** Window flag: special flag to let windows be shown when the screen
584         * is locked. This will let application windows take precedence over
585         * key guard or any other lock screens. Can be used with
586         * {@link #FLAG_KEEP_SCREEN_ON} to turn screen on and display windows
587         * directly before showing the key guard window.  Can be used with
588         * {@link #FLAG_DISMISS_KEYGUARD} to automatically fully dismisss
589         * non-secure keyguards.  This flag only applies to the top-most
590         * full-screen window.
591         */
592        public static final int FLAG_SHOW_WHEN_LOCKED = 0x00080000;
593
594        /** Window flag: ask that the system wallpaper be shown behind
595         * your window.  The window surface must be translucent to be able
596         * to actually see the wallpaper behind it; this flag just ensures
597         * that the wallpaper surface will be there if this window actually
598         * has translucent regions.
599         */
600        public static final int FLAG_SHOW_WALLPAPER = 0x00100000;
601
602        /** Window flag: when set as a window is being added or made
603         * visible, once the window has been shown then the system will
604         * poke the power manager's user activity (as if the user had woken
605         * up the device) to turn the screen on. */
606        public static final int FLAG_TURN_SCREEN_ON = 0x00200000;
607
608        /** Window flag: when set the window will cause the keyguard to
609         * be dismissed, only if it is not a secure lock keyguard.  Because such
610         * a keyguard is not needed for security, it will never re-appear if
611         * the user navigates to another window (in contrast to
612         * {@link #FLAG_SHOW_WHEN_LOCKED}, which will only temporarily
613         * hide both secure and non-secure keyguards but ensure they reappear
614         * when the user moves to another UI that doesn't hide them).
615         * If the keyguard is currently active and is secure (requires an
616         * unlock pattern) than the user will still need to confirm it before
617         * seeing this window, unless {@link #FLAG_SHOW_WHEN_LOCKED} has
618         * also been set.
619         */
620        public static final int FLAG_DISMISS_KEYGUARD = 0x00400000;
621
622        /** Window flag: when set the window will accept for touch events
623         * outside of its bounds to be sent to other windows that also
624         * support split touch.  When this flag is not set, the first pointer
625         * that goes down determines the window to which all subsequent touches
626         * go until all pointers go up.  When this flag is set, each pointer
627         * (not necessarily the first) that goes down determines the window
628         * to which all subsequent touches of that pointer will go until that
629         * pointer goes up thereby enabling touches with multiple pointers
630         * to be split across multiple windows.
631         */
632        public static final int FLAG_SPLIT_TOUCH = 0x00800000;
633
634        /**
635         * Indicates whether this window should be hardware accelerated.
636         * Requesting hardware acceleration does not guarantee it will happen.
637         */
638        public static final int FLAG_HARDWARE_ACCELERATED = 0x01000000;
639
640        // ----- HIDDEN FLAGS.
641        // These start at the high bit and go down.
642
643        /**
644         * Flag for a window belonging to an activity that responds to {@link KeyEvent#KEYCODE_MENU}
645         * and therefore needs a Menu key. For devices where Menu is a physical button this flag is
646         * ignored, but on devices where the Menu key is drawn in software it may be hidden unless
647         * this flag is set.
648         *
649         * (Note that Action Bars, when available, are the preferred way to offer additional
650         * functions otherwise accessed via an options menu.)
651         *
652         * {@hide}
653         */
654        public static final int FLAG_NEEDS_MENU_KEY = 0x08000000;
655
656        /** Window flag: *sigh* The lock screen wants to continue running its
657         * animation while it is fading.  A kind-of hack to allow this.  Maybe
658         * in the future we just make this the default behavior.
659         *
660         * {@hide} */
661        public static final int FLAG_KEEP_SURFACE_WHILE_ANIMATING = 0x10000000;
662
663        /** Window flag: special flag to limit the size of the window to be
664         * original size ([320x480] x density). Used to create window for applications
665         * running under compatibility mode.
666         *
667         * {@hide} */
668        public static final int FLAG_COMPATIBLE_WINDOW = 0x20000000;
669
670        /** Window flag: a special option intended for system dialogs.  When
671         * this flag is set, the window will demand focus unconditionally when
672         * it is created.
673         * {@hide} */
674        public static final int FLAG_SYSTEM_ERROR = 0x40000000;
675
676        /**
677         * Given a particular set of window manager flags, determine whether
678         * such a window may be a target for an input method when it has
679         * focus.  In particular, this checks the
680         * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM}
681         * flags and returns true if the combination of the two corresponds
682         * to a window that needs to be behind the input method so that the
683         * user can type into it.
684         *
685         * @param flags The current window manager flags.
686         *
687         * @return Returns true if such a window should be behind/interact
688         * with an input method, false if not.
689         */
690        public static boolean mayUseInputMethod(int flags) {
691            switch (flags&(FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
692                case 0:
693                case FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM:
694                    return true;
695            }
696            return false;
697        }
698
699        /**
700         * Mask for {@link #softInputMode} of the bits that determine the
701         * desired visibility state of the soft input area for this window.
702         */
703        public static final int SOFT_INPUT_MASK_STATE = 0x0f;
704
705        /**
706         * Visibility state for {@link #softInputMode}: no state has been specified.
707         */
708        public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0;
709
710        /**
711         * Visibility state for {@link #softInputMode}: please don't change the state of
712         * the soft input area.
713         */
714        public static final int SOFT_INPUT_STATE_UNCHANGED = 1;
715
716        /**
717         * Visibility state for {@link #softInputMode}: please hide any soft input
718         * area when normally appropriate (when the user is navigating
719         * forward to your window).
720         */
721        public static final int SOFT_INPUT_STATE_HIDDEN = 2;
722
723        /**
724         * Visibility state for {@link #softInputMode}: please always hide any
725         * soft input area when this window receives focus.
726         */
727        public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3;
728
729        /**
730         * Visibility state for {@link #softInputMode}: please show the soft
731         * input area when normally appropriate (when the user is navigating
732         * forward to your window).
733         */
734        public static final int SOFT_INPUT_STATE_VISIBLE = 4;
735
736        /**
737         * Visibility state for {@link #softInputMode}: please always make the
738         * soft input area visible when this window receives input focus.
739         */
740        public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5;
741
742        /**
743         * Mask for {@link #softInputMode} of the bits that determine the
744         * way that the window should be adjusted to accommodate the soft
745         * input window.
746         */
747        public static final int SOFT_INPUT_MASK_ADJUST = 0xf0;
748
749        /** Adjustment option for {@link #softInputMode}: nothing specified.
750         * The system will try to pick one or
751         * the other depending on the contents of the window.
752         */
753        public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00;
754
755        /** Adjustment option for {@link #softInputMode}: set to allow the
756         * window to be resized when an input
757         * method is shown, so that its contents are not covered by the input
758         * method.  This can <em>not</em> be combined with
759         * {@link #SOFT_INPUT_ADJUST_PAN}; if
760         * neither of these are set, then the system will try to pick one or
761         * the other depending on the contents of the window.
762         */
763        public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10;
764
765        /** Adjustment option for {@link #softInputMode}: set to have a window
766         * pan when an input method is
767         * shown, so it doesn't need to deal with resizing but just panned
768         * by the framework to ensure the current input focus is visible.  This
769         * can <em>not</em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if
770         * neither of these are set, then the system will try to pick one or
771         * the other depending on the contents of the window.
772         */
773        public static final int SOFT_INPUT_ADJUST_PAN = 0x20;
774
775        /** Adjustment option for {@link #softInputMode}: set to have a window
776         * not adjust for a shown input method.  The window will not be resized,
777         * and it will not be panned to make its focus visible.
778         */
779        public static final int SOFT_INPUT_ADJUST_NOTHING = 0x30;
780
781        /**
782         * Bit for {@link #softInputMode}: set when the user has navigated
783         * forward to the window.  This is normally set automatically for
784         * you by the system, though you may want to set it in certain cases
785         * when you are displaying a window yourself.  This flag will always
786         * be cleared automatically after the window is displayed.
787         */
788        public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;
789
790        /**
791         * Desired operating mode for any soft input area.  May any combination
792         * of:
793         *
794         * <ul>
795         * <li> One of the visibility states
796         * {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED},
797         * {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}, or
798         * {@link #SOFT_INPUT_STATE_VISIBLE}.
799         * <li> One of the adjustment options
800         * {@link #SOFT_INPUT_ADJUST_UNSPECIFIED},
801         * {@link #SOFT_INPUT_ADJUST_RESIZE}, or
802         * {@link #SOFT_INPUT_ADJUST_PAN}.
803         */
804        public int softInputMode;
805
806        /**
807         * Placement of window within the screen as per {@link Gravity}.  Both
808         * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
809         * android.graphics.Rect) Gravity.apply} and
810         * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect)
811         * Gravity.applyDisplay} are used during window layout, with this value
812         * given as the desired gravity.  For example you can specify
813         * {@link Gravity#DISPLAY_CLIP_HORIZONTAL Gravity.DISPLAY_CLIP_HORIZONTAL} and
814         * {@link Gravity#DISPLAY_CLIP_VERTICAL Gravity.DISPLAY_CLIP_VERTICAL} here
815         * to control the behavior of
816         * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect)
817         * Gravity.applyDisplay}.
818         *
819         * @see Gravity
820         */
821        public int gravity;
822
823        /**
824         * The horizontal margin, as a percentage of the container's width,
825         * between the container and the widget.  See
826         * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
827         * android.graphics.Rect) Gravity.apply} for how this is used.  This
828         * field is added with {@link #x} to supply the <var>xAdj</var> parameter.
829         */
830        public float horizontalMargin;
831
832        /**
833         * The vertical margin, as a percentage of the container's height,
834         * between the container and the widget.  See
835         * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
836         * android.graphics.Rect) Gravity.apply} for how this is used.  This
837         * field is added with {@link #y} to supply the <var>yAdj</var> parameter.
838         */
839        public float verticalMargin;
840
841        /**
842         * The desired bitmap format.  May be one of the constants in
843         * {@link android.graphics.PixelFormat}.  Default is OPAQUE.
844         */
845        public int format;
846
847        /**
848         * A style resource defining the animations to use for this window.
849         * This must be a system resource; it can not be an application resource
850         * because the window manager does not have access to applications.
851         */
852        public int windowAnimations;
853
854        /**
855         * An alpha value to apply to this entire window.
856         * An alpha of 1.0 means fully opaque and 0.0 means fully transparent
857         */
858        public float alpha = 1.0f;
859
860        /**
861         * When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming
862         * to apply.  Range is from 1.0 for completely opaque to 0.0 for no
863         * dim.
864         */
865        public float dimAmount = 1.0f;
866
867        /**
868         * Default value for {@link #screenBrightness} and {@link #buttonBrightness}
869         * indicating that the brightness value is not overridden for this window
870         * and normal brightness policy should be used.
871         */
872        public static final float BRIGHTNESS_OVERRIDE_NONE = -1.0f;
873
874        /**
875         * Value for {@link #screenBrightness} and {@link #buttonBrightness}
876         * indicating that the screen or button backlight brightness should be set
877         * to the lowest value when this window is in front.
878         */
879        public static final float BRIGHTNESS_OVERRIDE_OFF = 0.0f;
880
881        /**
882         * Value for {@link #screenBrightness} and {@link #buttonBrightness}
883         * indicating that the screen or button backlight brightness should be set
884         * to the hightest value when this window is in front.
885         */
886        public static final float BRIGHTNESS_OVERRIDE_FULL = 1.0f;
887
888        /**
889         * This can be used to override the user's preferred brightness of
890         * the screen.  A value of less than 0, the default, means to use the
891         * preferred screen brightness.  0 to 1 adjusts the brightness from
892         * dark to full bright.
893         */
894        public float screenBrightness = BRIGHTNESS_OVERRIDE_NONE;
895
896        /**
897         * This can be used to override the standard behavior of the button and
898         * keyboard backlights.  A value of less than 0, the default, means to
899         * use the standard backlight behavior.  0 to 1 adjusts the brightness
900         * from dark to full bright.
901         */
902        public float buttonBrightness = BRIGHTNESS_OVERRIDE_NONE;
903
904        /**
905         * Identifier for this window.  This will usually be filled in for
906         * you.
907         */
908        public IBinder token = null;
909
910        /**
911         * Name of the package owning this window.
912         */
913        public String packageName = null;
914
915        /**
916         * Specific orientation value for a window.
917         * May be any of the same values allowed
918         * for {@link android.content.pm.ActivityInfo#screenOrientation}.
919         * If not set, a default value of
920         * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}
921         * will be used.
922         */
923        public int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
924
925
926        public LayoutParams() {
927            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
928            type = TYPE_APPLICATION;
929            format = PixelFormat.OPAQUE;
930        }
931
932        public LayoutParams(int _type) {
933            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
934            type = _type;
935            format = PixelFormat.OPAQUE;
936        }
937
938        public LayoutParams(int _type, int _flags) {
939            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
940            type = _type;
941            flags = _flags;
942            format = PixelFormat.OPAQUE;
943        }
944
945        public LayoutParams(int _type, int _flags, int _format) {
946            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
947            type = _type;
948            flags = _flags;
949            format = _format;
950        }
951
952        public LayoutParams(int w, int h, int _type, int _flags, int _format) {
953            super(w, h);
954            type = _type;
955            flags = _flags;
956            format = _format;
957        }
958
959        public LayoutParams(int w, int h, int xpos, int ypos, int _type,
960                int _flags, int _format) {
961            super(w, h);
962            x = xpos;
963            y = ypos;
964            type = _type;
965            flags = _flags;
966            format = _format;
967        }
968
969        public final void setTitle(CharSequence title) {
970            if (null == title)
971                title = "";
972
973            mTitle = TextUtils.stringOrSpannedString(title);
974        }
975
976        public final CharSequence getTitle() {
977            return mTitle;
978        }
979
980        public int describeContents() {
981            return 0;
982        }
983
984        public void writeToParcel(Parcel out, int parcelableFlags) {
985            out.writeInt(width);
986            out.writeInt(height);
987            out.writeInt(x);
988            out.writeInt(y);
989            out.writeInt(type);
990            out.writeInt(memoryType);
991            out.writeInt(flags);
992            out.writeInt(softInputMode);
993            out.writeInt(gravity);
994            out.writeFloat(horizontalMargin);
995            out.writeFloat(verticalMargin);
996            out.writeInt(format);
997            out.writeInt(windowAnimations);
998            out.writeFloat(alpha);
999            out.writeFloat(dimAmount);
1000            out.writeFloat(screenBrightness);
1001            out.writeFloat(buttonBrightness);
1002            out.writeStrongBinder(token);
1003            out.writeString(packageName);
1004            TextUtils.writeToParcel(mTitle, out, parcelableFlags);
1005            out.writeInt(screenOrientation);
1006        }
1007
1008        public static final Parcelable.Creator<LayoutParams> CREATOR
1009                    = new Parcelable.Creator<LayoutParams>() {
1010            public LayoutParams createFromParcel(Parcel in) {
1011                return new LayoutParams(in);
1012            }
1013
1014            public LayoutParams[] newArray(int size) {
1015                return new LayoutParams[size];
1016            }
1017        };
1018
1019
1020        public LayoutParams(Parcel in) {
1021            width = in.readInt();
1022            height = in.readInt();
1023            x = in.readInt();
1024            y = in.readInt();
1025            type = in.readInt();
1026            memoryType = in.readInt();
1027            flags = in.readInt();
1028            softInputMode = in.readInt();
1029            gravity = in.readInt();
1030            horizontalMargin = in.readFloat();
1031            verticalMargin = in.readFloat();
1032            format = in.readInt();
1033            windowAnimations = in.readInt();
1034            alpha = in.readFloat();
1035            dimAmount = in.readFloat();
1036            screenBrightness = in.readFloat();
1037            buttonBrightness = in.readFloat();
1038            token = in.readStrongBinder();
1039            packageName = in.readString();
1040            mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
1041            screenOrientation = in.readInt();
1042        }
1043
1044        @SuppressWarnings({"PointlessBitwiseExpression"})
1045        public static final int LAYOUT_CHANGED = 1<<0;
1046        public static final int TYPE_CHANGED = 1<<1;
1047        public static final int FLAGS_CHANGED = 1<<2;
1048        public static final int FORMAT_CHANGED = 1<<3;
1049        public static final int ANIMATION_CHANGED = 1<<4;
1050        public static final int DIM_AMOUNT_CHANGED = 1<<5;
1051        public static final int TITLE_CHANGED = 1<<6;
1052        public static final int ALPHA_CHANGED = 1<<7;
1053        public static final int MEMORY_TYPE_CHANGED = 1<<8;
1054        public static final int SOFT_INPUT_MODE_CHANGED = 1<<9;
1055        public static final int SCREEN_ORIENTATION_CHANGED = 1<<10;
1056        public static final int SCREEN_BRIGHTNESS_CHANGED = 1<<11;
1057        /** {@hide} */
1058        public static final int BUTTON_BRIGHTNESS_CHANGED = 1<<12;
1059
1060        // internal buffer to backup/restore parameters under compatibility mode.
1061        private int[] mCompatibilityParamsBackup = null;
1062
1063        public final int copyFrom(LayoutParams o) {
1064            int changes = 0;
1065
1066            if (width != o.width) {
1067                width = o.width;
1068                changes |= LAYOUT_CHANGED;
1069            }
1070            if (height != o.height) {
1071                height = o.height;
1072                changes |= LAYOUT_CHANGED;
1073            }
1074            if (x != o.x) {
1075                x = o.x;
1076                changes |= LAYOUT_CHANGED;
1077            }
1078            if (y != o.y) {
1079                y = o.y;
1080                changes |= LAYOUT_CHANGED;
1081            }
1082            if (horizontalWeight != o.horizontalWeight) {
1083                horizontalWeight = o.horizontalWeight;
1084                changes |= LAYOUT_CHANGED;
1085            }
1086            if (verticalWeight != o.verticalWeight) {
1087                verticalWeight = o.verticalWeight;
1088                changes |= LAYOUT_CHANGED;
1089            }
1090            if (horizontalMargin != o.horizontalMargin) {
1091                horizontalMargin = o.horizontalMargin;
1092                changes |= LAYOUT_CHANGED;
1093            }
1094            if (verticalMargin != o.verticalMargin) {
1095                verticalMargin = o.verticalMargin;
1096                changes |= LAYOUT_CHANGED;
1097            }
1098            if (type != o.type) {
1099                type = o.type;
1100                changes |= TYPE_CHANGED;
1101            }
1102            if (memoryType != o.memoryType) {
1103                memoryType = o.memoryType;
1104                changes |= MEMORY_TYPE_CHANGED;
1105            }
1106            if (flags != o.flags) {
1107                flags = o.flags;
1108                changes |= FLAGS_CHANGED;
1109            }
1110            if (softInputMode != o.softInputMode) {
1111                softInputMode = o.softInputMode;
1112                changes |= SOFT_INPUT_MODE_CHANGED;
1113            }
1114            if (gravity != o.gravity) {
1115                gravity = o.gravity;
1116                changes |= LAYOUT_CHANGED;
1117            }
1118            if (horizontalMargin != o.horizontalMargin) {
1119                horizontalMargin = o.horizontalMargin;
1120                changes |= LAYOUT_CHANGED;
1121            }
1122            if (verticalMargin != o.verticalMargin) {
1123                verticalMargin = o.verticalMargin;
1124                changes |= LAYOUT_CHANGED;
1125            }
1126            if (format != o.format) {
1127                format = o.format;
1128                changes |= FORMAT_CHANGED;
1129            }
1130            if (windowAnimations != o.windowAnimations) {
1131                windowAnimations = o.windowAnimations;
1132                changes |= ANIMATION_CHANGED;
1133            }
1134            if (token == null) {
1135                // NOTE: token only copied if the recipient doesn't
1136                // already have one.
1137                token = o.token;
1138            }
1139            if (packageName == null) {
1140                // NOTE: packageName only copied if the recipient doesn't
1141                // already have one.
1142                packageName = o.packageName;
1143            }
1144            if (!mTitle.equals(o.mTitle)) {
1145                mTitle = o.mTitle;
1146                changes |= TITLE_CHANGED;
1147            }
1148            if (alpha != o.alpha) {
1149                alpha = o.alpha;
1150                changes |= ALPHA_CHANGED;
1151            }
1152            if (dimAmount != o.dimAmount) {
1153                dimAmount = o.dimAmount;
1154                changes |= DIM_AMOUNT_CHANGED;
1155            }
1156            if (screenBrightness != o.screenBrightness) {
1157                screenBrightness = o.screenBrightness;
1158                changes |= SCREEN_BRIGHTNESS_CHANGED;
1159            }
1160            if (buttonBrightness != o.buttonBrightness) {
1161                buttonBrightness = o.buttonBrightness;
1162                changes |= BUTTON_BRIGHTNESS_CHANGED;
1163            }
1164
1165            if (screenOrientation != o.screenOrientation) {
1166                screenOrientation = o.screenOrientation;
1167                changes |= SCREEN_ORIENTATION_CHANGED;
1168            }
1169
1170            return changes;
1171        }
1172
1173        @Override
1174        public String debug(String output) {
1175            output += "Contents of " + this + ":";
1176            Log.d("Debug", output);
1177            output = super.debug("");
1178            Log.d("Debug", output);
1179            Log.d("Debug", "");
1180            Log.d("Debug", "WindowManager.LayoutParams={title=" + mTitle + "}");
1181            return "";
1182        }
1183
1184        @Override
1185        public String toString() {
1186            StringBuilder sb = new StringBuilder(256);
1187            sb.append("WM.LayoutParams{");
1188            sb.append("(");
1189            sb.append(x);
1190            sb.append(',');
1191            sb.append(y);
1192            sb.append(")(");
1193            sb.append((width== MATCH_PARENT ?"fill":(width==WRAP_CONTENT?"wrap":width)));
1194            sb.append('x');
1195            sb.append((height== MATCH_PARENT ?"fill":(height==WRAP_CONTENT?"wrap":height)));
1196            sb.append(")");
1197            if (horizontalMargin != 0) {
1198                sb.append(" hm=");
1199                sb.append(horizontalMargin);
1200            }
1201            if (verticalMargin != 0) {
1202                sb.append(" vm=");
1203                sb.append(verticalMargin);
1204            }
1205            if (gravity != 0) {
1206                sb.append(" gr=#");
1207                sb.append(Integer.toHexString(gravity));
1208            }
1209            if (softInputMode != 0) {
1210                sb.append(" sim=#");
1211                sb.append(Integer.toHexString(softInputMode));
1212            }
1213            sb.append(" ty=");
1214            sb.append(type);
1215            sb.append(" fl=#");
1216            sb.append(Integer.toHexString(flags));
1217            sb.append(" fmt=");
1218            sb.append(format);
1219            if (windowAnimations != 0) {
1220                sb.append(" wanim=0x");
1221                sb.append(Integer.toHexString(windowAnimations));
1222            }
1223            if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
1224                sb.append(" or=");
1225                sb.append(screenOrientation);
1226            }
1227            if (alpha != 1.0f) {
1228                sb.append(" alpha=");
1229                sb.append(alpha);
1230            }
1231            if (screenBrightness != BRIGHTNESS_OVERRIDE_NONE) {
1232                sb.append(" sbrt=");
1233                sb.append(screenBrightness);
1234            }
1235            if (buttonBrightness != BRIGHTNESS_OVERRIDE_NONE) {
1236                sb.append(" bbrt=");
1237                sb.append(buttonBrightness);
1238            }
1239            if ((flags & FLAG_COMPATIBLE_WINDOW) != 0) {
1240                sb.append(" compatible=true");
1241            }
1242            sb.append('}');
1243            return sb.toString();
1244        }
1245
1246        /**
1247         * Scale the layout params' coordinates and size.
1248         * @hide
1249         */
1250        public void scale(float scale) {
1251            x = (int) (x * scale + 0.5f);
1252            y = (int) (y * scale + 0.5f);
1253            if (width > 0) {
1254                width = (int) (width * scale + 0.5f);
1255            }
1256            if (height > 0) {
1257                height = (int) (height * scale + 0.5f);
1258            }
1259        }
1260
1261        /**
1262         * Backup the layout parameters used in compatibility mode.
1263         * @see LayoutParams#restore()
1264         */
1265        void backup() {
1266            int[] backup = mCompatibilityParamsBackup;
1267            if (backup == null) {
1268                // we backup 4 elements, x, y, width, height
1269                backup = mCompatibilityParamsBackup = new int[4];
1270            }
1271            backup[0] = x;
1272            backup[1] = y;
1273            backup[2] = width;
1274            backup[3] = height;
1275        }
1276
1277        /**
1278         * Restore the layout params' coordinates, size and gravity
1279         * @see LayoutParams#backup()
1280         */
1281        void restore() {
1282            int[] backup = mCompatibilityParamsBackup;
1283            if (backup != null) {
1284                x = backup[0];
1285                y = backup[1];
1286                width = backup[2];
1287                height = backup[3];
1288            }
1289        }
1290
1291        private CharSequence mTitle = "";
1292    }
1293}
1294