diff options
| author | 2010-10-15 02:53:58 +0300 | |
|---|---|---|
| committer | 2010-10-18 00:53:18 +0300 | |
| commit | 042856c1de6cdce854641aaecd68a689c5ba64f3 (patch) | |
| tree | ca7b1acc6ba6e7734101987bb3c53e075687e49f | |
| parent | fdb39feedd34087c9a5c7492ca31a38ec46bc2ed (diff) | |
Make disabled TextViews uneditable
Fixes Issue 2771
From now on:
disabling a TextView closes the associated on-screen keyboard
selecting a disabled TextView does not open the on-screen keyboard
can't edit contents if the disabled TextView focus is gained by the directional keys
Change-Id: I44e3c0aff2a0ce1e6426818bfe16c1d19c7c18ac
| -rw-r--r-- | core/java/android/widget/TextView.java | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index e6ed70ae3bf3..05db26683ac8 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -944,6 +944,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener setTypeface(tf, styleIndex); } + @Override + public void setEnabled(boolean enabled) { + if (enabled == isEnabled()) { + return; + } + + if (!enabled) { + // Hide the soft input if the currently active TextView is disabled + InputMethodManager imm = InputMethodManager.peekInstance(); + if (imm != null && imm.isActive(this)) { + imm.hideSoftInputFromWindow(getWindowToken(), 0); + } + } + super.setEnabled(enabled); + } + /** * Sets the typeface and style in which the text should be displayed, * and turns on the fake bold and italic bits in the Paint if the @@ -4436,7 +4452,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { - if (onCheckIsTextEditor()) { + if (onCheckIsTextEditor() && isEnabled()) { if (mInputMethodState == null) { mInputMethodState = new InputMethodState(); } @@ -6575,7 +6591,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return superResult; } - if ((mMovement != null || onCheckIsTextEditor()) && mText instanceof Spannable && mLayout != null) { + if ((mMovement != null || onCheckIsTextEditor()) && isEnabled() + && mText instanceof Spannable && mLayout != null) { boolean handled = false; |