ViewParent.java revision ac84d3ba81f08036308b17e1ab919e43987a3df5
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 * The location array is an array of two int values which respectively 67 * define the left and the top position of the dirty child. 68 * 69 * 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. 73 * 74 * 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. 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 public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset); 119 120 /** 121 * Find the nearest view in the specified direction that wants to take focus 122 * 123 * @param v The view that currently has focus 124 * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT 125 */ 126 public View focusSearch(View v, int direction); 127 128 /** 129 * Change the z order of the child so it's on top of all other children 130 * 131 * @param child 132 */ 133 public void bringChildToFront(View child); 134 135 /** 136 * Tells the parent that a new focusable view has become available. This is 137 * to handle transitions from the case where there are no focusable views to 138 * the case where the first focusable view appears. 139 * 140 * @param v The view that has become newly focusable 141 */ 142 public void focusableViewAvailable(View v); 143 144 /** 145 * Bring up a context menu for the specified view or its ancestors. 146 * <p> 147 * In most cases, a subclass does not need to override this. However, if 148 * the subclass is added directly to the window manager (for example, 149 * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)}) 150 * then it should override this and show the context menu. 151 * 152 * @param originalView The source view where the context menu was first invoked 153 * @return true if a context menu was displayed 154 */ 155 public boolean showContextMenuForChild(View originalView); 156 157 /** 158 * Have the parent populate the specified context menu if it has anything to 159 * add (and then recurse on its parent). 160 * 161 * @param menu The menu to populate 162 */ 163 public void createContextMenu(ContextMenu menu); 164 165 /** 166 * Start an action mode for the specified view. 167 * <p> 168 * In most cases, a subclass does not need to override this. However, if the 169 * subclass is added directly to the window manager (for example, 170 * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)}) 171 * then it should override this and start the action mode. 172 * 173 * @param originalView The source view where the action mode was first invoked 174 * @param callback The callback that will handle lifecycle events for the action mode 175 * @return The new action mode if it was started, null otherwise 176 */ 177 public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback); 178 179 /** 180 * This method is called on the parent when a child's drawable state 181 * has changed. 182 * 183 * @param child The child whose drawable state has changed. 184 */ 185 public void childDrawableStateChanged(View child); 186 187 /** 188 * Called when a child does not want this parent and its ancestors to 189 * intercept touch events with 190 * {@link ViewGroup#onInterceptTouchEvent(MotionEvent)}. 191 * <p> 192 * This parent should pass this call onto its parents. This parent must obey 193 * this request for the duration of the touch (that is, only clear the flag 194 * after this parent has received an up or a cancel. 195 * 196 * @param disallowIntercept True if the child does not want the parent to 197 * intercept touch events. 198 */ 199 public void requestDisallowInterceptTouchEvent(boolean disallowIntercept); 200 201 /** 202 * Called when a child of this group wants a particular rectangle to be 203 * positioned onto the screen. {@link ViewGroup}s overriding this can trust 204 * that: 205 * <ul> 206 * <li>child will be a direct child of this group</li> 207 * <li>rectangle will be in the child's coordinates</li> 208 * </ul> 209 * 210 * <p>{@link ViewGroup}s overriding this should uphold the contract:</p> 211 * <ul> 212 * <li>nothing will change if the rectangle is already visible</li> 213 * <li>the view port will be scrolled only just enough to make the 214 * rectangle visible</li> 215 * <ul> 216 * 217 * @param child The direct child making the request. 218 * @param rectangle The rectangle in the child's coordinates the child 219 * wishes to be on the screen. 220 * @param immediate True to forbid animated or delayed scrolling, 221 * false otherwise 222 * @return Whether the group scrolled to handle the operation 223 */ 224 public boolean requestChildRectangleOnScreen(View child, Rect rectangle, 225 boolean immediate); 226 227 /** 228 * Called by a child to request from its parent to send an {@link AccessibilityEvent}. 229 * The child has already populated a record for itself in the event and is delegating 230 * to its parent to send the event. The parent can optionally add a record for itself. 231 * <p> 232 * Note: An accessibility event is fired by an individual view which populates the 233 * event with a record for its state and requests from its parent to perform 234 * the sending. The parent can optionally add a record for itself before 235 * dispatching the request to its parent. A parent can also choose not to 236 * respect the request for sending the event. The accessibility event is sent 237 * by the topmost view in the view tree. 238 * 239 * @param child The child which requests sending the event. 240 * @param event The event to be sent. 241 * @return True if the event was sent. 242 */ 243 public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event); 244} 245