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