diff options
author | Mitsuru Oshima <oshima@google.com> | 2009-06-03 11:19:12 -0700 |
---|---|---|
committer | Mitsuru Oshima <oshima@google.com> | 2009-06-03 16:28:10 -0700 |
commit | 9189cabb0b6c6c28232fe6f412b7ba7a37352a6a (patch) | |
tree | 6ddc6a8eb0158cba32cc6139b04c6b6eb9f0ba5f /core/java/android/content | |
parent | eaeb663bcd7a82b654954b42663232cbd7bef7e7 (diff) | |
download | frameworks_base-9189cabb0b6c6c28232fe6f412b7ba7a37352a6a.zip frameworks_base-9189cabb0b6c6c28232fe6f412b7ba7a37352a6a.tar.gz frameworks_base-9189cabb0b6c6c28232fe6f412b7ba7a37352a6a.tar.bz2 |
* Moved supports-density tag under manifest
* Refactored Compatibility code
* Added CompatibilityInfo class
* Removed getApplicationScale from Context
* Added Resources#getCompatibilityInfo so that RootView can get the compatibility info w/o going through Context
* Expandable support
* Added expandable tag under manifest
* Old application w/o expandable is given the default screen size ([320, 480] x density).
* The non-expandable window is centered.
Diffstat (limited to 'core/java/android/content')
-rw-r--r-- | core/java/android/content/Context.java | 10 | ||||
-rw-r--r-- | core/java/android/content/ContextWrapper.java | 8 | ||||
-rw-r--r-- | core/java/android/content/pm/ApplicationInfo.java | 11 | ||||
-rw-r--r-- | core/java/android/content/pm/PackageManager.java | 6 | ||||
-rw-r--r-- | core/java/android/content/pm/PackageParser.java | 49 | ||||
-rw-r--r-- | core/java/android/content/res/CompatibilityInfo.java | 102 | ||||
-rw-r--r-- | core/java/android/content/res/Resources.java | 44 |
7 files changed, 187 insertions, 43 deletions
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index c328d16..ec847a4 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -527,16 +527,6 @@ public abstract class Context { public abstract int getWallpaperDesiredMinimumHeight(); /** - * Returns the scale in which the application will be drawn on the - * screen. This is usually 1.0f if the application supports the device's - * resolution/density. This will be 1.5f, for example, if the application - * that supports only 160 density runs on 240 density screen. - * - * @hide - */ - public abstract float getApplicationScale(); - - /** * Change the current system wallpaper to a bitmap. The given bitmap is * converted to a PNG and stored as the wallpaper. On success, the intent * {@link Intent#ACTION_WALLPAPER_CHANGED} is broadcast. diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java index 25b2cae..36e1c34 100644 --- a/core/java/android/content/ContextWrapper.java +++ b/core/java/android/content/ContextWrapper.java @@ -419,12 +419,4 @@ public class ContextWrapper extends Context { throws PackageManager.NameNotFoundException { return mBase.createPackageContext(packageName, flags); } - - /** - * @hide - */ - @Override - public float getApplicationScale() { - return mBase.getApplicationScale(); - } } diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java index f16eb74..f3dfc5a 100644 --- a/core/java/android/content/pm/ApplicationInfo.java +++ b/core/java/android/content/pm/ApplicationInfo.java @@ -186,7 +186,6 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { */ public int uid; - /** * The list of densities in DPI that application supprots. This * field is only set if the {@link PackageManager#GET_SUPPORTS_DENSITIES} flag was @@ -195,6 +194,12 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { public int[] supportsDensities; /** + * True when the application's window can be expanded over default window + * size in target density (320x480 for 1.0 density, 480x720 for 1.5 density etc) + */ + public boolean expandable = false; + + /** * The minimum SDK version this application targets. It may run on earilier * versions, but it knows how to work with any new behavior added at this * version. Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT} @@ -228,6 +233,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName); pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes)); pw.println(prefix + "supportsDensities=" + supportsDensities); + pw.println(prefix + "expandable=" + expandable); super.dumpBack(pw, prefix); } @@ -275,6 +281,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { manageSpaceActivityName = orig.manageSpaceActivityName; descriptionRes = orig.descriptionRes; supportsDensities = orig.supportsDensities; + expandable = orig.expandable; } @@ -307,6 +314,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { dest.writeString(backupAgentName); dest.writeInt(descriptionRes); dest.writeIntArray(supportsDensities); + dest.writeInt(expandable ? 1 : 0); } public static final Parcelable.Creator<ApplicationInfo> CREATOR @@ -338,6 +346,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { backupAgentName = source.readString(); descriptionRes = source.readInt(); supportsDensities = source.createIntArray(); + expandable = source.readInt() != 0; } /** diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index a2c82e8..6578391 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -180,6 +180,12 @@ public abstract class PackageManager { public static final int MATCH_DEFAULT_ONLY = 0x00010000; /** + * {@link ApplicationInfo} flag: return the + * {link ApplicationInfo#expandable} boolean flag of the package. + */ + public static final int GET_EXPANDABLE = 0x00020000; + + /** * Permission check result: this is returned by {@link #checkPermission} * if the permission has been granted to the given package. */ diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index 212b590..e2c0fe6 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -835,6 +835,26 @@ public class PackageParser { + parser.getName(); mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return null; + + + } else if (tagName.equals("supports-density")) { + sa = res.obtainAttributes(attrs, + com.android.internal.R.styleable.AndroidManifestSupportsDensity); + + int density = sa.getInteger( + com.android.internal.R.styleable.AndroidManifestSupportsDensity_density, -1); + + sa.recycle(); + + if (density != -1 && !pkg.supportsDensityList.contains(density)) { + pkg.supportsDensityList.add(density); + } + + XmlUtils.skipCurrentTag(parser); + + } else if (tagName.equals("expandable")) { + pkg.expandable = true; + XmlUtils.skipCurrentTag(parser); } else { Log.w(TAG, "Bad element under <manifest>: " + parser.getName()); @@ -866,7 +886,8 @@ public class PackageParser { pkg.usesLibraryFiles = new String[pkg.usesLibraries.size()]; pkg.usesLibraries.toArray(pkg.usesLibraryFiles); } - + // TODO: enable all density & expandable if target sdk is higher than donut + int size = pkg.supportsDensityList.size(); if (size > 0) { int densities[] = pkg.supportsDensities = new int[size]; @@ -1345,21 +1366,6 @@ public class PackageParser { XmlUtils.skipCurrentTag(parser); - } else if (tagName.equals("supports-density")) { - sa = res.obtainAttributes(attrs, - com.android.internal.R.styleable.AndroidManifestSupportsDensity); - - int density = sa.getInteger( - com.android.internal.R.styleable.AndroidManifestSupportsDensity_density, -1); - - sa.recycle(); - - if (density != -1 && !owner.supportsDensityList.contains(density)) { - owner.supportsDensityList.add(density); - } - - XmlUtils.skipCurrentTag(parser); - } else { if (!RIGID_PARSER) { Log.w(TAG, "Problem in package " + mArchiveSourcePath + ":"); @@ -2244,6 +2250,9 @@ public class PackageParser { public final ArrayList<Integer> supportsDensityList = new ArrayList<Integer>(); public int[] supportsDensities = null; + // If the application's window is expandable. + public boolean expandable; + // If this is a 3rd party app, this is the path of the zip file. public String mPath; @@ -2415,7 +2424,10 @@ public class PackageParser { return true; } if ((flags & PackageManager.GET_SUPPORTS_DENSITIES) != 0 - && p.supportsDensities != null) { + && p.supportsDensities != null) { + return true; + } + if ((flags & PackageManager.GET_EXPANDABLE) != 0) { return true; } return false; @@ -2438,6 +2450,9 @@ public class PackageParser { if ((flags & PackageManager.GET_SUPPORTS_DENSITIES) != 0) { ai.supportsDensities = p.supportsDensities; } + if ((flags & PackageManager.GET_EXPANDABLE) != 0) { + ai.expandable = p.expandable; + } return ai; } diff --git a/core/java/android/content/res/CompatibilityInfo.java b/core/java/android/content/res/CompatibilityInfo.java new file mode 100644 index 0000000..8a6a6f0 --- /dev/null +++ b/core/java/android/content/res/CompatibilityInfo.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.content.res; + +import android.content.pm.ApplicationInfo; +import android.util.DisplayMetrics; +import android.view.Gravity; + +/** + * CompatibilityInfo class keeps the information about compatibility mode that the application is + * running under. + * + * {@hide} + */ +public class CompatibilityInfo { + /** default compatibility info object for compatible applications */ + public static final CompatibilityInfo DEFAULT_COMPATIBILITY_INFO = new CompatibilityInfo(); + + /** + * The default width of the screen in portrait mode. + */ + public static final int DEFAULT_PORTRAIT_WIDTH = 320; + + /** + * The default height of the screen in portrait mode. + */ + public static final int DEFAULT_PORTRAIT_HEIGHT = 480; + + /** + * Application's scale. + */ + public final float mApplicationScale; + + /** + * Application's inverted scale. + */ + public final float mApplicationInvertedScale; + + /** + * + * A boolean flag to indicates that the application can expand over the original size. + */ + public final boolean mExpandable; + + /** + * A boolean flag to tell if the application needs scaling (when mApplicationScale != 1.0f) + */ + public final boolean mScalingRequired; + + public CompatibilityInfo(ApplicationInfo appInfo) { + mExpandable = appInfo.expandable; + float packageDensityScale = -1.0f; + if (appInfo.supportsDensities != null) { + int minDiff = Integer.MAX_VALUE; + for (int density : appInfo.supportsDensities) { + int tmpDiff = Math.abs(DisplayMetrics.DEVICE_DENSITY - density); + if (tmpDiff == 0) { + packageDensityScale = 1.0f; + break; + } + // prefer higher density (appScale>1.0), unless that's only option. + if (tmpDiff < minDiff && packageDensityScale < 1.0f) { + packageDensityScale = DisplayMetrics.DEVICE_DENSITY / (float) density; + minDiff = tmpDiff; + } + } + } + if (packageDensityScale > 0.0f) { + mApplicationScale = packageDensityScale; + } else { + mApplicationScale = DisplayMetrics.DEVICE_DENSITY / (float) DisplayMetrics.DEFAULT_DENSITY; + } + mApplicationInvertedScale = 1.0f / mApplicationScale; + mScalingRequired = mApplicationScale != 1.0f; + } + + private CompatibilityInfo() { + mApplicationScale = mApplicationInvertedScale = 1.0f; + mExpandable = true; + mScalingRequired = false; + } + + @Override + public String toString() { + return "CompatibilityInfo{scale=" + mApplicationScale + + ", expandable=" + mExpandable + "}"; + } +} diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index 665e40c..976b618 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -22,6 +22,8 @@ import com.android.internal.util.XmlUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import android.app.ActivityThread.PackageInfo; +import android.content.pm.ApplicationInfo; import android.graphics.Movie; import android.graphics.drawable.Drawable; import android.graphics.drawable.BitmapDrawable; @@ -84,7 +86,9 @@ public class Resources { private final Configuration mConfiguration = new Configuration(); /*package*/ final DisplayMetrics mMetrics = new DisplayMetrics(); PluralRules mPluralRule; - + + private final CompatibilityInfo mCompatibilityInfo; + private static final SparseArray<Object> EMPTY_ARRAY = new SparseArray<Object>() { @Override public void put(int k, Object o) { @@ -126,23 +130,36 @@ public class Resources { */ public Resources(AssetManager assets, DisplayMetrics metrics, Configuration config) { - this(assets, metrics, config, true); + this(assets, metrics, config, null); } /** - * Create a resource with an additional flag for preloaded - * drawable cache. Used by {@link ActivityThread}. - * + * Creates a new Resources object with ApplicationInfo. + * + * @param assets Previously created AssetManager. + * @param metrics Current display metrics to consider when + * selecting/computing resource values. + * @param config Desired device configuration to consider when + * selecting/computing resource values (optional). + * @param appInfo this resource's application info. * @hide */ public Resources(AssetManager assets, DisplayMetrics metrics, - Configuration config, boolean usePreloadedCache) { + Configuration config, ApplicationInfo appInfo) { mAssets = assets; mConfiguration.setToDefaults(); mMetrics.setToDefaults(); + if (appInfo != null) { + mCompatibilityInfo = new CompatibilityInfo(appInfo); + if (DEBUG_CONFIG) { + Log.d(TAG, "compatibility for " + appInfo.packageName + " : " + mCompatibilityInfo); + } + } else { + mCompatibilityInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; + } updateConfiguration(config, metrics); assets.ensureStringBlocks(); - if (usePreloadedCache) { + if (!mCompatibilityInfo.mScalingRequired) { mPreloadedDrawables = sPreloadedDrawables; } else { mPreloadedDrawables = emptySparseArray(); @@ -1251,6 +1268,7 @@ public class Resources { } if (metrics != null) { mMetrics.setTo(metrics); + mMetrics.updateMetrics(mCompatibilityInfo, mConfiguration); } mMetrics.scaledDensity = mMetrics.density * mConfiguration.fontScale; @@ -1356,6 +1374,17 @@ public class Resources { public Configuration getConfiguration() { return mConfiguration; } + + /** + * Return the compatibility mode information for the application. + * The returned object should be treated as read-only. + * + * @return compatibility info. null if the app does not require compatibility mode. + * @hide + */ + public CompatibilityInfo getCompatibilityInfo() { + return mCompatibilityInfo; + } /** * Return a resource identifier for the given resource name. A fully @@ -1920,5 +1949,6 @@ public class Resources { updateConfiguration(null, null); mAssets.ensureStringBlocks(); mPreloadedDrawables = sPreloadedDrawables; + mCompatibilityInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; } } |