1 /* 2 * Copyright 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.compose.ui.autofill 18 19 import androidx.autofill.HintConstants.AUTOFILL_HINT_BIRTH_DATE_DAY 20 import androidx.autofill.HintConstants.AUTOFILL_HINT_BIRTH_DATE_FULL 21 import androidx.autofill.HintConstants.AUTOFILL_HINT_BIRTH_DATE_MONTH 22 import androidx.autofill.HintConstants.AUTOFILL_HINT_BIRTH_DATE_YEAR 23 import androidx.autofill.HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE 24 import androidx.autofill.HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY 25 import androidx.autofill.HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH 26 import androidx.autofill.HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR 27 import androidx.autofill.HintConstants.AUTOFILL_HINT_CREDIT_CARD_NUMBER 28 import androidx.autofill.HintConstants.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE 29 import androidx.autofill.HintConstants.AUTOFILL_HINT_EMAIL_ADDRESS 30 import androidx.autofill.HintConstants.AUTOFILL_HINT_GENDER 31 import androidx.autofill.HintConstants.AUTOFILL_HINT_NEW_PASSWORD 32 import androidx.autofill.HintConstants.AUTOFILL_HINT_NEW_USERNAME 33 import androidx.autofill.HintConstants.AUTOFILL_HINT_PASSWORD 34 import androidx.autofill.HintConstants.AUTOFILL_HINT_PERSON_NAME 35 import androidx.autofill.HintConstants.AUTOFILL_HINT_PERSON_NAME_FAMILY 36 import androidx.autofill.HintConstants.AUTOFILL_HINT_PERSON_NAME_GIVEN 37 import androidx.autofill.HintConstants.AUTOFILL_HINT_PERSON_NAME_MIDDLE 38 import androidx.autofill.HintConstants.AUTOFILL_HINT_PERSON_NAME_MIDDLE_INITIAL 39 import androidx.autofill.HintConstants.AUTOFILL_HINT_PERSON_NAME_PREFIX 40 import androidx.autofill.HintConstants.AUTOFILL_HINT_PERSON_NAME_SUFFIX 41 import androidx.autofill.HintConstants.AUTOFILL_HINT_PHONE_COUNTRY_CODE 42 import androidx.autofill.HintConstants.AUTOFILL_HINT_PHONE_NATIONAL 43 import androidx.autofill.HintConstants.AUTOFILL_HINT_PHONE_NUMBER 44 import androidx.autofill.HintConstants.AUTOFILL_HINT_PHONE_NUMBER_DEVICE 45 import androidx.autofill.HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS 46 import androidx.autofill.HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY 47 import androidx.autofill.HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_ADDRESS 48 import androidx.autofill.HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_POSTAL_CODE 49 import androidx.autofill.HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY 50 import androidx.autofill.HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_REGION 51 import androidx.autofill.HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS 52 import androidx.autofill.HintConstants.AUTOFILL_HINT_POSTAL_CODE 53 import androidx.autofill.HintConstants.AUTOFILL_HINT_SMS_OTP 54 import androidx.autofill.HintConstants.AUTOFILL_HINT_USERNAME 55 56 /** 57 * Gets the Android specific [AutofillHint][android.view.ViewStructure.setAutofillHints] 58 * corresponding to the current [AutofillType]. 59 */ 60 @Suppress("Deprecation") 61 internal val AutofillType.androidType: String 62 get() { 63 val androidAutofillType = androidAutofillTypes[this] <lambda>null64 requireNotNull(androidAutofillType) { "Unsupported autofill type" } 65 return androidAutofillType 66 } 67 68 /** Maps each [AutofillType] to one of the autofill hints in [androidx.autofill.HintConstants] */ 69 @Suppress("Deprecation") 70 private val androidAutofillTypes: HashMap<AutofillType, String> = 71 hashMapOf( 72 AutofillType.EmailAddress to AUTOFILL_HINT_EMAIL_ADDRESS, 73 AutofillType.Username to AUTOFILL_HINT_USERNAME, 74 AutofillType.Password to AUTOFILL_HINT_PASSWORD, 75 AutofillType.NewUsername to AUTOFILL_HINT_NEW_USERNAME, 76 AutofillType.NewPassword to AUTOFILL_HINT_NEW_PASSWORD, 77 AutofillType.PostalAddress to AUTOFILL_HINT_POSTAL_ADDRESS, 78 AutofillType.PostalCode to AUTOFILL_HINT_POSTAL_CODE, 79 AutofillType.CreditCardNumber to AUTOFILL_HINT_CREDIT_CARD_NUMBER, 80 AutofillType.CreditCardSecurityCode to AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE, 81 AutofillType.CreditCardExpirationDate to AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE, 82 AutofillType.CreditCardExpirationMonth to AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH, 83 AutofillType.CreditCardExpirationYear to AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR, 84 AutofillType.CreditCardExpirationDay to AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY, 85 AutofillType.AddressCountry to AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY, 86 AutofillType.AddressRegion to AUTOFILL_HINT_POSTAL_ADDRESS_REGION, 87 AutofillType.AddressLocality to AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY, 88 AutofillType.AddressStreet to AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS, 89 AutofillType.AddressAuxiliaryDetails to AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_ADDRESS, 90 AutofillType.PostalCodeExtended to AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_POSTAL_CODE, 91 AutofillType.PersonFullName to AUTOFILL_HINT_PERSON_NAME, 92 AutofillType.PersonFirstName to AUTOFILL_HINT_PERSON_NAME_GIVEN, 93 AutofillType.PersonLastName to AUTOFILL_HINT_PERSON_NAME_FAMILY, 94 AutofillType.PersonMiddleName to AUTOFILL_HINT_PERSON_NAME_MIDDLE, 95 AutofillType.PersonMiddleInitial to AUTOFILL_HINT_PERSON_NAME_MIDDLE_INITIAL, 96 AutofillType.PersonNamePrefix to AUTOFILL_HINT_PERSON_NAME_PREFIX, 97 AutofillType.PersonNameSuffix to AUTOFILL_HINT_PERSON_NAME_SUFFIX, 98 AutofillType.PhoneNumber to AUTOFILL_HINT_PHONE_NUMBER, 99 AutofillType.PhoneNumberDevice to AUTOFILL_HINT_PHONE_NUMBER_DEVICE, 100 AutofillType.PhoneCountryCode to AUTOFILL_HINT_PHONE_COUNTRY_CODE, 101 AutofillType.PhoneNumberNational to AUTOFILL_HINT_PHONE_NATIONAL, 102 AutofillType.Gender to AUTOFILL_HINT_GENDER, 103 AutofillType.BirthDateFull to AUTOFILL_HINT_BIRTH_DATE_FULL, 104 AutofillType.BirthDateDay to AUTOFILL_HINT_BIRTH_DATE_DAY, 105 AutofillType.BirthDateMonth to AUTOFILL_HINT_BIRTH_DATE_MONTH, 106 AutofillType.BirthDateYear to AUTOFILL_HINT_BIRTH_DATE_YEAR, 107 AutofillType.SmsOtpCode to AUTOFILL_HINT_SMS_OTP 108 ) 109