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