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 17 package android.view; 18 19 import 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 */ 26 public 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 */ requestLayout()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 */ isLayoutRequested()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 */ requestTransparentRegion(View child)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 */ invalidateChild(View child, Rect r)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 */ invalidateChildInParent(int[] location, Rect r)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 */ getParent()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 */ requestChildFocus(View child, View focused)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 */ recomputeViewAttributes(View child)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 */ clearChildFocus(View child)115 public void clearChildFocus(View child); 116 getChildVisibleRect(View child, Rect r, android.graphics.Point offset)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 */ focusSearch(View v, int direction)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 */ bringChildToFront(View child)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 */ focusableViewAvailable(View v)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 */ showContextMenuForChild(View originalView)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 */ createContextMenu(ContextMenu menu)162 public void createContextMenu(ContextMenu menu); 163 164 /** 165 * This method is called on the parent when a child's drawable state 166 * has changed. 167 * 168 * @param child The child whose drawable state has changed. 169 */ childDrawableStateChanged(View child)170 public void childDrawableStateChanged(View child); 171 172 /** 173 * Called when a child does not want this parent and its ancestors to 174 * intercept touch events with 175 * {@link ViewGroup#onInterceptTouchEvent(MotionEvent)}. 176 * <p> 177 * This parent should pass this call onto its parents. This parent must obey 178 * this request for the duration of the touch (that is, only clear the flag 179 * after this parent has received an up or a cancel. 180 * 181 * @param disallowIntercept True if the child does not want the parent to 182 * intercept touch events. 183 */ requestDisallowInterceptTouchEvent(boolean disallowIntercept)184 public void requestDisallowInterceptTouchEvent(boolean disallowIntercept); 185 186 /** 187 * Called when a child of this group wants a particular rectangle to be 188 * positioned onto the screen. {@link ViewGroup}s overriding this can trust 189 * that: 190 * <ul> 191 * <li>child will be a direct child of this group</li> 192 * <li>rectangle will be in the child's coordinates</li> 193 * </ul> 194 * 195 * <p>{@link ViewGroup}s overriding this should uphold the contract:</p> 196 * <ul> 197 * <li>nothing will change if the rectangle is already visible</li> 198 * <li>the view port will be scrolled only just enough to make the 199 * rectangle visible</li> 200 * <ul> 201 * 202 * @param child The direct child making the request. 203 * @param rectangle The rectangle in the child's coordinates the child 204 * wishes to be on the screen. 205 * @param immediate True to forbid animated or delayed scrolling, 206 * false otherwise 207 * @return Whether the group scrolled to handle the operation 208 */ requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate)209 public boolean requestChildRectangleOnScreen(View child, Rect rectangle, 210 boolean immediate); 211 } 212