Commit d46be1ad authored by Elizabeth Popova's avatar Elizabeth Popova Committed by Commit Bot

[Android] Fix initial keyboard showing on Android P+ in prefeditor dialog

Due to Focus/Keyboard Navigation Changes in Android P+ initial focus is no longer assigned which causes the keyboard not to be shown on Android P+.
This behavior was fixed by:
- triggering default focus programatically (no-op on pre Android P)
- showing keyboard only after the focus is set

Bug: 1144129
Change-Id: Ib7539ba307e62c7c00a66ae088e9ffe15a45a4df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2510211Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Commit-Queue: Elizabeth Popova <lizapopova@google.com>
Cr-Commit-Position: refs/heads/master@{#824957}
parent b8878bf7
...@@ -571,10 +571,6 @@ public class EditorDialog ...@@ -571,10 +571,6 @@ public class EditorDialog
for (int i = 0; i < mEditableTextFields.size(); i++) { for (int i = 0; i < mEditableTextFields.size(); i++) {
mEditableTextFields.get(i).setEnabled(true); mEditableTextFields.get(i).setEnabled(true);
} }
// Note that keyboard will not show for dropdown field since it's not necessary.
if (getCurrentFocus() != null) {
KeyboardVisibilityDelegate.getInstance().showKeyboard(getCurrentFocus());
}
mDialogInOutAnimator = null; mDialogInOutAnimator = null;
initFocus(); initFocus();
} }
...@@ -584,20 +580,21 @@ public class EditorDialog ...@@ -584,20 +580,21 @@ public class EditorDialog
} }
private void initFocus() { private void initFocus() {
// Immediately focus the first invalid field to make it faster to edit. mHandler.post(() -> {
final List<EditorFieldView> invalidViews = getViewsWithInvalidInformation(false); List<EditorFieldView> invalidViews = getViewsWithInvalidInformation(false);
if (!invalidViews.isEmpty()) { if (!invalidViews.isEmpty()) {
mHandler.post(new Runnable() { // Immediately focus the first invalid field to make it faster to edit.
@Override invalidViews.get(0).scrollToAndFocus();
public void run() { } else {
invalidViews.get(0).scrollToAndFocus(); // Trigger default focus as it is not triggered automatically on Android P+.
if (sObserverForTest != null) sObserverForTest.onEditorReadyToEdit(); mLayout.requestFocus();
} }
}); // Note that keyboard will not be shown for dropdown field since it's not necessary.
} else { if (getCurrentFocus() != null) {
// The first field will be focused, we are ready to edit. KeyboardVisibilityDelegate.getInstance().showKeyboard(getCurrentFocus());
}
if (sObserverForTest != null) sObserverForTest.onEditorReadyToEdit(); if (sObserverForTest != null) sObserverForTest.onEditorReadyToEdit();
} });
} }
private List<EditorFieldView> getViewsWithInvalidInformation(boolean findAll) { private List<EditorFieldView> getViewsWithInvalidInformation(boolean findAll) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment