From 569076c9f6bdadb4d3285a26e069634a839b5b87 Mon Sep 17 00:00:00 2001 From: Mitsuru Oshima Date: Thu, 2 Jul 2009 20:06:08 -0700 Subject: widgets scaling fix. Use container's compatibility info and display metrics when container and widgets disagree. --- .../android/content/res/CompatibilityInfo.java | 28 ++++++++++++++++++---- core/java/android/content/res/Resources.java | 22 ++++++++++++++++- 2 files changed, 44 insertions(+), 6 deletions(-) (limited to 'core/java/android/content') diff --git a/core/java/android/content/res/CompatibilityInfo.java b/core/java/android/content/res/CompatibilityInfo.java index 4e6fe07..dfe304d 100644 --- a/core/java/android/content/res/CompatibilityInfo.java +++ b/core/java/android/content/res/CompatibilityInfo.java @@ -159,15 +159,33 @@ public class CompatibilityInfo { } } + private CompatibilityInfo(int appFlags, int compFlags, float scale, float invertedScale) { + this.appFlags = appFlags; + mCompatibilityFlags = compFlags; + applicationScale = scale; + applicationInvertedScale = invertedScale; + } + private CompatibilityInfo() { - appFlags = ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS + this(ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS - | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; - applicationScale = applicationInvertedScale = 1.0f; - mCompatibilityFlags = EXPANDABLE | CONFIGURED_EXPANDABLE; + | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS, + EXPANDABLE | CONFIGURED_EXPANDABLE, + 1.0f, + 1.0f); } /** + * Returns the copy of this instance. + */ + public CompatibilityInfo copy() { + CompatibilityInfo info = new CompatibilityInfo(appFlags, mCompatibilityFlags, + applicationScale, applicationInvertedScale); + info.setVisibleRect(mXOffset, mWidth, mHeight); + return info; + } + + /** * Sets the application's visible rect in compatibility mode. * @param xOffset the application's x offset that is added to center the content. * @param widthPixels the application's width in real pixels on the screen. @@ -470,4 +488,4 @@ public class CompatibilityInfo { return mVisibleInsets; } } -} \ No newline at end of file +} diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index d7512bb..49ad656 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -129,7 +129,7 @@ public class Resources { */ public Resources(AssetManager assets, DisplayMetrics metrics, Configuration config) { - this(assets, metrics, config, null); + this(assets, metrics, config, (ApplicationInfo) null); } /** @@ -166,6 +166,26 @@ public class Resources { } /** + * Creates a new resources that uses the given compatibility info. Used to create + * a context for widgets using the container's compatibility info. + * {@see ApplicationContext#createPackageCotnext}. + * @hide + */ + public Resources(AssetManager assets, DisplayMetrics metrics, + Configuration config, CompatibilityInfo info) { + mAssets = assets; + mMetrics.setToDefaults(); + mCompatibilityInfo = info; + updateConfiguration(config, metrics); + assets.ensureStringBlocks(); + if (mCompatibilityInfo.isScalingRequired()) { + mPreloadedDrawables = emptySparseArray(); + } else { + mPreloadedDrawables = sPreloadedDrawables; + } + } + + /** * Return a global shared Resources object that provides access to only * system resources (no application resources), and is not configured for * the current screen (can not use dimension units, does not change based -- cgit v1.1