From 0bdf1c9c76c0832d3adbe85bdc0cde4c1e3102ce Mon Sep 17 00:00:00 2001 From: Jiaquan He Date: Mon, 1 May 2017 14:17:07 -0700 Subject: [PATCH] Check state_focus in foreground. This commit checks whether the state_focus is specified in the foreground of a view. If it is, the default focus highlight won't show up. Test: cts-tradefed run singleCommand cts --skip-device-info --skip-preconditions --abi armeabi-v7a -m CtsViewTestCases -t android.view.cts.View_DefaultFocusHighlightTest#testIsDefaultFocusHighlightNeeded Bug: 37288730 Change-Id: I5256eb656c1b8729d685edb914e867ee9a3a92a4 --- api/test-current.txt | 1 + core/java/android/view/View.java | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/api/test-current.txt b/api/test-current.txt index d3cb4c9335c5..cf119d112010 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -45743,6 +45743,7 @@ package android.view { method public boolean isAttachedToWindow(); method public boolean isClickable(); method public boolean isContextClickable(); + method public boolean isDefaultFocusHighlightNeeded(android.graphics.drawable.Drawable, android.graphics.drawable.Drawable); method public boolean isDirty(); method public boolean isDrawingCacheEnabled(); method public boolean isDuplicateParentStateEnabled(); diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 5b51c16a1dfb..19639cf06a41 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -19801,18 +19801,23 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * Check whether we need to draw a default focus highlight when this view gets focused, * which requires: * * @return {@code true} if a default focus highlight is needed. + * @hide */ - private boolean isDefaultFocusHighlightNeeded(Drawable background) { - final boolean hasFocusStateSpecified = background == null || !background.isStateful() - || !background.hasFocusStateSpecified(); - return !isInTouchMode() && getDefaultFocusHighlightEnabled() && hasFocusStateSpecified + @TestApi + public boolean isDefaultFocusHighlightNeeded(Drawable background, Drawable foreground) { + final boolean lackFocusState = (background == null || !background.isStateful() + || !background.hasFocusStateSpecified()) + && (foreground == null || !foreground.isStateful() + || !foreground.hasFocusStateSpecified()); + return !isInTouchMode() && getDefaultFocusHighlightEnabled() && lackFocusState && isAttachedToWindow() && sUseDefaultFocusHighlight; } @@ -19824,7 +19829,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ private void switchDefaultFocusHighlight() { if (isFocused()) { - final boolean needed = isDefaultFocusHighlightNeeded(mBackground); + final boolean needed = isDefaultFocusHighlightNeeded(mBackground, + mForegroundInfo == null ? null : mForegroundInfo.mDrawable); final boolean active = mDefaultFocusHighlight != null; if (needed && !active) { setDefaultFocusHighlight(getDefaultFocusHighlightDrawable()); -- 2.11.0