Skip to content

Commit f9307c5

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Fix bug #7334966 Padding is still broken in RTL languages" into jb-mr1-dev
2 parents 59cb2cf + 84ebb35 commit f9307c5

File tree

6 files changed

+120
-34
lines changed

6 files changed

+120
-34
lines changed

api/17.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29625,7 +29625,6 @@ package android.widget {
2962529625
method protected void onTextChanged(java.lang.CharSequence, int, int, int);
2962629626
method public boolean onTextContextMenuItem(int);
2962729627
method public void removeTextChangedListener(android.text.TextWatcher);
29628-
method protected void resetResolvedDrawables();
2962929628
method public void setAllCaps(boolean);
2963029629
method public final void setAutoLinkMask(int);
2963129630
method public void setCompoundDrawablePadding(int);

api/current.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29625,7 +29625,6 @@ package android.widget {
2962529625
method protected void onTextChanged(java.lang.CharSequence, int, int, int);
2962629626
method public boolean onTextContextMenuItem(int);
2962729627
method public void removeTextChangedListener(android.text.TextWatcher);
29628-
method protected void resetResolvedDrawables();
2962929628
method public void setAllCaps(boolean);
2963029629
method public final void setAutoLinkMask(int);
2963129630
method public void setCompoundDrawablePadding(int);

core/java/android/view/View.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,15 +3666,10 @@ public void onClick(View v) {
36663666
// Padding from the background drawable is stored at this point in mUserPaddingLeftInitial
36673667
// and mUserPaddingRightInitial) so drawable padding will be used as ultimate default if
36683668
// defined.
3669-
if (startPaddingDefined) {
3670-
mUserPaddingLeftInitial = startPadding;
3671-
} else if (leftPaddingDefined) {
3669+
if (leftPaddingDefined) {
36723670
mUserPaddingLeftInitial = leftPadding;
36733671
}
3674-
if (endPaddingDefined) {
3675-
mUserPaddingRightInitial = endPadding;
3676-
}
3677-
else if (rightPaddingDefined) {
3672+
if (rightPaddingDefined) {
36783673
mUserPaddingRightInitial = rightPadding;
36793674
}
36803675
}
@@ -11559,8 +11554,10 @@ protected void onAttachedToWindow() {
1155911554

1156011555
/**
1156111556
* Resolve all RTL related properties.
11557+
*
11558+
* @hide
1156211559
*/
11563-
void resolveRtlPropertiesIfNeeded() {
11560+
public void resolveRtlPropertiesIfNeeded() {
1156411561
if (!needRtlPropertiesResolution()) return;
1156511562

1156611563
// Order is important here: LayoutDirection MUST be resolved first
@@ -11584,8 +11581,12 @@ void resolveRtlPropertiesIfNeeded() {
1158411581
onRtlPropertiesChanged(getLayoutDirection());
1158511582
}
1158611583

11587-
// Reset resolution of all RTL related properties.
11588-
void resetRtlProperties() {
11584+
/**
11585+
* Reset resolution of all RTL related properties.
11586+
*
11587+
* @hide
11588+
*/
11589+
public void resetRtlProperties() {
1158911590
resetResolvedLayoutDirection();
1159011591
resetResolvedTextDirection();
1159111592
resetResolvedTextAlignment();
@@ -14195,7 +14196,7 @@ public void unscheduleDrawable(Drawable who) {
1419514196
*
1419614197
* @hide
1419714198
*/
14198-
public void resolveDrawables() {
14199+
protected void resolveDrawables() {
1419914200
if (mBackground != null) {
1420014201
mBackground.setLayoutDirection(getLayoutDirection());
1420114202
}
@@ -14218,7 +14219,10 @@ public void resolveDrawables() {
1421814219
public void onResolveDrawables(int layoutDirection) {
1421914220
}
1422014221

14221-
private void resetResolvedDrawables() {
14222+
/**
14223+
* @hide
14224+
*/
14225+
protected void resetResolvedDrawables() {
1422214226
mPrivateFlags2 &= ~PFLAG2_DRAWABLE_RESOLVED;
1422314227
}
1422414228

@@ -14804,14 +14808,14 @@ public void resetPaddingToInitialValues() {
1480414808
if (isRtlCompatibilityMode()) {
1480514809
mPaddingLeft = mUserPaddingLeftInitial;
1480614810
mPaddingRight = mUserPaddingRightInitial;
14811+
return;
14812+
}
14813+
if (isLayoutRtl()) {
14814+
mPaddingLeft = (mUserPaddingEnd >= 0) ? mUserPaddingEnd : mUserPaddingLeftInitial;
14815+
mPaddingRight = (mUserPaddingStart >= 0) ? mUserPaddingStart : mUserPaddingRightInitial;
1480714816
} else {
14808-
if (isLayoutRtl()) {
14809-
mPaddingLeft = mUserPaddingRightInitial;
14810-
mPaddingRight = mUserPaddingLeftInitial;
14811-
} else {
14812-
mPaddingLeft = mUserPaddingLeftInitial;
14813-
mPaddingRight = mUserPaddingRightInitial;
14814-
}
14817+
mPaddingLeft = (mUserPaddingStart >= 0) ? mUserPaddingStart : mUserPaddingLeftInitial;
14818+
mPaddingRight = (mUserPaddingEnd >= 0) ? mUserPaddingEnd : mUserPaddingRightInitial;
1481514819
}
1481614820
}
1481714821

core/java/android/view/ViewGroup.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5259,6 +5259,21 @@ public void requestTransitionStart(LayoutTransition transition) {
52595259
}
52605260
}
52615261

5262+
/**
5263+
* @hide
5264+
*/
5265+
@Override
5266+
public void resolveRtlPropertiesIfNeeded() {
5267+
super.resolveRtlPropertiesIfNeeded();
5268+
int count = getChildCount();
5269+
for (int i = 0; i < count; i++) {
5270+
final View child = getChildAt(i);
5271+
if (child.isLayoutDirectionInherited()) {
5272+
child.resolveRtlPropertiesIfNeeded();
5273+
}
5274+
}
5275+
}
5276+
52625277
/**
52635278
* @hide
52645279
*/
@@ -5313,6 +5328,51 @@ public boolean resolveTextAlignment() {
53135328
return result;
53145329
}
53155330

5331+
/**
5332+
* @hide
5333+
*/
5334+
@Override
5335+
public void resolvePadding() {
5336+
super.resolvePadding();
5337+
int count = getChildCount();
5338+
for (int i = 0; i < count; i++) {
5339+
final View child = getChildAt(i);
5340+
if (child.isLayoutDirectionInherited()) {
5341+
child.resolvePadding();
5342+
}
5343+
}
5344+
}
5345+
5346+
/**
5347+
* @hide
5348+
*/
5349+
@Override
5350+
protected void resolveDrawables() {
5351+
super.resolveDrawables();
5352+
int count = getChildCount();
5353+
for (int i = 0; i < count; i++) {
5354+
final View child = getChildAt(i);
5355+
if (child.isLayoutDirectionInherited()) {
5356+
child.resolveDrawables();
5357+
}
5358+
}
5359+
}
5360+
5361+
/**
5362+
* @hide
5363+
*/
5364+
@Override
5365+
public void resetRtlProperties() {
5366+
super.resetRtlProperties();
5367+
int count = getChildCount();
5368+
for (int i = 0; i < count; i++) {
5369+
final View child = getChildAt(i);
5370+
if (child.isLayoutDirectionInherited()) {
5371+
child.resetRtlProperties();
5372+
}
5373+
}
5374+
}
5375+
53165376
/**
53175377
* @hide
53185378
*/
@@ -5361,6 +5421,38 @@ public void resetResolvedTextAlignment() {
53615421
}
53625422
}
53635423

5424+
/**
5425+
* @hide
5426+
*/
5427+
@Override
5428+
public void resetResolvedPadding() {
5429+
super.resetResolvedPadding();
5430+
5431+
int count = getChildCount();
5432+
for (int i = 0; i < count; i++) {
5433+
final View child = getChildAt(i);
5434+
if (child.isLayoutDirectionInherited()) {
5435+
child.resetResolvedPadding();
5436+
}
5437+
}
5438+
}
5439+
5440+
/**
5441+
* @hide
5442+
*/
5443+
@Override
5444+
protected void resetResolvedDrawables() {
5445+
super.resetResolvedDrawables();
5446+
5447+
int count = getChildCount();
5448+
for (int i = 0; i < count; i++) {
5449+
final View child = getChildAt(i);
5450+
if (child.isLayoutDirectionInherited()) {
5451+
child.resetResolvedDrawables();
5452+
}
5453+
}
5454+
}
5455+
53645456
/**
53655457
* Return true if the pressed state should be delayed for children or descendants of this
53665458
* ViewGroup. Generally, this should be done for containers that can scroll, such as a List.

core/java/android/widget/CheckedTextView.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,11 @@ private void updatePadding() {
188188
resetPaddingToInitialValues();
189189
int newPadding = (mCheckMarkDrawable != null) ?
190190
mCheckMarkWidth + mBasePadding : mBasePadding;
191-
mNeedRequestlayout |= (mPaddingRight != newPadding);
192191
if (isLayoutRtl()) {
192+
mNeedRequestlayout |= (mPaddingLeft != newPadding);
193193
mPaddingLeft = newPadding;
194194
} else {
195+
mNeedRequestlayout |= (mPaddingRight != newPadding);
195196
mPaddingRight = newPadding;
196197
}
197198
if (mNeedRequestlayout) {
@@ -200,18 +201,6 @@ private void updatePadding() {
200201
}
201202
}
202203

203-
@Override
204-
public void setPadding(int left, int top, int right, int bottom) {
205-
super.setPadding(left, top, right, bottom);
206-
setBasePadding(isLayoutRtl());
207-
}
208-
209-
@Override
210-
public void setPaddingRelative(int start, int top, int end, int bottom) {
211-
super.setPaddingRelative(start, top, end, bottom);
212-
setBasePadding(isLayoutRtl());
213-
}
214-
215204
private void setBasePadding(boolean isLayoutRtl) {
216205
if (isLayoutRtl) {
217206
mBasePadding = mPaddingLeft;

core/java/android/widget/TextView.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8314,6 +8314,9 @@ private void updateDrawablesLayoutDirection(Drawables dr, int layoutDirection) {
83148314
}
83158315
}
83168316

8317+
/**
8318+
* @hide
8319+
*/
83178320
protected void resetResolvedDrawables() {
83188321
mResolvedDrawables = false;
83198322
}

0 commit comments

Comments
 (0)