ViewParent.java revision 6e34636749217654f43221885afb7a29bb5ca96a
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; 20 21/** 22 * Defines the responsibilities for a class that will be a parent of a View. 23 * This is the API that a view sees when it wants to interact with its parent. 24 * 25 */ 26public interface ViewParent { 27 /** 28 * Called when something has changed which has invalidated the layout of a 29 * child of this view parent. This will schedule a layout pass of the view 30 * tree. 31 */ 32 public void requestLayout(); 33 34 /** 35 * Indicates whether layout was requested on this view parent. 36 * 37 * @return true if layout was requested, false otherwise 38 */ 39 public boolean isLayoutRequested(); 40 41 /** 42 * Called when a child wants the view hierarchy to gather and report 43 * transparent regions to the window compositor. Views that "punch" holes in 44 * the view hierarchy, such as SurfaceView can use this API to improve 45 * performance of the system. When no such a view is present in the 46 * hierarchy, this optimization in unnecessary and might slightly reduce the 47 * view hierarchy performance. 48 * 49 * @param child the view requesting the transparent region computation 50 * 51 */ 52 public void requestTransparentRegion(View child); 53 54 /** 55 * All or part of a child is dirty and needs to be redrawn. 56 * 57 * @param child The child which is dirty 58 * @param r The area within the child that is invalid 59 */ 60 public void invalidateChild(View child, Rect r); 61 62 /** 63 * All or part of a child is dirty and needs to be redrawn. 64 * 65 * The location array is an array of two int values which respectively 66 * define the left and the top position of the dirty child. 67 * 68 * This method must return the parent of this ViewParent if the specified 69 * rectangle must be invalidated in the parent. If the specified rectangle 70 * does not require invalidation in the parent or if the parent does not 71 * exist, this method must return null. 72 * 73 * When this method returns a non-null value, the location array must 74 * have been updated with the left and top coordinates of this ViewParent. 75 * 76 * @param location An array of 2 ints containing the left and top 77 * coordinates of the child to invalidate 78 * @param r The area within the child that is invalid 79 * 80 * @return the parent of this ViewParent or null 81 */ 82 public ViewParent invalidateChildInParent(int[] location, Rect r); 83 84 /** 85 * Returns the parent if it exists, or null. 86 * 87 * @return a ViewParent or null if this ViewParent does not have a parent 88 */ 89 public ViewParent getParent(); 90 91 /** 92 * Called when a child of this parent wants focus 93 * 94 * @param child The child of this ViewParent that wants focus. This view 95 * will contain the focused view. It is not necessarily the view that 96 * actually has focus. 97 * @param focused The view that is a descendant of child that actually has 98 * focus 99 */ 100 public void requestChildFocus(View child, View focused); 101 102 /** 103 * Tell view hierarchy that the global view attributes need to be 104 * re-evaluated. 105 * 106 * @param child View whose attributes have changed. 107 */ 108 public void recomputeViewAttributes(View child); 109 110 /** 111 * Called when a child of this parent is giving up focus 112 * 113 * @param child The view that is giving up focus 114 */ 115 public void clearChildFocus(View child); 116 117 public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset); 118 119 /** 120 * Find the nearest view in the specified direction that wants to take focus 121 * 122 * @param v The view that currently has focus 123 * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT 124 */ 125 public View focusSearch(View v, int direction); 126 127 /** 128 * Change the z order of the child so it's on top of all other children 129 * 130 * @param child 131 */ 132 public void bringChildToFront(View child); 133 134 /** 135 * Tells the parent that a new focusable view has become available. This is 136 * to handle transitions from the case where there are no focusable views to 137 * the case where the first focusable view appears. 138 * 139 * @param v The view that has become newly focusable 140 */ 141 public void focusableViewAvailable(View v); 142 143 /** 144 * Bring up a context menu for the specified view or its ancestors. 145 * <p> 146 * In most cases, a subclass does not need to override this. However, if 147 * the subclass is added directly to the window manager (for example, 148 * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)}) 149 * then it should override this and show the context menu. 150 * 151 * @param originalView The source view where the context menu was first invoked 152 * @return true if a context menu was displayed 153 */ 154 public boolean showContextMenuForChild(View originalView); 155 156 /** 157 * Have the parent populate the specified context menu if it has anything to 158 * add (and then recurse on its parent). 159 * 160 * @param menu The menu to populate 161 */ 162 public void createContextMenu(ContextMenu menu); 163 164 /** 165 * Start an action mode for the specified view. 166 * <p> 167 * In most cases, a subclass does not need to override this. However, if the 168 * 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 start the action mode. 171 * 172 * @param originalView The source view where the action mode was first invoked 173 * @param callback The callback that will handle lifecycle events for the action mode 174 * @return The new action mode if it was started, null otherwise 175 */ 176 public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback); 177 178 /** 179 * This method is called on the parent when a child's drawable state 180 * has changed. 181 * 182 * @param child The child whose drawable state has changed. 183 */ 184 public void childDrawableStateChanged(View child); 185 186 /** 187 * Called when a child does not want this parent and its ancestors to 188 * intercept touch events with 189 * {@link ViewGroup#onInterceptTouchEvent(MotionEvent)}. 190 * <p> 191 * This parent should pass this call onto its parents. This parent must obey 192 * this request for the duration of the touch (that is, only clear the flag 193 * after this parent has received an up or a cancel. 194 * 195 * @param disallowIntercept True if the child does not want the parent to 196 * intercept touch events. 197 */ 198 public void requestDisallowInterceptTouchEvent(boolean disallowIntercept); 199 200 /** 201 * Called when a child of this group wants a particular rectangle to be 202 * positioned onto the screen. {@link ViewGroup}s overriding this can trust 203 * that: 204 * <ul> 205 * <li>child will be a direct child of this group</li> 206 * <li>rectangle will be in the child's coordinates</li> 207 * </ul> 208 * 209 * <p>{@link ViewGroup}s overriding this should uphold the contract:</p> 210 * <ul> 211 * <li>nothing will change if the rectangle is already visible</li> 212 * <li>the view port will be scrolled only just enough to make the 213 * rectangle visible</li> 214 * <ul> 215 * 216 * @param child The direct child making the request. 217 * @param rectangle The rectangle in the child's coordinates the child 218 * wishes to be on the screen. 219 * @param immediate True to forbid animated or delayed scrolling, 220 * false otherwise 221 * @return Whether the group scrolled to handle the operation 222 */ 223 public boolean requestChildRectangleOnScreen(View child, Rect rectangle, 224 boolean immediate); 225} 226