Package io.flutter.util

## Class ViewUtils

- java.lang.Object
- - io.flutter.util.ViewUtils

-     public final class ViewUtils
      extends Object

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `ViewUtils.ViewVisitor` | Allows to visit a view.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ViewUtils()` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static boolean` | `childHasFocus​(View root)` | Determines if the current view or any descendant view has focus.
    `static int` | `generateViewId​(int fallbackId)` | Generates a view id.
    `static Activity` | `getActivity​(Context context)` | Retrieves the `Activity` from a given `Context`.
    `static boolean` | `hasChildViewOfType​(View root, Class<? extends View>[] viewTypes)` | Returns true if the root or any child view is an instance of the given types.
    `static boolean` | `traverseHierarchy​(View root, ViewUtils.ViewVisitor visitor)` | Traverses the view hierarchy in pre-order and runs the visitor for each child view including the root view.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ViewUtils

          public ViewUtils()

  - ### Method Detail

    - #### getActivity

          @Nullable
          public static Activity getActivity​(@Nullable
                                             Context context)

      Retrieves the `Activity` from a given `Context`.

      This method will recursively traverse up the context chain if it is a `ContextWrapper` until it finds the first instance of the base context that is an `Activity`.

    - #### generateViewId

          public static int generateViewId​(int fallbackId)

      Generates a view id.

      In API level 17 and above, this ID is unique. Below 17, the fallback id is used instead.

      Parameters:
        `fallbackId` - the fallback id.
      Returns:
        the view id.

    - #### childHasFocus

          public static boolean childHasFocus​(@Nullable
                                              View root)

      Determines if the current view or any descendant view has focus.
      Parameters:
        `root` - The root view.
      Returns:
        True if the current view or any descendant view has focus.

    - #### hasChildViewOfType

          public static boolean hasChildViewOfType​(@Nullable
                                                   View root,
                                                   Class<? extends View>[] viewTypes)

      Returns true if the root or any child view is an instance of the given types.
      Parameters:
        `root` - The root view.
        `viewTypes` - The types of views.
      Returns:
        true if any child view is an instance of any of the given types.

    - #### traverseHierarchy

          public static boolean traverseHierarchy​(@Nullable
                                                  View root,
                                                  @NonNull
                                                  ViewUtils.ViewVisitor visitor)

      Traverses the view hierarchy in pre-order and runs the visitor for each child view including the root view.

      If the visitor returns true, the traversal stops, and the method returns true.

      If the visitor returns false, the traversal continues until all views are visited.

      Parameters:
        `root` - The root view.
        `visitor` - The visitor.
      Returns:
        true if the visitor returned true for a given view.