diff options
| author | Gilles Debunne <debunne@google.com> | 2010-11-08 17:34:49 -0800 |
|---|---|---|
| committer | Gilles Debunne <debunne@google.com> | 2010-11-08 18:03:45 -0800 |
| commit | 91a08cfc4f8111ed66e51f9471e956d201cc8b60 (patch) | |
| tree | 74070ec78f3e01dbc5c753d2497844080c7d5f23 /core | |
| parent | 010e2c299746d31f8f233eefc6828ec1c2785efd (diff) | |
| download | frameworks_base-91a08cfc4f8111ed66e51f9471e956d201cc8b60.zip frameworks_base-91a08cfc4f8111ed66e51f9471e956d201cc8b60.tar.gz frameworks_base-91a08cfc4f8111ed66e51f9471e956d201cc8b60.tar.bz2 | |
Rationalized singleLine in TextView, take 2.
Same as CL 77435, but without the default singleLine value change.
Change-Id: I04794ed72716bbe5a285d2bbbb3f536308e5972f
Diffstat (limited to 'core')
| -rw-r--r-- | core/java/android/widget/TextView.java | 53 |
1 files changed, 16 insertions, 37 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 2ebed5f..3838a02 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -791,10 +791,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener ? inputType : EditorInfo.TYPE_CLASS_TEXT; } else if (inputType != EditorInfo.TYPE_NULL) { setInputType(inputType, true); - singleLine = (inputType&(EditorInfo.TYPE_MASK_CLASS - | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE)) != - (EditorInfo.TYPE_CLASS_TEXT - | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE); + // If set, the input type overrides what was set using the deprecated singleLine flag. + singleLine = !isMultilineInputType(inputType); } else if (phone) { mInput = DialerKeyListener.getInstance(); mInputType = inputType = EditorInfo.TYPE_CLASS_PHONE; @@ -813,9 +811,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener TextKeyListener.Capitalize cap; inputType = EditorInfo.TYPE_CLASS_TEXT; - if (!singleLine) { - inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; - } switch (autocap) { case 1: @@ -843,9 +838,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } else if (editable) { mInput = TextKeyListener.getInstance(); mInputType = EditorInfo.TYPE_CLASS_TEXT; - if (!singleLine) { - mInputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; - } } else { mInput = null; @@ -888,12 +880,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener drawableLeft, drawableTop, drawableRight, drawableBottom); setCompoundDrawablePadding(drawablePadding); - if (singleLine) { - setSingleLine(); - - if (mInput == null && ellipsize < 0) { + setSingleLine(singleLine); + if (singleLine && mInput == null && ellipsize < 0) { ellipsize = 3; // END - } } switch (ellipsize) { @@ -1157,14 +1146,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } catch (IncompatibleClassChangeError e) { mInputType = EditorInfo.TYPE_CLASS_TEXT; } - if ((mInputType&EditorInfo.TYPE_MASK_CLASS) - == EditorInfo.TYPE_CLASS_TEXT) { - if (mSingleLine) { - mInputType &= ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; - } else { - mInputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; - } - } + setSingleLine(mSingleLine); } else { mInputType = EditorInfo.TYPE_NULL; } @@ -2992,6 +2974,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return mHint; } + private boolean isMultilineInputType(int type) { + return (type & (EditorInfo.TYPE_MASK_CLASS | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE)) == + (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE); + } + /** * Set the type of the content with a constant as defined for * {@link EditorInfo#inputType}. This will take care of changing @@ -3028,17 +3015,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } - boolean multiLine = (type&(EditorInfo.TYPE_MASK_CLASS - | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE)) == - (EditorInfo.TYPE_CLASS_TEXT - | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE); + boolean singleLine = !isMultilineInputType(type); // We need to update the single line mode if it has changed or we // were previously in password mode. - if (mSingleLine == multiLine || forceUpdate) { + if (mSingleLine != singleLine || forceUpdate) { // Change single line mode, but only change the transformation if // we are not in password mode. - applySingleLine(!multiLine, !isPassword); + applySingleLine(singleLine, !isPassword); } InputMethodManager imm = InputMethodManager.peekInstance(); @@ -4746,10 +4730,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION; } } - if ((outAttrs.inputType & (InputType.TYPE_MASK_CLASS - | InputType.TYPE_TEXT_FLAG_MULTI_LINE)) - == (InputType.TYPE_CLASS_TEXT - | InputType.TYPE_TEXT_FLAG_MULTI_LINE)) { + if (isMultilineInputType(outAttrs.inputType)) { // Multi-line text editors should always show an enter key. outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION; } @@ -6092,8 +6073,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener */ @android.view.RemotableViewMethod public void setSingleLine(boolean singleLine) { - if ((mInputType&EditorInfo.TYPE_MASK_CLASS) - == EditorInfo.TYPE_CLASS_TEXT) { + if ((mInputType & EditorInfo.TYPE_MASK_CLASS) == EditorInfo.TYPE_CLASS_TEXT) { if (singleLine) { mInputType &= ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; } else { @@ -6109,8 +6089,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener setLines(1); setHorizontallyScrolling(true); if (applyTransformation) { - setTransformationMethod(SingleLineTransformationMethod. - getInstance()); + setTransformationMethod(SingleLineTransformationMethod.getInstance()); } } else { setMaxLines(Integer.MAX_VALUE); |
