Felipe Leme | 979013d | 2017-06-22 10:59:23 -0700 | [diff] [blame] | 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 android.service.autofill; |
| 17 | |
| 18 | import android.annotation.NonNull; |
| 19 | import android.annotation.Nullable; |
Philip P. Moltmann | ebbe2d4 | 2017-07-10 12:07:54 -0700 | [diff] [blame] | 20 | import android.annotation.TestApi; |
Felipe Leme | 979013d | 2017-06-22 10:59:23 -0700 | [diff] [blame] | 21 | import android.view.autofill.AutofillId; |
Felipe Leme | c8c0a82 | 2018-01-26 15:51:56 -0800 | [diff] [blame] | 22 | import android.view.autofill.AutofillValue; |
Felipe Leme | 979013d | 2017-06-22 10:59:23 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Helper object used to obtain the value of a field in the screen being autofilled. |
| 26 | * |
| 27 | * @hide |
| 28 | */ |
Philip P. Moltmann | ebbe2d4 | 2017-07-10 12:07:54 -0700 | [diff] [blame] | 29 | @TestApi |
Felipe Leme | 979013d | 2017-06-22 10:59:23 -0700 | [diff] [blame] | 30 | public interface ValueFinder { |
| 31 | |
| 32 | /** |
Felipe Leme | c8c0a82 | 2018-01-26 15:51:56 -0800 | [diff] [blame] | 33 | * Gets the value of a field as String, or {@code null} when not found. |
| 34 | */ |
| 35 | @Nullable |
| 36 | default String findByAutofillId(@NonNull AutofillId id) { |
| 37 | final AutofillValue value = findRawValueByAutofillId(id); |
| 38 | return (value == null || !value.isText()) ? null : value.getTextValue().toString(); |
| 39 | } |
| 40 | |
| 41 | /** |
Felipe Leme | 979013d | 2017-06-22 10:59:23 -0700 | [diff] [blame] | 42 | * Gets the value of a field, or {@code null} when not found. |
| 43 | */ |
Felipe Leme | c8c0a82 | 2018-01-26 15:51:56 -0800 | [diff] [blame] | 44 | @Nullable |
| 45 | AutofillValue findRawValueByAutofillId(@NonNull AutofillId id); |
Felipe Leme | 979013d | 2017-06-22 10:59:23 -0700 | [diff] [blame] | 46 | } |