Skip to content

Commit 4443b65

Browse files
Fixed: Mark view as important for AutoFill before requesting an AutoFill
Co-authored-by: @AChep <[email protected]> Co-authored-by: @agnostic-apollo <[email protected]>
1 parent a8a69c6 commit 4443b65

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

terminal-view/src/main/java/com/termux/view/TerminalView.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ public final class TerminalView extends View {
100100
@RequiresApi(api = Build.VERSION_CODES.O)
101101
private int mAutoFillType = AUTOFILL_TYPE_NONE;
102102

103+
/**
104+
* The current AutoFill type returned for {@link View#getImportantForAutofill()} by
105+
* {@link #getImportantForAutofill()}.
106+
*
107+
* The default is {@link #IMPORTANT_FOR_AUTOFILL_NO} so that view is not considered important
108+
* for AutoFill. This value should be updated to required value, like
109+
* {@link #IMPORTANT_FOR_AUTOFILL_YES} before calling {@link AutofillManager#requestAutofill(View)}
110+
* so that Android and apps consider the view as important for AutoFill to process the request.
111+
* The updated value set will automatically be restored to {@link #IMPORTANT_FOR_AUTOFILL_NO} in
112+
* {@link #autofill(AutofillValue)} by calling {@link #resetAutoFill()}.
113+
*/
114+
@RequiresApi(api = Build.VERSION_CODES.O)
115+
private int mAutoFillImportance = IMPORTANT_FOR_AUTOFILL_NO;
116+
103117
/**
104118
* The current AutoFill hints returned for {@link View#getAutofillHints()} ()} by {@link #getAutofillHints()} ()}.
105119
*
@@ -1078,13 +1092,14 @@ public AutofillValue getAutofillValue() {
10781092
@RequiresApi(api = Build.VERSION_CODES.O)
10791093
@Override
10801094
public int getImportantForAutofill() {
1081-
return IMPORTANT_FOR_AUTOFILL_NO;
1095+
return mAutoFillImportance;
10821096
}
10831097

10841098
@RequiresApi(api = Build.VERSION_CODES.O)
10851099
private synchronized void resetAutoFill() {
10861100
// Restore none type so that AutoFill UI isn't shown anymore.
10871101
mAutoFillType = AUTOFILL_TYPE_NONE;
1102+
mAutoFillImportance = IMPORTANT_FOR_AUTOFILL_NO;
10881103
mAutoFillHints = new String[0];
10891104
}
10901105

@@ -1134,6 +1149,9 @@ public synchronized void requestAutoFill(String[] autoFillHints) {
11341149
if (autofillManager != null && autofillManager.isEnabled()) {
11351150
// Update type that will be returned by `getAutofillType()` so that AutoFill UI is shown.
11361151
mAutoFillType = AUTOFILL_TYPE_TEXT;
1152+
// Update importance that will be returned by `getImportantForAutofill()` so that
1153+
// AutoFill considers the view as important.
1154+
mAutoFillImportance = IMPORTANT_FOR_AUTOFILL_YES;
11371155
// Update hints that will be returned by `getAutofillHints()` for which to show AutoFill UI.
11381156
mAutoFillHints = autoFillHints;
11391157
autofillManager.requestAutofill(this);

0 commit comments

Comments
 (0)