@@ -100,6 +100,20 @@ public final class TerminalView extends View {
100
100
@ RequiresApi (api = Build .VERSION_CODES .O )
101
101
private int mAutoFillType = AUTOFILL_TYPE_NONE ;
102
102
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
+
103
117
/**
104
118
* The current AutoFill hints returned for {@link View#getAutofillHints()} ()} by {@link #getAutofillHints()} ()}.
105
119
*
@@ -1059,13 +1073,14 @@ public AutofillValue getAutofillValue() {
1059
1073
@ RequiresApi (api = Build .VERSION_CODES .O )
1060
1074
@ Override
1061
1075
public int getImportantForAutofill () {
1062
- return IMPORTANT_FOR_AUTOFILL_NO ;
1076
+ return mAutoFillImportance ;
1063
1077
}
1064
1078
1065
1079
@ RequiresApi (api = Build .VERSION_CODES .O )
1066
1080
private synchronized void resetAutoFill () {
1067
1081
// Restore none type so that AutoFill UI isn't shown anymore.
1068
1082
mAutoFillType = AUTOFILL_TYPE_NONE ;
1083
+ mAutoFillImportance = IMPORTANT_FOR_AUTOFILL_NO ;
1069
1084
mAutoFillHints = new String [0 ];
1070
1085
}
1071
1086
@@ -1115,6 +1130,9 @@ public synchronized void requestAutoFill(String[] autoFillHints) {
1115
1130
if (autofillManager != null && autofillManager .isEnabled ()) {
1116
1131
// Update type that will be returned by `getAutofillType()` so that AutoFill UI is shown.
1117
1132
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 ;
1118
1136
// Update hints that will be returned by `getAutofillHints()` for which to show AutoFill UI.
1119
1137
mAutoFillHints = autoFillHints ;
1120
1138
autofillManager .requestAutofill (this );
0 commit comments