Stop cursor from blinking when not visible

Cursor continues to blink in a text field even when the text field is
not currently visible. This change checks the visibility of the window
that houses the text field in addition to checking if the view is in
focus.

Bug: 228354442

Test: Added logging to the shouldBlink() method ran following steps:
     1: open contacts app
     2: tap add new contact, tap in an edit field
     3: move back to home screen
     4: lock screen, then unlock screen
     5: observed logs written out to logcat console when app not
        visible.
     after change logs no longer printed to console, cursor still blinks
     correctly after app is re-opened or when new field becomes in
     focus.
Test: CtsWidgetTestCases:EditTextTest#
        testCursorNotBlinkingOnNewActivity_WithoutFocus()
	testCursorBlinkingOnNewActivity_WithFocus()
	testSuspendAndResumeBlinkingCursor()
Change-Id: Iad4396e5f7fd810344c711320d65c57ea25eda70
Merged-In: Iad4396e5f7fd810344c711320d65c57ea25eda70
This commit is contained in:
Steven Terrell
2022-05-13 16:10:32 +00:00
parent 057f721740
commit 4ec6dfc389

View File

@@ -709,7 +709,7 @@ public class Editor {
}
getPositionListener().addSubscriber(mCursorAnchorInfoNotifier, true);
resumeBlink();
makeBlink();
}
void onDetachedFromWindow() {
@@ -1685,17 +1685,12 @@ public class Editor {
void onWindowFocusChanged(boolean hasWindowFocus) {
if (hasWindowFocus) {
if (mBlink != null) {
mBlink.uncancel();
makeBlink();
}
resumeBlink();
if (mTextView.hasSelection() && !extractedTextModeWillBeStarted()) {
refreshTextActionMode();
}
} else {
if (mBlink != null) {
mBlink.cancel();
}
suspendBlink();
if (mInputContentType != null) {
mInputContentType.enterDown = false;
}
@@ -2851,7 +2846,8 @@ public class Editor {
* @return True when the TextView isFocused and has a valid zero-length selection (cursor).
*/
private boolean shouldBlink() {
if (!isCursorVisible() || !mTextView.isFocused()) return false;
if (!isCursorVisible() || !mTextView.isFocused()
|| mTextView.getWindowVisibility() != mTextView.VISIBLE) return false;
final int start = mTextView.getSelectionStart();
if (start < 0) return false;