Java Code Examples for android.view.autofill.AutofillValue#isDate()
The following examples show how to use
android.view.autofill.AutofillValue#isDate() .
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: DateTransformation.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** @hide */ @Override @TestApi public void apply(@NonNull ValueFinder finder, @NonNull RemoteViews parentTemplate, int childViewId) throws Exception { final AutofillValue value = finder.findRawValueByAutofillId(mFieldId); if (value == null) { Log.w(TAG, "No value for id " + mFieldId); return; } if (!value.isDate()) { Log.w(TAG, "Value for " + mFieldId + " is not date: " + value); return; } try { final Date date = new Date(value.getDateValue()); final String transformed = mDateFormat.format(date); if (sDebug) Log.d(TAG, "Transformed " + date + " to " + transformed); parentTemplate.setCharSequence(childViewId, "setText", transformed); } catch (Exception e) { Log.w(TAG, "Could not apply " + mDateFormat + " to " + value + ": " + e); } }
Example 2
Source File: TimePicker.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public final void autofill(AutofillValue value) { if (value == null || !value.isDate()) { Log.w(LOG_TAG, value + " could not be autofilled into " + this); return; } final long time = value.getDateValue(); final Calendar cal = Calendar.getInstance(mLocale); cal.setTimeInMillis(time); setDate(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE)); // Must set mAutofilledValue *after* calling subclass method to make sure the value // returned by getAutofillValue() matches it. mAutofilledValue = time; }
Example 3
Source File: DatePicker.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public final void autofill(AutofillValue value) { if (value == null || !value.isDate()) { Log.w(LOG_TAG, value + " could not be autofilled into " + this); return; } final long time = value.getDateValue(); final Calendar cal = Calendar.getInstance(mCurrentLocale); cal.setTimeInMillis(time); updateDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); // Must set mAutofilledValue *after* calling subclass method to make sure the value // returned by getAutofillValue() matches it. mAutofilledValue = time; }
Example 4
Source File: ClientAutofillDataBuilder.java From input-samples with Apache License 2.0 | 5 votes |
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 5
Source File: Util.java From input-samples with Apache License 2.0 | 5 votes |
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 6
Source File: CreditCardExpirationDatePickerView.java From input-samples with Apache License 2.0 | 5 votes |
@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); }
Example 7
Source File: CreditCardExpirationDateCompoundView.java From input-samples with Apache License 2.0 | 5 votes |
@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])); }
Example 8
Source File: Util.java From input-samples with Apache License 2.0 | 5 votes |
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: DateValueSanitizer.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** @hide */ @Override @TestApi @Nullable public AutofillValue sanitize(@NonNull AutofillValue value) { if (value == null) { Log.w(TAG, "sanitize() called with null value"); return null; } if (!value.isDate()) { if (sDebug) Log.d(TAG, value + " is not a date"); return null; } try { final Date date = new Date(value.getDateValue()); // First convert it to string final String converted = mDateFormat.format(date); if (sDebug) Log.d(TAG, "Transformed " + date + " to " + converted); // Then parse it back to date final Date sanitized = mDateFormat.parse(converted); if (sDebug) Log.d(TAG, "Sanitized to " + sanitized); return AutofillValue.forDate(sanitized.getTime()); } catch (Exception e) { Log.w(TAG, "Could not apply " + mDateFormat + " to " + value + ": " + e); return null; } }
Example 10
Source File: ClientAutofillDataBuilder.java From android-AutofillFramework with Apache License 2.0 | 5 votes |
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 11
Source File: Util.java From android-AutofillFramework with Apache License 2.0 | 5 votes |
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 12
Source File: CreditCardExpirationDatePickerView.java From android-AutofillFramework with Apache License 2.0 | 5 votes |
@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); }
Example 13
Source File: CreditCardExpirationDateCompoundView.java From android-AutofillFramework with Apache License 2.0 | 5 votes |
@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])); }
Example 14
Source File: Util.java From android-AutofillFramework with Apache License 2.0 | 5 votes |
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 15
Source File: TimePicker.java From DateTimePicker with Apache License 2.0 | 5 votes |
@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()); }