Java 类android.view.autofill.AutofillValue 实例源码

项目:android-AutofillFramework    文件:CreditCardExpirationDateCompoundView.java   
@Override
public AutofillValue getAutofillValue() {
    Calendar calendar = Calendar.getInstance();
    // Set hours, minutes, seconds, and millis to 0 to ensure getAutofillValue() == the value
    // set by autofill(). Without this line, the view will not turn yellow when updated.
    calendar.clear();
    int year = Integer.parseInt(mCcExpYearSpinner.getSelectedItem().toString());
    int month = mCcExpMonthSpinner.getSelectedItemPosition();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    long unixTime = calendar.getTimeInMillis();
    return AutofillValue.forDate(unixTime);
}
项目:android-AutofillFramework    文件:Util.java   
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();
}
项目:android-AutofillFramework    文件:CreditCardExpirationDatePickerView.java   
@Override
public AutofillValue getAutofillValue() {
    Calendar c = getCalendar();
    AutofillValue value = AutofillValue.forDate(c.getTimeInMillis());
    if (DEBUG) Log.d(TAG, "getAutofillValue(): " + value);
    return value;
}
项目:android-AutofillFramework    文件:CreditCardExpirationDatePickerView.java   
@Override
public void autofill(AutofillValue value) {
    if (value == null || !value.isDate()) {
        Log.w(TAG, "autofill(): invalid value " + value);
        return;
    }
    long time = value.getDateValue();
    mTempCalendar.setTimeInMillis(time);
    int year = mTempCalendar.get(Calendar.YEAR);
    int month = mTempCalendar.get(Calendar.MONTH);
    if (DEBUG) Log.d(TAG, "autofill(" + value + "): " + month + "/" + year);
    setDate(year, month);
}
项目:android-AutofillFramework    文件:CreditCardExpirationDateCompoundView.java   
@Override
public void autofill(AutofillValue value) {
    if (!value.isDate()) {
        Log.w(TAG, "Ignoring autofill() because service sent a non-date value:" + value);
        return;
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(value.getDateValue());
    int month = calendar.get(Calendar.MONTH);
    int year = calendar.get(Calendar.YEAR);
    mCcExpMonthSpinner.setSelection(month);
    mCcExpYearSpinner.setSelection(year - Integer.parseInt(mYears[0]));
}
项目:android-AutofillFramework    文件:CustomVirtualView.java   
public AutofillValue getAutofillValue() {
    switch (type) {
        case AUTOFILL_TYPE_TEXT:
            return (TextUtils.getTrimmedLength(text) > 0)
                    ? AutofillValue.forText(text)
                    : null;
        case AUTOFILL_TYPE_DATE:
            return AutofillValue.forDate(date);
        default:
            return null;
    }
}
项目:android-AutofillFramework    文件:Util.java   
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();
}
项目:DateTimePicker    文件:TimePicker.java   
@TargetApi(Build.VERSION_CODES.O)
@Override
public void autofill(AutofillValue value) {
    if (!isEnabled()) return;

    if (!value.isDate()) {
        Log.w(LOG_TAG, value + " could not be autofilled into " + this);
        return;
    }

    mDelegate.setDate(value.getDateValue());
}
项目:android-AutofillFramework    文件:StructureParser.java   
private void parseLocked(boolean forFill, ViewNode viewNode, StringBuilder validWebDomain) {
    String webDomain = viewNode.getWebDomain();
    if (webDomain != null) {
        logd("child web domain: %s", webDomain);
        if (validWebDomain.length() > 0) {
            if (!webDomain.equals(validWebDomain.toString())) {
                throw new SecurityException("Found multiple web domains: valid= "
                        + validWebDomain + ", child=" + webDomain);
            }
        } else {
            validWebDomain.append(webDomain);
        }
    }

    if (viewNode.getAutofillHints() != null) {
        String[] filteredHints = AutofillHints.filterForSupportedHints(
                viewNode.getAutofillHints());
        if (filteredHints != null && filteredHints.length > 0) {
            if (forFill) {
                mAutofillFields.add(new AutofillFieldMetadata(viewNode));
            } else {
                FilledAutofillField filledAutofillField =
                        new FilledAutofillField(viewNode.getAutofillHints());
                AutofillValue autofillValue = viewNode.getAutofillValue();
                if (autofillValue.isText()) {
                    // Using toString of AutofillValue.getTextValue in order to save it to
                    // SharedPreferences.
                    filledAutofillField.setTextValue(autofillValue.getTextValue().toString());
                } else if (autofillValue.isDate()) {
                    filledAutofillField.setDateValue(autofillValue.getDateValue());
                } else if (autofillValue.isList()) {
                    filledAutofillField.setListValue(viewNode.getAutofillOptions(),
                            autofillValue.getListValue());
                }
                mFilledAutofillFieldCollection.add(filledAutofillField);
            }
        }
    }
    int childrenSize = viewNode.getChildCount();
    if (childrenSize > 0) {
        for (int i = 0; i < childrenSize; i++) {
            parseLocked(forFill, viewNode.getChildAt(i), validWebDomain);
        }
    }
}
项目:android-AutofillFramework    文件:FilledAutofillFieldCollection.java   
/**
 * Populates a {@link Dataset.Builder} with appropriate values for each {@link AutofillId}
 * in a {@code AutofillFieldMetadataCollection}.
 * <p>
 * In other words, it constructs an autofill
 * {@link Dataset.Builder} by applying saved values (from this {@code FilledAutofillFieldCollection})
 * to Views specified in a {@code AutofillFieldMetadataCollection}, which represents the current
 * page the user is on.
 */
public boolean applyToFields(AutofillFieldMetadataCollection autofillFieldMetadataCollection,
        Dataset.Builder datasetBuilder) {
    boolean setValueAtLeastOnce = false;
    List<String> allHints = autofillFieldMetadataCollection.getAllHints();
    for (int hintIndex = 0; hintIndex < allHints.size(); hintIndex++) {
        String hint = allHints.get(hintIndex);
        List<AutofillFieldMetadata> fillableAutofillFields =
                autofillFieldMetadataCollection.getFieldsForHint(hint);
        if (fillableAutofillFields == null) {
            continue;
        }
        for (int autofillFieldIndex = 0; autofillFieldIndex < fillableAutofillFields.size(); autofillFieldIndex++) {
            FilledAutofillField filledAutofillField = mHintMap.get(hint);
            if (filledAutofillField == null) {
                continue;
            }
            AutofillFieldMetadata autofillFieldMetadata = fillableAutofillFields.get(autofillFieldIndex);
            AutofillId autofillId = autofillFieldMetadata.getId();
            int autofillType = autofillFieldMetadata.getAutofillType();
            switch (autofillType) {
                case View.AUTOFILL_TYPE_LIST:
                    int listValue = autofillFieldMetadata.getAutofillOptionIndex(filledAutofillField.getTextValue());
                    if (listValue != -1) {
                        datasetBuilder.setValue(autofillId, AutofillValue.forList(listValue));
                        setValueAtLeastOnce = true;
                    }
                    break;
                case View.AUTOFILL_TYPE_DATE:
                    Long dateValue = filledAutofillField.getDateValue();
                    if (dateValue != null) {
                        datasetBuilder.setValue(autofillId, AutofillValue.forDate(dateValue));
                        setValueAtLeastOnce = true;
                    }
                    break;
                case View.AUTOFILL_TYPE_TEXT:
                    String textValue = filledAutofillField.getTextValue();
                    if (textValue != null) {
                        datasetBuilder.setValue(autofillId, AutofillValue.forText(textValue));
                        setValueAtLeastOnce = true;
                    }
                    break;
                case View.AUTOFILL_TYPE_TOGGLE:
                    Boolean toggleValue = filledAutofillField.getToggleValue();
                    if (toggleValue != null) {
                        datasetBuilder.setValue(autofillId, AutofillValue.forToggle(toggleValue));
                        setValueAtLeastOnce = true;
                    }
                    break;
                case View.AUTOFILL_TYPE_NONE:
                default:
                    logw("Invalid autofill type - %d", autofillType);
                    break;
            }
        }
    }
    return setValueAtLeastOnce;
}
项目:firefox-tv    文件:SystemWebView.java   
@Override
public void autofill(SparseArray<AutofillValue> values) {
    super.autofill(values);

    TelemetryWrapper.autofillPerformedEvent();
}
项目:DateTimePicker    文件:TimePicker.java   
@TargetApi(Build.VERSION_CODES.O)
@Override
public AutofillValue getAutofillValue() {
    return isEnabled() ? AutofillValue.forDate(mDelegate.getDate()) : null;
}
项目:focus-android    文件:SystemWebView.java   
@Override
public void autofill(SparseArray<AutofillValue> values) {
    super.autofill(values);

    TelemetryWrapper.autofillPerformedEvent();
}
项目:material-components-android    文件:ViewStructureImpl.java   
@Override
public void setAutofillValue(AutofillValue value) {}