Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 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 android.service.autofill; |
| 18 | |
| 19 | import android.app.assist.AssistStructure.ViewNode; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | /** |
| 24 | * Represents a view field that can be auto-filled. |
| 25 | * |
| 26 | * <p>Currently only text-fields are supported, so the value of the field can be obtained through |
| 27 | * {@link #getValue()}. |
| 28 | * |
| 29 | * @hide |
| 30 | */ |
| 31 | public final class FillableInputField implements Parcelable { |
| 32 | |
| 33 | private final int mId; |
| 34 | private final String mValue; |
| 35 | |
| 36 | private FillableInputField(int id, String value) { |
| 37 | mId = id; |
| 38 | mValue = value; |
| 39 | } |
| 40 | |
| 41 | private FillableInputField(Parcel parcel) { |
| 42 | mId = parcel.readInt(); |
| 43 | mValue = parcel.readString(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Gets the view id as returned by {@link ViewNode#getAutoFillId()}. |
| 48 | */ |
| 49 | public int getId() { |
| 50 | return mId; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Gets the value of this field. |
| 55 | */ |
| 56 | public String getValue() { |
| 57 | return mValue; |
| 58 | |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public String toString() { |
| 63 | return "[AutoFillField: " + mId + "=" + mValue + "]"; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Creates an {@code AutoFillField} for a text field. |
| 68 | * |
| 69 | * @param id view id as returned by {@link ViewNode#getAutoFillId()}. |
| 70 | * @param text value to be auto-filled. |
| 71 | */ |
| 72 | public static FillableInputField forText(int id, String text) { |
| 73 | return new FillableInputField(id, text); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public int describeContents() { |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public void writeToParcel(Parcel parcel, int flags) { |
| 83 | parcel.writeInt(mId); |
| 84 | parcel.writeString(mValue); |
| 85 | } |
| 86 | |
| 87 | public static final Parcelable.Creator<FillableInputField> CREATOR = |
| 88 | new Parcelable.Creator<FillableInputField>() { |
| 89 | @Override |
| 90 | public FillableInputField createFromParcel(Parcel source) { |
| 91 | return new FillableInputField(source); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public FillableInputField[] newArray(int size) { |
| 96 | return new FillableInputField[size]; |
| 97 | } |
| 98 | }; |
| 99 | } |