Merge "Mark focused Views as keep clear areas" into tm-dev

This commit is contained in:
Robert Horvath
2022-03-03 13:14:56 +00:00
committed by Android (Google) Code Review
4 changed files with 64 additions and 11 deletions

View File

@@ -4769,6 +4769,9 @@ 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.
@@ -8171,6 +8174,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
notifyEnterOrExitForAutoFillIfNeeded(gainFocus);
updatePreferKeepClearForFocus();
}
/**
@@ -11934,19 +11938,46 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*/
@NonNull
List<Rect> collectPreferKeepClearRects() {
final ListenerInfo info = mListenerInfo;
if (info != null) {
final List<Rect> list = new ArrayList();
if (info.mPreferKeepClear) {
list.add(new Rect(0, 0, getWidth(), getHeight()));
}
if (info.mKeepClearRects != null) {
list.addAll(info.mKeepClearRects);
}
return list;
ListenerInfo info = mListenerInfo;
final List<Rect> list = new ArrayList<>();
if ((info != null && info.mPreferKeepClear) || mPreferKeepClearForFocus) {
list.add(new Rect(0, 0, getWidth(), getHeight()));
}
return Collections.emptyList();
if (info != null && info.mKeepClearRects != null) {
list.addAll(info.mKeepClearRects);
}
return list;
}
private void updatePreferKeepClearForFocus() {
if (mMarkPreferKeepClearForFocus != null) {
removeCallbacks(mMarkPreferKeepClearForFocus);
mMarkPreferKeepClearForFocus = null;
}
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;
}
/**
@@ -13656,6 +13687,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
invalidate();
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
updatePreferKeepClearForFocus();
return true;
}
return false;
@@ -13735,6 +13767,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
sendAccessibilityEventUnchecked(event);
}
}
updatePreferKeepClearForFocus();
}
}
@@ -20987,6 +21021,7 @@ 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.

View File

@@ -347,6 +347,7 @@ public class ViewConfiguration {
private final long mScreenshotChordKeyTimeout;
private final int mSmartSelectionInitializedTimeout;
private final int mSmartSelectionInitializingTimeout;
private final int mPreferKeepClearForFocusDelay;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768915)
private boolean sHasPermanentMenuKey;
@@ -392,6 +393,7 @@ public class ViewConfiguration {
mMinScalingSpan = 0;
mSmartSelectionInitializedTimeout = SMART_SELECTION_INITIALIZED_TIMEOUT_IN_MILLISECOND;
mSmartSelectionInitializingTimeout = SMART_SELECTION_INITIALIZING_TIMEOUT_IN_MILLISECOND;
mPreferKeepClearForFocusDelay = -1;
}
/**
@@ -506,6 +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);
}
/**
@@ -1095,6 +1099,15 @@ public class ViewConfiguration {
return mSmartSelectionInitializingTimeout;
}
/**
* @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.
* @hide
*/
public int getPreferKeepClearForFocusDelay() {
return mPreferKeepClearForFocusDelay;
}
/**
* @return the duration in milliseconds before an end of a long press causes a tooltip to be
* hidden

View File

@@ -5192,6 +5192,10 @@
when TextClassifier has not been initialized. -->
<integer name="config_smartSelectionInitializingTimeoutMillis">500</integer>
<!-- The delay in milliseconds before focused Views set themselves as preferred to keep clear.
Set to -1 if Views should not set themselves as preferred to keep clear. -->
<integer name="config_preferKeepClearForFocusDelayMillis">-1</integer>
<!-- Indicates that default fitness tracker app needs to request sensor and location permissions. -->
<bool name="config_trackerAppNeedsPermissions">false</bool>

View File

@@ -493,6 +493,7 @@
<java-symbol type="string" name="config_bandwidthEstimateSource" />
<java-symbol type="integer" name="config_smartSelectionInitializedTimeoutMillis" />
<java-symbol type="integer" name="config_smartSelectionInitializingTimeoutMillis" />
<java-symbol type="integer" name="config_preferKeepClearForFocusDelayMillis" />
<java-symbol type="bool" name="config_hibernationDeletesOatArtifactsEnabled"/>
<java-symbol type="integer" name="config_defaultAnalogClockSecondsHandFps"/>