• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.view.autofill;
17 
18 import android.annotation.TestApi;
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.view.View;
22 
23 /**
24  * A unique identifier for an autofill node inside an {@link android.app.Activity}.
25  */
26 public final class AutofillId implements Parcelable {
27 
28     private final int mViewId;
29     private final boolean mVirtual;
30     private final int mVirtualId;
31 
32     /** @hide */
33     @TestApi
AutofillId(int id)34     public AutofillId(int id) {
35         mVirtual = false;
36         mViewId = id;
37         mVirtualId = View.NO_ID;
38     }
39 
40     /** @hide */
AutofillId(AutofillId parent, int virtualChildId)41     public AutofillId(AutofillId parent, int virtualChildId) {
42         mVirtual = true;
43         mViewId = parent.mViewId;
44         mVirtualId = virtualChildId;
45     }
46 
47     /** @hide */
AutofillId(int parentId, int virtualChildId)48     public AutofillId(int parentId, int virtualChildId) {
49         mVirtual = true;
50         mViewId = parentId;
51         mVirtualId = virtualChildId;
52     }
53 
54     /** @hide */
getViewId()55     public int getViewId() {
56         return mViewId;
57     }
58 
59     /** @hide */
getVirtualChildId()60     public int getVirtualChildId() {
61         return mVirtualId;
62     }
63 
64     /** @hide */
isVirtual()65     public boolean isVirtual() {
66         return mVirtual;
67     }
68 
69     /////////////////////////////////
70     //  Object "contract" methods. //
71     /////////////////////////////////
72 
73     @Override
hashCode()74     public int hashCode() {
75         final int prime = 31;
76         int result = 1;
77         result = prime * result + mViewId;
78         result = prime * result + mVirtualId;
79         return result;
80     }
81 
82     @Override
equals(Object obj)83     public boolean equals(Object obj) {
84         if (this == obj) return true;
85         if (obj == null) return false;
86         if (getClass() != obj.getClass()) return false;
87         final AutofillId other = (AutofillId) obj;
88         if (mViewId != other.mViewId) return false;
89         if (mVirtualId != other.mVirtualId) return false;
90         return true;
91     }
92 
93     @Override
toString()94     public String toString() {
95         final StringBuilder builder = new StringBuilder().append(mViewId);
96         if (mVirtual) {
97             builder.append(':').append(mVirtualId);
98         }
99         return builder.toString();
100     }
101 
102     @Override
describeContents()103     public int describeContents() {
104         return 0;
105     }
106 
107     @Override
writeToParcel(Parcel parcel, int flags)108     public void writeToParcel(Parcel parcel, int flags) {
109         parcel.writeInt(mViewId);
110         parcel.writeInt(mVirtual ? 1 : 0);
111         parcel.writeInt(mVirtualId);
112     }
113 
AutofillId(Parcel parcel)114     private AutofillId(Parcel parcel) {
115         mViewId = parcel.readInt();
116         mVirtual = parcel.readInt() == 1;
117         mVirtualId = parcel.readInt();
118     }
119 
120     public static final Parcelable.Creator<AutofillId> CREATOR =
121             new Parcelable.Creator<AutofillId>() {
122         @Override
123         public AutofillId createFromParcel(Parcel source) {
124             return new AutofillId(source);
125         }
126 
127         @Override
128         public AutofillId[] newArray(int size) {
129             return new AutofillId[size];
130         }
131     };
132 }
133