ViewStructure.java revision 5cfaae4aae744574f0fcc0876cdc5473bc1a344d
1/*
2 * Copyright (C) 2015 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
17package android.view;
18
19import android.graphics.Rect;
20import android.os.Bundle;
21import android.text.TextPaint;
22
23/**
24 * Container for storing additional per-view data generated by {@link View#onProvideStructure
25 * View.onProvideStructure}.
26 */
27public abstract class ViewStructure {
28    /**
29     * Set the identifier for this view.
30     *
31     * @param id The view's identifier, as per {@link View#getId View.getId()}.
32     * @param packageName The package name of the view's identifier, or null if there is none.
33     * @param typeName The type name of the view's identifier, or null if there is none.
34     * @param entryName The entry name of the view's identifier, or null if there is none.
35     */
36    public abstract void setId(int id, String packageName, String typeName, String entryName);
37
38    /**
39     * Set the basic dimensions of this view.
40     *
41     * @param left The view's left position, in pixels relative to its parent's left edge.
42     * @param top The view's top position, in pixels relative to its parent's top edge.
43     * @param scrollX How much the view's x coordinate space has been scrolled, in pixels.
44     * @param scrollY How much the view's y coordinate space has been scrolled, in pixels.
45     * @param width The view's visible width, in pixels.  This is the width visible on screen,
46     * not the total data width of a scrollable view.
47     * @param height The view's visible height, in pixels.  This is the height visible on
48     * screen, not the total data height of a scrollable view.
49     */
50    public abstract void setDimens(int left, int top, int scrollX, int scrollY, int width,
51            int height);
52
53    /**
54     * Set the visibility state of this view, as per
55     * {@link View#getVisibility View.getVisibility()}.
56     */
57    public abstract void setVisibility(int visibility);
58
59    /** @hide */
60    public abstract void setAssistBlocked(boolean state);
61
62    /**
63     * Set the enabled state of this view, as per {@link View#isEnabled View.isEnabled()}.
64     */
65    public abstract void setEnabled(boolean state);
66
67    /**
68     * Set the clickable state of this view, as per {@link View#isClickable View.isClickable()}.
69     */
70    public abstract void setClickable(boolean state);
71
72    /**
73     * Set the long clickable state of this view, as per
74     * {@link View#isLongClickable View.isLongClickable()}.
75     */
76    public abstract void setLongClickable(boolean state);
77
78    /**
79     * Set the stylus button pressable state of this view, as per
80     * {@link View#isStylusButtonPressable View.isStylusButtonPressable()}.
81     */
82    public abstract void setStylusButtonPressable(boolean state);
83
84    /**
85     * Set the focusable state of this view, as per {@link View#isFocusable View.isFocusable()}.
86     */
87    public abstract void setFocusable(boolean state);
88
89    /**
90     * Set the focused state of this view, as per {@link View#isFocused View.isFocused()}.
91     */
92    public abstract void setFocused(boolean state);
93
94    /**
95     * Set the accessibility focused state of this view, as per
96     * {@link View#isAccessibilityFocused View.isAccessibilityFocused()}.
97     */
98    public abstract void setAccessibilityFocused(boolean state);
99
100    /**
101     * Set the checkable state of this view, such as whether it implements the
102     * {@link android.widget.Checkable} interface.
103     */
104    public abstract void setCheckable(boolean state);
105
106    /**
107     * Set the checked state of this view, such as
108     * {@link android.widget.Checkable#isChecked Checkable.isChecked()}.
109     */
110    public abstract void setChecked(boolean state);
111
112    /**
113     * Set the selected state of this view, as per {@link View#isSelected View.isSelected()}.
114     */
115    public abstract void setSelected(boolean state);
116
117    /**
118     * Set the activated state of this view, as per {@link View#isActivated View.isActivated()}.
119     */
120    public abstract void setActivated(boolean state);
121
122    /**
123     * Set the class name of the view, as per
124     * {@link View#getAccessibilityClassName View.getAccessibilityClassName()}.
125     */
126    public abstract void setClassName(String className);
127
128    /**
129     * Set the content description of the view, as per
130     * {@link View#getContentDescription View.getContentDescription()}.
131     */
132    public abstract void setContentDescription(CharSequence contentDescription);
133
134    /**
135     * Set the text that is associated with this view.  There is no selection
136     * associated with the text.  The text may have style spans to supply additional
137     * display and semantic information.
138     */
139    public abstract void setText(CharSequence text);
140
141    /**
142     * Like {@link #setText(CharSequence)} but with an active selection
143     * extending from <var>selectionStart</var> through <var>selectionEnd</var>.
144     */
145    public abstract void setText(CharSequence text, int selectionStart, int selectionEnd);
146
147    /**
148     * Explicitly set default global style information for text that was previously set with
149     * {@link #setText}.
150     *
151     * @param size The size, in pixels, of the text.
152     * @param fgColor The foreground color, packed as 0xAARRGGBB.
153     * @param bgColor The background color, packed as 0xAARRGGBB.
154     * @param style Style flags, as defined by {@link android.app.AssistStructure.ViewNode}.
155     */
156    public abstract void setTextStyle(float size, int fgColor, int bgColor, int style);
157
158    /**
159     * Set optional hint text associated with this view; this is for example the text that is
160     * shown by an EditText when it is empty to indicate to the user the kind of text to input.
161     */
162    public abstract void setHint(CharSequence hint);
163
164    /**
165     * Retrieve the last {@link #setText(CharSequence)}.
166     */
167    public abstract CharSequence getText();
168
169    /**
170     * Retrieve the last selection start set by {@link #setText(CharSequence, int, int)}.
171     */
172    public abstract int getTextSelectionStart();
173
174    /**
175     * Retrieve the last selection end set by {@link #setText(CharSequence, int, int)}.
176     */
177    public abstract int getTextSelectionEnd();
178
179    /**
180     * Retrieve the last hint set by {@link #setHint}.
181     */
182    public abstract CharSequence getHint();
183
184    /**
185     * Get extra data associated with this view structure; the returned Bundle is mutable,
186     * allowing you to view and modify its contents.  Keys placed in the Bundle should use
187     * an appropriate namespace prefix (such as com.google.MY_KEY) to avoid conflicts.
188     */
189    public abstract Bundle getExtras();
190
191    /**
192     * Returns true if {@link #getExtras} has been used to create extra content.
193     */
194    public abstract boolean hasExtras();
195
196    /**
197     * Set the number of children of this view, which defines the range of indices you can
198     * use with {@link #newChild} and {@link #asyncNewChild}.  Calling this method again
199     * resets all of the child state of the view, removing any children that had previously
200     * been added.
201     */
202    public abstract void setChildCount(int num);
203
204    /**
205     * Return the child count as set by {@link #setChildCount}.
206     */
207    public abstract int getChildCount();
208
209    /**
210     * Create a new child {@link ViewStructure} in this view, putting into the list of
211     * children at <var>index</var>.
212     * @return Returns an fresh {@link ViewStructure} ready to be filled in.
213     */
214    public abstract ViewAssistStructure newChild(int index);
215
216    /**
217     * Like {@link #newChild}, but allows the caller to asynchronously populate the returned
218     * child.  It can transfer the returned {@link ViewStructure} to another thread for it
219     * to build its content (and children etc).  Once done, some thread must call
220     * {@link #asyncCommit} to tell the containing {@link ViewStructure} that the async
221     * population is done.
222     * @return Returns an fresh {@link ViewStructure} ready to be filled in.
223     */
224    public abstract ViewAssistStructure asyncNewChild(int index);
225
226    /**
227     * Call when done populating a {@link ViewStructure} returned by
228     * {@link #asyncNewChild}.
229     */
230    public abstract void asyncCommit();
231
232    /** @hide */
233    public abstract Rect getTempRect();
234}
235