下面列出了android.view.autofill.AutofillValue#isText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void parseAutofillFields(AssistStructure.ViewNode viewNode,
DatasetWithFilledAutofillFields datasetWithFilledAutofillFields, int partition) {
String[] hints = viewNode.getAutofillHints();
if (hints == null || hints.length == 0) {
return;
}
AutofillValue autofillValue = viewNode.getAutofillValue();
String textValue = null;
Long dateValue = null;
Boolean toggleValue = null;
CharSequence[] autofillOptions = null;
Integer listIndex = null;
if (autofillValue != null) {
if (autofillValue.isText()) {
// Using toString of AutofillValue.getTextValue in order to save it to
// SharedPreferences.
textValue = autofillValue.getTextValue().toString();
} else if (autofillValue.isDate()) {
dateValue = autofillValue.getDateValue();
} else if (autofillValue.isList()) {
autofillOptions = viewNode.getAutofillOptions();
listIndex = autofillValue.getListValue();
} else if (autofillValue.isToggle()) {
toggleValue = autofillValue.getToggleValue();
}
}
appendViewMetadata(datasetWithFilledAutofillFields,
hints, partition, textValue, dateValue, toggleValue,
autofillOptions, listIndex);
}
private static String getAutofillValueAndTypeAsString(AutofillValue value) {
if (value == null) return "null";
StringBuilder builder = new StringBuilder(value.toString()).append('(');
if (value.isText()) {
builder.append("isText");
} else if (value.isDate()) {
builder.append("isDate");
} else if (value.isToggle()) {
builder.append("isToggle");
} else if (value.isList()) {
builder.append("isList");
}
return builder.append(')').toString();
}
private static String getAutofillValueAndTypeAsString(AutofillValue value) {
if (value == null) return "null";
StringBuilder builder = new StringBuilder(value.toString()).append('(');
if (value.isText()) {
builder.append("isText");
} else if (value.isDate()) {
builder.append("isDate");
} else if (value.isToggle()) {
builder.append("isToggle");
} else if (value.isList()) {
builder.append("isList");
}
return builder.append(')').toString();
}
/**
* Updates the {@link AutofillValue} of this structure.
*
* <p>Should be used just before sending the structure to the
* {@link android.service.autofill.AutofillService} for saving, since it will override the
* initial value.
*
* @hide
*/
public void updateAutofillValue(AutofillValue value) {
mAutofillValue = value;
if (value.isText()) {
if (mText == null) {
mText = new ViewNodeText();
}
mText.mText = value.getTextValue();
}
}
/** @hide */
@Override
@TestApi
@Nullable
public AutofillValue sanitize(@NonNull AutofillValue value) {
if (value == null) {
Slog.w(TAG, "sanitize() called with null value");
return null;
}
if (!value.isText()) {
if (sDebug) Slog.d(TAG, "sanitize() called with non-text value: " + value);
return null;
}
final CharSequence text = value.getTextValue();
try {
final Matcher matcher = mRegex.matcher(text);
if (!matcher.matches()) {
if (sDebug) Slog.d(TAG, "sanitize(): " + mRegex + " failed for " + value);
return null;
}
final CharSequence sanitized = matcher.replaceAll(mSubst);
return AutofillValue.forText(sanitized);
} catch (Exception e) {
Slog.w(TAG, "Exception evaluating " + mRegex + "/" + mSubst + ": " + e);
return null;
}
}
private void parseAutofillFields(AssistStructure.ViewNode viewNode,
DatasetWithFilledAutofillFields datasetWithFilledAutofillFields, int partition) {
String[] hints = viewNode.getAutofillHints();
if (hints == null || hints.length == 0) {
return;
}
AutofillValue autofillValue = viewNode.getAutofillValue();
String textValue = null;
Long dateValue = null;
Boolean toggleValue = null;
CharSequence[] autofillOptions = null;
Integer listIndex = null;
if (autofillValue != null) {
if (autofillValue.isText()) {
// Using toString of AutofillValue.getTextValue in order to save it to
// SharedPreferences.
textValue = autofillValue.getTextValue().toString();
} else if (autofillValue.isDate()) {
dateValue = autofillValue.getDateValue();
} else if (autofillValue.isList()) {
autofillOptions = viewNode.getAutofillOptions();
listIndex = autofillValue.getListValue();
} else if (autofillValue.isToggle()) {
toggleValue = autofillValue.getToggleValue();
}
}
appendViewMetadata(datasetWithFilledAutofillFields,
hints, partition, textValue, dateValue, toggleValue,
autofillOptions, listIndex);
}
private static String getAutofillValueAndTypeAsString(AutofillValue value) {
if (value == null) return "null";
StringBuilder builder = new StringBuilder(value.toString()).append('(');
if (value.isText()) {
builder.append("isText");
} else if (value.isDate()) {
builder.append("isDate");
} else if (value.isToggle()) {
builder.append("isToggle");
} else if (value.isList()) {
builder.append("isList");
}
return builder.append(')').toString();
}
private static String getAutofillValueAndTypeAsString(AutofillValue value) {
if (value == null) return "null";
StringBuilder builder = new StringBuilder(value.toString()).append('(');
if (value.isText()) {
builder.append("isText");
} else if (value.isDate()) {
builder.append("isDate");
} else if (value.isToggle()) {
builder.append("isToggle");
} else if (value.isList()) {
builder.append("isList");
}
return builder.append(')').toString();
}
/**
* Gets the value of a field as String, or {@code null} when not found.
*/
@Nullable
default String findByAutofillId(@NonNull AutofillId id) {
final AutofillValue value = findRawValueByAutofillId(id);
return (value == null || !value.isText()) ? null : value.getTextValue().toString();
}