1/* 2 * Copyright (C) 2011 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 com.android.layoutlib.bridge.android.BridgeWindowManager; 20import com.android.layoutlib.bridge.impl.RenderAction; 21import com.android.tools.layoutlib.annotations.LayoutlibDelegate; 22 23import android.os.RemoteException; 24 25/** 26 * Delegate used to provide new implementation of a select few methods of {@link Display} 27 * 28 * Through the layoutlib_create tool, the original methods of Display have been replaced 29 * by calls to methods of the same name in this delegate class. 30 * 31 */ 32public class Display_Delegate { 33 34 // ---- Overridden methods ---- 35 36 @LayoutlibDelegate 37 public static IWindowManager getWindowManager() { 38 return RenderAction.getCurrentContext().getIWindowManager(); 39 } 40 41 // ---- Native methods ---- 42 43 @LayoutlibDelegate 44 /*package*/ static int getDisplayCount() { 45 return 1; 46 } 47 48 @LayoutlibDelegate 49 /** @hide special for when we are faking the screen size. */ 50 /*package*/ static int getRawWidthNative(Display theDisplay) { 51 // same as real since we're not faking compatibility mode. 52 return RenderAction.getCurrentContext().getIWindowManager().getMetrics().widthPixels; 53 } 54 55 @LayoutlibDelegate 56 /** @hide special for when we are faking the screen size. */ 57 /*package*/ static int getRawHeightNative(Display theDisplay) { 58 // same as real since we're not faking compatibility mode. 59 return RenderAction.getCurrentContext().getIWindowManager().getMetrics().heightPixels; 60 } 61 62 @LayoutlibDelegate 63 /*package*/ static int getOrientation(Display theDisplay) { 64 try { 65 // always dynamically query for the current window manager 66 return getWindowManager().getRotation(); 67 } catch (RemoteException e) { 68 // this will never been thrown since this is not a true RPC. 69 } 70 71 return Surface.ROTATION_0; 72 } 73 74 @LayoutlibDelegate 75 /*package*/ static void nativeClassInit() { 76 // not needed for now. 77 } 78 79 @LayoutlibDelegate 80 /*package*/ static void init(Display theDisplay, int display) { 81 // always dynamically query for the current window manager 82 BridgeWindowManager wm = RenderAction.getCurrentContext().getIWindowManager(); 83 theDisplay.mDensity = wm.getMetrics().density; 84 theDisplay.mDpiX = wm.getMetrics().xdpi; 85 theDisplay.mDpiY = wm.getMetrics().ydpi; 86 } 87} 88