@@ -2150,7 +2150,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
21502150 * Group of bits indicating that RTL properties resolution is done.
21512151 */
21522152 static final int ALL_RTL_PROPERTIES_RESOLVED = PFLAG2_LAYOUT_DIRECTION_RESOLVED |
2153- PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_ALIGNMENT_RESOLVED;
2153+ PFLAG2_TEXT_DIRECTION_RESOLVED |
2154+ PFLAG2_TEXT_ALIGNMENT_RESOLVED |
2155+ PFLAG2_PADDING_RESOLVED |
2156+ PFLAG2_DRAWABLE_RESOLVED;
21542157
21552158 // There are a couple of flags left in mPrivateFlags2
21562159
@@ -3299,6 +3302,11 @@ public View(Context context, AttributeSet attrs, int defStyle) {
32993302 int overScrollMode = mOverScrollMode;
33003303 boolean initializeScrollbars = false;
33013304
3305+ boolean leftPaddingDefined = false;
3306+ boolean rightPaddingDefined = false;
3307+ boolean startPaddingDefined = false;
3308+ boolean endPaddingDefined = false;
3309+
33023310 final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
33033311
33043312 final int N = a.getIndexCount();
@@ -3312,26 +3320,32 @@ public View(Context context, AttributeSet attrs, int defStyle) {
33123320 padding = a.getDimensionPixelSize(attr, -1);
33133321 mUserPaddingLeftInitial = padding;
33143322 mUserPaddingRightInitial = padding;
3323+ leftPaddingDefined = true;
3324+ rightPaddingDefined = true;
33153325 break;
33163326 case com.android.internal.R.styleable.View_paddingLeft:
33173327 leftPadding = a.getDimensionPixelSize(attr, -1);
33183328 mUserPaddingLeftInitial = leftPadding;
3329+ leftPaddingDefined = true;
33193330 break;
33203331 case com.android.internal.R.styleable.View_paddingTop:
33213332 topPadding = a.getDimensionPixelSize(attr, -1);
33223333 break;
33233334 case com.android.internal.R.styleable.View_paddingRight:
33243335 rightPadding = a.getDimensionPixelSize(attr, -1);
33253336 mUserPaddingRightInitial = rightPadding;
3337+ rightPaddingDefined = true;
33263338 break;
33273339 case com.android.internal.R.styleable.View_paddingBottom:
33283340 bottomPadding = a.getDimensionPixelSize(attr, -1);
33293341 break;
33303342 case com.android.internal.R.styleable.View_paddingStart:
33313343 startPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING);
3344+ startPaddingDefined = true;
33323345 break;
33333346 case com.android.internal.R.styleable.View_paddingEnd:
33343347 endPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING);
3348+ endPaddingDefined = true;
33353349 break;
33363350 case com.android.internal.R.styleable.View_scrollX:
33373351 x = a.getDimensionPixelOffset(attr, 0);
@@ -3629,10 +3643,24 @@ public void onClick(View v) {
36293643 mUserPaddingRightInitial = padding;
36303644 }
36313645
3646+ // RTL compatibility mode: pre Jelly Bean MR1 case OR no RTL support case.
3647+ // left / right padding are used if defined (meaning here nothing to do). If they are not
3648+ // defined and start / end padding are defined (e.g. in Frameworks resources), then we use
3649+ // start / end and resolve them as left / right (layout direction is not taken into account).
3650+ if (isRtlCompatibilityMode()) {
3651+ if (!leftPaddingDefined && startPaddingDefined) {
3652+ leftPadding = startPadding;
3653+ }
3654+ if (!rightPaddingDefined && endPaddingDefined) {
3655+ rightPadding = endPadding;
3656+ }
3657+ }
3658+
36323659 // If the user specified the padding (either with android:padding or
36333660 // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise
36343661 // use the default padding or the padding from the background drawable
3635- // (stored at this point in mPadding*)
3662+ // (stored at this point in mPadding*). Padding resolution will happen later if
3663+ // RTL is supported.
36363664 mUserPaddingLeftInitial = leftPadding >= 0 ? leftPadding : mPaddingLeft;
36373665 mUserPaddingRightInitial = rightPadding >= 0 ? rightPadding : mPaddingRight;
36383666 internalSetPadding(
@@ -11568,6 +11596,15 @@ private boolean hasRtlSupport() {
1156811596 return mContext.getApplicationInfo().hasRtlSupport();
1156911597 }
1157011598
11599+ /**
11600+ * Return true if we are in RTL compatibility mode (either before Jelly Bean MR1 or
11601+ * RTL not supported)
11602+ */
11603+ private boolean isRtlCompatibilityMode() {
11604+ final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
11605+ return targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport();
11606+ }
11607+
1157111608 /**
1157211609 * @return true if RTL properties need resolution.
1157311610 */
@@ -11693,26 +11730,7 @@ boolean isPaddingResolved() {
1169311730 * @hide
1169411731 */
1169511732 public void resolvePadding() {
11696- final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
11697- if (targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport()) {
11698- // Pre Jelly Bean MR1 case (compatibility mode) OR no RTL support case:
11699- // left / right padding are used if defined. If they are not defined and start / end
11700- // padding are defined (e.g. in Frameworks resources), then we use start / end and
11701- // resolve them as left / right (layout direction is not taken into account).
11702- if (mUserPaddingLeftInitial == UNDEFINED_PADDING &&
11703- mUserPaddingStart != UNDEFINED_PADDING) {
11704- mUserPaddingLeft = mUserPaddingStart;
11705- }
11706- if (mUserPaddingRightInitial == UNDEFINED_PADDING &&
11707- mUserPaddingEnd != UNDEFINED_PADDING) {
11708- mUserPaddingRight = mUserPaddingEnd;
11709- }
11710-
11711- mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom;
11712-
11713- internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight,
11714- mUserPaddingBottom);
11715- } else {
11733+ if (!isRtlCompatibilityMode()) {
1171611734 // Post Jelly Bean MR1 case: we need to take the resolved layout direction into account.
1171711735 // If start / end padding are defined, they will be resolved (hence overriding) to
1171811736 // left / right or right / left depending on the resolved layout direction.
0 commit comments