[go: nahoru, domu]

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