Merge "Compatibility measurement hacks when targetSdkVersion <= JB-MR1"
This commit is contained in:
@@ -40,6 +40,7 @@ import android.graphics.Shader;
|
|||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.hardware.display.DisplayManagerGlobal;
|
import android.hardware.display.DisplayManagerGlobal;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -688,6 +689,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
|||||||
*/
|
*/
|
||||||
public static final int NO_ID = -1;
|
public static final int NO_ID = -1;
|
||||||
|
|
||||||
|
private static boolean sUseBrokenMakeMeasureSpec = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This view does not want keystrokes. Use with TAKES_FOCUS_MASK when
|
* This view does not want keystrokes. Use with TAKES_FOCUS_MASK when
|
||||||
* calling setFlags.
|
* calling setFlags.
|
||||||
@@ -3234,6 +3237,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
|||||||
setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS);
|
setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS);
|
||||||
mUserPaddingStart = UNDEFINED_PADDING;
|
mUserPaddingStart = UNDEFINED_PADDING;
|
||||||
mUserPaddingEnd = UNDEFINED_PADDING;
|
mUserPaddingEnd = UNDEFINED_PADDING;
|
||||||
|
|
||||||
|
if (!sUseBrokenMakeMeasureSpec && context.getApplicationInfo().targetSdkVersion <=
|
||||||
|
Build.VERSION_CODES.JELLY_BEAN_MR1 ) {
|
||||||
|
// Older apps may need this compatibility hack for measurement.
|
||||||
|
sUseBrokenMakeMeasureSpec = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17328,7 +17337,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
|||||||
* @return the measure specification based on size and mode
|
* @return the measure specification based on size and mode
|
||||||
*/
|
*/
|
||||||
public static int makeMeasureSpec(int size, int mode) {
|
public static int makeMeasureSpec(int size, int mode) {
|
||||||
return (size & ~MODE_MASK) | (mode & MODE_MASK);
|
if (sUseBrokenMakeMeasureSpec) {
|
||||||
|
return size + mode;
|
||||||
|
} else {
|
||||||
|
return (size & ~MODE_MASK) | (mode & MODE_MASK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import android.graphics.RectF;
|
|||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -93,6 +94,9 @@ public class ImageView extends View {
|
|||||||
private int mBaseline = -1;
|
private int mBaseline = -1;
|
||||||
private boolean mBaselineAlignBottom = false;
|
private boolean mBaselineAlignBottom = false;
|
||||||
|
|
||||||
|
// AdjustViewBounds behavior will be in compatibility mode for older apps.
|
||||||
|
private boolean mAdjustViewBoundsCompat = false;
|
||||||
|
|
||||||
private static final ScaleType[] sScaleTypeArray = {
|
private static final ScaleType[] sScaleTypeArray = {
|
||||||
ScaleType.MATRIX,
|
ScaleType.MATRIX,
|
||||||
ScaleType.FIT_XY,
|
ScaleType.FIT_XY,
|
||||||
@@ -167,6 +171,8 @@ public class ImageView extends View {
|
|||||||
private void initImageView() {
|
private void initImageView() {
|
||||||
mMatrix = new Matrix();
|
mMatrix = new Matrix();
|
||||||
mScaleType = ScaleType.FIT_CENTER;
|
mScaleType = ScaleType.FIT_CENTER;
|
||||||
|
mAdjustViewBoundsCompat = mContext.getApplicationInfo().targetSdkVersion <=
|
||||||
|
Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -801,7 +807,7 @@ public class ImageView extends View {
|
|||||||
pleft + pright;
|
pleft + pright;
|
||||||
|
|
||||||
// Allow the width to outgrow its original estimate if height is fixed.
|
// Allow the width to outgrow its original estimate if height is fixed.
|
||||||
if (!resizeHeight) {
|
if (!resizeHeight && !mAdjustViewBoundsCompat) {
|
||||||
widthSize = resolveAdjustedSize(newWidth, mMaxWidth, widthMeasureSpec);
|
widthSize = resolveAdjustedSize(newWidth, mMaxWidth, widthMeasureSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -817,7 +823,7 @@ public class ImageView extends View {
|
|||||||
ptop + pbottom;
|
ptop + pbottom;
|
||||||
|
|
||||||
// Allow the height to outgrow its original estimate if width is fixed.
|
// Allow the height to outgrow its original estimate if width is fixed.
|
||||||
if (!resizeWidth) {
|
if (!resizeWidth && !mAdjustViewBoundsCompat) {
|
||||||
heightSize = resolveAdjustedSize(newHeight, mMaxHeight,
|
heightSize = resolveAdjustedSize(newHeight, mMaxHeight,
|
||||||
heightMeasureSpec);
|
heightMeasureSpec);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import android.content.Context;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.os.Build;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Pools.SimplePool;
|
import android.util.Pools.SimplePool;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
@@ -199,18 +200,29 @@ public class RelativeLayout extends ViewGroup {
|
|||||||
private View[] mSortedVerticalChildren = new View[0];
|
private View[] mSortedVerticalChildren = new View[0];
|
||||||
private final DependencyGraph mGraph = new DependencyGraph();
|
private final DependencyGraph mGraph = new DependencyGraph();
|
||||||
|
|
||||||
|
// Compatibility hack. Old versions of the platform had problems
|
||||||
|
// with MeasureSpec value overflow and RelativeLayout was one source of them.
|
||||||
|
// Some apps came to rely on them. :(
|
||||||
|
private boolean mAllowBrokenMeasureSpecs = false;
|
||||||
|
|
||||||
public RelativeLayout(Context context) {
|
public RelativeLayout(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <=
|
||||||
|
Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RelativeLayout(Context context, AttributeSet attrs) {
|
public RelativeLayout(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
initFromAttributes(context, attrs);
|
initFromAttributes(context, attrs);
|
||||||
|
mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <=
|
||||||
|
Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RelativeLayout(Context context, AttributeSet attrs, int defStyle) {
|
public RelativeLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
initFromAttributes(context, attrs);
|
initFromAttributes(context, attrs);
|
||||||
|
mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <=
|
||||||
|
Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFromAttributes(Context context, AttributeSet attrs) {
|
private void initFromAttributes(Context context, AttributeSet attrs) {
|
||||||
@@ -670,7 +682,7 @@ public class RelativeLayout extends ViewGroup {
|
|||||||
mPaddingLeft, mPaddingRight,
|
mPaddingLeft, mPaddingRight,
|
||||||
myWidth);
|
myWidth);
|
||||||
int childHeightMeasureSpec;
|
int childHeightMeasureSpec;
|
||||||
if (myHeight < 0) {
|
if (myHeight < 0 && !mAllowBrokenMeasureSpecs) {
|
||||||
// Negative values in a mySize/myWidth/myWidth value in RelativeLayout measurement
|
// Negative values in a mySize/myWidth/myWidth value in RelativeLayout measurement
|
||||||
// is code for, "we got an unspecified mode in the RelativeLayout's measurespec."
|
// is code for, "we got an unspecified mode in the RelativeLayout's measurespec."
|
||||||
// Carry it forward.
|
// Carry it forward.
|
||||||
@@ -702,7 +714,7 @@ public class RelativeLayout extends ViewGroup {
|
|||||||
private int getChildMeasureSpec(int childStart, int childEnd,
|
private int getChildMeasureSpec(int childStart, int childEnd,
|
||||||
int childSize, int startMargin, int endMargin, int startPadding,
|
int childSize, int startMargin, int endMargin, int startPadding,
|
||||||
int endPadding, int mySize) {
|
int endPadding, int mySize) {
|
||||||
if (mySize < 0) {
|
if (mySize < 0 && !mAllowBrokenMeasureSpecs) {
|
||||||
// Negative values in a mySize/myWidth/myWidth value in RelativeLayout measurement
|
// Negative values in a mySize/myWidth/myWidth value in RelativeLayout measurement
|
||||||
// is code for, "we got an unspecified mode in the RelativeLayout's measurespec."
|
// is code for, "we got an unspecified mode in the RelativeLayout's measurespec."
|
||||||
// Carry it forward.
|
// Carry it forward.
|
||||||
|
|||||||
Reference in New Issue
Block a user