The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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.util; |
| 18 | |
| 19 | import android.os.*; |
| 20 | |
| 21 | |
| 22 | /** |
| 23 | * A structure describing general information about a display, such as its |
| 24 | * size, density, and font scaling. |
| 25 | */ |
| 26 | public class DisplayMetrics { |
| 27 | /** |
| 28 | * The reference density used throughout the system. |
| 29 | * |
| 30 | * @hide Pending API council approval |
| 31 | */ |
| 32 | public static final int DEFAULT_DENSITY = 160; |
| 33 | |
Mitsuru Oshima | 2e3d3b9 | 2009-05-06 15:04:28 -0700 | [diff] [blame^] | 34 | /** |
| 35 | * The device's density. |
| 36 | * @hide |
| 37 | */ |
| 38 | public static final int DEVICE_DENSITY = SystemProperties.getInt("ro.sf.lcd_density", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | DEFAULT_DENSITY); |
| 40 | |
| 41 | /** |
| 42 | * The absolute width of the display in pixels. |
| 43 | */ |
| 44 | public int widthPixels; |
| 45 | /** |
| 46 | * The absolute height of the display in pixels. |
| 47 | */ |
| 48 | public int heightPixels; |
| 49 | /** |
| 50 | * The logical density of the display. This is a scaling factor for the |
| 51 | * Density Independent Pixel unit, where one DIP is one pixel on an |
| 52 | * approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen), |
| 53 | * providing the baseline of the system's display. Thus on a 160dpi screen |
| 54 | * this density value will be 1; on a 106 dpi screen it would be .75; etc. |
| 55 | * |
| 56 | * <p>This value does not exactly follow the real screen size (as given by |
| 57 | * {@link #xdpi} and {@link #ydpi}, but rather is used to scale the size of |
| 58 | * the overall UI in steps based on gross changes in the display dpi. For |
| 59 | * example, a 240x320 screen will have a density of 1 even if its width is |
| 60 | * 1.8", 1.3", etc. However, if the screen resolution is increased to |
| 61 | * 320x480 but the screen size remained 1.5"x2" then the density would be |
| 62 | * increased (probably to 1.5). |
| 63 | * |
| 64 | * @see #DEFAULT_DENSITY |
| 65 | */ |
| 66 | public float density; |
| 67 | /** |
| 68 | * A scaling factor for fonts displayed on the display. This is the same |
| 69 | * as {@link #density}, except that it may be adjusted in smaller |
| 70 | * increments at runtime based on a user preference for the font size. |
| 71 | */ |
| 72 | public float scaledDensity; |
| 73 | /** |
| 74 | * The exact physical pixels per inch of the screen in the X dimension. |
| 75 | */ |
| 76 | public float xdpi; |
| 77 | /** |
| 78 | * The exact physical pixels per inch of the screen in the Y dimension. |
| 79 | */ |
| 80 | public float ydpi; |
| 81 | |
| 82 | public DisplayMetrics() { |
| 83 | } |
| 84 | |
| 85 | public void setTo(DisplayMetrics o) { |
| 86 | widthPixels = o.widthPixels; |
| 87 | heightPixels = o.heightPixels; |
| 88 | density = o.density; |
| 89 | scaledDensity = o.scaledDensity; |
| 90 | xdpi = o.xdpi; |
| 91 | ydpi = o.ydpi; |
| 92 | } |
| 93 | |
| 94 | public void setToDefaults() { |
| 95 | widthPixels = 0; |
| 96 | heightPixels = 0; |
Mitsuru Oshima | 2e3d3b9 | 2009-05-06 15:04:28 -0700 | [diff] [blame^] | 97 | density = DEVICE_DENSITY / (float) DEFAULT_DENSITY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | scaledDensity = density; |
Mitsuru Oshima | 2e3d3b9 | 2009-05-06 15:04:28 -0700 | [diff] [blame^] | 99 | xdpi = DEVICE_DENSITY; |
| 100 | ydpi = DEVICE_DENSITY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | } |
| 102 | } |