summaryrefslogtreecommitdiffstats
path: root/core/java/android/util/DisplayMetrics.java
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2009-07-29 14:25:07 -0700
committerJean-Baptiste Queru <jbq@google.com>2009-07-29 14:25:07 -0700
commita8675f67e33bc7337d148358783b0fd138b501ff (patch)
tree71fb9d10330ef9161b3ead71d01074b3ef9e53ba /core/java/android/util/DisplayMetrics.java
parentcf4550c3198d6b3d92cdc52707fe70d7cc0caa9f (diff)
downloadframeworks_base-a8675f67e33bc7337d148358783b0fd138b501ff.zip
frameworks_base-a8675f67e33bc7337d148358783b0fd138b501ff.tar.gz
frameworks_base-a8675f67e33bc7337d148358783b0fd138b501ff.tar.bz2
donut snapshot
Diffstat (limited to 'core/java/android/util/DisplayMetrics.java')
-rw-r--r--core/java/android/util/DisplayMetrics.java135
1 files changed, 83 insertions, 52 deletions
diff --git a/core/java/android/util/DisplayMetrics.java b/core/java/android/util/DisplayMetrics.java
index 4179edb..061f98a 100644
--- a/core/java/android/util/DisplayMetrics.java
+++ b/core/java/android/util/DisplayMetrics.java
@@ -27,17 +27,31 @@ import android.os.*;
*/
public class DisplayMetrics {
/**
+ * Standard quantized DPI for low-density screens.
+ */
+ public static final int DENSITY_LOW = 120;
+
+ /**
+ * Standard quantized DPI for medium-density screens.
+ */
+ public static final int DENSITY_MEDIUM = 160;
+
+ /**
+ * Standard quantized DPI for high-density screens.
+ */
+ public static final int DENSITY_HIGH = 240;
+
+ /**
* The reference density used throughout the system.
- *
- * @hide Pending API council approval
*/
- public static final int DEFAULT_DENSITY = 160;
+ public static final int DENSITY_DEFAULT = DENSITY_MEDIUM;
/**
* The device's density.
- * @hide
+ * @hide becase eventually this should be able to change while
+ * running, so shouldn't be a constant.
*/
- public static final int DEVICE_DENSITY = getDeviceDensity();
+ public static final int DENSITY_DEVICE = getDeviceDensity();
/**
* The absolute width of the display in pixels.
@@ -62,7 +76,7 @@ public class DisplayMetrics {
* 320x480 but the screen size remained 1.5"x2" then the density would be
* increased (probably to 1.5).
*
- * @see #DEFAULT_DENSITY
+ * @see #DENSITY_DEFAULT
*/
public float density;
/**
@@ -95,10 +109,10 @@ public class DisplayMetrics {
public void setToDefaults() {
widthPixels = 0;
heightPixels = 0;
- density = DEVICE_DENSITY / (float) DEFAULT_DENSITY;
+ density = DENSITY_DEVICE / (float) DENSITY_DEFAULT;
scaledDensity = density;
- xdpi = DEVICE_DENSITY;
- ydpi = DEVICE_DENSITY;
+ xdpi = DENSITY_DEVICE;
+ ydpi = DENSITY_DEVICE;
}
/**
@@ -109,60 +123,77 @@ public class DisplayMetrics {
*/
public void updateMetrics(CompatibilityInfo compatibilityInfo, int orientation,
int screenLayout) {
- int xOffset = 0;
- if (!compatibilityInfo.isConfiguredExpandable()) {
- // Note: this assume that configuration is updated before calling
- // updateMetrics method.
- if (screenLayout == Configuration.SCREENLAYOUT_LARGE) {
- // This is a large screen device and the app is not
- // compatible with large screens, to diddle it.
-
+ boolean expandable = compatibilityInfo.isConfiguredExpandable();
+ boolean largeScreens = compatibilityInfo.isConfiguredLargeScreens();
+
+ // Note: this assume that configuration is updated before calling
+ // updateMetrics method.
+ if (!expandable) {
+ if ((screenLayout&Configuration.SCREENLAYOUT_COMPAT_NEEDED) == 0) {
+ expandable = true;
+ // the current screen size is compatible with non-resizing apps.
+ compatibilityInfo.setExpandable(true);
+ } else {
compatibilityInfo.setExpandable(false);
- // Figure out the compatibility width and height of the screen.
- int defaultWidth;
- int defaultHeight;
- switch (orientation) {
- case Configuration.ORIENTATION_LANDSCAPE: {
- defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density);
- defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density);
- break;
- }
- case Configuration.ORIENTATION_PORTRAIT:
- case Configuration.ORIENTATION_SQUARE:
- default: {
- defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density);
- defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density);
- break;
- }
- case Configuration.ORIENTATION_UNDEFINED: {
- // don't change
- return;
- }
+ }
+ }
+ if (!largeScreens) {
+ if ((screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK)
+ != Configuration.SCREENLAYOUT_SIZE_LARGE) {
+ largeScreens = true;
+ // the current screen size is not large.
+ compatibilityInfo.setLargeScreens(true);
+ } else {
+ compatibilityInfo.setLargeScreens(false);
+ }
+ }
+
+ if (!expandable || !largeScreens) {
+ // This is a larger screen device and the app is not
+ // compatible with large screens, so diddle it.
+
+ // Figure out the compatibility width and height of the screen.
+ int defaultWidth;
+ int defaultHeight;
+ switch (orientation) {
+ case Configuration.ORIENTATION_LANDSCAPE: {
+ defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density +
+ 0.5f);
+ defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density +
+ 0.5f);
+ break;
}
-
- if (defaultWidth < widthPixels) {
- // content/window's x offset in original pixels
- xOffset = ((widthPixels - defaultWidth) / 2);
- widthPixels = defaultWidth;
+ case Configuration.ORIENTATION_PORTRAIT:
+ case Configuration.ORIENTATION_SQUARE:
+ default: {
+ defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density +
+ 0.5f);
+ defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density +
+ 0.5f);
+ break;
}
- if (defaultHeight < heightPixels) {
- heightPixels = defaultHeight;
+ case Configuration.ORIENTATION_UNDEFINED: {
+ // don't change
+ return;
}
-
- } else {
- // the screen size is same as expected size. make it expandable
- compatibilityInfo.setExpandable(true);
+ }
+
+ if (defaultWidth < widthPixels) {
+ // content/window's x offset in original pixels
+ widthPixels = defaultWidth;
+ }
+ if (defaultHeight < heightPixels) {
+ heightPixels = defaultHeight;
}
}
- compatibilityInfo.setVisibleRect(xOffset, widthPixels, heightPixels);
if (compatibilityInfo.isScalingRequired()) {
float invertedRatio = compatibilityInfo.applicationInvertedScale;
density *= invertedRatio;
scaledDensity *= invertedRatio;
xdpi *= invertedRatio;
ydpi *= invertedRatio;
- widthPixels *= invertedRatio;
- heightPixels *= invertedRatio;
+ widthPixels = (int) (widthPixels * invertedRatio + 0.5f);
+ heightPixels = (int) (heightPixels * invertedRatio + 0.5f);
}
}
@@ -179,6 +210,6 @@ public class DisplayMetrics {
// The reason for this is that ro.sf.lcd_density is write-once and is
// set by the init process when it parses build.prop before anything else.
return SystemProperties.getInt("qemu.sf.lcd_density",
- SystemProperties.getInt("ro.sf.lcd_density", DEFAULT_DENSITY));
+ SystemProperties.getInt("ro.sf.lcd_density", DENSITY_DEFAULT));
}
}