@@ -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
*
@@ -1078,13 +1092,14 @@ public AutofillValue getAutofillValue() {
1078
1092
@ RequiresApi (api = Build .VERSION_CODES .O )
1079
1093
@ Override
1080
1094
public int getImportantForAutofill () {
1081
- return IMPORTANT_FOR_AUTOFILL_NO ;
1095
+ return mAutoFillImportance ;
1082
1096
}
1083
1097
1084
1098
@ RequiresApi (api = Build .VERSION_CODES .O )
1085
1099
private synchronized void resetAutoFill () {
1086
1100
// Restore none type so that AutoFill UI isn't shown anymore.
1087
1101
mAutoFillType = AUTOFILL_TYPE_NONE ;
1102
+ mAutoFillImportance = IMPORTANT_FOR_AUTOFILL_NO ;
1088
1103
mAutoFillHints = new String [0 ];
1089
1104
}
1090
1105
@@ -1134,6 +1149,9 @@ public synchronized void requestAutoFill(String[] autoFillHints) {
1134
1149
if (autofillManager != null && autofillManager .isEnabled ()) {
1135
1150
// Update type that will be returned by `getAutofillType()` so that AutoFill UI is shown.
1136
1151
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 ;
1137
1155
// Update hints that will be returned by `getAutofillHints()` for which to show AutoFill UI.
1138
1156
mAutoFillHints = autoFillHints ;
1139
1157
autofillManager .requestAutofill (this );
0 commit comments