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