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.model 17 18 import android.app.assist.AssistStructure 19 import android.view.autofill.AutofillValue 20 import com.example.android.autofillframework.multidatasetservice.AutofillHelper 21 import com.google.gson.annotations.Expose 22 23 /** 24 * JSON serializable data class containing the same data as an [AutofillValue]. 25 */ 26 class FilledAutofillField(viewNode: AssistStructure.ViewNode) { 27 @Expose 28 var textValue: String? = null 29 30 @Expose 31 var dateValue: Long? = null 32 33 @Expose 34 var toggleValue: Boolean? = null 35 36 val autofillHints = viewNode.autofillHints.filter(AutofillHelper::isValidHint).toTypedArray() 37 38 init { 39 viewNode.autofillValue?.let { 40 if (it.isList) { 41 val index = it.listValue 42 viewNode.autofillOptions?.let { autofillOptions -> 43 if (autofillOptions.size > index) { 44 textValue = autofillOptions[index].toString() 45 } 46 } 47 } else if (it.isDate) { 48 dateValue = it.dateValue 49 } else if (it.isText) { 50 // Using toString of AutofillValue.getTextValue in order to save it to 51 // SharedPreferences. 52 textValue = it.textValue.toString() 53 } else { 54 } 55 } 56 } 57 58 fun isNull(): Boolean { 59 return textValue == null && dateValue == null && toggleValue == null 60 } 61 } 62