Java Code Examples for android.view.autofill.AutofillValue#isText()

The following examples show how to use android.view.autofill.AutofillValue#isText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientAutofillDataBuilder.java    From input-samples with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 2
Source File: Util.java    From input-samples with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 3
Source File: Util.java    From input-samples with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 4
Source File: AssistStructure.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example 5
Source File: TextValueSanitizer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @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;
    }
}
 
Example 6
Source File: ClientAutofillDataBuilder.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: Util.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 8
Source File: Util.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 9
Source File: ValueFinder.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * 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();
}