diff options
author | Dianne Hackborn <hackbod@google.com> | 2012-09-30 15:52:46 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-09-30 15:52:47 -0700 |
commit | 2a30547af44536f6b0e2f7020ac1a435c72afc84 (patch) | |
tree | 51b7e3d767df429fed33315471b70ad6b0c277bb /core/java | |
parent | 2b58c1b503334ea20be9de3c2b5654855f9d4669 (diff) | |
parent | fe37f8f51d90fc4c6230e54dcd1270df5fcc6be3 (diff) | |
download | frameworks_base-2a30547af44536f6b0e2f7020ac1a435c72afc84.zip frameworks_base-2a30547af44536f6b0e2f7020ac1a435c72afc84.tar.gz frameworks_base-2a30547af44536f6b0e2f7020ac1a435c72afc84.tar.bz2 |
Merge "Work on issue #6949468: android.dpi.cts.ConfigurationScreenLayoutTest..." into jb-mr1-dev
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/app/ActivityThread.java | 14 | ||||
-rw-r--r-- | core/java/android/content/res/Configuration.java | 72 |
2 files changed, 81 insertions, 5 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 6638433..6ef3651 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -3872,14 +3872,20 @@ public final class ActivityThread { final void applyNonDefaultDisplayMetricsToConfigurationLocked( DisplayMetrics dm, Configuration config) { - config.screenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE - | Configuration.SCREENLAYOUT_LONG_NO; config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; - config.orientation = (dm.widthPixels >= dm.heightPixels) ? - Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT; config.densityDpi = dm.densityDpi; config.screenWidthDp = (int)(dm.widthPixels / dm.density); config.screenHeightDp = (int)(dm.heightPixels / dm.density); + int sl = Configuration.resetScreenLayout(config.screenLayout); + if (dm.widthPixels > dm.heightPixels) { + config.orientation = Configuration.ORIENTATION_LANDSCAPE; + config.screenLayout = Configuration.reduceScreenLayout(sl, + config.screenWidthDp, config.screenHeightDp); + } else { + config.orientation = Configuration.ORIENTATION_PORTRAIT; + config.screenLayout = Configuration.reduceScreenLayout(sl, + config.screenHeightDp, config.screenWidthDp); + } config.smallestScreenWidthDp = config.screenWidthDp; // assume screen does not rotate config.compatScreenWidthDp = config.screenWidthDp; config.compatScreenHeightDp = config.screenHeightDp; diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java index 51b8d25..86d6ee7 100644 --- a/core/java/android/content/res/Configuration.java +++ b/core/java/android/content/res/Configuration.java @@ -172,7 +172,77 @@ public final class Configuration implements Parcelable, Comparable<Configuration * Multiple Screens</a> for more information. */ public int screenLayout; - + + /** @hide */ + static public int resetScreenLayout(int curLayout) { + return (curLayout&~(SCREENLAYOUT_LONG_MASK | SCREENLAYOUT_SIZE_MASK + | SCREENLAYOUT_COMPAT_NEEDED)) + | (SCREENLAYOUT_LONG_YES | SCREENLAYOUT_SIZE_XLARGE); + } + + /** @hide */ + static public int reduceScreenLayout(int curLayout, int longSizeDp, int shortSizeDp) { + int screenLayoutSize; + boolean screenLayoutLong; + boolean screenLayoutCompatNeeded; + + // These semi-magic numbers define our compatibility modes for + // applications with different screens. These are guarantees to + // app developers about the space they can expect for a particular + // configuration. DO NOT CHANGE! + if (longSizeDp < 470) { + // This is shorter than an HVGA normal density screen (which + // is 480 pixels on its long side). + screenLayoutSize = SCREENLAYOUT_SIZE_SMALL; + screenLayoutLong = false; + screenLayoutCompatNeeded = false; + } else { + // What size is this screen screen? + if (longSizeDp >= 960 && shortSizeDp >= 720) { + // 1.5xVGA or larger screens at medium density are the point + // at which we consider it to be an extra large screen. + screenLayoutSize = SCREENLAYOUT_SIZE_XLARGE; + } else if (longSizeDp >= 640 && shortSizeDp >= 480) { + // VGA or larger screens at medium density are the point + // at which we consider it to be a large screen. + screenLayoutSize = SCREENLAYOUT_SIZE_LARGE; + } else { + screenLayoutSize = SCREENLAYOUT_SIZE_NORMAL; + } + + // If this screen is wider than normal HVGA, or taller + // than FWVGA, then for old apps we want to run in size + // compatibility mode. + if (shortSizeDp > 321 || longSizeDp > 570) { + screenLayoutCompatNeeded = true; + } else { + screenLayoutCompatNeeded = false; + } + + // Is this a long screen? + if (((longSizeDp*3)/5) >= (shortSizeDp-1)) { + // Anything wider than WVGA (5:3) is considering to be long. + screenLayoutLong = true; + } else { + screenLayoutLong = false; + } + } + + // Now reduce the last screenLayout to not be better than what we + // have found. + if (!screenLayoutLong) { + curLayout = (curLayout&~SCREENLAYOUT_LONG_MASK) | SCREENLAYOUT_LONG_NO; + } + if (screenLayoutCompatNeeded) { + curLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; + } + int curSize = curLayout&SCREENLAYOUT_SIZE_MASK; + if (screenLayoutSize < curSize) { + curLayout = (curLayout&~SCREENLAYOUT_SIZE_MASK) | screenLayoutSize; + } + return curLayout; + } + /** * Check if the Configuration's current {@link #screenLayout} is at * least the given size. |