diff options
| author | 2017-05-02 17:40:25 -0700 | |
|---|---|---|
| committer | 2017-07-24 16:34:48 -0700 | |
| commit | e329c38c4af8041ed243075c2e7c5a341d2e1042 (patch) | |
| tree | 240cac9f33df15eaba24a90408f4542bc08bdf67 | |
| parent | 1d0667b89904fa471e142abc78b4222587b0f4e4 (diff) | |
Disabled views won't receive focus
This is how other UI toolkits behave and is what users
expect.
Bug: 33672074
Test: Added CTS Test.
Change-Id: Ia4d215bc26844141287faddb3eb19a199f9691a5
| -rw-r--r-- | core/java/android/view/View.java | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 52251214d611..a93f08706fa9 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -6856,8 +6856,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } - // Invisible and gone views are never focusable. - if ((mViewFlags & VISIBILITY_MASK) != VISIBLE) { + // Invisible, gone, or disabled views are never focusable. + if ((mViewFlags & VISIBILITY_MASK) != VISIBLE + || (mViewFlags & ENABLED_MASK) != ENABLED) { return false; } @@ -10480,7 +10481,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (views == null) { return; } - if (!isFocusable()) { + if (!isFocusable() || !isEnabled()) { return; } if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE @@ -10803,7 +10804,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, private boolean requestFocusNoSearch(int direction, Rect previouslyFocusedRect) { // need to be focusable if ((mViewFlags & FOCUSABLE) != FOCUSABLE - || (mViewFlags & VISIBILITY_MASK) != VISIBLE) { + || (mViewFlags & VISIBILITY_MASK) != VISIBLE + || (mViewFlags & ENABLED_MASK) != ENABLED) { return false; } @@ -13281,12 +13283,28 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // about in case nothing has focus. even if this specific view // isn't focusable, it may contain something that is, so let // the root view try to give this focus if nothing else does. - if ((mParent != null)) { + if ((mParent != null) && (mViewFlags & ENABLED_MASK) == ENABLED) { mParent.focusableViewAvailable(this); } } } + if ((changed & ENABLED_MASK) != 0) { + if ((mViewFlags & ENABLED_MASK) == ENABLED) { + // a view becoming enabled should notify the parent as long as the view is also + // visible and the parent wasn't already notified by becoming visible during this + // setFlags invocation. + if ((mViewFlags & VISIBILITY_MASK) == VISIBLE + && ((changed & VISIBILITY_MASK) == 0)) { + if ((mParent != null) && (mViewFlags & ENABLED_MASK) == ENABLED) { + mParent.focusableViewAvailable(this); + } + } + } else { + if (hasFocus()) clearFocus(); + } + } + /* Check if the GONE bit has changed */ if ((changed & GONE) != 0) { needGlobalAttributesUpdate(false); |