diff options
| author | 2013-10-14 11:27:19 -0700 | |
|---|---|---|
| committer | 2013-10-14 13:32:02 -0700 | |
| commit | cf18b47ed44157e7aadc55fe8c4796df13e1b86f (patch) | |
| tree | 63daa592acfaf74f9fa8a3ba0d9d2bbc136f436d | |
| parent | 306ed4fd4f7e05d0e87b06816fd8bc6bc7d91846 (diff) | |
Wrap measurement optimization in targetSdk check
A measurement optimization has exposed some apps that are relying
on incidental layout requests to have themselves update. With the
optimization enabled, these apps break.
Apps targetted at older versions of Android should not
break due to this optimization.
bug:11192311
Change-Id: Id5fc7f83ec2cb1541d3d0d16f951cd57c0afaccd
| -rw-r--r-- | core/java/android/view/View.java | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 9c388ddeaafe..e2d98edafc49 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -18,6 +18,7 @@ package android.view; import android.content.ClipData; import android.content.Context; +import android.content.pm.ApplicationInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; @@ -691,9 +692,23 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ public static final int NO_ID = -1; + /** + * Signals that compatibility booleans have been initialized according to + * target SDK versions. + */ + private static boolean sCompatibilityDone = false; + + /** + * Use the old (broken) way of building MeasureSpecs. + */ private static boolean sUseBrokenMakeMeasureSpec = false; /** + * Ignore any optimizations using the measure cache. + */ + private static boolean sIgnoreMeasureCache = false; + + /** * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when * calling setFlags. */ @@ -3426,10 +3441,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mUserPaddingStart = UNDEFINED_PADDING; mUserPaddingEnd = UNDEFINED_PADDING; - if (!sUseBrokenMakeMeasureSpec && context != null && - context.getApplicationInfo().targetSdkVersion <= JELLY_BEAN_MR1) { + if (!sCompatibilityDone && context != null) { + final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion; + // Older apps may need this compatibility hack for measurement. - sUseBrokenMakeMeasureSpec = true; + sUseBrokenMakeMeasureSpec = targetSdkVersion <= JELLY_BEAN_MR1; + + // Older apps expect onMeasure() to always be called on a layout pass, regardless + // of whether a layout was requested on that View. + sIgnoreMeasureCache = targetSdkVersion < KITKAT; + + sCompatibilityDone = true; } } @@ -16431,7 +16453,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, int cacheIndex = (mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT ? -1 : mMeasureCache.indexOfKey(key); - if (cacheIndex < 0) { + if (cacheIndex < 0 || sIgnoreMeasureCache) { // measure ourselves, this should set the measured dimension flag back onMeasure(widthMeasureSpec, heightMeasureSpec); mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT; |