Merge change 4829 into donut

* changes:
  Fixes #1926784. Setting android:ellipsize on an EditText now ellipsizes the hint.
This commit is contained in:
Android (Google) Code Review
2009-06-19 18:18:42 -07:00

View File

@@ -416,6 +416,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
boolean singleLine = false; boolean singleLine = false;
int maxlength = -1; int maxlength = -1;
CharSequence text = ""; CharSequence text = "";
CharSequence hint = null;
int shadowcolor = 0; int shadowcolor = 0;
float dx = 0, dy = 0, r = 0; float dx = 0, dy = 0, r = 0;
boolean password = false; boolean password = false;
@@ -543,7 +544,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
break; break;
case com.android.internal.R.styleable.TextView_hint: case com.android.internal.R.styleable.TextView_hint:
setHint(a.getText(attr)); hint = a.getText(attr);
break; break;
case com.android.internal.R.styleable.TextView_text: case com.android.internal.R.styleable.TextView_text:
@@ -873,6 +874,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
setText(text, bufferType); setText(text, bufferType);
if (hint != null) setHint(hint);
/* /*
* Views are not normally focusable unless specified to be. * Views are not normally focusable unless specified to be.
@@ -2817,9 +2819,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
checkForRelayout(); checkForRelayout();
} }
if (mText.length() == 0) if (mText.length() == 0) {
invalidate(); invalidate();
} }
}
/** /**
* Sets the text to be displayed when the text of the TextView is empty, * Sets the text to be displayed when the text of the TextView is empty,
@@ -4802,10 +4805,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
alignment = Layout.Alignment.ALIGN_NORMAL; alignment = Layout.Alignment.ALIGN_NORMAL;
} }
boolean shouldEllipsize = mEllipsize != null && mInput == null;
if (mText instanceof Spannable) { if (mText instanceof Spannable) {
mLayout = new DynamicLayout(mText, mTransformed, mTextPaint, w, mLayout = new DynamicLayout(mText, mTransformed, mTextPaint, w,
alignment, mSpacingMult, alignment, mSpacingMult,
mSpacingAdd, mIncludePad, mEllipsize, mSpacingAdd, mIncludePad, mInput == null ? mEllipsize : null,
ellipsisWidth); ellipsisWidth);
} else { } else {
if (boring == UNKNOWN_BORING) { if (boring == UNKNOWN_BORING) {
@@ -4832,7 +4837,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Log.e("aaa", "Boring: " + mTransformed); // Log.e("aaa", "Boring: " + mTransformed);
mSavedLayout = (BoringLayout) mLayout; mSavedLayout = (BoringLayout) mLayout;
} else if (mEllipsize != null && boring.width <= w) { } else if (shouldEllipsize && boring.width <= w) {
if (mSavedLayout != null) { if (mSavedLayout != null) {
mLayout = mSavedLayout. mLayout = mSavedLayout.
replaceOrMake(mTransformed, mTextPaint, replaceOrMake(mTransformed, mTextPaint,
@@ -4845,7 +4850,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
boring, mIncludePad, mEllipsize, boring, mIncludePad, mEllipsize,
ellipsisWidth); ellipsisWidth);
} }
} else if (mEllipsize != null) { } else if (shouldEllipsize) {
mLayout = new StaticLayout(mTransformed, mLayout = new StaticLayout(mTransformed,
0, mTransformed.length(), 0, mTransformed.length(),
mTextPaint, w, alignment, mSpacingMult, mTextPaint, w, alignment, mSpacingMult,
@@ -4857,7 +4862,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mIncludePad); mIncludePad);
// Log.e("aaa", "Boring but wide: " + mTransformed); // Log.e("aaa", "Boring but wide: " + mTransformed);
} }
} else if (mEllipsize != null) { } else if (shouldEllipsize) {
mLayout = new StaticLayout(mTransformed, mLayout = new StaticLayout(mTransformed,
0, mTransformed.length(), 0, mTransformed.length(),
mTextPaint, w, alignment, mSpacingMult, mTextPaint, w, alignment, mSpacingMult,
@@ -4870,9 +4875,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
} }
shouldEllipsize = mEllipsize != null;
mHintLayout = null; mHintLayout = null;
if (mHint != null) { if (mHint != null) {
if (shouldEllipsize) hintWidth = w;
if (hintBoring == UNKNOWN_BORING) { if (hintBoring == UNKNOWN_BORING) {
hintBoring = BoringLayout.isBoring(mHint, mTextPaint, hintBoring = BoringLayout.isBoring(mHint, mTextPaint,
mHintBoring); mHintBoring);
@@ -4882,24 +4890,50 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
if (hintBoring != null) { if (hintBoring != null) {
if (hintBoring.width <= hintWidth) { if (hintBoring.width <= hintWidth &&
(!shouldEllipsize || hintBoring.width <= ellipsisWidth)) {
if (mSavedHintLayout != null) { if (mSavedHintLayout != null) {
mHintLayout = mSavedHintLayout. mHintLayout = mSavedHintLayout.
replaceOrMake(mHint, mTextPaint, replaceOrMake(mHint, mTextPaint,
hintWidth, alignment, mSpacingMult, hintWidth, alignment, mSpacingMult, mSpacingAdd,
mSpacingAdd, hintBoring, mIncludePad); hintBoring, mIncludePad);
} else { } else {
mHintLayout = BoringLayout.make(mHint, mTextPaint, mHintLayout = BoringLayout.make(mHint, mTextPaint,
hintWidth, alignment, mSpacingMult, hintWidth, alignment, mSpacingMult, mSpacingAdd,
mSpacingAdd, hintBoring, mIncludePad); hintBoring, mIncludePad);
} }
mSavedHintLayout = (BoringLayout) mHintLayout; mSavedHintLayout = (BoringLayout) mHintLayout;
} else if (shouldEllipsize && hintBoring.width <= hintWidth) {
if (mSavedHintLayout != null) {
mHintLayout = mSavedHintLayout.
replaceOrMake(mHint, mTextPaint,
hintWidth, alignment, mSpacingMult, mSpacingAdd,
hintBoring, mIncludePad, mEllipsize,
ellipsisWidth);
} else {
mHintLayout = BoringLayout.make(mHint, mTextPaint,
hintWidth, alignment, mSpacingMult, mSpacingAdd,
hintBoring, mIncludePad, mEllipsize,
ellipsisWidth);
}
} else if (shouldEllipsize) {
mHintLayout = new StaticLayout(mHint,
0, mHint.length(),
mTextPaint, hintWidth, alignment, mSpacingMult,
mSpacingAdd, mIncludePad, mEllipsize,
ellipsisWidth);
} else { } else {
mHintLayout = new StaticLayout(mHint, mTextPaint, mHintLayout = new StaticLayout(mHint, mTextPaint,
hintWidth, alignment, mSpacingMult, mSpacingAdd, hintWidth, alignment, mSpacingMult, mSpacingAdd,
mIncludePad); mIncludePad);
} }
} else if (shouldEllipsize) {
mHintLayout = new StaticLayout(mHint,
0, mHint.length(),
mTextPaint, hintWidth, alignment, mSpacingMult,
mSpacingAdd, mIncludePad, mEllipsize,
ellipsisWidth);
} else { } else {
mHintLayout = new StaticLayout(mHint, mTextPaint, mHintLayout = new StaticLayout(mHint, mTextPaint,
hintWidth, alignment, mSpacingMult, mSpacingAdd, hintWidth, alignment, mSpacingMult, mSpacingAdd,
@@ -4983,8 +5017,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
} }
private static final BoringLayout.Metrics UNKNOWN_BORING = private static final BoringLayout.Metrics UNKNOWN_BORING = new BoringLayout.Metrics();
new BoringLayout.Metrics();
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@@ -5011,8 +5044,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
if (des < 0) { if (des < 0) {
boring = BoringLayout.isBoring(mTransformed, mTextPaint, boring = BoringLayout.isBoring(mTransformed, mTextPaint, mBoring);
mBoring);
if (boring != null) { if (boring != null) {
mBoring = boring; mBoring = boring;
} }
@@ -5022,8 +5054,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (boring == null || boring == UNKNOWN_BORING) { if (boring == null || boring == UNKNOWN_BORING) {
if (des < 0) { if (des < 0) {
des = (int) FloatMath.ceil(Layout. des = (int) FloatMath.ceil(Layout.getDesiredWidth(mTransformed, mTextPaint));
getDesiredWidth(mTransformed, mTextPaint));
} }
width = des; width = des;
@@ -5041,13 +5072,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
int hintDes = -1; int hintDes = -1;
int hintWidth; int hintWidth;
if (mHintLayout != null) { if (mHintLayout != null && mEllipsize == null) {
hintDes = desired(mHintLayout); hintDes = desired(mHintLayout);
} }
if (hintDes < 0) { if (hintDes < 0) {
hintBoring = BoringLayout.isBoring(mHint, mTextPaint, hintBoring = BoringLayout.isBoring(mHint, mTextPaint, mHintBoring);
mHintBoring);
if (hintBoring != null) { if (hintBoring != null) {
mHintBoring = hintBoring; mHintBoring = hintBoring;
} }
@@ -5055,8 +5085,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (hintBoring == null || hintBoring == UNKNOWN_BORING) { if (hintBoring == null || hintBoring == UNKNOWN_BORING) {
if (hintDes < 0) { if (hintDes < 0) {
hintDes = (int) FloatMath.ceil(Layout. hintDes = (int) FloatMath.ceil(
getDesiredWidth(mHint, mTextPaint)); Layout.getDesiredWidth(mHint, mTextPaint));
} }
hintWidth = hintDes; hintWidth = hintDes;
@@ -5102,8 +5132,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (mLayout == null) { if (mLayout == null) {
makeNewLayout(want, hintWant, boring, hintBoring, makeNewLayout(want, hintWant, boring, hintBoring,
width - getCompoundPaddingLeft() - getCompoundPaddingRight(), width - getCompoundPaddingLeft() - getCompoundPaddingRight(), false);
false);
} else if ((mLayout.getWidth() != want) || (hintWidth != hintWant) || } else if ((mLayout.getWidth() != want) || (hintWidth != hintWant) ||
(mLayout.getEllipsizedWidth() != (mLayout.getEllipsizedWidth() !=
width - getCompoundPaddingLeft() - getCompoundPaddingRight())) { width - getCompoundPaddingLeft() - getCompoundPaddingRight())) {
@@ -5114,8 +5143,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mLayout.increaseWidthTo(want); mLayout.increaseWidthTo(want);
} else { } else {
makeNewLayout(want, hintWant, boring, hintBoring, makeNewLayout(want, hintWant, boring, hintBoring,
width - getCompoundPaddingLeft() - getCompoundPaddingRight(), width - getCompoundPaddingLeft() - getCompoundPaddingRight(), false);
false);
} }
} else { } else {
// Width has not changed. // Width has not changed.
@@ -5136,11 +5164,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
} }
int unpaddedHeight = height - getCompoundPaddingTop() - int unpaddedHeight = height - getCompoundPaddingTop() - getCompoundPaddingBottom();
getCompoundPaddingBottom();
if (mMaxMode == LINES && mLayout.getLineCount() > mMaximum) { if (mMaxMode == LINES && mLayout.getLineCount() > mMaximum) {
unpaddedHeight = Math.min(unpaddedHeight, unpaddedHeight = Math.min(unpaddedHeight, mLayout.getLineTop(mMaximum));
mLayout.getLineTop(mMaximum));
} }
/* /*
@@ -5159,8 +5185,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
private int getDesiredHeight() { private int getDesiredHeight() {
return Math.max(getDesiredHeight(mLayout, true), return Math.max(
getDesiredHeight(mHintLayout, false)); getDesiredHeight(mLayout, true),
getDesiredHeight(mHintLayout, mEllipsize != null));
} }
private int getDesiredHeight(Layout layout, boolean cap) { private int getDesiredHeight(Layout layout, boolean cap) {
@@ -5803,6 +5830,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
private void startMarquee() { private void startMarquee() {
// Do not ellipsize EditText
if (mInput != null) return;
if (compressText(getWidth() - getCompoundPaddingLeft() - getCompoundPaddingRight())) { if (compressText(getWidth() - getCompoundPaddingLeft() - getCompoundPaddingRight())) {
return; return;
} }