From 2a6ce367fe5d53194a3de2f034cf2770f8979edc Mon Sep 17 00:00:00 2001 From: Robert Horvath Date: Thu, 5 May 2022 18:38:00 +0200 Subject: [PATCH] Remove preferKeepClearAreaForFocusDelay, turn it into a flag TV PiP repositioning in response to keep clear area changes will be debounced in SystemUI, so the client side delay in setting a keep clear area with focus becomes obsolete. Instead the config is turned into a flag for whether focused views should automatically be marked as keep clear areas. Bug: 231309309 Test: atest KeepClearRectsTests Change-Id: I0ac61e671bb75e22a95b400c9bd8d84004379e43 Merged-In: I0ac61e671bb75e22a95b400c9bd8d84004379e43 --- core/api/test-current.txt | 2 +- core/java/android/view/View.java | 37 +++---------------- core/java/android/view/ViewConfiguration.java | 16 ++++---- core/res/res/values/config.xml | 5 +-- core/res/res/values/symbols.xml | 2 +- 5 files changed, 18 insertions(+), 44 deletions(-) diff --git a/core/api/test-current.txt b/core/api/test-current.txt index fe99c71d9a9a3..48277fb3b488c 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -2923,7 +2923,7 @@ package android.view { method public static int getHoverTooltipHideTimeout(); method public static int getHoverTooltipShowTimeout(); method public static int getLongPressTooltipHideTimeout(); - method public int getPreferKeepClearForFocusDelay(); + method public boolean isPreferKeepClearForFocusEnabled(); } public class ViewDebug { diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 38ca2481726bd..90497e7adbf73 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -4781,9 +4781,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @UnsupportedAppUsage ListenerInfo mListenerInfo; - private boolean mPreferKeepClearForFocus; - private Runnable mMarkPreferKeepClearForFocus; - private static class TooltipInfo { /** * Text to be displayed in a tooltip popup. @@ -11962,8 +11959,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @NonNull List collectPreferKeepClearRects() { ListenerInfo info = mListenerInfo; - boolean keepBoundsClear = - (info != null && info.mPreferKeepClear) || mPreferKeepClearForFocus; + boolean keepClearForFocus = isFocused() + && ViewConfiguration.get(mContext).isPreferKeepClearForFocusEnabled(); + boolean keepBoundsClear = (info != null && info.mPreferKeepClear) || keepClearForFocus; boolean hasCustomKeepClearRects = info != null && info.mKeepClearRects != null; if (!keepBoundsClear && !hasCustomKeepClearRects) { @@ -11985,31 +11983,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } private void updatePreferKeepClearForFocus() { - if (mMarkPreferKeepClearForFocus != null) { - removeCallbacks(mMarkPreferKeepClearForFocus); - mMarkPreferKeepClearForFocus = null; + if (ViewConfiguration.get(mContext).isPreferKeepClearForFocusEnabled()) { + updatePositionUpdateListener(); + post(this::updateKeepClearRects); } - - final ViewConfiguration configuration = ViewConfiguration.get(mContext); - final int delay = configuration.getPreferKeepClearForFocusDelay(); - if (delay >= 0) { - mMarkPreferKeepClearForFocus = () -> { - mPreferKeepClearForFocus = isFocused(); - mMarkPreferKeepClearForFocus = null; - - updatePositionUpdateListener(); - post(this::updateKeepClearRects); - }; - postDelayed(mMarkPreferKeepClearForFocus, delay); - } - } - - private void cancelMarkPreferKeepClearForFocus() { - if (mMarkPreferKeepClearForFocus != null) { - removeCallbacks(mMarkPreferKeepClearForFocus); - mMarkPreferKeepClearForFocus = null; - } - mPreferKeepClearForFocus = false; } /** @@ -13754,7 +13731,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } invalidate(); sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED); - updatePreferKeepClearForFocus(); return true; } return false; @@ -21154,7 +21130,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, removePerformClickCallback(); clearAccessibilityThrottles(); stopNestedScroll(); - cancelMarkPreferKeepClearForFocus(); // Anything that started animating right before detach should already // be in its final state when re-attached. diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index ebc409e470e90..638b8f9f9b404 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -347,7 +347,7 @@ public class ViewConfiguration { private final long mScreenshotChordKeyTimeout; private final int mSmartSelectionInitializedTimeout; private final int mSmartSelectionInitializingTimeout; - private final int mPreferKeepClearForFocusDelay; + private final boolean mPreferKeepClearForFocusEnabled; @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768915) private boolean sHasPermanentMenuKey; @@ -393,7 +393,7 @@ public class ViewConfiguration { mMinScalingSpan = 0; mSmartSelectionInitializedTimeout = SMART_SELECTION_INITIALIZED_TIMEOUT_IN_MILLISECOND; mSmartSelectionInitializingTimeout = SMART_SELECTION_INITIALIZING_TIMEOUT_IN_MILLISECOND; - mPreferKeepClearForFocusDelay = -1; + mPreferKeepClearForFocusEnabled = false; } /** @@ -508,8 +508,8 @@ public class ViewConfiguration { com.android.internal.R.integer.config_smartSelectionInitializedTimeoutMillis); mSmartSelectionInitializingTimeout = res.getInteger( com.android.internal.R.integer.config_smartSelectionInitializingTimeoutMillis); - mPreferKeepClearForFocusDelay = res.getInteger( - com.android.internal.R.integer.config_preferKeepClearForFocusDelayMillis); + mPreferKeepClearForFocusEnabled = res.getBoolean( + com.android.internal.R.bool.config_preferKeepClearForFocus); } /** @@ -1100,13 +1100,13 @@ public class ViewConfiguration { } /** - * @return The delay in milliseconds before focused Views set themselves as preferred to keep - * clear, or -1 if Views should not set themselves as preferred to keep clear. + * @return {@code true} if Views should set themselves as preferred to keep clear when focused, + * {@code false} otherwise. * @hide */ @TestApi - public int getPreferKeepClearForFocusDelay() { - return mPreferKeepClearForFocusDelay; + public boolean isPreferKeepClearForFocusEnabled() { + return mPreferKeepClearForFocusEnabled; } /** diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index b139e472460a1..403624d5c4a11 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -5166,9 +5166,8 @@ when TextClassifier has not been initialized. --> 500 - - -1 + + false false diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 77007afc2156d..816510bcdfe94 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -479,7 +479,7 @@ - +