summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2010-12-13 17:22:39 -0800
committerGilles Debunne <debunne@google.com>2010-12-14 10:28:35 -0800
commita3ae4a06569afbbf135692b8d55289117c42b205 (patch)
tree0357c5637d1ad3e91c954e89405d39d7606c9a3c /core/java/android/widget
parent03955450e42f08d6e684a07bf61d8644a74fe228 (diff)
downloadframeworks_base-a3ae4a06569afbbf135692b8d55289117c42b205.zip
frameworks_base-a3ae4a06569afbbf135692b8d55289117c42b205.tar.gz
frameworks_base-a3ae4a06569afbbf135692b8d55289117c42b205.tar.bz2
Make TextView respect the maxLines attribute.
Bug 3186626 Restore some of the changes introduced in CL 78854. Also added a few comments to the documentation. Change-Id: I775be85c33ebe4a2384a40b21eec57f34fddcd33
Diffstat (limited to 'core/java/android/widget')
-rw-r--r--core/java/android/widget/TextView.java70
1 files changed, 47 insertions, 23 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 160af21..751cd53 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -918,9 +918,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
drawableLeft, drawableTop, drawableRight, drawableBottom);
setCompoundDrawablePadding(drawablePadding);
- // Same as setSingleLine, but make sure the transformation method is unchanged.
+ // Same as setSingleLine(), but make sure the transformation method and the maximum number
+ // of lines of height (for multi-line only) are unchanged.
setInputTypeSingleLine(singleLine);
- applySingleLine(singleLine, false);
+ applySingleLine(singleLine, false, false);
if (singleLine && mInput == null && ellipsize < 0) {
ellipsize = 3; // END
@@ -2156,7 +2157,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
/**
- * Makes the TextView at least this many lines tall
+ * Makes the TextView at least this many lines tall.
+ *
+ * Setting this value overrides any other (minimum) height setting. A single line TextView will
+ * set this value to 1.
*
* @attr ref android.R.styleable#TextView_minLines
*/
@@ -2170,7 +2174,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
/**
- * Makes the TextView at least this many pixels tall
+ * Makes the TextView at least this many pixels tall.
+ *
+ * Setting this value overrides any other (minimum) number of lines setting.
*
* @attr ref android.R.styleable#TextView_minHeight
*/
@@ -2184,7 +2190,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
/**
- * Makes the TextView at most this many lines tall
+ * Makes the TextView at most this many lines tall.
+ *
+ * Setting this value overrides any other (maximum) height setting.
*
* @attr ref android.R.styleable#TextView_maxLines
*/
@@ -2198,7 +2206,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
/**
- * Makes the TextView at most this many pixels tall
+ * Makes the TextView at most this many pixels tall. This option is mutually exclusive with the
+ * {@link #setMaxLines(int)} method.
+ *
+ * Setting this value overrides any other (maximum) number of lines setting.
*
* @attr ref android.R.styleable#TextView_maxHeight
*/
@@ -2212,7 +2223,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
/**
- * Makes the TextView exactly this many lines tall
+ * Makes the TextView exactly this many lines tall.
+ *
+ * Note that setting this value overrides any other (minimum / maximum) number of lines or
+ * height setting. A single line TextView will set this value to 1.
*
* @attr ref android.R.styleable#TextView_lines
*/
@@ -2230,6 +2244,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* You could do the same thing by specifying this number in the
* LayoutParams.
*
+ * Note that setting this value overrides any other (minimum / maximum) number of lines or
+ * height setting.
+ *
* @attr ref android.R.styleable#TextView_height
*/
@android.view.RemotableViewMethod
@@ -3027,12 +3044,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
/**
- * Set the type of the content with a constant as defined for
- * {@link EditorInfo#inputType}. This will take care of changing
- * the key listener, by calling {@link #setKeyListener(KeyListener)}, to
- * match the given content type. If the given content type is
- * {@link EditorInfo#TYPE_NULL} then a soft keyboard will
- * not be displayed for this text view.
+ * Set the type of the content with a constant as defined for {@link EditorInfo#inputType}. This
+ * will take care of changing the key listener, by calling {@link #setKeyListener(KeyListener)},
+ * to match the given content type. If the given content type is {@link EditorInfo#TYPE_NULL}
+ * then a soft keyboard will not be displayed for this text view.
+ *
+ * Note that the maximum number of displayed lines (see {@link #setMaxLines(int)}) will be
+ * modified if you change the {@link EditorInfo#TYPE_TEXT_FLAG_MULTI_LINE} flag of the input
+ * type.
*
* @see #getInputType()
* @see #setRawInputType(int)
@@ -3069,7 +3088,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (mSingleLine != singleLine || forceUpdate) {
// Change single line mode, but only change the transformation if
// we are not in password mode.
- applySingleLine(singleLine, !isPassword);
+ applySingleLine(singleLine, !isPassword, true);
}
InputMethodManager imm = InputMethodManager.peekInstance();
@@ -6308,19 +6327,21 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
/**
- * If true, sets the properties of this field (lines, horizontally
- * scrolling, transformation method) to be for a single-line input;
- * if false, restores these to the default conditions.
- * Note that calling this with false restores default conditions,
- * not necessarily those that were in effect prior to calling
- * it with true.
+ * If true, sets the properties of this field (number of lines, horizontally scrolling,
+ * transformation method) to be for a single-line input; if false, restores these to the default
+ * conditions.
+ *
+ * Note that the default conditions are not necessarily those that were in effect prior this
+ * method, and you may want to reset these properties to your custom values.
*
* @attr ref android.R.styleable#TextView_singleLine
*/
@android.view.RemotableViewMethod
public void setSingleLine(boolean singleLine) {
+ // Could be used, but may break backward compatibility.
+ // if (mSingleLine == singleLine) return;
setInputTypeSingleLine(singleLine);
- applySingleLine(singleLine, true);
+ applySingleLine(singleLine, true, true);
}
/**
@@ -6337,7 +6358,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
}
- private void applySingleLine(boolean singleLine, boolean applyTransformation) {
+ private void applySingleLine(boolean singleLine, boolean applyTransformation,
+ boolean changeMaxLines) {
mSingleLine = singleLine;
if (singleLine) {
setLines(1);
@@ -6347,7 +6369,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
setBackgroundDrawable(mEditTextSingleLineBackground);
} else {
- setMaxLines(Integer.MAX_VALUE);
+ if (changeMaxLines) {
+ setMaxLines(Integer.MAX_VALUE);
+ }
setHorizontallyScrolling(false);
if (applyTransformation) {
setTransformationMethod(null);