Window.java revision aa1008cba4b97a269f65f86534d994347b6cdeff
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.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.SystemApi;
22import android.content.Context;
23import android.content.res.Configuration;
24import android.content.res.Resources;
25import android.content.res.TypedArray;
26import android.graphics.PixelFormat;
27import android.graphics.drawable.Drawable;
28import android.media.session.MediaController;
29import android.net.Uri;
30import android.os.Bundle;
31import android.os.IBinder;
32import android.os.SystemProperties;
33import android.transition.Scene;
34import android.transition.Transition;
35import android.transition.TransitionManager;
36import android.view.accessibility.AccessibilityEvent;
37
38/**
39 * Abstract base class for a top-level window look and behavior policy.  An
40 * instance of this class should be used as the top-level view added to the
41 * window manager. It provides standard UI policies such as a background, title
42 * area, default key processing, etc.
43 *
44 * <p>The only existing implementation of this abstract class is
45 * android.policy.PhoneWindow, which you should instantiate when needing a
46 * Window.  Eventually that class will be refactored and a factory method
47 * added for creating Window instances without knowing about a particular
48 * implementation.
49 */
50public abstract class Window {
51    /** Flag for the "options panel" feature.  This is enabled by default. */
52    public static final int FEATURE_OPTIONS_PANEL = 0;
53    /** Flag for the "no title" feature, turning off the title at the top
54     *  of the screen. */
55    public static final int FEATURE_NO_TITLE = 1;
56    /** Flag for the progress indicator feature */
57    public static final int FEATURE_PROGRESS = 2;
58    /** Flag for having an icon on the left side of the title bar */
59    public static final int FEATURE_LEFT_ICON = 3;
60    /** Flag for having an icon on the right side of the title bar */
61    public static final int FEATURE_RIGHT_ICON = 4;
62    /** Flag for indeterminate progress */
63    public static final int FEATURE_INDETERMINATE_PROGRESS = 5;
64    /** Flag for the context menu.  This is enabled by default. */
65    public static final int FEATURE_CONTEXT_MENU = 6;
66    /** Flag for custom title. You cannot combine this feature with other title features. */
67    public static final int FEATURE_CUSTOM_TITLE = 7;
68    /**
69     * Flag for enabling the Action Bar.
70     * This is enabled by default for some devices. The Action Bar
71     * replaces the title bar and provides an alternate location
72     * for an on-screen menu button on some devices.
73     */
74    public static final int FEATURE_ACTION_BAR = 8;
75    /**
76     * Flag for requesting an Action Bar that overlays window content.
77     * Normally an Action Bar will sit in the space above window content, but if this
78     * feature is requested along with {@link #FEATURE_ACTION_BAR} it will be layered over
79     * the window content itself. This is useful if you would like your app to have more control
80     * over how the Action Bar is displayed, such as letting application content scroll beneath
81     * an Action Bar with a transparent background or otherwise displaying a transparent/translucent
82     * Action Bar over application content.
83     *
84     * <p>This mode is especially useful with {@link View#SYSTEM_UI_FLAG_FULLSCREEN
85     * View.SYSTEM_UI_FLAG_FULLSCREEN}, which allows you to seamlessly hide the
86     * action bar in conjunction with other screen decorations.
87     *
88     * <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, when an
89     * ActionBar is in this mode it will adjust the insets provided to
90     * {@link View#fitSystemWindows(android.graphics.Rect) View.fitSystemWindows(Rect)}
91     * to include the content covered by the action bar, so you can do layout within
92     * that space.
93     */
94    public static final int FEATURE_ACTION_BAR_OVERLAY = 9;
95    /**
96     * Flag for specifying the behavior of action modes when an Action Bar is not present.
97     * If overlay is enabled, the action mode UI will be allowed to cover existing window content.
98     */
99    public static final int FEATURE_ACTION_MODE_OVERLAY = 10;
100    /**
101     * Flag for requesting a decoration-free window that is dismissed by swiping from the left.
102     */
103    public static final int FEATURE_SWIPE_TO_DISMISS = 11;
104    /**
105     * Flag for requesting that window content changes should be represented
106     * with scenes and transitions.
107     *
108     * TODO Add docs
109     *
110     * @see #setContentView
111     */
112    public static final int FEATURE_CONTENT_TRANSITIONS = 12;
113
114    /**
115     * Enables Activities to run Activity Transitions either through sending or receiving
116     * ActivityOptions bundle created with
117     * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(android.app.Activity,
118     * android.util.Pair[])} or {@link android.app.ActivityOptions#makeSceneTransitionAnimation(
119     * android.app.Activity, View, String)}.
120     */
121    public static final int FEATURE_ACTIVITY_TRANSITIONS = 13;
122
123    /**
124     * Max value used as a feature ID
125     * @hide
126     */
127    public static final int FEATURE_MAX = FEATURE_ACTIVITY_TRANSITIONS;
128
129    /** Flag for setting the progress bar's visibility to VISIBLE */
130    public static final int PROGRESS_VISIBILITY_ON = -1;
131    /** Flag for setting the progress bar's visibility to GONE */
132    public static final int PROGRESS_VISIBILITY_OFF = -2;
133    /** Flag for setting the progress bar's indeterminate mode on */
134    public static final int PROGRESS_INDETERMINATE_ON = -3;
135    /** Flag for setting the progress bar's indeterminate mode off */
136    public static final int PROGRESS_INDETERMINATE_OFF = -4;
137    /** Starting value for the (primary) progress */
138    public static final int PROGRESS_START = 0;
139    /** Ending value for the (primary) progress */
140    public static final int PROGRESS_END = 10000;
141    /** Lowest possible value for the secondary progress */
142    public static final int PROGRESS_SECONDARY_START = 20000;
143    /** Highest possible value for the secondary progress */
144    public static final int PROGRESS_SECONDARY_END = 30000;
145
146    /**
147     * The transitionName for the status bar background View when a custom background is used.
148     * @see android.view.Window#setStatusBarColor(int)
149     */
150    public static final String STATUS_BAR_BACKGROUND_TRANSITION_NAME = "android:status:background";
151
152    /**
153     * The transitionName for the navigation bar background View when a custom background is used.
154     * @see android.view.Window#setNavigationBarColor(int)
155     */
156    public static final String NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME =
157            "android:navigation:background";
158
159    /**
160     * The default features enabled.
161     * @deprecated use {@link #getDefaultFeatures(android.content.Context)} instead.
162     */
163    @Deprecated
164    @SuppressWarnings({"PointlessBitwiseExpression"})
165    protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) |
166            (1 << FEATURE_CONTEXT_MENU);
167
168    /**
169     * The ID that the main layout in the XML layout file should have.
170     */
171    public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content;
172
173    private static final String PROPERTY_HARDWARE_UI = "persist.sys.ui.hw";
174
175    private final Context mContext;
176
177    private TypedArray mWindowStyle;
178    private Callback mCallback;
179    private OnWindowDismissedCallback mOnWindowDismissedCallback;
180    private WindowManager mWindowManager;
181    private IBinder mAppToken;
182    private String mAppName;
183    private boolean mHardwareAccelerated;
184    private Window mContainer;
185    private Window mActiveChild;
186    private boolean mIsActive = false;
187    private boolean mHasChildren = false;
188    private boolean mCloseOnTouchOutside = false;
189    private boolean mSetCloseOnTouchOutside = false;
190    private int mForcedWindowFlags = 0;
191
192    private int mFeatures;
193    private int mLocalFeatures;
194
195    private boolean mHaveWindowFormat = false;
196    private boolean mHaveDimAmount = false;
197    private int mDefaultWindowFormat = PixelFormat.OPAQUE;
198
199    private boolean mHasSoftInputMode = false;
200
201    private boolean mDestroyed;
202
203    // The current window attributes.
204    private final WindowManager.LayoutParams mWindowAttributes =
205        new WindowManager.LayoutParams();
206
207    /**
208     * API from a Window back to its caller.  This allows the client to
209     * intercept key dispatching, panels and menus, etc.
210     */
211    public interface Callback {
212        /**
213         * Called to process key events.  At the very least your
214         * implementation must call
215         * {@link android.view.Window#superDispatchKeyEvent} to do the
216         * standard key processing.
217         *
218         * @param event The key event.
219         *
220         * @return boolean Return true if this event was consumed.
221         */
222        public boolean dispatchKeyEvent(KeyEvent event);
223
224        /**
225         * Called to process a key shortcut event.
226         * At the very least your implementation must call
227         * {@link android.view.Window#superDispatchKeyShortcutEvent} to do the
228         * standard key shortcut processing.
229         *
230         * @param event The key shortcut event.
231         * @return True if this event was consumed.
232         */
233        public boolean dispatchKeyShortcutEvent(KeyEvent event);
234
235        /**
236         * Called to process touch screen events.  At the very least your
237         * implementation must call
238         * {@link android.view.Window#superDispatchTouchEvent} to do the
239         * standard touch screen processing.
240         *
241         * @param event The touch screen event.
242         *
243         * @return boolean Return true if this event was consumed.
244         */
245        public boolean dispatchTouchEvent(MotionEvent event);
246
247        /**
248         * Called to process trackball events.  At the very least your
249         * implementation must call
250         * {@link android.view.Window#superDispatchTrackballEvent} to do the
251         * standard trackball processing.
252         *
253         * @param event The trackball event.
254         *
255         * @return boolean Return true if this event was consumed.
256         */
257        public boolean dispatchTrackballEvent(MotionEvent event);
258
259        /**
260         * Called to process generic motion events.  At the very least your
261         * implementation must call
262         * {@link android.view.Window#superDispatchGenericMotionEvent} to do the
263         * standard processing.
264         *
265         * @param event The generic motion event.
266         *
267         * @return boolean Return true if this event was consumed.
268         */
269        public boolean dispatchGenericMotionEvent(MotionEvent event);
270
271        /**
272         * Called to process population of {@link AccessibilityEvent}s.
273         *
274         * @param event The event.
275         *
276         * @return boolean Return true if event population was completed.
277         */
278        public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event);
279
280        /**
281         * Instantiate the view to display in the panel for 'featureId'.
282         * You can return null, in which case the default content (typically
283         * a menu) will be created for you.
284         *
285         * @param featureId Which panel is being created.
286         *
287         * @return view The top-level view to place in the panel.
288         *
289         * @see #onPreparePanel
290         */
291        @Nullable
292        public View onCreatePanelView(int featureId);
293
294        /**
295         * Initialize the contents of the menu for panel 'featureId'.  This is
296         * called if onCreatePanelView() returns null, giving you a standard
297         * menu in which you can place your items.  It is only called once for
298         * the panel, the first time it is shown.
299         *
300         * <p>You can safely hold on to <var>menu</var> (and any items created
301         * from it), making modifications to it as desired, until the next
302         * time onCreatePanelMenu() is called for this feature.
303         *
304         * @param featureId The panel being created.
305         * @param menu The menu inside the panel.
306         *
307         * @return boolean You must return true for the panel to be displayed;
308         *         if you return false it will not be shown.
309         */
310        public boolean onCreatePanelMenu(int featureId, Menu menu);
311
312        /**
313         * Prepare a panel to be displayed.  This is called right before the
314         * panel window is shown, every time it is shown.
315         *
316         * @param featureId The panel that is being displayed.
317         * @param view The View that was returned by onCreatePanelView().
318         * @param menu If onCreatePanelView() returned null, this is the Menu
319         *             being displayed in the panel.
320         *
321         * @return boolean You must return true for the panel to be displayed;
322         *         if you return false it will not be shown.
323         *
324         * @see #onCreatePanelView
325         */
326        public boolean onPreparePanel(int featureId, View view, Menu menu);
327
328        /**
329         * Called when a panel's menu is opened by the user. This may also be
330         * called when the menu is changing from one type to another (for
331         * example, from the icon menu to the expanded menu).
332         *
333         * @param featureId The panel that the menu is in.
334         * @param menu The menu that is opened.
335         * @return Return true to allow the menu to open, or false to prevent
336         *         the menu from opening.
337         */
338        public boolean onMenuOpened(int featureId, Menu menu);
339
340        /**
341         * Called when a panel's menu item has been selected by the user.
342         *
343         * @param featureId The panel that the menu is in.
344         * @param item The menu item that was selected.
345         *
346         * @return boolean Return true to finish processing of selection, or
347         *         false to perform the normal menu handling (calling its
348         *         Runnable or sending a Message to its target Handler).
349         */
350        public boolean onMenuItemSelected(int featureId, MenuItem item);
351
352        /**
353         * This is called whenever the current window attributes change.
354         *
355         */
356        public void onWindowAttributesChanged(WindowManager.LayoutParams attrs);
357
358        /**
359         * This hook is called whenever the content view of the screen changes
360         * (due to a call to
361         * {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams)
362         * Window.setContentView} or
363         * {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams)
364         * Window.addContentView}).
365         */
366        public void onContentChanged();
367
368        /**
369         * This hook is called whenever the window focus changes.  See
370         * {@link View#onWindowFocusChanged(boolean)
371         * View.onWindowFocusChangedNotLocked(boolean)} for more information.
372         *
373         * @param hasFocus Whether the window now has focus.
374         */
375        public void onWindowFocusChanged(boolean hasFocus);
376
377        /**
378         * Called when the window has been attached to the window manager.
379         * See {@link View#onAttachedToWindow() View.onAttachedToWindow()}
380         * for more information.
381         */
382        public void onAttachedToWindow();
383
384        /**
385         * Called when the window has been attached to the window manager.
386         * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()}
387         * for more information.
388         */
389        public void onDetachedFromWindow();
390
391        /**
392         * Called when a panel is being closed.  If another logical subsequent
393         * panel is being opened (and this panel is being closed to make room for the subsequent
394         * panel), this method will NOT be called.
395         *
396         * @param featureId The panel that is being displayed.
397         * @param menu If onCreatePanelView() returned null, this is the Menu
398         *            being displayed in the panel.
399         */
400        public void onPanelClosed(int featureId, Menu menu);
401
402        /**
403         * Called when the user signals the desire to start a search.
404         *
405         * @return true if search launched, false if activity refuses (blocks)
406         *
407         * @see android.app.Activity#onSearchRequested()
408         */
409        public boolean onSearchRequested();
410
411        /**
412         * Called when an action mode is being started for this window. Gives the
413         * callback an opportunity to handle the action mode in its own unique and
414         * beautiful way. If this method returns null the system can choose a way
415         * to present the mode or choose not to start the mode at all.
416         *
417         * @param callback Callback to control the lifecycle of this action mode
418         * @return The ActionMode that was started, or null if the system should present it
419         */
420        @Nullable
421        public ActionMode onWindowStartingActionMode(ActionMode.Callback callback);
422
423        /**
424         * Called when an action mode has been started. The appropriate mode callback
425         * method will have already been invoked.
426         *
427         * @param mode The new mode that has just been started.
428         */
429        public void onActionModeStarted(ActionMode mode);
430
431        /**
432         * Called when an action mode has been finished. The appropriate mode callback
433         * method will have already been invoked.
434         *
435         * @param mode The mode that was just finished.
436         */
437        public void onActionModeFinished(ActionMode mode);
438    }
439
440    /** @hide */
441    public interface OnWindowDismissedCallback {
442        /**
443         * Called when a window is dismissed. This informs the callback that the
444         * window is gone, and it should finish itself.
445         */
446        public void onWindowDismissed();
447    }
448
449    public Window(Context context) {
450        mContext = context;
451        mFeatures = mLocalFeatures = getDefaultFeatures(context);
452    }
453
454    /**
455     * Return the Context this window policy is running in, for retrieving
456     * resources and other information.
457     *
458     * @return Context The Context that was supplied to the constructor.
459     */
460    public final Context getContext() {
461        return mContext;
462    }
463
464    /**
465     * Return the {@link android.R.styleable#Window} attributes from this
466     * window's theme.
467     */
468    public final TypedArray getWindowStyle() {
469        synchronized (this) {
470            if (mWindowStyle == null) {
471                mWindowStyle = mContext.obtainStyledAttributes(
472                        com.android.internal.R.styleable.Window);
473            }
474            return mWindowStyle;
475        }
476    }
477
478    /**
479     * Set the container for this window.  If not set, the DecorWindow
480     * operates as a top-level window; otherwise, it negotiates with the
481     * container to display itself appropriately.
482     *
483     * @param container The desired containing Window.
484     */
485    public void setContainer(Window container) {
486        mContainer = container;
487        if (container != null) {
488            // Embedded screens never have a title.
489            mFeatures |= 1<<FEATURE_NO_TITLE;
490            mLocalFeatures |= 1<<FEATURE_NO_TITLE;
491            container.mHasChildren = true;
492        }
493    }
494
495    /**
496     * Return the container for this Window.
497     *
498     * @return Window The containing window, or null if this is a
499     *         top-level window.
500     */
501    public final Window getContainer() {
502        return mContainer;
503    }
504
505    public final boolean hasChildren() {
506        return mHasChildren;
507    }
508
509    /** @hide */
510    public final void destroy() {
511        mDestroyed = true;
512    }
513
514    /** @hide */
515    public final boolean isDestroyed() {
516        return mDestroyed;
517    }
518
519    /**
520     * Set the window manager for use by this Window to, for example,
521     * display panels.  This is <em>not</em> used for displaying the
522     * Window itself -- that must be done by the client.
523     *
524     * @param wm The window manager for adding new windows.
525     */
526    public void setWindowManager(WindowManager wm, IBinder appToken, String appName) {
527        setWindowManager(wm, appToken, appName, false);
528    }
529
530    /**
531     * Set the window manager for use by this Window to, for example,
532     * display panels.  This is <em>not</em> used for displaying the
533     * Window itself -- that must be done by the client.
534     *
535     * @param wm The window manager for adding new windows.
536     */
537    public void setWindowManager(WindowManager wm, IBinder appToken, String appName,
538            boolean hardwareAccelerated) {
539        mAppToken = appToken;
540        mAppName = appName;
541        mHardwareAccelerated = hardwareAccelerated
542                || SystemProperties.getBoolean(PROPERTY_HARDWARE_UI, false);
543        if (wm == null) {
544            wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
545        }
546        mWindowManager = ((WindowManagerImpl)wm).createLocalWindowManager(this);
547    }
548
549    void adjustLayoutParamsForSubWindow(WindowManager.LayoutParams wp) {
550        CharSequence curTitle = wp.getTitle();
551        if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&
552            wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
553            if (wp.token == null) {
554                View decor = peekDecorView();
555                if (decor != null) {
556                    wp.token = decor.getWindowToken();
557                }
558            }
559            if (curTitle == null || curTitle.length() == 0) {
560                String title;
561                if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) {
562                    title="Media";
563                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) {
564                    title="MediaOvr";
565                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
566                    title="Panel";
567                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) {
568                    title="SubPanel";
569                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) {
570                    title="AtchDlg";
571                } else {
572                    title=Integer.toString(wp.type);
573                }
574                if (mAppName != null) {
575                    title += ":" + mAppName;
576                }
577                wp.setTitle(title);
578            }
579        } else {
580            if (wp.token == null) {
581                wp.token = mContainer == null ? mAppToken : mContainer.mAppToken;
582            }
583            if ((curTitle == null || curTitle.length() == 0)
584                    && mAppName != null) {
585                wp.setTitle(mAppName);
586            }
587        }
588        if (wp.packageName == null) {
589            wp.packageName = mContext.getPackageName();
590        }
591        if (mHardwareAccelerated) {
592            wp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
593        }
594    }
595
596    /**
597     * Return the window manager allowing this Window to display its own
598     * windows.
599     *
600     * @return WindowManager The ViewManager.
601     */
602    public WindowManager getWindowManager() {
603        return mWindowManager;
604    }
605
606    /**
607     * Set the Callback interface for this window, used to intercept key
608     * events and other dynamic operations in the window.
609     *
610     * @param callback The desired Callback interface.
611     */
612    public void setCallback(Callback callback) {
613        mCallback = callback;
614    }
615
616    /**
617     * Return the current Callback interface for this window.
618     */
619    public final Callback getCallback() {
620        return mCallback;
621    }
622
623    /** @hide */
624    public final void setOnWindowDismissedCallback(OnWindowDismissedCallback dcb) {
625        mOnWindowDismissedCallback = dcb;
626    }
627
628    /** @hide */
629    public final void dispatchOnWindowDismissed() {
630        if (mOnWindowDismissedCallback != null) {
631            mOnWindowDismissedCallback.onWindowDismissed();
632        }
633    }
634
635    /**
636     * Take ownership of this window's surface.  The window's view hierarchy
637     * will no longer draw into the surface, though it will otherwise continue
638     * to operate (such as for receiving input events).  The given SurfaceHolder
639     * callback will be used to tell you about state changes to the surface.
640     */
641    public abstract void takeSurface(SurfaceHolder.Callback2 callback);
642
643    /**
644     * Take ownership of this window's InputQueue.  The window will no
645     * longer read and dispatch input events from the queue; it is your
646     * responsibility to do so.
647     */
648    public abstract void takeInputQueue(InputQueue.Callback callback);
649
650    /**
651     * Return whether this window is being displayed with a floating style
652     * (based on the {@link android.R.attr#windowIsFloating} attribute in
653     * the style/theme).
654     *
655     * @return Returns true if the window is configured to be displayed floating
656     * on top of whatever is behind it.
657     */
658    public abstract boolean isFloating();
659
660    /**
661     * Set the width and height layout parameters of the window.  The default
662     * for both of these is MATCH_PARENT; you can change them to WRAP_CONTENT
663     * or an absolute value to make a window that is not full-screen.
664     *
665     * @param width The desired layout width of the window.
666     * @param height The desired layout height of the window.
667     *
668     * @see ViewGroup.LayoutParams#height
669     * @see ViewGroup.LayoutParams#width
670     */
671    public void setLayout(int width, int height) {
672        final WindowManager.LayoutParams attrs = getAttributes();
673        attrs.width = width;
674        attrs.height = height;
675        dispatchWindowAttributesChanged(attrs);
676    }
677
678    /**
679     * Set the gravity of the window, as per the Gravity constants.  This
680     * controls how the window manager is positioned in the overall window; it
681     * is only useful when using WRAP_CONTENT for the layout width or height.
682     *
683     * @param gravity The desired gravity constant.
684     *
685     * @see Gravity
686     * @see #setLayout
687     */
688    public void setGravity(int gravity)
689    {
690        final WindowManager.LayoutParams attrs = getAttributes();
691        attrs.gravity = gravity;
692        dispatchWindowAttributesChanged(attrs);
693    }
694
695    /**
696     * Set the type of the window, as per the WindowManager.LayoutParams
697     * types.
698     *
699     * @param type The new window type (see WindowManager.LayoutParams).
700     */
701    public void setType(int type) {
702        final WindowManager.LayoutParams attrs = getAttributes();
703        attrs.type = type;
704        dispatchWindowAttributesChanged(attrs);
705    }
706
707    /**
708     * Set the format of window, as per the PixelFormat types.  This overrides
709     * the default format that is selected by the Window based on its
710     * window decorations.
711     *
712     * @param format The new window format (see PixelFormat).  Use
713     *               PixelFormat.UNKNOWN to allow the Window to select
714     *               the format.
715     *
716     * @see PixelFormat
717     */
718    public void setFormat(int format) {
719        final WindowManager.LayoutParams attrs = getAttributes();
720        if (format != PixelFormat.UNKNOWN) {
721            attrs.format = format;
722            mHaveWindowFormat = true;
723        } else {
724            attrs.format = mDefaultWindowFormat;
725            mHaveWindowFormat = false;
726        }
727        dispatchWindowAttributesChanged(attrs);
728    }
729
730    /**
731     * Specify custom animations to use for the window, as per
732     * {@link WindowManager.LayoutParams#windowAnimations
733     * WindowManager.LayoutParams.windowAnimations}.  Providing anything besides
734     * 0 here will override the animations the window would
735     * normally retrieve from its theme.
736     */
737    public void setWindowAnimations(int resId) {
738        final WindowManager.LayoutParams attrs = getAttributes();
739        attrs.windowAnimations = resId;
740        dispatchWindowAttributesChanged(attrs);
741    }
742
743    /**
744     * Specify an explicit soft input mode to use for the window, as per
745     * {@link WindowManager.LayoutParams#softInputMode
746     * WindowManager.LayoutParams.softInputMode}.  Providing anything besides
747     * "unspecified" here will override the input mode the window would
748     * normally retrieve from its theme.
749     */
750    public void setSoftInputMode(int mode) {
751        final WindowManager.LayoutParams attrs = getAttributes();
752        if (mode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
753            attrs.softInputMode = mode;
754            mHasSoftInputMode = true;
755        } else {
756            mHasSoftInputMode = false;
757        }
758        dispatchWindowAttributesChanged(attrs);
759    }
760
761    /**
762     * Convenience function to set the flag bits as specified in flags, as
763     * per {@link #setFlags}.
764     * @param flags The flag bits to be set.
765     * @see #setFlags
766     * @see #clearFlags
767     */
768    public void addFlags(int flags) {
769        setFlags(flags, flags);
770    }
771
772    /** @hide */
773    public void addPrivateFlags(int flags) {
774        setPrivateFlags(flags, flags);
775    }
776
777    /**
778     * Convenience function to clear the flag bits as specified in flags, as
779     * per {@link #setFlags}.
780     * @param flags The flag bits to be cleared.
781     * @see #setFlags
782     * @see #addFlags
783     */
784    public void clearFlags(int flags) {
785        setFlags(0, flags);
786    }
787
788    /**
789     * Set the flags of the window, as per the
790     * {@link WindowManager.LayoutParams WindowManager.LayoutParams}
791     * flags.
792     *
793     * <p>Note that some flags must be set before the window decoration is
794     * created (by the first call to
795     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
796     * {@link #getDecorView()}:
797     * {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
798     * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}.  These
799     * will be set for you based on the {@link android.R.attr#windowIsFloating}
800     * attribute.
801     *
802     * @param flags The new window flags (see WindowManager.LayoutParams).
803     * @param mask Which of the window flag bits to modify.
804     * @see #addFlags
805     * @see #clearFlags
806     */
807    public void setFlags(int flags, int mask) {
808        final WindowManager.LayoutParams attrs = getAttributes();
809        attrs.flags = (attrs.flags&~mask) | (flags&mask);
810        mForcedWindowFlags |= mask;
811        dispatchWindowAttributesChanged(attrs);
812    }
813
814    private void setPrivateFlags(int flags, int mask) {
815        final WindowManager.LayoutParams attrs = getAttributes();
816        attrs.privateFlags = (attrs.privateFlags & ~mask) | (flags & mask);
817        dispatchWindowAttributesChanged(attrs);
818    }
819
820    /**
821     * {@hide}
822     */
823    protected void setNeedsMenuKey(int value) {
824        final WindowManager.LayoutParams attrs = getAttributes();
825        attrs.needsMenuKey = value;
826        dispatchWindowAttributesChanged(attrs);
827    }
828
829    /**
830     * {@hide}
831     */
832    protected void dispatchWindowAttributesChanged(WindowManager.LayoutParams attrs) {
833        if (mCallback != null) {
834            mCallback.onWindowAttributesChanged(attrs);
835        }
836    }
837
838    /**
839     * Set the amount of dim behind the window when using
840     * {@link WindowManager.LayoutParams#FLAG_DIM_BEHIND}.  This overrides
841     * the default dim amount of that is selected by the Window based on
842     * its theme.
843     *
844     * @param amount The new dim amount, from 0 for no dim to 1 for full dim.
845     */
846    public void setDimAmount(float amount) {
847        final WindowManager.LayoutParams attrs = getAttributes();
848        attrs.dimAmount = amount;
849        mHaveDimAmount = true;
850        dispatchWindowAttributesChanged(attrs);
851    }
852
853    /**
854     * Specify custom window attributes.  <strong>PLEASE NOTE:</strong> the
855     * layout params you give here should generally be from values previously
856     * retrieved with {@link #getAttributes()}; you probably do not want to
857     * blindly create and apply your own, since this will blow away any values
858     * set by the framework that you are not interested in.
859     *
860     * @param a The new window attributes, which will completely override any
861     *          current values.
862     */
863    public void setAttributes(WindowManager.LayoutParams a) {
864        mWindowAttributes.copyFrom(a);
865        dispatchWindowAttributesChanged(mWindowAttributes);
866    }
867
868    /**
869     * Retrieve the current window attributes associated with this panel.
870     *
871     * @return WindowManager.LayoutParams Either the existing window
872     *         attributes object, or a freshly created one if there is none.
873     */
874    public final WindowManager.LayoutParams getAttributes() {
875        return mWindowAttributes;
876    }
877
878    /**
879     * Return the window flags that have been explicitly set by the client,
880     * so will not be modified by {@link #getDecorView}.
881     */
882    protected final int getForcedWindowFlags() {
883        return mForcedWindowFlags;
884    }
885
886    /**
887     * Has the app specified their own soft input mode?
888     */
889    protected final boolean hasSoftInputMode() {
890        return mHasSoftInputMode;
891    }
892
893    /** @hide */
894    public void setCloseOnTouchOutside(boolean close) {
895        mCloseOnTouchOutside = close;
896        mSetCloseOnTouchOutside = true;
897    }
898
899    /** @hide */
900    public void setCloseOnTouchOutsideIfNotSet(boolean close) {
901        if (!mSetCloseOnTouchOutside) {
902            mCloseOnTouchOutside = close;
903            mSetCloseOnTouchOutside = true;
904        }
905    }
906
907    /** @hide */
908    @SystemApi
909    public void setDisableWallpaperTouchEvents(boolean disable) {
910        setPrivateFlags(disable
911                ? WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS : 0,
912                WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS);
913    }
914
915    /** @hide */
916    public abstract void alwaysReadCloseOnTouchAttr();
917
918    /** @hide */
919    public boolean shouldCloseOnTouch(Context context, MotionEvent event) {
920        if (mCloseOnTouchOutside && event.getAction() == MotionEvent.ACTION_DOWN
921                && isOutOfBounds(context, event) && peekDecorView() != null) {
922            return true;
923        }
924        return false;
925    }
926
927    private boolean isOutOfBounds(Context context, MotionEvent event) {
928        final int x = (int) event.getX();
929        final int y = (int) event.getY();
930        final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
931        final View decorView = getDecorView();
932        return (x < -slop) || (y < -slop)
933                || (x > (decorView.getWidth()+slop))
934                || (y > (decorView.getHeight()+slop));
935    }
936
937    /**
938     * Enable extended screen features.  This must be called before
939     * setContentView().  May be called as many times as desired as long as it
940     * is before setContentView().  If not called, no extended features
941     * will be available.  You can not turn off a feature once it is requested.
942     * You canot use other title features with {@link #FEATURE_CUSTOM_TITLE}.
943     *
944     * @param featureId The desired features, defined as constants by Window.
945     * @return The features that are now set.
946     */
947    public boolean requestFeature(int featureId) {
948        final int flag = 1<<featureId;
949        mFeatures |= flag;
950        mLocalFeatures |= mContainer != null ? (flag&~mContainer.mFeatures) : flag;
951        return (mFeatures&flag) != 0;
952    }
953
954    /**
955     * @hide Used internally to help resolve conflicting features.
956     */
957    protected void removeFeature(int featureId) {
958        final int flag = 1<<featureId;
959        mFeatures &= ~flag;
960        mLocalFeatures &= ~(mContainer != null ? (flag&~mContainer.mFeatures) : flag);
961    }
962
963    public final void makeActive() {
964        if (mContainer != null) {
965            if (mContainer.mActiveChild != null) {
966                mContainer.mActiveChild.mIsActive = false;
967            }
968            mContainer.mActiveChild = this;
969        }
970        mIsActive = true;
971        onActive();
972    }
973
974    public final boolean isActive()
975    {
976        return mIsActive;
977    }
978
979    /**
980     * Finds a view that was identified by the id attribute from the XML that
981     * was processed in {@link android.app.Activity#onCreate}.  This will
982     * implicitly call {@link #getDecorView} for you, with all of the
983     * associated side-effects.
984     *
985     * @return The view if found or null otherwise.
986     */
987    public View findViewById(int id) {
988        return getDecorView().findViewById(id);
989    }
990
991    /**
992     * Convenience for
993     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
994     * to set the screen content from a layout resource.  The resource will be
995     * inflated, adding all top-level views to the screen.
996     *
997     * @param layoutResID Resource ID to be inflated.
998     * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
999     */
1000    public abstract void setContentView(int layoutResID);
1001
1002    /**
1003     * Convenience for
1004     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
1005     * set the screen content to an explicit view.  This view is placed
1006     * directly into the screen's view hierarchy.  It can itself be a complex
1007     * view hierarhcy.
1008     *
1009     * @param view The desired content to display.
1010     * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
1011     */
1012    public abstract void setContentView(View view);
1013
1014    /**
1015     * Set the screen content to an explicit view.  This view is placed
1016     * directly into the screen's view hierarchy.  It can itself be a complex
1017     * view hierarchy.
1018     *
1019     * <p>Note that calling this function "locks in" various characteristics
1020     * of the window that can not, from this point forward, be changed: the
1021     * features that have been requested with {@link #requestFeature(int)},
1022     * and certain window flags as described in {@link #setFlags(int, int)}.
1023     *
1024     * @param view The desired content to display.
1025     * @param params Layout parameters for the view.
1026     */
1027    public abstract void setContentView(View view, ViewGroup.LayoutParams params);
1028
1029    /**
1030     * Variation on
1031     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
1032     * to add an additional content view to the screen.  Added after any existing
1033     * ones in the screen -- existing views are NOT removed.
1034     *
1035     * @param view The desired content to display.
1036     * @param params Layout parameters for the view.
1037     */
1038    public abstract void addContentView(View view, ViewGroup.LayoutParams params);
1039
1040    /**
1041     * Return the view in this Window that currently has focus, or null if
1042     * there are none.  Note that this does not look in any containing
1043     * Window.
1044     *
1045     * @return View The current View with focus or null.
1046     */
1047    @Nullable
1048    public abstract View getCurrentFocus();
1049
1050    /**
1051     * Quick access to the {@link LayoutInflater} instance that this Window
1052     * retrieved from its Context.
1053     *
1054     * @return LayoutInflater The shared LayoutInflater.
1055     */
1056    @NonNull
1057    public abstract LayoutInflater getLayoutInflater();
1058
1059    public abstract void setTitle(CharSequence title);
1060
1061    @Deprecated
1062    public abstract void setTitleColor(int textColor);
1063
1064    public abstract void openPanel(int featureId, KeyEvent event);
1065
1066    public abstract void closePanel(int featureId);
1067
1068    public abstract void togglePanel(int featureId, KeyEvent event);
1069
1070    public abstract void invalidatePanelMenu(int featureId);
1071
1072    public abstract boolean performPanelShortcut(int featureId,
1073                                                 int keyCode,
1074                                                 KeyEvent event,
1075                                                 int flags);
1076    public abstract boolean performPanelIdentifierAction(int featureId,
1077                                                 int id,
1078                                                 int flags);
1079
1080    public abstract void closeAllPanels();
1081
1082    public abstract boolean performContextMenuIdentifierAction(int id, int flags);
1083
1084    /**
1085     * Should be called when the configuration is changed.
1086     *
1087     * @param newConfig The new configuration.
1088     */
1089    public abstract void onConfigurationChanged(Configuration newConfig);
1090
1091    /**
1092     * Sets the window elevation.
1093     * <p>
1094     * Changes to this property take effect immediately and will cause the
1095     * window surface to be recreated. This is an expensive operation and as a
1096     * result, this property should not be animated.
1097     *
1098     * @param elevation The window elevation.
1099     * @see View#setElevation(float)
1100     * @see android.R.styleable#Window_windowElevation
1101     */
1102    public void setElevation(float elevation) {}
1103
1104    /**
1105     * Sets whether window content should be clipped to the outline of the
1106     * window background.
1107     *
1108     * @param clipToOutline Whether window content should be clipped to the
1109     *                      outline of the window background.
1110     * @see View#setClipToOutline(boolean)
1111     * @see android.R.styleable#Window_windowClipToOutline
1112     */
1113    public void setClipToOutline(boolean clipToOutline) {}
1114
1115    /**
1116     * Change the background of this window to a Drawable resource. Setting the
1117     * background to null will make the window be opaque. To make the window
1118     * transparent, you can use an empty drawable (for instance a ColorDrawable
1119     * with the color 0 or the system drawable android:drawable/empty.)
1120     *
1121     * @param resId The resource identifier of a drawable resource which will
1122     *              be installed as the new background.
1123     */
1124    public void setBackgroundDrawableResource(int resId) {
1125        setBackgroundDrawable(mContext.getDrawable(resId));
1126    }
1127
1128    /**
1129     * Change the background of this window to a custom Drawable. Setting the
1130     * background to null will make the window be opaque. To make the window
1131     * transparent, you can use an empty drawable (for instance a ColorDrawable
1132     * with the color 0 or the system drawable android:drawable/empty.)
1133     *
1134     * @param drawable The new Drawable to use for this window's background.
1135     */
1136    public abstract void setBackgroundDrawable(Drawable drawable);
1137
1138    /**
1139     * Set the value for a drawable feature of this window, from a resource
1140     * identifier.  You must have called requestFeauture(featureId) before
1141     * calling this function.
1142     *
1143     * @see android.content.res.Resources#getDrawable(int)
1144     *
1145     * @param featureId The desired drawable feature to change, defined as a
1146     * constant by Window.
1147     * @param resId Resource identifier of the desired image.
1148     */
1149    public abstract void setFeatureDrawableResource(int featureId, int resId);
1150
1151    /**
1152     * Set the value for a drawable feature of this window, from a URI. You
1153     * must have called requestFeature(featureId) before calling this
1154     * function.
1155     *
1156     * <p>The only URI currently supported is "content:", specifying an image
1157     * in a content provider.
1158     *
1159     * @see android.widget.ImageView#setImageURI
1160     *
1161     * @param featureId The desired drawable feature to change. Features are
1162     * constants defined by Window.
1163     * @param uri The desired URI.
1164     */
1165    public abstract void setFeatureDrawableUri(int featureId, Uri uri);
1166
1167    /**
1168     * Set an explicit Drawable value for feature of this window. You must
1169     * have called requestFeature(featureId) before calling this function.
1170     *
1171     * @param featureId The desired drawable feature to change. Features are
1172     *                  constants defined by Window.
1173     * @param drawable A Drawable object to display.
1174     */
1175    public abstract void setFeatureDrawable(int featureId, Drawable drawable);
1176
1177    /**
1178     * Set a custom alpha value for the given drawable feature, controlling how
1179     * much the background is visible through it.
1180     *
1181     * @param featureId The desired drawable feature to change. Features are
1182     *                  constants defined by Window.
1183     * @param alpha The alpha amount, 0 is completely transparent and 255 is
1184     *              completely opaque.
1185     */
1186    public abstract void setFeatureDrawableAlpha(int featureId, int alpha);
1187
1188    /**
1189     * Set the integer value for a feature. The range of the value depends on
1190     * the feature being set. For {@link #FEATURE_PROGRESS}, it should go from
1191     * 0 to 10000. At 10000 the progress is complete and the indicator hidden.
1192     *
1193     * @param featureId The desired feature to change. Features are constants
1194     *                  defined by Window.
1195     * @param value The value for the feature. The interpretation of this
1196     *              value is feature-specific.
1197     */
1198    public abstract void setFeatureInt(int featureId, int value);
1199
1200    /**
1201     * Request that key events come to this activity. Use this if your
1202     * activity has no views with focus, but the activity still wants
1203     * a chance to process key events.
1204     */
1205    public abstract void takeKeyEvents(boolean get);
1206
1207    /**
1208     * Used by custom windows, such as Dialog, to pass the key press event
1209     * further down the view hierarchy. Application developers should
1210     * not need to implement or call this.
1211     *
1212     */
1213    public abstract boolean superDispatchKeyEvent(KeyEvent event);
1214
1215    /**
1216     * Used by custom windows, such as Dialog, to pass the key shortcut press event
1217     * further down the view hierarchy. Application developers should
1218     * not need to implement or call this.
1219     *
1220     */
1221    public abstract boolean superDispatchKeyShortcutEvent(KeyEvent event);
1222
1223    /**
1224     * Used by custom windows, such as Dialog, to pass the touch screen event
1225     * further down the view hierarchy. Application developers should
1226     * not need to implement or call this.
1227     *
1228     */
1229    public abstract boolean superDispatchTouchEvent(MotionEvent event);
1230
1231    /**
1232     * Used by custom windows, such as Dialog, to pass the trackball event
1233     * further down the view hierarchy. Application developers should
1234     * not need to implement or call this.
1235     *
1236     */
1237    public abstract boolean superDispatchTrackballEvent(MotionEvent event);
1238
1239    /**
1240     * Used by custom windows, such as Dialog, to pass the generic motion event
1241     * further down the view hierarchy. Application developers should
1242     * not need to implement or call this.
1243     *
1244     */
1245    public abstract boolean superDispatchGenericMotionEvent(MotionEvent event);
1246
1247    /**
1248     * Retrieve the top-level window decor view (containing the standard
1249     * window frame/decorations and the client's content inside of that), which
1250     * can be added as a window to the window manager.
1251     *
1252     * <p><em>Note that calling this function for the first time "locks in"
1253     * various window characteristics as described in
1254     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}.</em></p>
1255     *
1256     * @return Returns the top-level window decor view.
1257     */
1258    public abstract View getDecorView();
1259
1260    /**
1261     * Retrieve the current decor view, but only if it has already been created;
1262     * otherwise returns null.
1263     *
1264     * @return Returns the top-level window decor or null.
1265     * @see #getDecorView
1266     */
1267    public abstract View peekDecorView();
1268
1269    public abstract Bundle saveHierarchyState();
1270
1271    public abstract void restoreHierarchyState(Bundle savedInstanceState);
1272
1273    protected abstract void onActive();
1274
1275    /**
1276     * Return the feature bits that are enabled.  This is the set of features
1277     * that were given to requestFeature(), and are being handled by this
1278     * Window itself or its container.  That is, it is the set of
1279     * requested features that you can actually use.
1280     *
1281     * <p>To do: add a public version of this API that allows you to check for
1282     * features by their feature ID.
1283     *
1284     * @return int The feature bits.
1285     */
1286    protected final int getFeatures()
1287    {
1288        return mFeatures;
1289    }
1290
1291    /**
1292     * Return the feature bits set by default on a window.
1293     * @param context The context used to access resources
1294     */
1295    public static int getDefaultFeatures(Context context) {
1296        int features = 0;
1297
1298        final Resources res = context.getResources();
1299        if (res.getBoolean(com.android.internal.R.bool.config_defaultWindowFeatureOptionsPanel)) {
1300            features |= 1 << FEATURE_OPTIONS_PANEL;
1301        }
1302
1303        if (res.getBoolean(com.android.internal.R.bool.config_defaultWindowFeatureContextMenu)) {
1304            features |= 1 << FEATURE_CONTEXT_MENU;
1305        }
1306
1307        return features;
1308    }
1309
1310    /**
1311     * Query for the availability of a certain feature.
1312     *
1313     * @param feature The feature ID to check
1314     * @return true if the feature is enabled, false otherwise.
1315     */
1316    public boolean hasFeature(int feature) {
1317        return (getFeatures() & (1 << feature)) != 0;
1318    }
1319
1320    /**
1321     * Return the feature bits that are being implemented by this Window.
1322     * This is the set of features that were given to requestFeature(), and are
1323     * being handled by only this Window itself, not by its containers.
1324     *
1325     * @return int The feature bits.
1326     */
1327    protected final int getLocalFeatures()
1328    {
1329        return mLocalFeatures;
1330    }
1331
1332    /**
1333     * Set the default format of window, as per the PixelFormat types.  This
1334     * is the format that will be used unless the client specifies in explicit
1335     * format with setFormat();
1336     *
1337     * @param format The new window format (see PixelFormat).
1338     *
1339     * @see #setFormat
1340     * @see PixelFormat
1341     */
1342    protected void setDefaultWindowFormat(int format) {
1343        mDefaultWindowFormat = format;
1344        if (!mHaveWindowFormat) {
1345            final WindowManager.LayoutParams attrs = getAttributes();
1346            attrs.format = format;
1347            dispatchWindowAttributesChanged(attrs);
1348        }
1349    }
1350
1351    /** @hide */
1352    protected boolean haveDimAmount() {
1353        return mHaveDimAmount;
1354    }
1355
1356    public abstract void setChildDrawable(int featureId, Drawable drawable);
1357
1358    public abstract void setChildInt(int featureId, int value);
1359
1360    /**
1361     * Is a keypress one of the defined shortcut keys for this window.
1362     * @param keyCode the key code from {@link android.view.KeyEvent} to check.
1363     * @param event the {@link android.view.KeyEvent} to use to help check.
1364     */
1365    public abstract boolean isShortcutKey(int keyCode, KeyEvent event);
1366
1367    /**
1368     * @see android.app.Activity#setVolumeControlStream(int)
1369     */
1370    public abstract void setVolumeControlStream(int streamType);
1371
1372    /**
1373     * @see android.app.Activity#getVolumeControlStream()
1374     */
1375    public abstract int getVolumeControlStream();
1376
1377    /**
1378     * Sets a {@link MediaController} to send media keys and volume changes to.
1379     * If set, this should be preferred for all media keys and volume requests
1380     * sent to this window.
1381     *
1382     * @param controller The controller for the session which should receive
1383     *            media keys and volume changes.
1384     * @see android.app.Activity#setMediaController(android.media.session.MediaController)
1385     */
1386    public void setMediaController(MediaController controller) {
1387    }
1388
1389    /**
1390     * Gets the {@link MediaController} that was previously set.
1391     *
1392     * @return The controller which should receive events.
1393     * @see #setMediaController(android.media.session.MediaController)
1394     * @see android.app.Activity#getMediaController()
1395     */
1396    public MediaController getMediaController() {
1397        return null;
1398    }
1399
1400    /**
1401     * Set extra options that will influence the UI for this window.
1402     * @param uiOptions Flags specifying extra options for this window.
1403     */
1404    public void setUiOptions(int uiOptions) { }
1405
1406    /**
1407     * Set extra options that will influence the UI for this window.
1408     * Only the bits filtered by mask will be modified.
1409     * @param uiOptions Flags specifying extra options for this window.
1410     * @param mask Flags specifying which options should be modified. Others will remain unchanged.
1411     */
1412    public void setUiOptions(int uiOptions, int mask) { }
1413
1414    /**
1415     * Set the primary icon for this window.
1416     *
1417     * @param resId resource ID of a drawable to set
1418     */
1419    public void setIcon(int resId) { }
1420
1421    /**
1422     * Set the default icon for this window.
1423     * This will be overridden by any other icon set operation which could come from the
1424     * theme or another explicit set.
1425     *
1426     * @hide
1427     */
1428    public void setDefaultIcon(int resId) { }
1429
1430    /**
1431     * Set the logo for this window. A logo is often shown in place of an
1432     * {@link #setIcon(int) icon} but is generally wider and communicates window title information
1433     * as well.
1434     *
1435     * @param resId resource ID of a drawable to set
1436     */
1437    public void setLogo(int resId) { }
1438
1439    /**
1440     * Set the default logo for this window.
1441     * This will be overridden by any other logo set operation which could come from the
1442     * theme or another explicit set.
1443     *
1444     * @hide
1445     */
1446    public void setDefaultLogo(int resId) { }
1447
1448    /**
1449     * Set focus locally. The window should have the
1450     * {@link WindowManager.LayoutParams#FLAG_LOCAL_FOCUS_MODE} flag set already.
1451     * @param hasFocus Whether this window has focus or not.
1452     * @param inTouchMode Whether this window is in touch mode or not.
1453     */
1454    public void setLocalFocus(boolean hasFocus, boolean inTouchMode) { }
1455
1456    /**
1457     * Inject an event to window locally.
1458     * @param event A key or touch event to inject to this window.
1459     */
1460    public void injectInputEvent(InputEvent event) { }
1461
1462    /**
1463     * Retrieve the {@link TransitionManager} responsible for  for default transitions
1464     * in this window. Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
1465     *
1466     * <p>This method will return non-null after content has been initialized (e.g. by using
1467     * {@link #setContentView}) if {@link #FEATURE_CONTENT_TRANSITIONS} has been granted.</p>
1468     *
1469     * @return This window's content TransitionManager or null if none is set.
1470     */
1471    public TransitionManager getTransitionManager() {
1472        return null;
1473    }
1474
1475    /**
1476     * Set the {@link TransitionManager} to use for default transitions in this window.
1477     * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
1478     *
1479     * @param tm The TransitionManager to use for scene changes.
1480     */
1481    public void setTransitionManager(TransitionManager tm) {
1482        throw new UnsupportedOperationException();
1483    }
1484
1485    /**
1486     * Retrieve the {@link Scene} representing this window's current content.
1487     * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
1488     *
1489     * <p>This method will return null if the current content is not represented by a Scene.</p>
1490     *
1491     * @return Current Scene being shown or null
1492     */
1493    public Scene getContentScene() {
1494        return null;
1495    }
1496
1497    /**
1498     * Sets the Transition that will be used to move Views into the initial scene. The entering
1499     * Views will be those that are regular Views or ViewGroups that have
1500     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1501     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1502     * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
1503     * entering Views will remain unaffected.
1504     *
1505     * @param transition The Transition to use to move Views into the initial Scene.
1506     * @attr ref android.R.styleable#Window_windowEnterTransition
1507     */
1508    public void setEnterTransition(Transition transition) {}
1509
1510    /**
1511     * Sets the Transition that will be used to move Views out of the scene when the Window is
1512     * preparing to close, for example after a call to
1513     * {@link android.app.Activity#finishAfterTransition()}. The exiting
1514     * Views will be those that are regular Views or ViewGroups that have
1515     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1516     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1517     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
1518     * entering Views will remain unaffected. If nothing is set, the default will be to
1519     * use the same value as set in {@link #setEnterTransition(android.transition.Transition)}.
1520     *
1521     * @param transition The Transition to use to move Views out of the Scene when the Window
1522     *                   is preparing to close.
1523     * @attr ref android.R.styleable#Window_windowReturnTransition
1524     */
1525    public void setReturnTransition(Transition transition) {}
1526
1527    /**
1528     * Sets the Transition that will be used to move Views out of the scene when starting a
1529     * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
1530     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1531     * {@link android.transition.Visibility} as exiting is governed by changing visibility
1532     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
1533     * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1534     *
1535     * @param transition The Transition to use to move Views out of the scene when calling a
1536     *                   new Activity.
1537     * @attr ref android.R.styleable#Window_windowExitTransition
1538     */
1539    public void setExitTransition(Transition transition) {}
1540
1541    /**
1542     * Sets the Transition that will be used to move Views in to the scene when returning from
1543     * a previously-started Activity. The entering Views will be those that are regular Views
1544     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
1545     * will extend {@link android.transition.Visibility} as exiting is governed by changing
1546     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
1547     * the views will remain unaffected. If nothing is set, the default will be to use the same
1548     * transition as {@link #setExitTransition(android.transition.Transition)}.
1549     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1550     *
1551     * @param transition The Transition to use to move Views into the scene when reentering from a
1552     *                   previously-started Activity.
1553     * @attr ref android.R.styleable#Window_windowReenterTransition
1554     */
1555    public void setReenterTransition(Transition transition) {}
1556
1557    /**
1558     * Returns the transition used to move Views into the initial scene. The entering
1559     * Views will be those that are regular Views or ViewGroups that have
1560     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1561     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1562     * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
1563     * entering Views will remain unaffected.  Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1564     *
1565     * @return the Transition to use to move Views into the initial Scene.
1566     * @attr ref android.R.styleable#Window_windowEnterTransition
1567     */
1568    public Transition getEnterTransition() { return null; }
1569
1570    /**
1571     * Returns he Transition that will be used to move Views out of the scene when the Window is
1572     * preparing to close, for example after a call to
1573     * {@link android.app.Activity#finishAfterTransition()}. The exiting
1574     * Views will be those that are regular Views or ViewGroups that have
1575     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1576     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1577     * {@link View#VISIBLE} to {@link View#INVISIBLE}.
1578     *
1579     * @return The Transition to use to move Views out of the Scene when the Window
1580     *         is preparing to close.
1581     * @attr ref android.R.styleable#Window_windowReturnTransition
1582     */
1583    public Transition getReturnTransition() { return null; }
1584
1585    /**
1586     * Returns the Transition that will be used to move Views out of the scene when starting a
1587     * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
1588     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1589     * {@link android.transition.Visibility} as exiting is governed by changing visibility
1590     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
1591     * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1592     *
1593     * @return the Transition to use to move Views out of the scene when calling a
1594     * new Activity.
1595     * @attr ref android.R.styleable#Window_windowExitTransition
1596     */
1597    public Transition getExitTransition() { return null; }
1598
1599    /**
1600     * Returns the Transition that will be used to move Views in to the scene when returning from
1601     * a previously-started Activity. The entering Views will be those that are regular Views
1602     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
1603     * will extend {@link android.transition.Visibility} as exiting is governed by changing
1604     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}.
1605     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1606     *
1607     * @return The Transition to use to move Views into the scene when reentering from a
1608     *         previously-started Activity.
1609     * @attr ref android.R.styleable#Window_windowReenterTransition
1610     */
1611    public Transition getReenterTransition() { return null; }
1612
1613    /**
1614     * Sets the Transition that will be used for shared elements transferred into the content
1615     * Scene. Typical Transitions will affect size and location, such as
1616     * {@link android.transition.ChangeBounds}. A null
1617     * value will cause transferred shared elements to blink to the final position.
1618     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1619     *
1620     * @param transition The Transition to use for shared elements transferred into the content
1621     *                   Scene.
1622     * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
1623     */
1624    public void setSharedElementEnterTransition(Transition transition) {}
1625
1626    /**
1627     * Sets the Transition that will be used for shared elements transferred back to a
1628     * calling Activity. Typical Transitions will affect size and location, such as
1629     * {@link android.transition.ChangeBounds}. A null
1630     * value will cause transferred shared elements to blink to the final position.
1631     * If no value is set, the default will be to use the same value as
1632     * {@link #setSharedElementEnterTransition(android.transition.Transition)}.
1633     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1634     *
1635     * @param transition The Transition to use for shared elements transferred out of the content
1636     *                   Scene.
1637     * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
1638     */
1639    public void setSharedElementReturnTransition(Transition transition) {}
1640
1641    /**
1642     * Returns the Transition that will be used for shared elements transferred into the content
1643     * Scene. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1644     *
1645     * @return Transition to use for sharend elements transferred into the content Scene.
1646     * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
1647     */
1648    public Transition getSharedElementEnterTransition() { return null; }
1649
1650    /**
1651     * Returns the Transition that will be used for shared elements transferred back to a
1652     * calling Activity. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1653     *
1654     * @return Transition to use for sharend elements transferred into the content Scene.
1655     * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
1656     */
1657    public Transition getSharedElementReturnTransition() { return null; }
1658
1659    /**
1660     * Sets the Transition that will be used for shared elements after starting a new Activity
1661     * before the shared elements are transferred to the called Activity. If the shared elements
1662     * must animate during the exit transition, this Transition should be used. Upon completion,
1663     * the shared elements may be transferred to the started Activity.
1664     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1665     *
1666     * @param transition The Transition to use for shared elements in the launching Window
1667     *                   prior to transferring to the launched Activity's Window.
1668     * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
1669     */
1670    public void setSharedElementExitTransition(Transition transition) {}
1671
1672    /**
1673     * Sets the Transition that will be used for shared elements reentering from a started
1674     * Activity after it has returned the shared element to it start location. If no value
1675     * is set, this will default to
1676     * {@link #setSharedElementExitTransition(android.transition.Transition)}.
1677     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1678     *
1679     * @param transition The Transition to use for shared elements in the launching Window
1680     *                   after the shared element has returned to the Window.
1681     * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
1682     */
1683    public void setSharedElementReenterTransition(Transition transition) {}
1684
1685    /**
1686     * Returns the Transition to use for shared elements in the launching Window prior
1687     * to transferring to the launched Activity's Window.
1688     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1689     *
1690     * @return the Transition to use for shared elements in the launching Window prior
1691     * to transferring to the launched Activity's Window.
1692     * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
1693     */
1694    public Transition getSharedElementExitTransition() { return null; }
1695
1696    /**
1697     * Returns the Transition that will be used for shared elements reentering from a started
1698     * Activity after it has returned the shared element to it start location.
1699     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1700     *
1701     * @return the Transition that will be used for shared elements reentering from a started
1702     * Activity after it has returned the shared element to it start location.
1703     * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
1704     */
1705    public Transition getSharedElementReenterTransition() { return null; }
1706
1707    /**
1708     * Controls how the transition set in
1709     * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
1710     * transition of the calling Activity. When true, the transition will start as soon as possible.
1711     * When false, the transition will wait until the remote exiting transition completes before
1712     * starting.
1713     *
1714     * @param allow true to start the enter transition when possible or false to
1715     *              wait until the exiting transition completes.
1716     * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
1717     */
1718    public void setAllowEnterTransitionOverlap(boolean allow) {}
1719
1720    /**
1721     * Returns how the transition set in
1722     * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
1723     * transition of the calling Activity. When true, the transition will start as soon as possible.
1724     * When false, the transition will wait until the remote exiting transition completes before
1725     * starting.
1726     *
1727     * @return true when the enter transition should start as soon as possible or false to
1728     * when it should wait until the exiting transition completes.
1729     * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
1730     */
1731    public boolean getAllowEnterTransitionOverlap() { return true; }
1732
1733    /**
1734     * Controls how the transition set in
1735     * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
1736     * transition of the called Activity when reentering after if finishes. When true,
1737     * the transition will start as soon as possible. When false, the transition will wait
1738     * until the called Activity's exiting transition completes before starting.
1739     *
1740     * @param allow true to start the transition when possible or false to wait until the
1741     *              called Activity's exiting transition completes.
1742     * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
1743     */
1744    public void setAllowReturnTransitionOverlap(boolean allow) {}
1745
1746    /**
1747     * TODO: remove this.
1748     * @hide
1749     */
1750    public void setAllowExitTransitionOverlap(boolean allow) {
1751        setAllowReturnTransitionOverlap(allow);
1752    }
1753
1754    /**
1755     * Returns how the transition set in
1756     * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
1757     * transition of the called Activity when reentering after if finishes. When true,
1758     * the transition will start as soon as possible. When false, the transition will wait
1759     * until the called Activity's exiting transition completes before starting.
1760     *
1761     * @return true when the transition should start when possible or false when it should wait
1762     * until the called Activity's exiting transition completes.
1763     * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
1764     */
1765    public boolean getAllowReturnTransitionOverlap() { return true; }
1766
1767    /**
1768     * TODO: remove this.
1769     * @hide
1770     */
1771    public boolean getAllowExitTransitionOverlap() { return getAllowReturnTransitionOverlap(); }
1772
1773    /**
1774     * Returns the duration, in milliseconds, of the window background fade
1775     * when transitioning into or away from an Activity when called with an Activity Transition.
1776     * <p>When executing the enter transition, the background starts transparent
1777     * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
1778     * 300 milliseconds.</p>
1779     *
1780     * @return The duration of the window background fade to opaque during enter transition.
1781     * @see #getEnterTransition()
1782     * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
1783     */
1784    public long getTransitionBackgroundFadeDuration() { return 0; }
1785
1786    /**
1787     * Sets the duration, in milliseconds, of the window background fade
1788     * when transitioning into or away from an Activity when called with an Activity Transition.
1789     * <p>When executing the enter transition, the background starts transparent
1790     * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
1791     * 300 milliseconds.</p>
1792     *
1793     * @param fadeDurationMillis The duration of the window background fade to or from opaque
1794     *                           during enter transition.
1795     * @see #setEnterTransition(android.transition.Transition)
1796     * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
1797     */
1798    public void setTransitionBackgroundFadeDuration(long fadeDurationMillis) { }
1799
1800    /**
1801     * Returns <code>true</code> when shared elements should use an Overlay during
1802     * shared element transitions or <code>false</code> when they should animate as
1803     * part of the normal View hierarchy. The default value is true.
1804     *
1805     * @return <code>true</code> when shared elements should use an Overlay during
1806     * shared element transitions or <code>false</code> when they should animate as
1807     * part of the normal View hierarchy.
1808     * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
1809     */
1810    public boolean getSharedElementsUseOverlay() { return true; }
1811
1812    /**
1813     * Sets whether or not shared elements should use an Overlay during shared element transitions.
1814     * The default value is true.
1815     *
1816     * @param sharedElementsUseOverlay <code>true</code> indicates that shared elements should
1817     *                                 be transitioned with an Overlay or <code>false</code>
1818     *                                 to transition within the normal View hierarchy.
1819     * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
1820     */
1821    public void setSharedElementsUseOverlay(boolean sharedElementsUseOverlay) { }
1822
1823    /**
1824     * @return the color of the status bar.
1825     */
1826    public abstract int getStatusBarColor();
1827
1828    /**
1829     * Sets the color of the status bar to {@param color}.
1830     *
1831     * For this to take effect,
1832     * the window must be drawing the system bar backgrounds with
1833     * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
1834     * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_STATUS} must not be set.
1835     *
1836     * If {@param color} is not opaque, consider setting
1837     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
1838     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}.
1839     * <p>
1840     * The transitionName for the view background will be "android:status:background".
1841     * </p>
1842     */
1843    public abstract void setStatusBarColor(int color);
1844
1845    /**
1846     * @return the color of the navigation bar.
1847     */
1848    public abstract int getNavigationBarColor();
1849
1850    /**
1851     * Sets the color of the navigation bar to {@param color}.
1852     *
1853     * For this to take effect,
1854     * the window must be drawing the system bar backgrounds with
1855     * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
1856     * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_NAVIGATION} must not be set.
1857     *
1858     * If {@param color} is not opaque, consider setting
1859     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
1860     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}.
1861     * <p>
1862     * The transitionName for the view background will be "android:navigation:background".
1863     * </p>
1864     */
1865    public abstract void setNavigationBarColor(int color);
1866
1867
1868}
1869