summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/view/View.java30
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;