Merge "Target API check for margin params fix" into nyc-mr1-dev

This commit is contained in:
Yigit Boyar
2016-08-02 20:41:07 +00:00
committed by Android (Google) Code Review
5 changed files with 43 additions and 24 deletions

View File

@@ -820,6 +820,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*/ */
static boolean sTextureViewIgnoresDrawableSetters = false; static boolean sTextureViewIgnoresDrawableSetters = false;
/**
* Prior to N, some ViewGroups would not convert LayoutParams properly even though both extend
* MarginLayoutParams. For instance, converting LinearLayout.LayoutParams to
* RelativeLayout.LayoutParams would lose margin information. This is fixed on N but target API
* check is implemented for backwards compatibility.
*
* {@hide}
*/
protected static boolean sPreserveMarginParamsInLayoutParamConversion;
/** /**
* 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.
@@ -4052,6 +4063,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
// On N+, we throw, but that breaks compatibility with apps that use these methods. // On N+, we throw, but that breaks compatibility with apps that use these methods.
sTextureViewIgnoresDrawableSetters = targetSdkVersion <= M; sTextureViewIgnoresDrawableSetters = targetSdkVersion <= M;
// Prior to N, we would drop margins in LayoutParam conversions. The fix triggers bugs
// in apps so we target check it to avoid breaking existing apps.
sPreserveMarginParamsInLayoutParamConversion = targetSdkVersion >= N;
sCompatibilityDone = true; sCompatibilityDone = true;
} }
} }

View File

@@ -382,13 +382,14 @@ public class FrameLayout extends ViewGroup {
@Override @Override
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) { protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
if (lp instanceof LayoutParams) { if (sPreserveMarginParamsInLayoutParamConversion) {
return new LayoutParams((LayoutParams) lp); if (lp instanceof LayoutParams) {
} else if (lp instanceof MarginLayoutParams) { return new LayoutParams((LayoutParams) lp);
return new LayoutParams((MarginLayoutParams) lp); } else if (lp instanceof MarginLayoutParams) {
} else { return new LayoutParams((MarginLayoutParams) lp);
return new LayoutParams(lp); }
} }
return new LayoutParams(lp);
} }
@Override @Override

View File

@@ -868,13 +868,14 @@ public class GridLayout extends ViewGroup {
@Override @Override
protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) { protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
if (lp instanceof LayoutParams) { if (sPreserveMarginParamsInLayoutParamConversion) {
return new LayoutParams((LayoutParams) lp); if (lp instanceof LayoutParams) {
} else if (lp instanceof MarginLayoutParams) { return new LayoutParams((LayoutParams) lp);
return new LayoutParams((MarginLayoutParams) lp); } else if (lp instanceof MarginLayoutParams) {
} else { return new LayoutParams((MarginLayoutParams) lp);
return new LayoutParams(lp); }
} }
return new LayoutParams(lp);
} }
// Draw grid // Draw grid

View File

@@ -1844,13 +1844,14 @@ public class LinearLayout extends ViewGroup {
@Override @Override
protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) { protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
if (lp instanceof LayoutParams) { if (sPreserveMarginParamsInLayoutParamConversion) {
return new LayoutParams((LayoutParams) lp); if (lp instanceof LayoutParams) {
} else if (lp instanceof MarginLayoutParams) { return new LayoutParams((LayoutParams) lp);
return new LayoutParams((MarginLayoutParams) lp); } else if (lp instanceof MarginLayoutParams) {
} else { return new LayoutParams((MarginLayoutParams) lp);
return new LayoutParams(lp); }
} }
return new LayoutParams(lp);
} }

View File

@@ -1104,13 +1104,14 @@ public class RelativeLayout extends ViewGroup {
@Override @Override
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) { protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
if (lp instanceof LayoutParams) { if (sPreserveMarginParamsInLayoutParamConversion) {
return new LayoutParams((LayoutParams) lp); if (lp instanceof LayoutParams) {
} else if (lp instanceof MarginLayoutParams) { return new LayoutParams((LayoutParams) lp);
return new LayoutParams((MarginLayoutParams) lp); } else if (lp instanceof MarginLayoutParams) {
} else { return new LayoutParams((MarginLayoutParams) lp);
return new LayoutParams(lp); }
} }
return new LayoutParams(lp);
} }
/** @hide */ /** @hide */