diff options
| author | 2009-05-06 15:04:28 -0700 | |
|---|---|---|
| committer | 2009-05-06 16:42:11 -0700 | |
| commit | 2e3d3b9ce74cb9c906e5cc0e9898d757d45c4237 (patch) | |
| tree | 290b7354db79d006ae9aae1c22bc496ba8161090 | |
| parent | f2331a63c0e7f6ffeedf16185c92a0aeffa5512c (diff) | |
* update density correctly when the configuration is changed.
* Turns private sLcdDensity to public DEVICE_DENSITY to use it in ActivityThread
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 12 | ||||
| -rw-r--r-- | core/java/android/util/DisplayMetrics.java | 12 |
2 files changed, 15 insertions, 9 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index dfa3fa8f1471..2fc476ec603d 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -316,18 +316,16 @@ public final class ActivityThread { float appScale = -1.0f; if (ai.supportsDensities != null) { - // TODO: precompute this in DisplayMetrics - float systemDensityDpi = metrics.density * DisplayMetrics.DEFAULT_DENSITY; int minDiff = Integer.MAX_VALUE; for (int density : ai.supportsDensities) { - int tmpDiff = (int) Math.abs(systemDensityDpi - density); + int tmpDiff = (int) Math.abs(DisplayMetrics.DEVICE_DENSITY - density); if (tmpDiff == 0) { appScale = 1.0f; break; } // prefer higher density (appScale>1.0), unless that's only option. if (tmpDiff < minDiff && appScale < 1.0f) { - appScale = systemDensityDpi / density; + appScale = DisplayMetrics.DEVICE_DENSITY / density; minDiff = tmpDiff; } } @@ -3482,6 +3480,8 @@ public final class ActivityThread { } mConfiguration.updateFrom(config); DisplayMetrics dm = getDisplayMetricsLocked(true); + DisplayMetrics appDm = new DisplayMetrics(); + appDm.setTo(dm); // set it for java, this also affects newly created Resources if (config.locale != null) { @@ -3501,7 +3501,9 @@ public final class ActivityThread { WeakReference<Resources> v = it.next(); Resources r = v.get(); if (r != null) { - r.updateConfiguration(config, dm); + // keep the original density based on application cale. + appDm.density = r.getDisplayMetrics().density; + r.updateConfiguration(config, appDm); //Log.i(TAG, "Updated app resources " + v.getKey() // + " " + r + ": " + r.getConfiguration()); } else { diff --git a/core/java/android/util/DisplayMetrics.java b/core/java/android/util/DisplayMetrics.java index 9de4cbe80665..095f4f476417 100644 --- a/core/java/android/util/DisplayMetrics.java +++ b/core/java/android/util/DisplayMetrics.java @@ -31,7 +31,11 @@ public class DisplayMetrics { */ public static final int DEFAULT_DENSITY = 160; - private static final int sLcdDensity = SystemProperties.getInt("ro.sf.lcd_density", + /** + * The device's density. + * @hide + */ + public static final int DEVICE_DENSITY = SystemProperties.getInt("ro.sf.lcd_density", DEFAULT_DENSITY); /** @@ -90,9 +94,9 @@ public class DisplayMetrics { public void setToDefaults() { widthPixels = 0; heightPixels = 0; - density = sLcdDensity / (float) DEFAULT_DENSITY; + density = DEVICE_DENSITY / (float) DEFAULT_DENSITY; scaledDensity = density; - xdpi = sLcdDensity; - ydpi = sLcdDensity; + xdpi = DEVICE_DENSITY; + ydpi = DEVICE_DENSITY; } } |