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.content.Context;
     20 import android.content.res.Configuration;
     21 import android.content.res.TypedArray;
     22 import android.graphics.PixelFormat;
     23 import android.graphics.drawable.Drawable;
     24 import android.net.Uri;
     25 import android.os.Bundle;
     26 import android.os.IBinder;
     27 import android.view.accessibility.AccessibilityEvent;
     28 
     29 /**
     30  * Abstract base class for a top-level window look and behavior policy.  An
     31  * instance of this class should be used as the top-level view added to the
     32  * window manager. It provides standard UI policies such as a background, title
     33  * area, default key processing, etc.
     34  *
     35  * <p>The only existing implementation of this abstract class is
     36  * android.policy.PhoneWindow, which you should instantiate when needing a
     37  * Window.  Eventually that class will be refactored and a factory method
     38  * added for creating Window instances without knowing about a particular
     39  * implementation.
     40  */
     41 public abstract class Window {
     42     /** Flag for the "options panel" feature.  This is enabled by default. */
     43     public static final int FEATURE_OPTIONS_PANEL = 0;
     44     /** Flag for the "no title" feature, turning off the title at the top
     45      *  of the screen. */
     46     public static final int FEATURE_NO_TITLE = 1;
     47     /** Flag for the progress indicator feature */
     48     public static final int FEATURE_PROGRESS = 2;
     49     /** Flag for having an icon on the left side of the title bar */
     50     public static final int FEATURE_LEFT_ICON = 3;
     51     /** Flag for having an icon on the right side of the title bar */
     52     public static final int FEATURE_RIGHT_ICON = 4;
     53     /** Flag for indeterminate progress */
     54     public static final int FEATURE_INDETERMINATE_PROGRESS = 5;
     55     /** Flag for the context menu.  This is enabled by default. */
     56     public static final int FEATURE_CONTEXT_MENU = 6;
     57     /** Flag for custom title. You cannot combine this feature with other title features. */
     58     public static final int FEATURE_CUSTOM_TITLE = 7;
     59     /** Flag for asking for an OpenGL enabled window.
     60         All 2D graphics will be handled by OpenGL ES.
     61         @hide
     62     */
     63     public static final int FEATURE_OPENGL = 8;
     64     /** Flag for setting the progress bar's visibility to VISIBLE */
     65     public static final int PROGRESS_VISIBILITY_ON = -1;
     66     /** Flag for setting the progress bar's visibility to GONE */
     67     public static final int PROGRESS_VISIBILITY_OFF = -2;
     68     /** Flag for setting the progress bar's indeterminate mode on */
     69     public static final int PROGRESS_INDETERMINATE_ON = -3;
     70     /** Flag for setting the progress bar's indeterminate mode off */
     71     public static final int PROGRESS_INDETERMINATE_OFF = -4;
     72     /** Starting value for the (primary) progress */
     73     public static final int PROGRESS_START = 0;
     74     /** Ending value for the (primary) progress */
     75     public static final int PROGRESS_END = 10000;
     76     /** Lowest possible value for the secondary progress */
     77     public static final int PROGRESS_SECONDARY_START = 20000;
     78     /** Highest possible value for the secondary progress */
     79     public static final int PROGRESS_SECONDARY_END = 30000;
     80 
     81     /** The default features enabled */
     82     @SuppressWarnings({"PointlessBitwiseExpression"})
     83     protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) |
     84             (1 << FEATURE_CONTEXT_MENU);
     85 
     86     /**
     87      * The ID that the main layout in the XML layout file should have.
     88      */
     89     public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content;
     90 
     91     private final Context mContext;
     92 
     93     private TypedArray mWindowStyle;
     94     private Callback mCallback;
     95     private WindowManager mWindowManager;
     96     private IBinder mAppToken;
     97     private String mAppName;
     98     private Window mContainer;
     99     private Window mActiveChild;
    100     private boolean mIsActive = false;
    101     private boolean mHasChildren = false;
    102     private int mForcedWindowFlags = 0;
    103 
    104     private int mFeatures = DEFAULT_FEATURES;
    105     private int mLocalFeatures = DEFAULT_FEATURES;
    106 
    107     private boolean mHaveWindowFormat = false;
    108     private int mDefaultWindowFormat = PixelFormat.OPAQUE;
    109 
    110     private boolean mHasSoftInputMode = false;
    111 
    112     // The current window attributes.
    113     private final WindowManager.LayoutParams mWindowAttributes =
    114         new WindowManager.LayoutParams();
    115 
    116     /**
    117      * API from a Window back to its caller.  This allows the client to
    118      * intercept key dispatching, panels and menus, etc.
    119      */
    120     public interface Callback {
    121         /**
    122          * Called to process key events.  At the very least your
    123          * implementation must call
    124          * {@link android.view.Window#superDispatchKeyEvent} to do the
    125          * standard key processing.
    126          *
    127          * @param event The key event.
    128          *
    129          * @return boolean Return true if this event was consumed.
    130          */
    131         public boolean dispatchKeyEvent(KeyEvent event);
    132 
    133         /**
    134          * Called to process touch screen events.  At the very least your
    135          * implementation must call
    136          * {@link android.view.Window#superDispatchTouchEvent} to do the
    137          * standard touch screen processing.
    138          *
    139          * @param event The touch screen event.
    140          *
    141          * @return boolean Return true if this event was consumed.
    142          */
    143         public boolean dispatchTouchEvent(MotionEvent event);
    144 
    145         /**
    146          * Called to process trackball events.  At the very least your
    147          * implementation must call
    148          * {@link android.view.Window#superDispatchTrackballEvent} to do the
    149          * standard trackball processing.
    150          *
    151          * @param event The trackball event.
    152          *
    153          * @return boolean Return true if this event was consumed.
    154          */
    155         public boolean dispatchTrackballEvent(MotionEvent event);
    156 
    157         /**
    158          * Called to process population of {@link AccessibilityEvent}s.
    159          *
    160          * @param event The event.
    161          *
    162          * @return boolean Return true if event population was completed.
    163          */
    164         public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event);
    165 
    166         /**
    167          * Instantiate the view to display in the panel for 'featureId'.
    168          * You can return null, in which case the default content (typically
    169          * a menu) will be created for you.
    170          *
    171          * @param featureId Which panel is being created.
    172          *
    173          * @return view The top-level view to place in the panel.
    174          *
    175          * @see #onPreparePanel
    176          */
    177         public View onCreatePanelView(int featureId);
    178 
    179         /**
    180          * Initialize the contents of the menu for panel 'featureId'.  This is
    181          * called if onCreatePanelView() returns null, giving you a standard
    182          * menu in which you can place your items.  It is only called once for
    183          * the panel, the first time it is shown.
    184          *
    185          * <p>You can safely hold on to <var>menu</var> (and any items created
    186          * from it), making modifications to it as desired, until the next
    187          * time onCreatePanelMenu() is called for this feature.
    188          *
    189          * @param featureId The panel being created.
    190          * @param menu The menu inside the panel.
    191          *
    192          * @return boolean You must return true for the panel to be displayed;
    193          *         if you return false it will not be shown.
    194          */
    195         public boolean onCreatePanelMenu(int featureId, Menu menu);
    196 
    197         /**
    198          * Prepare a panel to be displayed.  This is called right before the
    199          * panel window is shown, every time it is shown.
    200          *
    201          * @param featureId The panel that is being displayed.
    202          * @param view The View that was returned by onCreatePanelView().
    203          * @param menu If onCreatePanelView() returned null, this is the Menu
    204          *             being displayed in the panel.
    205          *
    206          * @return boolean You must return true for the panel to be displayed;
    207          *         if you return false it will not be shown.
    208          *
    209          * @see #onCreatePanelView
    210          */
    211         public boolean onPreparePanel(int featureId, View view, Menu menu);
    212 
    213         /**
    214          * Called when a panel's menu is opened by the user. This may also be
    215          * called when the menu is changing from one type to another (for
    216          * example, from the icon menu to the expanded menu).
    217          *
    218          * @param featureId The panel that the menu is in.
    219          * @param menu The menu that is opened.
    220          * @return Return true to allow the menu to open, or false to prevent
    221          *         the menu from opening.
    222          */
    223         public boolean onMenuOpened(int featureId, Menu menu);
    224 
    225         /**
    226          * Called when a panel's menu item has been selected by the user.
    227          *
    228          * @param featureId The panel that the menu is in.
    229          * @param item The menu item that was selected.
    230          *
    231          * @return boolean Return true to finish processing of selection, or
    232          *         false to perform the normal menu handling (calling its
    233          *         Runnable or sending a Message to its target Handler).
    234          */
    235         public boolean onMenuItemSelected(int featureId, MenuItem item);
    236 
    237         /**
    238          * This is called whenever the current window attributes change.
    239          *
    240          */
    241         public void onWindowAttributesChanged(WindowManager.LayoutParams attrs);
    242 
    243         /**
    244          * This hook is called whenever the content view of the screen changes
    245          * (due to a call to
    246          * {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams)
    247          * Window.setContentView} or
    248          * {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams)
    249          * Window.addContentView}).
    250          */
    251         public void onContentChanged();
    252 
    253         /**
    254          * This hook is called whenever the window focus changes.  See
    255          * {@link View#onWindowFocusChanged(boolean)
    256          * View.onWindowFocusChanged(boolean)} for more information.
    257          *
    258          * @param hasFocus Whether the window now has focus.
    259          */
    260         public void onWindowFocusChanged(boolean hasFocus);
    261 
    262         /**
    263          * Called when the window has been attached to the window manager.
    264          * See {@link View#onAttachedToWindow() View.onAttachedToWindow()}
    265          * for more information.
    266          */
    267         public void onAttachedToWindow();
    268 
    269         /**
    270          * Called when the window has been attached to the window manager.
    271          * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()}
    272          * for more information.
    273          */
    274         public void onDetachedFromWindow();
    275 
    276         /**
    277          * Called when a panel is being closed.  If another logical subsequent
    278          * panel is being opened (and this panel is being closed to make room for the subsequent
    279          * panel), this method will NOT be called.
    280          *
    281          * @param featureId The panel that is being displayed.
    282          * @param menu If onCreatePanelView() returned null, this is the Menu
    283          *            being displayed in the panel.
    284          */
    285         public void onPanelClosed(int featureId, Menu menu);
    286 
    287         /**
    288          * Called when the user signals the desire to start a search.
    289          *
    290          * @return true if search launched, false if activity refuses (blocks)
    291          *
    292          * @see android.app.Activity#onSearchRequested()
    293          */
    294         public boolean onSearchRequested();
    295     }
    296 
    297     public Window(Context context) {
    298         mContext = context;
    299     }
    300 
    301     /**
    302      * Return the Context this window policy is running in, for retrieving
    303      * resources and other information.
    304      *
    305      * @return Context The Context that was supplied to the constructor.
    306      */
    307     public final Context getContext() {
    308         return mContext;
    309     }
    310 
    311     /**
    312      * Return the {@link android.R.styleable#Window} attributes from this
    313      * window's theme.
    314      */
    315     public final TypedArray getWindowStyle() {
    316         synchronized (this) {
    317             if (mWindowStyle == null) {
    318                 mWindowStyle = mContext.obtainStyledAttributes(
    319                         com.android.internal.R.styleable.Window);
    320             }
    321             return mWindowStyle;
    322         }
    323     }
    324 
    325     /**
    326      * Set the container for this window.  If not set, the DecorWindow
    327      * operates as a top-level window; otherwise, it negotiates with the
    328      * container to display itself appropriately.
    329      *
    330      * @param container The desired containing Window.
    331      */
    332     public void setContainer(Window container) {
    333         mContainer = container;
    334         if (container != null) {
    335             // Embedded screens never have a title.
    336             mFeatures |= 1<<FEATURE_NO_TITLE;
    337             mLocalFeatures |= 1<<FEATURE_NO_TITLE;
    338             container.mHasChildren = true;
    339         }
    340     }
    341 
    342     /**
    343      * Return the container for this Window.
    344      *
    345      * @return Window The containing window, or null if this is a
    346      *         top-level window.
    347      */
    348     public final Window getContainer() {
    349         return mContainer;
    350     }
    351 
    352     public final boolean hasChildren() {
    353         return mHasChildren;
    354     }
    355 
    356     /**
    357      * Set the window manager for use by this Window to, for example,
    358      * display panels.  This is <em>not</em> used for displaying the
    359      * Window itself -- that must be done by the client.
    360      *
    361      * @param wm The ViewManager for adding new windows.
    362      */
    363     public void setWindowManager(WindowManager wm,
    364             IBinder appToken, String appName) {
    365         mAppToken = appToken;
    366         mAppName = appName;
    367         if (wm == null) {
    368             wm = WindowManagerImpl.getDefault();
    369         }
    370         mWindowManager = new LocalWindowManager(wm);
    371     }
    372 
    373     private class LocalWindowManager implements WindowManager {
    374         LocalWindowManager(WindowManager wm) {
    375             mWindowManager = wm;
    376             mDefaultDisplay = mContext.getResources().getDefaultDisplay(
    377                     mWindowManager.getDefaultDisplay());
    378         }
    379 
    380         public final void addView(View view, ViewGroup.LayoutParams params) {
    381             // Let this throw an exception on a bad params.
    382             WindowManager.LayoutParams wp = (WindowManager.LayoutParams)params;
    383             CharSequence curTitle = wp.getTitle();
    384             if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&
    385                 wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
    386                 if (wp.token == null) {
    387                     View decor = peekDecorView();
    388                     if (decor != null) {
    389                         wp.token = decor.getWindowToken();
    390                     }
    391                 }
    392                 if (curTitle == null || curTitle.length() == 0) {
    393                     String title;
    394                     if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) {
    395                         title="Media";
    396                     } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) {
    397                         title="MediaOvr";
    398                     } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
    399                         title="Panel";
    400                     } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) {
    401                         title="SubPanel";
    402                     } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) {
    403                         title="AtchDlg";
    404                     } else {
    405                         title=Integer.toString(wp.type);
    406                     }
    407                     if (mAppName != null) {
    408                         title += ":" + mAppName;
    409                     }
    410                     wp.setTitle(title);
    411                 }
    412             } else {
    413                 if (wp.token == null) {
    414                     wp.token = mContainer == null ? mAppToken : mContainer.mAppToken;
    415                 }
    416                 if ((curTitle == null || curTitle.length() == 0)
    417                         && mAppName != null) {
    418                     wp.setTitle(mAppName);
    419                 }
    420            }
    421             if (wp.packageName == null) {
    422                 wp.packageName = mContext.getPackageName();
    423             }
    424             mWindowManager.addView(view, params);
    425         }
    426 
    427         public void updateViewLayout(View view, ViewGroup.LayoutParams params) {
    428             mWindowManager.updateViewLayout(view, params);
    429         }
    430 
    431         public final void removeView(View view) {
    432             mWindowManager.removeView(view);
    433         }
    434 
    435         public final void removeViewImmediate(View view) {
    436             mWindowManager.removeViewImmediate(view);
    437         }
    438 
    439         public Display getDefaultDisplay() {
    440             return mDefaultDisplay;
    441         }
    442 
    443         private final WindowManager mWindowManager;
    444 
    445         private final Display mDefaultDisplay;
    446     }
    447 
    448     /**
    449      * Return the window manager allowing this Window to display its own
    450      * windows.
    451      *
    452      * @return WindowManager The ViewManager.
    453      */
    454     public WindowManager getWindowManager() {
    455         return mWindowManager;
    456     }
    457 
    458     /**
    459      * Set the Callback interface for this window, used to intercept key
    460      * events and other dynamic operations in the window.
    461      *
    462      * @param callback The desired Callback interface.
    463      */
    464     public void setCallback(Callback callback) {
    465         mCallback = callback;
    466     }
    467 
    468     /**
    469      * Return the current Callback interface for this window.
    470      */
    471     public final Callback getCallback() {
    472         return mCallback;
    473     }
    474 
    475     /**
    476      * Take ownership of this window's surface.  The window's view hierarchy
    477      * will no longer draw into the surface, though it will otherwise continue
    478      * to operate (such as for receiving input events).  The given SurfaceHolder
    479      * callback will be used to tell you about state changes to the surface.
    480      */
    481     public abstract void takeSurface(SurfaceHolder.Callback2 callback);
    482 
    483     /**
    484      * Take ownership of this window's InputQueue.  The window will no
    485      * longer read and dispatch input events from the queue; it is your
    486      * responsibility to do so.
    487      */
    488     public abstract void takeInputQueue(InputQueue.Callback callback);
    489 
    490     /**
    491      * Return whether this window is being displayed with a floating style
    492      * (based on the {@link android.R.attr#windowIsFloating} attribute in
    493      * the style/theme).
    494      *
    495      * @return Returns true if the window is configured to be displayed floating
    496      * on top of whatever is behind it.
    497      */
    498     public abstract boolean isFloating();
    499 
    500     /**
    501      * Set the width and height layout parameters of the window.  The default
    502      * for both of these is MATCH_PARENT; you can change them to WRAP_CONTENT to
    503      * make a window that is not full-screen.
    504      *
    505      * @param width The desired layout width of the window.
    506      * @param height The desired layout height of the window.
    507      */
    508     public void setLayout(int width, int height)
    509     {
    510         final WindowManager.LayoutParams attrs = getAttributes();
    511         attrs.width = width;
    512         attrs.height = height;
    513         if (mCallback != null) {
    514             mCallback.onWindowAttributesChanged(attrs);
    515         }
    516     }
    517 
    518     /**
    519      * Set the gravity of the window, as per the Gravity constants.  This
    520      * controls how the window manager is positioned in the overall window; it
    521      * is only useful when using WRAP_CONTENT for the layout width or height.
    522      *
    523      * @param gravity The desired gravity constant.
    524      *
    525      * @see Gravity
    526      * @see #setLayout
    527      */
    528     public void setGravity(int gravity)
    529     {
    530         final WindowManager.LayoutParams attrs = getAttributes();
    531         attrs.gravity = gravity;
    532         if (mCallback != null) {
    533             mCallback.onWindowAttributesChanged(attrs);
    534         }
    535     }
    536 
    537     /**
    538      * Set the type of the window, as per the WindowManager.LayoutParams
    539      * types.
    540      *
    541      * @param type The new window type (see WindowManager.LayoutParams).
    542      */
    543     public void setType(int type) {
    544         final WindowManager.LayoutParams attrs = getAttributes();
    545         attrs.type = type;
    546         if (mCallback != null) {
    547             mCallback.onWindowAttributesChanged(attrs);
    548         }
    549     }
    550 
    551     /**
    552      * Set the format of window, as per the PixelFormat types.  This overrides
    553      * the default format that is selected by the Window based on its
    554      * window decorations.
    555      *
    556      * @param format The new window format (see PixelFormat).  Use
    557      *               PixelFormat.UNKNOWN to allow the Window to select
    558      *               the format.
    559      *
    560      * @see PixelFormat
    561      */
    562     public void setFormat(int format) {
    563         final WindowManager.LayoutParams attrs = getAttributes();
    564         if (format != PixelFormat.UNKNOWN) {
    565             attrs.format = format;
    566             mHaveWindowFormat = true;
    567         } else {
    568             attrs.format = mDefaultWindowFormat;
    569             mHaveWindowFormat = false;
    570         }
    571         if (mCallback != null) {
    572             mCallback.onWindowAttributesChanged(attrs);
    573         }
    574     }
    575 
    576     /**
    577      * Specify custom animations to use for the window, as per
    578      * {@link WindowManager.LayoutParams#windowAnimations
    579      * WindowManager.LayoutParams.windowAnimations}.  Providing anything besides
    580      * 0 here will override the animations the window would
    581      * normally retrieve from its theme.
    582      */
    583     public void setWindowAnimations(int resId) {
    584         final WindowManager.LayoutParams attrs = getAttributes();
    585         attrs.windowAnimations = resId;
    586         if (mCallback != null) {
    587             mCallback.onWindowAttributesChanged(attrs);
    588         }
    589     }
    590 
    591     /**
    592      * Specify an explicit soft input mode to use for the window, as per
    593      * {@link WindowManager.LayoutParams#softInputMode
    594      * WindowManager.LayoutParams.softInputMode}.  Providing anything besides
    595      * "unspecified" here will override the input mode the window would
    596      * normally retrieve from its theme.
    597      */
    598     public void setSoftInputMode(int mode) {
    599         final WindowManager.LayoutParams attrs = getAttributes();
    600         if (mode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
    601             attrs.softInputMode = mode;
    602             mHasSoftInputMode = true;
    603         } else {
    604             mHasSoftInputMode = false;
    605         }
    606         if (mCallback != null) {
    607             mCallback.onWindowAttributesChanged(attrs);
    608         }
    609     }
    610 
    611     /**
    612      * Convenience function to set the flag bits as specified in flags, as
    613      * per {@link #setFlags}.
    614      * @param flags The flag bits to be set.
    615      * @see #setFlags
    616      */
    617     public void addFlags(int flags) {
    618         setFlags(flags, flags);
    619     }
    620 
    621     /**
    622      * Convenience function to clear the flag bits as specified in flags, as
    623      * per {@link #setFlags}.
    624      * @param flags The flag bits to be cleared.
    625      * @see #setFlags
    626      */
    627     public void clearFlags(int flags) {
    628         setFlags(0, flags);
    629     }
    630 
    631     /**
    632      * Set the flags of the window, as per the
    633      * {@link WindowManager.LayoutParams WindowManager.LayoutParams}
    634      * flags.
    635      *
    636      * <p>Note that some flags must be set before the window decoration is
    637      * created (by the first call to
    638      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
    639      * {@link #getDecorView()}:
    640      * {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
    641      * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}.  These
    642      * will be set for you based on the {@link android.R.attr#windowIsFloating}
    643      * attribute.
    644      *
    645      * @param flags The new window flags (see WindowManager.LayoutParams).
    646      * @param mask Which of the window flag bits to modify.
    647      */
    648     public void setFlags(int flags, int mask) {
    649         final WindowManager.LayoutParams attrs = getAttributes();
    650         attrs.flags = (attrs.flags&~mask) | (flags&mask);
    651         mForcedWindowFlags |= mask;
    652         if (mCallback != null) {
    653             mCallback.onWindowAttributesChanged(attrs);
    654         }
    655     }
    656 
    657     /**
    658      * Specify custom window attributes.  <strong>PLEASE NOTE:</strong> the
    659      * layout params you give here should generally be from values previously
    660      * retrieved with {@link #getAttributes()}; you probably do not want to
    661      * blindly create and apply your own, since this will blow away any values
    662      * set by the framework that you are not interested in.
    663      *
    664      * @param a The new window attributes, which will completely override any
    665      *          current values.
    666      */
    667     public void setAttributes(WindowManager.LayoutParams a) {
    668         mWindowAttributes.copyFrom(a);
    669         if (mCallback != null) {
    670             mCallback.onWindowAttributesChanged(mWindowAttributes);
    671         }
    672     }
    673 
    674     /**
    675      * Retrieve the current window attributes associated with this panel.
    676      *
    677      * @return WindowManager.LayoutParams Either the existing window
    678      *         attributes object, or a freshly created one if there is none.
    679      */
    680     public final WindowManager.LayoutParams getAttributes() {
    681         return mWindowAttributes;
    682     }
    683 
    684     /**
    685      * Return the window flags that have been explicitly set by the client,
    686      * so will not be modified by {@link #getDecorView}.
    687      */
    688     protected final int getForcedWindowFlags() {
    689         return mForcedWindowFlags;
    690     }
    691 
    692     /**
    693      * Has the app specified their own soft input mode?
    694      */
    695     protected final boolean hasSoftInputMode() {
    696         return mHasSoftInputMode;
    697     }
    698 
    699     /**
    700      * Enable extended screen features.  This must be called before
    701      * setContentView().  May be called as many times as desired as long as it
    702      * is before setContentView().  If not called, no extended features
    703      * will be available.  You can not turn off a feature once it is requested.
    704      * You canot use other title features with {@link #FEATURE_CUSTOM_TITLE}.
    705      *
    706      * @param featureId The desired features, defined as constants by Window.
    707      * @return The features that are now set.
    708      */
    709     public boolean requestFeature(int featureId) {
    710         final int flag = 1<<featureId;
    711         mFeatures |= flag;
    712         mLocalFeatures |= mContainer != null ? (flag&~mContainer.mFeatures) : flag;
    713         return (mFeatures&flag) != 0;
    714     }
    715 
    716     public final void makeActive() {
    717         if (mContainer != null) {
    718             if (mContainer.mActiveChild != null) {
    719                 mContainer.mActiveChild.mIsActive = false;
    720             }
    721             mContainer.mActiveChild = this;
    722         }
    723         mIsActive = true;
    724         onActive();
    725     }
    726 
    727     public final boolean isActive()
    728     {
    729         return mIsActive;
    730     }
    731 
    732     /**
    733      * Finds a view that was identified by the id attribute from the XML that
    734      * was processed in {@link android.app.Activity#onCreate}.  This will
    735      * implicitly call {@link #getDecorView} for you, with all of the
    736      * associated side-effects.
    737      *
    738      * @return The view if found or null otherwise.
    739      */
    740     public View findViewById(int id) {
    741         return getDecorView().findViewById(id);
    742     }
    743 
    744     /**
    745      * Convenience for
    746      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
    747      * to set the screen content from a layout resource.  The resource will be
    748      * inflated, adding all top-level views to the screen.
    749      *
    750      * @param layoutResID Resource ID to be inflated.
    751      * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
    752      */
    753     public abstract void setContentView(int layoutResID);
    754 
    755     /**
    756      * Convenience for
    757      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
    758      * set the screen content to an explicit view.  This view is placed
    759      * directly into the screen's view hierarchy.  It can itself be a complex
    760      * view hierarhcy.
    761      *
    762      * @param view The desired content to display.
    763      * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
    764      */
    765     public abstract void setContentView(View view);
    766 
    767     /**
    768      * Set the screen content to an explicit view.  This view is placed
    769      * directly into the screen's view hierarchy.  It can itself be a complex
    770      * view hierarchy.
    771      *
    772      * <p>Note that calling this function "locks in" various characteristics
    773      * of the window that can not, from this point forward, be changed: the
    774      * features that have been requested with {@link #requestFeature(int)},
    775      * and certain window flags as described in {@link #setFlags(int, int)}.
    776      *
    777      * @param view The desired content to display.
    778      * @param params Layout parameters for the view.
    779      */
    780     public abstract void setContentView(View view, ViewGroup.LayoutParams params);
    781 
    782     /**
    783      * Variation on
    784      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
    785      * to add an additional content view to the screen.  Added after any existing
    786      * ones in the screen -- existing views are NOT removed.
    787      *
    788      * @param view The desired content to display.
    789      * @param params Layout parameters for the view.
    790      */
    791     public abstract void addContentView(View view, ViewGroup.LayoutParams params);
    792 
    793     /**
    794      * Return the view in this Window that currently has focus, or null if
    795      * there are none.  Note that this does not look in any containing
    796      * Window.
    797      *
    798      * @return View The current View with focus or null.
    799      */
    800     public abstract View getCurrentFocus();
    801 
    802     /**
    803      * Quick access to the {@link LayoutInflater} instance that this Window
    804      * retrieved from its Context.
    805      *
    806      * @return LayoutInflater The shared LayoutInflater.
    807      */
    808     public abstract LayoutInflater getLayoutInflater();
    809 
    810     public abstract void setTitle(CharSequence title);
    811 
    812     public abstract void setTitleColor(int textColor);
    813 
    814     public abstract void openPanel(int featureId, KeyEvent event);
    815 
    816     public abstract void closePanel(int featureId);
    817 
    818     public abstract void togglePanel(int featureId, KeyEvent event);
    819 
    820     public abstract boolean performPanelShortcut(int featureId,
    821                                                  int keyCode,
    822                                                  KeyEvent event,
    823                                                  int flags);
    824     public abstract boolean performPanelIdentifierAction(int featureId,
    825                                                  int id,
    826                                                  int flags);
    827 
    828     public abstract void closeAllPanels();
    829 
    830     public abstract boolean performContextMenuIdentifierAction(int id, int flags);
    831 
    832     /**
    833      * Should be called when the configuration is changed.
    834      *
    835      * @param newConfig The new configuration.
    836      */
    837     public abstract void onConfigurationChanged(Configuration newConfig);
    838 
    839     /**
    840      * Change the background of this window to a Drawable resource. Setting the
    841      * background to null will make the window be opaque. To make the window
    842      * transparent, you can use an empty drawable (for instance a ColorDrawable
    843      * with the color 0 or the system drawable android:drawable/empty.)
    844      *
    845      * @param resid The resource identifier of a drawable resource which will be
    846      *              installed as the new background.
    847      */
    848     public void setBackgroundDrawableResource(int resid)
    849     {
    850         setBackgroundDrawable(mContext.getResources().getDrawable(resid));
    851     }
    852 
    853     /**
    854      * Change the background of this window to a custom Drawable. Setting the
    855      * background to null will make the window be opaque. To make the window
    856      * transparent, you can use an empty drawable (for instance a ColorDrawable
    857      * with the color 0 or the system drawable android:drawable/empty.)
    858      *
    859      * @param drawable The new Drawable to use for this window's background.
    860      */
    861     public abstract void setBackgroundDrawable(Drawable drawable);
    862 
    863     /**
    864      * Set the value for a drawable feature of this window, from a resource
    865      * identifier.  You must have called requestFeauture(featureId) before
    866      * calling this function.
    867      *
    868      * @see android.content.res.Resources#getDrawable(int)
    869      *
    870      * @param featureId The desired drawable feature to change, defined as a
    871      * constant by Window.
    872      * @param resId Resource identifier of the desired image.
    873      */
    874     public abstract void setFeatureDrawableResource(int featureId, int resId);
    875 
    876     /**
    877      * Set the value for a drawable feature of this window, from a URI. You
    878      * must have called requestFeature(featureId) before calling this
    879      * function.
    880      *
    881      * <p>The only URI currently supported is "content:", specifying an image
    882      * in a content provider.
    883      *
    884      * @see android.widget.ImageView#setImageURI
    885      *
    886      * @param featureId The desired drawable feature to change. Features are
    887      * constants defined by Window.
    888      * @param uri The desired URI.
    889      */
    890     public abstract void setFeatureDrawableUri(int featureId, Uri uri);
    891 
    892     /**
    893      * Set an explicit Drawable value for feature of this window. You must
    894      * have called requestFeature(featureId) before calling this function.
    895      *
    896      * @param featureId The desired drawable feature to change.
    897      * Features are constants defined by Window.
    898      * @param drawable A Drawable object to display.
    899      */
    900     public abstract void setFeatureDrawable(int featureId, Drawable drawable);
    901 
    902     /**
    903      * Set a custom alpha value for the given drawale feature, controlling how
    904      * much the background is visible through it.
    905      *
    906      * @param featureId The desired drawable feature to change.
    907      * Features are constants defined by Window.
    908      * @param alpha The alpha amount, 0 is completely transparent and 255 is
    909      *              completely opaque.
    910      */
    911     public abstract void setFeatureDrawableAlpha(int featureId, int alpha);
    912 
    913     /**
    914      * Set the integer value for a feature.  The range of the value depends on
    915      * the feature being set.  For FEATURE_PROGRESSS, it should go from 0 to
    916      * 10000. At 10000 the progress is complete and the indicator hidden.
    917      *
    918      * @param featureId The desired feature to change.
    919      * Features are constants defined by Window.
    920      * @param value The value for the feature.  The interpretation of this
    921      *              value is feature-specific.
    922      */
    923     public abstract void setFeatureInt(int featureId, int value);
    924 
    925     /**
    926      * Request that key events come to this activity. Use this if your
    927      * activity has no views with focus, but the activity still wants
    928      * a chance to process key events.
    929      */
    930     public abstract void takeKeyEvents(boolean get);
    931 
    932     /**
    933      * Used by custom windows, such as Dialog, to pass the key press event
    934      * further down the view hierarchy. Application developers should
    935      * not need to implement or call this.
    936      *
    937      */
    938     public abstract boolean superDispatchKeyEvent(KeyEvent event);
    939 
    940     /**
    941      * Used by custom windows, such as Dialog, to pass the touch screen event
    942      * further down the view hierarchy. Application developers should
    943      * not need to implement or call this.
    944      *
    945      */
    946     public abstract boolean superDispatchTouchEvent(MotionEvent event);
    947 
    948     /**
    949      * Used by custom windows, such as Dialog, to pass the trackball event
    950      * further down the view hierarchy. Application developers should
    951      * not need to implement or call this.
    952      *
    953      */
    954     public abstract boolean superDispatchTrackballEvent(MotionEvent event);
    955 
    956     /**
    957      * Retrieve the top-level window decor view (containing the standard
    958      * window frame/decorations and the client's content inside of that), which
    959      * can be added as a window to the window manager.
    960      *
    961      * <p><em>Note that calling this function for the first time "locks in"
    962      * various window characteristics as described in
    963      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}.</em></p>
    964      *
    965      * @return Returns the top-level window decor view.
    966      */
    967     public abstract View getDecorView();
    968 
    969     /**
    970      * Retrieve the current decor view, but only if it has already been created;
    971      * otherwise returns null.
    972      *
    973      * @return Returns the top-level window decor or null.
    974      * @see #getDecorView
    975      */
    976     public abstract View peekDecorView();
    977 
    978     public abstract Bundle saveHierarchyState();
    979 
    980     public abstract void restoreHierarchyState(Bundle savedInstanceState);
    981 
    982     protected abstract void onActive();
    983 
    984     /**
    985      * Return the feature bits that are enabled.  This is the set of features
    986      * that were given to requestFeature(), and are being handled by this
    987      * Window itself or its container.  That is, it is the set of
    988      * requested features that you can actually use.
    989      *
    990      * <p>To do: add a public version of this API that allows you to check for
    991      * features by their feature ID.
    992      *
    993      * @return int The feature bits.
    994      */
    995     protected final int getFeatures()
    996     {
    997         return mFeatures;
    998     }
    999 
   1000     /**
   1001      * Return the feature bits that are being implemented by this Window.
   1002      * This is the set of features that were given to requestFeature(), and are
   1003      * being handled by only this Window itself, not by its containers.
   1004      *
   1005      * @return int The feature bits.
   1006      */
   1007     protected final int getLocalFeatures()
   1008     {
   1009         return mLocalFeatures;
   1010     }
   1011 
   1012     /**
   1013      * Set the default format of window, as per the PixelFormat types.  This
   1014      * is the format that will be used unless the client specifies in explicit
   1015      * format with setFormat();
   1016      *
   1017      * @param format The new window format (see PixelFormat).
   1018      *
   1019      * @see #setFormat
   1020      * @see PixelFormat
   1021      */
   1022     protected void setDefaultWindowFormat(int format) {
   1023         mDefaultWindowFormat = format;
   1024         if (!mHaveWindowFormat) {
   1025             final WindowManager.LayoutParams attrs = getAttributes();
   1026             attrs.format = format;
   1027             if (mCallback != null) {
   1028                 mCallback.onWindowAttributesChanged(attrs);
   1029             }
   1030         }
   1031     }
   1032 
   1033     public abstract void setChildDrawable(int featureId, Drawable drawable);
   1034 
   1035     public abstract void setChildInt(int featureId, int value);
   1036 
   1037     /**
   1038      * Is a keypress one of the defined shortcut keys for this window.
   1039      * @param keyCode the key code from {@link android.view.KeyEvent} to check.
   1040      * @param event the {@link android.view.KeyEvent} to use to help check.
   1041      */
   1042     public abstract boolean isShortcutKey(int keyCode, KeyEvent event);
   1043 
   1044     /**
   1045      * @see android.app.Activity#setVolumeControlStream(int)
   1046      */
   1047     public abstract void setVolumeControlStream(int streamType);
   1048 
   1049     /**
   1050      * @see android.app.Activity#getVolumeControlStream()
   1051      */
   1052     public abstract int getVolumeControlStream();
   1053 
   1054 }
   1055