OSDN Git Service

Add new supports-screen API to set maximum allowed size.
authorDianne Hackborn <hackbod@google.com>
Thu, 2 Jun 2011 04:27:05 +0000 (21:27 -0700)
committerDianne Hackborn <hackbod@google.com>
Thu, 2 Jun 2011 05:20:38 +0000 (22:20 -0700)
Change-Id: I0a7cd4ba73a4c18558e6daee28963d5fd12c7978

api/current.xml
core/java/android/content/pm/ApplicationInfo.java
core/java/android/content/pm/PackageParser.java
core/java/android/content/res/CompatibilityInfo.java
core/res/res/values/attrs_manifest.xml
core/res/res/values/public.xml

index 7670bc9..83e571d 100644 (file)
  visibility="public"
 >
 </field>
+<field name="largestWidthLimitDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843622"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="launchMode"
  type="int"
  transient="false"
  visibility="public"
 >
 </field>
+<field name="largestWidthLimitDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="manageSpaceActivityName"
  type="java.lang.String"
  transient="false"
index ab31865..2bd632d 100644 (file)
@@ -337,6 +337,14 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     public int compatibleWidthLimitDp = 0;
 
     /**
+     * The maximum smallest screen width the application will work on.  If 0,
+     * nothing has been specified.  Comes from
+     * {@link android.R.styleable#AndroidManifestSupportsScreens_largestWidthLimitDp
+     * android:largestWidthLimitDp} attribute of the &lt;supports-screens&gt; tag.
+     */
+    public int largestWidthLimitDp = 0;
+
+    /**
      * Full path to the location of this package.
      */
     public String sourceDir;
@@ -418,7 +426,8 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
         pw.println(prefix + "uid=" + uid + " flags=0x" + Integer.toHexString(flags)
                 + " theme=0x" + Integer.toHexString(theme));
         pw.println(prefix + "requiresSmallestWidthDp=" + requiresSmallestWidthDp
-                + " compatibleWidthLimitDp=" + compatibleWidthLimitDp);
+                + " compatibleWidthLimitDp=" + compatibleWidthLimitDp
+                + " largestWidthLimitDp=" + largestWidthLimitDp);
         pw.println(prefix + "sourceDir=" + sourceDir);
         if (sourceDir == null) {
             if (publicSourceDir != null) {
@@ -480,6 +489,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
         flags = orig.flags;
         requiresSmallestWidthDp = orig.requiresSmallestWidthDp;
         compatibleWidthLimitDp = orig.compatibleWidthLimitDp;
+        largestWidthLimitDp = orig.largestWidthLimitDp;
         sourceDir = orig.sourceDir;
         publicSourceDir = orig.publicSourceDir;
         nativeLibraryDir = orig.nativeLibraryDir;
@@ -515,6 +525,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
         dest.writeInt(flags);
         dest.writeInt(requiresSmallestWidthDp);
         dest.writeInt(compatibleWidthLimitDp);
+        dest.writeInt(largestWidthLimitDp);
         dest.writeString(sourceDir);
         dest.writeString(publicSourceDir);
         dest.writeString(nativeLibraryDir);
@@ -550,6 +561,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
         flags = source.readInt();
         requiresSmallestWidthDp = source.readInt();
         compatibleWidthLimitDp = source.readInt();
+        largestWidthLimitDp = source.readInt();
         sourceDir = source.readString();
         publicSourceDir = source.readString();
         nativeLibraryDir = source.readString();
index 9b4ff75..98ce8aa 100644 (file)
@@ -999,6 +999,9 @@ public class PackageParser {
                 pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
                         com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp,
                         0);
+                pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
+                        com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp,
+                        0);
 
                 // This is a trick to get a boolean and still able to detect
                 // if a value was actually set.
index 0d2e567..b686e54 100644 (file)
@@ -96,21 +96,42 @@ public class CompatibilityInfo implements Parcelable {
             boolean forceCompat) {
         int compatFlags = 0;
 
-        if (appInfo.requiresSmallestWidthDp != 0 || appInfo.compatibleWidthLimitDp != 0) {
+        if (appInfo.requiresSmallestWidthDp != 0 || appInfo.compatibleWidthLimitDp != 0
+                || appInfo.largestWidthLimitDp != 0) {
             // New style screen requirements spec.
             int required = appInfo.requiresSmallestWidthDp != 0
                     ? appInfo.requiresSmallestWidthDp
                     : appInfo.compatibleWidthLimitDp;
+            if (required == 0) {
+                required = appInfo.largestWidthLimitDp;
+            }
             int compat = appInfo.compatibleWidthLimitDp != 0
-                    ? appInfo.compatibleWidthLimitDp
-                    : appInfo.requiresSmallestWidthDp;
+                    ? appInfo.compatibleWidthLimitDp : required;
             if (compat < required)  {
                 compat = required;
             }
-
-            if (compat >= sw) {
+            int largest = appInfo.largestWidthLimitDp;
+
+            if (required > DEFAULT_NORMAL_SHORT_DIMENSION) {
+                // For now -- if they require a size larger than the only
+                // size we can do in compatibility mode, then don't ever
+                // allow the app to go in to compat mode.  Trying to run
+                // it at a smaller size it can handle will make it far more
+                // broken than running at a larger size than it wants or
+                // thinks it can handle.
+                compatFlags |= NEVER_NEEDS_COMPAT;
+            } else if (largest != 0 && sw > largest) {
+                // If the screen size is larger than the largest size the
+                // app thinks it can work with, then always force it in to
+                // compatibility mode.
+                compatFlags |= NEEDS_SCREEN_COMPAT | ALWAYS_NEEDS_COMPAT;
+            } else if (compat >= sw) {
+                // The screen size is something the app says it was designed
+                // for, so never do compatibility mode.
                 compatFlags |= NEVER_NEEDS_COMPAT;
             } else if (forceCompat) {
+                // The app may work better with or without compatibility mode.
+                // Let the user decide.
                 compatFlags |= NEEDS_SCREEN_COMPAT;
             }
 
index 41c4c29..38790ea 100644 (file)
              used with this attribute are 320 for a phone screen, 600 for a
              7" tablet, and 720 for a 10" tablet. -->
         <attr name="compatibleWidthLimitDp" format="integer" />
+        <!-- Starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB_MR2},
+             this is the new way to specify the screens an application is
+             compatible with.  This attribute provides the maximum
+             "smallest screen width" (as per the -swNNNdp resource configuration)
+             that the application can work well on.  If this value is smaller than
+             the "smallest screen width" of the device it is running on, the
+             application will be forced in to screen compatibility mode with
+             no way for the user to turn it off.  Currently the compatibility mode
+             only emulates phone screens, so even if this value is larger than 320
+             the width the app runs in will be a 320 phone dimension. -->
+        <attr name="largestWidthLimitDp" format="integer" />
         <!-- Indicates whether the application supports smaller screen form-factors.
              A small screen is defined as one with a smaller aspect ratio than
              the traditional HVGA screen; that is, for a portrait screen, less
index 27ca952..85884b1 100644 (file)
   <eat-comment />
   <public type="attr" name="requiresSmallestWidthDp" id="0x01010364" />
   <public type="attr" name="compatibleWidthLimitDp" />
+  <public type="attr" name="largestWidthLimitDp" />
 </resources>