diff options
Diffstat (limited to 'input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model')
4 files changed, 12 insertions, 144 deletions
diff --git a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/AutofillField.kt b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/AutofillField.kt deleted file mode 100644 index 474454a3..00000000 --- a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/AutofillField.kt +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.example.android.autofillframework.multidatasetservice.model - -import android.app.assist.AssistStructure.ViewNode; -import android.service.autofill.SaveInfo -import android.view.View -import android.view.autofill.AutofillId - -/** - * A stripped down version of a [ViewNode] that contains only autofill-relevant metadata. It also - * contains a `saveType` flag that is calculated based on the [ViewNode]'s autofill hints. - */ -class AutofillField(view: ViewNode) { - var saveType = 0 - private set - - val autofillHints: Array<String> = view.autofillHints - val autofillId: AutofillId = view.autofillId - val autofillType: Int = view.autofillType - val autofillOptions: Array<CharSequence>? = view.autofillOptions - val isFocused: Boolean = view.isFocused - - init { - updateSaveTypeFromHints() - } - - /** - * When the [ViewNode] is a list that the user needs to choose a string from (i.e. a spinner), - * this is called to return the index of a specific item in the list. - */ - fun getAutofillOptionIndex(value: CharSequence): Int? { - return autofillOptions?.indexOf(value) - } - - private fun updateSaveTypeFromHints() { - saveType = 0 - for (hint in autofillHints) { - when (hint) { - View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE, - View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY, - View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH, - View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR, - View.AUTOFILL_HINT_CREDIT_CARD_NUMBER, - View.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE -> { - saveType = saveType or SaveInfo.SAVE_DATA_TYPE_CREDIT_CARD - } - View.AUTOFILL_HINT_EMAIL_ADDRESS -> { - saveType = saveType or SaveInfo.SAVE_DATA_TYPE_EMAIL_ADDRESS - } - View.AUTOFILL_HINT_PHONE, View.AUTOFILL_HINT_NAME -> { - saveType = saveType or SaveInfo.SAVE_DATA_TYPE_GENERIC - } - View.AUTOFILL_HINT_PASSWORD -> { - saveType = saveType or SaveInfo.SAVE_DATA_TYPE_PASSWORD - saveType = saveType and SaveInfo.SAVE_DATA_TYPE_EMAIL_ADDRESS.inv() - saveType = saveType and SaveInfo.SAVE_DATA_TYPE_USERNAME.inv() - } - View.AUTOFILL_HINT_POSTAL_ADDRESS, - View.AUTOFILL_HINT_POSTAL_CODE -> { - saveType = saveType or SaveInfo.SAVE_DATA_TYPE_ADDRESS - } - View.AUTOFILL_HINT_USERNAME -> { - saveType = saveType or SaveInfo.SAVE_DATA_TYPE_USERNAME - } - } - } - } -} diff --git a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/AutofillFieldsCollection.kt b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/AutofillFieldsCollection.kt deleted file mode 100644 index c62ea327..00000000 --- a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/AutofillFieldsCollection.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.example.android.autofillframework.multidatasetservice.model - -import android.view.autofill.AutofillId -import java.util.ArrayList -import java.util.HashMap - -/** - * Data structure that stores a collection of `AutofillField`s. Contains all of the client's `View` - * hierarchy autofill-relevant metadata. - */ -data class AutofillFieldsCollection(val autofillIds: ArrayList<AutofillId> = ArrayList<AutofillId>(), - val allAutofillHints: ArrayList<String> = ArrayList<String>(), - val focusedAutofillHints: ArrayList<String> = ArrayList<String>()) { - - private val autofillHintsToFieldsMap = HashMap<String, MutableList<AutofillField>>() - var saveType = 0 - private set - - fun add(autofillField: AutofillField) { - saveType = saveType or autofillField.saveType - autofillIds.add(autofillField.autofillId) - val hintsList = autofillField.autofillHints - allAutofillHints.addAll(hintsList) - if (autofillField.isFocused) { - focusedAutofillHints.addAll(hintsList) - } - autofillField.autofillHints.forEach { autofillHint -> - autofillHintsToFieldsMap[autofillHint] = autofillHintsToFieldsMap[autofillHint] ?: ArrayList<AutofillField>() - autofillHintsToFieldsMap[autofillHint]?.add(autofillField) - } - } - - fun getFieldsForHint(hint: String): MutableList<AutofillField>? { - return autofillHintsToFieldsMap[hint] - } -} diff --git a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/SavableAutofillData.kt b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/FilledAutofillField.kt index 3c50d339..fd2e1769 100644 --- a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/SavableAutofillData.kt +++ b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/FilledAutofillField.kt @@ -21,7 +21,7 @@ import android.view.autofill.AutofillValue /** * JSON serializable data class containing the same data as an [AutofillValue]. */ -class SavableAutofillData(viewNode: AssistStructure.ViewNode) { +class FilledAutofillField(viewNode: AssistStructure.ViewNode) { var textValue: CharSequence? = null var dateValue: Long? = null var toggleValue: Boolean? = null diff --git a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/ClientFormData.kt b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/FilledAutofillFieldCollection.kt index 8f434abe..1adf1dcc 100644 --- a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/ClientFormData.kt +++ b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/FilledAutofillFieldCollection.kt @@ -20,36 +20,37 @@ import android.util.Log import android.view.View import android.view.autofill.AutofillId import android.view.autofill.AutofillValue +import com.example.android.autofillframework.multidatasetservice.AutofillFieldMetadataCollection import java.util.HashMap /** - * ClientFormData is the model that represents all of the form data on a client app's page, plus the + * FilledAutofillFieldCollection is the model that represents all of the form data on a client app's page, plus the * dataset name associated with it. */ -class ClientFormData constructor(var datasetName: String? = null, - private val hintMap: HashMap<String, SavableAutofillData> = HashMap<String, SavableAutofillData>()) { +class FilledAutofillFieldCollection constructor(var datasetName: String? = null, + private val hintMap: HashMap<String, FilledAutofillField> = HashMap<String, FilledAutofillField>()) { - private val TAG = "ClientFormData" + private val TAG = "FilledAutofillFieldCollection" /** * Sets values for a list of autofillHints. */ - fun setAutofillValuesForHints(autofillHints: Array<String>, autofillData: SavableAutofillData) { + fun setAutofillValuesForHints(autofillHints: Array<String>, autofillField: FilledAutofillField) { autofillHints.forEach { hint -> - hintMap[hint] = autofillData + hintMap[hint] = autofillField } } /** * Populates a [Dataset.Builder] with appropriate values for each [AutofillId] - * in a `AutofillFieldsCollection`. + * in a `AutofillFieldMetadataCollection`. */ - fun applyToFields(autofillFieldsCollection: AutofillFieldsCollection, + fun applyToFields(autofillFieldMetadataCollection: AutofillFieldMetadataCollection, datasetBuilder: Dataset.Builder): Boolean { var setValueAtLeastOnce = false - for (hint in autofillFieldsCollection.allAutofillHints) { - val autofillFields = autofillFieldsCollection.getFieldsForHint(hint) ?: continue + for (hint in autofillFieldMetadataCollection.allAutofillHints) { + val autofillFields = autofillFieldMetadataCollection.getFieldsForHint(hint) ?: continue for (autofillField in autofillFields) { val autofillId = autofillField.autofillId val autofillType = autofillField.autofillType |