WindowManagerImpl.java revision bd6e1500aedc5461e832f69e76341bff0e55fa2b
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.view; 18 19import android.content.Context; 20import android.hardware.display.DisplayManager; 21 22/** 23 * Provides low-level communication with the system window manager for 24 * operations that are bound to a particular context, display or parent window. 25 * Instances of this object are sensitive to the compatibility info associated 26 * with the running application. 27 * 28 * This object implements the {@link ViewManager} interface, 29 * allowing you to add any View subclass as a top-level window on the screen. 30 * Additional window manager specific layout parameters are defined for 31 * control over how windows are displayed. It also implements the {@link WindowManager} 32 * interface, allowing you to control the displays attached to the device. 33 * 34 * <p>Applications will not normally use WindowManager directly, instead relying 35 * on the higher-level facilities in {@link android.app.Activity} and 36 * {@link android.app.Dialog}. 37 * 38 * <p>Even for low-level window manager access, it is almost never correct to use 39 * this class. For example, {@link android.app.Activity#getWindowManager} 40 * provides a window manager for adding windows that are associated with that 41 * activity -- the window manager will not normally allow you to add arbitrary 42 * windows that are not associated with an activity. 43 * 44 * @see WindowManager 45 * @see WindowManagerGlobal 46 * @hide 47 */ 48public final class WindowManagerImpl implements WindowManager { 49 private final WindowManagerGlobal mGlobal = WindowManagerGlobal.getInstance(); 50 private final Context mContext; 51 private final Display mDisplay; 52 private final Window mParentWindow; 53 54 public WindowManagerImpl(Context context, int displayId) { 55 DisplayManager dm = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); 56 mContext = context; 57 mDisplay = dm.getDisplay(displayId); 58 mParentWindow = null; 59 } 60 61 private WindowManagerImpl(Context context, Display display, Window parentWindow) { 62 mContext = context; 63 mDisplay = display; 64 mParentWindow = parentWindow; 65 } 66 67 public WindowManagerImpl createLocalWindowManager(Window parentWindow) { 68 return new WindowManagerImpl(mContext, mDisplay, parentWindow); 69 } 70 71 @Override 72 public void addView(View view, ViewGroup.LayoutParams params) { 73 mGlobal.addView(view, params, mDisplay, mParentWindow); 74 } 75 76 @Override 77 public void updateViewLayout(View view, ViewGroup.LayoutParams params) { 78 mGlobal.updateViewLayout(view, params); 79 } 80 81 @Override 82 public void removeView(View view) { 83 mGlobal.removeView(view, false); 84 } 85 86 @Override 87 public void removeViewImmediate(View view) { 88 mGlobal.removeView(view, true); 89 } 90 91 @Override 92 public Display getDefaultDisplay() { 93 return mDisplay; 94 } 95} 96