Merge change 1408 into donut

* changes:
  * update all metrics data when updating density. * Keyboard should use DisplayMetrics from Resource rather than getting it from WindowManager as   the display metrics can differ under compatibility mode.
This commit is contained in:
Android (Google) Code Review
2009-05-11 21:20:55 -07:00
3 changed files with 33 additions and 15 deletions

View File

@@ -191,16 +191,11 @@ public final class ActivityThread {
usePreloaded = false; usePreloaded = false;
DisplayMetrics newMetrics = new DisplayMetrics(); DisplayMetrics newMetrics = new DisplayMetrics();
newMetrics.setTo(metrics); newMetrics.setTo(metrics);
float invertedScale = 1.0f / applicationScale; float newDensity = metrics.density / applicationScale;
newMetrics.density *= invertedScale; newMetrics.updateDensity(newDensity);
newMetrics.xdpi *= invertedScale;
newMetrics.ydpi *= invertedScale;
newMetrics.widthPixels *= invertedScale;
newMetrics.heightPixels *= invertedScale;
metrics = newMetrics; metrics = newMetrics;
} }
//Log.i(TAG, "Resource:" + appDir + ", density " + newMetrics.density + ", orig density:" + //Log.i(TAG, "Resource:" + appDir + ", display metrics=" + metrics);
// metrics.density);
r = new Resources(assets, metrics, getConfiguration(), usePreloaded); r = new Resources(assets, metrics, getConfiguration(), usePreloaded);
//Log.i(TAG, "Created app resources " + r + ": " + r.getConfiguration()); //Log.i(TAG, "Created app resources " + r + ": " + r.getConfiguration());
// XXX need to remove entries when weak references go away // XXX need to remove entries when weak references go away
@@ -3502,8 +3497,11 @@ public final class ActivityThread {
Resources r = v.get(); Resources r = v.get();
if (r != null) { if (r != null) {
// keep the original density based on application cale. // keep the original density based on application cale.
appDm.density = r.getDisplayMetrics().density; appDm.updateDensity(r.getDisplayMetrics().density);
Log.i("oshima", "Updated app display metrics " + appDm);
r.updateConfiguration(config, appDm); r.updateConfiguration(config, appDm);
// reset
appDm.setTo(dm);
//Log.i(TAG, "Updated app resources " + v.getKey() //Log.i(TAG, "Updated app resources " + v.getKey()
// + " " + r + ": " + r.getConfiguration()); // + " " + r + ": " + r.getConfiguration());
} else { } else {

View File

@@ -27,8 +27,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.util.Xml; import android.util.Xml;
import android.view.Display; import android.util.DisplayMetrics;
import android.view.WindowManager;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -510,10 +509,11 @@ public class Keyboard {
* @param modeId keyboard mode identifier * @param modeId keyboard mode identifier
*/ */
public Keyboard(Context context, int xmlLayoutResId, int modeId) { public Keyboard(Context context, int xmlLayoutResId, int modeId) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = context.getResources().getDisplayMetrics();
final Display display = wm.getDefaultDisplay(); mDisplayWidth = dm.widthPixels;
mDisplayWidth = display.getWidth(); mDisplayHeight = dm.heightPixels;
mDisplayHeight = display.getHeight(); //Log.v(TAG, "keyboard's display metrics:" + dm);
mDefaultHorizontalGap = 0; mDefaultHorizontalGap = 0;
mDefaultWidth = mDisplayWidth / 10; mDefaultWidth = mDisplayWidth / 10;
mDefaultVerticalGap = 0; mDefaultVerticalGap = 0;

View File

@@ -99,4 +99,24 @@ public class DisplayMetrics {
xdpi = DEVICE_DENSITY; xdpi = DEVICE_DENSITY;
ydpi = DEVICE_DENSITY; ydpi = DEVICE_DENSITY;
} }
/**
* Set the display metrics' density and update parameters depend on it.
* @hide
*/
public void updateDensity(float newDensity) {
float ratio = newDensity / density;
density = newDensity;
scaledDensity = density;
widthPixels *= ratio;
heightPixels *= ratio;
xdpi *= ratio;
ydpi *= ratio;
}
public String toString() {
return "DisplayMetrics{density=" + density + ", width=" + widthPixels +
", height=" + heightPixels + ", scaledDensity=" + scaledDensity +
", xdpi=" + xdpi + ", ydpi=" + ydpi + "}";
}
} }