Build 1.0_r1(from source)

android.view
Class ViewRoot

java.lang.Object
  extended by android.os.Handler
      extended by android.view.ViewRoot
All Implemented Interfaces:
View.AttachInfo.SoundEffectPlayer, ViewParent

final class ViewRoot
extends Handler
implements ViewParent, View.AttachInfo.SoundEffectPlayer

The top of a view hierarchy, implementing the needed protocol between View and the WindowManager. This is for the most part an internal implementation detail of WindowManagerImpl.


Nested Class Summary
static class ViewRoot.CalledFromWrongThreadException
           
(package private) static class ViewRoot.RunQueue
           
(package private) static class ViewRoot.TrackballAxis
          Maintains state information for a single trackball axis, generating discrete (DPAD) movements based on raw trackball motion.
(package private) static class ViewRoot.W
           
 
Field Summary
(package private)  int mAddNesting
           
(package private) static int MAX_TRACKBALL_DELAY
          Maximum time we allow the user to roll the trackball enough to generate a key event, before resetting the counters.
(package private)  ViewRoot.W mWindow
           
(package private) static boolean PROFILE_DRAWING
           
(package private) static ViewRoot.RunQueue sRunQueue
           
(package private) static ThreadLocal<Handler> sUiThreads
           
 
Constructor Summary
ViewRoot()
           
 
Method Summary
 void bringChildToFront(View child)
          Change the z order of the child so it's on top of all other children
(package private)  void checkThread()
           
 void childDrawableStateChanged(View child)
          This method is called on the parent when a child's drawable state has changed.
 void clearChildFocus(View child)
          Called when a child of this parent is giving up focus
 void createContextMenu(ContextMenu menu)
          Have the parent populate the specified context menu if it has anything to add (and then recurse on its parent).
 void debug()
           
 void die(boolean immediate)
           
 void dispatchAppVisibility(boolean visible)
           
(package private)  void dispatchDetachedFromWindow()
           
 void dispatchGetNewSurface()
           
 void dispatchKey(KeyEvent event)
           
 void dispatchPointer(MotionEvent event, long eventTime)
           
 void dispatchResized(int w, int h, boolean reportDraw)
           
 void dispatchTrackball(MotionEvent event, long eventTime)
           
(package private)  boolean ensureTouchMode(boolean inTouchMode)
          Something in the current window tells us we need to change the touch mode.
protected  void finalize()
          Called by the virtual machine when there are no longer any (non-weak) references to the receiver.
 void focusableViewAvailable(View v)
          Tells the parent that a new focusable view has become available.
 View focusSearch(View focused, int direction)
          Find the nearest view in the specified direction that wants to take focus
 boolean getChildVisibleRect(View child, Rect r, Point offset)
           
(package private)  int getHostVisibility()
           
static long getInstanceCount()
           
(package private)  WindowLeaked getLocation()
           
 ViewParent getParent()
          Returns the parent if it exists, or null.
 View getView()
           
protected  Rect getWindowFrame()
           
(package private)  void handleAppVisibility(boolean visible)
           
(package private)  void handleGetNewSurface()
           
 void handleMessage(Message msg)
          Subclasses must implement this to receive messages.
 void invalidateChild(View child, Rect dirty)
          All or part of a child is dirty and needs to be redrawn.
 ViewParent invalidateChildInParent(int[] location, Rect dirty)
          All or part of a child is dirty and needs to be redrawn.
(package private) static boolean isDirectional(int keyCode)
           
(package private) static boolean isInTouchMode()
          Indicates whether we are in touch mode.
 boolean isLayoutRequested()
          Indicates whether layout was requested on this view parent.
 void playSoundEffect(int effectId)
          
 void profile()
          Call this to profile the next traversal call.
 void recomputeViewAttributes(View child)
          Tell view hierarchy that the global view attributes need to be re-evaluated.
 void requestChildFocus(View child, View focused)
          Called when a child of this parent wants focus
 void requestDisallowInterceptTouchEvent(boolean disallowIntercept)
          Called when a child does not want this parent and its ancestors to intercept touch events with ViewGroup.onInterceptTouchEvent(MotionEvent).
 void requestLayout()
          Called when something has changed which has invalidated the layout of a child of this view parent.
 void requestTransparentRegion(View child)
          Called when a child wants the view hierarchy to gather and report transparent regions to the window compositor.
 void scheduleTraversals()
           
 void setLayoutParams(WindowManager.LayoutParams attrs)
           
 void setView(View view, WindowManager.LayoutParams attrs, View panelParentView)
          We have one child
 boolean showContextMenuForChild(View originalView)
          Bring up a context menu for the specified view or its ancestors.
 void unscheduleTraversals()
           
 void windowFocusChanged(boolean hasFocus, boolean inTouchMode)
           
 
Methods inherited from class android.os.Handler
dispatchMessage, dump, getLooper, hasMessages, hasMessages, obtainMessage, obtainMessage, obtainMessage, obtainMessage, obtainMessage, post, postAtFrontOfQueue, postAtTime, postAtTime, postDelayed, removeCallbacks, removeCallbacks, removeCallbacksAndMessages, removeMessages, removeMessages, sendEmptyMessage, sendEmptyMessageAtTime, sendEmptyMessageDelayed, sendMessage, sendMessageAtFrontOfQueue, sendMessageAtTime, sendMessageDelayed, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROFILE_DRAWING

static final boolean PROFILE_DRAWING
See Also:
Constant Field Values

MAX_TRACKBALL_DELAY

static final int MAX_TRACKBALL_DELAY
Maximum time we allow the user to roll the trackball enough to generate a key event, before resetting the counters.

See Also:
Constant Field Values

sUiThreads

static final ThreadLocal<Handler> sUiThreads

sRunQueue

static final ViewRoot.RunQueue sRunQueue

mWindow

final ViewRoot.W mWindow

mAddNesting

int mAddNesting
Constructor Detail

ViewRoot

public ViewRoot()
Method Detail

finalize

protected void finalize()
                 throws Throwable
Description copied from class: Object
Called by the virtual machine when there are no longer any (non-weak) references to the receiver. Subclasses can use this facility to guarantee that any associated resources are cleaned up before the receiver is garbage collected. Uncaught exceptions which are thrown during the running of the method cause it to terminate immediately, but are otherwise ignored.

Note: The virtual machine assumes that the implementation in class Object is empty.

Overrides:
finalize in class Object
Throws:
Throwable - The virtual machine ignores any exceptions which are thrown during finalization.

getInstanceCount

public static long getInstanceCount()

profile

public void profile()
Call this to profile the next traversal call. FIXME for perf testing only. Remove eventually


isInTouchMode

static boolean isInTouchMode()
Indicates whether we are in touch mode. Calling this method triggers an IPC call and should be avoided whenever possible.

Returns:
True, if the device is in touch mode, false otherwise.

setView

public void setView(View view,
                    WindowManager.LayoutParams attrs,
                    View panelParentView)
We have one child


getView

public View getView()

getLocation

final WindowLeaked getLocation()

setLayoutParams

public void setLayoutParams(WindowManager.LayoutParams attrs)

handleAppVisibility

void handleAppVisibility(boolean visible)

handleGetNewSurface

void handleGetNewSurface()

requestLayout

public void requestLayout()
Called when something has changed which has invalidated the layout of a child of this view parent. This will schedule a layout pass of the view tree.

Specified by:
requestLayout in interface ViewParent

isLayoutRequested

public boolean isLayoutRequested()
Indicates whether layout was requested on this view parent.

Specified by:
isLayoutRequested in interface ViewParent
Returns:
true if layout was requested, false otherwise

invalidateChild

public void invalidateChild(View child,
                            Rect dirty)
Description copied from interface: ViewParent
All or part of a child is dirty and needs to be redrawn.

Specified by:
invalidateChild in interface ViewParent
Parameters:
child - The child which is dirty
dirty - The area within the child that is invalid

getParent

public ViewParent getParent()
Description copied from interface: ViewParent
Returns the parent if it exists, or null.

Specified by:
getParent in interface ViewParent
Returns:
a ViewParent or null if this ViewParent does not have a parent

invalidateChildInParent

public ViewParent invalidateChildInParent(int[] location,
                                          Rect dirty)
Description copied from interface: ViewParent
All or part of a child is dirty and needs to be redrawn. The location array is an array of two int values which respectively define the left and the top position of the dirty child. This method must return the parent of this ViewParent if the specified rectangle must be invalidated in the parent. If the specified rectangle does not require invalidation in the parent or if the parent does not exist, this method must return null. When this method returns a non-null value, the location array must have been updated with the left and top coordinates of this ViewParent.

Specified by:
invalidateChildInParent in interface ViewParent
Parameters:
location - An array of 2 ints containing the left and top coordinates of the child to invalidate
dirty - The area within the child that is invalid
Returns:
the parent of this ViewParent or null

getChildVisibleRect

public boolean getChildVisibleRect(View child,
                                   Rect r,
                                   Point offset)
Specified by:
getChildVisibleRect in interface ViewParent

bringChildToFront

public void bringChildToFront(View child)
Description copied from interface: ViewParent
Change the z order of the child so it's on top of all other children

Specified by:
bringChildToFront in interface ViewParent

scheduleTraversals

public void scheduleTraversals()

unscheduleTraversals

public void unscheduleTraversals()

getHostVisibility

int getHostVisibility()

requestTransparentRegion

public void requestTransparentRegion(View child)
Description copied from interface: ViewParent
Called when a child wants the view hierarchy to gather and report transparent regions to the window compositor. Views that "punch" holes in the view hierarchy, such as SurfaceView can use this API to improve performance of the system. When no such a view is present in the hierarchy, this optimization in unnecessary and might slightly reduce the view hierarchy performance.

Specified by:
requestTransparentRegion in interface ViewParent
Parameters:
child - the view requesting the transparent region computation

requestChildFocus

public void requestChildFocus(View child,
                              View focused)
Description copied from interface: ViewParent
Called when a child of this parent wants focus

Specified by:
requestChildFocus in interface ViewParent
Parameters:
child - The child of this ViewParent that wants focus. This view will contain the focused view. It is not necessarily the view that actually has focus.
focused - The view that is a descendant of child that actually has focus

clearChildFocus

public void clearChildFocus(View child)
Description copied from interface: ViewParent
Called when a child of this parent is giving up focus

Specified by:
clearChildFocus in interface ViewParent
Parameters:
child - The view that is giving up focus

focusableViewAvailable

public void focusableViewAvailable(View v)
Description copied from interface: ViewParent
Tells the parent that a new focusable view has become available. This is to handle transitions from the case where there are no focusable views to the case where the first focusable view appears.

Specified by:
focusableViewAvailable in interface ViewParent
Parameters:
v - The view that has become newly focusable

recomputeViewAttributes

public void recomputeViewAttributes(View child)
Description copied from interface: ViewParent
Tell view hierarchy that the global view attributes need to be re-evaluated.

Specified by:
recomputeViewAttributes in interface ViewParent
Parameters:
child - View whose attributes have changed.

dispatchDetachedFromWindow

void dispatchDetachedFromWindow()

handleMessage

public void handleMessage(Message msg)
Description copied from class: Handler
Subclasses must implement this to receive messages.

Overrides:
handleMessage in class Handler

ensureTouchMode

boolean ensureTouchMode(boolean inTouchMode)
Something in the current window tells us we need to change the touch mode. For example, we are not in touch mode, and the user touches the screen. If the touch mode has changed, tell the window manager, and handle it locally.

Parameters:
inTouchMode - Whether we want to be in touch mode.
Returns:
True if the touch mode changed and focus changed was changed as a result

isDirectional

static boolean isDirectional(int keyCode)
Parameters:
keyCode - The key code
Returns:
True if the key is directional.

playSoundEffect

public void playSoundEffect(int effectId)

Specified by:
playSoundEffect in interface View.AttachInfo.SoundEffectPlayer

focusSearch

public View focusSearch(View focused,
                        int direction)
Find the nearest view in the specified direction that wants to take focus

Specified by:
focusSearch in interface ViewParent
Parameters:
focused - The view that currently has focus
direction - One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT

debug

public void debug()

die

public void die(boolean immediate)

dispatchResized

public void dispatchResized(int w,
                            int h,
                            boolean reportDraw)

dispatchKey

public void dispatchKey(KeyEvent event)

dispatchPointer

public void dispatchPointer(MotionEvent event,
                            long eventTime)

dispatchTrackball

public void dispatchTrackball(MotionEvent event,
                              long eventTime)

dispatchAppVisibility

public void dispatchAppVisibility(boolean visible)

dispatchGetNewSurface

public void dispatchGetNewSurface()

windowFocusChanged

public void windowFocusChanged(boolean hasFocus,
                               boolean inTouchMode)

showContextMenuForChild

public boolean showContextMenuForChild(View originalView)
Description copied from interface: ViewParent
Bring up a context menu for the specified view or its ancestors.

In most cases, a subclass does not need to override this. However, if the subclass is added directly to the window manager (for example, ViewManager.addView(View, android.view.ViewGroup.LayoutParams)) then it should override this and show the context menu.

Specified by:
showContextMenuForChild in interface ViewParent
Parameters:
originalView - The source view where the context menu was first invoked
Returns:
true if a context menu was displayed

createContextMenu

public void createContextMenu(ContextMenu menu)
Description copied from interface: ViewParent
Have the parent populate the specified context menu if it has anything to add (and then recurse on its parent).

Specified by:
createContextMenu in interface ViewParent
Parameters:
menu - The menu to populate

childDrawableStateChanged

public void childDrawableStateChanged(View child)
Description copied from interface: ViewParent
This method is called on the parent when a child's drawable state has changed.

Specified by:
childDrawableStateChanged in interface ViewParent
Parameters:
child - The child whose drawable state has changed.

getWindowFrame

protected Rect getWindowFrame()

checkThread

void checkThread()

requestDisallowInterceptTouchEvent

public void requestDisallowInterceptTouchEvent(boolean disallowIntercept)
Description copied from interface: ViewParent
Called when a child does not want this parent and its ancestors to intercept touch events with ViewGroup.onInterceptTouchEvent(MotionEvent).

This parent should pass this call onto its parents. This parent must obey this request for the duration of the touch (that is, only clear the flag after this parent has received an up or a cancel.

Specified by:
requestDisallowInterceptTouchEvent in interface ViewParent
Parameters:
disallowIntercept - True if the child does not want the parent to intercept touch events.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature