blob: 86b89adb5ce38dcfd2525fd2a9fb60703cafb301 [file] [log] [blame]
Felipe Leme1dfa9a02018-10-17 17:24:37 -07001/*
2 * Copyright (C) 2018 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 */
Felipe Leme749b8892018-12-03 16:30:30 -080016package android.view.contentcapture;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070017
Felipe Leme88eae3b2018-11-07 15:11:56 -080018import android.annotation.NonNull;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070019import android.annotation.Nullable;
20import android.annotation.SystemApi;
21import android.app.assist.AssistStructure;
Felipe Leme88eae3b2018-11-07 15:11:56 -080022import android.graphics.Matrix;
23import android.graphics.Rect;
24import android.os.Bundle;
25import android.os.LocaleList;
26import android.os.Parcel;
27import android.util.Log;
28import android.view.View;
29import android.view.ViewParent;
30import android.view.ViewStructure;
31import android.view.ViewStructure.HtmlInfo.Builder;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070032import android.view.autofill.AutofillId;
Felipe Leme88eae3b2018-11-07 15:11:56 -080033import android.view.autofill.AutofillValue;
34
35import com.android.internal.util.Preconditions;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070036
37//TODO(b/111276913): add javadocs / implement Parcelable / implement
38//TODO(b/111276913): for now it's extending ViewNode directly as it needs most of its properties,
39// but it might be better to create a common, abstract android.view.ViewNode class that both extend
40// instead
41/** @hide */
42@SystemApi
43public final class ViewNode extends AssistStructure.ViewNode {
44
Felipe Leme88eae3b2018-11-07 15:11:56 -080045 private static final String TAG = "ViewNode";
46
47 private AutofillId mParentAutofillId;
48
49 // TODO(b/111276913): temporarily setting some fields here while they're not accessible from the
50 // superclass
51 private AutofillId mAutofillId;
52 private CharSequence mText;
53 private String mClassName;
54
Felipe Leme1dfa9a02018-10-17 17:24:37 -070055 /** @hide */
56 public ViewNode() {
57 }
58
59 /**
60 * Returns the {@link AutofillId} of this view's parent, if the parent is also part of the
61 * screen observation tree.
62 */
63 @Nullable
64 public AutofillId getParentAutofillId() {
Felipe Leme88eae3b2018-11-07 15:11:56 -080065 return mParentAutofillId;
66 }
67
68 // TODO(b/111276913): temporarily overwriting some methods
69 @Override
70 public AutofillId getAutofillId() {
71 return mAutofillId;
72 }
73 @Override
74 public CharSequence getText() {
75 return mText;
76 }
77 @Override
78 public String getClassName() {
79 return mClassName;
80 }
81
82 /** @hide */
83 public static void writeToParcel(@NonNull Parcel parcel, @Nullable ViewNode node, int flags) {
84 if (node == null) {
85 parcel.writeParcelable(null, flags);
86 return;
87 }
88 parcel.writeParcelable(node.mAutofillId, flags);
89 parcel.writeParcelable(node.mParentAutofillId, flags);
90 parcel.writeCharSequence(node.mText);
91 parcel.writeString(node.mClassName);
92 }
93
94 /** @hide */
95 public static @Nullable ViewNode readFromParcel(@NonNull Parcel parcel) {
96 final AutofillId id = parcel.readParcelable(null);
97 if (id == null) return null;
98
99 final ViewNode node = new ViewNode();
100
101 node.mAutofillId = id;
102 node.mParentAutofillId = parcel.readParcelable(null);
103 node.mText = parcel.readCharSequence();
104 node.mClassName = parcel.readString();
105
106 return node;
107 }
108
109 /** @hide */
110 static final class ViewStructureImpl extends ViewStructure {
111
112 final ViewNode mNode = new ViewNode();
113
114 ViewStructureImpl(@NonNull View view) {
115 mNode.mAutofillId = Preconditions.checkNotNull(view).getAutofillId();
116 final ViewParent parent = view.getParent();
117 if (parent instanceof View) {
118 mNode.mParentAutofillId = ((View) parent).getAutofillId();
119 }
120 }
121
122 ViewStructureImpl(@NonNull AutofillId parentId, int virtualId) {
123 mNode.mParentAutofillId = Preconditions.checkNotNull(parentId);
124 mNode.mAutofillId = new AutofillId(parentId, virtualId);
125 }
126
127 @Override
128 public void setId(int id, String packageName, String typeName, String entryName) {
129 // TODO(b/111276913): implement or move to superclass
130 }
131
132 @Override
133 public void setDimens(int left, int top, int scrollX, int scrollY, int width, int height) {
134 // TODO(b/111276913): implement or move to superclass
135 }
136
137 @Override
138 public void setTransformation(Matrix matrix) {
139 // TODO(b/111276913): implement or move to superclass
140 }
141
142 @Override
143 public void setElevation(float elevation) {
144 // TODO(b/111276913): implement or move to superclass
145 }
146
147 @Override
148 public void setAlpha(float alpha) {
149 // TODO(b/111276913): implement or move to superclass
150 }
151
152 @Override
153 public void setVisibility(int visibility) {
154 // TODO(b/111276913): implement or move to superclass
155 }
156
157 @Override
158 public void setAssistBlocked(boolean state) {
159 // TODO(b/111276913): implement or move to superclass
160 }
161
162 @Override
163 public void setEnabled(boolean state) {
164 // TODO(b/111276913): implement or move to superclass
165 }
166
167 @Override
168 public void setClickable(boolean state) {
169 // TODO(b/111276913): implement or move to superclass
170 }
171
172 @Override
173 public void setLongClickable(boolean state) {
174 // TODO(b/111276913): implement or move to superclass
175 }
176
177 @Override
178 public void setContextClickable(boolean state) {
179 // TODO(b/111276913): implement or move to superclass
180 }
181
182 @Override
183 public void setFocusable(boolean state) {
184 // TODO(b/111276913): implement or move to superclass
185 }
186
187 @Override
188 public void setFocused(boolean state) {
189 // TODO(b/111276913): implement or move to superclass
190 }
191
192 @Override
193 public void setAccessibilityFocused(boolean state) {
194 // TODO(b/111276913): implement or move to superclass
195 }
196
197 @Override
198 public void setCheckable(boolean state) {
199 // TODO(b/111276913): implement or move to superclass
200 }
201
202 @Override
203 public void setChecked(boolean state) {
204 // TODO(b/111276913): implement or move to superclass
205 }
206
207 @Override
208 public void setSelected(boolean state) {
209 // TODO(b/111276913): implement or move to superclass
210 }
211
212 @Override
213 public void setActivated(boolean state) {
214 // TODO(b/111276913): implement or move to superclass
215 }
216
217 @Override
218 public void setOpaque(boolean opaque) {
219 // TODO(b/111276913): implement or move to superclass
220 }
221
222 @Override
223 public void setClassName(String className) {
224 // TODO(b/111276913): temporarily setting directly; should be done on superclass instead
225 mNode.mClassName = className;
226 }
227
228 @Override
229 public void setContentDescription(CharSequence contentDescription) {
230 // TODO(b/111276913): implement or move to superclass
231 }
232
233 @Override
234 public void setText(CharSequence text) {
235 // TODO(b/111276913): temporarily setting directly; should be done on superclass instead
236 mNode.mText = text;
237 }
238
239 @Override
240 public void setText(CharSequence text, int selectionStart, int selectionEnd) {
Felipe Lemee56d1912018-11-26 14:04:51 -0800241 // TODO(b/111276913): temporarily setting directly; should be done on superclass instead
242 mNode.mText = text;
Felipe Leme88eae3b2018-11-07 15:11:56 -0800243 // TODO(b/111276913): implement or move to superclass
244 }
245
246 @Override
247 public void setTextStyle(float size, int fgColor, int bgColor, int style) {
248 // TODO(b/111276913): implement or move to superclass
249 }
250
251 @Override
252 public void setTextLines(int[] charOffsets, int[] baselines) {
253 // TODO(b/111276913): implement or move to superclass
254 }
255
256 @Override
257 public void setHint(CharSequence hint) {
258 // TODO(b/111276913): implement or move to superclass
259 }
260
261 @Override
262 public CharSequence getText() {
263 // TODO(b/111276913): temporarily getting directly; should be done on superclass instead
264 return mNode.mText;
265 }
266
267 @Override
268 public int getTextSelectionStart() {
269 // TODO(b/111276913): implement or move to superclass
270 return 0;
271 }
272
273 @Override
274 public int getTextSelectionEnd() {
275 // TODO(b/111276913): implement or move to superclass
276 return 0;
277 }
278
279 @Override
280 public CharSequence getHint() {
281 // TODO(b/111276913): implement or move to superclass
282 return null;
283 }
284
285 @Override
286 public Bundle getExtras() {
287 // TODO(b/111276913): implement or move to superclass
288 return null;
289 }
290
291 @Override
292 public boolean hasExtras() {
293 // TODO(b/111276913): implement or move to superclass
294 return false;
295 }
296
297 @Override
298 public void setChildCount(int num) {
299 Log.w(TAG, "setChildCount() is not supported");
300 }
301
302 @Override
303 public int addChildCount(int num) {
304 Log.w(TAG, "addChildCount() is not supported");
305 return 0;
306 }
307
308 @Override
309 public int getChildCount() {
310 Log.w(TAG, "getChildCount() is not supported");
311 return 0;
312 }
313
314 @Override
315 public ViewStructure newChild(int index) {
316 Log.w(TAG, "newChild() is not supported");
317 return null;
318 }
319
320 @Override
321 public ViewStructure asyncNewChild(int index) {
322 Log.w(TAG, "asyncNewChild() is not supported");
323 return null;
324 }
325
326 @Override
327 public AutofillId getAutofillId() {
328 // TODO(b/111276913): temporarily getting directly; should be done on superclass instead
329 return mNode.mAutofillId;
330 }
331
332 @Override
333 public void setAutofillId(AutofillId id) {
334 // TODO(b/111276913): temporarily setting directly; should be done on superclass instead
335 mNode.mAutofillId = id;
336 }
337
338 @Override
339 public void setAutofillId(AutofillId parentId, int virtualId) {
340 // TODO(b/111276913): temporarily setting directly; should be done on superclass instead
341 mNode.mAutofillId = new AutofillId(parentId, virtualId);
342 }
343
344 @Override
345 public void setAutofillType(int type) {
346 // TODO(b/111276913): implement or move to superclass
347 }
348
349 @Override
350 public void setAutofillHints(String[] hint) {
351 // TODO(b/111276913): implement or move to superclass
352 }
353
354 @Override
355 public void setAutofillValue(AutofillValue value) {
356 // TODO(b/111276913): implement or move to superclass
357 }
358
359 @Override
360 public void setAutofillOptions(CharSequence[] options) {
361 // TODO(b/111276913): implement or move to superclass
362 }
363
364 @Override
365 public void setInputType(int inputType) {
366 // TODO(b/111276913): implement or move to superclass
367 }
368
369 @Override
370 public void setDataIsSensitive(boolean sensitive) {
371 // TODO(b/111276913): implement or move to superclass
372 }
373
374 @Override
375 public void asyncCommit() {
376 Log.w(TAG, "asyncCommit() is not supported");
377 }
378
379 @Override
380 public Rect getTempRect() {
381 // TODO(b/111276913): implement or move to superclass
382 return null;
383 }
384
385 @Override
386 public void setWebDomain(String domain) {
387 Log.w(TAG, "setWebDomain() is not supported");
388 }
389
390 @Override
391 public void setLocaleList(LocaleList localeList) {
392 // TODO(b/111276913): implement or move to superclass
393 }
394
395 @Override
396 public Builder newHtmlInfoBuilder(String tagName) {
397 Log.w(TAG, "newHtmlInfoBuilder() is not supported");
398 return null;
399 }
400
401 @Override
402 public void setHtmlInfo(HtmlInfo htmlInfo) {
403 Log.w(TAG, "setHtmlInfo() is not supported");
404 }
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700405 }
406}