Skip to content

Commit ee9b31a

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 68865fb commit ee9b31a

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

+19-1
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
*
@@ -1059,13 +1073,14 @@ public AutofillValue getAutofillValue() {
10591073
@RequiresApi(api = Build.VERSION_CODES.O)
10601074
@Override
10611075
public int getImportantForAutofill() {
1062-
return IMPORTANT_FOR_AUTOFILL_NO;
1076+
return mAutoFillImportance;
10631077
}
10641078

10651079
@RequiresApi(api = Build.VERSION_CODES.O)
10661080
private synchronized void resetAutoFill() {
10671081
// Restore none type so that AutoFill UI isn't shown anymore.
10681082
mAutoFillType = AUTOFILL_TYPE_NONE;
1083+
mAutoFillImportance = IMPORTANT_FOR_AUTOFILL_NO;
10691084
mAutoFillHints = new String[0];
10701085
}
10711086

@@ -1115,6 +1130,9 @@ public synchronized void requestAutoFill(String[] autoFillHints) {
11151130
if (autofillManager != null && autofillManager.isEnabled()) {
11161131
// Update type that will be returned by `getAutofillType()` so that AutoFill UI is shown.
11171132
mAutoFillType = AUTOFILL_TYPE_TEXT;
1133+
// Update importance that will be returned by `getImportantForAutofill()` so that
1134+
// AutoFill considers the view as important.
1135+
mAutoFillImportance = IMPORTANT_FOR_AUTOFILL_YES;
11181136
// Update hints that will be returned by `getAutofillHints()` for which to show AutoFill UI.
11191137
mAutoFillHints = autoFillHints;
11201138
autofillManager.requestAutofill(this);

0 commit comments

Comments
 (0)