1/*
2 * Copyright (C) 2006 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.view.accessibility.AccessibilityEvent;
21
22/**
23 * Defines the responsibilities for a class that will be a parent of a View.
24 * This is the API that a view sees when it wants to interact with its parent.
25 *
26 */
27public interface ViewParent {
28    /**
29     * Called when something has changed which has invalidated the layout of a
30     * child of this view parent. This will schedule a layout pass of the view
31     * tree.
32     */
33    public void requestLayout();
34
35    /**
36     * Indicates whether layout was requested on this view parent.
37     *
38     * @return true if layout was requested, false otherwise
39     */
40    public boolean isLayoutRequested();
41
42    /**
43     * Called when a child wants the view hierarchy to gather and report
44     * transparent regions to the window compositor. Views that "punch" holes in
45     * the view hierarchy, such as SurfaceView can use this API to improve
46     * performance of the system. When no such a view is present in the
47     * hierarchy, this optimization in unnecessary and might slightly reduce the
48     * view hierarchy performance.
49     *
50     * @param child the view requesting the transparent region computation
51     *
52     */
53    public void requestTransparentRegion(View child);
54
55    /**
56     * All or part of a child is dirty and needs to be redrawn.
57     *
58     * @param child The child which is dirty
59     * @param r The area within the child that is invalid
60     */
61    public void invalidateChild(View child, Rect r);
62
63    /**
64     * All or part of a child is dirty and needs to be redrawn.
65     *
66     * <p>The location array is an array of two int values which respectively
67     * define the left and the top position of the dirty child.</p>
68     *
69     * <p>This method must return the parent of this ViewParent if the specified
70     * rectangle must be invalidated in the parent. If the specified rectangle
71     * does not require invalidation in the parent or if the parent does not
72     * exist, this method must return null.</p>
73     *
74     * <p>When this method returns a non-null value, the location array must
75     * have been updated with the left and top coordinates of this ViewParent.</p>
76     *
77     * @param location An array of 2 ints containing the left and top
78     *        coordinates of the child to invalidate
79     * @param r The area within the child that is invalid
80     *
81     * @return the parent of this ViewParent or null
82     */
83    public ViewParent invalidateChildInParent(int[] location, Rect r);
84
85    /**
86     * Returns the parent if it exists, or null.
87     *
88     * @return a ViewParent or null if this ViewParent does not have a parent
89     */
90    public ViewParent getParent();
91
92    /**
93     * Called when a child of this parent wants focus
94     *
95     * @param child The child of this ViewParent that wants focus. This view
96     *        will contain the focused view. It is not necessarily the view that
97     *        actually has focus.
98     * @param focused The view that is a descendant of child that actually has
99     *        focus
100     */
101    public void requestChildFocus(View child, View focused);
102
103    /**
104     * Tell view hierarchy that the global view attributes need to be
105     * re-evaluated.
106     *
107     * @param child View whose attributes have changed.
108     */
109    public void recomputeViewAttributes(View child);
110
111    /**
112     * Called when a child of this parent is giving up focus
113     *
114     * @param child The view that is giving up focus
115     */
116    public void clearChildFocus(View child);
117
118    /**
119     * Compute the visible part of a rectangular region defined in terms of a child view's
120     * coordinates.
121     *
122     * <p>Returns the clipped visible part of the rectangle <code>r</code>, defined in the
123     * <code>child</code>'s local coordinate system. <code>r</code> is modified by this method to
124     * contain the result, expressed in the global (root) coordinate system.</p>
125     *
126     * <p>The resulting rectangle is always axis aligned. If a rotation is applied to a node in the
127     * View hierarchy, the result is the axis-aligned bounding box of the visible rectangle.</p>
128     *
129     * @param child A child View, whose rectangular visible region we want to compute
130     * @param r The input rectangle, defined in the child coordinate system. Will be overwritten to
131     * contain the resulting visible rectangle, expressed in global (root) coordinates
132     * @param offset The input coordinates of a point, defined in the child coordinate system.
133     * As with the <code>r</code> parameter, this will be overwritten to contain the global (root)
134     * coordinates of that point.
135     * A <code>null</code> value is valid (in case you are not interested in this result)
136     * @return true if the resulting rectangle is not empty, false otherwise
137     */
138    public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset);
139
140    /**
141     * Find the nearest view in the specified direction that wants to take focus
142     *
143     * @param v The view that currently has focus
144     * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
145     */
146    public View focusSearch(View v, int direction);
147
148    /**
149     * Change the z order of the child so it's on top of all other children
150     *
151     * @param child
152     */
153    public void bringChildToFront(View child);
154
155    /**
156     * Tells the parent that a new focusable view has become available. This is
157     * to handle transitions from the case where there are no focusable views to
158     * the case where the first focusable view appears.
159     *
160     * @param v The view that has become newly focusable
161     */
162    public void focusableViewAvailable(View v);
163
164    /**
165     * Bring up a context menu for the specified view or its ancestors.
166     *
167     * <p>In most cases, a subclass does not need to override this.  However, if
168     * the subclass is added directly to the window manager (for example,
169     * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)})
170     * then it should override this and show the context menu.</p>
171     *
172     * @param originalView The source view where the context menu was first invoked
173     * @return true if a context menu was displayed
174     */
175    public boolean showContextMenuForChild(View originalView);
176
177    /**
178     * Have the parent populate the specified context menu if it has anything to
179     * add (and then recurse on its parent).
180     *
181     * @param menu The menu to populate
182     */
183    public void createContextMenu(ContextMenu menu);
184
185    /**
186     * Start an action mode for the specified view.
187     *
188     * <p>In most cases, a subclass does not need to override this. However, if the
189     * subclass is added directly to the window manager (for example,
190     * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)})
191     * then it should override this and start the action mode.</p>
192     *
193     * @param originalView The source view where the action mode was first invoked
194     * @param callback The callback that will handle lifecycle events for the action mode
195     * @return The new action mode if it was started, null otherwise
196     */
197    public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback);
198
199    /**
200     * This method is called on the parent when a child's drawable state
201     * has changed.
202     *
203     * @param child The child whose drawable state has changed.
204     */
205    public void childDrawableStateChanged(View child);
206
207    /**
208     * Called when a child does not want this parent and its ancestors to
209     * intercept touch events with
210     * {@link ViewGroup#onInterceptTouchEvent(MotionEvent)}.
211     *
212     * <p>This parent should pass this call onto its parents. This parent must obey
213     * this request for the duration of the touch (that is, only clear the flag
214     * after this parent has received an up or a cancel.</p>
215     *
216     * @param disallowIntercept True if the child does not want the parent to
217     *            intercept touch events.
218     */
219    public void requestDisallowInterceptTouchEvent(boolean disallowIntercept);
220
221    /**
222     * Called when a child of this group wants a particular rectangle to be
223     * positioned onto the screen.  {@link ViewGroup}s overriding this can trust
224     * that:
225     * <ul>
226     *   <li>child will be a direct child of this group</li>
227     *   <li>rectangle will be in the child's coordinates</li>
228     * </ul>
229     *
230     * <p>{@link ViewGroup}s overriding this should uphold the contract:</p>
231     * <ul>
232     *   <li>nothing will change if the rectangle is already visible</li>
233     *   <li>the view port will be scrolled only just enough to make the
234     *       rectangle visible</li>
235     * <ul>
236     *
237     * @param child The direct child making the request.
238     * @param rectangle The rectangle in the child's coordinates the child
239     *        wishes to be on the screen.
240     * @param immediate True to forbid animated or delayed scrolling,
241     *        false otherwise
242     * @return Whether the group scrolled to handle the operation
243     */
244    public boolean requestChildRectangleOnScreen(View child, Rect rectangle,
245            boolean immediate);
246
247    /**
248     * Called by a child to request from its parent to send an {@link AccessibilityEvent}.
249     * The child has already populated a record for itself in the event and is delegating
250     * to its parent to send the event. The parent can optionally add a record for itself.
251     * <p>
252     * Note: An accessibility event is fired by an individual view which populates the
253     *       event with a record for its state and requests from its parent to perform
254     *       the sending. The parent can optionally add a record for itself before
255     *       dispatching the request to its parent. A parent can also choose not to
256     *       respect the request for sending the event. The accessibility event is sent
257     *       by the topmost view in the view tree.</p>
258     *
259     * @param child The child which requests sending the event.
260     * @param event The event to be sent.
261     * @return True if the event was sent.
262     */
263    public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event);
264
265    /**
266     * Called when a child view now has or no longer is tracking transient state.
267     *
268     * @param child Child view whose state has changed
269     * @param hasTransientState true if this child has transient state
270     *
271     * @hide
272     */
273    public void childHasTransientStateChanged(View child, boolean hasTransientState);
274
275    /**
276     * Ask that a new dispatch of {@link View#fitSystemWindows(Rect)
277     * View.fitSystemWindows(Rect)} be performed.
278     */
279    public void requestFitSystemWindows();
280
281    /**
282     * Gets the parent of a given View for accessibility. Since some Views are not
283     * exposed to the accessibility layer the parent for accessibility is not
284     * necessarily the direct parent of the View, rather it is a predecessor.
285     *
286     * @return The parent or <code>null</code> if no such is found.
287     */
288    public ViewParent getParentForAccessibility();
289
290    /**
291     * A child notifies its parent that its state for accessibility has changed.
292     * That is some of the child properties reported to accessibility services has
293     * changed, hence the interested services have to be notified for the new state.
294     *
295     * @hide
296     */
297    public void childAccessibilityStateChanged(View child);
298}
299