am 07581745: am 71175f72: Merge "Fix bug #7621927 Radio button/TextView drawable regression in 4.2" into jb-mr1.1-dev

* commit '075817450c61902ecaaf4af2d96e8542123a86bd':
  Fix bug #7621927 Radio button/TextView drawable regression in 4.2
This commit is contained in:
Fabrice Di Meglio
2012-11-29 14:25:43 -08:00
committed by Android Git Automerger
2 changed files with 23 additions and 4 deletions

View File

@@ -248,6 +248,15 @@ public abstract class CompoundButton extends Button implements Checkable {
return padding;
}
/**
* @hide
*/
@Override
public int getHorizontalOffsetForDrawables() {
final Drawable buttonDrawable = mButtonDrawable;
return (buttonDrawable != null) ? buttonDrawable.getIntrinsicWidth() : 0;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

View File

@@ -4863,6 +4863,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
return highlight;
}
/**
* @hide
*/
public int getHorizontalOffsetForDrawables() {
return 0;
}
@Override
protected void onDraw(Canvas canvas) {
restartMarqueeIfNeeded();
@@ -4880,6 +4887,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
final int left = mLeft;
final int bottom = mBottom;
final int top = mTop;
final boolean isLayoutRtl = isLayoutRtl();
final int offset = getHorizontalOffsetForDrawables();
final int leftOffset = isLayoutRtl ? 0 : offset;
final int rightOffset = isLayoutRtl ? offset : 0 ;
final Drawables dr = mDrawables;
if (dr != null) {
@@ -4895,7 +4906,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Make sure to update invalidateDrawable() when changing this code.
if (dr.mDrawableLeft != null) {
canvas.save();
canvas.translate(scrollX + mPaddingLeft,
canvas.translate(scrollX + mPaddingLeft + leftOffset,
scrollY + compoundPaddingTop +
(vspace - dr.mDrawableHeightLeft) / 2);
dr.mDrawableLeft.draw(canvas);
@@ -4906,7 +4917,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Make sure to update invalidateDrawable() when changing this code.
if (dr.mDrawableRight != null) {
canvas.save();
canvas.translate(scrollX + right - left - mPaddingRight - dr.mDrawableSizeRight,
canvas.translate(scrollX + right - left - mPaddingRight
- dr.mDrawableSizeRight - rightOffset,
scrollY + compoundPaddingTop + (vspace - dr.mDrawableHeightRight) / 2);
dr.mDrawableRight.draw(canvas);
canvas.restore();
@@ -4991,8 +5003,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
canvas.translate(compoundPaddingLeft, extendedPaddingTop + voffsetText);
final boolean isLayoutRtl = isLayoutRtl();
final int layoutDirection = getLayoutDirection();
final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
if (mEllipsize == TextUtils.TruncateAt.MARQUEE &&