1 /* 2 * Copyright (C) 2017 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 package com.example.android.autofillframework.multidatasetservice 17 18 import android.view.autofill.AutofillId 19 20 /** 21 * Data structure that stores a collection of `AutofillFieldMetadata`s. Contains all of the client's `View` 22 * hierarchy autofill-relevant metadata. 23 */ 24 data class AutofillFieldMetadataCollection @JvmOverloads constructor( 25 val autofillIds: ArrayList<AutofillId> = ArrayList<AutofillId>(), 26 val allAutofillHints: ArrayList<String> = ArrayList<String>(), 27 val focusedAutofillHints: ArrayList<String> = ArrayList<String>() 28 ) { 29 30 private val autofillHintsToFieldsMap = HashMap<String, MutableList<AutofillFieldMetadata>>() 31 var saveType = 0 32 private set 33 addnull34 fun add(autofillFieldMetadata: AutofillFieldMetadata) { 35 saveType = saveType or autofillFieldMetadata.saveType 36 autofillIds.add(autofillFieldMetadata.autofillId) 37 val hintsList = autofillFieldMetadata.autofillHints 38 allAutofillHints.addAll(hintsList) 39 if (autofillFieldMetadata.isFocused) { 40 focusedAutofillHints.addAll(hintsList) 41 } 42 autofillFieldMetadata.autofillHints.forEach { 43 val fields = autofillHintsToFieldsMap[it] ?: ArrayList<AutofillFieldMetadata>() 44 autofillHintsToFieldsMap[it] = fields 45 fields.add(autofillFieldMetadata) 46 } 47 } 48 getFieldsForHintnull49 fun getFieldsForHint(hint: String): MutableList<AutofillFieldMetadata>? { 50 return autofillHintsToFieldsMap[hint] 51 } 52 } 53