ScreenShapeHelper.java revision a0938021718867edd267d4905f3c17ef2944aa65
1package com.android.internal.util; 2 3import android.content.res.Resources; 4import android.content.res.TypedArray; 5import android.os.Build; 6import android.os.SystemProperties; 7import android.util.DisplayMetrics; 8import android.util.TypedValue; 9import android.view.ViewRootImpl; 10 11import com.android.internal.R; 12 13/** 14 * @hide 15 */ 16public class ScreenShapeHelper { 17 private static final boolean IS_EMULATOR = Build.HARDWARE.contains("goldfish"); 18 19 /** 20 * Return the bottom pixel window outset of a window given its style attributes. 21 * @param displayMetrics Display metrics of the current device 22 * @param windowStyle Window style attributes for the window. 23 * @return An outset dimension in pixels or 0 if no outset should be applied. 24 */ 25 public static int getWindowOutsetBottomPx(DisplayMetrics displayMetrics, 26 TypedArray windowStyle) { 27 if (IS_EMULATOR) { 28 return SystemProperties.getInt(ViewRootImpl.PROPERTY_EMULATOR_WIN_OUTSET_BOTTOM_PX, 0); 29 } else if (windowStyle.hasValue(R.styleable.Window_windowOutsetBottom)) { 30 TypedValue outsetBottom = new TypedValue(); 31 windowStyle.getValue(R.styleable.Window_windowOutsetBottom, outsetBottom); 32 return (int) outsetBottom.getDimension(displayMetrics); 33 } 34 return 0; 35 } 36 37 /** 38 * Get whether a device has has a round screen. 39 */ 40 public static boolean getWindowIsRound(Resources resources) { 41 if (IS_EMULATOR) { 42 return SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false); 43 } else { 44 return resources.getBoolean( 45 com.android.internal.R.bool.config_windowIsRound); 46 } 47 } 48} 49