Skip to content

Commit b878ddb

Browse files
author
Fabrice Di Meglio
committed
Fix bug #7621927 Radio button/TextView drawable regression in 4.2
- as we remove the 9 patch padding trick, we need also to do the correct positioning of the radio / checkbox / star during draw Change-Id: I02b67bef9c0f2dc1c0c65361de14ab20ce9b881d
1 parent 02053d1 commit b878ddb

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

core/java/android/widget/CompoundButton.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ public int getCompoundPaddingRight() {
248248
return padding;
249249
}
250250

251+
/**
252+
* @hide
253+
*/
254+
@Override
255+
public int getHorizontalOffsetForDrawables() {
256+
final Drawable buttonDrawable = mButtonDrawable;
257+
return (buttonDrawable != null) ? buttonDrawable.getIntrinsicWidth() : 0;
258+
}
259+
251260
@Override
252261
protected void onDraw(Canvas canvas) {
253262
super.onDraw(canvas);

core/java/android/widget/TextView.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4734,6 +4734,13 @@ private Path getUpdatedHighlightPath() {
47344734
return highlight;
47354735
}
47364736

4737+
/**
4738+
* @hide
4739+
*/
4740+
public int getHorizontalOffsetForDrawables() {
4741+
return 0;
4742+
}
4743+
47374744
@Override
47384745
protected void onDraw(Canvas canvas) {
47394746
restartMarqueeIfNeeded();
@@ -4751,6 +4758,10 @@ protected void onDraw(Canvas canvas) {
47514758
final int left = mLeft;
47524759
final int bottom = mBottom;
47534760
final int top = mTop;
4761+
final boolean isLayoutRtl = isLayoutRtl();
4762+
final int offset = getHorizontalOffsetForDrawables();
4763+
final int leftOffset = isLayoutRtl ? 0 : offset;
4764+
final int rightOffset = isLayoutRtl ? offset : 0 ;
47544765

47554766
final Drawables dr = mDrawables;
47564767
if (dr != null) {
@@ -4766,7 +4777,7 @@ protected void onDraw(Canvas canvas) {
47664777
// Make sure to update invalidateDrawable() when changing this code.
47674778
if (dr.mDrawableLeft != null) {
47684779
canvas.save();
4769-
canvas.translate(scrollX + mPaddingLeft,
4780+
canvas.translate(scrollX + mPaddingLeft + leftOffset,
47704781
scrollY + compoundPaddingTop +
47714782
(vspace - dr.mDrawableHeightLeft) / 2);
47724783
dr.mDrawableLeft.draw(canvas);
@@ -4777,7 +4788,8 @@ protected void onDraw(Canvas canvas) {
47774788
// Make sure to update invalidateDrawable() when changing this code.
47784789
if (dr.mDrawableRight != null) {
47794790
canvas.save();
4780-
canvas.translate(scrollX + right - left - mPaddingRight - dr.mDrawableSizeRight,
4791+
canvas.translate(scrollX + right - left - mPaddingRight
4792+
- dr.mDrawableSizeRight - rightOffset,
47814793
scrollY + compoundPaddingTop + (vspace - dr.mDrawableHeightRight) / 2);
47824794
dr.mDrawableRight.draw(canvas);
47834795
canvas.restore();
@@ -4862,8 +4874,6 @@ protected void onDraw(Canvas canvas) {
48624874
}
48634875
canvas.translate(compoundPaddingLeft, extendedPaddingTop + voffsetText);
48644876

4865-
final boolean isLayoutRtl = isLayoutRtl();
4866-
48674877
final int layoutDirection = getLayoutDirection();
48684878
final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
48694879
if (mEllipsize == TextUtils.TruncateAt.MARQUEE &&

0 commit comments

Comments
 (0)